-
Notifications
You must be signed in to change notification settings - Fork 22
Added late loading functionality for mods. #55
base: master
Are you sure you want to change the base?
Conversation
This makes the ModLoader watch the nml_mods directory and attempt to load any new .dll file it finds in there as a mod.
Would it make sense to also be prompting the user before actually loading new assemblies. Could provide the name and if the maybe if the mod has explicit support for being hotloaded? |
maybe config options for enabling/disabling hotloading for anymod/not explicitly supported mods |
Could do that. Though currently a mod has no way of explicitly identifying itself as hotloadable. Also: |
Also fixed line endings in NeosMod.cs
Also added a new config option to disable late loading.
if the mod implements onlateload then its hotloadable? |
On the one hand, I like this. On the other hand, that'll just make a lot of mods override OnLateLoad with the same thing again. (just calling OnEngineInit) |
Time to start a NML2 branch and start doing the refactors to make this better but maybe break backwards compatibility slightly? |
Sounds like that might make sense. Though I had one idea that would work as a temporary solution: |
Mods now have an OnInit(bool atStartup) which replaces the old OnEngineInit(). If it is available, that signals to the modloader that the mod supports hotloading.
I have now done this so mods can implement a new I have documented the config parameters that control this ( I think that this is a clean way of doing it since all the backwards compatibility for |
As described OnEngineInit wouldn't be legacy? as that would be how a mod continues to say it doesn't support hotloading. Unless the intention is that a mod that doesn't support hotloading uses OnInit and just stops itself if it isn't at startup? That seems like it existing at all would signal to the mod loader that it can be hotloaded despite not and trying to explicitly state it doesn't |
Is a mod signalling to the modloader in anyway that it actually supports being hotloaded aside from the existence of a method that would eventually be the single Init function again? Or only the other way around of the modloader informing a mod when it is loaded from the start vs later on. Dunno how much it actually matters I suppose |
You're right. OnInit() more just signals "I support this new way of handling initialization" and then the mod can decide to not do anything if it gets hotloaded but doesn't like that. The idea there is that most mods should probably be able to support hotloading and if they don't, they'll just not do anything until you restart the game. There could be a separate variable in the mod that explicitly tells the modloader if it likes being hotloaded but I'm not sure how often that would be used since I can't think of many reasons for a mod to not support hotloading. (if programmed properly with hotloading in mind) |
i dont really see an issue with just using OnEngineInit for mods that dont support hot loading. |
maybe there should be a field in the mod class that a mod can set that overrides nml's config for if it should attempt to late load OnEngineInit |
I don't think there should be. With the new OnInit function being fine for both early and late loading (and a mod being able to distinguish via the passed-in bool) I think that a mod should instead just replace their OnEngineInit() with a OnInit(bool atStartup). It's a one-line change and lets us deprecate OnEngineInit() to not keep lumping around two init functions where we only really need one. |
my reasoning for wanting the loader to know if a mod explicitly does not support late loading is we can have it log that it wont load x mod due to it not supporting late loading |
there should probably be a method or delegate for other mods to know when a mod has been late loaded. this would be useful for mods like the config mod or ExposePatchedMethods to know when to update their objects |
If we're going to be doing things that deprecate methods, I'd much rather introduce an assembly level attribute to indicate that the mod supports it rather than parameters or class overrides. Since my opinion is that almost all of the |
thats a good point, if a mod explicitly not supporting late loading was an assembly attribute we could check that before loading any assemblies |
I agree on using assembly attributes, would allow more options before loading an assembly |
I just discovered that this crashes if nml_mods doesn't exist yet (cause it creates the file system watcher on it without checking) |
Reading over this, it seems like there are two possible approaches. Either way we add an
I don't see a need to alter The assembly attribute is a fine idea, except existing mods won't have it so if we go for option 1 we'll need to load them and call |
@Psychpsyo The merge conflict is due to us screwing with all the whitespace in the project (sorry). You can fix it trivially with these commands: git merge -X ours origin/master
dotnet format |
Alright. |
This makes the modloader watch the nml_mods directory and attempt to load any new .dll file it finds in there during runtime as a new mod.
This also adds a new function, OnLateInit() to the NeosMod class. This can be overriden by a mod to handle late loading differently from being loaded at startup.
When late loading a mod, the modloader will use the FrooxEngine.LoadingIndicator to indicate success or failure to the user so that a new mod appearing isn't entirely invisible.
Multiple sections of code in the ModLoader and one in AssemblyLoader have been turned into their own functions to be reused during late loading.