Skip to content

Commit 7d23805

Browse files
committed
some cleanup
1 parent 66abfba commit 7d23805

File tree

1 file changed

+49
-55
lines changed

1 file changed

+49
-55
lines changed

MGS3CrouchWalk/dllmain.cpp

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ uintptr_t PlayerSetMotion(int64_t work, PlayerMotion motion)
3838
return PlayerSetMotionInternal(work, (PlayerMotion)motionIndex);
3939
}
4040

41+
int64_t __fastcall ActMovementHook(MovementWork* plWork, int64_t work, int flag)
42+
{
43+
if (plWorkGlobal != NULL && plWorkGlobal->action != ActSquatStillOffset)
44+
{
45+
CrouchWalkEnabled = false;
46+
CrouchMoving = false;
47+
}
48+
49+
return ActMovement(plWork, work, flag);
50+
}
51+
52+
void __fastcall SetMotionDataHook(MotionControl* motionControl, int layer, PlayerMotion motion, int time, int64_t mask)
53+
{
54+
if (motionControl->mtcmControl->mtarName == 0x6891CC)
55+
mCtrlGlobal = motionControl;
56+
57+
if (motion == PlayerMotion::StandMoveStalk && CrouchWalkEnabled)
58+
{
59+
float* currentTime = (float*)((uintptr_t)motionControl + 0x128);
60+
61+
time = (int)*currentTime;
62+
motion = PlayerMotion::SquatMove;
63+
}
64+
65+
SetMotionData(motionControl, layer, motion, time, mask);
66+
}
67+
4168
int64_t __fastcall GetButtonHoldingStateHook(int64_t work, MovementWork* plWork)
4269
{
4370
if (IgnoreButtonHold)
@@ -46,6 +73,28 @@ int64_t __fastcall GetButtonHoldingStateHook(int64_t work, MovementWork* plWork)
4673
return GetButtonHoldingState(work, plWork);
4774
}
4875

76+
int* __fastcall CalculateCamoIndexHook(int* a1, int a2)
77+
{
78+
int* result = CalculateCamoIndex(a1, a2);
79+
80+
if (CamoIndexData == NULL || CrouchWalkEnabled || !CrouchMoving)
81+
return result;
82+
83+
int index = a2 << 7;
84+
auto camoIndex = (int*)((char*)&CamoIndexData[4] + index + 4);
85+
86+
if (*camoIndex >= 1000) // ignore if stealth is equipped (todo: properly check item for ezgun and spider camo)
87+
return result;
88+
89+
*camoIndex = *camoIndex < 0 ? *camoIndex / CamoIndexModifier : *camoIndex * CamoIndexModifier;
90+
*camoIndex += CamoIndexValue;
91+
92+
if (*camoIndex > 950) *camoIndex = 950;
93+
if (*camoIndex < -1000) *camoIndex = -1000;
94+
95+
return result;
96+
}
97+
4998
int* __fastcall ActionSquatStillHook(int64_t work, MovementWork* plWork, int64_t a3, int64_t a4)
5099
{
51100
// we store this here so we don't have to hardcode another address that
@@ -92,61 +141,6 @@ int* __fastcall ActionSquatStillHook(int64_t work, MovementWork* plWork, int64_t
92141
return result;
93142
}
94143

95-
void __fastcall SetMotionDataHook(MotionControl* motionControl, int layer, PlayerMotion motion, int time, int64_t mask)
96-
{
97-
if (motionControl->mtcmControl->mtarName == 0x6891CC)
98-
mCtrlGlobal = motionControl;
99-
100-
if (motion == PlayerMotion::StandMoveStalk && CrouchWalkEnabled)
101-
{
102-
float* currentTime = (float*)((uintptr_t)motionControl + 0x128);
103-
104-
time = (int)*currentTime;
105-
motion = PlayerMotion::SquatMove;
106-
}
107-
108-
SetMotionData(motionControl, layer, motion, time, mask);
109-
}
110-
111-
int64_t __fastcall ActMovementHook(MovementWork* plWork, int64_t work, int flag)
112-
{
113-
if (plWorkGlobal != NULL && plWorkGlobal->action != ActSquatStillOffset)
114-
{
115-
CrouchWalkEnabled = false;
116-
CrouchMoving = false;
117-
}
118-
119-
return ActMovement(plWork, work, flag);
120-
}
121-
122-
int* __fastcall CalculateCamoIndexHook(int* a1, int a2)
123-
{
124-
int* result = CalculateCamoIndex(a1, a2);
125-
126-
if (CamoIndexData != NULL && CrouchWalkEnabled)
127-
{
128-
int index = a2 << 7;
129-
auto camoIndex = (int*)((char*)&CamoIndexData[4] + index + 4);
130-
auto movementState = (int*)((char*)&CamoIndexData[4] + index + 8);
131-
132-
if (*camoIndex >= 1000) // ignore if stealth is equipped (todo: properly check item for ezgun and spider camo)
133-
{
134-
return result;
135-
}
136-
137-
if (CrouchMoving)
138-
{
139-
*camoIndex = *camoIndex < 0 ? *camoIndex / CamoIndexModifier : *camoIndex * CamoIndexModifier;
140-
*camoIndex += CamoIndexValue;
141-
142-
if (*camoIndex > 950) *camoIndex = 950;
143-
if (*camoIndex < -1000) *camoIndex = -1000;
144-
}
145-
}
146-
147-
return result;
148-
}
149-
150144
void InstallHooks()
151145
{
152146
int status = MH_Initialize();

0 commit comments

Comments
 (0)