2023-07-19 19:29:11 -04:00
|
|
|
|
2023-07-19 13:39:50 -04:00
|
|
|
#include <stdio.h>
|
2023-07-19 19:29:11 -04:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
#include "include/main.h"
|
|
|
|
#include "include/sdk.h"
|
2023-07-20 11:44:35 -04:00
|
|
|
#include "include/globals.h"
|
|
|
|
#include "include/hooks.h"
|
2023-07-19 13:39:50 -04:00
|
|
|
|
2023-07-19 14:24:34 -04:00
|
|
|
/*
|
|
|
|
* We need:
|
|
|
|
* __attribute__((constructor))
|
|
|
|
* To indicate that this function will be the entry point once injected.
|
|
|
|
*/
|
2023-07-19 13:39:50 -04:00
|
|
|
__attribute__((constructor)) void load(void) {
|
2023-07-20 11:44:35 -04:00
|
|
|
printf("hl-cheat injected!\n");
|
2023-07-19 19:29:11 -04:00
|
|
|
|
2023-07-20 11:44:35 -04:00
|
|
|
/* Initialize globals/interfaces */
|
2023-07-19 19:29:11 -04:00
|
|
|
if (!globals_init()) {
|
2023-07-20 11:44:35 -04:00
|
|
|
fprintf(stderr, "hl-cheat: load: error loading globals, aborting\n");
|
2023-07-19 19:29:11 -04:00
|
|
|
self_unload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-20 11:44:35 -04:00
|
|
|
/* Hook functions */
|
|
|
|
if (!hooks_init()) {
|
|
|
|
fprintf(stderr, "hl-cheat: load: error hooking functions, aborting\n");
|
|
|
|
self_unload();
|
|
|
|
return;
|
|
|
|
}
|
2023-07-19 19:29:11 -04:00
|
|
|
|
2023-07-20 11:44:35 -04:00
|
|
|
gp_engine->pfnClientCmd("echo \"hl-cheat loaded successfully!\"");
|
2023-07-19 19:29:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void self_unload(void) {
|
|
|
|
/*
|
|
|
|
* RTLD_LAZY: If the symbol is never referenced, then it is never resolved.
|
|
|
|
* RTLD_NOLOAD: Don't load the shared object.
|
|
|
|
*/
|
|
|
|
void* self = dlopen("libhlcheat.so", RTLD_LAZY | RTLD_NOLOAD);
|
|
|
|
|
|
|
|
/* Close the call we just made to dlopen() */
|
|
|
|
dlclose(self);
|
|
|
|
|
|
|
|
/* Close the call our injector made */
|
|
|
|
dlclose(self);
|
2023-07-19 13:39:50 -04:00
|
|
|
}
|