Skip to content

Commit

Permalink
minor optimization stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nullifiedcat committed Feb 26, 2017
1 parent 5c01617 commit 005415d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#ifndef CATHOOK_BUILD_NUMBER
#define CATHOOK_BUILD_NUMBER "LATEST"
#endif
#define CATHOOK_BUILD_NAME "Butterscotch Pie"
#define CATHOOK_BUILD_NAME "Cat's Eye"

#define CON_NAME "cat"
#define CON_PREFIX CON_NAME "_"
Expand Down
4 changes: 4 additions & 0 deletions src/crits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#define CRITS_H_

class CUserCmd;
class IClientEntity;

bool RandomCrits();
bool WeaponCanCrit();
bool IsAttackACrit(CUserCmd* cmd);

//bool CalcIsAttackCritical(IClientEntity* weapon);


#endif /* CRITS_H_ */
9 changes: 8 additions & 1 deletion src/entitycache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void CachedEntity::Update(int idx) {

m_ESPOrigin.Zero();

m_nESPStrings = 0;
m_IDX = idx;
m_pEntity = interfaces::entityList->GetClientEntity(idx);
if (!m_pEntity) {
Expand Down Expand Up @@ -228,6 +227,14 @@ EntityCache::~EntityCache() {
delete [] m_pArray;
}

void CachedEntity::PruneStrings() {
m_nESPStrings = 0;
}

void EntityCache::PruneStrings() {
for (int i = 0; i < m_nMax && i < MAX_ENTITIES; i++) m_pArray[i].PruneStrings();
}

void EntityCache::Update() {
m_nMax = interfaces::entityList->GetHighestEntityIndex();
for (int i = 0; i < m_nMax && i < MAX_ENTITIES; i++) {
Expand Down
4 changes: 3 additions & 1 deletion src/entitycache.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct mstudiobbox_t;
#define CE_VECTOR(entity, offset) CE_VAR(entity, offset, Vector)

#define CE_GOOD_NO_DORMANT_CHECK(entity) (!g_Settings.bInvalid && dynamic_cast<CachedEntity*>(entity) && dynamic_cast<IClientEntity*>(entity->m_pEntity))
#define CE_GOOD(entity) (!g_Settings.bInvalid && dynamic_cast<CachedEntity*>(entity) && dynamic_cast<IClientEntity*>(entity->m_pEntity) && !entity->m_pEntity->IsDormant())
#define CE_GOOD(entity) (!g_Settings.bInvalid && dynamic_cast<CachedEntity*>(entity) && dynamic_cast<IClientEntity*>(entity->m_pEntity) && entity->m_pEntity->GetIClientEntity() && !entity->m_pEntity->GetIClientEntity()->IsDormant())
#define CE_BAD(entity) (!CE_GOOD(entity))

#define IDX_GOOD(idx) (idx >= 0 && idx < HIGHEST_ENTITY && idx < MAX_ENTITIES)
Expand Down Expand Up @@ -107,6 +107,7 @@ class CachedEntity {
~CachedEntity();

void Update(int idx);
void PruneStrings();
void AddESPString(const char* string, ...);
ESPStringCompound& GetESPString(int idx);

Expand Down Expand Up @@ -166,6 +167,7 @@ class EntityCache {
~EntityCache();

void Update();
void PruneStrings();
void Invalidate();
CachedEntity* GetEntity(int idx);

Expand Down
2 changes: 1 addition & 1 deletion src/hack.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
g_ph##x = new x()

#define HACK_PROCESS_USERCMD(x, y) \
g_ph##x->ProcessUserCmd(y)
{ PROF_SECTION(x); g_ph##x->ProcessUserCmd(y); }

#define HACK_DRAW(x) \
g_ph##x->Draw()
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/CreateMove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
}
bool ret = ((CreateMove_t*)hooks::hkClientMode->GetMethod(hooks::offCreateMove))(thisptr, inputSample, cmd);

//PROF_SECTION(CreateMove);
PROF_SECTION(CreateMove);

if (!cmd) {
return ret;
Expand Down Expand Up @@ -82,11 +82,13 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
gEntityCache.Invalidate();
}
// PROF_BEGIN();
SAFE_CALL(gEntityCache.Update());
{ PROF_SECTION(EntityCache); SAFE_CALL(gEntityCache.Update()); }
// PROF_END("Entity Cache updating");
SAFE_CALL(g_pPlayerResource->Update());
SAFE_CALL(g_pLocalPlayer->Update());
g_Settings.bInvalid = false;
if (!cmd->command_number) return ret;
gEntityCache.PruneStrings();
if (CE_GOOD(g_pLocalPlayer->entity)) {
g_pLocalPlayer->v_OrigViewangles = cmd->viewangles;
// PROF_BEGIN();
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/PaintTraverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "hookedmethods.h"
#include "../gui/GUI.h"
#include "../segvcatch/segvcatch.h"
#include "../profiler.h"

void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) {
#if DEBUG_SEGV == true
Expand All @@ -33,6 +34,7 @@ void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) {


if (call_default) SAFE_CALL(((PaintTraverse_t*)hooks::hkPanel->GetMethod(hooks::offPaintTraverse))(p, vp, fr, ar));
PROF_SECTION(PaintTraverse);
if (vp == panel_top) draw_flag = true;
if (!g_Settings.bHackEnabled->GetBool()) return;
// Because of single-multi thread shit I'm gonna put this thing riiiight here.
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/hookedmethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ typedef void(LevelInit_t)(void*, const char*);
typedef void(LevelShutdown_t)(void*);
typedef void(BeginFrame_t)(IStudioRender*);
typedef bool(*CanInspect_t)(IClientEntity*);
//typedef void(*CInput__CreateMove_t)(void*, int, float, bool);
//void CInput__CreateMove_hook(void*, int sequence_number, float input_sample_frametime, bool active);
bool CanInspect_hook(IClientEntity*);
const unsigned int offCanInspect = 512;
void BeginFrame_hook(IStudioRender*);
Expand Down
2 changes: 1 addition & 1 deletion src/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ProfilerNode {
ProfilerSection& m_section;
};

#define ENABLE_PROFILER true
#define ENABLE_PROFILER false
#if ENABLE_PROFILER
#define PROF_SECTION(id) \
static ProfilerSection __PROFILER__##id(#id); \
Expand Down

0 comments on commit 005415d

Please sign in to comment.