Realloc localize on sp

This commit is contained in:
fed 2024-01-30 02:12:42 +01:00
parent a51fa416cf
commit 2e392bb7a3
2 changed files with 76 additions and 1 deletions

View File

@ -1084,12 +1084,87 @@ namespace fastfiles
}
}
namespace sp
{
constexpr unsigned int get_asset_type_size(const game::XAssetType type)
{
constexpr int asset_type_sizes[] =
{
96, 88, 128, 56, 40, 216,
56, 680, 592, 32, 32, 32,
32, 32, 2112, 1936, 104,
32, 24, 152, 152, 152, 16,
64, 640, 40, 16, 136, 24,
296, 176, 2864, 48, 0, 24,
200, 88, 16, 144, 3616, 56,
64, 16, 16, 0, 0, 0, 0, 24,
40, 24, 48, 40, 24, 16, 80,
128, 2256, 136, 32, 72,
24, 64, 88, 48, 32, 96, 152,
64, 32, 32,
};
return asset_type_sizes[type];
}
constexpr unsigned int get_pool_type_size(const game::XAssetType type)
{
constexpr int asset_pool_sizes[] =
{
128, 1024, 16, 1, 128, 5000, 5248,
2560, 10624, 256, 49152, 12288, 12288,
72864, 512, 2750, 12000, 16000, 256,
64, 64, 64, 64, 8000, 1, 1, 1, 1,
1, 2, 1, 1, 32, 0, 128,
400, 0, 11500, 128, 360, 1, 2048,
4, 6, 0, 0, 0, 0, 1024,
768, 400, 128, 128, 24, 24, 24,
32, 128, 2, 0, 64, 384, 128,
1, 128, 64, 32, 32, 16, 32, 16,
};
return asset_pool_sizes[type];
}
template <game::XAssetType Type, size_t Size>
char* reallocate_asset_pool()
{
constexpr auto element_size = get_asset_type_size(Type);
static char new_pool[element_size * Size] = {0};
static_assert(element_size != 0);
assert(element_size == game::DB_GetXAssetTypeSize(Type));
std::memmove(new_pool, game::g_assetPool[Type], game::g_poolSize[Type] * element_size);
game::g_assetPool[Type] = new_pool;
game::g_poolSize[Type] = Size;
return new_pool;
}
template <game::XAssetType Type, size_t Multiplier>
char* reallocate_asset_pool_multiplier()
{
constexpr auto pool_size = get_pool_type_size(Type);
return reallocate_asset_pool<Type, pool_size* Multiplier>();
}
void reallocate_asset_pools()
{
reallocate_asset_pool_multiplier<game::ASSET_TYPE_LOCALIZE, 2>();
}
}
void reallocate_asset_pools()
{
if (!game::environment::is_sp())
{
mp::reallocate_asset_pools();
}
else
{
sp::reallocate_asset_pools();
}
}
utils::hook::detour db_link_x_asset_entry_hook;

View File

@ -199,7 +199,7 @@ namespace game
WEAK symbol<void(XAssetType type, void(__cdecl* func)(XAssetHeader, void*), const void* inData, bool includeOverride)>
DB_EnumXAssets_Internal{0x1F0BF0, 0x394C60};
WEAK symbol<const char*(const XAsset* asset)> DB_GetXAssetName{0x1BF890, 0x366140};
WEAK symbol<int(XAssetType type)> DB_GetXAssetTypeSize{0x0, 0x366180};
WEAK symbol<int(XAssetType type)> DB_GetXAssetTypeSize{0x1BF8D0, 0x366180};
WEAK symbol<XAssetHeader(XAssetType type, const char* name,
int createDefault)> DB_FindXAssetHeader{0x1F1120, 0x3950C0};
WEAK symbol<void(void* levelLoad, const char* name,