style: move repeated code to their own functions
This commit is contained in:
+58
-128
@@ -123,26 +123,12 @@ class Dumper
|
|||||||
*/
|
*/
|
||||||
public void DumpCharacters()
|
public void DumpCharacters()
|
||||||
{
|
{
|
||||||
if (_dataPak == null || _provider == null)
|
ProcessDataTables("/CharacterDescriptionDB.uasset", "characters", (rowKey, props) =>
|
||||||
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
|
||||||
|
|
||||||
_log.Info("Dumping characters");
|
|
||||||
|
|
||||||
List<string> charDbPaths = _dataPak.Files.Keys.Where(x => x.Contains("/CharacterDescriptionDB.uasset", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
||||||
|
|
||||||
foreach (string path in charDbPaths)
|
|
||||||
{
|
{
|
||||||
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;
|
|
||||||
|
|
||||||
if (!TryGetProp<int>(props, "CharacterIndex", out int charIndex))
|
if (!TryGetProp<int>(props, "CharacterIndex", out int charIndex))
|
||||||
throw new KeyNotFoundException("CharacterIndex was not found.");
|
throw new KeyNotFoundException("CharacterIndex was not found.");
|
||||||
if (charIndex == -1) continue;
|
|
||||||
|
if (charIndex == -1) return;
|
||||||
|
|
||||||
if (!TryGetStringProp<FText>(props, "DisplayName", out string charName) || !TryGetStringProp<FName>(props, "IconFilePath", out string charIconFilePath))
|
if (!TryGetStringProp<FText>(props, "DisplayName", out string charName) || !TryGetStringProp<FName>(props, "IconFilePath", out string charIconFilePath))
|
||||||
throw new KeyNotFoundException("DisplayName or IconFilePath was not found.");
|
throw new KeyNotFoundException("DisplayName or IconFilePath was not found.");
|
||||||
@@ -153,168 +139,113 @@ class Dumper
|
|||||||
idx = charIndex,
|
idx = charIndex,
|
||||||
iconFilePath = charIconFilePath
|
iconFilePath = charIconFilePath
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_log.Info("Dumped {0} characters", _characterMap.Count);
|
_log.Info("Dumped {0} characters", _characterMap.Count);
|
||||||
|
|
||||||
WriteJson("characters", _characterMap.Values);
|
WriteJson("characters", _characterMap.Values);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DumpCharacterIcons()
|
|
||||||
{
|
|
||||||
if (_provider == null)
|
|
||||||
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
|
||||||
|
|
||||||
_log.Info("Dumping character icons");
|
|
||||||
|
|
||||||
foreach (CharacterInfo info in _characterMap.Values)
|
|
||||||
ExportIcon(info.iconFilePath, "/character-icons/");
|
|
||||||
|
|
||||||
_log.Info("Dumped all character icons");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DumpItems()
|
public void DumpItems()
|
||||||
{
|
{
|
||||||
if (_dataPak == null || _provider == null)
|
ProcessDataTables("/ItemDB.uasset", "items", (rowKey, props) =>
|
||||||
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
|
||||||
|
|
||||||
_log.Info("Dumping items");
|
|
||||||
|
|
||||||
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)
|
if (!TryGetProp(props, "Type", out EInventoryItemType itemType)
|
||||||
|| !TryGetProp(props, "UIData", out FStructFallback uiDataFb)
|
|| !TryGetProp(props, "UIData", out FStructFallback uiDataFb)
|
||||||
|| !TryGetProp(props, "Role", out EPlayerRole role)
|
|| !TryGetProp(props, "Role", out EPlayerRole role)
|
||||||
|| !TryGetProp(props, "Inventory", out bool isInventory)
|
|| !TryGetProp(props, "Inventory", out bool isInventory)
|
||||||
|| !TryGetProp(props, "IsFakeItem", out bool isFakeItem)
|
|| !TryGetProp(props, "IsFakeItem", out bool isFakeItem))
|
||||||
)
|
|
||||||
throw new KeyNotFoundException("Type, UIData, Role, Inventory or IsFakeItem was not found.");
|
throw new KeyNotFoundException("Type, UIData, Role, Inventory or IsFakeItem was not found.");
|
||||||
|
|
||||||
UIDataStruct uiData = uiDataFb.MapToStruct<UIDataStruct>();
|
UIDataStruct uiData = uiDataFb.MapToStruct<UIDataStruct>();
|
||||||
|
|
||||||
if (isFakeItem || !isInventory || itemType != EInventoryItemType.Item || role != EPlayerRole.VE_Camper)
|
if (isFakeItem || !isInventory || itemType != EInventoryItemType.Item || role != EPlayerRole.VE_Camper)
|
||||||
{
|
return;
|
||||||
_log.Verbose("Ignoring invalid item ({0})", itemId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uiData.IconAssetList.Length == 0)
|
if (uiData.IconAssetList.Length == 0)
|
||||||
throw new InvalidDataException("Item's UIData had no icons");
|
throw new InvalidDataException("Item's UIData had no icons");
|
||||||
|
|
||||||
_itemMap[itemId] = new ItemInfo
|
_itemMap[rowKey] = new ItemInfo
|
||||||
{
|
{
|
||||||
id = itemId,
|
id = rowKey,
|
||||||
name = uiData.DisplayName.ToString(),
|
name = uiData.DisplayName.ToString(),
|
||||||
iconFilePath = uiData.IconAssetList[0].ToString()
|
iconFilePath = uiData.IconAssetList[0].ToString()
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteJson("items", _itemMap.Values);
|
|
||||||
_log.Info("Dumped {0} items", _itemMap.Count);
|
_log.Info("Dumped {0} items", _itemMap.Count);
|
||||||
}
|
WriteJson("items", _itemMap.Values);
|
||||||
|
|
||||||
public void DumpItemIcons()
|
|
||||||
{
|
|
||||||
if (_provider == null)
|
|
||||||
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
|
||||||
|
|
||||||
_log.Info("Dumping item icons");
|
|
||||||
|
|
||||||
foreach (ItemInfo info in _itemMap.Values)
|
|
||||||
ExportIcon(info.iconFilePath, "/item-icons/");
|
|
||||||
|
|
||||||
_log.Info("Dumped all item icons");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DumpOfferings()
|
public void DumpOfferings()
|
||||||
|
{
|
||||||
|
ProcessDataTables("/OfferingDB.uasset", "offerings", (rowKey, props) =>
|
||||||
|
{
|
||||||
|
if (!TryGetProp(props, "Role", out EPlayerRole role)
|
||||||
|
|| !TryGetProp(props, "UIData", out FStructFallback uiDataFb)
|
||||||
|
|| !TryGetProp(props, "Inventory", out bool isInventory)
|
||||||
|
|| !TryGetProp(props, "IsFakeItem", out bool isFakeItem))
|
||||||
|
throw new KeyNotFoundException("Role, UIData, Inventory or IsFakeItem was not found");
|
||||||
|
|
||||||
|
UIDataStruct uiData = uiDataFb.MapToStruct<UIDataStruct>();
|
||||||
|
|
||||||
|
if (!isInventory || isFakeItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (uiData.IconAssetList.Length == 0)
|
||||||
|
throw new InvalidDataException("Offerings's UIData had no icons");
|
||||||
|
|
||||||
|
_offeringMap[rowKey] = new OfferingInfo
|
||||||
|
{
|
||||||
|
id = rowKey,
|
||||||
|
name = uiData.DisplayName.ToString(),
|
||||||
|
iconFilePath = uiData.IconAssetList[0].ToString(),
|
||||||
|
role = role
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
_log.Info("Dumped {0} offerings", _offeringMap.Count);
|
||||||
|
WriteJson("offerings", _offeringMap.Values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DumpCharacterIcons() => ExportIcons(_characterMap.Values.Select(x => x.iconFilePath), "character", "/character-icons/");
|
||||||
|
public void DumpItemIcons() => ExportIcons(_itemMap.Values.Select(x => x.iconFilePath), "item", "/item-icons/");
|
||||||
|
public void DumpOfferingIcons() => ExportIcons(_offeringMap.Values.Select(x => x.iconFilePath), "offering", "/offering-icons/");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bulk functions for dumping
|
||||||
|
*/
|
||||||
|
private void ProcessDataTables(string pathFilter, string logName, Action<string, List<FPropertyTag>> rowProcessor)
|
||||||
{
|
{
|
||||||
if (_dataPak == null || _provider == null)
|
if (_dataPak == null || _provider == null)
|
||||||
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
||||||
|
|
||||||
_log.Info("Dumping offerings");
|
_log.Info($"Dumping {logName}");
|
||||||
|
|
||||||
List<string> offeringDBPaths = _dataPak.Files.Keys.Where(x => x.Contains("/OfferingDB.uasset", StringComparison.OrdinalIgnoreCase)).ToList();
|
var dbPaths = _dataPak.Files.Keys.Where(x => x.Contains(pathFilter, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
foreach (string path in offeringDBPaths)
|
foreach (string path in dbPaths)
|
||||||
{
|
{
|
||||||
string cleanPath = path.Contains('.') ? path[..path.LastIndexOf('.')] : path;
|
string cleanPath = path.Contains('.') ? path[..path.LastIndexOf('.')] : path;
|
||||||
|
|
||||||
if (_provider.TryLoadPackageObject<UDataTable>(cleanPath, out UDataTable? dataTable))
|
if (_provider.TryLoadPackageObject<UDataTable>(cleanPath, out UDataTable? dataTable))
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<FName, FStructFallback> row in dataTable.RowMap)
|
foreach (KeyValuePair<FName, FStructFallback> row in dataTable.RowMap)
|
||||||
{
|
rowProcessor(row.Key.Text, row.Value.Properties);
|
||||||
List<FPropertyTag> props = row.Value.Properties;
|
|
||||||
|
|
||||||
string offeringId = row.Key.Text;
|
|
||||||
|
|
||||||
if (!TryGetProp(props, "Role", out EPlayerRole role)
|
|
||||||
|| !TryGetProp(props, "UIData", out FStructFallback uiDataFb)
|
|
||||||
|| !TryGetProp(props, "Inventory", out bool isInventory)
|
|
||||||
|| !TryGetProp(props, "IsFakeItem", out bool isFakeItem)
|
|
||||||
)
|
|
||||||
throw new KeyNotFoundException("Role, UIData, Inventory or IsFakeItem was not found");
|
|
||||||
|
|
||||||
UIDataStruct uiData = uiDataFb.MapToStruct<UIDataStruct>();
|
|
||||||
|
|
||||||
if (!isInventory || isFakeItem)
|
|
||||||
{
|
|
||||||
_log.Verbose("Ignoring invalid offering ({0})", offeringDBPaths);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uiData.IconAssetList.Length == 0)
|
|
||||||
throw new InvalidDataException("Offerings's UIData had no icons");
|
|
||||||
|
|
||||||
_offeringMap[offeringId] = new OfferingInfo
|
|
||||||
{
|
|
||||||
id = offeringId,
|
|
||||||
name = uiData.DisplayName.ToString(),
|
|
||||||
iconFilePath = uiData.IconAssetList[0].ToString(),
|
|
||||||
role = role
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteJson("offerings", _offeringMap.Values);
|
private void ExportIcons(IEnumerable<string> iconPaths, string logName, string outFolder)
|
||||||
_log.Info("Dumped {0} offerings", _offeringMap.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DumpOfferingIcons()
|
|
||||||
{
|
{
|
||||||
if (_provider == null)
|
if (_provider == null)
|
||||||
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
throw new InvalidOperationException("Attempted to call dump function without dumper initialization/state");
|
||||||
|
|
||||||
_log.Info("Dumping offering icons");
|
_log.Info($"Dumping {logName} icons");
|
||||||
|
|
||||||
foreach (OfferingInfo info in _offeringMap.Values)
|
foreach (string path in iconPaths)
|
||||||
ExportIcon(info.iconFilePath, "/offering-icons/");
|
ExportIcon(path, outFolder);
|
||||||
|
|
||||||
_log.Info("Dumped all offering icons");
|
_log.Info($"Dumped all {logName} icons");
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -413,7 +344,6 @@ class Dumper
|
|||||||
Directory.CreateDirectory(parentFolder);
|
Directory.CreateDirectory(parentFolder);
|
||||||
|
|
||||||
File.WriteAllBytes(fullPath, bytes);
|
File.WriteAllBytes(fullPath, bytes);
|
||||||
_log.Verbose("Exported icon: {0}", fileName);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new InvalidDataException("Bitmap was invalid");
|
throw new InvalidDataException("Bitmap was invalid");
|
||||||
|
|||||||
Reference in New Issue
Block a user