-
1 Attachment(s)
[C++] Changing gravity
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
Code:
/*
Author - Team Zebra
addresses.h - addresses of Gunz functions that we wanna call.
*/
#ifndef _ADDRESSES_H_
#define _ADDRESSES_H_
#define ADDR_GETGRAVITYCONST 0x0047DB30
#endif
main.cpp
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;
}
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.
-Team Zebra
-
Re: [C++] Changing gravity
Very Nice ;)
C++ FTW!
p.s First XD
-
Re: [C++] Changing gravity
Great job. This is quite pro. now lets make it auto inject! ;p
-
Re: [C++] Changing gravity
Quote:
Originally Posted by
XZeenon
Great job. This is quite pro. now lets make it auto inject! ;p
No point making it auto-inject how it is right now, it gives everyone the same gravity (0.1). Once I get it parsing the room names, then it'll be useful.
Now that I know how to write DLLs and hook functions on a basic level though, there are a few things I want to try to write. Nothing malicious, just fun, game enhancers :P
-
Re: [C++] Changing gravity
Dumb question here, but which program should I use to compile it?
Dev-Cpp or Visual C++ 2005 Express?
I'm planning to test this.
-
Re: [C++] Changing gravity
Visual C++ 2005 Express Edition is a good one :D
But also Dev-Cpp for quickness.
-
Re: [C++] Changing gravity
I dunno, I use Visual Studio 2005, never tried anything else. Keep in mind you also need the Windows SDK installed as well to include windows.h.
-
Re: [C++] Changing gravity
Wait, what does this dll do?
Does it lower gravity? or Make gravity force strongeR?
-
Re: [C++] Changing gravity
very nice, so all we have to do right now is inject in-game?
-
Re: [C++] Changing gravity
-
Re: [C++] Changing gravity
Quote:
Originally Posted by
Team Zebra
I dunno, I use Visual Studio 2005, never tried anything else. Keep in mind you also need the Windows SDK installed as well to include windows.h.
Done that, but it's giving me problems about finding Stdafx.h.
-
Re: [C++] Changing gravity
Very nice.
Linear88, have you added "#include "Stdafx.h" above the other includes?
Quote:
/*
Author - Team Zebra
main.cpp - main code for our DLL.
*/
#include "Stdafx.h"
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <stdio.h>
#include <windows.h>
#include "detours.h"
#include "addresses.h"
#pragma comment(lib, "detours.lib")
Edit: Quick question, how do you avoid the crappy wallrun? What is the normal value?
-
Re: [C++] Changing gravity
I haven't tested it out, but I'm gonna assume the original value is 1.0.
-
Re: [C++] Changing gravity
I have tried nothing changed :S
-
Re: [C++] Changing gravity
The original is 1.0, but wallrun still works badly.
-
Re: [C++] Changing gravity
GREAT JOB Zebra!
Awsome one.
10/10.
-
Re: [C++] Changing gravity
Lol, posted that hook a few days ago.
Anyway, good luck on it.
-
Re: [C++] Changing gravity
ll i lik eit
---------- Post added at 07:43 PM ---------- Previous post was at 07:40 PM ----------
dddsssssssssssssss
-
Re: [C++] Changing gravity
Hello people, Team Zebra would like to ask in Visual Basic, I conpilia with him, why the dev c + +, I could not, and how I Faso to hokke (nerd) in theduel.exe? can you explain thanks.
Tranks
-
Re: [C++] Changing gravity
-
Re: [C++] Changing gravity
-
Re: [C++] Changing gravity
-
Re: [C++] Changing gravity
:thumbup1: nice job thx for share
-
Re: [C++] Changing gravity
-
Re: [C++] Changing gravity
Quote:
Originally Posted by
XZeenon
OMG, quit grave digging.
Like he understands English. :sleep:
*hides for infraction*
-
Re: [C++] Changing gravity
Grate Work :P 9/10 But i am sad Coz i have maked 1 Before U post this This will not help me But thanx Any way
-
Re: [C++] Changing gravity
Quote:
Originally Posted by
PrØ
Grate Work :P 9/10 But i am sad Coz i have maked 1 Before U post this This will not help me But thanx Any way
Stop bullshit-ing and learn to appreciate. We all know you haven't coded your own gravity DLL.
-
Re: [C++] Changing gravity
Quote:
Originally Posted by
PrØ
Grate Work :P 9/10 But i am sad Coz i have maked 1 Before U post this This will not help me But thanx Any way
No one gives a fuck.
-
Re: [C++] Changing gravity
Nice No Errors Tried it.It Works Perfect
-
Re: [C++] Changing gravity
helpful release, many were waiting for something like that, eh well there is many kinds of that but part of them kinda bullshiting.
Best Regards, Wizard