From df2dd13b1dfcd6ef9f79de528a8638ada80af7d7 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 28 May 2017 18:13:48 +0200 Subject: [PATCH] [Maps] Make sure techsets are clean when sorting materials --- .../Modules/AssetInterfaces/IFxEffectDef.cpp | 2 +- src/Components/Modules/Maps.cpp | 30 ++++--------------- src/Components/Modules/Maps.hpp | 2 +- src/Components/Modules/Materials.cpp | 17 ++++++----- src/Components/Modules/Materials.hpp | 3 +- src/Game/Structs.hpp | 3 +- 6 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp index e939a36e..5dc04ae0 100644 --- a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp @@ -7,7 +7,7 @@ namespace Assets void IFxEffectDef::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) { if (!header->data) this->loadEfx(header, name, builder); // Check if we have an editor fx - //if (!header->data) this->loadNative(header, name, builder); // Check if there is a native one + if (!header->data) this->loadNative(header, name, builder); // Check if there is a native one if (!header->data) this->loadBinary(header, name, builder); // Check if we need to import a new one into the game } diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 577a87f5..051d636b 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -848,29 +848,9 @@ namespace Components } } - int Maps::DatabaseReadyDelayed() -{ - static bool ready = false; - static Utils::Time::Interval interval; - - if(Game::Sys_IsDatabaseReady()) - { - if(!ready) - { - ready = true; - interval.update(); - } - else if(interval.elapsed(2s)) - { - return 1; - } - } - else - { - ready = false; - } - - return 0; + int Maps::DatabaseAndTechsetsReady() + { + return (Game::Sys_IsDatabaseReady() && !*reinterpret_cast(0x69F9AFD)); // Make sure techsets are not dirty } Maps::Maps() @@ -956,8 +936,8 @@ namespace Components // Disable distortion on custom maps Utils::Hook(0x50AA47, Maps::SetDistortionStub, HOOK_CALL).install()->quick(); - // Delay material sorting - Utils::Hook(0x50AAE6, Maps::DatabaseReadyDelayed, HOOK_CALL).install()->quick(); + // Only sort materials when techsets are clean + Utils::Hook(0x50AAE6, Maps::DatabaseAndTechsetsReady, HOOK_CALL).install()->quick(); // Intercept map loading for usermap initialization Utils::Hook(0x6245E3, Maps::SpawnServerStub, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index ef174c42..46bd67f9 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -123,7 +123,7 @@ namespace Components static Game::dvar_t* GetDistortionDvar(); static void SetDistortionStub(); - static int DatabaseReadyDelayed(); + static int DatabaseAndTechsetsReady(); void reallocateEntryPool(); }; diff --git a/src/Components/Modules/Materials.cpp b/src/Components/Modules/Materials.cpp index cbf8366e..f8eb3ab4 100644 --- a/src/Components/Modules/Materials.cpp +++ b/src/Components/Modules/Materials.cpp @@ -126,6 +126,12 @@ namespace Components return _snprintf_s(buffer, size, size, "images/%s.iwi", image); } + int Materials::MaterialComparePrint(Game::Material* m1, Game::Material* m2) + { + //__debugbreak(); + return Utils::Hook::Call(0x5235B0)(m1, m2); + } + #ifdef DEBUG void Materials::DumpImageCfg(int, const char*, const char* material) { @@ -142,12 +148,6 @@ namespace Components } } - int Materials::MaterialComparePrint(Game::Material* m1, Game::Material* m2) - { - //__debugbreak(); - return Utils::Hook::Call(0x5235B0)(m1, m2); - } - #endif Materials::Materials() @@ -169,6 +169,9 @@ namespace Components // Resolve preview images to loadscreens Utils::Hook(0x53AC19, Materials::FormatImagePath, HOOK_CALL).install()->quick(); + // Debug material comparison + Utils::Hook::Set(0x523894, Materials::MaterialComparePrint); + #ifdef DEBUG if (Flags::HasFlag("dump")) { @@ -182,8 +185,6 @@ namespace Components Utils::Hook::Nop(0x51F5AC, 5); Utils::Hook::Nop(0x51F4C4, 5); } - - Utils::Hook::Set(0x523894, Materials::MaterialComparePrint); #endif // Renderer::OnFrame([] () diff --git a/src/Components/Modules/Materials.hpp b/src/Components/Modules/Materials.hpp index 55eabe17..55d479fa 100644 --- a/src/Components/Modules/Materials.hpp +++ b/src/Components/Modules/Materials.hpp @@ -30,7 +30,8 @@ namespace Components #ifdef DEBUG static void DumpImageCfg(int, const char*, const char* material); static void DumpImageCfgPath(int, const char*, const char* material); - static int MaterialComparePrint(Game::Material* m1, Game::Material* m2); #endif + + static int MaterialComparePrint(Game::Material* m1, Game::Material* m2); }; } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index c42f826b..fa8f20b9 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -4049,7 +4049,6 @@ namespace Game unsigned int entityOffset; }; - /* 3765 */ struct VariableValue { VariableUnion u; @@ -4058,7 +4057,7 @@ namespace Game struct ScriptContainer { - Game::VariableValue* stack; + VariableValue* stack; char unk1; char unk2; char unk3;