feat: add item dumper

This commit is contained in:
2026-06-18 17:20:40 -03:00
parent 1354874bb2
commit 6dad0eecee
2 changed files with 73 additions and 1 deletions
+59 -1
View File
@@ -21,15 +21,24 @@ struct CharacterInfo
public string iconFilePath; public string iconFilePath;
} }
struct ItemInfo
{
public string id;
public string name;
public string iconFilePath;
}
class Dumper class Dumper
{ {
private DefaultFileProvider? _provider; private DefaultFileProvider? _provider;
private IAesVfsReader? _dataPak; private IAesVfsReader? _dataPak;
private readonly Dictionary<int, CharacterInfo> _characterMap = new();
private Logger _log; private Logger _log;
private string _outDir; private string _outDir;
private readonly Dictionary<int, CharacterInfo> _characterMap = new();
private readonly Dictionary<string, ItemInfo> _itemMap = new();
public Dumper(string outDir) public Dumper(string outDir)
{ {
_log = new Logger("Dumper"); _log = new Logger("Dumper");
@@ -160,6 +169,55 @@ class Dumper
return; return;
} }
public void DumpItems()
{
if (_dataPak == null || _provider == null)
throw new InvalidOperationException("Attempted to call dump function without dumper initialization");
_log.Info("Dumping character icons");
List<string> itemDBPaths = _dataPak.Files.Keys.Where(x => x.Contains("/ItemDB.uasset", StringComparison.OrdinalIgnoreCase)).ToList();
foreach (string path in itemDBPaths)
{
string cleanPath = path.Contains('.') ? path[..path.LastIndexOf('.')] : path;
if (_provider.TryLoadPackageObject<UDataTable>(cleanPath, out UDataTable? dataTable))
{
foreach (KeyValuePair<FName, FStructFallback> row in dataTable.RowMap)
{
List<FPropertyTag> props = row.Value.Properties;
string itemId = row.Key.Text;
if (!TryGetProp(props, "Type", out EInventoryItemType itemType) || !TryGetProp(props, "UIData", out FStructFallback uiDataFb))
throw new KeyNotFoundException("Type or UIData was not found.");
UIDataStruct uiData = uiDataFb.MapToStruct<UIDataStruct>();
if (itemType != EInventoryItemType.Item)
{
_log.Verbose("Ignoring invalid item type ({0})", itemType.ToString());
continue;
}
if (uiData.IconAssetList.Length == 0)
throw new InvalidDataException("Item's UIData had no icons");
_itemMap[itemId] = new ItemInfo
{
id = itemId,
name = uiData.DisplayName.ToString(),
iconFilePath = uiData.IconAssetList[0].ToString()
};
}
}
}
WriteJson("items", _itemMap.Values);
_log.Info("Dumped all items");
}
/* /*
* internal helper functions * internal helper functions
*/ */
+14
View File
@@ -24,6 +24,20 @@ catch (Exception er)
return 1; return 1;
} }
log.Info("Getting item data and icons");
try
{
dumper.DumpItems();
}
catch (Exception er)
{
log.Error("Error while dumping items");
log.Error("Exception: {0}", er.ToString());
Console.ReadKey();
return 1;
}
log.Info("Dump finished"); log.Info("Dump finished");
return 0; return 0;