Cephei

The official unoffical "help a fellow plugin developer" thread

Recommended Posts

Hello KSPUtil is no more needed? I don't find it on the pre-release (GNU/Linux)

Edited by Malah

Share this post


Link to post
Share on other sites
1 minute ago, Malah said:

Hello KSPUtil is no more needed? I don't find it on the pre-release (GNU/Linux)

Correct. Here is the official notes:

and discuss 1.2 modding in that forum.

  • Like 1

Share this post


Link to post
Share on other sites
12 hours ago, katateochi said:

I'm still very new writing KSP plugins, when you say take a look at the definition, where should I be looking?

Both MonoDevelop and Visual Studio will show you the definition via autocomplete.. just start typing the name and it should pop up.  There may be a better way in the IDE to browse them, I don't know.

Most of the online documentation is out of date shortly after it's written/scraped.  The IDE is the best source of truth.  I just skim the online docs as a vague reference to find likely class names.

EDIT: I just saw that with1.2, there are official API docs!  Woohoo!  Check out https://kerbalspaceprogram.com/api/index.html

Edited by hab136

Share this post


Link to post
Share on other sites

@hab136 I'm using Monodevelop. 
Yeah just saw that the official API was now public. Joy! First thing I noticed was that there's an XKCDColors class, lol. 

Share this post


Link to post
Share on other sites
6 hours ago, katateochi said:

@hab136 I'm using Monodevelop. 
Yeah just saw that the official API was now public. Joy! First thing I noticed was that there's an XKCDColors class, lol. 

For those who don't know the page : https://xkcd.com/color/rgb/

  • Like 2

Share this post


Link to post
Share on other sites

New to KSP modding and C#/Unity platform in general. Is there any good way to conditionally reference KSPUtil to maintain backward compatibility?

Share this post


Link to post
Share on other sites
2 minutes ago, kball said:

New to KSP modding and C#/Unity platform in general. Is there any good way to conditionally reference KSPUtil to maintain backward compatibility?

I don't think there's much reason to do that.  The API has changed, and you should really only be trying to build against one version of KSP.

Share this post


Link to post
Share on other sites

Ok, definitely down with that. Just wasn't sure if the references would break if building against 1.2 but running in 1.1.3. Should have tested that before posting, but testing now.

Edit: Doesn't seem like that works. So we need to branch our plugins for the new version? Can that be right?

Edited by kball

Share this post


Link to post
Share on other sites
18 hours ago, kball said:

Ok, definitely down with that. Just wasn't sure if the references would break if building against 1.2 but running in 1.1.3. Should have tested that before posting, but testing now.

Edit: Doesn't seem like that works. So we need to branch our plugins for the new version? Can that be right?

Yes, I also use a branch when I want to keep support of an old version, but it's often useless (I've only keep support of KSP 1.0.5 because KSP 1.1.X wasn't stable on GNU/Linux), with KSP 1.2, I think I can drop support of KSP 1.0.5.

On Monodevelop, when I read the Assembly-CSharp I see many private var which have strange character like a square with numbers. Can we access to these var with reflection?

Exemple: for my mod QuickHide I work on the ApplicationLauncher, I've read the new API doc and I've found this:

List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appList = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListHidden = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListMod = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListModHidden = new List<ApplicationLauncherButton>()
	private

and in Monodevelop I read this:

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> 	;

Source: https://kerbalspaceprogram.com/api/class_k_s_p_1_1_u_i_1_1_screens_1_1_application_launcher.html

Can I use appListMod in reflection?

Share this post


Link to post
Share on other sites
9 minutes ago, Malah said:

Yes, I also use a branch when I want to keep support of an old version, but it's often useless (I've only keep support of KSP 1.0.5 because KSP 1.1.X wasn't stable on GNU/Linux), with KSP 1.2, I think I can drop support of KSP 1.0.5.

On Monodevelop, when I read the Assembly-CSharp I see many private var which have strange character like a square with numbers. Can we access to these var with reflection?

Exemple: for my mod QuickHide I work on the ApplicationLauncher, I've read the new API doc and I've found this:


List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appList = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListHidden = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListMod = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListModHidden = new List<ApplicationLauncherButton>()
	private

and in Monodevelop I read this:


private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> 	;

Source: https://kerbalspaceprogram.com/api/class_k_s_p_1_1_u_i_1_1_screens_1_1_application_launcher.html

Can I use appListMod in reflection?

Not according to the rules you can't. Refer to rule 7 of the Add-On rules:

A better question would be why? the API for the Application Launcher contains public methods and vars to facilitate a mod integrating into that class.

Edited by JPLRepo
  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, JPLRepo said:

Not according to the rules you can't. Refer to rule 7 of the Add-On rules:

A better question would be why? the API for the Application Launcher contains public methods and vars to facilitate a mod integrating into that class.

I wanted to use this var to access and hide others mods applauncher :wink:

At this time I use

ApplicationLauncherButton[] _appLauncherButtons = (ApplicationLauncherButton[])Resources.FindObjectsOfTypeAll (typeof (ApplicationLauncherButton));

 

Share this post


Link to post
Share on other sites

No, the private fields name are obfuscated on build and could differ between Windows/OSX/Linux

  • Like 1

Share this post


Link to post
Share on other sites
On 7/12/2016 at 9:09 AM, Papa_Joe said:

The reason I do not use the class @Tralfagar mentioned is 1)  It did not exist when these mods were created, and 2), it does not give me sufficient resolution for my needs.  The class works just fine, but does not give you the ability to pick a specific seat, nor does it allow for crew swaps.  In ShipManifest, I account for both.  Therefore I've continued to use the method similar to CrewManifest, but with several enhancements.  ShipManifest will allow seat to seat transfers within the same part, and part to part transfers (including swapping crew members if the seat/part is full in both cases).  Additionally, in Realism mode, I've also included sounds and a delay to simulate the time needed to move from part to part or seat.

Additionally, I've included support for ConnectedLivingSpace, When in realism mode and with CLS enalbled within SM, transfers now respect whether or not the parts have an internal connection to each other. if not, then the transfer must be accomplished by EVA.  hmm... you gave me an idea.  if you cannot transfer internally, I could change the xfer button to initiate an eva instead...

 

Update.  I've added the capability to send a Kerbal EVA in realism mode if CLS prevents an internal transfer.  I will be releasing this feature soon in a point upgrade.   thanks for giving me this great idea.

@Tralfagar feel free to look over and leverage any of the code you see of value in SM.  I hope it helps you in some small way.  

@Papa_Joe

I'm having an issue where I am getting the kerbal EVA'd, but need to eject him, ie:  not have him holding on to the ship.  

I'm using this:

FlightEVA.fetch.spawnEVA(kerbal, p, p.airlock)

but, when I do this:

 FlightGlobals.Vessels[i].rootPart.Rigidbody.AddForce(FlightGlobals.Vessels[i].rootPart.transform.up * ejectionForce);

it doesn't seem to do anything, the kerbal stays attached.

Any ideas?

Share this post


Link to post
Share on other sites
6 minutes ago, linuxgurugamer said:

Any ideas?

You can no longer use AddForce directly, you must do what it says in the thread about the changes in 1.2.

Search for AddForce.  Basically, you need to call Part.AddForce rather than calling the RigidBody directly.

Also, I suspect there is a better way to make him let go of the hatch than smacking him with an invisible hammer... :wink:

Edited by Padishar

Share this post


Link to post
Share on other sites
2 minutes ago, Padishar said:

You can no longer use AddForce directly, you must do what it says in the thread about the changes in 1.2.

Search for AddForce.  Basically, you need to call Part.AddForce rather than calling the RigidBody directly.

Thanks.

I'm resurrecting EVA Parachutes, and fixing a couple of problems also

Share this post


Link to post
Share on other sites

I am trying display a list of parts but when I try to use Part.partName it just says "Part" for all of them.

Here is what I have

using System;
using System.Collections.Generic;
using UnityEngine;
using KSP;

namespace AutoAbortSystem
{
    public class ModuleAAS : PartModule
    {
        List<ModuleAAS> AASmodules = new List<ModuleAAS>();
        List<Part> parts = new List<Part>();
        public void Start()
        {

        }

        public void Update()
        {
            parts.Clear();
            AASmodules.Clear();
            foreach(Part part in FlightGlobals.ActiveVessel.parts)
            {
                parts.Add(part);
                if (part.gameObject.GetComponent<ModuleAAS>()) AASmodules.Add(part.GetComponent<ModuleAAS>());
            }
        }

        public void OnGUI()
        {
            if(this == AASmodules.ToArray()[0]) GUILayout.Window(616173, new Rect(100,100,350,800), window, "Automatic Abort System", HighLogic.Skin.window);
        }

        public void window(int windowID)
        {
            foreach (Part part in parts)
            {
                if (part != this.part) GUILayout.Label(part.partName);
                else GUILayout.Label(part.partName + " (active)");
            }
        }

        public void OnDestroy()
        {
            AASmodules.Remove(this);
        }


    }
}

4W5v48y.png

Am I doing something wrong or is this a bug?

Share this post


Link to post
Share on other sites
5 minutes ago, JoePatrick1 said:

I am trying display a list of parts but when I try to use Part.partName it just says "Part" for all of them.

Here is what I have

<snip>

Am I doing something wrong or is this a bug?

You want the part.partInfo.title or part.name

Share this post


Link to post
Share on other sites
1 hour ago, linuxgurugamer said:

Thanks.

I'm resurrecting EVA Parachutes, and fixing a couple of problems also

What @Padishar said. It's Underlined for a reason. Do not apply forces directly to rigidbodies. that is the job of the FlightIntegrator

Share this post


Link to post
Share on other sites
1 minute ago, JPLRepo said:

What @Padishar said. It's Underlined for a reason. Do not apply forces directly to rigidbodies. that is the job of the FlightIntegrator

Like I said, this is a mod I'm reviving, and this was some old code.

Thanks for the info.

Share this post


Link to post
Share on other sites
1 minute ago, linuxgurugamer said:

Like I said, this is a mod I'm reviving, and this was some old code.

Thanks for the info.

NPs. I wasn't having a dig at you. Just for everyone's benefit. It's really important. Or bad things will happen.

Share this post


Link to post
Share on other sites
Just now, JPLRepo said:

NPs. I wasn't having a dig at you. Just for everyone's benefit. It's really important. Or bad things will happen.

No offense taken

Any idea how to have a partmodule on an unfocused ship (but still close by) to continue to work?

Share this post


Link to post
Share on other sites
20 minutes ago, linuxgurugamer said:

Any idea how to have a partmodule on an unfocused ship (but still close by) to continue to work?

Normal update methods should be run for any part on a vessel within physics range.  Is there a case where that doesn't seem to be happening?

Share this post


Link to post
Share on other sites
Just now, blowfish said:

Normal update methods should be run for any part on a vessel within physics range.  Is there a case where that doesn't seem to be happening?

That's what I thought.  

I'm EVA'ing a number of kerbals, and having a chute open up after they eva.  It isn't working for some of them, so it's something in the code.

This is the EVA Parachute mod I'm reviving

Also, my understanding is that spawnEVA will spawn the kerbal and make the kerbal the active vessel.

Will this also happen if you do a spawnEVA on a vessel which isn't the active vessel?

Share this post


Link to post
Share on other sites

Well, Update is running, so I need to figure out what else is going on.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now