Modding development - speed up csharp loading

Started by LeatherCat, December 11, 2019, 03:21:21 PM

Previous topic - Next topic

LeatherCat

Technical question to .NET experts.

Scenario:
I am developing mod which is already depends on other 5 mods (3 of them are technical mods like JecsTools).
Game load time is ~1 minute in total, and 50% for dll loading and patching. So is it possible to like "compile" game with all harmony patches from other mod dlls once?

Load order:
Fat.dll = game + system + mod dlls
MyMod.dll

K

A quick search turns up ILMerge which looks like it can do this: https://github.com/dotnet/ILMerge

However, my guess is that you may break the game trying to do this. While you can certainly try it, RimWorld isn't built to have mod dlls included in the main dll, and the mod loading system might not work if you do this. Proceed at your own risk.

LeatherCat

Thank you! I think more about what I asked and it seams impossible.
I afraid that ILMerge will only merge classes from initial assemblies, but not the resulting dynamic assembly after all dynamic patches applied... So patches will be applied anyway on every game startup.
But I have to try it, just need to think how to test that patches are not applied during runtime, but already exist in assembly. Thank you for help once again!

K

I misread your question, sorry. If you want to include patches into the dll, dnSpy says it can modify the contents of a dll: https://github.com/0xd4d/dnSpy

This is once again pretty dangerous and you'd have to do it by hand, adding the patch code into the methods that they patch to replicate the behavior of the patches without the patches themselves.

LWM

The better approach would probably be a custom version of Harmony that outputs all the IL code to a text file as it patches, which could then be compiled separately?

I wouldn't have thought patching would take so long!

Canute

I don't think you can made a dynamic enviroment that would work.
Mods are very dynamic, that why you can add/remove them at that easy way.

I think when you would speed up the loading process, you would need a mod compiler which load all the mod's like rimworld would do and create a meta mod based on all loaded mod which don't need any patching anymore (beside Core).

LeatherCat

Quote from: Canute on December 13, 2019, 03:43:18 AM
I think when you would speed up the loading process, you would need a mod compiler which load all the mod's like rimworld would do and create a meta mod based on all loaded mod which don't need any patching anymore (beside Core).
Exactly! Kind of 'Save final patched code as new dll'. Use this dll during development only.

From logs:
45 seconds ExecuteToExecuteWhenFinished()
where: 37 sec Static constructor calls - what is I guess Harmony patches, right? they are defined in Static constructors

LWM

Quote from: LeatherCat on December 13, 2019, 02:15:14 PM
Exactly! Kind of 'Save final patched code as new dll'. Use this dll during development only.

This is probably doable.  It's probably Very Difficult(tm).  But I'm sure you're not the only one who would love this.  My cursory internet search for ways to write the entire executable's IL code to disk were fruitless, but I am feverish, so I may not be thinking super clearly.

Quote
From logs:
45 seconds ExecuteToExecuteWhenFinished()
where: 37 sec Static constructor calls - what is I guess Harmony patches, right? they are defined in Static constructors

Okay then!  And an unmodded game has very little time in static constructors?