diff --git a/iw4/Components/AssetHandler.cpp b/iw4/Components/AssetHandler.cpp index dfcb5810..50854bc0 100644 --- a/iw4/Components/AssetHandler.cpp +++ b/iw4/Components/AssetHandler.cpp @@ -6,6 +6,8 @@ namespace Components std::map AssetHandler::TypeCallbacks; std::vector AssetHandler::RestrictCallbacks; + std::map AssetHandler::Relocations; + Game::XAssetHeader AssetHandler::FindAsset(Game::XAssetType type, const char* filename) { Game::XAssetHeader header = { 0 }; @@ -98,11 +100,6 @@ namespace Components test al, al jz doNotLoad -// push [esp + 8] -// push [esp + 8] -// call DoBeforeLoadAsset -// add esp, 08h - mov eax, [esp + 8] sub esp, 14h mov ecx, 5BB657h @@ -124,10 +121,33 @@ namespace Components AssetHandler::RestrictCallbacks.push_back(callback); } + void AssetHandler::Relocate(void* start, void* to, DWORD size) + { + for (DWORD i = 0; i < size; i += 4) + { + AssetHandler::Relocations[reinterpret_cast(start) + i] = reinterpret_cast(to) + i; + } + } + + void AssetHandler::OffsetToAlias(FastFiles::Offset* offset) + { + offset->fullPointer = *reinterpret_cast((*Game::g_streamBlocks)[offset->GetDecrementedStream()].data + offset->GetDecrementedPointer()); + + if (AssetHandler::Relocations.find(offset->fullPointer) != AssetHandler::Relocations.end()) + { + offset->fullPointer = AssetHandler::Relocations[offset->fullPointer]; + } + } + AssetHandler::AssetHandler() { + // DB_FindXAssetHeader Utils::Hook(Game::DB_FindXAssetHeader, AssetHandler::FindAssetStub).Install()->Quick(); + // DB_ConvertOffsetToAlias + Utils::Hook(0x4FDFA0, AssetHandler::OffsetToAlias, HOOK_JUMP).Install()->Quick(); + + // DB_AddXAsset Utils::Hook(0x5BB650, AssetHandler::AddAssetStub, HOOK_JUMP).Install()->Quick(); } diff --git a/iw4/Components/AssetHandler.hpp b/iw4/Components/AssetHandler.hpp index b1090aba..42c71772 100644 --- a/iw4/Components/AssetHandler.hpp +++ b/iw4/Components/AssetHandler.hpp @@ -13,8 +13,7 @@ namespace Components static void OnFind(Game::XAssetType type, Callback callback); static void OnLoad(RestrictCallback callback); - static const bool Restrict; - static const bool Load; + static void Relocate(void* start, void* to, DWORD size = 4); private: static bool BypassState; @@ -24,7 +23,11 @@ namespace Components static void FindAssetStub(); static void AddAssetStub(); + static void OffsetToAlias(FastFiles::Offset* offset); + static std::map TypeCallbacks; static std::vector RestrictCallbacks; + + static std::map Relocations; }; } diff --git a/iw4/Components/FastFiles.hpp b/iw4/Components/FastFiles.hpp index 4cca26ab..e9b77408 100644 --- a/iw4/Components/FastFiles.hpp +++ b/iw4/Components/FastFiles.hpp @@ -3,6 +3,36 @@ namespace Components class FastFiles : public Component { public: + + class Offset + { + public: + union + { + struct + { + uint32_t pointer : 28; + int stream : 4; + }; + uint32_t fullValue; + void* fullPointer; + }; + + uint32_t GetDecrementedPointer() + { + Offset offset = *this; + offset.fullValue--; + return offset.pointer; + }; + + int GetDecrementedStream() + { + Offset offset = *this; + offset.fullValue--; + return offset.stream; + }; + }; + FastFiles(); ~FastFiles(); const char* GetName() { return "FastFiles"; }; diff --git a/iw4/Game/Functions.cpp b/iw4/Game/Functions.cpp index c11262e0..1487ce1d 100644 --- a/iw4/Game/Functions.cpp +++ b/iw4/Game/Functions.cpp @@ -111,6 +111,8 @@ namespace Game int* gameTypeCount = (int*)0x62E50A0; gameTypeName_t* gameTypes = (gameTypeName_t*)0x62E50A4; + XBlock** g_streamBlocks = (XBlock**)0x16E554C; + void* ReallocateAssetPool(XAssetType type, unsigned int newSize) { int elSize = DB_GetXAssetSizeHandlers[type](); diff --git a/iw4/Game/Functions.hpp b/iw4/Game/Functions.hpp index d702804c..cfc3fd60 100644 --- a/iw4/Game/Functions.hpp +++ b/iw4/Game/Functions.hpp @@ -214,6 +214,8 @@ namespace Game extern int* gameTypeCount; extern gameTypeName_t* gameTypes; + extern XBlock** g_streamBlocks; + void* ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_t* item); void OOBPrintT(int type, netadr_t netadr, const char* message); diff --git a/iw4/Game/Structs.hpp b/iw4/Game/Structs.hpp index 92aca077..e051dbf8 100644 --- a/iw4/Game/Structs.hpp +++ b/iw4/Game/Structs.hpp @@ -887,6 +887,12 @@ namespace Game XAssetHeader header; }; + struct XBlock + { + char *data; + unsigned int size; + }; + struct XAssetEntry { XAsset asset;