ClientFrameStage_t curStage;
void CEnginePrediction::PreStart()
{
if (csgo->g_flVelMod < 1.f)
*(bool*)((uintptr_t)interfaces.prediction + 0x24) = true;
if (csgo->client_state->iDeltaTick > 0)
interfaces.prediction->Update(csgo->client_state->iDeltaTick, true, csgo->client_state->nLastCommandAck, csgo->client_state->nLastOutgoingCommand + csgo->client_state->iChokedCommands);
}
void CEnginePrediction::UpdatePrediction() {
//auto local_player = interfaces.ent_list->GetClientEntity(interfaces.engine->GetLocalPlayer());
auto local_player = csgo->local;
bool valid{ csgo->client_state->iDeltaTick > 0 };
if (m_stored_variables.m_flVelocityModifier < 1.0) {
*reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(interfaces.prediction + 0x24)) = 1;
}
// render start was not called.
if (curStage == FRAME_NET_UPDATE_END) {
int start = csgo->client_state->iDeltaTick;
int stop = csgo->client_state->nLastOutgoingCommand + csgo->client_state->iChokedCommands;
// call CPrediction::Update.
interfaces.prediction->Update(csgo->client_state->iDeltaTick, valid, start, stop);
}
}
void CEnginePrediction::Start(CUserCmd* cmd, IBasePlayer* local) {
static CMoveData data{ };
//auto local_player = interfaces.ent_list->GetClientEntity(interfaces.engine->GetLocalPlayer());
auto local_player = csgo->local;
interfaces.prediction->bInPrediction = true;
// CPrediction::StartCommand
local_player->SetCurrentCommand(cmd);
//*interfaces.prediction->m_nPredictionRandomSeed = cmd->random_seed;
//interfaces.prediction->m_pPredictionPlayer = local_player;
// backup globals.
m_stored_variables.m_flCurtime = interfaces.global_vars->curtime;
m_stored_variables.m_flFrametime = interfaces.global_vars->frametime;
// CPrediction::RunCommand
// set globals appropriately.
interfaces.global_vars->curtime = TICKS_TO_TIME(local_player->GetTickBase());
interfaces.global_vars->frametime = interfaces.global_vars->interval_per_tick;
// set target player ( host ).
interfaces.move_helper->SetHost(local_player);
interfaces.game_movement->StartTrackPredictionErrors(local_player);
// setup input.
interfaces.prediction->SetupMove(local_player, cmd, interfaces.move_helper, &data);
// run movement.
interfaces.game_movement->ProcessMovement(local_player, &data);
interfaces.prediction->FinishMove(local_player, cmd, &data);
interfaces.game_movement->FinishTrackPredictionErrors(local_player);
// reset target player ( host ).
interfaces.move_helper->SetHost(nullptr);
}
void CEnginePrediction::Finish(CUserCmd* cmd) {
//auto local_player = interfaces.ent_list->GetClientEntity(interfaces.engine->GetLocalPlayer());
auto local_player = csgo->local;
if (!cmd || !local_player)
return;
interfaces.prediction->bInPrediction = false;
//*interfaces.prediction->m_nPredictionRandomSeed = -1;
//interfaces.prediction->m_pPredictionPlayer = nullptr;
// restore globals.
interfaces.global_vars->curtime = m_stored_variables.m_flCurtime;
interfaces.global_vars->frametime = m_stored_variables.m_flFrametime;
}
void CEnginePrediction::CorrectViewmodelData() {
auto local_player = csgo->local;
if (!local_player->isAlive()) {
return;
}
if (local_player->GetViewModel()) {
IBasePlayer* const pViewModel = interfaces.ent_list->GetClientEntityFromHandle(local_player->GetViewModelPred());
if (!pViewModel) {
return;
}
pViewModel->GetAnimtime() = StoredViewmodel.m_flViewmodelAnimTime;
pViewModel->GetCycle() = StoredViewmodel.m_flViewmodelCycle;
}
}
void CEnginePrediction::UpdateViewmodelData() {
auto local_player = csgo->local;
if (!local_player->isAlive()) {
return;
}
if (local_player->GetViewModel() ) {
IBasePlayer* const pViewModel = interfaces.ent_list->GetClientEntityFromHandle(local_player->GetViewModelPred());
if (!pViewModel) {
return;
}
StoredViewmodel.m_flViewmodelCycle = pViewModel->GetCycle();
StoredViewmodel.m_flViewmodelAnimTime = pViewModel->GetAnimtime();
}
}