1
0
mirror of synced 2025-01-20 09:42:49 +01:00

Add Cubic Scaled Deadband option to Daytona Championship USA

hopefully help sensitivity with controllers

Credit
http://www.mimirgames.com/articles/games/joystick-input-and-using-deadbands/
This commit is contained in:
Aaron M 2020-12-31 15:51:46 +13:00
parent 0fe76287fd
commit 42ad314538

View File

@ -20,6 +20,26 @@ static bool keybdleft = false;
static bool keybdright = false; static bool keybdright = false;
static bool keybdup = false; static bool keybdup = false;
float Cubic(const float x, const float weight)
{
return weight * x * x * x + (1.0 - weight) * x;
}
float joystickCubicScaledDeadband(const float x)
{
const float deadbandCutoff = 0.2f;
const float weight = 0.5f;
if (fabs(x) < deadbandCutoff)
{
return 0;
}
else
{
return (Cubic(x, weight) - (fabs(x) / x) * Cubic(deadbandCutoff, weight)) / (1.0 - Cubic(deadbandCutoff, weight));
}
}
void ShiftUp(BYTE shift) void ShiftUp(BYTE shift)
{ {
*(BYTE*)(imageBase + 0x15B468C) = shift + 1; *(BYTE*)(imageBase + 0x15B468C) = shift + 1;
@ -30,9 +50,8 @@ void ShiftDown(BYTE shift)
*(BYTE*)(imageBase + 0x15B468C) = shift - 1; *(BYTE*)(imageBase + 0x15B468C) = shift - 1;
} }
static void InjectKeys() static int ThreadLoop()
{ {
DWORD buttons2 = *wheelSection; DWORD buttons2 = *wheelSection;
DWORD buttons = *ffbOffset; DWORD buttons = *ffbOffset;
BYTE wheel = *ffbOffset2; BYTE wheel = *ffbOffset2;
@ -48,6 +67,15 @@ static void InjectKeys()
HWND hWnd = FindWindowA(0, ("Daytona Championship USA")); HWND hWnd = FindWindowA(0, ("Daytona Championship USA"));
if (ToBool(config["General"]["Cubic Scaled Deadband"]))
{
float joycubicdeadband = joystickCubicScaledDeadband((*ffbOffset2 - 128) / 128.0);
wheel = 128 + (joycubicdeadband * 128.0);
if (wheel >= 251)
wheel = 255;
}
//Menu Movement & Game Initial Screen //Menu Movement & Game Initial Screen
if (gamestate == 18 || gamestate == 30) if (gamestate == 18 || gamestate == 30)
{ {
@ -277,13 +305,13 @@ static void InjectKeys()
} }
} }
int(__stdcall* g_origControlsFunction)(); static DWORD WINAPI RunningLoop(LPVOID lpParam)
int __stdcall ControlsFunction()
{ {
int result = g_origControlsFunction(); while (true)
InjectKeys(); {
return result; ThreadLoop();
Sleep(16);
}
} }
static InitFunction Daytona3Func([]() static InitFunction Daytona3Func([]()
@ -299,17 +327,18 @@ static InitFunction Daytona3Func([]()
injector::MakeNOP(imageBase + 0x1DE10D, 6); injector::MakeNOP(imageBase + 0x1DE10D, 6);
injector::MakeNOP(imageBase + 0x29B481, 3); injector::MakeNOP(imageBase + 0x29B481, 3);
injector::MakeNOP(imageBase + 0x29B513, 4); injector::MakeNOP(imageBase + 0x29B513, 4);
if (ToBool(config["General"]["MSAA4X Disable"])) if (ToBool(config["General"]["MSAA4X Disable"]))
{ {
injector::WriteMemoryRaw(imageBase + 0x17CD3D, "\x00", 1, true); injector::WriteMemoryRaw(imageBase + 0x17CD3D, "\x00", 1, true);
} }
if (ToBool(config["General"]["Hide Cursor"])) if (ToBool(config["General"]["Hide Cursor"]))
{ {
SetCursorPos(20000, 20000); SetCursorPos(20000, 20000);
} }
MH_Initialize();
MH_CreateHook((void*)(imageBase + 0x1E9280), ControlsFunction, (void**)&g_origControlsFunction); CreateThread(NULL, 0, RunningLoop, NULL, 0, NULL);
MH_EnableHook(MH_ALL_HOOKS);
}, GameID::Daytona3); }, GameID::Daytona3);
#endif #endif