/** * @file DXAPI.cpp * @brief The DXAPI is an API that allows you to manipulate various game objects * in Tribes 2 from raw C++ code. It dynamically resolves the addresses of member * variables as you can't really trust the compiler to produce binary compatible classes, * especially with all the inheritance involved in the original Tribes 2 codebase. * * This code wouldn't be possible without Linker's original gift on the-construct.net forums, * whose files are appropriately labelled in this codebase. These files have been edited where * appropriate in order to make that code play better with the DXAPI. * * @copyright (c) 2014 Robert MacGregor */ #include #include #include #include namespace DX { const char * StringTableInsert(const char * str,bool casesensitive) { const char* retval; unsigned int * StringTablePtr=(unsigned int *)0x9e618c; unsigned int StrTableAddr=*StringTablePtr; __asm { mov ecx,StrTableAddr push casesensitive push str mov eax,0x441A00 call eax mov retval,eax } return retval; } bool memPatch(unsigned int addr, unsigned char * data, unsigned int size){ DWORD oldprotect=0; DWORD oldnewprotect=0; VirtualProtect((void *)addr,size,PAGE_EXECUTE_READWRITE,&oldprotect); memcpy((void *)addr,(void*) data,size); VirtualProtect((void *)addr,size,oldprotect,&oldnewprotect); return true; } float memToFloat(unsigned int addr){ DWORD oldprotect=0; DWORD oldnewprotect=0; VirtualProtect((void *)addr,4,PAGE_EXECUTE_READWRITE,&oldprotect); float * floatout=(float *)addr; float retfloat=0.0; retfloat = *floatout; VirtualProtect((void *)addr,4,oldprotect,&oldnewprotect); return true; } unsigned int memToUInt(unsigned int addr){ DWORD oldprotect=0; DWORD oldnewprotect=0; VirtualProtect((void *)addr,4,PAGE_EXECUTE_READWRITE,&oldprotect); unsigned int * intout=(unsigned int *)addr; int retint=0; retint = *intout; VirtualProtect((void *)addr,4,oldprotect,&oldnewprotect); return true; } bool memToHex(unsigned int addr, char * dst, int size, bool spaces=false){ DWORD oldprotect=0; DWORD oldnewprotect=0; char hexdigits[20]=""; char outstr[256]; VirtualProtect((void *)addr,size,PAGE_EXECUTE_READWRITE,&oldprotect); for (int i=0; i(address); unsigned char* sourceData = reinterpret_cast(payload); for (unsigned int iteration = 0; iteration < payloadSize; ++iteration) destination[iteration] = sourceData[iteration]; return true; } bool memPatch(unsigned int address, void* payload, unsigned int payloadSize) { return memPatch(reinterpret_cast(address), payload, payloadSize); } }