mirror of
https://github.com/isledecomp/LEGOIslandRebuilder.git
synced 2025-02-17 00:20:40 -05:00
added more patches
This commit is contained in:
parent
64c6c0ada5
commit
349714b0c4
4 changed files with 157 additions and 34 deletions
136
lib/hooks.cpp
136
lib/hooks.cpp
|
@ -183,20 +183,15 @@ LONG WINAPI InterceptRegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpR
|
|||
return RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
|
||||
}
|
||||
|
||||
BOOL StringEquals(const std::string &a, const char *b)
|
||||
{
|
||||
return !(strcmp(a.c_str(), b));
|
||||
}
|
||||
|
||||
void WINAPI InterceptSleep(DWORD dwMilliseconds)
|
||||
{
|
||||
// Do nothing
|
||||
std::string fps_behavior = config.GetString(_T("FPSLimit"));
|
||||
|
||||
// If uncapped, do nothing
|
||||
if (!StringEquals(fps_behavior, "Uncapped")) {
|
||||
if (fps_behavior != "Uncapped") {
|
||||
// If not default, pass through new FPS
|
||||
if (StringEquals(fps_behavior, "Limited")) {
|
||||
if (fps_behavior == "Limited") {
|
||||
dwMilliseconds = 1000.0f / config.GetFloat(_T("CustomFPS"));
|
||||
}
|
||||
|
||||
|
@ -204,9 +199,6 @@ void WINAPI InterceptSleep(DWORD dwMilliseconds)
|
|||
}
|
||||
}
|
||||
|
||||
/*typedef D3DVALUE (WINAPI *d3drmViewportGetFieldFunction)(LPDIRECT3DRMVIEWPORT viewport);
|
||||
d3drmViewportGetFieldFunction d3drmViewportGetFieldOriginal = NULL;*/
|
||||
|
||||
LPDIRECT3DRMVIEWPORT last_viewport = NULL;
|
||||
D3DVALUE last_fov = 0.0f;
|
||||
typedef HRESULT (WINAPI *d3drmViewportSetFieldFunction)(LPDIRECT3DRMVIEWPORT viewport, D3DVALUE field);
|
||||
|
@ -226,10 +218,6 @@ HRESULT WINAPI InterceptD3DRMCreateViewport(LPDIRECT3DRM d3drm, LPDIRECT3DRMDEVI
|
|||
HRESULT res = d3drmCreateViewportOriginal(d3drm, device, frame, x, y, w, h, viewport);
|
||||
|
||||
if (res == DD_OK) {
|
||||
/*if (!d3drmViewportGetFieldOriginal) {
|
||||
d3drmViewportGetFieldOriginal = (d3drmViewportGetFieldFunction)OverwriteVirtualTable(*viewport, 0x22, NULL);
|
||||
}*/
|
||||
|
||||
if (!d3drmViewportSetFieldOriginal) {
|
||||
d3drmViewportSetFieldOriginal = (d3drmViewportSetFieldFunction)OverwriteVirtualTable(*viewport, 0x10, (LPVOID)InterceptD3DRMViewportSetField);
|
||||
}
|
||||
|
@ -264,17 +252,16 @@ WNDPROC originalWndProc = NULL;
|
|||
LRESULT CALLBACK InterceptWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (uMsg == WM_MOUSEWHEEL) {
|
||||
short distance = HIWORD(wParam);
|
||||
SHORT distance = HIWORD(wParam);
|
||||
distance /= WHEEL_DELTA;
|
||||
|
||||
float multiplier = 0.005 * distance;
|
||||
|
||||
InterceptD3DRMViewportSetField(last_viewport, last_fov + multiplier);
|
||||
} else if (uMsg == WM_KEYDOWN) {
|
||||
if (wParam == 'M') {
|
||||
MessageBoxA(0, "would be cool to trigger any animation from here", 0, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return originalWndProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
@ -286,3 +273,114 @@ ATOM WINAPI InterceptRegisterClassA(const WNDCLASSA *c)
|
|||
|
||||
return RegisterClassA(©);
|
||||
}
|
||||
|
||||
typedef HRESULT (WINAPI *dsCreateSoundBufferFunction)(LPDIRECTSOUND lpDS, LPCDSBUFFERDESC desc, LPDIRECTSOUNDBUFFER *buffer, LPUNKNOWN unk);
|
||||
dsCreateSoundBufferFunction dsCreateSoundBufferOriginal = NULL;
|
||||
HRESULT WINAPI InterceptDirectSoundCreateSoundBuffer(LPDIRECTSOUND lpDS, LPCDSBUFFERDESC desc, LPDIRECTSOUNDBUFFER *buffer, LPUNKNOWN unk)
|
||||
{
|
||||
DSBUFFERDESC copy = *desc;
|
||||
|
||||
if (config.GetInt(_T("StayActiveWhenDefocused")) && !(copy.dwFlags & DSBCAPS_PRIMARYBUFFER)) {
|
||||
copy.dwFlags |= DSBCAPS_GLOBALFOCUS;
|
||||
}
|
||||
|
||||
return dsCreateSoundBufferOriginal(lpDS, ©, buffer, unk);
|
||||
}
|
||||
|
||||
dsCreateFunction dsCreateOriginal = NULL;
|
||||
HRESULT WINAPI InterceptDirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND* ppDS, LPUNKNOWN pUnkOuter )
|
||||
{
|
||||
HRESULT res = dsCreateOriginal(lpGuid, ppDS, pUnkOuter);
|
||||
|
||||
if (res == DD_OK) {
|
||||
if (!dsCreateSoundBufferOriginal) {
|
||||
dsCreateSoundBufferOriginal = (dsCreateSoundBufferFunction)OverwriteVirtualTable(*ppDS, 0x3, (LPVOID)InterceptDirectSoundCreateSoundBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
SHORT WINAPI InterceptGetAsyncKeyState(int vKey)
|
||||
{
|
||||
if (config.GetInt("UseWASD")) {
|
||||
switch (vKey) {
|
||||
case VK_UP:
|
||||
vKey = 'W';
|
||||
break;
|
||||
case VK_LEFT:
|
||||
vKey = 'A';
|
||||
break;
|
||||
case VK_DOWN:
|
||||
vKey = 'S';
|
||||
break;
|
||||
case VK_RIGHT:
|
||||
vKey = 'D';
|
||||
break;
|
||||
case 'W':
|
||||
vKey = VK_UP;
|
||||
break;
|
||||
case 'A':
|
||||
vKey = VK_LEFT;
|
||||
break;
|
||||
case 'S':
|
||||
vKey = VK_DOWN;
|
||||
break;
|
||||
case 'D':
|
||||
vKey = VK_RIGHT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return GetAsyncKeyState(vKey);
|
||||
}
|
||||
|
||||
typedef HRESULT (WINAPI *dinputGetDeviceStateFunction)(LPDIRECTINPUTDEVICEA lpDevice, DWORD cbData, LPVOID lpvData);
|
||||
dinputGetDeviceStateFunction dinputGetDeviceStateOriginal = NULL;
|
||||
HRESULT WINAPI InterceptDirectInputGetDeviceStateA(LPDIRECTINPUTDEVICEA lpDevice, DWORD cbData, LPVOID lpvData)
|
||||
{
|
||||
HRESULT res = dinputGetDeviceStateOriginal(lpDevice, cbData, lpvData);
|
||||
|
||||
if (config.GetInt("UseWASD") && res == DD_OK) {
|
||||
if (cbData == 256) {
|
||||
unsigned char *keys = (unsigned char *)lpvData;
|
||||
|
||||
// Swap state of WASD with arrow keys
|
||||
std::swap(keys[DIK_W], keys[DIK_UP]);
|
||||
std::swap(keys[DIK_A], keys[DIK_LEFT]);
|
||||
std::swap(keys[DIK_S], keys[DIK_DOWN]);
|
||||
std::swap(keys[DIK_D], keys[DIK_RIGHT]);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
typedef HRESULT (WINAPI *dinputCreateDeviceFunction)(LPDIRECTINPUTA lpDI, REFGUID, LPDIRECTINPUTDEVICEA *, LPUNKNOWN);
|
||||
dinputCreateDeviceFunction dinputCreateDeviceOriginal = NULL;
|
||||
HRESULT WINAPI InterceptDirectInputCreateDeviceA(LPDIRECTINPUTA lpDI, REFGUID guid, LPDIRECTINPUTDEVICEA *ppDevice, LPUNKNOWN unk)
|
||||
{
|
||||
HRESULT res = dinputCreateDeviceOriginal(lpDI, guid, ppDevice, unk);
|
||||
|
||||
if (res == DD_OK) {
|
||||
if (!dinputGetDeviceStateOriginal) {
|
||||
dinputGetDeviceStateOriginal = (dinputGetDeviceStateFunction)OverwriteVirtualTable(*ppDevice, 0x9, (LPVOID)InterceptDirectInputGetDeviceStateA);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
dinputCreateFunction dinputCreateOriginal = NULL;
|
||||
HRESULT WINAPI InterceptDirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter)
|
||||
{
|
||||
HRESULT res = dinputCreateOriginal(hinst, dwVersion, ppDI, punkOuter);
|
||||
|
||||
if (res == DD_OK) {
|
||||
if (!dinputCreateDeviceOriginal) {
|
||||
dinputCreateDeviceOriginal = (dinputCreateDeviceFunction)OverwriteVirtualTable(*ppDI, 0x3, (LPVOID)InterceptDirectInputCreateDeviceA);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
12
lib/hooks.h
12
lib/hooks.h
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <D3DRM.H>
|
||||
#include <DDRAW.H>
|
||||
#include <DINPUT.H>
|
||||
#include <DSOUND.H>
|
||||
#include <WINDOWS.H>
|
||||
|
||||
void InterceptOutputDebugStringA(LPCSTR s);
|
||||
|
@ -51,4 +53,14 @@ typedef HRESULT (WINAPI *d3drmCreateFunction)(LPDIRECT3DRM FAR *lplpDirect3DRM);
|
|||
extern d3drmCreateFunction d3drmCreateOriginal;
|
||||
HRESULT WINAPI InterceptDirect3DRMCreate(LPDIRECT3DRM FAR *lplpDirect3DRM);
|
||||
|
||||
typedef HRESULT (WINAPI *dsCreateFunction)(LPGUID lpGuid, LPDIRECTSOUND* ppDS, LPUNKNOWN pUnkOuter );
|
||||
extern dsCreateFunction dsCreateOriginal;
|
||||
HRESULT WINAPI InterceptDirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND* ppDS, LPUNKNOWN pUnkOuter );
|
||||
|
||||
SHORT WINAPI InterceptGetAsyncKeyState(int vKey);
|
||||
|
||||
typedef HRESULT (WINAPI *dinputCreateFunction)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter);
|
||||
extern dinputCreateFunction dinputCreateOriginal;
|
||||
HRESULT WINAPI InterceptDirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter);
|
||||
|
||||
#endif // HOOKS_H
|
||||
|
|
12
lib/util.cpp
12
lib/util.cpp
|
@ -95,8 +95,9 @@ LPVOID OverwriteImport(LPVOID imageBase, LPCSTR overrideFunction, LPVOID overrid
|
|||
PIMAGE_IMPORT_BY_NAME functionName = (PIMAGE_IMPORT_BY_NAME)((UINT_PTR)imageBase + (UINT_PTR)originalFirstThunk->u1.AddressOfData);
|
||||
|
||||
if (!strcmp((const char*)functionName->Name, overrideFunction)) {
|
||||
LPVOID originalFunction = (LPVOID)firstThunk->u1.Function;
|
||||
firstThunk->u1.Function = (PDWORD)override;
|
||||
// Write to memory
|
||||
LPVOID originalFunction;
|
||||
WriteMemory(&firstThunk->u1.Function, &override, sizeof(LPVOID), &originalFunction);
|
||||
|
||||
// Return original function and end loop here
|
||||
printf("Hooked %s\n", overrideFunction);
|
||||
|
@ -117,12 +118,9 @@ LPVOID OverwriteVirtualTable(LPVOID object, SIZE_T methodIndex, LPVOID overrideF
|
|||
{
|
||||
LPVOID *vtable = ((LPVOID**)(object))[0];
|
||||
LPVOID &functionAddress = vtable[methodIndex];
|
||||
LPVOID originalFunction = functionAddress;
|
||||
LPVOID originalFunction = NULL;
|
||||
|
||||
if (overrideFunction) {
|
||||
functionAddress = overrideFunction;
|
||||
printf("Hooked vtable %p+%lu\n", vtable, methodIndex);
|
||||
}
|
||||
WriteMemory(&functionAddress, overrideFunction ? &overrideFunction : NULL, sizeof(LPVOID), &originalFunction);
|
||||
|
||||
return originalFunction;
|
||||
}
|
||||
|
|
|
@ -25,23 +25,20 @@ DWORD WINAPI Patch()
|
|||
OverwriteImport(exeBase, "RegisterClassA", (LPVOID)InterceptRegisterClassA);
|
||||
OverwriteImport(dllBase, "Sleep", (LPVOID)InterceptSleep);
|
||||
OverwriteImport(exeBase, "Sleep", (LPVOID)InterceptSleep);
|
||||
OverwriteImport(dllBase, "GetAsyncKeyState", (LPVOID)InterceptGetAsyncKeyState);
|
||||
ddCreateOriginal = (ddCreateFunction)OverwriteImport(dllBase, "DirectDrawCreate", (LPVOID)InterceptDirectDrawCreate);
|
||||
d3drmCreateOriginal = (d3drmCreateFunction)OverwriteImport(dllBase, "Direct3DRMCreate", (LPVOID)InterceptDirect3DRMCreate);
|
||||
dsCreateOriginal = (dsCreateFunction)OverwriteImport(dllBase, "DirectSoundCreate", (LPVOID)InterceptDirectSoundCreate);
|
||||
dinputCreateOriginal = (dinputCreateFunction)OverwriteImport(dllBase, "DirectInputCreateA", (LPVOID)InterceptDirectInputCreateA);
|
||||
|
||||
// Stay active when defocused
|
||||
if (config.GetInt(_T("StayActiveWhenDefocused"))) {
|
||||
// Patch jump if window isn't active
|
||||
// Patch jump if window isn't active (TODO: Replace with C++ patch)
|
||||
SearchReplacePattern(exeBase, "\x89\x58\x70", "\x90\x90\x90", 3);
|
||||
|
||||
// Patch DirectSound flags so that sound doesn't mute when inactive
|
||||
SearchReplacePattern(dllBase, "\xC7\x44\x24\x24\xE0\x00\x00\x00", "\xC7\x44\x24\x24\xE0\x80\x00\x00", 8);
|
||||
SearchReplacePattern(dllBase, "\xC7\x44\x24\x24\xB0\x00\x00\x00", "\xC7\x44\x24\x24\xB0\x80\x00\x00", 8);
|
||||
SearchReplacePattern(dllBase, "\xC7\x45\xCC\x11\x00\x00\x00", "\xC7\x45\xCC\x11\x80\x00\x00", 7);
|
||||
SearchReplacePattern(dllBase, "\xC7\x45\xCC\xE0\x00\x00\x00", "\xC7\x45\xCC\xE0\x80\x00\x00", 7);
|
||||
}
|
||||
|
||||
// Allow multiple instances
|
||||
if (config.GetInt(_T("AllowMultipleInstances"))) {
|
||||
if (config.GetInt(_T("MultipleInstances"))) {
|
||||
// Patch FindWindowA import to always tell ISLE that no other ISLE window exists
|
||||
OverwriteImport(exeBase, "FindWindowA", (LPVOID)InterceptFindWindowA);
|
||||
}
|
||||
|
@ -94,6 +91,24 @@ DWORD WINAPI Patch()
|
|||
SearchReplacePattern(dllBase, nav_block_src, nav_block_dst, nav_block_sz);
|
||||
}
|
||||
|
||||
// Model Quality
|
||||
std::string model_quality = config.GetString("ModelQuality");
|
||||
float mq_val = 3.6f;
|
||||
if (model_quality == "Infinite") {
|
||||
mq_val = 999999.0f;
|
||||
} else if (model_quality == "High") {
|
||||
mq_val = 5.0f;
|
||||
} else if (model_quality == "Medium") {
|
||||
mq_val = 3.6f;
|
||||
} else if (model_quality == "Low") {
|
||||
mq_val = 0.0f;
|
||||
}
|
||||
const char *mq_pattern = "\x00\x00\x80\x40\x66\x66\x66\x40";
|
||||
char mq_replace[8];
|
||||
memcpy(mq_replace, mq_pattern, 8);
|
||||
memcpy(mq_replace+4, &mq_val, sizeof(mq_val));
|
||||
SearchReplacePattern(dllBase, mq_pattern, mq_replace, 8);
|
||||
|
||||
// Field of view
|
||||
const char *fov_pattern = "\x00\x00\x00\x3F\x17\x6C\xC1\x16\x6C\xC1\x76\x3F";
|
||||
char fov_replace[12];
|
||||
|
|
Loading…
Reference in a new issue