1
0
mirror of synced 2025-02-01 12:17:55 +01:00

Merge pull request #12 from Boomslangnz/master

Fixed game crash with no controller connected
This commit is contained in:
Reaver 2018-11-03 15:31:43 +02:00 committed by GitHub
commit 1148385c7d
3 changed files with 632 additions and 603 deletions

View File

@ -1,4 +1,4 @@
#include <StdInc.h>
#include <StdInc.h>
#include "Utility/InitFunction.h"
#include "Functions/Global.h"
#include "Utility\Hooking.Patterns.h"
@ -11,6 +11,7 @@ extern int* ffbOffset;
extern int* ffbOffset2;
extern int* ffbOffset3;
extern int* ffbOffset4;
bool daytonaPressStart = false;
uintptr_t imageBase;
bool shiftup = false;
bool shiftdown = false;
@ -27,81 +28,99 @@ void ShiftDown(BYTE shift)
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 + 0x1228C78);
DWORD track = *(DWORD *)(imageBase + 0x011B0148);
if (track != 0)
{
BYTE track1 = *(BYTE *)(track + 0x4);
#ifdef _DEBUG
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;
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");
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 wheel1");
info(true, "Normal wheel2");
#endif
}
if (gas >= 0x40)
{
daytonaPressStart = true;
}
else
{
*(BYTE *)(imageBase + 0x15B4678) = wheel;
#ifdef _DEBUG
info(true, "Normal wheel2");
#endif
daytonaPressStart = false;
}
if(wheel <= 0x40)
if (wheel <= 0x40)
{
//Menu Left
DWORD p = *(DWORD *)(imageBase + 0x1AAFFF0);
DWORD p1 = *(DWORD *)(p + 0x00);
if (p != 0)
{
*(BYTE *)(p1 + 0x25) = 0xFF;
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
{
*(BYTE *)(p1 + 0x25) = 0xFF;
}
}
}
else if(wheel >= 0xC0)
else if (wheel >= 0xC0)
{
//Menu Right
DWORD p = *(DWORD *)(imageBase + 0x1AAFFF0);
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
if (p != 0)
{
*(BYTE *)(p1 + 0x27) = 0xFF;
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
{
*(BYTE *)(p1 + 0x27) = 0xFF;
}
}
}
else
{
DWORD p = *(DWORD *)(imageBase + 0x1AAFFF0);
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
if (p != 0)
{
*(BYTE *)(p1 + 0x25) = 0x00;
*(BYTE *)(p1 + 0x27) = 0x00;
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
{
*(BYTE *)(p1 + 0x25) = 0x00;
*(BYTE *)(p1 + 0x27) = 0x00;
}
}
}
@ -109,19 +128,25 @@ static void InjectKeys()
{
//Inject Start
DWORD p = *(DWORD *)(imageBase + 0x1AB0010);
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
if (p != 0)
{
*(DWORD *)(p1 + 0x08) = 0x01;
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
{
*(DWORD *)(p1 + 0x08) = 0x01;
}
}
}
else
{
DWORD p = *(DWORD *)(imageBase + 0x1AB0010);
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
if (p != 0)
{
*(DWORD *)(p1 + 0x08) = 0x00;
DWORD p1 = *(DWORD *)(p + 0x00);
if (p1 != 0)
{
*(DWORD *)(p1 + 0x08) = 0x00;
}
}
}
@ -138,7 +163,7 @@ static void InjectKeys()
shiftup = false;
}
if ((buttons == 0x04) && (gear > 0x00)) //crashes right now
if ((buttons == 0x04) && (gear > 0x00))
{
if (!shiftdown)
{
@ -227,15 +252,19 @@ 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::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);
}
MH_Initialize();
MH_CreateHook((void*)(imageBase + 0x1E9280), ControlsFunction, (void**)&g_origControlsFunction);
MH_EnableHook(MH_ALL_HOOKS);

View File

@ -23,8 +23,6 @@ HANDLE XboxOneControllerMutex[4] = { 0 };
static unsigned short idVendor = 0x045E;
static unsigned short idProduct = 0x02D1;
static bool daytonaPressStart = false;
int configuration = 1;
int interface = 0;
int endpointIn = 0x81;
@ -356,4 +354,4 @@ static InitFunction XInputHook([]()
MH_EnableHook(MH_ALL_HOOKS);
}
});
#pragma optimize("", on)
#pragma optimize("", on)´

View File

@ -150,3 +150,5 @@ typedef struct _XINPUT_KEYSTROKE
BYTE UserIndex;
BYTE HidCode;
} XINPUT_KEYSTROKE, *PXINPUT_KEYSTROKE;
extern bool daytonaPressStart;