Tutorial How to hook arrays in Unity's Il2cpp

Numark

Awesome Active Platinian
Original poster
May 23, 2017
116
930
193
Okay, so apparently I've been asked many times on how to modify arrays, not gonna get deep into this, but here we go.


First of all, you need a monoArray struct, which I will provide.
C++:
template <typename T>
struct monoArray
{
    void* klass;
    void* monitor;
    void* bounds;
    int   max_length;
    void* vector [1];
    int getLength()
    {
        return max_length;
    }
    T getPointer()
    {
        return (T)vector;
    }
};

Let's say you wanted to modify a Player List in a photon game, like getting other players?
1618015202344.png


When you use this Array, you need to make a hook for this.
C++:
monoArray<void *> *(*PhotonNetwork_get_OtherPlayers)() = (monoArray<void *> *(*)())il2cppAddress + 0x84EB8C;
To access players as an example, you can use this code to get a vector to the players.

C++:
auto photonplayers = PhotonNetwork_getOtherPlayers();

for (int i = 0; i < photonplayers->getLength(); ++i)
{
    auto photonplayer = photonplayers->getPointer()[i];
}
If whatever type the method is, change it if it's a void, int, bool, float, whatever it is.

Credits: Toshiro and Slice Cast
 

asdf101

Platinian
Jun 8, 2021
15
2
3
24
-
Can you help me with List<>. I dont know how to hook that
Code:
// RVA: 0x140D26C Offset: 0x140D26C VA: 0x140D26C
    public static List<RemotePlayer> GetRemotePlayers(Predicate<RemotePlayer> predicate) { }
 

hienngocloveyou

Solid & Active Platinian
May 16, 2021
62
7
8
38
VN
Can you help me with List<>. I dont know how to hook that
Code:
// RVA: 0x140D26C Offset: 0x140D26C VA: 0x140D26C
    public static List<RemotePlayer> GetRemotePlayers(Predicate<RemotePlayer> predicate) { }
Use this link


You can find the struct monoList in that page.

Regards,
 

asdf101

Platinian
Jun 8, 2021
15
2
3
24
-
I mean how can you get the predicate<playerbase> because you need it in order for the hook to work correctly
 

asdf101

Platinian
Jun 8, 2021
15
2
3
24
-
Another question: I want to read c# list of strings
Code:
// RVA: 0x140C528 Offset: 0x140C528 VA: 0x140C528
    public static List<string> GetAllPlayersIdShuffled() { }
Is this how I should do it?
Code:
monoList<monoString> *(*GetPlayerIds)() = (monoList<monoString> *(*)()) getAbsoluteAddress(targetLibName, 0x140C528);
auto getplayerids = GetPlayerIds();
I dont know how to read it. Help please
 
  • Like
Reactions: hienngocloveyou

hienngocloveyou

Solid & Active Platinian
May 16, 2021
62
7
8
38
VN
Another question: I want to read c# list of strings
Code:
// RVA: 0x140C528 Offset: 0x140C528 VA: 0x140C528
    public static List<string> GetAllPlayersIdShuffled() { }
Is this how I should do it?
Code:
monoList<monoString> *(*GetPlayerIds)() = (monoList<monoString> *(*)()) getAbsoluteAddress(targetLibName, 0x140C528);
auto getplayerids = GetPlayerIds();
I dont know how to read it. Help please
Please read document I posted above

1625910479475.png
 

asdf101

Platinian
Jun 8, 2021
15
2
3
24
-
You must make that object and reference to it
In c# predicate class only returns boolean, true or false. Since it only returns that can you do this?

C++:
monoList<void**> *(*GetPlayers)(bool) = (monoList<void**> *(*)(bool)) getAbsoluteAddress(targetLibName, offset);
 

Baba44

Platinian
Jan 9, 2024
6
0
1
19
public void InitiatePurchase(Product product, string developerPayload) { }

In lgl menu how to hack this free store using monostring??