Skip to content

Commit eea0ecc

Browse files
committed
Add pm_snapVector
1 parent c2a2de7 commit eea0ecc

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/client/component/gameplay.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace gameplay
1313
utils::hook::detour pm_player_trace_hook;
1414
utils::hook::detour pm_crashland_hook;
1515

16+
game::dvar_t* pm_snap_vector = nullptr;
17+
1618
void pm_player_trace_stub(game::pmove_t* pm, game::trace_t* results, const float* start,
1719
const float* end, const game::Bounds* bounds, int passEntityNum, int contentMask)
1820
{
@@ -111,6 +113,51 @@ namespace gameplay
111113
a.bind(loc_140691518);
112114
a.jmp(0x140691518);
113115
}
116+
117+
void sys_snap_vector(float* velocity)
118+
{
119+
if (!pm_snap_vector->current.enabled)
120+
{
121+
return;
122+
}
123+
124+
velocity[0] = std::floorf(velocity[0] + 0.5f);
125+
velocity[1] = std::floorf(velocity[1] + 0.5f);
126+
velocity[2] = std::floorf(velocity[2] + 0.5f);
127+
}
128+
129+
void add_snap_vector_call(utils::hook::assembler& a)
130+
{
131+
a.pushad64();
132+
a.mov(rcx, rsi);
133+
a.call_aligned(sys_snap_vector);
134+
a.popad64();
135+
}
136+
137+
void pmove_single_stub1(utils::hook::assembler& a)
138+
{
139+
const auto loc_14068FEBD = a.newLabel();
140+
141+
a.comiss(xmm5, xmm4);
142+
a.jbe(loc_14068FEBD);
143+
a.mov(rax, 0x3F800000);
144+
a.movq(xmm1, rax);
145+
a.jmp(0x14068FE99);
146+
147+
a.bind(loc_14068FEBD);
148+
add_snap_vector_call(a);
149+
a.jmp(0x14068FEBD);
150+
}
151+
152+
void pmove_single_stub2(utils::hook::assembler& a)
153+
{
154+
a.movss(dword_ptr(rsi, 8), xmm1);
155+
a.movss(dword_ptr(rsi, 4), xmm0);
156+
a.movss(dword_ptr(rsi), xmm6);
157+
158+
add_snap_vector_call(a);
159+
a.jmp(0x14068FEBD);
160+
}
114161
}
115162

116163
class component final : public component_interface
@@ -154,6 +201,11 @@ namespace gameplay
154201
game::DVAR_FLAG_REPLICATED, "Game gravity in inches per second squared");
155202
dvars::register_int("g_speed", 190, 0, 1000,
156203
game::DVAR_FLAG_REPLICATED, "Player speed");
204+
205+
pm_snap_vector = dvars::register_bool("pm_snapVector", false, game::DVAR_FLAG_REPLICATED, "Snap velocity vector (mp movement)");
206+
207+
utils::hook::jump(0x14068FE8C, utils::hook::assemble(pmove_single_stub1), true);
208+
utils::hook::jump(0x14068FEAF, utils::hook::assemble(pmove_single_stub2), true);
157209
}
158210
};
159211
}

0 commit comments

Comments
 (0)