2019-09-14 03:13:05 +02:00
|
|
|
/*This file is part of FFB Arcade Plugin.
|
|
|
|
FFB Arcade Plugin is free software : you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
FFB Arcade Plugin is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FFB Arcade Plugin.If not, see < https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-07 07:16:19 +02:00
|
|
|
#include <string>
|
|
|
|
#include "Daytona3.h"
|
|
|
|
#include "SDL.h"
|
|
|
|
#include <Windows.h>
|
2019-10-26 07:49:14 +02:00
|
|
|
static bool keybdleft = false;
|
|
|
|
static bool keybdright = false;
|
|
|
|
static bool keybdup = false;
|
2019-11-02 02:11:34 +01:00
|
|
|
static bool init = false;
|
2021-02-20 09:34:03 +01:00
|
|
|
extern int EnableDamper;
|
|
|
|
extern int DamperStrength;
|
2019-05-15 09:25:41 +02:00
|
|
|
static EffectTriggers *myTriggers;
|
|
|
|
static EffectConstants *myConstants;
|
|
|
|
static Helpers *myHelpers;
|
2020-08-01 06:11:15 +02:00
|
|
|
extern SDL_Event e;
|
2019-05-15 09:25:41 +02:00
|
|
|
static wchar_t *settingsFilename = TEXT(".\\FFBPlugin.ini");
|
|
|
|
static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename);
|
|
|
|
static int ChangeGearsViaPlugin = GetPrivateProfileInt(TEXT("Settings"), TEXT("ChangeGearsViaPlugin"), 0, settingsFilename);
|
|
|
|
static int EscapeKeyExitViaPlugin = GetPrivateProfileInt(TEXT("Settings"), TEXT("EscapeKeyExitViaPlugin"), 0, settingsFilename);
|
|
|
|
static int MenuMovementViaPlugin = GetPrivateProfileInt(TEXT("Settings"), TEXT("MenuMovementViaPlugin"), 0, settingsFilename);
|
|
|
|
static int Gear1 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear1"), 0, settingsFilename);
|
|
|
|
static int Gear2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear2"), 0, settingsFilename);
|
|
|
|
static int Gear3 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear3"), 0, settingsFilename);
|
|
|
|
static int Gear4 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear4"), 0, settingsFilename);
|
|
|
|
static int GearUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("GearUp"), 0, settingsFilename);
|
|
|
|
static int GearDown = GetPrivateProfileInt(TEXT("Settings"), TEXT("GearDown"), 0, settingsFilename);
|
|
|
|
static int HideCursor = GetPrivateProfileInt(TEXT("Settings"), TEXT("HideCursor"), 0, settingsFilename);
|
|
|
|
|
2019-12-18 01:41:02 +01:00
|
|
|
static int ThreadLoop()
|
|
|
|
{
|
|
|
|
while (SDL_WaitEvent(&e) != 0)
|
|
|
|
{
|
|
|
|
UINT8 gear = myHelpers->ReadByte(0x019B468C, /* isRelativeOffset */ false);
|
2019-05-15 09:25:41 +02:00
|
|
|
|
2019-12-18 01:41:02 +01:00
|
|
|
if (ShowButtonNumbersForSetup == 1)
|
|
|
|
{
|
|
|
|
if (e.type == SDL_JOYBUTTONDOWN)
|
2019-05-15 09:25:41 +02:00
|
|
|
{
|
2019-12-18 01:41:02 +01:00
|
|
|
if (e.jbutton.button >= 0)
|
2019-11-02 02:11:34 +01:00
|
|
|
{
|
2019-12-18 01:41:02 +01:00
|
|
|
char buff[100];
|
|
|
|
sprintf_s(buff, "Button %d Pressed", e.jbutton.button);
|
|
|
|
MessageBoxA(NULL, buff, "", NULL);
|
2019-11-02 02:11:34 +01:00
|
|
|
}
|
2019-05-15 09:25:41 +02:00
|
|
|
}
|
2019-12-18 01:41:02 +01:00
|
|
|
}
|
2019-05-15 09:25:41 +02:00
|
|
|
|
2019-12-18 01:41:02 +01:00
|
|
|
if (e.type == SDL_JOYBUTTONDOWN)
|
|
|
|
{
|
2023-03-10 08:34:30 +01:00
|
|
|
if (ChangeGearsViaPlugin)
|
2019-10-26 07:49:14 +02:00
|
|
|
{
|
2019-12-18 01:41:02 +01:00
|
|
|
if (e.jbutton.button == Gear1)
|
|
|
|
{
|
|
|
|
myHelpers->WriteByte(0x019B468C, 0x00, false);
|
|
|
|
}
|
|
|
|
else if (e.jbutton.button == Gear2)
|
|
|
|
{
|
|
|
|
myHelpers->WriteByte(0x019B468C, 0x02, false);
|
|
|
|
}
|
|
|
|
else if (e.jbutton.button == Gear3)
|
2019-10-26 07:49:14 +02:00
|
|
|
{
|
2019-12-18 01:41:02 +01:00
|
|
|
myHelpers->WriteByte(0x019B468C, 0x01, false);
|
|
|
|
}
|
|
|
|
else if (e.jbutton.button == Gear4)
|
|
|
|
{
|
|
|
|
myHelpers->WriteByte(0x019B468C, 0x03, false);
|
|
|
|
}
|
2023-03-10 08:34:30 +01:00
|
|
|
else if (e.jbutton.button == GearDown && gear > 0x00)
|
2019-12-18 01:41:02 +01:00
|
|
|
{
|
|
|
|
myHelpers->WriteByte(0x019B468C, --gear, false);
|
|
|
|
}
|
2023-03-10 08:34:30 +01:00
|
|
|
else if (e.jbutton.button == GearUp && gear < 0x03)
|
2019-12-18 01:41:02 +01:00
|
|
|
{
|
|
|
|
myHelpers->WriteByte(0x019B468C, ++gear, false);
|
2019-10-26 07:49:14 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 09:25:41 +02:00
|
|
|
}
|
2019-12-18 01:41:02 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI RunningLoop(LPVOID lpParam)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
ThreadLoop();
|
|
|
|
Sleep(16);
|
|
|
|
}
|
2019-05-15 09:25:41 +02:00
|
|
|
}
|
2019-04-07 07:16:19 +02:00
|
|
|
|
2019-11-02 02:11:34 +01:00
|
|
|
void Daytona3::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers* triggers) {
|
|
|
|
|
|
|
|
if (!init)
|
|
|
|
{
|
2019-05-15 09:25:41 +02:00
|
|
|
myTriggers = triggers;
|
|
|
|
myConstants = constants;
|
|
|
|
myHelpers = helpers;
|
2019-12-18 01:41:02 +01:00
|
|
|
CreateThread(NULL, 0, RunningLoop, NULL, 0, NULL);
|
2019-11-02 02:11:34 +01:00
|
|
|
init = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT8 steering = helpers->ReadByte(0x019B4678, false);
|
|
|
|
UINT8 gamestate = helpers->ReadByte(0x19B5744, false);
|
|
|
|
UINT8 ff = helpers->ReadByte(0x15AFC46, false);
|
|
|
|
HWND hWnd = FindWindowA(0, ("Daytona Championship USA"));
|
|
|
|
|
2023-03-10 08:34:30 +01:00
|
|
|
if (HideCursor)
|
2019-11-02 02:11:34 +01:00
|
|
|
SetCursorPos(2000, 2000);
|
2019-09-27 22:23:02 +02:00
|
|
|
|
2023-03-10 08:34:30 +01:00
|
|
|
if (GetAsyncKeyState(VK_ESCAPE) && EscapeKeyExitViaPlugin)
|
2019-11-02 02:11:34 +01:00
|
|
|
{
|
|
|
|
if (hWnd > NULL)
|
2019-04-07 07:16:19 +02:00
|
|
|
{
|
2019-11-02 02:11:34 +01:00
|
|
|
//SendMessage(hWnd, WM_CLOSE, NULL, NULL);
|
|
|
|
system("taskkill /f /im InpWrapper.exe");
|
2020-01-05 10:21:12 +01:00
|
|
|
ExitProcess(0);
|
2019-11-02 02:11:34 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-27 22:23:02 +02:00
|
|
|
|
2019-11-02 02:11:34 +01:00
|
|
|
if (MenuMovementViaPlugin == 1)
|
|
|
|
{
|
|
|
|
//Menu Movement & Game Initial Screen
|
|
|
|
if (gamestate == 18 || gamestate == 30)
|
2019-04-07 07:16:19 +02:00
|
|
|
{
|
2023-03-10 08:34:30 +01:00
|
|
|
if (steering <= 0x75 && steering > 0x50)
|
2019-04-07 07:16:19 +02:00
|
|
|
{
|
2019-11-02 02:11:34 +01:00
|
|
|
//Menu Left
|
|
|
|
if (!keybdleft)
|
2019-04-07 07:16:19 +02:00
|
|
|
{
|
2019-11-02 02:11:34 +01:00
|
|
|
keybdleft = true;
|
|
|
|
SendMessage(hWnd, WM_KEYDOWN, VK_LEFT, 0);
|
2019-04-07 07:16:19 +02:00
|
|
|
}
|
2019-11-02 02:11:34 +01:00
|
|
|
else
|
2019-04-07 07:16:19 +02:00
|
|
|
{
|
2019-11-02 02:11:34 +01:00
|
|
|
SendMessage(hWnd, WM_KEYUP, VK_LEFT, 0);
|
2019-04-07 07:16:19 +02:00
|
|
|
}
|
2019-11-02 02:11:34 +01:00
|
|
|
}
|
|
|
|
else if (steering <= 0x50)
|
|
|
|
{
|
|
|
|
SendMessage(hWnd, WM_KEYDOWN, VK_LEFT, 0);
|
|
|
|
}
|
|
|
|
else if ((steering >= 0x89) && (steering < 0xAE))
|
|
|
|
{
|
|
|
|
//Menu Right
|
|
|
|
if (!keybdright)
|
2019-04-07 07:16:19 +02:00
|
|
|
{
|
2019-11-02 02:11:34 +01:00
|
|
|
keybdright = true;
|
|
|
|
SendMessage(hWnd, WM_KEYDOWN, VK_RIGHT, 0);
|
2019-04-07 07:16:19 +02:00
|
|
|
}
|
2019-11-02 02:11:34 +01:00
|
|
|
else
|
2019-04-07 07:16:19 +02:00
|
|
|
{
|
2019-11-02 02:11:34 +01:00
|
|
|
SendMessage(hWnd, WM_KEYUP, VK_RIGHT, 0);
|
2019-04-07 07:16:19 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-02 02:11:34 +01:00
|
|
|
else if (steering >= 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);
|
|
|
|
}
|
2019-04-07 07:16:19 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-02 02:11:34 +01:00
|
|
|
|
2023-03-10 08:34:30 +01:00
|
|
|
if (EnableDamper)
|
2021-02-20 09:34:03 +01:00
|
|
|
triggers->Damper(DamperStrength / 100.0);
|
|
|
|
|
2019-11-02 02:11:34 +01:00
|
|
|
if (ff > 15)
|
|
|
|
{
|
|
|
|
double percentForce = (31 - ff) / 15.0;
|
|
|
|
double percentLength = 100;
|
|
|
|
triggers->Rumble(percentForce, 0, percentLength);
|
|
|
|
triggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce);
|
|
|
|
}
|
|
|
|
else if (ff > 0)
|
|
|
|
{
|
|
|
|
double percentForce = (16 - ff) / 15.0;
|
|
|
|
double percentLength = 100;
|
|
|
|
triggers->Rumble(0, percentForce, percentLength);
|
|
|
|
triggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce);
|
|
|
|
}
|
2023-03-10 08:34:30 +01:00
|
|
|
|
2019-11-02 02:11:34 +01:00
|
|
|
myTriggers = triggers;
|
|
|
|
myConstants = constants;
|
|
|
|
myHelpers = helpers;
|
2019-05-15 09:25:41 +02:00
|
|
|
}
|