make listassetpool use game function to iterate specified asset pool

Co-Authored-By: Maurice Heumann <MauriceHeumann@gmail.com>
This commit is contained in:
Michael Akopyan 2021-03-13 10:35:18 -08:00
parent 46406fac62
commit 107907f003
2 changed files with 29 additions and 37 deletions

View File

@ -226,44 +226,13 @@ namespace command
}
}
void list_asset_pool(const game::XAssetType type)
void enum_assets(const game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride)
{
if (type < 0 || type >= game::XAssetType::ASSET_TYPE_COUNT)
{
game_console::print(game_console::con_type_error,
"Invalid pool passed must be between [%d, %d]", 0,
game::XAssetType::ASSET_TYPE_COUNT - 1);
return;
}
game_console::print(game_console::con_type_info, "Listing assets in pool %s",
game::g_assetNames[type]);
auto db_size = 121000;
unsigned int* table = game::db_hashTable;
game::XAssetEntry* entry;
while (db_size--)
{
for (auto hash = *table; hash; hash = entry->nextHash)
game::DB_EnumXAssets_Internal(type, static_cast<void(*)(game::XAssetHeader, void*)>([](game::XAssetHeader header, void* data)
{
entry = &game::g_assetEntryPool[hash];
if (entry->asset.type == type)
{
game_console::print(game_console::con_type_info, "%s",
game::DB_GetXAssetName(&entry->asset));
auto hash_override = entry->nextOverride;
while (hash_override)
{
const auto* entry_override = &game::g_assetEntryPool[hash_override];
hash_override = game::g_assetEntryPool[hash_override].nextOverride;
game_console::print(game_console::con_type_info, "%s | override",
game::DB_GetXAssetName(&entry_override->asset));
}
}
}
table++;
}
const auto& cb = *static_cast<const std::function<void(game::XAssetHeader)>*>(data);
cb(header);
}), &callback, includeOverride);
}
class component final : public component_interface
@ -370,7 +339,26 @@ namespace command
else
{
const auto type = static_cast<game::XAssetType>(atoi(params.get(1)));
list_asset_pool(type);
if (type < 0 || type >= game::XAssetType::ASSET_TYPE_COUNT)
{
game_console::print(game_console::con_type_error,
"Invalid pool passed must be between [%d, %d]", 0,
game::XAssetType::ASSET_TYPE_COUNT - 1);
return;
}
game_console::print(game_console::con_type_info, "Listing assets in pool %s",
game::g_assetNames[type]);
enum_assets(type, [type](game::XAssetHeader header)
{
const auto asset = game::XAsset{ type, header };
const auto* const asset_name = game::DB_GetXAssetName(&asset);
//const auto entry = game::DB_FindXAssetEntry(type, asset_name);
//TODO: display which zone the asset is from
game_console::print(game_console::con_type_info, "%s", asset_name);
}, true);
}
});
}

View File

@ -41,6 +41,10 @@ namespace game
WEAK symbol<void(XAssetType type, void (__cdecl* func)(XAssetHeader, void*), void* inData, bool includeOverride)>
DB_EnumXAssets_FastFile{0x14017D7C0, 0x14026EC10};
WEAK symbol<void(XAssetType type, void(__cdecl* func)(game::XAssetHeader, void*), const void* inData, bool includeOverride)>
DB_EnumXAssets_Internal{ 0x14017D830, 0x14026EC80 };
WEAK symbol<game::XAssetEntry(game::XAssetType type, const char* name)>
DB_FindXAssetEntry{ 0x14017D830, 0x14026F020 };
WEAK symbol<const char* (const XAsset* asset)> DB_GetXAssetName{0x140151C00, 0x140240DD0};
WEAK symbol<int(XAssetType type)> DB_GetXAssetTypeSize{0x140151C20, 0x140240DF0};
WEAK symbol<void(XZoneInfo* zoneInfo, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{