Skip to content

Commit 124e7d4

Browse files
committed
Merge branch 'master' into console
2 parents ffd5f86 + 8083f97 commit 124e7d4

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/modules/Patches.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include <Hooking.Patterns.h>
22
#include <MinHook.h>
3+
#include <thread>
34

45
#include "Patches.h"
56
#include "util/Hooking.h"
67
#include "game/Game.h"
78
#include "MainMenu.h"
89
#include "patches/Reloc.h"
910
#include "patches/ErrorHandler.h"
11+
#include "patches/Multicore.h"
1012
#include "game/Camera.h"
1113

1214
// Instance of patches so we can get it in our hooks without calling GetModule<T> each call
@@ -91,6 +93,13 @@ static void __stdcall DeathState_Process(int player, int data)
9193
}
9294
}
9395

96+
static unsigned char CPUCount(unsigned int* TotAvailLogical, unsigned int* TotAvailCore, unsigned int* PhysicalNum)
97+
{
98+
*TotAvailLogical = std::thread::hardware_concurrency();
99+
100+
return 0;
101+
}
102+
94103
Patches::Patches()
95104
{
96105
s_patches = this;
@@ -134,6 +143,12 @@ Patches::Patches()
134143
PatchHeapSize();
135144
}
136145

146+
#ifdef TR8
147+
// Fix cdcMultiCore breaking on high number of CPU cores
148+
MH_CreateHook((void*)0x4A21D0, CPUCount, nullptr);
149+
MH_CreateHook((void*)0x4A2680, cdc::JobChainImplWithThreads::StartSystem, (void**)&cdc::JobChainImplWithThreads::s_StartSystem);
150+
#endif
151+
137152
#ifdef TR7
138153
if (m_shadowMapSize.GetValue() > 0)
139154
{

src/modules/patches/Multicore.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "Multicore.h"
2+
3+
#include "Hook.h"
4+
#include "modules/Log.h"
5+
6+
bool(*cdc::JobChainImplWithThreads::s_StartSystem)(int);
7+
8+
bool cdc::JobChainImplWithThreads::StartSystem(int numThreads)
9+
{
10+
if (numThreads > 31)
11+
{
12+
numThreads = 31;
13+
}
14+
15+
Hook::GetInstance().GetModule<Log>()->WriteLine("cdc::JobChainImplWithThreads::StartSystem(%d)", numThreads);
16+
17+
return s_StartSystem(numThreads);
18+
}

src/modules/patches/Multicore.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
namespace cdc
4+
{
5+
class JobChainImplWithThreads
6+
{
7+
public:
8+
static bool(*s_StartSystem)(int);
9+
10+
static bool StartSystem(int numThreads);
11+
};
12+
}

vendor/patterns

0 commit comments

Comments
 (0)