diff --git a/include/Constants.hpp b/include/Constants.hpp new file mode 100644 index 00000000..e494dc4d --- /dev/null +++ b/include/Constants.hpp @@ -0,0 +1,17 @@ +/* + * Constants.hpp + * + * Created on: October 16, 2019 + * Author: LightCat + */ + +// This file will include global constant expressions +#pragma once +#include + +constexpr const char *CON_PREFIX = "cat_"; + +constexpr int MAX_ENTITIES = 2048; +constexpr int MAX_PLAYERS = 32; +// 0 is "World" but we still can have MAX_PLAYERS players, so consider that +constexpr int PLAYER_ARRAY_SIZE = 1 + MAX_PLAYERS; diff --git a/include/angles.hpp b/include/angles.hpp index 305b9828..f2299465 100644 --- a/include/angles.hpp +++ b/include/angles.hpp @@ -77,13 +77,13 @@ struct angle_data_s int angle_count{ 0 }; }; -extern angle_data_s data_[32]; +extern angle_data_s data_[MAX_PLAYERS]; void Update(); inline angle_data_s &data_idx(int index) { - if (index < 1 || index > 32) + if (index < 1 || index > MAX_PLAYERS) { throw std::out_of_range("Angle table entity index out of range"); } diff --git a/include/chatstack.hpp b/include/chatstack.hpp index a1f48ef2..8cec1c1d 100644 --- a/include/chatstack.hpp +++ b/include/chatstack.hpp @@ -7,7 +7,7 @@ #pragma once -#define CHATSTACK_INTERVAL 0.8f +constexpr float CHATSTACK_INTERVAL = 0.8f; #include "config.h" #include diff --git a/include/common.hpp b/include/common.hpp index b3b7a08e..595362f3 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -47,6 +47,7 @@ #include "averager.hpp" #include "core/macros.hpp" +#include "Constants.hpp" #if ENABLE_VISUALS #include #include @@ -121,9 +122,6 @@ template constexpr T _clamp(T _min, T _max, T _val) #define SQR(x) (x) * (x) -#define CON_NAME "cat" -#define CON_PREFIX CON_NAME "_" - #define SUPER_VERBOSE_DEBUG false #if SUPER_VERBOSE_DEBUG == true #define SVDBG(...) logging::Info(__VA_ARGS__) diff --git a/include/entitycache.hpp b/include/entitycache.hpp index 882c20dd..e8fb7fc4 100644 --- a/include/entitycache.hpp +++ b/include/entitycache.hpp @@ -24,6 +24,7 @@ #include "classinfo/classinfo.hpp" #include "classinfo/tf2.gen.hpp" #include "client_class.h" +#include "Constants.hpp" struct matrix3x4_t; @@ -33,8 +34,7 @@ struct model_t; struct mstudiohitboxset_t; struct mstudiobbox_t; -#define MAX_STRINGS 16 -#define MAX_ENTITIES 2048 +constexpr int MAX_STRINGS = 16; #define PROXY_ENTITY true diff --git a/include/entityhitboxcache.hpp b/include/entityhitboxcache.hpp index 049bfd67..db4e91c5 100644 --- a/include/entityhitboxcache.hpp +++ b/include/entityhitboxcache.hpp @@ -15,7 +15,7 @@ #include class CachedEntity; -#define CACHE_MAX_HITBOXES 64 +constexpr int CACHE_MAX_HITBOXES = 64; namespace hitbox_cache { diff --git a/include/globals.h b/include/globals.h index 639edf5c..e16c50fc 100755 --- a/include/globals.h +++ b/include/globals.h @@ -9,6 +9,7 @@ #include #include #include +#include "Constants.hpp" class Vector; class CUserCmd; @@ -29,9 +30,9 @@ extern int last_cmd_number; extern time_t time_injected; struct brutestruct { - int brutenum[33]; - Vector last_angles[33]; - std::deque choke[33]; + int brutenum[PLAYER_ARRAY_SIZE]; + Vector last_angles[PLAYER_ARRAY_SIZE]; + std::deque choke[PLAYER_ARRAY_SIZE]; float lastsimtime; }; class GlobalSettings diff --git a/include/hacks/Backtrack.hpp b/include/hacks/Backtrack.hpp index 84360642..3e04d9e2 100644 --- a/include/hacks/Backtrack.hpp +++ b/include/hacks/Backtrack.hpp @@ -52,7 +52,7 @@ struct CIncomingSequence }; typedef boost::circular_buffer_space_optimized circular_buf; extern circular_buf sequences; -extern BacktrackData headPositions[33][66]; +extern BacktrackData headPositions[PLAYER_ARRAY_SIZE][66]; extern bool isBacktrackEnabled; extern bool Vischeck_Success; diff --git a/include/hacks/ac/aimbot.hpp b/include/hacks/ac/aimbot.hpp index 972acb8b..8e209bb1 100644 --- a/include/hacks/ac/aimbot.hpp +++ b/include/hacks/ac/aimbot.hpp @@ -23,7 +23,7 @@ struct ac_data int check_timer; int last_weapon; }; -extern int amount[32]; +extern int amount[MAX_PLAYERS]; void ResetEverything(); std::unordered_map &player_orgs(); diff --git a/include/hacks/ac/antiaim.hpp b/include/hacks/ac/antiaim.hpp index 89b4868f..006150da 100644 --- a/include/hacks/ac/antiaim.hpp +++ b/include/hacks/ac/antiaim.hpp @@ -13,7 +13,7 @@ class CachedEntity; namespace ac::antiaim { -extern int amount[32]; +extern int amount[MAX_PLAYERS]; void ResetEverything(); void ResetPlayer(int idx); diff --git a/include/helpers.hpp b/include/helpers.hpp index be5bc3cd..03ac5861 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -19,8 +19,8 @@ class Vector; class ICvar; void SetCVarInterface(ICvar *iface); -#define PI 3.14159265358979323846f -#define RADPI 57.295779513082f +constexpr float PI = 3.14159265358979323846f; +constexpr float RADPI = 57.295779513082f; //#define DEG2RAD(x) (float)(x) * (float)(PI / 180.0f) #include diff --git a/include/sdk/in_buttons.h b/include/sdk/in_buttons.h index f1b9cc35..3ed0b653 100644 --- a/include/sdk/in_buttons.h +++ b/include/sdk/in_buttons.h @@ -11,29 +11,29 @@ #pragma once #endif -#define IN_ATTACK (1 << 0) -#define IN_JUMP (1 << 1) -#define IN_DUCK (1 << 2) -#define IN_FORWARD (1 << 3) -#define IN_BACK (1 << 4) -#define IN_USE (1 << 5) -#define IN_CANCEL (1 << 6) -#define IN_LEFT (1 << 7) -#define IN_RIGHT (1 << 8) -#define IN_MOVELEFT (1 << 9) -#define IN_MOVERIGHT (1 << 10) -#define IN_ATTACK2 (1 << 11) -#define IN_RUN (1 << 12) -#define IN_RELOAD (1 << 13) -#define IN_ALT1 (1 << 14) -#define IN_ALT2 (1 << 15) -#define IN_SCORE (1 << 16) // Used by client.dll for when scoreboard is held down -#define IN_SPEED (1 << 17) // Player is holding the speed key -#define IN_WALK (1 << 18) // Player holding walk key -#define IN_ZOOM (1 << 19) // Zoom key for HUD zoom -#define IN_WEAPON1 (1 << 20) // weapon defines these bits -#define IN_WEAPON2 (1 << 21) // weapon defines these bits -#define IN_BULLRUSH (1 << 22) -#define IN_GRENADE1 (1 << 23) // grenade 1 -#define IN_GRENADE2 (1 << 24) // grenade 2 -#define IN_ATTACK3 (1 << 25) +constexpr int IN_ATTACK = (1 << 0); +constexpr int IN_JUMP = (1 << 1); +constexpr int IN_DUCK = (1 << 2); +constexpr int IN_FORWARD = (1 << 3); +constexpr int IN_BACK = (1 << 4); +constexpr int IN_USE = (1 << 5); +constexpr int IN_CANCEL = (1 << 6); +constexpr int IN_LEFT = (1 << 7); +constexpr int IN_RIGHT = (1 << 8); +constexpr int IN_MOVELEFT = (1 << 9); +constexpr int IN_MOVERIGHT = (1 << 10); +constexpr int IN_ATTACK2 = (1 << 11); +constexpr int IN_RUN = (1 << 12); +constexpr int IN_RELOAD = (1 << 13); +constexpr int IN_ALT1 = (1 << 14); +constexpr int IN_ALT2 = (1 << 15); +constexpr int IN_SCORE = (1 << 16); // Used by client.dll for when scoreboard is held down +constexpr int IN_SPEED = (1 << 17); // Player is holding the speed key +constexpr int IN_WALK = (1 << 18); // Player holding walk key +constexpr int IN_ZOOM = (1 << 19); // Zoom key for HUD zoom +constexpr int IN_WEAPON1 = (1 << 20); // weapon defines these bits +constexpr int IN_WEAPON2 = (1 << 21); // weapon defines these bits +constexpr int IN_BULLRUSH = (1 << 22); +constexpr int IN_GRENADE1 = (1 << 23); // grenade 1 +constexpr int IN_GRENADE2 = (1 << 24); // grenade 2 +constexpr int IN_ATTACK3 = (1 << 25); diff --git a/src/angles.cpp b/src/angles.cpp index a97322a3..bb061fa9 100644 --- a/src/angles.cpp +++ b/src/angles.cpp @@ -9,11 +9,11 @@ namespace angles { -angle_data_s data_[32]; +angle_data_s data_[MAX_PLAYERS]; void Update() { - for (int i = 1; i < 33; i++) + for (int i = 1; i <= MAX_PLAYERS; i++) { auto &d = data_idx(i); CachedEntity *ent = ENTITY(i); diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index a04c290f..7597d39f 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -1478,7 +1478,7 @@ static void DrawText() // Debug stuff if (!aimbot_debug) return; - for (int i = 1; i < 32; i++) + for (int i = 1; i < PLAYER_ARRAY_SIZE; i++) { CachedEntity *ent = ENTITY(i); if (CE_GOOD(ent)) diff --git a/src/hacks/AntiBackstab.cpp b/src/hacks/AntiBackstab.cpp index 1a630eea..1f7c132e 100644 --- a/src/hacks/AntiBackstab.cpp +++ b/src/hacks/AntiBackstab.cpp @@ -60,7 +60,7 @@ CachedEntity *ClosestSpy() closest = nullptr; closest_dist = 0.0f; - for (int i = 1; i < 32 && i < g_IEntityList->GetHighestEntityIndex(); i++) + for (int i = 1; i < PLAYER_ARRAY_SIZE && i < g_IEntityList->GetHighestEntityIndex(); i++) { ent = ENTITY(i); if (CE_BAD(ent)) diff --git a/src/hacks/AutoHeal.cpp b/src/hacks/AutoHeal.cpp index bf3e9d73..b6db7d4a 100644 --- a/src/hacks/AutoHeal.cpp +++ b/src/hacks/AutoHeal.cpp @@ -72,8 +72,8 @@ int vaccinator_change_ticks = 0; int vaccinator_ideal_resist = 0; int vaccinator_change_timer = 0; -std::array reset_cd{}; -std::vector data(32); +std::array reset_cd{}; +std::vector data(MAX_PLAYERS); struct proj_data_s { @@ -212,7 +212,7 @@ int BlastDangerValue(CachedEntity *patient) return 1; } // Find rockets/pipes nearby - for (int i = 32; i <= HIGHEST_ENTITY; i++) + for (int i = PLAYER_ARRAY_SIZE; i <= HIGHEST_ENTITY; i++) { CachedEntity *ent = ENTITY(i); if (CE_BAD(ent)) @@ -433,7 +433,7 @@ bool IsVaccinator() void UpdateData() { - for (int i = 1; i < 32; i++) + for (int i = 1; i < MAX_PLAYERS; i++) { if (reset_cd[i].test_and_set(10000)) data[i] = {}; diff --git a/src/hacks/Backtrack.cpp b/src/hacks/Backtrack.cpp index 75bd08fe..e09162bd 100644 --- a/src/hacks/Backtrack.cpp +++ b/src/hacks/Backtrack.cpp @@ -30,7 +30,7 @@ void EmptyBacktrackData(BacktrackData &i); std::pair getBestEntBestTick(); bool shouldBacktrack(); -BacktrackData headPositions[33][66]{}; +BacktrackData headPositions[PLAYER_ARRAY_SIZE][66]{}; int lastincomingsequencenumber = 0; bool isBacktrackEnabled = false; bool Vischeck_Success = false; @@ -69,7 +69,7 @@ void AddLatencyToNetchan(INetChannel *ch) } void Init() { - for (int i = 0; i < 33; i++) + for (int i = 0; i < PLAYER_ARRAY_SIZE; i++) for (int j = 0; j < 66; j++) headPositions[i][j] = {}; @@ -78,8 +78,8 @@ void Init() int BestTick = -1; int iBestTarget = -1; -bool istickvalid[33][66]{}; -bool istickinvalid[33][66]{}; +bool istickvalid[PLAYER_ARRAY_SIZE][66]{}; +bool istickinvalid[PLAYER_ARRAY_SIZE][66]{}; static float latency_rampup = 0.0f; static void Run() diff --git a/src/hacks/ESP.cpp b/src/hacks/ESP.cpp index 8d605f00..20220ad7 100644 --- a/src/hacks/ESP.cpp +++ b/src/hacks/ESP.cpp @@ -265,7 +265,7 @@ static void cm() continue; ProcessEntity(ent); // Update Bones - if (i <= 32) + if (i <= MAX_PLAYERS) ent->hitboxes.GetHitbox(0); // Dont know what this check is for if (data[i].string_count) @@ -1198,7 +1198,7 @@ void _FASTCALL ProcessEntity(CachedEntity *ent) { int handle = weapon_list[i]; int eid = handle & 0xFFF; - if (eid >= 32 && eid <= HIGHEST_ENTITY) + if (eid > MAX_PLAYERS && eid <= HIGHEST_ENTITY) { CachedEntity *weapon = ENTITY(eid); if (!CE_INVALID(weapon) && weapon->m_iClassID() == CL_CLASS(CWeaponMedigun) && weapon) diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index 9ab6eb32..6f3a1272 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -79,7 +79,7 @@ static bool inited = false; static Timer lastTaunt{}; // time since taunt was last executed, used to avoid kicks static Timer lastJump{}; -static std::array afkTicks; // for how many ms the player hasn't been moving +static std::array afkTicks; // for how many ms the player hasn't been moving static void checkAFK() { diff --git a/src/hacks/LightESP.cpp b/src/hacks/LightESP.cpp index 4e4a6c98..0fd3daa8 100644 --- a/src/hacks/LightESP.cpp +++ b/src/hacks/LightESP.cpp @@ -6,10 +6,10 @@ namespace hacks::shared::lightesp { static settings::Boolean enable{ "lightesp.enable", "false" }; -static Vector hitp[33]; -static Vector minp[33]; -static Vector maxp[33]; -static bool drawEsp[33]; +static Vector hitp[PLAYER_ARRAY_SIZE]; +static Vector minp[PLAYER_ARRAY_SIZE]; +static Vector maxp[PLAYER_ARRAY_SIZE]; +static bool drawEsp[PLAYER_ARRAY_SIZE]; rgba_t LightESPColor(CachedEntity *ent) { diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index 7661b7ce..7891479c 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -256,7 +256,7 @@ void DrawText() } if (show_spectators) { - for (int i = 0; i < 32; i++) + for (int i = 0; i < PLAYER_ARRAY_SIZE; i++) { // Assign the for loops tick number to an ent CachedEntity *ent = ENTITY(i); @@ -671,7 +671,7 @@ UpdateLocalPlayerVisionFlags_t UpdateLocalPlayerVisionFlags_fn; int *g_nLocalPlayerVisionFlags; int *g_nLocalPlayerVisionFlagsWeaponsCheck; // If you wish then change this to some other flag you want to apply/remove -#define PYROVISION 1 +constexpr int PYROVISION = 1; static settings::Int force_pyrovision("visual.force-pyrovision", "0"); diff --git a/src/hacks/MiscPlayerInfo.cpp b/src/hacks/MiscPlayerInfo.cpp index 21c8c3d5..7bf27d8a 100644 --- a/src/hacks/MiscPlayerInfo.cpp +++ b/src/hacks/MiscPlayerInfo.cpp @@ -47,7 +47,7 @@ std::string random_mafia_entry(int level, unsigned steamid) else return store.at(rand() % store.size()); } -static std::array death_timer; +static std::array death_timer; void Paint() { if (!*draw_kda && !*mafia_city) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 37759911..d9c18c4d 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -35,7 +35,7 @@ static std::vector> sniper_spots; // How long should the bot wait until pathing again? static Timer wait_until_path{}; // Time before following target cloaked spy again -static std::array spy_cloak{}; +static std::array spy_cloak{}; // Don't spam spy path thanks static Timer spy_path{}; // What is the bot currently doing @@ -415,7 +415,7 @@ static inline bool hasLowAmmo() { int handle = weapon_list[i]; int eid = handle & 0xFFF; - if (eid >= 32 && eid <= HIGHEST_ENTITY) + if (eid > MAX_PLAYERS && eid <= HIGHEST_ENTITY) { IClientEntity *weapon = g_IEntityList->GetClientEntity(eid); if (weapon and re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon) && re::C_TFWeaponBase::UsesPrimaryAmmo(weapon) && !re::C_TFWeaponBase::HasPrimaryAmmo(weapon)) diff --git a/src/hacks/SkinChanger.cpp b/src/hacks/SkinChanger.cpp index 6bce25b9..34e65d0b 100644 --- a/src/hacks/SkinChanger.cpp +++ b/src/hacks/SkinChanger.cpp @@ -274,7 +274,7 @@ void FrameStageNotify(int stage) { handle = weapon_list[i]; eid = handle & 0xFFF; - if (eid < 32 || eid > HIGHEST_ENTITY) + if (eid <= MAX_PLAYERS || eid > HIGHEST_ENTITY) continue; // logging::Info("eid, %i", eid); entity = g_IEntityList->GetClientEntity(eid); diff --git a/src/hacks/SpyAlert.cpp b/src/hacks/SpyAlert.cpp index 44c771e6..f5b23b51 100644 --- a/src/hacks/SpyAlert.cpp +++ b/src/hacks/SpyAlert.cpp @@ -39,7 +39,7 @@ void Draw() spy_count = 0; if (last_say > g_GlobalVars->curtime) last_say = 0; - for (int i = 0; i <= HIGHEST_ENTITY && i < 32; i++) + for (int i = 0; i <= HIGHEST_ENTITY && i <= MAX_PLAYERS; i++) { ent = ENTITY(i); if (CE_BAD(ent)) diff --git a/src/hacks/Walkbot.cpp b/src/hacks/Walkbot.cpp index 98cd8fae..228babf4 100644 --- a/src/hacks/Walkbot.cpp +++ b/src/hacks/Walkbot.cpp @@ -243,7 +243,7 @@ bool HasLowAmmo() { int handle = weapon_list[i]; int eid = handle & 0xFFF; - if (eid >= 32 && eid <= HIGHEST_ENTITY) + if (eid > MAX_PLAYERS && eid <= HIGHEST_ENTITY) { IClientEntity *weapon = g_IEntityList->GetClientEntity(eid); if (weapon and re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon) and re::C_TFWeaponBase::UsesPrimaryAmmo(weapon) and not re::C_TFWeaponBase::HasPrimaryAmmo(weapon)) diff --git a/src/hacks/ac/aimbot.cpp b/src/hacks/ac/aimbot.cpp index f1af837c..cd743005 100644 --- a/src/hacks/ac/aimbot.cpp +++ b/src/hacks/ac/aimbot.cpp @@ -16,8 +16,8 @@ static settings::Boolean enable{ "find-cheaters.aimbot.enable", "true" }; static settings::Float detect_angle{ "find-cheaters.aimbot.angle", "30" }; static settings::Int detections_warning{ "find-cheaters.aimbot.detections", "3" }; -ac_data data_table[32]; -int amount[32]; +ac_data data_table[MAX_PLAYERS]; +int amount[MAX_PLAYERS]; std::unordered_map Player_origs{}; std::unordered_map &player_orgs() @@ -26,7 +26,7 @@ std::unordered_map &player_orgs() } void ResetEverything() { - memset(&data_table, 0, sizeof(ac_data) * 32); + memset(&data_table, 0, sizeof(ac_data) * MAX_PLAYERS); Player_origs.clear(); } @@ -106,7 +106,7 @@ void Event(KeyValues *event) int victim = event->GetInt("userid"); int eid = g_IEngine->GetPlayerForUserID(attacker); int vid = g_IEngine->GetPlayerForUserID(victim); - if (eid > 0 && eid < 33 && vid > 0 && vid < 33) + if (eid > 0 && eid <= MAX_PLAYERS && vid > 0 && vid <= MAX_PLAYERS) { CachedEntity *victim = ENTITY(vid); CachedEntity *attacker = ENTITY(eid); diff --git a/src/hacks/ac/antiaim.cpp b/src/hacks/ac/antiaim.cpp index 6eb780f9..6d1fe9e8 100644 --- a/src/hacks/ac/antiaim.cpp +++ b/src/hacks/ac/antiaim.cpp @@ -13,11 +13,11 @@ namespace ac::antiaim { static settings::Boolean enable{ "find-cheaters.antiaim.enable", "true" }; -unsigned long last_accusation[32]{ 0 }; +unsigned long last_accusation[MAX_PLAYERS]{ 0 }; void ResetEverything() { - memset(last_accusation, 0, sizeof(unsigned long) * 32); + memset(last_accusation, 0, sizeof(unsigned long) * MAX_PLAYERS); } void ResetPlayer(int idx) @@ -34,7 +34,7 @@ void Update(CachedEntity *player) { if (!enable) return; - int amount[32]; + int amount[MAX_PLAYERS]; auto &am = amount[player->m_IDX - 1]; if (tickcount - last_accusation[player->m_IDX - 1] < 60 * 60) return; diff --git a/src/hacks/ac/bhop.cpp b/src/hacks/ac/bhop.cpp index 1b4f2cc0..e586645c 100644 --- a/src/hacks/ac/bhop.cpp +++ b/src/hacks/ac/bhop.cpp @@ -13,11 +13,11 @@ namespace ac::bhop { static settings::Int bhop_detect_count{ "find-cheaters.bunnyhop.detections", "4" }; -ac_data data_table[32]{}; +ac_data data_table[MAX_PLAYERS]{}; void ResetEverything() { - memset(data_table, 0, sizeof(ac_data) * 32); + memset(data_table, 0, sizeof(ac_data) * MAX_PLAYERS); } void ResetPlayer(int idx) diff --git a/src/hitrate.cpp b/src/hitrate.cpp index baaed025..e092a853 100644 --- a/src/hitrate.cpp +++ b/src/hitrate.cpp @@ -60,9 +60,9 @@ CatCommand debug_ammo("debug_ammo", "Debug ammo", []() { logging::Info("%d %d", i, CE_INT(LOCAL_E, netvar.m_iAmmo + i * 4)); } }); -bool brutesoon[33]; +bool brutesoon[PLAYER_ARRAY_SIZE]; int lasthits = 0; -std::array xd{}; +std::array xd{}; void Update() { CachedEntity *weapon = LOCAL_W; @@ -87,7 +87,7 @@ void Update() INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); static bool firstcall = true; - for (int i = 0; i < 33; i++) + for (int i = 0; i < PLAYER_ARRAY_SIZE; i++) { if (firstcall) xd[i].update(); diff --git a/src/hooks/GetFriendPersonaName.cpp b/src/hooks/GetFriendPersonaName.cpp index 7fd3aa3f..e8beefe7 100644 --- a/src/hooks/GetFriendPersonaName.cpp +++ b/src/hooks/GetFriendPersonaName.cpp @@ -31,7 +31,7 @@ bool StolenName() // Array to store potential namestealer targets with a bookkeeper to tell // how full it is - int potential_targets[32]; + int potential_targets[MAX_PLAYERS]; int potential_targets_length = 0; // Go through entities looking for potential targets diff --git a/src/hooks/LevelInit.cpp b/src/hooks/LevelInit.cpp index 76b63d72..5d2e0313 100644 --- a/src/hooks/LevelInit.cpp +++ b/src/hooks/LevelInit.cpp @@ -50,7 +50,7 @@ DEFINE_HOOKED_METHOD(LevelInit, void, void *this_, const char *name) else if (holiday->m_nValue == 2) holiday->SetValue(0); #endif - for (int i = 0; i < 32; i++) + for (int i = 0; i < MAX_PLAYERS; i++) g_Settings.brute.brutenum[i] = 0; g_IEngine->ClientCmd_Unrestricted("exec cat_matchexec"); chat_stack::Reset(); diff --git a/src/hooks/visual/CHudChat.cpp b/src/hooks/visual/CHudChat.cpp index 2979aee1..0d535201 100644 --- a/src/hooks/visual/CHudChat.cpp +++ b/src/hooks/visual/CHudChat.cpp @@ -32,7 +32,7 @@ struct SpamClass }; // Storage for the spam messages -std::array, 32> spam_storage; +std::array, MAX_PLAYERS> spam_storage; DEFINE_HOOKED_METHOD(ChatPrintf, void, CHudBaseChat *_this, int player_idx, int iFilter, const char *str, ...) { auto buf = std::make_unique(1024); diff --git a/src/hoovy.cpp b/src/hoovy.cpp index 076d5d37..0f74f9ac 100644 --- a/src/hoovy.cpp +++ b/src/hoovy.cpp @@ -7,7 +7,7 @@ #include "common.hpp" -static bool hoovy_list[33] = { 0 }; +static bool hoovy_list[PLAYER_ARRAY_SIZE] = { 0 }; bool HasSandvichOut(CachedEntity *entity) { @@ -43,7 +43,7 @@ void UpdateHoovyList() return; static CachedEntity *ent; - for (int i = 1; i <= 32 && i < g_IEntityList->GetHighestEntityIndex(); i++) + for (int i = 1; i <= MAX_PLAYERS && i < g_IEntityList->GetHighestEntityIndex(); i++) { ent = ENTITY(i); if (CE_GOOD(ent) && CE_BYTE(ent, netvar.iLifeState) == LIFE_ALIVE) diff --git a/src/ipc.cpp b/src/ipc.cpp index 1ddbd93b..d8ea09c7 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -116,7 +116,7 @@ peer_t *peer{ nullptr }; CatCommand debug_get_ingame_ipc("ipc_debug_dump_server", "Show other bots on server", []() { std::vector players{}; - for (int j = 1; j < 32; j++) + for (int j = 1; j <= MAX_PLAYERS; j++) { player_info_s info; if (g_IEngine->GetPlayerInfo(j, &info)) diff --git a/src/playerresource.cpp b/src/playerresource.cpp index 859b23f2..3322b8db 100755 --- a/src/playerresource.cpp +++ b/src/playerresource.cpp @@ -74,7 +74,7 @@ int TFPlayerResource::GetTeam(int idx) { IClientEntity *ent; - if (idx >= 64 || idx < 0) + if (idx >= MAX_PLAYERS || idx < 0) return 0; ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) @@ -86,7 +86,7 @@ int TFPlayerResource::GetScore(int idx) { IClientEntity *ent; - if (idx >= 32 || idx < 1) + if (idx >= MAX_PLAYERS || idx < 1) return 0; ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) @@ -98,7 +98,7 @@ int TFPlayerResource::GetKills(int idx) { IClientEntity *ent; - if (idx >= 32 || idx < 1) + if (idx >= MAX_PLAYERS || idx < 1) return 0; ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) @@ -110,7 +110,7 @@ int TFPlayerResource::GetDeaths(int idx) { IClientEntity *ent; - if (idx >= 32 || idx < 1) + if (idx >= MAX_PLAYERS || idx < 1) return 0; ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) @@ -122,7 +122,7 @@ int TFPlayerResource::GetLevel(int idx) { IClientEntity *ent; - if (idx >= 32 || idx < 1) + if (idx >= MAX_PLAYERS || idx < 1) return 0; ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) @@ -134,7 +134,7 @@ int TFPlayerResource::GetDamage(int idx) { IClientEntity *ent; - if (idx >= 32 || idx < 1) + if (idx >= MAX_PLAYERS || idx < 1) return 0; ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) @@ -145,7 +145,7 @@ int TFPlayerResource::GetPing(int idx) { IClientEntity *ent; - if (idx >= 32 || idx < 1) + if (idx >= MAX_PLAYERS || idx < 1) return 0; ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) @@ -162,7 +162,7 @@ int TFPlayerResource::GetClass(CachedEntity *player) if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) return 0; idx = player->m_IDX; - if (idx >= 64 || idx < 0) + if (idx >= MAX_PLAYERS || idx < 0) return 0; return *(int *) ((unsigned) ent + netvar.res_iPlayerClass + 4 * idx); } @@ -172,7 +172,7 @@ bool TFPlayerResource::isAlive(int idx) IClientEntity *ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) return 0; - if (idx >= 64 || idx < 0) + if (idx >= MAX_PLAYERS || idx < 0) return false; return *(bool *) ((unsigned) ent + netvar.res_bAlive + idx); } @@ -182,7 +182,7 @@ int TFPlayerResource::getClass(int idx) IClientEntity *ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) return 0; - if (idx >= 64 || idx < 0) + if (idx >= MAX_PLAYERS || idx < 0) return 0; return *(int *) ((unsigned) ent + netvar.res_iPlayerClass + 4 * idx); } @@ -192,7 +192,7 @@ int TFPlayerResource::getTeam(int idx) IClientEntity *ent = g_IEntityList->GetClientEntity(entity); if (!ent || ent->GetClientClass()->m_ClassID != RCC_PLAYERRESOURCE) return 0; - if (idx >= 64 || idx < 0) + if (idx >= MAX_PLAYERS || idx < 0) return 0; return *(int *) ((unsigned) ent + netvar.res_iTeam + 4 * idx); } diff --git a/src/prediction.cpp b/src/prediction.cpp index 546101f5..34826945 100644 --- a/src/prediction.cpp +++ b/src/prediction.cpp @@ -55,8 +55,8 @@ void Prediction_CreateMove() if (!setup) { setup = true; - predicted_players_engine.resize(33); - player_vel.resize(33); + predicted_players_engine.resize(PLAYER_ARRAY_SIZE); + player_vel.resize(PLAYER_ARRAY_SIZE); } for (int i = 1; i <= g_GlobalVars->maxClients; i++) { @@ -272,7 +272,7 @@ Vector EnginePrediction(CachedEntity *entity, float time) memset(&fakecmd, 0, sizeof(CUserCmd)); Vector vel(0.0f); - if (entity->m_IDX <= 33 && player_vel[entity->m_IDX].size()) + if (entity->m_IDX <= MAX_PLAYERS && player_vel[entity->m_IDX].size()) { for (auto entry : player_vel[entity->m_IDX]) vel += entry; @@ -328,7 +328,7 @@ Vector ProjectilePrediction_Engine(CachedEntity *ent, int hb, float speed, float if (speed == 0.0f) return Vector(); Vector velocity(0.0f); - if (ent->m_IDX <= 33 && player_vel[ent->m_IDX].size()) + if (ent->m_IDX <= MAX_PLAYERS && player_vel[ent->m_IDX].size()) { for (auto entry : player_vel[ent->m_IDX]) velocity += entry; @@ -444,7 +444,7 @@ Vector ProjectilePrediction(CachedEntity *ent, int hb, float speed, float gravit if (speed == 0.0f) return Vector(); Vector velocity(0.0f); - if (ent->m_IDX <= 33 && player_vel[ent->m_IDX].size()) + if (ent->m_IDX <= MAX_PLAYERS && player_vel[ent->m_IDX].size()) { for (auto entry : player_vel[ent->m_IDX]) velocity += entry; diff --git a/src/visual/EffectChams.cpp b/src/visual/EffectChams.cpp index 1d9b2f61..e043960b 100644 --- a/src/visual/EffectChams.cpp +++ b/src/visual/EffectChams.cpp @@ -90,10 +90,10 @@ void EffectChams::EndRenderChams() g_IVModelRender->ForcedMaterialOverride(nullptr); #endif } -static rgba_t data[33] = { colors::empty }; +static rgba_t data[PLAYER_ARRAY_SIZE] = { colors::empty }; void EffectChams::SetEntityColor(CachedEntity *ent, rgba_t color) { - if (ent->m_IDX > 32 || ent->m_IDX < 0) + if (ent->m_IDX > MAX_PLAYERS || ent->m_IDX < 0) return; data[ent->m_IDX] = color; } @@ -162,7 +162,7 @@ rgba_t EffectChams::ChamsColor(IClientEntity *entity) } return disco; } - if (ent->m_IDX <= 32 && ent->m_IDX >= 0) + if (ent->m_IDX <= MAX_PLAYERS && ent->m_IDX >= 0) { if (data[entity->entindex()] != colors::empty) { diff --git a/src/visual/EventLogging.cpp b/src/visual/EventLogging.cpp index 182f916e..9828b653 100644 --- a/src/visual/EventLogging.cpp +++ b/src/visual/EventLogging.cpp @@ -111,7 +111,7 @@ static void handlePlayerSpawn(KeyValues *kv) static void handlePlayerChangeClass(KeyValues *kv) { int id = kv->GetInt("userid"); - if (id > 33 || id < 0) + if (id > PLAYER_ARRAY_SIZE || id < 0) return; player_info_s info{}; if (!g_IEngine->GetPlayerInfo(g_IEngine->GetPlayerForUserID(id), &info)) diff --git a/src/visual/menu/GuiInterface.cpp b/src/visual/menu/GuiInterface.cpp index 6d50e647..0be167a1 100644 --- a/src/visual/menu/GuiInterface.cpp +++ b/src/visual/menu/GuiInterface.cpp @@ -162,7 +162,7 @@ bool gui::handleSdlEvent(SDL_Event *event) if (controller && CE_GOOD(LOCAL_E) && update_players.test_and_set(10000)) { controller->removeAll(); - for (auto i = 1; i < 32; ++i) + for (auto i = 1; i <= MAX_PLAYERS; ++i) { player_info_s info{}; if (g_IEngine->GetPlayerInfo(i, &info)) @@ -202,7 +202,7 @@ void gui::onLevelLoad() if (controller) { controller->removeAll(); - for (auto i = 1; i < 32; ++i) + for (auto i = 1; i < MAX_PLAYERS; ++i) { player_info_s info{}; if (g_IEngine->GetPlayerInfo(i, &info))