|
| 1 | +--- |
| 2 | +Title: Prepatchers |
| 3 | +Sort_Priority: 33 |
| 4 | +--- |
| 5 | + |
| 6 | +# Prepatchers |
| 7 | + |
| 8 | +In certain contexts you may need to edit game files before start. This is where |
| 9 | +prepatchers come in. Prepatchers are run by OWML directly before the game starts, allowing you to modify game files you would otherwise not be able to. |
| 10 | + |
| 11 | +To create a prepatcher you'll need a separate project from your mod. This can be done by creating a new project in your solution with the executable type, it should automatically build to your mod folder. |
| 12 | + |
| 13 | +Now in your mod manifest you need to set the `patcher` field to the path of the executable relative to the root of the |
| 14 | +mod folder. |
| 15 | + |
| 16 | +## Creating A Prepatcher |
| 17 | + |
| 18 | +A prepatcher is a simple console app that OWML executes, it's only passed the location of your mod folder. |
| 19 | +However, it is possible to get the game's location by doing `AppDomain.CurrentDomain.BaseDirectory`: |
| 20 | + |
| 21 | +```csharp |
| 22 | +public static void Main(string[] args) |
| 23 | +{ |
| 24 | + var modPath = args.Length > 0 ? args[0] : "."; |
| 25 | + var gamePath = AppDomain.CurrentDomain.BaseDirectory; |
| 26 | + |
| 27 | + Console.WriteLine($"Mod Path: {modPath}"); |
| 28 | + Console.WriteLine($"Game Path: {gamePath}"); |
| 29 | + |
| 30 | + // DoStuff(modPath, gamePath); |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +Keep in mind the `ModHelper` is not available in a prepatcher. |
| 35 | +You'll need to have the prepatcher include libraries like Newtonsoft.Json to read and write JSON files. |
| 36 | + |
| 37 | +As an example, Quantum Space Buddies [utilizes a pre-patcher](https://github.com/qsb-dev/quantum-space-buddies/tree/master/QSBPatcher). You can use this as an example. Notice how it also needs to [set this as `patcher` in its manifest](https://github.com/qsb-dev/quantum-space-buddies/blob/master/QSB/manifest.json#L18) in order for OWML to know to run it. |
| 38 | + |
| 39 | +### Logging |
| 40 | + |
| 41 | +Due to a lack of `ModHelper`, you'll need to use `Console.WriteLine` to log information. |
| 42 | +This **will not output to the manager window**. To test prepatchers, we recommend you launch `OWML.Launcher.exe` in a |
| 43 | +terminal directly to properly see stdout. |
| 44 | + |
| 45 | +If a prepatcher errors it *should usually* be outputted to the manager window as OWML is setup to catch and |
| 46 | +log any exceptions thrown by the prepatcher. |
| 47 | + |
| 48 | +### Warnings |
| 49 | + |
| 50 | +Due to the nature of prepatchers, the manager cannot undo changes made by them. This means the game will continue to be modified even if the |
| 51 | +mod is uninstalled or disabled. |
| 52 | + |
| 53 | +The manager will try its best to warn the user of this. If your mod has prepatcher and |
| 54 | +is disabled or uninstalled the manager will show a dialog explaining that |
| 55 | +your mod has modified game files in an irreversible way and encourages them to validate the game files. |
0 commit comments