Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

OnVesselRecoveryRequested triggers in-flight when you click the recover button at the top, but not when recovering from the Space Center.

OnVesselRecovered triggers after the recovery summary pops up.

OnVesselRecoveryProcessing (or whatever it's called) triggers before the summary appears, but it is also used to trigger all of the stock recovery methods, so I'm not sure that it will let you actually interrupt anything.

You can, however, change the amount of science/funds/rep after the vessel is recovered. This is kind of clunky, but if you just want to alter or remove the recovery amounts it works.

Link to comment
Share on other sites

OnVesselRecoveryRequested triggers in-flight when you click the recover button at the top, but not when recovering from the Space Center.

OnVesselRecovered triggers after the recovery summary pops up.

OnVesselRecoveryProcessing (or whatever it's called) triggers before the summary appears, but it is also used to trigger all of the stock recovery methods, so I'm not sure that it will let you actually interrupt anything.

You can, however, change the amount of science/funds/rep after the vessel is recovered. This is kind of clunky, but if you just want to alter or remove the recovery amounts it works.

I'm trying to add a timer restricting the recovery of science/funds/rep based on the vessel's distance from the KSC (just for some basic realism type thing). I'll give some of those methods a try and see what I get. Thanks

Link to comment
Share on other sites

I'm kinda new to this whole compilation thing, coming from the sunny pastures of Python, so, my question is: How can I say that I want to reference DangIt.dll without providing a specific version/location? As in my mod depends on another, how do I do a import of that mod in such a way that whenever it (other mod) updates, I don't have to update mine as well?

As it is it fails to load with

ERR 21:16:10.616] AssemblyLoader: Exception loading 'Entropy': System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
at AssemblyLoader.LoadAssemblies () [0x00000] in <filename unknown>:0

Additional information about this exception:

System.IO.FileNotFoundException: Could not load file or assembly 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null'

System.IO.FileNotFoundException: Could not load file or assembly 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null'

System.IO.FileNotFoundException: Could not load file or assembly 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null'

System.IO.FileNotFoundException: Could not load file or assembly 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null'

System.IO.FileNotFoundException: Could not load file or assembly 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null'

System.IO.FileNotFoundException: Could not load file or assembly 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null'

System.IO.FileNotFoundException: Could not load file or assembly 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DangIt, Version=0.5.0.33221, Culture=neutral, PublicKeyToken=null'

System.TypeLoadException: Could not load type '<WaitAndPrint>d__0' from assembly 'Entropy, Version=0.3.5456.33498, Culture=neutral, PublicKeyToken=null'.

even though I have both installed! What is the "real" way to fix this?

ALSO: Anyone know why this code dosen't add a right click action???

[KSPEvent(guiActive = true, guiName = "Mute Alarms")]
public void MuteAlarms()
{
DangIt.Instance.alarmManager.ClearAllAlarmsForModule (this);
this.Events["MuteAlarms"].active = false; //Hide the menu item
}

Edited by Coffeeman
Link to comment
Share on other sites

ALSO: Anyone know why this code dosen't add a right click action???

[KSPEvent(guiActive = true, guiName = "Mute Alarms")]
public void MuteAlarms()
{
DangIt.Instance.alarmManager.ClearAllAlarmsForModule (this);
this.Events["MuteAlarms"].active = false; //Hide the menu item
}

I think the version problem depends on whether the assembly version number actually changes for the assembly you are referencing, but I've never been very clear on this stuff. I suppose you could try to handle everything through reflection, but I'm not sure how practical that is.

The event needs an "active = true" argument on the first line. I think they are all active = false by default. guiActive just means that it will show up in the right-click menu whenever the event is actually active (there are other options to allow visibility when the part isn't on the current vessel or when you're on EVA).

Link to comment
Share on other sites

OnVesselRecoveryRequested triggers in-flight when you click the recover button at the top, but not when recovering from the Space Center.

OnVesselRecovered triggers after the recovery summary pops up.

OnVesselRecoveryProcessing (or whatever it's called) triggers before the summary appears, but it is also used to trigger all of the stock recovery methods, so I'm not sure that it will let you actually interrupt anything.

You can, however, change the amount of science/funds/rep after the vessel is recovered. This is kind of clunky, but if you just want to alter or remove the recovery amounts it works.

When I try to override I get a 'no suitable method found to override' error.

public override void OnVesselRecoveryProcessing() {
timeOfRecovery = currentUniversalTime + timeToRecoverVessel;
if (currentUniversalTime == timeOfRecovery) {
recoveryTimeIsMet = true;
}
}

The process inside it seems right (and is referenced from my .cs file correctly) but I'm not quite sure I understand overrides in C# yet. Would anyone be able to explain why I'm getting this error and how I can fix it? Cheers

Link to comment
Share on other sites

How does one go about adjusting science return?

Nvm about the trait creation, I believe that this will work, although I don't know how to do ProtoCrewMember.

public class SurfaceScientist : MonoBehaviour
{
public ExperienceTrait Geologist = new ExperienceTrait();
public ExperienceTraitConfig GeoConf = ExperienceTraitConfig.Create(ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData"));
public void CreateGeologist()
{
Experience.ExperienceTrait.Create(Geologist, GeoConf, ProtoCrewMember);
}
}

Edit once more, nvm, I figured out what type is.

Edited by Robotengineer
Link to comment
Share on other sites

How does one go about adjusting science return?

Nvm about the trait creation, I believe that this will work, although I don't know how to do ProtoCrewMember.

public class SurfaceScientist : MonoBehaviour
{
public ExperienceTrait Geologist = new ExperienceTrait();
public ExperienceTraitConfig GeoConf = ExperienceTraitConfig.Create(ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData"));
public void CreateGeologist()
{
Experience.ExperienceTrait.Create(Geologist, GeoConf, ProtoCrewMember);
}
}

Edit once more, nvm, I figured out what type is.

Edit GameData/Squad/Resources/ScienceDefs.cfg and/or the PartModule definitions for ModuleScienceExperiments on parts.

Link to comment
Share on other sites

I'm trying to do it with a KXP effect, so with a plug in.

There's no good way to do this. There are a lot of nasty hacks.

The game loads a set of ConfigNodes into GameDatabase at startup from the ScienceDefs file. You could find and modify those ConfigNodes prior to the ResearchAndDevelopment class starting up - MainMenu, something like that. ModuleManager might have some hooks to do that, I'm not sure. GameDatabase.Instance.GetConfigNodes("EXPERIMENT_DEFINITION") should get all of them, IIRC. That would involve a KSPAddon with startup set to Instantly or MainMenu, and is probably the cleanest solution.

ResearchAndDevelopment is the class that does a lot of the science stuff. You could theoretically use reflection to mess with its internal database of ScienceSubjects and ScienceExperiments. This is incredibly ugly, possibly violates the EULA (which may well be legal where you live, and probably is, but will lead to Squad not posting your mod on the forums), and is technically hard.

You could hook the various events fired when science is generated. OnScienceReceived might work, but I'm not sure if it's called in all situations that are relevant. This will be very fiddly.

Link to comment
Share on other sites

Suppose i setup GetModuleCost() to add extra cost to specific part with specific module.

But with that function only, the editor will not update the cost unless I detach that part and attach it again.

How do I ask editor to update the cost?

Thanks beforehand.

Link to comment
Share on other sites

Hi guys! Rather than starting a new thread, I figured my request would fit here quite nicely.

I don't really want to make a new Mod myself, but I did want to poke around in my favorite mods. You know, easy fixes, help debugging, help porting to newer KSP versions, adding some features and the likes. Turns out I am completely lost.

Here is where I am currently:

I'm fairly good with C++ and Java, but I don't know C# yet. But how hard can it be, right? Also, I don't know anything about Unity except that it's a C++/C# Game engine.

Basically any help and pointers (heh) would be appreciated, but here are some specific questions:

- What IDE do you use? I have access to Visual Studio Proffesional SuperduperHype 2026. Is it any good, or should I use another one?

- .NET vs Mono: So there are two frameworks for C#, and Unity/KSP uses Mono if I understand correctly. Can I use both for development or only Mono? How to configure my IDE for that?

- Anything else you want to tell me, really.

The first step I want to do is to compile a stable Mod (like MechJeb or something). The second step is changing a string to "Hello World" or something. If you guys could get me this far, I'd really appreciate it.

Link to comment
Share on other sites

I don't really want to make a new Mod myself, but I did want to poke around in my favorite mods. You know, easy fixes, help debugging, help porting to newer KSP versions, adding some features and the likes. Turns out I am completely lost.

Don't even think twice about this, compiling C# projects is much easier than C++ ones, so you'll have no issues.

I'm fairly good with C++ and Java, but I don't know C# yet. But how hard can it be, right?

If you're fluent in C++ then C# will be a breeze.

- What IDE do you use? I have access to Visual Studio Proffesional SuperduperHype 2026. Is it any good, or should I use another one?

Microsoft's IDE is the best way to develop C# applications at the moment so I'd stick with that.

- .NET vs Mono: So there are two frameworks for C#, and Unity/KSP uses Mono if I understand correctly. Can I use both for development or only Mono? How to configure my IDE for that?

Mono and Visual Studio should produce more or less the same output, dll's compiled in both are compatible and interchangeable. Just make sure to compile for .NET framework 3.5 and not 4.0 or higher (KSP doesn't support those).

- Anything else you want to tell me, really.

You can try compiling my really simple No More Grind mod (it has only one source file), it should be as easy as loading the solution in VS, pointing the project references to your own UnityEngine.dll and Assembly-CSharp.dll (found in KSP/KSP_Data/Managed) and re-compiling.

Edited by nlight
('
Link to comment
Share on other sites

Note you will want to reference Assembly-CSharp-FirstPass.dll as well.

As you are familiar with programming already, the quick and dirty setup method:

1) Install Visual Studio (or other IDE, but as VS is currently free I recommend it.)

2) Make a dev copy of KSP that you can strip out parts from. 95% of KSP's load time is loading parts, if you can get your part count down KSP loads faster when you are making changes. Important as you have to quit KSP completely and re-load for any change to a .dll file.

3) Make a new project that outputs a basic .dll file. Pretty sure it is the top choice when making a C# project VS offers you.

4) Change build target to Net 3.5 in the project's options.

5) Remove broken reference to Microsoft-CSharp that can't be used on Net 3.5 and add reference to the 3 files already listed.

6) Add "using UnityEngine" to the top of your .cs file, just below all the other using statements.

7) Change build location to your sub-folder in GameData, so {KSP-Install}\GameData\{YourModFolder}

8) Code!

Hope that helps,

D.

Link to comment
Share on other sites

Note you will want to reference Assembly-CSharp-FirstPass.dll as well.

Actually, most of the more useful stuff has been moved out of -FirstPass into the main assembly over the last few versions. A lot of plugins don't need it anymore...

Link to comment
Share on other sites

Having the reference doesn't hurt and until someone can prove to me everything is moved out of it I'm leaving it in.

I did not have it originally and it took 3 pages of posts in this thread to figure out why my code was not running when it worked fine for the person helping me out.

Admittedly this was before the useful stuff got moved, but I still recommend you reference it.

D.

Link to comment
Share on other sites

Edit : I should refesh the thread before replying 3H after reading the post :P

I come from Java and the transition was not hard. C# is mostly Java done right :P

- Visual Studio Pro or Community works fine for KSP mods. You just have to make sure the project is set to .NET 3.5

- Mono is just a runtime. As long as you use the .NET 3.5 profile you'll be ok.

- You don't really need Unity to code KSP mods. The only time I use it is when I want to prototype some code faster, but you can't test everything in it since you don't have KSP running in it.

MechJeb is large peice of code, I m not sure it's the best way to start. Have a look at the Link Compilation post and you ll find some example and tutorials near the end of the first post.

Link to comment
Share on other sites

I am a web developer (PHP) and used to program in Java (Android apps and some commercial standard PC software), C++ and C#. What I find hard is to understand how does KSP process the code I am writing. So it's not hard for me to understand or write the code itself at all. I am not sure how to find which functions are required to be overriden or what are the relations between parts, vessels and what are the limitations. It doesn't seem that there is such a documentation out there.

Code wise, the documentation available is nice and clear, though as I said, it's only code wise. Stuff that's useful for programmers already familiar with how the code is going to be processed by KSP. Are there any instructions on what I mentioned in my previous paragraph?

Additionaly, my simple plugin (which should just print out "Hello World" to test the API) is not being recognized by KSP 0.90 (never tried it on 0.25 honestly, but that shouldn't be a problem in that simple case). I chose a stock part (this standard cylindric science module), copied it to my GameData/PluginName/Parts/ folder and changed its name to the name of my plugin. I also changed the module name and the title to that plugin's name and pasted the plugin into the GameData/PluginName/Plugins/ folder. The problem is, I can't seem to find this part in KSP whatever I do. Is there anything I am missing yet?

I would appreciate some help with that.

Link to comment
Share on other sites

I'm getting an unexpected result when attempting to locate the save folder within the plugin. There's only one line that pulls it, and I consistently return the folder name "DestructibleTest" instead of the actual folder name loaded. My code to return the full path:

private static readonly String save_folder = GetRootPath() + "/saves/" + HighLogic.SaveFolder + "/";

EDIT: Yeah, I'm an idiot. I was getting the whole string set up before the game was even loaded. Moved it to Start() and it's working fine now.

Edited by johnqevil
Link to comment
Share on other sites

I'm getting "An object reference is required for the non-static field, method, or property" error for each of my lines trying to store science/funds/rep gained from a mission. Hopefully I'm not being stupid about this :sticktongue:

Currency storedReputation = MissionRecoveryDialog.reputationEarned;            
Currency storedScience = MissionRecoveryDialog.scienceEarned;
Currency storedFunds = MissionRecoveryDialog.fundsEarned;

Link to comment
Share on other sites

How do I use ConfigNode.Load()?


KSP.IO.PluginConfiguration config = KSP.IO.PluginConfiguration.CreateForType<YourConfigClass>();
config.load();
yourVar = config.GetValue("ValueKy", yourVar);

This example shows how I use it.


[Question]

Has someone already found out how it is possible to select another category in the editor?

EditorPartList.Instance.SelectTab(PartCategories[index]);

seems to be depricated and no longer working.

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