feat: add item dumper
This commit is contained in:
+59
-1
@@ -21,15 +21,24 @@ struct CharacterInfo
|
||||
public string iconFilePath;
|
||||
}
|
||||
|
||||
struct ItemInfo
|
||||
{
|
||||
public string id;
|
||||
public string name;
|
||||
public string iconFilePath;
|
||||
}
|
||||
|
||||
class Dumper
|
||||
{
|
||||
private DefaultFileProvider? _provider;
|
||||
private IAesVfsReader? _dataPak;
|
||||
private readonly Dictionary<int, CharacterInfo> _characterMap = new();
|
||||
private Logger _log;
|
||||
|
||||
private string _outDir;
|
||||
|
||||
private readonly Dictionary<int, CharacterInfo> _characterMap = new();
|
||||
private readonly Dictionary<string, ItemInfo> _itemMap = new();
|
||||
|
||||
public Dumper(string outDir)
|
||||
{
|
||||
_log = new Logger("Dumper");
|
||||
@@ -160,6 +169,55 @@ class Dumper
|
||||
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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user