void engine_prediction::RunEnginePred()
{
static int nTickBase;
static CUserCmd* pLastCmd;
if (pLastCmd)
{
if (pLastCmd->hasbeenpredicted)
nTickBase = Globals::LocalPlayer->GetTickBase();
else
++nTickBase;
}
const auto getRandomSeed = []()
{
using MD5_PseudoRandomFn = unsigned long(__cdecl*)(std::uintptr_t);
static auto offset = Utils::FindSignature("client_panorama.dll", "55 8B EC 83 E4 F8 83 EC 70 6A 58");
static auto MD5_PseudoRandom = reinterpret_cast<MD5_PseudoRandomFn>(offset);
return MD5_PseudoRandom(Globals::pCmd->command_number) & 0x7FFFFFFF;
};
pLastCmd = Globals::pCmd;
flOldCurtime = g_pGlobalVars->curtime;
flOldFrametime = g_pGlobalVars->frametime;
Globals::uRandomSeed = getRandomSeed();
g_pGlobalVars->curtime = nTickBase * g_pGlobalVars->intervalPerTick;
g_pGlobalVars->frametime = g_pGlobalVars->intervalPerTick;
g_pMovement->StartTrackPredictionErrors(Globals::LocalPlayer);
CMoveData data;
memset(&data, 0, sizeof(CMoveData));
g_pMoveHelper->SetHost(Globals::LocalPlayer);
g_pPrediction->SetupMove(Globals::LocalPlayer, Globals::pCmd, g_pMoveHelper, &data);
g_pMovement->ProcessMovement(Globals::LocalPlayer, &data);
g_pPrediction->FinishMove(Globals::LocalPlayer, Globals::pCmd, &data);
}
void engine_prediction::EndEnginePred()
{
g_pMovement->FinishTrackPredictionErrors(Globals::LocalPlayer);
g_pMoveHelper->SetHost(nullptr);
Globals::uRandomSeed = -1;
g_pGlobalVars->curtime = flOldCurtime;
g_pGlobalVars->frametime = flOldFrametime;
}