diff --git a/OpenParrot/src/Functions/Games/Other/Daytona3.cpp b/OpenParrot/src/Functions/Games/Other/Daytona3.cpp index cf62163..f598450 100644 --- a/OpenParrot/src/Functions/Games/Other/Daytona3.cpp +++ b/OpenParrot/src/Functions/Games/Other/Daytona3.cpp @@ -15,65 +15,130 @@ bool daytonaPressStart = false; uintptr_t imageBase; bool shiftup = false; bool shiftdown = false; +static bool viewchange = false; +static bool keybdleft = false; +static bool keybdright = false; +static bool keybdup = false; void ShiftUp(BYTE shift) { - *(BYTE *)(imageBase + 0x15B468C) = shift + 1; + *(BYTE*)(imageBase + 0x15B468C) = shift + 1; } void ShiftDown(BYTE shift) { - *(BYTE *)(imageBase + 0x15B468C) = shift - 1; + *(BYTE*)(imageBase + 0x15B468C) = shift - 1; } static void InjectKeys() { - + DWORD buttons2 = *wheelSection; DWORD buttons = *ffbOffset; BYTE wheel = *ffbOffset2; BYTE gas = *ffbOffset3; BYTE brake = *ffbOffset4; - - BYTE gamestate = *(BYTE *)(imageBase + 0x15B5744); - BYTE gear = *(BYTE *)(imageBase + 0x15B468C); - - *(BYTE *)(imageBase + 0x15B4679) = gas; - *(BYTE *)(imageBase + 0x15B467A) = brake; - - DWORD track = *(DWORD *)(imageBase + 0x011B0148); - if (track != 0) + + BYTE gamestate = *(BYTE*)(imageBase + 0x15B5744); + BYTE gear = *(BYTE*)(imageBase + 0x15B468C); + BYTE viewread = *(BYTE*)(imageBase + 0x15B5DB0); + + *(BYTE*)(imageBase + 0x15B4679) = gas; + *(BYTE*)(imageBase + 0x15B467A) = brake; + + HWND hWnd = FindWindowA(0, ("Daytona Championship USA")); + + //Menu Movement & Game Initial Screen + if (gamestate == 18 || gamestate == 30) { - BYTE track1 = *(BYTE *)(track + 0x4); -#ifdef _DEBUG - info(true, "%02X %02X", track1, gamestate); -#endif - if ((track1 == 2 || track1 == 4) && (gamestate == 0x16)) + if ((wheel <= 0x75) && (wheel > 0x50)) + { + //Menu Left + if (!keybdleft) { - BYTE reverse = wheel * 0xFF; - if (reverse == 0x00) - *(BYTE *)(imageBase + 0x15B4678) = 0xFF; - else - *(BYTE *)(imageBase + 0x15B4678) = reverse; -#ifdef _DEBUG - info(true, "Reverse wheel"); -#endif + keybdleft = true; + SendMessage(hWnd, WM_KEYDOWN, VK_LEFT, 0); } else { - *(BYTE *)(imageBase + 0x15B4678) = wheel; -#ifdef _DEBUG - info(true, "Normal wheel1"); -#endif + SendMessage(hWnd, WM_KEYUP, VK_LEFT, 0); } } + else if (wheel <= 0x50) + { + SendMessage(hWnd, WM_KEYDOWN, VK_LEFT, 0); + } + else if ((wheel >= 0x89) && (wheel < 0xAE)) + { + //Menu Right + if (!keybdright) + { + keybdright = true; + SendMessage(hWnd, WM_KEYDOWN, VK_RIGHT, 0); + } + else + { + SendMessage(hWnd, WM_KEYUP, VK_RIGHT, 0); + } + } + else if (wheel >= 0xAE) + { + SendMessage(hWnd, WM_KEYDOWN, VK_RIGHT, 0); + } else { - *(BYTE *)(imageBase + 0x15B4678) = wheel; + keybdleft = false; + keybdright = false; + SendMessage(hWnd, WM_KEYUP, VK_RIGHT, 0); + SendMessage(hWnd, WM_KEYUP, VK_LEFT, 0); + } + keybdup = false; + } + else + { + if (!keybdup) + { + keybdup = true; + keybdleft = false; + keybdright = false; + SendMessage(hWnd, WM_KEYUP, VK_RIGHT, 0); + SendMessage(hWnd, WM_KEYUP, VK_LEFT, 0); + } + } + + DWORD track = *(DWORD*)(imageBase + 0x011B0148); + if (track != 0) + { + BYTE track1 = *(BYTE*)(track + 0x4); #ifdef _DEBUG - info(true, "Normal wheel2"); + info(true, "%02X %02X", track1, gamestate); +#endif + if ((track1 == 2 || track1 == 4) && (gamestate == 0x16)) + { + BYTE reverse = wheel * 0xFF; + if (reverse == 0x00) + *(BYTE*)(imageBase + 0x15B4678) = 0xFF; + else + *(BYTE*)(imageBase + 0x15B4678) = reverse; +#ifdef _DEBUG + info(true, "Reverse wheel"); #endif } + else + { + *(BYTE*)(imageBase + 0x15B4678) = wheel; +#ifdef _DEBUG + info(true, "Normal wheel1"); +#endif + } + } + else + { + *(BYTE*)(imageBase + 0x15B4678) = wheel; +#ifdef _DEBUG + info(true, "Normal wheel2"); +#endif + } if (gas >= 0x40) { @@ -84,68 +149,28 @@ static void InjectKeys() daytonaPressStart = false; } - if (wheel <= 0x40) - { - //Menu Left - DWORD p = *(DWORD *)(imageBase + 0x1AAFFF0); - if (p != 0) - { - DWORD p1 = *(DWORD *)(p + 0x00); - if (p1 != 0) - { - *(BYTE *)(p1 + 0x25) = 0xFF; - } - } - } - else if (wheel >= 0xC0) - { - //Menu Right - DWORD p = *(DWORD *)(imageBase + 0x1AAFFF0); - if (p != 0) - { - DWORD p1 = *(DWORD *)(p + 0x00); - if (p1 != 0) - { - *(BYTE *)(p1 + 0x27) = 0xFF; - } - } - } - else - { - DWORD p = *(DWORD *)(imageBase + 0x1AAFFF0); - if (p != 0) - { - DWORD p1 = *(DWORD *)(p + 0x00); - if (p1 != 0) - { - *(BYTE *)(p1 + 0x25) = 0x00; - *(BYTE *)(p1 + 0x27) = 0x00; - } - } - } - if (buttons == 0x01) { //Inject Start - DWORD p = *(DWORD *)(imageBase + 0x1AB0010); + DWORD p = *(DWORD*)(imageBase + 0x1AB0010); if (p != 0) { - DWORD p1 = *(DWORD *)(p + 0x00); + DWORD p1 = *(DWORD*)(p + 0x00); if (p1 != 0) { - *(DWORD *)(p1 + 0x08) = 0x01; + *(DWORD*)(p1 + 0x08) = 0x01; } } } else { - DWORD p = *(DWORD *)(imageBase + 0x1AB0010); + DWORD p = *(DWORD*)(imageBase + 0x1AB0010); if (p != 0) { - DWORD p1 = *(DWORD *)(p + 0x00); + DWORD p1 = *(DWORD*)(p + 0x00); if (p1 != 0) { - *(DWORD *)(p1 + 0x08) = 0x00; + *(DWORD*)(p1 + 0x08) = 0x00; } } } @@ -155,7 +180,7 @@ static void InjectKeys() if (!shiftup) { shiftup = true; - ShiftUp(*(BYTE *)(imageBase + 0x15B468C)); + ShiftUp(*(BYTE*)(imageBase + 0x15B468C)); } } else @@ -168,7 +193,7 @@ static void InjectKeys() if (!shiftdown) { shiftdown = true; - ShiftDown(*(BYTE *)(imageBase + 0x15B468C)); + ShiftDown(*(BYTE*)(imageBase + 0x15B468C)); } } else @@ -179,69 +204,80 @@ static void InjectKeys() if (buttons2 == 0x01) { //Gear Change 1 - *(BYTE *)(imageBase + 0x15B468C) = 0x00; + *(BYTE*)(imageBase + 0x15B468C) = 0x00; } if (buttons2 == 0x02) { //Gear Change 2 - *(BYTE *)(imageBase + 0x15B468C) = 0x01; + *(BYTE*)(imageBase + 0x15B468C) = 0x01; } if (buttons2 == 0x04) { //Gear Change 3 - *(BYTE *)(imageBase + 0x15B468C) = 0x02; + *(BYTE*)(imageBase + 0x15B468C) = 0x02; } if (buttons2 == 0x08) { //Gear Change 4 - *(BYTE *)(imageBase + 0x15B468C) = 0x03; + *(BYTE*)(imageBase + 0x15B468C) = 0x03; } - if (buttons2 == 0x10) + if (ToBool(config["General"]["View Change 1 To Cycle All Views"])) { - //View Change 1 + if ((buttons2 == 0x10) && (viewread < 4)) //INCLUDES SPECIAL VIEW { - *(DWORD *)(imageBase + 0x15B5DB0) = 0x00; + //View Change 1 + if (!viewchange) + { + viewchange = true; + *(BYTE*)(imageBase + 0x15B5DB0) = ++viewread; + } + } + else if ((buttons2 == 0x10) && (viewread == 4)) + { + if (!viewchange) + { + viewchange = true; + *(BYTE*)(imageBase + 0x15B5DB0) = 0x00; + } + } + else + { + viewchange = false; } } - - if (buttons2 == 0x20) + else { - //View Change 2 + if (buttons2 == 0x10) { - *(DWORD *)(imageBase + 0x15B5DB0) = 0x01; + //View Change 1 + *(DWORD*)(imageBase + 0x15B5DB0) = 0x00; } - } - if (buttons2 == 0x40) - { - //View Change 3 + if (buttons2 == 0x20) { - *(DWORD *)(imageBase + 0x15B5DB0) = 0x02; + //View Change 2 + *(DWORD*)(imageBase + 0x15B5DB0) = 0x01; } - } - if (buttons2 == 0x80) - { - //View Change 4 + if (buttons2 == 0x40) { - *(DWORD *)(imageBase + 0x15B5DB0) = 0x03; + //View Change 3 + *(DWORD*)(imageBase + 0x15B5DB0) = 0x02; } - } - if (buttons2 == 0xF0) - { - //View Change 5 + if (buttons2 == 0x80) { - *(DWORD *)(imageBase + 0x15B5DB0) = 0x04; + //View Change 4 + *(DWORD*)(imageBase + 0x15B5DB0) = 0x03; } } } -int(__stdcall *g_origControlsFunction)(); +int(__stdcall* g_origControlsFunction)(); int __stdcall ControlsFunction() { @@ -251,29 +287,29 @@ int __stdcall ControlsFunction() } static InitFunction Daytona3Func([]() -{ - imageBase = (uintptr_t)GetModuleHandleA(0); - injector::WriteMemoryRaw(imageBase + 0xDD697, "\x90\x90\x90\x90\x90\x90\x38\x05\xC8\xF9\x5A\x01\x90\x90\x90\x90\x90\x90", 18, true); - injector::WriteMemoryRaw(imageBase + 0x12958F, "\x33\xC0\x8A\x45\x08\x90\x90\x90\x90\x72\x08\x66\xA3\x46\xFC\x5A\x01\xEB\x06\x66\xA3\x44\xFC\x5A\x01\x31\xFF\x31\xF6\x47\xBE\x0F\x00\x00\x00\xEB\x4C\x90\x90\x90\x90", 41, true); - injector::WriteMemoryRaw(imageBase + 0xD8616C, "\x2E\x2E\x2F\x73\x68\x65\x6C\x6C\x00\x00\x00\x00\x00\x00\x00\x00\x2E\x2E\x2F\x73\x68\x65\x6C\x6C\x5C\x49\x6E\x70\x57\x72\x61\x70\x70\x65\x72\x2E\x65\x78\x65\x00\x00\x00\x00\x00\x00\x00\x00\x00", 48, true); - injector::WriteMemoryRaw(imageBase + 0x7D087, "\x85\xFF\x0F\x84\xE9\x01\x00\x00\x6A\x00\x8B\xCF\xE8\xC8\xD2\x21\x00\x8D\x80\x00\x80\x00\x00\x89\x46\x40\x6A\x05\x8B\xCF\xE8\xB6\xD2\x21\x00\xC1\xE0\x08\x89\x46\x44\x6A\x04\x8B\xCF\xE8\xA7\xD2\x21\x00\xC1\xE0\x08\x89\x46\x48\x90\xEB\x2E\xE8\xE9\xD4\x21\x00\x8B\x5E\x04\x8B\xF8\x8B\xCF\xE8\x2D\xD5\x21\x00\x8D\x4B\x01\x3B\xC1\x0F\x8C\x9A\x01\x00\x00\x53\x8B\xCF\xE8\xDA\xD4\x21\x00\x8B\xF8\xEB\x9D\x90\x90\x90\x90\x90\x90", 105, true); - injector::MakeNOP(imageBase + 0x1DDDFA, 5); - injector::MakeNOP(imageBase + 0x1DDE1E, 6); - injector::MakeNOP(imageBase + 0x1DDE45, 6); - injector::MakeNOP(imageBase + 0x1DE10D, 6); - injector::MakeNOP(imageBase + 0x29B481, 3); - injector::MakeNOP(imageBase + 0x29B513, 4); - if (ToBool(config["General"]["MSAA4X Disable"])) { - injector::WriteMemoryRaw(imageBase + 0x17CD3D, "\x00", 1, true); - } - if (ToBool(config["General"]["Hide Cursor"])) - { - SetCursorPos(2000, 2000); - } - MH_Initialize(); - MH_CreateHook((void*)(imageBase + 0x1E9280), ControlsFunction, (void**)&g_origControlsFunction); - MH_EnableHook(MH_ALL_HOOKS); - -}, GameID::Daytona3); + imageBase = (uintptr_t)GetModuleHandleA(0); + injector::WriteMemoryRaw(imageBase + 0xDD697, "\x90\x90\x90\x90\x90\x90\x38\x05\xC8\xF9\x5A\x01\x90\x90\x90\x90\x90\x90", 18, true); + injector::WriteMemoryRaw(imageBase + 0x12958F, "\x33\xC0\x8A\x45\x08\x90\x90\x90\x90\x72\x08\x66\xA3\x46\xFC\x5A\x01\xEB\x06\x66\xA3\x44\xFC\x5A\x01\x31\xFF\x31\xF6\x47\xBE\x0F\x00\x00\x00\xEB\x4C\x90\x90\x90\x90", 41, true); + injector::WriteMemoryRaw(imageBase + 0xD8616C, "\x2E\x2E\x2F\x73\x68\x65\x6C\x6C\x00\x00\x00\x00\x00\x00\x00\x00\x2E\x2E\x2F\x73\x68\x65\x6C\x6C\x5C\x49\x6E\x70\x57\x72\x61\x70\x70\x65\x72\x2E\x65\x78\x65\x00\x00\x00\x00\x00\x00\x00\x00\x00", 48, true); + injector::WriteMemoryRaw(imageBase + 0x7D087, "\x85\xFF\x0F\x84\xE9\x01\x00\x00\x6A\x00\x8B\xCF\xE8\xC8\xD2\x21\x00\x8D\x80\x00\x80\x00\x00\x89\x46\x40\x6A\x05\x8B\xCF\xE8\xB6\xD2\x21\x00\xC1\xE0\x08\x89\x46\x44\x6A\x04\x8B\xCF\xE8\xA7\xD2\x21\x00\xC1\xE0\x08\x89\x46\x48\x90\xEB\x2E\xE8\xE9\xD4\x21\x00\x8B\x5E\x04\x8B\xF8\x8B\xCF\xE8\x2D\xD5\x21\x00\x8D\x4B\x01\x3B\xC1\x0F\x8C\x9A\x01\x00\x00\x53\x8B\xCF\xE8\xDA\xD4\x21\x00\x8B\xF8\xEB\x9D\x90\x90\x90\x90\x90\x90", 105, true); + injector::MakeNOP(imageBase + 0x1DDDFA, 5); + injector::MakeNOP(imageBase + 0x1DDE1E, 6); + injector::MakeNOP(imageBase + 0x1DDE45, 6); + injector::MakeNOP(imageBase + 0x1DE10D, 6); + injector::MakeNOP(imageBase + 0x29B481, 3); + injector::MakeNOP(imageBase + 0x29B513, 4); + if (ToBool(config["General"]["MSAA4X Disable"])) + { + injector::WriteMemoryRaw(imageBase + 0x17CD3D, "\x00", 1, true); + } + if (ToBool(config["General"]["Hide Cursor"])) + { + SetCursorPos(2000, 2000); + } + MH_Initialize(); + MH_CreateHook((void*)(imageBase + 0x1E9280), ControlsFunction, (void**)&g_origControlsFunction); + MH_EnableHook(MH_ALL_HOOKS); + + }, GameID::Daytona3); #endif \ No newline at end of file diff --git a/OpenParrot/src/Functions/XInputEmu.cpp b/OpenParrot/src/Functions/XInputEmu.cpp index b8e888f..c1e7c9f 100644 --- a/OpenParrot/src/Functions/XInputEmu.cpp +++ b/OpenParrot/src/Functions/XInputEmu.cpp @@ -6,7 +6,7 @@ struct XboxOneControllerHandler { - struct usb_dev_handle *handle; + struct usb_dev_handle* handle; bool isConnected; XBOXONE_STATE controllerState; @@ -16,7 +16,7 @@ struct XboxOneControllerHandler XINPUT_GAMEPAD lastGamepadState; }; -XboxOneControllerHandler *controllerHandler[4] = { NULL, NULL, NULL, NULL }; +XboxOneControllerHandler* controllerHandler[4] = { NULL, NULL, NULL, NULL }; HANDLE XboxOneControllerThread[4] = { 0 }; HANDLE XboxOneControllerMutex[4] = { 0 }; @@ -162,7 +162,18 @@ DWORD WINAPI XInputGetState if (GameDetect::currentGame == GameID::Daytona3) { gamepadState.bRightTrigger = daytonaPressStart ? 0xFF : 0x00; - gamepadState.sThumbLX |= (-(33024 - *ffbOffset2) * 255); + if (*ffbOffset2 < 1) + { + gamepadState.sThumbLX |= 257 - (-(32767 - *ffbOffset2) * 257); + } + else if ((*ffbOffset2 >= 121) && (*ffbOffset2 <= 133)) //Deadzone for FFB + { + gamepadState.sThumbLX == 32768; + } + else + { + gamepadState.sThumbLX |= (-(32768 - *ffbOffset2) * 257); + } } #endif if (pState->dwPacketNumber == UINT_MAX) @@ -414,29 +425,29 @@ LPCWSTR daytonalibName = L"xinput9_1_0.dll"; LPCWSTR ptrToUse; static InitFunction XInputHook([]() -{ - if (GameDetect::currentGame == GameID::PokkenTournament || GameDetect::currentGame == GameID::SchoolOfRagnarok || GameDetect::currentGame == GameID::Daytona3 || GameDetect::currentGame == GameID::GHA || GameDetect::currentGame == GameID::JLeague) { - controllerInit = true; + if (GameDetect::currentGame == GameID::PokkenTournament || GameDetect::currentGame == GameID::SchoolOfRagnarok || GameDetect::currentGame == GameID::Daytona3 || GameDetect::currentGame == GameID::GHA || GameDetect::currentGame == GameID::JLeague) + { + controllerInit = true; - MH_Initialize(); + MH_Initialize(); - if (GameDetect::currentGame == GameID::Daytona3) - ptrToUse = daytonalibName; - else - ptrToUse = libName; + if (GameDetect::currentGame == GameID::Daytona3) + ptrToUse = daytonalibName; + else + ptrToUse = libName; - MH_CreateHookApi(ptrToUse, "XInputGetState", &XInputGetState, NULL); - MH_CreateHookApi(ptrToUse, "XInputSetState", &XInputSetState, NULL); - MH_CreateHookApi(ptrToUse, "XInputGetCapabilities", &XInputGetCapabilities, NULL); - MH_CreateHookApi(ptrToUse, "XInputEnable", &XInputEnable, NULL); - MH_CreateHookApi(ptrToUse, "XInputGetDSoundAudioDeviceGuids", &XInputGetDSoundAudioDeviceGuids, NULL); - MH_CreateHookApi(ptrToUse, "XInputGetBatteryInformation", &XInputGetBatteryInformation, NULL); - MH_CreateHookApi(ptrToUse, "XInputGetKeystroke", &XInputGetKeystroke, NULL); - MH_CreateHookApi(ptrToUse, "XInputGetStateEx", &XInputGetStateEx, NULL); - MH_CreateHookApi(ptrToUse, "XInputSetStateEx", &XInputSetStateEx, NULL); + MH_CreateHookApi(ptrToUse, "XInputGetState", &XInputGetState, NULL); + MH_CreateHookApi(ptrToUse, "XInputSetState", &XInputSetState, NULL); + MH_CreateHookApi(ptrToUse, "XInputGetCapabilities", &XInputGetCapabilities, NULL); + MH_CreateHookApi(ptrToUse, "XInputEnable", &XInputEnable, NULL); + MH_CreateHookApi(ptrToUse, "XInputGetDSoundAudioDeviceGuids", &XInputGetDSoundAudioDeviceGuids, NULL); + MH_CreateHookApi(ptrToUse, "XInputGetBatteryInformation", &XInputGetBatteryInformation, NULL); + MH_CreateHookApi(ptrToUse, "XInputGetKeystroke", &XInputGetKeystroke, NULL); + MH_CreateHookApi(ptrToUse, "XInputGetStateEx", &XInputGetStateEx, NULL); + MH_CreateHookApi(ptrToUse, "XInputSetStateEx", &XInputSetStateEx, NULL); - MH_EnableHook(MH_ALL_HOOKS); - } -}); -#pragma optimize("", on)´ + MH_EnableHook(MH_ALL_HOOKS); + } + }); +#pragma optimize("", on)´ \ No newline at end of file