1
0
mirror of synced 2025-02-22 12:50:25 +01:00

103 lines
2.7 KiB
C++
Raw Normal View History

/*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/>.
*/
#include <string>
2023-03-25 23:14:46 +13:00
#include "GRIDReal.h"
#include "SDL.h"
2023-04-07 08:10:00 +12:00
#include <Xinput.h>
2023-03-11 15:55:48 +13:00
static EffectTriggers* myTriggers;
static EffectConstants* myConstants;
static Helpers* myHelpers;
2023-03-11 15:55:48 +13:00
extern int EnableDamper;
extern int DamperStrength;
2023-04-07 08:10:00 +12:00
extern int FFBOrRumble;
2019-11-02 09:34:33 +13:00
2023-03-11 15:55:48 +13:00
static bool init;
2023-03-11 15:55:48 +13:00
static int FFBCounter;
2023-03-11 15:55:48 +13:00
static int(__stdcall* Out32Ori)(DWORD device, DWORD data);
static int __stdcall Out32Hook(DWORD device, DWORD data)
{
2023-04-07 10:43:30 +12:00
if (FFBOrRumble)
return 0;
2023-03-12 12:37:03 +13:00
if (device == 0x1020)
2023-03-11 15:55:48 +13:00
{
2023-03-12 12:37:03 +13:00
++FFBCounter;
2023-03-12 12:37:03 +13:00
if (FFBCounter == 5)
2023-03-12 12:10:42 +13:00
{
2023-03-12 12:37:03 +13:00
FFBCounter = 0;
if (data > 15)
{
double percentForce = (31 - data) / 15.0;
double percentLength = 100;
myTriggers->Rumble(percentForce, 0, percentLength);
myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce);
}
else if (data > 0)
{
double percentForce = (16 - data) / 15.0;
double percentLength = 100;
myTriggers->Rumble(0, percentForce, percentLength);
myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce);
}
2023-03-11 15:55:48 +13:00
}
2019-10-28 22:24:26 +13:00
}
2023-04-07 10:43:30 +12:00
return 0;
2023-03-11 15:55:48 +13:00
}
2023-03-17 23:56:00 +13:00
static int(__fastcall* EnableFFBOri)(int a1, double a2);
static int __fastcall EnableFFBHook(int a1, double a2)
{
EnableFFBOri(a1, a2);
2023-04-07 08:10:00 +12:00
*(BYTE*)(a1 + 92) = 1; // FFB
if (FFBOrRumble)
*(BYTE*)(a1 + 12) = 1; // Rumble
2023-03-17 23:56:00 +13:00
return 0;
}
2023-04-07 08:10:00 +12:00
static DWORD WINAPI XInputSetStateGRID(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration)
{
myTriggers->Rumble(pVibration->wLeftMotorSpeed / 65535.0, pVibration->wRightMotorSpeed / 65535.0, 100.0);
return ERROR_SUCCESS;
}
2023-03-25 23:14:46 +13:00
void GRIDReal::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers* triggers) {
2023-03-11 15:55:48 +13:00
if (!init)
2019-11-02 09:34:33 +13:00
{
2023-03-11 15:55:48 +13:00
init = true;
2023-03-12 09:20:48 +13:00
DWORD ImageBase = (DWORD)GetModuleHandleA(0);
MH_Initialize();
2023-03-17 23:56:00 +13:00
MH_CreateHook((void*)(ImageBase + 0x79CDE0), EnableFFBHook, (void**)&EnableFFBOri);
2023-04-07 10:43:30 +12:00
MH_CreateHookApi(L"inpout32.dll", "Out32", Out32Hook, (void**)&Out32Ori);
if (FFBOrRumble)
2023-04-07 08:10:00 +12:00
MH_CreateHookApi(L"xinput1_3.dll", "XInputSetState", &XInputSetStateGRID, NULL);
2023-03-12 09:20:48 +13:00
MH_EnableHook(MH_ALL_HOOKS);
}
2023-03-11 15:55:48 +13:00
2019-11-02 09:34:33 +13:00
myTriggers = triggers;
myConstants = constants;
myHelpers = helpers;
}