Тьомчик
-
Автор темы
- #1
поскажите это правильная робота бектрека?
переменные
struct backtrack_data
{
float sim_time;
Vector hitbox_position;
matrix3x4_t boneMatrix[128];
matrix3x4_t boneMatrixCur[128];
};
float latency = 0.0f;
float lerp_time = 0.0f;
float correct_time = 0.0f;
float delta_time = 0.0f;
std::map<int, std::deque<backtrack_data>> data;
get convars & lerp_time & latency:
static ConVar* sv_max_unlag = g_CVar->FindVar("sv_maxunlag");
static ConVar* sv_min_update_rate = g_CVar->FindVar("sv_minupdaterate");
static ConVar* sv_max_update_rate = g_CVar->FindVar("sv_maxupdaterate");
static ConVar* sv_client_min_interp_ratio = g_CVar->FindVar("sv_client_min_interp_ratio");
static ConVar* sv_client_max_interp_ratio = g_CVar->FindVar("sv_client_max_interp_ratio");
static ConVar* cl_interp_ratio = g_CVar->FindVar("cl_interp_ratio");
static ConVar* cl_interp = g_CVar->FindVar("cl_interp");
static ConVar* cl_updaterate = g_CVar->FindVar("cl_updaterate");
float float_max_unlag = sv_max_unlag->GetFloat();
float float_update_rate = cl_updaterate->GetFloat();
float float_min_update_rate = sv_min_update_rate->GetFloat();
float float_max_update_rate = sv_max_update_rate->GetFloat();
float float_min_interp = sv_client_min_interp_ratio->GetFloat();
float float_max_interp = sv_client_max_interp_ratio->GetFloat();
float float_lerp_amount = cl_interp->GetFloat();
float float_lerp_ratio = cl_interp_ratio->GetFloat();
float_lerp_ratio = std::clamp(float_lerp_ratio, float_min_interp, float_max_interp);
if (float_lerp_ratio == 0.0f)
{
float_lerp_ratio = 1.0f;
}
float update_rate = std::clamp(float_update_rate, float_min_update_rate, float_max_update_rate);
latency = g_EngineClient->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING) + g_EngineClient->GetNetChannelInfo()->GetLatency(FLOW_INCOMING);
lerp_time = std::fmaxf(float_lerp_amount, float_lerp_ratio / update_rate);
setup/record hitboxes:
for (auto i = 1; i < g_GlobalVars->maxClients; i++)
{
player_t* entity = player_t::GetPlayerByIndex(i);
// i do here checks
auto& cur_data = data[i];
if (!cur_data.empty())
{
auto& front = cur_data.front();
if (front.sim_time == entity->simulation_time())
{
continue;
}
while (!cur_data.empty())
{
auto& back = cur_data.back();
correct_time += latency;
correct_time += lerp_time;
correct_time = std::clamp(correct_time, 0.f, float_max_unlag);
delta_time = correct_time - (g_GlobalVars->curtime - back.sim_time);
if (std::fabs(delta_time) > 0.2f)
{
break;
}
cur_data.pop_back();
}
}
auto model = entity->GetModel();
if (!model)
{
continue;
}
auto hdr = g_MdlInfo->GetStudiomodel(model);
if (!hdr)
{
continue;
}
auto hitbox_set = hdr->GetHitboxSet(entity->hitbox_set());
auto hitbox_head = hitbox_set->GetHitbox(HITBOX_HEAD);
auto hitbox_center = (hitbox_head->bbmin + hitbox_head->bbmax) * 0.5f;
backtrack_data bd;
bd.sim_time = entity->simulation_time();
*(Vector*)((uintptr_t)entity + 0xA0) = entity->origin();
*(int*)((uintptr_t)entity + 0xA68) = 0;
*(int*)((uintptr_t)entity + 0xA30) = 0;
entity->InvalidateBoneCache();
entity->SetupBones(bd.boneMatrix, 128, 256, g_GlobalVars->curtime);
math::vector_transform(hitbox_center, bd.boneMatrix[hitbox_head->bone], bd.hitbox_position);
data[i].push_front(bd);
}
backtrack shoot & fov:
int tick_count = -1;
float best_fov = current_settings.fov;
for (auto& node : data)
{
auto& cur_data = node.second;
if (cur_data.empty())
{
continue;
}
for (auto& bd : cur_data)
{
if (std::fabsf(delta_time) > 0.2f)
{
continue;
}
float fov = math::calculate_fov(csgo::local_player->get_eye_pos(), bd.hitbox_position, cmd->viewangles);
if (fov < best_fov)
{
best_fov = fov;
tick_count = TIME_TO_TICKS(bd.sim_time + lerp_time);
}
}
}
if (tick_count != -1)
{
cmd->tick_count = tick_count;
}
переменные
struct backtrack_data
{
float sim_time;
Vector hitbox_position;
matrix3x4_t boneMatrix[128];
matrix3x4_t boneMatrixCur[128];
};
float latency = 0.0f;
float lerp_time = 0.0f;
float correct_time = 0.0f;
float delta_time = 0.0f;
std::map<int, std::deque<backtrack_data>> data;