Skip to content

Commit

Permalink
regression fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anzz1 authored Oct 4, 2023
1 parent 54efb94 commit 44db028
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
7 changes: 6 additions & 1 deletion include/game_aowht.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ int __stdcall hk_bind(SOCKET s, struct sockaddr* addr, int namelen);
LPHOSTENT __stdcall hk_gethostbyname(const char* name);

__forceinline static void aowht_hook_gs() {
HMODULE gsdll = LoadLibraryA("GameSpyDLL.dll");
HMODULE gsdll;

HOOK_FUNC(0, gethostbyname, hk_gethostbyname, "wsock32.dll", 52, TRUE);
HOOK_FUNC(0, bind, hk_bind, "wsock32.dll", 2, TRUE);

gsdll = LoadLibraryA("GameSpyDLL.dll");
if (gsdll) {
HOOK_FUNC(gsdll, gethostbyname, hk_gethostbyname, "wsock32.dll", 52, TRUE);
HOOK_FUNC(gsdll, bind, hk_bind, "wsock32.dll", 2, TRUE);
Expand Down
7 changes: 6 additions & 1 deletion include/game_dh2k.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ int __stdcall hk_bind(SOCKET s, struct sockaddr* addr, int namelen);
LPHOSTENT __stdcall hk_gethostbyname(const char* name);

__forceinline static void dh2k_hook_gs() {
HMODULE aspen = GetModuleHandleA("Aspen.dll");
HMODULE aspen;

HOOK_FUNC(0, gethostbyname, hk_gethostbyname, "wsock32.dll", 52, TRUE);
HOOK_FUNC(0, bind, hk_bind, "wsock32.dll", 2, TRUE);

aspen = GetModuleHandleA("Aspen.dll");
if (aspen) {
HOOK_FUNC(aspen, gethostbyname, hk_gethostbyname, "wsock32.dll", 52, TRUE);
HOOK_FUNC(aspen, bind, hk_bind, "wsock32.dll", 2, TRUE);
Expand Down
1 change: 1 addition & 0 deletions include/game_fear.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ __forceinline static void fear_hook_gs() {
HMODULE server;

HOOK_FUNC(0, gethostbyname, fear_hk_gethostbyname, "wsock32.dll", 52, TRUE);
HOOK_FUNC(0, bind, hk_bind, "wsock32.dll", 2, TRUE);
HOOK_FUNC(0, LoadLibraryA, fear_hk_LoadLibraryA, "kernel32.dll", 0, FALSE);

server = GetModuleHandleA("EngineServer.dll");
Expand Down
2 changes: 2 additions & 0 deletions include/game_go.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ HMODULE __stdcall go_hk_LoadLibraryA(LPCSTR lpLibFileName) {
__forceinline static void go_hook_gs() {
HMODULE mod;

HOOK_FUNC(0, gethostbyname, hk_gethostbyname, "wsock32.dll", 52, TRUE);
HOOK_FUNC(0, bind, hk_bind, "wsock32.dll", 2, TRUE);
HOOK_FUNC(0, LoadLibraryA, go_hk_LoadLibraryA, "kernel32.dll", 0, FALSE);

mod = GetModuleHandleA("server.dll");
Expand Down
23 changes: 13 additions & 10 deletions include/game_pk.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ LPHOSTENT __stdcall hk_gethostbyname(const char* name);
__forceinline static void pk_fix_rdtsc_div(HMODULE engine) {
BYTE aulldiv_sig[] = {0x53,0x56,0x8B,0x44,0x24,0x18,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x14};

if (!engine) return;

// check _aulldiv is at right place
if (!__memcmp((void*)((DWORD)engine+0x002881C0), aulldiv_sig, sizeof(aulldiv_sig))) {
BYTE match1[] = {0x33,0xC0,0x33,0xD2,0x0F,0x31,0xF7,0x74,0x24,0x04,0x89,0x04,0x24,0x8B,0x04,0x24,0x83,0xC4,0x08,0xC3,0xCC,0xCC};
Expand Down Expand Up @@ -63,20 +65,21 @@ long __stdcall pk_hk_RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpR
}

__forceinline static void pk_hook_gs(HMODULE engine) {
//ragdolldata = (DWORD)(GetTickCount() ^ 0xC4FEB4B3) | ((0xFFi64 & GetTickCount()) << 32) | (1i64 << 36);
ragdolldata = (__rdtsc() & 0xFFFFFFFFFFi64) | (1i64 << 36);

HOOK_FUNC(engine, RegQueryValueExA, pk_hk_RegQueryValueExA, 0, 0, TRUE);
HOOK_FUNC(engine, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
HOOK_FUNC(engine, bind, hk_bind, "ws2_32.dll", 2, TRUE);
HOOK_FUNC(0, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
HOOK_FUNC(0, bind, hk_bind, "ws2_32.dll", 2, TRUE);

if (engine) {
ragdolldata = (__rdtsc() & 0xFFFFFFFFFFi64) | (1i64 << 36);
HOOK_FUNC(engine, RegQueryValueExA, pk_hk_RegQueryValueExA, 0, 0, TRUE);
HOOK_FUNC(engine, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
HOOK_FUNC(engine, bind, hk_bind, "ws2_32.dll", 2, TRUE);
}
}

__noinline static void patch_pk() {
HMODULE engine = GetModuleHandleA("Engine.dll");
if (engine) {
pk_hook_gs(engine);
pk_fix_rdtsc_div(engine);
}
pk_hook_gs(engine);
pk_fix_rdtsc_div(engine);
}

__declspec(naked) void _alldiv()
Expand Down

0 comments on commit 44db028

Please sign in to comment.