-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchungus.cpp
175 lines (151 loc) · 6.99 KB
/
chungus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "component/scheduler.hpp"
#include "component/command.hpp"
#include "component/console.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
utils::hook::detour StartWeaponAnim_hook;
void StartWeaponAnim_stub(int localClientNum, int a2, unsigned int hand, unsigned int anim, unsigned int anim2, float transitiontime)
{
if ((anim2 == 38 || anim2 == 40) && (anim == 1 || anim == 2))
{
anim2 = 27;
transitiontime = 0.5f;
}
StartWeaponAnim_hook.invoke<void>(localClientNum, a2, hand, anim, anim2, transitiontime);
}
utils::hook::detour PM_BeginWeaponChange_hook;
void PM_BeginWeaponChange_stub(game::pmove_t* pm, game::Weapon newweapon, bool isNewAlternate, bool quick, unsigned int* holdrand)
{
int weapAnim[2] = { pm->ps->weapState[0].weapAnim, pm->ps->weapState[1].weapAnim };
PM_BeginWeaponChange_hook.invoke(pm, newweapon, isNewAlternate, quick, holdrand);
if (pm->ps->pm_flags & 0x4000)
{
pm->ps->weapState[0].weapAnim = weapAnim[0];
pm->ps->weapState[1].weapAnim = weapAnim[1];
}
}
void PM_Weapon_BeginWeaponRaise_stub(game::pmove_t* pm, int, unsigned int, float, int, int hand)
{
utils::hook::invoke<void>(0x140233DB0, pm, hand);
pm->ps->weapState[hand].weapAnim = 1;
}
bool PM_Weapon_CheckForRightyTighty(game::pmove_t* pm)
{
if ((pm->oldcmd.buttons & game::BUTTON_USERELOAD) == 0 && ((pm->cmd.buttons & game::BUTTON_USERELOAD) != 0) ||
((pm->oldcmd.buttons & game::BUTTON_RELOAD) == 0 && ((pm->cmd.buttons & game::BUTTON_RELOAD) != 0)))
{
if ((pm->ps->sprintState.lastSprintEnd - pm->ps->sprintState.lastSprintStart) < 50) //Increase to make righty tighty easier
{
if (game::PM_Weapon_AllowReload(pm->ps, game::WEAPON_HAND_RIGHT) && !game::PM_Weapon_AllowReload(pm->ps, game::WEAPON_HAND_LEFT))
{
game::PM_SetReloadingState(pm->ps, game::WEAPON_HAND_RIGHT);
return true;
}
}
}
return false;
}
bool PM_Weapon_CheckForWristTwist(game::pmove_t* pm)
{
if ((pm->cmd.buttons & game::BUTTON_USERELOAD) == 0 && ((pm->oldcmd.buttons & game::BUTTON_USERELOAD) != 0) ||
(pm->cmd.buttons & game::BUTTON_RELOAD) == 0 && ((pm->oldcmd.buttons & game::BUTTON_RELOAD) != 0))
{
//if we are allowed to reload our left gun, and NOT allowed to reload right gun, start wrist twist
if (game::PM_Weapon_AllowReload(pm->ps, game::WEAPON_HAND_LEFT) && !game::PM_Weapon_AllowReload(pm->ps, game::WEAPON_HAND_RIGHT))
{
game::PM_SetReloadingState(pm->ps, game::WEAPON_HAND_LEFT);
//have no ideia what this could be on ghosts and im lazy
//pm->ps->torsoAnim = 3181; //reload anim, overrides the reset in BG_ClearReloadAnim, makes it so the sprint anim is shown on 3rd person character
return true;
}
}
return false;
}
void Sprint_State_Drop(game::pmove_t* pm)
{
game::mp::playerState_s* ps = pm->ps;
bool isDualWielding = game::BG_PlayerDualWieldingWeapon(ps, ps->weapon);
int handIndex = game::BG_PlayerLastWeaponHand(ps);
for (int i = 0; i <= handIndex; i++)
{
if (i == game::WEAPON_HAND_LEFT && PM_Weapon_CheckForRightyTighty(pm)) {
continue;
}
ps->weapState[i].weaponState = game::WEAPON_SPRINT_DROP;
ps->weapState[i].weaponTime = game::BG_SprintOutTime(ps->weapon, false, isDualWielding);
ps->weapState[i].weaponDelay = 0;
if ((BYTE)ps->pm_type < 7u)
{
ps->weapState[i].weapAnim = (0x21 | (ps->weapState[i].weaponState) & 0x800);
}
}
}
void Sprint_State_Raise(game::pmove_t* pm)
{
game::mp::playerState_s* ps = pm->ps;
int handIndex = game::BG_PlayerLastWeaponHand(ps);
bool isDualWielding = game::BG_PlayerDualWieldingWeapon(ps, ps->weapon);
for (int i = 0; i <= handIndex; i++)
{
ps->weapState[i].weaponState = game::WEAPON_SPRINT_RAISE;
ps->weapState[i].weaponTime = game::BG_SprintInTime(ps->weapon, false, isDualWielding);
ps->weapState[i].weaponDelay = 0;
if ((BYTE)ps->pm_flags < 7u)
ps->weapState[i].weapAnim = (ps->weapState[i].weaponState) & 0x800 | 0x1E;
if (isDualWielding)
{
if (i == game::PlayerHandIndex::WEAPON_HAND_RIGHT)
{
PM_Weapon_CheckForRightyTighty(pm);
}
else if (i == game::PlayerHandIndex::WEAPON_HAND_LEFT)
{
PM_Weapon_CheckForWristTwist(pm);
}
}
}
}
//thank you silver
utils::hook::detour PM_Weapon_CheckForSprint_hook;
void PM_Weapon_CheckForSprint_stub(game::pmove_t* pm)
{
if (!pm->cmd.weapon) {
return;
}
int weaponStateRight = pm->ps->weapState[game::WEAPON_HAND_RIGHT].weaponState;
int weaponStateLeft = pm->ps->weapState[game::WEAPON_HAND_LEFT].weaponState;
if ((pm->ps->pm_flags & 0x4) == 0 && weaponStateRight != game::WEAPON_FIRING && weaponStateRight != game::WEAPON_RECHAMBERING && weaponStateRight != game::WEAPON_MELEE_FIRE && weaponStateRight != game::WEAPON_MELEE_END)
{
if (weaponStateLeft != game::WEAPON_FIRING && weaponStateLeft != game::WEAPON_RECHAMBERING
&& weaponStateLeft != game::WEAPON_MELEE_FIRE && weaponStateLeft != game::WEAPON_MELEE_END
&& weaponStateRight != game::WEAPON_RAISING && weaponStateRight != game::WEAPON_RAISING_ALTSWITCH
&& weaponStateRight != game::WEAPON_DROPPING && weaponStateRight != game::WEAPON_DROPPING_QUICK && weaponStateRight != game::WEAPON_DROPPING_ALT
&& weaponStateRight != game::WEAPON_OFFHAND_INIT && weaponStateRight != game::WEAPON_OFFHAND_PREPARE && weaponStateRight != game::WEAPON_OFFHAND_HOLD && weaponStateRight != game::WEAPON_OFFHAND_HOLD_PRIMED && weaponStateRight != game::WEAPON_OFFHAND_END
)
{
if (((pm->ps->pm_flags & 0x4000) != 0) && (weaponStateRight != game::WEAPON_SPRINT_RAISE && weaponStateRight != game::WEAPON_SPRINT_LOOP && weaponStateRight != game::WEAPON_SPRINT_DROP))
{
Sprint_State_Raise(pm);
}
else if (((pm->ps->pm_flags & 0x4000) == 0) && (weaponStateRight == game::WEAPON_SPRINT_RAISE || weaponStateRight == game::WEAPON_SPRINT_LOOP))
{
Sprint_State_Drop(pm);
}
}
}
}
class cymatic_hooks final : public component_interface
{
public:
void post_unpack() override
{
PM_Weapon_CheckForSprint_hook.create(0x140232B80, PM_Weapon_CheckForSprint_stub);
StartWeaponAnim_hook.create(0x1402B3810, StartWeaponAnim_stub);
PM_BeginWeaponChange_hook.create(0x14022E9D0, PM_BeginWeaponChange_stub);
utils::hook::call(0x1402319F1, PM_Weapon_BeginWeaponRaise_stub);
}
};
REGISTER_COMPONENT(cymatic_hooks)