1
0
mirror of synced 2024-09-24 02:58:20 +02:00
This commit is contained in:
00C0FFEE 2019-05-18 14:26:22 +02:00
parent 7e11e0ea67
commit 607b2641fb
2 changed files with 142 additions and 159 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ ParrotLoader/ParrotLoader\.vcxproj\.user
*.user *.user
*.aps *.aps
OpenParrot/src/Functions/Games/Other/FNFSB2.cpp

View File

@ -14,6 +14,16 @@ DWORD BaseAddress4 = 0x00400000;
int horizontal4 = 0; int horizontal4 = 0;
int vertical4 = 0; int vertical4 = 0;
HWND hWndRT4 = 0; HWND hWndRT4 = 0;
bool movable4 = false;
bool polling4 = false;
static bool previousLeft = false;
static bool previousRight = false;
static bool previousUp = false;
static bool previousDown = false;
static bool gaspressed = false;
static bool brakepressed = false;
// controls // controls
extern int* ffbOffset; extern int* ffbOffset;
extern int* ffbOffset2; extern int* ffbOffset2;
@ -23,6 +33,7 @@ extern int* ffbOffset4;
BOOL(__stdcall *original_SetWindowPos4)(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags); BOOL(__stdcall *original_SetWindowPos4)(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
BOOL(__stdcall *original_CreateWindowExA4)(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); BOOL(__stdcall *original_CreateWindowExA4)(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
BOOL(__stdcall *original_DefWindowProcA4)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); BOOL(__stdcall *original_DefWindowProcA4)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL(__stdcall *original_SetCursorPosRT4)(int X, int Y);
DWORD WINAPI DefWindowProcART4(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) DWORD WINAPI DefWindowProcART4(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
@ -32,31 +43,34 @@ DWORD WINAPI DefWindowProcART4(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
switch (message) switch (message)
{ {
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
injector::WriteMemory<BYTE>((0x576CF + BaseAddress4), 0x01, true);
SetCapture(hWnd); movable4 = true;
xClick = LOWORD(lParam);
yClick = HIWORD(lParam);
break; break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
ReleaseCapture(); injector::WriteMemory<BYTE>((0x576CF + BaseAddress4), 0x00, true);
movable4 = false;
break; break;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
{ {
if (GetCapture() == hWnd) if (movable4 == true)
{ {
RECT rcWindow; injector::WriteMemory<BYTE>((0x576CF + BaseAddress4), 0x01, true);
GetWindowRect(hWnd, &rcWindow); return 0;
int xMouse = LOWORD(lParam);
int yMouse = HIWORD(lParam);
int xWindow = rcWindow.left + xMouse - xClick;
int yWindow = rcWindow.top + yMouse - yClick;
original_SetWindowPos4(hWnd, HWND_TOP, xWindow, yWindow, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
} }
else
{
if (polling4 == false)
{
return 0;
}
if (polling4 == true)
{
break; break;
} }
}
}
} }
return original_DefWindowProcA4(hWnd, message, wParam, lParam); return original_DefWindowProcA4(hWnd, message, wParam, lParam);
} }
@ -88,7 +102,7 @@ DWORD WINAPI InputRT4(LPVOID lpParam)
// TEST // TEST
if (*ffbOffset & 0x01) if (*ffbOffset & 0x01)
{ {
injector::WriteMemory<BYTE>((0x41599 + BaseAddress4), 0xEB, true); injector::WriteMemory<BYTE>((0x4C424 + BaseAddress4), 0xEB, true);
} }
// NITRO ( = START too) // NITRO ( = START too)
if (*ffbOffset & 0x100) if (*ffbOffset & 0x100)
@ -96,34 +110,7 @@ DWORD WINAPI InputRT4(LPVOID lpParam)
injector::WriteMemory<BYTE>((keyboardBuffer + DIK_N), 2, true); injector::WriteMemory<BYTE>((keyboardBuffer + DIK_N), 2, true);
injector::WriteMemory<BYTE>((keyboardBuffer + DIK_SPACE), 2, true); injector::WriteMemory<BYTE>((keyboardBuffer + DIK_SPACE), 2, true);
} }
// SHIFT DOWN
if (*ffbOffset & 0x2000)
{
if (!previousDown)
{
injector::WriteMemory<BYTE>((keyboardBuffer + DIK_DOWN), 2, true);
previousDown = true;
}
else
{
previousDown = false;
}
}
// SHIFT UP
if (*ffbOffset & 0x1000)
{
if (!previousUp)
{
injector::WriteMemory<BYTE>((keyboardBuffer + DIK_UP), 2, true);
previousUp = true;
}
else
{
previousUp = false;
}
}
// BUTTON 1/ VIEW 1 // BUTTON 1/ VIEW 1
if (*ffbOffset & 0x200) if (*ffbOffset & 0x200)
{ {
@ -150,8 +137,10 @@ DWORD WINAPI InputRT4(LPVOID lpParam)
injector::WriteMemory<BYTE>((keyboardBuffer + DIK_LEFT), 2, true); injector::WriteMemory<BYTE>((keyboardBuffer + DIK_LEFT), 2, true);
previousLeft = true; previousLeft = true;
} }
}
else else
{
if (previousLeft == true)
{ {
previousLeft = false; previousLeft = false;
} }
@ -164,117 +153,76 @@ DWORD WINAPI InputRT4(LPVOID lpParam)
injector::WriteMemory<BYTE>((keyboardBuffer + DIK_RIGHT), 2, true); injector::WriteMemory<BYTE>((keyboardBuffer + DIK_RIGHT), 2, true);
previousRight = true; previousRight = true;
} }
}
else else
{
if (previousRight == true)
{ {
previousRight = false; previousRight = false;
} }
} }
INPUT input[4]; RECT rect;
WORD vkey; GetWindowRect(hWndRT4, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
int windowcenterx = (rect.left + (width * 0.5));
int windowcentery = (rect.top + (height * 0.5));
// WHEEL // WHEEL
if (*ffbOffset2 >= 0x85) // RIGHT int iWheel0 = (((float)*ffbOffset2) - 128);
{ float wheel = (iWheel0 * 0.0078125f);
vkey = 0x66; // NUMPAD6 key down int iWheel = (int)((width - 20) * 0.5 * wheel);
input[0].type = INPUT_KEYBOARD; double fx = (float)((0 + wheel) * (65535.0f / horizontal4));
input[0].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC); double fy = (float)((0) *(65535.0f / vertical4));
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[0].ki.wVk = vkey;
input[0].ki.dwFlags = 0;
vkey = 0x64; // NUMPAD4 key up
input[1].type = INPUT_KEYBOARD;
input[1].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC);
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
input[1].ki.wVk = vkey;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
}
else if (*ffbOffset2 <= 0x75) // LEFT
{
vkey = 0x66; // NUMPAD6 key up
input[0].type = INPUT_KEYBOARD;
input[0].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC);
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[0].ki.wVk = vkey;
input[0].ki.dwFlags = KEYEVENTF_KEYUP;
vkey = 0x64; // NUMPAD4 key down
input[1].type = INPUT_KEYBOARD;
input[1].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC);
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
input[1].ki.wVk = vkey;
input[1].ki.dwFlags = 0;
} if (movable4 == false) // then poll ugly mouse input
else // CENTER
{ {
vkey = 0x66; // NUMPAD6 key up polling4 = true;
input[0].type = INPUT_KEYBOARD; mouse_event(MOUSEEVENTF_MOVE, fx, 0, 0, 0);
input[0].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC); polling4 = false;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[0].ki.wVk = vkey;
input[0].ki.dwFlags = KEYEVENTF_KEYUP;
vkey = 0x64; // NUMPAD4 key up
input[1].type = INPUT_KEYBOARD;
input[1].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC);
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
input[1].ki.wVk = vkey;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
} }
WORD vkey;
// GAS // GAS
vkey = 0x51; // Q key (qwerty A)
if (*ffbOffset3 >= 5) if (*ffbOffset3 >= 5)
{ {
vkey = 0x51; // Q key (qwerty A) if (gaspressed == false)
input[2].type = INPUT_KEYBOARD; {
input[2].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC); keybd_event(vkey, MapVirtualKey(vkey, MAPVK_VK_TO_VSC), 0, 0);
input[2].ki.time = 0; gaspressed = true;
input[2].ki.dwExtraInfo = 0; }
input[2].ki.wVk = vkey;
input[2].ki.dwFlags = 0;
} }
else else
{ {
vkey = 0x51; // Q key (qwerty A) if (gaspressed == true)
input[2].type = INPUT_KEYBOARD; {
input[2].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC); keybd_event(vkey, MapVirtualKey(vkey, MAPVK_VK_TO_VSC), KEYEVENTF_KEYUP, 0);
input[2].ki.time = 0; gaspressed = false;
input[2].ki.dwExtraInfo = 0; }
input[2].ki.wVk = vkey;
input[2].ki.dwFlags = KEYEVENTF_KEYUP;
} }
// BRAKE // BRAKE
vkey = 0x57; // W key (qwerty Z)
if (*ffbOffset4 >= 5) if (*ffbOffset4 >= 5)
{ {
vkey = 0x57; // W key (qwerty Z) if (brakepressed == false)
input[3].type = INPUT_KEYBOARD; {
input[3].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC); keybd_event(vkey, MapVirtualKey(vkey, MAPVK_VK_TO_VSC), 0, 0);
input[3].ki.time = 0; brakepressed = true;
input[3].ki.dwExtraInfo = 0; }
input[3].ki.wVk = vkey;
input[3].ki.dwFlags = 0;
} }
else else
{ {
vkey = 0x57; // W key (qwerty Z) if (brakepressed == true)
input[3].type = INPUT_KEYBOARD; {
input[3].ki.wScan = MapVirtualKey(vkey, MAPVK_VK_TO_VSC); keybd_event(vkey, MapVirtualKey(vkey, MAPVK_VK_TO_VSC), KEYEVENTF_KEYUP, 0);
input[3].ki.time = 0; brakepressed = false;
input[3].ki.dwExtraInfo = 0; }
input[3].ki.wVk = vkey;
input[3].ki.dwFlags = KEYEVENTF_KEYUP;
} }
SendInput(4, input, sizeof(INPUT));
//DEBUG////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //DEBUG//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// info(true, "test values *ffbOffset2=0x%02X / *ffbOffset3=0x%02X / *ffbOffset4=0x%02X ", *ffbOffset2, *ffbOffset3, *ffbOffset4); // info(true, "test values *ffbOffset2=0x%02X / *iWheel=%d / *wheel=%f ", *ffbOffset2, iWheel, fx);
//DEBUG////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //DEBUG//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Sleep(deltaTimer); Sleep(deltaTimer);
@ -282,6 +230,7 @@ DWORD WINAPI InputRT4(LPVOID lpParam)
return 0; return 0;
} }
DWORD WINAPI WindowRT4(LPVOID lpParam) DWORD WINAPI WindowRT4(LPVOID lpParam)
{ {
while (true) while (true)
@ -296,10 +245,42 @@ DWORD WINAPI WindowRT4(LPVOID lpParam)
} }
if (hWndTMP == hWndRT4) if (hWndTMP == hWndRT4)
{ {
injector::WriteMemory<BYTE>((0x576CF + BaseAddress4), 0x01, true);
movable4 = true;
original_SetWindowPos4(hWndRT4, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE); original_SetWindowPos4(hWndRT4, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE);
ShowWindow(hWndRT4, SW_MINIMIZE); ShowWindow(hWndRT4, SW_MINIMIZE);
} }
} }
// LEFT-CLICK MOVES WINDOW FROM TOP-LEFT CORNER
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
{
HWND hWndTMP = GetForegroundWindow();
if (hWndRT4 == 0)
{
hWndRT4 = FindWindowA(NULL, "Fast n Furious SuperBikes");
}
if (hWndTMP == hWndRT4)
{
injector::WriteMemory<BYTE>((0x576CF + BaseAddress4), 0x01, true);
movable4 = true;
POINT point;
GetCursorPos(&point);
RECT rect;
GetWindowRect(hWndRT4, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
LPARAM blah = MAKELPARAM(point.x, point.y);
int xClick = LOWORD(blah);
int yClick = HIWORD(blah);
original_SetWindowPos4(hWndRT4, HWND_TOP, xClick, yClick, width, height, SWP_NOSIZE);
SetForegroundWindow(hWndRT4);
}
}
else
{
injector::WriteMemory<BYTE>((0x576CF + BaseAddress4), 0x00, true);
movable4 = false;
}
} }
} }
@ -310,7 +291,7 @@ DWORD WINAPI CreateWindowExART4(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWi
DWORD WINAPI SetCursorPosRT4(int X, int Y) DWORD WINAPI SetCursorPosRT4(int X, int Y)
{ {
return 1; return 0;
} }
DWORD WINAPI SetWindowPosRT4(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) DWORD WINAPI SetWindowPosRT4(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
@ -330,25 +311,26 @@ static InitFunction FNFSBFunc([]()
// FIX file write on D: // FIX file write on D:
injector::WriteMemoryRaw((0x125B50 + BaseAddress4), "\x2E\x5C\x65\x72\x72\x6F\x72\x6C\x6F\x67\x2E\x74\x78\x74\x00", 15, true); injector::WriteMemoryRaw((0x125B50 + BaseAddress4), "\x2E\x5C\x65\x72\x72\x6F\x72\x6C\x6F\x67\x2E\x74\x78\x74\x00", 15, true);
injector::WriteMemoryRaw((0x11FAD4 + BaseAddress4), "\x2E\x5C\x76\x65\x72\x73\x69\x6F\x6E\x2E\x74\x78\x74\x00", 14, true);
// TEST KEY FIX (uses BACKSPACE now) // TEST KEY FIX (uses BACKSPACE now)
injector::MakeNOP((0x4C426 + BaseAddress4), 14); injector::MakeNOP((0x4C426 + BaseAddress4), 14);
injector::WriteMemory<BYTE>((0x4C435 + BaseAddress4), DIK_BACK, true); injector::WriteMemory<BYTE>((0x4C435 + BaseAddress4), DIK_BACK, true);
MH_Initialize();
MH_CreateHookApi(L"user32.dll", "SetCursorPos", &SetCursorPosRT4, (void**)&original_SetCursorPosRT4);
MH_CreateHookApi(L"user32.dll", "DefWindowProcA", &DefWindowProcART4, (void**)&original_DefWindowProcA4);
MH_EnableHook(MH_ALL_HOOKS);
CreateThread(NULL, 0, InputRT4, NULL, 0, NULL); CreateThread(NULL, 0, InputRT4, NULL, 0, NULL);
if (ToBool(config["General"]["Windowed"])) if (ToBool(config["General"]["Windowed"]))
{ {
// CURSOR NOT HIDDEN
injector::WriteMemory<BYTE>((0x576CF + BaseAddress4), 0x01, true);
CreateThread(NULL, 0, WindowRT4, NULL, 0, NULL); CreateThread(NULL, 0, WindowRT4, NULL, 0, NULL);
MH_Initialize(); MH_Initialize();
MH_CreateHookApi(L"user32.dll", "CreateWindowExA", &CreateWindowExART4, (void**)&original_CreateWindowExA4); MH_CreateHookApi(L"user32.dll", "CreateWindowExA", &CreateWindowExART4, (void**)&original_CreateWindowExA4);
MH_CreateHookApi(L"user32.dll", "SetCursorPos", &SetCursorPosRT4, NULL);
MH_CreateHookApi(L"user32.dll", "SetWindowPos", &SetWindowPosRT4, (void**)&original_SetWindowPos4); MH_CreateHookApi(L"user32.dll", "SetWindowPos", &SetWindowPosRT4, (void**)&original_SetWindowPos4);
MH_CreateHookApi(L"user32.dll", "DefWindowProcA", &DefWindowProcART4, (void**)&original_DefWindowProcA4);
MH_EnableHook(MH_ALL_HOOKS); MH_EnableHook(MH_ALL_HOOKS);
} }