[Materials] Don't compare remapped techniques

This commit is contained in:
momo5502 2017-05-28 22:21:26 +02:00
parent df2dd13b1d
commit 144874d36b
4 changed files with 37 additions and 17 deletions

View File

@ -269,19 +269,17 @@ namespace Components
Game::G_GlassData* Maps::GetWorldData()
{
Game::G_GlassData** dataPtr;
Logger::Print("Waiting for database...\n");
while (!Game::Sys_IsDatabaseReady()) std::this_thread::sleep_for(10ms);
if (!Utils::String::StartsWith(Maps::CurrentMainZone, "mp_") || Maps::SPMap)
{
dataPtr = &Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_SP].gameWorldSp[0].data;
return Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_SP].gameWorldSp[0].data;
}
else
{
dataPtr = &Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP].gameWorldMp[0].data;
return Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP].gameWorldMp[0].data;
}
Logger::Print("Waiting for database...\n");
while(!*dataPtr) std::this_thread::sleep_for(1ms);
return *dataPtr;
}
__declspec(naked) void Maps::GetWorldDataStub()
@ -848,11 +846,6 @@ namespace Components
}
}
int Maps::DatabaseAndTechsetsReady()
{
return (Game::Sys_IsDatabaseReady() && !*reinterpret_cast<bool*>(0x69F9AFD)); // Make sure techsets are not dirty
}
Maps::Maps()
{
Dvar::OnInit([]()
@ -936,9 +929,6 @@ namespace Components
// Disable distortion on custom maps
Utils::Hook(0x50AA47, Maps::SetDistortionStub, 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();
Utils::Hook(0x62493E, Maps::SpawnServerStub, HOOK_CALL).install()->quick();

View File

@ -123,8 +123,6 @@ namespace Components
static Game::dvar_t* GetDistortionDvar();
static void SetDistortionStub();
static int DatabaseAndTechsetsReady();
void reallocateEntryPool();
};
}

View File

@ -2,6 +2,7 @@
namespace Components
{
std::mutex Materials::TechsetMutex;
int Materials::ImageNameLength;
Utils::Hook Materials::ImageVersionCheckHook;
@ -150,6 +151,22 @@ namespace Components
#endif
void Materials::OverrideTechsets()
{
std::lock_guard<std::mutex> _(Materials::TechsetMutex);
Utils::Hook::Call<void()>(0x522D00)(); // Material_OverrideTechniqueSets
}
void Materials::MaterialSort()
{
std::lock_guard<std::mutex> _(Materials::TechsetMutex);
if (!*reinterpret_cast<bool*>(0x69F9AFD))
{
Utils::Hook::Call<void()>(0x523A20)(); // Material_Sort
}
}
Materials::Materials()
{
Materials::ImageNameLength = 7;
@ -172,6 +189,18 @@ namespace Components
// Debug material comparison
Utils::Hook::Set<void*>(0x523894, Materials::MaterialComparePrint);
// Synchronize material sorting
Utils::Hook(0x50AAFE, Materials::MaterialSort, HOOK_CALL).install()->quick();
// Don't compare remapped techsets
Utils::Hook::Set<BYTE>(0x523490, 0xEB);
Utils::Hook::Set<BYTE>(0x5234A0, 0xEB);
// Synchronize techset remapping
Utils::Hook(0x50AAD8, Materials::OverrideTechsets, HOOK_CALL).install()->quick();
Utils::Hook(0x518BB8, Materials::OverrideTechsets, HOOK_CALL).install()->quick();
Utils::Hook(0x5BC791, Materials::OverrideTechsets, HOOK_CALL).install()->quick();
#ifdef DEBUG
if (Flags::HasFlag("dump"))
{

View File

@ -15,6 +15,7 @@ namespace Components
static int FormatImagePath(char* buffer, size_t size, int, int, const char* image);
private:
static std::mutex TechsetMutex;
static int ImageNameLength;
static Utils::Hook ImageVersionCheckHook;
@ -33,5 +34,7 @@ namespace Components
#endif
static int MaterialComparePrint(Game::Material* m1, Game::Material* m2);
static void OverrideTechsets();
static void MaterialSort();
};
}