diff --git a/AssetStudio.CLI/Exporter.cs b/AssetStudio.CLI/Exporter.cs index b0cbfbc..d7a6501 100644 --- a/AssetStudio.CLI/Exporter.cs +++ b/AssetStudio.CLI/Exporter.cs @@ -229,7 +229,7 @@ namespace AssetStudio.CLI #region Face int sum = 0; - for (var i = 0; i < m_Mesh.m_SubMeshes.Length; i++) + for (var i = 0; i < m_Mesh.m_SubMeshes.Count; i++) { sb.AppendLine($"g {m_Mesh.m_Name}_{i}"); int indexCount = (int)m_Mesh.m_SubMeshes[i].indexCount; diff --git a/AssetStudio.CLI/Studio.cs b/AssetStudio.CLI/Studio.cs index 0413619..1c7b281 100644 --- a/AssetStudio.CLI/Studio.cs +++ b/AssetStudio.CLI/Studio.cs @@ -81,7 +81,7 @@ namespace AssetStudio.CLI { var bundleFile = new BundleFile(reader, Game); reader.Dispose(); - if (bundleFile.fileList.Length > 0) + if (bundleFile.fileList.Count > 0) { var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); return ExtractStreamFile(extractPath, bundleFile.fileList); @@ -99,7 +99,7 @@ namespace AssetStudio.CLI Logger.Info($"Decompressing {reader.FileName} ..."); var webFile = new WebFile(reader); reader.Dispose(); - if (webFile.fileList.Length > 0) + if (webFile.fileList.Count > 0) { var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); return ExtractStreamFile(extractPath, webFile.fileList); @@ -125,8 +125,8 @@ namespace AssetStudio.CLI case FileType.BundleFile: total += ExtractBundleFile(subReader, subSavePath); break; - case FileType.Mhy0File: - total += ExtractMhy0File(subReader, subSavePath); + case FileType.MhyFile: + total += ExtractMhyFile(subReader, subSavePath); break; } } while (stream.Remaining > 0); @@ -154,14 +154,14 @@ namespace AssetStudio.CLI return total; } - private static int ExtractMhy0File(FileReader reader, string savePath) + private static int ExtractMhyFile(FileReader reader, string savePath) { Logger.Info($"Decompressing {reader.FileName} ..."); try { - var mhy0File = new Mhy0File(reader, reader.FullPath, (Mhy0)Game); + var mhy0File = new MhyFile(reader, reader.FullPath, (Mhy)Game); reader.Dispose(); - if (mhy0File.fileList.Length > 0) + if (mhy0File.fileList.Count > 0) { var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); return ExtractStreamFile(extractPath, mhy0File.fileList); @@ -169,12 +169,12 @@ namespace AssetStudio.CLI } catch (InvalidCastException) { - Logger.Error($"Game type mismatch, Expected {nameof(Mhy0)} but got {Game.Name} ({Game.GetType().Name}) !!"); + Logger.Error($"Game type mismatch, Expected {nameof(Mhy)} but got {Game.Name} ({Game.GetType().Name}) !!"); } return 0; } - private static int ExtractStreamFile(string extractPath, StreamFile[] fileList) + private static int ExtractStreamFile(string extractPath, List fileList) { int extractedCount = 0; foreach (var file in fileList) diff --git a/AssetStudio.GUI/Exporter.cs b/AssetStudio.GUI/Exporter.cs index 27cfdc4..0318441 100644 --- a/AssetStudio.GUI/Exporter.cs +++ b/AssetStudio.GUI/Exporter.cs @@ -229,7 +229,7 @@ namespace AssetStudio.GUI #region Face int sum = 0; - for (var i = 0; i < m_Mesh.m_SubMeshes.Length; i++) + for (var i = 0; i < m_Mesh.m_SubMeshes.Count; i++) { sb.AppendLine($"g {m_Mesh.m_Name}_{i}"); int indexCount = (int)m_Mesh.m_SubMeshes[i].indexCount; diff --git a/AssetStudio.GUI/Studio.cs b/AssetStudio.GUI/Studio.cs index 79da5ec..1ae95e9 100644 --- a/AssetStudio.GUI/Studio.cs +++ b/AssetStudio.GUI/Studio.cs @@ -82,7 +82,7 @@ namespace AssetStudio.GUI { var bundleFile = new BundleFile(reader, Game); reader.Dispose(); - if (bundleFile.fileList.Length > 0) + if (bundleFile.fileList.Count > 0) { var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); return ExtractStreamFile(extractPath, bundleFile.fileList); @@ -100,7 +100,7 @@ namespace AssetStudio.GUI StatusStripUpdate($"Decompressing {reader.FileName} ..."); var webFile = new WebFile(reader); reader.Dispose(); - if (webFile.fileList.Length > 0) + if (webFile.fileList.Count > 0) { var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); return ExtractStreamFile(extractPath, webFile.fileList); @@ -126,8 +126,8 @@ namespace AssetStudio.GUI case FileType.BundleFile: total += ExtractBundleFile(subReader, subSavePath); break; - case FileType.Mhy0File: - total += ExtractMhy0File(subReader, subSavePath); + case FileType.MhyFile: + total += ExtractMhyFile(subReader, subSavePath); break; } } while (stream.Remaining > 0); @@ -155,14 +155,14 @@ namespace AssetStudio.GUI return total; } - private static int ExtractMhy0File(FileReader reader, string savePath) + private static int ExtractMhyFile(FileReader reader, string savePath) { StatusStripUpdate($"Decompressing {reader.FileName} ..."); try { - var mhy0File = new Mhy0File(reader, reader.FullPath, (Mhy0)Game); + var mhy0File = new MhyFile(reader, reader.FullPath, (Mhy)Game); reader.Dispose(); - if (mhy0File.fileList.Length > 0) + if (mhy0File.fileList.Count > 0) { var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); return ExtractStreamFile(extractPath, mhy0File.fileList); @@ -170,12 +170,12 @@ namespace AssetStudio.GUI } catch (InvalidCastException) { - Logger.Error($"Game type mismatch, Expected {nameof(Mhy0)} but got {Game.Name} ({Game.GetType().Name}) !!"); + Logger.Error($"Game type mismatch, Expected {nameof(Mhy)} but got {Game.Name} ({Game.GetType().Name}) !!"); } return 0; } - private static int ExtractStreamFile(string extractPath, StreamFile[] fileList) + private static int ExtractStreamFile(string extractPath, List fileList) { int extractedCount = 0; foreach (var file in fileList) diff --git a/AssetStudio.Utility/ModelConverter.cs b/AssetStudio.Utility/ModelConverter.cs index 9d8c3b4..a9e14db 100644 --- a/AssetStudio.Utility/ModelConverter.cs +++ b/AssetStudio.Utility/ModelConverter.cs @@ -225,7 +225,7 @@ namespace AssetStudio private ImportedFrame ConvertTransform(Transform trans) { - var frame = new ImportedFrame(trans.m_Children.Length); + var frame = new ImportedFrame(trans.m_Children.Count); transformDictionary.Add(trans, frame); trans.m_GameObject.TryGet(out var m_GameObject); frame.Name = m_GameObject.m_Name; @@ -308,7 +308,7 @@ namespace AssetStudio iMesh.hasColor = mesh.m_Colors?.Length > 0; int firstFace = 0; - for (int i = 0; i < mesh.m_SubMeshes.Length; i++) + for (int i = 0; i < mesh.m_SubMeshes.Count; i++) { int numFaces = (int)mesh.m_SubMeshes[i].indexCount / 3; if (subHashSet.Count > 0 && !subHashSet.Contains(i)) @@ -319,7 +319,7 @@ namespace AssetStudio var submesh = mesh.m_SubMeshes[i]; var iSubmesh = new ImportedSubmesh(); Material mat = null; - if (i - firstSubMesh < meshR.m_Materials.Length) + if (i - firstSubMesh < meshR.m_Materials.Count) { if (meshR.m_Materials[i - firstSubMesh].TryGet(out var m_Material)) { @@ -408,7 +408,7 @@ namespace AssetStudio } } //BoneInfluence - if (mesh.m_Skin?.Length > 0) + if (mesh.m_Skin?.Count > 0) { var inf = mesh.m_Skin[j]; iVertex.BoneIndices = new int[4]; @@ -431,16 +431,16 @@ namespace AssetStudio * 2 - m_BoneNameHashes */ var boneType = 0; - if (sMesh.m_Bones.Length > 0) + if (sMesh.m_Bones.Count > 0) { - if (sMesh.m_Bones.Length == mesh.m_BindPose.Length) + if (sMesh.m_Bones.Count == mesh.m_BindPose.Length) { var verifiedBoneCount = sMesh.m_Bones.Count(x => x.TryGet(out _)); if (verifiedBoneCount > 0) { boneType = 1; } - if (verifiedBoneCount != sMesh.m_Bones.Length) + if (verifiedBoneCount != sMesh.m_Bones.Count) { //尝试使用m_BoneNameHashes 4.3 and up if (mesh.m_BindPose.Length > 0 && (mesh.m_BindPose.Length == mesh.m_BoneNameHashes?.Length)) @@ -470,7 +470,7 @@ namespace AssetStudio if (boneType == 1) { - var boneCount = sMesh.m_Bones.Length; + var boneCount = sMesh.m_Bones.Count; iMesh.BoneList = new List(boneCount); for (int i = 0; i < boneCount; i++) { @@ -501,13 +501,13 @@ namespace AssetStudio } //Morphs - if (mesh.m_Shapes?.channels?.Length > 0) + if (mesh.m_Shapes?.channels?.Count > 0) { var morph = new ImportedMorph(); MorphList.Add(morph); morph.Path = iMesh.Path; - morph.Channels = new List(mesh.m_Shapes.channels.Length); - for (int i = 0; i < mesh.m_Shapes.channels.Length; i++) + morph.Channels = new List(mesh.m_Shapes.channels.Count); + for (int i = 0; i < mesh.m_Shapes.channels.Count; i++) { var channel = new ImportedMorphChannel(); morph.Channels.Add(channel); @@ -534,7 +534,7 @@ namespace AssetStudio keyframe.hasTangents = shape.hasTangents; keyframe.VertexList = new List((int)shape.vertexCount); var vertexEnd = shape.firstVertex + shape.vertexCount; - for (uint j = shape.firstVertex; j < vertexEnd; j++) + for (int j = (int)shape.firstVertex; j < vertexEnd; j++) { var destVertex = new ImportedMorphVertex(); keyframe.VertexList.Add(destVertex); @@ -918,7 +918,7 @@ namespace AssetStudio { var frame = streamedFrames[frameIndex]; var streamedValues = frame.keyList.Select(x => x.value).ToArray(); - for (int curveIndex = 0; curveIndex < frame.keyList.Length;) + for (int curveIndex = 0; curveIndex < frame.keyList.Count;) { var index = frame.keyList[curveIndex].index; if (!Game.Type.IsSRGroup()) diff --git a/AssetStudio.Utility/ShaderConverter.cs b/AssetStudio.Utility/ShaderConverter.cs index 1122aea..55b10e1 100644 --- a/AssetStudio.Utility/ShaderConverter.cs +++ b/AssetStudio.Utility/ShaderConverter.cs @@ -1,5 +1,6 @@ using SpirV; using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -153,42 +154,42 @@ namespace AssetStudio { sb.Append(ConvertSerializedShaderState(m_Passe.m_State)); - if (m_Passe.progVertex.m_SubPrograms.Length > 0) + if (m_Passe.progVertex.m_SubPrograms.Count > 0) { sb.Append("Program \"vp\" {\n"); sb.Append(ConvertSerializedSubPrograms(m_Passe.progVertex.m_SubPrograms, platforms, shaderPrograms)); sb.Append("}\n"); } - if (m_Passe.progFragment.m_SubPrograms.Length > 0) + if (m_Passe.progFragment.m_SubPrograms.Count > 0) { sb.Append("Program \"fp\" {\n"); sb.Append(ConvertSerializedSubPrograms(m_Passe.progFragment.m_SubPrograms, platforms, shaderPrograms)); sb.Append("}\n"); } - if (m_Passe.progGeometry.m_SubPrograms.Length > 0) + if (m_Passe.progGeometry.m_SubPrograms.Count > 0) { sb.Append("Program \"gp\" {\n"); sb.Append(ConvertSerializedSubPrograms(m_Passe.progGeometry.m_SubPrograms, platforms, shaderPrograms)); sb.Append("}\n"); } - if (m_Passe.progHull.m_SubPrograms.Length > 0) + if (m_Passe.progHull.m_SubPrograms.Count > 0) { sb.Append("Program \"hp\" {\n"); sb.Append(ConvertSerializedSubPrograms(m_Passe.progHull.m_SubPrograms, platforms, shaderPrograms)); sb.Append("}\n"); } - if (m_Passe.progDomain.m_SubPrograms.Length > 0) + if (m_Passe.progDomain.m_SubPrograms.Count > 0) { sb.Append("Program \"dp\" {\n"); sb.Append(ConvertSerializedSubPrograms(m_Passe.progDomain.m_SubPrograms, platforms, shaderPrograms)); sb.Append("}\n"); } - if (m_Passe.progRayTracing?.m_SubPrograms.Length > 0) + if (m_Passe.progRayTracing?.m_SubPrograms.Count > 0) { sb.Append("Program \"rtp\" {\n"); sb.Append(ConvertSerializedSubPrograms(m_Passe.progRayTracing.m_SubPrograms, platforms, shaderPrograms)); @@ -200,7 +201,7 @@ namespace AssetStudio return sb.ToString(); } - private static string ConvertSerializedSubPrograms(SerializedSubProgram[] m_SubPrograms, ShaderCompilerPlatform[] platforms, ShaderProgram[] shaderPrograms) + private static string ConvertSerializedSubPrograms(List m_SubPrograms, ShaderCompilerPlatform[] platforms, ShaderProgram[] shaderPrograms) { var sb = new StringBuilder(); var groups = m_SubPrograms.GroupBy(x => x.m_BlobIndex); @@ -496,10 +497,10 @@ namespace AssetStudio } } - private static string ConvertSerializedShaderRTBlendState(SerializedShaderRTBlendState[] rtBlend, bool rtSeparateBlend) + private static string ConvertSerializedShaderRTBlendState(List rtBlend, bool rtSeparateBlend) { var sb = new StringBuilder(); - for (var i = 0; i < rtBlend.Length; i++) + for (var i = 0; i < rtBlend.Count; i++) { var blend = rtBlend[i]; if (blend.srcBlend.val != 1f || @@ -653,7 +654,7 @@ namespace AssetStudio private static string ConvertSerializedTagMap(SerializedTagMap m_Tags, int intent) { var sb = new StringBuilder(); - if (m_Tags.tags.Length > 0) + if (m_Tags.tags.Count > 0) { sb.Append(new string(' ', intent)); sb.Append("Tags { "); diff --git a/AssetStudio.Utility/SpriteHelper.cs b/AssetStudio.Utility/SpriteHelper.cs index 7b30d9c..2110b71 100644 --- a/AssetStudio.Utility/SpriteHelper.cs +++ b/AssetStudio.Utility/SpriteHelper.cs @@ -150,7 +150,7 @@ namespace AssetStudio var vertices = new Vector2[subMesh.vertexCount]; for (int v = 0; v < subMesh.vertexCount; v++) { - vertices[v] = vertexReader.ReadVector3(); + vertices[v] = new Vector3(vertexReader.ReadSingle(), vertexReader.ReadSingle(), vertexReader.ReadSingle()); vertexReader.BaseStream.Position += m_Stream.stride - 12; } diff --git a/AssetStudio.Utility/YAML/AnimationClipConverter.cs b/AssetStudio.Utility/YAML/AnimationClipConverter.cs index 8afee60..d536d32 100644 --- a/AssetStudio.Utility/YAML/AnimationClipConverter.cs +++ b/AssetStudio.Utility/YAML/AnimationClipConverter.cs @@ -26,12 +26,12 @@ namespace AssetStudio private readonly Dictionary>> m_floats = new Dictionary>>(); private readonly Dictionary> m_pptrs = new Dictionary>(); - public Vector3Curve[] Translations { get; private set; } - public QuaternionCurve[] Rotations { get; private set; } - public Vector3Curve[] Scales { get; private set; } - public Vector3Curve[] Eulers { get; private set; } - public FloatCurve[] Floats { get; private set; } - public PPtrCurve[] PPtrs { get; private set; } + public List Translations { get; private set; } + public List Rotations { get; private set; } + public List Scales { get; private set; } + public List Eulers { get; private set; } + public List Floats { get; private set; } + public List PPtrs { get; private set; } public AnimationClipConverter(AnimationClip clip) { @@ -81,17 +81,17 @@ namespace AssetStudio private void CreateCurves() { m_translations.AsEnumerable().ToList().ForEach(x => x.Key.curve.m_Curve.AddRange(x.Value)); - Translations = m_translations.Keys.ToArray(); + Translations = m_translations.Keys.ToList(); m_rotations.AsEnumerable().ToList().ForEach(x => x.Key.curve.m_Curve.AddRange(x.Value)); - Rotations = m_rotations.Keys.ToArray(); + Rotations = m_rotations.Keys.ToList(); m_scales.AsEnumerable().ToList().ForEach(x => x.Key.curve.m_Curve.AddRange(x.Value)); - Scales = m_scales.Keys.ToArray(); + Scales = m_scales.Keys.ToList(); m_eulers.AsEnumerable().ToList().ForEach(x => x.Key.curve.m_Curve.AddRange(x.Value)); - Eulers = m_eulers.Keys.ToArray(); + Eulers = m_eulers.Keys.ToList(); m_floats.AsEnumerable().ToList().ForEach(x => x.Key.curve.m_Curve.AddRange(x.Value)); - Floats = m_floats.Keys.ToArray(); + Floats = m_floats.Keys.ToList(); m_pptrs.AsEnumerable().ToList().ForEach(x => x.Key.curve.AddRange(x.Value)); - PPtrs = m_pptrs.Keys.ToArray(); + PPtrs = m_pptrs.Keys.ToList(); } private void ProcessStreams(List streamFrames, AnimationClipBindingConstant bindings, Dictionary tos, float sampleRate) @@ -107,7 +107,7 @@ namespace AssetStudio for (var frameIndex = 1; frameIndex < streamFrames.Count - 1; frameIndex++) { var frame = streamFrames[frameIndex]; - for (var curveIndex = 0; curveIndex < frame.keyList.Length;) + for (var curveIndex = 0; curveIndex < frame.keyList.Count;) { var curve = frame.keyList[curveIndex]; var index = curve.index; @@ -496,7 +496,7 @@ namespace AssetStudio for (frameIndex = currentFrame - 1; frameIndex >= 0; frameIndex--) { var frame = streamFrames[frameIndex]; - for (curveIndex = 0; curveIndex < frame.keyList.Length; curveIndex++) + for (curveIndex = 0; curveIndex < frame.keyList.Count; curveIndex++) { var curve = frame.keyList[curveIndex]; if (curve.index == curveID) @@ -512,7 +512,7 @@ namespace AssetStudio { var curve = frame.keyList[currentCurve]; int i = currentCurve + 1; - for (; i < frame.keyList.Length; i++) + for (; i < frame.keyList.Count; i++) { if (frame.keyList[i].index != curve.index) { diff --git a/AssetStudio.Utility/YAML/AnimationClipExtensions.cs b/AssetStudio.Utility/YAML/AnimationClipExtensions.cs index c4ad660..b0780a6 100644 --- a/AssetStudio.Utility/YAML/AnimationClipExtensions.cs +++ b/AssetStudio.Utility/YAML/AnimationClipExtensions.cs @@ -112,10 +112,10 @@ namespace AssetStudio } private static bool AddTOS(this AnimationClip clip, Dictionary src, Dictionary dest) { - int tosCount = clip.m_ClipBindingConstant.genericBindings.Length; + int tosCount = clip.m_ClipBindingConstant.genericBindings.Count; for (int i = 0; i < tosCount; i++) { - ref GenericBinding binding = ref clip.m_ClipBindingConstant.genericBindings[i]; + var binding = clip.m_ClipBindingConstant.genericBindings[i]; if (src.TryGetValue(binding.path, out string path)) { dest[binding.path] = path; @@ -147,12 +147,12 @@ namespace AssetStudio if (!clip.m_Legacy || clip.m_MuscleClip != null) { var converter = AnimationClipConverter.Process(clip); - clip.m_RotationCurves = converter.Rotations.Union(clip.m_RotationCurves).ToArray(); - clip.m_EulerCurves = converter.Eulers.Union(clip.m_EulerCurves).ToArray(); - clip.m_PositionCurves = converter.Translations.Union(clip.m_PositionCurves).ToArray(); - clip.m_ScaleCurves = converter.Scales.Union(clip.m_ScaleCurves).ToArray(); - clip.m_FloatCurves = converter.Floats.Union(clip.m_FloatCurves).ToArray(); - clip.m_PPtrCurves = converter.PPtrs.Union(clip.m_PPtrCurves).ToArray(); + clip.m_RotationCurves = converter.Rotations.Union(clip.m_RotationCurves).ToList(); + clip.m_EulerCurves = converter.Eulers.Union(clip.m_EulerCurves).ToList(); + clip.m_PositionCurves = converter.Translations.Union(clip.m_PositionCurves).ToList(); + clip.m_ScaleCurves = converter.Scales.Union(clip.m_ScaleCurves).ToList(); + clip.m_FloatCurves = converter.Floats.Union(clip.m_FloatCurves).ToList(); + clip.m_PPtrCurves = converter.PPtrs.Union(clip.m_PPtrCurves).ToList(); } return ConvertSerializedAnimationClip(clip); } diff --git a/AssetStudio/AssetMap.cs b/AssetStudio/AssetMap.cs index 97142b8..9c42c08 100644 --- a/AssetStudio/AssetMap.cs +++ b/AssetStudio/AssetMap.cs @@ -12,7 +12,7 @@ namespace AssetStudio [Key(0)] public GameType GameType { get; set; } [Key(1)] - public AssetEntry[] AssetEntries { get; set; } + public List AssetEntries { get; set; } } [MessagePackObject] public record AssetEntry diff --git a/AssetStudio/AssetsHelper.cs b/AssetStudio/AssetsHelper.cs index c7e39d3..6d9d90b 100644 --- a/AssetStudio/AssetsHelper.cs +++ b/AssetStudio/AssetsHelper.cs @@ -10,7 +10,6 @@ using System.Text.RegularExpressions; using System.Xml; using System.Text; using MessagePack; -using System.Reflection.Metadata.Ecma335; namespace AssetStudio { @@ -30,7 +29,7 @@ namespace AssetStudio { public string Path { get; set; } public long Offset { get; set; } - public string[] Dependencies { get; set; } + public List Dependencies { get; set; } } public static void SetUnityVersion(string version) @@ -207,7 +206,7 @@ namespace AssetStudio { Path = relativePath, Offset = assetsFile.offset, - Dependencies = assetsFile.m_Externals.Select(x => x.fileName).ToArray() + Dependencies = assetsFile.m_Externals.Select(x => x.fileName).ToList() }; if (CABMap.ContainsKey(assetsFile.fileName)) @@ -236,7 +235,7 @@ namespace AssetStudio writer.Write(kv.Key); writer.Write(kv.Value.Path); writer.Write(kv.Value.Offset); - writer.Write(kv.Value.Dependencies.Length); + writer.Write(kv.Value.Dependencies.Count); foreach (var cab in kv.Value.Dependencies) { writer.Write(cab); @@ -298,10 +297,10 @@ namespace AssetStudio var path = reader.ReadString(); var offset = reader.ReadInt64(); var depCount = reader.ReadInt32(); - var dependencies = new string[depCount]; + var dependencies = new List(); for (int j = 0; j < depCount; j++) { - dependencies[j] = reader.ReadString(); + dependencies.Add(reader.ReadString()); } var entry = new Entry() { @@ -328,7 +327,7 @@ namespace AssetStudio UpdateContainers(assets, game); - ExportAssetsMap(assets.ToArray(), game, mapName, savePath, exportListType, resetEvent); + ExportAssetsMap(assets, game, mapName, savePath, exportListType, resetEvent); } catch(Exception e) { @@ -528,7 +527,7 @@ namespace AssetStudio } } - private static void ExportAssetsMap(AssetEntry[] toExportAssets, Game game, string name, string savePath, ExportListType exportListType, ManualResetEvent resetEvent = null) + private static void ExportAssetsMap(List toExportAssets, Game game, string name, string savePath, ExportListType exportListType, ManualResetEvent resetEvent = null) { ThreadPool.QueueUserWorkItem(state => { @@ -588,7 +587,7 @@ namespace AssetStudio MessagePackSerializer.Serialize(file, assetMap, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray)); } - Logger.Info($"Finished buidling AssetMap with {toExportAssets.Length} assets."); + Logger.Info($"Finished buidling AssetMap with {toExportAssets.Count} assets."); } resetEvent?.Set(); @@ -613,7 +612,7 @@ namespace AssetStudio DumpCABMap(mapName); Logger.Info($"Map build successfully !! {collision} collisions found"); - ExportAssetsMap(assets.ToArray(), game, mapName, savePath, exportListType, resetEvent); + ExportAssetsMap(assets, game, mapName, savePath, exportListType, resetEvent); } } } diff --git a/AssetStudio/AssetsManager.cs b/AssetStudio/AssetsManager.cs index 9a59702..beccd03 100644 --- a/AssetStudio/AssetsManager.cs +++ b/AssetStudio/AssetsManager.cs @@ -157,6 +157,9 @@ namespace AssetStudio case FileType.BlkFile: LoadBlkFile(reader); break; + case FileType.MhyFile: + LoadMhyFile(reader); + break; } } @@ -448,6 +451,9 @@ namespace AssetStudio case FileType.BlbFile: LoadBlbFile(subReader, reader.FullPath, offset, false); break; + case FileType.MhyFile: + LoadMhyFile(subReader, reader.FullPath, offset, false); + break; } } } @@ -478,8 +484,8 @@ namespace AssetStudio case FileType.BundleFile: LoadBundleFile(subReader, reader.FullPath, offset, false); break; - case FileType.Mhy0File: - LoadMhy0File(subReader, reader.FullPath, offset, false); + case FileType.MhyFile: + LoadMhyFile(subReader, reader.FullPath, offset, false); break; } } @@ -497,7 +503,7 @@ namespace AssetStudio reader.Dispose(); } } - private void LoadMhy0File(FileReader reader, string originalPath = null, long originalOffset = 0, bool log = true) + private void LoadMhyFile(FileReader reader, string originalPath = null, long originalOffset = 0, bool log = true) { if (log) { @@ -505,15 +511,15 @@ namespace AssetStudio } try { - var mhy0File = new Mhy0File(reader, reader.FullPath, (Mhy0)Game); - Logger.Verbose($"mhy0 total size: {mhy0File.TotalSize:X8}"); - foreach (var file in mhy0File.fileList) + var mhyFile = new MhyFile(reader, reader.FullPath, (Mhy)Game); + Logger.Verbose($"mhy total size: {mhyFile.TotalSize:X8}"); + foreach (var file in mhyFile.fileList) { var dummyPath = Path.Combine(Path.GetDirectoryName(reader.FullPath), file.fileName); var cabReader = new FileReader(dummyPath, file.stream); if (cabReader.FileType == FileType.AssetsFile) { - LoadAssetsFromMemory(cabReader, originalPath ?? reader.FullPath, mhy0File.m_Header.unityRevision, originalOffset); + LoadAssetsFromMemory(cabReader, originalPath ?? reader.FullPath, mhyFile.m_Header.unityRevision, originalOffset); } else { @@ -524,11 +530,11 @@ namespace AssetStudio } catch (InvalidCastException) { - Logger.Error($"Game type mismatch, Expected {nameof(Mhy0)} but got {Game.Name} ({Game.GetType().Name}) !!"); + Logger.Error($"Game type mismatch, Expected {nameof(Mhy)} but got {Game.Name} ({Game.GetType().Name}) !!"); } catch (Exception e) { - var str = $"Error while reading mhy0 file {reader.FullPath}"; + var str = $"Error while reading mhy file {reader.FullPath}"; if (originalPath != null) { str += $" from {Path.GetFileName(originalPath)}"; @@ -705,7 +711,7 @@ namespace AssetStudio } if (obj is GameObject m_GameObject) { - Logger.Verbose($"GameObject with {m_GameObject.m_PathID} in file {m_GameObject.assetsFile.fileName} has {m_GameObject.m_Components.Length} components, Attempting to fetch them..."); + Logger.Verbose($"GameObject with {m_GameObject.m_PathID} in file {m_GameObject.assetsFile.fileName} has {m_GameObject.m_Components.Count} components, Attempting to fetch them..."); foreach (var pptr in m_GameObject.m_Components) { if (pptr.TryGet(out var m_Component)) @@ -744,7 +750,7 @@ namespace AssetStudio { if (m_SpriteAtlas.m_RenderDataMap.Count > 0) { - Logger.Verbose($"SpriteAtlas with {m_SpriteAtlas.m_PathID} in file {m_SpriteAtlas.assetsFile.fileName} has {m_SpriteAtlas.m_PackedSprites.Length} packed sprites, Attempting to fetch them..."); + Logger.Verbose($"SpriteAtlas with {m_SpriteAtlas.m_PathID} in file {m_SpriteAtlas.assetsFile.fileName} has {m_SpriteAtlas.m_PackedSprites.Count} packed sprites, Attempting to fetch them..."); foreach (var m_PackedSprite in m_SpriteAtlas.m_PackedSprites) { if (m_PackedSprite.TryGet(out var m_Sprite)) diff --git a/AssetStudio/BlbFile.cs b/AssetStudio/BlbFile.cs index 27e30ea..53f01d1 100644 --- a/AssetStudio/BlbFile.cs +++ b/AssetStudio/BlbFile.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; @@ -8,11 +9,11 @@ namespace AssetStudio { private const uint DefaultUncompressedSize = 0x20000; - private BundleFile.StorageBlock[] m_BlocksInfo; - private BundleFile.Node[] m_DirectoryInfo; + private List m_BlocksInfo; + private List m_DirectoryInfo; public BundleFile.Header m_Header; - public StreamFile[] fileList; + public List fileList; public long Offset; @@ -68,30 +69,30 @@ namespace AssetStudio var bundleInfoOffset = reader.Position + reader.ReadInt64(); reader.Position = blocksInfoOffset; - m_BlocksInfo = new BundleFile.StorageBlock[blocksInfoCount]; + m_BlocksInfo = new List(); Logger.Verbose($"Blocks count: {blocksInfoCount}"); for (int i = 0; i < blocksInfoCount; i++) { - m_BlocksInfo[i] = new BundleFile.StorageBlock + m_BlocksInfo.Add(new BundleFile.StorageBlock { compressedSize = reader.ReadUInt32(), uncompressedSize = i == blocksInfoCount - 1 ? lastUncompressedSize : DefaultUncompressedSize, flags = (StorageBlockFlags)0x43 - }; + }); Logger.Verbose($"Block {i} Info: {m_BlocksInfo[i]}"); } reader.Position = nodesInfoOffset; - m_DirectoryInfo = new BundleFile.Node[nodesCount]; + m_DirectoryInfo = new List(); Logger.Verbose($"Directory count: {nodesCount}"); for (int i = 0; i < nodesCount; i++) { - m_DirectoryInfo[i] = new BundleFile.Node + m_DirectoryInfo.Add(new BundleFile.Node { offset = reader.ReadInt32(), size = reader.ReadInt32() - }; + }); var pathOffset = reader.Position + reader.ReadInt64(); @@ -146,12 +147,12 @@ namespace AssetStudio { Logger.Verbose($"Writing files from blocks stream..."); - fileList = new StreamFile[m_DirectoryInfo.Length]; - for (int i = 0; i < m_DirectoryInfo.Length; i++) + fileList = new List(); + for (int i = 0; i < m_DirectoryInfo.Count; i++) { var node = m_DirectoryInfo[i]; var file = new StreamFile(); - fileList[i] = file; + fileList.Add(file); file.path = node.path; file.fileName = Path.GetFileName(node.path); if (node.size >= int.MaxValue) diff --git a/AssetStudio/BundleFile.cs b/AssetStudio/BundleFile.cs index ed8b1be..b3f52ca 100644 --- a/AssetStudio/BundleFile.cs +++ b/AssetStudio/BundleFile.cs @@ -5,6 +5,8 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Text; +using System.Collections.Generic; +using System.Runtime.InteropServices; namespace AssetStudio { @@ -104,10 +106,10 @@ namespace AssetStudio private UnityCN UnityCN; public Header m_Header; - private Node[] m_DirectoryInfo; - private StorageBlock[] m_BlocksInfo; + private List m_DirectoryInfo; + private List m_BlocksInfo; - public StreamFile[] fileList; + public List fileList; private bool HasUncompressedDataHash = true; @@ -216,7 +218,7 @@ namespace AssetStudio m_Header.size = reader.ReadUInt32(); var numberOfLevelsToDownloadBeforeStreaming = reader.ReadUInt32(); var levelCount = reader.ReadInt32(); - m_BlocksInfo = new StorageBlock[1]; + m_BlocksInfo = new List(); for (int i = 0; i < levelCount; i++) { var storageBlock = new StorageBlock() @@ -226,7 +228,7 @@ namespace AssetStudio }; if (i == levelCount - 1) { - m_BlocksInfo[0] = storageBlock; + m_BlocksInfo.Add(storageBlock); } } if (m_Header.version >= 2) @@ -277,16 +279,16 @@ namespace AssetStudio blocksStream.Position = 0; var blocksReader = new EndianBinaryReader(blocksStream); var nodesCount = blocksReader.ReadInt32(); - m_DirectoryInfo = new Node[nodesCount]; + m_DirectoryInfo = new List(); Logger.Verbose($"Directory count: {nodesCount}"); for (int i = 0; i < nodesCount; i++) { - m_DirectoryInfo[i] = new Node + m_DirectoryInfo.Add(new Node { path = blocksReader.ReadStringToNull(), offset = blocksReader.ReadUInt32(), size = blocksReader.ReadUInt32() - }; + }); } } @@ -294,12 +296,12 @@ namespace AssetStudio { Logger.Verbose($"Writing files from blocks stream..."); - fileList = new StreamFile[m_DirectoryInfo.Length]; - for (int i = 0; i < m_DirectoryInfo.Length; i++) + fileList = new List(); + for (int i = 0; i < m_DirectoryInfo.Count; i++) { var node = m_DirectoryInfo[i]; var file = new StreamFile(); - fileList[i] = file; + fileList.Add(file); file.path = node.path; file.fileName = Path.GetFileName(node.path); if (node.size >= int.MaxValue) @@ -412,7 +414,7 @@ namespace AssetStudio blocksInfoBytes = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize); } MemoryStream blocksInfoUncompresseddStream; - var blocksInfoBytesSpan = blocksInfoBytes.AsSpan(); + var blocksInfoBytesSpan = blocksInfoBytes.AsSpan(0, (int)m_Header.compressedBlocksInfoSize); var uncompressedSize = m_Header.uncompressedBlocksInfoSize; var compressionType = (CompressionType)(m_Header.flags & ArchiveFlags.CompressionTypeMask); Logger.Verbose($"BlockInfo compression type: {compressionType}"); @@ -436,13 +438,15 @@ namespace AssetStudio case CompressionType.Lz4: //LZ4 case CompressionType.Lz4HC: //LZ4HC { - var uncompressedBytes = new byte[uncompressedSize]; - var numWrite = LZ4.Decompress(blocksInfoBytesSpan, uncompressedBytes); + var uncompressedBytes = BigArrayPool.Shared.Rent((int)uncompressedSize); + var uncompressedBytesSpan = uncompressedBytes.AsSpan(0, (int)uncompressedSize); + var numWrite = LZ4.Decompress(blocksInfoBytesSpan, uncompressedBytesSpan); if (numWrite != uncompressedSize) { throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes"); } - blocksInfoUncompresseddStream = new MemoryStream(uncompressedBytes); + blocksInfoUncompresseddStream = new MemoryStream(uncompressedBytesSpan.ToArray()); + BigArrayPool.Shared.Return(uncompressedBytes); break; } case CompressionType.Lz4Mr0k: //Lz4Mr0k @@ -462,32 +466,32 @@ namespace AssetStudio var uncompressedDataHash = blocksInfoReader.ReadBytes(16); } var blocksInfoCount = blocksInfoReader.ReadInt32(); - m_BlocksInfo = new StorageBlock[blocksInfoCount]; + m_BlocksInfo = new List(); Logger.Verbose($"Blocks count: {blocksInfoCount}"); for (int i = 0; i < blocksInfoCount; i++) { - m_BlocksInfo[i] = new StorageBlock + m_BlocksInfo.Add(new StorageBlock { uncompressedSize = blocksInfoReader.ReadUInt32(), compressedSize = blocksInfoReader.ReadUInt32(), flags = (StorageBlockFlags)blocksInfoReader.ReadUInt16() - }; + }); Logger.Verbose($"Block {i} Info: {m_BlocksInfo[i]}"); } var nodesCount = blocksInfoReader.ReadInt32(); - m_DirectoryInfo = new Node[nodesCount]; + m_DirectoryInfo = new List(); Logger.Verbose($"Directory count: {nodesCount}"); for (int i = 0; i < nodesCount; i++) { - m_DirectoryInfo[i] = new Node + m_DirectoryInfo.Add(new Node { offset = blocksInfoReader.ReadInt64(), size = blocksInfoReader.ReadInt64(), flags = blocksInfoReader.ReadUInt32(), path = blocksInfoReader.ReadStringToNull(), - }; + }); Logger.Verbose($"Directory {i} Info: {m_DirectoryInfo[i]}"); } @@ -502,7 +506,7 @@ namespace AssetStudio { Logger.Verbose($"Writing block to blocks stream..."); - for (int i = 0; i < m_BlocksInfo.Length; i++) + for (int i = 0; i < m_BlocksInfo.Count; i++) { Logger.Verbose($"Reading block {i}..."); var blockInfo = m_BlocksInfo[i]; diff --git a/AssetStudio/Classes/Animation.cs b/AssetStudio/Classes/Animation.cs index b03035b..e5e7ed0 100644 --- a/AssetStudio/Classes/Animation.cs +++ b/AssetStudio/Classes/Animation.cs @@ -7,16 +7,16 @@ namespace AssetStudio { public sealed class Animation : Behaviour { - public PPtr[] m_Animations; + public List> m_Animations; public Animation(ObjectReader reader) : base(reader) { var m_Animation = new PPtr(reader); int numAnimations = reader.ReadInt32(); - m_Animations = new PPtr[numAnimations]; + m_Animations = new List>(); for (int i = 0; i < numAnimations; i++) { - m_Animations[i] = new PPtr(reader); + m_Animations.Add(new PPtr(reader)); } } } diff --git a/AssetStudio/Classes/AnimationClip.cs b/AssetStudio/Classes/AnimationClip.cs index 8867300..53ee896 100644 --- a/AssetStudio/Classes/AnimationClip.cs +++ b/AssetStudio/Classes/AnimationClip.cs @@ -91,7 +91,7 @@ namespace AssetStudio { var version = reader.version; int numCurves = reader.ReadInt32(); - m_Curve = new List>(numCurves); + m_Curve = new List>(); for (int i = 0; i < numCurves; i++) { m_Curve.Add(new Keyframe(reader, readerFunc)); @@ -568,7 +568,7 @@ namespace AssetStudio public PPtrCurve(ObjectReader reader) { int numCurves = reader.ReadInt32(); - curve = new List(numCurves); + curve = new List(); for (int i = 0; i < numCurves; i++) { curve.Add(new PPtrKeyframe(reader)); @@ -646,7 +646,7 @@ namespace AssetStudio public HandPose(ObjectReader reader) { - m_GrabX = reader.ReadXForm(reader.version); + m_GrabX = reader.ReadXForm(); m_DoFArray = reader.ReadSingleArray(); m_Override = reader.ReadSingle(); m_CloseOpen = reader.ReadSingle(); @@ -658,7 +658,7 @@ namespace AssetStudio { var handPose = new HandPose(); - handPose.m_GrabX = reader.ReadXForm(reader.version, true); + handPose.m_GrabX = reader.ReadXForm4(); handPose.m_DoFArray = reader.ReadSingleArray(20); handPose.m_Override = reader.ReadSingle(); handPose.m_CloseOpen = reader.ReadSingle(); @@ -681,7 +681,7 @@ namespace AssetStudio public HumanGoal(ObjectReader reader) { var version = reader.version; - m_X = reader.ReadXForm(reader.version); + m_X = reader.ReadXForm(); m_WeightT = reader.ReadSingle(); m_WeightR = reader.ReadSingle(); if (version[0] >= 5)//5.0 and up @@ -695,7 +695,7 @@ namespace AssetStudio { var humanGoal = new HumanGoal(); - humanGoal.m_X = reader.ReadXForm(reader.version, true); + humanGoal.m_X = reader.ReadXForm4(); humanGoal.m_WeightT = reader.ReadSingle(); humanGoal.m_WeightR = reader.ReadSingle(); @@ -714,7 +714,7 @@ namespace AssetStudio public XForm m_RootX; public Vector3 m_LookAtPosition; public Vector4 m_LookAtWeight; - public HumanGoal[] m_GoalArray; + public List m_GoalArray; public HandPose m_LeftHandPose; public HandPose m_RightHandPose; public float[] m_DoFArray; @@ -724,15 +724,15 @@ namespace AssetStudio public HumanPose(ObjectReader reader) { var version = reader.version; - m_RootX = reader.ReadXForm(reader.version); + m_RootX = reader.ReadXForm(); m_LookAtPosition = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? reader.ReadVector3() : (Vector3)reader.ReadVector4();//5.4 and up m_LookAtWeight = reader.ReadVector4(); int numGoals = reader.ReadInt32(); - m_GoalArray = new HumanGoal[numGoals]; + m_GoalArray = new List(); for (int i = 0; i < numGoals; i++) { - m_GoalArray[i] = new HumanGoal(reader); + m_GoalArray.Add(new HumanGoal(reader)); } m_LeftHandPose = new HandPose(reader); @@ -742,28 +742,23 @@ namespace AssetStudio if (version[0] > 5 || (version[0] == 5 && version[1] >= 2))//5.2 and up { - int numTDof = reader.ReadInt32(); - m_TDoFArray = new Vector3[numTDof]; - for (int i = 0; i < numTDof; i++) - { - m_TDoFArray[i] = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? reader.ReadVector3() : (Vector3)reader.ReadVector4();//5.4 and up + m_TDoFArray = reader.ReadVector3Array(); } } - } public static HumanPose ParseGI(ObjectReader reader) { var version = reader.version; var humanPose = new HumanPose(); - humanPose.m_RootX = reader.ReadXForm(version, true); + humanPose.m_RootX = reader.ReadXForm4(); humanPose.m_LookAtPosition = (Vector3)reader.ReadVector4(); humanPose.m_LookAtWeight = reader.ReadVector4(); - humanPose.m_GoalArray = new HumanGoal[4]; + humanPose.m_GoalArray = new List(); for (int i = 0; i < 4; i++) { - humanPose.m_GoalArray[i] = HumanGoal.ParseGI(reader); + humanPose.m_GoalArray.Add(HumanGoal.ParseGI(reader)); } humanPose.m_LeftHandPose = HandPose.ParseGI(reader); @@ -771,11 +766,7 @@ namespace AssetStudio humanPose.m_DoFArray = reader.ReadSingleArray(0x37); - humanPose.m_TDoFArray = new Vector3[0x15]; - for (int i = 0; i < 0x15; i++) - { - humanPose.m_TDoFArray[i] = (Vector3)reader.ReadVector4(); - } + humanPose.m_TDoFArray = reader.ReadVector4Array(0x15).Select(x => (Vector3)x).ToArray(); reader.Position += 4; @@ -973,17 +964,17 @@ namespace AssetStudio public class StreamedFrame { public float time; - public StreamedCurveKey[] keyList; + public List keyList; public StreamedFrame(EndianBinaryReader reader) { time = reader.ReadSingle(); int numKeys = reader.ReadInt32(); - keyList = new StreamedCurveKey[numKeys]; + keyList = new List(); for (int i = 0; i < numKeys; i++) { - keyList[i] = new StreamedCurveKey(reader); + keyList.Add(new StreamedCurveKey(reader)); } } } @@ -1220,15 +1211,15 @@ namespace AssetStudio public class ValueArrayConstant { - public ValueConstant[] m_ValueArray; + public List m_ValueArray; public ValueArrayConstant(ObjectReader reader) { int numVals = reader.ReadInt32(); - m_ValueArray = new ValueConstant[numVals]; + m_ValueArray = new List(); for (int i = 0; i < numVals; i++) { - m_ValueArray[i] = new ValueConstant(reader); + m_ValueArray.Add(new ValueConstant(reader)); } } } @@ -1301,7 +1292,7 @@ namespace AssetStudio var bindings = new AnimationClipBindingConstant(); var genericBindings = new List(); var values = m_Binding; - for (int i = 0; i < values.m_ValueArray.Length;) + for (int i = 0; i < values.m_ValueArray.Count;) { var curveID = values.m_ValueArray[i].m_ID; var curveTypeID = values.m_ValueArray[i].m_TypeID; @@ -1336,7 +1327,7 @@ namespace AssetStudio i++; } } - bindings.genericBindings = genericBindings.ToArray(); + bindings.genericBindings = genericBindings; return bindings; } } @@ -1371,7 +1362,7 @@ namespace AssetStudio public float m_CycleOffset; public float m_AverageAngularSpeed; public int[] m_IndexArray; - public ValueDelta[] m_ValueArrayDelta; + public List m_ValueArrayDelta; public float[] m_ValueArrayReferencePose; public bool m_Mirror; public bool m_LoopTime; @@ -1391,17 +1382,17 @@ namespace AssetStudio { var version = reader.version; m_DeltaPose = new HumanPose(reader); - m_StartX = reader.ReadXForm(reader.version); + m_StartX = reader.ReadXForm(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 5))//5.5 and up { - m_StopX = reader.ReadXForm(reader.version); + m_StopX = reader.ReadXForm(); } - m_LeftFootStartX = reader.ReadXForm(reader.version); - m_RightFootStartX = reader.ReadXForm(reader.version); + m_LeftFootStartX = reader.ReadXForm(); + m_RightFootStartX = reader.ReadXForm(); if (version[0] < 5)//5.0 down { - m_MotionStartX = reader.ReadXForm(reader.version); - m_MotionStopX = reader.ReadXForm(reader.version); + m_MotionStartX = reader.ReadXForm(); + m_MotionStopX = reader.ReadXForm(); } m_AverageSpeed = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? reader.ReadVector3() : (Vector3)reader.ReadVector4();//5.4 and up m_Clip = new Clip(reader); @@ -1425,10 +1416,10 @@ namespace AssetStudio var m_AdditionalCurveIndexArray = reader.ReadInt32Array(); } int numDeltas = reader.ReadInt32(); - m_ValueArrayDelta = new ValueDelta[numDeltas]; + m_ValueArrayDelta = new List(); for (int i = 0; i < numDeltas; i++) { - m_ValueArrayDelta[i] = new ValueDelta(reader); + m_ValueArrayDelta.Add(new ValueDelta(reader)); } if (version[0] > 5 || (version[0] == 5 && version[1] >= 3))//5.3 and up { @@ -1460,10 +1451,10 @@ namespace AssetStudio var clipMuscleConstant = new ClipMuscleConstant(); clipMuscleConstant.m_DeltaPose = HumanPose.ParseGI(reader); - clipMuscleConstant.m_StartX = reader.ReadXForm(version, true); - clipMuscleConstant.m_StopX = reader.ReadXForm(version, true); - clipMuscleConstant.m_LeftFootStartX = reader.ReadXForm(version, true); - clipMuscleConstant.m_RightFootStartX = reader.ReadXForm(version, true); + clipMuscleConstant.m_StartX = reader.ReadXForm4(); + clipMuscleConstant.m_StopX = reader.ReadXForm4(); + clipMuscleConstant.m_LeftFootStartX = reader.ReadXForm4(); + clipMuscleConstant.m_RightFootStartX = reader.ReadXForm4(); clipMuscleConstant.m_AverageSpeed = (Vector3)reader.ReadVector4(); @@ -1510,10 +1501,10 @@ namespace AssetStudio if (valueArrayDeltaCount > 0) { reader.Position = valueArrayDeltaOffset; - clipMuscleConstant.m_ValueArrayDelta = new ValueDelta[valueArrayDeltaCount]; + clipMuscleConstant.m_ValueArrayDelta = new List(); for (int i = 0; i < valueArrayDeltaCount; i++) { - clipMuscleConstant.m_ValueArrayDelta[i] = new ValueDelta(reader); + clipMuscleConstant.m_ValueArrayDelta.Add(new ValueDelta(reader)); } } @@ -1611,25 +1602,25 @@ namespace AssetStudio public class AnimationClipBindingConstant : IYAMLExportable { - public GenericBinding[] genericBindings; - public PPtr[] pptrCurveMapping; + public List genericBindings; + public List> pptrCurveMapping; public AnimationClipBindingConstant() { } public AnimationClipBindingConstant(ObjectReader reader) { int numBindings = reader.ReadInt32(); - genericBindings = new GenericBinding[numBindings]; + genericBindings = new List(); for (int i = 0; i < numBindings; i++) { - genericBindings[i] = new GenericBinding(reader); + genericBindings.Add(new GenericBinding(reader)); } int numMappings = reader.ReadInt32(); - pptrCurveMapping = new PPtr[numMappings]; + pptrCurveMapping = new List>(); for (int i = 0; i < numMappings; i++) { - pptrCurveMapping[i] = new PPtr(reader); + pptrCurveMapping.Add(new PPtr(reader)); } } @@ -1732,20 +1723,20 @@ namespace AssetStudio public bool m_Legacy; public bool m_Compressed; public bool m_UseHighQualityCurve; - public QuaternionCurve[] m_RotationCurves; - public CompressedAnimationCurve[] m_CompressedRotationCurves; - public Vector3Curve[] m_EulerCurves; - public Vector3Curve[] m_PositionCurves; - public Vector3Curve[] m_ScaleCurves; - public FloatCurve[] m_FloatCurves; - public PPtrCurve[] m_PPtrCurves; + public List m_RotationCurves; + public List m_CompressedRotationCurves; + public List m_EulerCurves; + public List m_PositionCurves; + public List m_ScaleCurves; + public List m_FloatCurves; + public List m_PPtrCurves; public float m_SampleRate; public int m_WrapMode; public AABB m_Bounds; public uint m_MuscleClipSize; public ClipMuscleConstant m_MuscleClip; public AnimationClipBindingConstant m_ClipBindingConstant; - public AnimationEvent[] m_Events; + public List m_Events; public StreamingInfo m_StreamData; private bool hasStreamingInfo = false; @@ -1773,57 +1764,57 @@ namespace AssetStudio } reader.AlignStream(); int numRCurves = reader.ReadInt32(); - m_RotationCurves = new QuaternionCurve[numRCurves]; + m_RotationCurves = new List(); for (int i = 0; i < numRCurves; i++) { - m_RotationCurves[i] = new QuaternionCurve(reader); + m_RotationCurves.Add(new QuaternionCurve(reader)); } int numCRCurves = reader.ReadInt32(); - m_CompressedRotationCurves = new CompressedAnimationCurve[numCRCurves]; + m_CompressedRotationCurves = new List(); for (int i = 0; i < numCRCurves; i++) { - m_CompressedRotationCurves[i] = new CompressedAnimationCurve(reader); + m_CompressedRotationCurves.Add(new CompressedAnimationCurve(reader)); } if (version[0] > 5 || (version[0] == 5 && version[1] >= 3))//5.3 and up { int numEulerCurves = reader.ReadInt32(); - m_EulerCurves = new Vector3Curve[numEulerCurves]; + m_EulerCurves = new List(); for (int i = 0; i < numEulerCurves; i++) { - m_EulerCurves[i] = new Vector3Curve(reader); + m_EulerCurves.Add(new Vector3Curve(reader)); } } int numPCurves = reader.ReadInt32(); - m_PositionCurves = new Vector3Curve[numPCurves]; + m_PositionCurves = new List(); for (int i = 0; i < numPCurves; i++) { - m_PositionCurves[i] = new Vector3Curve(reader); + m_PositionCurves.Add(new Vector3Curve(reader)); } int numSCurves = reader.ReadInt32(); - m_ScaleCurves = new Vector3Curve[numSCurves]; + m_ScaleCurves = new List(); for (int i = 0; i < numSCurves; i++) { - m_ScaleCurves[i] = new Vector3Curve(reader); + m_ScaleCurves.Add(new Vector3Curve(reader)); } int numFCurves = reader.ReadInt32(); - m_FloatCurves = new FloatCurve[numFCurves]; + m_FloatCurves = new List(); for (int i = 0; i < numFCurves; i++) { - m_FloatCurves[i] = new FloatCurve(reader); + m_FloatCurves.Add(new FloatCurve(reader)); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { int numPtrCurves = reader.ReadInt32(); - m_PPtrCurves = new PPtrCurve[numPtrCurves]; + m_PPtrCurves = new List(); for (int i = 0; i < numPtrCurves; i++) { - m_PPtrCurves[i] = new PPtrCurve(reader); + m_PPtrCurves.Add(new PPtrCurve(reader)); } } @@ -1864,10 +1855,10 @@ namespace AssetStudio { var m_AclClipData = reader.ReadUInt8Array(); var aclBindingsCount = reader.ReadInt32(); - var m_AclBindings = new GenericBinding[aclBindingsCount]; + var m_AclBindings = new List(); for (int i = 0; i < aclBindingsCount; i++) { - m_AclBindings[i] = new GenericBinding(reader); + m_AclBindings.Add(new GenericBinding(reader)); } var m_AclRange = new KeyValuePair(reader.ReadSingle(), reader.ReadSingle()); } @@ -1882,10 +1873,10 @@ namespace AssetStudio reader.AlignStream(); } int numEvents = reader.ReadInt32(); - m_Events = new AnimationEvent[numEvents]; + m_Events = new List(); for (int i = 0; i < numEvents; i++) { - m_Events[i] = new AnimationEvent(reader); + m_Events.Add(new AnimationEvent(reader)); } if (version[0] >= 2017) //2017 and up { diff --git a/AssetStudio/Classes/AnimatorController.cs b/AssetStudio/Classes/AnimatorController.cs index 719e57f..3919b2e 100644 --- a/AssetStudio/Classes/AnimatorController.cs +++ b/AssetStudio/Classes/AnimatorController.cs @@ -38,15 +38,15 @@ namespace AssetStudio public class SkeletonMask { - public SkeletonMaskElement[] m_Data; + public List m_Data; public SkeletonMask(ObjectReader reader) { int numElements = reader.ReadInt32(); - m_Data = new SkeletonMaskElement[numElements]; + m_Data = new List(); for (int i = 0; i < numElements; i++) { - m_Data[i] = new SkeletonMaskElement(reader); + m_Data.Add(new SkeletonMaskElement(reader)); } } } @@ -104,7 +104,7 @@ namespace AssetStudio public class TransitionConstant { - public ConditionConstant[] m_ConditionConstantArray; + public List m_ConditionConstantArray; public uint m_DestinationState; public uint m_FullPathID; public uint m_ID; @@ -124,10 +124,10 @@ namespace AssetStudio var version = reader.version; int numConditions = reader.ReadInt32(); - m_ConditionConstantArray = new ConditionConstant[numConditions]; + m_ConditionConstantArray = new List(); for (int i = 0; i < numConditions; i++) { - m_ConditionConstantArray[i] = new ConditionConstant(reader); + m_ConditionConstantArray.Add(new ConditionConstant(reader)); } m_DestinationState = reader.ReadUInt32(); @@ -191,7 +191,7 @@ namespace AssetStudio public float[] m_ChildMagnitudeArray; public Vector2[] m_ChildPairVectorArray; public float[] m_ChildPairAvgMagInvArray; - public MotionNeighborList[] m_ChildNeighborListArray; + public List m_ChildNeighborListArray; public Blend2dDataConstant(ObjectReader reader) { @@ -201,10 +201,10 @@ namespace AssetStudio m_ChildPairAvgMagInvArray = reader.ReadSingleArray(); int numNeighbours = reader.ReadInt32(); - m_ChildNeighborListArray = new MotionNeighborList[numNeighbours]; + m_ChildNeighborListArray = new List(); for (int i = 0; i < numNeighbours; i++) { - m_ChildNeighborListArray[i] = new MotionNeighborList(reader); + m_ChildNeighborListArray.Add(new MotionNeighborList(reader)); } } } @@ -303,7 +303,7 @@ namespace AssetStudio public class BlendTreeConstant { - public BlendTreeNodeConstant[] m_NodeArray; + public List m_NodeArray; public ValueArrayConstant m_BlendEventArrayConstant; public BlendTreeConstant(ObjectReader reader) @@ -311,10 +311,10 @@ namespace AssetStudio var version = reader.version; int numNodes = reader.ReadInt32(); - m_NodeArray = new BlendTreeNodeConstant[numNodes]; + m_NodeArray = new List(); for (int i = 0; i < numNodes; i++) { - m_NodeArray[i] = new BlendTreeNodeConstant(reader); + m_NodeArray.Add(new BlendTreeNodeConstant(reader)); } if (version[0] < 4 || (version[0] == 4 && version[1] < 5)) //4.5 down @@ -327,10 +327,10 @@ namespace AssetStudio public class StateConstant { - public TransitionConstant[] m_TransitionConstantArray; + public List m_TransitionConstantArray; public int[] m_BlendTreeConstantIndexArray; - public LeafInfoConstant[] m_LeafInfoArray; - public BlendTreeConstant[] m_BlendTreeConstantArray; + public List m_LeafInfoArray; + public List m_BlendTreeConstantArray; public uint m_NameID; public uint m_PathID; public uint m_FullPathID; @@ -350,10 +350,10 @@ namespace AssetStudio var version = reader.version; int numTransistions = reader.ReadInt32(); - m_TransitionConstantArray = new TransitionConstant[numTransistions]; + m_TransitionConstantArray = new List(); for (int i = 0; i < numTransistions; i++) { - m_TransitionConstantArray[i] = new TransitionConstant(reader); + m_TransitionConstantArray.Add(new TransitionConstant(reader)); } m_BlendTreeConstantIndexArray = reader.ReadInt32Array(); @@ -361,18 +361,18 @@ namespace AssetStudio if (version[0] < 5 || (version[0] == 5 && version[1] < 2)) //5.2 down { int numInfos = reader.ReadInt32(); - m_LeafInfoArray = new LeafInfoConstant[numInfos]; + m_LeafInfoArray = new List(); for (int i = 0; i < numInfos; i++) { - m_LeafInfoArray[i] = new LeafInfoConstant(reader); + m_LeafInfoArray.Add(new LeafInfoConstant(reader)); } } int numBlends = reader.ReadInt32(); - m_BlendTreeConstantArray = new BlendTreeConstant[numBlends]; + m_BlendTreeConstantArray = new List(); for (int i = 0; i < numBlends; i++) { - m_BlendTreeConstantArray[i] = new BlendTreeConstant(reader); + m_BlendTreeConstantArray.Add(new BlendTreeConstant(reader)); } m_NameID = reader.ReadUInt32(); @@ -428,34 +428,34 @@ namespace AssetStudio public class SelectorTransitionConstant { public uint m_Destination; - public ConditionConstant[] m_ConditionConstantArray; + public List m_ConditionConstantArray; public SelectorTransitionConstant(ObjectReader reader) { m_Destination = reader.ReadUInt32(); int numConditions = reader.ReadInt32(); - m_ConditionConstantArray = new ConditionConstant[numConditions]; + m_ConditionConstantArray = new List(); for (int i = 0; i < numConditions; i++) { - m_ConditionConstantArray[i] = new ConditionConstant(reader); + m_ConditionConstantArray.Add(new ConditionConstant(reader)); } } } public class SelectorStateConstant { - public SelectorTransitionConstant[] m_TransitionConstantArray; + public List m_TransitionConstantArray; public uint m_FullPathID; public bool m_isEntry; public SelectorStateConstant(ObjectReader reader) { int numTransitions = reader.ReadInt32(); - m_TransitionConstantArray = new SelectorTransitionConstant[numTransitions]; + m_TransitionConstantArray = new List(); for (int i = 0; i < numTransitions; i++) { - m_TransitionConstantArray[i] = new SelectorTransitionConstant(reader); + m_TransitionConstantArray.Add(new SelectorTransitionConstant(reader)); } m_FullPathID = reader.ReadUInt32(); @@ -466,9 +466,9 @@ namespace AssetStudio public class StateMachineConstant { - public StateConstant[] m_StateConstantArray; - public TransitionConstant[] m_AnyStateTransitionConstantArray; - public SelectorStateConstant[] m_SelectorStateConstantArray; + public List m_StateConstantArray; + public List m_AnyStateTransitionConstantArray; + public List m_SelectorStateConstantArray; public uint m_DefaultState; public uint m_MotionSetCount; @@ -477,26 +477,26 @@ namespace AssetStudio var version = reader.version; int numStates = reader.ReadInt32(); - m_StateConstantArray = new StateConstant[numStates]; + m_StateConstantArray = new List(); for (int i = 0; i < numStates; i++) { - m_StateConstantArray[i] = new StateConstant(reader); + m_StateConstantArray.Add(new StateConstant(reader)); } int numAnyStates = reader.ReadInt32(); - m_AnyStateTransitionConstantArray = new TransitionConstant[numAnyStates]; + m_AnyStateTransitionConstantArray = new List(); for (int i = 0; i < numAnyStates; i++) { - m_AnyStateTransitionConstantArray[i] = new TransitionConstant(reader); + m_AnyStateTransitionConstantArray.Add(new TransitionConstant(reader)); } if (version[0] >= 5) //5.0 and up { int numSelectors = reader.ReadInt32(); - m_SelectorStateConstantArray = new SelectorStateConstant[numSelectors]; + m_SelectorStateConstantArray = new List(); for (int i = 0; i < numSelectors; i++) { - m_SelectorStateConstantArray[i] = new SelectorStateConstant(reader); + m_SelectorStateConstantArray.Add(new SelectorStateConstant(reader)); } } @@ -533,21 +533,11 @@ namespace AssetStudio } else { - int numPosValues = reader.ReadInt32(); - m_PositionValues = new Vector3[numPosValues]; - for (int i = 0; i < numPosValues; i++) - { - m_PositionValues[i] = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? reader.ReadVector3() : (Vector3)reader.ReadVector4(); //5.4 and up - } + m_PositionValues = reader.ReadVector3Array(); m_QuaternionValues = reader.ReadVector4Array(); - int numScaleValues = reader.ReadInt32(); - m_ScaleValues = new Vector3[numScaleValues]; - for (int i = 0; i < numScaleValues; i++) - { - m_ScaleValues[i] = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? reader.ReadVector3() : (Vector3)reader.ReadVector4(); //5.4 and up - } + m_ScaleValues = reader.ReadVector3Array(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 5)) //5.5 and up { @@ -562,25 +552,25 @@ namespace AssetStudio public class ControllerConstant { - public LayerConstant[] m_LayerArray; - public StateMachineConstant[] m_StateMachineArray; + public List m_LayerArray; + public List m_StateMachineArray; public ValueArrayConstant m_Values; public ValueArray m_DefaultValues; public ControllerConstant(ObjectReader reader) { int numLayers = reader.ReadInt32(); - m_LayerArray = new LayerConstant[numLayers]; + m_LayerArray = new List(); for (int i = 0; i < numLayers; i++) { - m_LayerArray[i] = new LayerConstant(reader); + m_LayerArray.Add(new LayerConstant(reader)); } int numStates = reader.ReadInt32(); - m_StateMachineArray = new StateMachineConstant[numStates]; + m_StateMachineArray = new List(); for (int i = 0; i < numStates; i++) { - m_StateMachineArray[i] = new StateMachineConstant(reader); + m_StateMachineArray.Add(new StateMachineConstant(reader)); } m_Values = new ValueArrayConstant(reader); @@ -591,7 +581,7 @@ namespace AssetStudio public sealed class AnimatorController : RuntimeAnimatorController { public Dictionary m_TOS; - public PPtr[] m_AnimationClips; + public List> m_AnimationClips; public AnimatorController(ObjectReader reader) : base(reader) { @@ -599,17 +589,17 @@ namespace AssetStudio var m_Controller = new ControllerConstant(reader); int tosSize = reader.ReadInt32(); - m_TOS = new Dictionary(tosSize); + m_TOS = new Dictionary(); for (int i = 0; i < tosSize; i++) { m_TOS.Add(reader.ReadUInt32(), reader.ReadAlignedString()); } int numClips = reader.ReadInt32(); - m_AnimationClips = new PPtr[numClips]; + m_AnimationClips = new List>(); for (int i = 0; i < numClips; i++) { - m_AnimationClips[i] = new PPtr(reader); + m_AnimationClips.Add(new PPtr(reader)); } } } diff --git a/AssetStudio/Classes/AnimatorOverrideController.cs b/AssetStudio/Classes/AnimatorOverrideController.cs index c89e7a2..6dbcb0c 100644 --- a/AssetStudio/Classes/AnimatorOverrideController.cs +++ b/AssetStudio/Classes/AnimatorOverrideController.cs @@ -20,17 +20,17 @@ namespace AssetStudio public sealed class AnimatorOverrideController : RuntimeAnimatorController { public PPtr m_Controller; - public AnimationClipOverride[] m_Clips; + public List m_Clips; public AnimatorOverrideController(ObjectReader reader) : base(reader) { m_Controller = new PPtr(reader); int numOverrides = reader.ReadInt32(); - m_Clips = new AnimationClipOverride[numOverrides]; + m_Clips = new List(); for (int i = 0; i < numOverrides; i++) { - m_Clips[i] = new AnimationClipOverride(reader); + m_Clips.Add(new AnimationClipOverride(reader)); } } } diff --git a/AssetStudio/Classes/AssetBundle.cs b/AssetStudio/Classes/AssetBundle.cs index 247575c..756c74c 100644 --- a/AssetStudio/Classes/AssetBundle.cs +++ b/AssetStudio/Classes/AssetBundle.cs @@ -22,64 +22,24 @@ namespace AssetStudio public sealed class AssetBundle : NamedObject { - public PPtr[] m_PreloadTable; - public KeyValuePair[] m_Container; - //public AssetInfo m_MainAsset; - //public uint m_RuntimeComaptability; - //public string m_AssetBundleName; - //public string[] m_Dependencies; - //public bool m_IsStreamedSceneAssetBundle; - //public int m_ExplicitDataLayout; - //public int m_PathFlags; - //public KeyValuePair[] m_SceneHashes; + public List> m_PreloadTable; + public List> m_Container; public AssetBundle(ObjectReader reader) : base(reader) { var m_PreloadTableSize = reader.ReadInt32(); - m_PreloadTable = new PPtr[m_PreloadTableSize]; + m_PreloadTable = new List>(); for (int i = 0; i < m_PreloadTableSize; i++) { - m_PreloadTable[i] = new PPtr(reader); + m_PreloadTable.Add(new PPtr(reader)); } var m_ContainerSize = reader.ReadInt32(); - m_Container = new KeyValuePair[m_ContainerSize]; + m_Container = new List>(); for (int i = 0; i < m_ContainerSize; i++) { - m_Container[i] = new KeyValuePair(reader.ReadAlignedString(), new AssetInfo(reader)); + m_Container.Add(new KeyValuePair(reader.ReadAlignedString(), new AssetInfo(reader))); } - - //if (reader.Game.Type.IsMhyGroup()) - //{ - // m_MainAsset = new AssetInfo(reader); - // m_RuntimeComaptability = reader.ReadUInt32(); - // m_AssetBundleName = reader.ReadAlignedString(); - // var dependencyCount = reader.ReadInt32(); - // m_Dependencies = new string[dependencyCount]; - // for (int k = 0; k < dependencyCount; k++) - // { - // m_Dependencies[k] = reader.ReadAlignedString(); - // } - // if (reader.Game.Type.IsGIGroup()) - // { - // m_IsStreamedSceneAssetBundle = reader.ReadBoolean(); - // reader.AlignStream(); - // if (reader.Game.Type.IsGICB3() || reader.Game.Type.IsGI()) - // { - // m_ExplicitDataLayout = reader.ReadInt32(); - // } - // m_PathFlags = reader.ReadInt32(); - // if (reader.Game.Type.IsGI()) - // { - // var sceneHashCount = reader.ReadInt32(); - // m_SceneHashes = new KeyValuePair[sceneHashCount]; - // for (int l = 0; l < sceneHashCount; l++) - // { - // m_SceneHashes[l] = new KeyValuePair(reader.ReadAlignedString(), reader.ReadAlignedString()); - // } - // } - // } - //} } } } diff --git a/AssetStudio/Classes/Avatar.cs b/AssetStudio/Classes/Avatar.cs index 2b00923..ee61b88 100644 --- a/AssetStudio/Classes/Avatar.cs +++ b/AssetStudio/Classes/Avatar.cs @@ -66,27 +66,26 @@ namespace AssetStudio public class Skeleton { - public Node[] m_Node; + public List m_Node; public uint[] m_ID; - public Axes[] m_AxesArray; - + public List m_AxesArray; public Skeleton(ObjectReader reader) { int numNodes = reader.ReadInt32(); - m_Node = new Node[numNodes]; + m_Node = new List(); for (int i = 0; i < numNodes; i++) { - m_Node[i] = new Node(reader); + m_Node.Add(new Node(reader)); } m_ID = reader.ReadUInt32Array(); int numAxes = reader.ReadInt32(); - m_AxesArray = new Axes[numAxes]; + m_AxesArray = new List(); for (int i = 0; i < numAxes; i++) { - m_AxesArray[i] = new Axes(reader); + m_AxesArray.Add(new Axes(reader)); } } } @@ -97,12 +96,7 @@ namespace AssetStudio public SkeletonPose(ObjectReader reader) { - int numXforms = reader.ReadInt32(); - m_X = new XForm[numXforms]; - for (int i = 0; i < numXforms; i++) - { - m_X[i] = reader.ReadXForm(reader.version); - } + m_X = reader.ReadXFormArray(); } } @@ -124,7 +118,7 @@ namespace AssetStudio public Handle(ObjectReader reader) { - m_X = reader.ReadXForm(reader.version); + m_X = reader.ReadXForm(); m_ParentHumanIndex = reader.ReadUInt32(); m_ID = reader.ReadUInt32(); } @@ -144,7 +138,7 @@ namespace AssetStudio public Collider(ObjectReader reader) { - m_X = reader.ReadXForm(reader.version); + m_X = reader.ReadXForm(); m_Type = reader.ReadUInt32(); m_XMotionType = reader.ReadUInt32(); m_YMotionType = reader.ReadUInt32(); @@ -163,8 +157,8 @@ namespace AssetStudio public SkeletonPose m_SkeletonPose; public Hand m_LeftHand; public Hand m_RightHand; - public Handle[] m_Handles; - public Collider[] m_ColliderArray; + public List m_Handles; + public List m_ColliderArray; public int[] m_HumanBoneIndex; public float[] m_HumanBoneMass; public int[] m_ColliderIndex; @@ -183,7 +177,7 @@ namespace AssetStudio public Human(ObjectReader reader) { var version = reader.version; - m_RootX = reader.ReadXForm(reader.version); + m_RootX = reader.ReadXForm(); m_Skeleton = new Skeleton(reader); m_SkeletonPose = new SkeletonPose(reader); m_LeftHand = new Hand(reader); @@ -192,17 +186,17 @@ namespace AssetStudio if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { int numHandles = reader.ReadInt32(); - m_Handles = new Handle[numHandles]; + m_Handles = new List(); for (int i = 0; i < numHandles; i++) { - m_Handles[i] = new Handle(reader); + m_Handles.Add(new Handle(reader)); } int numColliders = reader.ReadInt32(); - m_ColliderArray = new Collider[numColliders]; + m_ColliderArray = new List(numColliders); for (int i = 0; i < numColliders; i++) { - m_ColliderArray[i] = new Collider(reader); + m_ColliderArray.Add(new Collider(reader)); } } @@ -271,7 +265,7 @@ namespace AssetStudio } m_RootMotionBoneIndex = reader.ReadInt32(); - m_RootMotionBoneX = reader.ReadXForm(reader.version); + m_RootMotionBoneX = reader.ReadXForm(); if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { @@ -295,7 +289,7 @@ namespace AssetStudio m_Avatar = new AvatarConstant(reader); int numTOS = reader.ReadInt32(); - m_TOS = new Dictionary(numTOS); + m_TOS = new Dictionary(); for (int i = 0; i < numTOS; i++) { m_TOS.Add(reader.ReadUInt32(), reader.ReadAlignedString()); diff --git a/AssetStudio/Classes/GameObject.cs b/AssetStudio/Classes/GameObject.cs index 6dc9f13..18903b3 100644 --- a/AssetStudio/Classes/GameObject.cs +++ b/AssetStudio/Classes/GameObject.cs @@ -9,7 +9,7 @@ namespace AssetStudio { public sealed class GameObject : EditorExtension { - public PPtr[] m_Components; + public List> m_Components; public string m_Name; public Transform m_Transform; @@ -23,14 +23,14 @@ namespace AssetStudio public GameObject(ObjectReader reader) : base(reader) { int m_Component_size = reader.ReadInt32(); - m_Components = new PPtr[m_Component_size]; + m_Components = new List>(); for (int i = 0; i < m_Component_size; i++) { if ((version[0] == 5 && version[1] < 5) || version[0] < 5) //5.5 down { int first = reader.ReadInt32(); } - m_Components[i] = new PPtr(reader); + m_Components.Add(new PPtr(reader)); } var m_Layer = reader.ReadInt32(); diff --git a/AssetStudio/Classes/IndexObject.cs b/AssetStudio/Classes/IndexObject.cs index cfb5b71..9c838b0 100644 --- a/AssetStudio/Classes/IndexObject.cs +++ b/AssetStudio/Classes/IndexObject.cs @@ -17,17 +17,17 @@ namespace AssetStudio public sealed class IndexObject : NamedObject { public int Count; - public KeyValuePair[] AssetMap; + public List> AssetMap; public override string Name => "IndexObject"; public IndexObject(ObjectReader reader) : base(reader) { Count = reader.ReadInt32(); - AssetMap = new KeyValuePair[Count]; + AssetMap = new List>(); for (int i = 0; i < Count; i++) { - AssetMap[i] = new KeyValuePair(reader.ReadAlignedString(), new Index(reader)); + AssetMap.Add(new KeyValuePair(reader.ReadAlignedString(), new Index(reader))); } } } diff --git a/AssetStudio/Classes/Material.cs b/AssetStudio/Classes/Material.cs index 124a24d..4569d52 100644 --- a/AssetStudio/Classes/Material.cs +++ b/AssetStudio/Classes/Material.cs @@ -22,44 +22,44 @@ namespace AssetStudio public class UnityPropertySheet { - public KeyValuePair[] m_TexEnvs; - public KeyValuePair[] m_Ints; - public KeyValuePair[] m_Floats; - public KeyValuePair[] m_Colors; + public List> m_TexEnvs; + public List> m_Ints; + public List> m_Floats; + public List> m_Colors; public UnityPropertySheet(ObjectReader reader) { var version = reader.version; int m_TexEnvsSize = reader.ReadInt32(); - m_TexEnvs = new KeyValuePair[m_TexEnvsSize]; + m_TexEnvs = new List>(); for (int i = 0; i < m_TexEnvsSize; i++) { - m_TexEnvs[i] = new(reader.ReadAlignedString(), new UnityTexEnv(reader)); + m_TexEnvs.Add(new(reader.ReadAlignedString(), new UnityTexEnv(reader))); } if (version[0] >= 2021) //2021.1 and up { int m_IntsSize = reader.ReadInt32(); - m_Ints = new KeyValuePair[m_IntsSize]; + m_Ints = new List>(); for (int i = 0; i < m_IntsSize; i++) { - m_Ints[i] = new(reader.ReadAlignedString(), reader.ReadInt32()); + m_Ints.Add(new(reader.ReadAlignedString(), reader.ReadInt32())); } } int m_FloatsSize = reader.ReadInt32(); - m_Floats = new KeyValuePair[m_FloatsSize]; + m_Floats = new List>(); for (int i = 0; i < m_FloatsSize; i++) { - m_Floats[i] = new(reader.ReadAlignedString(), reader.ReadSingle()); + m_Floats.Add(new(reader.ReadAlignedString(), reader.ReadSingle())); } int m_ColorsSize = reader.ReadInt32(); - m_Colors = new KeyValuePair[m_ColorsSize]; + m_Colors = new List>(); for (int i = 0; i < m_ColorsSize; i++) { - m_Colors[i] = new(reader.ReadAlignedString(), reader.ReadColor4()); + m_Colors.Add(new(reader.ReadAlignedString(), reader.ReadColor4())); } } } diff --git a/AssetStudio/Classes/Mesh.cs b/AssetStudio/Classes/Mesh.cs index 451a034..64ce81e 100644 --- a/AssetStudio/Classes/Mesh.cs +++ b/AssetStudio/Classes/Mesh.cs @@ -12,7 +12,7 @@ namespace AssetStudio public Vector3 m_Min; public Vector3 m_Max; - public MinMaxAABB(EndianBinaryReader reader) + public MinMaxAABB(ObjectReader reader) { m_Min = reader.ReadVector3(); m_Max = reader.ReadVector3(); @@ -124,8 +124,8 @@ namespace AssetStudio { public uint m_CurrentChannels; public uint m_VertexCount; - public ChannelInfo[] m_Channels; - public StreamInfo[] m_Streams; + public List m_Channels; + public List m_Streams; public byte[] m_DataSize; public VertexData(ObjectReader reader) @@ -142,25 +142,18 @@ namespace AssetStudio if (version[0] >= 4) //4.0 and up { var m_ChannelsSize = reader.ReadInt32(); - m_Channels = new ChannelInfo[m_ChannelsSize]; + m_Channels = new List(); for (int i = 0; i < m_ChannelsSize; i++) { - m_Channels[i] = new ChannelInfo(reader); + m_Channels.Add(new ChannelInfo(reader)); } } if (version[0] < 5) //5.0 down { - if (version[0] < 4) - { - m_Streams = new StreamInfo[4]; - } - else - { - m_Streams = new StreamInfo[reader.ReadInt32()]; - } - - for (int i = 0; i < m_Streams.Length; i++) + var numStreams = version[0] < 4 ? 4 : reader.ReadInt32(); + m_Streams = new List(); + for (int i = 0; i < numStreams; i++) { m_Streams[i] = new StreamInfo(reader); } @@ -182,13 +175,13 @@ namespace AssetStudio private void GetStreams(int[] version) { var streamCount = m_Channels.Max(x => x.stream) + 1; - m_Streams = new StreamInfo[streamCount]; + m_Streams = new List(); uint offset = 0; for (int s = 0; s < streamCount; s++) { uint chnMask = 0; uint stride = 0; - for (int chn = 0; chn < m_Channels.Length; chn++) + for (int chn = 0; chn < m_Channels.Count; chn++) { var m_Channel = m_Channels[chn]; if (m_Channel.stream == s) @@ -200,14 +193,14 @@ namespace AssetStudio } } } - m_Streams[s] = new StreamInfo + m_Streams.Add(new StreamInfo { channelMask = chnMask, offset = offset, stride = stride, dividerOp = 0, frequency = 0 - }; + }); offset += m_VertexCount * stride; //static size_t AlignStreamSize (size_t size) { return (size + (kVertexStreamAlign-1)) & ~(kVertexStreamAlign-1); } offset = (offset + (16u - 1u)) & ~(16u - 1u); @@ -216,12 +209,12 @@ namespace AssetStudio private void GetChannels(int[] version) { - m_Channels = new ChannelInfo[6]; + m_Channels = new List(6); for (int i = 0; i < 6; i++) { - m_Channels[i] = new ChannelInfo(); + m_Channels.Add(new ChannelInfo()); } - for (var s = 0; s < m_Streams.Length; s++) + for (var s = 0; s < m_Streams.Count; s++) { var m_Stream = m_Streams[s]; var channelMask = new BitArray(new[] { (int)m_Stream.channelMask }); @@ -345,9 +338,9 @@ namespace AssetStudio public class BlendShapeData { - public BlendShapeVertex[] vertices; - public MeshBlendShape[] shapes; - public MeshBlendShapeChannel[] channels; + public List vertices; + public List shapes; + public List channels; public float[] fullWeights; public BlendShapeData(ObjectReader reader) @@ -357,24 +350,24 @@ namespace AssetStudio if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { int numVerts = reader.ReadInt32(); - vertices = new BlendShapeVertex[numVerts]; + vertices = new List(); for (int i = 0; i < numVerts; i++) { - vertices[i] = new BlendShapeVertex(reader); + vertices.Add(new BlendShapeVertex(reader)); } int numShapes = reader.ReadInt32(); - shapes = new MeshBlendShape[numShapes]; + shapes = new List(); for (int i = 0; i < numShapes; i++) { - shapes[i] = new MeshBlendShape(reader); + shapes.Add(new MeshBlendShape(reader)); } int numChannels = reader.ReadInt32(); - channels = new MeshBlendShapeChannel[numChannels]; + channels = new List(); for (int i = 0; i < numChannels; i++) { - channels[i] = new MeshBlendShapeChannel(reader); + channels.Add(new MeshBlendShapeChannel(reader)); } fullWeights = reader.ReadSingleArray(); @@ -382,17 +375,17 @@ namespace AssetStudio else { var m_ShapesSize = reader.ReadInt32(); - var m_Shapes = new MeshBlendShape[m_ShapesSize]; + var m_Shapes = new List(); for (int i = 0; i < m_ShapesSize; i++) { - m_Shapes[i] = new MeshBlendShape(reader); + m_Shapes.Add(new MeshBlendShape(reader)); } reader.AlignStream(); var m_ShapeVerticesSize = reader.ReadInt32(); - var m_ShapeVertices = new BlendShapeVertex[m_ShapeVerticesSize]; //MeshBlendShapeVertex + var m_ShapeVertices = new List(); //MeshBlendShapeVertex for (int i = 0; i < m_ShapeVerticesSize; i++) { - m_ShapeVertices[i] = new BlendShapeVertex(reader); + m_ShapeVertices.Add(new BlendShapeVertex(reader)); } } } @@ -449,14 +442,14 @@ namespace AssetStudio public sealed class Mesh : NamedObject { private bool m_Use16BitIndices = true; - public SubMesh[] m_SubMeshes; + public List m_SubMeshes; private uint[] m_IndexBuffer; public BlendShapeData m_Shapes; public Matrix4x4[] m_BindPose; public uint[] m_BoneNameHashes; public int m_VertexCount; public float[] m_Vertices; - public BoneWeights4[] m_Skin; + public List m_Skin; public float[] m_Normals; public float[] m_Colors; public float[] m_UV0; @@ -502,10 +495,10 @@ namespace AssetStudio } int m_SubMeshesSize = reader.ReadInt32(); - m_SubMeshes = new SubMesh[m_SubMeshesSize]; + m_SubMeshes = new List(); for (int i = 0; i < m_SubMeshesSize; i++) { - m_SubMeshes[i] = new SubMesh(reader); + m_SubMeshes.Add(new SubMesh(reader)); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 1)) //4.1 and up @@ -525,10 +518,10 @@ namespace AssetStudio if (version[0] >= 2019) //2019 and up { var m_BonesAABBSize = reader.ReadInt32(); - var m_BonesAABB = new MinMaxAABB[m_BonesAABBSize]; + var m_BonesAABB = new List(); for (int i = 0; i < m_BonesAABBSize; i++) { - m_BonesAABB[i] = new MinMaxAABB(reader); + m_BonesAABB.Add(new MinMaxAABB(reader)); } var m_VariableBoneCountWeights = reader.ReadUInt32Array(); @@ -594,10 +587,11 @@ namespace AssetStudio m_VertexCount = reader.ReadInt32(); m_Vertices = reader.ReadSingleArray(m_VertexCount * 3); //Vector3 - m_Skin = new BoneWeights4[reader.ReadInt32()]; - for (int s = 0; s < m_Skin.Length; s++) + var skinNum = reader.ReadInt32(); + m_Skin = new List(); + for (int s = 0; s < skinNum; s++) { - m_Skin[s] = new BoneWeights4(reader); + m_Skin.Add(new BoneWeights4(reader)); } m_BindPose = reader.ReadMatrixArray(); @@ -633,10 +627,11 @@ namespace AssetStudio { if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { - m_Skin = new BoneWeights4[reader.ReadInt32()]; - for (int s = 0; s < m_Skin.Length; s++) + var skinNum = reader.ReadInt32(); + m_Skin = new List(); + for (int s = 0; s < skinNum; s++) { - m_Skin[s] = new BoneWeights4(reader); + m_Skin.Add(new BoneWeights4(reader)); } } @@ -763,7 +758,7 @@ namespace AssetStudio { m_VertexCount = (int)m_VertexData.m_VertexCount; - for (var chn = 0; chn < m_VertexData.m_Channels.Length; chn++) + for (var chn = 0; chn < m_VertexData.m_Channels.Count; chn++) { var m_Channel = m_VertexData.m_Channels[chn]; if (m_Channel.dimension > 0) @@ -1184,10 +1179,10 @@ namespace AssetStudio private void InitMSkin() { - m_Skin = new BoneWeights4[m_VertexCount]; + m_Skin = new List(); for (int i = 0; i < m_VertexCount; i++) { - m_Skin[i] = new BoneWeights4(); + m_Skin.Add(new BoneWeights4()); } } diff --git a/AssetStudio/Classes/MiHoYoBinData.cs b/AssetStudio/Classes/MiHoYoBinData.cs index 7344f46..82eb6aa 100644 --- a/AssetStudio/Classes/MiHoYoBinData.cs +++ b/AssetStudio/Classes/MiHoYoBinData.cs @@ -24,8 +24,7 @@ namespace AssetStudio public MiHoYoBinData(ObjectReader reader) : base(reader) { - var length = reader.ReadInt32(); - RawData = reader.ReadBytes(length); + RawData = reader.ReadUInt8Array(); } public string AsString => Type switch diff --git a/AssetStudio/Classes/Renderer.cs b/AssetStudio/Classes/Renderer.cs index 3f0ce2e..fd8156f 100644 --- a/AssetStudio/Classes/Renderer.cs +++ b/AssetStudio/Classes/Renderer.cs @@ -21,7 +21,7 @@ namespace AssetStudio { public static bool Parsable; - public PPtr[] m_Materials; + public List> m_Materials; public StaticBatchInfo m_StaticBatchInfo; public uint[] m_SubsetIndices; private bool isNewHeader = false; @@ -165,10 +165,10 @@ namespace AssetStudio var m_ShaderLODDistanceRatio = reader.ReadSingle(); } var m_MaterialsSize = reader.ReadInt32(); - m_Materials = new PPtr[m_MaterialsSize]; + m_Materials = new List>(); for (int i = 0; i < m_MaterialsSize; i++) { - m_Materials[i] = new PPtr(reader); + m_Materials.Add(new PPtr(reader)); } if (version[0] < 3) //3.0 down diff --git a/AssetStudio/Classes/ResourceManager.cs b/AssetStudio/Classes/ResourceManager.cs index 05f159b..5d74ff0 100644 --- a/AssetStudio/Classes/ResourceManager.cs +++ b/AssetStudio/Classes/ResourceManager.cs @@ -4,15 +4,15 @@ namespace AssetStudio { public class ResourceManager : Object { - public KeyValuePair>[] m_Container; + public List>> m_Container; public ResourceManager(ObjectReader reader) : base(reader) { var m_ContainerSize = reader.ReadInt32(); - m_Container = new KeyValuePair>[m_ContainerSize]; + m_Container = new List>>(); for (int i = 0; i < m_ContainerSize; i++) { - m_Container[i] = new KeyValuePair>(reader.ReadAlignedString(), new PPtr(reader)); + m_Container.Add(new KeyValuePair>(reader.ReadAlignedString(), new PPtr(reader))); } } } diff --git a/AssetStudio/Classes/Shader.cs b/AssetStudio/Classes/Shader.cs index 4dc45eb..384a20f 100644 --- a/AssetStudio/Classes/Shader.cs +++ b/AssetStudio/Classes/Shader.cs @@ -18,8 +18,8 @@ namespace AssetStudio public class StructParameter { - public MatrixParameter[] m_MatrixParams; - public VectorParameter[] m_VectorParams; + public List m_MatrixParams; + public List m_VectorParams; public StructParameter(EndianBinaryReader reader) { @@ -29,17 +29,17 @@ namespace AssetStudio var m_StructSize = reader.ReadInt32(); int numVectorParams = reader.ReadInt32(); - m_VectorParams = new VectorParameter[numVectorParams]; + m_VectorParams = new List(); for (int i = 0; i < numVectorParams; i++) { - m_VectorParams[i] = new VectorParameter(reader); + m_VectorParams.Add(new VectorParameter(reader)); } int numMatrixParams = reader.ReadInt32(); - m_MatrixParams = new MatrixParameter[numMatrixParams]; + m_MatrixParams = new List(); for (int i = 0; i < numMatrixParams; i++) { - m_MatrixParams[i] = new MatrixParameter(reader); + m_MatrixParams.Add(new MatrixParameter(reader)); } } } @@ -113,15 +113,15 @@ namespace AssetStudio public class SerializedProperties { - public SerializedProperty[] m_Props; + public List m_Props; public SerializedProperties(EndianBinaryReader reader) { int numProps = reader.ReadInt32(); - m_Props = new SerializedProperty[numProps]; + m_Props = new List(); for (int i = 0; i < numProps; i++) { - m_Props[i] = new SerializedProperty(reader); + m_Props.Add(new SerializedProperty(reader)); } } } @@ -206,7 +206,7 @@ namespace AssetStudio public class SerializedShaderState { public string m_Name; - public SerializedShaderRTBlendState[] rtBlend; + public List rtBlend; public bool rtSeparateBlend; public SerializedShaderFloatValue zClip; public SerializedShaderFloatValue zTest; @@ -237,10 +237,10 @@ namespace AssetStudio var version = reader.version; m_Name = reader.ReadAlignedString(); - rtBlend = new SerializedShaderRTBlendState[8]; + rtBlend = new List(); for (int i = 0; i < 8; i++) { - rtBlend[i] = new SerializedShaderRTBlendState(reader); + rtBlend.Add(new SerializedShaderRTBlendState(reader)); } rtSeparateBlend = reader.ReadBoolean(); reader.AlignStream(); @@ -291,16 +291,16 @@ namespace AssetStudio public class ParserBindChannels { - public ShaderBindChannel[] m_Channels; + public List m_Channels; public uint m_SourceMap; public ParserBindChannels(EndianBinaryReader reader) { int numChannels = reader.ReadInt32(); - m_Channels = new ShaderBindChannel[numChannels]; + m_Channels = new List(); for (int i = 0; i < numChannels; i++) { - m_Channels[i] = new ShaderBindChannel(reader); + m_Channels.Add(new ShaderBindChannel(reader)); } reader.AlignStream(); @@ -391,9 +391,9 @@ namespace AssetStudio public class ConstantBuffer { public int m_NameIndex; - public MatrixParameter[] m_MatrixParams; - public VectorParameter[] m_VectorParams; - public StructParameter[] m_StructParams; + public List m_MatrixParams; + public List m_VectorParams; + public List m_StructParams; public int m_Size; public bool m_IsPartialCB; @@ -404,25 +404,25 @@ namespace AssetStudio m_NameIndex = reader.ReadInt32(); int numMatrixParams = reader.ReadInt32(); - m_MatrixParams = new MatrixParameter[numMatrixParams]; + m_MatrixParams = new List(); for (int i = 0; i < numMatrixParams; i++) { - m_MatrixParams[i] = new MatrixParameter(reader); + m_MatrixParams.Add(new MatrixParameter(reader)); } int numVectorParams = reader.ReadInt32(); - m_VectorParams = new VectorParameter[numVectorParams]; + m_VectorParams = new List(); for (int i = 0; i < numVectorParams; i++) { - m_VectorParams[i] = new VectorParameter(reader); + m_VectorParams.Add(new VectorParameter(reader)); } if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3)) //2017.3 and up { int numStructParams = reader.ReadInt32(); - m_StructParams = new StructParameter[numStructParams]; + m_StructParams = new List(); for (int i = 0; i < numStructParams; i++) { - m_StructParams[i] = new StructParameter(reader); + m_StructParams.Add(new StructParameter(reader)); } } m_Size = reader.ReadInt32(); @@ -492,71 +492,71 @@ namespace AssetStudio public class SerializedProgramParameters { - public VectorParameter[] m_VectorParams; - public MatrixParameter[] m_MatrixParams; - public TextureParameter[] m_TextureParams; - public BufferBinding[] m_BufferParams; - public ConstantBuffer[] m_ConstantBuffers; - public BufferBinding[] m_ConstantBufferBindings; - public UAVParameter[] m_UAVParams; - public SamplerParameter[] m_Samplers; + public List m_VectorParams; + public List m_MatrixParams; + public List m_TextureParams; + public List m_BufferParams; + public List m_ConstantBuffers; + public List m_ConstantBufferBindings; + public List m_UAVParams; + public List m_Samplers; public SerializedProgramParameters(ObjectReader reader) { int numVectorParams = reader.ReadInt32(); - m_VectorParams = new VectorParameter[numVectorParams]; + m_VectorParams = new List(); for (int i = 0; i < numVectorParams; i++) { - m_VectorParams[i] = new VectorParameter(reader); + m_VectorParams.Add(new VectorParameter(reader)); } int numMatrixParams = reader.ReadInt32(); - m_MatrixParams = new MatrixParameter[numMatrixParams]; + m_MatrixParams = new List(); for (int i = 0; i < numMatrixParams; i++) { - m_MatrixParams[i] = new MatrixParameter(reader); + m_MatrixParams.Add(new MatrixParameter(reader)); } int numTextureParams = reader.ReadInt32(); - m_TextureParams = new TextureParameter[numTextureParams]; + m_TextureParams = new List(); for (int i = 0; i < numTextureParams; i++) { - m_TextureParams[i] = new TextureParameter(reader); + m_TextureParams.Add(new TextureParameter(reader)); } int numBufferParams = reader.ReadInt32(); - m_BufferParams = new BufferBinding[numBufferParams]; + m_BufferParams = new List(); for (int i = 0; i < numBufferParams; i++) { - m_BufferParams[i] = new BufferBinding(reader); + m_BufferParams.Add(new BufferBinding(reader)); } int numConstantBuffers = reader.ReadInt32(); - m_ConstantBuffers = new ConstantBuffer[numConstantBuffers]; + m_ConstantBuffers = new List(); for (int i = 0; i < numConstantBuffers; i++) { - m_ConstantBuffers[i] = new ConstantBuffer(reader); + m_ConstantBuffers.Add(new ConstantBuffer(reader)); } int numConstantBufferBindings = reader.ReadInt32(); - m_ConstantBufferBindings = new BufferBinding[numConstantBufferBindings]; + m_ConstantBufferBindings = new List(); for (int i = 0; i < numConstantBufferBindings; i++) { - m_ConstantBufferBindings[i] = new BufferBinding(reader); + m_ConstantBufferBindings.Add(new BufferBinding(reader)); } int numUAVParams = reader.ReadInt32(); - m_UAVParams = new UAVParameter[numUAVParams]; + m_UAVParams = new List(); for (int i = 0; i < numUAVParams; i++) { - m_UAVParams[i] = new UAVParameter(reader); + m_UAVParams.Add(new UAVParameter(reader)); } int numSamplers = reader.ReadInt32(); - m_Samplers = new SamplerParameter[numSamplers]; + m_Samplers = new List(); for (int i = 0; i < numSamplers; i++) { - m_Samplers[i] = new SamplerParameter(reader); + m_Samplers.Add(new SamplerParameter(reader)); } } } @@ -569,14 +569,14 @@ namespace AssetStudio public sbyte m_ShaderHardwareTier; public ShaderGpuProgramType m_GpuProgramType; public SerializedProgramParameters m_Parameters; - public VectorParameter[] m_VectorParams; - public MatrixParameter[] m_MatrixParams; - public TextureParameter[] m_TextureParams; - public BufferBinding[] m_BufferParams; - public ConstantBuffer[] m_ConstantBuffers; - public BufferBinding[] m_ConstantBufferBindings; - public UAVParameter[] m_UAVParams; - public SamplerParameter[] m_Samplers; + public List m_VectorParams; + public List m_MatrixParams; + public List m_TextureParams; + public List m_BufferParams; + public List m_ConstantBuffers; + public List m_ConstantBufferBindings; + public List m_UAVParams; + public List m_Samplers; public static bool HasGlobalLocalKeywordIndices(SerializedType type) => type.Match("E99740711222CD922E9A6F92FF1EB07A", "450A058C218DAF000647948F2F59DA6D"); public static bool HasInstancedStructuredBuffers(SerializedType type) => type.Match("E99740711222CD922E9A6F92FF1EB07A"); @@ -630,61 +630,61 @@ namespace AssetStudio else { int numVectorParams = reader.ReadInt32(); - m_VectorParams = new VectorParameter[numVectorParams]; + m_VectorParams = new List(); for (int i = 0; i < numVectorParams; i++) { - m_VectorParams[i] = new VectorParameter(reader); + m_VectorParams.Add(new VectorParameter(reader)); } int numMatrixParams = reader.ReadInt32(); - m_MatrixParams = new MatrixParameter[numMatrixParams]; + m_MatrixParams = new List(); for (int i = 0; i < numMatrixParams; i++) { - m_MatrixParams[i] = new MatrixParameter(reader); + m_MatrixParams.Add(new MatrixParameter(reader)); } int numTextureParams = reader.ReadInt32(); - m_TextureParams = new TextureParameter[numTextureParams]; + m_TextureParams = new List(); for (int i = 0; i < numTextureParams; i++) { - m_TextureParams[i] = new TextureParameter(reader); + m_TextureParams.Add(new TextureParameter(reader)); } int numBufferParams = reader.ReadInt32(); - m_BufferParams = new BufferBinding[numBufferParams]; + m_BufferParams = new List(); for (int i = 0; i < numBufferParams; i++) { - m_BufferParams[i] = new BufferBinding(reader); + m_BufferParams.Add(new BufferBinding(reader)); } int numConstantBuffers = reader.ReadInt32(); - m_ConstantBuffers = new ConstantBuffer[numConstantBuffers]; + m_ConstantBuffers = new List(); for (int i = 0; i < numConstantBuffers; i++) { - m_ConstantBuffers[i] = new ConstantBuffer(reader); + m_ConstantBuffers.Add(new ConstantBuffer(reader)); } int numConstantBufferBindings = reader.ReadInt32(); - m_ConstantBufferBindings = new BufferBinding[numConstantBufferBindings]; + m_ConstantBufferBindings = new List(); for (int i = 0; i < numConstantBufferBindings; i++) { - m_ConstantBufferBindings[i] = new BufferBinding(reader); + m_ConstantBufferBindings.Add(new BufferBinding(reader)); } int numUAVParams = reader.ReadInt32(); - m_UAVParams = new UAVParameter[numUAVParams]; + m_UAVParams = new List(); for (int i = 0; i < numUAVParams; i++) { - m_UAVParams[i] = new UAVParameter(reader); + m_UAVParams.Add(new UAVParameter(reader)); } if (version[0] >= 2017) //2017 and up { int numSamplers = reader.ReadInt32(); - m_Samplers = new SamplerParameter[numSamplers]; + m_Samplers = new List(); for (int i = 0; i < numSamplers; i++) { - m_Samplers[i] = new SamplerParameter(reader); + m_Samplers.Add(new SamplerParameter(reader)); } } } @@ -704,10 +704,10 @@ namespace AssetStudio if (HasInstancedStructuredBuffers(reader.serializedType)) { int numInstancedStructuredBuffers = reader.ReadInt32(); - var m_InstancedStructuredBuffers = new ConstantBuffer[numInstancedStructuredBuffers]; + var m_InstancedStructuredBuffers = new List(); for (int i = 0; i < numInstancedStructuredBuffers; i++) { - m_InstancedStructuredBuffers[i] = new ConstantBuffer(reader); + m_InstancedStructuredBuffers.Add(new ConstantBuffer(reader)); } } } @@ -715,7 +715,7 @@ namespace AssetStudio public class SerializedProgram { - public SerializedSubProgram[] m_SubPrograms; + public List m_SubPrograms; public SerializedProgramParameters m_CommonParameters; public ushort[] m_SerializedKeywordStateMask; @@ -724,10 +724,10 @@ namespace AssetStudio var version = reader.version; int numSubPrograms = reader.ReadInt32(); - m_SubPrograms = new SerializedSubProgram[numSubPrograms]; + m_SubPrograms = new List(); for (int i = 0; i < numSubPrograms; i++) { - m_SubPrograms[i] = new SerializedSubProgram(reader); + m_SubPrograms.Add(new SerializedSubProgram(reader)); } if ((version[0] == 2020 && version[1] > 3) || @@ -756,11 +756,11 @@ namespace AssetStudio public class SerializedPass { - public Hash128[] m_EditorDataHash; + public List m_EditorDataHash; public byte[] m_Platforms; public ushort[] m_LocalKeywordMask; public ushort[] m_GlobalKeywordMask; - public KeyValuePair[] m_NameIndices; + public List> m_NameIndices; public PassType m_Type; public SerializedShaderState m_State; public uint m_ProgramMask; @@ -784,10 +784,10 @@ namespace AssetStudio if (version[0] > 2020 || (version[0] == 2020 && version[1] >= 2)) //2020.2 and up { int numEditorDataHash = reader.ReadInt32(); - m_EditorDataHash = new Hash128[numEditorDataHash]; + m_EditorDataHash = new List(); for (int i = 0; i < numEditorDataHash; i++) { - m_EditorDataHash[i] = new Hash128(reader); + m_EditorDataHash.Add(new Hash128(reader)); } reader.AlignStream(); m_Platforms = reader.ReadUInt8Array(); @@ -802,10 +802,10 @@ namespace AssetStudio } int numIndices = reader.ReadInt32(); - m_NameIndices = new KeyValuePair[numIndices]; + m_NameIndices = new List>(); for (int i = 0; i < numIndices; i++) { - m_NameIndices[i] = new KeyValuePair(reader.ReadAlignedString(), reader.ReadInt32()); + m_NameIndices.Add(new KeyValuePair(reader.ReadAlignedString(), reader.ReadInt32())); } m_Type = (PassType)reader.ReadInt32(); @@ -840,32 +840,32 @@ namespace AssetStudio public class SerializedTagMap { - public KeyValuePair[] tags; + public List> tags; public SerializedTagMap(EndianBinaryReader reader) { int numTags = reader.ReadInt32(); - tags = new KeyValuePair[numTags]; + tags = new List>(); for (int i = 0; i < numTags; i++) { - tags[i] = new KeyValuePair(reader.ReadAlignedString(), reader.ReadAlignedString()); + tags.Add(new KeyValuePair(reader.ReadAlignedString(), reader.ReadAlignedString())); } } } public class SerializedSubShader { - public SerializedPass[] m_Passes; + public List m_Passes; public SerializedTagMap m_Tags; public int m_LOD; public SerializedSubShader(ObjectReader reader) { int numPasses = reader.ReadInt32(); - m_Passes = new SerializedPass[numPasses]; + m_Passes = new List(); for (int i = 0; i < numPasses; i++) { - m_Passes[i] = new SerializedPass(reader); + m_Passes.Add(new SerializedPass(reader)); } m_Tags = new SerializedTagMap(reader); @@ -900,14 +900,14 @@ namespace AssetStudio public class SerializedShader { public SerializedProperties m_PropInfo; - public SerializedSubShader[] m_SubShaders; + public List m_SubShaders; public string[] m_KeywordNames; public byte[] m_KeywordFlags; public string m_Name; public string m_CustomEditorName; public string m_FallbackName; - public SerializedShaderDependency[] m_Dependencies; - public SerializedCustomEditorForRenderPipeline[] m_CustomEditorForRenderPipelines; + public List m_Dependencies; + public List m_CustomEditorForRenderPipelines; public bool m_DisableNoSubshadersMessage; public SerializedShader(ObjectReader reader) @@ -917,10 +917,10 @@ namespace AssetStudio m_PropInfo = new SerializedProperties(reader); int numSubShaders = reader.ReadInt32(); - m_SubShaders = new SerializedSubShader[numSubShaders]; + m_SubShaders = new List(); for (int i = 0; i < numSubShaders; i++) { - m_SubShaders[i] = new SerializedSubShader(reader); + m_SubShaders.Add(new SerializedSubShader(reader)); } if (version[0] > 2021 || (version[0] == 2021 && version[1] >= 2)) //2021.2 and up @@ -935,19 +935,19 @@ namespace AssetStudio m_FallbackName = reader.ReadAlignedString(); int numDependencies = reader.ReadInt32(); - m_Dependencies = new SerializedShaderDependency[numDependencies]; + m_Dependencies = new List(); for (int i = 0; i < numDependencies; i++) { - m_Dependencies[i] = new SerializedShaderDependency(reader); + m_Dependencies.Add(new SerializedShaderDependency(reader)); } if (version[0] >= 2021) //2021.1 and up { int m_CustomEditorForRenderPipelinesSize = reader.ReadInt32(); - m_CustomEditorForRenderPipelines = new SerializedCustomEditorForRenderPipeline[m_CustomEditorForRenderPipelinesSize]; + m_CustomEditorForRenderPipelines = new List(); for (int i = 0; i < m_CustomEditorForRenderPipelinesSize; i++) { - m_CustomEditorForRenderPipelines[i] = new SerializedCustomEditorForRenderPipeline(reader); + m_CustomEditorForRenderPipelines.Add(new SerializedCustomEditorForRenderPipeline(reader)); } } diff --git a/AssetStudio/Classes/SkinnedMeshRenderer.cs b/AssetStudio/Classes/SkinnedMeshRenderer.cs index d189641..605746b 100644 --- a/AssetStudio/Classes/SkinnedMeshRenderer.cs +++ b/AssetStudio/Classes/SkinnedMeshRenderer.cs @@ -8,13 +8,12 @@ namespace AssetStudio public sealed class SkinnedMeshRenderer : Renderer { public PPtr m_Mesh; - public PPtr[] m_Bones; + public List> m_Bones; public float[] m_BlendShapeWeights; public PPtr m_RootBone; public AABB m_AABB; public bool m_DirtyAABB; - public SkinnedMeshRenderer(ObjectReader reader) : base(reader) { int m_Quality = reader.ReadInt32(); @@ -29,10 +28,11 @@ namespace AssetStudio m_Mesh = new PPtr(reader); - m_Bones = new PPtr[reader.ReadInt32()]; - for (int b = 0; b < m_Bones.Length; b++) + var numBones = reader.ReadInt32(); + m_Bones = new List>(); + for (int b = 0; b < numBones; b++) { - m_Bones[b] = new PPtr(reader); + m_Bones.Add(new PPtr(reader)); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up diff --git a/AssetStudio/Classes/Sprite.cs b/AssetStudio/Classes/Sprite.cs index 752794f..26e7db7 100644 --- a/AssetStudio/Classes/Sprite.cs +++ b/AssetStudio/Classes/Sprite.cs @@ -79,14 +79,14 @@ namespace AssetStudio { public PPtr texture; public PPtr alphaTexture; - public SecondarySpriteTexture[] secondaryTextures; - public SubMesh[] m_SubMeshes; + public List secondaryTextures; + public List m_SubMeshes; public byte[] m_IndexBuffer; public VertexData m_VertexData; - public SpriteVertex[] vertices; + public List vertices; public ushort[] indices; public Matrix4x4[] m_Bindpose; - public BoneWeights4[] m_SourceSkin; + public List m_SourceSkin; public Rectf textureRect; public Vector2 textureRectOffset; public Vector2 atlasRectOffset; @@ -107,20 +107,20 @@ namespace AssetStudio if (version[0] >= 2019) //2019 and up { var secondaryTexturesSize = reader.ReadInt32(); - secondaryTextures = new SecondarySpriteTexture[secondaryTexturesSize]; + secondaryTextures = new List(); for (int i = 0; i < secondaryTexturesSize; i++) { - secondaryTextures[i] = new SecondarySpriteTexture(reader); + secondaryTextures.Add(new SecondarySpriteTexture(reader)); } } if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up { var m_SubMeshesSize = reader.ReadInt32(); - m_SubMeshes = new SubMesh[m_SubMeshesSize]; + m_SubMeshes = new List(); for (int i = 0; i < m_SubMeshesSize; i++) { - m_SubMeshes[i] = new SubMesh(reader); + m_SubMeshes.Add(new SubMesh(reader)); } m_IndexBuffer = reader.ReadUInt8Array(); @@ -131,10 +131,10 @@ namespace AssetStudio else { var verticesSize = reader.ReadInt32(); - vertices = new SpriteVertex[verticesSize]; + vertices = new List(); for (int i = 0; i < verticesSize; i++) { - vertices[i] = new SpriteVertex(reader); + vertices.Add(new SpriteVertex(reader)); } indices = reader.ReadUInt16Array(); @@ -204,7 +204,7 @@ namespace AssetStudio public string[] m_AtlasTags; public PPtr m_SpriteAtlas; public SpriteRenderData m_RD; - public Vector2[][] m_PhysicsShape; + public List m_PhysicsShape; public Sprite(ObjectReader reader) : base(reader) { @@ -247,10 +247,10 @@ namespace AssetStudio if (version[0] >= 2017) //2017 and up { var m_PhysicsShapeSize = reader.ReadInt32(); - m_PhysicsShape = new Vector2[m_PhysicsShapeSize][]; + m_PhysicsShape = new List(); for (int i = 0; i < m_PhysicsShapeSize; i++) { - m_PhysicsShape[i] = reader.ReadVector2Array(); + m_PhysicsShape.Add(reader.ReadVector2Array()); } } diff --git a/AssetStudio/Classes/SpriteAtlas.cs b/AssetStudio/Classes/SpriteAtlas.cs index c1a97c5..3b57b64 100644 --- a/AssetStudio/Classes/SpriteAtlas.cs +++ b/AssetStudio/Classes/SpriteAtlas.cs @@ -13,7 +13,7 @@ namespace AssetStudio public Vector4 uvTransform; public float downscaleMultiplier; public SpriteSettings settingsRaw; - public SecondarySpriteTexture[] secondaryTextures; + public List secondaryTextures; public SpriteAtlasData(ObjectReader reader) { @@ -32,10 +32,10 @@ namespace AssetStudio if (version[0] > 2020 || (version[0] == 2020 && version[1] >= 2)) //2020.2 and up { var secondaryTexturesSize = reader.ReadInt32(); - secondaryTextures = new SecondarySpriteTexture[secondaryTexturesSize]; + secondaryTextures = new List(); for (int i = 0; i < secondaryTexturesSize; i++) { - secondaryTextures[i] = new SecondarySpriteTexture(reader); + secondaryTextures.Add(new SecondarySpriteTexture(reader)); } reader.AlignStream(); } @@ -44,23 +44,23 @@ namespace AssetStudio public sealed class SpriteAtlas : NamedObject { - public PPtr[] m_PackedSprites; + public List> m_PackedSprites; public Dictionary, SpriteAtlasData> m_RenderDataMap; public bool m_IsVariant; public SpriteAtlas(ObjectReader reader) : base(reader) { var m_PackedSpritesSize = reader.ReadInt32(); - m_PackedSprites = new PPtr[m_PackedSpritesSize]; + m_PackedSprites = new List>(); for (int i = 0; i < m_PackedSpritesSize; i++) { - m_PackedSprites[i] = new PPtr(reader); + m_PackedSprites.Add(new PPtr(reader)); } var m_PackedSpriteNamesToIndex = reader.ReadStringArray(); var m_RenderDataMapSize = reader.ReadInt32(); - m_RenderDataMap = new Dictionary, SpriteAtlasData>(m_RenderDataMapSize); + m_RenderDataMap = new Dictionary, SpriteAtlasData>(); for (int i = 0; i < m_RenderDataMapSize; i++) { var first = new Guid(reader.ReadBytes(16)); diff --git a/AssetStudio/Classes/Transform.cs b/AssetStudio/Classes/Transform.cs index 4e730a0..65778b1 100644 --- a/AssetStudio/Classes/Transform.cs +++ b/AssetStudio/Classes/Transform.cs @@ -10,7 +10,7 @@ namespace AssetStudio public Quaternion m_LocalRotation; public Vector3 m_LocalPosition; public Vector3 m_LocalScale; - public PPtr[] m_Children; + public List> m_Children; public PPtr m_Father; public Transform(ObjectReader reader) : base(reader) @@ -20,10 +20,10 @@ namespace AssetStudio m_LocalScale = reader.ReadVector3(); int m_ChildrenCount = reader.ReadInt32(); - m_Children = new PPtr[m_ChildrenCount]; + m_Children = new List>(); for (int i = 0; i < m_ChildrenCount; i++) { - m_Children[i] = new PPtr(reader); + m_Children.Add(new PPtr(reader)); } m_Father = new PPtr(reader); } diff --git a/AssetStudio/Classes/VideoClip.cs b/AssetStudio/Classes/VideoClip.cs index a5af6f9..ed33acf 100644 --- a/AssetStudio/Classes/VideoClip.cs +++ b/AssetStudio/Classes/VideoClip.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; namespace AssetStudio { @@ -44,10 +45,10 @@ namespace AssetStudio if (version[0] >= 2020) //2020.1 and up { var m_VideoShadersSize = reader.ReadInt32(); - var m_VideoShaders = new PPtr[m_VideoShadersSize]; + var m_VideoShaders = new List>(); for (int i = 0; i < m_VideoShadersSize; i++) { - m_VideoShaders[i] = new PPtr(reader); + m_VideoShaders.Add(new PPtr(reader)); } } m_ExternalResources = new StreamedResource(reader); diff --git a/AssetStudio/Crypto/CryptoHelper.cs b/AssetStudio/Crypto/CryptoHelper.cs index c77c4ae..32f5301 100644 --- a/AssetStudio/Crypto/CryptoHelper.cs +++ b/AssetStudio/Crypto/CryptoHelper.cs @@ -8,9 +8,9 @@ namespace AssetStudio public static readonly byte[] GISBox = new byte[] { 0xF7, 0xE7, 0xD8, 0xB8, 0x64, 0x31, 0xD1, 0x74, 0x88, 0xAA, 0xB4, 0x8B, 0x6A, 0xA3, 0xFC, 0x55, 0x59, 0xC5, 0x6D, 0xC9, 0x9A, 0x11, 0x2F, 0x37, 0xAD, 0x35, 0x15, 0x62, 0x61, 0x04, 0x44, 0x01, 0xDD, 0x47, 0x3D, 0xFF, 0x8F, 0x51, 0xAF, 0x0F, 0x19, 0x23, 0x92, 0x13, 0x00, 0x53, 0x4B, 0x67, 0x21, 0x1C, 0x1B, 0x94, 0xE2, 0x29, 0x9F, 0x4C, 0xFB, 0xBB, 0x75, 0xF0, 0xFE, 0x1F, 0xDB, 0xEF, 0x1D, 0xF1, 0x3A, 0x1A, 0x05, 0x06, 0xCE, 0xDE, 0x63, 0x0A, 0x6B, 0x2D, 0x28, 0x41, 0x6C, 0x0C, 0x42, 0xDC, 0x58, 0xB6, 0x39, 0x2E, 0xD2, 0xF6, 0x2B, 0xAC, 0x84, 0x96, 0x17, 0xF3, 0x3F, 0x8D, 0xAB, 0x95, 0xCD, 0x30, 0x0E, 0x66, 0x90, 0xF4, 0xED, 0xE0, 0x8E, 0xC2, 0x78, 0x2C, 0x7E, 0xF8, 0x5D, 0x02, 0x91, 0xFA, 0x3C, 0xDA, 0xB7, 0x6F, 0xF9, 0x4F, 0x14, 0x5E, 0xEA, 0x24, 0x56, 0x9E, 0xC1, 0xA5, 0x85, 0xD7, 0x08, 0x83, 0x4E, 0xF5, 0x76, 0x32, 0x86, 0x5C, 0xD3, 0x09, 0x5F, 0xFD, 0x36, 0x03, 0xEE, 0xE3, 0x34, 0x77, 0x79, 0x18, 0xBD, 0xDF, 0x97, 0x71, 0xBA, 0x65, 0x68, 0x7A, 0x54, 0x80, 0x48, 0x38, 0x5B, 0x4D, 0x5A, 0x7F, 0x0B, 0x7C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x15, 0x87, 0x93, 0xC1, 0x91, 0xE5, 0x8D, 0x44, 0x10, 0x98, 0x34, 0x08, 0x7A, 0xB6, 0x76, 0xAA, 0xB5, 0x34, 0x21, 0xEE, 0x72, 0x58, 0x27, 0x3F, 0x72, 0x5A, 0x93, 0x75, 0x78, 0x60, 0xC0, 0xA2, 0xF5, 0x52, 0x97, 0x9F, 0xF5, 0x28, 0x86, 0x23, 0x3A, 0xB4, 0xEA, 0xC3, 0x40, 0x12, 0x39, 0x92, 0xE2, 0x33, 0xD8, 0x7A, 0x39, 0x44, 0xA9, 0x5B, 0x58, 0x5F, 0x7C, 0xD9, 0xFC, 0x9F, 0xEF, 0x3F, 0x3A, 0x05, 0x5B, 0xA5, 0x4D, 0x1D, 0x63, 0x33, 0xD5, 0xEB, 0x43, 0x42, 0x79, 0x71, 0x85, 0x57, 0x92, 0xF8, 0xDE, 0xED, 0x7D, 0xE3, 0xF8, 0x33, 0x20, 0x2C, 0x92, 0x22, 0xE5, 0x6E, 0xCC, 0x1D, 0x21, 0x71, 0x04, 0xB8, 0xA7, 0x8D, 0x3B, 0xE6, 0x19, 0x53, 0x36, 0x1E, 0x14, 0x40, 0x12, 0xED, 0x7B, 0x85, 0x47, 0x8D, 0xD2, 0xCD, 0xF8, 0x4D, 0x71, 0xBC, 0x62 }; public static readonly byte[] GIInitVector = new byte[] { 0xE3, 0xFC, 0x2D, 0x26, 0x9C, 0xC5, 0xA2, 0xEC, 0xD3, 0xF8, 0xC6, 0xD3, 0x77, 0xC2, 0x49, 0xB9 }; - public static readonly byte[] GIMhy0ShiftRow = new byte[] { 0x0B, 0x02, 0x08, 0x0C, 0x01, 0x05, 0x00, 0x0F, 0x06, 0x07, 0x09, 0x03, 0x0D, 0x04, 0x0E, 0x0A, 0x04, 0x05, 0x07, 0x0A, 0x02, 0x0F, 0x0B, 0x08, 0x0E, 0x0D, 0x09, 0x06, 0x0C, 0x03, 0x00, 0x01, 0x08, 0x00, 0x0C, 0x06, 0x04, 0x0B, 0x07, 0x09, 0x05, 0x03, 0x0F, 0x01, 0x0D, 0x0A, 0x02, 0x0E }; - public static readonly byte[] GIMhy0Key = new byte[] { 0x48, 0x14, 0x36, 0xED, 0x8E, 0x44, 0x5B, 0xB6 }; - public static readonly byte[] GIMhy0Mul = new byte[] { 0xA7, 0x99, 0x66, 0x50, 0xB9, 0x2D, 0xF0, 0x78 }; + public static readonly byte[] GIMhyShiftRow = new byte[] { 0x0B, 0x02, 0x08, 0x0C, 0x01, 0x05, 0x00, 0x0F, 0x06, 0x07, 0x09, 0x03, 0x0D, 0x04, 0x0E, 0x0A, 0x04, 0x05, 0x07, 0x0A, 0x02, 0x0F, 0x0B, 0x08, 0x0E, 0x0D, 0x09, 0x06, 0x0C, 0x03, 0x00, 0x01, 0x08, 0x00, 0x0C, 0x06, 0x04, 0x0B, 0x07, 0x09, 0x05, 0x03, 0x0F, 0x01, 0x0D, 0x0A, 0x02, 0x0E }; + public static readonly byte[] GIMhyKey = new byte[] { 0x48, 0x14, 0x36, 0xED, 0x8E, 0x44, 0x5B, 0xB6 }; + public static readonly byte[] GIMhyMul = new byte[] { 0xA7, 0x99, 0x66, 0x50, 0xB9, 0x2D, 0xF0, 0x78 }; public static readonly ulong GIInitSeed = 0x567BA22BABB08098; #endregion @@ -18,9 +18,9 @@ namespace AssetStudio public static readonly byte[] GI_CBXSBox = new byte[] { 0x42, 0x78, 0x81, 0xD1, 0xDD, 0x1A, 0xDC, 0xFD, 0x5F, 0x4E, 0x31, 0xE0, 0x02, 0x46, 0x4D, 0xBF, 0x3D, 0xF7, 0xD7, 0x71, 0xC0, 0x21, 0xB4, 0x63, 0x1E, 0xE3, 0x25, 0xAB, 0x69, 0x09, 0xF5, 0x0D, 0x82, 0x3E, 0x23, 0x22, 0x0F, 0x4A, 0x9D, 0x03, 0x01, 0xE5, 0x07, 0x11, 0xB5, 0xBE, 0xD5, 0xD0, 0x3B, 0x84, 0x9A, 0xDE, 0x6E, 0x6D, 0x8F, 0xB1, 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 0xE4, 0x54, 0x02, 0xA7, 0xD1, 0x71, 0xC0, 0xF6, 0xE0, 0xFF, 0xDD, 0x01, 0xBA, 0xD5, 0x26, 0x94, 0x2D, 0x85, 0xA3, 0x7D, 0xDF, 0x0F, 0x94, 0x2F, 0xD6, 0x39, 0xE6, 0xEC, 0xCA, 0x86, 0x73, 0xD5, 0x66, 0x6A, 0x98, 0x92, 0x86, 0xCE, 0x20, 0xB4, 0xF0, 0x4C, 0xAA, 0xDD, 0x5A, 0xD5, 0x78, 0x2C, 0x81, 0xBE, 0xAE, 0x3A, 0x31, 0x14 }; public static readonly byte[] GI_CBXInitVector = new byte[] { 0xA2, 0x25, 0x25, 0x99, 0xB7, 0x62, 0xF4, 0x39, 0x28, 0xE1, 0xB7, 0x73, 0x91, 0x05, 0x25, 0x87 }; - public static readonly byte[] GI_CBXMhy0ShiftRow = new byte[] { 0x0D, 0x0E, 0x05, 0x0A, 0x00, 0x04, 0x0C, 0x0B, 0x06, 0x02, 0x03, 0x08, 0x0F, 0x01, 0x07, 0x09, 0x00, 0x0B, 0x09, 0x03, 0x08, 0x07, 0x05, 0x02, 0x0A, 0x0F, 0x01, 0x06, 0x0D, 0x04, 0x0C, 0x0E, 0x04, 0x0F, 0x0D, 0x07, 0x0C, 0x02, 0x05, 0x01, 0x09, 0x06, 0x0A, 0x00, 0x03, 0x08, 0x0B, 0x0E }; - public static readonly byte[] GI_CBXMhy0Key = new byte[] { 0x69, 0xB0, 0x8C, 0x21, 0xDC, 0x23, 0x3D, 0x9B }; - public static readonly byte[] GI_CBXMhy0Mul = new byte[] { 0x47, 0x0C, 0xF7, 0x6E, 0x9D, 0xF1, 0xBB, 0x88 }; + public static readonly byte[] GI_CBXMhyShiftRow = new byte[] { 0x0D, 0x0E, 0x05, 0x0A, 0x00, 0x04, 0x0C, 0x0B, 0x06, 0x02, 0x03, 0x08, 0x0F, 0x01, 0x07, 0x09, 0x00, 0x0B, 0x09, 0x03, 0x08, 0x07, 0x05, 0x02, 0x0A, 0x0F, 0x01, 0x06, 0x0D, 0x04, 0x0C, 0x0E, 0x04, 0x0F, 0x0D, 0x07, 0x0C, 0x02, 0x05, 0x01, 0x09, 0x06, 0x0A, 0x00, 0x03, 0x08, 0x0B, 0x0E }; + public static readonly byte[] GI_CBXMhyKey = new byte[] { 0x69, 0xB0, 0x8C, 0x21, 0xDC, 0x23, 0x3D, 0x9B }; + public static readonly byte[] GI_CBXMhyMul = new byte[] { 0x47, 0x0C, 0xF7, 0x6E, 0x9D, 0xF1, 0xBB, 0x88 }; public static readonly ulong GI_CBXInitSeed = 0xCEAC3B5A867837AC; #endregion diff --git a/AssetStudio/EndianBinaryReader.cs b/AssetStudio/EndianBinaryReader.cs index 3214ede..74ae4de 100644 --- a/AssetStudio/EndianBinaryReader.cs +++ b/AssetStudio/EndianBinaryReader.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Buffers.Binary; using System.Collections.Generic; using System.IO; @@ -108,6 +109,31 @@ namespace AssetStudio } return base.ReadDouble(); } + public override byte[] ReadBytes(int count) + { + if (count == 0) + { + return Array.Empty(); + } + + var buffer = ArrayPool.Shared.Rent(0x1000); + List result = new List(); + do + { + var readNum = Math.Min(count, buffer.Length); + int n = Read(buffer, 0, readNum); + if (n == 0) + { + break; + } + + result.AddRange(buffer[..n]); + count -= n; + } while (count > 0); + + ArrayPool.Shared.Return(buffer); + return result.ToArray(); + } public void AlignStream() { @@ -164,11 +190,6 @@ namespace AssetStudio return new Vector2(ReadSingle(), ReadSingle()); } - public Vector3 ReadVector3() - { - return new Vector3(ReadSingle(), ReadSingle(), ReadSingle()); - } - public Vector4 ReadVector4() { return new Vector4(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); @@ -184,33 +205,24 @@ namespace AssetStudio return new Matrix4x4(ReadSingleArray(16)); } - public XForm ReadXForm(int[] version, bool isVector4 = false) - { - var t = (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) && !isVector4 ? ReadVector3() : (Vector3)ReadVector4();//5.4 and up - var q = ReadQuaternion(); - var s = (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) && !isVector4 ? ReadVector3() : (Vector3)ReadVector4();//5.4 and up - - return new XForm(t, q, s); - } - public Float ReadFloat() { return new Float(ReadSingle()); } - public int ReadMhy0Int() + public int ReadMhyInt() { var buffer = ReadBytes(6); return buffer[2] | (buffer[4] << 8) | (buffer[0] << 0x10) | (buffer[5] << 0x18); } - public uint ReadMhy0UInt() + public uint ReadMhyUInt() { var buffer = ReadBytes(7); return (uint)(buffer[1] | (buffer[6] << 8) | (buffer[3] << 0x10) | (buffer[2] << 0x18)); } - public string ReadMhy0String() + public string ReadMhyString() { var pos = BaseStream.Position; var str = ReadStringToNull(); @@ -218,94 +230,134 @@ namespace AssetStudio return str; } - private T[] ReadArray(Func del, int length) + internal T[] ReadArray(Func del, int length) { - var array = new T[length]; - for (int i = 0; i < length; i++) + if (length < 0x1000) { - array[i] = del(); + var array = new T[length]; + for (int i = 0; i < length; i++) + { + array[i] = del(); + } + return array; + } + else + { + var list = new List(); + for (int i = 0; i < length; i++) + { + list.Add(del()); + } + return list.ToArray(); } - return array; } - public bool[] ReadBooleanArray() + public bool[] ReadBooleanArray(int length = 0) { - return ReadArray(ReadBoolean, ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(ReadBoolean, length); } - public byte[] ReadUInt8Array() + public byte[] ReadUInt8Array(int length = 0) { - return ReadBytes(ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadBytes(length); } - public short[] ReadInt16Array() - { - return ReadArray(ReadInt16, ReadInt32()); - } - - public short[] ReadInt16Array(int length) + public short[] ReadInt16Array(int length = 0) { + if (length == 0) + { + length = ReadInt32(); + } return ReadArray(ReadInt16, length); } - public ushort[] ReadUInt16Array() + public ushort[] ReadUInt16Array(int length = 0) { - return ReadArray(ReadUInt16, ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(ReadUInt16, length); } - public int[] ReadInt32Array() - { - return ReadArray(ReadInt32, ReadInt32()); - } - - public int[] ReadInt32Array(int length) + public int[] ReadInt32Array(int length = 0) { + if (length == 0) + { + length = ReadInt32(); + } return ReadArray(ReadInt32, length); } - public uint[] ReadUInt32Array() - { - return ReadArray(ReadUInt32, ReadInt32()); - } - - public uint[][] ReadUInt32ArrayArray() - { - return ReadArray(ReadUInt32Array, ReadInt32()); - } - - public uint[] ReadUInt32Array(int length) + public uint[] ReadUInt32Array(int length = 0) { + if (length == 0) + { + length = ReadInt32(); + } return ReadArray(ReadUInt32, length); } - public float[] ReadSingleArray() + public uint[][] ReadUInt32ArrayArray(int length = 0) { - return ReadArray(ReadSingle, ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(() => ReadUInt32Array(), length); } - public float[] ReadSingleArray(int length) + public float[] ReadSingleArray(int length = 0) { + if (length == 0) + { + length = ReadInt32(); + } return ReadArray(ReadSingle, length); } - public string[] ReadStringArray() + public string[] ReadStringArray(int length = 0) { - return ReadArray(ReadAlignedString, ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(ReadAlignedString, length); } - public Vector2[] ReadVector2Array() + public Vector2[] ReadVector2Array(int length = 0) { - return ReadArray(ReadVector2, ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(ReadVector2, length); } - public Vector4[] ReadVector4Array() + public Vector4[] ReadVector4Array(int length = 0) { - return ReadArray(ReadVector4, ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(ReadVector4, length); } - public Matrix4x4[] ReadMatrixArray() + public Matrix4x4[] ReadMatrixArray(int length = 0) { - return ReadArray(ReadMatrix, ReadInt32()); + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(ReadMatrix, length); } } } diff --git a/AssetStudio/FileReader.cs b/AssetStudio/FileReader.cs index f755563..2b4ebcd 100644 --- a/AssetStudio/FileReader.cs +++ b/AssetStudio/FileReader.cs @@ -83,7 +83,7 @@ namespace AssetStudio Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(zipMagic)} or {Convert.ToHexString(zipSpannedMagic)}"); if (mhy0Magic.SequenceEqual(magic)) { - return FileType.Mhy0File; + return FileType.MhyFile; } Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(mhy0Magic)}"); if (blbMagic.SequenceEqual(magic)) diff --git a/AssetStudio/FileType.cs b/AssetStudio/FileType.cs index 5ba4321..5fd3540 100644 --- a/AssetStudio/FileType.cs +++ b/AssetStudio/FileType.cs @@ -16,7 +16,7 @@ namespace AssetStudio BrotliFile, ZipFile, BlkFile, - Mhy0File, + MhyFile, BlbFile, ENCRFile, BlockFile diff --git a/AssetStudio/GameManager.cs b/AssetStudio/GameManager.cs index 6826c03..b2a076a 100644 --- a/AssetStudio/GameManager.cs +++ b/AssetStudio/GameManager.cs @@ -13,12 +13,12 @@ namespace AssetStudio int index = 0; Games.Add(index++, new(GameType.Normal)); Games.Add(index++, new(GameType.UnityCN)); - Games.Add(index++, new Mhy0(GameType.GI, GIMhy0ShiftRow, GIMhy0Key, GIMhy0Mul, GIExpansionKey, GISBox, GIInitVector, GIInitSeed)); + Games.Add(index++, new Mhy(GameType.GI, GIMhyShiftRow, GIMhyKey, GIMhyMul, GIExpansionKey, GISBox, GIInitVector, GIInitSeed)); Games.Add(index++, new Mr0k(GameType.GI_Pack, PackExpansionKey, blockKey: PackBlockKey)); Games.Add(index++, new Mr0k(GameType.GI_CB1)); Games.Add(index++, new Blk(GameType.GI_CB2, GI_CBXExpansionKey, initVector: GI_CBXInitVector, initSeed: GI_CBXInitSeed)); Games.Add(index++, new Blk(GameType.GI_CB3, GI_CBXExpansionKey, initVector: GI_CBXInitVector, initSeed: GI_CBXInitSeed)); - Games.Add(index++, new Mhy0(GameType.GI_CB3Pre, GI_CBXMhy0ShiftRow, GI_CBXMhy0Key, GI_CBXMhy0Mul, GI_CBXExpansionKey, GI_CBXSBox, GI_CBXInitVector, GI_CBXInitSeed)); + Games.Add(index++, new Mhy(GameType.GI_CB3Pre, GI_CBXMhyShiftRow, GI_CBXMhyKey, GI_CBXMhyMul, GI_CBXExpansionKey, GI_CBXSBox, GI_CBXInitVector, GI_CBXInitSeed)); Games.Add(index++, new Mr0k(GameType.BH3, BH3ExpansionKey, BH3SBox, BH3InitVector, BH3BlockKey)); Games.Add(index++, new Mr0k(GameType.BH3Pre, PackExpansionKey, blockKey: PackBlockKey)); Games.Add(index++, new Mr0k(GameType.SR_CB2, Mr0kExpansionKey, initVector: Mr0kInitVector, blockKey: Mr0kBlockKey)); @@ -108,17 +108,17 @@ namespace AssetStudio } } - public record Mhy0 : Blk + public record Mhy : Blk { - public byte[] Mhy0ShiftRow { get; } - public byte[] Mhy0Key { get; } - public byte[] Mhy0Mul { get; } + public byte[] MhyShiftRow { get; } + public byte[] MhyKey { get; } + public byte[] MhyMul { get; } - public Mhy0(GameType type, byte[] mhy0ShiftRow, byte[] mhy0Key, byte[] mhy0Mul, byte[] expansionKey = null, byte[] sBox = null, byte[] initVector = null, ulong initSeed = 0) : base(type, expansionKey, sBox, initVector, initSeed) + public Mhy(GameType type, byte[] mhyShiftRow, byte[] mhyKey, byte[] mhyMul, byte[] expansionKey = null, byte[] sBox = null, byte[] initVector = null, ulong initSeed = 0) : base(type, expansionKey, sBox, initVector, initSeed) { - Mhy0ShiftRow = mhy0ShiftRow; - Mhy0Key = mhy0Key; - Mhy0Mul = mhy0Mul; + MhyShiftRow = mhyShiftRow; + MhyKey = mhyKey; + MhyMul = mhyMul; } } diff --git a/AssetStudio/Mhy0File.cs b/AssetStudio/MhyFile.cs similarity index 86% rename from AssetStudio/Mhy0File.cs rename to AssetStudio/MhyFile.cs index cf75ec7..e885dc0 100644 --- a/AssetStudio/Mhy0File.cs +++ b/AssetStudio/MhyFile.cs @@ -1,31 +1,33 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; namespace AssetStudio { - public class Mhy0File + public class MhyFile { - private BundleFile.StorageBlock[] m_BlocksInfo; - private BundleFile.Node[] m_DirectoryInfo; + private string signature; + private List m_BlocksInfo; + private List m_DirectoryInfo; public BundleFile.Header m_Header; - public StreamFile[] fileList; + public List fileList; public long Offset; - public Mhy0 mhy0; + public Mhy mhy; public long TotalSize => 8 + m_Header.compressedBlocksInfoSize + m_BlocksInfo.Sum(x => x.compressedSize); - public Mhy0File(FileReader reader, string path, Mhy0 mhy0) + public MhyFile(FileReader reader, string path, Mhy mhy) { - this.mhy0 = mhy0; + this.mhy = mhy; Offset = reader.Position; reader.Endian = EndianType.LittleEndian; - var signature = reader.ReadStringToNull(4); + signature = reader.ReadStringToNull(4); Logger.Verbose($"Parsed signature {signature}"); if (signature != "mhy0") - throw new Exception("not a mhy0"); + throw new Exception("not a mhy file"); m_Header = new BundleFile.Header { @@ -44,17 +46,19 @@ namespace AssetStudio private void ReadBlocksInfoAndDirectory(FileReader reader) { + int offset = 0x20; var blocksInfo = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize); DescrambleHeader(blocksInfo); Logger.Verbose($"Descrambled blocksInfo signature {Convert.ToHexString(blocksInfo, 0 , 4)}"); - using var blocksInfoStream = new MemoryStream(blocksInfo, 0x20, (int)m_Header.compressedBlocksInfoSize - 0x20); + using var blocksInfoStream = new MemoryStream(blocksInfo, offset, (int)m_Header.compressedBlocksInfoSize - offset); using var blocksInfoReader = new EndianBinaryReader(blocksInfoStream); - m_Header.uncompressedBlocksInfoSize = blocksInfoReader.ReadMhy0UInt(); + m_Header.uncompressedBlocksInfoSize = blocksInfoReader.ReadMhyUInt(); Logger.Verbose($"uncompressed blocksInfo size: 0x{m_Header.uncompressedBlocksInfoSize:X8}"); var compressedBlocksInfo = blocksInfoReader.ReadBytes((int)blocksInfoReader.Remaining); - var uncompressedBlocksInfo = new byte[(int)m_Header.uncompressedBlocksInfoSize]; - var numWrite = LZ4.Decompress(compressedBlocksInfo, uncompressedBlocksInfo); + var uncompressedBlocksInfo = BigArrayPool.Shared.Rent((int)m_Header.uncompressedBlocksInfoSize); + var uncompressedBlocksInfoSpan = uncompressedBlocksInfo.AsSpan(0, (int)m_Header.uncompressedBlocksInfoSize); + var numWrite = LZ4.Decompress(compressedBlocksInfo, uncompressedBlocksInfoSpan); if (numWrite != m_Header.uncompressedBlocksInfoSize) { throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {m_Header.uncompressedBlocksInfoSize} bytes"); @@ -63,36 +67,38 @@ namespace AssetStudio Logger.Verbose($"Writing block and directory to blocks stream..."); using var blocksInfoUncompressedStream = new MemoryStream(uncompressedBlocksInfo); using var blocksInfoUncompressedReader = new EndianBinaryReader(blocksInfoUncompressedStream); - var nodesCount = blocksInfoUncompressedReader.ReadMhy0Int(); - m_DirectoryInfo = new BundleFile.Node[nodesCount]; + var nodesCount = blocksInfoUncompressedReader.ReadMhyInt(); + m_DirectoryInfo = new List(); Logger.Verbose($"Directory count: {nodesCount}"); for (int i = 0; i < nodesCount; i++) { - m_DirectoryInfo[i] = new BundleFile.Node + m_DirectoryInfo.Add(new BundleFile.Node { - path = blocksInfoUncompressedReader.ReadMhy0String(), + path = blocksInfoUncompressedReader.ReadMhyString(), flags = blocksInfoUncompressedReader.ReadBoolean() ? 4u : 0, - offset = blocksInfoUncompressedReader.ReadMhy0Int(), - size = blocksInfoUncompressedReader.ReadMhy0UInt() - }; + offset = blocksInfoUncompressedReader.ReadMhyInt(), + size = blocksInfoUncompressedReader.ReadMhyUInt() + }); Logger.Verbose($"Directory {i} Info: {m_DirectoryInfo[i]}"); } - var blocksInfoCount = blocksInfoUncompressedReader.ReadMhy0Int(); - m_BlocksInfo = new BundleFile.StorageBlock[blocksInfoCount]; + var blocksInfoCount = blocksInfoUncompressedReader.ReadMhyInt(); + m_BlocksInfo = new List(); Logger.Verbose($"Blocks count: {blocksInfoCount}"); for (int i = 0; i < blocksInfoCount; i++) { - m_BlocksInfo[i] = new BundleFile.StorageBlock + m_BlocksInfo.Add(new BundleFile.StorageBlock { - compressedSize = (uint)blocksInfoUncompressedReader.ReadMhy0Int(), - uncompressedSize = blocksInfoUncompressedReader.ReadMhy0UInt(), + compressedSize = (uint)blocksInfoUncompressedReader.ReadMhyInt(), + uncompressedSize = blocksInfoUncompressedReader.ReadMhyUInt(), flags = (StorageBlockFlags)0x43 - }; + }); Logger.Verbose($"Block {i} Info: {m_BlocksInfo[i]}"); } + + BigArrayPool.Shared.Return(uncompressedBlocksInfo); } private Stream CreateBlocksStream(string path) @@ -122,12 +128,13 @@ namespace AssetStudio var uncompressedBytes = BigArrayPool.Shared.Rent(uncompressedSize); reader.Read(compressedBytes, 0, compressedSize); + var offset = 0xC; var compressedBytesSpan = compressedBytes.AsSpan(0, compressedSize); var uncompressedBytesSpan = uncompressedBytes.AsSpan(0, uncompressedSize); DescrambleEntry(compressedBytesSpan); Logger.Verbose($"Descrambled block signature {Convert.ToHexString(compressedBytes, 0, 4)}"); - var numWrite = LZ4.Decompress(compressedBytesSpan[0xC..compressedSize], uncompressedBytesSpan); + var numWrite = LZ4.Decompress(compressedBytesSpan[offset..], uncompressedBytesSpan); if (numWrite != uncompressedSize) { throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes"); @@ -143,12 +150,12 @@ namespace AssetStudio { Logger.Verbose($"Writing files from blocks stream..."); - fileList = new StreamFile[m_DirectoryInfo.Length]; - for (int i = 0; i < m_DirectoryInfo.Length; i++) + fileList = new List(); + for (int i = 0; i < m_DirectoryInfo.Count; i++) { var node = m_DirectoryInfo[i]; var file = new StreamFile(); - fileList[i] = file; + fileList.Add(file); file.path = node.path; file.fileName = Path.GetFileName(node.path); if (node.size >= int.MaxValue) @@ -177,9 +184,9 @@ namespace AssetStudio { for (int j = 0; j < 0x10; j++) { - int k = mhy0.Mhy0ShiftRow[(2 - i) * 0x10 + j]; + int k = mhy.MhyShiftRow[(2 - i) * 0x10 + j]; int idx = j % 8; - vector[j] = (byte)(mhy0.Mhy0Key[idx] ^ mhy0.SBox[(j % 4 * 0x100) | GF256Mul(mhy0.Mhy0Mul[idx], input[k])]); + vector[j] = (byte)(mhy.MhyKey[idx] ^ mhy.SBox[(j % 4 * 0x100) | GF256Mul(mhy.MhyMul[idx], input[k])]); } vector.CopyTo(input); } @@ -193,8 +200,8 @@ namespace AssetStudio for (int i = 0; i < 4; i++) input[i] ^= input[i + 4]; - var currentEntry = roundedEntrySize + 4; var finished = false; + var currentEntry = roundedEntrySize + 4; while (currentEntry < blockSize && !finished) { for (int i = 0; i < entrySize; i++) diff --git a/AssetStudio/ObjectReader.cs b/AssetStudio/ObjectReader.cs index 8c704a4..808ef13 100644 --- a/AssetStudio/ObjectReader.cs +++ b/AssetStudio/ObjectReader.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; namespace AssetStudio { @@ -43,10 +40,64 @@ namespace AssetStudio Logger.Verbose($"Initialized reader for {type} object with {m_PathID} in file {assetsFile.fileName} !!"); } + public override int Read(byte[] buffer, int index, int count) + { + var pos = Position - byteStart; + if (pos + count > byteSize) + { + throw new EndOfStreamException("Unable to read beyond the end of the stream."); + } + return base.Read(buffer, index, count); + } + public void Reset() { Logger.Verbose($"Resetting reader position to object offset 0x{byteStart:X8}..."); Position = byteStart; } + + public Vector3 ReadVector3() + { + if (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) + { + return new Vector3(ReadSingle(), ReadSingle(), ReadSingle()); + } + else + { + return new Vector4(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle()); + } + } + + public XForm ReadXForm() + { + var t = ReadVector3(); + var q = ReadQuaternion(); + var s = ReadVector3(); + + return new XForm(t, q, s); + } + + public XForm ReadXForm4() + { + var t = ReadVector4(); + var q = ReadQuaternion(); + var s = ReadVector4(); + + return new XForm(t, q, s); + } + + public Vector3[] ReadVector3Array(int length = 0) + { + if (length == 0) + { + length = ReadInt32(); + } + return ReadArray(ReadVector3, length); + } + + public XForm[] ReadXFormArray() + { + return ReadArray(ReadXForm, ReadInt32()); + } } } diff --git a/AssetStudio/OffsetStream.cs b/AssetStudio/OffsetStream.cs index 5073244..c4e77f6 100644 --- a/AssetStudio/OffsetStream.cs +++ b/AssetStudio/OffsetStream.cs @@ -85,10 +85,11 @@ namespace AssetStudio { FileType.BundleFile => "UnityFS\x00", FileType.BlbFile => "Blb\x02", - FileType.Mhy0File => "mhy0", + FileType.MhyFile => Encoding.UTF8.GetString(reader.ReadBytes(4)), FileType.ENCRFile => "ENCR\x00", _ => throw new InvalidOperationException() }; + reader.Position = 0; Logger.Verbose($"Prased signature: {signature}"); diff --git a/AssetStudio/ResourceMap.cs b/AssetStudio/ResourceMap.cs index 035eb98..1e21960 100644 --- a/AssetStudio/ResourceMap.cs +++ b/AssetStudio/ResourceMap.cs @@ -1,13 +1,14 @@ using MessagePack; using System; +using System.Collections.Generic; using System.IO; namespace AssetStudio { public static class ResourceMap { - private static AssetMap Instance = new() { GameType = GameType.Normal, AssetEntries = Array.Empty() }; - public static AssetEntry[] GetEntries() => Instance.AssetEntries; + private static AssetMap Instance = new() { GameType = GameType.Normal, AssetEntries = new List() }; + public static List GetEntries() => Instance.AssetEntries; public static void FromFile(string path) { if (!string.IsNullOrEmpty(path)) @@ -31,7 +32,7 @@ namespace AssetStudio public static void Clear() { Instance.GameType = GameType.Normal; - Instance.AssetEntries = Array.Empty(); + Instance.AssetEntries = new List(); } } } diff --git a/AssetStudio/SerializedFile.cs b/AssetStudio/SerializedFile.cs index 3021eef..9401ef9 100644 --- a/AssetStudio/SerializedFile.cs +++ b/AssetStudio/SerializedFile.cs @@ -106,7 +106,7 @@ namespace AssetStudio // Read Types int typeCount = reader.ReadInt32(); - m_Types = new List(typeCount); + m_Types = new List(); Logger.Verbose($"Found {typeCount} serialized types"); for (int i = 0; i < typeCount; i++) { @@ -120,9 +120,9 @@ namespace AssetStudio // Read Objects int objectCount = reader.ReadInt32(); - m_Objects = new List(objectCount); - Objects = new List(objectCount); - ObjectsDic = new Dictionary(objectCount); + m_Objects = new List(); + Objects = new List(); + ObjectsDic = new Dictionary(); Logger.Verbose($"Found {objectCount} objects"); for (int i = 0; i < objectCount; i++) { @@ -182,7 +182,7 @@ namespace AssetStudio { int scriptCount = reader.ReadInt32(); Logger.Verbose($"Found {scriptCount} scripts"); - m_ScriptTypes = new List(scriptCount); + m_ScriptTypes = new List(); for (int i = 0; i < scriptCount; i++) { var m_ScriptType = new LocalSerializedObjectIdentifier(); @@ -202,7 +202,7 @@ namespace AssetStudio } int externalsCount = reader.ReadInt32(); - m_Externals = new List(externalsCount); + m_Externals = new List(); Logger.Verbose($"Found {externalsCount} externals"); for (int i = 0; i < externalsCount; i++) { @@ -225,7 +225,7 @@ namespace AssetStudio if (header.m_Version >= SerializedFileFormatVersion.SupportsRefObject) { int refTypesCount = reader.ReadInt32(); - m_RefTypes = new List(refTypesCount); + m_RefTypes = new List(); Logger.Verbose($"Found {refTypesCount} reference types"); for (int i = 0; i < refTypesCount; i++) { diff --git a/AssetStudio/TypeTreeHelper.cs b/AssetStudio/TypeTreeHelper.cs index b0e5210..5b493f2 100644 --- a/AssetStudio/TypeTreeHelper.cs +++ b/AssetStudio/TypeTreeHelper.cs @@ -250,7 +250,7 @@ namespace AssetStudio var next = 4 + first.Count; var second = GetNodes(map, next); var size = reader.ReadInt32(); - var dic = new List>(size); + var dic = new List>(); for (int j = 0; j < size; j++) { int tmp1 = 0; @@ -276,7 +276,7 @@ namespace AssetStudio var vector = GetNodes(m_Nodes, i); i += vector.Count - 1; var size = reader.ReadInt32(); - var list = new List(size); + var list = new List(); for (int j = 0; j < size; j++) { int tmp = 3; diff --git a/AssetStudio/WebFile.cs b/AssetStudio/WebFile.cs index 9bce62c..427dd0c 100644 --- a/AssetStudio/WebFile.cs +++ b/AssetStudio/WebFile.cs @@ -6,7 +6,7 @@ namespace AssetStudio { public class WebFile { - public StreamFile[] fileList; + public List fileList; private class WebData { @@ -43,7 +43,7 @@ namespace AssetStudio dataList.Add(data); } Logger.Verbose("Writing files to streams..."); - fileList = new StreamFile[dataList.Count]; + fileList = new List(); for (int i = 0; i < dataList.Count; i++) { var data = dataList[i];