From 462ac7b396e3070246b9f8e477838774e1d94fd8 Mon Sep 17 00:00:00 2001 From: Razmoth <32140579+Razmoth@users.noreply.github.com> Date: Tue, 20 Feb 2024 20:42:47 +0400 Subject: [PATCH] - [Core] fix bug with `AssetMap` --- AssetStudio.GUI/AssetBrowser.cs | 19 +++++++--------- AssetStudio/AssetsHelper.cs | 39 +++++++++++++-------------------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/AssetStudio.GUI/AssetBrowser.cs b/AssetStudio.GUI/AssetBrowser.cs index 7bdec1e..ca5a8a0 100644 --- a/AssetStudio.GUI/AssetBrowser.cs +++ b/AssetStudio.GUI/AssetBrowser.cs @@ -126,7 +126,7 @@ private void BuildAssetData(List exportableAssets, AssetEntry[] entri { foreach (var asset in assetsFile.Objects) { - ProcessAssetData(asset, exportableAssets, entries, objectAssetItemDic, mihoyoBinDataNames, containers); + ProcessAssetData(asset, exportableAssets, objectAssetItemDic, mihoyoBinDataNames, containers); } } foreach ((var pptr, var name) in mihoyoBinDataNames) @@ -151,16 +151,12 @@ private void BuildAssetData(List exportableAssets, AssetEntry[] entri } } containers.Clear(); - for (int i = exportableAssets.Count - 1; i >= 0; i--) - { - var asset = exportableAssets[i]; - if (!entries.Any(x => x.Container == asset.Container && x.Name == asset.Text && x.Type == asset.Type && x.PathID == asset.m_PathID)) - { - exportableAssets.Remove(asset); - } - } + + var matches = exportableAssets.Where(asset => entries.Any(x => x.Container == asset.Container && x.Name == asset.Text && x.Type == asset.Type && x.PathID == asset.m_PathID)).ToArray(); + exportableAssets.Clear(); + exportableAssets.AddRange(matches); } - private void ProcessAssetData(Object asset, List exportableAssets, AssetEntry[] entries, Dictionary objectAssetItemDic, List<(PPtr, string)> mihoyoBinDataNames, List<(PPtr, string)> containers) + private void ProcessAssetData(Object asset, List exportableAssets, Dictionary objectAssetItemDic, List<(PPtr, string)> mihoyoBinDataNames, List<(PPtr, string)> containers) { var assetItem = new AssetItem(asset); objectAssetItemDic.Add(asset, assetItem); @@ -231,12 +227,13 @@ private void ProcessAssetData(Object asset, List exportableAssets, As exportable = true; break; } + if (assetItem.Text == "") { assetItem.Text = assetItem.TypeString + assetItem.UniqueID; } - if (entries.Any(x => x.Name == assetItem.Text && x.Type == assetItem.Type) && exportable) + if (exportable) { exportableAssets.Add(assetItem); } diff --git a/AssetStudio/AssetsHelper.cs b/AssetStudio/AssetsHelper.cs index a9893ed..9aa58e8 100644 --- a/AssetStudio/AssetsHelper.cs +++ b/AssetStudio/AssetsHelper.cs @@ -339,6 +339,7 @@ public static async Task BuildAssetMap(string[] files, string mapName, Game game private static void BuildAssetMap(string file, List assets, ClassIDType[] typeFilters = null, Regex[] nameFilters = null, Regex[] containerFilters = null) { + var matches = new List(); var containers = new List<(PPtr, string)>(); var mihoyoBinDataNames = new List<(PPtr, string)>(); var objectAssetItemDic = new Dictionary(); @@ -457,25 +458,18 @@ private static void BuildAssetMap(string file, List assets, ClassIDT objectAssetItemDic.Add(obj, asset); assetsFile.AddObject(obj); } - var isMatchRegex = nameFilters.IsNullOrEmpty() || nameFilters.Any(x => x.IsMatch(asset.Name) || asset.Type == ClassIDType.Animator); - var isFilteredType = typeFilters.IsNullOrEmpty() || typeFilters.Contains(asset.Type) || asset.Type == ClassIDType.Animator; - if (isMatchRegex && isFilteredType && exportable) + if (exportable) { - assets.Add(asset); + matches.Add(asset); } } } foreach ((var pptr, var asset) in animators) { - if (pptr.TryGet(out var gameObject) && (nameFilters.IsNullOrEmpty() || nameFilters.Any(x => x.IsMatch(gameObject.m_Name))) && (typeFilters.IsNullOrEmpty() || typeFilters.Contains(asset.Type))) + if (pptr.TryGet(out var gameObject)) { asset.Name = gameObject.m_Name; } - else - { - assets.Remove(asset); - } - } foreach ((var pptr, var name) in mihoyoBinDataNames) { @@ -490,24 +484,21 @@ private static void BuildAssetMap(string file, List assets, ClassIDT else asset.Name = $"BinFile #{asset.PathID}"; } } - if (!containerFilters.IsNullOrEmpty()) + foreach ((var pptr, var container) in containers) { - foreach ((var pptr, var container) in containers) + if (pptr.TryGet(out var obj)) { - if (pptr.TryGet(out var obj)) - { - var item = objectAssetItemDic[obj]; - if (containerFilters.Any(x => x.IsMatch(container))) - { - item.Container = container; - } - else - { - assets.Remove(item); - } - } + objectAssetItemDic[obj].Container = container; } } + + assets.AddRange(matches.Where(x => + { + var isMatchRegex = nameFilters.IsNullOrEmpty() || nameFilters.Any(y => y.IsMatch(x.Name)); + var isFilteredType = typeFilters.IsNullOrEmpty() || typeFilters.Contains(x.Type); + var isContainerMatch = containerFilters.IsNullOrEmpty() || containerFilters.Any(y => y.IsMatch(x.Container)); + return isMatchRegex && isFilteredType && isContainerMatch; + })); } public static string[] ParseAssetMap(string mapName, ExportListType mapType, ClassIDType[] typeFilter, Regex[] nameFilter, Regex[] containerFilter)