Skip to content

Commit

Permalink
TimeShift: fix MP on gog/steam releases
Browse files Browse the repository at this point in the history
  • Loading branch information
anzz1 committed Dec 9, 2023
1 parent 4526718 commit 99b94e3
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion include/game_ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,52 @@ BOOL __stdcall ts_hk_GetProcessAffinityMask(HANDLE hProcess, PDWORD_PTR lpProces
return FALSE;
}

// Enable GameSpy
long __stdcall ts_hk_RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult) {
if(!__strcmp(lpSubKey, "SOFTWARE\\Sierra Entertainment\\TimeShift\\1.00.000")) {
if (phkResult) *phkResult = (HKEY)0xF5C0FFEE;
SetLastError(0);
return 0;
}

return oRegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, phkResult);
}

long __stdcall ts_hk_RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) {
if (lpValueName && !__strcmp(lpValueName, "CDKey")) {
if (lpType) *lpType = REG_SZ;
if (lpData) __strcpy(lpData, "DAW5-ZYB5-XYB5-LAW3-8385");
if (lpcbData) *lpcbData = 25;
SetLastError(0);
return 0;
}
return oRegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
}

long __stdcall ts_hk_RegCloseKey(HKEY hKey) {
if(hKey == (HKEY)0xF5C0FFEE) {
SetLastError(0);
return 0;
}

return oRegCloseKey(hKey);
}

// fix crash on cpus with more than 8C/8T
__forceinline static void ts_hook_corelimit() {
HOOK_FUNC(0, GetSystemInfo, ts_hk_GetSystemInfo, "kernel32.dll", 0, FALSE);
HOOK_FUNC(0, GetProcessAffinityMask, ts_hk_GetProcessAffinityMask, "kernel32.dll", 0, FALSE);
}

__forceinline static void ts_hook_gs() {
HOOK_FUNC(0, RegOpenKeyExA, ts_hk_RegOpenKeyExA, 0, 0, TRUE);
HOOK_FUNC(0, RegQueryValueExA, ts_hk_RegQueryValueExA, 0, 0, TRUE);
HOOK_FUNC(0, RegCloseKey, ts_hk_RegCloseKey, 0, 0, TRUE);
}

__noinline static void patch_ts() {
ts_hook_corelimit();
ts_hook_gs();
}

#endif // __GAME_FEAR_H
#endif // __GAME_TS_H

0 comments on commit 99b94e3

Please sign in to comment.