сосиска джем
-
Автор темы
- #1
Всё в шапке.
В bullet_tracer.h
В bullet_tracer.cpp
В bullet_tracer.h
Код:
#pragma once
#include <vector>
#include "../tools/entity.h"
#include "../tools/config.h"
#include "../tools/game.h"
class cbullet_tracer
{
public:
void log(CUserCmd* cmd);
void draw();
private:
class cbullet_tracer_info
{
public:
cbullet_tracer_info(Vector src, Vector dst, float time, Color color)
{
this->src = src;
this->dst = dst;
this->time = time;
this->color = color;
}
Vector src, dst;
float time;
Color color;
};
std::vector<cbullet_tracer_info> logs;
};
extern cbullet_tracer* bullet_tracer;
Код:
#include "bullet_tracer.h"
cbullet_tracer* bullet_tracer = new cbullet_tracer();
void cbullet_tracer::log(CUserCmd * cmd)
{
if (!config.visuals_enabled || !config.visuals_bullet_tracer)
return;
//get local player
auto local = static_cast<C_BasePlayer*>(Interfaces::EntityList()->GetClientEntity(Interfaces::Engine()->GetLocalPlayer()));
if (!local)
return;
//get local player's active weapon
auto weapon = static_cast<C_BaseAttributableItem*>(Interfaces::EntityList()->GetClientEntityFromHandle(*local->GetActiveWeapon()));
if (!weapon)
return;
//get weapon data
auto weapon_data = weapon->GetWeaponData();
if (!weapon_data)
return;
//return if we have an invalid weapon
switch (weapon_data->iWeaponType)
{
case WEAPONTYPE_KNIFE:
case WEAPONTYPE_C4:
case WEAPONTYPE_PLACEHOLDER:
case WEAPONTYPE_GRENADE:
case WEAPONTYPE_UNKNOWN:
return;
default:
break;
}
//get actual server time
float server_time = local->GetTickBase() * Interfaces::Globals()->interval_per_tick;
//return if we aren't pressing fire button or we cant fire
if (!(cmd->buttons & IN_ATTACK) || server_time <= local->GetNextAttack() || server_time <= weapon->GetNextPrimaryAttack())
return;
//calculate spread
weapon->UpdateAccuracyPenalty();
game::RandomSeed((cmd->random_seed & 0xFF) + 1);
float fRand1 = game::RandomFloat(0.f, 1.f);
float fRandPi1 = game::RandomFloat(0.f, 2.f * M_PI);
float fRand2 = game::RandomFloat(0.f, 1.f);
float fRandPi2 = game::RandomFloat(0.f, 2.f * M_PI);
int m_iItemDefinitionIndex = weapon->GetItemDefinitionIndex();
float m_flRecoilIndex = weapon->GetRecoilIndex();
if (m_iItemDefinitionIndex == WEAPON_REVOLVER)
{
if (cmd->buttons & IN_ATTACK2)
{
fRand1 = 1.f - fRand1 * fRand1;
fRand2 = 1.f - fRand2 * fRand2;
}
}
else if (m_iItemDefinitionIndex == WEAPON_NEGEV && m_flRecoilIndex < 3.f)
{
for (int i = 3; i > m_flRecoilIndex; --i)
{
fRand1 *= fRand1;
fRand2 *= fRand2;
}
fRand1 = 1.f - fRand1;
fRand2 = 1.f - fRand2;
}
float fRandInaccuracy = fRand1 * weapon->GetInaccuracy();
float fRandSpread = fRand2 * weapon->GetSpread();
float fSpreadX = cos(fRandPi1) * fRandInaccuracy + cos(fRandPi2) * fRandSpread;
float fSpreadY = sin(fRandPi1) * fRandInaccuracy + sin(fRandPi2) * fRandSpread;
Vector vecForward, vecRight, vecUp, vecDir, vecAntiDir, qAntiSpread;
math::AngleVectors(cmd->viewangles, &vecForward, &vecRight, &vecUp);
vecDir.x = (float)((float)(vecRight.x * fSpreadX) + vecForward.x) + (float)(vecUp.x * fSpreadY);
vecDir.y = (float)((float)(fSpreadX * vecRight.y) + vecForward.y) + (float)(fSpreadY * vecUp.y);
vecDir.z = (float)((float)(vecRight.z * fSpreadX) + vecForward.z) + (float)(vecUp.z * fSpreadY);
vecAntiDir = vecForward + (vecRight * -fSpreadX) + (vecUp * -fSpreadY);
vecAntiDir.NormalizeInPlace();
math::SpreadVectorAngles(vecAntiDir, qAntiSpread);
//add recoil
qAntiSpread += local->GetAimPunch() * 2;
math::NormalizeAngle(qAntiSpread.y);
math::ClampAngle(qAntiSpread);
Vector forward, src, dst;
math::AngleVectors(qAntiSpread, forward);
src = local->GetEyePosition();
dst = src + (forward * weapon_data->flRange);
Ray_t ray;
ray.Init(src, dst);
//skip local player
CTraceFilter filter(local);
//trace a ray to get the point that hits something
trace_t tr;
Interfaces::Trace()->TraceRay(ray, MASK_SHOT, &filter, &tr);
//get color, use different color when we hit a player
auto color = (tr.m_pEnt && tr.hitgroup > 0 && tr.hitgroup <= 7) ? Color(140, 29, 29, 220) : Color(163, 43, 206, 220);
//push info to our vector
logs.push_back(cbullet_tracer_info(src, tr.endpos, server_time, color));
}
void cbullet_tracer::draw()
{
if (!config.visuals_enabled || !config.visuals_bullet_tracer)
return;
//get local player
auto local = static_cast<C_BasePlayer*>(Interfaces::EntityList()->GetClientEntity(Interfaces::Engine()->GetLocalPlayer()));
if (!local)
return;
//get actual server time
float server_time = local->GetTickBase() * Interfaces::Globals()->interval_per_tick;
//loop through our vector
for (size_t i = 0; i < logs.size(); i++)
{
//get the current item
auto current = logs.at(i);
//draw a line from local player's head position to the hit point
Interfaces::DebugOverlay()->AddLineOverlay(current.src, current.dst, current.color.r(), current.color.g(), current.color.b(), true, -1.0f);
//draw a box at the hit point
Interfaces::DebugOverlay()->AddBoxOverlay(current.dst, Vector(-2, -2, -2), Vector(2, 2, 2), Vector(0, 0, 0), 255, 0, 0, 255, -1.0f);
//if the item is older than 5 seconds, delete it
if (fabs(server_time - current.time) > 5.f)
logs.erase(logs.begin() + i);
}
}
Последнее редактирование: