Merge pull request #1 from 8dcc/player_extra_info

Player extra info
This commit is contained in:
8dcc­ 2023-07-28 15:47:25 +02:00 committed by GitHub
commit c99976c5ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 6 deletions

View File

@ -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);
@ -19,9 +21,14 @@ 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;
/*----------------------------------------------------------------------------*/
bool globals_init(void) {
/*
* Get handler for hw.so
@ -49,6 +56,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 ||

View File

@ -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;

View File

@ -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);
@ -35,6 +44,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;
/*----------------------------------------------------------------------------*/

View File

@ -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_ */

View File

@ -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);

View File

@ -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;

View File

@ -2,6 +2,7 @@
#include <string.h>
#include <math.h>
#include <GL/gl.h>
#include <dlfcn.h> /* dlsym */
#include <unistd.h> /* getpagesize */
#include <sys/mman.h> /* mprotect */
@ -22,7 +23,6 @@ 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;
}
@ -32,10 +32,15 @@ bool valid_player(cl_entity_t* ent) {
}
bool is_friend(cl_entity_t* ent) {
/* TODO */
if (!ent)
return false;
(void)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) {
@ -45,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;