- jan.oxymorondeveloper
- Posts : 2309
Reputation : 336
Join date : 2018-03-23
Modding tutorial - setting up code mods
Tue Dec 01, 2020 4:57 pm
Hi, this is a first WIP version of this guide currently only visible to the Release testing group, but should have all the info to get started.
- .NET Framework 3.5 (you should be able to select this version when installing Visual Studio)
- (At Oxymoron Games we use IntelliJ Rider instead, but it doesn't currently have a free version that could be easily obtained - open source projects at least 3 months old should be eligible though)
- Grab the attached mod example solution, it includes all necessary libraries (Harmony, matching Unity dlls).
The last item is the 'main' class of the mod that can be used to patch code using Harmony and is also very useful just for printing info about the mod to log for testing.
Each mod needs to inherit from HospitalMod, that's how the game recognizes it's the 'main' class.
Dependencies
The dependencies are already included, but feel free to grab later version from the game install. Game code is not expected to change in a way that would break compatibility at this point. Note: the latest version of Harmony pops up an error (not sure if harmless), the one from this thread is currently included: https://projecthospital.forumotion.com/t2449-modharmony-doctor-mode-perks-and-cost
- Assembly-CSharp.dll is the game code
- UnityEngine.CoreModule.dll
- UnityEngine.dll
- 0Harmony.dll
Building the project
The project builds a single library, .NET framework version needs to be set to 3.5 to match the version of Unity the game is built with
I'd recommend keeping the mod solution in a separate location, then for testing in game you can copy your mod contents into a folder under Addons, that only needs to contain:
- YourModLibrary.dll (needs to have the same name as the folder + .dll)
- Database
- Other assets like icons
- 0Harmony.dll
- All scripts inherit from ProcedureScript class
- All scripts share the same data structures like ProcedureScene and simple parameters that are supported by the game's save and load system
- An example of a very simple examination is included in the test project
TODO
- Explain the data and links between xml and code (this will be quite long)
- Example of an existing examination
- Example of a surgery?
https://projecthospital.forumotion.com/t2449-modharmony-doctor-mode-perks-and-cost#8862
Modders usually use dnSpy to look into the game code: https://github.com/0xd4d/dnSpy/releases
Related: tutorial for Rimworld which should be a pretty similar case: https://rimworldwiki.com/wiki/Modding_Tutorials/Harmony
System setup
- Visual studio 2017 or higher, free community version is available here : https://visualstudio.microsoft.com/free-developer-offers/- .NET Framework 3.5 (you should be able to select this version when installing Visual Studio)
- (At Oxymoron Games we use IntelliJ Rider instead, but it doesn't currently have a free version that could be easily obtained - open source projects at least 3 months old should be eligible though)
- Grab the attached mod example solution, it includes all necessary libraries (Harmony, matching Unity dlls).
Game setup
- Game version 1.2.21966, Patch 34 (first experimental support) or higherMod project setup
After loading the example project, rename the solution, project and ModCodeTestMain.cs to your liking.The last item is the 'main' class of the mod that can be used to patch code using Harmony and is also very useful just for printing info about the mod to log for testing.
Each mod needs to inherit from HospitalMod, that's how the game recognizes it's the 'main' class.
Dependencies
The dependencies are already included, but feel free to grab later version from the game install. Game code is not expected to change in a way that would break compatibility at this point. Note: the latest version of Harmony pops up an error (not sure if harmless), the one from this thread is currently included: https://projecthospital.forumotion.com/t2449-modharmony-doctor-mode-perks-and-cost
- Assembly-CSharp.dll is the game code
- UnityEngine.CoreModule.dll
- UnityEngine.dll
- 0Harmony.dll
Building the project
The project builds a single library, .NET framework version needs to be set to 3.5 to match the version of Unity the game is built with
I'd recommend keeping the mod solution in a separate location, then for testing in game you can copy your mod contents into a folder under Addons, that only needs to contain:
- YourModLibrary.dll (needs to have the same name as the folder + .dll)
- Database
- Other assets like icons
- 0Harmony.dll
Adding new scripts for procedures (examinations, treatments and surgeries)
The procedure script system has been designed to be very generic to allow adding new procedures for new examinations and treatments.- All scripts inherit from ProcedureScript class
- All scripts share the same data structures like ProcedureScene and simple parameters that are supported by the game's save and load system
- An example of a very simple examination is included in the test project
TODO
- Explain the data and links between xml and code (this will be quite long)
- Example of an existing examination
- Example of a surgery?
Patching game code
This is what Harmony is for, for now you can check PanzerKadaver's example using Prefix and Postfix methods here:https://projecthospital.forumotion.com/t2449-modharmony-doctor-mode-perks-and-cost#8862
Modders usually use dnSpy to look into the game code: https://github.com/0xd4d/dnSpy/releases
Related: tutorial for Rimworld which should be a pretty similar case: https://rimworldwiki.com/wiki/Modding_Tutorials/Harmony
- Attachments
Butch, James, sleepy068 and Greymind like this post
Permissions in this forum:
You cannot reply to topics in this forum