Jump to content

Info on how to convert your Plugin to KSP 1.1


Recommended Posts

6 hours ago, Ziw said:

Amazing how people don't read the OP.

@sarbian take a look here on my humble attempts at creating an window abstration. And this is an example of use. It worked fine in my separate U5 project, but I did not have much time to tinker with it. Feel free to use any part of the code if you want to start a proper library.

This little source already shows we why the assetbundles are now integrated.
The old system was so bad but never looked like soooo much work to just create a few basic windows.

Link to comment
Share on other sites

Okay, this is a Windows question more then a KSP question, but I'm hoping someone can help.

Running KSP from within Steam the game has no issues. I copied the KSP folder out to make a stand alone dev version. When I right-click the KSP.exe icon and run as adminstrator, everything is fine.

However, if I just double click the icon I get the following error on several files, including ones that come with KSP.

[LOG 20:29:31.774] Load(Assembly): Squad/Plugins/KSPSteamCtrlr
[LOG 20:29:31.775] AssemblyLoader: Loading assembly at H:\1.1 Dev\GameData\Squad\Plugins\KSPSteamCtrlr.dll
[ERR 20:29:31.777] Failed to load assembly H:\1.1 Dev\GameData\Squad\Plugins\KSPSteamCtrlr.dll:
System.UnauthorizedAccessException: Access to the path "H:\1.1 Dev\GameData\Squad\Plugins\KSPSteamCtrlr.dll" is denied.
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode) [0x00000] in <filename unknown>:0 
  at AssemblyLoader.LoadExternalAssembly (System.String file) [0x00000] in <filename unknown>:0 

I didn't have this issue on previous versions and I'm pretty sure I've set the security settings so that Users (as well as Administrators) have full control of the KSP folder.

This is on Windows 7 64-bit and both KSP 32 and 64 bit display the same behavior.

Anyone have any ideas? Having to run KSP.exe as administrator every time I want to run it will quickly become a pain.

D.

Issue's fixed.

Edited by Diazo
Link to comment
Share on other sites

It's not just that .dll, there's 4 or 5 .dlls that come with KSP doing this, then any .dll files I make for my mods also do it so they never load.

That just happened to be the one I copied pasted as an example.

It has to be something to do with Windows security, but I'm totally stumped on what else I can try.

D.

Issue's fixed.

Edited by Diazo
Link to comment
Share on other sites

1 minute ago, Diazo said:

It's not just that .dll, there's 4 or 5 .dlls that come with KSP doing this, then any .dll files I make for my mods also do it so they never load.

That just happened to be the one I copied pasted as an example.

It has to be something to do with Windows security, but I'm totally stumped on what else I can try.

D.

Strange... I did exactly that.. took sveral copies of the steam folder for testing each of my mods. Nuked all the Steam files, folders, plugin.... 
Haven't had an issue. and on Win 7 64bit as well.

Link to comment
Share on other sites

Ugh, nothing to do with Windows, turns out it was my security software. Fixed now.

However, to actually contribute it appears that the old UI classes have been left in but are unused.

In flight mode, the FlightUIController class is still present but doesn't do anything and should no longer be referenced. Note that the class initializes and so a null check fails as it is present with it's defaults, they just never update. I assume the same is true for the Editor UI classes but I didn't actually check them tonight.  

Worth adding to the opening post?

 

To actually hook into the new UI I was unable to find an entry point to reference the on-screen objects but the templates can all be found in the KSP.UI namespace and they inherit from monobehavior so the FindObjectsOfType methods work on them.

You can see how I do this here to access the altitude tumbler at the top of the screen.

However, I need some help, how do I error trap this? When leaving the flight scene there is a race condition where the altitude tumbler can be destroyed but my mod still runs for a few update frames, is there a better way of handling this then the try/catch block I'm currently using?

I'll dig into some of my bigger mods tomorrow, LandingHeight was a nice and small one to get my feet wet.

D.

Apparently I just can't think straight tonight.

The FlightUIController.SpeedDisplayMode property is no longer used, having been replaced by FlightGlobals.SpeedDisplayMode which was the reason I though the entire class had been abandonded. However, it appears the FlightUIController class is in fact still valid, the FlightUIController.alt object is of the new KSP.UI type and appears to be the object I want to reference so the FindObjectsOfType method is not needed.

I'll do some more digging tomorrow and see if I can actually wrap my brain around this.

Edited by Diazo
Link to comment
Share on other sites

4 hours ago, Alewx said:

This little source already shows we why the assetbundles are now integrated.
The old system was so bad but never looked like soooo much work to just create a few basic windows.

Prefabs are fine if you have fixed UI so you can create it in advance in Unity Editor. If your UI is dynamic - you need some way of creating UI dynamically via code.

Link to comment
Share on other sites

One small thing I finally figured out in working to get my RenderTextures to show. I had been using KSP/Alpha/Unlit Transparent for materials I'd been writing to the RT. Shader.Find("KSP/Alpha/Unlit Transparent") doesn't throw an exception, but nothing will show up on the RT. I substituted Sprites/Default and that solved the problem.

Link to comment
Share on other sites

Is everyone going to use this single topic to discus module debugging moving forward or will we be creating new topics in this forum (until actual 1.1 release that is)?

Assuming option 1, I don't know what I'm doing, but I can't get my stuff to accept that there's a ConfigNode method to override, and all the new DLLs are linked in.  If I knew enough to look further I'd be annoyed or something, but I don't, which is probably the issue.  But I'm going to post a couple of questions here to clarify things for others.

32 vs 64 bit?  I notice the KSP_Data/Managed cache of DLLs comes in 32 and 64 bit flavours.  Do mods need to be compiled twice, once for 64bit and once for people with ancient kit?

What on Kerbin are these new fangled IDE things?  Related question: Can I rewrite my module in bash?

Is anyone interested in helping a C# n00b out with some code updating?  I can swap you some 3D modelling.

Not all questions are of equal seriousness.

Link to comment
Share on other sites

2 hours ago, kujuman said:

One small thing I finally figured out in working to get my RenderTextures to show. I had been using KSP/Alpha/Unlit Transparent for materials I'd been writing to the RT. Shader.Find("KSP/Alpha/Unlit Transparent") doesn't throw an exception, but nothing will show up on the RT. I substituted Sprites/Default and that solved the problem.

I dropped all the in-game Shader names to a text file here.
 

Link to comment
Share on other sites

3 hours ago, Ziw said:

Prefabs are fine if you have fixed UI so you can create it in advance in Unity Editor. If your UI is dynamic - you need some way of creating UI dynamically via code.

That is something I need in welding. Do you know something about the DefaultController.CreatePanel/Dropdown and so on?

Link to comment
Share on other sites

9 minutes ago, Alewx said:

That is something I need in welding. Do you know something about the DefaultController.CreatePanel/Dropdown and so on?

Take a look here There is a dynamic combo-box code somewhere there

Link to comment
Share on other sites

ScaledSpace.Instance.scaledSpaceTransforms is effectively gone (and probably good riddance).

If what you are after is the transform for a celestial body, it is very easy to get now: cb.MapObject.transform

Link to comment
Share on other sites

2 hours ago, TiktaalikDreaming said:

Is everyone going to use this single topic to discus module debugging moving forward or will we be creating new topics in this forum (until actual 1.1 release that is)?

Assuming option 1, I don't know what I'm doing, but I can't get my stuff to accept that there's a ConfigNode method to override, and all the new DLLs are linked in.  If I knew enough to look further I'd be annoyed or something, but I don't, which is probably the issue.  But I'm going to post a couple of questions here to clarify things for others.

32 vs 64 bit?  I notice the KSP_Data/Managed cache of DLLs comes in 32 and 64 bit flavours.  Do mods need to be compiled twice, once for 64bit and once for people with ancient kit?

What on Kerbin are these new fangled IDE things?  Related question: Can I rewrite my module in bash?

Is anyone interested in helping a C# n00b out with some code updating?  I can swap you some 3D modelling.

Not all questions are of equal seriousness.

There is a specific sub forum from mod dev and anything that is not specific to updating a mod to 1.1 should go there. You can use the 32 or 64 bit dlls to compile your mod and they will work on both arch.

The rest is giberish and I would rather see the post stay on topic.

Link to comment
Share on other sites

Some of my mods respond to a right-click on the toolbar button (stock toolbar)

It's not working anymore.  However, left-button clicks still work.

Here is the basic code.  First, this line adds the button to the toolbar:

TT_Button = ApplicationLauncher.Instance.AddModApplication (GUIToggleToolbar, GUIToggleToolbar,
					null, null,
					null, null,
					ApplicationLauncher.AppScenes.SPACECENTER,
					TT_button_img);

and here is the function (simplified):

		public void GUIToggleToolbar ()
		{
			//GUIToggle (true);
			Log.Info("GUIToggleToolbar");
			//stockToolBarcreated = true;
			if (Input.GetMouseButtonUp (1)) {
				//onRightButtonStockClick ();
				configDisplayActive = !configDisplayActive;
				if (configDisplayActive) {
					SetConfigVisible (true);
					cfgWinData = false;
				}
			}
		}

What I saw by adding the Log.Info line, is that the toolbar is not passing right-clicks to the function.

Edit:  clarification:  The function is not called at all when I right-click on the tool-bar button

Is this a bug, or a change in the functionality?

Thanks

Edited by linuxgurugamer
Link to comment
Share on other sites

1 hour ago, linuxgurugamer said:

What I saw by adding the Log.Info line, is that the toolbar is not passing right-clicks to the function.

Do you mean that right-clicks don't cause the function to be called at all or just that Input.GetMouseButtonUp(1) returns false?

Link to comment
Share on other sites

I'm trying to get ahold of the NavBall object.  I see it's been relocated to KSP.UI.Screens.Flight.NavBall, but the method I used to use to fetch it isn't working.

FlightUIController.fetch.GetComponentInChildren<NavBall>();

This is called from a VesselModule descendant's Start() method.  FlightUIController.fetch is null.  Should I be looking somewhere else to get a reference to the object?

 

Link to comment
Share on other sites

9 minutes ago, MOARdV said:

I'm trying to get ahold of the NavBall object.  I see it's been relocated to KSP.UI.Screens.Flight.NavBall, but the method I used to use to fetch it isn't working.


FlightUIController.fetch.GetComponentInChildren<NavBall>();

This is called from a VesselModule descendant's Start() method.  FlightUIController.fetch is null.  Should I be looking somewhere else to get a reference to the object?

 

You might want to try looking in KSP.UI.Screens.Flight
NavBallBurnVector has a public NavBall object.

Link to comment
Share on other sites

6 minutes ago, JPLRepo said:

You might want to try looking in KSP.UI.Screens.Flight
NavBallBurnVector has a public NavBall object.

I see that, but how do I get an instance of it?  What do I use instead of FlightUIController.fetch to get to the UI instance is what I think I'm trying to ask.

Link to comment
Share on other sites

7 minutes ago, MOARdV said:

I see that, but how do I get an instance of it?  What do I use instead of FlightUIController.fetch to get to the UI instance is what I think I'm trying to ask.

FlightGlobals.SpeedDisplayMode

@Diazo found it above.

 

Link to comment
Share on other sites

5 minutes ago, JPLRepo said:

FlightGlobals.SpeedDisplayMode

@Diazo found it above.

 

Ah, okay.  I knew I had seen something like that around here, but it didn't show up when I searched for it.  Thank you.

Link to comment
Share on other sites

Okay. Now that I'm actually looking at this when I'm not tired from staying up late, I can confirm that in flight mode, the FlightUIController class is still present but doesn't do anything and should no longer be referenced. Note that the class initializes and so a null check fails as it is present with it's defaults, they just never update. I assume the same is true for the Editor UI classes but I didn't actually check them. (Not sure of the class name.) 

To actually hook into the new UI I was unable to find an entry point to reference the on-screen objects but the templates can all be found in the KSP.UI namespace and they inherit from monobehavior so the FindObjectsOfType methods work on them and as each UI element has its own class it's reasonably straightforward as each element is named so you can figure out what it does.

You can see how I do this here to access the altitude tumbler at the top of the screen. Note that I'm caching the reference, FindObejctsOfType takes a long time to run and it shouldn't be running more then it has to.

However, I need some help, how do I error trap this? When leaving the flight scene there is a race condition where the altitude tumbler can be destroyed but my mod still runs for a few update frames, is there a better way of handling this then the try/catch block I'm currently using?

@MOARdVThe FlightGlobals.SpeedDisplayMode is just to see what the speed indicator above the navball displays (Surface, Orbit, or Target), it doesn't actually get you any UI element references.

D.

Link to comment
Share on other sites

Just now, Diazo said:

@MOARdVThe FlightGlobals.SpeedDisplayMode is just to see what the speed indicator above the navball displays (Surface, Orbit, or Target), it doesn't actually get you any UI element references.

D.

I saw that, but I also saw how you were getting the UI element in that code snippet on GitHub.  That same approach works for the NavBall object, so the your post indirectly helped me solve my problem (and it also pointed out that I needed to use FlightGlobals for speedDisplayMode).

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...