Cool way to define class members

Results 1 to 6 of 6
  1. #1
    Mako is insane. ThePhailure772 is offline
    MemberRank
    Sep 2007 Join Date
    1,115Posts

    Cool way to define class members

    Code:
    #define GET_CLASS_MEMBER(func, type, offset) type ##func () { \
    													return (type)((unsigned char*)this + offset); \
    											}
    #define GET_CLASS_MEMBER_NOPTR(func, type, offset) type & ##func () { \
    														return *(type*)((unsigned char*)this + offset); \
    													}
    struct ZGameClient
    {
    	GET_CLASS_MEMBER(GetPlayerUID, MUID*, 0x198);
    	GET_CLASS_MEMBER(GetStageUID, MUID*, 0x23C);
    	GET_CLASS_MEMBER(GetChannelUID, MUID*, 0x1D0);
    };
    
    struct ZGame
    {
    	GET_CLASS_MEMBER(GetCharacterManager, ZCharacterManager*, 0x68);
    	GET_CLASS_MEMBER_NOPTR(GetCharacterManagerNoPtr, ZCharacterManager, 0x68);
    	GET_CLASS_MEMBER(GetMyCharacter, ZCharacter*, 0x58);
    };
    
    struct ZCharacterManager
    {
    #define CALL_FUNC_1(func, type, arg, offset) type ##func (arg a) { \
    													return ((type (__thiscall*)(ZCharacterManager*, arg))offset) (this, a); \
    											 }
    
    	CALL_FUNC_1(Find, ZCharacter*, MUID*, 0);
    };


  2. #2
    GunZ Developer dacharles is offline
    MemberRank
    Oct 2006 Join Date
    476Posts

    Re: Cool way to define class members

    when you will need a function with 2 arguments or 3 or 4, it won't be a cool way at all...

  3. #3
    Retired. Don't PM. SecretsOThePast is offline
    DeveloperRank
    Jan 2009 Join Date
    643Posts

    Re: Cool way to define class members

    Quote Originally Posted by dacharles View Post
    when you will need a function with 2 arguments or 3 or 4, it won't be a cool way at all...
    Why's that?

    The way he is getting class members works fine, if it's a static pointer to data.

    A function is a whole other thing entirely; This is simply an example of accessing data that looks clean on the eyes.

    Would you prefer using a function for each thing

    Code:
    DWORD ZGetGame( )
    {
        DWORD dwEax = *(DWORD*)0x000000;
        dwEax ? dwEax = *(DWORD*)dwEax : dwEax = 0;
        dwEax ? dwEax = *(DWORD*)( dwEax + 0x000 ) : dwEax = 0;
    
        return dwEax;
    }
    or doing it his way, which organizes it a bit better and helps when mapping out things in Olly/IDA?

    Functions are irrelevant in this case, is the point I am trying to make.

  4. #4
    GunZ Developer dacharles is offline
    MemberRank
    Oct 2006 Join Date
    476Posts

    Re: Cool way to define class members

    I did not understand what you said ._.

    For a function with 2 arguments you will need to make this:

    Code:
    #define CALL_FUNC_2(func, type, arg, arg2, offset) type ##func (arg a, arg2 b) { \
        return ((type (__thiscall*)(ZCharacterManager*, arg))offset) (this, a, b); \
    }
    
        CALL_FUNC_2(Func2Args, RetType*, Type1*, Type2*, 0);
    };
    Now you get the idea? How would it be for a function with 3 arguments?

    I already did something like this, added some macros for the CDetour customized library and I had to make multiple macros for functions with 3 4 5 arguments. Sucks a little bit...
    Last edited by dacharles; 15-08-11 at 03:49 PM.

  5. #5
    Wait wut PenguinGuy is offline
    MemberRank
    Apr 2010 Join Date
    United StatesLocation
    765Posts

    Re: Cool way to define class members

    ... Dacharles, you don't need multiple prep. definitions for functions that require different arguments. Take a peek into Lance's CDetour class again, and look into (if I remember right, been a while since I actually looked into his sources) the Org function. It's quite easy to start, a bit more difficult to expand it into just a regular function caller. Not too difficult though lol.

    I usually stay away from #define, but I can make an exception for this lol. Nice, Phail. ^_~
    Posted via Mobile Device

  6. #6
    GunZ Developer dacharles is offline
    MemberRank
    Oct 2006 Join Date
    476Posts

    Re: Cool way to define class members

    You are talking about to use the definitions and the .Org function? Well Org is like a re-call function right? but I don't really understand how that will help me to use only 1 definition (and not multiple to handle multiple arguments).

    I mean ITT Phail is talking about to use definitions to reduce some code but it will not be nice for the reason I just posted...



Advertisement