Skip to content

Commit

Permalink
add 'dinput.dll' proxy, fix 'dsound.dll'
Browse files Browse the repository at this point in the history
- add proxy as 'dinput.dll'
- add ordinals for 'dsound.dll', as it seems sometimes dsound funcs are imported by ordinals

note that ordinals are correct only for dsound, while others are whatever as ordinals can be only correct for one of the dlls. but so far i havent seen any other currently supported proxy dlls (dinput/dinput8/version) to have their funcs imported by ordinals anywhere, so this is unlikely to ever be a problem
  • Loading branch information
anzz1 authored Aug 10, 2023
1 parent 8057453 commit b3160ae
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Please note that the GameSpy protocol is old and does not meet modern password e
## Remarks
To uninstall, simply delete the `openspy.dll` file.

If a game is not listed, you can try renaming it as the different variations openspy-client currently supports:
If a game is not listed, you can try renaming it as the different variations openspy-client currently supports:
- `dinput.dll`
- `dinput8.dll`
- `version.dll`
- `dsound.dll`
Expand Down
5 changes: 4 additions & 1 deletion dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "include/global.h"
#include "include/version_dll.h"
#include "include/dinput_dll.h"
#include "include/dinput8_dll.h"
#include "include/dsound_dll.h"
#include "include/game_cry.h"
Expand Down Expand Up @@ -110,7 +111,9 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
p = __strrchr(s, '\\');
if (p) {
p++;
if (!__stricmp(p, sDInput)) // dinput8.dll
if (!__stricmp(p, sDInput)) // dinput.dll
dinput_hook();
else if (!__stricmp(p, sDInput8)) // dinput8.dll
dinput8_hook();
else if (!__stricmp(p, sDSound)) // dsound.dll
dsound_hook();
Expand Down
6 changes: 3 additions & 3 deletions include/dinput8_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ long __stdcall p_DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID rii
#endif

if (!oDirectInput8Create)
oDirectInput8Create = GetSysProc(sDInput, "DirectInput8Create");
oDirectInput8Create = GetSysProc(sDInput8, "DirectInput8Create");
if (oDirectInput8Create)
return oDirectInput8Create(hinst, dwVersion, riidltf, ppvOut, punkOuter);

Expand All @@ -26,9 +26,9 @@ long __stdcall p_DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID rii

static void dinput8_hook() {
HMODULE hm;
hm = LoadSysMod(sDInput);
hm = LoadSysMod(sDInput8);
if (hm) {
pModName = sDInput;
pModName = sDInput8;
oDirectInput8Create = (DirectInput8Create_fn)GetProcAddress(hm,"DirectInput8Create");
oDllGetClassObject = (DllGetClassObject_fn)GetProcAddress(hm,"DllGetClassObject");
oDllRegisterServer = (DllRegisterServer_fn)GetProcAddress(hm,"DllRegisterServer");
Expand Down
78 changes: 78 additions & 0 deletions include/dinput_dll.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// dinput_dll.h

#ifndef __DINPUT_DLL_H
#define __DINPUT_DLL_H

#include "include/global.h"
#include "include/shared.h"

typedef long (__stdcall *DirectInputCreateA_fn)(HINSTANCE hinst, DWORD dwVersion, /* LPDIRECTINPUTA* */ LPVOID *lplpDirectInput, /* LPUNKNOWN */ LPVOID punkOuter);
DirectInputCreateA_fn oDirectInputCreateA = 0;
typedef long (__stdcall *DirectInputCreateEx_fn)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID * ppvOut, /* LPUNKNOWN */ LPVOID punkOuter);
DirectInputCreateEx_fn oDirectInputCreateEx = 0;
typedef long (__stdcall *DirectInputCreateW_fn)(HINSTANCE hinst, DWORD dwVersion, /* LPDIRECTINPUTW* */ LPVOID *lplpDirectInput, /* LPUNKNOWN */ LPVOID punkOuter);
DirectInputCreateW_fn oDirectInputCreateW = 0;

long __stdcall p_DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, /* LPDIRECTINPUTA* */ LPVOID *lplpDirectInput, /* LPUNKNOWN */ LPVOID punkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectInputCreateA=p_DirectInputCreateA")
#else
#pragma comment(linker, "/EXPORT:DirectInputCreateA=_p_DirectInputCreateA@16")
#endif

if (!oDirectInputCreateA)
oDirectInputCreateA = GetSysProc(sDInput, "DirectInputCreateA");
if (oDirectInputCreateA)
return oDirectInputCreateA(hinst, dwVersion, lplpDirectInput, punkOuter);

return 1;
}

long __stdcall p_DirectInputCreateEx(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID *ppvOut, /* LPUNKNOWN */ LPVOID punkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectInputCreateEx=p_DirectInputCreateEx")
#else
#pragma comment(linker, "/EXPORT:DirectInputCreateEx=_p_DirectInputCreateEx@20")
#endif

if (!oDirectInputCreateEx)
oDirectInputCreateEx = GetSysProc(sDInput, "DirectInputCreateEx");
if (oDirectInputCreateEx)
return oDirectInputCreateEx(hinst, dwVersion, riidltf, ppvOut, punkOuter);

return 1;
}

long __stdcall p_DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, /* LPDIRECTINPUTW* */ LPVOID *lplpDirectInput, /* LPUNKNOWN */ LPVOID punkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectInputCreateW=p_DirectInputCreateW")
#else
#pragma comment(linker, "/EXPORT:DirectInputCreateW=_p_DirectInputCreateW@16")
#endif

if (!oDirectInputCreateW)
oDirectInputCreateW = GetSysProc(sDInput, "DirectInputCreateW");
if (oDirectInputCreateW)
return oDirectInputCreateW(hinst, dwVersion, lplpDirectInput, punkOuter);

return 1;
}

static void dinput_hook() {
HMODULE hm;
hm = LoadSysMod(sDInput);
if (hm) {
pModName = sDInput;
oDirectInputCreateA = (DirectInputCreateA_fn)GetProcAddress(hm,"DirectInputCreateA");
oDirectInputCreateEx = (DirectInputCreateEx_fn)GetProcAddress(hm,"DirectInputCreateEx");
oDirectInputCreateW = (DirectInputCreateW_fn)GetProcAddress(hm,"DirectInputCreateW");
oDllGetClassObject = (DllGetClassObject_fn)GetProcAddress(hm,"DllGetClassObject");
oDllRegisterServer = (DllRegisterServer_fn)GetProcAddress(hm,"DllRegisterServer");
oDllUnregisterServer = (DllUnregisterServer_fn)GetProcAddress(hm,"DllUnregisterServer");
if (oDirectInputCreateA)
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCSTR)oDirectInputCreateA, &hm);
}
}

#endif // __DINPUT_DLL_H

40 changes: 20 additions & 20 deletions include/dsound_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ GetDeviceID_fn oGetDeviceID = 0;

long __stdcall p_DirectSoundCaptureCreate(LPGUID lpGUID, LPVOID *lplpDSC, /* LPUNKNOWN */ LPVOID punkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate=p_DirectSoundCaptureCreate")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate=p_DirectSoundCaptureCreate,@6")
#else
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate=_p_DirectSoundCaptureCreate@12")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate=_p_DirectSoundCaptureCreate@12,@6")
#endif

if (!oDirectSoundCaptureCreate)
Expand All @@ -53,9 +53,9 @@ long __stdcall p_DirectSoundCaptureCreate(LPGUID lpGUID, LPVOID *lplpDSC, /* LPU

long __stdcall p_DirectSoundCaptureCreate8(LPCGUID lpcGUID, LPVOID *lplpDSC, /* LPUNKNOWN */ LPVOID punkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate8=p_DirectSoundCaptureCreate8")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate8=p_DirectSoundCaptureCreate8,@12")
#else
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate8=_p_DirectSoundCaptureCreate8@12")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureCreate8=_p_DirectSoundCaptureCreate8@12,@12")
#endif

if (!oDirectSoundCaptureCreate8)
Expand All @@ -68,9 +68,9 @@ long __stdcall p_DirectSoundCaptureCreate8(LPCGUID lpcGUID, LPVOID *lplpDSC, /*

long __stdcall p_DirectSoundCaptureEnumerateA(LPVOID lpDSEnumCallback, LPVOID lpContext) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateA=p_DirectSoundCaptureEnumerateA")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateA=p_DirectSoundCaptureEnumerateA,@7")
#else
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateA=_p_DirectSoundCaptureEnumerateA@8")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateA=_p_DirectSoundCaptureEnumerateA@8,@7")
#endif

if (!oDirectSoundCaptureEnumerateA)
Expand All @@ -83,9 +83,9 @@ long __stdcall p_DirectSoundCaptureEnumerateA(LPVOID lpDSEnumCallback, LPVOID lp

long __stdcall p_DirectSoundCaptureEnumerateW(LPVOID lpDSEnumCallback, LPVOID lpContext) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateW=p_DirectSoundCaptureEnumerateW")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateW=p_DirectSoundCaptureEnumerateW,@8")
#else
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateW=_p_DirectSoundCaptureEnumerateW@8")
#pragma comment(linker, "/EXPORT:DirectSoundCaptureEnumerateW=_p_DirectSoundCaptureEnumerateW@8,@8")
#endif

if (!oDirectSoundCaptureEnumerateW)
Expand All @@ -98,9 +98,9 @@ long __stdcall p_DirectSoundCaptureEnumerateW(LPVOID lpDSEnumCallback, LPVOID lp

long __stdcall p_DirectSoundCreate(LPGUID lpGuid, LPVOID *ppDS, /* LPUNKNOWN */ LPVOID pUnkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundCreate=p_DirectSoundCreate")
#pragma comment(linker, "/EXPORT:DirectSoundCreate=p_DirectSoundCreate,@1")
#else
#pragma comment(linker, "/EXPORT:DirectSoundCreate=_p_DirectSoundCreate@12")
#pragma comment(linker, "/EXPORT:DirectSoundCreate=_p_DirectSoundCreate@12,@1")
#endif

if (!oDirectSoundCreate)
Expand All @@ -113,9 +113,9 @@ long __stdcall p_DirectSoundCreate(LPGUID lpGuid, LPVOID *ppDS, /* LPUNKNOWN */

long __stdcall p_DirectSoundCreate8(LPCGUID lpcGuidDevice, LPVOID *ppDS8, /* LPUNKNOWN */ LPVOID pUnkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundCreate8=p_DirectSoundCreate8")
#pragma comment(linker, "/EXPORT:DirectSoundCreate8=p_DirectSoundCreate8,@11")
#else
#pragma comment(linker, "/EXPORT:DirectSoundCreate8=_p_DirectSoundCreate8@12")
#pragma comment(linker, "/EXPORT:DirectSoundCreate8=_p_DirectSoundCreate8@12,@11")
#endif

if (!oDirectSoundCreate8)
Expand All @@ -128,9 +128,9 @@ long __stdcall p_DirectSoundCreate8(LPCGUID lpcGuidDevice, LPVOID *ppDS8, /* LPU

long __stdcall p_DirectSoundEnumerateA(LPVOID lpDSEnumCallback, LPVOID lpContext) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateA=p_DirectSoundEnumerateA")
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateA=p_DirectSoundEnumerateA,@2")
#else
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateA=_p_DirectSoundEnumerateA@8")
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateA=_p_DirectSoundEnumerateA@8,@2")
#endif

if (!oDirectSoundEnumerateA)
Expand All @@ -143,9 +143,9 @@ long __stdcall p_DirectSoundEnumerateA(LPVOID lpDSEnumCallback, LPVOID lpContext

long __stdcall p_DirectSoundEnumerateW(LPVOID lpDSEnumCallback, LPVOID lpContext) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateW=p_DirectSoundEnumerateW")
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateW=p_DirectSoundEnumerateW,@3")
#else
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateW=_p_DirectSoundEnumerateW@8")
#pragma comment(linker, "/EXPORT:DirectSoundEnumerateW=_p_DirectSoundEnumerateW@8,@3")
#endif

if (!oDirectSoundEnumerateW)
Expand All @@ -158,9 +158,9 @@ long __stdcall p_DirectSoundEnumerateW(LPVOID lpDSEnumCallback, LPVOID lpContext

long __stdcall p_DirectSoundFullDuplexCreate(LPCGUID pcGuidCaptureDevice, LPCGUID pcGuidRenderDevice, LPVOID pcDSCBufferDesc, LPVOID pcDSBufferDesc, HWND hWnd, DWORD dwLevel, LPVOID *ppDSFD, LPVOID *ppDSCBuffer8, LPVOID *ppDSBuffer8, /* LPUNKNOWN */ LPVOID pUnkOuter) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:DirectSoundFullDuplexCreate=p_DirectSoundFullDuplexCreate")
#pragma comment(linker, "/EXPORT:DirectSoundFullDuplexCreate=p_DirectSoundFullDuplexCreate,@10")
#else
#pragma comment(linker, "/EXPORT:DirectSoundFullDuplexCreate=_p_DirectSoundFullDuplexCreate@40")
#pragma comment(linker, "/EXPORT:DirectSoundFullDuplexCreate=_p_DirectSoundFullDuplexCreate@40,@10")
#endif

if (!oDirectSoundFullDuplexCreate)
Expand All @@ -173,9 +173,9 @@ long __stdcall p_DirectSoundFullDuplexCreate(LPCGUID pcGuidCaptureDevice, LPCGUI

long __stdcall p_GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest) {
#ifdef _WIN64
#pragma comment(linker, "/EXPORT:GetDeviceID=p_GetDeviceID")
#pragma comment(linker, "/EXPORT:GetDeviceID=p_GetDeviceID,@9")
#else
#pragma comment(linker, "/EXPORT:GetDeviceID=_p_GetDeviceID@8")
#pragma comment(linker, "/EXPORT:GetDeviceID=_p_GetDeviceID@8,@9")
#endif

if (!oGetDeviceID)
Expand Down
11 changes: 6 additions & 5 deletions include/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

#include "include/global.h"

static const char* sDInput = "dinput8.dll";
static const char* sDInput = "dinput.dll";
static const char* sDInput8 = "dinput8.dll";
static const char* sDSound = "dsound.dll";
static const char* pModName = 0;

Expand Down Expand Up @@ -35,9 +36,9 @@ long __stdcall p_DllRegisterServer(void) {
#pragma comment(linker, "/EXPORT:DllRegisterServer=_p_DllRegisterServer@0")
#endif

if (pModName == sDInput) {
if (pModName == sDInput || pModName == sDInput8) {
if (!oDllRegisterServer)
oDllRegisterServer = GetSysProc(sDInput, "DllRegisterServer");
oDllRegisterServer = GetSysProc(pModName, "DllRegisterServer");
if (oDllRegisterServer)
return oDllRegisterServer();
}
Expand All @@ -52,9 +53,9 @@ long __stdcall p_DllUnregisterServer(void) {
#pragma comment(linker, "/EXPORT:DllUnregisterServer=_p_DllUnregisterServer@0")
#endif

if (pModName == sDInput) {
if (pModName == sDInput || pModName == sDInput8) {
if (!oDllUnregisterServer)
oDllUnregisterServer = GetSysProc(sDInput, "DllUnregisterServer");
oDllUnregisterServer = GetSysProc(pModName, "DllUnregisterServer");
if (oDllUnregisterServer)
return oDllUnregisterServer();
}
Expand Down

0 comments on commit b3160ae

Please sign in to comment.