From b45d895e5fbf82a338b82d4bbbc67b9383fc3b90 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Fri, 28 Apr 2023 20:50:38 +0200 Subject: [PATCH] Actually fix reallocs --- src/client/component/fastfiles.cpp | 72 ++++++++++-------------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index b7651765..a190d66a 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -526,8 +526,6 @@ namespace fastfiles namespace mp { - char* new_pools[game::XAssetType::ASSET_TYPE_COUNT]{nullptr}; - constexpr unsigned int get_asset_type_size(const game::XAssetType type) { constexpr int asset_type_sizes[] = @@ -573,38 +571,23 @@ namespace fastfiles char* reallocate_asset_pool() { constexpr auto element_size = get_asset_type_size(Type); - constexpr auto new_pool_size = element_size * Size; - char* new_pool = reinterpret_cast(utils::hook::allocate_somewhere_near( - reinterpret_cast(game::base_address), new_pool_size)); - - assert(new_pool != nullptr); - assert(utils::hook::is_relatively_far(game::g_assetPool[Type], new_pool) == false); - + static char new_pool[element_size * Size] = {0}; static_assert(element_size != 0); assert(element_size == game::DB_GetXAssetTypeSize(Type)); - std::memset(new_pool, 0, new_pool_size); 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; - new_pools[Type] = new_pool; - return new_pool; } - template - char* reallocate_asset_pool_multiplier() - { - constexpr auto pool_size = get_pool_type_size(Type); - return reallocate_asset_pool(pool_size * Multiplier)>(); - } - template char* reallocate_asset_pool_multiplier() { - return reallocate_asset_pool_multiplier(Multiplier)>(); + constexpr auto pool_size = get_pool_type_size(Type); + return reallocate_asset_pool(); } #define RVA(ptr) static_cast(reinterpret_cast(ptr) - 0_b) @@ -1053,25 +1036,29 @@ namespace fastfiles reallocate_attachment_pool(); } + void reallocate_sound_pool() + { + constexpr auto original_pool_size = get_pool_type_size(game::ASSET_TYPE_SOUND); + constexpr auto multiplier = 2; + constexpr auto pool_size = original_pool_size * multiplier; + + const auto pool = reallocate_asset_pool(); + utils::hook::inject(0x39621D_b + 3, reinterpret_cast(reinterpret_cast(pool) + 8)); + + static unsigned short net_const_string_sound_map[pool_size]{}; + utils::hook::inject(0x2B0CEA_b + 3, net_const_string_sound_map); + utils::hook::inject(0x2B0F52_b + 3, net_const_string_sound_map); + utils::hook::inject(0x2B1866_b + 3, net_const_string_sound_map); + utils::hook::inject(0x2B1CC7_b + 3, net_const_string_sound_map); + } + void reallocate_asset_pools() { reallocate_attachment_and_weapon(); - reallocate_asset_pool_multiplier(); - reallocate_asset_pool_multiplier(); - reallocate_asset_pool_multiplier(); - reallocate_asset_pool_multiplier(); - } - - void free_reallocated_asset_pools() - { - for (auto* pool : new_pools) - { - if (pool) - { - VirtualFree(pool, 0, MEM_RELEASE); - pool = nullptr; - } - } + reallocate_sound_pool(); + reallocate_asset_pool_multiplier(); + reallocate_asset_pool_multiplier(); + reallocate_asset_pool_multiplier(); } } @@ -1083,14 +1070,6 @@ namespace fastfiles } } - void free_reallocated_asset_pools() - { - if (!game::environment::is_sp()) - { - mp::free_reallocated_asset_pools(); - } - } - utils::hook::detour db_link_x_asset_entry_hook; game::XAssetEntry* db_link_x_asset_entry_stub(game::XAssetType type, game::XAssetHeader* header) { @@ -1348,11 +1327,6 @@ namespace fastfiles console::info("assets: %i / %i\n", count, 155000); }); } - - void pre_destroy() override - { - free_reallocated_asset_pools(); - } }; }