mirror of
https://github.com/isledecomp/LEGOIslandRebuilder.git
synced 2024-11-30 10:57:49 -05:00
implemented more stuff
This commit is contained in:
parent
7daa030991
commit
5db2d24785
5 changed files with 124 additions and 9 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 937145d0f2a0bc43d8e69927fff1b166fb93ce69
|
Subproject commit b6c42e8efe8ba250a49372919c164eeff5e35c09
|
106
lib/hooks.cpp
106
lib/hooks.cpp
|
@ -54,7 +54,7 @@ HRESULT WINAPI InterceptSurfaceGetDesc(LPDIRECTDRAWSURFACE lpDDSurface, LPDDSURF
|
||||||
HRESULT res = originalDDSurfaceGetDescFunction(lpDDSurface, lpDDSurfaceDesc);
|
HRESULT res = originalDDSurfaceGetDescFunction(lpDDSurface, lpDDSurfaceDesc);
|
||||||
|
|
||||||
if (res == DD_OK) {
|
if (res == DD_OK) {
|
||||||
ForceDDSurfaceDescTo16(lpDDSurfaceDesc);
|
//ForceDDSurfaceDescTo16(lpDDSurfaceDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -145,7 +145,8 @@ LONG WINAPI InterceptRegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpR
|
||||||
|
|
||||||
} else if (!strcmp(lpValueName, "Full Screen")) {
|
} else if (!strcmp(lpValueName, "Full Screen")) {
|
||||||
|
|
||||||
ReturnRegistryYESNOFromBool(lpData, config.GetInt(_T("FullScreen"), 1));
|
//ReturnRegistryYESNOFromBool(lpData, config.GetInt(_T("FullScreen"), 1));
|
||||||
|
ReturnRegistryYESNOFromBool(lpData, FALSE);
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
|
|
||||||
} else if (!strcmp(lpValueName, "Draw Cursor")) {
|
} else if (!strcmp(lpValueName, "Draw Cursor")) {
|
||||||
|
@ -182,13 +183,106 @@ LONG WINAPI InterceptRegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpR
|
||||||
return RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
|
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)
|
void WINAPI InterceptSleep(DWORD dwMilliseconds)
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
/*std::string fps_behavior = config.GetString(_T("FPSLimit"));
|
std::string fps_behavior = config.GetString(_T("FPSLimit"));
|
||||||
|
|
||||||
|
// If uncapped, do nothing
|
||||||
|
if (!StringEquals(fps_behavior, "Uncapped")) {
|
||||||
|
// If not default, pass through new FPS
|
||||||
|
if (StringEquals(fps_behavior, "Limited")) {
|
||||||
|
dwMilliseconds = 1000.0f / config.GetFloat(_T("CustomFPS"));
|
||||||
|
}
|
||||||
|
|
||||||
if (fps_behavior != "Uncapped") {
|
|
||||||
// Pass through to default function unless uncapped, in which case no sleep is done at all
|
|
||||||
Sleep(dwMilliseconds);
|
Sleep(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);
|
||||||
|
d3drmViewportSetFieldFunction d3drmViewportSetFieldOriginal = NULL;
|
||||||
|
HRESULT WINAPI InterceptD3DRMViewportSetField(LPDIRECT3DRMVIEWPORT viewport, D3DVALUE field)
|
||||||
|
{
|
||||||
|
last_viewport = viewport;
|
||||||
|
last_fov = field;
|
||||||
|
|
||||||
|
return d3drmViewportSetFieldOriginal(viewport, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef HRESULT (WINAPI *d3drmCreateViewportFunction)(LPDIRECT3DRM d3drm, LPDIRECT3DRMDEVICE device, LPDIRECT3DRMFRAME frame, DWORD x, DWORD y, DWORD w, DWORD h, LPDIRECT3DRMVIEWPORT *viewport);
|
||||||
|
d3drmCreateViewportFunction d3drmCreateViewportOriginal = NULL;
|
||||||
|
HRESULT WINAPI InterceptD3DRMCreateViewport(LPDIRECT3DRM d3drm, LPDIRECT3DRMDEVICE device, LPDIRECT3DRMFRAME frame, DWORD x, DWORD y, DWORD w, DWORD h, LPDIRECT3DRMVIEWPORT *viewport)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
d3drmCreateFunction d3drmCreateOriginal = NULL;
|
||||||
|
HRESULT WINAPI InterceptDirect3DRMCreate(LPDIRECT3DRM FAR *lplpDirect3DRM)
|
||||||
|
{
|
||||||
|
HRESULT result = d3drmCreateOriginal(lplpDirect3DRM);
|
||||||
|
|
||||||
|
if (result == DD_OK) {
|
||||||
|
if (!d3drmCreateViewportOriginal) {
|
||||||
|
d3drmCreateViewportOriginal = (d3drmCreateViewportFunction)OverwriteVirtualTable(*lplpDirect3DRM, 0x38, (LPVOID)InterceptD3DRMCreateViewport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef WM_MOUSEWHEEL
|
||||||
|
#define WM_MOUSEWHEEL 0x020A
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WHEEL_DELTA
|
||||||
|
#define WHEEL_DELTA 120
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WNDPROC originalWndProc = NULL;
|
||||||
|
LRESULT CALLBACK InterceptWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
if (uMsg == WM_MOUSEWHEEL) {
|
||||||
|
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 originalWndProc(hwnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
ATOM WINAPI InterceptRegisterClassA(const WNDCLASSA *c)
|
||||||
|
{
|
||||||
|
WNDCLASSA copy = *c;
|
||||||
|
originalWndProc = copy.lpfnWndProc;
|
||||||
|
copy.lpfnWndProc = InterceptWindowProc;
|
||||||
|
|
||||||
|
return RegisterClassA(©);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef HOOKS_H
|
#ifndef HOOKS_H
|
||||||
#define HOOKS_H
|
#define HOOKS_H
|
||||||
|
|
||||||
|
#include <D3DRM.H>
|
||||||
#include <DDRAW.H>
|
#include <DDRAW.H>
|
||||||
#include <WINDOWS.H>
|
#include <WINDOWS.H>
|
||||||
|
|
||||||
|
@ -21,6 +22,8 @@ HWND WINAPI InterceptCreateWindowExA(
|
||||||
LPVOID lpParam
|
LPVOID lpParam
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LONG
|
LONG
|
||||||
APIENTRY
|
APIENTRY
|
||||||
InterceptRegQueryValueExA (
|
InterceptRegQueryValueExA (
|
||||||
|
@ -32,6 +35,8 @@ InterceptRegQueryValueExA (
|
||||||
LPDWORD lpcbData
|
LPDWORD lpcbData
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ATOM WINAPI InterceptRegisterClassA(const WNDCLASSA *c);
|
||||||
|
|
||||||
HWND WINAPI InterceptFindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName);
|
HWND WINAPI InterceptFindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName);
|
||||||
|
|
||||||
typedef HRESULT (WINAPI *ddCreateFunction)(GUID *lpGUID, LPDIRECTDRAW *lplpDD, IUnknown *pUnkOuterS);
|
typedef HRESULT (WINAPI *ddCreateFunction)(GUID *lpGUID, LPDIRECTDRAW *lplpDD, IUnknown *pUnkOuterS);
|
||||||
|
@ -42,4 +47,8 @@ HRESULT WINAPI InterceptSurfaceGetDesc(LPDIRECTDRAWSURFACE lpDDSurface, LPDDSURF
|
||||||
|
|
||||||
VOID WINAPI InterceptSleep(DWORD dwMilliseconds);
|
VOID WINAPI InterceptSleep(DWORD dwMilliseconds);
|
||||||
|
|
||||||
|
typedef HRESULT (WINAPI *d3drmCreateFunction)(LPDIRECT3DRM FAR *lplpDirect3DRM);
|
||||||
|
extern d3drmCreateFunction d3drmCreateOriginal;
|
||||||
|
HRESULT WINAPI InterceptDirect3DRMCreate(LPDIRECT3DRM FAR *lplpDirect3DRM);
|
||||||
|
|
||||||
#endif // HOOKS_H
|
#endif // HOOKS_H
|
||||||
|
|
|
@ -22,9 +22,11 @@ DWORD WINAPI Patch()
|
||||||
OverwriteImport(exeBase, "CreateWindowExA", (LPVOID)InterceptCreateWindowExA);
|
OverwriteImport(exeBase, "CreateWindowExA", (LPVOID)InterceptCreateWindowExA);
|
||||||
OverwriteImport(dllBase, "OutputDebugStringA", (LPVOID)InterceptOutputDebugStringA);
|
OverwriteImport(dllBase, "OutputDebugStringA", (LPVOID)InterceptOutputDebugStringA);
|
||||||
OverwriteImport(exeBase, "RegQueryValueExA", (LPVOID)InterceptRegQueryValueExA);
|
OverwriteImport(exeBase, "RegQueryValueExA", (LPVOID)InterceptRegQueryValueExA);
|
||||||
|
OverwriteImport(exeBase, "RegisterClassA", (LPVOID)InterceptRegisterClassA);
|
||||||
OverwriteImport(dllBase, "Sleep", (LPVOID)InterceptSleep);
|
OverwriteImport(dllBase, "Sleep", (LPVOID)InterceptSleep);
|
||||||
OverwriteImport(exeBase, "Sleep", (LPVOID)InterceptSleep);
|
OverwriteImport(exeBase, "Sleep", (LPVOID)InterceptSleep);
|
||||||
ddCreateOriginal = (ddCreateFunction)OverwriteImport(dllBase, "DirectDrawCreate", (LPVOID)InterceptDirectDrawCreate);
|
ddCreateOriginal = (ddCreateFunction)OverwriteImport(dllBase, "DirectDrawCreate", (LPVOID)InterceptDirectDrawCreate);
|
||||||
|
d3drmCreateOriginal = (d3drmCreateFunction)OverwriteImport(dllBase, "Direct3DRMCreate", (LPVOID)InterceptDirect3DRMCreate);
|
||||||
|
|
||||||
// Stay active when defocused
|
// Stay active when defocused
|
||||||
if (config.GetInt(_T("StayActiveWhenDefocused"))) {
|
if (config.GetInt(_T("StayActiveWhenDefocused"))) {
|
||||||
|
@ -92,6 +94,16 @@ DWORD WINAPI Patch()
|
||||||
SearchReplacePattern(dllBase, nav_block_src, nav_block_dst, nav_block_sz);
|
SearchReplacePattern(dllBase, nav_block_src, nav_block_dst, nav_block_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Field of view
|
||||||
|
const char *fov_pattern = "\x00\x00\x00\x3F\x17\x6C\xC1\x16\x6C\xC1\x76\x3F";
|
||||||
|
char fov_replace[12];
|
||||||
|
float fov;
|
||||||
|
memcpy(fov_replace, fov_pattern, 12); // Make editable copy of pattern
|
||||||
|
memcpy(&fov, fov_replace, sizeof(fov)); // Get float from bytes
|
||||||
|
fov *= 1.0f/config.GetFloat(_T("FOVMultiplier")); // Multiply FOV
|
||||||
|
memcpy(fov_replace, &fov, sizeof(fov)); // Store back into bytes
|
||||||
|
SearchReplacePattern(dllBase, fov_pattern, fov_replace, 12);
|
||||||
|
|
||||||
// DDRAW GetSurfaceDesc Override
|
// DDRAW GetSurfaceDesc Override
|
||||||
OverwriteCall((LPVOID) ((UINT_PTR)dllBase+0xBA7D5), (LPVOID)InterceptSurfaceGetDesc);
|
OverwriteCall((LPVOID) ((UINT_PTR)dllBase+0xBA7D5), (LPVOID)InterceptSurfaceGetDesc);
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,8 @@ PatchGrid::PatchGrid()
|
||||||
|
|
||||||
AddPatch("FOVMultiplier",
|
AddPatch("FOVMultiplier",
|
||||||
_T("Globally adjusts the field of view by a multiplier\n\n"
|
_T("Globally adjusts the field of view by a multiplier\n\n"
|
||||||
"0.1 = Default (smaller than 0.1 is more zoomed in, larger than 0.1 is more zoomed out"),
|
"1.0 = Default (greater than 1.0 is zoomed in, less than 1.0 is zoomed out)"),
|
||||||
AddDoubleItem(sectionGraphics, _T("Field of View Adjustment"), 0.1));
|
AddDoubleItem(sectionGraphics, _T("Field of View Adjustment"), 1.0));
|
||||||
|
|
||||||
// Audio section
|
// Audio section
|
||||||
HSECTION sectionMusic = AddSection(_T("Audio"));
|
HSECTION sectionMusic = AddSection(_T("Audio"));
|
||||||
|
|
Loading…
Reference in a new issue