Jump to content

Addon Controller - Toggle addons and parts on/off for individual saves


Uzza

Recommended Posts

Release thread

Javascript is disabled. View full album

This is the development thread for my Addon Cotroller plugin.

Basic goal of this project is to create a way for users to control what addons and parts should be running/be available for individual saves, and provide an endpoint that addon developers can use to enable their addons to be dynamically turned on or off.

Discussion and suggestions are welcome.

Features

  • Prevent specific addons from running for a given save (if it implements support)
  • Prevent specific part modules from running for a given save
  • Prevent specific parts from being available for a given save

Source

https://bitbucket.org/uzza/kspaddoncontroller

API

The API can be found by looking at the AddonControllerApi and RefelctionAddonControllerApi classes. The RefelctionAddonControllerApi class is built so it does not need an assembly reference, so just copy the class to your addon project and start using it, and it'll return correct values i.e. return true on AddonIsAllowed when not installed, and the actual value when it is.

Also, all addons are allowed to run during the loading screen and while in the main menu. In all other cases, the actual value is returned.

If you add support using the API, please comment so I can compile a list of supported addons.

Todo

Future plans

  • Investigate possibility of dynamically unloading and loading textures to only keep textures of loaded parts in memory.
  • Investigate if it's possible to show existing part info window when hovering over part in the part list.
  • Add support for KSP-AVC.

Edited by Uzza
Link to comment
Share on other sites

I've spent the most of yesterday figuring out how the Unity UI works, and I think I've gotten it mostly figured out.

Here's the current UI, addons section still WIP:

6H20slH.pngnY9HVfn.png

Also, based on NathanKells comment in the release thread, I've made the functionality of preventing addons from loading a config option.

I think I'm also going to make it an option per addon in the UI, so if you know an addon can be toggled off by it not loading, you can toggle it for that addon.

Edited by Uzza
Link to comment
Share on other sites

v 0.3 has just been released and the release thread has been updated.

Next task on the list is to expand the API.

I was thinking of adding the ability for addons to register parts that's associated with them, so when an addon is disabled, the parts are also removed.

Thoughts on that, or other ideas for expanding the API?

Link to comment
Share on other sites

Ok i have some questions and comments

1. Does the game still load everything into memory at startup?

2. Do you have any plans for organising the choices a bit? People with hundreds of parts will probably not bother with it unless you can check or uncheck whole mods or folders.

Link to comment
Share on other sites

1: Currently I don't touch any of the loading sequence, so everything is loaded normally.

Hmm, loading only the parts needed as you load load a game would be an interesting idea, and unloading them when you exit. Don't know if it's easy, hard, or even possible though.

2: My initial plan was to have a directory tree where you can check or uncheck an entire node at once.

This is my first foray into the Unity UI system though, so I very quickly changed initial goal to just get a usable UI so you don't have to edit the config manually.

Should probably start looking at how to implement it.

Edited by Uzza
Link to comment
Share on other sites

So I've played around with the UI, and I've ended up with a tree view that I think looks pretty good!

I'm basically using the folder structure, though cleaned slightly to remove excess nodes like /Parts.

Besides the obvious unlit and green lights, the orange lights represent nodes where not all child nodes are selected. Clicking on an orange node will deselect all child nodes.

What do you guys think?

Em0oRgj.png

Edited by Uzza
Link to comment
Share on other sites

I just looked at part organizer, and while you can get the same effect, that plugin is more intended for sorting and finding specific parts when building. My plugin prevents the parts from even appearing in the first place.

That's just the parts though. My plugin also allows you to, with some limitations, stop plugins/mods from running for specific saves.

This way you should be able to tailor the game experience for each save.

Link to comment
Share on other sites

I would really love this to work..

but it probbably can't..

you are walking in a good direction - but I'm not sure there is a place to arraive there..

at the time you select the save file, the addon loader is allready through..

all parts/plugins are allready in the memory..

since THIS is the actual problem that needs to be solved (lag because of ram and gameload crashes because of too many mods) - this plugin does not serve it's purpose right now.. - sorry to be so blunt :-)

I mean if my lag does not go away, I might aswell show the parts in editor - becaue if they are just hidden but still lag my game, why would I wan't them to be hidden?

Also with your plugin, the only way to get B9 out my memory for one save is to remove it physically from gamedata.

I was thinking a few minutes how to solve this - but I guess since KSP loads all parts before you select the save, it might be a futile excercise to try..

you would need to restart the game load after selecting your plugins - and then this setting would affect all save games..

the only "real" way to have it work with current KSP would be a standalone application, that will rename files (dll => dll.txt, same for pics and cfg, and models) so they wont load..

but I'm sure, this is not what you intended to code..

Or: KSP needs to have a hook point prior the part loader and the part loader has to run after the save game select or this will never work I'm afraid..

correct me if I'm wrong guys..

Link to comment
Share on other sites

That's just the parts though. My plugin also allows you to, with some limitations, stop plugins/mods from running for specific saves.

This way you should be able to tailor the game experience for each save.

Oops. You should advertise this aspect of it a lot more. I just quickly scanned through this thread initially and what stands out most is the part hiding feature.

It's definitely great to be able to disable e.g. DRE and FAR for a particular save, but what would be even greater is if you could stop plugins and art assets from loading at all. This would be a great tool for modders. Right now we're all forced to keep seperate installs for development with minimum/no mods installed for quick loading.

Or: KSP needs to have a hook point prior the part loader and the part loader has to run after the save game select or this will never work I'm afraid..

correct me if I'm wrong guys..

Dev Helper has a way of specifying which save to load automatically which it stores in an XML file IIRC. Maybe there could be some cooperation there.

Edited by Cpt. Kipard
Link to comment
Share on other sites

Oops. You should advertise this aspect of it a lot more. I just quickly scanned through this thread initially and what stands out most is the part hiding feature.

I should probably update the first post to be more informative, like the release thread, to make it more clear.

It's definitely great to be able to disable e.g. DRE and FAR for a particular save, but what would be even greater is if you could stop plugins and art assets from loading at all. This would be a great tool for modders. Right now we're all forced to keep seperate installs for development with minimum/no mods installed for quick loading.

You can stop KSPAddons from loading, so mods that are wholly contained inside a KSPAddon is stopped if you toggle off "Allow Start". I don't do anything with PartModules though currently, which is something I need to figure out how to disable.

I did have a quick look at textures, and it's easy to unload them, so I can unload all part textures as they're being loaded, and then only load the ones that's needed when loading a game.

I'm having some difficulty with loading them again though. I tried using the existing texture loaders (e.g. DatabaseLoaderTexture_MBM), but they were never successful.

I then used the MBMReader to directly load an mbm texture for a squad part, but I could never get the model to use the new texture. Feels like I'm missing something.

Here's the code:


private void Stuff()
{
GameDatabase.Instance.RemoveTexture("Squad/Parts/Command/advSasModule/model000");
GameDatabase.Instance.RemoveTexture("Squad/Parts/Command/advSasModule/model001");

this.LoadTexture("Squad/Parts/Command/advSasModule/model000");
this.LoadTexture("Squad/Parts/Command/advSasModule/model001");
}

private void LoadTexture(string textureName)
{
var fullPath = KSPUtil.ApplicationRootPath + "/GameData/" + textureName + ".mbm";
var isNormal = false;
var tex = MBMReader.Read(fullPath, out isNormal);
if (tex != null)
{
Debug.Log("Loading successful " + fullPath);
var info = new GameDatabase.TextureInfo(tex, isNormal, true, true);
info.name = textureName;

GameDatabase.Instance.databaseTexture.Add(info);
}
else
{
Debug.Log("Loading not successful " + fullPath);
}
}

Edited by Uzza
Link to comment
Share on other sites

Dev Helper has a way of specifying which save to load automatically which it stores in an XML file IIRC. Maybe there could be some cooperation there.

Oh I see where you are getting at..

as a work around for the limiting KSP procedures on partload, one could make a list of stuff to rename (pics, mu, cfg, and dlls), force the game to close, start a batch that does the renaming and restarting the game with allready selected save..

that way, the "unloading", that happens after the tediouse loading time can be prevented by not loading them in the first place.

That unloading is btw done by KSP itselfe - check logs - every X frames, the garbadge collecter runs and unloads unused assets..

does really not save any time at game load..

in other words, it still solves a problem that does not exist..

the better way to solve the "existing" problem could be the auto renaming - although it's a messy workaround it could work.

at least on windows - not sure if mac has batch files..

Link to comment
Share on other sites

While I find the intent, idea (and code) great just know that replacing the addon loader (and other part of the stock loader) as you do will just means one thing : I will not provide any support for any of my mod when yours is present.

Link to comment
Share on other sites

While I find the intent, idea (and code) great just know that replacing the addon loader (and other part of the stock loader) as you do will just means one thing : I will not provide any support for any of my mod when yours is present.

While wrapping the loader was my initial idea to be able to prevent addons from starting, which would have worked without support from other mods, it became obvious that it was not nearly a universal solution, which is why it's currently a secondary citizen and only used if the user explicitly sets it.

I've been thinking about removing that part completely, but that would require that other mods add support and starts checking against my plugin if the user has allowed it.

Given how dependent it was on how the addons were coded though, removing the loader replacement might be the best path, and hope that addon devs add support through the api.

A question. Is it possible to revert the changes to parts that Module Manager does? If so it might be possible to integrate so a user could stop specific changes to parts, which I could then show in my UI.

Link to comment
Share on other sites

No, there are too much things going on after loading for something to work properly. The GameDatabase loads the .cfg, then MM does its work and after that PartLoader compiles the part from the GameDatabase. And some mods builds things from GameDatabase when they reach the game menu or spaceport (or earlier, but it's a bad idea imho).

MM allows for a reload of the DB that reapply the patch so it would be possible if I added a way to block some mod from loading in MM, but mods that builds some of their config when reaching the Main Menu may break.

But it's still a support nightmare. You can't know if something failed because a user deactivated a dependency of an other mod. Like those who removed MM from FAR install because they tough MM was somehow bad.

Link to comment
Share on other sites

That's a shame, would have hoped it for it to be easy, as it means it's not possible to revert changes to, for example, stock parts if MM is installed.

On dependencies though, I could probably check the KSPAssemblyDependency, so if a user disables a mod, those that depend on it are also disabled.

Would you have any suggestions on what kind of API functions you think would be useful? As I mentioned previously, I've thought about addons being able to register parts that should be disabled when the addon is disabled, which should add some easy of use for end users.

Also, does anyone know if it's possible to show the part information window on the fly outside of the editor/R&D? Would be nice to be able to show it when hovering over parts in the part list.

Link to comment
Share on other sites

I've seen it before and it works pretty well. Some quick testing doesn't show any issues together with my plugin.

I'll see if unloading textures of excluded parts works together with it. In that case I'll add it as a feature that runs on the condition that LOD is installed.

Link to comment
Share on other sites

A new week, more development (working on this mostly on weekends).

I have decided to completely remove the ability to prevent addons from running, as per the previous discussions. So now it's only possible to stop addons if they implement support through the API.

Speaking of the API, I've created an actual API class and a reflection based version of it. Just copy the RefelctionAddonControllerApi class to your project. and start using it.

I've added an examples project that shows how to use the API.

I've also been finishing up the tree view, so now there's a tree view for both addons and parts. It also remembers it's state for each save, so it's easy to switch between saves and see what's toggled on/off.

Addons are grouped by first subfolder in GameData, and then by the assembly they're in.

Have a look at it below.

Javascript is disabled. View full album

Going to see if there's any more changes I'm going to add before making a new release.

Link to comment
Share on other sites

How are you handling cleanup of the mods? There are many things in EVE that I think would not play nicely with being removed in-game.

I could see how other mods might change many stateful aspects of things in KSP that would not work.

On the other-hand, If you altered the AddonLoader mechanism to delay loading mods until after a save is selected that could work. It would just mean that in order to properly clean things up, you would have to quit the game to load a new save.

Link to comment
Share on other sites

How are you handling cleanup of the mods? There are many things in EVE that I think would not play nicely with being removed in-game.

I could see how other mods might change many stateful aspects of things in KSP that would not work.

On the other-hand, If you altered the AddonLoader mechanism to delay loading mods until after a save is selected that could work. It would just mean that in order to properly clean things up, you would have to quit the game to load a new save.

That was the problem, I couldn't actually do that, and EVE was actually the first one I noticed it on.

This is one of the reasons that I've now moved away from altering the addon loading process, and now doing a purely API driven approach. The support will be much easier, as then it's just a case of if the mod supports toggling by checking it's state.

The API is currently just a function that takes an addon type and returns a boolean that indicates if it has been disabled, so it shouldn't be that difficult to update a mod around that.

Link to comment
Share on other sites

  • 2 weeks later...

A quick suggestion until the problem is solved for loading/unloading textures dynamically:

Would it be possible to generate a list of all parts disabled?

If that's done, then manually or automatically we can disable those parts.

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...