commit
c99976c5ef
|
@ -8,6 +8,8 @@
|
||||||
#include "include/sdk.h"
|
#include "include/sdk.h"
|
||||||
#include "include/util.h"
|
#include "include/util.h"
|
||||||
|
|
||||||
|
enum game_id this_game_id = HL;
|
||||||
|
|
||||||
void* hw;
|
void* hw;
|
||||||
void** h_client;
|
void** h_client;
|
||||||
DECL_INTF(cl_enginefunc_t, engine);
|
DECL_INTF(cl_enginefunc_t, engine);
|
||||||
|
@ -19,9 +21,14 @@ DECL_INTF(StudioModelRenderer_t, studiomodelrenderer);
|
||||||
/* Game struct with some useful info */
|
/* Game struct with some useful info */
|
||||||
game_t* game_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 */
|
/* Updated in CL_CreateMove hook */
|
||||||
cl_entity_t* localplayer = NULL;
|
cl_entity_t* localplayer = NULL;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
bool globals_init(void) {
|
bool globals_init(void) {
|
||||||
/*
|
/*
|
||||||
* Get handler for hw.so
|
* Get handler for hw.so
|
||||||
|
@ -49,6 +56,9 @@ bool globals_init(void) {
|
||||||
const char* SMR_STR = "g_StudioRenderer"; /* For clang-format */
|
const char* SMR_STR = "g_StudioRenderer"; /* For clang-format */
|
||||||
i_studiomodelrenderer = *(StudioModelRenderer_t**)dlsym(*h_client, SMR_STR);
|
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");
|
game_info = *(game_t**)dlsym(hw, "game");
|
||||||
|
|
||||||
if (!i_engine || !i_client || !i_pmove || !i_enginestudio ||
|
if (!i_engine || !i_client || !i_pmove || !i_enginestudio ||
|
||||||
|
|
|
@ -23,12 +23,15 @@ DECL_HOOK(CL_Move);
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
bool hooks_init(void) {
|
bool hooks_init(void) {
|
||||||
|
/* VMT hooking */
|
||||||
HOOK(i_client, CL_CreateMove);
|
HOOK(i_client, CL_CreateMove);
|
||||||
HOOK(i_client, HUD_Redraw);
|
HOOK(i_client, HUD_Redraw);
|
||||||
HOOK(i_studiomodelrenderer, StudioRenderModel);
|
HOOK(i_studiomodelrenderer, StudioRenderModel);
|
||||||
|
|
||||||
|
/* OpenGL hooks */
|
||||||
GL_HOOK(glColor4f);
|
GL_HOOK(glColor4f);
|
||||||
|
|
||||||
|
/* Detour hooks */
|
||||||
void* clmove_ptr = dlsym(hw, "CL_Move");
|
void* clmove_ptr = dlsym(hw, "CL_Move");
|
||||||
if (!clmove_ptr)
|
if (!clmove_ptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4,6 +4,13 @@
|
||||||
|
|
||||||
#include "sdk.h"
|
#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* hw;
|
||||||
extern void** h_client; /* hClientDLL hander */
|
extern void** h_client; /* hClientDLL hander */
|
||||||
DECL_INTF_EXTERN(cl_enginefunc_t, engine);
|
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);
|
DECL_INTF_EXTERN(StudioModelRenderer_t, studiomodelrenderer);
|
||||||
|
|
||||||
extern game_t* game_info;
|
extern game_t* game_info;
|
||||||
|
extern extra_player_info_t* player_extra_info;
|
||||||
extern cl_entity_t* localplayer;
|
extern cl_entity_t* localplayer;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -91,12 +91,15 @@
|
||||||
bool hooks_init(void);
|
bool hooks_init(void);
|
||||||
void hooks_restore(void);
|
void hooks_restore(void);
|
||||||
|
|
||||||
|
/* VMT hooks */
|
||||||
DECL_HOOK_EXTERN(void, CL_CreateMove, float, usercmd_t*, int);
|
DECL_HOOK_EXTERN(void, CL_CreateMove, float, usercmd_t*, int);
|
||||||
DECL_HOOK_EXTERN(int, HUD_Redraw, float, 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);
|
DECL_HOOK_EXTERN(void, CL_Move);
|
||||||
|
|
||||||
#endif /* HOOKS_H_ */
|
#endif /* HOOKS_H_ */
|
||||||
|
|
|
@ -28,6 +28,7 @@ bool is_alive(cl_entity_t* ent);
|
||||||
bool valid_player(cl_entity_t* ent);
|
bool valid_player(cl_entity_t* ent);
|
||||||
bool is_friend(cl_entity_t* ent);
|
bool is_friend(cl_entity_t* ent);
|
||||||
char* get_name(int ent_idx);
|
char* get_name(int ent_idx);
|
||||||
|
game_id get_cur_game(void);
|
||||||
vec3_t vec3(float x, float y, float z);
|
vec3_t vec3(float x, float y, float z);
|
||||||
bool vec_is_zero(vec3_t v);
|
bool vec_is_zero(vec3_t v);
|
||||||
float vec_len2d(vec3_t v);
|
float vec_len2d(vec3_t v);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "include/globals.h"
|
#include "include/globals.h"
|
||||||
#include "include/cvars.h"
|
#include "include/cvars.h"
|
||||||
#include "include/hooks.h"
|
#include "include/hooks.h"
|
||||||
|
#include "include/util.h"
|
||||||
|
|
||||||
static bool loaded = false;
|
static bool loaded = false;
|
||||||
|
|
||||||
|
@ -35,6 +36,9 @@ void load(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get game version after injecting */
|
||||||
|
this_game_id = get_cur_game();
|
||||||
|
|
||||||
i_engine->pfnClientCmd("echo \"hl-cheat loaded successfully!\"");
|
i_engine->pfnClientCmd("echo \"hl-cheat loaded successfully!\"");
|
||||||
|
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
|
31
src/util.c
31
src/util.c
|
@ -2,6 +2,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#include <dlfcn.h> /* dlsym */
|
||||||
#include <unistd.h> /* getpagesize */
|
#include <unistd.h> /* getpagesize */
|
||||||
#include <sys/mman.h> /* mprotect */
|
#include <sys/mman.h> /* mprotect */
|
||||||
|
|
||||||
|
@ -22,7 +23,6 @@ cl_entity_t* get_player(int ent_idx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_alive(cl_entity_t* ent) {
|
bool is_alive(cl_entity_t* ent) {
|
||||||
/* TODO */
|
|
||||||
return ent && ent->curstate.movetype != 6 && ent->curstate.movetype != 0;
|
return ent && ent->curstate.movetype != 6 && ent->curstate.movetype != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,14 @@ bool valid_player(cl_entity_t* ent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_friend(cl_entity_t* ent) {
|
bool is_friend(cl_entity_t* ent) {
|
||||||
/* TODO */
|
if (!ent)
|
||||||
|
return false;
|
||||||
|
|
||||||
(void)ent;
|
/* 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +50,26 @@ char* get_name(int ent_idx) {
|
||||||
return info.name;
|
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 vec3(float x, float y, float z) {
|
||||||
vec3_t ret;
|
vec3_t ret;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue