1
0
mirror of synced 2025-01-19 15:48:40 +01:00

Added gear change and wheel spin FFB effects and various cheats to WMMT5

This commit is contained in:
pinkimo 2019-10-28 00:09:17 +01:00
parent 66bd2437c7
commit 388b54ed20
2 changed files with 229 additions and 38 deletions

View File

@ -282,7 +282,18 @@ JointsAndStripesStrength=100
CollisionsStrength=100
TiresSlipStrength=100
HighSpeedVibrationsStrength=100
GearChangeStrength=20
GearChangeDelay=250
GearChangeLength=200
WheelSpinStrength=100
LimitBetweenHighSpeedVibrationsAndTiresSlip=75
ShowButtonNumbersForSetup=0
ForceFullTune=0
DisableRaceTimer=0
EnableForceFinish=0
EnableForceTimeUp=0
ForceFinishButton=99
ForceTimeUpButton=99
[Mame 0199 32bit]
GameId=34

View File

@ -13,33 +13,139 @@ along with FFB Arcade Plugin.If not, see < https://www.gnu.org/licenses/>.
#include <string>
#include "WMMT5.h"
#include <Windows.h>
#include "SDL.h"
bool gameFfbStarted = false;
wchar_t* settingsWMMT5 = TEXT(".\\FFBPlugin.ini");
int SpringStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("SpringStrength"), 0, settingsWMMT5);
int FrictionStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("FrictionStrength"), 0, settingsWMMT5);
int JointsAndStripesStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("JointsAndStripesStrength"), 0, settingsWMMT5);
int CollisionsStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CollisionsStrength"), 0, settingsWMMT5);
int TiresSlipStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TiresSlipStrength"), 0, settingsWMMT5);
int HighSpeedVibrationsStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("HighSpeedVibrationsStrength"), 0, settingsWMMT5);
int LimitBetweenHighSpeedVibrationsAndTiresSlipWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("LimitBetweenHighSpeedVibrationsAndTiresSlip"), 0, settingsWMMT5);
static EffectTriggers* myTriggers;
static EffectConstants* myConstants;
static Helpers* myHelpers;
static SDL_Event e;
static UINT8 oldgear = 0;
static bool init = false;
static bool gameFfbStarted = false;
static wchar_t* settingsFilename = TEXT(".\\FFBPlugin.ini");
static int SpringStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("SpringStrength"), 100, settingsFilename);
static int FrictionStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("FrictionStrength"), 0, settingsFilename);
static int JointsAndStripesStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("JointsAndStripesStrength"), 100, settingsFilename);
static int CollisionsStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("CollisionsStrength"), 100, settingsFilename);
static int TiresSlipStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("TiresSlipStrength"), 100, settingsFilename);
static int HighSpeedVibrationsStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("HighSpeedVibrationsStrength"), 100, settingsFilename);
static int LimitBetweenHighSpeedVibrationsAndTiresSlip = GetPrivateProfileInt(TEXT("Settings"), TEXT("LimitBetweenHighSpeedVibrationsAndTiresSlip"), 75, settingsFilename);
static int GearChangeStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("GearChangeStrength"), 20, settingsFilename);
static int GearChangeDelay = GetPrivateProfileInt(TEXT("Settings"), TEXT("GearChangeDelay"), 250, settingsFilename);
static int GearChangeLength = GetPrivateProfileInt(TEXT("Settings"), TEXT("GearChangeLength"), 200, settingsFilename);
static int WheelSpinStrength = GetPrivateProfileInt(TEXT("Settings"), TEXT("WheelSpinStrength"), 100, settingsFilename);
static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename);
static int ForceFullTune = GetPrivateProfileInt(TEXT("Settings"), TEXT("ForceFullTune"), 0, settingsFilename);
static int DisableRaceTimer = GetPrivateProfileInt(TEXT("Settings"), TEXT("DisableRaceTimer"), 0, settingsFilename);
static int EnableForceFinish = GetPrivateProfileInt(TEXT("Settings"), TEXT("EnableForceFinish"), 0, settingsFilename);
static int EnableForceTimeUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("EnableForceTimeUp"), 0, settingsFilename);
static int ForceFinishButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ForceFinishButton"), 99, settingsFilename);
static int ForceTimeUpButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ForceTimeUpButton"), 99, settingsFilename);
void WMMT5::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers* triggers) {
static int InputThread(void *ptr)
{
myHelpers->log("starting input thread");
while (SDL_WaitEvent(&e) != 0)
{
if (e.type == SDL_JOYBUTTONDOWN)
{
myHelpers->log("button pressed");
if (1 == ShowButtonNumbersForSetup && e.jbutton.button >= 0)
{
char buff[100];
sprintf_s(buff, "Button %d Pressed", e.jbutton.button);
MessageBoxA(NULL, buff, "", NULL);
}
float spring = helpers->ReadFloat32(0x196F18C, /* isRelativeOffset*/ true);
float friction = helpers->ReadFloat32(0x196F190, /* isRelativeOffset*/ true);
float collisions = helpers->ReadFloat32(0x196F194, /* isRelativeOffset*/ true);
float tiresSlip = helpers->ReadFloat32(0x196F188, /* isRelativeOffset*/ true);
helpers->log("got value: ");
std::string ffs = "spring: " + std::to_string(spring);
helpers->log((char*)ffs.c_str());
ffs = "friction: " + std::to_string(friction);
helpers->log((char*)ffs.c_str());
ffs = "collisions: " + std::to_string(collisions);
helpers->log((char*)ffs.c_str());
ffs = "tires slip: " + std::to_string(tiresSlip);
helpers->log((char*)ffs.c_str());
if (1 == EnableForceFinish && e.jbutton.button == ForceFinishButton)
{
INT_PTR ptr1 = myHelpers->ReadIntPtr(0x199A468, true);
myHelpers->WriteByte(ptr1 + 0x28, 8, false);
}
else if (1 == EnableForceTimeUp && e.jbutton.button == ForceTimeUpButton)
{
int tempDisableRaceTimer = DisableRaceTimer;
DisableRaceTimer = 0;
myHelpers->WriteFloat32(0x199AE18, 0, true);
if (1 == tempDisableRaceTimer)
{
Sleep(10000);
DisableRaceTimer = tempDisableRaceTimer;
}
}
}
}
myHelpers->log("input thread stopped");
return 0;
}
static int SpamThread(void* ptr)
{
if (1 != ForceFullTune && 1 != DisableRaceTimer)
{
return 0;
}
Sleep(5000); // To avoid crashes
myHelpers->log("starting spam thread");
while (1)
{
if (1 == ForceFullTune)
{
INT_PTR ptr1 = myHelpers->ReadIntPtr(0x1948F10, true);
INT_PTR ptr2 = myHelpers->ReadIntPtr(ptr1 + 0x180 + 0xa8 + 0x18, false);
UINT8 car = myHelpers->ReadByte(ptr2 + 0x2C, false);
std::string msg = "car: " + std::to_string(car);
myHelpers->log((char*)msg.c_str());
if (0x00 < car)
{
UINT8 power = myHelpers->ReadByte(ptr2 + 0x98, false);
UINT8 handling = myHelpers->ReadByte(ptr2 + 0x9C, false);
msg = "power: " + std::to_string(power) + " | handling: " + std::to_string(handling);
myHelpers->log((char*)msg.c_str());
if (0x20 != (power + handling))
{
myHelpers->log("forcing full tune");
myHelpers->WriteByte(ptr2 + 0x98, 0x10, false);
myHelpers->WriteByte(ptr2 + 0x9C, 0x10, false);
}
}
}
if (1 == DisableRaceTimer)
{
myHelpers->WriteFloat32(0x199AE18, 999.99, true);
}
Sleep(500); // We don't need to spam too much
}
myHelpers->log("spam thread stopped");
return 0;
}
void WMMT5::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers* triggers) {
if (!init)
{
init = true;
myTriggers = triggers;
myConstants = constants;
myHelpers = helpers;
SDL_Thread* inputThread = SDL_CreateThread(InputThread, "InputThread", (void*)NULL);
SDL_Thread* spamThread = SDL_CreateThread(SpamThread, "SpamThread", (void*)NULL);
}
float spring = helpers->ReadFloat32(0x196F18C, true);
float friction = helpers->ReadFloat32(0x196F190, true);
float collisions = helpers->ReadFloat32(0x196F194, true);
float tiresSlip = helpers->ReadFloat32(0x196F188, true);
int speed = helpers->ReadInt32(0x196FEBC, true);
std::string msg = "spring: " + std::to_string(spring) + " | friction: " + std::to_string(friction)
+ " | collisions: " + std::to_string(collisions) + " | tires slip: " + std::to_string(tiresSlip)
+ " | speed: " + std::to_string(speed);
helpers->log((char*)msg.c_str());
double percentForce;
if (0 < spring)
@ -49,20 +155,20 @@ void WMMT5::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers
helpers->log("game's FFB started");
gameFfbStarted = true;
}
percentForce = (1.0 * spring) * SpringStrengthWMMT5 / 100.0;
percentForce = (1.0 * spring) * SpringStrength / 100.0;
triggers->Spring(percentForce);
}
else if (!gameFfbStarted)
{
helpers->log("fake spring/friction until game's FFB starts");
percentForce = 0.4 * SpringStrengthWMMT5 / 100.0;
percentForce = 0.3 * SpringStrength / 100.0;
triggers->Spring(percentForce);
percentForce = 0.5 * FrictionStrengthWMMT5 / 100.0;
percentForce = 0.5 * FrictionStrength / 100.0;
triggers->Friction(percentForce);
}
if (0 < friction)
{
percentForce = (1.0 * friction) * FrictionStrengthWMMT5 / 100.0;
percentForce = (1.0 * friction) * FrictionStrength / 100.0;
triggers->Friction(percentForce);
}
if (0 < collisions)
@ -70,14 +176,14 @@ void WMMT5::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers
if (0.209 <= collisions && 0.311 >= collisions)
{
helpers->log("joint/stripe on the right");
percentForce = (1.0 * collisions) * JointsAndStripesStrengthWMMT5 / 100.0;
percentForce = (1.0 * collisions) * JointsAndStripesStrength / 100.0;
triggers->Sine(80, 80, percentForce);
triggers->LeftRight(0, percentForce, 150);
}
else
{
helpers->log("collision on the right");
percentForce = (1.0 * collisions) * CollisionsStrengthWMMT5 / 100.0;
percentForce = (1.0 * collisions) * CollisionsStrength / 100.0;
triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce);
triggers->LeftRight(0, percentForce, 150);
}
@ -87,14 +193,14 @@ void WMMT5::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers
if (-0.209 >= collisions && -0.311 <= collisions)
{
helpers->log("joint/stripe on the left");
percentForce = (1.0 * collisions) * JointsAndStripesStrengthWMMT5 / 100.0;
percentForce = (1.0 * collisions) * JointsAndStripesStrength / 100.0;
triggers->Sine(80, 80, percentForce);
triggers->LeftRight(0, -1.0 * percentForce, 150);
}
else
{
helpers->log("collision on the left");
percentForce = (-1.0 * collisions) * CollisionsStrengthWMMT5 / 100.0;
percentForce = (-1.0 * collisions) * CollisionsStrength / 100.0;
triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce);
triggers->LeftRight(0, percentForce, 150);
}
@ -103,11 +209,11 @@ void WMMT5::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers
if (0 < tiresSlip)
{
helpers->log("tires slip left");
bool highSpeedVibrations = (1.0 * tiresSlip) < (LimitBetweenHighSpeedVibrationsAndTiresSlipWMMT5 / 1000.0);
percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighSpeedVibrationsStrengthWMMT5 : TiresSlipStrengthWMMT5) / 100.0;
bool highSpeedVibrations = (294 <= speed) && (1.0 * tiresSlip) < (LimitBetweenHighSpeedVibrationsAndTiresSlip / 1000.0);
percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighSpeedVibrationsStrength : TiresSlipStrength) / 100.0;
triggers->Sine(100, 100, percentForce);
if (!highSpeedVibrations && ((0 == JointsAndStripesStrengthWMMT5 && 0 == CollisionsStrengthWMMT5) || (0.001 > collisions && -0.001 < collisions)))
if (!highSpeedVibrations && ((0 == JointsAndStripesStrength && 0 == CollisionsStrength) || (0.001 > collisions && -0.001 < collisions)))
{
triggers->LeftRight(0, -1.0 * percentForce, 150);
}
@ -115,13 +221,87 @@ void WMMT5::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers
else if (0 > tiresSlip)
{
helpers->log("tires slip right");
bool highSpeedVibrations = (-1.0 * tiresSlip) < (LimitBetweenHighSpeedVibrationsAndTiresSlipWMMT5 / 1000.0);
percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighSpeedVibrationsStrengthWMMT5 : TiresSlipStrengthWMMT5) / 100.0;
bool highSpeedVibrations = (294 <= speed) && (-1.0 * tiresSlip) < (LimitBetweenHighSpeedVibrationsAndTiresSlip / 1000.0);
percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighSpeedVibrationsStrength : TiresSlipStrength) / 100.0;
triggers->Sine(100, 100, percentForce);
if (!highSpeedVibrations && ((0 == JointsAndStripesStrengthWMMT5 && 0 == CollisionsStrengthWMMT5) || (0.001 > collisions && -0.001 < collisions)))
if (!highSpeedVibrations && ((0 == JointsAndStripesStrength && 0 == CollisionsStrength) || (0.001 > collisions && -0.001 < collisions)))
{
triggers->LeftRight(0, percentForce, 150);
}
}
INT_PTR ptr1 = helpers->ReadIntPtr(0x199A450, true);
UINT8 gear = helpers->ReadByte(ptr1 + 0x398, false);
if (0 < WheelSpinStrength)
{
INT_PTR ptr1 = myHelpers->ReadIntPtr(0x1948F10, true);
INT_PTR ptr2 = myHelpers->ReadIntPtr(ptr1 + 0x180 + 0xa8 + 0x18, false);
UINT8 power = myHelpers->ReadByte(ptr2 + 0x98, false);
int rpm = helpers->ReadInt32(0x1970038, true);
int diff = 0x0A <= power ? 0 : 20;
if (
1 == gear && 10 < speed && (
((30 - diff) > speed && 3500 < rpm)
|| ((55 - diff) > speed && 5500 < rpm)
|| ((75 - diff) > speed && 7000 < rpm)
|| ((100 - diff) > speed && 7800 < rpm)
)
)
{
percentForce = (((100.0 - speed) / 100.0) * ((rpm * 100.0 / 8500.0) / 100.0)) * WheelSpinStrength / 100.0;
triggers->Sine(120, 120, percentForce);
triggers->LeftRight(0, percentForce, 150);
msg = "tires spin: gear: " + std::to_string(gear) + " | speed: " + std::to_string(speed)
+ " | rpm: " + std::to_string(rpm) + " | force: " + std::to_string(percentForce);
helpers->log((char*)msg.c_str());
}
else if (
2 == gear && 10 < speed && (
((110 - (2 * diff)) > speed && 5000 < rpm)
|| ((130 - (2 * diff)) > speed && 6000 < rpm)
|| ((145 - (2 * diff)) > speed && 6500 < rpm)
|| ((160 - (2 * diff)) > speed && 7000 < rpm)
)
)
{
percentForce = (((160.0 - speed) / 150.0) * ((rpm * 100.0 / 8500.0) / 100.0)) * WheelSpinStrength / 100.0;
triggers->Sine(120, 120, percentForce);
triggers->LeftRight(0, percentForce, 150);
msg = "tires spin: gear: " + std::to_string(gear) + " | speed: " + std::to_string(speed)
+ " | rpm: " + std::to_string(rpm) + " | force: " + std::to_string(percentForce);
helpers->log((char*)msg.c_str());
}
}
if (0 < GearChangeStrength)
{
ptr1 = helpers->ReadIntPtr(0x199A468, true);
float time = helpers->ReadFloat32(ptr1 + 0x18, false);
if (oldgear != gear && 0 < gear && 0 < time)
{
msg = "oldgear: " + std::to_string(oldgear) + " | gear: " + std::to_string(gear)
+ " | time: " + std::to_string(time) + " | speed: " + std::to_string(speed);
helpers->log((char*)msg.c_str());
}
if (oldgear != gear && 0 < gear && 0.5 < time && 0.1 <= speed)
{
if (GearChangeDelay > 0)
{
Sleep(GearChangeDelay);
}
helpers->log("gear change");
percentForce = GearChangeStrength / 100.0;
triggers->Sine(GearChangeLength, 0, percentForce);
triggers->LeftRight(0, percentForce, 150);
}
oldgear = gear;
}
}