Skip to content

Commit fc0ca54

Browse files
committed
hijack motion sequence
1 parent 3e1c7d0 commit fc0ca54

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

MGS3CrouchWalk/dllmain.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bool CrouchWalkEnabled = false;
1515
bool CrouchMoving = false;
1616
bool CrouchMovingSlow = false;
1717
bool IgnoreButtonHold = false;
18+
bool HijackSequence = false;
1819

1920
// config values
2021
float CamoIndexModifier = 1.0f;
@@ -31,6 +32,7 @@ PlayerStatusCheckDelegate* PlayerStatusCheck;
3132
PlayerStatusSetDelegate* PlayerStatusSet;
3233
ActMovementDelegate* ActMovement;
3334
GetButtonHoldingStateDelegate* GetButtonHoldingState;
35+
MotionPlaySequenceDelegate* MotionPlaySequence;
3436

3537
uintptr_t PlayerSetMotion(int64_t work, PlayerMotion motion)
3638
{
@@ -64,9 +66,12 @@ void __fastcall SetMotionDataHook(MotionControl* motionControl, int layer, Playe
6466

6567
time = (int)*currentTime;
6668
motion = PlayerMotion::SquatMove;
69+
70+
HijackSequence = true;
6771
}
6872

6973
SetMotionData(motionControl, layer, motion, time, mask);
74+
HijackSequence = false;
7075
}
7176

7277
int64_t __fastcall GetButtonHoldingStateHook(int64_t work, MovementWork* plWork)
@@ -77,6 +82,14 @@ int64_t __fastcall GetButtonHoldingStateHook(int64_t work, MovementWork* plWork)
7782
return GetButtonHoldingState(work, plWork);
7883
}
7984

85+
int64_t __fastcall MotionPlaySequenceHook(__int64 mtsq_ctrl, int layer, int num, int flag, int loop_time)
86+
{
87+
if (HijackSequence)
88+
num = CrouchMovingSlow ? PlayerMotion::StandMoveSlow : PlayerMotion::StandMoveStalk;
89+
90+
return MotionPlaySequence(mtsq_ctrl, layer, num, flag, loop_time);
91+
}
92+
8093
int* __fastcall CalculateCamoIndexHook(int* a1, int a2)
8194
{
8295
int* result = CalculateCamoIndex(a1, a2);
@@ -123,6 +136,8 @@ int* __fastcall ActionSquatStillHook(int64_t work, MovementWork* plWork, int64_t
123136

124137
// check that the pad is being held down
125138
int16_t padForce = *(int16_t*)(work + 2016);
139+
bool wasMoving = CrouchMoving;
140+
bool wasSlow = CrouchMovingSlow;
126141
CrouchMoving = padForce > plWork->padForceLimit;
127142
CrouchMovingSlow = padForce < 180;
128143

@@ -134,14 +149,12 @@ int* __fastcall ActionSquatStillHook(int64_t work, MovementWork* plWork, int64_t
134149
{
135150
mCtrlGlobal->mtcmControl->motionTimeBase = CrouchMovingSlow ? CrouchStalkSpeed : CrouchWalkSpeed;
136151

137-
auto mtsq_cntrl = *((uintptr_t*)mCtrlGlobal + 15);
138-
auto sound = (uint8_t*)mtsq_cntrl + 0x3C;
139-
auto soundType = (uint8_t*)mtsq_cntrl + 0x48;
140-
auto motionId = (uint8_t*)mtsq_cntrl + 0x40;
152+
auto mtsqCntrl = *((uintptr_t*)mCtrlGlobal + 15);
141153

142-
*sound = 5;
143-
*soundType = CrouchMovingSlow ? 0x40 : 0x60;
144-
*motionId = CrouchMovingSlow ? PlayerMotion::StandMoveStalk : PlayerMotion::StandMoveSlow;
154+
if (wasMoving && wasSlow != CrouchMovingSlow)
155+
{
156+
MotionPlaySequence(mtsqCntrl, 0, CrouchMovingSlow ? PlayerMotion::StandMoveSlow : PlayerMotion::StandMoveStalk, 5, 0x1b0);
157+
}
145158
}
146159

147160
PlayerStatusSet(11, 14, 0x10C, 0xFFFFFFFF); // enables grass movement sounds
@@ -163,6 +176,7 @@ void InstallHooks()
163176
uintptr_t setMotionDataOffset = (uintptr_t)Memory::PatternScan(GameModule, "48 85 C9 0F 84 42 03 00 00 4C 8B DC 55 53 56 41");
164177
uintptr_t calcuateCamoIndexOffset = (uintptr_t)Memory::PatternScan(GameModule, "48 83 EC 30 0F 29 74 24 20 48 8B F9 48 63 F2 E8") - 0x10;
165178
uintptr_t getBtnHoldStateOffset = (uintptr_t)Memory::PatternScan(GameModule, "44 0F B7 8A 8E 00 00 00 4C 8B C2 66 45 85 C9 78");
179+
uintptr_t motionPlaySeqOffset = (uintptr_t)Memory::PatternScan(GameModule, "4D 63 D8 48 85 C9 74 6B 48 63 C2 48 8D 14 40 48");
166180
uint8_t* disableCrouchProneOffset = Memory::PatternScan(GameModule, "00 00 7E 19 83 4F 68 10");
167181

168182
ActSquatStillOffset = (uintptr_t)Memory::PatternScan(GameModule, "4C 8B DC 55 57 41 56 49 8D 6B A1 48 81 EC 00 01");
@@ -175,6 +189,7 @@ void InstallHooks()
175189
Memory::DetourFunction(setMotionDataOffset, (LPVOID)SetMotionDataHook, (LPVOID*)&SetMotionData);
176190
Memory::DetourFunction(calcuateCamoIndexOffset, (LPVOID)CalculateCamoIndexHook, (LPVOID*)&CalculateCamoIndex);
177191
Memory::DetourFunction(getBtnHoldStateOffset, (LPVOID)GetButtonHoldingStateHook, (LPVOID*)&GetButtonHoldingState);
192+
Memory::DetourFunction(motionPlaySeqOffset, (LPVOID)MotionPlaySequenceHook, (LPVOID*)&MotionPlaySequence);
178193
Memory::DetourFunction(ActSquatStillOffset, (LPVOID)ActionSquatStillHook, (LPVOID*)&ActionSquatStill);
179194

180195
CamoIndexData = InitializeCamoIndex(0, 0);

MGS3CrouchWalk/types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ typedef void __fastcall SetMotionDataDelegate(MotionControl* motionControl, int
106106
typedef int64_t __fastcall PlayerStatusCheckDelegate(unsigned int a1);
107107
typedef int64_t __fastcall ActMovementDelegate(MovementWork* plWork, int64_t work, int flag);
108108
typedef int64_t __fastcall GetButtonHoldingStateDelegate(int64_t work, MovementWork* plWork);
109-
typedef int64_t __fastcall PlayerStatusSetDelegate(int a1, int64_t a2, int64_t a3, int64_t a4);
109+
typedef int64_t __fastcall PlayerStatusSetDelegate(int a1, int64_t a2, int64_t a3, int64_t a4);
110+
typedef int64_t __fastcall MotionPlaySequenceDelegate(__int64 mtsqCtrl, int layer, int num, int flag, int loop_time);

0 commit comments

Comments
 (0)