From 0b27e890be14b39c02a3d80b5cd87a6d3ebf64e8 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Thu, 6 Feb 2020 21:05:35 -0500 Subject: [PATCH] Improve bin.gz endianness detection --- .../FileFormats/HyruleWarriors/LINKDATA.cs | 5 ++- .../AnimationRewrite/InterpolationHelper.cs | 42 +++++++++++++++++++ .../Compression/STLibraryCompression.cs | 20 +++++---- .../FileFormats/Assimp/Assimp.cs | 12 ------ 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/File_Format_Library/FileFormats/HyruleWarriors/LINKDATA.cs b/File_Format_Library/FileFormats/HyruleWarriors/LINKDATA.cs index 063218de..ee124920 100644 --- a/File_Format_Library/FileFormats/HyruleWarriors/LINKDATA.cs +++ b/File_Format_Library/FileFormats/HyruleWarriors/LINKDATA.cs @@ -64,7 +64,7 @@ namespace FirstPlugin entry.FileName = $"file {i}"; entry.Read(reader); - if (entry.Size != 0 && entry.CompFlags == 0) + if (entry.CompFlags != 0) files.Add(entry); } @@ -82,11 +82,12 @@ namespace FirstPlugin { DataReader.SeekBegin(files[i].Offset); var magicCheck = DataReader.ReadString(4); - Console.WriteLine("MAGIC=" + magicCheck); if (magicCheck == "SARC") files[i].FileName = $"Layout/{files[i].FileName}.szs"; else if (magicCheck == "SPKG") files[i].FileName = $"ShaderPackage/{files[i].FileName}.spkg"; + else if (files[i].CompFlags != 0) + files[i].FileName = $"CompressedFiles/{files[i].FileName}.bin.gz"; else files[i].FileName = $"UnknownTypes/{files[i].FileName}.bin"; } diff --git a/Switch_Toolbox_Library/Animations/AnimationRewrite/InterpolationHelper.cs b/Switch_Toolbox_Library/Animations/AnimationRewrite/InterpolationHelper.cs index 30495923..8c000b8a 100644 --- a/Switch_Toolbox_Library/Animations/AnimationRewrite/InterpolationHelper.cs +++ b/Switch_Toolbox_Library/Animations/AnimationRewrite/InterpolationHelper.cs @@ -22,5 +22,47 @@ namespace Toolbox.Library.Animations return Result; } + + public static float HermiteInterpolate(float frame, float frame1, float frame2, + float inSlope, float outSlope, float p0, float p1) + { + if (frame == frame1) return p0; + if (frame == frame2) return p1; + + float t = (frame - frame1) / (frame2 - frame1); + return GetPointHermite(p0, p1, outSlope, inSlope, t); + } + + private static float GetPointHermite(float p0, float p1, float s0, float s1, float t) { + float cf0 = (p0 * 2) + (p1 * -2) + (s0 * 1) + (s1 * 1); + float cf1 = (p0 * -3) + (p1 * 3) + (s0 * -2) + (s1 * -1); + float cf2 = (p0 * 0) + (p1 * 0) + (s0 * 1) + (s1 * 0); + float cf3 = (p0 * 1) + (p1 * 0) + (s0 * 0) + (s1 * 0); + return GetPointCubic(cf0, cf1, cf2, cf3, t); + } + + private static float GetPointCubic(float cf0, float cf1, float cf2, float cf3, float t) { + return (((cf0 * t + cf1) * t + cf2) * t + cf3); + } + + public static float[] CalculateCubicCoef(float frameA, float frameB, float valueA, float valueB, float inSlope, float outSlope) { + return CalculateCubicCoef(frameB - frameA, valueA, valueB, inSlope, outSlope); + } + + public static float[] GetCubicSlopes(float time, float delta, float[] coef) + { + float outSlope = coef[1] / time; + float param = coef[3] - (-2 * delta); + float inSlope = param / time - outSlope; + return new float[2] { inSlope, outSlope }; + } + + public static float[] CalculateCubicCoef(float time, float valueA, float valueB, float inSlope, float outSlope) + { + float[] values = new float[4]; + //Cubics have 4 coefficents + + return values; + } } } diff --git a/Switch_Toolbox_Library/Compression/STLibraryCompression.cs b/Switch_Toolbox_Library/Compression/STLibraryCompression.cs index 991f7a75..26b94a78 100644 --- a/Switch_Toolbox_Library/Compression/STLibraryCompression.cs +++ b/Switch_Toolbox_Library/Compression/STLibraryCompression.cs @@ -44,9 +44,11 @@ namespace Toolbox.Library.IO using (var reader = new FileReader(stream, true)) { reader.Position = 0; - reader.SetByteOrder(true); - uint chunkSize = reader.ReadUInt32(); - if (chunkSize == 256) + ushort check = reader.ReadUInt16(); + reader.ReadUInt16(); + if (check != 0) + reader.SetByteOrder(true); + else reader.SetByteOrder(false); uint chunkCount = reader.ReadUInt32(); @@ -77,9 +79,11 @@ namespace Toolbox.Library.IO { using (var reader = new FileReader(stream, true)) { - reader.SetByteOrder(true); - uint chunkSize = reader.ReadUInt32(); - if (chunkSize == 256) + ushort check = reader.ReadUInt16(); + reader.ReadUInt16(); + if (check != 0) + reader.SetByteOrder(true); + else reader.SetByteOrder(false); try @@ -92,6 +96,8 @@ namespace Toolbox.Library.IO List DecompressedChunks = new List(); + Console.WriteLine($"pos {reader.Position}"); + //Now search for zlibbed chunks while (!reader.EndOfStream) { @@ -101,7 +107,7 @@ namespace Toolbox.Library.IO ushort magic = reader.ReadUInt16(); ///Check zlib magic - if (magic == 0x78da) + if (magic == 0x78da || magic == 0xda78) { var data = STLibraryCompression.ZLIB.Decompress(reader.getSection((uint)pos, size)); DecompressedChunks.Add(data); diff --git a/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs b/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs index f398f0d3..e27c9dff 100644 --- a/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs +++ b/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs @@ -652,18 +652,6 @@ namespace Toolbox.Library obj.vertices = GetVertices(msh, transform, obj); obj.VertexBufferIndex = Index; - //Correct the vertex colors because assimp is broken. - if (Geomerties.Count > Index) - { - Console.WriteLine($"v count {obj.vertices.Count}"); - Console.WriteLine($"color count {Geomerties[Index].ColorList.Count}"); - - for (int v = 0; v < Geomerties[Index].ColorList.Count; v++) { - if (v < obj.vertices.Count) - obj.vertices[v].col = Geomerties[Index].ColorList[v]; - } - } - return obj; }