Quick Introduction to EndZone modding - InflexCZE/PatchZone GitHub Wiki

This is just a rudimentary introduction, by far not exhaustive EndZone modding guide.
Nonetheless, it should walk you through your first modding steps and give you some insight on the current state of the EndZone modding.

Keep in mind that this guide will focus mainly on gamelogic modding.
Some parts/steps may be applicable to asset modding, but I'd say there are better tutorials on how to mod Unity-game asserts.

Get to know the game language

Both EndZone a PatchZone are written in C# programming language,
so you should know it at least a bit so that when you see some code you can understand it and feel confident to modify it ;)

There is ton of online tutorials and crash courses, pick one.
I'll mention Microsoft's official guide as an example:
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/

Get dnSpy (Optional, but recommended)

https://github.com/0xd4d/dnSpy
Once you know how to read the game's code, you'll also need a tool that will show it to you.
You're free to choose any tool you like, I like dnSpy, so I'll continue this tutorial with it.

Find the right place

Once you have your code decompiler/reflector ready, open Endzone_Data/Managed/AfterTheEnd.dll
This binary contains all the gamelogic, nicely structured into system services.
Your objective is to narrow down the code section that is related to the system you're trying to modify.

If you're new to this kind of reverse engineering, grab your favorite drink and get comfortable, this will take a while, that's normal.
Take pen&paper, make notes, draw graphs, whatever helps you.

Keep in mind that other experienced modders can help you if you ask the right questions, so don't hesitate to, tho make sure you follow the "Don't ask to ask" paradigm:
https://dontasktoask.com/  

Attach debugger to a running game (Optional, but recommended)

Once you have a rough idea what system you'll be modifying it's time to get to know it.
From my experience the best way to understand how things work is to observe them in action. Fortunately we can do this with debugger (integrated part of dnSpy).

Unity games need a bit of special  treatment before you can attach debugger to them. Nothing complicated, it's well explained in the link below, follow it and you'll be fine.
https://github.com/0xd4d/dnSpy/wiki/Debugging-Unity-Games

Note: Prebuilt Debug Mono runtime libraries are currently not available on official repo.
You can follow advanced steps in the guide and build your own libs or use PatchZone's precompiled bins:
https://github.com/InflexCZE/PatchZone/tree/master/Externals/dnSpy-Unity-mono-bins/



After successfully attaching the debugger to the game, place a breakpoint somewhere in the identified code from the previous step and make the game use the code by performing appropriate in-game action (if necessary). Once the game stops in the debugger at your breakpoint you're free to step around and get to know the system, instruction after instruction, by stepping the logic line by line.

Again, your free to use any debugger you like, any managed debugger that can attach to Mono CLR runtime will do.  

Narrow down the patch

By now you should have a pretty good idea how the game system(s) you're trying to mod work, so it should be pretty easy for you to sum up changes that need to be done in order to make the game behave the way you want it to.  

Test your patch  (Optional, but recommended)

When you think you've found what you'd like to change it's time to test it.
dnSpy can edit the game binaries directly, so you can quickly iterate your changes.
Kill the game, edit the game code in the game Dll, save the changes, restart the game, see if it works as you expect. If not, debug it and repeat the steps.

If everything works exactly how you'd like it to, hooray, you have your patch.
Note it down and restore the original version of the game Dll (back to vanilla) before you continue.  

Make the mod, finally ;)

Editing game Dlls is fine and all, it will do the trick, but only on your PC, it's not so easy to distribute to other players and having multiple mods loaded side by side is practically impossible. This is where PatchZone comes into rescue.

PatchZone is a mod loader that will help you load your mod (e.g. gamelogic patch) into the game at runtime, transparently alongside any number of other mods.
In order to create your first PatchZone mode (project) follow these steps:
https://github.com/InflexCZE/PatchZone#how-to-create-patchzone-mod

PatchZone will automatically create empty mod for you and if there is Visual Studio, VSCode or any other IDE that can open MSBuild Solution installed on your system (highly recommended) PatchZone will automatically open it and load the mod project for you.

Add your gamelogic to the mod

As I've said before, vanilla gamelogic is structured into systems/services. PatchZone follows the suit and your logic needs to be in service class as well.
PatchZone will create the first service for you, it's called LocalizationService and it adds basic info about your mod into the game's main menu. Adjust the info string and test it! The project is pre-configured to launch the game along with your mod when you hit F5 or Start button (or whatever equivalent in your IDE). Once the game loads, you should see your string in the main menu, bottom right.

Once you verify that everything works and your mod loads into the game you can go ahead and add new service into the project.
You can either clone the LocalizationService or type it by hand, the template is following:

public class YOUR_NAME : ProxyService<YOUR_NAME, INTERFACE_FOR_COMMUNICATION_WITH_GAME>
{
    //Future logic goes here
}

where INTERFACE_FOR_COMMUNICATING_WITH_GAME should be the system (interface, not implementing class) that you've previously identified that you'll be changing. YOUR_NAME class is now your sandbox, space for your mod's gamelogic.

From previous steps you should know precisely what method of the vanilla logic you'd like to change. In order to do that, just type the method here into the YOUR_NAME class and mark it with [LogicProxy] attribute. That's it, the game will now call your method instead of its own vanilla logic. In order to call back the vanilla logic you can use this.Vanilla helper.

[LogicProxy]
public void Tick(float deltaTime)
{
   //Speeds up the vanilla system 2 times
   this.Vanilla.Tick(deltaTime * 2);
}


Finally, you need to tell the PatchZone to load your shiny new service into the game.
It's very simple, locate MY_MOD_NAME.OnBeforeGameStart method in your mod, that would be here:
https://github.com/InflexCZE/PatchZone/blob/master/Assets/ModTemplate/___MOD_NAME___/___MOD_NAME___.cs#L26
and add the following line at the end of the method body:

this.Context.RegisterProxyService<YOUR_NAME, INTERFACE_FOR_COMMUNICATION_WITH_GAME>();

Enjoy your mod

With this your mod should be ready for the very first test run. Hit F5 to start the game again, let it load and see if the game behaves how you expect it to.
If yes, congrats, you have your first mod ready for shipping 🎉

⚠️ **GitHub.com Fallback** ⚠️