Update thirdperson.c, hooks.c, and 3 more files...
This commit is contained in:
		
							
								
								
									
										51
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -18,7 +18,6 @@ | ||||
|  | ||||
| static bool loaded = false; | ||||
|  | ||||
| /* Create a debug log file */ | ||||
| void debug_log(const char* message) { | ||||
|     FILE* logfile = fopen("/tmp/cheat-unload-debug.log", "a"); | ||||
|     if (logfile) { | ||||
| @@ -30,54 +29,39 @@ void debug_log(const char* message) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| /* Enhanced unloading with debug logging */ | ||||
| void safe_unload_with_debug(void) { | ||||
|     debug_log("Starting safe unload with debug logging"); | ||||
|      | ||||
|     /* Log important function addresses for debugging */ | ||||
|     char buf[256]; | ||||
|     snprintf(buf, sizeof(buf), "Function addresses - self_unload: %p, unload: %p, hooks_restore: %p",  | ||||
|              (void*)self_unload, (void*)unload, (void*)hooks_restore); | ||||
|     debug_log(buf); | ||||
|      | ||||
|     /* Reset all settings to safe values */ | ||||
|     debug_log("Resetting all settings to default values"); | ||||
|     i_engine->pfnClientCmd("echo \"Step 0: Resetting all settings...\""); | ||||
|     settings_reset(); | ||||
|      | ||||
|     /* Unhook everything first in an orderly manner */ | ||||
|     i_engine->pfnClientCmd("echo \"Step 1: Unhooking functions...\""); | ||||
|     debug_log("Unhooking all functions"); | ||||
|      | ||||
|     /* First OpenGL hooks since they're most likely to crash if not restored */ | ||||
|     debug_log("Restoring OpenGL hooks"); | ||||
|     // Don't manually unhook GL functions, it's already handled in hooks_restore | ||||
|      | ||||
|     /* Then restore other hooks */ | ||||
|     debug_log("Restoring VMT hooks"); | ||||
|     hooks_restore(); | ||||
|      | ||||
|     /* Restore globals */ | ||||
|     debug_log("Restoring globals"); | ||||
|     globals_restore(); | ||||
|      | ||||
|     /* Remove our command */ | ||||
|     debug_log("Removing custom commands"); | ||||
|     i_engine->pfnClientCmd("echo \"Step 2: Removing custom commands...\""); | ||||
|      | ||||
|     /* Wait a bit to ensure all hooks are properly removed */ | ||||
|     debug_log("Waiting for hooks to settle"); | ||||
|     i_engine->pfnClientCmd("echo \"Step 3: Waiting for hooks to settle...\""); | ||||
|     usleep(250000); /* 250ms */ | ||||
|     usleep(250000); | ||||
|      | ||||
|     /* Now try to unload the library */ | ||||
|     debug_log("Beginning library unload sequence"); | ||||
|     i_engine->pfnClientCmd("echo \"Step 4: Unloading library...\""); | ||||
|      | ||||
|     /* | ||||
|      * 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); | ||||
|      | ||||
|     snprintf(buf, sizeof(buf), "dlopen result: %p", self); | ||||
| @@ -108,51 +92,42 @@ void safe_unload_with_debug(void) { | ||||
|     i_engine->pfnClientCmd("echo \"Unload procedure completed\""); | ||||
| } | ||||
|  | ||||
| /* Handler for dz_uninject command */ | ||||
| void UNINJECT_CommandHandler(void) { | ||||
|     i_engine->pfnClientCmd("echo \"Uninjecting goldsource-cheat with debug logging...\""); | ||||
|      | ||||
|     /* Use the safe unload with debug instead of scheduling uninjection */ | ||||
|     safe_unload_with_debug(); | ||||
| } | ||||
|  | ||||
| /* Handler for dz_menu command */ | ||||
| void MENU_CommandHandler(void) { | ||||
|     extern bool g_menu_open; | ||||
|     g_menu_open = !g_menu_open; | ||||
|     i_engine->Con_Printf("Menu toggled to %s\n", g_menu_open ? "open" : "closed"); | ||||
| } | ||||
|  | ||||
| __attribute__((constructor)) /* Entry point when injected */ | ||||
| __attribute__((constructor)) | ||||
| void load(void) { | ||||
|     printf("goldsource-cheat injected!\n"); | ||||
|  | ||||
|     /* Initialize globals/interfaces */ | ||||
|     if (!globals_init()) { | ||||
|         fprintf(stderr, "goldsource-cheat: load: error loading globals, aborting\n"); | ||||
|         self_unload(); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     /* Initialize settings with defaults */ | ||||
|     settings_init(); | ||||
|  | ||||
|     /* Hook functions */ | ||||
|     if (!hooks_init()) { | ||||
|         fprintf(stderr, "goldsource-cheat: load: error hooking functions, aborting\n"); | ||||
|         self_unload(); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     /* Register custom commands */ | ||||
|     i_engine->pfnAddCommand("dz_uninject", UNINJECT_CommandHandler); | ||||
|     i_engine->pfnAddCommand("dz_menu", MENU_CommandHandler); | ||||
|      | ||||
|     // Bind INSERT key to dz_menu command (for menu toggle) | ||||
|     i_engine->pfnClientCmd("bind INS dz_menu"); | ||||
|     i_engine->Con_Printf("Bound INSERT key to menu toggle\n"); | ||||
|  | ||||
|     /* Play sound to indicate successful injection */ | ||||
|     if (IsCS16()) { | ||||
|         i_engine->pfnClientCmd("play weapons/knife_deploy1.wav"); | ||||
|         i_engine->pfnClientCmd("speak \"Cheat successfully loaded\""); | ||||
| @@ -179,7 +154,6 @@ void load(void) { | ||||
|     i_engine->pfnClientCmd("echo \"Deadzone rulez!\""); | ||||
|     i_engine->pfnClientCmd("echo \"https://git.deadzone.lol/Wizzard/goldsrc-cheat\""); | ||||
|  | ||||
|     /* Get game version after injecting */ | ||||
|     GameType game = get_current_game(); | ||||
|     switch(game) { | ||||
|         case GAME_HALFLIFE: | ||||
| @@ -208,31 +182,24 @@ void load(void) { | ||||
|     loaded = true; | ||||
| } | ||||
|  | ||||
| __attribute__((destructor)) /* Entry point when unloaded */ | ||||
| __attribute__((destructor)) | ||||
| void unload(void) { | ||||
|     if (loaded) { | ||||
|         /* Reset all settings to default values */ | ||||
|         settings_reset(); | ||||
|          | ||||
|         globals_restore(); | ||||
|         hooks_restore(); | ||||
|  | ||||
|         // Don't manually unhook GL functions, it's already handled in hooks_restore | ||||
|     } | ||||
|  | ||||
|     printf("goldsource-cheat unloaded.\n\n"); | ||||
| } | ||||
|  | ||||
| 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); | ||||
|      | ||||
|     if (self) { | ||||
|         dlclose(self); | ||||
|         dlclose(self); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user