@@ -15,6 +15,7 @@ bool CrouchWalkEnabled = false;
1515bool CrouchMoving = false ;
1616bool CrouchMovingSlow = false ;
1717bool IgnoreButtonHold = false ;
18+ bool HijackSequence = false ;
1819
1920// config values
2021float CamoIndexModifier = 1 .0f ;
@@ -31,6 +32,7 @@ PlayerStatusCheckDelegate* PlayerStatusCheck;
3132PlayerStatusSetDelegate* PlayerStatusSet;
3233ActMovementDelegate* ActMovement;
3334GetButtonHoldingStateDelegate* GetButtonHoldingState;
35+ MotionPlaySequenceDelegate* MotionPlaySequence;
3436
3537uintptr_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
7277int64_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+
8093int * __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 );
0 commit comments