-
Автор темы
- #1
Its useless but here
prediction.cpp:
#include "prediction.hpp"
namespace Engine
{
void Prediction::begin(CUserCmd* cmd)
{
if (C_CSPlayer::localPlayer())
m_nTickBase = C_CSPlayer::localPlayer()->m_nTickBase();
auto delta_tick = m_pClientState->m_iDeltaTick;
m_pPrediction->Update(delta_tick, true, m_pClientState->m_iLastCommandAck,
m_pClientState->m_iLastOutgoingCommand + m_pClientState->m_iChockedCommands);
if (!cmd)
return;
m_pWeapon = (C_WeaponCSBaseGun*)(m_pEntList->GetClientEntityFromHandle(g_ctx.local()->m_hActiveWeapon()));
if (!m_pWeapon)
return;
m_fFlags = g_ctx.local()->m_fFlags();
m_vecVelocity = g_ctx.local()->m_vecVelocity();
m_flCurrentTime = m_pGlobalVars->curtime;
m_flFrameTime = m_pGlobalVars->frametime;
fix_netvar_compression();
m_nServerCommandsAcknowledged = *(int*)(uintptr_t(m_pPrediction) + 0x20);
m_bInPrediction = *(bool*)(uintptr_t(m_pPrediction) + 8);
*(int*)(uintptr_t(m_pPrediction) + 0x20) = 0;
*(bool*)(uintptr_t(m_pPrediction) + 8) = 1;
C_BaseEntity::SetPredictionRandomSeed(cmd);
C_BaseEntity::SetPredictionPlayer(g_ctx.local());
g_ctx.local()->SetCurrentCommand(cmd);
m_pGlobalVars->curtime = static_cast<float>(g_ctx.local()->m_nTickBase()) * m_pGlobalVars->interval_per_tick;
m_pGlobalVars->frametime = *(bool*)(uintptr_t(m_pPrediction) + 0xA)? 0.f : m_pGlobalVars->interval_per_tick;
m_pGameMovement->StartTrackPredictionErrors(g_ctx.local());
m_pMoveHelper->SetHost(g_ctx.local());
m_pPrediction->SetupMove(g_ctx.local(), cmd, m_pMoveHelper, &move_data);
m_pGameMovement->ProcessMovement(g_ctx.local(), &move_data);
m_pPrediction->FinishMove(g_ctx.local(), cmd, &move_data);
m_pGameMovement->FinishTrackPredictionErrors(g_ctx.local());
m_pMoveHelper->SetHost(nullptr);
C_BaseEntity::SetPredictionRandomSeed(nullptr);
C_BaseEntity::SetPredictionPlayer(nullptr);
g_ctx.local()->SetCurrentCommand(nullptr);
g_ctx.local()->set_abs_angles(QAngle(0,real_angle,0));
g_ctx.local()->force_bone_rebuild();
g_ctx.local()->SetupBonesEx();
}
void Prediction::end()
{
if (!g_ctx.local() || !m_pWeapon)
return;
m_pGlobalVars->curtime = m_flCurrentTime;
m_pGlobalVars->frametime = m_flFrameTime;
*(int*)(uintptr_t(m_pPrediction) + 0x20) = m_nServerCommandsAcknowledged;
*(bool*)(uintptr_t(m_pPrediction) + 8) = m_bInPrediction;
}
int Prediction::get_flags()
{
return m_fFlags;
}
CUserCmd Prediction::get_prev_cmd() { return *m_pPrevCmd; }
Vector Prediction::get_velocity() { return m_vecVelocity; }
void Prediction::fix_netvar_compression()
{
auto g_ctx.local = g_ctx.local();
if (g_ctx.local)
{
if (!g_ctx.local->IsDead())
{
const auto &data = m_Data[g_ctx.local->m_nTickBase() % 150];
if (fabsf(g_ctx.local->m_aimPunchAngle().x - data.m_aimPunchAngle.x) < 0.03125f &&
fabsf(g_ctx.local->m_aimPunchAngle().y - data.m_aimPunchAngle.y) < 0.03125f &&
fabsf(g_ctx.local->m_aimPunchAngle().z - data.m_aimPunchAngle.z) < 0.03125f)
g_ctx.local->m_aimPunchAngle() = data.m_aimPunchAngle;
if (fabsf(g_ctx.local->m_aimPunchAngleVel().x - data.m_aimPunchAngleVel.x) < 0.03125f &&
fabsf(g_ctx.local->m_aimPunchAngleVel().y - data.m_aimPunchAngleVel.y) < 0.03125f &&
fabsf(g_ctx.local->m_aimPunchAngleVel().z - data.m_aimPunchAngleVel.z) < 0.03125f)
g_ctx.local->m_aimPunchAngleVel() = data.m_aimPunchAngleVel;
if (fabsf(g_ctx.local->m_vecViewOffset().z - data.m_vecViewOffset.z) < 0.03125f)
g_ctx.local->m_vecViewOffset().z = data.m_vecViewOffset.z;
if (fabsf(g_ctx.local->m_flDuckAmount() - data.m_flDuckAmount) < 0.03125f)
g_ctx.local->m_flDuckAmount() = data.m_flDuckAmount;
g_ctx.local->m_flDuckSpeed() = data.m_flDuckSpeed;
}
}
}
void Prediction::on_run_command(C_BasePlayer* player)
{
auto g_ctx.local = C_CSPlayer::localPlayer();
if (!g_ctx.local || g_ctx.local != player)
return;
auto data = &m_Data[g_ctx.local->m_nTickBase() % 150];
data->m_aimPunchAngle = g_ctx.local->m_aimPunchAngle();
data->m_aimPunchAngleVel = g_ctx.local->m_aimPunchAngleVel();
data->m_vecViewOffset = g_ctx.local->m_vecViewOffset();
data->m_flDuckAmount = g_ctx.local->m_flDuckAmount();
data->m_flDuckSpeed = g_ctx.local->m_flDuckSpeed();
data->m_viewPunchAngle = g_ctx.local->m_viewPunchAngle();
data->m_vecBaseVelocity = g_ctx.local->m_vecBaseVelocity();
data->m_vecVelocity = g_ctx.local->m_vecVelocity();
data->m_vecOrigin = g_ctx.local->m_vecOrigin();
data->m_flFallVelocity = g_ctx.local->m_flFallVelocity();
data->m_flVelocityModifier = g_ctx.local->m_flVelocityModifier();
data->m_hGroundEntity = g_ctx.local->m_hGroundEntity();
data->m_nMoveType = g_ctx.local->m_MoveType();
data->m_nFlags = g_ctx.local->m_fFlags();
if (auto wpn = g_ctx.local->get_weapon(); wpn != nullptr)
{
data->m_fAccuracyPenalty = wpn->m_fAccuracyPenalty();
data->m_flRecoilIndex = wpn->m_flRecoilIndex();
}
data->is_filled = true;
}
}
}
prediction.hpp:
#pragma once
#include "sdk.hpp"
namespace Engine
{
struct player_data
{
void reset()
{
m_aimPunchAngle.clear();
m_aimPunchAngleVel.clear();
m_viewPunchAngle.clear();
m_vecViewOffset.clear();
m_vecBaseVelocity.clear();
m_vecVelocity.clear();
m_vecOrigin.clear();
m_flFallVelocity = 0.0f;
m_flVelocityModifier = 0.0f;
m_flDuckAmount = 0.0f;
m_flDuckSpeed = 0.0f;
m_fAccuracyPenalty = 0.0f;
m_hGroundEntity = 0;
m_nMoveType = 0;
m_nFlags = 0;
m_nTickBase = 0;
m_flRecoilIndex = 0;
}
QAngle m_aimPunchAngle = {};
QAngle m_aimPunchAngleVel = {};
QAngle m_viewPunchAngle = {};
Vector m_vecViewOffset = {};
Vector m_vecBaseVelocity = {};
Vector m_vecVelocity = {};
Vector m_vecOrigin = {};
float m_flFallVelocity = 0.0f;
float m_flVelocityModifier = 0.0f;
float m_flDuckAmount = 0.0f;
float m_flDuckSpeed = 0.0f;
float m_fAccuracyPenalty = 0.0f;
int m_hGroundEntity = 0;
int m_nMoveType = 0;
int m_nFlags = 0;
int m_nTickBase = 0;
int m_flRecoilIndex = 0;
bool is_filled = false;
};
class Prediction : public Core::Singleton<Prediction>
{
public:
void begin(CUserCmd* cmd);
void end();
int get_flags();
CUserCmd get_prev_cmd();
Vector get_velocity();
void fix_netvar_compression();
void on_run_command(C_BasePlayer* player);
CMoveData move_data;
private:
CUserCmd* m_pPrevCmd = nullptr;
C_WeaponCSBaseGun* m_pWeapon = nullptr;
int m_fFlags = 0;
Vector m_vecVelocity = Vector::Zero;
float m_flCurrentTime = 0.0f;
float m_flFrameTime = 0.0f;
int m_nTickBase = 0;
int m_nServerCommandsAcknowledged;
bool m_bInPrediction;
player_data m_Data[150] = {};
};
}