Jump to content

[WIP] KSPPluginReload, reload plugins without rebooting


m1nd0

Recommended Posts

I started developing KSP this week and one of the things I hated most about it was rebooting KSP constantly.

So before I actually developed a plugin I developed a plugin-reloader.

Description

This tool allows you to reload plugins without the need for restarting KSP.

There are some downsides:

  • Only classes which inherit MonoBehaviour and include the attribute KSPAddon will be reloaded. Parts & partmodules will not be reloaded.
  • Custom parts and partmodules won't work when loading a DLL with this (see note1)
  • Only use this for developing/debugging. Since KSP doesn't allow AppDomains each reload loads a second instance of the plugin, therefore increasing the memory usage.

But even without part reloading, my development speed is now over 9000.

Installation

  1. download latest build or build from source and extract to ksp directory
  2. remove your plugin.dll from \GameData\YourPlugins\plugins\ (see note1, bottom of this page for part & partmodule code)
  3. edit Settings.cfg in "\GameData\PluginReload".
  4. open AssemblyInfo.cs in your project and change AssemblyVersion & AssemblyFileVersion to "1.0.0.*". Visual Studio will auto-increment your build, this is the only way to allow reloading of a DLL.

Usage

Launch your game. Test something. Rebuild the dll, press Reload plugins to reload plugins. ALT+P opens/closes the rebuild menu.

Example of settings.cfg


PluginSetting
{
name = Myplugginname
path = C:\develop\myplugin\debug\myplugin.dll
loadOnce = false
methodsAllowedToFail = false
}

Known issues

  • If your mod uses KSPAddon.Startup.PSystemSpawn this may issues since the solar system is already created at reload. (untested)
  • Probably more

Credits

Ezriilc (http://www.kerbaltekaerospace.com/). Used hyperedit GUI code as base for GUI.

Terms of Use

http://creativecommons.org/licenses/by-nc-sa/3.0/

Download

Binaries

Github

Note1:

You can leave your plugin in \GameData\ if you need your parts/partmodules in your code. However you MUST put your parts and modules inside a different DLL which loads them. If you place any code that launches (KSPAddon) it won't be unloaded when all plugins are reloaded, and you will wind up with duplicated code being executing.

So far I've only testes this with my own plugin and hyperedit. If you experience issues please use github or this forum to report bugs.

Link to comment
Share on other sites

ALT-F12 will bring up Squad's debug panel that reloads game database; ModuleManager also includes improved reloader since 2.3.x. ALT-F11.

But it can't reload plugins. Until now, you'd have to restart KSP t reload the plugins.

Link to comment
Share on other sites

The plugin are reloaded but since you can't replace the dll while they are opened (on Windows) it does not help much.

They don't reload dlls. And even if they did they actually don't use different AppDomains for loading assemblies this means:

  • The current assembly will not unload
  • Created classes won't be destroyed and will keep running (duplicated code)

Even if they were to replace their current method:

Assembly.LoadFrom(this.path);

by a version which would not lock the file (for example):

Assembly.Load(File.ReadBytes(this.path));

The new DLL would still not be used for parts and code because the current domain still has the old dll reference.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...