diff --git a/include/MiscTemporary.hpp b/include/MiscTemporary.hpp index c47d9b91..5e24393b 100755 --- a/include/MiscTemporary.hpp +++ b/include/MiscTemporary.hpp @@ -16,6 +16,7 @@ extern std::array timers; extern Timer DelayTimer; extern bool firstcm; +extern bool calculated_can_shoot; extern float prevflow; extern int prevflowticks; #if ENABLE_VISUALS @@ -31,6 +32,3 @@ extern settings::Bool disable_visuals; extern settings::Int print_r; extern settings::Int print_g; extern settings::Int print_b; - -void SetCanshootStatus(); -extern bool CanShootException; diff --git a/src/MiscTemporary.cpp b/src/MiscTemporary.cpp old mode 100644 new mode 100755 index 5d53699a..2fbee87e --- a/src/MiscTemporary.cpp +++ b/src/MiscTemporary.cpp @@ -11,28 +11,12 @@ int spectator_target; CLC_VoiceData *voicecrash{}; bool firstcm = false; Timer DelayTimer{}; -float prevflow = 0.0f; -int prevflowticks = 0; +float prevflow = 0.0f; +int prevflowticks = 0; +bool calculated_can_shoot = false; bool *bSendPackets{ nullptr }; -bool CanShootException = false; -void SetCanshootStatus() -{ - static int lastammo = -1; - static int prevweaponclass = -1; - if (LOCAL_W->m_iClassID() != prevweaponclass) - lastammo = -1; - if (GetWeaponMode() != weapon_melee && lastammo == 0 && CE_INT(LOCAL_W, netvar.m_iClip1)) - { - CanShootException = true; - } - else - CanShootException = false; - lastammo = CE_INT(LOCAL_W, netvar.m_iClip1); - prevweaponclass = LOCAL_W->m_iClassID(); -} - settings::Bool crypt_chat{ "chat.crypto", "true" }; settings::Bool clean_screenshots{ "visual.clean-screenshots", "false" }; settings::Bool nolerp{ "misc.no-lerp", "false" }; diff --git a/src/hack.cpp b/src/hack.cpp index 322020b4..fb8e35e8 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -108,7 +108,7 @@ void critical_error_handler(int signum) std::ofstream out(strfmt("/tmp/cathook-%s-%d-segfault.log", pwd->pw_name, getpid()).get()); Dl_info info; - if (!dladdr(reinterpret_cast(SetCanshootStatus), &info)) + if (!dladdr(reinterpret_cast(hack::ExecuteCommand), &info)) return; unsigned int baseaddr = (unsigned int) info.dli_fbase - 1; diff --git a/src/helpers.cpp b/src/helpers.cpp index 345632ec..84a64dac 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -6,10 +6,10 @@ */ #include "common.hpp" -#include "MiscTemporary.hpp" #include -#include +#include "settings/Bool.hpp" +#include "MiscTemporary.hpp" static settings::Bool tcm{ "debug.tcm", "true" }; @@ -1321,19 +1321,8 @@ bool CanHeadshot() bool CanShoot() { - static float servertime, lastfire, nextattack; - - float currfire = CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flLastFireTime); - - if (lastfire != currfire || GetWeaponMode() == weapon_melee) - { - lastfire = currfire; - nextattack = CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flNextPrimaryAttack); - } - servertime = (float) (CE_INT(g_pLocalPlayer->entity, netvar.nTickBase)) * g_GlobalVars->interval_per_tick; - if (CanShootException) - return true; - return nextattack <= servertime; + // PrecalculateCanShoot() CreateMove.cpp + return calculated_can_shoot; } QAngle VectorToQAngle(Vector in) diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index e59bceca..ab12ce8b 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -89,6 +89,37 @@ void RunEnginePrediction(IClientEntity *ent, CUserCmd *ucmd) } } // namespace engine_prediction +void PrecalculateCanShoot() +{ + auto weapon = g_pLocalPlayer->weapon(); + // Check if player and weapon are good + if (CE_BAD(g_pLocalPlayer->entity) || CE_BAD(weapon)) + { + calculated_can_shoot = false; + return; + } + + // flNextPrimaryAttack without reload + static float next_attack = 0.0f; + // Last shot fired using weapon + static float last_attack = 0.0f; + // Last weapon used + static CachedEntity *last_weapon = nullptr; + float server_time = (float) (CE_INT(g_pLocalPlayer->entity, netvar.nTickBase)) * g_GlobalVars->interval_per_tick; + float new_next_attack = CE_FLOAT(weapon, netvar.flNextPrimaryAttack); + float new_last_attack = CE_FLOAT(weapon, netvar.flLastFireTime); + + // Reset everything if using a new weapon/shot fired + if (new_last_attack != last_attack || last_weapon != weapon) + { + next_attack = new_next_attack; + last_attack = new_last_attack; + last_weapon = weapon; + } + // Check if can shoot + calculated_can_shoot = next_attack <= server_time; +} + static int attackticks = 0; namespace hooked_methods @@ -252,8 +283,7 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, CUs PROF_SECTION(CM_LocalPlayer); g_pLocalPlayer->Update(); } - if (CE_GOOD(LOCAL_E) && !g_pLocalPlayer->life_state && CE_GOOD(LOCAL_W)) - SetCanshootStatus(); + PrecalculateCanShoot(); if (firstcm) { DelayTimer.update(); diff --git a/src/visual/menu/menu/Text.cpp b/src/visual/menu/menu/Text.cpp index 2c6784a3..501760d8 100644 --- a/src/visual/menu/menu/Text.cpp +++ b/src/visual/menu/menu/Text.cpp @@ -74,7 +74,13 @@ void zerokernel::Text::recalculateSize() BaseMenuObject::recalculateSize(); float w, h; - font->stringSize(data, &w, &h); + if (data.empty() || !font) + { + w = 0.0f; + h = 0.0f; + } + else + font->stringSize(data, &w, &h); text_size_x = int(w); text_size_y = int(h); diff --git a/update b/update index 5a6db5ce..425ed32a 100755 --- a/update +++ b/update @@ -1,6 +1,6 @@ #!/usr/bin/env bash if [ $EUID == 0 ]; then - echo "\033[1;31m\nThis script must not be run as root\n\033[0m" + echo -e "\033[1;31m\nThis script must not be run as root\n\033[0m" exit 1 fi #Get updated source code