Cephei

The official unoffical "help a fellow plugin developer" thread

2628 posts in this topic

If you have a question regarding the programming part, or anything really, i\'m sure there is someone out there that can help you. You don\'t have to make a new thread for a simple question, just post it here :)

Share this post


Link to post
Share on other sites

Great thread, I will use this frequently if you guys don\'t mind

using public override bool RequestFuel, however an error is returned:

'not all code paths return a value'

No idea what it means. :D

Share this post


Link to post
Share on other sites

Great thread, I will use this frequently if you guys don\'t mind

using public override bool RequestFuel, however an error is returned:

'not all code paths return a value'

No idea what it means. :D

i dont think anyone else (except devs and mods) know either

this thread will have 150% more people posting once the docs are up. before then no one will even really bother writing anything...

so i guess we\'ll just have to wait for now patiently for the big bang of new parts appearing out of nowhere ;P

hey anyone wanna team up with me?? i can write c++ (and c# doesnt look that different) but i have no clue about 3d designing and all that

would like to make some parts though and if you dont know programming.... :)

Share this post


Link to post
Share on other sites

i dont think anyone else (except devs and mods) know either

this thread will have 150% more people posting once the docs are up. before then no one will even really bother writing anything...

so i guess we\'ll just have to wait for now patiently for the big bang of new parts appearing out of nowhere ;P

hey anyone wanna team up with me?? i can write c++ (and c# doesnt look that different) but i have no clue about 3d designing and all that

would like to make some parts though and if you dont know programming.... :)

Haha, that\'s OK.

I guess we\'ll wait for Cephei, he might know.

Share this post


Link to post
Share on other sites

Great thread, I will use this frequently if you guys don\'t mind

using public override bool RequestFuel, however an error is returned:

'not all code paths return a value'

No idea what it means. :D

not all code paths return a value refers to the method requiring a bool return ( meaning either true or false ). the game later checks this value to determine if the fuel request was successful and if not shuts down the engine that requested it for example. you have to make sure that all possible execution paths ( the paths that the code can take inside the method ) end with returning either true or false

before then no one will even really bother writing anything...

*cough* http://kerbalspaceprogram.com/forum/index.php?topic=7847.0

Share this post


Link to post
Share on other sites

I got one question.

How does making the source code public prevent malware .dlls? I could likewise just exclude the bad parts of the code. I suggest changing the guidelines to include your whole plugin project, just to be one the safe side.

Share this post


Link to post
Share on other sites

I got one question.

How does making the source code public prevent malware .dlls? I could likewise just exclude the bad parts of the code. I suggest changing the guidelines to include your whole plugin project, just to be one the safe side.

it doesn\'t, it\'s for people who want to compile the plugin themselves, if it doesn\'t work then you can assume that there is something wrong

Share this post


Link to post
Share on other sites

The argument of including the whole project also doesn\'t work, by the fact they could simply show you a project with offending code removed ...

Share this post


Link to post
Share on other sites

Where can I get OnActivate() and other functions\' documentation? Is it even available at the moment? Also, is SharpDevelop or MonoDevelop worth getting if I want to start making my parts?

Share this post


Link to post
Share on other sites

The argument of including the whole project also doesn\'t work, by the fact they could simply show you a project with offending code removed ...

:D My brain is a few steps behind everything that\'s happening.

Share this post


Link to post
Share on other sites

The argument of including the whole project also doesn\'t work, by the fact they could simply show you a project with offending code removed ...

Best option would be to provide code only, without compiled dll file. Everyone interested would have to do it alone.

Share this post


Link to post
Share on other sites

Best option would be to provide code only, without compiled dll file. Everyone interested would have to do it alone.

Bit of a long shot here but what chance would there be of including a compiler into KSP itself? Distribute plugins as sourcecode and have KSP compile them the first time they are run?

Then again I dare say that implementing that would be more effort than sandboxing the the plugin system so filesystem access for the plugins would be limited to a directory inside the KSP directory structure and limit plugin\'s ability to access external API calls. (Not all of them tho. I want API access to the Windows Joystick routines to bypass Unity\'s not-fit-for-purpose excuse for joystick handling)

Anyhoow, while I\'m typing I might as well ask a few questions of my own:

1: How is input in KSP handled? I\'m guessing that the user input and the input fed to the rocket are separate things and that KSP does some kind of stuff in-between. I suppose a way to describe what I am asking is does KSP have some sort of virtual joystick (ie the one inside the command pod) that is controlled based on user input? Can I write code that can alter the input handling behaviour?

2: How is code actually executed in game? Not counting initialisation and clean-up code how does the \'meat\' run? Is there a function in the plugin that can be called once per physics frame or similar? Is the plugin code run paralel to the game (multithreaded) or sequentially? (eg, a badly coded plugin in a endless loop freezing the game)

3: Documentation? I have been watching the forums like a hawk for ages now and in the absence of any documentiaiton of the game\'s APIs how comes we already have people writing plugins with new parts with new fuel types and GUIs and autopilots. Unless I am going blind, or senile, or both! ^_^

Anyhoow, once I have given myself a crash course on C# I plan on making my contribution to KSP, a command pod with a (near) fully functional 6502 based computer built into it. Code your software in 6502 asm, for C use CC65 or load in a EhBASIC image to code like its the 80s 8)

1 person likes this

Share this post


Link to post
Share on other sites

The argument of including the whole project also doesn\'t work, by the fact they could simply show you a project with offending code removed ...

There are still ways to inspect such assemblies.

Share this post


Link to post
Share on other sites

Just a little question : What are the conditionss to use (i mean : When this happens-->do this) ?

I seen OnPartActivate, OnPartAwake, OnFlightStart, OnDecouple, what are the others ?

Share this post


Link to post
Share on other sites

Just a little question : What are the conditionss to use (i mean : When this happens-->do this) ?

I seen OnPartActivate, OnPartAwake, OnFlightStart, OnDecouple, what are the others ?

If you\'re using Visual C#/Studio, just type override and press space, and it\'ll give you a list of stuff you can override. Besides that, you have to wait for Squad\'s code documentation.

Share this post


Link to post
Share on other sites

3: Documentation? I have been watching the forums like a hawk for ages now and in the absence of any documentiaiton of the game\'s APIs how comes we already have people writing plugins with new parts with new fuel types and GUIs and autopilots. Unless I am going blind, or senile, or both! ^_^

I\'ve heard all from 'wait' to 'a few days' and 'weeks'. I\'m hoping for a few days :V

Share this post


Link to post
Share on other sites

I\'ve heard all from 'wait' to 'a few days' and 'weeks'. I\'m hoping for a few days :V

The compile docs are up. The code docs will be up soon. I don\'t have a specific date, however, I know they\'re working on it. Plus, many members have been figuring it out on their own.

Share this post


Link to post
Share on other sites

'override'? Going to learn C#, because i never seen override on C/C++... is OnPartExplode a correct value ? Also, i cannot use visual studio because i\'m on a Mac, so what can I do ? I have unity (free version, not pro) so i have MonoDevelop but i never used it. Is it some kind of compiler ? Also, if i want to do a new propulsion system (tank+engine+refiller), i have all of them in the same DLL ?

I will read Cephei\'s plugin, to see if i can understand a few things.

Share this post


Link to post
Share on other sites

Override is just a way to ensure the virtual function you are trying to override exists. C/C++ doesn\'t have this declaration as it\'s more to for 'safety' reasons than anything else (there\'s been some modifications in C++11, only thing that comes to top of my head is 'final' to ensure a virutal function doesn\'t get overridden after that class). Although C# still needs the override key word otherwise you might get a warning or error?

Share this post


Link to post
Share on other sites

Seeing as how i have Unity installed on my laptop, do you guys recommend i use mono to code such plugins?

Share this post


Link to post
Share on other sites

Do you even need Unity to code plugins?

no

what you do need though is a fair knowledge about c# and programming in general, this is no entry level task and not something that i\'d recommend a beginner to start with

Share this post


Link to post
Share on other sites

I think I\'ll give it a try, I\'ve been learning C++ for some time now. Shouldn\'t be so hard to adapt to a new syntax. I hope...

Share this post


Link to post
Share on other sites

Just a little question : What are the conditionss to use (i mean : When this happens-->do this) ?

I seen OnPartActivate, OnPartAwake, OnFlightStart, OnDecouple, what are the others ?

Here\'s my list so far

onPartActivate()

onPartAttach()

onPartAwake()

onPartDeactivate()

onPartDelete()

onPartDetach()

onPartExplode)

onPartFixedUpdate()

onPartLiftOff()

onPartLoad()

onPartSplashdown()

onPartStart()

onPartTouchdown()

onPartUpdate()

onUnpack()

onPack()

onPartDestroy

onJointDisable()

onJointReset()

onFlightStartAtLaunchPad()

onFlightStart()

onGamePause()

onGameResume()

onEditorUpdate()

onDisconnect()

onDecouple(float)

onCtrlUpd(FlightCtrlState)

onCopy()

onActiveUpdate()

onActiveFixedUpdate()

I really suggest just opening up Assembly-Csharp in the object browser and looking for yourself, this is just from the 'Part' class, and there are other goodies there too.

The Vessel Class looks like we could have fun with too.(i.e. Autopilot stuff)

This looks like it could be extremely powerful. Not Just creating custom parts, You could make major changes to the game if you wanted.

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