Cephei

The official unoffical "help a fellow plugin developer" thread

Recommended Posts

Hello everyone,
I have decided to expand from writing ModuleManager patch code to something more serious, C#.
I think I may have mistaken the title for this thread but I will give this a punt anyways.
I am looking for someone to help me make sure I have Visual Studio (just downloaded it today, VS Community 2017 - aka the free one) ready for KSP mod making.
I have read a few of the hits I got when searching for this, and well I found them a little dated.
To recap. At this stage I am looking to make sure I have all the goodies and setting right in order to be able to write source code, or load someone elses in and have a go.

Edited by Apaseall

Share this post


Link to post
Share on other sites

@Apaseall So what you're going to want to do is make a new solution, create a new project inside of that, and set it to compile to a project library (.dll). You're free to start developing your plugin at that point. I'd recommend following this tutorial (pinned at the top of this subforum).  As always, we're more than happy to help you out if you need anything!

 

  • Like 1

Share this post


Link to post
Share on other sites
38 minutes ago, Benjamin Kerman said:

@Apaseall So what you're going to want to do is make a new solution, create a new project inside of that, and set it to compile to a project library (.dll).

I'd strongly recommend trying it with someone else's already working project first (all KSP mods have source code available). That way you know that any problems you encounter are in your environment setup rather than in the code. Then once you're able to compile an existing mod, you can start your own project confident that all the problems are in the new code.

  • Like 2

Share this post


Link to post
Share on other sites

At this point I am more concerned with making sure I have all the things I need to get started.
For example it was not overly clear that I needed to add the .NET part to VS.
Yes I read that I need to add the Unit part.
But when I came to set the class I was trying to find Installed > Templates > Visual C# > Windows  from here :https://wiki.kerbalspaceprogram.com/wiki/Setting_up_Visual_Studio

Later when trying to download DevHelper from here:https://steamcommunity.com/sharedfiles/filedetails/?id=435932924

Then trying to speed up load time by deleting stuff from /squad/parts and /squad/spaces, also found in the steam link just above.

Here is a different question.
I see I have a folder called Unity 2018.1.6f1 (64-bit).
But does that refer to KSP 1.5 only?
I want to still work on stuff in 1.4.5.
Will I have to do something interesting to be able to do that?

Share this post


Link to post
Share on other sites
On 10/19/2018 at 1:04 AM, Apaseall said:

At this point I am more concerned with making sure I have all the things I need to get started.

This all assumes you are writing a plugin (I have literally no experience making parts) and are running Windows. (warning - image heavy)

Diazo's thread does cover this, but this is more specific to VS 2017.

First make sure you have .Net Framework 3.5 installed (you can do this through "turn Windows Features on or off")

In Visual Studio Installer you need to install the.Net Desktop Environment

feoiUEN.png

Then, in Individual Components, you install .Net Framework 3.5 development tools (this will not show up if you don't have .Net 3.5 installed)

svlee0e.png

Once that's installed, Start up VS and click File>New>Project

Select Class Library (.Net Framework) and select .Net Framework 3.5 at the bottom.

FBk1hpe.png

Once your solution has been created/loads, in your Solution Explorer right click on "references" then click "Add Reference"

Click on Browse

Navigate to <Your KSP folder>/KSP_x64 data/Managed

Select (using CTRL to select multiple if necessary) Assemble-Csharp.dll, Assembly-Csharp-firstpass.dll, UnityEngine.dll, UnityEngineUI.dll - then click Add, Then OK.

At this point your solution is ready, and you can use the the link provided by Benjamin Kerman as a guide to create the type of mod you want.

Quote

I see I have a folder called Unity 2018.1.6f1 (64-bit).
But does that refer to KSP 1.5 only?

No. KSP is using 2017.1.3p1 - if you want to use the Debug Tools in this thread you will need to install the same version of Unity. You won't need to change your Unity version for 1.4.5/1.5 as they use the same version. If KSP updates Unity again in the future, you will need to update this. Incidentally, you can always check what version of Unity KSP is using, by looking at your output_log file. There will be a line that says something like: Initialize engine version: 2017.1.3p1

Edited by severedsolo
  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, severedsolo said:

This all assumes you are writing a plugin (I have literally no experience making parts) and are running Windows. (warning - image heavy)

First make sure you have .Net Framework 3.5 installed (you can do this through "turn Windows Features on or off")

Yes I plan on making and or editing plugins.
.Net Framework exists as at least 3.5 and 3.5.1, there is also something about service pack 1?
Therefore when you write 3.5 which version do you mean?

Share this post


Link to post
Share on other sites
On 10/19/2018 at 1:04 AM, Apaseall said:

 

 

36 minutes ago, Apaseall said:

Yes I plan on making and or editing plugins.
.Net Framework exists as at least 3.5 and 3.5.1, there is also something about service pack 1?
Therefore when you write 3.5 which version do you mean?

Bah stupid indestructible quote boxes. Just go into "turn windows features on or off" and tick the box next to. Net Framework 3.5 (including 2.0) - on mobile so can't check exact name, but that's the gist. Windows will then get the latest version for you.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, severedsolo said:

Bah stupid indestructible quote boxes. Just go into "turn windows features on or off" and tick the box next to. Net Framework 3.5 (including 2.0) - on mobile so can't check exact name, but that's the gist. Windows will then get the latest version for you.

On my PC in the place mentioned I only see .Net 3.5.1. It has a blue square box next to it. It expands to show two sub options; Windows Communication Foundation HTTP Activation and Windows Communication Foundation non-HTTP Activation. Both of those are not ticked.
I presume that I do not need those sub options.
But I am right back to asking 3.5? This does not exist for me. 3.5.1 does.
Do I need to download and install .Net 3.5, which I have a download file called detNetFx35setup.exe?
I am not sure how sensitive "IT" is to version, i.e. will 3.5.1 produce odd behavior, or is it ok to use any 3.5.x version?

Edited by Apaseall

Share this post


Link to post
Share on other sites
27 minutes ago, maja said:

Guys, I'm at lost here. I'm trying for three days to save a position of a PopupDialog (like @HebaruSan does this in his Astrogator mod), but to no avail. Can some look at my code and tell me, what's wrong there?

Source code is here: https://github.com/jarosm/KSP-BonVoyage/tree/devel/BonVoyage

Do you mean save it between sessions, or during the same session? If the former, you'd have to save and load MainWindowModel.MainWindowPosition to/from a file somewhere. The Settings object does that for Astrogator:

https://github.com/HebaruSan/Astrogator/blob/0bb22564957534be0b27e7c36780b5c87427b734/src/Settings.cs#L18-L40

There may be ways to create an object that the core game will auto-save/load for you, but I haven't worked with them.

Share this post


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

Do you mean save it between sessions, or during the same session? If the former, you'd have to save and load MainWindowModel.MainWindowPosition to/from a file somewhere. The Settings object does that for Astrogator:

https://github.com/HebaruSan/Astrogator/blob/0bb22564957534be0b27e7c36780b5c87427b734/src/Settings.cs#L18-L40

There may be ways to create an object that the core game will auto-save/load for you, but I haven't worked with them.

Right now I need to preserve it's position in the same scene when user closes the dialog and then opens it again. Persisting them between sessions will come later and it's not a problem (I know how to do it).

Maybe I'm missing something, but it seems, that the new values for the position are ignored and only the starting ones are used. I checked once more, that the new values are availaible when MultiOptionDialog needs them.

Share this post


Link to post
Share on other sites
41 minutes ago, maja said:

Right now I need to preserve it's position in the same scene when user closes the dialog and then opens it again. Persisting them between sessions will come later and it's not a problem (I know how to do it).

Maybe I'm missing something, but it seems, that the new values for the position are ignored and only the starting ones are used. I checked once more, that the new values are availaible when MultiOptionDialog needs them.

So MultiOptionDialog is just ignoring its Rect parameter? Sorry, I haven't seen that happen, and I don't see anything in your code that looks like it would cause that. Is it putting the window in the exact same spot every time?

Share this post


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

So MultiOptionDialog is just ignoring its Rect parameter? Sorry, I haven't seen that happen, and I don't see anything in your code that looks like it would cause that. Is it putting the window in the exact same spot every time?

Yes, exactly in the same spot depending on the anchor parameters. It looks like the dialog's anchor point is always positioned to the center of the screen. Only the width and height of the dialog is changing. Just for the record, UI scale is 100%.

I tried your mod in my clear devel install of KSP before posting and it was behaving like expected. Where I leaved the window, there it was after reopening.

Share this post


Link to post
Share on other sites

@HebaruSan Progress. I tried once again that test dialog in Update event and it moved as expected. So there must be something wrong with that specific dialog I'm creating. Back to square one and create it from scratch with extensive position testing.

  • Like 1

Share this post


Link to post
Share on other sites

Just to wrap it up @HebaruSan. The problem was too small height of the MultiOptionDialog (the height value in the geometry Rect). The dialog was then streched vertically and position part of the geometry was omitted. Another quirk of the KSP API :)

  • Like 1

Share this post


Link to post
Share on other sites

How to add new runtime info-strings in the flight part-right-click menu for stock modules?
For example, some additional info for parts with ModuleScienceConverter and ModuleScienceLab?
Do I need to create a new module ModuleScienceInfo, attach to the parts using the ModuleManager, and work in the ModuleScienceInfo?

Edited by flart

Share this post


Link to post
Share on other sites
36 minutes ago, Benjamin Kerman said:

Try adding a [KSPField(guiActive = true, guiActiveEditor = true)] on a string that you won't change. 

I think the issue is changing an existing PartModule from the stock game.

Share this post


Link to post
Share on other sites

@Benjamin Kerman @0111narwhalz 

Yes, I can create a new PartModule, add to parts using MM-patch, create new fields in the code
using 
KSPField[guiActive = true], and filled the fields with whatever values I want. 

But It looks like overdoing for just showing few strings for an existing stock PartModule.

P. S.
a runrime strings, I mean they can change on Unity.update(), or at least, on some KSPEvent()

Edited by flart

Share this post


Link to post
Share on other sites

I wrote a PartModule with a sound effect in it. The sound doesn't fade with camera distance! I googled out something about AudioSource and AudioListener, but couldn't find any KSP related example. Any help? Thanks!

Share this post


Link to post
Share on other sites
4 hours ago, peteletroll said:

I wrote a PartModule with a sound effect in it. The sound doesn't fade with camera distance! I googled out something about AudioSource and AudioListener, but couldn't find any KSP related example. Any help? Thanks!

Figured it out! Must set AudioSource spatialBlend to 1.0f.

  • Like 1

Share this post


Link to post
Share on other sites

I have an issue with Visual Studio Community 2017 (v15.8.9). I had to reinstall the system and installed VS anew. Now, it doesn't open my mods projects because ".NET Framework 3.5 is not installed on this machine". In fact I have installed .NET dev pack 3.5 and .NET Runtime 3.5. I don't remember this problem in the past. What am I doing wrong?

Share this post


Link to post
Share on other sites

I think I saw another thread about this, so I'll pull a parrot and repeat what I saw there :P

Did you check the box that said something along the lines of 'install .NET frameworks>3.5'?

Share this post


Link to post
Share on other sites

Is there an elegant way to disable collisions for an entire vessel? Just setting the rigidbody detectCollisions false on all the parts of a vessel seems problematic (nullrefs are thrown).

Share this post


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

Is there an elegant way to disable collisions for an entire vessel? Just setting the rigidbody detectCollisions false on all the parts of a vessel seems problematic (nullrefs are thrown).

Try changing the collision layer?

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