-
Автор темы
- #1
predfix.cpp:
#include "globals.hpp"
#include "predfix.hpp"
#include "event_logs.hpp"
// fix all wrong values for predicted netvars
void c_prediction_fix::store(int tick)
{
auto netvars = &compressed_netvars[tick % 150];
netvars->store(tick);
}
void c_prediction_fix::fix_netvars(int tick)
{
pred_error_occured = false;
auto netvars = &compressed_netvars[tick % 150];
if (!netvars->filled || netvars->cmd_number != tick)
return;
if (netvars->tickbase != 0 && HACKS->local->tickbase() != netvars->tickbase)
return;
//if ( checks )
// EVENT_LOGS->info_push_message(XOR("The information from the server didn't come true on the client, prediction error occured"), { 255, 99, 99 });
auto aim_punch_diff = netvars->aimpunch - HACKS->local->aim_punch_angle();
if (std::abs(aim_punch_diff.x) <= 0.03125f && std::abs(aim_punch_diff.y) <= 0.03125 && std::abs(aim_punch_diff.z) <= 0.03125f)
HACKS->local->aim_punch_angle() = netvars->aimpunch;
else
pred_error_occured = true;
auto view_punch_diff = netvars->viewpunch - HACKS->local->view_punch_angle();
if (std::abs(view_punch_diff.x) <= 0.03125f && std::abs(view_punch_diff.y) <= 0.03125f && std::abs(view_punch_diff.z) <= 0.03125f)
HACKS->local->view_punch_angle() = netvars->viewpunch;
else
pred_error_occured = true;
auto aim_punch_vel_diff = netvars->aimpunch_vel - HACKS->local->aim_punch_angle_vel();
if (std::abs(aim_punch_vel_diff.x) <= 0.03125f && std::abs(aim_punch_vel_diff.y) <= 0.03125 && std::abs(aim_punch_vel_diff.z) <= 0.03125f)
HACKS->local->aim_punch_angle_vel() = netvars->aimpunch_vel;
else
pred_error_occured = true;
auto view_offset_diff = netvars->viewoffset - HACKS->local->view_offset();
if (std::abs(view_offset_diff.z) <= 0.065f)
HACKS->local->view_offset() = netvars->viewoffset;
else
pred_error_occured = true;
auto origin_diff = netvars->origin - HACKS->local->origin();
if (std::abs(origin_diff.x ) < 0.03125f && std::abs(origin_diff.y ) < 0.03125f && std::abs(origin_diff.z ) < 0.03125f )
HACKS->local->origin() = netvars->origin;
else
pred_error_occured = true;
auto fall_velocity_diff = netvars->fall_velocity - HACKS->local->fall_velocity();
if (std::abs(fall_velocity_diff) <= 0.5f)
HACKS->local->fall_velocity() = netvars->fall_velocity;
else
pred_error_occured = true;
auto crouch_amount_diff = netvars->duck_amount - HACKS->local->duck_amount();
if (std::abs(crouch_amount_diff) < 0.03125f)
{
HACKS->local->duck_amount() = netvars->duck_amount;
HACKS->local->duck_speed() = netvars->duck_speed;
}
else
pred_error_occured = true;
auto velocity_modifier_diff = netvars->velocity_modifier - HACKS->local->velocity_modifier();
if (std::abs(velocity_modifier_diff) < 0.03125f)
HACKS->local->velocity_modifier() = netvars->velocity_modifier;
else
pred_error_occured = true;
auto base_velocity_diff = netvars->base_velocity - HACKS->local->base_velocity();
if (std::abs(base_velocity_diff.x) < 0.03125f && std::abs(base_velocity_diff.y) < 0.03125f && std::abs(base_velocity_diff.z) < 0.03125f)
HACKS->local->base_velocity() = netvars->base_velocity;
else
pred_error_occured = true;
auto velocity_diff = netvars->velocity - HACKS->local->velocity();
if (std::abs(velocity_diff.x) > 0.5f || std::abs(velocity_diff.y) > 0.5f || std::abs(velocity_diff.z) > 0.5f)
pred_error_occured = true;
auto net_origin_diff = netvars->network_origin - HACKS->local->network_origin();
if (std::abs(net_origin_diff.x) > 0.0625f || std::abs(net_origin_diff.y) > 0.0625f || std::abs(net_origin_diff.z) > 0.0625f)
pred_error_occured = true;
if (!pred_error_occured)
return;
HACKS->prediction->prev_start_frame = -1;
HACKS->prediction->commands_predicted = 0;
HACKS->prediction->prev_ack_had_errors = 1;
}
predfix.hpp:
#pragma once
class c_prediction_fix
{
private:
struct compressed_netvars_t
{
bool filled{};
int cmd_number{};
int tickbase{};
float fall_velocity{};
float velocity_modifier{};
float stamina{};
float duck_amount{};
float duck_speed{};
vec3_t aimpunch{};
vec3_t viewpunch{};
vec3_t aimpunch_vel{};
vec3_t viewoffset{};
vec3_t origin{};
vec3_t base_velocity{};
vec3_t velocity{};
vec3_t network_origin{};
INLINE void store(int tick)
{
tickbase = HACKS->local->tickbase();
fall_velocity = HACKS->local->fall_velocity();
velocity_modifier = HACKS->local->velocity_modifier();
aimpunch = HACKS->local->aim_punch_angle();
viewpunch = HACKS->local->view_punch_angle();
aimpunch_vel = HACKS->local->aim_punch_angle_vel();
viewoffset = HACKS->local->view_offset();
origin = HACKS->local->origin();
base_velocity = HACKS->local->base_velocity();
velocity = HACKS->local->velocity();
network_origin = HACKS->local->network_origin();
stamina = HACKS->local->stamina();
duck_amount = HACKS->local->duck_amount();
duck_speed = HACKS->local->duck_speed();
cmd_number = tick;
filled = true;
}
INLINE void reset()
{
filled = false;
cmd_number = 0;
tickbase = 0;
fall_velocity = 0.f;
velocity_modifier = 0.f;
stamina = 0.f;
aimpunch.reset();
viewpunch.reset();
aimpunch_vel.reset();
viewoffset.reset();
origin.reset();
base_velocity.reset();
velocity.reset();
network_origin.reset();
}
};
struct ping_backup_t
{
int cs_tickcount{};
int tickcount{};
float curtime{};
float frametime{};
INLINE void store()
{
if (!HACKS->client_state)
return;
curtime = HACKS->global_vars->curtime;
frametime = HACKS->global_vars->frametime;
tickcount = HACKS->global_vars->tickcount;
cs_tickcount = HACKS->client_state->old_tickcount;
}
INLINE void restore()
{
if (!HACKS->client_state)
return;
HACKS->global_vars->curtime = curtime;
HACKS->global_vars->frametime = frametime;
HACKS->global_vars->tickcount = tickcount;
HACKS->client_state->old_tickcount = cs_tickcount;
}
INLINE void reset()
{
cs_tickcount = 0;
tickcount = 0;
curtime = 0.f;
frametime = 0.f;
}
};
compressed_netvars_t compressed_netvars[150]{};
public:
bool pred_error_occured{};
float velocity_modifier{};
ping_backup_t ping_backup{};
INLINE void reset()
{
pred_error_occured = false;
velocity_modifier = 0.f;
ping_backup.reset();
for (auto& i : compressed_netvars)
i.reset();
}
INLINE bool available()
{
if (!HACKS->engine->is_connected() || !HACKS->engine->is_in_game())
return false;
auto net_chan = HACKS->engine->get_net_channel();
if (!net_chan)
return false;
if (net_chan->is_loopback())
return false;
return true;
}
INLINE bool should_reduce_ping()
{
if (!available())
return false;
ping_backup.restore();
return true;
}
INLINE void update_ping_values(bool final_tick)
{
if (!available())
return;
static auto original_packet = hooker::get_original(&hooks::detour::read_packets);
ping_backup_t backup;
backup.store();
original_packet(final_tick);
ping_backup.store();
backup.restore();
}
INLINE compressed_netvars_t* get_compressed_netvars(int cmd)
{
return &compressed_netvars[cmd % 150];
}
void fix_netvars(int tick);
void store(int tick);
};
#ifdef _DEBUG
inline auto PREDFIX = std::make_unique<c_prediction_fix>();
#else
CREATE_DUMMY_PTR(c_prediction_fix);
DECLARE_XORED_PTR(c_prediction_fix, GET_XOR_KEYUI32);
#define PREDFIX XORED_PTR(c_prediction_fix)
#endif