2023-07-20 01:29:11 +02:00
|
|
|
|
2023-07-19 19:39:50 +02:00
|
|
|
#include <stdio.h>
|
2023-07-20 01:29:11 +02:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
#include "include/main.h"
|
|
|
|
#include "include/sdk.h"
|
2023-07-20 17:44:35 +02:00
|
|
|
#include "include/globals.h"
|
2023-07-21 13:44:53 +02:00
|
|
|
#include "include/cvars.h"
|
2023-07-20 17:44:35 +02:00
|
|
|
#include "include/hooks.h"
|
2023-07-28 15:44:31 +02:00
|
|
|
#include "include/util.h"
|
2023-07-19 19:39:50 +02:00
|
|
|
|
2023-07-21 07:02:38 +02:00
|
|
|
static bool loaded = false;
|
|
|
|
|
2023-07-21 13:59:38 +02:00
|
|
|
__attribute__((constructor)) /* Entry point when injected */
|
|
|
|
void load(void) {
|
2023-07-20 17:44:35 +02:00
|
|
|
printf("hl-cheat injected!\n");
|
2023-07-20 01:29:11 +02:00
|
|
|
|
2023-07-20 17:44:35 +02:00
|
|
|
/* Initialize globals/interfaces */
|
2023-07-20 01:29:11 +02:00
|
|
|
if (!globals_init()) {
|
2023-07-20 17:44:35 +02:00
|
|
|
fprintf(stderr, "hl-cheat: load: error loading globals, aborting\n");
|
2023-07-20 01:29:11 +02:00
|
|
|
self_unload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:44:53 +02:00
|
|
|
/* Create cvars for settings */
|
|
|
|
if (!cvars_init()) {
|
|
|
|
fprintf(stderr, "hl-cheat: load: error creating cvars, aborting\n");
|
|
|
|
self_unload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-20 17:44:35 +02:00
|
|
|
/* Hook functions */
|
|
|
|
if (!hooks_init()) {
|
|
|
|
fprintf(stderr, "hl-cheat: load: error hooking functions, aborting\n");
|
|
|
|
self_unload();
|
|
|
|
return;
|
|
|
|
}
|
2023-07-20 01:29:11 +02:00
|
|
|
|
2023-07-28 15:44:31 +02:00
|
|
|
/* Get game version after injecting */
|
|
|
|
this_game_id = get_cur_game();
|
|
|
|
|
2023-07-20 20:25:49 +02:00
|
|
|
i_engine->pfnClientCmd("echo \"hl-cheat loaded successfully!\"");
|
2023-07-21 07:02:38 +02:00
|
|
|
|
|
|
|
loaded = true;
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:59:38 +02:00
|
|
|
__attribute__((destructor)) /* Entry point when unloaded */
|
|
|
|
void unload() {
|
2023-07-21 13:58:47 +02:00
|
|
|
if (loaded) {
|
|
|
|
/* TODO: Remove our cvars */
|
|
|
|
|
2023-07-21 07:02:38 +02:00
|
|
|
globals_restore();
|
2023-07-25 20:37:52 +02:00
|
|
|
hooks_restore();
|
2023-07-25 14:28:03 +02:00
|
|
|
|
|
|
|
GL_UNHOOK(glColor4f); /* Manually restore OpenGL hooks here */
|
2023-07-21 13:58:47 +02:00
|
|
|
}
|
2023-07-21 07:02:38 +02:00
|
|
|
|
|
|
|
printf("hl-cheat unloaded.\n\n");
|
2023-07-20 01:29:11 +02: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 19:39:50 +02:00
|
|
|
}
|