#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #define DLSYM_GOT_260B 0x0804adb0 #define DLOPEN_GOT_260B 0x0804b830 //from sdk #define RF_DEPTHHACK 0x000008 // for view weapon Z crunching #define RF_NOSHADOW 0x000010 // don't add stencil shadows #define CG_R_ADDREFENTITYTOSCENE 60 typedef int syscall_t(int command, ...); typedef void dllEntry_t(syscall_t *); syscall_t *orig_syscall = NULL; dllEntry_t *orig_dllEntry = NULL; void *cgameLibHandle = NULL; // do t3h depthhack int our_syscall(int command, ...) { int arg[10]; va_list args; va_start(args, command); int count = 0; for (; count < 10; count++) arg[count] = va_arg(args, int); va_end(args); if( command == CG_R_ADDREFENTITYTOSCENE ){ // arg[0] passes pointer to a refEntity_t, just change renderfx at right offset (which is 4) //refEnt->renderfx |= RF_DEPTHHACK | RF_NOSHADOW; *(int *)(arg[0]+4) |= RF_DEPTHHACK | RF_NOSHADOW; } return orig_syscall(command, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]); } void cg_dllEntry(syscall_t *syscallptr) { orig_syscall = syscallptr; orig_dllEntry(our_syscall); } // detour dllEntry so we can intercept cgame's syscall void *our_dlsym(void *handle, const char *symbol) { void *result = dlsym(handle, symbol); // Hook dllEntry if (!strcmp(symbol, "dllEntry") && handle == cgameLibHandle ) { orig_dllEntry = result; return cg_dllEntry; } return result; } // get the libhandle to cgame void *our_dlopen(const char *filename, int flag) { void *result = dlopen(filename, flag); if (result && filename) if (strstr(filename, "cgame.mp.i386.so")) cgameLibHandle = result; } //this is the dll initat0r void __attribute__ ((constructor)) hookInit() { char exeFilename[PATH_MAX]; memset(exeFilename, 0, sizeof(exeFilename)); if (readlink("/proc/self/exe", exeFilename, sizeof(exeFilename)) <= 0) { printf("Can't find et.x86\n"); exit(1); } // Find et.x86 if (!strcmp(basename(exeFilename), "et.x86")) { // hook dlsym() and dlopen() through GOT *(void **)DLSYM_GOT_260B = our_dlsym; *(void **)DLOPEN_GOT_260B = our_dlopen; } }