From 73c5919a1cd117a0fada8b5118636197c22fcce7 Mon Sep 17 00:00:00 2001 From: Aaron M Date: Sat, 6 Jun 2020 20:08:40 +1200 Subject: [PATCH] Demul Input stuff --- Common Files/CRCCheck.h | 137 +++ Common Files/Game.cpp | 11 +- Common Files/Game.h | 2 +- Config/FFBPlugin.ini | 55 + Dinput8Wrapper.vcxproj | 7 + Dinput8Wrapper.vcxproj.filters | 9 + DllMain.cpp | 2 +- Game Files/ChaseHQ2.cpp | 7 +- Game Files/Demul.cpp | 687 ++++++++++--- Game Files/DemulATVTrackInputs.cpp | 963 ++++++++++++++++++ Game Files/DemulFasterThanSpeedInputs.cpp | 887 +++++++++++++++++ Game Files/DemulInitialDInputs.cpp | 863 ++++++++++++++++ Game Files/DemulMaximumSpeedInputs.cpp | 816 +++++++++++++++ Game Files/DemulNascarInputs.cpp | 1104 +++++++++++++++++++++ Game Files/DemulSmashingDriveInputs.cpp | 955 ++++++++++++++++++ Game Files/M2Emulator.cpp | 24 +- Game Files/RoadFighters3D.cpp | 66 +- 17 files changed, 6360 insertions(+), 235 deletions(-) create mode 100644 Common Files/CRCCheck.h create mode 100644 Game Files/DemulATVTrackInputs.cpp create mode 100644 Game Files/DemulFasterThanSpeedInputs.cpp create mode 100644 Game Files/DemulInitialDInputs.cpp create mode 100644 Game Files/DemulMaximumSpeedInputs.cpp create mode 100644 Game Files/DemulNascarInputs.cpp create mode 100644 Game Files/DemulSmashingDriveInputs.cpp diff --git a/Common Files/CRCCheck.h b/Common Files/CRCCheck.h new file mode 100644 index 0000000..cfd5b64 --- /dev/null +++ b/Common Files/CRCCheck.h @@ -0,0 +1,137 @@ +/*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/>. +*/ + +#pragma once + +static const unsigned int kCrc32Table[256] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, +}; // kCrc32Table + +static DWORD crc_32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; + +static uint32_t GetCRC32(const void* pData, int length) +{ + uint32_t _crc = 0xFFFFFFFF; + unsigned char* pCur = (unsigned char*)pData; + int remaining = length; + for (; remaining--; ++pCur) + _crc = (_crc >> 8) ^ kCrc32Table[(_crc ^ *pCur) & 0xff]; + + return _crc ^ 0xFFFFFFFF; +} \ No newline at end of file diff --git a/Common Files/Game.cpp b/Common Files/Game.cpp index 1e40643..02874a5 100644 --- a/Common Files/Game.cpp +++ b/Common Files/Game.cpp @@ -71,12 +71,17 @@ INT_PTR Helpers::WriteIntPtr(INT_PTR offset, INT_PTR val, bool isRelativeOffset) return val; }; -UINT8 Helpers::WriteNop(INT_PTR offset, bool isRelativeOffset) +UINT8 Helpers::WriteNop(INT_PTR offset, int countBytes, bool isRelativeOffset) { U8 nop = 0x90; SIZE_T written; - LPVOID trueOffset = (isRelativeOffset ? GetTranslatedOffset(offset) : (LPVOID)offset); - WriteProcessMemory(GetCurrentProcess(), trueOffset, &nop, 1, &written); + for (int i = 0; i < countBytes; i++) + { + offset = offset + i; + LPVOID trueOffset = (isRelativeOffset ? GetTranslatedOffset(offset) : (LPVOID)offset); + WriteProcessMemory(GetCurrentProcess(), trueOffset, &nop, 1, &written); + offset = offset - i; + } return nop; } diff --git a/Common Files/Game.h b/Common Files/Game.h index a39ea4f..0236ed5 100644 --- a/Common Files/Game.h +++ b/Common Files/Game.h @@ -105,7 +105,7 @@ public: float WriteFloat32(INT_PTR offset, float val, bool isRelativeOffset); UINT8 WriteByte(INT_PTR offset, UINT8 val, bool isRelativeOffset); INT_PTR WriteIntPtr(INT_PTR offset, INT_PTR val, bool isRelativeOffset); - UINT8 WriteNop(INT_PTR offset, bool isRelativeOffset); + UINT8 WriteNop(INT_PTR offset, int countBytes, bool isRelativeOffset); INT_PTR ReadIntPtr(INT_PTR offset, bool isRelativeOffset); float ReadFloat32(INT_PTR offset, bool isRelativeOffset); }; diff --git a/Config/FFBPlugin.ini b/Config/FFBPlugin.ini index 5b765e4..94d29a5 100644 --- a/Config/FFBPlugin.ini +++ b/Config/FFBPlugin.ini @@ -553,6 +553,61 @@ HideCursor=0 [Demul] GameId=26 +AutoCloseWindowError=0 +InputDeviceWheelEnable=0 +InputDeviceWheelSteeringAxis=99 +InputDeviceWheelAcclAxis=99 +InputDeviceWheelBrakeAxis=99 +InputDeviceWheelReverseAxis=0 +InputDeviceCombinedPedals=0 +SteeringDeadzone=2 +PedalDeadzone=2 +SequentialGears=0 +ShowButtonNumbersForSetup=0 +ShowAxisForSetup=0 +DpadUp= +DpadDown= +DpadLeft= +DpadRight= +ExitButton=99 +TestButton=99 +ServiceButton=99 +CreditButton=99 +BoostButton=99 +HornButton=99 +VolumeUp=99 +VolumeDown=99 +ViewButton=99 +StartButton=99 +ShiftUp=99 +ShiftDown=99 +EmergencyStop=99 +Gear1=99 +Gear2=99 +Gear3=99 +Gear4=99 +Device2GUID= +DpadUpDevice2= +DpadDownDevice2= +DpadLeftDevice2= +DpadRightDevice2= +ExitButtonDevice2=99 +TestButtonDevice2=99 +ServiceButtonDevice2=99 +CreditButtonDevice2=99 +BoostButtonDevice2=99 +HornButtonDevice2=99 +VolumeUpDevice2=99 +VolumeDownDevice2=99 +ViewButtonDevice2=99 +StartButtonDevice2=99 +ShiftUpDevice2=99 +ShiftDownDevice2=99 +EmergencyStopDevice2=99 +Gear1Device2=99 +Gear2Device2=99 +Gear3Device2=99 +Gear4Device2=99 PowerModeInitialDDemul=0 FeedbackLengthInitialDDemul=500 MinForceInitialDDemul=0 diff --git a/Dinput8Wrapper.vcxproj b/Dinput8Wrapper.vcxproj index 2c4fe01..ce869dd 100644 --- a/Dinput8Wrapper.vcxproj +++ b/Dinput8Wrapper.vcxproj @@ -19,6 +19,7 @@ + @@ -55,6 +56,11 @@ + + + + + @@ -62,6 +68,7 @@ + diff --git a/Dinput8Wrapper.vcxproj.filters b/Dinput8Wrapper.vcxproj.filters index d0f1a80..d7bfc89 100644 --- a/Dinput8Wrapper.vcxproj.filters +++ b/Dinput8Wrapper.vcxproj.filters @@ -125,6 +125,12 @@ + + + + + + @@ -278,6 +284,9 @@ Common Header Files + + Common Header Files + diff --git a/DllMain.cpp b/DllMain.cpp index 1c9761a..0bed4c5 100644 --- a/DllMain.cpp +++ b/DllMain.cpp @@ -1925,7 +1925,7 @@ DWORD WINAPI FFBLoop(LPVOID lpParam) if (EnableRumble == 1) { - if ((configGameId != 1) && (configGameId != 9) && (configGameId != 12) && (configGameId != 28) && (configGameId != 29) && (configGameId != 30) && (configGameId != 31) && (configGameId != 35)) + if ((configGameId != 1) && (configGameId != 9) && (configGameId != 12) && (configGameId != 26) && (configGameId != 28) && (configGameId != 29) && (configGameId != 30) && (configGameId != 31) && (configGameId != 35)) { // Workaround for SDL_JoystickRumble rumble not stopping issue SDL_CreateThread(WorkaroundToFixRumble, "WorkaroundToFixRumble", (void*)NULL); diff --git a/Game Files/ChaseHQ2.cpp b/Game Files/ChaseHQ2.cpp index 5cf3ac6..4743ba4 100644 --- a/Game Files/ChaseHQ2.cpp +++ b/Game Files/ChaseHQ2.cpp @@ -109,12 +109,7 @@ void ChaseHQ2::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTrigg { if (!removecel) { - helpers->WriteNop(0x31FFA, true); - helpers->WriteNop(0x31FFB, true); - helpers->WriteNop(0x31FFC, true); - helpers->WriteNop(0x31FFD, true); - helpers->WriteNop(0x31FFE, true); - helpers->WriteNop(0x31FFF, true); + helpers->WriteNop(0x31FFA, 6, true); removecel = true; } helpers->WriteByte(0x130CB30, 0x00, true); // Remove Cel Shaded Filter diff --git a/Game Files/Demul.cpp b/Game Files/Demul.cpp index 299f6b5..72057e4 100644 --- a/Game Files/Demul.cpp +++ b/Game Files/Demul.cpp @@ -18,8 +18,52 @@ along with FFB Arcade Plugin.If not, see < https://www.gnu.org/licenses/>. #include #include #include +#include "SDL.h" +#include "../Common Files/CRCCheck.h" #include "../Common Files/SignatureScanning.h" +extern void NascarInputsEnabled(Helpers* helpers); +extern void InitialDInputsEnabled(Helpers* helpers); +extern void SmashingDriveInputsEnabled(Helpers* helpers); +extern void ATVTrackInputsEnabled(Helpers* helpers); +extern void FasterThanSpeedInputsEnabled(Helpers* helpers); +extern void MaximumSpeedInputsEnabled(Helpers* helpers); + +static EffectTriggers* myTriggers; +static EffectConstants* myConstants; +static Helpers* myHelpers; +static HINSTANCE gl_padDemul; + +extern int joystick_index1; +extern int joystick_index2; +extern SDL_Joystick* GameController2; +static bool testbuttonA; +static bool servicebuttonA; +static bool startbuttonA; +static bool viewbuttonA; +static bool shiftupA; +static bool shiftdownA; +static bool coinA; +static bool VolumeMute = false; +static bool VolumeMute2 = false; +static bool CRCinit = false; +static bool NOPinit = false; +static bool InputFind = false; +static SDL_Event e; + +INT_PTR SteeringAddress; +INT_PTR AcclAddress; +INT_PTR BrakeAddress; +INT_PTR StartViewAddress; +INT_PTR ShiftUpDownAddress; +INT_PTR ServiceTestAddress; +INT_PTR CoinAddress; + +static HWND hWnd; + +static bool Demul180428 = false; +static bool Demul111117 = false; + extern wchar_t* settingsFilename; extern int DeviceGUID; extern int configFeedbackLength; @@ -37,6 +81,9 @@ extern int configAlternativeMaxForceRight; extern int EnableForceSpringEffect; extern int ForceSpringStrength; +static int InputDeviceWheelEnable = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelEnable"), 0, settingsFilename); +static int AutoCloseWindowError = GetPrivateProfileInt(TEXT("Settings"), TEXT("AutoCloseWindowError"), 0, settingsFilename); + static int configMinForceInitialDDemul = GetPrivateProfileInt(TEXT("Settings"), TEXT("MinForceInitialDDemul"), 0, settingsFilename); static int configMaxForceInitialDDemul = GetPrivateProfileInt(TEXT("Settings"), TEXT("MaxForceInitialDDemul"), 100, settingsFilename); static int configAlternativeMinForceLeftInitialDDemul = GetPrivateProfileInt(TEXT("Settings"), TEXT("AlternativeMinForceLeftInitialDDemul"), 0, settingsFilename); @@ -242,6 +289,233 @@ int fasterspeed(int ffspeed) { } } +static int InitialDFFBLoop() +{ + UINT8 ff1 = myHelpers->ReadByte(FFBAddress, false); + UINT8 ff2 = myHelpers->ReadByte(FFBAddress + 0x01, false); + UINT8 ff3 = myHelpers->ReadByte(FFBAddress + 0x02, false); + + if (KickStartWait) + { + if ((ff1 == 0x80) && (ff3 == 0x01)) + { + myTriggers->Spring(1.0); + } + + if ((ff1 == 0x85) && (ff2 == 0x3F) && (ff3 > 0x00) && (ff3 < 0x30)) + { + double percentForce = ff3 / 47.0; + double percentLength = 100; + myTriggers->Rumble(percentForce, percentForce, percentLength); + myTriggers->Sine(40, 0, percentForce); + } + + if ((ff1 == 0x86) && (ff2 == 0x02) && (ff3 > 0x09) && (ff3 < 0x3C)) + { + double percentForce = (60 - ff3) / 43.0; + double percentLength = 100; + myTriggers->Spring(percentForce); + } + + if ((ff1 == 0x84) && (ff2 == 0x00) && (ff3 > 0x37) && (ff3 < 0x80)) + { + double percentForce = (128 - ff3) / 72.0; + double percentLength = 100; + myTriggers->Rumble(percentForce, 0, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce); + } + else if ((ff1 == 0x84) && (ff2 == 0x01) && (ff3 > 0x00) && (ff3 < 0x49)) + { + double percentForce = (ff3 / 72.0); + double percentLength = 100; + myTriggers->Rumble(0, percentForce, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); + } + } + return 0; +} + +static int SmashingDriveFFBLoop() +{ + INT_PTR FFBSmashingDrive = myHelpers->ReadIntPtr(FFBAddress, false); + + if ((FFBSmashingDrive > 0x01) && (FFBSmashingDrive < 0x100)) + { + double percentForce = FFBSmashingDrive / 255.0; + double percentLength = 100; + myTriggers->Rumble(percentForce, 0, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce); + } + else if ((FFBSmashingDrive > 0x1FF) && (FFBSmashingDrive < 0xFF01)) + { + double percentForce = (FFBSmashingDrive / 65280.0); + double percentLength = 100; + myTriggers->Rumble(0, percentForce, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); + } + return 0; +} + +static int ATVTrackFFBLoop() +{ + float FFBATVTrack = myHelpers->ReadFloat32(FFBAddress, false); + + if (FFBATVTrack > 0) + { + double percentForce = FFBATVTrack; + double percentLength = 100; + myTriggers->Rumble(percentForce, 0, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce); + } + else if (FFBATVTrack < 0) + { + double percentForce = -FFBATVTrack; + double percentLength = 100; + myTriggers->Rumble(0, percentForce, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); + } + return 0; +} + +static int FasterThanSpeedFFBLoop() +{ + UINT8 ffbfaster = myHelpers->ReadByte(FFBAddress, false); + fffaster = fasterspeed(ffbfaster); + + if ((fffaster > 0x0B) && (fffaster < 0x17)) + { + double percentForce = (fffaster - 11) / 11.0; + double percentLength = 100; + myTriggers->Rumble(percentForce, 0, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce); + } + else if ((fffaster > 0x00) && (fffaster < 0x0C)) + { + double percentForce = fffaster / 11.0; + double percentLength = 100; + myTriggers->Rumble(0, percentForce, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); + } + return 0; +} + +static int MaximumSpeedFFBLoop() +{ + UINT8 FFBMaximumSpeed = myHelpers->ReadIntPtr(FFBAddress, false); + UINT8 FFBMaximumSpeed2 = myHelpers->ReadByte(FFBAddress + 0x01, false); + + if ((FFBMaximumSpeed > 0x7F) && (FFBMaximumSpeed < 0x100) && (FFBMaximumSpeed2 == 0xFF)) + { + double percentForce = (256 - FFBMaximumSpeed) / 128.0; + double percentLength = 100; + myTriggers->Rumble(percentForce, 0, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce); + } + else if ((FFBMaximumSpeed > 0x00) && (FFBMaximumSpeed < 0x81) && (FFBMaximumSpeed2 == 0x00)) + { + double percentForce = FFBMaximumSpeed / 128.0; + double percentLength = 100; + myTriggers->Rumble(0, percentForce, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); + } + return 0; +} + +static int NascarFFBLoop() +{ + UINT8 ffnas = myHelpers->ReadByte(FFBAddress, false); + ffnascar = nascar(ffnas); + + if ((ffnascar > 0x10) && (ffnascar < 0x21)) + { + double percentForce = (ffnascar - 16) / 16.0; + double percentLength = 100; + myTriggers->Rumble(percentForce, 0, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_LEFT, percentForce); + } + else if ((ffnascar > 0x00) && (ffnascar < 0x11)) + { + double percentForce = (17 - ffnascar) / 16.0; + double percentLength = 100; + myTriggers->Rumble(0, percentForce, percentLength); + myTriggers->Constant(myConstants->DIRECTION_FROM_RIGHT, percentForce); + } + return 0; +} + +static DWORD WINAPI NascarRunningLoop(LPVOID lpParam) +{ + while (true) + { + NascarFFBLoop(); + Sleep(16); + } +} + +static DWORD WINAPI InitialDRunningLoop(LPVOID lpParam) +{ + while (true) + { + InitialDFFBLoop(); + Sleep(16); + } +} + +static DWORD WINAPI SmashingDriveRunningLoop(LPVOID lpParam) +{ + while (true) + { + SmashingDriveFFBLoop(); + Sleep(16); + } +} + +static DWORD WINAPI ATVTrackRunningLoop(LPVOID lpParam) +{ + while (true) + { + ATVTrackFFBLoop(); + Sleep(16); + } +} + +static DWORD WINAPI FasterThanSpeedRunningLoop(LPVOID lpParam) +{ + while (true) + { + FasterThanSpeedFFBLoop(); + Sleep(16); + } +} + +static DWORD WINAPI MaximumSpeedRunningLoop(LPVOID lpParam) +{ + while (true) + { + MaximumSpeedFFBLoop(); + Sleep(16); + } +} + +void changeVolume() +{ + INPUT ip = { 0 }; + ip.type = INPUT_KEYBOARD; + ip.ki.wVk = VK_VOLUME_MUTE; + SendInput(1, &ip, sizeof(INPUT)); + ip.ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(1, &ip, sizeof(INPUT)); +} + +static DWORD WINAPI VolumeMuteThread(LPVOID lpParam) +{ + SendMessage(hWnd, WM_CLOSE, NULL, NULL); + Sleep(1500); + changeVolume(); + VolumeMute = true; + return 0; +} + static BOOL CALLBACK FindWindowBySubstr(HWND hwnd, LPARAM substring) { const DWORD TITLE_SIZE = 1024; @@ -268,6 +542,142 @@ const TCHAR substring6[] = TEXT("ATV Track"); void Demul::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers* triggers) { + myTriggers = triggers; + myConstants = constants; + myHelpers = helpers; + + if (AutoCloseWindowError == 1) + { + if (!VolumeMute) + { + if (!VolumeMute2) + { + changeVolume(); + VolumeMute2 = true; + } + + //Remove window error popup + hWnd = FindWindowA(0, ("padDemul")); + if (hWnd > NULL) + { + CreateThread(NULL, 0, VolumeMuteThread, NULL, 0, NULL); + } + } + } + + if (!CRCinit) + { + if (InputDeviceWheelEnable == 1) + { + static char newCrc[0x400]; + // Craft CRC detection without virtual address + memcpy(newCrc, GetModuleHandle(nullptr), 0x400); + DWORD pePTR = *(DWORD*)(newCrc + 0x3C); + + // Overwrite ImageBase with 8 bytes of 0 + *(DWORD*)(newCrc + pePTR + 0x18) = 0x00000000; + *(DWORD*)(newCrc + pePTR + 0x18 + 4) = 0x00000000; +#ifdef _AMD64_ + * (DWORD*)(newCrc + pePTR + 50) = 0x00000000; +#endif + * (DWORD*)(newCrc + pePTR + 54) = 0x00000000; + uint32_t newCrcResult = GetCRC32(newCrc, 0x400); + switch (newCrcResult) + { + case 0x875a800d: + Demul180428 = true; + break; + case 0x04f85ceb: + Demul111117 = true; + break; + } + + if ((Demul180428) || (Demul111117)) + { + CRCinit = true; + } + } + } + + if (NOPinit) + { + gl_padDemul = LoadLibraryA("padDemul.dll"); + + if (Demul180428) + { + helpers->WriteNop((INT_PTR)gl_padDemul + 0x27013, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26F31, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x271F7, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x276BD, 4, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x272FF, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26FBD, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x27685, 4, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x276A2, 4, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26FEC, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x270A3, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26FE1, 3, false); + } + + if (Demul111117) + { + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26B31, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26DD0, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x272AD, 4, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26B9C, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x27275, 4, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x27292, 4, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26BC2, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26BBA, 3, false); + helpers->WriteNop((INT_PTR)gl_padDemul + 0x26BE3, 3, false); + } + + if (NascarRunning) + { + helpers->WriteByte(SteeringAddress, 0x80, false); + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + NascarInputsEnabled(helpers); + } + + if (InitialDRunning) + { + helpers->WriteByte(SteeringAddress, 0x80, false); + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + InitialDInputsEnabled(helpers); + } + + if (SmashingDriveRunning) + { + helpers->WriteByte(SteeringAddress, 0x80, false); + SmashingDriveInputsEnabled(helpers); + } + + if (ATVTrackRunning) + { + helpers->WriteByte(SteeringAddress, 0x80, false); + helpers->WriteByte(AcclAddress, 0x00, false); + ATVTrackInputsEnabled(helpers); + } + + if (FasterThanSpeedRunning) + { + helpers->WriteByte(SteeringAddress, 0x80, false); + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + FasterThanSpeedInputsEnabled(helpers); + } + + if (MaximumSpeedRunning) + { + helpers->WriteByte(SteeringAddress, 0x80, false); + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + MaximumSpeedInputsEnabled(helpers); + } + } + if (EnableForceSpringEffect == 1) { triggers->Springi(ForceSpringStrength / 100.0); @@ -385,33 +795,34 @@ void Demul::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers { if (!FFBGameInit) { - FFBGameInit = true; aAddy2 = PatternScan("\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50\x72\x6F\x64\x75\x63\x65\x64\x20\x42\x79\x20", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); FFBAddress = (int)aAddy2 - 0x2F0; + CreateThread(NULL, 0, NascarRunningLoop, NULL, 0, NULL); + FFBGameInit = true; } - - UINT8 ffnas = helpers->ReadByte(FFBAddress, false); - std::string ffs = std::to_string(ffnas); - helpers->log((char*)ffs.c_str()); - helpers->log("got value: "); - ffnascar = nascar(ffnas); - - if ((ffnascar > 0x10) && (ffnascar < 0x21)) + else { - helpers->log("moving wheel right"); - double percentForce = (ffnascar - 16) / 16.0; - double percentLength = 100; - triggers->Rumble(percentForce, 0, percentLength); - triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce); - } - else if ((ffnascar > 0x00) && (ffnascar < 0x11)) - { - helpers->log("moving wheel left"); - double percentForce = (17 - ffnascar) / 16.0; - double percentLength = 100; - triggers->Rumble(0, percentForce, percentLength); - triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce); - } + if (InputDeviceWheelEnable == 1) + { + if (!InputFind) + { + aAddy = PatternScan("\x11\x00\x16\x1F\x05\x04\x1D\x0D\x07\x12\x18\x14\x02\x13\x09\x15\x0E\x19\x01\x1C\x08\x1A\x17\x03\x0F\x1B\x00\x10\x0A\x0B\x0C\x06\x01", "x?xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + UINT8 CheckaAddy = helpers->ReadByte((int)aAddy + 0x01, false); + if (CheckaAddy == 0x1E) + { + SteeringAddress = (int)aAddy - 0xC45; + AcclAddress = (int)aAddy - 0xC0D; + BrakeAddress = (int)aAddy - 0xBD5; + ShiftUpDownAddress = (int)aAddy - 0xDEA; + ServiceTestAddress = (int)aAddy - 0x108A; + StartViewAddress = (int)aAddy - 0xF8E; + CoinAddress = (int)aAddy - 0xFE2; + NOPinit = true; + InputFind = true; + } + } + } + } } if (InitialDRunning) @@ -419,69 +830,45 @@ void Demul::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers if (!FFBGameInit) { Sleep(6000); - FFBGameInit = true; aAddy2 = PatternScan("\x88\xA9\x00\x09", "xxxx"); FFBAddress = (int)aAddy2 + 0x01; + FFBGameInit = true; } - UINT8 ff1 = helpers->ReadByte(FFBAddress, false); - UINT8 ff2 = helpers->ReadByte(FFBAddress + 0x01, false); - UINT8 ff3 = helpers->ReadByte(FFBAddress + 0x02, false); - - std::string ffs = std::to_string(ff1); - helpers->log((char*)ffs.c_str()); - helpers->log("got value: "); - if (!KickStartWait) { if (FFBAddress > 0) { Sleep(6000); + CreateThread(NULL, 0, InitialDRunningLoop, NULL, 0, NULL); KickStartWait = true; } } - - if (KickStartWait) - { - if ((ff1 == 0x80) && (ff3 == 0x01)) + else + { + if (InputDeviceWheelEnable == 1) { - triggers->Spring(1.0); - } - - if ((ff1 == 0x85) && (ff2 == 0x3F) && (ff3 > 0x00) && (ff3 < 0x30)) - { - double percentForce = ff3 / 47.0; - double percentLength = 100; - triggers->Rumble(percentForce, percentForce, percentLength); - triggers->Sine(40, 0, percentForce); - } - - if ((ff1 == 0x86) && (ff2 == 0x02) && (ff3 > 0x09) && (ff3 < 0x3C)) - { - double percentForce = (60 - ff3) / 43.0; - double percentLength = 100; - triggers->Spring(percentForce); - } - - if ((ff1 == 0x84) && (ff2 == 0x00) && (ff3 > 0x37) && (ff3 < 0x80)) - { - helpers->log("moving wheel right"); - double percentForce = (128 - ff3) / 72.0; - double percentLength = 100; - triggers->Rumble(percentForce, 0, percentLength); - triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce); - } - else if ((ff1 == 0x84) && (ff2 == 0x01) && (ff3 > 0x00) && (ff3 < 0x49)) - { - helpers->log("moving wheel left"); - double percentForce = (ff3 / 72.0); - double percentLength = 100; - triggers->Rumble(0, percentForce, percentLength); - triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce); + if (!InputFind) + { + aAddy = PatternScan("\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + UINT8 CheckaAddy = helpers->ReadByte((int)aAddy - 0x2A0, false); + if (CheckaAddy == 0x01) + { + SteeringAddress = (int)aAddy - 0x85; + AcclAddress = (int)aAddy - 0x4D; + BrakeAddress = (int)aAddy - 0x15; + StartViewAddress = (int)aAddy - 0x14A; + ShiftUpDownAddress = (int)aAddy - 0xDA; + ServiceTestAddress = (int)aAddy - 0x246; + CoinAddress = (int)aAddy - 0x19E; + NOPinit = true; + InputFind = true; + } + } } } } - + if (SmashingDriveRunning) { if (!FFBGameInit) @@ -492,32 +879,27 @@ void Demul::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers if (CheckAddy == 0x07) { FFBAddress = (int)aAddy2 - 0xD0; + CreateThread(NULL, 0, SmashingDriveRunningLoop, NULL, 0, NULL); FFBGameInit = true; } } else { - INT_PTR FFBSmashingDrive = helpers->ReadIntPtr(FFBAddress, false); - - std::string ffs = std::to_string(FFBSmashingDrive); - helpers->log((char*)ffs.c_str()); - helpers->log("got value: "); - - if ((FFBSmashingDrive > 0x01) && (FFBSmashingDrive < 0x100)) + if (InputDeviceWheelEnable == 1) { - helpers->log("moving wheel right"); - double percentForce = FFBSmashingDrive / 255.0; - double percentLength = 100; - triggers->Rumble(percentForce, 0, percentLength); - triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce); - } - else if ((FFBSmashingDrive > 0x1FF) && (FFBSmashingDrive < 0xFF01)) - { - helpers->log("moving wheel left"); - double percentForce = (FFBSmashingDrive / 65280.0); - double percentLength = 100; - triggers->Rumble(0, percentForce, percentLength); - triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce); + if (!InputFind) + { + aAddy = PatternScan("\x0C\x00\x0E\x0F\x08\x09\x0A\x0B\x1C\x1D\x1E\x1F\x18\x19\x1A\x1B\x04\x05\x06\x07\x00\x01\x02\x03\x14\x15\x16\x17\x10\x11", "x?xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + UINT8 CheckaAddy = helpers->ReadByte((int)aAddy + 0x01, false); + if (CheckaAddy == 0x0D) + { + SteeringAddress = (int)aAddy - 0x80A; + ServiceTestAddress = (int)aAddy - 0x95A; + AcclAddress = (int)aAddy - 0x896; + NOPinit = true; + InputFind = true; + } + } } } } @@ -532,33 +914,30 @@ void Demul::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers if (CheckAddy == 0xFC) { FFBAddress = (int)aAddy2 + 0x18; + CreateThread(NULL, 0, MaximumSpeedRunningLoop, NULL, 0, NULL); FFBGameInit = true; } } else { - UINT8 FFBMaximumSpeed = helpers->ReadIntPtr(FFBAddress, false); - UINT8 FFBMaximumSpeed2 = helpers->ReadByte(FFBAddress + 0x01, false); - - std::string ffs = std::to_string(FFBMaximumSpeed); - helpers->log((char*)ffs.c_str()); - helpers->log("got value: "); - - if ((FFBMaximumSpeed > 0x7F) && (FFBMaximumSpeed < 0x100) && (FFBMaximumSpeed2 == 0xFF)) + if (InputDeviceWheelEnable == 1) { - helpers->log("moving wheel right"); - double percentForce = (256 - FFBMaximumSpeed) / 128.0; - double percentLength = 100; - triggers->Rumble(percentForce, 0, percentLength); - triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce); - } - else if ((FFBMaximumSpeed > 0x00) && (FFBMaximumSpeed < 0x81) && (FFBMaximumSpeed2 == 0x00)) - { - helpers->log("moving wheel left"); - double percentForce = FFBMaximumSpeed / 128.0; - double percentLength = 100; - triggers->Rumble(0, percentForce, percentLength); - triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce); + if (!InputFind) + { + aAddy = PatternScan("\x14\x00\x05\x10\x0C\x18\x19\x04\x0B\x11\x0D\x1C\x1D\x02\x1F\x08\x06\x17\x0A\x0E\x16\x1A\x07\x15\x0F\x13\x01\x12\x03\x1E\x09", "x?xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + UINT8 CheckaAddy = helpers->ReadByte((int)aAddy + 0x01, false); + if (CheckaAddy == 0x1B) + { + SteeringAddress = (int)aAddy - 0x1316; + AcclAddress = (int)aAddy - 0x12DE; + BrakeAddress = (int)aAddy - 0x12A6; + ShiftUpDownAddress = (int)aAddy - 0x14F2; + ServiceTestAddress = (int)aAddy - 0x14F1; + CoinAddress = (int)aAddy - 0x136A; + NOPinit = true; + InputFind = true; + } + } } } } @@ -573,32 +952,32 @@ void Demul::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers if (CheckAddy == 0x0C) { FFBAddress = (int)aAddy2 + 0x0F; + CreateThread(NULL, 0, FasterThanSpeedRunningLoop, NULL, 0, NULL); FFBGameInit = true; } } - - UINT8 ffbfaster = helpers->ReadByte(FFBAddress, false); - std::string ffs = std::to_string(ffbfaster); - helpers->log((char*)ffs.c_str()); - helpers->log("got value: "); - fffaster = fasterspeed(ffbfaster); - - if ((fffaster > 0x0B) && (fffaster < 0x17)) + else { - helpers->log("moving wheel right"); - double percentForce = (fffaster - 11) / 11.0; - double percentLength = 100; - triggers->Rumble(percentForce, 0, percentLength); - triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce); - } - else if ((fffaster > 0x00) && (fffaster < 0x0C)) - { - helpers->log("moving wheel left"); - double percentForce = fffaster / 11.0; - double percentLength = 100; - triggers->Rumble(0, percentForce, percentLength); - triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce); - } + if (InputDeviceWheelEnable == 1) + { + if (!InputFind) + { + aAddy = PatternScan("\x14\x00\x05\x10\x0C\x18\x19\x04\x0B\x11\x0D\x1C\x1D\x02\x1F\x08\x06\x17\x0A\x0E\x16\x1A\x07\x15\x0F\x13\x01\x12\x03\x1E\x09", "x?xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + UINT8 CheckaAddy = helpers->ReadByte((int)aAddy + 0x01, false); + if (CheckaAddy == 0x1B) + { + SteeringAddress = (int)aAddy - 0x1316; + AcclAddress = (int)aAddy - 0x12DE; + BrakeAddress = (int)aAddy - 0x12A6; + ShiftUpDownAddress = (int)aAddy - 0x14F2; + ServiceTestAddress = (int)aAddy - 0x14F1; + CoinAddress = (int)aAddy - 0x136A; + NOPinit = true; + InputFind = true; + } + } + } + } } if (ATVTrackRunning) @@ -606,35 +985,33 @@ void Demul::FFBLoop(EffectConstants* constants, Helpers* helpers, EffectTriggers if (!FFBGameInit) { aAddy2 = PatternScan("\x49\x55\x4C\x00\x00\x00\x05", "xxxxxxx"); - UINT8 CheckAddy = helpers->ReadByte((int)aAddy2 - 0x04, false); if (CheckAddy == 0x1E) { FFBAddress = (int)aAddy2 - 0x1A; + CreateThread(NULL, 0, ATVTrackRunningLoop, NULL, 0, NULL); FFBGameInit = true; } } - - float FFBATVTrack = helpers->ReadFloat32(FFBAddress, false); - std::string ffs = std::to_string(FFBATVTrack); - helpers->log((char*)ffs.c_str()); - helpers->log("got value: "); - - if (FFBATVTrack > 0) - { - helpers->log("moving wheel right"); - double percentForce = FFBATVTrack; - double percentLength = 100; - triggers->Rumble(percentForce, 0, percentLength); - triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce); - } - else if (FFBATVTrack < 0) - { - helpers->log("moving wheel left"); - double percentForce = -FFBATVTrack; - double percentLength = 100; - triggers->Rumble(0, percentForce, percentLength); - triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce); + else + { + if (InputDeviceWheelEnable == 1) + { + if (!InputFind) + { + aAddy = PatternScan("\x11\x00\x16\x1F\x05\x04\x1D\x0D\x07\x12\x18\x14\x02\x13\x09\x15\x0E\x19\x01\x1C\x08\x1A\x17\x03\x0F\x1B\x00\x10\x0A\x0B\x0C\x06\x01", "x?xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + UINT8 CheckaAddy = helpers->ReadByte((int)aAddy + 0x01, false); + if (CheckaAddy == 0x1E) + { + SteeringAddress = (int)aAddy - 0xA16; + AcclAddress = (int)aAddy - 0x9DE; + BrakeAddress = (int)aAddy - 0xABE; + ServiceTestAddress = (int)aAddy - 0xB82; + NOPinit = true; + InputFind = true; + } + } + } } } } \ No newline at end of file diff --git a/Game Files/DemulATVTrackInputs.cpp b/Game Files/DemulATVTrackInputs.cpp new file mode 100644 index 0000000..d94b199 --- /dev/null +++ b/Game Files/DemulATVTrackInputs.cpp @@ -0,0 +1,963 @@ +#include "../Common Files/Game.h" +#include +#include +#include "SDL.h" + +extern int joystick_index1; +extern int joystick_index2; +extern SDL_Joystick* GameController2; +static bool testbuttonA; +static bool servicebuttonA; +static bool startbuttonA; +static bool viewbuttonA; +static bool volumeupA; +static bool volumedownA; +static bool coinA; +static bool brakepressed; +static bool emergencystopA; +static bool Inputsinit = false; +static bool InputFind = false; +static SDL_Event e; + +static int SteeringValue; +static int BrakeValue; + +extern INT_PTR SteeringAddress; +extern INT_PTR AcclAddress; +extern INT_PTR BrakeAddress; +extern INT_PTR ServiceTestAddress; + +extern wchar_t* settingsFilename; +static int InputDeviceWheelEnable = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelEnable"), 0, settingsFilename); +static int InputDeviceWheelSteeringAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelSteeringAxis"), 0, settingsFilename); +static int InputDeviceWheelAcclAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelAcclAxis"), 0, settingsFilename); +static int InputDeviceWheelBrakeAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelBrakeAxis"), 0, settingsFilename); +static int InputDeviceWheelReverseAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelReverseAxis"), 0, settingsFilename); +static int InputDeviceCombinedPedals = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceCombinedPedals"), 0, settingsFilename); +static int SteeringDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("SteeringDeadzone"), 0, settingsFilename); +static int PedalDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("PedalDeadzone"), 0, settingsFilename); +static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename); +static int ShowAxisForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowAxisForSetup"), 0, settingsFilename); +static int ExitButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButton"), 0, settingsFilename); +static int TestButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButton"), 0, settingsFilename); +static int ServiceButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButton"), 0, settingsFilename); +static int CreditButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButton"), 0, settingsFilename); +static int ViewButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ViewButton"), 0, settingsFilename); +static int StartButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButton"), 0, settingsFilename); +static int VolumeUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeUp"), 0, settingsFilename); +static int VolumeDown = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeDown"), 0, settingsFilename); +static int EmergencyStop = GetPrivateProfileInt(TEXT("Settings"), TEXT("EmergencyStop"), 0, settingsFilename); +static int ExitButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButtonDevice2"), 0, settingsFilename); +static int TestButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButtonDevice2"), 0, settingsFilename); +static int ServiceButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButtonDevice2"), 0, settingsFilename); +static int CreditButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButtonDevice2"), 0, settingsFilename); +static int ViewButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ViewButtonDevice2"), 0, settingsFilename); +static int StartButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButtonDevice2"), 0, settingsFilename); +static int VolumeUpDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeUpDevice2"), 0, settingsFilename); +static int VolumeDownDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeDownDevice2"), 0, settingsFilename); +static int EmergencyStopDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("EmergencyStopDevice2"), 0, settingsFilename); + +void ATVTrackInputsEnabled(Helpers* helpers) +{ + if (!Inputsinit) + { + //Added 2nd device stuff from here + wchar_t* deviceGUIDString2 = new wchar_t[256]; + int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); + char joystick_guid[256]; + sprintf(joystick_guid, "%S", deviceGUIDString2); + SDL_JoystickGUID guid, dev_guid; + int numJoysticks = SDL_NumJoysticks(); + std::string njs = std::to_string(numJoysticks); + ((char)njs.c_str()); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + SDL_Joystick* js2 = SDL_JoystickOpen(i); + joystick_index2 = SDL_JoystickInstanceID(js2); + SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); + char guid_str[1024]; + SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); + const char* name = SDL_JoystickName(js2); + char text[256]; + sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); + guid = SDL_JoystickGetGUIDFromString(joystick_guid); + dev_guid = SDL_JoystickGetGUID(js2); + SDL_JoystickClose(js2); + if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) + { + GameController2 = SDL_JoystickOpen(i); + break; + } + } + Inputsinit = true; + } + + // Dpad stuff here to set as any button + char DpadUpChar[256]; + char DpadDownChar[256]; + char DpadLeftChar[256]; + char DpadRightChar[256]; + char DpadUpCharDevice2[256]; + char DpadDownCharDevice2[256]; + char DpadLeftCharDevice2[256]; + char DpadRightCharDevice2[256]; + GetPrivateProfileStringA("Settings", "DpadUp", "", DpadUpChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDown", "", DpadDownChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeft", "", DpadLeftChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRight", "", DpadRightChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadUpDevice2", "", DpadUpCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDownDevice2", "", DpadDownCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeftDevice2", "", DpadLeftCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRightDevice2", "", DpadRightCharDevice2, 256, ".\\FFBplugin.ini"); + std::string exit("ExitButton"); + std::string test("TestButton"); + std::string service("ServiceButton"); + std::string coin("CoinButton"); + std::string view("ViewButton"); + std::string start("StartButton"); + std::string volup("VolumeUp"); + std::string voldown("VolumeDown"); + std::string emergency("EmergencyStop"); + std::string exit2("ExitButtonDevice2"); + std::string test2("TestButtonDevice2"); + std::string service2("ServiceButtonDevice2"); + std::string coin2("CoinButtonDevice2"); + std::string view2("ViewButtonDevice2"); + std::string start2("StartButtonDevice2"); + std::string volup2("VolumeUpDevice2"); + std::string voldown2("VolumeDownDevice2"); + std::string emergency2("EmergencyStopDevice2"); + std::string dpdup(DpadUpChar); + std::string dpddown(DpadDownChar); + std::string dpdleft(DpadLeftChar); + std::string dpdright(DpadRightChar); + std::string dpdup2(DpadUpCharDevice2); + std::string dpddown2(DpadDownCharDevice2); + std::string dpdleft2(DpadLeftCharDevice2); + std::string dpdright2(DpadRightCharDevice2); + + const int WHEEL_DEAD_ZONE = (SteeringDeadzone * 100.0); + const int ACCL_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int BRAKE_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int SETUP_DEAD_ZONE = 20000; + + UINT8 brakeread = helpers->ReadByte(BrakeAddress, false); + UINT8 servicetestread = helpers->ReadByte(ServiceTestAddress, false); + + while (SDL_WaitEvent(&e) != 0) + { + if ((e.type == SDL_JOYAXISMOTION) & (ShowAxisForSetup == 0)) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis == InputDeviceWheelSteeringAxis) + { + //Left of dead zone + if (e.jaxis.value < -WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - WHEEL_DEAD_ZONE; + SteeringValue = (128 + (e.jaxis.value + WHEEL_DEAD_ZONE) / 255); + } + //Right of dead zone + else if (e.jaxis.value > WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + WHEEL_DEAD_ZONE; + SteeringValue = (127 + (e.jaxis.value - WHEEL_DEAD_ZONE) / 255); + } + else if ((e.jaxis.value < WHEEL_DEAD_ZONE) & (e.jaxis.value > -WHEEL_DEAD_ZONE)) + { + SteeringValue = 0x7F; + } + + helpers->WriteByte(SteeringAddress, -SteeringValue - 1, false); + } + if (InputDeviceWheelReverseAxis == 1) + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128.5), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + BrakeValue = ((e.jaxis.value + ACCL_DEAD_ZONE) / 128); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0x00, false); + BrakeValue = 0x00; + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x10, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x10, false); + brakepressed = false; + } + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 - e.jaxis.value, false); + } + } + else if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 127 - e.jaxis.value; + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 128 - e.jaxis.value; + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x10, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x10, false); + brakepressed = false; + } + } + } + } + } + else + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + BrakeValue = ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0xFF, false); + BrakeValue = 0x00; + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x10, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x10, false); + brakepressed = false; + } + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 + e.jaxis.value, false); + } + } + if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 128 + e.jaxis.value; + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 127 + e.jaxis.value; + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x10, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x10, false); + brakepressed = false; + } + } + } + } + } + } + } + + if (ShowAxisForSetup == 1) + { + if (e.type == SDL_JOYAXISMOTION) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis >= 0) + { + if (e.jaxis.value < -SETUP_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - SETUP_DEAD_ZONE; + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + else if (e.jaxis.value > SETUP_DEAD_ZONE) + { + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + } + + if (ShowButtonNumbersForSetup == 1) + { + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jaxis.which == joystick_index1 || e.jaxis.which == joystick_index2) + { + if (e.jbutton.button >= 0) + { + char buff[100]; + sprintf_s(buff, "Button %d Pressed", e.jbutton.button); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + + if (e.jhat.type == SDL_JOYHATMOTION) + { + if (e.jhat.value == SDL_HAT_CENTERED) + { + if (e.jhat.which == joystick_index1) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + servicebuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x80, false); + startbuttonA = false; + } + if (volumeupA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + volumeupA = false; + } + if (volumedownA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + volumedownA = false; + } + if (emergencystopA) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x40, false); + emergencystopA = false; + } + if (coinA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + coinA = false; + } + } + else if (e.jhat.which == joystick_index2) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + servicebuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x80, false); + startbuttonA = false; + } + if (volumeupA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + volumeupA = false; + } + if (volumedownA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + volumedownA = false; + } + if (emergencystopA) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x40, false); + emergencystopA = false; + } + if (coinA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + coinA = false; + } + } + } + if (e.jhat.value == SDL_HAT_UP) + { + if (e.jhat.which == joystick_index1) + { + if (dpdup.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdup.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdup.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpdup.compare(emergency) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpdup.compare(start) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpdup.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpdup.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdup.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdup.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdup.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpdup.compare(emergency2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpdup.compare(start2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpdup.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpdup.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_DOWN) + { + if (e.jhat.which == joystick_index1) + { + if (dpddown.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpddown.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpddown.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpddown.compare(emergency) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpddown.compare(start) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpddown.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpddown.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpddown2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpddown2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpddown2.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpddown2.compare(emergency2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpddown2.compare(start2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpddown2.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpddown2.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_LEFT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdleft.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdleft.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdleft.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpdleft.compare(emergency) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpdleft.compare(start) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpdleft.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpdleft.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdleft2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdleft2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdleft2.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpdleft2.compare(emergency2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpdleft2.compare(start2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpdleft2.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpdleft2.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_RIGHT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdright.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdright.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdright.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpdright.compare(emergency) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpdright.compare(start) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpdright.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpdright.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdright2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdright2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdright2.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinA = true; + } + if (dpdright2.compare(emergency2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + emergencystopA = true; + } + if (dpdright2.compare(start2) == 0) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + startbuttonA = true; + } + if (dpdright2.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volumeupA = true; + } + if (dpdright2.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + volumedownA = true; + } + } + } + } + + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + } + if (e.jbutton.button == ExitButton) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == EmergencyStop) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + } + if (e.jbutton.button == VolumeUp) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + } + if (e.jbutton.button == VolumeDown) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + } + if (e.jbutton.button == ExitButtonDevice2) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == EmergencyStopDevice2) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x40, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x80, false); + } + if (e.jbutton.button == VolumeUpDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + } + if (e.jbutton.button == VolumeDownDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + } + } + } + if (e.type == SDL_JOYBUTTONUP) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == EmergencyStop) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x40, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x80, false); + } + if (e.jbutton.button == VolumeUp) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + } + if (e.jbutton.button == VolumeDown) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == EmergencyStopDevice2) + { + helpers->WriteByte(BrakeAddress, brakeread -= 0x40, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(BrakeAddress, brakeread += 0x80, false); + } + if (e.jbutton.button == VolumeUpDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + } + if (e.jbutton.button == VolumeDownDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + } + } + } + } +} \ No newline at end of file diff --git a/Game Files/DemulFasterThanSpeedInputs.cpp b/Game Files/DemulFasterThanSpeedInputs.cpp new file mode 100644 index 0000000..3c8341b --- /dev/null +++ b/Game Files/DemulFasterThanSpeedInputs.cpp @@ -0,0 +1,887 @@ +#include "../Common Files/Game.h" +#include +#include +#include "SDL.h" + +extern int joystick_index1; +extern int joystick_index2; +extern SDL_Joystick* GameController2; +static bool testbuttonA; +static bool servicebuttonA; +static bool startbuttonA; +static bool boostbuttonA; +static bool shiftupA; +static bool shiftdownA; +static bool coinA; +static bool Inputsinit = false; +static bool InputFind = false; +static SDL_Event e; + +extern INT_PTR SteeringAddress; +extern INT_PTR AcclAddress; +extern INT_PTR BrakeAddress; +extern INT_PTR ShiftUpDownAddress; +extern INT_PTR ServiceTestAddress; +extern INT_PTR CoinAddress; + +extern wchar_t* settingsFilename; +static int InputDeviceWheelEnable = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelEnable"), 0, settingsFilename); +static int InputDeviceWheelSteeringAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelSteeringAxis"), 0, settingsFilename); +static int InputDeviceWheelAcclAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelAcclAxis"), 0, settingsFilename); +static int InputDeviceWheelBrakeAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelBrakeAxis"), 0, settingsFilename); +static int InputDeviceWheelReverseAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelReverseAxis"), 0, settingsFilename); +static int InputDeviceCombinedPedals = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceCombinedPedals"), 0, settingsFilename); +static int SteeringDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("SteeringDeadzone"), 0, settingsFilename); +static int PedalDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("PedalDeadzone"), 0, settingsFilename); +static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename); +static int ShowAxisForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowAxisForSetup"), 0, settingsFilename); +static int ExitButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButton"), 0, settingsFilename); +static int TestButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButton"), 0, settingsFilename); +static int ServiceButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButton"), 0, settingsFilename); +static int CreditButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButton"), 0, settingsFilename); +static int BoostButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("BoostButton"), 0, settingsFilename); +static int StartButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButton"), 0, settingsFilename); +static int ShiftUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUp"), 0, settingsFilename); +static int ShiftDown = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDown"), 0, settingsFilename); +static int ExitButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButtonDevice2"), 0, settingsFilename); +static int TestButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButtonDevice2"), 0, settingsFilename); +static int ServiceButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButtonDevice2"), 0, settingsFilename); +static int CreditButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButtonDevice2"), 0, settingsFilename); +static int BoostButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("BoostButtonDevice2"), 0, settingsFilename); +static int StartButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButtonDevice2"), 0, settingsFilename); +static int ShiftUpDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUpDevice2"), 0, settingsFilename); +static int ShiftDownDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDownDevice2"), 0, settingsFilename); + +void FasterThanSpeedInputsEnabled(Helpers* helpers) +{ + if (!Inputsinit) + { + //Added 2nd device stuff from here + wchar_t* deviceGUIDString2 = new wchar_t[256]; + int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); + char joystick_guid[256]; + sprintf(joystick_guid, "%S", deviceGUIDString2); + SDL_JoystickGUID guid, dev_guid; + int numJoysticks = SDL_NumJoysticks(); + std::string njs = std::to_string(numJoysticks); + ((char)njs.c_str()); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + SDL_Joystick* js2 = SDL_JoystickOpen(i); + joystick_index2 = SDL_JoystickInstanceID(js2); + SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); + char guid_str[1024]; + SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); + const char* name = SDL_JoystickName(js2); + char text[256]; + sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); + guid = SDL_JoystickGetGUIDFromString(joystick_guid); + dev_guid = SDL_JoystickGetGUID(js2); + SDL_JoystickClose(js2); + if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) + { + GameController2 = SDL_JoystickOpen(i); + break; + } + } + Inputsinit = true; + } + + // Dpad stuff here to set as any button + char DpadUpChar[256]; + char DpadDownChar[256]; + char DpadLeftChar[256]; + char DpadRightChar[256]; + char DpadUpCharDevice2[256]; + char DpadDownCharDevice2[256]; + char DpadLeftCharDevice2[256]; + char DpadRightCharDevice2[256]; + GetPrivateProfileStringA("Settings", "DpadUp", "", DpadUpChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDown", "", DpadDownChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeft", "", DpadLeftChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRight", "", DpadRightChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadUpDevice2", "", DpadUpCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDownDevice2", "", DpadDownCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeftDevice2", "", DpadLeftCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRightDevice2", "", DpadRightCharDevice2, 256, ".\\FFBplugin.ini"); + std::string exit("ExitButton"); + std::string test("TestButton"); + std::string service("ServiceButton"); + std::string coin("CoinButton"); + std::string boost("BoostButton"); + std::string start("StartButton"); + std::string sftup("ShiftUp"); + std::string sftdown("ShiftDown"); + std::string exit2("ExitButtonDevice2"); + std::string test2("TestButtonDevice2"); + std::string service2("ServiceButtonDevice2"); + std::string coin2("CoinButtonDevice2"); + std::string boost2("BoostButtonDevice2"); + std::string start2("StartButtonDevice2"); + std::string sftup2("ShiftUpDevice2"); + std::string sftdown2("ShiftDownDevice2"); + std::string dpdup(DpadUpChar); + std::string dpddown(DpadDownChar); + std::string dpdleft(DpadLeftChar); + std::string dpdright(DpadRightChar); + std::string dpdup2(DpadUpCharDevice2); + std::string dpddown2(DpadDownCharDevice2); + std::string dpdleft2(DpadLeftCharDevice2); + std::string dpdright2(DpadRightCharDevice2); + + const int WHEEL_DEAD_ZONE = (SteeringDeadzone * 100.0); + const int ACCL_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int BRAKE_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int SETUP_DEAD_ZONE = 20000; + + UINT8 shiftupdownread = helpers->ReadByte(ShiftUpDownAddress, false); + UINT8 coinread = helpers->ReadByte(CoinAddress, false); + UINT8 servicetestread = helpers->ReadByte(ServiceTestAddress, false); + + while (SDL_WaitEvent(&e) != 0) + { + if ((e.type == SDL_JOYAXISMOTION) & (ShowAxisForSetup == 0)) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis == InputDeviceWheelSteeringAxis) + { + //Left of dead zone + if (e.jaxis.value < -WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (128 + (e.jaxis.value + WHEEL_DEAD_ZONE) / 255), false); + } + //Right of dead zone + else if (e.jaxis.value > WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (127 + (e.jaxis.value - WHEEL_DEAD_ZONE) / 255), false); + } + else if ((e.jaxis.value < WHEEL_DEAD_ZONE) & (e.jaxis.value > -WHEEL_DEAD_ZONE)) + { + helpers->WriteByte(SteeringAddress, 0x7F, false); + } + } + if (InputDeviceWheelReverseAxis == 1) + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128.5), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 - e.jaxis.value, false); + } + } + else if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 - e.jaxis.value, false); + } + } + } + } + else + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0xFF, false); + helpers->WriteByte(BrakeAddress, 0xFF, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 + e.jaxis.value, false); + } + } + if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 + e.jaxis.value, false); + } + } + } + } + } + } + + if (ShowAxisForSetup == 1) + { + if (e.type == SDL_JOYAXISMOTION) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis >= 0) + { + if (e.jaxis.value < -SETUP_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - SETUP_DEAD_ZONE; + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + else if (e.jaxis.value > SETUP_DEAD_ZONE) + { + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + } + + if (ShowButtonNumbersForSetup == 1) + { + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jaxis.which == joystick_index1 || e.jaxis.which == joystick_index2) + { + if (e.jbutton.button >= 0) + { + char buff[100]; + sprintf_s(buff, "Button %d Pressed", e.jbutton.button); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + + if (e.jhat.type == SDL_JOYHATMOTION) + { + if (e.jhat.value == SDL_HAT_CENTERED) + { + if (e.jhat.which == joystick_index1) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + servicebuttonA = false; + } + if (boostbuttonA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x04, false); + boostbuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + startbuttonA = false; + } + if (shiftupA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftupA = false; + } + if (shiftdownA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftdownA = false; + } + if (coinA) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + coinA = false; + } + } + else if (e.jhat.which == joystick_index2) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + servicebuttonA = false; + } + if (boostbuttonA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x04, false); + boostbuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + startbuttonA = false; + } + if (shiftupA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftupA = false; + } + if (shiftdownA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftdownA = false; + } + if (coinA) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + coinA = false; + } + } + } + if (e.jhat.value == SDL_HAT_UP) + { + if (e.jhat.which == joystick_index1) + { + if (dpdup.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdup.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdup.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdup.compare(boost) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpdup.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpdup.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdup.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdup2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdup2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdup2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdup2.compare(boost2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpdup2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpdup2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdup2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_DOWN) + { + if (e.jhat.which == joystick_index1) + { + if (dpddown.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpddown.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpddown.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpddown.compare(boost) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpddown.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpddown.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpddown.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpddown2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpddown2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpddown2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpddown2.compare(boost2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpddown2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpddown2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpddown2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_LEFT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdleft.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdleft.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdleft.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdleft.compare(boost) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpdleft.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdleft.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdleft.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdleft2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdleft2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdleft2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdleft2.compare(boost2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpdleft2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdleft2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdleft2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_RIGHT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdright.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdright.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdright.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdright.compare(boost) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpdright.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdright.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdright.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdright2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdright2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdright2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdright2.compare(boost2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + boostbuttonA = true; + } + if (dpdright2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdright2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdright2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + } + + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + } + if (e.jbutton.button == ExitButton) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + } + if (e.jbutton.button == BoostButton) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + } + if (e.jbutton.button == ShiftUp) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + } + if (e.jbutton.button == ShiftDown) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + } + if (e.jbutton.button == ExitButtonDevice2) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + } + if (e.jbutton.button == BoostButtonDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x04, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + } + if (e.jbutton.button == ShiftUpDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + } + if (e.jbutton.button == ShiftDownDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + } + } + } + if (e.type == SDL_JOYBUTTONUP) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (e.jbutton.button == BoostButton) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x04, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + } + if (e.jbutton.button == ShiftUp) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + } + if (e.jbutton.button == ShiftDown) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (e.jbutton.button == BoostButtonDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x04, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + } + if (e.jbutton.button == ShiftUpDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + } + if (e.jbutton.button == ShiftDownDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + } + } + } + } +} \ No newline at end of file diff --git a/Game Files/DemulInitialDInputs.cpp b/Game Files/DemulInitialDInputs.cpp new file mode 100644 index 0000000..9f35d51 --- /dev/null +++ b/Game Files/DemulInitialDInputs.cpp @@ -0,0 +1,863 @@ +#include "../Common Files/Game.h" +#include +#include +#include "SDL.h" + +extern int joystick_index1; +extern int joystick_index2; +extern SDL_Joystick* GameController2; +static bool testbuttonA; +static bool servicebuttonA; +static bool startbuttonA; +static bool viewbuttonA; +static bool shiftupA; +static bool shiftdownA; +static bool coinA; +static bool Inputsinit = false; +static bool InputFind = false; +static SDL_Event e; + +extern INT_PTR SteeringAddress; +extern INT_PTR AcclAddress; +extern INT_PTR BrakeAddress; +extern INT_PTR StartViewAddress; +extern INT_PTR ShiftUpDownAddress; +extern INT_PTR ServiceTestAddress; +extern INT_PTR CoinAddress; + +extern wchar_t* settingsFilename; +static int InputDeviceWheelEnable = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelEnable"), 0, settingsFilename); +static int InputDeviceWheelSteeringAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelSteeringAxis"), 0, settingsFilename); +static int InputDeviceWheelAcclAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelAcclAxis"), 0, settingsFilename); +static int InputDeviceWheelBrakeAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelBrakeAxis"), 0, settingsFilename); +static int InputDeviceWheelReverseAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelReverseAxis"), 0, settingsFilename); +static int InputDeviceCombinedPedals = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceCombinedPedals"), 0, settingsFilename); +static int SteeringDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("SteeringDeadzone"), 0, settingsFilename); +static int PedalDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("PedalDeadzone"), 0, settingsFilename); +static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename); +static int ShowAxisForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowAxisForSetup"), 0, settingsFilename); +static int ExitButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButton"), 0, settingsFilename); +static int TestButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButton"), 0, settingsFilename); +static int ServiceButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButton"), 0, settingsFilename); +static int CreditButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButton"), 0, settingsFilename); +static int ViewButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ViewButton"), 0, settingsFilename); +static int StartButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButton"), 0, settingsFilename); +static int ShiftUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUp"), 0, settingsFilename); +static int ShiftDown = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDown"), 0, settingsFilename); +static int ExitButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButtonDevice2"), 0, settingsFilename); +static int TestButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButtonDevice2"), 0, settingsFilename); +static int ServiceButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButtonDevice2"), 0, settingsFilename); +static int CreditButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButtonDevice2"), 0, settingsFilename); +static int ViewButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ViewButtonDevice2"), 0, settingsFilename); +static int StartButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButtonDevice2"), 0, settingsFilename); +static int ShiftUpDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUpDevice2"), 0, settingsFilename); +static int ShiftDownDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDownDevice2"), 0, settingsFilename); + +void InitialDInputsEnabled(Helpers* helpers) +{ + if (!Inputsinit) + { + //Added 2nd device stuff from here + wchar_t* deviceGUIDString2 = new wchar_t[256]; + int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); + char joystick_guid[256]; + sprintf(joystick_guid, "%S", deviceGUIDString2); + SDL_JoystickGUID guid, dev_guid; + int numJoysticks = SDL_NumJoysticks(); + std::string njs = std::to_string(numJoysticks); + ((char)njs.c_str()); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + SDL_Joystick* js2 = SDL_JoystickOpen(i); + joystick_index2 = SDL_JoystickInstanceID(js2); + SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); + char guid_str[1024]; + SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); + const char* name = SDL_JoystickName(js2); + char text[256]; + sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); + guid = SDL_JoystickGetGUIDFromString(joystick_guid); + dev_guid = SDL_JoystickGetGUID(js2); + SDL_JoystickClose(js2); + if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) + { + GameController2 = SDL_JoystickOpen(i); + break; + } + } + Inputsinit = true; + } + + // Dpad stuff here to set as any button + char DpadUpChar[256]; + char DpadDownChar[256]; + char DpadLeftChar[256]; + char DpadRightChar[256]; + char DpadUpCharDevice2[256]; + char DpadDownCharDevice2[256]; + char DpadLeftCharDevice2[256]; + char DpadRightCharDevice2[256]; + GetPrivateProfileStringA("Settings", "DpadUp", "", DpadUpChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDown", "", DpadDownChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeft", "", DpadLeftChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRight", "", DpadRightChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadUpDevice2", "", DpadUpCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDownDevice2", "", DpadDownCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeftDevice2", "", DpadLeftCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRightDevice2", "", DpadRightCharDevice2, 256, ".\\FFBplugin.ini"); + std::string exit("ExitButton"); + std::string test("TestButton"); + std::string service("ServiceButton"); + std::string coin("CoinButton"); + std::string view("ViewButton"); + std::string start("StartButton"); + std::string sftup("ShiftUp"); + std::string sftdown("ShiftDown"); + std::string exit2("ExitButtonDevice2"); + std::string test2("TestButtonDevice2"); + std::string service2("ServiceButtonDevice2"); + std::string coin2("CoinButtonDevice2"); + std::string view2("ViewButtonDevice2"); + std::string start2("StartButtonDevice2"); + std::string sftup2("ShiftUpDevice2"); + std::string sftdown2("ShiftDownDevice2"); + std::string dpdup(DpadUpChar); + std::string dpddown(DpadDownChar); + std::string dpdleft(DpadLeftChar); + std::string dpdright(DpadRightChar); + std::string dpdup2(DpadUpCharDevice2); + std::string dpddown2(DpadDownCharDevice2); + std::string dpdleft2(DpadLeftCharDevice2); + std::string dpdright2(DpadRightCharDevice2); + + const int WHEEL_DEAD_ZONE = (SteeringDeadzone * 100.0); + const int ACCL_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int BRAKE_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int SETUP_DEAD_ZONE = 20000; + + UINT8 startviewread = helpers->ReadByte(StartViewAddress, false); + UINT8 shiftupdownread = helpers->ReadByte(ShiftUpDownAddress, false); + UINT8 coinread = helpers->ReadByte(CoinAddress, false); + UINT8 servicetestread = helpers->ReadByte(ServiceTestAddress, false); + + while (SDL_WaitEvent(&e) != 0) + { + if ((e.type == SDL_JOYAXISMOTION) & (ShowAxisForSetup == 0)) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis == InputDeviceWheelSteeringAxis) + { + //Left of dead zone + if (e.jaxis.value < -WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (128 + (e.jaxis.value + WHEEL_DEAD_ZONE) / 255), false); + } + //Right of dead zone + else if (e.jaxis.value > WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (127 + (e.jaxis.value - WHEEL_DEAD_ZONE) / 255), false); + } + else if ((e.jaxis.value < WHEEL_DEAD_ZONE) & (e.jaxis.value > -WHEEL_DEAD_ZONE)) + { + helpers->WriteByte(SteeringAddress, 0x7F, false); + } + } + if (InputDeviceWheelReverseAxis == 1) + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128.5), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 - e.jaxis.value, false); + } + } + else if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 - e.jaxis.value, false); + } + } + } + } + else + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0xFF, false); + helpers->WriteByte(BrakeAddress, 0xFF, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 + e.jaxis.value, false); + } + } + if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 + e.jaxis.value, false); + } + } + } + } + } + } + + if (ShowAxisForSetup == 1) + { + if (e.type == SDL_JOYAXISMOTION) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis >= 0) + { + if (e.jaxis.value < -SETUP_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - SETUP_DEAD_ZONE; + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + else if (e.jaxis.value > SETUP_DEAD_ZONE) + { + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + } + + if (ShowButtonNumbersForSetup == 1) + { + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jaxis.which == joystick_index1 || e.jaxis.which == joystick_index2) + { + if (e.jbutton.button >= 0) + { + char buff[100]; + sprintf_s(buff, "Button %d Pressed", e.jbutton.button); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + + if (e.jhat.type == SDL_JOYHATMOTION) + { + if (e.jhat.value == SDL_HAT_CENTERED) + { + if (e.jhat.which == joystick_index1) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x10, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + servicebuttonA = false; + } + if (viewbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + viewbuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + startbuttonA = false; + } + if (shiftupA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftupA = false; + } + if (shiftdownA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftdownA = false; + } + } + else if (e.jhat.which == joystick_index2) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x10, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + servicebuttonA = false; + } + if (viewbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + viewbuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + startbuttonA = false; + } + if (shiftupA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftupA = false; + } + if (shiftdownA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftdownA = false; + } + } + } + if (e.jhat.value == SDL_HAT_UP) + { + if (e.jhat.which == joystick_index1) + { + if (dpdup.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpdup.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdup.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpdup.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdup.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdup.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpdup.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdup2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpdup2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdup2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpdup2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdup2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdup2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpdup2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_DOWN) + { + if (e.jhat.which == joystick_index1) + { + if (dpddown.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpddown.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpddown.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpddown.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpddown.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpddown.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpddown.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpddown2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpddown2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpddown2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpddown2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpddown2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpddown2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpddown2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_LEFT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdleft.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpdleft.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdleft.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpdleft.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdleft.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdleft.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpdleft.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdleft2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpdleft2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdleft2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpdleft2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdleft2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdleft2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpdleft2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_RIGHT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdright.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpdright.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdright.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpdright.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdright.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdright.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpdright.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdright2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + testbuttonA = true; + } + if (dpdright2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + testbuttonA = true; + } + if (dpdright2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (dpdright2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdright2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdright2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftupA = true; + } + if (dpdright2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftdownA = true; + } + } + } + } + + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + } + if (e.jbutton.button == ExitButton) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (e.jbutton.button == ViewButton) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + } + if (e.jbutton.button == ShiftUp) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + } + if (e.jbutton.button == ShiftDown) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x10, false); + } + if (e.jbutton.button == ExitButtonDevice2) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (e.jbutton.button == ViewButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + } + if (e.jbutton.button == ShiftUpDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + } + if (e.jbutton.button == ShiftDownDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + } + } + } + if (e.type == SDL_JOYBUTTONUP) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x10, false); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == ViewButton) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + } + if (e.jbutton.button == ShiftUp) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + } + if (e.jbutton.button == ShiftDown) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x10, false); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == ViewButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + } + if (e.jbutton.button == ShiftUpDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + } + if (e.jbutton.button == ShiftDownDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + } + } + } + } +} \ No newline at end of file diff --git a/Game Files/DemulMaximumSpeedInputs.cpp b/Game Files/DemulMaximumSpeedInputs.cpp new file mode 100644 index 0000000..89a8a5a --- /dev/null +++ b/Game Files/DemulMaximumSpeedInputs.cpp @@ -0,0 +1,816 @@ +#include "../Common Files/Game.h" +#include +#include +#include "SDL.h" + +extern int joystick_index1; +extern int joystick_index2; +extern SDL_Joystick* GameController2; +static bool testbuttonA; +static bool servicebuttonA; +static bool startbuttonA; +static bool shiftupA; +static bool shiftdownA; +static bool coinA; +static bool Inputsinit = false; +static bool InputFind = false; +static SDL_Event e; + +extern INT_PTR SteeringAddress; +extern INT_PTR AcclAddress; +extern INT_PTR BrakeAddress; +extern INT_PTR ShiftUpDownAddress; +extern INT_PTR ServiceTestAddress; +extern INT_PTR CoinAddress; + +extern wchar_t* settingsFilename; +static int InputDeviceWheelEnable = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelEnable"), 0, settingsFilename); +static int InputDeviceWheelSteeringAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelSteeringAxis"), 0, settingsFilename); +static int InputDeviceWheelAcclAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelAcclAxis"), 0, settingsFilename); +static int InputDeviceWheelBrakeAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelBrakeAxis"), 0, settingsFilename); +static int InputDeviceWheelReverseAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelReverseAxis"), 0, settingsFilename); +static int InputDeviceCombinedPedals = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceCombinedPedals"), 0, settingsFilename); +static int SteeringDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("SteeringDeadzone"), 0, settingsFilename); +static int PedalDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("PedalDeadzone"), 0, settingsFilename); +static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename); +static int ShowAxisForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowAxisForSetup"), 0, settingsFilename); +static int ExitButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButton"), 0, settingsFilename); +static int TestButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButton"), 0, settingsFilename); +static int ServiceButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButton"), 0, settingsFilename); +static int CreditButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButton"), 0, settingsFilename); +static int StartButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButton"), 0, settingsFilename); +static int ShiftUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUp"), 0, settingsFilename); +static int ShiftDown = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDown"), 0, settingsFilename); +static int ExitButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButtonDevice2"), 0, settingsFilename); +static int TestButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButtonDevice2"), 0, settingsFilename); +static int ServiceButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButtonDevice2"), 0, settingsFilename); +static int CreditButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButtonDevice2"), 0, settingsFilename); +static int StartButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButtonDevice2"), 0, settingsFilename); +static int ShiftUpDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUpDevice2"), 0, settingsFilename); +static int ShiftDownDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDownDevice2"), 0, settingsFilename); + +void MaximumSpeedInputsEnabled(Helpers* helpers) +{ + if (!Inputsinit) + { + //Added 2nd device stuff from here + wchar_t* deviceGUIDString2 = new wchar_t[256]; + int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); + char joystick_guid[256]; + sprintf(joystick_guid, "%S", deviceGUIDString2); + SDL_JoystickGUID guid, dev_guid; + int numJoysticks = SDL_NumJoysticks(); + std::string njs = std::to_string(numJoysticks); + ((char)njs.c_str()); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + SDL_Joystick* js2 = SDL_JoystickOpen(i); + joystick_index2 = SDL_JoystickInstanceID(js2); + SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); + char guid_str[1024]; + SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); + const char* name = SDL_JoystickName(js2); + char text[256]; + sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); + guid = SDL_JoystickGetGUIDFromString(joystick_guid); + dev_guid = SDL_JoystickGetGUID(js2); + SDL_JoystickClose(js2); + if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) + { + GameController2 = SDL_JoystickOpen(i); + break; + } + } + Inputsinit = true; + } + + // Dpad stuff here to set as any button + char DpadUpChar[256]; + char DpadDownChar[256]; + char DpadLeftChar[256]; + char DpadRightChar[256]; + char DpadUpCharDevice2[256]; + char DpadDownCharDevice2[256]; + char DpadLeftCharDevice2[256]; + char DpadRightCharDevice2[256]; + GetPrivateProfileStringA("Settings", "DpadUp", "", DpadUpChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDown", "", DpadDownChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeft", "", DpadLeftChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRight", "", DpadRightChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadUpDevice2", "", DpadUpCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDownDevice2", "", DpadDownCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeftDevice2", "", DpadLeftCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRightDevice2", "", DpadRightCharDevice2, 256, ".\\FFBplugin.ini"); + std::string exit("ExitButton"); + std::string test("TestButton"); + std::string service("ServiceButton"); + std::string coin("CoinButton"); + std::string start("StartButton"); + std::string sftup("ShiftUp"); + std::string sftdown("ShiftDown"); + std::string exit2("ExitButtonDevice2"); + std::string test2("TestButtonDevice2"); + std::string service2("ServiceButtonDevice2"); + std::string coin2("CoinButtonDevice2"); + std::string start2("StartButtonDevice2"); + std::string sftup2("ShiftUpDevice2"); + std::string sftdown2("ShiftDownDevice2"); + std::string dpdup(DpadUpChar); + std::string dpddown(DpadDownChar); + std::string dpdleft(DpadLeftChar); + std::string dpdright(DpadRightChar); + std::string dpdup2(DpadUpCharDevice2); + std::string dpddown2(DpadDownCharDevice2); + std::string dpdleft2(DpadLeftCharDevice2); + std::string dpdright2(DpadRightCharDevice2); + + const int WHEEL_DEAD_ZONE = (SteeringDeadzone * 100.0); + const int ACCL_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int BRAKE_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int SETUP_DEAD_ZONE = 20000; + + UINT8 shiftupdownread = helpers->ReadByte(ShiftUpDownAddress, false); + UINT8 coinread = helpers->ReadByte(CoinAddress, false); + UINT8 servicetestread = helpers->ReadByte(ServiceTestAddress, false); + + while (SDL_WaitEvent(&e) != 0) + { + if ((e.type == SDL_JOYAXISMOTION) & (ShowAxisForSetup == 0)) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis == InputDeviceWheelSteeringAxis) + { + //Left of dead zone + if (e.jaxis.value < -WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (128 + (e.jaxis.value + WHEEL_DEAD_ZONE) / 255), false); + } + //Right of dead zone + else if (e.jaxis.value > WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (127 + (e.jaxis.value - WHEEL_DEAD_ZONE) / 255), false); + } + else if ((e.jaxis.value < WHEEL_DEAD_ZONE) & (e.jaxis.value > -WHEEL_DEAD_ZONE)) + { + helpers->WriteByte(SteeringAddress, 0x7F, false); + } + } + if (InputDeviceWheelReverseAxis == 1) + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128.5), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 - e.jaxis.value, false); + } + } + else if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 - e.jaxis.value, false); + } + } + } + } + else + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0xFF, false); + helpers->WriteByte(BrakeAddress, 0xFF, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 + e.jaxis.value, false); + } + } + if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 + e.jaxis.value, false); + } + } + } + } + } + } + + if (ShowAxisForSetup == 1) + { + if (e.type == SDL_JOYAXISMOTION) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis >= 0) + { + if (e.jaxis.value < -SETUP_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - SETUP_DEAD_ZONE; + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + else if (e.jaxis.value > SETUP_DEAD_ZONE) + { + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + } + + if (ShowButtonNumbersForSetup == 1) + { + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jaxis.which == joystick_index1 || e.jaxis.which == joystick_index2) + { + if (e.jbutton.button >= 0) + { + char buff[100]; + sprintf_s(buff, "Button %d Pressed", e.jbutton.button); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + + if (e.jhat.type == SDL_JOYHATMOTION) + { + if (e.jhat.value == SDL_HAT_CENTERED) + { + if (e.jhat.which == joystick_index1) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + servicebuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + startbuttonA = false; + } + if (shiftupA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftupA = false; + } + if (shiftdownA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftdownA = false; + } + if (coinA) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + coinA = false; + } + } + else if (e.jhat.which == joystick_index2) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + servicebuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + startbuttonA = false; + } + if (shiftupA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + shiftupA = false; + } + if (shiftdownA) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + shiftdownA = false; + } + if (coinA) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + coinA = false; + } + } + } + if (e.jhat.value == SDL_HAT_UP) + { + if (e.jhat.which == joystick_index1) + { + if (dpdup.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdup.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdup.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdup.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpdup.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdup.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdup2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdup2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdup2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdup2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpdup2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdup2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_DOWN) + { + if (e.jhat.which == joystick_index1) + { + if (dpddown.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpddown.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpddown.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpddown.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpddown.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpddown.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpddown2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpddown2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpddown2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpddown2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + startbuttonA = true; + } + if (dpddown2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpddown2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_LEFT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdleft.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdleft.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdleft.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdleft.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdleft.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdleft.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdleft2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdleft2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdleft2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdleft2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdleft2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdleft2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_RIGHT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdright.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdright.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdright.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdright.compare(start) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdright.compare(sftup) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdright.compare(sftdown) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdright2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + testbuttonA = true; + } + if (dpdright2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + servicebuttonA = true; + } + if (dpdright2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + coinA = true; + } + if (dpdright2.compare(start2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x80, false); + startbuttonA = true; + } + if (dpdright2.compare(sftup2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + shiftupA = true; + } + if (dpdright2.compare(sftdown2) == 0) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + shiftdownA = true; + } + } + } + } + + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + } + if (e.jbutton.button == ExitButton) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + } + if (e.jbutton.button == ShiftUp) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + } + if (e.jbutton.button == ShiftDown) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x40, false); + } + if (e.jbutton.button == ExitButtonDevice2) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(CoinAddress, coinread -= 0x01, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x08, false); + } + if (e.jbutton.button == ShiftUpDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x10, false); + } + if (e.jbutton.button == ShiftDownDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread -= 0x20, false); + } + } + } + if (e.type == SDL_JOYBUTTONUP) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + } + if (e.jbutton.button == ShiftUp) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + } + if (e.jbutton.button == ShiftDown) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x40, false); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x08, false); + } + if (e.jbutton.button == ShiftUpDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x10, false); + } + if (e.jbutton.button == ShiftDownDevice2) + { + helpers->WriteByte(ShiftUpDownAddress, shiftupdownread += 0x20, false); + } + } + } + } +} \ No newline at end of file diff --git a/Game Files/DemulNascarInputs.cpp b/Game Files/DemulNascarInputs.cpp new file mode 100644 index 0000000..e44730d --- /dev/null +++ b/Game Files/DemulNascarInputs.cpp @@ -0,0 +1,1104 @@ +#include "../Common Files/Game.h" +#include +#include +#include "SDL.h" + +extern int joystick_index1; +extern int joystick_index2; +extern SDL_Joystick* GameController2; +static bool testbuttonA; +static bool servicebuttonA; +static bool startbuttonA; +static bool viewbuttonA; +static bool shiftupA; +static bool shiftdownA; +static bool coinA; +static bool Inputsinit = false; +static bool InputFind = false; +static SDL_Event e; + +extern INT_PTR SteeringAddress; +extern INT_PTR AcclAddress; +extern INT_PTR BrakeAddress; +extern INT_PTR StartViewAddress; +extern INT_PTR ShiftUpDownAddress; +extern INT_PTR ServiceTestAddress; +extern INT_PTR CoinAddress; + +extern wchar_t* settingsFilename; +static int InputDeviceWheelEnable = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelEnable"), 0, settingsFilename); +static int InputDeviceWheelSteeringAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelSteeringAxis"), 0, settingsFilename); +static int InputDeviceWheelAcclAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelAcclAxis"), 0, settingsFilename); +static int InputDeviceWheelBrakeAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelBrakeAxis"), 0, settingsFilename); +static int InputDeviceWheelReverseAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelReverseAxis"), 0, settingsFilename); +static int InputDeviceCombinedPedals = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceCombinedPedals"), 0, settingsFilename); +static int SteeringDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("SteeringDeadzone"), 0, settingsFilename); +static int PedalDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("PedalDeadzone"), 0, settingsFilename); +static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename); +static int ShowAxisForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowAxisForSetup"), 0, settingsFilename); +static int ExitButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButton"), 0, settingsFilename); +static int TestButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButton"), 0, settingsFilename); +static int ServiceButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButton"), 0, settingsFilename); +static int CreditButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButton"), 0, settingsFilename); +static int ViewButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ViewButton"), 0, settingsFilename); +static int StartButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButton"), 0, settingsFilename); +static int ShiftUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUp"), 0, settingsFilename); +static int ShiftDown = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDown"), 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 ExitButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButtonDevice2"), 0, settingsFilename); +static int TestButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButtonDevice2"), 0, settingsFilename); +static int ServiceButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButtonDevice2"), 0, settingsFilename); +static int CreditButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButtonDevice2"), 0, settingsFilename); +static int ViewButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ViewButtonDevice2"), 0, settingsFilename); +static int StartButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButtonDevice2"), 0, settingsFilename); +static int ShiftUpDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftUpDevice2"), 0, settingsFilename); +static int ShiftDownDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShiftDownDevice2"), 0, settingsFilename); +static int Gear1Device2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear1Device2"), 0, settingsFilename); +static int Gear2Device2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear2Device2"), 0, settingsFilename); +static int Gear3Device2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear3Device2"), 0, settingsFilename); +static int Gear4Device2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("Gear4Device2"), 0, settingsFilename); + +void NascarInputsEnabled(Helpers* helpers) +{ + if (!Inputsinit) + { + //Added 2nd device stuff from here + wchar_t* deviceGUIDString2 = new wchar_t[256]; + int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); + char joystick_guid[256]; + sprintf(joystick_guid, "%S", deviceGUIDString2); + SDL_JoystickGUID guid, dev_guid; + int numJoysticks = SDL_NumJoysticks(); + std::string njs = std::to_string(numJoysticks); + ((char)njs.c_str()); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + SDL_Joystick* js2 = SDL_JoystickOpen(i); + joystick_index2 = SDL_JoystickInstanceID(js2); + SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); + char guid_str[1024]; + SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); + const char* name = SDL_JoystickName(js2); + char text[256]; + sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); + guid = SDL_JoystickGetGUIDFromString(joystick_guid); + dev_guid = SDL_JoystickGetGUID(js2); + SDL_JoystickClose(js2); + if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) + { + GameController2 = SDL_JoystickOpen(i); + break; + } + } + Inputsinit = true; + } + + // Dpad stuff here to set as any button + char DpadUpChar[256]; + char DpadDownChar[256]; + char DpadLeftChar[256]; + char DpadRightChar[256]; + char DpadUpCharDevice2[256]; + char DpadDownCharDevice2[256]; + char DpadLeftCharDevice2[256]; + char DpadRightCharDevice2[256]; + GetPrivateProfileStringA("Settings", "DpadUp", "", DpadUpChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDown", "", DpadDownChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeft", "", DpadLeftChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRight", "", DpadRightChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadUpDevice2", "", DpadUpCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDownDevice2", "", DpadDownCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeftDevice2", "", DpadLeftCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRightDevice2", "", DpadRightCharDevice2, 256, ".\\FFBplugin.ini"); + std::string exit("ExitButton"); + std::string test("TestButton"); + std::string service("ServiceButton"); + std::string coin("CoinButton"); + std::string view("ViewButton"); + std::string start("StartButton"); + std::string sftup("ShiftUp"); + std::string sftdown("ShiftDown"); + std::string exit2("ExitButtonDevice2"); + std::string test2("TestButtonDevice2"); + std::string service2("ServiceButtonDevice2"); + std::string coin2("CoinButtonDevice2"); + std::string view2("ViewButtonDevice2"); + std::string start2("StartButtonDevice2"); + std::string sftup2("ShiftUpDevice2"); + std::string sftdown2("ShiftDownDevice2"); + std::string dpdup(DpadUpChar); + std::string dpddown(DpadDownChar); + std::string dpdleft(DpadLeftChar); + std::string dpdright(DpadRightChar); + std::string dpdup2(DpadUpCharDevice2); + std::string dpddown2(DpadDownCharDevice2); + std::string dpdleft2(DpadLeftCharDevice2); + std::string dpdright2(DpadRightCharDevice2); + + const int WHEEL_DEAD_ZONE = (SteeringDeadzone * 100.0); + const int ACCL_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int BRAKE_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int SETUP_DEAD_ZONE = 20000; + + UINT8 startviewread = helpers->ReadByte(StartViewAddress, false); + UINT8 shiftupdownread = helpers->ReadByte(ShiftUpDownAddress, false); + UINT8 coinread = helpers->ReadByte(CoinAddress, false); + UINT8 servicetestread = helpers->ReadByte(ServiceTestAddress, false); + + while (SDL_WaitEvent(&e) != 0) + { + UINT8 shiftupdownreadA = helpers->ReadByte(ShiftUpDownAddress, false); + if ((e.type == SDL_JOYAXISMOTION) & (ShowAxisForSetup == 0)) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis == InputDeviceWheelSteeringAxis) + { + //Left of dead zone + if (e.jaxis.value < -WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (128 + (e.jaxis.value + WHEEL_DEAD_ZONE) / 255), false); + } + //Right of dead zone + else if (e.jaxis.value > WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (127 + (e.jaxis.value - WHEEL_DEAD_ZONE) / 255), false); + } + else if ((e.jaxis.value < WHEEL_DEAD_ZONE) & (e.jaxis.value > -WHEEL_DEAD_ZONE)) + { + helpers->WriteByte(SteeringAddress, 0x7F, false); + } + } + if (InputDeviceWheelReverseAxis == 1) + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128.5), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0x00, false); + helpers->WriteByte(BrakeAddress, 0x00, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 - e.jaxis.value, false); + } + } + else if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 - e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 - e.jaxis.value, false); + } + } + } + } + else + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + helpers->WriteByte(AcclAddress, ((e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + helpers->WriteByte(BrakeAddress, ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128), false); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + helpers->WriteByte(AcclAddress, 0xFF, false); + helpers->WriteByte(BrakeAddress, 0xFF, false); + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(AcclAddress, 127 + e.jaxis.value, false); + } + } + if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 128 + e.jaxis.value, false); + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + helpers->WriteByte(BrakeAddress, 127 + e.jaxis.value, false); + } + } + } + } + } + } + + if (ShowAxisForSetup == 1) + { + if (e.type == SDL_JOYAXISMOTION) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis >= 0) + { + if (e.jaxis.value < -SETUP_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - SETUP_DEAD_ZONE; + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + else if (e.jaxis.value > SETUP_DEAD_ZONE) + { + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + } + + if (ShowButtonNumbersForSetup == 1) + { + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jaxis.which == joystick_index1 || e.jaxis.which == joystick_index2) + { + if (e.jbutton.button >= 0) + { + char buff[100]; + sprintf_s(buff, "Button %d Pressed", e.jbutton.button); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + + if (e.jhat.type == SDL_JOYHATMOTION) + { + if (e.jhat.value == SDL_HAT_CENTERED) + { + if (e.jhat.which == joystick_index1) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + servicebuttonA = false; + } + if (viewbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + viewbuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + startbuttonA = false; + } + if (shiftupA) + { + shiftupA = false; + } + if (shiftdownA) + { + shiftdownA = false; + } + } + else if (e.jhat.which == joystick_index2) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + servicebuttonA = false; + } + if (viewbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + viewbuttonA = false; + } + if (startbuttonA) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + startbuttonA = false; + } + if (shiftupA) + { + shiftupA = false; + } + if (shiftdownA) + { + shiftdownA = false; + } + } + } + if (e.jhat.value == SDL_HAT_UP) + { + if (e.jhat.which == joystick_index1) + { + if (dpdup.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdup.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpdup.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpdup.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdup.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdup.compare(sftup) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpdup.compare(sftdown) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdup2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdup2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpdup2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpdup2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdup2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdup2.compare(sftup2) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpdup2.compare(sftdown2) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_DOWN) + { + if (e.jhat.which == joystick_index1) + { + if (dpddown.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpddown.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpddown.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpddown.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpddown.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpddown.compare(sftup) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpddown.compare(sftdown) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpddown2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpddown2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpddown2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpddown2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpddown2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpddown2.compare(sftup2) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpddown2.compare(sftdown2) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_LEFT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdleft.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdleft.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpdleft.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpdleft.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdleft.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdleft.compare(sftup) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpdleft.compare(sftdown) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdleft2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdleft2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpdleft2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpdleft2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdleft2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdleft2.compare(sftup2) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpdleft2.compare(sftdown2) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_RIGHT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdright.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdright.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpdright.compare(coin) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpdright.compare(view) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdright.compare(start) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdright.compare(sftup) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpdright.compare(sftdown) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdright2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdright2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + servicebuttonA = true; + } + if (dpdright2.compare(coin2) == 0) + { + helpers->WriteByte(CoinAddress, coinread += 0x01, false); + } + if (dpdright2.compare(view2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + viewbuttonA = true; + } + if (dpdright2.compare(start2) == 0) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + startbuttonA = true; + } + if (dpdright2.compare(sftup2) == 0) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + shiftupA = true; + } + if (dpdright2.compare(sftdown2) == 0) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + shiftdownA = true; + } + } + } + } + + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + } + if (e.jbutton.button == ExitButton) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (e.jbutton.button == ViewButton) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + } + if (e.jbutton.button == Gear1) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (e.jbutton.button == Gear2) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (e.jbutton.button == Gear3) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (e.jbutton.button == Gear4) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + if (e.jbutton.button == ShiftUp) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + } + if (e.jbutton.button == ShiftDown) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + } + if (e.jbutton.button == ExitButtonDevice2) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(CoinAddress, ++coinread, false); + } + if (e.jbutton.button == ViewButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x10, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread += 0x80, false); + } + if (e.jbutton.button == Gear1Device2) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (e.jbutton.button == Gear2Device2) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (e.jbutton.button == Gear3Device2) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (e.jbutton.button == Gear4Device2) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + if (e.jbutton.button == ShiftUpDevice2) + { + if (shiftupdownreadA == 0x28) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x10, false); + } + } + if (e.jbutton.button == ShiftDownDevice2) + { + if (shiftupdownreadA == 0x18) + { + helpers->WriteByte(ShiftUpDownAddress, 0x28, false); + } + if (shiftupdownreadA == 0x20) + { + helpers->WriteByte(ShiftUpDownAddress, 0x18, false); + } + if (shiftupdownreadA == 0x10) + { + helpers->WriteByte(ShiftUpDownAddress, 0x20, false); + } + } + } + } + if (e.type == SDL_JOYBUTTONUP) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + } + if (e.jbutton.button == ViewButton) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + } + if (e.jbutton.button == StartButton) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + } + if (e.jbutton.button == ViewButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x10, false); + } + if (e.jbutton.button == StartButtonDevice2) + { + helpers->WriteByte(StartViewAddress, startviewread -= 0x80, false); + } + } + } + } +} \ No newline at end of file diff --git a/Game Files/DemulSmashingDriveInputs.cpp b/Game Files/DemulSmashingDriveInputs.cpp new file mode 100644 index 0000000..3d8d58a --- /dev/null +++ b/Game Files/DemulSmashingDriveInputs.cpp @@ -0,0 +1,955 @@ +#include "../Common Files/Game.h" +#include +#include +#include "SDL.h" + +extern int joystick_index1; +extern int joystick_index2; +extern SDL_Joystick* GameController2; +static bool testbuttonA; +static bool servicebuttonA; +static bool coinbuttonA; +static bool hornbuttonA; +static bool volupA; +static bool voldownA; +static bool acclpressed; +static bool brakepressed; +static bool Inputsinit = false; +static bool InputFind = false; +static SDL_Event e; + +extern INT_PTR SteeringAddress; +extern INT_PTR AcclAddress; +extern INT_PTR BrakeAddress; +extern INT_PTR ServiceTestAddress; + +static int AcclValue; +static int BrakeValue; + +extern wchar_t* settingsFilename; +static int InputDeviceWheelEnable = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelEnable"), 0, settingsFilename); +static int InputDeviceWheelSteeringAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelSteeringAxis"), 0, settingsFilename); +static int InputDeviceWheelAcclAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelAcclAxis"), 0, settingsFilename); +static int InputDeviceWheelBrakeAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelBrakeAxis"), 0, settingsFilename); +static int InputDeviceWheelReverseAxis = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceWheelReverseAxis"), 0, settingsFilename); +static int InputDeviceCombinedPedals = GetPrivateProfileInt(TEXT("Settings"), TEXT("InputDeviceCombinedPedals"), 0, settingsFilename); +static int SteeringDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("SteeringDeadzone"), 0, settingsFilename); +static int PedalDeadzone = GetPrivateProfileInt(TEXT("Settings"), TEXT("PedalDeadzone"), 0, settingsFilename); +static int ShowButtonNumbersForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowButtonNumbersForSetup"), 0, settingsFilename); +static int ShowAxisForSetup = GetPrivateProfileInt(TEXT("Settings"), TEXT("ShowAxisForSetup"), 0, settingsFilename); +static int ExitButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButton"), 0, settingsFilename); +static int TestButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButton"), 0, settingsFilename); +static int ServiceButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButton"), 0, settingsFilename); +static int CreditButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButton"), 0, settingsFilename); +static int HornButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("HornButton"), 0, settingsFilename); +static int StartButton = GetPrivateProfileInt(TEXT("Settings"), TEXT("StartButton"), 0, settingsFilename); +static int VolumeUp = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeUp"), 0, settingsFilename); +static int VolumeDown = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeDown"), 0, settingsFilename); +static int ExitButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ExitButtonDevice2"), 0, settingsFilename); +static int TestButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TestButtonDevice2"), 0, settingsFilename); +static int ServiceButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("ServiceButtonDevice2"), 0, settingsFilename); +static int CreditButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CreditButtonDevice2"), 0, settingsFilename); +static int HornButtonDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("HornButtonDevice2"), 0, settingsFilename); +static int VolumeUpDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeUpDevice2"), 0, settingsFilename); +static int VolumeDownDevice2 = GetPrivateProfileInt(TEXT("Settings"), TEXT("VolumeDownDevice2"), 0, settingsFilename); + +void SmashingDriveInputsEnabled(Helpers* helpers) +{ + if (!Inputsinit) + { + //Added 2nd device stuff from here + wchar_t* deviceGUIDString2 = new wchar_t[256]; + int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); + char joystick_guid[256]; + sprintf(joystick_guid, "%S", deviceGUIDString2); + SDL_JoystickGUID guid, dev_guid; + int numJoysticks = SDL_NumJoysticks(); + std::string njs = std::to_string(numJoysticks); + ((char)njs.c_str()); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + SDL_Joystick* js2 = SDL_JoystickOpen(i); + joystick_index2 = SDL_JoystickInstanceID(js2); + SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); + char guid_str[1024]; + SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); + const char* name = SDL_JoystickName(js2); + char text[256]; + sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); + guid = SDL_JoystickGetGUIDFromString(joystick_guid); + dev_guid = SDL_JoystickGetGUID(js2); + SDL_JoystickClose(js2); + if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) + { + GameController2 = SDL_JoystickOpen(i); + break; + } + } + Inputsinit = true; + } + + // Dpad stuff here to set as any button + char DpadUpChar[256]; + char DpadDownChar[256]; + char DpadLeftChar[256]; + char DpadRightChar[256]; + char DpadUpCharDevice2[256]; + char DpadDownCharDevice2[256]; + char DpadLeftCharDevice2[256]; + char DpadRightCharDevice2[256]; + GetPrivateProfileStringA("Settings", "DpadUp", "", DpadUpChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDown", "", DpadDownChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeft", "", DpadLeftChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRight", "", DpadRightChar, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadUpDevice2", "", DpadUpCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadDownDevice2", "", DpadDownCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadLeftDevice2", "", DpadLeftCharDevice2, 256, ".\\FFBplugin.ini"); + GetPrivateProfileStringA("Settings", "DpadRightDevice2", "", DpadRightCharDevice2, 256, ".\\FFBplugin.ini"); + std::string exit("ExitButton"); + std::string test("TestButton"); + std::string service("ServiceButton"); + std::string coin("CoinButton"); + std::string horn("HornButton"); + std::string volup("VolumeUp"); + std::string voldown("VolumeDown"); + std::string exit2("ExitButtonDevice2"); + std::string test2("TestButtonDevice2"); + std::string service2("ServiceButtonDevice2"); + std::string coin2("CoinButtonDevice2"); + std::string horn2("HornButtonDevice2"); + std::string volup2("VolumeUpDevice2"); + std::string voldown2("VolumeDownDevice2"); + std::string dpdup(DpadUpChar); + std::string dpddown(DpadDownChar); + std::string dpdleft(DpadLeftChar); + std::string dpdright(DpadRightChar); + std::string dpdup2(DpadUpCharDevice2); + std::string dpddown2(DpadDownCharDevice2); + std::string dpdleft2(DpadLeftCharDevice2); + std::string dpdright2(DpadRightCharDevice2); + + const int WHEEL_DEAD_ZONE = (SteeringDeadzone * 100.0); + const int ACCL_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int BRAKE_DEAD_ZONE = (1 + PedalDeadzone * 100.0); + const int SETUP_DEAD_ZONE = 20000; + + UINT8 servicetestread = helpers->ReadByte(ServiceTestAddress, false); + UINT8 acclbrakeread = helpers->ReadByte(AcclAddress, false); + + while (SDL_WaitEvent(&e) != 0) + { + if ((e.type == SDL_JOYAXISMOTION) & (ShowAxisForSetup == 0)) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis == InputDeviceWheelSteeringAxis) + { + //Left of dead zone + if (e.jaxis.value < -WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (128 + (e.jaxis.value + WHEEL_DEAD_ZONE) / 255), false); + } + //Right of dead zone + else if (e.jaxis.value > WHEEL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + WHEEL_DEAD_ZONE; + helpers->WriteByte(SteeringAddress, (127 + (e.jaxis.value - WHEEL_DEAD_ZONE) / 255), false); + } + else if ((e.jaxis.value < WHEEL_DEAD_ZONE) & (e.jaxis.value > -WHEEL_DEAD_ZONE)) + { + helpers->WriteByte(SteeringAddress, 0x7F, false); + } + } + if (InputDeviceWheelReverseAxis == 1) + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + AcclValue = ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128.5); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + BrakeValue = ((e.jaxis.value + ACCL_DEAD_ZONE) / 128); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + AcclValue = 0x00; + BrakeValue = 0x00; + } + + if (AcclValue > 0) + { + if (!acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x10, false); + acclpressed = true; + } + } + else + { + if (acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x10, false); + acclpressed = false; + } + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x20, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x20, false); + brakepressed = false; + } + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + AcclValue = 127 - e.jaxis.value; + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + AcclValue = 128 - e.jaxis.value; + } + + if (AcclValue > 0) + { + if (!acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x10, false); + acclpressed = true; + } + } + else + { + if (acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x10, false); + acclpressed = false; + } + } + } + else if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 127 - e.jaxis.value; + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 128 - e.jaxis.value; + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x20, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x20, false); + brakepressed = false; + } + } + } + } + } + else + { + if (InputDeviceCombinedPedals == 1) + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - ACCL_DEAD_ZONE; + AcclValue = ((e.jaxis.value + ACCL_DEAD_ZONE) / 128); + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value + ACCL_DEAD_ZONE; + BrakeValue = ((-e.jaxis.value + ACCL_DEAD_ZONE) / 128); + } + else if ((e.jaxis.value < ACCL_DEAD_ZONE) & (e.jaxis.value > -ACCL_DEAD_ZONE)) + { + AcclValue = 0xFF; + BrakeValue = 0xFF; + } + + if (AcclValue > 0) + { + if (!acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x10, false); + acclpressed = true; + } + } + else + { + if (acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x10, false); + acclpressed = false; + } + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x20, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x20, false); + brakepressed = false; + } + } + } + } + else + { + if (e.jaxis.axis == InputDeviceWheelAcclAxis) + { + if (e.jaxis.value < -ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + AcclValue = 128 + e.jaxis.value; + } + else if (e.jaxis.value > ACCL_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + AcclValue = 127 + e.jaxis.value; + } + + if (AcclValue > 0) + { + if (!acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x10, false); + acclpressed = true; + } + } + else + { + if (acclpressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x10, false); + acclpressed = false; + } + } + } + if (e.jaxis.axis == InputDeviceWheelBrakeAxis) + { + if (e.jaxis.value < -BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 128 + e.jaxis.value; + } + else if (e.jaxis.value > BRAKE_DEAD_ZONE) + { + e.jaxis.value = (e.jaxis.value / 255); + BrakeValue = 127 + e.jaxis.value; + } + + if (BrakeValue > 0) + { + if (!brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x20, false); + brakepressed = true; + } + } + else + { + if (brakepressed) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x20, false); + brakepressed = false; + } + } + } + } + } + } + } + + if (ShowAxisForSetup == 1) + { + if (e.type == SDL_JOYAXISMOTION) + { + if (e.jaxis.which == joystick_index1) + { + if (e.jaxis.axis >= 0) + { + if (e.jaxis.value < -SETUP_DEAD_ZONE) + { + e.jaxis.value = e.jaxis.value - SETUP_DEAD_ZONE; + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + else if (e.jaxis.value > SETUP_DEAD_ZONE) + { + char buff[100]; + sprintf_s(buff, "Axis %d Moved", e.jaxis.axis); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + } + + if (ShowButtonNumbersForSetup == 1) + { + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jaxis.which == joystick_index1 || e.jaxis.which == joystick_index2) + { + if (e.jbutton.button >= 0) + { + char buff[100]; + sprintf_s(buff, "Button %d Pressed", e.jbutton.button); + MessageBoxA(NULL, buff, "", NULL); + } + } + } + } + + if (e.jhat.type == SDL_JOYHATMOTION) + { + if (e.jhat.value == SDL_HAT_CENTERED) + { + if (e.jhat.which == joystick_index1) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + servicebuttonA = false; + } + if (hornbuttonA) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x40, false); + hornbuttonA = false; + } + if (coinbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + coinbuttonA = false; + } + if (volupA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + volupA = false; + } + if (voldownA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + voldownA = false; + } + } + else if (e.jhat.which == joystick_index2) + { + if (testbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + testbuttonA = false; + } + if (servicebuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + servicebuttonA = false; + } + if (hornbuttonA) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x40, false); + hornbuttonA = false; + } + if (coinbuttonA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + coinbuttonA = false; + } + if (volupA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + volupA = false; + } + if (voldownA) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + voldownA = false; + } + } + } + if (e.jhat.value == SDL_HAT_UP) + { + if (e.jhat.which == joystick_index1) + { + if (dpdup.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdup.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdup.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpdup.compare(horn) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpdup.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpdup.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdup2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdup2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdup2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdup2.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpdup2.compare(horn2) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpdup2.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpdup2.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_DOWN) + { + if (e.jhat.which == joystick_index1) + { + if (dpddown.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpddown.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpddown.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpddown.compare(horn) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpddown.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpddown.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpddown2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpddown2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpddown2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpddown2.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpddown2.compare(horn2) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpddown2.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpddown2.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_LEFT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdleft.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdleft.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdleft.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpdleft.compare(horn) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpdleft.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpdleft.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdleft2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdleft2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdleft2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdleft2.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpdleft2.compare(horn2) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpdleft2.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpdleft2.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + } + if (e.jhat.value == SDL_HAT_RIGHT) + { + if (e.jhat.which == joystick_index1) + { + if (dpdright.compare(exit) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright.compare(test) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdright.compare(service) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdright.compare(coin) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpdright.compare(horn) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpdright.compare(volup) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpdright.compare(voldown) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + else if (e.jhat.which == joystick_index2) + { + if (dpdright2.compare(exit2) == 0) + { + system("taskkill /f /im demul.exe"); + } + if (dpdright2.compare(test2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + testbuttonA = true; + } + if (dpdright2.compare(service2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + servicebuttonA = true; + } + if (dpdright2.compare(coin2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + coinbuttonA = true; + } + if (dpdright2.compare(horn2) == 0) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + hornbuttonA = true; + } + if (dpdright2.compare(volup2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + volupA = true; + } + if (dpdright2.compare(voldown2) == 0) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + voldownA = true; + } + } + } + } + + if (e.type == SDL_JOYBUTTONDOWN) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + } + if (e.jbutton.button == ExitButton) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == HornButton) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + } + if (e.jbutton.button == VolumeUp) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + } + if (e.jbutton.button == VolumeDown) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x08, false); + } + if (e.jbutton.button == ExitButtonDevice2) + { + system("taskkill /f /im demul.exe"); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x02, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x20, false); + } + if (e.jbutton.button == HornButtonDevice2) + { + helpers->WriteByte(AcclAddress, acclbrakeread -= 0x40, false); + } + if (e.jbutton.button == VolumeUpDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x01, false); + } + if (e.jbutton.button == VolumeDownDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread -= 0x04, false); + } + } + } + if (e.type == SDL_JOYBUTTONUP) + { + if (e.jbutton.which == joystick_index1) + { + if (e.jbutton.button == TestButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + } + if (e.jbutton.button == ServiceButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + } + if (e.jbutton.button == CreditButton) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == HornButton) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x40, false); + } + if (e.jbutton.button == VolumeUp) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + } + if (e.jbutton.button == VolumeDown) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + } + } + else if (e.jbutton.which == joystick_index2) + { + if (e.jbutton.button == TestButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x08, false); + } + if (e.jbutton.button == ServiceButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x02, false); + } + if (e.jbutton.button == CreditButtonDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x20, false); + } + if (e.jbutton.button == HornButtonDevice2) + { + helpers->WriteByte(AcclAddress, acclbrakeread += 0x40, false); + } + if (e.jbutton.button == VolumeUpDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x01, false); + } + if (e.jbutton.button == VolumeDownDevice2) + { + helpers->WriteByte(ServiceTestAddress, servicetestread += 0x04, false); + } + } + } + } +} \ No newline at end of file diff --git a/Game Files/M2Emulator.cpp b/Game Files/M2Emulator.cpp index 25300f4..beb764a 100644 --- a/Game Files/M2Emulator.cpp +++ b/Game Files/M2Emulator.cpp @@ -397,9 +397,7 @@ void M2Emulator::FFBLoop(EffectConstants * constants, Helpers * helpers, EffectT else if ((gamestate == 0x1A) & (gamestatetimer > 100)) { Sleep(100); - helpers->WriteNop(0xC2130, true); - helpers->WriteNop(0xC2131, true); - helpers->WriteNop(0xC2132, true); + helpers->WriteNop(0xC2130, 3, true); } if ((gamestate > 0x1A)& (gamestate < 0x1A)) @@ -501,9 +499,7 @@ void M2Emulator::FFBLoop(EffectConstants * constants, Helpers * helpers, EffectT else if ((gamestate == 0x1A) & (gamestatetimer > 100)) { Sleep(100); - helpers->WriteNop(0xC2130, true); - helpers->WriteNop(0xC2131, true); - helpers->WriteNop(0xC2132, true); + helpers->WriteNop(0xC2130, 3, true); } if ((gamestate > 0x1A)& (gamestate < 0x1A)) @@ -560,9 +556,7 @@ void M2Emulator::FFBLoop(EffectConstants * constants, Helpers * helpers, EffectT else if ((gamestate == 0x1A) & (gamestatetimer > 100)) { Sleep(100); - helpers->WriteNop(0xC2130, true); - helpers->WriteNop(0xC2131, true); - helpers->WriteNop(0xC2132, true); + helpers->WriteNop(0xC2130, 3, true); } if ((gamestate > 0x1A)& (gamestate < 0x1A)) @@ -688,9 +682,7 @@ void M2Emulator::FFBLoop(EffectConstants * constants, Helpers * helpers, EffectT else if ((gamestate == 0x1A) & (gamestatetimer > 100)) { Sleep(100); - helpers->WriteNop(0xC2130, true); - helpers->WriteNop(0xC2131, true); - helpers->WriteNop(0xC2132, true); + helpers->WriteNop(0xC2130, 3, true); } if ((gamestate > 0x1A)& (gamestate < 0x1A)) @@ -761,9 +753,7 @@ void M2Emulator::FFBLoop(EffectConstants * constants, Helpers * helpers, EffectT else if ((gamestate == 0x1A) & (gamestatetimer > 100)) { Sleep(100); - helpers->WriteNop(0xC2130, true); - helpers->WriteNop(0xC2131, true); - helpers->WriteNop(0xC2132, true); + helpers->WriteNop(0xC2130, 3, true); } if ((gamestate > 0x1A)& (gamestate < 0x1A)) @@ -820,9 +810,7 @@ void M2Emulator::FFBLoop(EffectConstants * constants, Helpers * helpers, EffectT else if ((gamestate == 0x1A) & (gamestatetimer > 100)) { Sleep(100); - helpers->WriteNop(0xC2130, true); - helpers->WriteNop(0xC2131, true); - helpers->WriteNop(0xC2132, true); + helpers->WriteNop(0xC2130, 3, true); } if ((gamestate > 0x1A)& (gamestate < 0x1A)) diff --git a/Game Files/RoadFighters3D.cpp b/Game Files/RoadFighters3D.cpp index d653727..80a1ed9 100644 --- a/Game Files/RoadFighters3D.cpp +++ b/Game Files/RoadFighters3D.cpp @@ -168,30 +168,14 @@ static int ThreadLoop() if (Only2D == 1) { //2D Only - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24C9F, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CA0, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CA1, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CAA, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CAB, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CAC, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CBA, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CBB, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CBC, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x478F, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x4790, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x4791, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x3E6DB, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x3E6DC, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x3E6DD, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391D8, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391D9, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391DA, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391EF, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391F0, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391F1, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x5962F, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x59630, false); - myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x59631, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24C9F, 3, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CAA, 3, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x24CBA, 3, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x478F, 3, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x3E6DB, 3, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391D8, 3, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x1391EF, 3, false); + myHelpers->WriteNop((INT_PTR)gl_hjgtDll + 0x5962F, 3, false); int TwoDee1 = myHelpers->ReadIntPtr((INT_PTR)gl_hjgtDll + 0x00946DA0, false); int TwoDee2 = myHelpers->ReadIntPtr((INT_PTR)TwoDee1 + 0x38, false); int TwoDee3 = myHelpers->ReadIntPtr((INT_PTR)TwoDee2 + 0x94, false); @@ -309,31 +293,13 @@ void RoadFighters3D::FFBLoop(EffectConstants *constants, Helpers *helpers, Effec init = true; } - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D84B, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D84C, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D84D, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D852, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D853, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D854, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D85C, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D85D, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D85E, false); + helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D84B, 3, false); + helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D852, 3, false); + helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18D85C, 3, false); // Spicetools shit below. STOPS test buttons showing in menu etc if not nop - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA89, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA8A, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA8B, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA8C, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA8D, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA8E, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DAA3, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DAA4, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DAA5, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA97, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA98, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA99, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA9A, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA9B, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA9C, false); + helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA89, 6, false); + helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DAA3, 3, false); + helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x18DA97, 6, false); // Dpad stuff here to set as any button char DpadUpChar[256]; @@ -391,9 +357,7 @@ void RoadFighters3D::FFBLoop(EffectConstants *constants, Helpers *helpers, Effec if (SequentialGears == 1) { - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x95DDA, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x95DDB, false); - helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x95DDC, false); + helpers->WriteNop((INT_PTR)gl_hjgtDll + 0x95DDA, 3, false); } const int WHEEL_DEAD_ZONE = (SteeringDeadzone * 100.0);