diff --git a/.gitignore b/.gitignore index 5c70d044..bfded36a 100755 --- a/.gitignore +++ b/.gitignore @@ -285,3 +285,5 @@ scripts/updater-preferences /modules/*/ !/modules/readme.md !/modules/CMakeLists.txt + +scripts/partybypass-preferences diff --git a/CMakeLists.txt b/CMakeLists.txt index ca2a6fb2..f6eefc03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,12 @@ # SDL2 # GLEW -set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/cotire/CMake") -cmake_policy(SET CMP0011 NEW) -include(cotire) +set(EnableCotire 1 CACHE BOOL "Enable CoTiRe (Compile Time Reducer)") +if (EnableCotire) + set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/cotire/CMake") + cmake_policy(SET CMP0011 NEW) + include(cotire) +endif() if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type") @@ -138,9 +141,11 @@ add_subdirectory(include) add_subdirectory(external) add_subdirectory(modules) -set_target_properties(cathook PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${CMAKE_SOURCE_DIR}/include/common.hpp") -set_target_properties(cathook PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) -cotire(cathook) +if (EnableCotire) + set_target_properties(cathook PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${CMAKE_SOURCE_DIR}/include/common.hpp") + set_target_properties(cathook PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) + cotire(cathook) +endif() add_custom_command(TARGET cathook POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_SOURCE_DIR}/bin/$") diff --git a/attach b/attach index 2881a4b0..35e0bcfb 100755 --- a/attach +++ b/attach @@ -1,6 +1,7 @@ #!/usr/bin/env bash sudo ./scripts/auto-updater +sudo ./scripts/attach-partybypass $1 line=$(pidof hl2_linux) arr=($line) inst=$1 diff --git a/attach-gdb b/attach-gdb index 2ecca801..a98fd7e0 100755 --- a/attach-gdb +++ b/attach-gdb @@ -1,6 +1,7 @@ #!/usr/bin/env bash sudo ./scripts/auto-updater +sudo ./scripts/attach-partybypass $1 line=$(pidof hl2_linux) arr=($line) inst=$1 diff --git a/attach-libnamed.sh b/attach-libnamed.sh index 09f5aeec..2b01035a 100755 --- a/attach-libnamed.sh +++ b/attach-libnamed.sh @@ -4,6 +4,7 @@ # https://github.com/LWSS/Fuzion/commit/a53b6c634cde0ed47b08dd587ba40a3806adf3fe sudo ./scripts/auto-updater +sudo ./scripts/attach-partybypass $1 line=$(pidof hl2_linux) arr=($line) inst=$1 diff --git a/include/hacks/FollowBot.hpp b/include/hacks/FollowBot.hpp index 7accb8e1..60b0d445 100644 --- a/include/hacks/FollowBot.hpp +++ b/include/hacks/FollowBot.hpp @@ -13,5 +13,5 @@ namespace hacks::shared::followbot int ClassPriority(CachedEntity *ent); bool isEnabled(); -int getTarget(); +extern int follow_target; } // namespace hacks::shared::followbot diff --git a/include/hacks/NavBot.hpp b/include/hacks/NavBot.hpp index ff38021d..3ed07998 100644 --- a/include/hacks/NavBot.hpp +++ b/include/hacks/NavBot.hpp @@ -12,9 +12,11 @@ enum task : uint8_t sniper_spot, stay_near, health, - ammo + ammo, + followbot }; -} +extern task current_task; +} // namespace task struct bot_class_config { float min; diff --git a/lib/libpartybypass-linux.so b/lib/libpartybypass-linux.so new file mode 100644 index 00000000..aeff700d Binary files /dev/null and b/lib/libpartybypass-linux.so differ diff --git a/scripts/attach-partybypass b/scripts/attach-partybypass new file mode 100755 index 00000000..abb87c34 --- /dev/null +++ b/scripts/attach-partybypass @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +if [ ! -f ./scripts/partybypass-preferences ]; then + while true; do + echo 'https://github.com/nullworks/cathook/wiki/What-is-Partybypass-and-how-do-I-use-it%3F' + read -p "Do you want to enable the precompiled partybypass library? y/n " yn + case $yn in + [Yy]* ) echo true > ./scripts/partybypass-preferences; break;; + [Nn]* ) echo false > ./scripts/partybypass-preferences; exit;; + * ) echo "Please answer y or n.";; + esac + done +fi +if [ `cat ./scripts/partybypass-preferences` == "true" ]; then + line=$(pidof hl2_linux) + arr=($line) + inst=$1 + if [ $# == 0 ]; then + inst=0 + fi + + if [ ${#arr[@]} == 0 ]; then + echo TF2 isn\'t running! + exit + fi + + if [ $inst -gt ${#arr[@]} ] || [ $inst == ${#arr[@]} ]; then + echo wrong index! + exit + fi + + proc=${arr[$inst]} + + # pBypass for crash dumps being sent + # You may also want to consider using -nobreakpad in your launch options. + sudo rm -rf /tmp/dumps # Remove if it exists + sudo mkdir /tmp/dumps # Make it as root + sudo chmod 000 /tmp/dumps # No permissions + + FILENAME="/tmp/.gl$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)" + + cp "./lib/libpartybypass-linux.so" "$FILENAME" + + gdb -n -q -batch \ + -ex "attach $proc" \ + -ex "set \$dlopen = (void*(*)(char*, int)) dlopen" \ + -ex "call \$dlopen(\"$FILENAME\", 1)" \ + -ex "detach" \ + -ex "quit" > /dev/null 2>&1 + + rm $FILENAME + echo -e "\n\033[1;34mPartybypass injected.\033[0m" && exit 0 +fi diff --git a/src/MiscTemporary.cpp b/src/MiscTemporary.cpp index cf471740..d6cf5e25 100644 --- a/src/MiscTemporary.cpp +++ b/src/MiscTemporary.cpp @@ -38,3 +38,5 @@ settings::Bool clean_screenshots{ "visual.clean-screenshots", "false" }; settings::Bool nolerp{ "misc.no-lerp", "false" }; settings::Bool no_zoom{ "remove.scope", "false" }; settings::Bool disable_visuals{ "visual.disable", "false" }; + +static CatCommand identify("print_steamid", "Prints your SteamID", []() { g_ICvar->ConsolePrintf("%u\n", g_ISteamUser->GetSteamID().GetAccountID()); }); diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index 07302359..09d0cf6d 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -430,8 +430,26 @@ bool IsTargetStateGood(CachedEntity *entity) // Distance if (EffectiveTargetingRange()) { - if (entity->m_flDistance() > EffectiveTargetingRange()) - return false; + if (g_pLocalPlayer->weapon_mode != weapon_melee) + { + if (entity->m_flDistance() > EffectiveTargetingRange()) + return false; + } + else + { + float swingrange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W)); + int hb = BestHitbox(entity); + if (hb == -1) + return false; + Vector newangle = GetAimAtAngles(g_pLocalPlayer->v_Eye, entity->hitboxes.GetHitbox(hb)->center); + trace_t trace; + Ray_t ray; + trace::filter_default.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); + ray.Init(g_pLocalPlayer->v_Eye, GetForwardVector(g_pLocalPlayer->v_Eye, newangle, swingrange)); + g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, &trace); + if ((IClientEntity *) trace.m_pEnt != RAW_ENT(entity)) + return false; + } } // Rage only check if (rageonly) diff --git a/src/hacks/AntiAntiAim.cpp b/src/hacks/AntiAntiAim.cpp index abbdc208..388a37e6 100644 --- a/src/hacks/AntiAntiAim.cpp +++ b/src/hacks/AntiAntiAim.cpp @@ -100,7 +100,7 @@ void ResetPlayer(int idx) g_Settings.brute.choke[idx] = {}; g_Settings.brute.brutenum[idx] = 0; g_Settings.brute.last_angles[idx] = {}; - g_Settings.brute.lastsimtime = 0.0f; + g_Settings.brute.lastsimtime = 0.0f; } class ResolverListener : public IGameEventListener { diff --git a/src/hacks/AutoHeal.cpp b/src/hacks/AutoHeal.cpp index e821a780..99f67402 100644 --- a/src/hacks/AutoHeal.cpp +++ b/src/hacks/AutoHeal.cpp @@ -472,7 +472,7 @@ int HealingPriority(int idx) #if ENABLE_IPC if (ipc::peer) { - if (hacks::shared::followbot::isEnabled() && hacks::shared::followbot::getTarget() == idx) + if (hacks::shared::followbot::isEnabled() && hacks::shared::followbot::follow_target == idx) { priority *= 6.0f; } diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index da80e269..0999b82a 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -12,6 +12,7 @@ #endif #include #include "navparser.hpp" +#include "NavBot.hpp" static settings::Bool enable{ "follow-bot.enable", "false" }; static settings::Bool roambot{ "follow-bot.roaming", "true" }; @@ -30,10 +31,12 @@ static settings::Bool corneractivate{ "follow-bot.corners", "true" }; static settings::Int steam_var{ "follow-bot.steamid", "0" }; namespace hacks::shared::followbot { -static Timer navBotInterval{}; -unsigned steamid = 0x0; +namespace nb = hacks::tf2::NavBot; -CatCommand follow_steam("fb_steam", "Follow Steam Id", [](const CCommand &args) { +static Timer navBotInterval{}; +static unsigned steamid = 0x0; + +static CatCommand follow_steam("fb_steam", "Follow Steam Id", [](const CCommand &args) { if (args.ArgC() < 1) { steam_var = 0; @@ -52,7 +55,7 @@ CatCommand follow_steam("fb_steam", "Follow Steam Id", [](const CCommand &args) } }); -CatCommand steam_debug("debug_steamid", "Print steamids", []() { +static CatCommand steam_debug("debug_steamid", "Print steamids", []() { for (int i = 0; i < g_IEngine->GetMaxClients(); i++) { auto ent = ENTITY(i); @@ -62,19 +65,19 @@ CatCommand steam_debug("debug_steamid", "Print steamids", []() { // Something to store breadcrumbs created by followed players static std::vector breadcrumbs; -static const int crumb_limit = 64; // limit +static constexpr int crumb_limit = 64; // limit static bool followcart{ false }; // Followed entity, externed for highlight color -int follow_target = 0; -static bool inited; +int follow_target = 0; +static bool inited = false; -Timer lastTaunt{}; // time since taunt was last executed, used to avoid kicks -Timer lastJump{}; -std::array afkTicks; // for how many ms the player hasn't been moving +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 -void checkAFK() +static void checkAFK() { for (int i = 0; i < g_GlobalVars->maxClients; i++) { @@ -88,7 +91,7 @@ void checkAFK() } } -void init() +static void init() { for (int i = 0; i < afkTicks.size(); i++) { @@ -99,7 +102,7 @@ void init() } // auto add checked crumbs for the walkbot to follow -void addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) +static void addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) { breadcrumbs.clear(); if (g_pLocalPlayer->v_Origin != corner) @@ -120,7 +123,7 @@ void addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) } } -void addCrumbPair(CachedEntity *player1, CachedEntity *player2, std::pair corners) +static void addCrumbPair(CachedEntity *player1, CachedEntity *player2, std::pair corners) { Vector corner1 = corners.first; Vector corner2 = corners.second; @@ -163,7 +166,7 @@ void addCrumbPair(CachedEntity *player1, CachedEntity *player2, std::pairm_flDistance() <= (float) follow_activation) + { + if (corneractivate) + { + Vector indirectOrigin = VischeckCorner(LOCAL_E, entity, *follow_activation / 2, + true); // get the corner location that the + // future target is visible from + std::pair corners; + if (!indirectOrigin.z && entity->m_IDX == lastent) // if we couldn't find it, run + // wallcheck instead + { + corners = VischeckWall(LOCAL_E, entity, float(follow_activation) / 2, true); + if (!corners.first.z || !corners.second.z) + return false; + // addCrumbs(LOCAL_E, corners.first); + // addCrumbs(entity, corners.second); + addCrumbPair(LOCAL_E, entity, corners); + return true; + } + if (indirectOrigin.z) + { + addCrumbs(entity, indirectOrigin); + return true; + } + } + else + { + if (VisCheckEntFromEnt(LOCAL_E, entity)) + { + return true; + } + } + } + if (useNavbot) + { + if (nav::navTo(entity->m_vecOrigin(), 8, true, false)) + { + navtarget = entity->m_IDX; + return true; + } + } + return false; +} #if ENABLE_IPC static void cm() @@ -193,6 +244,8 @@ static void cm() if (!enable) { follow_target = 0; + if (nb::task::current_task == nb::task::followbot) + nb::task::current_task = nb::task::none; return; } if (!inited) @@ -200,6 +253,13 @@ static void cm() // We need a local player to control if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer() || CE_BAD(LOCAL_W)) + { + follow_target = 0; + if (nb::task::current_task == nb::task::followbot) + nb::task::current_task = nb::task::none; + return; + } + if (nb::task::current_task == nb::task::health || nb::task::current_task == nb::task::ammo) { follow_target = 0; return; @@ -208,33 +268,6 @@ static void cm() if (afk) checkAFK(); - // Naving - static bool isnaving = false; - static Timer navtime{}; - static Timer navtimeout{}; - - if (isnaving) - { - if (!follow_target) - { - isnaving = false; - return; - } - if (CE_GOOD(ENTITY(follow_target)) && navtime.test_and_set(500)) - { - if (nav::navTo(ENTITY(follow_target)->m_vecOrigin(), 8, true, false)) - { - navtimeout.update(); - } - } - if (navtimeout.check(15000) || nav::curr_priority == 0) - { - isnaving = false; - nav::clearInstructions(); - } - return; - } - // Still good check if (follow_target) { @@ -254,11 +287,11 @@ static void cm() // Target Selection { - if (steamid && ((follow_target && ENTITY(follow_target)->player_info.friendsID != steamid) || !follow_target)) + if (steamid && !(ENTITY(follow_target)->player_info.friendsID == steamid || ENTITY(navtarget)->player_info.friendsID == steamid)) { // Find a target with the steam id, as it is prioritized auto ent_count = g_IEngine->GetMaxClients(); - for (int i = 0; i < ent_count; i++) + for (int i = 1; i < ent_count; i++) { auto entity = ENTITY(i); if (CE_BAD(entity)) // Exist + dormant @@ -272,57 +305,24 @@ static void cm() if (!entity->m_bAlivePlayer()) // Dont follow dead players continue; - bool found = false; - if (corneractivate) + if (startFollow(entity, isNavBotCM)) { - Vector indirectOrigin = VischeckCorner(LOCAL_E, entity, *follow_activation / 2, - true); // get the corner location that the - // future target is visible from - std::pair corners; - if (!indirectOrigin.z && entity->m_IDX == lastent) // if we couldn't find it, run - // wallcheck instead - { - corners = VischeckWall(LOCAL_E, entity, float(follow_activation) / 2, true); - if (!corners.first.z || !corners.second.z) - continue; - // addCrumbs(LOCAL_E, corners.first); - // addCrumbs(entity, corners.second); - addCrumbPair(LOCAL_E, entity, corners); - found = true; - } - if (indirectOrigin.z) - { - addCrumbs(entity, indirectOrigin); - found = true; - } + navinactivity.update(); + follow_target = entity->m_IDX; + afkTicks[i].update(); + break; } - else - { - if (VisCheckEntFromEnt(LOCAL_E, entity)) - found = true; - } - if (isNavBotCM && !found) - { - if (!nav::navTo(entity->m_vecOrigin())) - continue; - navtimeout.update(); - found = true; - } - if (!found) - continue; - follow_target = entity->m_IDX; - break; } } } // If we dont have a follow target from that, we look again for someone // else who is suitable { - if ((!follow_target || change || (ClassPriority(ENTITY(follow_target)) < 6 && ENTITY(follow_target)->player_info.friendsID != steamid)) && roambot) + if (roambot && !navtarget && (!follow_target || change || (ClassPriority(ENTITY(follow_target)) < 6 && ENTITY(follow_target)->player_info.friendsID != steamid))) { // Try to get a new target auto ent_count = followcart ? HIGHEST_ENTITY : g_IEngine->GetMaxClients(); - for (int i = 0; i < ent_count; i++) + for (int i = 1; i < ent_count; i++) { auto entity = ENTITY(i); if (CE_BAD(entity)) // Exist + dormant @@ -341,9 +341,7 @@ static void cm() continue; if (!entity->m_bAlivePlayer()) // Dont follow dead players continue; - if (follow_activation && entity->m_flDistance() > (float) follow_activation) - continue; - const model_t *model = ENTITY(follow_target)->InternalEntity()->GetModel(); + // const model_t *model = ENTITY(follow_target)->InternalEntity()->GetModel(); // FIXME follow cart/point /*if (followcart && model && (lagexploit::pointarr[0] || lagexploit::pointarr[1] || @@ -364,56 +362,64 @@ static void cm() // target if (ClassPriority(ENTITY(follow_target)) >= ClassPriority(ENTITY(i))) continue; - bool found = false; - if (corneractivate) + if (startFollow(entity, isNavBotCM)) { - Vector indirectOrigin = VischeckCorner(LOCAL_E, entity, *follow_activation / 2, - true); // get the corner location that the - // future target is visible from - std::pair corners; - if (!indirectOrigin.z && entity->m_IDX == lastent) // if we couldn't find it, run - // wallcheck instead - { - corners = VischeckWall(LOCAL_E, entity, float(follow_activation) / 2, true); - if (!corners.first.z || !corners.second.z) - continue; - // addCrumbs(LOCAL_E, corners.first); - // addCrumbs(entity, corners.second); - addCrumbPair(LOCAL_E, entity, corners); - found = true; - } - if (indirectOrigin.z) - { - addCrumbs(entity, indirectOrigin); - found = true; - } + // ooooo, a target + navinactivity.update(); + follow_target = i; + afkTicks[i].update(); // set afk time to 03 + break; } - else - { - if (VisCheckEntFromEnt(LOCAL_E, entity)) - found = true; - } - if (isNavBotCM && !found) - { - if (!nav::navTo(entity->m_vecOrigin())) - continue; - navtimeout.update(); - found = true; - } - if (!found) - continue; - // ooooo, a target - follow_target = i; - afkTicks[i].update(); // set afk time to 0 } } } lastent++; if (lastent > g_IEngine->GetMaxClients()) - lastent = 0; + lastent = 1; + + if (navtarget) + { + auto ent = ENTITY(navtarget); + if (CE_GOOD(ent) && startFollow(ent, false)) + { + follow_target = navtarget; + navtarget = 0; + } + else + { + breadcrumbs.clear(); + follow_target = 0; + static Timer navtimer{}; + if (CE_GOOD(ent)) + { + if (!ent->m_bAlivePlayer()) + { + navtarget = 0; + } + if (navtimer.test_and_set(800)) + { + if (nav::navTo(ent->m_vecOrigin(), 8, true, false)) + navinactivity.update(); + } + } + if (navinactivity.check(15000)) + { + navtarget = 0; + } + nb::task::current_task = nb::task::followbot; + return; + } + } + // last check for entity before we continue if (!follow_target) + { + if (nb::task::current_task == nb::task::followbot) + nb::task::current_task = nb::task::none; return; + } + nb::task::current_task = nb::task::followbot; + nav::clearInstructions(); CachedEntity *followtar = ENTITY(follow_target); // wtf is this needed @@ -582,20 +588,6 @@ static void draw() } #endif -static InitRoutine runinit([]() { -#if ENABLE_IPC - EC::Register(EC::CreateMove, cm, "cm_followbot", EC::average); -#endif -#if ENABLE_VISUALS - EC::Register(EC::Draw, draw, "draw_followbot", EC::average); -#endif -}); - -int getTarget() -{ - return follow_target; -} - bool isEnabled() { return *enable; @@ -641,5 +633,14 @@ void rvarCallback(settings::VariableBase &var, int after) return; steamid = after; } -static InitRoutine Init([]() { steam_var.installChangeCallback(rvarCallback); }); + +static InitRoutine runinit([]() { +#if ENABLE_IPC + EC::Register(EC::CreateMove, cm, "cm_followbot", EC::average); +#endif +#if ENABLE_VISUALS + EC::Register(EC::Draw, draw, "draw_followbot", EC::average); +#endif + steam_var.installChangeCallback(rvarCallback); +}); } // namespace hacks::shared::followbot diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 92e5a299..844f5c99 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -3,6 +3,7 @@ #include "NavBot.hpp" #include "PlayerTools.hpp" #include "Aimbot.hpp" +#include "FollowBot.hpp" namespace hacks::tf2::NavBot { @@ -22,13 +23,17 @@ static bool stayNear(); static bool getHealthAndAmmo(); static void autoJump(); static void updateSlot(); +using task::current_task; // -Variables- static std::vector> sniper_spots; // How long should the bot wait until pathing again? static Timer wait_until_path{}; // What is the bot currently doing -static task::task current_task; +namespace task +{ +task current_task; +} constexpr bot_class_config DIST_OTHER{ 100.0f, 200.0f, 300.0f }; constexpr bot_class_config DIST_SNIPER{ 1000.0f, 1500.0f, 3000.0f }; @@ -38,7 +43,7 @@ static void CreateMove() return; if (!init(false)) return; - if (!nav::ReadyForCommands) + if (!nav::ReadyForCommands || current_task == task::followbot) wait_until_path.update(); else current_task = task::none; @@ -52,7 +57,7 @@ static void CreateMove() if (getHealthAndAmmo()) return; // Try to stay near enemies to increase efficiency - if (stay_near || heavy_mode) + if ((stay_near || heavy_mode) && current_task != task::followbot) if (stayNear()) return; // We don't have anything else to do. Just nav to sniper spots. @@ -88,7 +93,7 @@ bool init(bool first_cm) static bool navToSniperSpot() { // Don't path if you already have commands. But also don't error out. - if (!nav::ReadyForCommands) + if (!nav::ReadyForCommands || current_task != task::none) return true; // Wait arround a bit before pathing again if (!wait_until_path.check(2000)) @@ -327,6 +332,8 @@ static bool getHealthAndAmmo() static Timer health_ammo_timer{}; if (!health_ammo_timer.check(3000)) return false; + if (current_task == task::health && static_cast(LOCAL_E->m_iHealth()) / LOCAL_E->m_iMaxHealth() >= 0.64f) + current_task = task::none; if (current_task == task::health) return true; @@ -353,6 +360,8 @@ static bool getHealthAndAmmo() } } + if (current_task == task::ammo && !hasLowAmmo()) + current_task = task::none; if (current_task == task::ammo) return true; if (hasLowAmmo()) @@ -405,6 +414,8 @@ static int GetBestSlot() return primary; case tf_heavy: return primary; + case tf_medic: + return secondary; default: { float nearest_dist = getNearestPlayerDistance().second; diff --git a/src/helpers.cpp b/src/helpers.cpp index d90dcc1c..e8aeadcb 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -481,16 +481,19 @@ void ReplaceString(std::string &input, const std::string &what, const std::strin } } -void ReplaceSpecials(std::string &str) { +void ReplaceSpecials(std::string &str) +{ int val, i; size_t c = 0, len = str.size(); - for (int i = 0; i + c < len; ++i) { + for (int i = 0; i + c < len; ++i) + { str[i] = str[i + c]; if (str[i] != '\\') continue; if (i + c + 1 == len) break; - switch (str[i + c + 1]) { + switch (str[i + c + 1]) + { // Several control characters case 'b': ++c; @@ -544,15 +547,20 @@ void ReplaceSpecials(std::string &str) { std::sscanf(&str[i + c + 2], "%04X", &val); c += 5; // 2. Convert value to UTF-8 - if (val <= 0x7F) { + if (val <= 0x7F) + { str[i] = val; - } else if (val <= 0x7FF) { - str[i] = 0xC0 | ((val >> 6) & 0x1F); + } + else if (val <= 0x7FF) + { + str[i] = 0xC0 | ((val >> 6) & 0x1F); str[i + 1] = 0x80 | (val & 0x3F); ++i; --c; - } else { - str[i] = 0xE0 | ((val >> 12) & 0xF); + } + else + { + str[i] = 0xE0 | ((val >> 12) & 0xF); str[i + 1] = 0x80 | ((val >> 6) & 0x3F); str[i + 2] = 0x80 | (val & 0x3F); i += 2; @@ -885,6 +893,8 @@ bool VisCheckEntFromEntVector(Vector startVector, CachedEntity *startEnt, Cached Vector GetBuildingPosition(CachedEntity *ent) { + if (ent->hitboxes.GetHitbox(0)) + return ent->hitboxes.GetHitbox(0)->center; Vector res; res = ent->m_vecOrigin(); int classid = ent->m_iClassID(); diff --git a/src/itemtypes.cpp b/src/itemtypes.cpp index 36f6fc53..d1517b73 100644 --- a/src/itemtypes.cpp +++ b/src/itemtypes.cpp @@ -183,27 +183,14 @@ void ItemModelMapper::RegisterItem(std::string modelpath, k_EItemType type) k_EItemType ItemModelMapper::GetItemType(CachedEntity *entity) { const uintptr_t model = (uint64_t) RAW_ENT(entity)->GetModel(); - try - { - return map.at(model); - } - // Do Nothing - catch (std::out_of_range) - { - - } + auto find = map.find(model); + if (find != map.end()) + return find->second; std::string path(g_IModelInfo->GetModelName((const model_t *) model)); - bool set = false; - // Do Nothing - try - { - models.at(path); + bool set = false; + auto find2 = models.find(path); + if (find2 != models.end()) set = true; - } - catch (std::out_of_range) - { - - } if (!set) map[model] = k_EItemType::ITEM_NONE; return k_EItemType::ITEM_NONE; diff --git a/src/settings/SettingsIO.cpp b/src/settings/SettingsIO.cpp index eaa608f4..db1f7202 100644 --- a/src/settings/SettingsIO.cpp +++ b/src/settings/SettingsIO.cpp @@ -6,6 +6,8 @@ #include #include #include "core/logging.hpp" +#include "interfaces.hpp" +#include "icvar.h" settings::SettingsWriter::SettingsWriter(settings::Manager &manager) : manager(manager) { @@ -21,6 +23,7 @@ bool settings::SettingsWriter::saveTo(std::string path, bool only_changed) if (!stream || stream.bad() || !stream.is_open() || stream.fail()) { logging::Info("cat_save: FATAL! FAILED to create stream!"); + g_ICvar->ConsolePrintf("CAT: cat_save: Can't create config file!\n"); return false; } @@ -42,8 +45,12 @@ bool settings::SettingsWriter::saveTo(std::string path, bool only_changed) stream.flush(); } if (!stream || stream.bad() || stream.fail()) + { + g_ICvar->ConsolePrintf("CAT: cat_save: Failed to save config!\n"); logging::Info("cat_save: FATAL! Stream bad!"); - logging::Info("cat_save: Finished"); + } + else + g_ICvar->ConsolePrintf("CAT: cat_save: Successfully saved config!\n"); stream.close(); if (stream.fail()) logging::Info("cat_save: FATAL! Stream bad (2)!"); @@ -92,6 +99,7 @@ bool settings::SettingsReader::loadFrom(std::string path) if (stream.fail()) { logging::Info("cat_load: Can't access file!"); + g_ICvar->ConsolePrintf("CAT: cat_load: File doesn't exist / can't open file!\n"); return false; } @@ -106,10 +114,12 @@ bool settings::SettingsReader::loadFrom(std::string path) if (stream.fail() && !stream.eof()) { logging::Info("cat_load: FATAL: Read failed!"); + g_ICvar->ConsolePrintf("CAT: cat_load: Failed to read config!\n"); return false; } logging::Info("cat_load: Read Success!"); + g_ICvar->ConsolePrintf("CAT: cat_load: Successfully loaded config!\n"); finishString(true); return true; diff --git a/src/tfmm.cpp b/src/tfmm.cpp index 72cba184..8a0e8595 100644 --- a/src/tfmm.cpp +++ b/src/tfmm.cpp @@ -30,6 +30,8 @@ CatCommand get_state("mm_state", "Get party state", []() { logging::Info("State: %d", re::CTFParty::state_(party)); }); +static CatCommand mm_stop_queue("mm_stop_queue", "Stop current TF2 MM queue", []() { tfmm::leaveQueue(); }); + namespace tfmm { int queuecount = 0; diff --git a/src/visual/menu/GuiInterface.cpp b/src/visual/menu/GuiInterface.cpp index b4be8cfd..864b25a7 100644 --- a/src/visual/menu/GuiInterface.cpp +++ b/src/visual/menu/GuiInterface.cpp @@ -50,32 +50,32 @@ public: } else if (name == "player_disconnect") { - //logging::Info("removePlayer %d", userid); + // logging::Info("removePlayer %d", userid); controller->removePlayer(userid); } else if (name == "player_team") { - //logging::Info("updatePlayerTeam %d", userid); + // logging::Info("updatePlayerTeam %d", userid); controller->updatePlayerTeam(userid, event->GetInt("team") - 1); } else if (name == "player_changeclass") { - //logging::Info("updatePlayerClass %d", userid); + // logging::Info("updatePlayerClass %d", userid); controller->updatePlayerClass(userid, event->GetInt("class")); } else if (name == "player_changename") { - //logging::Info("updatePlayerName %d", userid); + // logging::Info("updatePlayerName %d", userid); controller->updatePlayerName(userid, event->GetString("newname")); } else if (name == "player_death") { - //logging::Info("updatePlayerLifeState %d", userid); + // logging::Info("updatePlayerLifeState %d", userid); controller->updatePlayerLifeState(userid, true); } else if (name == "player_spawn") { - //logging::Info("updatePlayerLifeState %d", userid); + // logging::Info("updatePlayerLifeState %d", userid); controller->updatePlayerLifeState(userid, false); } } @@ -148,7 +148,7 @@ bool gui::handleSdlEvent(SDL_Event *event) { if (event->key.keysym.scancode == (*open_gui_button).scan) { - //logging::Info("GUI open button pressed"); + // logging::Info("GUI open button pressed"); zerokernel::Menu::instance->setInGame(!zerokernel::Menu::instance->isInGame()); if (!zerokernel::Menu::instance->isInGame()) {