diff --git a/AssetStudio/Classes/AnimationClip.cs b/AssetStudio/Classes/AnimationClip.cs index 3cc54c2..38f9559 100644 --- a/AssetStudio/Classes/AnimationClip.cs +++ b/AssetStudio/Classes/AnimationClip.cs @@ -527,14 +527,13 @@ namespace AssetStudio public List ReadData() { var frameList = new List(); - using (Stream stream = new MemoryStream()) + var buffer = new byte[data.Length * 4]; + Buffer.BlockCopy(data, 0, buffer, 0, buffer.Length); + using (var reader = new BinaryReader(new MemoryStream(buffer))) { - BinaryWriter writer = new BinaryWriter(stream); - writer.Write(data); - stream.Position = 0; - while (stream.Position < stream.Length) + while (reader.BaseStream.Position < reader.BaseStream.Length) { - frameList.Add(new StreamedFrame(new BinaryReader(stream))); + frameList.Add(new StreamedFrame(reader)); } } diff --git a/AssetStudio/Classes/AnimatorOverrideController.cs b/AssetStudio/Classes/AnimatorOverrideController.cs index 62c30cc..6f7d095 100644 --- a/AssetStudio/Classes/AnimatorOverrideController.cs +++ b/AssetStudio/Classes/AnimatorOverrideController.cs @@ -5,22 +5,32 @@ using System.Text; namespace AssetStudio { + public class AnimationClipOverride + { + public PPtr m_OriginalClip; + public PPtr m_OverrideClip; + + public AnimationClipOverride(ObjectReader reader) + { + m_OriginalClip = reader.ReadPPtr(); + m_OverrideClip = reader.ReadPPtr(); + } + } + public class AnimatorOverrideController : NamedObject { public PPtr m_Controller; - public PPtr[][] m_Clips; + public List m_Clips; public AnimatorOverrideController(ObjectReader reader) : base(reader) { m_Controller = reader.ReadPPtr(); int numOverrides = reader.ReadInt32(); - m_Clips = new PPtr[numOverrides][]; + m_Clips = new List(numOverrides); for (int i = 0; i < numOverrides; i++) { - m_Clips[i] = new PPtr[2]; - m_Clips[i][0] = reader.ReadPPtr(); - m_Clips[i][1] = reader.ReadPPtr(); + m_Clips.Add(new AnimationClipOverride(reader)); } } } diff --git a/AssetStudio/Classes/AssetBundle.cs b/AssetStudio/Classes/AssetBundle.cs index 27dac69..5ab7db1 100644 --- a/AssetStudio/Classes/AssetBundle.cs +++ b/AssetStudio/Classes/AssetBundle.cs @@ -5,41 +5,39 @@ using System.Text; namespace AssetStudio { + public class AssetInfo + { + public int preloadIndex; + public int preloadSize; + public PPtr asset; + + public AssetInfo(ObjectReader reader) + { + preloadIndex = reader.ReadInt32(); + preloadSize = reader.ReadInt32(); + asset = reader.ReadPPtr(); + } + } public sealed class AssetBundle : NamedObject { - public class AssetInfo - { - public int preloadIndex; - public int preloadSize; - public PPtr asset; - } - - public class ContainerData - { - public string first; - public AssetInfo second; - } - - public List m_Container = new List(); + public List m_PreloadTable; + public List> m_Container; public AssetBundle(ObjectReader reader) : base(reader) { - var size = reader.ReadInt32(); - for (int i = 0; i < size; i++) + var m_PreloadTableSize = reader.ReadInt32(); + m_PreloadTable = new List(m_PreloadTableSize); + for (int i = 0; i < m_PreloadTableSize; i++) { - reader.ReadPPtr(); + m_PreloadTable.Add(reader.ReadPPtr()); } - size = reader.ReadInt32(); - for (int i = 0; i < size; i++) + + var m_ContainerSize = reader.ReadInt32(); + m_Container = new List>(m_ContainerSize); + for (int i = 0; i < m_ContainerSize; i++) { - var temp = new ContainerData(); - temp.first = reader.ReadAlignedString(); - temp.second = new AssetInfo(); - temp.second.preloadIndex = reader.ReadInt32(); - temp.second.preloadSize = reader.ReadInt32(); - temp.second.asset = reader.ReadPPtr(); - m_Container.Add(temp); + m_Container.Add(new KeyValuePair(reader.ReadAlignedString(), new AssetInfo(reader))); } } } diff --git a/AssetStudio/CommonString.cs b/AssetStudio/CommonString.cs index 55bfdee..0fc0d60 100644 --- a/AssetStudio/CommonString.cs +++ b/AssetStudio/CommonString.cs @@ -110,7 +110,7 @@ namespace AssetStudio {1057, "int2_storage"}, {1070, "int3_storage"}, {1083, "BoundsInt"}, - {1092, "m_CorrespondingSourceObject"} + {1093, "m_CorrespondingSourceObject"} }; } } diff --git a/AssetStudio/Extensions/BinaryWriterExtensions.cs b/AssetStudio/Extensions/BinaryWriterExtensions.cs index 81f488f..2557813 100644 --- a/AssetStudio/Extensions/BinaryWriterExtensions.cs +++ b/AssetStudio/Extensions/BinaryWriterExtensions.cs @@ -14,11 +14,6 @@ namespace AssetStudio } } - public static void Write(this BinaryWriter writer, uint[] array) - { - WriteArray(writer.Write, array); - } - public static void AlignStream(this BinaryWriter writer, int alignment) { var pos = writer.BaseStream.Position; diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index 07d11e6..d18b82e 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -66,7 +66,7 @@ namespace AssetStudioGUI //tree search private int nextGObject; - private List treeSrcResults = new List(); + private List treeSrcResults = new List(); [DllImport("gdi32.dll")] private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts); @@ -481,12 +481,9 @@ namespace AssetStudioGUI { if (treeSrcResults.Count == 0) { - foreach (var node in treeNodeDictionary.Values) + foreach (TreeNode node in sceneTreeView.Nodes) { - if (node.Text.IndexOf(treeSearch.Text, StringComparison.CurrentCultureIgnoreCase) >= 0) - { - treeSrcResults.Add(node); - } + TreeNodeSearch(node); } } if (treeSrcResults.Count > 0) @@ -502,6 +499,19 @@ namespace AssetStudioGUI } } + private void TreeNodeSearch(TreeNode treeNode) + { + if (treeNode.Text.IndexOf(treeSearch.Text, StringComparison.CurrentCultureIgnoreCase) >= 0) + { + treeSrcResults.Add(treeNode); + } + + foreach (TreeNode node in treeNode.Nodes) + { + TreeNodeSearch(node); + } + } + private void sceneTreeView_AfterCheck(object sender, TreeViewEventArgs e) { foreach (TreeNode childNode in e.Node.Nodes) @@ -1701,8 +1711,6 @@ namespace AssetStudioGUI pair.Value.Dispose(); } LoadedModuleDic.Clear(); - - treeNodeDictionary.Clear(); } private void assetListView_MouseClick(object sender, MouseEventArgs e) @@ -1820,9 +1828,9 @@ namespace AssetStudioGUI private void jumpToSceneHierarchyToolStripMenuItem_Click(object sender, EventArgs e) { var selectasset = (AssetItem)assetListView.Items[assetListView.SelectedIndices[0]]; - if (selectasset.gameObject != null) + if (selectasset.TreeNode != null) { - sceneTreeView.SelectedNode = treeNodeDictionary[selectasset.gameObject]; + sceneTreeView.SelectedNode = selectasset.TreeNode; tabControl1.SelectedTab = tabPage1; } } diff --git a/AssetStudioGUI/Components/AssetItem.cs b/AssetStudioGUI/Components/AssetItem.cs index 81f9490..452fee6 100644 --- a/AssetStudioGUI/Components/AssetItem.cs +++ b/AssetStudioGUI/Components/AssetItem.cs @@ -12,7 +12,7 @@ namespace AssetStudioGUI public string TypeString; public string InfoText; public string UniqueID; - public GameObject gameObject; + public GameObjectTreeNode TreeNode; public AssetItem(ObjectReader reader) { diff --git a/AssetStudioGUI/Studio.cs b/AssetStudioGUI/Studio.cs index f04903f..50bd9f5 100644 --- a/AssetStudioGUI/Studio.cs +++ b/AssetStudioGUI/Studio.cs @@ -15,11 +15,9 @@ namespace AssetStudioGUI internal static class Studio { public static AssetsManager assetsManager = new AssetsManager(); - private static HashSet assetsNameHash = new HashSet(); public static List exportableAssets = new List(); public static List visibleAssets = new List(); - public static Dictionary> AllTypeMap = new Dictionary>(); - public static Dictionary treeNodeDictionary = new Dictionary(); + public static Dictionary> AllTypeMap = new Dictionary>(); //TODO Delete it public static bool ModuleLoaded; public static Dictionary LoadedModuleDic = new Dictionary(); @@ -96,9 +94,10 @@ namespace AssetStudioGUI public static void BuildAssetList(Dictionary tempDic, bool displayAll, bool displayOriginalName, out string productName) { - productName = string.Empty; Logger.Info("Building asset list..."); + productName = string.Empty; + var assetsNameHash = new HashSet(); var progressCount = assetsManager.assetsFileList.Sum(x => x.ObjectReaders.Count); int j = 0; Progress.Reset(); @@ -248,17 +247,18 @@ namespace AssetStudioGUI } if (displayOriginalName && ab != null) { - foreach (var x in tempExportableAssets) + foreach (var asset in tempExportableAssets) { - var replacename = ab.m_Container.Find(y => y.second.asset.m_PathID == x.reader.m_PathID)?.first; - if (!string.IsNullOrEmpty(replacename)) + var originalPath = ab.m_Container.Find(y => y.Value.asset.m_PathID == asset.reader.m_PathID).Key; + if (!string.IsNullOrEmpty(originalPath)) { - var ex = Path.GetExtension(replacename); - x.Text = !string.IsNullOrEmpty(ex) ? replacename.Replace(ex, "") : replacename; - if (!assetsNameHash.Add((x.TypeString + x.Text).ToUpper())) + var extension = Path.GetExtension(originalPath); + if (!string.IsNullOrEmpty(extension) && asset.Type == ClassIDType.TextAsset) { - x.Text = Path.GetDirectoryName(replacename) + "\\" + Path.GetFileNameWithoutExtension(replacename) + x.UniqueID; + //asset.Extension = extension; //TODO } + + asset.Text = Path.GetDirectoryName(originalPath) + "\\" + asset.Text; } } } @@ -277,6 +277,7 @@ namespace AssetStudioGUI if (gameObjectCount > 0) { Logger.Info("Building tree structure..."); + var treeNodeDictionary = new Dictionary(); int i = 0; Progress.Reset(); foreach (var assetsFile in assetsManager.assetsFileList) @@ -285,6 +286,12 @@ namespace AssetStudioGUI foreach (var m_GameObject in assetsFile.GameObjects.Values) { + if (!treeNodeDictionary.TryGetValue(m_GameObject, out var currentNode)) + { + currentNode = new GameObjectTreeNode(m_GameObject); + treeNodeDictionary.Add(m_GameObject, currentNode); + } + foreach (var m_Component in m_GameObject.m_Components) { if (m_Component.TryGet(out var asset)) @@ -310,7 +317,7 @@ namespace AssetStudioGUI if (m_MeshFilter.m_Mesh.TryGet(out objectReader)) { var item = tempDic[objectReader]; - item.gameObject = m_GameObject; + item.TreeNode = currentNode; } } break; @@ -324,7 +331,7 @@ namespace AssetStudioGUI if (m_SkinnedMeshRenderer.m_Mesh.TryGet(out objectReader)) { var item = tempDic[objectReader]; - item.gameObject = m_GameObject; + item.TreeNode = currentNode; } } break; @@ -357,11 +364,6 @@ namespace AssetStudioGUI } } - if (!treeNodeDictionary.TryGetValue(m_GameObject, out var currentNode)) - { - currentNode = new GameObjectTreeNode(m_GameObject); - treeNodeDictionary.Add(m_GameObject, currentNode); - } parentNode.Nodes.Add(currentNode); Progress.Report(++i, gameObjectCount); @@ -372,6 +374,8 @@ namespace AssetStudioGUI treeNodeCollection.Add(fileNode); } } + + treeNodeDictionary.Clear(); } return treeNodeCollection;