How to create simple mod menu in Unity games

Sbenny.com is trusted by 1,313,147 happy users since 2014.
Register

AndnixSH

Savage Lv6️⃣
SB Mod Squad ⭐
Member for 8 years

I have gotten a lot of request for a tutorial how to make MOD Menu but haven't got time and almost forgot it. I had to pause all my other protects and start working with this tutorial straight away.

With MOD Menu, it allows the player to choose what hacks to use. MOD Menu can be useful in multiplayer games that player can enable and disable hack quickly to avoid being reported by legit players

So let's get started.

Requirements:
- Basic Unity modding expernence
- Familar with C# and dnSpy
- dnSpy installed on your computer
- Unity editor installed on your computer
- Visual Studio 2017 installed on your computer (Optional.)

Installing Unity editor:
First, create an account or sign in with Google or Facebook at Unity

Go to Unity - Store and select "Try personal". It is completely free. Download and install it. If you like to have Visaul Studio 2017 installed, make sure to select it in installer. If not installed, you will use MonoDevelop.

1517086146771.png


Setting up Unity editor:
Launch Unity, login with your account and complete your survey. After that you can create a new project. Name it you want and keep 3D selected. Click "Create project"

The dashboard will launch.

Create a new C# script:

1517086157910.png


Click on Assets -> Create -> C# script or right click on Project section Create -> C# script

Drag your script and drop on top of Main Camera below Untitled to make sure your script is shown in game scene.

Designing and testing GUI:
Tip:
While you programming, you can click play and edit code while the game scene is running. The editor will freeze a while when you open it.

Remove Start() and Update() methods and add a OnGUI() method like this:

C#:
public class ModMenuScript : MonoBehaviour {

    void OnGUI() {

    }

}
Add some fields above OnGUI() so you can use it later

Code:
public bool hack1;
public string string1;
public bool ShowHide = false;
Create a button "SHOW/HIDE"

C#:
GUI.Button(new Rect(20, 20, 160, 20), "SHOW/HIDE"
The numbers (20, 20, 160f, 20f) means (x, y, width, height)

Add if-statement on GUI button with operator so you can hide/show menu by clicking on button

C#:
if (GUI.Button(new Rect(20, 20, 160, 20), "SHOW/HIDE"))
{
    ShowHide = !ShowHide;
}
Add new if statement code method to design menu

C#:
if (ShowHide)
{

}
Add GUI box with title inside if statement code

C#:
GUI.Box(new Rect(20, 50, 170, 150), "iAndroHacker's mod menu");
And add the button with operator bwloe GUI box

C#:
if (GUI.Button(new Rect(25, 80, 160f, 30f), string1))
{
    hack1 = !hack1;
}
Add new if-else-statement code that changes the text

C#:
if (hack1)
{
    string1 = "Unlimited health <color=green>ON</color>";
    hack1 = false;
}
else
{
    string1 = "Unlimited health <color=red>OFF</color>";
    hack1 = true;
}
Congratulations, you have created a very simple MOD Menu. You can now customize and add more button easly by yourself and view it in game scene J

Script template: ModMenuScript.cs · master · iAndroHacker / unity-mod-menu · GitLab

1517086460977.png


See some useful documentation:

Styled text: Unity - Manual: Rich Text

Immediate Mode GUI (IMGUI): Unity - Manual: Rich Text

Adding mod menu into assembly-sharp.dll file:
This is a tricky part because there are many ways to add your own code like adding OnGUI method on any classes (Loading, LoadingScreen, MainMenu, etc…) or add code on existing OnGUI methods.

Method 1: Adding OnGUI method

In this example, I will create OnGUI and add my code in UserInterfaceManager on Super Dungeon Bros.

Find an active class or search "Loading" and pick one of loading method. In my example, I picked DisplayLoadingScreen located in UserInterfaceManager. Right click on UserInterfaceManager and create a method.

Note: Make sure the class have Instance method. If it does not have Instance, you have to create your own class

1517086507093.png


Name it OnGUI and click OK.

Right click on OnGUI(); and edit method

1517086512467.png


Remove "extern" and modify code so it looks like this:

C#:
public void OnGUI() {
}
You can paste your code here and compile it.

Remove "static" modifier if MOD Menu doesn't appear

Method 2: Create a new class for GUI

Add a class on empty namespace

1517086572219.png


Add your whole code and name your class. Make sure you add public and static modifier like below so other classes can access the fields. Your method name must not be called OnGUI, call it MyGUI or whatever. It is to avoid confusion with another OnGUI since Unity always read something if it recognize OnGUI methods.

Example:
C#:
public void OnGUI()
{
     ModMenuScript.OnGUI(); //makes problem
}
if you don't add static modifer, you will get an error "An object reference is required for the non-static field, method, or property '<code>'"

1517086591413.png


Save the class. Sometimes dnSpy can't find class you created so you have to save the assembly as Assembly-Csharp1.dll or whatever, Close all dlls and open Assembly-Csharp1.dll

To make your MOD Menu appear in-game, find an active class or search "Loading" and pick one of loading method, create OnGUI method and edit the code like:

C#:
public void OnGUI()
{
      ModMenuScript.MyGUI();
}
Hacking functions
Now search some functions to hack. If you had added OnGUI in an existing class with Instance method, modify the code like this:

(I modify this getter method as an example)

C#:
public float ArmorCapacity
{
    get
    {
        if (UserInterfaceManager.Instance.hack1)
        {
            return 999f;
        }
        return this._armorCapacity;
    }
    set
    {
    }
}
If you had added your own classes, modify the code like this:

C#:
public int get_SupplyCost()
{
    if (ModMenuScript.hack1)
    {
        return 999;
    }
    return this.UnitInstance.SupplyCost;
}
There are other ways to hack it but these methods are the best way to hack for beginners.

Save the dll file and test your MOD Menu :)

Video example: bandicam 2018-01-26 18-59-25-119 - Streamable

Credit:
iAndroHacker
 
Last edited:

Sbenny

A crazy scientist
Staff member
Admin
SB Mod Squad ⭐
✔ Approved Releaser
Active User
This is pure gold <3 thank you so much for sharing your unique tutorial with us @iAndroHacker :D
 

BRILLIANT

Veteran Lv7️⃣
✔ Approved Releaser
Member for 6 years
TYSM your a life saver , this is my HolyGrail! :):lurking:
 

MrOnline

APK Fanatic Lv5️⃣
Member for 5 years
@AndnixSH I Appreciate Your Hard Work On Thread And Video. But For Newbies Like Me Video Was Too Fast and Thread was Lil Hard Anyway If We really want to do something then we definitely achieve it same happened with me.after watching your videos more then 20 times and getting about 100 times compiler error i finally managed to get menu shown on game.Thanks For This Great tutorial.now im working on to make it working .Thanks You Too Much:inlovedroid::kissdroid:

EDIT:MANAGED TO MAKE IT WORKING.THANKS YOU AGAIN FOR THIS TUTORIAL NOW MY MOD WORKS COMPLETELY NORMALLY <3
 
Last edited:

shashuke

Lurker Lv0️⃣
Member for 7 years
bro how to add image ico >> show/hide menu if (name.Image == null)
 
Top