[C++] Changing gravity

Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    much coder t0p lel Team Zebra is offline
    MemberRank
    Mar 2009 Join Date
    234Posts

    [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
    Attached Files Attached Files


  2. #2
    Account Upgraded | Title Enabled! shortymant is offline
    MemberRank
    Nov 2008 Join Date
    606Posts

    Re: [C++] Changing gravity

    Very Nice ;)
    C++ FTW!
    p.s First XD

  3. #3
    WowIwasSuperCringeB4 XZeenon is offline
    MemberRank
    Jun 2008 Join Date
    CanadaLocation
    1,405Posts

    Re: [C++] Changing gravity

    Great job. This is quite pro. now lets make it auto inject! ;p

  4. #4
    much coder t0p lel Team Zebra is offline
    MemberRank
    Mar 2009 Join Date
    234Posts

    Re: [C++] Changing gravity

    Quote Originally Posted by XZeenon View Post
    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

  5. #5

    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.

  6. #6
    Account Upgraded | Title Enabled! shortymant is offline
    MemberRank
    Nov 2008 Join Date
    606Posts

    Re: [C++] Changing gravity

    Visual C++ 2005 Express Edition is a good one :D
    But also Dev-Cpp for quickness.

  7. #7
    much coder t0p lel Team Zebra is offline
    MemberRank
    Mar 2009 Join Date
    234Posts

    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.

  8. #8
    Extreme Coder - Delphi bounty-hunter is offline
    MemberRank
    Sep 2007 Join Date
    GunZone MansionLocation
    1,725Posts

    Re: [C++] Changing gravity

    Wait, what does this dll do?
    Does it lower gravity? or Make gravity force strongeR?

  9. #9
    DRGunZ 2 Creator wesman2232 is offline
    MemberRank
    Jan 2007 Join Date
    Erie, PALocation
    4,872Posts

    Re: [C++] Changing gravity

    very nice, so all we have to do right now is inject in-game?

  10. #10
    Sultan of Yolo Demantor is offline
    MemberRank
    May 2008 Join Date
    GermanyLocation
    1,266Posts

    Re: [C++] Changing gravity

    Very nice, ty^^

  11. #11

    Re: [C++] Changing gravity

    Quote Originally Posted by Team Zebra View Post
    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.

  12. #12
    Account Upgraded | Title Enabled! Mr.Lucifer is offline
    MemberRank
    Apr 2007 Join Date
    797Posts

    Re: [C++] Changing gravity

    Very nice.

    Linear88, have you added "#include "Stdafx.h" above the other includes?

    /*
    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?
    Last edited by Mr.Lucifer; 19-04-09 at 04:20 PM.

  13. #13
    much coder t0p lel Team Zebra is offline
    MemberRank
    Mar 2009 Join Date
    234Posts

    Re: [C++] Changing gravity

    I haven't tested it out, but I'm gonna assume the original value is 1.0.

  14. #14
    Account Upgraded | Title Enabled! 00niels00 is offline
    MemberRank
    Sep 2008 Join Date
    The NetherlandsLocation
    1,041Posts

    Re: [C++] Changing gravity

    I have tried nothing changed :S

  15. #15
    Account Upgraded | Title Enabled! Mr.Lucifer is offline
    MemberRank
    Apr 2007 Join Date
    797Posts

    Re: [C++] Changing gravity

    The original is 1.0, but wallrun still works badly.



Page 1 of 2 12 LastLast

Advertisement