1
0
mirror of synced 2024-11-28 00:20:52 +01:00
FFBArcadePlugin/Game Files/Demul.cpp

199 lines
4.7 KiB
C++
Raw Normal View History

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 <tchar.h>
#include "Demul.h"
#include "math.h"
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "SDL.h"
static SDL_Event e;
static EffectTriggers* myTriggers;
static EffectConstants* myConstants;
static Helpers* myHelpers;
2019-04-07 07:16:19 +02:00
int nascar(int ffnas) {
switch (ffnas) {
case 0x04:
return 32;
case 0x84:
return 31;
case 0x44:
return 30;
case 0xC4:
return 29;
case 0x24:
return 28;
case 0xA4:
return 27;
case 0x64:
return 26;
case 0xE4:
return 25;
case 0x14:
return 24;
case 0x94:
return 23;
case 0x54:
return 22;
case 0xD4:
return 21;
case 0x34:
return 20;
case 0xB4:
return 19;
case 0x74:
return 18;
case 0xF4:
return 17;
case 0xFC:
return 16;
case 0x7C:
return 15;
case 0xBC:
return 14;
case 0x3C:
return 13;
case 0xDC:
return 12;
case 0x5C:
return 11;
case 0x9C:
return 10;
case 0x1C:
return 9;
case 0xEC:
return 8;
case 0x6C:
return 7;
case 0xAC:
return 6;
case 0x2C:
return 5;
case 0xCC:
return 4;
case 0x4C:
return 3;
case 0x8C:
return 2;
case 0x0C:
return 1;
default:
return 0;
}
}
BOOL CALLBACK FindWindowBySubstr(HWND hwnd, LPARAM substring)
{
const DWORD TITLE_SIZE = 1024;
TCHAR windowTitle[TITLE_SIZE];
if (GetWindowText(hwnd, windowTitle, TITLE_SIZE))
{
//_tprintf(TEXT("%s\n"), windowTitle);
// Uncomment to print all windows being enumerated
if (_tcsstr(windowTitle, LPCTSTR(substring)) != NULL)
{
// We found the window! Stop enumerating.
return false;
}
}
return true; // Need to continue enumerating windows
}
static int RunningThread(void* ptr)
{
int cnt;
for (cnt = 0; cnt >= 0; ++cnt)
2019-04-07 07:16:19 +02:00
{
const TCHAR substring[] = TEXT("NASCAR");
EnumWindows(FindWindowBySubstr, (LPARAM)substring);
wchar_t* settingsFilename = TEXT(".\\FFBPlugin.ini");
int FFBMode = GetPrivateProfileInt(TEXT("Settings"), TEXT("FFBMode"), 0, settingsFilename);
2019-04-07 07:16:19 +02:00
{
int ffnascar = 0;
2019-04-07 07:16:19 +02:00
{
if (!EnumWindows(FindWindowBySubstr, (LPARAM)substring))
2019-04-07 07:16:19 +02:00
{
UINT8 ffnas = myHelpers->ReadByte(0x30060C, /* isRelativeOffset */ true); //Nascar Arcade
std::string ffs = std::to_string(ffnas);
myHelpers->log((char*)ffs.c_str());
myHelpers->log("got value: ");
ffnascar = nascar(ffnas);
if (FFBMode == 0)
2019-04-07 07:16:19 +02:00
{
if ((ffnascar > 16)& (ffnascar < 33))
{
myHelpers->log("moving wheel left");
double percentForce = (ffnascar - 16) / 16.0;
double percentLength = 100;
myTriggers->Rumble(percentForce, 0, percentLength);
myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce);
}
else if ((ffnascar > 0)& (ffnascar < 17))
{
myHelpers->log("moving wheel right");
double percentForce = (17 - ffnascar) / 16.0;
double percentLength = 100;
myTriggers->Rumble(0, percentForce, percentLength);
myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce);
}
2019-04-07 07:16:19 +02:00
}
else
2019-04-07 07:16:19 +02:00
{
if ((ffnascar > 16)& (ffnascar < 33))
{
myHelpers->log("moving wheel left");
double percentForce = (ffnascar - 16) / 16.0;
double percentLength = 100;
myTriggers->Rumble(pow(percentForce, 0.5), 0, percentLength);
myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, (pow(percentForce, 0.5)));
}
else if ((ffnascar > 0)& (ffnascar < 17))
{
myHelpers->log("moving wheel right");
double percentForce = (17 - ffnascar) / 16.0;
double percentLength = 100;
myTriggers->Rumble(0, pow(percentForce, 0.5), percentLength);
myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, (pow(percentForce, 0.5)));
}
2019-04-07 07:16:19 +02:00
}
}
}
}
}
}
void Demul::FFBLoop(EffectConstants * constants, Helpers * helpers, EffectTriggers * triggers) {
myTriggers = triggers;
myConstants = constants;
myHelpers = helpers;
SDL_Thread* thread;
thread = SDL_CreateThread(RunningThread, "RunningThread", (void*)NULL);
while (SDL_WaitEvent(&e) != 0)
{
myTriggers = triggers;
myConstants = constants;
myHelpers = helpers;
}
}