From e0014854baf24e9b8f9d589219d9268525719ae3 Mon Sep 17 00:00:00 2001 From: Razmoth <12517189-Razmoth@users.noreply.gitlab.com> Date: Sat, 8 Oct 2022 20:35:11 +0400 Subject: [PATCH] Improvements and bug fixes. --- AssetStudio/GameManager.cs | 1 - AssetStudio/ResourceIndex.cs | 47 ++++++++++--------- AssetStudio/SerializedFile.cs | 16 ++++--- AssetStudio/TypeTreeHelper.cs | 4 +- AssetStudioUtility/AnimationClipExtensions.cs | 4 +- AssetStudioUtility/SpriteHelper.cs | 2 +- 6 files changed, 40 insertions(+), 34 deletions(-) diff --git a/AssetStudio/GameManager.cs b/AssetStudio/GameManager.cs index f653160..6e711a9 100644 --- a/AssetStudio/GameManager.cs +++ b/AssetStudio/GameManager.cs @@ -43,7 +43,6 @@ namespace AssetStudio public static Game[] GetGames() => Games.Values.ToArray(); public static string[] GetGameNames() => Games.Values.Select(x => x.Name).ToArray(); public static string SupportedGames() => $"Supported Games:\n{string.Join("\n", Games.Values.Select(x => $"{x.Name} ({x.DisplayName})"))}"; - public static string ToString() => string.Join("\n", Games.Values); } public abstract class Game diff --git a/AssetStudio/ResourceIndex.cs b/AssetStudio/ResourceIndex.cs index b46479f..f37ac5e 100644 --- a/AssetStudio/ResourceIndex.cs +++ b/AssetStudio/ResourceIndex.cs @@ -31,35 +31,38 @@ namespace AssetStudio } public static void FromFile(string path) { - Logger.Info(string.Format("Parsing....")); - try + if (!string.IsNullOrEmpty(path)) { - Clear(); - - using (var stream = File.OpenRead(path)) + Logger.Info(string.Format("Parsing....")); + try { - var bytes = new byte[stream.Length]; - var count = stream.Read(bytes, 0, bytes.Length); + Clear(); - if (count != bytes.Length) - throw new Exception("Error While Reading AssetIndex"); - - var json = Encoding.UTF8.GetString(bytes); - - var obj = JsonConvert.DeserializeObject(json); - if (obj != null) + using (var stream = File.OpenRead(path)) { - MapToResourceIndex(obj); + var bytes = new byte[stream.Length]; + var count = stream.Read(bytes, 0, bytes.Length); + + if (count != bytes.Length) + throw new Exception("Error While Reading AssetIndex"); + + var json = Encoding.UTF8.GetString(bytes); + + var obj = JsonConvert.DeserializeObject(json); + if (obj != null) + { + MapToResourceIndex(obj); + } } } + catch (Exception e) + { + Logger.Error("AssetIndex was not loaded"); + Console.WriteLine(e.ToString()); + return; + } + Logger.Info("Loaded !!"); } - catch (Exception e) - { - Logger.Error("AssetIndex was not loaded"); - Console.WriteLine(e.ToString()); - return; - } - Logger.Info("Loaded !!"); } public static void Clear() { diff --git a/AssetStudio/SerializedFile.cs b/AssetStudio/SerializedFile.cs index f0641b4..8d4a2af 100644 --- a/AssetStudio/SerializedFile.cs +++ b/AssetStudio/SerializedFile.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers.Binary; using System.Collections.Generic; using System.IO; using System.Linq; @@ -31,8 +32,6 @@ namespace AssetStudio public List m_RefTypes; public string userInformation; - private static int DecryptClassId(int id) => (id ^ 0x23746FBE) - 3; - public SerializedFile(FileReader reader, AssetsManager assetsManager, string path = null) { this.assetsManager = assetsManager; @@ -238,12 +237,9 @@ namespace AssetStudio var type = new SerializedType(); type.classID = reader.ReadInt32(); - - if ((type.classID > 0xFFFF || type.classID <= 0x0) && !Enum.IsDefined(typeof(ClassIDType), type.classID)) + if (BitConverter.ToBoolean(header.m_Reserved, 0)) { - byte[] classIdBytes = BitConverter.GetBytes(type.classID); - Array.Reverse(classIdBytes); - type.classID = DecryptClassId(BitConverter.ToInt32(classIdBytes, 0)); + type.classID = DecodeClassID(type.classID); } if (header.m_Version >= SerializedFileFormatVersion.RefactoredClassId) @@ -385,6 +381,12 @@ namespace AssetStudio ObjectsDic.Add(obj.m_PathID, obj); } + private int DecodeClassID(int value) + { + var bytes = BitConverter.GetBytes(value); + value = BinaryPrimitives.ReadInt32BigEndian(bytes); + return (value ^ 0x23746FBE) - 3; + } public bool IsVersionStripped => unityVersion == strippedVersion; private const string strippedVersion = "0.0.0"; diff --git a/AssetStudio/TypeTreeHelper.cs b/AssetStudio/TypeTreeHelper.cs index ace4f29..7b4e959 100644 --- a/AssetStudio/TypeTreeHelper.cs +++ b/AssetStudio/TypeTreeHelper.cs @@ -194,9 +194,11 @@ namespace AssetStudio value = reader.ReadSByte(); break; case "UInt8": - case "char": value = reader.ReadByte(); break; + case "char": + value = BitConverter.ToChar(reader.ReadBytes(2), 0); + break; case "short": case "SInt16": value = reader.ReadInt16(); diff --git a/AssetStudioUtility/AnimationClipExtensions.cs b/AssetStudioUtility/AnimationClipExtensions.cs index b9d2859..9bce0ab 100644 --- a/AssetStudioUtility/AnimationClipExtensions.cs +++ b/AssetStudioUtility/AnimationClipExtensions.cs @@ -15,10 +15,10 @@ namespace AssetStudio animationClip.m_ScaleCurves = converter.Scales.Union(animationClip.m_ScaleCurves).ToArray(); animationClip.m_FloatCurves = converter.Floats.Union(animationClip.m_FloatCurves).ToArray(); animationClip.m_PPtrCurves = converter.PPtrs.Union(animationClip.m_PPtrCurves).ToArray(); - return ConvertSerializedAnimationClip(animationClip, game); + return ConvertSerializedAnimationClip(animationClip); } - public static string ConvertSerializedAnimationClip(AnimationClip animationClip, Game game) + public static string ConvertSerializedAnimationClip(AnimationClip animationClip) { var sb = new StringBuilder(); using (var stringWriter = new StringWriter(sb)) diff --git a/AssetStudioUtility/SpriteHelper.cs b/AssetStudioUtility/SpriteHelper.cs index c9e2af1..db1ac99 100644 --- a/AssetStudioUtility/SpriteHelper.cs +++ b/AssetStudioUtility/SpriteHelper.cs @@ -82,7 +82,7 @@ namespace AssetStudio var polygons = triangles.Select(x => new Polygon(new LinearLineSegment(x.Select(y => new PointF(y.X, y.Y)).ToArray()))).ToArray(); IPathCollection path = new PathCollection(polygons); var matrix = Matrix3x2.CreateScale(m_Sprite.m_PixelsToUnits); - matrix *= Matrix3x2.CreateTranslation(textureRect.width * m_Sprite.m_Pivot.X - textureRectOffset.X, textureRect.height * m_Sprite.m_Pivot.Y - textureRectOffset.Y); + matrix *= Matrix3x2.CreateTranslation(m_Sprite.m_Rect.width * m_Sprite.m_Pivot.X - textureRectOffset.X, m_Sprite.m_Rect.height * m_Sprite.m_Pivot.Y - textureRectOffset.Y); path = path.Transform(matrix); var graphicsOptions = new GraphicsOptions {