using CLMove_t = void(__vectorcall*)(float, bool);
void __vectorcall hooks::hooked_clmove(float accumulated_extra_samples, bool bFinalTick)
{
if (g_ctx.globals.should_recharge)
{
g_ctx.get_command()->m_tickcount = INT_MAX;
if (++g_ctx.globals.ticks_allowed >= 14)
{
g_ctx.globals.should_recharge = false;
g_ctx.send_packet = true;
}
else
g_ctx.send_packet = false;
return;
}
((CLMove_t)original_clmove)(accumulated_extra_samples, bFinalTick);
if (g_ctx.available() && g_ctx.local()->is_alive())
{
if (g_ctx.globals.trigger_teleport)
{
for (int i = 0; i < g_ctx.globals.teleport_amount; i++)
((CLMove_t)original_clmove)(accumulated_extra_samples, bFinalTick);
g_ctx.globals.teleport_amount = 0;
g_ctx.globals.trigger_teleport = false;
}
}
}
using WriteUsercmdDeltaToBuffer_t = bool(__thiscall*)(void*, int, void*, int, int, bool);
void WriteUserÑmd(void* buf, CUserCmd* incmd, CUserCmd* outcmd);
bool __fastcall hooks::hooked_writeusercmddeltatobuffer(void* ecx, void* edx, int slot, bf_write* buf, int from, int to, bool is_new_command)
{
static auto original_fn = client_hook->get_func_address <WriteUsercmdDeltaToBuffer_t>(24);
if (!g_ctx.globals.tickbase_shift)
return original_fn(ecx, slot, buf, from, to, is_new_command);
if (from != -1)
return true;
auto final_from = -1;
uintptr_t frame_ptr;
__asm mov frame_ptr, ebp;
auto backup_commands = reinterpret_cast <int*> (frame_ptr + 0xFD8);
auto new_commands = reinterpret_cast <int*> (frame_ptr + 0xFDC);
auto newcmds = *new_commands;
auto shift = g_ctx.globals.tickbase_shift;
g_ctx.globals.tickbase_shift = 0;
*backup_commands = 0;
auto choked_modifier = newcmds + shift;
if (choked_modifier > 62)
choked_modifier = 62;
*new_commands = choked_modifier;
auto next_cmdnr = m_clientstate()->iChokedCommands + m_clientstate()->nLastOutgoingCommand + 1;
auto final_to = next_cmdnr - newcmds + 1;
if (final_to <= next_cmdnr)
{
while (original_fn(ecx, slot, buf, final_from, final_to, true))
{
final_from = final_to++;
if (final_to > next_cmdnr)
goto next_cmd;
}
return false;
}
next_cmd:
auto user_cmd = m_input()->GetUserCmd(final_from);
if (!user_cmd)
return true;
CUserCmd to_cmd;
CUserCmd from_cmd;
from_cmd = *user_cmd;
to_cmd = from_cmd;
to_cmd.m_command_number++;
to_cmd.m_tickcount += 200;
if (newcmds > choked_modifier)
return true;
for (auto i = choked_modifier - newcmds + 1; i > 0; --i)
{
WriteUserÑmd(buf, &to_cmd, &from_cmd);
from_cmd = to_cmd;
to_cmd.m_command_number++;
to_cmd.m_tickcount++;
}
return true;
}
void WriteUserÑmd(void* buf, CUserCmd* incmd, CUserCmd* outcmd)
{
using WriteUserCmd_t = void(__fastcall*)(void*, CUserCmd*, CUserCmd*);
static auto Fn = (WriteUserCmd_t)util::FindSignature(crypt_str("client.dll"), crypt_str("55 8B EC 83 E4 F8 51 53 56 8B D9"));
__asm
{
mov ecx, buf
mov edx, incmd
push outcmd
call Fn
add esp, 4
}
}