Skip to content

Commit

Permalink
Added Controller Support
Browse files Browse the repository at this point in the history
Resolves #1
  • Loading branch information
Renzo904 committed Mar 29, 2024
1 parent 0f04796 commit eeb82c8
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion BetterDivaPractice/src/Mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <map>
#include <dxgi.h>
#include <cmath>


float checkpointposition = 0;
Expand All @@ -16,6 +17,24 @@ float restartOffset = 1.5f;



__int64 controllerMask;
enum controllerButtons {
DPAD_UP = 3,
DPAD_DOWN,
DPAD_LEFT,
DPAD_RIGHT,
SQUARE,
TRIANGLE,
CIRCLE,
CROSS,
L1,
R1,
L2,
R2,
L3,
R3,
SELECT
};

void writeInstruction(char time) {

Expand All @@ -34,6 +53,10 @@ void writeInstruction(char time) {
}
}

bool isButtonPressed(controllerButtons button) {
return (controllerMask & (long long)pow(2, (int)button)) > 0;
}


/*
Original author:Braasileiro
Expand Down Expand Up @@ -74,6 +97,15 @@ SIG_SCAN
"xxxxx?"
)


SIG_SCAN
(
sigJoystickLoop,
0x140600fe0,
"\x48\x89\x74\x24\x20",
"xxxxx"
)

HOOK(void, __fastcall, _DrawCursor, sigDrawCursor(), practiceCursor* a1, long long param_2)
{
void (*FUN_140621b10)(long long, float) = (void (*)(long long, float))0x140621b10;
Expand Down Expand Up @@ -109,7 +141,7 @@ HOOK(void, __fastcall, _SetCursor, sigSetCursor(), practiceCursor* a1)
}
}
else {
if (GetKeyState(VK_SHIFT) & 0x8000)
if (GetKeyState(VK_SHIFT) & 0x8000 || isButtonPressed(R1))
{
checkpointposition = checkpointposition + (float)rewindTime; //forward cursor
if (checkpointposition > a1->songLenght - rewindTime) {
Expand Down Expand Up @@ -148,6 +180,14 @@ HOOK(__int64, __fastcall, _SongPracticeStart, sigSongPracticeStart(), __int32 a,
return original_SongPracticeStart(a, startingPosition);
}

HOOK(void, __fastcall, _JoystickLoop, sigJoystickLoop(), char* param_1, char* param_2)
{
original_JoystickLoop(param_1, param_2);

controllerMask = *(long long*)(param_2 + 0x30);

}

extern "C"
{
void __declspec(dllexport) Init() {
Expand All @@ -156,6 +196,7 @@ extern "C"
INSTALL_HOOK(_SetCursor);
INSTALL_HOOK(_SongPracticeStart);
INSTALL_HOOK(_DrawCursor);
INSTALL_HOOK(_JoystickLoop);

//Load configs
auto config = toml::parse_file("config.toml");
Expand Down

0 comments on commit eeb82c8

Please sign in to comment.