1
0
mirror of synced 2024-11-15 07:17:35 +01:00

- Snocross: minor code cleanup, fix windowed mode

- Snocross: minor code cleanup, fix windowed mode
This commit is contained in:
Nezarn 2021-02-02 13:50:59 +01:00
parent e767c483e3
commit 80a07a3710
3 changed files with 171 additions and 269 deletions

View File

@ -13,9 +13,6 @@ typedef unsigned int U32;
typedef unsigned char U8; typedef unsigned char U8;
DWORD BaseAddress7 = 0x00400000; DWORD BaseAddress7 = 0x00400000;
int horizontal7 = 0;
int vertical7 = 0;
HWND hWndRT7 = 0;
static bool previousLeft = false; static bool previousLeft = false;
static bool previousRight = false; static bool previousRight = false;
@ -43,9 +40,6 @@ extern int* ffbOffset;
extern int* ffbOffset2; extern int* ffbOffset2;
extern int* ffbOffset3; extern int* ffbOffset3;
extern int* ffbOffset4; extern int* ffbOffset4;
// hooks ori
BOOL(__stdcall* original_SetWindowPos7)(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
BOOL(__stdcall* original_CreateWindowExA7)(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
DWORD WINAPI InputRT7(LPVOID lpParam) DWORD WINAPI InputRT7(LPVOID lpParam)
{ {
@ -55,20 +49,6 @@ DWORD WINAPI InputRT7(LPVOID lpParam)
while (true) while (true)
{ {
// ESCAPE QUITS GAME
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
{
HWND hWndTMP = GetForegroundWindow();
if (hWndRT7 == 0)
{
hWndRT7 = FindWindowA(NULL, "X-Games SnoCross");
}
if (hWndTMP == hWndRT7)
{
exit(0);
}
}
if (GetAsyncKeyState(VK_NUMPAD1) & 0x0001) if (GetAsyncKeyState(VK_NUMPAD1) & 0x0001)
{ {
if (NUMpressed1 == false) if (NUMpressed1 == false)
@ -432,103 +412,8 @@ DWORD WINAPI InputRT7(LPVOID lpParam)
return 0; return 0;
} }
DWORD WINAPI WindowRT7(LPVOID lpParam)
{
while (true)
{
// RIGHT-CLICK MINIMIZES WINDOW
if (GetAsyncKeyState(VK_RBUTTON) & 0x8000)
{
HWND hWndTMP = GetForegroundWindow();
if (hWndRT7 == 0)
{
hWndRT7 = FindWindowA(NULL, "X-Games SnoCross");
}
if (hWndTMP == hWndRT7)
{
RECT rect;
GetWindowRect(hWndRT7, &rect);
int currentwidth = rect.right - rect.left;
int currentheight = rect.bottom - rect.top;
original_SetWindowPos7(hWndRT7, HWND_BOTTOM, 0, 0, 1366, 768, SWP_NOSIZE);
ShowWindow(hWndRT7, SW_MINIMIZE);
}
}
}
}
BOOL(__stdcall* original_DefWindowProcA7)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
DWORD WINAPI DefWindowProcART7(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int xClick;
static int yClick;
switch (message)
{
case WM_LBUTTONDOWN:
SetCapture(hWnd);
xClick = LOWORD(lParam);
yClick = HIWORD(lParam);
break;
case WM_LBUTTONUP:
ReleaseCapture();
break;
case WM_MOUSEMOVE:
{
if (GetCapture() == hWnd)
{
RECT rcWindow;
GetWindowRect(hWnd, &rcWindow);
int xMouse = LOWORD(lParam);
int yMouse = HIWORD(lParam);
int xWindow = rcWindow.left + xMouse - xClick;
int yWindow = rcWindow.top + yMouse - yClick;
if (xWindow >= (horizontal7 - 100))
xWindow = 0;
if (yWindow >= (vertical7 - 100))
yWindow = 0;
original_SetWindowPos7(hWnd, NULL, xWindow, yWindow, 1366, 768, SWP_NOSIZE | SWP_NOZORDER);
}
break;
}
}
return original_DefWindowProcA7(hWnd, message, wParam, lParam);
}
DWORD WINAPI CreateWindowExART7(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
return original_CreateWindowExA7(dwExStyle, lpClassName, "X-Games SnoCross", 0x94000000, 0, 0, 1366, 768, hWndParent, hMenu, hInstance, lpParam);
}
DWORD WINAPI SetCursorPosRT7(int X, int Y)
{
return 1;
}
DWORD WINAPI SetWindowPosRT7(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
{
return 1;
}
bool windowed = false;
static InitFunction SnoCrossFunc([]() static InitFunction SnoCrossFunc([]()
{ {
MH_Initialize();
MH_CreateHookApi(L"user32.dll", "CreateWindowExA", CreateWindowExART7, (void**)& original_CreateWindowExA7);
MH_CreateHookApi(L"user32.dll", "SetWindowPos", SetWindowPosRT7, (void**)& original_SetWindowPos7);
if (ToBool(config["General"]["Windowed"]))
{
windowed = true;
MH_CreateHookApi(L"user32.dll", "DefWindowProcA", DefWindowProcART7, (void**)& original_DefWindowProcA7);
MH_CreateHookApi(L"user32.dll", "SetCursorPos", SetCursorPosRT7, NULL);
}
GetDesktopResolution(horizontal7, vertical7);
// PATCHING EXE AT RUNTIME (reboots, network, filepath, config, CRC...36DF3D // PATCHING EXE AT RUNTIME (reboots, network, filepath, config, CRC...36DF3D
injector::WriteMemoryRaw((0x36DF3D + BaseAddress7), "\x75\x0D", 2, true); injector::WriteMemoryRaw((0x36DF3D + BaseAddress7), "\x75\x0D", 2, true);
injector::WriteMemoryRaw((0x6C7EB + BaseAddress7), "\xF0", 1, true); injector::WriteMemoryRaw((0x6C7EB + BaseAddress7), "\xF0", 1, true);
@ -539,11 +424,6 @@ static InitFunction SnoCrossFunc([]()
injector::WriteMemoryRaw((0x70DE0 + BaseAddress7), "\x90\x90", 2, true); injector::WriteMemoryRaw((0x70DE0 + BaseAddress7), "\x90\x90", 2, true);
injector::WriteMemoryRaw((0x71499 + BaseAddress7), "\xE9\x9A\x00\x00\x00\x90", 6, true); injector::WriteMemoryRaw((0x71499 + BaseAddress7), "\xE9\x9A\x00\x00\x00\x90", 6, true);
injector::WriteMemoryRaw((0x3783AD + BaseAddress7), "\x31\xC0\x40", 3, true); injector::WriteMemoryRaw((0x3783AD + BaseAddress7), "\x31\xC0\x40", 3, true);
//injector::WriteMemoryRaw((0x3A8F90 + BaseAddress7), "\x2E\x5C\x63\x6F\x70\x73\x32\x2E\x68\x73\x74\x00", 12, true);
//injector::WriteMemoryRaw((0x3A9D48 + BaseAddress7), "\x2E\x5C\x61\x75\x64\x62\x61\x6B\x00\x00\x00\x00\x61\x75\x64\x69\x74\x73\x00\x00\x2E\x5C\x61\x75\x64\x69\x74\x73\x00", 29, true);
//injector::WriteMemoryRaw((0x3A9D5C + BaseAddress7), "\x2E\x5C\x41\x75\x64\x69\x74\x4C\x6F\x67\x30\x30\x30\x2E\x74\x78\x74\x00\x00", 19, true);
//injector::WriteMemoryRaw((0x3ACE14 + BaseAddress7), "\x2E\x5C\x70\x72\x65\x66\x73\x62\x61\x6B\x00\x00\x70\x72\x65\x66\x73\x00\x00\x00\x2E\x5C\x70\x72\x65\x66\x73\x00", 28, true);
//injector::WriteMemoryRaw((0x3AF5C8 + BaseAddress7), "\x2E\x5C\x6D\x70\x2E\x70\x64\x74\x00", 9, true);
injector::WriteMemoryRaw(0x3A8F90 + BaseAddress7, ".\\cops2.hst\0", 12, true); injector::WriteMemoryRaw(0x3A8F90 + BaseAddress7, ".\\cops2.hst\0", 12, true);
injector::WriteMemoryRaw(0x3A9D48 + BaseAddress7, ".\\audbak\0", 9, true); injector::WriteMemoryRaw(0x3A9D48 + BaseAddress7, ".\\audbak\0", 9, true);
injector::WriteMemoryRaw(0x3A9D5C + BaseAddress7, ".\\audits\0", 9, true); injector::WriteMemoryRaw(0x3A9D5C + BaseAddress7, ".\\audits\0", 9, true);
@ -559,6 +439,10 @@ static InitFunction SnoCrossFunc([]()
injector::WriteMemoryRaw(0x3AE200 + BaseAddress7, ".\\errorlog.txt\0", 15, true); injector::WriteMemoryRaw(0x3AE200 + BaseAddress7, ".\\errorlog.txt\0", 15, true);
injector::WriteMemoryRaw(0x3AE210 + BaseAddress7, ".\\Minidump_%d.dmp\0", 18, true); injector::WriteMemoryRaw(0x3AE210 + BaseAddress7, ".\\Minidump_%d.dmp\0", 18, true);
injector::WriteMemoryRaw(0x3B03A4 + BaseAddress7, ".\\Minidump\0", 11, true); injector::WriteMemoryRaw(0x3B03A4 + BaseAddress7, ".\\Minidump\0", 11, true);
injector::WriteMemoryRaw(0x3AE268 + BaseAddress7, "%c\\AuditLog%04i.txt\0", 20, true);
injector::WriteMemoryRaw(0x3AE23C + BaseAddress7, "%c\\erlg%.4d.txt\0", 16, true);
injector::WriteMemoryRaw(0x3AE2B0 + BaseAddress7, "%c\\scores%04i.html\0", 19, true);
injector::WriteMemoryRaw(0x3AE280 + BaseAddress7, "%c\\audit%04i.txt\0", 17, true);
// some %c string fix // some %c string fix
injector::WriteMemory<BYTE>(0xA2A6A + BaseAddress7, 0x2E, true); injector::WriteMemory<BYTE>(0xA2A6A + BaseAddress7, 0x2E, true);
@ -573,12 +457,23 @@ static InitFunction SnoCrossFunc([]()
CreateThread(NULL, 0, InputRT7, NULL, 0, NULL); CreateThread(NULL, 0, InputRT7, NULL, 0, NULL);
if (windowed) if (ToBool(config["General"]["Windowed"]))
{ {
// NO HIDE CURSOR // NO HIDE CURSOR
injector::WriteMemory<BYTE>((0x14A9F + BaseAddress7), 0x01, true); injector::WriteMemory<BYTE>((0x14A9F + BaseAddress7), 0x01, true);
injector::MakeNOP(BaseAddress7 + 0x14B44, 8, true);
CreateThread(NULL, 0, WindowRT7, NULL, 0, NULL); static const char* title = "OpenParrot - X-Games SnoCross";
injector::WriteMemory<DWORD>(BaseAddress7 + 0x14DC5, (DWORD)title, true);
windowHooks hooks = { 0 };
hooks.createWindowExA = BaseAddress7 + 0x3A32F4;
hooks.adjustWindowRect = BaseAddress7 + 0x3A332C;
hooks.adjustWindowRectEx = BaseAddress7 + 0x3A32F8;
hooks.setWindowPos = BaseAddress7 + 0x3A3328;
hooks.setCursorPos = BaseAddress7 + 0x3A3300;
init_windowHooks(&hooks);
} }
// MACHINE ID setting // MACHINE ID setting
@ -621,13 +516,9 @@ static InitFunction SnoCrossFunc([]()
// redirect messages.txt // redirect messages.txt
injector::WriteMemoryRaw(BaseAddress7 + 0x4A9EF4, "./messages.txt", 14, true); injector::WriteMemoryRaw(BaseAddress7 + 0x4A9EF4, "./messages.txt", 14, true);
// redirect auditlog.txt
injector::WriteMemoryRaw(BaseAddress7 + 0x3AA054, ".//AuditLog%.3d.txt", 19, true);
//graphics crashfix //graphics crashfix
injector::WriteMemory<BYTE>(BaseAddress7 + 0xC7FE2, 0xEB, true); injector::WriteMemory<BYTE>(BaseAddress7 + 0xC7FE2, 0xEB, true);
injector::MakeNOP(BaseAddress7 + 0xC7FDB, 2, true); injector::MakeNOP(BaseAddress7 + 0xC7FDB, 2, true);
MH_EnableHook(MH_ALL_HOOKS);
}, GameID::SnoCross); }, GameID::SnoCross);
#endif #endif

View File

@ -225,6 +225,11 @@ BOOL WINAPI ClipCursorHk(const RECT* lpRect)
return false; return false;
} }
BOOL WINAPI SetCursorPosHk(int X, int Y)
{
return true;
}
void init_windowHooks(windowHooks* data) void init_windowHooks(windowHooks* data)
{ {
g_windowStyle = WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; g_windowStyle = WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
@ -279,6 +284,11 @@ void init_windowHooks(windowHooks* data)
{ {
*(BOOL*)data->clipCursor = (BOOL)ClipCursorHk; *(BOOL*)data->clipCursor = (BOOL)ClipCursorHk;
} }
if (data->setCursorPos != NULL)
{
*(BOOL*)data->setCursorPos = (BOOL)SetCursorPosHk;
}
} }
/* END WINDOW HOOKS */ /* END WINDOW HOOKS */

View File

@ -15,6 +15,7 @@ struct windowHooks
int changeDisplaySettingsExW; int changeDisplaySettingsExW;
int updateWindow; int updateWindow;
int clipCursor; int clipCursor;
int setCursorPos;
}; };
void init_windowHooks(windowHooks* data); void init_windowHooks(windowHooks* data);