|
11 | 11 | #include "patches/Multicore.h" |
12 | 12 | #include "game/Camera.h" |
13 | 13 | #include "render/Draw.h" |
| 14 | +#include "file/FileSystem.h" |
14 | 15 |
|
15 | 16 | // Instance of patches so we can get it in our hooks without calling GetModule<T> each call |
16 | 17 | static Patches* s_patches; |
@@ -90,13 +91,25 @@ static void __stdcall DeathState_Process(int player, int data) |
90 | 91 | } |
91 | 92 | } |
92 | 93 |
|
| 94 | +#ifdef TR8 |
| 95 | +static void(*s_MAIN_DoMainInit)(); |
| 96 | + |
93 | 97 | static unsigned char CPUCount(unsigned int* TotAvailLogical, unsigned int* TotAvailCore, unsigned int* PhysicalNum) |
94 | 98 | { |
95 | 99 | *TotAvailLogical = std::thread::hardware_concurrency(); |
96 | 100 |
|
97 | 101 | return 0; |
98 | 102 | } |
99 | 103 |
|
| 104 | +static void MAIN_DoMainInit() |
| 105 | +{ |
| 106 | + s_MAIN_DoMainInit(); |
| 107 | + |
| 108 | + // Patch the player list once globalInfo has been loaded |
| 109 | + s_patches->PatchPlayersList(); |
| 110 | +} |
| 111 | +#endif |
| 112 | + |
100 | 113 | Patches::Patches() |
101 | 114 | { |
102 | 115 | s_patches = this; |
@@ -144,6 +157,8 @@ Patches::Patches() |
144 | 157 | // Fix cdcMultiCore breaking on high number of CPU cores |
145 | 158 | MH_CreateHook((void*)0x4A21D0, CPUCount, nullptr); |
146 | 159 | MH_CreateHook((void*)0x4A2680, cdc::JobChainImplWithThreads::StartSystem, (void**)&cdc::JobChainImplWithThreads::s_StartSystem); |
| 160 | + |
| 161 | + MH_CreateHook((void*)0x5DEF70, MAIN_DoMainInit, (void**)&s_MAIN_DoMainInit); |
147 | 162 | #endif |
148 | 163 |
|
149 | 164 | #ifdef TR7 |
@@ -191,6 +206,39 @@ void Patches::PatchShadowMap() const noexcept |
191 | 206 | } |
192 | 207 | #endif |
193 | 208 |
|
| 209 | +#ifdef TR8 |
| 210 | +// Iterates the player list from globalInfo and removes any player objects that don't actually exist |
| 211 | +// rather than using a hardcoded list this actually checks if it exists to account for mods |
| 212 | +void Patches::PatchPlayersList() const noexcept |
| 213 | +{ |
| 214 | + auto globalInfo = *(GlobalInfo**)0xE7EE50; |
| 215 | + auto players = globalInfo->playerObjects; |
| 216 | + |
| 217 | + auto fileSystem = GetFS(); |
| 218 | + char fileName[256]; |
| 219 | + |
| 220 | + for (int i = 0; i < players->numPlayerObjects; ) |
| 221 | + { |
| 222 | + auto name = OBTABLE_GetObjectName(players->playerObjectList[i]); |
| 223 | + |
| 224 | + LOAD_UnitFileName(fileName, name, "drm"); |
| 225 | + |
| 226 | + // Check if the object exist |
| 227 | + if (!fileSystem->FileExists(fileName)) |
| 228 | + { |
| 229 | + // If the file does not exist, remove it from the list |
| 230 | + for (int j = i; j < players->numPlayerObjects - 1; j++) players->playerObjectList[j] = players->playerObjectList[j + 1]; |
| 231 | + |
| 232 | + players->numPlayerObjects--; |
| 233 | + } |
| 234 | + else |
| 235 | + { |
| 236 | + i++; |
| 237 | + } |
| 238 | + } |
| 239 | +} |
| 240 | +#endif |
| 241 | + |
194 | 242 | void Patches::OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
195 | 243 | { |
196 | 244 | // Remove the quit message |
|
0 commit comments