Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Is it currently possible to reload or modify the current solar system in-game?

My idea is to write a plug-in that, when a player triggers a certain object in space, unloads (and saves) the entire solar system and loads a new one in its place. The player ship de-spawns and re-spawns in the newly loaded solar system in a predefined orbit.

However, that depends on whether it is possible to modify orbital objects "on rails" at run time. The loading does not have to be instantaneous and physics do not have to simulate.

Link to comment
Share on other sites

So I was wondering, what is the 'proper' way to detect another mods presence? For example, I want to make a plugin that does RemoteTech stuff, but only if remotetech is installed. I have been searching this forum, but the search on here isn't exactly that helpful.

Link to comment
Share on other sites

So I was wondering, what is the 'proper' way to detect another mods presence? For example, I want to make a plugin that does RemoteTech stuff, but only if remotetech is installed. I have been searching this forum, but the search on here isn't exactly that helpful.

You could try something like this. Essentially you iterate through loaded assemblies until you find the one you're looking for.

Link to comment
Share on other sites

If you just want to check if another mod is installed, blowfish's method is the way to go. RT's assembly name is: if (Asm.dllName == "RemoteTech") (I actually check for RT in one of my own mods exactly like this.)

If you are trying to call a command in another mod, you can also do it this way:

The following code tries to execute the AGXInstalled method (which is static) from the AGExtExternal class in the ActionGroupsExtended namespace. If it is present it returns the bool from the method (in this case true as this is simply a check to see if AGX is present). If the mod is not present, it hits the catch block where you run the code you want to if the mod is not present (in this case false to indicate AGX is not present).

public static bool AGExtInstalled()
{
try //try-catch is required as the below code returns a NullRef if AGX is not present.
{
Type calledType = Type.GetType("ActionGroupsExtended.AGExtExternal, AGExt");
return (bool)calledType.InvokeMember("AGXInstalled", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, null);
}
catch
{
return false;
}
}

D.

Edited by Diazo
Link to comment
Share on other sites

Catching an Exception is by design slower since it involve the creation of the Exception object and walking thru the heap to find where/if something catch it. Exception should be avoided in a "normal" flow if performance is key. For a single test like that it would not matter much but I would side with Padishar for a null testing anyway.

Link to comment
Share on other sites

Documentation for creating contracts?

I'm interested in starting small by creating a collection of contracts, but having looked through the various development postings here I don't see anything that talks about it. Can I get a pointer to documentation, tutorials, or anything else that would help with that? Thanks.

Link to comment
Share on other sites

Documentation for creating contracts?

I'm interested in starting small by creating a collection of contracts, but having looked through the various development postings here I don't see anything that talks about it. Can I get a pointer to documentation, tutorials, or anything else that would help with that? Thanks.

http://forum.kerbalspaceprogram.com/threads/86588-Contract-Modding-Information-for-Mod-Authors

Link to comment
Share on other sites

Is it currently possible to reload or modify the current solar system in-game?

My idea is to write a plug-in that, when a player triggers a certain object in space, unloads (and saves) the entire solar system and loads a new one in its place. The player ship de-spawns and re-spawns in the newly loaded solar system in a predefined orbit.

However, that depends on whether it is possible to modify orbital objects "on rails" at run time. The loading does not have to be instantaneous and physics do not have to simulate.

Do you want to change the planets, ships, or both?

Kerbal Warp Drive changes the planets while the game is loaded. Ships remain in the same orbit around their parent body.

Modifying on-rails ships is also possible; Orbit Decay Lite does this.

I don't know how either one works, but you can ask in the threads and/or look at the source.

Link to comment
Share on other sites

Hopefully someone can point me in the right direction. Is it possible to find the footprint of a ship? I want to use a variable offset and I'm going to use the center of mass of the ship (or the center of my part) as a min and the radius of the ship as the max. I haven't started yet, just curious if anyone knows if its possible before I head down a road that could lead nowhere.

Link to comment
Share on other sites

Hey guys,

I'm currently trying to create a contract where I need to specify the Mun as the targetBody. Anyone got a good idea on how to explicitly do that? Most examples I've found randonmly generates a target body depending on celestial progression.

Link to comment
Share on other sites

It depends how precise you want to be. The fast version is more or less that. The slow one would go thru all the vertex of each parts.

This code does not compute the distance to the CoM but it is an easy change.

Edit : bonus code to draw it (with some MJ call you can find in the same file). I should rewrite some of this...

Edited by sarbian
Link to comment
Share on other sites

Do you want to change the planets, ships, or both?

Kerbal Warp Drive changes the planets while the game is loaded. Ships remain in the same orbit around their parent body.

Modifying on-rails ships is also possible; Orbit Decay Lite does this.

I don't know how either one works, but you can ask in the threads and/or look at the source.

Thanks, I think I can start from there, that looks like the goal I was trying to accomplish (albeit through a separate object).

My idea is to create a Mass Effect-style relay in high solar orbit that the player can discover and travel to other planets (and back).

Link to comment
Share on other sites

If you just want to check if another mod is installed, blowfish's method is the way to go. RT's assembly name is: if (Asm.dllName == "RemoteTech") (I actually check for RT in one of my own mods exactly like this.)

If you are trying to call a command in another mod, you can also do it this way:

The following code tries to execute the AGXInstalled method (which is static) from the AGExtExternal class in the ActionGroupsExtended namespace. If it is present it returns the bool from the method (in this case true as this is simply a check to see if AGX is present). If the mod is not present, it hits the catch block where you run the code you want to if the mod is not present (in this case false to indicate AGX is not present).

public static bool AGExtInstalled()
{
try //try-catch is required as the below code returns a NullRef if AGX is not present.
{
Type calledType = Type.GetType("ActionGroupsExtended.AGExtExternal, AGExt");
return (bool)calledType.InvokeMember("AGXInstalled", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, null);
}
catch
{
return false;
}
}

D.

You're right that i'm trying to invoke a method in the remotetech api. For starters I first want to have it write the RT api's methods to the debuglog. I'm rather confused however. If I try to run the code below, it tells me that RTType is null, and indeed if I try RTType.GetMethods() I get a NullReferenceException.

[FONT=Monospace]
[COLOR=#009695]if[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]RTLoaded[/COLOR][COLOR=#333333])[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#3364a4]Debug[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]Log[/COLOR][COLOR=#333333]([/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]RT[/COLOR][COLOR=#f57d00] is [/COLOR][COLOR=#f57d00]loaded[/COLOR][COLOR=#f57d00]![/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#3364a4]Type [/COLOR][COLOR=#333333]RTType [/COLOR][COLOR=#333333]= [/COLOR][COLOR=#3364a4]Type[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]GetType[/COLOR][COLOR=#333333]([/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]RemoteTech[/COLOR][COLOR=#f57d00].[/COLOR][COLOR=#f57d00]API[/COLOR][COLOR=#f57d00].[/COLOR][COLOR=#f57d00]API[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#009695]if[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]RTType [/COLOR][COLOR=#333333]==[/COLOR][COLOR=#009695] null[/COLOR][COLOR=#333333])[/COLOR]
[COLOR=#3364a4]Debug[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]Log[/COLOR][COLOR=#333333]([/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]RTTYPE[/COLOR][COLOR=#f57d00] is [/COLOR][COLOR=#f57d00]null[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];
}[/COLOR][/FONT]

GetType should take "Namespace.Classname" as an argument right? If so what does ", AGExt" mean in this:

Type calledType = Type.GetType("ActionGroupsExtended.AGExtExternal, AGExt");

if it helps the remotetech api code is here:

https://github.com/RemoteTechnologiesGroup/RemoteTech/blob/1.7.0/src/RemoteTech/API/API.cs

Link to comment
Share on other sites

GetType should take "Namespace.Classname" as an argument right? If so what does ", AGExt" mean in this:

Type calledType = Type.GetType("ActionGroupsExtended.AGExtExternal, AGExt");

That is referring to my AGX mod for which the code is found here.

ActionGroupsExtended -> The Namespace, found at line 10 of the link.

AGExtExternal -> The Class inside the namespace at line 13 of the link

AGExt -> Assembly Name, not in the code but .dll container my code compiles into.

Now, I haven't tired exactly what you are doing, but it looks like you are not telling it which assembly to look for that class in.

As another example, the following is a call to RT that gets the signal delay for the current vessel:

public static double RTTimeDelay(Vessel vsl) //gets delay for directly activated actions
{
try
{
Type calledType = Type.GetType("RemoteTech.API.API, RemoteTech");
return (double)calledType.InvokeMember("GetShortestSignalDelay", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, new System.Object[] { vsl.id });

}
catch
{
return 0;
}
}

That is a direct copy-paste from my working code so I know it works. All my RemoteTech related code can be found here if you want other examples.

D.

Link to comment
Share on other sites

KSP 1.0.5 IScienceDataContainer interface.

Seems there is a new method expected:- ReturnData(ScienceData data).

Anyone have any ideas what this is expected to do?

An empty method of course seems to work.. but would be good to know what this is for.

Edit: Never mind I figured it out. Should read the release notes more carefully. It's for when a transmit of science data fails and is called to return the science back to the container.

Edited by JPLRepo
Link to comment
Share on other sites

@Diazo: Thanks! I finally got it to work. It wasn't clear from online C# documentation/tutorials that I needed to specify the assembly which contains the class I wanted to access. So thanks again, you (and this thread as a whole) have been a great help.

Link to comment
Share on other sites

KSP 1.0.5 IScienceDataContainer interface.

Seems there is a new method expected:- ReturnData(ScienceData data).

Anyone have any ideas what this is expected to do?

An empty method of course seems to work.. but would be good to know what this is for.

Edit: Never mind I figured it out. Should read the release notes more carefully. It's for when a transmit of science data fails and is called to return the science back to the container.

You should also note that the Science Data constructor has two new arguments (with default values). I'm not really sure what the bool does, but the uint is used by the transmitter to correctly identify which part the science data came from. This is used to return the data if the transmission fails. I'm using false for the bool and the part.flightID for the uint and it seems to be working correctly.

Link to comment
Share on other sites

You should also note that the Science Data constructor has two new arguments (with default values). I'm not really sure what the bool does, but the uint is used by the transmitter to correctly identify which part the science data came from. This is used to return the data if the transmission fails. I'm using false for the bool and the part.flightID for the uint and it seems to be working correctly.

Good pick up. Thanks. Yeah, nothing as to what that bool triggered is for.

Link to comment
Share on other sites

That's a pretty cool mod, I'll have to play around with it. I was more looking for buttons and such, like push a button and open the cargo bay. I know I can just right click but what I'm building will have quite a long right click menu. I'd like to be able to put a button somewhere that I can walk up and use as a Kerbal in EVA. I don't know if anyone has done that yet, if not I will see what I can figure out when my project gets to that point. Any assistance on the matter would be greatly appreciated. :)

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