From fd0aea976f7ed3235e4090d4754aa637b0c09e19 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Thu, 27 Jul 2023 22:13:34 +0200 Subject: [PATCH 1/7] Get player_extra_info symbol --- src/globals.c | 6 ++++++ src/include/globals.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/globals.c b/src/globals.c index 3f390aa..7b60109 100644 --- a/src/globals.c +++ b/src/globals.c @@ -19,6 +19,9 @@ DECL_INTF(StudioModelRenderer_t, studiomodelrenderer); /* Game struct with some useful info */ game_t* game_info; +/* Array of extra_player_info's for each player */ +extra_player_info_t* player_extra_info; + /* Updated in CL_CreateMove hook */ cl_entity_t* localplayer = NULL; @@ -49,6 +52,9 @@ bool globals_init(void) { const char* SMR_STR = "g_StudioRenderer"; /* For clang-format */ i_studiomodelrenderer = *(StudioModelRenderer_t**)dlsym(*h_client, SMR_STR); + const char* PEI_STR = "g_PlayerExtraInfo"; /* For clang-format */ + player_extra_info = (extra_player_info_t*)dlsym(*h_client, PEI_STR); + game_info = *(game_t**)dlsym(hw, "game"); if (!i_engine || !i_client || !i_pmove || !i_enginestudio || diff --git a/src/include/globals.h b/src/include/globals.h index a0dafc6..a3dbad3 100644 --- a/src/include/globals.h +++ b/src/include/globals.h @@ -35,6 +35,7 @@ DECL_INTF_EXTERN(engine_studio_api_t, enginestudio); DECL_INTF_EXTERN(StudioModelRenderer_t, studiomodelrenderer); extern game_t* game_info; +extern extra_player_info_t* player_extra_info; extern cl_entity_t* localplayer; /*----------------------------------------------------------------------------*/ From 260d6647e63eba63f5eacc2a6220177898ac89ab Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Thu, 27 Jul 2023 22:13:54 +0200 Subject: [PATCH 2/7] Check is_friend with player_extra_info --- src/util.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util.c b/src/util.c index 682a031..101851b 100644 --- a/src/util.c +++ b/src/util.c @@ -32,10 +32,8 @@ bool valid_player(cl_entity_t* ent) { } bool is_friend(cl_entity_t* ent) { - /* TODO */ - - (void)ent; - return false; + return !strcmp(player_extra_info[ent->index].teamname, + player_extra_info[localplayer->index].teamname); } char* get_name(int ent_idx) { From eff4c7073970098d8195b45c378360544b765dc2 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Fri, 28 Jul 2023 14:41:34 +0200 Subject: [PATCH 3/7] Change is_alive checks Add ent check to is_friend --- src/util.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/util.c b/src/util.c index 101851b..37fb4e3 100644 --- a/src/util.c +++ b/src/util.c @@ -22,8 +22,7 @@ cl_entity_t* get_player(int ent_idx) { } bool is_alive(cl_entity_t* ent) { - /* TODO */ - return ent && ent->curstate.movetype != 6 && ent->curstate.movetype != 0; + return ent && !player_extra_info[ent->index].dead; } bool valid_player(cl_entity_t* ent) { @@ -32,8 +31,8 @@ bool valid_player(cl_entity_t* ent) { } bool is_friend(cl_entity_t* ent) { - return !strcmp(player_extra_info[ent->index].teamname, - player_extra_info[localplayer->index].teamname); + return ent && !strcmp(player_extra_info[ent->index].teamname, + player_extra_info[localplayer->index].teamname); } char* get_name(int ent_idx) { From f924628fd9aab0615be37a8cb57b2df29d446d14 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Fri, 28 Jul 2023 15:33:18 +0200 Subject: [PATCH 4/7] Add hook comments --- src/hooks.c | 3 +++ src/include/hooks.h | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hooks.c b/src/hooks.c index 10e3d09..465b1da 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -23,12 +23,15 @@ DECL_HOOK(CL_Move); /*----------------------------------------------------------------------------*/ bool hooks_init(void) { + /* VMT hooking */ HOOK(i_client, CL_CreateMove); HOOK(i_client, HUD_Redraw); HOOK(i_studiomodelrenderer, StudioRenderModel); + /* OpenGL hooks */ GL_HOOK(glColor4f); + /* Detour hooks */ void* clmove_ptr = dlsym(hw, "CL_Move"); if (!clmove_ptr) return false; diff --git a/src/include/hooks.h b/src/include/hooks.h index 674aafc..ab709d5 100644 --- a/src/include/hooks.h +++ b/src/include/hooks.h @@ -91,12 +91,15 @@ bool hooks_init(void); void hooks_restore(void); +/* VMT hooks */ DECL_HOOK_EXTERN(void, CL_CreateMove, float, usercmd_t*, int); DECL_HOOK_EXTERN(int, HUD_Redraw, float, int); -DECL_HOOK_EXTERN(void, StudioRenderModel, void* this_ptr); +DECL_HOOK_EXTERN(void, StudioRenderModel, void*); -DECL_HOOK_EXTERN(void, glColor4f, GLfloat r, GLfloat g, GLfloat b, GLfloat a); +/* OpenGL hooks */ +DECL_HOOK_EXTERN(void, glColor4f, GLfloat, GLfloat, GLfloat, GLfloat); +/* Detour hooks */ DECL_HOOK_EXTERN(void, CL_Move); #endif /* HOOKS_H_ */ From de578033f2c001065df0809112eef70ed755ab20 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Fri, 28 Jul 2023 15:43:35 +0200 Subject: [PATCH 5/7] Add this_game_id global For storing the current game we are playing --- src/globals.c | 4 ++++ src/include/globals.h | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/globals.c b/src/globals.c index 7b60109..ff4e53a 100644 --- a/src/globals.c +++ b/src/globals.c @@ -8,6 +8,8 @@ #include "include/sdk.h" #include "include/util.h" +enum game_id this_game_id = HL; + void* hw; void** h_client; DECL_INTF(cl_enginefunc_t, engine); @@ -25,6 +27,8 @@ extra_player_info_t* player_extra_info; /* Updated in CL_CreateMove hook */ cl_entity_t* localplayer = NULL; +/*----------------------------------------------------------------------------*/ + bool globals_init(void) { /* * Get handler for hw.so diff --git a/src/include/globals.h b/src/include/globals.h index a3dbad3..1c17d35 100644 --- a/src/include/globals.h +++ b/src/include/globals.h @@ -4,6 +4,13 @@ #include "sdk.h" +enum game_id { + HL = 0, /* Half-Life 1 */ + CS = 1, /* Counter-Strike 1.6 */ + TF = 2, /* Team Fortress Classic */ + DOD = 3, /* Day of Defeat */ +}; + /*----------------------------------------------------------------------------*/ /* @@ -26,6 +33,8 @@ /*----------------------------------------------------------------------------*/ +extern game_id this_game_id; + extern void* hw; extern void** h_client; /* hClientDLL hander */ DECL_INTF_EXTERN(cl_enginefunc_t, engine); From 418f1afacaecffc96bddcb681b7de274e35cf4b2 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Fri, 28 Jul 2023 15:43:51 +0200 Subject: [PATCH 6/7] Add get_cur_game to util.c Reverse is_alive method to avoid esp on some dead people Add game check to is_friend, since the team method only works on certain games --- src/include/util.h | 1 + src/util.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/include/util.h b/src/include/util.h index ec1c80e..ac48129 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -28,6 +28,7 @@ bool is_alive(cl_entity_t* ent); bool valid_player(cl_entity_t* ent); bool is_friend(cl_entity_t* ent); char* get_name(int ent_idx); +game_id get_cur_game(void); vec3_t vec3(float x, float y, float z); bool vec_is_zero(vec3_t v); float vec_len2d(vec3_t v); diff --git a/src/util.c b/src/util.c index 37fb4e3..85d8984 100644 --- a/src/util.c +++ b/src/util.c @@ -2,6 +2,7 @@ #include #include #include +#include /* dlsym */ #include /* getpagesize */ #include /* mprotect */ @@ -22,7 +23,7 @@ cl_entity_t* get_player(int ent_idx) { } bool is_alive(cl_entity_t* ent) { - return ent && !player_extra_info[ent->index].dead; + return ent && ent->curstate.movetype != 6 && ent->curstate.movetype != 0; } bool valid_player(cl_entity_t* ent) { @@ -31,8 +32,15 @@ bool valid_player(cl_entity_t* ent) { } bool is_friend(cl_entity_t* ent) { - return ent && !strcmp(player_extra_info[ent->index].teamname, - player_extra_info[localplayer->index].teamname); + if (!ent) + return false; + + /* Check the current game because this method only works for some games */ + if (this_game_id == CS || this_game_id == TF) + return player_extra_info[ent->index].teamnumber == + player_extra_info[localplayer->index].teamnumber; + else + return false; } char* get_name(int ent_idx) { @@ -42,6 +50,26 @@ char* get_name(int ent_idx) { return info.name; } +game_id get_cur_game(void) { + typedef void (*COM_ParseDirectoryFromCmd_t)(const char*, char*, int, + const char*); + COM_ParseDirectoryFromCmd_t COM_ParseDirectoryFromCmd = + (COM_ParseDirectoryFromCmd_t)dlsym(hw, "COM_ParseDirectoryFromCmd"); + + char game[FILENAME_MAX]; + COM_ParseDirectoryFromCmd("-game", game, sizeof(game), "valve"); + + /* Get the current game we are playing */ + if (game[0] == 'c' && game[1] == 's') /* cstrike */ + return CS; + else if (*game == 'd') /* dod */ + return DOD; + else if (*game == 't') /* tfc */ + return TF; + else + return HL; +} + vec3_t vec3(float x, float y, float z) { vec3_t ret; From 3e28c655ea578ca5936552a9f319a742dcf3cbb4 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Fri, 28 Jul 2023 15:44:31 +0200 Subject: [PATCH 7/7] Get the current game once when injecting --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index 92e5756..4639e41 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,7 @@ #include "include/globals.h" #include "include/cvars.h" #include "include/hooks.h" +#include "include/util.h" static bool loaded = false; @@ -35,6 +36,9 @@ void load(void) { return; } + /* Get game version after injecting */ + this_game_id = get_cur_game(); + i_engine->pfnClientCmd("echo \"hl-cheat loaded successfully!\""); loaded = true;