goldsrc-cheat/src/hooks.c

98 lines
2.4 KiB
C
Raw Normal View History

#include "include/hooks.h"
#include "include/sdk.h"
#include "include/globals.h"
2023-07-24 04:15:03 -04:00
#include "include/util.h"
2023-07-22 10:23:15 -04:00
/* bhop(), esp(), etc. */
#include "features/features.h"
DECL_HOOK(CL_CreateMove);
2023-07-21 09:42:01 -04:00
DECL_HOOK(HUD_Redraw);
2023-07-24 10:17:57 -04:00
DECL_HOOK(StudioRenderModel);
DECL_HOOK(glColor4f);
bool hooks_init(void) {
HOOK(i_client, CL_CreateMove);
2023-07-21 09:42:01 -04:00
HOOK(i_client, HUD_Redraw);
2023-07-24 10:17:57 -04:00
HOOK(i_studiomodelrenderer, StudioRenderModel);
GL_HOOK(glColor4f);
return true;
}
/*----------------------------------------------------------------------------*/
void h_CL_CreateMove(float frametime, usercmd_t* cmd, int active) {
ORIGINAL(CL_CreateMove, frametime, cmd, active);
vec3_t old_angles = cmd->viewangles;
2023-07-20 17:30:44 -04:00
/* Declared in globals.c */
localplayer = i_engine->GetLocalPlayer();
bhop(cmd);
correct_movement(cmd, old_angles);
2023-07-24 04:15:03 -04:00
vec_clamp(cmd->viewangles);
}
2023-07-21 09:42:01 -04:00
/*----------------------------------------------------------------------------*/
2023-07-21 09:42:01 -04:00
int h_HUD_Redraw(float time, int intermission) {
int ret = ORIGINAL(HUD_Redraw, time, intermission);
/* Watermark */
i_engine->pfnDrawSetTextColor(1, 1, 1);
i_engine->pfnDrawConsoleString(5, 5, "8dcc/hl-cheat");
2023-07-23 09:54:56 -04:00
#ifdef DEBUG
char pos[100];
sprintf(pos, "x: %f, y: %f, z: %f", localplayer->origin[0],
localplayer->origin[1], localplayer->origin[2]);
i_engine->pfnDrawSetTextColor(1, 1, 1);
i_engine->pfnDrawConsoleString(5, 20, pos);
2023-07-23 09:54:56 -04:00
#endif
esp();
2023-07-21 09:42:01 -04:00
return ret;
}
2023-07-24 10:17:57 -04:00
/*----------------------------------------------------------------------------*/
2023-07-24 10:17:57 -04:00
void h_StudioRenderModel(void* this_ptr) {
2023-07-24 11:03:22 -04:00
if (!chams(this_ptr))
ORIGINAL(StudioRenderModel, this_ptr);
2023-07-24 10:17:57 -04:00
}
/*----------------------------------------------------------------------------*/
void h_glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
/* This visible_mode variable is changed inside the chams() function, which
* is called from the StudioRenderModel hook.
*
* Depending on the type of entity we are trying to render from there, and
* depending on its visibility, we change this visible_mode variable. */
switch (visible_mode) {
case VISIBLE:
r = 0.40f;
g = 0.73f;
b = 0.41f;
break;
case NOT_VISIBLE:
r = 0.90f;
g = 0.07f;
b = 0.27f;
break;
default:
case NONE:
break;
}
ORIGINAL(glColor4f, r, g, b, a);
}