Skip to content

Commit

Permalink
disable_upnp & crysis2
Browse files Browse the repository at this point in the history
- can disable UPNP/NAT-PMP auto port forwarding by creating text file
  "disable_upnp.txt" next to openspy dll
- add preliminary crysis2 support (untested)
  • Loading branch information
anzz1 committed Dec 2, 2023
1 parent f18d410 commit b643e41
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ body:
- type: checkboxes
attributes:
label: '🔍'
description: Please check that the game is in the [supported games list](https://github.com/anzz1/openspy-test#working-games). If not, submit a [request for game support](https://github.com/anzz1/openspy-test/issues/new?labels=game+request&template=request-for-game-support.yml&title=%5Bgame-request%5D+) instead.
description: Please check that the game is in the [supported games list](https://github.com/anzz1/openspy-client#supported-games-list). If not, submit a [request for game support](https://github.com/anzz1/openspy-client/issues/new?labels=game+request&template=request-for-game-support.yml&title=%5Bgame-request%5D+GAME+NAME) instead.
options:
- label: The game is in the [supported games list](https://github.com/anzz1/openspy-test#working-games).
- label: The game is in the [supported games list](https://github.com/anzz1/openspy-client#supported-games-list).
required: true
- type: textarea
id: what-happened
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Please note that the GameSpy protocol is old and does not meet modern password e
| Rise Of Nations: Rise Of Legends | coming soon™, see [issue #2](https://github.com/anzz1/openspy-client/issues/2) |
| Soldier of Fortune 2: Double Helix | not working |
| Test Drive Unlimited | not working |
| [report unsupported game](https://github.com/anzz1/openspy-client/issues/new?assignees=&labels=game+request&projects=&template=request-for-game-support.yml&title=%5Bgame-request%5D+GAME+NAME) |
| [report unsupported game](https://github.com/anzz1/openspy-client/issues/new?labels=game+request&template=request-for-game-support.yml&title=%5Bgame-request%5D+GAME+NAME) |

## Remarks
To uninstall, simply delete the `openspy.dll` file.
Expand Down
38 changes: 16 additions & 22 deletions dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "include/winmm_dll.h"

#include "include/game_cry.h"
#include "include/game_cry2.h"
#ifndef _WIN64
#include "include/game_sr2.h"
#include "include/game_cmr5.h"
Expand Down Expand Up @@ -52,6 +53,8 @@
// Redirect all bind() to 0.0.0.0
static int force_bind_ip = 1;

static int enable_upnp = 1;

typedef HINTERNET (__stdcall *InternetOpenUrlA_fn)(HINTERNET hInternet, LPCSTR lpszUrl, LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext);
InternetOpenUrlA_fn oInternetOpenUrlA = 0;

Expand All @@ -74,7 +77,7 @@ int __stdcall hk_bind(SOCKET s, struct sockaddr *addr, int namelen) {
getsockopt(s, SOL_SOCKET, SO_TYPE, (char*)&type, &len);
ret = obind(s, addr, namelen);

if (type == SOCK_STREAM || type == SOCK_DGRAM) {
if (enable_upnp && (type == SOCK_STREAM || type == SOCK_DGRAM)) {
unsigned long param = (unsigned long)ntohs(*(unsigned short*)(addr->sa_data));
if (param == 0) {
struct sockaddr_in sin;
Expand Down Expand Up @@ -122,18 +125,6 @@ __forceinline static int securom_check(HMODULE hModule) {
PIMAGE_NT_HEADERS img_nt_headers;
PIMAGE_SECTION_HEADER img_sec_header;
unsigned int n;
char path[512];
char* p;

if (GetModuleFileNameA(hModule, path, 511)) {
path[511] = 0;
p = __strrchr(path, '\\');
if (p && p-path < 485) {
__strcpy(++p, "disable_securom_guard.txt");
if (FileExistsA(path))
return 0;
}
}

img_dos_headers = (PIMAGE_DOS_HEADER)GetModuleHandleA(0);
if (img_dos_headers->e_magic != IMAGE_DOS_SIGNATURE)
Expand Down Expand Up @@ -199,9 +190,13 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCSTR)&p_DirectInput8Create, &hm);

// SecuROM guard
if (securom_check(hm))
if (!LocalDirFileExists("disable_securom_guard.txt") && securom_check(hm))
return 1;

// UPNP
if (LocalDirFileExists("disable_upnp.txt"))
enable_upnp = 0;

// Load system directory to memory
InitSysDir();

Expand Down Expand Up @@ -230,19 +225,18 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
p = __strrchr(s, '\\');
if (p) {
p++;
#ifdef _WIN64
if (!__stricmp(p, "crysis.exe") || !__stricmp(p, "crysis64.exe") || !__stricmp(p, "crysisdedicatedserver.exe") || !__stricmp(p, "crysiswarsdedicatedserver.exe") || !__stricmp(p, "crysisheadlessserver.exe")) { // Crysis / Crysis Wars (64-bit)
if (!__stricmp(p, "crysis.exe") || !__stricmp(p, "crysis64.exe") || !__stricmp(p, "crysisdedicatedserver.exe") || !__stricmp(p, "crysiswarsdedicatedserver.exe") || !__stricmp(p, "crysisheadlessserver.exe")) { // Crysis / Crysis Wars
force_bind_ip = 0;
patch_cry();
} else if (!__stricmp(p, "crysis2.exe") || !__stricmp(p, "crysis2dedicatedserver.exe")) { // Crysis 2
force_bind_ip = 0;
patch_cry2();
}
#else // !_WIN64
if (!__stricmp(p, "sr2_pc.exe")) { // Saints Row 2
#ifndef _WIN64
else if (!__stricmp(p, "sr2_pc.exe")) { // Saints Row 2
patch_sr2();
} else if (!__stricmp(p, "cmr5.exe")) { // Colin McRae Rally 2005
patch_cmr5();
} else if (!__stricmp(p, "crysis.exe") || !__stricmp(p, "crysisdedicatedserver.exe") || !__stricmp(p, "crysiswarsdedicatedserver.exe") || !__stricmp(p, "crysisheadlessserver.exe")) { // Crysis / Crysis Wars (32-bit)
force_bind_ip = 0;
patch_cry();
} else if (!__stricmp(p, "ut3.exe")) { // Unreal Tournament 3
patch_ut3();
} else if (!__stricmp(p, "painkiller.exe")) { // Painkiller
Expand Down Expand Up @@ -316,7 +310,7 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
if (!__memcmp(pguid, &mua_guid, sizeof(GUID))) patch_mua(); // Marvel Ultimate Alliance
}
}
#endif // _WIN64 || !_WIN64
#endif // !_WIN64
}
}

Expand Down
23 changes: 23 additions & 0 deletions include/game_cry2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// game_cry2.h

#ifndef __GAME_CRY2_H
#define __GAME_CRY2_H

#include "include/global.h"

// Disable HTTPS
__forceinline static void cry2_disable_https() {
BYTE* ptr = 0;
BYTE search[] = {0xC7,0x46,0x28,0x01,0x00,0x00,0x00,0x83,0xC3,0x08};

ptr = find_pattern_mem(0, search, search + 9, TRUE);
if (ptr)
write_mem(ptr+3, "\0", 1);
}

__noinline static void patch_cry2() {
cry2_disable_https();
gs_replace_pubkey(0);
}

#endif // __GAME_CRY2_H
13 changes: 13 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,19 @@ __forceinline static int FileExistsA(const char* path) {
return 1;
}

static int LocalDirFileExists(const char* filename) {
char *p, path[512];
if (GetModuleFileNameA(GetModuleHandle(0), path, 511)) {
path[511] = 0;
p = __strrchr(path, '\\');
if (p && p-path < 485) {
__strcpy(++p, "disable_securom_guard.txt");
return FileExistsA(path);
}
}
return 0;
}

static BOOL CreateRegKey(HKEY hKeyRoot, char* subKey) {
HKEY hKey;
char *p = subKey;
Expand Down

0 comments on commit b643e41

Please sign in to comment.