Logging upgrade and aimbot fix
Logging now uses modern c++ as far as much as possible, aimbot now checks if it can actually hit the head
This commit is contained in:
parent
faf35624e1
commit
c9f23a80e5
@ -7,14 +7,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace logging
|
||||
{
|
||||
#endif
|
||||
|
||||
extern FILE *handle;
|
||||
extern std::ofstream handle;
|
||||
|
||||
void Initialize();
|
||||
void Shutdown();
|
||||
|
@ -88,7 +88,7 @@ void VectorAngles(Vector &forward, Vector &angles);
|
||||
void AngleVectors2(const QAngle &angles, Vector *forward);
|
||||
extern std::mutex trace_lock;
|
||||
bool IsEntityVisible(CachedEntity *entity, int hb);
|
||||
bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos);
|
||||
bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos, trace_t *trace = nullptr);
|
||||
bool VisCheckEntFromEnt(CachedEntity *startEnt, CachedEntity *endEnt);
|
||||
bool VisCheckEntFromEntVector(Vector startVector, CachedEntity *startEnt, CachedEntity *endEnt);
|
||||
Vector VischeckCorner(CachedEntity *player, CachedEntity *target, float maxdist, bool checkWalkable);
|
||||
|
@ -16,48 +16,47 @@
|
||||
|
||||
settings::Bool log_to_console{ "hack.log-console", "false" };
|
||||
|
||||
FILE *logging::handle{ nullptr };
|
||||
std::ofstream logging::handle;
|
||||
|
||||
void logging::Initialize()
|
||||
{
|
||||
// FIXME other method of naming the file?
|
||||
passwd *pwd = getpwuid(getuid());
|
||||
logging::handle = fopen(strfmt("/tmp/cathook-%s-%d.log", pwd->pw_name, getpid()).get(), "w");
|
||||
logging::handle = std::ofstream(strfmt("/tmp/cathook-%s-%d.log", pwd->pw_name, getpid()).get());
|
||||
if (!logging::handle.is_open())
|
||||
throw std::runtime_error("Can't open logging file");
|
||||
}
|
||||
|
||||
void logging::Info(const char *fmt, ...)
|
||||
{
|
||||
if (logging::handle == nullptr)
|
||||
if (!logging::handle.is_open())
|
||||
logging::Initialize();
|
||||
char *buffer = new char[1024];
|
||||
auto time = std::time(nullptr);
|
||||
auto tm = *std::localtime(&time);
|
||||
|
||||
// Argument list
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
vsprintf(buffer, fmt, list);
|
||||
// Allocate buffer
|
||||
auto result = std::make_unique<char[]>(512);
|
||||
// Fill buffer
|
||||
if (vsnprintf(result.get(), 512, fmt, list) < 0)
|
||||
return;
|
||||
va_end(list);
|
||||
size_t length = strlen(buffer);
|
||||
char *result = new char[length + 24];
|
||||
time_t current_time;
|
||||
struct tm *time_info = nullptr;
|
||||
char timeString[10];
|
||||
time(¤t_time);
|
||||
time_info = localtime(¤t_time);
|
||||
strftime(timeString, sizeof(timeString), "%H:%M:%S", time_info);
|
||||
sprintf(result, "%% [%s] %s\n", timeString, buffer);
|
||||
fprintf(logging::handle, "%s", result);
|
||||
fflush(logging::handle);
|
||||
|
||||
// Print to file
|
||||
logging::handle << std::put_time(&tm, "%H:%M:%S ") << result.get() << std::endl;
|
||||
// Print to console
|
||||
#if ENABLE_VISUALS
|
||||
if (!hack::shutdown)
|
||||
{
|
||||
if (*log_to_console)
|
||||
g_ICvar->ConsolePrintf("%s", result);
|
||||
g_ICvar->ConsolePrintf("CAT: %s \n", result.get());
|
||||
}
|
||||
#endif
|
||||
delete[] buffer;
|
||||
delete[] result;
|
||||
}
|
||||
|
||||
void logging::Shutdown()
|
||||
{
|
||||
fclose(logging::handle);
|
||||
logging::handle = nullptr;
|
||||
logging::handle.close();
|
||||
}
|
||||
|
@ -905,7 +905,7 @@ int BestHitbox(CachedEntity *target)
|
||||
{
|
||||
|
||||
// Switch based apon the hitbox mode set by the user
|
||||
switch ((int) hitbox_mode)
|
||||
switch (*hitbox_mode)
|
||||
{
|
||||
case 0:
|
||||
{ // AUTO-HEAD priority
|
||||
@ -1109,7 +1109,10 @@ bool VischeckPredictedEntity(CachedEntity *entity, bool Backtracking)
|
||||
{
|
||||
// Update info
|
||||
cd.vcheck_tick = tickcount;
|
||||
cd.visible = IsEntityVectorVisible(entity, PredictEntity(entity));
|
||||
trace_t trace;
|
||||
cd.visible = IsEntityVectorVisible(entity, PredictEntity(entity), &trace);
|
||||
if (cd.visible && cd.hitbox == head && trace.hitbox != head)
|
||||
cd.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -359,7 +359,10 @@ bool canReachVector(Vector loc, Vector dest)
|
||||
trace_t trace;
|
||||
Ray_t ray;
|
||||
ray.Init(vec, directionalLoc);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace);
|
||||
{
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace);
|
||||
}
|
||||
// distance of trace < than 26
|
||||
if (trace.startpos.DistTo(trace.endpos) < 26.0f)
|
||||
return false;
|
||||
@ -399,7 +402,10 @@ bool canReachVector(Vector loc, Vector dest)
|
||||
trace_t trace;
|
||||
Ray_t ray;
|
||||
ray.Init(loc, directionalLoc);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace);
|
||||
{
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace);
|
||||
}
|
||||
// distance of trace < than 26
|
||||
if (trace.startpos.DistTo(trace.endpos) < 26.0f)
|
||||
return false;
|
||||
@ -723,9 +729,11 @@ bool IsEntityVisible(CachedEntity *entity, int hb)
|
||||
}
|
||||
|
||||
std::mutex trace_lock;
|
||||
bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos)
|
||||
bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos, trace_t *trace)
|
||||
{
|
||||
trace_t trace_object;
|
||||
if (!trace)
|
||||
trace = &trace_object;
|
||||
Ray_t ray;
|
||||
|
||||
if (g_Settings.bInvalid)
|
||||
@ -742,9 +750,9 @@ bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos)
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
std::lock_guard<std::mutex> lock(trace_lock);
|
||||
if (!tcm || g_Settings.is_create_move)
|
||||
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, &trace_object);
|
||||
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, trace);
|
||||
}
|
||||
return (((IClientEntity *) trace_object.m_pEnt) == RAW_ENT(entity) || trace_object.fraction >= 0.99f);
|
||||
return (((IClientEntity *) trace->m_pEnt) == RAW_ENT(entity) || trace->fraction >= 0.99f);
|
||||
}
|
||||
|
||||
// For when you need to vis check something that isnt the local player
|
||||
@ -1048,6 +1056,7 @@ bool IsVectorVisible(Vector origin, Vector target, bool enviroment_only)
|
||||
|
||||
trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity));
|
||||
ray.Init(origin, target);
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_no_player, &trace_visible);
|
||||
return (trace_visible.fraction == 1.0f);
|
||||
}
|
||||
@ -1058,6 +1067,7 @@ bool IsVectorVisible(Vector origin, Vector target, bool enviroment_only)
|
||||
|
||||
trace::filter_no_entity.SetSelf(RAW_ENT(g_pLocalPlayer->entity));
|
||||
ray.Init(origin, target);
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_no_entity, &trace_visible);
|
||||
return (trace_visible.fraction == 1.0f);
|
||||
}
|
||||
@ -1082,7 +1092,10 @@ void WhatIAmLookingAt(int *result_eindex, Vector *result_pos)
|
||||
forward.z = -sp;
|
||||
forward = forward * 8192.0f + g_pLocalPlayer->v_Eye;
|
||||
ray.Init(g_pLocalPlayer->v_Eye, forward);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_default, &trace);
|
||||
{
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_default, &trace);
|
||||
}
|
||||
if (result_pos)
|
||||
*result_pos = trace.endpos;
|
||||
if (result_eindex)
|
||||
@ -1250,7 +1263,10 @@ bool IsEntityVisiblePenetration(CachedEntity *entity, int hb)
|
||||
return false;
|
||||
}
|
||||
ray.Init(g_pLocalPlayer->v_Origin + g_pLocalPlayer->v_ViewOffset, hit);
|
||||
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_penetration, &trace_visible);
|
||||
{
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_penetration, &trace_visible);
|
||||
}
|
||||
correct_entity = false;
|
||||
if (trace_visible.m_pEnt)
|
||||
{
|
||||
@ -1258,7 +1274,10 @@ bool IsEntityVisiblePenetration(CachedEntity *entity, int hb)
|
||||
}
|
||||
if (!correct_entity)
|
||||
return false;
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_default, &trace_visible);
|
||||
{
|
||||
PROF_SECTION(IEVV_TraceRay);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_default, &trace_visible);
|
||||
}
|
||||
if (trace_visible.m_pEnt)
|
||||
{
|
||||
ent = (IClientEntity *) trace_visible.m_pEnt;
|
||||
|
Reference in New Issue
Block a user