From 7e8f6d011c4622289ba11a0ee2233f26e91d1b5d Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Wed, 16 Aug 2017 19:39:50 +0300 Subject: [PATCH 1/4] hitrate and IPC update --- src/hacks/Walkbot.cpp | 4 +- src/hitrate.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++ src/hitrate.hpp | 18 +++++++++ src/hooks/others.cpp | 6 +++ src/ipc.cpp | 4 ++ src/ipc.h | 3 ++ src/netvars.cpp | 1 + src/netvars.h | 1 + 8 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/hitrate.cpp create mode 100644 src/hitrate.hpp diff --git a/src/hacks/Walkbot.cpp b/src/hacks/Walkbot.cpp index ca08b83b..f857f202 100644 --- a/src/hacks/Walkbot.cpp +++ b/src/hacks/Walkbot.cpp @@ -269,8 +269,8 @@ bool Load(std::string filename) { { DIR* walkbot_dir = opendir(DATA_PATH "/walkbot"); if (!walkbot_dir) { - logging::Info("Walkbot directory doesn't exist, creating one!"); - mkdir(DATA_PATH "/walkbot", S_IRWXU | S_IRWXG); + logging::Info("Walkbot directory doesn't exist!"); + return false; } else closedir(walkbot_dir); } std::string path = format(DATA_PATH "/walkbot/", GetLevelName()); diff --git a/src/hitrate.cpp b/src/hitrate.cpp new file mode 100644 index 00000000..a3d2db39 --- /dev/null +++ b/src/hitrate.cpp @@ -0,0 +1,91 @@ +/* + * hitrate.cpp + * + * Created on: Aug 16, 2017 + * Author: nullifiedcat + */ + +#include "common.h" +#include "init.hpp" + +namespace hitrate { + +int lastweapon { 0 }; +int lastammo { 0 }; + +int count_shots { 0 }; +int count_hits { 0 }; +int count_hits_head { 0 }; + +std::vector> shots {}; + +void OnShot() { + ++count_shots; +} + +void OnHit(bool crit) { + count_hits++; + if (crit) { + count_hits_head++; + } +} + +CatCommand debug_hitrate("debug_hitrate", "Debug hitrate", []() { + int p1 = 0; + int p2 = 0; + if (count_shots) { + p1 = float(count_hits) / float(count_shots) * 100.0f; + } + if (count_hits) { + p1 = float(count_hits_head) / float(count_hits) * 100.0f; + } + logging::Info("%d / %d (%d%%)", count_hits, count_shots, p1); + logging::Info("%d / %d (%d%%)", count_hits_head, count_hits, p2); +}); + +CatCommand debug_ammo("debug_ammo", "Debug ammo", []() { + for (int i = 0; i < 4; i++) { + logging::Info("%d %d", i, CE_INT(LOCAL_E, netvar.m_iAmmo + i * 4)); + } +}); + +void Update() { + CachedEntity* weapon = LOCAL_W; + if (CE_GOOD(weapon)) { + if (LOCAL_W->m_iClassID == CL_CLASS(CTFSniperRifle) || LOCAL_W->m_iClassID == CL_CLASS(CTFSniperRifleDecap)) { + // ONLY tracks primary ammo + int ammo = CE_INT(LOCAL_E, netvar.m_iAmmo + 4); + if (lastweapon) { + if (ammo < lastammo) { + OnShot(); + } + } + lastweapon = weapon->m_IDX; + lastammo = ammo; + } + } else { + lastweapon = 0; + } +} + +class HurtListener : public IGameEventListener { +public: + virtual void FireGameEvent(KeyValues* event) { + if (strcmp("player_hurt", event->GetName())) return; + if (g_IEngine->GetPlayerForUserID(event->GetInt("attacker")) == g_IEngine->GetLocalPlayer()) { + if (CE_GOOD(LOCAL_W) && (LOCAL_W->m_iClassID == CL_CLASS(CTFSniperRifle) || LOCAL_W->m_iClassID == CL_CLASS(CTFSniperRifleDecap))) + OnHit(event->GetBool("crit")); + } + } +}; + +HurtListener& listener() { + static HurtListener l {}; + return l; +} + +InitRoutine init([]() { + g_IGameEventManager->AddListener(&listener(), false); +}); + +} diff --git a/src/hitrate.hpp b/src/hitrate.hpp new file mode 100644 index 00000000..f7a095e5 --- /dev/null +++ b/src/hitrate.hpp @@ -0,0 +1,18 @@ +/* + * hitrate.hpp + * + * Created on: Aug 16, 2017 + * Author: nullifiedcat + */ + +#pragma once + +namespace hitrate { + +extern int count_shots; +extern int count_hits; +extern int count_hits_head; + +void Update(); + +} diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index 08230f27..397a5d09 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -10,6 +10,7 @@ #include "../chatlog.hpp" #include "../hack.h" #include "ucccccp.hpp" +#include "../hitrate.hpp" #include "hookedmethods.h" #if ENABLE_VISUALS == 1 @@ -377,6 +378,8 @@ void FireGameEvent_hook(void* _this, IGameEvent* event) { original(_this, event); } +static CatVar hitrate_check(CV_SWITCH, "hitrate", "0", "Monitor hitrate"); + void FrameStageNotify_hook(void* _this, int stage) { static IClientEntity *ent; @@ -394,6 +397,9 @@ void FrameStageNotify_hook(void* _this, int stage) { if (stage == FRAME_NET_UPDATE_POSTDATAUPDATE_START) { angles::Update(); hacks::shared::anticheat::CreateMove(); + if (hitrate_check) { + hitrate::Update(); + } } if (resolver && cathook && !g_Settings.bInvalid && stage == FRAME_NET_UPDATE_POSTDATAUPDATE_START) { PROF_SECTION(FSN_resolver); diff --git a/src/ipc.cpp b/src/ipc.cpp index a7e533b2..8a2bfcbb 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -10,6 +10,7 @@ #include "common.h" #include "hack.h" +#include "hitrate.hpp" #ifdef IPC_ENABLED @@ -171,6 +172,9 @@ void UpdateServerAddress(bool shutdown) { void UpdateTemporaryData() { user_data_s& data = peer->memory->peer_user_data[peer->client_id]; data.connected = g_IEngine->IsInGame(); + data.shots = hitrate::count_shots; + data.hits = hitrate::count_hits; + data.headshots = hitrate::count_hits_head; if (data.connected) { IClientEntity* player = g_IEntityList->GetClientEntity(g_IEngine->GetLocalPlayer()); if (player) { diff --git a/src/ipc.h b/src/ipc.h index 1c9c8702..6a5dc326 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -67,6 +67,9 @@ struct user_data_s { time_t ts_injected; time_t ts_connected; time_t ts_disconnected; + int shots; + int hits; + int headshots; }; using peer_t = cat_ipc::Peer; diff --git a/src/netvars.cpp b/src/netvars.cpp index 8fdbe59f..43b09283 100644 --- a/src/netvars.cpp +++ b/src/netvars.cpp @@ -22,6 +22,7 @@ void NetVars::Init() { this->vVelocity = gNetvars.get_offset("DT_BasePlayer", "localdata", "m_vecVelocity[0]"); this->movetype = gNetvars.get_offset("DT_BaseEntity", "movetype"); this->m_iAmmo = gNetvars.get_offset("DT_BasePlayer", "localdata", "m_iAmmo"); + this->m_iClip1 = gNetvars.get_offset("DT_BaseCombatWeapon", "LocalWeaponData", "m_iClip1"); this->m_Collision = gNetvars.get_offset("DT_BaseEntity", "m_Collision"); m_flSimulationTime = gNetvars.get_offset("DT_BaseEntity", "m_flSimulationTime"); IF_GAME (IsTF2()) { diff --git a/src/netvars.h b/src/netvars.h index c6684afc..c294d177 100644 --- a/src/netvars.h +++ b/src/netvars.h @@ -75,6 +75,7 @@ public: offset_t iNextMeleeCrit; offset_t flNextPrimaryAttack; offset_t iNextThinkTick; + offset_t m_iClip1; //offset_t flReloadPriorNextFire; //offset_t flObservedCritChance; offset_t nTickBase; From 7d4909451e7a8e9d26413df6bc8fc1d9f43bab2d Mon Sep 17 00:00:00 2001 From: SylveonBottle Date: Wed, 16 Aug 2017 14:43:19 -0500 Subject: [PATCH 2/4] Update and rename update-gccdowngrade to arch-gcc-fix --- arch-gcc-fix | 18 ++++++++++++++++++ update-gccdowngrade | 28 ---------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 arch-gcc-fix delete mode 100644 update-gccdowngrade diff --git a/arch-gcc-fix b/arch-gcc-fix new file mode 100644 index 00000000..23bd5bdc --- /dev/null +++ b/arch-gcc-fix @@ -0,0 +1,18 @@ +#!/bin/bash + +# +# THIS IS FOR ARCH USERS ONLY +# Cathook requires gcc6 to build. Steam requires gcc7 to run. There is no gcc6 and gcc7 package on arch, only a single gcc package that is currently updated to gcc7. +# A solution to this would be to simply downgrade to gcc6 to update cathook, then re-upgrade to gcc7 to launch steam. +# This will install gcc6, backup the files, then upgrade to gcc7 and place the files back. This way, gcc7 will be installed, but cathook can still use gcc6. +# + +# Get gcc6 +sudo pacman -U /var/cache/pacman/pkg/lib32-gcc-libs-6.3.1-2-x86_64.pkg.tar.xz /var/cache/pacman/pkg/gcc-libs-multilib-6.3.1-2-x86_64.pkg.tar.xz /var/cache/pacman/pkg/gcc-multilib-6.3.1-2-x86_64.pkg.tar.xz +# Backup gcc6 to /tmp +sudo cp -r /usr/include/c++/6.3.1/ /tmp/ +# Update back to gcc7 +sudo pacman -S lib62-gcc-libs gcc-libs-multilib gcc-multilib +# Use backup of gcc6 and place back into c++ +sudo cp -r /tmp/6.3.1/ /usr/include/c++/ +# Should we remove the tmp folder afterwards..? It'll be deleted on restart regardless. diff --git a/update-gccdowngrade b/update-gccdowngrade deleted file mode 100644 index 8c13e3dd..00000000 --- a/update-gccdowngrade +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -# -# Super l33t code to downloade gcc to v6, update cathook, then re-upgrade to v7 -# Script was created to automate the problem of downgrading to gcc6 to update cathook, then update to gcc7 to launch steam -# This should only be useful for arch users who can not install gcc6 and gcc7 as seperate packages due to either lack of knowledge or technical reasons -# - -if [ $EUID == 0 ]; then - echo "This script must be ran as root" # Standard root check to not break anything if anything is breakable. - exit -fi - -if [ -e "/var/cache/pacman/pkg/lib32-gcc-libs-6.3.1-2-x86_64.pkg.tar.xz" ] # Check if user even has gcc6 - then - sudo pacman -U /var/cache/pacman/pkg/lib32-gcc-libs-6.3.1-2-x86_64.pkg.tar.xz /var/cache/pacman/pkg/gcc-libs-multilib-6.3.1-2-x86_64.pkg.tar.xz /var/cache/pacman/pkg/gcc-multilib-6.3.1-2-x86_64.pkg.tar.xz # Downgrade to gcc6 - else - echo "Weird, it doesn't appear that you have gcc6 installed." # Exit script if gcc6 isnt found, - echo "This would have normally been installed if you ran the" # which is impossible if they - echo "arch dependencies script provided by the cathook page." # followed the installation - echo "How about you go do that first before running cathook." # guide properly. - exit -fi - -cd ~/cathook # cd into cathook -sudo ./update # run cathook's update script -cd - # cd back into what we were in before the previous cd -sudo pacman -Syu # update the system (and gcc) From 28a07615fdca70d0ef82255a4e3961653ca869bc Mon Sep 17 00:00:00 2001 From: SylveonBottle Date: Wed, 16 Aug 2017 14:45:06 -0500 Subject: [PATCH 3/4] Updated arch dependencies script, added glew --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d166c47..9a54698c 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ sudo apt update && sudo apt install git libssl-dev:i386 libc6-dev:i386 gdb libsd Arch gcc6 & dependencies installation: ```bash -sudo pacman -Syu && sudo pacman -S gdb gdb-common glew1.10 glew lib32-glew1.10 rsync --noconfirm && yes | sudo pacman -U https://archive.archlinux.org/packages/g/gcc-multilib/gcc-multilib-6.3.1-2-x86_64.pkg.tar.xz https://archive.archlinux.org/packages/g/gcc-libs-multilib/gcc-libs-multilib-6.3.1-2-x86_64.pkg.tar.xz https://archive.archlinux.org/packages/l/lib32-gcc-libs/lib32-gcc-libs-6.3.1-2-x86_64.pkg.tar.xz +sudo pacman -U /var/cache/pacman/pkg/lib32-gcc-libs-6.3.1-2-x86_64.pkg.tar.xz /var/cache/pacman/pkg/gcc-libs-multilib-6.3.1-2-x86_64.pkg.tar.xz /var/cache/pacman/pkg/gcc-multilib-6.3.1-2-x86_64.pkg.tar.xz && sudo cp -r /usr/include/c++/6.3.1/ /tmp/ && sudo pacman -S gdb gdb-common glew1.10 glew lib32-glew1.10 rsync lib62-gcc-libs gcc-libs-multilib gcc-multilib --noconfirm && yes | sudo cp -r /tmp/6.3.1/ /usr/include/c++/ ``` If you don't use Ubuntu or Arch (or if Arch script gets outdated), here's the list of what cathook requires: @@ -51,13 +51,14 @@ If you don't use Ubuntu or Arch (or if Arch script gets outdated), here's the li * `g++-6` * `gcc-6-multilib` * `g++-6-multilib` +* `glew` * `gdb` (for the injection script, you can use different injector if you want) * `libssl-dev:i386` * `libc6-dev:i386` * `libsdl2-dev` * `libglew-dev:i386` * `libfreetype6-dev:i386` -* `rsync` (only for copying shaders/fonts to tf2 data directory, `update-data` script) +* `rsync` (used for copying shaders/fonts to tf2 data directory, `update-data` script) Cathook installation script: From 89bf29f17df5ade151fff97799fc3e57273c8ba0 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Thu, 17 Aug 2017 14:29:30 +0300 Subject: [PATCH 4/4] more connection flags --- src/hacks/Walkbot.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hacks/Walkbot.cpp b/src/hacks/Walkbot.cpp index f857f202..927a689b 100644 --- a/src/hacks/Walkbot.cpp +++ b/src/hacks/Walkbot.cpp @@ -50,7 +50,16 @@ struct walkbot_header_s { enum EConnectionFlags { CF_GOOD = (1 << 0), CF_LOW_HEALTH = (1 << 1), - CF_LOW_AMMO = (1 << 2) + CF_LOW_AMMO = (1 << 2), + + CF_RED = (1 << 3), + CF_BLU = (1 << 4), + + CF_CAPPED_1 = (1 << 5), + CF_CAPPED_2 = (1 << 6), + CF_CAPPED_3 = (1 << 7), + CF_CAPPED_4 = (1 << 8), + CF_CAPPED_5 = (1 << 9) }; struct connection_s {