Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the possibility to load/unload plugins at runtime #88

Closed
StevenKrahforst opened this issue Nov 5, 2022 · 2 comments
Closed

Adding the possibility to load/unload plugins at runtime #88

StevenKrahforst opened this issue Nov 5, 2022 · 2 comments
Labels
wontfix This will not be worked on

Comments

@StevenKrahforst
Copy link

For what that can be useful?

  • Ingame Mod Manager/Browser for downloading/installing plugins while game is running
  • Auto Updater before the game has been started (requires some more work cause the assemblies get locked when they are loaded)

Idea:

  • Static methods like LoadFile(path) or LoadFromStream(stream) or LoadFrom(byteArray) like Assembly.LoadFile(path)
  • Helper functions in order the mod can add compatibility when loaded manual
  • For unloading I have no idea yet, probably something with the Garbage Collecter after the plugin has been disabled
@nike4613
Copy link
Owner

nike4613 commented Nov 5, 2022

Unloading is not possible.

In a .NET Framework-adjacent environment like Unity Mono, the only way to do unloading is to load what you need into a separate AppDomain and then unload that domain. Unfortunately, in order to communicate between these domains, the runtime provides remoting proxies, and those are only generated for types which are MarshalByRefObject derived. Otherwise, the object is serialized in one domain then deserialized in the other. This would have unacceptable performance overhead, but even ignoring that, Unity would not behave, and at best you'd be unable to reliably create Unity object. At worst, you'd see hard-crashes.

It would be possible to just load a new copy of a given mot into memory, but that comes with its own set of problems. It would also require that the mod properly clean itself up when it is disabled, which the vast majority of mods simply do not do.


All that being said, the two uses you specified do not need unloading; they would just require a game restart. Both of them are, in fact, already possible with the functionality that BSIPA provides. BSIPA used to even have the updater built in, and a mod manager like plugin has existed (though not been published, in large part because of my own laziness) for years in the form of https://github.com/nike4613/BSIPA-ModList-BeatSaber. I believe that ModList does actually work at present, though I have not tested it myself.

@nike4613 nike4613 added the wontfix This will not be worked on label Nov 5, 2022
@StevenKrahforst
Copy link
Author

Yeah makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants