From 7a33fe42e8a5cc3e456970e75bdfe6e0241b4923 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Tue, 18 Jan 2022 11:10:53 +0000 Subject: [PATCH 1/5] :rotating_light: Fix DB_EnumXAssetEntries :zap: --- .../Modules/AssetInterfaces/IMaterial.cpp | 35 ++++++++++--------- src/Game/Functions.cpp | 22 +++++++++--- src/Game/Functions.hpp | 11 ++++++ src/Game/Structs.hpp | 13 +++++++ 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 89abca3d..23f63ef2 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -250,28 +250,31 @@ namespace Assets if (iw4TechSet) { Game::DB_EnumXAssetEntries(Game::XAssetType::ASSET_TYPE_MATERIAL, [asset, iw4TechSet](Game::XAssetEntry* entry) + { + if (!replacementFound) { - if (!replacementFound) + Game::XAssetHeader header = entry->asset.header; + + if (header.material->techniqueSet == iw4TechSet->asset.header.techniqueSet) { - Game::XAssetHeader header = entry->asset.header; + Components::Logger::Print("Material %s with techset %s has been mapped to %s (last chance!), taking the sort key of material %s\n", + asset->info.name, asset->techniqueSet->name, + header.material->techniqueSet->name, header.material->info.name); - if (header.material->techniqueSet == iw4TechSet->asset.header.techniqueSet) - { - Components::Logger::Print("Material %s with techset %s has been mapped to %s (last chance!), taking the sort key of material %s\n", asset->info.name, asset->techniqueSet->name, header.material->techniqueSet->name, header.material->info.name); - asset->info.sortKey = header.material->info.sortKey; - asset->techniqueSet = iw4TechSet->asset.header.techniqueSet; + asset->info.sortKey = header.material->info.sortKey; + asset->techniqueSet = iw4TechSet->asset.header.techniqueSet; - // this is terrible! - asset->stateBitsCount = header.material->stateBitsCount; - asset->stateBitsTable = header.material->stateBitsTable; - std::memcpy(asset->stateBitsEntry, header.material->stateBitsEntry, 48); - asset->constantCount = header.material->constantCount; - asset->constantTable = header.material->constantTable; + // this is terrible! + asset->stateBitsCount = header.material->stateBitsCount; + asset->stateBitsTable = header.material->stateBitsTable; + std::memcpy(asset->stateBitsEntry, header.material->stateBitsEntry, 48); + asset->constantCount = header.material->constantCount; + asset->constantTable = header.material->constantTable; - replacementFound = true; - } + replacementFound = true; } - }, false, false); + } + }, false, false); if (!replacementFound) { diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 86d8b5c5..39c91002 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -336,6 +336,9 @@ namespace Game Sys_SuspendOtherThreads_t Sys_SuspendOtherThreads = Sys_SuspendOtherThreads_t(0x45A190); Sys_ListFiles_t Sys_ListFiles = Sys_ListFiles_t(0x45A660); Sys_Milliseconds_t Sys_Milliseconds = Sys_Milliseconds_t(0x42A660); + Sys_LockWrite_t Sys_LockWrite = Sys_LockWrite_t(0x435880); + Sys_TempPriorityAtLeastNormalBegin_t Sys_TempPriorityAtLeastNormalBegin = Sys_TempPriorityAtLeastNormalBegin_t(0x478680); + Sys_TempPriorityEnd_t Sys_TempPriorityEnd = Sys_TempPriorityEnd_t(0x4DCF00); TeleportPlayer_t TeleportPlayer = TeleportPlayer_t(0x496850); @@ -493,6 +496,16 @@ namespace Game GraphFloat* aaInputGraph = reinterpret_cast(0x7A2FC0); + FastCriticalSection* db_hashCritSect = reinterpret_cast(0x16B8A54); + + void Sys_UnlockWrite(FastCriticalSection* critSect) + { + assert(critSect->writeCount > 0); + + InterlockedDecrement(&critSect->writeCount); + Sys_TempPriorityEnd(&critSect->tempPriority); + } + XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize) { int elSize = DB_GetXAssetSizeHandlers[type](); @@ -609,10 +622,8 @@ namespace Game void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides, bool lock) { - volatile long* lockVar = reinterpret_cast(0x16B8A54); - if (lock) InterlockedIncrement(lockVar); - - while (lock && *reinterpret_cast(0x16B8A58)) std::this_thread::sleep_for(1ms); + if (lock) + Sys_LockWrite(db_hashCritSect); const auto pool = Components::Maps::GetAssetEntryPool(); for(auto hash = 0; hash < 37000; hash++) @@ -641,7 +652,8 @@ namespace Game } } - if(lock) InterlockedDecrement(lockVar); + if(lock) + Sys_UnlockWrite(db_hashCritSect); } // this cant be MessageBox because windows.h has a define that converts it to MessageBoxW. which is just stupid diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 7da47215..127e606d 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -804,6 +804,15 @@ namespace Game typedef int(__cdecl * Sys_Milliseconds_t)(); extern Sys_Milliseconds_t Sys_Milliseconds; + typedef void(__cdecl * Sys_LockWrite_t)(FastCriticalSection* critSect); + extern Sys_LockWrite_t Sys_LockWrite; + + typedef void(__cdecl * Sys_TempPriorityAtLeastNormalBegin_t)(TempPriority*); + extern Sys_TempPriorityAtLeastNormalBegin_t Sys_TempPriorityAtLeastNormalBegin; + + typedef void(__cdecl * Sys_TempPriorityEnd_t)(TempPriority*); + extern Sys_TempPriorityEnd_t Sys_TempPriorityEnd; + typedef void(__cdecl * TeleportPlayer_t)(gentity_t* entity, float* pos, float* orientation); extern TeleportPlayer_t TeleportPlayer; @@ -1013,6 +1022,8 @@ namespace Game constexpr auto AIM_ASSIST_GRAPH_COUNT = 4u; extern GraphFloat* aaInputGraph; + void Sys_UnlockWrite(FastCriticalSection*); + XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_s* item); void Menu_SetNextCursorItem(Game::UiContext* ctx, Game::menuDef_t* currentMenu, int unk = 1); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 8a74e54d..a0ea28a9 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -6961,6 +6961,19 @@ namespace Game PM_EFF_STANCE_COUNT = 4 }; + struct TempPriority + { + void* threadHandle; + int oldPriority; + }; + + struct FastCriticalSection + { + volatile long readCount; + volatile long writeCount; + TempPriority tempPriority; + }; + #pragma endregion #ifndef IDA From d756e8626bc965669cc162c3b0065a202e64ba4d Mon Sep 17 00:00:00 2001 From: FutureRave Date: Tue, 18 Jan 2022 16:24:52 +0000 Subject: [PATCH 2/5] Reorder functions in the files --- src/Game/Functions.cpp | 4 ++-- src/Game/Functions.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 34d78e01..6f949634 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -502,6 +502,8 @@ namespace Game FastCriticalSection* db_hashCritSect = reinterpret_cast(0x16B8A54); + vec3_t* CorrectSolidDeltas = reinterpret_cast(0x739BB8); // Count 26 + void Sys_UnlockWrite(FastCriticalSection* critSect) { assert(critSect->writeCount > 0); @@ -510,8 +512,6 @@ namespace Game Sys_TempPriorityEnd(&critSect->tempPriority); } - vec3_t* CorrectSolidDeltas = reinterpret_cast(0x739BB8); // Count 26 - XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize) { int elSize = DB_GetXAssetSizeHandlers[type](); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 13514b23..9d49115a 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1032,10 +1032,10 @@ namespace Game constexpr auto AIM_ASSIST_GRAPH_COUNT = 4u; extern GraphFloat* aaInputGraph; - void Sys_UnlockWrite(FastCriticalSection*); - extern vec3_t* CorrectSolidDeltas; + void Sys_UnlockWrite(FastCriticalSection*); + XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_s* item); void Menu_SetNextCursorItem(Game::UiContext* ctx, Game::menuDef_t* currentMenu, int unk = 1); From 93cb764c23c693f68a0c6a83f5e39dc8469de0cb Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 19 Jan 2022 19:32:49 +0000 Subject: [PATCH 3/5] :lock: Used the wrong locks :lock: --- .../Modules/AssetInterfaces/IMaterial.cpp | 6 +++--- src/Components/Modules/ZoneBuilder.cpp | 2 +- src/Game/Functions.cpp | 20 ++++++++++--------- src/Game/Functions.hpp | 5 +++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 23f63ef2..637064b7 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -199,7 +199,7 @@ namespace Assets replacementFound = true; } } - }, false, false); + }, false); if (!replacementFound) { @@ -236,7 +236,7 @@ namespace Assets replacementFound = true; } } - }, false, false); + }, false); } if (!replacementFound && asset->techniqueSet) @@ -274,7 +274,7 @@ namespace Assets replacementFound = true; } } - }, false, false); + }, false); if (!replacementFound) { diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index a9a38a33..c48132f9 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -981,7 +981,7 @@ namespace Components replacementFound = true; } } - }, false, false); + }, false); if (replacementFound) return ret; return ""; diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 6f949634..43a9fe55 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -504,12 +504,16 @@ namespace Game vec3_t* CorrectSolidDeltas = reinterpret_cast(0x739BB8); // Count 26 - void Sys_UnlockWrite(FastCriticalSection* critSect) + void Sys_LockRead(FastCriticalSection* critSect) { - assert(critSect->writeCount > 0); + InterlockedIncrement(&critSect->readCount); + while (critSect->writeCount) std::this_thread::sleep_for(1ms); + } - InterlockedDecrement(&critSect->writeCount); - Sys_TempPriorityEnd(&critSect->tempPriority); + void Sys_UnlockRead(FastCriticalSection* critSect) + { + assert(critSect->readCount > 0); + InterlockedDecrement(&critSect->readCount); } XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize) @@ -626,10 +630,9 @@ namespace Game return false; } - void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides, bool lock) + void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides) { - if (lock) - Sys_LockWrite(db_hashCritSect); + Sys_LockRead(db_hashCritSect); const auto pool = Components::Maps::GetAssetEntryPool(); for(auto hash = 0; hash < 37000; hash++) @@ -658,8 +661,7 @@ namespace Game } } - if(lock) - Sys_UnlockWrite(db_hashCritSect); + Sys_UnlockRead(db_hashCritSect); } // this cant be MessageBox because windows.h has a define that converts it to MessageBoxW. which is just stupid diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 9d49115a..78281dab 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1034,7 +1034,8 @@ namespace Game extern vec3_t* CorrectSolidDeltas; - void Sys_UnlockWrite(FastCriticalSection*); + void Sys_LockRead(FastCriticalSection* critSect); + void Sys_UnlockRead(FastCriticalSection* critSect); XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_s* item); @@ -1049,7 +1050,7 @@ namespace Game XAssetType DB_GetXAssetNameType(const char* name); int DB_GetZoneIndex(const std::string& name); bool DB_IsZoneLoaded(const char* zone); - void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides, bool lock); + void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides); XAssetHeader DB_FindXAssetDefaultHeaderInternal(XAssetType type); XAssetEntry* DB_FindXAssetEntry(XAssetType type, const char* name); From ac7cd528a1b908f5d14dd14b2355eb51f41fbdeb Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 19 Jan 2022 19:41:35 +0000 Subject: [PATCH 4/5] Forgot to export the lock :lock: --- src/Game/Functions.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 78281dab..37f26b5a 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1034,6 +1034,8 @@ namespace Game extern vec3_t* CorrectSolidDeltas; + extern FastCriticalSection* db_hashCritSect; + void Sys_LockRead(FastCriticalSection* critSect); void Sys_UnlockRead(FastCriticalSection* critSect); From e210d29a9d50448b0841c41d0565e5bb4a4908ac Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 2 Mar 2022 12:18:24 +0000 Subject: [PATCH 5/5] Remove appvejor as it is not needed anymore --- README.md | 1 - appveyor.yml | 34 ---------------------------------- 2 files changed, 35 deletions(-) delete mode 100644 appveyor.yml diff --git a/README.md b/README.md index dfb2fcbc..fb5dc10a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ ![stars](https://img.shields.io/github/stars/IW4x/iw4x-client.svg) ![issues](https://img.shields.io/github/issues/IW4x/iw4x-client.svg) [![build](https://github.com/XLabsProject/iw4x-client/workflows/Build/badge.svg)](https://github.com/XLabsProject/iw4x-client/actions) -[![build status](https://ci.appveyor.com/api/projects/status/rvljq0ooxen0oexm/branch/develop?svg=true)](https://ci.appveyor.com/project/iw4x/iw4x-client/branch/develop) [![discord](https://img.shields.io/endpoint?url=https://momo5502.com/iw4x/members-badge.php)](https://discord.gg/sKeVmR3) [![patreon](https://img.shields.io/badge/patreon-support-blue.svg?logo=patreon)](https://www.patreon.com/xlabsproject) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 2f9649cd..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,34 +0,0 @@ -# AppVeyor CI configuration - -version: "#{build} ({branch})" - -environment: - matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 - PREMAKE_ACTION: vs2022 - -configuration: - - Debug - - Release - -platform: Win32 - -install: - - ps: | - Write-Host "Updating version information..." -ForegroundColor Cyan - - Update-AppveyorBuild -Version $(& tools/premake5.exe version | select -Last 1) - - git submodule update --init --recursive - - ps: | - Write-Host "Generating project files with premake..." -ForegroundColor Cyan - & "./tools/premake5.exe" $env:PREMAKE_ACTION - Write-Host "Generated" -ForegroundColor Green - -build: - project: build/iw4x.sln - parallel: true - verbosity: minimal - -artifacts: - - path: build/bin/**/*.dll - - path: build/bin/**/*.pdb