From c3dc8814ebabed4f4707f43494a98b44fc55a544 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 21 Jun 2017 19:56:20 +0200 Subject: [PATCH] [AssetHandler] Move asset related reallocations --- src/Components/Modules/AssetHandler.cpp | 71 +++++++++++++++++++++++ src/Components/Modules/AssetHandler.hpp | 2 + src/Components/Modules/Maps.cpp | 75 +------------------------ src/Components/Modules/Maps.hpp | 3 - src/Components/Modules/ZoneBuilder.cpp | 11 ---- 5 files changed, 74 insertions(+), 88 deletions(-) diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 205c317d..24bc2568 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -407,8 +407,57 @@ namespace Components Utils::Hook::Call(0x4F8C70)(severity, format, type, name); // Print error } + void AssetHandler::reallocateEntryPool() + { + AssertSize(Game::XAssetEntry, 16); + + size_t size = (ZoneBuilder::IsEnabled() ? 1183968 : 789312); + Game::XAssetEntry* entryPool = Utils::Memory::GetAllocator()->allocateArray(size); + + // Apply new size + Utils::Hook::Set(0x5BAEB0, size); + + // Apply new pool + DWORD patches[] = + { + 0x48E6F4, + 0x4C67E4, + 0x4C8584, + 0x5BAEA8, + 0x5BB0C4, + 0x5BB0F5, + 0x5BB1D4, + 0x5BB235, + 0x5BB278, + 0x5BB34C, + 0x5BB484, + 0x5BB570, + 0x5BB6B7, + 0x5BB844, + 0x5BB98D, + 0x5BBA66, + 0x5BBB8D, + 0x5BBCB1, + 0x5BBD9B, + 0x5BBE4C, + 0x5BBF14, + 0x5BBF54, + 0x5BBFB8 + }; + + for (int i = 0; i < ARRAYSIZE(patches); ++i) + { + Utils::Hook::Set(patches[i], entryPool); + } + + Utils::Hook::Set(0x5BAE91, entryPool + 1); + Utils::Hook::Set(0x5BAEA2, entryPool + 1); + } + AssetHandler::AssetHandler() { + this->reallocateEntryPool(); + Dvar::Register("r_noVoid", false, Game::DVAR_FLAG_SAVED, "Disable void model (red fx)"); AssetHandler::ClearTemporaryAssets(); @@ -450,9 +499,31 @@ namespace Components } }); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_GAMEWORLD_SP, 1); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, ZoneBuilder::IsEnabled() ? 14336 : 7168); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, 2700); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_FX, 1200); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_LOCALIZE_ENTRY, 14000); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_XANIMPARTS, 8192); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_XMODEL, 5125); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_PHYSPRESET, 128); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_PIXELSHADER, ZoneBuilder::IsEnabled() ? 0x4000 : 10000); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, ZoneBuilder::IsEnabled() ? 0x2000 : 3072); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_MATERIAL, 8192); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_VERTEXDECL, ZoneBuilder::IsEnabled() ? 0x400 : 196); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_WEAPON, WEAPON_LIMIT); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_STRINGTABLE, 800); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMPACT_FX, 8); + // Register asset interfaces if (ZoneBuilder::IsEnabled()) { + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_MAP_ENTS, 10); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_XMODELSURFS, 8192); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, 0x2000); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_FONT, 32); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_RAWFILE, 2048); + AssetHandler::RegisterInterface(new Assets::IFont_s()); AssetHandler::RegisterInterface(new Assets::IXModel()); AssetHandler::RegisterInterface(new Assets::IFxWorld()); diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index f82ff03d..e53f57f7 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -70,6 +70,8 @@ namespace Components static void SetBypassState(bool value); static void MissingAssetError(int severity, const char* format, const char* type, const char* name); + + void reallocateEntryPool(); }; } diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 82cc188a..098e1207 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -9,7 +9,6 @@ namespace Components bool Maps::SPMap; std::vector Maps::DlcPacks; - std::vector Maps::EntryPool; const char* Maps::UserMapFiles[4] = { @@ -713,59 +712,7 @@ namespace Components Game::XAssetEntry* Maps::GetAssetEntryPool() { - if(Maps::EntryPool.empty()) - { - return reinterpret_cast(0x134CAD8); - } - - return Maps::EntryPool.data(); - } - - void Maps::reallocateEntryPool() - { - AssertSize(Game::XAssetEntry, 16); - - Maps::EntryPool.clear(); - - if (ZoneBuilder::IsEnabled()) - { - Maps::EntryPool.resize(1183968); - } - else - { - Maps::EntryPool.resize(789312); - } - - // Apply new size - Utils::Hook::Set(0x5BAEB0, Maps::EntryPool.size()); - - // Apply new pool - Utils::Hook::Set(0x48E6F4, Maps::EntryPool.data()); - Utils::Hook::Set(0x4C67E4, Maps::EntryPool.data()); - Utils::Hook::Set(0x4C8584, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BAEA8, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB0C4, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB0F5, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB1D4, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB235, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB278, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB34C, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB484, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB570, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB6B7, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB844, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BB98D, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBA66, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBB8D, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBCB1, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBD9B, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBE4C, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBF14, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBF54, Maps::EntryPool.data()); - Utils::Hook::Set(0x5BBFB8, Maps::EntryPool.data()); - - Utils::Hook::Set(0x5BAE91, Maps::EntryPool.data() + 1); - Utils::Hook::Set(0x5BAEA2, Maps::EntryPool.data() + 1); + return *reinterpret_cast(0x48E6F4); } // dlcIsTrue serves as a check if the map is a custom map and if it's missing @@ -1022,24 +969,6 @@ namespace Components // Load usermap arena file Utils::Hook(0x630A88, Maps::LoadArenaFileStub, HOOK_CALL).install()->quick(); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_GAMEWORLD_SP, 1); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, 7168); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, 2700); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_FX, 1200); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_LOCALIZE_ENTRY, 14000); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_XANIMPARTS, 8192); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_XMODEL, 5125); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_PHYSPRESET, 128); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_PIXELSHADER, 10000); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, 3072); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_MATERIAL, 8192); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_VERTEXDECL, 196); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_WEAPON, WEAPON_LIMIT); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_STRINGTABLE, 800); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMPACT_FX, 8); - - this->reallocateEntryPool(); - // Dependencies //Maps::AddDependency("oilrig", "mp_subbase"); //Maps::AddDependency("gulag", "mp_subbase"); @@ -1113,7 +1042,5 @@ namespace Components Maps::DependencyList.clear(); Maps::CurrentMainZone.clear(); Maps::CurrentDependencies.clear(); - - Maps::EntryPool.clear(); } } diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index 6c169cf4..6f43abf5 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -78,7 +78,6 @@ namespace Components static bool SPMap; static UserMapContainer UserMap; static std::vector DlcPacks; - static std::vector EntryPool; static std::vector> DependencyList; static std::vector CurrentDependencies; @@ -123,7 +122,5 @@ namespace Components static Game::dvar_t* GetSpecularDvar(); static void SetSpecularStub1(); static void SetSpecularStub2(); - - void reallocateEntryPool(); }; } diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index 698dca23..86c909ae 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -1034,17 +1034,6 @@ namespace Components // Don't read stats Utils::Hook(0x4875E1, 0x487717, HOOK_JUMP).install()->quick(); - // Increase asset pools - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_MAP_ENTS, 10); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_XMODELSURFS, 8192); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, 14336); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, 0x2000); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_PIXELSHADER, 0x4000); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, 0x2000); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_VERTEXDECL, 0x400); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_FONT, 32); - Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_RAWFILE, 2048); - // patch g_copyInfo because we're using so many more assets than originally intended int newLimit = 0x2000; int* g_copyInfo_new = Utils::Memory::GetAllocator()->allocateArray(newLimit);