From f0c3fc54655b9b8ea75321294eb66a293f3b89a3 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Thu, 21 Nov 2019 21:46:51 -0500 Subject: [PATCH] Add proper hash matching for GFPAK Also add latest turbo muunt editor files --- .gitignore | 1 + .../FileFormats/Archives/GFPAK.cs | 106 ++++++++- .../Interfaces/I2DDrawableContainer.cs | 2 +- .../GUI/Byaml/MuuntEditor/MuuntEditor2D.cs | 5 +- .../MK8/PathDoublePointDrawableContainer.cs | 14 +- .../Plugins/MK8/PathDrawableContainer.cs | 14 +- .../MK8/RenderableSinglePointDrawable.cs | 70 ++++++ .../Plugins/MK8/TrackMuuntLoader.cs | 6 +- .../TurboCourseMuunt/Base/BasePathPoint.cs | 12 +- .../Byaml/TurboCourseMuunt/Matrix2DHelper.cs | 24 ++ .../Byaml/TurboCourseMuunt/Paths/LapPaths.cs | 25 +++ .../RenderableDoublePointPath.cs | 167 +++++--------- .../Editors/MK8TrackEditor/MapCameraViewer.cs | 3 + .../GUI/ViewportEditor.Designer.cs | 159 +++++++++++++ File_Format_Library/GUI/ViewportEditor.cs | 208 ++++++++++++++++++ File_Format_Library/GUI/ViewportEditor.resx | 123 +++++++++++ .../Properties/Resources.Designer.cs | 92 +++++--- File_Format_Library/Properties/Resources.resx | 3 + File_Format_Library/Resources/Hashes/Pkmn.txt | 62 ++++++ .../Animations/Animation.cs | 1 - .../Forms/Editors/TextEditor/TextEditor.cs | 1 + .../HashCalculate/FNV64A1.cs | 52 +++++ .../IO/Extensions/StringExtension.cs | 7 + .../Interfaces/IAnimationContainer.cs | 13 ++ .../OpenGL/IPickableObject.cs | 2 + Switch_Toolbox_Library/OpenGL/Viewport2D.cs | 52 +++++ Switch_Toolbox_Library/OpenGL/Viewport2D.resx | 120 ++++++++++ Switch_Toolbox_Library/Toolbox_Library.csproj | 5 + Toolbox/GUI/HashCalculatorForm.Designer.cs | 11 +- Toolbox/GUI/HashCalculatorForm.cs | 39 +++- 30 files changed, 1211 insertions(+), 188 deletions(-) create mode 100644 File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/RenderableSinglePointDrawable.cs create mode 100644 File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs create mode 100644 File_Format_Library/GUI/ViewportEditor.Designer.cs create mode 100644 File_Format_Library/GUI/ViewportEditor.cs create mode 100644 File_Format_Library/GUI/ViewportEditor.resx create mode 100644 File_Format_Library/Resources/Hashes/Pkmn.txt create mode 100644 Switch_Toolbox_Library/HashCalculate/FNV64A1.cs create mode 100644 Switch_Toolbox_Library/Interfaces/IAnimationContainer.cs create mode 100644 Switch_Toolbox_Library/OpenGL/Viewport2D.resx diff --git a/.gitignore b/.gitignore index 9d13503b..d16b8e12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .vs/ bin/ obj/ +*Google.FlatBuffers *NodeEditorWinforms-master *GL_EditorFramework-master *SuperBMD-master diff --git a/File_Format_Library/FileFormats/Archives/GFPAK.cs b/File_Format_Library/FileFormats/Archives/GFPAK.cs index 931fe3ba..2404d733 100644 --- a/File_Format_Library/FileFormats/Archives/GFPAK.cs +++ b/File_Format_Library/FileFormats/Archives/GFPAK.cs @@ -176,11 +176,16 @@ namespace FirstPlugin ulong FolderArrayOffset = reader.ReadUInt64(); reader.Seek((long)FolderArrayOffset, SeekOrigin.Begin); + + List FolderFiles = new List(); for (int i = 0; i < FolderCount; i++) { Folder folder = new Folder(); folder.Read(reader); folders.Add(folder); + + foreach (var hash in folder.hashes) + FolderFiles.Add(hash); } reader.Seek((long)hashArrayPathsOffset, SeekOrigin.Begin); @@ -195,47 +200,121 @@ namespace FirstPlugin { FileEntry fileEntry = new FileEntry(this); fileEntry.Read(reader); + fileEntry.FolderHash = FolderFiles[i]; fileEntry.FileName = GetString(hashes[i], fileEntry.FileData); + string suffix = hashes[i].ToString("X").GetLast(6); + ulong suffix64 = Convert.ToUInt64(suffix, 16); + + if (HashList.ContainsKey(suffix64)) + { + fileEntry.FileName = HashList[suffix64]; + } + + string baseName = Path.GetFileName(fileEntry.FileName.Replace("\r", "")); + switch (Utils.GetExtension(fileEntry.FileName)) { case ".gfbanm": - fileEntry.FileName = $"Animations/{fileEntry.FileName}"; + fileEntry.FileName = $"Animations/{baseName}"; break; case ".gfbanmcfg": - fileEntry.FileName = $"AnimationConfigs/{fileEntry.FileName}"; + fileEntry.FileName = $"AnimationConfigs/{baseName}"; break; case ".gfbmdl": - fileEntry.FileName = $"Models/{fileEntry.FileName}"; + fileEntry.FileName = $"Models/{baseName}"; break; case ".gfbpokecfg": - fileEntry.FileName = $"PokeConfigs/{fileEntry.FileName}"; + fileEntry.FileName = $"PokeConfigs/{baseName}"; break; case ".bntx": - fileEntry.FileName = $"Textures/{fileEntry.FileName}"; + fileEntry.FileName = $"Textures/{baseName}"; break; case ".bnsh": - fileEntry.FileName = $"Shaders/{fileEntry.FileName}"; + fileEntry.FileName = $"Shaders/{baseName}"; break; case ".ptcl": - fileEntry.FileName = $"Effects/{fileEntry.FileName}"; + fileEntry.FileName = $"Effects/{baseName}"; break; default: - fileEntry.FileName = $"OtherFiles/{fileEntry.FileName}"; + fileEntry.FileName = $"OtherFiles/{baseName}"; break; } + + + // Console.WriteLine($"{fileEntry.FileName} {fileEntry.FolderHash.hash.ToString("X")} {suffix64.ToString("X")}"); + files.Add(fileEntry); } } + private Dictionary hashList; + public Dictionary HashList + { + get + { + if (hashList == null) { + hashList = new Dictionary(); + GenerateHashList(); + } + return hashList; + } + } + + private void GenerateHashList() + { + foreach (string hashStr in Properties.Resources.Pkmn.Split('\n')) + { + string HashString = hashStr.TrimEnd(); + + ulong hash = FNV64A1.CalculateSuffix(HashString); + if (!hashList.ContainsKey(hash)) + hashList.Add(hash, HashString); + + if (HashString.Contains("pm0000")) + GeneratePokeStrings(HashString); + + string[] hashPaths = HashString.Split('/'); + for (int i = 0; i < hashPaths?.Length; i++) + { + hash = FNV64A1.CalculateSuffix(hashPaths[i]); + if (!hashList.ContainsKey(hash)) + hashList.Add(hash, HashString); + } + } + } + + private void GeneratePokeStrings(string hashStr) + { + //Also check file name just in case + if (FileName.Contains("pm")) + { + string baseName = Path.GetFileNameWithoutExtension(FileName); + string pokeStrFile = hashStr.Replace("pm0000_00", baseName); + + ulong hash = FNV64A1.CalculateSuffix(pokeStrFile); + if (!hashList.ContainsKey(hash)) + hashList.Add(hash, pokeStrFile); + } + + for (int i = 0; i < 1000; i++) + { + string pokeStr = hashStr.Replace("pm0000", $"pm{i.ToString("D4")}"); + + ulong hash = FNV64A1.CalculateSuffix(pokeStr); + if (!hashList.ContainsKey(hash)) + hashList.Add(hash, pokeStr); + } + } + private string GetString(ulong Hash, byte[] Data) { string ext = FindMatch(Data); if (ext == ".bntx" || ext == ".bfres" || ext == ".bnsh" || ext == ".bfsha") return GetBinaryHeaderName(Data) + ext; else - return $"{Hash}{ext}"; + return $"{Hash.ToString("X")}{ext}"; } public void Write(FileWriter writer) @@ -304,7 +383,7 @@ namespace FirstPlugin for (int f = 0; f < FileCount; f++) { HashIndex hash = new HashIndex(); - hash.Read(reader); + hash.Read(reader, this); hashes.Add(hash); } } @@ -325,8 +404,11 @@ namespace FirstPlugin public int Index; public uint unknown; - public void Read(FileReader reader) + public Folder Parent { get; set; } + + public void Read(FileReader reader, Folder parent) { + Parent = parent; hash = reader.ReadUInt64(); Index = reader.ReadInt32(); unknown = reader.ReadUInt32(); //Always 0xCC? @@ -340,6 +422,8 @@ namespace FirstPlugin } public class FileEntry : ArchiveFileInfo { + public HashIndex FolderHash; + public uint unkown; public uint CompressionType; private long DataOffset; diff --git a/File_Format_Library/GUI/Byaml/MuuntEditor/Interfaces/I2DDrawableContainer.cs b/File_Format_Library/GUI/Byaml/MuuntEditor/Interfaces/I2DDrawableContainer.cs index 54950afb..1685ef6f 100644 --- a/File_Format_Library/GUI/Byaml/MuuntEditor/Interfaces/I2DDrawableContainer.cs +++ b/File_Format_Library/GUI/Byaml/MuuntEditor/Interfaces/I2DDrawableContainer.cs @@ -8,6 +8,6 @@ namespace FirstPlugin.MuuntEditor { public interface I2DDrawableContainer { - IDrawableObject Drawable { get; } + List Drawables { get; } } } diff --git a/File_Format_Library/GUI/Byaml/MuuntEditor/MuuntEditor2D.cs b/File_Format_Library/GUI/Byaml/MuuntEditor/MuuntEditor2D.cs index 257cb6f8..924ba842 100644 --- a/File_Format_Library/GUI/Byaml/MuuntEditor/MuuntEditor2D.cs +++ b/File_Format_Library/GUI/Byaml/MuuntEditor/MuuntEditor2D.cs @@ -34,7 +34,10 @@ namespace FirstPlugin.MuuntEditor private void RenderGroupChildren(PropertyObject propertyObject) { if (propertyObject is I2DDrawableContainer) - ((I2DDrawableContainer)propertyObject).Drawable?.Draw(Camera.ModelViewMatrix); + { + foreach (var drawable in ((I2DDrawableContainer)propertyObject).Drawables) + drawable.Draw(Camera.ModelViewMatrix); + } foreach (var subProperty in propertyObject.SubObjects) RenderGroupChildren(subProperty); diff --git a/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDoublePointDrawableContainer.cs b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDoublePointDrawableContainer.cs index 46519eae..6327ff53 100644 --- a/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDoublePointDrawableContainer.cs +++ b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDoublePointDrawableContainer.cs @@ -28,15 +28,17 @@ namespace FirstPlugin.MuuntEditor } } - private IDrawableObject drawable; - public IDrawableObject Drawable + private List drawables; + public List Drawables { get { - if (drawable == null) - drawable = new RenderableDoublePointPath(PathGroups, PathColor); - - return drawable; + if (drawables == null) + { + drawables = new List(); + drawables.Add(new RenderableDoublePointPath(PathGroups, PathColor)); + } + return drawables; } } } diff --git a/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDrawableContainer.cs b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDrawableContainer.cs index 622fae05..180d7a5a 100644 --- a/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDrawableContainer.cs +++ b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/PathDrawableContainer.cs @@ -27,15 +27,17 @@ namespace FirstPlugin.MuuntEditor } } - private IDrawableObject drawable; - public IDrawableObject Drawable + private List drawables; + public List Drawables { get { - if (drawable == null) - drawable = new RenderablePath(PathGroups, PathColor); - - return drawable; + if (drawables == null) + { + drawables = new List(); + drawables.Add(new RenderablePath(PathGroups, PathColor)); + } + return drawables; } } } diff --git a/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/RenderableSinglePointDrawable.cs b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/RenderableSinglePointDrawable.cs new file mode 100644 index 00000000..d6cc3faf --- /dev/null +++ b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/RenderableSinglePointDrawable.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using FirstPlugin.Turbo.CourseMuuntStructs; +using Toolbox.Library; +using Toolbox.Library.IO; + +namespace FirstPlugin.MuuntEditor +{ + /// + /// Represets a single point that draws a 2D circle and optionally a line (for rotation) + /// + public class RenderableSinglePointDrawable : IDrawableObject + { + public bool DrawSelectionRotationLine = true; + + public List PathGroups = new List(); + + public Color LineColor = Color.Green; + + public RenderableSinglePointDrawable(List pathGroups, Color color) + { + PathGroups = pathGroups; + LineColor = color; + } + + public void Draw(Matrix4 mvp) + { + GL.Disable(EnableCap.DepthTest); + + for (int i = 0; i < PathGroups.Count; i++) + { + foreach (var path in PathGroups[i].PathPoints) + { + var translate = new Vector3(path.Translate.X, path.Translate.Z, path.Translate.Y); + + if (path.IsSelected) + { + Render2D.DrawFilledCircle(translate, Color.LightGreen, 30, 40, true); + + } + else if (path.IsHovered) + Render2D.DrawFilledCircle(translate, LineColor.Lighten(40), 40, 40, true); + else + Render2D.DrawFilledCircle(translate, LineColor.Darken(20), 30, 40, true); + + GL.LineWidth(2f); + + GL.Enable(EnableCap.DepthTest); + } + } + } + + private Vector3 RotatePoint(Vector3 translate, float X, float Y, float Z, Vector3 rotate) + { + Matrix4 rotationX = Matrix4.CreateRotationX(rotate.X); + Matrix4 rotationY = Matrix4.CreateRotationY(rotate.Z); + Matrix4 rotationZ = Matrix4.CreateRotationZ(-rotate.Y); + + Matrix4 transMat = Matrix4.CreateTranslation(new Vector3(translate.X, translate.Z, -translate.Y)); + Matrix4 comb = (rotationX * rotationY * rotationZ) * transMat; + Vector3 pos = new Vector3(X, Y, Z); + return Vector3.TransformPosition(pos, comb); + } + } +} diff --git a/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/TrackMuuntLoader.cs b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/TrackMuuntLoader.cs index e939b6f6..9fb4f0ba 100644 --- a/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/TrackMuuntLoader.cs +++ b/File_Format_Library/GUI/Byaml/MuuntEditor/Plugins/MK8/TrackMuuntLoader.cs @@ -30,14 +30,14 @@ namespace FirstPlugin.MuuntEditor var pathGroup = new ObjectGroup("Scene Objects"); Groups.Add(pathGroup); - PathDoublePointDrawableContainer lapPaths = new PathDoublePointDrawableContainer("Lap Paths", Color.Blue); + PathDoublePointDrawableContainer lapPaths = new PathDoublePointDrawableContainer("Lap Paths", Color.Cyan); PathDrawableContainer enemyPaths = new PathDrawableContainer("Enemy Paths", Color.Red); PathDrawableContainer glidePaths = new PathDrawableContainer("Glide Paths", Color.Orange); PathDrawableContainer itemPaths = new PathDrawableContainer("Item Paths", Color.Green); - PathDrawableContainer steerAssitPaths = new PathDrawableContainer("Steer Assist Paths", Color.Cyan); + PathDrawableContainer steerAssitPaths = new PathDrawableContainer("Steer Assist Paths", Color.Crimson); PathDrawableContainer gravityPaths = new PathDrawableContainer("Gravity Paths", Color.Purple); PathDrawableContainer pullPaths = new PathDrawableContainer("Pull Paths", Color.DarkSlateGray); - PathDrawableContainer paths = new PathDrawableContainer("Paths", Color.Black); + PathDrawableContainer paths = new PathDrawableContainer("Paths", Color.GreenYellow); PathDrawableContainer objPaths = new PathDrawableContainer("Object Paths", Color.Brown); PathDrawableContainer jugemPaths = new PathDrawableContainer("Latiku Paths", Color.Pink); PathDrawableContainer introCameras = new PathDrawableContainer("Intro Camera", Color.Yellow); diff --git a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Base/BasePathPoint.cs b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Base/BasePathPoint.cs index 79dcbf56..9b193651 100644 --- a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Base/BasePathPoint.cs +++ b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Base/BasePathPoint.cs @@ -40,7 +40,7 @@ namespace FirstPlugin.Turbo.CourseMuuntStructs public bool IsSelected { get; set; } public bool IsHovered { get; set; } - public bool IsHit(float X, float Y) + public virtual bool IsHit(float X, float Y) { return new STRectangle(Translate.X, Translate.Z, 40, 40).IsHit((int)X, (int)Y); @@ -76,6 +76,16 @@ namespace FirstPlugin.Turbo.CourseMuuntStructs Translate = new Vector3(Translate.X - X, Translate.Y - Z, Translate.Z - Y); } + public void PickRotate(float X, float Y, float Z) + { + Rotate = new Vector3(Rotate.X - X, Rotate.Y - Z, Rotate.Z - Y); + } + + public void PickScale(float X, float Y, float Z) + { + Scale = new Vector3(Scale.X - X, Scale.Y - Z, Scale.Z - Y); + } + public const string N_Translate = "Translate"; public const string N_Rotate = "Rotate"; public const string N_Scale = "Scale"; diff --git a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs new file mode 100644 index 00000000..77015a64 --- /dev/null +++ b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK; + +namespace FirstPlugin.Turbo.CourseMuuntStructs +{ + public class Matrix2DHelper + { + public static Vector3 RotatePoint(Vector3 translate, float X, float Y, float Z, Vector3 rotate) + { + Matrix4 rotationX = Matrix4.CreateRotationX(rotate.X); + Matrix4 rotationY = Matrix4.CreateRotationY(rotate.Z); + Matrix4 rotationZ = Matrix4.CreateRotationZ(-rotate.Y); + + Matrix4 transMat = Matrix4.CreateTranslation(new Vector3(translate.X, translate.Z, -translate.Y)); + Matrix4 comb = (rotationX * rotationY * rotationZ) * transMat; + Vector3 pos = new Vector3(X, Y, Z); + return Vector3.TransformPosition(pos, comb); + } + } +} diff --git a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Paths/LapPaths.cs b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Paths/LapPaths.cs index b4affd27..f6d11878 100644 --- a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Paths/LapPaths.cs +++ b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Paths/LapPaths.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using GL_EditorFramework.EditorDrawables; using OpenTK; +using Toolbox.Library; namespace FirstPlugin.Turbo.CourseMuuntStructs { @@ -74,6 +75,30 @@ namespace FirstPlugin.Turbo.CourseMuuntStructs { private RenderablePathPoint renderablePoint; + public override bool IsHit(float X, float Y) + { + //Here we need to detect 2 points and see if the space between is selected + var point1 = Matrix2DHelper.RotatePoint(Translate, Scale.X / 2, 44, Scale.Y / 2, Rotate); + var point2 = Matrix2DHelper.RotatePoint(Translate, -(Scale.X / 2), -44, -(Scale.Y / 2), Rotate); + + + float LeftPoint = point2.X; + float RightPoint = point1.X; + float BottomPoint = point2.Y; + float TopPoint = point1.Y; + + bool isInBetweenX = (X > LeftPoint) && (X < RightPoint) || + (X < LeftPoint) && (X > RightPoint); + + bool isInBetweenY = (Y > BottomPoint) && (Y < TopPoint) || + (Y < BottomPoint) && (Y > TopPoint); + + if (isInBetweenX && isInBetweenY) + return true; + else + return false; + } + [Browsable(false)] public override RenderablePathPoint RenderablePoint { diff --git a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/RenderableDoublePointPath.cs b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/RenderableDoublePointPath.cs index f133e867..d3b73b89 100644 --- a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/RenderableDoublePointPath.cs +++ b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/RenderableDoublePointPath.cs @@ -34,139 +34,72 @@ namespace FirstPlugin.MuuntEditor { foreach (var path in PathGroups[i].PathPoints) { - var translate = new Vector3(path.Translate.X, path.Translate.Z, path.Translate.Y); - //Draw a line repesenting the size of the path area - var point1 = RotatePoint(translate, path.Scale.X / 2, path.Scale.Z / 2, path.Scale.Y / 2, path.Rotate); - var point2 = RotatePoint(translate, -(path.Scale.X / 2), -(path.Scale.Z / 2), -(path.Scale.Y / 2), path.Rotate); -// - GL.PushMatrix(); - GL.Translate(translate); - GL.Rotate(MathHelper.RadiansToDegrees(path.Rotate.X), 1, 0, 0); - GL.Rotate(MathHelper.RadiansToDegrees(path.Rotate.Z), 0, 1, 0); - GL.Rotate(MathHelper.RadiansToDegrees(path.Rotate.Y), 0, 0, 1); + var point1 = Matrix2DHelper.RotatePoint(path.Translate, path.Scale.X / 2, path.Scale.Z / 2, path.Scale.Y / 2, path.Rotate); + var point2 = Matrix2DHelper.RotatePoint(path.Translate, -(path.Scale.X / 2), -(path.Scale.Z / 2), -(path.Scale.Y / 2), path.Rotate); + + Color pathColor = LineColor; + if (path.IsSelected) + pathColor = Color.LightGreen; + else if (path.IsHovered) + pathColor = LineColor.Lighten(70); - GL.Color3(LineColor); + GL.LineWidth(3f); + GL.Color3(pathColor); GL.Begin(PrimitiveType.Lines); GL.Vertex3(point1); GL.Vertex3(point2); GL.End(); - GL.PopMatrix(); //Draw 2 points repesenting the edges of the path + GL.LineWidth(2f); - /* if (path.IsSelected) - Render2D.DrawFilledCircle(translate, Color.LightGreen, 5, 40, true); - else if (path.IsHovered) - Render2D.DrawFilledCircle(translate, LineColor.Lighten(40), 6, 40, true); - else - Render2D.DrawFilledCircle(translate, LineColor.Darken(20), 5, 40, true); - */ - /* GL.LineWidth(2f); - foreach (var nextPt in path.NextPoints) - { - var nextTranslate = PathGroups[nextPt.PathID].PathPoints[nextPt.PtID].Translate; + foreach (var nextPt in path.NextPoints) + { + var nextPoint = PathGroups[nextPt.PathID].PathPoints[nextPt.PtID]; - GL.Color3(LineColor); - GL.Begin(PrimitiveType.Lines); - GL.Vertex3(translate); - GL.Vertex3(nextTranslate.X, nextTranslate.Z, nextTranslate.Y); - GL.End(); - } - foreach (var prevPt in path.PrevPoints) - { - var prevTranslate = PathGroups[prevPt.PathID].PathPoints[prevPt.PtID].Translate; + var nextPoint1 = Matrix2DHelper.RotatePoint(nextPoint.Translate, (nextPoint.Scale.X / 2), nextPoint.Scale.Z / 2, -nextPoint.Scale.Y / 2, nextPoint.Rotate); + var nextPoint2 = Matrix2DHelper.RotatePoint(nextPoint.Translate, -(nextPoint.Scale.X / 2), -(nextPoint.Scale.Z / 2), (nextPoint.Scale.Y / 2), nextPoint.Rotate); - GL.Color3(LineColor); - GL.Begin(PrimitiveType.Lines); - GL.Vertex3(translate); - GL.Vertex3(prevTranslate.X, prevTranslate.Z, prevTranslate.Y); - GL.End(); - }*/ + /* GL.Color3(Color.Green); + GL.Begin(PrimitiveType.Lines); + GL.Vertex3(point1); + GL.Vertex3(nextPoint1); + GL.End(); + + GL.Color3(Color.Green); + GL.Begin(PrimitiveType.Lines); + GL.Vertex3(point2); + GL.Vertex3(nextPoint2); + GL.End();*/ + } + + foreach (var prevPt in path.PrevPoints) + { + var prevPoint = PathGroups[prevPt.PathID].PathPoints[prevPt.PtID]; + + var prevPoint1 = Matrix2DHelper.RotatePoint(prevPoint.Translate, (prevPoint.Scale.X / 2), prevPoint.Scale.Z / 2, prevPoint.Scale.Y / 2, prevPoint.Rotate); + var prevPoint2 = Matrix2DHelper.RotatePoint(prevPoint.Translate, -(prevPoint.Scale.X / 2), -(prevPoint.Scale.Z / 2), -(prevPoint.Scale.Y / 2), prevPoint.Rotate); + + GL.Color3(Color.Green); + GL.Begin(PrimitiveType.Lines); + GL.Vertex3(point1); + GL.Vertex3(prevPoint1); + GL.End(); + + GL.Color3(Color.Green); + GL.Begin(PrimitiveType.Lines); + GL.Vertex3(point2); + GL.Vertex3(prevPoint2); + GL.End(); + } + + GL.LineWidth(1f); } } GL.Enable(EnableCap.DepthTest); } - - private void DrawPathPoint(Vector3 center, Vector3 scale, Vector3 rotate, Color color, bool useWireFrame = false) - { - GL.Color3(color); - - float sizeX = scale.X; - float sizeY = scale.Y; - float sizeZ = scale.Z; - - - PrimitiveType primitiveType = PrimitiveType.Quads; - if (useWireFrame) - { - GL.LineWidth(2); - primitiveType = PrimitiveType.LineLoop; - } - - GL.Begin(primitiveType); - GL.Normal3(0.0f, 1.0f, 0.0f); - GL.Vertex3(center.X + sizeX, center.Y + sizeY, center.Z - sizeZ); - GL.Vertex3(center.X - sizeX, center.Y + sizeY, center.Z - sizeZ); - GL.Vertex3(center.X - sizeX, center.Y + sizeY, center.Z + sizeZ); - GL.Vertex3(center.X + sizeX, center.Y + sizeY, center.Z + sizeZ); - GL.End(); - - GL.Begin(primitiveType); - GL.Normal3(0.0f, 0.0f, 1.0f); - GL.Vertex3(center.X + sizeX, center.Y - sizeY, center.Z + sizeZ); - GL.Vertex3(center.X - sizeX, center.Y - sizeY, center.Z + sizeZ); - GL.Vertex3(center.X - sizeX, center.Y - sizeY, center.Z - sizeZ); - GL.Vertex3(center.X + sizeX, center.Y - sizeY, center.Z - sizeZ); - GL.End(); - - GL.Begin(primitiveType); - GL.Normal3(1.0f, 0.0f, 0.0f); - GL.Vertex3(center.X + sizeX, center.Y + sizeY, center.Z + sizeZ); - GL.Vertex3(center.X - sizeX, center.Y + sizeY, center.Z + sizeZ); - GL.Vertex3(center.X - sizeX, center.Y - sizeY, center.Z + sizeZ); - GL.Vertex3(center.X + sizeX, center.Y - sizeY, center.Z + sizeZ); - GL.End(); - - GL.Begin(primitiveType); - GL.Normal3(-1.0f, 0.0f, 0.0f); - GL.Vertex3(center.X + sizeX, center.Y - sizeY, center.Z - sizeZ); - GL.Vertex3(center.X - sizeX, center.Y - sizeY, center.Z - sizeZ); - GL.Vertex3(center.X - sizeX, center.Y + sizeY, center.Z - sizeZ); - GL.Vertex3(center.X + sizeX, center.Y + sizeY, center.Z - sizeZ); - GL.End(); - - GL.Begin(primitiveType); - GL.Normal3(0.0f, -1.0f, 0.0f); - GL.Vertex3(center.X - sizeX, center.Y + sizeY, center.Z + sizeZ); - GL.Vertex3(center.X - sizeX, center.Y + sizeY, center.Z - sizeZ); - GL.Vertex3(center.X - sizeX, center.Y - sizeY, center.Z - sizeZ); - GL.Vertex3(center.X - sizeX, center.Y - sizeY, center.Z + sizeZ); - GL.End(); - - GL.Begin(primitiveType); - GL.Normal3(0.0f, 0.0f, -1.0f); - GL.Vertex3(center.X + sizeX, center.Y + sizeY, center.Z - sizeZ); - GL.Vertex3(center.X + sizeX, center.Y + sizeY, center.Z + sizeZ); - GL.Vertex3(center.X + sizeX, center.Y - sizeY, center.Z + sizeZ); - GL.Vertex3(center.X + sizeX, center.Y - sizeY, center.Z - sizeZ); - GL.End(); - } - - private Vector3 RotatePoint(Vector3 translate, float X, float Y, float Z, Vector3 rotate) - { - return new Vector3(X, Y, Z); - - Matrix4 rotationZ = Matrix4.CreateRotationZ(rotate.Y); - Matrix4 rotationY = Matrix4.CreateRotationY(rotate.Z); - Matrix4 rotationX = Matrix4.CreateRotationX(rotate.X); - - Matrix4 transMat = Matrix4.CreateTranslation(translate); - Matrix4 comb = (rotationX * rotationY * rotationZ) * transMat; - Vector3 pos = new Vector3(X, Y, Z); - return Vector3.TransformPosition(pos, comb); - } } } diff --git a/File_Format_Library/GUI/Editors/MK8TrackEditor/MapCameraViewer.cs b/File_Format_Library/GUI/Editors/MK8TrackEditor/MapCameraViewer.cs index 4adb0a5e..91cabe8a 100644 --- a/File_Format_Library/GUI/Editors/MK8TrackEditor/MapCameraViewer.cs +++ b/File_Format_Library/GUI/Editors/MK8TrackEditor/MapCameraViewer.cs @@ -60,6 +60,9 @@ namespace FirstPlugin.Turbo Translate -= new Vector3(X,Z,Y); } + public void PickRotate(float X, float Y, float Z) { } + public void PickScale(float X, float Y, float Z) { } + Course_MapCamera_bin.CameraData cameraData; public CameraPoint(Course_MapCamera_bin.CameraData data, bool isTarget) diff --git a/File_Format_Library/GUI/ViewportEditor.Designer.cs b/File_Format_Library/GUI/ViewportEditor.Designer.cs new file mode 100644 index 00000000..7fcfadb3 --- /dev/null +++ b/File_Format_Library/GUI/ViewportEditor.Designer.cs @@ -0,0 +1,159 @@ +namespace FirstPlugin.Forms +{ + partial class ViewportEditor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.stPanel2 = new Toolbox.Library.Forms.STPanel(); + this.stToolStrip1 = new Toolbox.Library.Forms.STToolStrip(); + this.toggleViewportToolStripBtn = new System.Windows.Forms.ToolStripButton(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.stPanel3 = new Toolbox.Library.Forms.STPanel(); + this.splitter1 = new System.Windows.Forms.Splitter(); + this.timelineTabPage = new Toolbox.Library.Forms.STPanel(); + this.splitter2 = new System.Windows.Forms.Splitter(); + this.stPanel2.SuspendLayout(); + this.stToolStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.stPanel3.SuspendLayout(); + this.SuspendLayout(); + // + // stPanel2 + // + this.stPanel2.Controls.Add(this.stToolStrip1); + this.stPanel2.Controls.Add(this.splitContainer1); + this.stPanel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.stPanel2.Location = new System.Drawing.Point(0, 0); + this.stPanel2.Name = "stPanel2"; + this.stPanel2.Size = new System.Drawing.Size(712, 543); + this.stPanel2.TabIndex = 4; + // + // stToolStrip1 + // + this.stToolStrip1.HighlightSelectedTab = false; + this.stToolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toggleViewportToolStripBtn}); + this.stToolStrip1.Location = new System.Drawing.Point(0, 0); + this.stToolStrip1.Name = "stToolStrip1"; + this.stToolStrip1.Size = new System.Drawing.Size(712, 25); + this.stToolStrip1.TabIndex = 2; + this.stToolStrip1.Text = "stToolStrip1"; + // + // toggleViewportToolStripBtn + // + this.toggleViewportToolStripBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toggleViewportToolStripBtn.Image = global::FirstPlugin.Properties.Resources.ViewportIcon; + this.toggleViewportToolStripBtn.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toggleViewportToolStripBtn.Name = "toggleViewportToolStripBtn"; + this.toggleViewportToolStripBtn.Size = new System.Drawing.Size(23, 22); + this.toggleViewportToolStripBtn.Text = "toolStripButton1"; + this.toggleViewportToolStripBtn.Click += new System.EventHandler(this.toggleViewportToolStripBtn_Click); + // + // splitContainer1 + // + this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.splitContainer1.Location = new System.Drawing.Point(0, 28); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.splitter2); + this.splitContainer1.Panel1.Controls.Add(this.timelineTabPage); + this.splitContainer1.Panel1.Controls.Add(this.stPanel3); + this.splitContainer1.Size = new System.Drawing.Size(712, 515); + this.splitContainer1.SplitterDistance = 440; + this.splitContainer1.TabIndex = 1; + // + // stPanel3 + // + this.stPanel3.Controls.Add(this.splitter1); + this.stPanel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.stPanel3.Location = new System.Drawing.Point(0, 0); + this.stPanel3.Name = "stPanel3"; + this.stPanel3.Size = new System.Drawing.Size(440, 515); + this.stPanel3.TabIndex = 4; + // + // splitter1 + // + this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.splitter1.Location = new System.Drawing.Point(0, 512); + this.splitter1.Name = "splitter1"; + this.splitter1.Size = new System.Drawing.Size(440, 3); + this.splitter1.TabIndex = 4; + this.splitter1.TabStop = false; + // + // timelineTabPage + // + this.timelineTabPage.Dock = System.Windows.Forms.DockStyle.Bottom; + this.timelineTabPage.Location = new System.Drawing.Point(0, 380); + this.timelineTabPage.Name = "timelineTabPage"; + this.timelineTabPage.Size = new System.Drawing.Size(440, 135); + this.timelineTabPage.TabIndex = 5; + // + // splitter2 + // + this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom; + this.splitter2.Location = new System.Drawing.Point(0, 377); + this.splitter2.Name = "splitter2"; + this.splitter2.Size = new System.Drawing.Size(440, 3); + this.splitter2.TabIndex = 6; + this.splitter2.TabStop = false; + // + // ViewportEditor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.stPanel2); + this.Name = "ViewportEditor"; + this.Size = new System.Drawing.Size(712, 543); + this.stPanel2.ResumeLayout(false); + this.stPanel2.PerformLayout(); + this.stToolStrip1.ResumeLayout(false); + this.stToolStrip1.PerformLayout(); + this.splitContainer1.Panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.stPanel3.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.SplitContainer splitContainer1; + private Toolbox.Library.Forms.STPanel stPanel2; + private Toolbox.Library.Forms.STPanel stPanel3; + private System.Windows.Forms.Splitter splitter1; + private Toolbox.Library.Forms.STToolStrip stToolStrip1; + private System.Windows.Forms.ToolStripButton toggleViewportToolStripBtn; + private System.Windows.Forms.Splitter splitter2; + private Toolbox.Library.Forms.STPanel timelineTabPage; + } +} diff --git a/File_Format_Library/GUI/ViewportEditor.cs b/File_Format_Library/GUI/ViewportEditor.cs new file mode 100644 index 00000000..1f138966 --- /dev/null +++ b/File_Format_Library/GUI/ViewportEditor.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Toolbox.Library.Forms; +using Toolbox.Library; +using GL_EditorFramework.Interfaces; +using GL_EditorFramework.EditorDrawables; + +namespace FirstPlugin.Forms +{ + public partial class ViewportEditor : STUserControl, IViewportContainer + { + private bool _displayViewport = true; + + public bool DisplayViewport + { + get + { + return _displayViewport; + } + set + { + _displayViewport = value; + SetupViewport(); + } + } + + private void SetupViewport() + { + if (DisplayViewport == true && Runtime.UseOpenGL) + { + stPanel3.Controls.Add(viewport); + splitContainer1.Panel1Collapsed = false; + toggleViewportToolStripBtn.Image = Properties.Resources.ViewportIcon; + + if (viewport != null) + OnLoadedTab(); + else + { + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); + viewport.Dock = DockStyle.Fill; + OnLoadedTab(); + } + } + else + { + stPanel3.Controls.Clear(); + splitContainer1.Panel1Collapsed = true; + toggleViewportToolStripBtn.Image = Properties.Resources.ViewportIconDisable; + } + } + + Viewport viewport + { + get + { + if (!Runtime.UseOpenGL || !DisplayViewport) + return null; + + var editor = LibraryGUI.GetObjectEditor(); + return editor.GetViewport(); + } + set + { + var editor = LibraryGUI.GetObjectEditor(); + editor.LoadViewport(value); + } + } + + AnimationPanel animationPanel; + + public ViewportEditor(bool HasModels) + { + InitializeComponent(); + + animationPanel = new AnimationPanel(); + animationPanel.CurrentAnimation = null; + animationPanel.Dock = DockStyle.Fill; + timelineTabPage.Controls.Add(animationPanel); + + //Always create an instance of the viewport unless opengl is disabled + if (viewport == null && Runtime.UseOpenGL) + { + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); + viewport.Dock = DockStyle.Fill; + } + + //If the option is enabled by settings, and it has models display the viewport + if (Runtime.UseOpenGL && Runtime.DisplayViewport && HasModels) + { + stPanel3.Controls.Add(viewport); + DisplayViewport = true; + } + else + { + DisplayViewport = false; + splitContainer1.Panel1Collapsed = true; + } + } + + public UserControl GetActiveEditor(Type type) + { + foreach (var ctrl in splitContainer1.Panel2.Controls) + { + if (type == null) + { + return (UserControl)ctrl; + } + + if (ctrl.GetType() == type) + { + return (UserControl)ctrl; + } + } + return null; + } + + public void LoadEditor(UserControl Control) + { + Control.Dock = DockStyle.Fill; + + splitContainer1.Panel2.Controls.Clear(); + splitContainer1.Panel2.Controls.Add(Control); + } + + public AnimationPanel GetAnimationPanel() => animationPanel; + + public Viewport GetViewport() => viewport; + + public void UpdateViewport() + { + if (viewport != null && Runtime.UseOpenGL && Runtime.DisplayViewport) + viewport.UpdateViewport(); + } + + + public bool IsLoaded = false; + + public void LoadViewport(DrawableContainer ActiveDrawable, List customContextMenus = null) + { + if (!Runtime.UseOpenGL || !DisplayViewport) + return; + + if (customContextMenus != null) + { + foreach (var menu in customContextMenus) + viewport.LoadCustomMenuItem(menu); + } + + viewport.ReloadDrawables(ActiveDrawable); + + OnLoadedTab(); + } + + public override void OnControlClosing() + { + } + + private void OnLoadedTab() + { + //If a model was loaded we don't need to load the drawables again + if (IsLoaded ||!Runtime.UseOpenGL || !Runtime.DisplayViewport) + return; + + viewport.LoadObjects(); + + IsLoaded = true; + } + + private void stTabControl1_TabIndexChanged(object sender, EventArgs e) + { + + } + + private void stTabControl1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + bool IsTimelineVisable = true; + int controlHeight = 0; + private void stPanel1_DoubleClick(object sender, EventArgs e) + { + + } + + private void toggleViewportToolStripBtn_Click(object sender, EventArgs e) + { + if (Runtime.DisplayViewport) + { + Runtime.DisplayViewport = false; + } + else + { + Runtime.DisplayViewport = true; + } + + DisplayViewport = Runtime.DisplayViewport; + Config.Save(); + } + } +} diff --git a/File_Format_Library/GUI/ViewportEditor.resx b/File_Format_Library/GUI/ViewportEditor.resx new file mode 100644 index 00000000..7930f31b --- /dev/null +++ b/File_Format_Library/GUI/ViewportEditor.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/File_Format_Library/Properties/Resources.Designer.cs b/File_Format_Library/Properties/Resources.Designer.cs index d9675ff2..41ee3d27 100644 --- a/File_Format_Library/Properties/Resources.Designer.cs +++ b/File_Format_Library/Properties/Resources.Designer.cs @@ -201,31 +201,64 @@ namespace FirstPlugin.Properties { } /// - /// Looks up a localized string similar to D:\Project\NeoPlum\Out\Dist\NXROM\NeoPlumNX64_dist.nss - ///nnSdk.nss - ///c:/NXSDK/V7_3_2/NintendoSDK/Libraries/NX-NXFP2-a64/Release/multimedia.nss - ///__nnDetailNintendoSdkRuntimeObjectFile - ///__nnDetailNintendoSdkRuntimeObjectFileRefer - ///__nnmusl_fini_dso - ///__nnmusl_init_dso - ///__rel_dyn_end - ///__rel_dyn_start - ///__rel_plt_end - ///__rel_plt_start - ///nndetailRoGetRoDataEnd - ///nndetailRoGetRoDataStart - ///nnMain - ///nninitStartup - ///_ZdlPv - ///_ZNSt3__112__next_primeEm - ///strtoul - ///strtod - ///vsnprintf - ///vswprintf - ///_ZdaPv - ///_Znwm - ///_Znam - ///__cxa_guard_ac [rest of string was truncated]";. + /// Looks up a localized string similar to 1 + ///boo + ///fan + ///ice + ///ivy + ///lob + ///net + ///nub + ///sky + ///_vicenight/riotguard/thigh1 + ///_vicenight/riotguard/thigh2 + ///_vicenight/riotguard/thigh3 + ///GenGlow + ///fx_divot_flash + ///_craterfield/podsspec + ///IDLE + ///Idle + ///Main + ///_tutorialfield/wall_base + ///Pass + ///_tutorialfield/wall_mask + ///_tutorialfield/wall_spec + ///arg1 + ///arm1 + ///ball + ///blue + ///boot + ///drum + ///dump + ///fins + ///fire + ///flag + ///glow + ///gold + ///hull + ///land + ///leg1 + ///leg2 + ///leg3 + ///lid1 + ///lid2 + ///lid3 + ///mast + ///palm + ///pole + ///pots + ///rock + ///roof + ///rope + ///sand + ///star + ///stop + ///toad + ///tree + ///whip + ///wood + ///proxy object05/claw1 + ///proxy [rest of string was truncated]";. /// internal static string LM3_Hashes { get { @@ -273,6 +306,15 @@ namespace FirstPlugin.Properties { } } + /// + /// Looks up a localized string similar to . + /// + internal static string Pkmn { + get { + return ResourceManager.GetString("Pkmn", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/File_Format_Library/Properties/Resources.resx b/File_Format_Library/Properties/Resources.resx index 041943e9..28fc83e3 100644 --- a/File_Format_Library/Properties/Resources.resx +++ b/File_Format_Library/Properties/Resources.resx @@ -202,4 +202,7 @@ ..\Resources\Hashes\LM3_Hashes.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + ..\Resources\Hashes\Pkmn.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + \ No newline at end of file diff --git a/File_Format_Library/Resources/Hashes/Pkmn.txt b/File_Format_Library/Resources/Hashes/Pkmn.txt new file mode 100644 index 00000000..30078f50 --- /dev/null +++ b/File_Format_Library/Resources/Hashes/Pkmn.txt @@ -0,0 +1,62 @@ +bin/pokemon/pm0000_00/mdl/pm0000_00.gfbmdl +bin/pokemon/pm0000_00/mdl/pm0000_00_rare.gfbmdl +bin/pokemon/pm0000_00/pm0000_00.gfbpokecfg +bin/pokemon/pm0000_00/anm/pm0000_00_field01.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_field.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_battle.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_capture.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_battle01.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_capture01.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_camp.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_app01.gfbanmcfg +bin/pokemon/pm0000_00/anm/pm0000_00_ba01_landA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba01_landB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba01_landC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba02_roar01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba10_waitA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba10_waitB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba10_waitC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba10_waitA02.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba10_waitB02.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba10_waitC02.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba20_buturi01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba20_buturi02.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba21_tokusyu01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba21_tokusyu02.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba30_damageS01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_ba41_down01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_fi20_walk01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_fi21_run01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_fi31_run_wait01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_fi31_wait_run01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_mouth01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_gloop01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_eye01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw10_respond01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw11_turnA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw11_turnB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw11_turnC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw20_drowseA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw20_drowseB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw20_drowseC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw21_sleepA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw21_sleepB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw21_sleepC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw30_hate01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw30_hate02.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw31_question01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw32_happyA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw32_happyB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw32_happyC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw33_moveA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw33_moveB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw33_moveC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw34_lonely01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw35_playA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw35_playB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw35_playC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw36_mad01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw50_eatA01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw50_eatB01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw50_eatC01.gfbanm +bin/pokemon/pm0000_00/anm/pm0000_00_kw60_touch01.gfbanm diff --git a/Switch_Toolbox_Library/Animations/Animation.cs b/Switch_Toolbox_Library/Animations/Animation.cs index 2e2a0f66..8f12884c 100644 --- a/Switch_Toolbox_Library/Animations/Animation.cs +++ b/Switch_Toolbox_Library/Animations/Animation.cs @@ -602,7 +602,6 @@ namespace Toolbox.Library.Animations b.rot = EulerToQuat(z, y, x); } } - } if (AdancedNextFrame) diff --git a/Switch_Toolbox_Library/Forms/Editors/TextEditor/TextEditor.cs b/Switch_Toolbox_Library/Forms/Editors/TextEditor/TextEditor.cs index 1d87ef1f..bb41da48 100644 --- a/Switch_Toolbox_Library/Forms/Editors/TextEditor/TextEditor.cs +++ b/Switch_Toolbox_Library/Forms/Editors/TextEditor/TextEditor.cs @@ -140,6 +140,7 @@ namespace Toolbox.Library.Forms { InitializeComponent(); + Dock = DockStyle.Fill; findReplaceDialog = new FindReplace(); findReplaceDialog.Scintilla = scintilla1; diff --git a/Switch_Toolbox_Library/HashCalculate/FNV64A1.cs b/Switch_Toolbox_Library/HashCalculate/FNV64A1.cs new file mode 100644 index 00000000..76a41f51 --- /dev/null +++ b/Switch_Toolbox_Library/HashCalculate/FNV64A1.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Toolbox.Library +{ + public class FNV64A1 + { + public static ulong Calculate(string text) { + return Calculate(Encoding.Default.GetBytes(text)); + } + + public static ulong CalculateSuffix(string text) { + return CalculateSuffix(Encoding.Default.GetBytes(text)); + } + + public static ulong CalculateSuffix(byte[] bytes) + { + const ulong fnv64Basis = 0x222645; + const ulong fnv64Prime = 0x0001b3; + const ulong mask = 0xffffff; + + ulong hash = fnv64Basis & mask; + for (var i = 0; i < bytes.Length; i++) + { + hash = hash ^ bytes[i]; + hash *= fnv64Prime; + hash = hash & mask; + } + + return hash; + } + + //https://gist.github.com/rasmuskl/3786618 + public static ulong Calculate(byte[] bytes) + { + const ulong fnv64Offset = 14695981039346656037; + const ulong fnv64Prime = 0x100000001b3; + ulong hash = fnv64Offset; + + for (var i = 0; i < bytes.Length; i++) + { + hash = hash ^ bytes[i]; + hash *= fnv64Prime; + } + + return hash; + } + } +} diff --git a/Switch_Toolbox_Library/IO/Extensions/StringExtension.cs b/Switch_Toolbox_Library/IO/Extensions/StringExtension.cs index 1b690238..f189e2bc 100644 --- a/Switch_Toolbox_Library/IO/Extensions/StringExtension.cs +++ b/Switch_Toolbox_Library/IO/Extensions/StringExtension.cs @@ -26,6 +26,13 @@ namespace System return normalizedPath.StartsWith(normalizedBaseDirPath, StringComparison.OrdinalIgnoreCase); } + public static string GetLast(this string source, int tail_length) + { + if (tail_length >= source.Length) + return source; + return source.Substring(source.Length - tail_length); + } + public static string RemoveNumbersAtEnd(this string str) { Regex rgx = new Regex(@"\d+$"); diff --git a/Switch_Toolbox_Library/Interfaces/IAnimationContainer.cs b/Switch_Toolbox_Library/Interfaces/IAnimationContainer.cs new file mode 100644 index 00000000..87dd674d --- /dev/null +++ b/Switch_Toolbox_Library/Interfaces/IAnimationContainer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Toolbox.Library.Animations +{ + public interface IAnimationContainer + { + STAnimation AnimationController { get; } + } +} diff --git a/Switch_Toolbox_Library/OpenGL/IPickableObject.cs b/Switch_Toolbox_Library/OpenGL/IPickableObject.cs index fde81b17..0a2a73a0 100644 --- a/Switch_Toolbox_Library/OpenGL/IPickableObject.cs +++ b/Switch_Toolbox_Library/OpenGL/IPickableObject.cs @@ -12,5 +12,7 @@ namespace Toolbox.Library bool IsSelected { get; set; } bool IsHovered { get; set; } void PickTranslate(float X, float Y, float Z); + void PickRotate(float X, float Y, float Z); + void PickScale(float X, float Y, float Z); } } diff --git a/Switch_Toolbox_Library/OpenGL/Viewport2D.cs b/Switch_Toolbox_Library/OpenGL/Viewport2D.cs index 80990638..fd285007 100644 --- a/Switch_Toolbox_Library/OpenGL/Viewport2D.cs +++ b/Switch_Toolbox_Library/OpenGL/Viewport2D.cs @@ -55,6 +55,8 @@ namespace Toolbox.Library.Forms glControl1.MouseDown += glControl1_MouseDown; glControl1.MouseUp += glControl1_MouseUp; glControl1.MouseMove += glControl1_MouseMove; + glControl1.KeyDown += glControl1_KeyDown; + glControl1.Paint += glControl1_Paint; glControl1.Resize += glControl1_Resize; Controls.Add(glControl1); @@ -354,6 +356,30 @@ namespace Toolbox.Library.Forms } } } + if (pickAction == PickAction.Rotate) + { + foreach (var pickObject in SelectedObjects) + { + if (pickOriginMouse != Point.Empty) + { + float rotX = 0; + float rotY = 0; + float rotZ = 0; + + if (pickAxis == PickAxis.X) + rotX = pickMouse.X * -0.015625f; + if (pickAxis == PickAxis.Y) + rotY = pickMouse.Y; + if (pickAxis == PickAxis.All) + { + rotX = pickMouse.X * -0.015625f; + // rotY = pickMouse.Y; + } + + pickObject.PickRotate(rotX, rotY, rotZ); + } + } + } pickOriginMouse = temp; @@ -370,6 +396,20 @@ namespace Toolbox.Library.Forms DrawSelectionBox(prevPos, curPos); } } + + private void glControl1_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.R) + { + if (isPicked) + pickAction = PickAction.Rotate; + } + if (e.KeyCode == Keys.G) + { + if (isPicked) + pickAction = PickAction.Translate; + } + } private void glControl1_Resize(object sender, EventArgs e) { @@ -396,5 +436,17 @@ namespace Toolbox.Library.Forms glControl1.Invalidate(); } + + private void InitializeComponent() + { + this.SuspendLayout(); + // + // Viewport2D + // + this.Name = "Viewport2D"; + this.Size = new System.Drawing.Size(405, 404); + this.ResumeLayout(false); + + } } } diff --git a/Switch_Toolbox_Library/OpenGL/Viewport2D.resx b/Switch_Toolbox_Library/OpenGL/Viewport2D.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/Switch_Toolbox_Library/OpenGL/Viewport2D.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Switch_Toolbox_Library/Toolbox_Library.csproj b/Switch_Toolbox_Library/Toolbox_Library.csproj index a5b069d8..1f0f0666 100644 --- a/Switch_Toolbox_Library/Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Toolbox_Library.csproj @@ -367,6 +367,7 @@ + @@ -376,6 +377,7 @@ + @@ -1158,6 +1160,9 @@ ListViewCustom.cs + + Viewport2D.cs + PublicResXFileCodeGenerator Designer diff --git a/Toolbox/GUI/HashCalculatorForm.Designer.cs b/Toolbox/GUI/HashCalculatorForm.Designer.cs index 9e478d0a..1a5e906e 100644 --- a/Toolbox/GUI/HashCalculatorForm.Designer.cs +++ b/Toolbox/GUI/HashCalculatorForm.Designer.cs @@ -80,16 +80,16 @@ this.stringTB.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.stringTB.Location = new System.Drawing.Point(88, 74); this.stringTB.Name = "stringTB"; - this.stringTB.Size = new System.Drawing.Size(121, 20); + this.stringTB.Size = new System.Drawing.Size(282, 20); this.stringTB.TabIndex = 11; this.stringTB.TextChanged += new System.EventHandler(this.stTextBox1_TextChanged); // // resultTB // this.resultTB.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.resultTB.Location = new System.Drawing.Point(299, 74); + this.resultTB.Location = new System.Drawing.Point(453, 74); this.resultTB.Name = "resultTB"; - this.resultTB.Size = new System.Drawing.Size(160, 20); + this.resultTB.Size = new System.Drawing.Size(199, 20); this.resultTB.TabIndex = 12; // // hashTypeCB @@ -103,6 +103,7 @@ this.hashTypeCB.Name = "hashTypeCB"; this.hashTypeCB.Size = new System.Drawing.Size(121, 21); this.hashTypeCB.TabIndex = 13; + this.hashTypeCB.SelectedIndexChanged += new System.EventHandler(this.hashTypeCB_SelectedIndexChanged); // // stLabel1 // @@ -125,7 +126,7 @@ // stLabel3 // this.stLabel3.AutoSize = true; - this.stLabel3.Location = new System.Drawing.Point(225, 76); + this.stLabel3.Location = new System.Drawing.Point(379, 76); this.stLabel3.Name = "stLabel3"; this.stLabel3.Size = new System.Drawing.Size(68, 13); this.stLabel3.TabIndex = 16; @@ -134,7 +135,7 @@ // chkUseHex // this.chkUseHex.AutoSize = true; - this.chkUseHex.Location = new System.Drawing.Point(299, 45); + this.chkUseHex.Location = new System.Drawing.Point(453, 45); this.chkUseHex.Name = "chkUseHex"; this.chkUseHex.Size = new System.Drawing.Size(86, 17); this.chkUseHex.TabIndex = 17; diff --git a/Toolbox/GUI/HashCalculatorForm.cs b/Toolbox/GUI/HashCalculatorForm.cs index 3eeac9c6..ea1c9028 100644 --- a/Toolbox/GUI/HashCalculatorForm.cs +++ b/Toolbox/GUI/HashCalculatorForm.cs @@ -21,6 +21,9 @@ namespace Toolbox InitializeComponent(); hashTypeCB.Items.Add("NLG_Hash"); + hashTypeCB.Items.Add("FNV64A1"); + hashTypeCB.Items.Add("CRC32"); + hashTypeCB.SelectedIndex = 0; maxLengthUD.Value = 3; @@ -32,10 +35,7 @@ namespace Toolbox private void UpdateHash() { - uint Hash = 0; - if (hashTypeCB.GetSelectedText() == "NLG_Hash") - Hash = StringToHash(stringTB.Text); - + ulong Hash = CalculateHash(hashTypeCB.GetSelectedText(), stringTB.Text); if (IsHex) resultTB.Text = Hash.ToString("X"); else @@ -46,6 +46,17 @@ namespace Toolbox UpdateHash(); } + public static ulong CalculateHash(string type, string text) + { + if (type == "NLG_Hash") + return StringToHash(text); + else if (type == "FNV64A1") + return FNV64A1.CalculateSuffix(text); + else if (type == "CRC32") + return Toolbox.Library.Security.Cryptography.Crc32.Compute(text); + return 0; + } + public static uint StringToHash(string name, bool caseSensative = false) { //From (Works as tested comparing hashbin strings/hashes @@ -91,14 +102,16 @@ namespace Toolbox progressBar.Show(); progressBar.Task = $"Searching characters"; + string hashType = hashTypeCB.GetSelectedText(); + Thread Thread = new Thread((ThreadStart)(() => { - BruteForceHashes(progressBar); + BruteForceHashes(progressBar, hashType); })); Thread.Start(); } - private void BruteForceHashes(STProgressBar progressBar) + private void BruteForceHashes(STProgressBar progressBar, string hashType) { if (bruteForceHashTB.Text.Length == 0) return; @@ -107,11 +120,11 @@ namespace Toolbox CancelOperation = false; - List hashes = new List(); + List hashes = new List(); foreach (var line in bruteForceHashTB.Lines) { - uint hash = 0; - uint.TryParse(line, out hash); + ulong hash = 0; + ulong.TryParse(line, out hash); if (hash == 0) continue; hashes.Add(hash); @@ -137,7 +150,7 @@ namespace Toolbox { String value = Sb.ToString(); - uint calculatedHash = StringToHash($"{characterStartTB.Text}{value}"); + ulong calculatedHash = CalculateHash(hashType, $"{characterStartTB.Text}{value}"); if (hashes.Contains(calculatedHash)) { UpdateTextbox($"{characterStartTB.Text}{value}"); @@ -157,7 +170,7 @@ namespace Toolbox foreach (var line in characterStartTB.Lines) { - uint calculatedHash2 = StringToHash($"{line}{value}"); + ulong calculatedHash2 = CalculateHash(hashType, $"{line}{value}"); if (hashes.Contains(calculatedHash2)) { UpdateTextbox($"{line}{value}"); @@ -283,5 +296,9 @@ namespace Toolbox { CancelOperation = true; } + + private void hashTypeCB_SelectedIndexChanged(object sender, EventArgs e) { + UpdateHash(); + } } }