From 6103ae8019d38d099502db8db4ca3f6c97a115f6 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Thu, 20 Jul 2023 01:44:20 +0200 Subject: [PATCH] Add globals.c file Declarations of the externs in the header globals_init() function for getting the hw.so handler and the gp_engine and gp_client symbol pointers --- src/globals.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/globals.c diff --git a/src/globals.c b/src/globals.c new file mode 100644 index 0000000..176667f --- /dev/null +++ b/src/globals.c @@ -0,0 +1,31 @@ + +#include +#include + +#include "include/globals.h" +#include "include/sdk.h" + +void* hw; +DECLARE_SYMBOLS(cl_enginefunc_t, engine); +DECLARE_SYMBOLS(cl_clientfunc_t, client); + +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) { + printf("hl-cheats: globals_init: can't open hw.so\n"); + return false; + } + + /* Get symbol addresses using dlsym and the handler we just opened */ + gp_engine = (cl_enginefunc_t*)dlsym(hw, "cl_enginefuncs"); + gp_client = (cl_clientfunc_t*)dlsym(hw, "cl_funcs"); + + return true; +}