bool __fastcall Hooks :: WriteUsercmdDeltaToBuffer_hook (void * ECX, void * EDX, int nSlot, bf_write * buf, int from, int to, bool isNewCmd)
{
static DWORD WriteUsercmdDeltaToBufferReturn = (DWORD) Utils :: FindSignature ("engine.dll", "84 C0 74 04 B0 01 EB 02 32 C0 8B FE 46 3B F3 7E C9 84 C0 0F 84);
static auto sendmovecall = Utils :: FindSignature ("engine.dll", "84 C0 74 04 B0 01 EB 02 32 C0 8B FE 46 3B F3 7E C9 84 C0 0F 84????");
static auto ofunct = g_Hooks.pClientHook-> GetOriginal <WriteUsercmdDeltaToBufferFn> (24);
if (_ReturnAddress ()! = (void *) sendmovecall ||
g :: tickbaseshift <= 0)
{
g :: tickbaseshift = 0;
return ofunct (ECX, nSlot, buf, from, to, isNewCmd);
}
if (from! = -1)
return true;
auto CL_SendMove = [] () {
using CL_SendMove_t = void (__ fastcall *) (void);
static CL_SendMove_t CL_SendMoveF = (CL_SendMove_t) Utils :: FindSignature ("engine.dll", "55 8B EC A1???? 81 EC???? B9???? 53 8B 98");
CL_SendMoveF ();
};
auto WriteUsercmd = [] (bf_write * buf, CUserCmd * in, CUserCmd * out) {
using WriteUsercmd_t = void (__ fastcall *) (bf_write *, CUserCmd *, CUserCmd *);
static WriteUsercmd_t WriteUsercmdF = (WriteUsercmd_t) Utils :: FindSignature ("client_panorama.dll", "55 8B EC 83 E4 F8 51 53 56 8B D9 8B 0D");
WriteUsercmdF (buf, in, out);
};
int * pNumBackupCommands = (int *) ((std :: uintptr_t) buf - 0x30);
int * pNumNewCommands = (int *) ((std :: uintptr_t) buf - 0x2C);
auto net_channel = * reinterpret_cast <NetChannel * *> (reinterpret_cast <uintptr_t> (g_pClientState) + 0x9C);
int32_t new_commands = * pNumNewCommands;
auto nextcmdnumber = g_pClientState-> lastoutgoingcommand + g_pClientState-> chokedcommands + 1;
auto totalnewcommands = std :: min (g :: tickbaseshift, 16);
g :: tickbaseshift - = totalnewcommands;
from = -1;
* pNumNewCommands = totalnewcommands;
* pNumBackupCommands = 0;
for (to = nextcmdnumber - new_commands + 1; to <= nextcmdnumber; to ++)
{
if (! ofunct (ECX, nSlot, buf, from, to, true))
return false;
from = to;
}
auto lastrealcmd = g_pInput-> GetUserCmd (nSlot, from);
CUserCmd fromcmd;
if (lastrealcmd)
fromcmd = * lastrealcmd;
CUserCmd tocmd = fromcmd;
tocmd.command_number ++;
tocmd.tick_count + = (TIME_TO_TICKS (0.5f) + nextcmdnumber);
for (int i = new_commands; i <= totalnewcommands; i ++)
{
WriteUsercmd (buf, & tocmd, & fromcmd);
fromcmd = tocmd;
tocmd.command_number ++;
tocmd.tick_count ++;
}
CL_SendMove ();
return true;
}