2023-07-19 19:44:20 -04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2023-07-22 09:48:01 -04:00
|
|
|
#include <string.h>
|
2023-07-19 19:44:20 -04:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
#include "include/globals.h"
|
|
|
|
#include "include/sdk.h"
|
2023-07-24 09:57:48 -04:00
|
|
|
#include "include/util.h"
|
2023-07-19 19:44:20 -04:00
|
|
|
|
|
|
|
void* hw;
|
2023-07-24 09:57:48 -04:00
|
|
|
void** h_client;
|
2023-07-20 10:38:02 -04:00
|
|
|
DECL_INTF(cl_enginefunc_t, engine);
|
|
|
|
DECL_INTF(cl_clientfunc_t, client);
|
2023-07-20 14:40:34 -04:00
|
|
|
DECL_INTF(playermove_t, pmove);
|
2023-07-24 10:29:19 -04:00
|
|
|
DECL_INTF(engine_studio_api_t, enginestudio);
|
2023-07-24 09:57:48 -04:00
|
|
|
DECL_INTF(StudioModelRenderer_t, studiomodelrenderer);
|
2023-07-19 19:44:20 -04:00
|
|
|
|
2023-07-20 17:30:44 -04:00
|
|
|
/* Updated in CL_CreateMove hook */
|
|
|
|
cl_entity_t* localplayer = NULL;
|
|
|
|
|
2023-07-19 19:44:20 -04:00
|
|
|
bool globals_init(void) {
|
|
|
|
/*
|
|
|
|
* Get handler for hw.so
|
|
|
|
* RTLD_LAZY: If the symbol is never referenced, then it is never resolved.
|
|
|
|
* RTLD_NOLOAD: Don't load the shared object.
|
|
|
|
*/
|
|
|
|
hw = dlopen("hw.so", RTLD_LAZY | RTLD_NOLOAD);
|
|
|
|
|
|
|
|
/* Make sure it's a valid handler */
|
|
|
|
if (!hw) {
|
2023-07-20 11:31:16 -04:00
|
|
|
printf("hl-cheat: globals_init: can't open hw.so\n");
|
2023-07-19 19:44:20 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-24 09:57:48 -04:00
|
|
|
h_client = (void**)dlsym(hw, "hClientDLL");
|
|
|
|
|
|
|
|
if (!h_client) {
|
|
|
|
printf("hl-cheat: globals_init: can't find hClientDLL\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-19 19:44:20 -04:00
|
|
|
/* Get symbol addresses using dlsym and the handler we just opened */
|
2023-07-24 10:29:19 -04:00
|
|
|
i_engine = (cl_enginefunc_t*)dlsym(hw, "cl_enginefuncs");
|
|
|
|
i_client = (cl_clientfunc_t*)dlsym(hw, "cl_funcs");
|
|
|
|
i_pmove = *(playermove_t**)dlsym(hw, "pmove");
|
|
|
|
i_enginestudio = (engine_studio_api_t*)dlsym(hw, "engine_studio_api");
|
2023-07-19 19:44:20 -04:00
|
|
|
|
2023-07-24 09:57:48 -04:00
|
|
|
const char* SMR_STR = "g_StudioRenderer"; /* For clang-format */
|
|
|
|
i_studiomodelrenderer = *(StudioModelRenderer_t**)dlsym(*h_client, SMR_STR);
|
|
|
|
|
2023-07-24 10:29:19 -04:00
|
|
|
if (!i_engine || !i_client || !i_pmove || !i_enginestudio ||
|
|
|
|
!i_studiomodelrenderer) {
|
2023-07-24 09:57:48 -04:00
|
|
|
printf("hl-cheat: globals_init: couldn't load some symbols\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!unprotect_addr(i_studiomodelrenderer)) {
|
|
|
|
printf("hl-cheat: globals_init: couldn't unprotect address of SMR\n");
|
2023-07-20 17:19:50 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-21 01:02:26 -04:00
|
|
|
globals_store();
|
|
|
|
|
2023-07-19 19:44:20 -04:00
|
|
|
return true;
|
|
|
|
}
|
2023-07-21 01:02:26 -04:00
|
|
|
|
|
|
|
void globals_store(void) {
|
2023-07-22 09:48:01 -04:00
|
|
|
memcpy(&o_engine, i_engine, sizeof(cl_enginefunc_t));
|
|
|
|
memcpy(&o_client, i_client, sizeof(cl_clientfunc_t));
|
2023-07-21 01:02:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void globals_restore(void) {
|
2023-07-22 09:48:01 -04:00
|
|
|
memcpy(i_engine, &o_engine, sizeof(cl_enginefunc_t));
|
|
|
|
memcpy(i_client, &o_client, sizeof(cl_clientfunc_t));
|
2023-07-21 01:02:26 -04:00
|
|
|
}
|