This is the AMP version of this page.
If you want to load the real page instead, click this text.

Solved Passing Value Types (enum and struct) as parameters

Status
Not open for further replies.

DigitalKnight

Awesome Active Platinian
Hello Guys, Hope everyone is fine.
For some games, some of the functions require a enum or struct parameter in order to return an object. If the function would simply return a basic value eg int or float, it would be fine. But if it returns object, we do need a proper struct or enum passed as in or the function won't work

Example:
Suppose here is the function:

Code:
public BigInteger get_currency(CurrencyType _type) {} //0x___

And here is the CurrencyType enum

Code:
public enum CurrencyType
{
public int value_;
public const int Gems = 0;
public const int Coins = 1;
public const int Tickets = 2;
public const int Spins = 4;
}

Now the basic idea would be to call the function in the hook, get the instance of the return object, edit it's fields and return it back.
The problem is, i cannot pass in the enum as is because i have no idea how to get it's passed value

So far i have tried int, int*, void*, made my own similiar enum and did CurrencyType*. But in all cases, when i do try to read the value, it either crashes or returns a bogus value such as -1123234213. Same goes with struct, i have no idea how to pass them as is. Thanks for the help!

Edit: If the enum or structs are not passed in as is, the function won't return the object. And the game would always display 0 gems, coins etc
 
This is more of a coding question rather than modding one.
You need to learn how C# and C++ work in order to be really able to use hooks. (Tutorials may be helpful, but more often than not they are just used for copy-pasting; pretty much missing the point on why they work).

Once you understand how these kind of arguments (in this case CurrencyType enum) are used/managed in C#/il2cpp library, and you are also familiar with C++'s, you will be able to craft hooks that properly interact with the game.

You can also debug and use disassemblers to help you.
 

I do know how they work normally, as for il2cpp, i have been trying to figure out how they are managed but i cannot find any resources. Normally they would be passed on as values, (and enums are strongly typed, meaning they cannot be casted into ints), but for some reason, il2cpp expects a pointer? I have no idea where to look man
 

What matters is how the data is recieved by your C++ hook library, not if they are strongly typed in the C# one.


This sentence still holds:
You can also debug and use disassemblers to help you.
 
What matters is how the data is recieved by your C++ hook library, not if they are strongly typed in the C# one.


This sentence still holds:


Catching up, i managed to solve the problem. So i went on to disassemble and debug. The values i would receive on debugger were -112324 etc and i knew this was an address and not an enum value. The thing that made me the most confused was that the dump showed that the function did only access a single parameter, the enum value.

Well so i fiddled a bit more, and then while i was viewing the pseudocode, i found this

Code:
System_Numerics_BigInteger_o *__fastcall Player_Wallet__get_currency(System_Numerics_BigInteger_o *retstr, Player_Wallet_o *this, int32_t type, const MethodInfo *method)

That's when it occured to me, the function actually accepts another pointer before the instance. Neither the debugger nor the normal disassembly view showed this.

So i made my hook into this

Code:
void *get_currency(void* bigint, void* instance, int type){
    if(instance != NULL && bigint != NULL){
        return old_get_currency(bigint, instance, type);
    }
}

And viola! Everything run fines now. All this while i thought i was crazy and that unity did magical stuff with enums lmao.
Hope this helps someone out and thank you!
 
Last edited:
And viola! Everything run fines now. All this while i thought i was crazy and that unity did magical stuff with enums lmao.
Hope this helps someone out and thank you!


Seeing the solution and checking back the original hypothesis regarding the problem truly shows how useful the tools are. I'm glad you took my word and were able to experience first hand this kind of situation.

Congratz
 
For me, I am Using This Code To Paas Custom Params,



Dump:



Code :
C++:
enum PlayerState {
    sitting,
    boarding,
    grinding,
    jumping,
    flipping,
    freefalling,
    falling,
    wingsuit,
    resetting
};
void (*_ChangePos)(void *_this, int32_t PlayerPos);
void ChangePos(void *_this, int32_t PlayerPos) {
    if (_this != NULL) {
        if (NM.playerState) {
            PlayerPos = NM.NewState;
        }
    }
    return _ChangePos(_this, PlayerPos);
}
HOOK_LIB("libil2cpp.so", "0x451390", ChangePos, _ChangePos); //17
Its Working for Me, i hope You can found this Example Useful.
 
Status
Not open for further replies.