• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Blueberry_pie

Recruit
1 Badges
Mar 11, 2015
3
0
  • Cities: Skylines
First of all, congrats to Colossal Order on the successful launch. I enjoyed what I've watched and played so far, and I'm very excited by how friendly the game is towards modding. :)

I've been using Visual Studio to compile my own mod DLLs, which works well so far. However, it's a bit frustrating that I still have to restart the game every time I want to reload the DLL to view the changes I've made. Is there any way to force the game to reload the mod?

I did some snooping around in the game code using ILSpy, and found that the following call is made when the game launches (in the Starter class):
Code:
Singleton<PluginManager>.instance.LoadPlugins();
Among other things, this results in calls to LoadPluginAtPath for every mod found in the mod directory. LoadPluginAtPath appears to check whether the specified mod is already loaded in memory, and if so, it unloads the old version of the mod. However, when I make my mod call LoadPlugins() during gameplay (e.g. using a keypress), the DLL file does not seem to get reloaded. The game hitches for a moment, so it does appear to be doing something, but the old DLL still gets used in the end. I don't see any changes until after I quit and launch the game again. Any ideas?
 
I think it does reload the mod when it notices that the DLL have changed, you just have to properly cleanup in the appropriate functions. I'll experiment with it later today.
Could be though since they also provide utility to compile the DLL for you that it does it only if it notices the source code has changed?
 
You should be able to create a new AppDomain and reload the DLL fairly easily. (Just google "C# AppDomain Load DLL" or something similar, and you should get a lot of hits.) I do this all the time in my professional code, but there I'm using true .NET, not Mono's outdated clone; but I would be flabbergasted and extremely puzzled if Mono didn't support that, too. Off the top of my head, I am kind of thinking it would be rather impossible for them not to support it.

ETA: The above also assumes the game isn't encrypting the assemblies which wouldn't be surprising.
 
  • 1
Reactions:
So here is how it seems to be When you exit to the menu it unloads the mods and if you start a game again it reloads thr dll i believe.
 
Thanks for the replies. It looks like the game does detect changes made to source files (even during gameplay), but not to externally compiled DLLs. Which is unfortunate, since the game's internal compiler only lets you reference the ICities and UnityEngine assemblies (unless there's a way around this).

You should be able to create a new AppDomain and reload the DLL fairly easily. (Just google "C# AppDomain Load DLL" or something similar, and you should get a lot of hits.) I do this all the time in my professional code, but there I'm using true .NET, not Mono's outdated clone; but I would be flabbergasted and extremely puzzled if Mono didn't support that, too. Off the top of my head, I am kind of thinking it would be rather impossible for them not to support it.

ETA: The above also assumes the game isn't encrypting the assemblies which wouldn't be surprising.
I was hoping to let the game do most of the work for me, so I only looked into that briefly. Looks like it's the best option for now, though, so I'll do that :)