-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,102 additions
and
696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# TweaksLauncher Developer Guide | ||
|
||
## Getting started | ||
|
||
### In order to build your own mod, you will need: | ||
- Basic C# knowledge | ||
- Some experience with Unity | ||
- A coffee | ||
|
||
## Creating your first mod project | ||
### There are 2 ways to create a new mod project: | ||
- Using our dev tools (recommended) | ||
- By creating a new C# Class Library project and referencing all dependencies manually | ||
|
||
### Create a mod project using our dev tools | ||
We recommend using this option because it will allow you to enable auto-build (which will automatically build and load new versions of your code). Next to that, all required libraries (including game libraries) will be automatically referenced.<br> | ||
This will automatically put your project in the `Dev` folder, next to the launcher.<br> | ||
For more advanced developers, we recommend this option when creating git repositories, as relative paths to referenced assemblies will be kept for everyone who clones your repository to the `Dev` directory, removing the need to ship your repository will all the game assemblies. | ||
|
||
- Run the `CreateMod` batch script (located next to the launcher). | ||
- Follow the instructions displayed on the console. | ||
- You're ready to code! | ||
|
||
### Create a mod project manually | ||
If you do not want to store your project in the `Dev` directory, this is the way to go. Keep in mind that there is no auto-build for external projects. | ||
|
||
- Create a new Class Library project (targetting .NET 8.0). | ||
- Specify the mod version by giving the assembly a version in your csproj (using the `AssemblyVersion` tag). | ||
- Manually reference `TweaksLauncher.API.dll` and `0harmony.dll` from the `libs` folder. You can find game proxy assemblies in `Games/Your Game Name/Proxies`. Make sure you've ran the game at least once using the launcher. | ||
- Create a new mod class by adding the `TweaksLauncher.IMod` interface to an existing class. | ||
- You're ready to code! | ||
|
||
## Coding Your Mod | ||
### Basic Structure | ||
Your main mod class should now look somewhat like this: | ||
```cs | ||
using TweaksLauncher; | ||
|
||
namespace MyMod; | ||
|
||
public class Main : IMod | ||
{ | ||
public static void Initialize(ModInstance mod) | ||
{ | ||
ModLogger.Log("Hello World!"); | ||
} | ||
} | ||
``` | ||
|
||
For now, this will only print `Hello World!` to the console.<br> | ||
- The `Initialize` method is ran when Unity has initialized, which is right before the Unity splash screen is shown. | ||
|
||
Sometimes we want to initialize our mod right when when the first game scene is loaded. There are 2 ways to receive a callback when that happens: | ||
- Using the `UnityEvents::FirstSceneLoad` event | ||
- Through our own `MonoBehaviour` (a.k.a. Unity component) | ||
|
||
## Events | ||
The `UnityEvents` class provides common Unity events that can be used by mods. Currently, there is only one event, but more might get added in the future. | ||
|
||
### FirstSceneLoad | ||
Occurs when the first game scene is loaded. | ||
|
||
The following code will print `Hello Game!` to the console once the first game scene is loaded: | ||
```cs | ||
public static void Initialize(ModInstance mod) | ||
{ | ||
UnityEvents.FirstSceneLoad += OnFirstSceneLoad; | ||
} | ||
|
||
private static void OnFirstSceneLoad() | ||
{ | ||
ModLogger.Log("Hello Game!"); | ||
} | ||
``` | ||
|
||
## Creating Unity components | ||
Creating Unity components in a mod is as simple as in Unity itself. | ||
|
||
To create a new Unity component, derive your class from `MonoBehaviour`. Now you can create instances of your component using Unity's API (for example `new GameObject().AddComponent<MyComponent>()`). | ||
|
||
TweaksLauncher provides a `UnitySingleton` attribute, which automatically loads your component once the game starts. The component will stay alive forever, unless manually destroyed. | ||
|
||
The following code will print `Hello World!` to the console once the component is loaded: | ||
```cs | ||
using TweaksLauncher; | ||
using UnityEngine; | ||
|
||
namespace MyMod; | ||
|
||
[UnitySingleton] // This will load the component automatically | ||
public class MyComponent : MonoBehaviour | ||
{ | ||
public void Start() | ||
{ | ||
ModLogger.Log("Hello World!"); | ||
} | ||
} | ||
``` | ||
|
||
## Patching Methods with Harmony | ||
Method patching is essencial for mods. It allows you to control the way the game behaves by replacing or adding code to existing game methods. | ||
|
||
Harmony is a library that allows just that. Harmony patches can be created through simple attributes. Learn more here: https://harmony.pardeike.net/articles/annotations.html. | ||
- The launcher will automatically apply all the `HarmonyPatch` attributes in your mod. Do NOT apply patches manually using the `PatchAll` method. | ||
|
||
Here is an example of a Harmony patch: | ||
```cs | ||
using HarmonyLib; | ||
|
||
// In this attribute you need to specify the class of the target method, the target method name, and the target method parameters. | ||
[HarmonyPatch(typeof(ClassOfTheMethodToPatch), "TargetMethodName", [ typeof(int) ])] | ||
private static class Patch | ||
{ | ||
private static void Prefix() | ||
{ | ||
// The code inside this method will run before 'TargetMethodName' is executed | ||
} | ||
|
||
private static void Postfix() | ||
{ | ||
// The code inside this method will run after 'TargetMethodName' has executed | ||
} | ||
} | ||
``` | ||
|
||
You can also modify the arguments and return values of the method call. Learn more here: https://harmony.pardeike.net/articles/patching-injections.html | ||
|
||
## Debugging | ||
### This guide primarily focuses on Visual Studio 2022 and up. | ||
|
||
You can easily debug your mod through your IDE. This will allow you to start the game through the IDE, set breakpoints and inspect unhandled exceptions. | ||
|
||
- First, you will need to add the launcher's executable as an existing project to your solution.<br> | ||
![Add the launcher's executable as an existing project](img/debug1.png) | ||
|
||
- Your solution should now look somewhat like this:<br> | ||
![Solution explorer](img/debug2.png) | ||
|
||
- Right click on the `TweaksLauncher` project and `Set as Startup Project`. | ||
|
||
- Right click on the project again and go to `Properties` | ||
|
||
- Set the `Arguments` property to the path of your game. Make sure to put it between double quotes. Example:<br> | ||
![Project Properties](image.png) | ||
|
||
- You're all set! You can now start debugging your mod by simply clicking the `Start` button at the top of your IDE. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
# W.I.P. | ||
This project is still in development. | ||
|
||
# TweaksLauncher | ||
A lightweight Unity Il2Cpp mod launcher. | ||
A lightweight Unity mod launcher for IL2CPP games built for windows x64 and x86. | ||
|
||
## How it works | ||
TweaksLauncher is a game launcher, meaning it does NOT inject itself into the game, but rather starts it manually through `UnityPlayer.dll`. | ||
TweaksLauncher is a game launcher, meaning it does NOT inject itself into the game, but rather starts it manually through its own executable. | ||
Mods can interact with the game through the generated proxy assemblies from [Il2CppInterop](https://github.com/BepInEx/Il2CppInterop), just like with any other known Il2Cpp mod loaders. | ||
|
||
## Requirements | ||
- [.NET 8.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-8.0.3-windows-x64-installer) | ||
|
||
## How to use | ||
**If you've already installed the launcher before, skip steps 1 and 2.** | ||
1. Grab the latest zip from the [Releases Page](https://github.com/slxdy/TweaksLauncher/releases). | ||
2. Unzip it to an empty folder (NOT IN A GAME FOLDER). | ||
3. Start the launcher, and follow the instruction displayed in the console. Do not use the x86 version unless you know what you're doing. This will allow you to start the game through the launcher. | ||
|
||
## How to install mods | ||
Depending on the mod, the installation instructions may vary. However, most zipped mods should be extracted to the launcher's folder. **Make sure to extract the entire zip, including all folders within it. Do NOT create any extra folders if prompted.** If the mod is a single DLL, follow instructions provided by the developer. | ||
|
||
## Developing Mods | ||
TweaksLauncher provides useful features for developers, such as auto-build and debugging (through your preferred IDE).<br> | ||
To get started, refer to the [Developer Guide](Guides/DeveloperGuide.md). | ||
|
||
## Compilation Guide | ||
The project should be compiled using Visual Studio. Make sure to build the entire solution. The builds are saved to the `output` directory. | ||
|
||
## Credits | ||
[Il2CppInterop](https://github.com/BepInEx/Il2CppInterop) - A tool interoperate between CoreCLR and Il2Cpp at runtime<br> | ||
[BepInEx/Dobby](https://github.com/BepInEx/Dobby) - Fork of jmpews/Dobby with stability edits for Windows<br> | ||
[Cpp2IL](https://github.com/SamboyCoding/Cpp2IL) - Work-in-progress tool to reverse unity's IL2CPP toolchain.<br> | ||
[BepInEx/Dobby](https://github.com/BepInEx/Dobby) - Fork of jmpews/Dobby with stability edits for Windows<br> | ||
[HarmonyX](https://github.com/BepInEx/HarmonyX) - Harmony built on top of MonoMod.RuntimeDetours with additional features<br> | ||
[Pastel](https://github.com/silkfire/Pastel) - A tiny utility class that makes colorizing console output a breeze. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.