Tutorial How to modify Unity's Il2cpp String method's

Numark

Awesome Active Platinian
Original poster
May 23, 2017
116
929
193
I heard people wanted to modify strings such as Player Names, etc. It's pretty easy.

First of all, create a header and call it Strings which will look like "Strings.h".

Make sure to include "Strings.h" in your main.cpp files so to make sure the files inside strings are working.

Paste this code in your strings.h

C++:
#include "Utils.h" (Don't really need this if you're using LGL's or made your own.)
#include "Substrate/SubstrateHook.h"

typedef struct _monoString {
    void *klass;
    void *monitor;
    int length;
    char chars[1];

    int getLength() {
        return length;
    }

    char *getChars() {
        return chars;
    }
} monoString;

monoString *CreateMonoString(const char *str) {
    monoString *(*String_CreateString)(void *instance, const char *str) = (monoString *(*)(void *, const char *))getRealOffset(OFFSET;

    return String_CreateString(NULL, str);
}
So where do we get the offsets?

Well, basically you've dumped the game using il2cpp dumper or whatever tool you used right?
After the game is dumped, we now get "dummy dll's". Drag all the dummy dll's inside "dnspy".

If you want to use notepad++ or any other tools without dnspy, then use "dump.cs".

But I'll be using dnspy for this tutorial.

Now once you have opened them, search for a method called "CreateString".

There will be multiples CreateString functions.
How do we know which is which and which we'll use?

Easy. I'm just gonna say it.

We'll use the one called
C++:
public void CreateString (Sbyte)
We will only use CreateString with the only parameter of SBYTE only!

Now just use that offset and paste it in your strings.h

Now how do we use strings? How do we use it for player names, etc? Easy.

We are gonna make our own hooks. If you have never read my tutorial called "Basic Hooking Tutorial". I suggest you doing it since it's the only way, but there's many ways as well, but just focus on that.


Let's create our hooks!
This one is with toggles.

C++:
monoString* (*old_playername)(void *instance);
monoString* playername(void *instance) {
    if(instance!=NULL) {
        if (Toggle) { //not needed if you want to have it automatically on without a toggle.
            return CreateMonoString("SliceCast is Daddy!");
        }
    }
    return old_playername(instance); //don't really need it if you have a toggle.
}
This one is without toggles (only if you want it on automatically!)

C++:
monoString* (*old_playername)(void *instance);
monoString* playername(void *instance) {
    if(instance!=NULL) {
            return CreateMonoString("SliceCast is Daddy!");
    }
}
Now we call the hooks.

C++:
MSHookFunction((void*)getRealOffset(OFFSETS), playername, (void**)&old_playername);
Now that's all.

You can set methods as well, but I won't spoon-feed everyone one of you.

Credits ~ Octowolve and Slice Cast
 
Last edited:

Sevol

Retired Staff
Retired but loved <3
Jun 8, 2019
219
5,936
193
Russia
Thanks, ask me any questions related to this thread only. I'll be here if you need anything.
I've known for a long time how to replace a string. just good lessons should be praised.