Hey guys. I decided to take a little break from working on the emulator for now, wanted to learn some new stuff and chill while I'm going through a lot of testing at school before I do a lot of work on it again.
So this morning I decided to learn how to write injectable DLLs. Hooking functions and calling external functions was a pretty new concept, as well as writing DLLs in general. But some googling and a few tutorials helped me right along.
I noticed a lot of people here were curious about editing the gravity and had trouble with it, so to give back, here's a DLL I wrote a bit ago that hooks the GetGravityConst() function and returns a custom value. It doesn't parse the room name yet, just returns a static value, though I plan on doing the room name thing soon. But hey, it works. Here's the code/download, enjoy.
addresses.h
main.cppCode:/* Author - Team Zebra addresses.h - addresses of Gunz functions that we wanna call. */ #ifndef _ADDRESSES_H_ #define _ADDRESSES_H_ #define ADDR_GETGRAVITYCONST 0x0047DB30 #endif
There's also detours.h and detours.lib, but I didn't write those, so I won't be posting the code, though they're in the download. Keep in mind that you need to link detours.lib to your project for it to compile. Enjoy.Code:/* Author - Team Zebra main.cpp - main code for our DLL. */ #define WIN32_LEAN_AND_MEAN #define WIN32_EXTRA_LEAN #include <windows.h> #include "detours.h" #include "addresses.h" #pragma comment(lib, "detours.lib") // GetGravityConst prototype float (__stdcall* GetGravityConst)(); // Our detoured GetGravityConst(), just returns our value. float GetGravityConstDetour(void) { return 0.1f; } // Entrypoint for the DLL. INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved) { switch(Reason) { case DLL_PROCESS_ATTACH: // set our detour GetGravityConst = (float (__stdcall*)())DetourFunction( (PBYTE)ADDR_GETGRAVITYCONST, (PBYTE)GetGravityConstDetour); DisableThreadLibraryCalls(hDLL); break; case DLL_THREAD_ATTACH: case DLL_PROCESS_DETACH: DetourRemove((PBYTE)ADDR_GETGRAVITYCONST, (PBYTE)GetGravityConstDetour); case DLL_THREAD_DETACH: break; } return TRUE; }
-Team Zebra



Reply With Quote![[C++] Changing gravity](http://ragezone.com/hyper728.png)


