Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

1 hour ago, TaxiService said:

Let's say I create a subclass 'SheepVesselModule' based on the KSP's existing class 'VesselModule'. Then, I just compile and launch KSP without any further action. I observe that the KSP actually accepts and integrates my "orphan" class into every existing vessel. It even calls some methods like Start() too.

Is this one of the Unity's strengths, or I misinterpret the result?

Well, it's how the VesselModule mechanism in KSP has been implemented.  Basically, after loading all mod assemblies, KSP enumerates all the classes that are derived from VesselModule and will then create one of each for every vessel that's loaded.  Squad implemented it like this to make it easy for mod authors to create VesselModules.

Edited by Padishar
Link to comment
Share on other sites

58 minutes ago, TaxiService said:

Let's say I create a subclass 'SheepVesselModule' based on the KSP's existing class 'VesselModule'. Then, I just compile and launch KSP without any further action. I observe that the KSP actually accepts and integrates my "orphan" class into every existing vessel. It even calls some methods like Start() too.

Is this one of the Unity's strengths, or I misinterpret the result?

KSP finds all subclasses of VesselModule and adds them to all vessels.  Once they're added to a vessel, they will get normal unity methods like Start() called, and also some KSP-specific methods.

Link to comment
Share on other sites

When/how to proper call:

Game.AddProtoScenarioModule (MyScenarioModule, SomeGameScenes) .

 

This is approximately the life of a custom scenario module (as far as I can tell):

  • When I call Game.AddProtoScenarioModule I can add, say, "MyScenarioModule".
  • The module is added to the game right away, so far so good.
  • When the scene is changed (exited) the module will be included in the .sfs file.
  • When the next scene is loaded OnLoad is called to take care of what ever I need to take care of.
  • When the scene is then changed again (exited) OnSave is called. At this point the .sfs file is all up to date.

 

The idea that I just have to call AddProtoScenarioModule in-game once and in the future KSP sees from the .sfs file that it should load up "MyScenarioModule" is nice.

The issue I ponder, is the 'delay' from you first add the scenario module (some time after the game is first spawned) and until the .sfs is updated with all saved values (after two scene changes) . How do you prefer to handle that?

 

Edited by Rodhern
line feed
Link to comment
Share on other sites

2 hours ago, Rodhern said:

he idea that I just have to call AddProtoScenarioModule in-game once and in the future KSP sees from the .sfs file that it should load up "MyScenarioModule" is nice.

Hum, You should not call that. Your scenario should have the KSPScenario attribute and the game handles it for you.

Link to comment
Share on other sites

I'm having trouble finding the KSPCore.dll file so I can use it as a reference in my Visual Studio project. I think it's supposed to be at this location:

    "Kerbal Space Program\KSP_x64_Data\Managed\KSPCore.dll"

but I can't find it there. My KSP runs fine though. Where could the KSPCore.dll be?

Edited by delta wee
Link to comment
Share on other sites

15 minutes ago, delta wee said:

I'm having trouble finding the KSPCore.dll file so I can use it as a reference in my Visual Studio project. I think it's supposed to be at this location:

    "Kerbal Space Program\KSP_x64_Data\Managed\KSPCore.dll"

but I can't find it there. My KSP runs fine though. Where could the KSPCore.dll be?

KSPCore, KSPUtil, and a couple of other DLLs were removed in KSP 1.2 (KSPCore didn't really contain much anyway).  Their contents are now in Assembly-CSharp.  You can safely remove the references.

Link to comment
Share on other sites

3 hours ago, blowfish said:

KSPCore, KSPUtil, and a couple of other DLLs were removed in KSP 1.2 (KSPCore didn't really contain much anyway).  Their contents are now in Assembly-CSharp.  You can safely remove the references.

Ah, thanks. I guess dll changes like that between KSP versions would explain why so many mods break when a new version comes out.

Link to comment
Share on other sites

Hey, everyone. I'm new to modding KSP, tho I did manage to include a few (working!) lines on someone else's code already. Now I got a few projects of my own, and the one that seemed the very simplest is already giving me a headache.

Does anyone know how to access the list of checks that the Engineer's Report performs?

I checked here, and the thing is private: even if I extend the class, I can't get to it :(

Link to comment
Share on other sites

1 hour ago, monstah said:

Hey, everyone. I'm new to modding KSP, tho I did manage to include a few (working!) lines on someone else's code already. Now I got a few projects of my own, and the one that seemed the very simplest is already giving me a headache.

Does anyone know how to access the list of checks that the Engineer's Report performs?

I checked here, and the thing is private: even if I extend the class, I can't get to it :(

What are you trying to do with the Engineer's report checks?
Add your own checks? or something else?

 

Link to comment
Share on other sites

18 minutes ago, JPLRepo said:

What are you trying to do with the Engineer's report checks?
Add your own checks? or something else?

Something else. I know the Report has methods for adding new checks, but I want to iterate over the existing ones. I want to figure out what the maximum warning level being noticed (i.e., if there is at least one Critical, otherwise at least one Warning, or one Notice, or none at all).

Link to comment
Share on other sites

8 minutes ago, monstah said:

Something else. I know the Report has methods for adding new checks, but I want to iterate over the existing ones.

Yeah you can't as existing tests are private.
All you can really do is add and remove your own tests.

Link to comment
Share on other sites

  • 2 weeks later...

Anyone know if floatcurve fields auto load like other fields. Looking through modulecolorchanger I didn't see any see any special code for parsing on load. The curve seems to load when I declare the field in this way. But, when I evaluate the curve, no mater what time arg is given, it always returns 0.

 

 

 

Link to comment
Share on other sites

3 hours ago, Bonus Eventus said:

Anyone know if floatcurve fields auto load like other fields. Looking through modulecolorchanger I didn't see any see any special code for parsing on load. The curve seems to load when I declare the field in this way. But, when I evaluate the curve, no mater what time arg is given, it always returns 0.

It will be automatically loaded if the field is not null when loading happens.  The most common thing to do is to initialize the field with an empty float curve:

[KSPField]
public FloatCurve animCurve = new FloatCurve();

If it's not initialized, it won't be loaded.  I'm not exactly sure if it will stay null forever if you don't create one though, it's possible Unity puts an empty one there at some point (which would probably evaluate to zero)

Link to comment
Share on other sites

19 minutes ago, blowfish said:

It will be automatically loaded if the field is not null when loading happens.  The most common thing to do is to initialize the field with an empty float curve:


[KSPField]
public FloatCurve animCurve = new FloatCurve();

If it's not initialized, it won't be loaded.  I'm not exactly sure if it will stay null forever if you don't create one though, it's possible Unity puts an empty one there at some point (which would probably evaluate to zero)

Wow, that was totally it, just tested it. Earlier today I was reading your post about UI_Controls and onFieldChange (which blew my mind) and now you're helping me again. Thanks @blowfish

Link to comment
Share on other sites

With the new update of KSP, CompatibilityChecker.cs is throwing a stack overflow when running in debug mode.  I'm using debug as Sarbian described here:

 

(top 3 lines repeat over and over)

    UnityEngine.RectTransform:get_rect()
    TMPro.TextMeshProUGUI:ComputeMarginSize()
    TMPro.TextMeshProUGUI:OnRectTransformDimensionsChange()

    UnityEngine.RectTransform:get_rect()
    TMPro.TextMeshProUGUI:ComputeMarginSize()
    TMPro.TextMeshProUGUI:OnRectTransformDimensionsChange()
    UnityEngine.RectTransform:set_anchorMax(Vector2)
    PopupDialog:SpawnPopupDialog(Vector2, Vector2, MultiOptionDialog, Boolean, UISkinDef, Boolean, String)
    PopupDialog:SpawnPopupDialog(Vector2, Vector2, String, String, String, Boolean, UISkinDef, Boolean, String)
    LunaClient.Utilities.CompatibilityChecker:Start() (at C:/shared/kerbal space program/LunaMultiPlayer/Client/Utilities/CompatibilityChecker.cs:166)

 

This is happening inside a compatibility checker by Majiir.  Should I contact him to fix it?  Is he around anymore?  It's easily worked around by simply updating my program to contain the new version, so it doesn't spawn the popup anymore.

This is the line that causes the problem:

PopupDialog.SpawnPopupDialog(new Vector2(0, 0), new Vector2(float.PositiveInfinity, float.PositiveInfinity), "Incompatible Mods Detected", message, "OK", true, HighLogic.UISkin);

 

Code that's causing the error (although you shouldn't need it)

https://github.com/DaggerES/LunaMultiPlayer/blob/master/Client/Utilities/CompatibilityChecker.cs

 

Edited by Lothsahn
Link to comment
Share on other sites

13 hours ago, Lothsahn said:

Hopefully a simple noob question, but does anyone know where KSPUtil.PrintTimeCompact(double time, bool explicitPositive) went to?

It's still there, but KSPUtil.dll has been folded into Assembly-CSharp.dll. You just need to remove your references to KSPUtil.dll (and probably recompile against 1.2.x)

Edited by severedsolo
Link to comment
Share on other sites

Actually, the KSPUtil class and assembly were two different things. The KSPUtil class, which had all of the time printing methods was always in in Assembly-CSharp, so if you have that error it might be caused by something else.

Link to comment
Share on other sites

Did something happen to the float custom game parameter in 1.2.2?

The following line works fine in 1.2.1, creating a slider in the settings menu that moved smoothly from 0.5 - 2.5 and displayed values from 50 - 250%.

[GameParameters.CustomFloatParameterUI("Base Scale", minValue = 0.5f, maxValue = 2.5f, displayFormat = "P0", autoPersistance = true)]
		public float baseScale = 1.25f;

But in 1.2.2 any attempt to change the slider causes this error:

[EXC 01:29:50.877] FormatException: Unknown char
	System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider)
	System.Single.Parse (System.String s)
	DifficultyOptionsMenu+<CreateDifficultWindow>c__AnonStorey15D.<>m__24B (Single v)
	UnityEngine.Events.InvokableCall`1[System.Single].Invoke (System.Object[] args)
	UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters)
	UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters)
	UnityEngine.Events.UnityEvent`1[System.Single].Invoke (Single arg0)
	UnityEngine.UI.Slider.Set (Single input, Boolean sendCallback)
	UnityEngine.UI.Slider.Set (Single input)
	UnityEngine.UI.Slider.set_value (Single value)
	DialogGUISlider.Update ()
	DialogGUIBase.Update ()
	DialogGUIVerticalLayout.Update ()
	DialogGUIBase.Update ()
	DialogGUIVerticalLayout.Update ()
	DialogGUIBase.Update ()
	DialogGUIBase.Update ()
	DialogGUIVerticalLayout.Update ()
	DialogGUIBase.Update ()
	MultiOptionDialog.Update ()
	PopupDialog.Update ()

The offending part seems to be the displayFormat = "P0". I have no idea why that would cause a problem.

I tried setting the format to N0 and turning asPercentage to true, but then the slider only allowed for integer values (1 or 2), though it did display the percentage correctly.

Is there something I'm missing? Do I have to set the stepCount to some specific value?

Link to comment
Share on other sites

@DMagic - looks like I inadvertently broke this will adding rounding in to fix another issue.  I tried to be clever and round using the display format, which doesn't work with the P0 display format (because Float.Parse() doesn't have smarts to recognize a percentage).

As a workaround, try using N1 + asPercentage.

Link to comment
Share on other sites

Alright, I'm taking my first baby steps trying to figure out the new GUI and have what should be a straightforward question.

In hooking up to an asset bundle, what does this string do?

infoKSP = go.GetComponentInChild<Text>("KSP");   (Example pulled from Sarbian's GC monitor.)

I am referring to the "KSP" string here.

I think I have the rest of that line of code figured out, in that I can find a valid Text object if I just use .GetComponentInChild<Text>(), but my test GUI only has a single Text object on it and I assume this is how you tell different objects apart.

Note I have never used Unity before, I had to download it to make this test GUI assetbundle so it is probably something really simple, I just don't know Unity or where to find it.

D.

Link to comment
Share on other sites

13 minutes ago, Diazo said:

Alright, I'm taking my first baby steps trying to figure out the new GUI and have what should be a straightforward question.

In hooking up to an asset bundle, what does this string do?

infoKSP = go.GetComponentInChild<Text>("KSP");   (Example pulled from Sarbian's GC monitor.)

I am referring to the "KSP" string here.

I think I have the rest of that line of code figured out, in that I can find a valid Text object if I just use .GetComponentInChild<Text>(), but my test GUI only has a single Text object on it and I assume this is how you tell different objects apart.

Note I have never used Unity before, I had to download it to make this test GUI assetbundle so it is probably something really simple, I just don't know Unity or where to find it.

D.

My UI is a game object with many children. One of those children is an object named "KSP" (in the tree to the left of the Unity Editor)  that contains a Text component. That call get a reference to that child.

You could also search your object by tag.

@DMagic wrote an awesome tutorial :

 

Link to comment
Share on other sites

I have been using DMagic's tutorial and it's the only reason I've gotten as far as I have.

However, that tutorial uses the 2 Assemblies method where there's a dedicated GUI assembly where you hook up the methods to the objects in the Unity editor itself, so the tutorial doesn't actually cover hooking up to objects directly via code as you do in GC Monitor.

Also, that explains what I was missing, I was changing settings on the Text component itself trying to get this to work, not the GameObject the Text is attached to.

Should be straightforward now, thanks for the help Sarbian.

D.

Edited by Diazo
Link to comment
Share on other sites

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