Project Hospital
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
jan.oxymoron
jan.oxymoron
developer
Posts : 2309
Reputation : 336
Join date : 2018-03-23

Modding tutorial - setting up code mods Empty Modding tutorial - setting up code mods

Tue Dec 01, 2020 4:57 pm
Message reputation : 100% (2 votes)
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.

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 higher

Mod 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.

Modding tutorial - setting up code mods Modcod10

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
Modding tutorial - setting up code mods Attachment
ModCodeTestProject.zip You don't have permission to download attachments.(1.2 Mb) Downloaded 38 times
Modding tutorial - setting up code mods Attachment
ModCodeTestBuild.zip You don't have permission to download attachments.(304 Kb) Downloaded 18 times


Last edited by jan.oxymoron on Fri Dec 04, 2020 4:43 pm; edited 1 time in total

Butch, James, sleepy068 and Greymind like this post

Back to top
Permissions in this forum:
You cannot reply to topics in this forum