1
0
mirror of synced 2025-02-08 07:08:17 +01:00

Merge pull request #65 from Boomslangnz/master

Daytona 3 and Xinput Changes
This commit is contained in:
Reaver 2019-11-15 02:12:37 +02:00 committed by GitHub
commit 6e962e60c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 201 additions and 154 deletions

View File

@ -15,15 +15,19 @@ bool daytonaPressStart = false;
uintptr_t imageBase; uintptr_t imageBase;
bool shiftup = false; bool shiftup = false;
bool shiftdown = false; bool shiftdown = false;
static bool viewchange = false;
static bool keybdleft = false;
static bool keybdright = false;
static bool keybdup = false;
void ShiftUp(BYTE shift) void ShiftUp(BYTE shift)
{ {
*(BYTE *)(imageBase + 0x15B468C) = shift + 1; *(BYTE*)(imageBase + 0x15B468C) = shift + 1;
} }
void ShiftDown(BYTE shift) void ShiftDown(BYTE shift)
{ {
*(BYTE *)(imageBase + 0x15B468C) = shift - 1; *(BYTE*)(imageBase + 0x15B468C) = shift - 1;
} }
static void InjectKeys() static void InjectKeys()
@ -35,16 +39,77 @@ static void InjectKeys()
BYTE gas = *ffbOffset3; BYTE gas = *ffbOffset3;
BYTE brake = *ffbOffset4; BYTE brake = *ffbOffset4;
BYTE gamestate = *(BYTE *)(imageBase + 0x15B5744); BYTE gamestate = *(BYTE*)(imageBase + 0x15B5744);
BYTE gear = *(BYTE *)(imageBase + 0x15B468C); BYTE gear = *(BYTE*)(imageBase + 0x15B468C);
BYTE viewread = *(BYTE*)(imageBase + 0x15B5DB0);
*(BYTE *)(imageBase + 0x15B4679) = gas; *(BYTE*)(imageBase + 0x15B4679) = gas;
*(BYTE *)(imageBase + 0x15B467A) = brake; *(BYTE*)(imageBase + 0x15B467A) = brake;
DWORD track = *(DWORD *)(imageBase + 0x011B0148); HWND hWnd = FindWindowA(0, ("Daytona Championship USA"));
//Menu Movement & Game Initial Screen
if (gamestate == 18 || gamestate == 30)
{
if ((wheel <= 0x75) && (wheel > 0x50))
{
//Menu Left
if (!keybdleft)
{
keybdleft = true;
SendMessage(hWnd, WM_KEYDOWN, VK_LEFT, 0);
}
else
{
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
{
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) if (track != 0)
{ {
BYTE track1 = *(BYTE *)(track + 0x4); BYTE track1 = *(BYTE*)(track + 0x4);
#ifdef _DEBUG #ifdef _DEBUG
info(true, "%02X %02X", track1, gamestate); info(true, "%02X %02X", track1, gamestate);
#endif #endif
@ -52,16 +117,16 @@ static void InjectKeys()
{ {
BYTE reverse = wheel * 0xFF; BYTE reverse = wheel * 0xFF;
if (reverse == 0x00) if (reverse == 0x00)
*(BYTE *)(imageBase + 0x15B4678) = 0xFF; *(BYTE*)(imageBase + 0x15B4678) = 0xFF;
else else
*(BYTE *)(imageBase + 0x15B4678) = reverse; *(BYTE*)(imageBase + 0x15B4678) = reverse;
#ifdef _DEBUG #ifdef _DEBUG
info(true, "Reverse wheel"); info(true, "Reverse wheel");
#endif #endif
} }
else else
{ {
*(BYTE *)(imageBase + 0x15B4678) = wheel; *(BYTE*)(imageBase + 0x15B4678) = wheel;
#ifdef _DEBUG #ifdef _DEBUG
info(true, "Normal wheel1"); info(true, "Normal wheel1");
#endif #endif
@ -69,7 +134,7 @@ static void InjectKeys()
} }
else else
{ {
*(BYTE *)(imageBase + 0x15B4678) = wheel; *(BYTE*)(imageBase + 0x15B4678) = wheel;
#ifdef _DEBUG #ifdef _DEBUG
info(true, "Normal wheel2"); info(true, "Normal wheel2");
#endif #endif
@ -84,68 +149,28 @@ static void InjectKeys()
daytonaPressStart = false; 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) if (buttons == 0x01)
{ {
//Inject Start //Inject Start
DWORD p = *(DWORD *)(imageBase + 0x1AB0010); DWORD p = *(DWORD*)(imageBase + 0x1AB0010);
if (p != 0) if (p != 0)
{ {
DWORD p1 = *(DWORD *)(p + 0x00); DWORD p1 = *(DWORD*)(p + 0x00);
if (p1 != 0) if (p1 != 0)
{ {
*(DWORD *)(p1 + 0x08) = 0x01; *(DWORD*)(p1 + 0x08) = 0x01;
} }
} }
} }
else else
{ {
DWORD p = *(DWORD *)(imageBase + 0x1AB0010); DWORD p = *(DWORD*)(imageBase + 0x1AB0010);
if (p != 0) if (p != 0)
{ {
DWORD p1 = *(DWORD *)(p + 0x00); DWORD p1 = *(DWORD*)(p + 0x00);
if (p1 != 0) if (p1 != 0)
{ {
*(DWORD *)(p1 + 0x08) = 0x00; *(DWORD*)(p1 + 0x08) = 0x00;
} }
} }
} }
@ -155,7 +180,7 @@ static void InjectKeys()
if (!shiftup) if (!shiftup)
{ {
shiftup = true; shiftup = true;
ShiftUp(*(BYTE *)(imageBase + 0x15B468C)); ShiftUp(*(BYTE*)(imageBase + 0x15B468C));
} }
} }
else else
@ -168,7 +193,7 @@ static void InjectKeys()
if (!shiftdown) if (!shiftdown)
{ {
shiftdown = true; shiftdown = true;
ShiftDown(*(BYTE *)(imageBase + 0x15B468C)); ShiftDown(*(BYTE*)(imageBase + 0x15B468C));
} }
} }
else else
@ -179,69 +204,80 @@ static void InjectKeys()
if (buttons2 == 0x01) if (buttons2 == 0x01)
{ {
//Gear Change 1 //Gear Change 1
*(BYTE *)(imageBase + 0x15B468C) = 0x00; *(BYTE*)(imageBase + 0x15B468C) = 0x00;
} }
if (buttons2 == 0x02) if (buttons2 == 0x02)
{ {
//Gear Change 2 //Gear Change 2
*(BYTE *)(imageBase + 0x15B468C) = 0x01; *(BYTE*)(imageBase + 0x15B468C) = 0x01;
} }
if (buttons2 == 0x04) if (buttons2 == 0x04)
{ {
//Gear Change 3 //Gear Change 3
*(BYTE *)(imageBase + 0x15B468C) = 0x02; *(BYTE*)(imageBase + 0x15B468C) = 0x02;
} }
if (buttons2 == 0x08) if (buttons2 == 0x08)
{ {
//Gear Change 4 //Gear Change 4
*(BYTE *)(imageBase + 0x15B468C) = 0x03; *(BYTE*)(imageBase + 0x15B468C) = 0x03;
} }
if (ToBool(config["General"]["View Change 1 To Cycle All Views"]))
{
if ((buttons2 == 0x10) && (viewread < 4)) //INCLUDES SPECIAL VIEW
{
//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;
}
}
else
{
if (buttons2 == 0x10) if (buttons2 == 0x10)
{ {
//View Change 1 //View Change 1
{ *(DWORD*)(imageBase + 0x15B5DB0) = 0x00;
*(DWORD *)(imageBase + 0x15B5DB0) = 0x00;
}
} }
if (buttons2 == 0x20) if (buttons2 == 0x20)
{ {
//View Change 2 //View Change 2
{ *(DWORD*)(imageBase + 0x15B5DB0) = 0x01;
*(DWORD *)(imageBase + 0x15B5DB0) = 0x01;
}
} }
if (buttons2 == 0x40) if (buttons2 == 0x40)
{ {
//View Change 3 //View Change 3
{ *(DWORD*)(imageBase + 0x15B5DB0) = 0x02;
*(DWORD *)(imageBase + 0x15B5DB0) = 0x02;
}
} }
if (buttons2 == 0x80) if (buttons2 == 0x80)
{ {
//View Change 4 //View Change 4
{ *(DWORD*)(imageBase + 0x15B5DB0) = 0x03;
*(DWORD *)(imageBase + 0x15B5DB0) = 0x03;
}
}
if (buttons2 == 0xF0)
{
//View Change 5
{
*(DWORD *)(imageBase + 0x15B5DB0) = 0x04;
} }
} }
} }
int(__stdcall *g_origControlsFunction)(); int(__stdcall* g_origControlsFunction)();
int __stdcall ControlsFunction() int __stdcall ControlsFunction()
{ {
@ -251,7 +287,7 @@ int __stdcall ControlsFunction()
} }
static InitFunction Daytona3Func([]() static InitFunction Daytona3Func([]()
{ {
imageBase = (uintptr_t)GetModuleHandleA(0); 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 + 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 + 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);
@ -275,5 +311,5 @@ static InitFunction Daytona3Func([]()
MH_CreateHook((void*)(imageBase + 0x1E9280), ControlsFunction, (void**)&g_origControlsFunction); MH_CreateHook((void*)(imageBase + 0x1E9280), ControlsFunction, (void**)&g_origControlsFunction);
MH_EnableHook(MH_ALL_HOOKS); MH_EnableHook(MH_ALL_HOOKS);
}, GameID::Daytona3); }, GameID::Daytona3);
#endif #endif

View File

@ -6,7 +6,7 @@
struct XboxOneControllerHandler struct XboxOneControllerHandler
{ {
struct usb_dev_handle *handle; struct usb_dev_handle* handle;
bool isConnected; bool isConnected;
XBOXONE_STATE controllerState; XBOXONE_STATE controllerState;
@ -16,7 +16,7 @@ struct XboxOneControllerHandler
XINPUT_GAMEPAD lastGamepadState; XINPUT_GAMEPAD lastGamepadState;
}; };
XboxOneControllerHandler *controllerHandler[4] = { NULL, NULL, NULL, NULL }; XboxOneControllerHandler* controllerHandler[4] = { NULL, NULL, NULL, NULL };
HANDLE XboxOneControllerThread[4] = { 0 }; HANDLE XboxOneControllerThread[4] = { 0 };
HANDLE XboxOneControllerMutex[4] = { 0 }; HANDLE XboxOneControllerMutex[4] = { 0 };
@ -162,7 +162,18 @@ DWORD WINAPI XInputGetState
if (GameDetect::currentGame == GameID::Daytona3) if (GameDetect::currentGame == GameID::Daytona3)
{ {
gamepadState.bRightTrigger = daytonaPressStart ? 0xFF : 0x00; 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 #endif
if (pState->dwPacketNumber == UINT_MAX) if (pState->dwPacketNumber == UINT_MAX)
@ -414,7 +425,7 @@ LPCWSTR daytonalibName = L"xinput9_1_0.dll";
LPCWSTR ptrToUse; LPCWSTR ptrToUse;
static InitFunction XInputHook([]() static InitFunction XInputHook([]()
{ {
if (GameDetect::currentGame == GameID::PokkenTournament || GameDetect::currentGame == GameID::SchoolOfRagnarok || GameDetect::currentGame == GameID::Daytona3 || GameDetect::currentGame == GameID::GHA || GameDetect::currentGame == GameID::JLeague) if (GameDetect::currentGame == GameID::PokkenTournament || GameDetect::currentGame == GameID::SchoolOfRagnarok || GameDetect::currentGame == GameID::Daytona3 || GameDetect::currentGame == GameID::GHA || GameDetect::currentGame == GameID::JLeague)
{ {
controllerInit = true; controllerInit = true;
@ -438,5 +449,5 @@ static InitFunction XInputHook([]()
MH_EnableHook(MH_ALL_HOOKS); MH_EnableHook(MH_ALL_HOOKS);
} }
}); });
#pragma optimize("", on)´ #pragma optimize("", on)´