From 6fdb0c7b0ef3c59b9c28295896e063542d73a90e Mon Sep 17 00:00:00 2001 From: Perfare Date: Thu, 6 Aug 2020 23:17:44 +0800 Subject: [PATCH] add ResourceManager --- AssetStudio/AssetStudio.csproj | 1 + AssetStudio/AssetsManager.cs | 3 ++ AssetStudio/Classes/ResourceManager.cs | 19 ++++++++++ AssetStudioGUI/Studio.cs | 48 ++++++++++++-------------- 4 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 AssetStudio/Classes/ResourceManager.cs diff --git a/AssetStudio/AssetStudio.csproj b/AssetStudio/AssetStudio.csproj index 788850d..85fe323 100644 --- a/AssetStudio/AssetStudio.csproj +++ b/AssetStudio/AssetStudio.csproj @@ -103,6 +103,7 @@ + diff --git a/AssetStudio/AssetsManager.cs b/AssetStudio/AssetsManager.cs index 1105a9b..762d3dc 100644 --- a/AssetStudio/AssetsManager.cs +++ b/AssetStudio/AssetsManager.cs @@ -333,6 +333,9 @@ namespace AssetStudio case ClassIDType.VideoClip: obj = new VideoClip(objectReader); break; + case ClassIDType.ResourceManager: + obj = new ResourceManager(objectReader); + break; default: obj = new Object(objectReader); break; diff --git a/AssetStudio/Classes/ResourceManager.cs b/AssetStudio/Classes/ResourceManager.cs new file mode 100644 index 0000000..05f159b --- /dev/null +++ b/AssetStudio/Classes/ResourceManager.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; + +namespace AssetStudio +{ + public class ResourceManager : Object + { + public KeyValuePair>[] m_Container; + + public ResourceManager(ObjectReader reader) : base(reader) + { + var m_ContainerSize = reader.ReadInt32(); + m_Container = new KeyValuePair>[m_ContainerSize]; + for (int i = 0; i < m_ContainerSize; i++) + { + m_Container[i] = new KeyValuePair>(reader.ReadAlignedString(), new PPtr(reader)); + } + } + } +} diff --git a/AssetStudioGUI/Studio.cs b/AssetStudioGUI/Studio.cs index 6992399..2d7b1d1 100644 --- a/AssetStudioGUI/Studio.cs +++ b/AssetStudioGUI/Studio.cs @@ -103,12 +103,11 @@ namespace AssetStudioGUI string productName = null; var objectCount = assetsManager.assetsFileList.Sum(x => x.Objects.Count); var objectAssetItemDic = new Dictionary(objectCount); + var containers = new List<(PPtr, string)>(); int i = 0; Progress.Reset(); foreach (var assetsFile in assetsManager.assetsFileList) { - var tempExportableAssets = new List(); - Dictionary containers = null; foreach (var asset in assetsFile.Objects) { var assetItem = new AssetItem(asset); @@ -173,7 +172,6 @@ namespace AssetStudioGUI productName = m_PlayerSettings.productName; break; case AssetBundle m_AssetBundle: - containers = new Dictionary(); foreach (var m_Container in m_AssetBundle.m_Container) { var preloadIndex = m_Container.Value.preloadIndex; @@ -181,15 +179,17 @@ namespace AssetStudioGUI var preloadEnd = preloadIndex + preloadSize; for (int k = preloadIndex; k < preloadEnd; k++) { - var m_PreloadTable = m_AssetBundle.m_PreloadTable[k]; - if (m_PreloadTable.m_FileID == 0) - { - containers[m_AssetBundle.m_PreloadTable[k].m_PathID] = m_Container.Key; - } + containers.Add((m_AssetBundle.m_PreloadTable[k], m_Container.Key)); } } assetItem.Text = m_AssetBundle.m_Name; break; + case ResourceManager m_ResourceManager: + foreach (var m_Container in m_ResourceManager.m_Container) + { + containers.Add((m_Container.Value, m_Container.Key)); + } + break; case NamedObject m_NamedObject: assetItem.Text = m_NamedObject.m_Name; break; @@ -200,28 +200,24 @@ namespace AssetStudioGUI } if (Properties.Settings.Default.displayAll || exportable) { - tempExportableAssets.Add(assetItem); + exportableAssets.Add(assetItem); } Progress.Report(++i, objectCount); } - foreach (var item in tempExportableAssets) - { - if (containers != null) - { - if (containers.TryGetValue(item.Asset.m_PathID, out var container)) - { - if (!string.IsNullOrEmpty(container)) - { - item.Container = container; - } - } - } - item.SetSubItems(); - } - exportableAssets.AddRange(tempExportableAssets); - tempExportableAssets.Clear(); - containers?.Clear(); } + foreach ((var pptr, var container) in containers) + { + if (pptr.TryGet(out var obj)) + { + objectAssetItemDic[obj].Container = container; + } + } + foreach (var tmp in exportableAssets) + { + tmp.SetSubItems(); + } + containers.Clear(); + visibleAssets = exportableAssets; StatusStripUpdate("Building tree structure...");