Jump to content

Modding KSP 2: What We Know


Nifty255

Recommended Posts

Hey there. I'm Nifty. Literal ages ago, I made a few KSP mods (DraftTwitchViewers among others). Despite the fact I probably won't have the time or energy to mod KSP 2 as well, I found myself interested in helping the community in its modding efforts, and the devs in their efforts to make the game more moddable. To that end, I went investigating.

I'm intending this post to become a sorta-central knowledgebase on KSP 2's modding capabilities that can grow and become more detailed over time. I'll check in every once in a while and compile comments into the main post as info comes in.

 

NOTE: 100% of the info in this post has been gathered without decompiling or even touching an IDE. I want to get confirmation from Private Division that Visual Studio's Object Browser feature doesn't constitute decompiling before I go using that. I'll remove the "IDE" part once I get confirmation and dig in.

  • KSP 2 is a Unity game. By checking the properties of "UnityPlayer.dll", the DLL's version "2020.3.33" is shown, which is a version of Unity Engine.
  • The game lacks a "GameData" folder, which is how KSP 1 loaded mods (part models, part configurations, code via DLLs, flags,  audio, so on). So assets have to be loaded a different way.
  • The folder "KSP2_x64_Data\StreamingAssets\aa\StandaloneWindows64" holds a litany of ".bundle" files, many of which match planet and part names. At first, I thought they were Unity Asset Bundles, but it seems not. Instead, they're Addressable Assets. This may be how modders can load their own, maybe not inside this folder though. https://docs.unity3d.com/Packages/[email protected]/manual/index.html
  • Save game data is stored in "AppData\LocalLow\Intercept Games\Kerbal Space Program 2". The data in this folder appears to be primarily JSON (thank whatever deity exists the old config syntax is dead).

By popping open my own save, I was able to find out the following about the structure of a craft and its parts:

  • A craft is composed of basic metadata as well as a list of "assemblies". 
  • Crafts seem to use GUIDs to keep track of which parts reference which other parts.
  • Parts can be part of at most one "symmetry set".
  • Parts can have 0 or more "modules" similar to KSP 1. These appear to be more complex than the original modules though.
  • Strangely, KSP 2 uses modules to apply color and drag?
  • Each module is made up of 3 components, references to actual namespace and class names can be seen in the craft file:
    • PartComponentModule (KSP.Sim.impl.PartComponentModule_ResourceCapacities)
    • Module (KSP.Modules.Module_ResourceCapacities)
    • Data (KSP.Modules.Data_ResourceCapacities)
  • Data surrounding a module such as an engine gimbal's limiter is nested within the Data component, which likely means the Module component handles logic and the PartComponentModule ties it together.
    • Side note: this pattern of separation of logic from data suggests a "data-oriented" programming style, which tells me KSP 2 takes advantage of Unity's DOTS system to some extent.
  • It appears one Module can have multiple Data components. For example, most parts have a data component for their role (e.g. "Data_Engine") as well as a "Data_ModuleActions".

That's all I've got for now.

Link to comment
Share on other sites

I've used dnSpy to open the code within the C-sharp assemblies, and it seems that there is already a ModManager implemented in the game (along with functions for both colonies and multiplayer, very interesting stuff indeed).

My suggestion would be to google Unity Modding - you will find quite a lot of information on how to tap into the addressables e.g.

Link to comment
Share on other sites

16 minutes ago, sarbian said:

But not finished.

Of course not - none of the components are finished. 

However, after some more digging it does seem like the modmanager loads mods from GameData/Mods, so that is quite interesting .. 

Link to comment
Share on other sites

4 hours ago, sarbian said:

It loads bundle (which we can not build without the devs sharing some Unity tool). And does nothing with them.

I've loaded an AssetBundle exported from a regular Unity editor. Everything loaded up. I'm using Bepinex to inject code and then calling AssetBundle.LoadFromFile. 

1 hour ago, Nifty255 said:

The point of this post was to give as much info as possible without violating the EULA. If I didn't care, it'd be trivial to learn much more than that.

I believe that reverse engineering to ensure compatibility with the software that you are developing cannot be restricted by a EULA in both US and the EU as its explicitly allowed.

Link to comment
Share on other sites

22 minutes ago, antra said:

I've loaded an AssetBundle exported from a regular Unity editor. Everything loaded up. I'm using Bepinex to inject code and then calling AssetBundle.LoadFromFile. 

But your bundle did not use any of KSP class since you do not have their reference id. And without that you will be limited with what you can do with it.

Link to comment
Share on other sites

12 minutes ago, sarbian said:

But your bundle did not use any of KSP class since you do not have their reference id. And without that you will be limited with what you can do with it.

The asset bundle didn’t, but the Bepinex plugin did.  It used the assemblies from the Managed folder, which contains a lot of functionality of the base game. Basically, the asset bundle can be used to bring in prefabs, UI prefabs in my case, while the logic stays in the Bepinex plug-in. I can access maneouver node logic, which is what I’m aiming at. 
 

Basically, the bulk of the game logic one way or another referenced by the GameInstance singleton. All KerbalMonoBehavior components include a reference to it. You can iterate through the root objects of the active scene and most of them contain components that extend KerbalMonoBehavior, giving you access to the core singleton. I’m not sure if you can get access to parts logic this way, but the core game seems to be accessible and the assemblies provide a pretty straightforward API, including comments. 

Edited by antra
Link to comment
Share on other sites

38 minutes ago, antra said:

I believe that reverse engineering to ensure compatibility with the software that you are developing cannot be restricted by a EULA in both US and the EU as its explicitly allowed.

Unfortunately, we don't get to decide what can and can't be restricted by a EULA, which is why I erred on the side of caution with this post. As a reminder, I have emailed Private Division for explicit permission to view the DLLs through Visual Studio's Object Browser, which will give legal access to likely hundreds of class names, public fields, etc. which will make learning and info sharing easier and much less scary. If/when I get permission, I'll post the email itself here and then start actually digging.

Link to comment
Share on other sites

16 minutes ago, Nifty255 said:

Unfortunately, we don't get to decide what can and can't be restricted by a EULA, which is why I erred on the side of caution with this post. As a reminder, I have emailed Private Division for explicit permission to view the DLLs through Visual Studio's Object Browser, which will give legal access to likely hundreds of class names, public fields, etc. which will make learning and info sharing easier and much less scary. If/when I get permission, I'll post the email itself here and then start actually digging.

It is a call that has to be made on an individual basis. Nothing I write is legal advice, and I can be wrong, but my understanding is that a EULA is not technically different from a waiver or a contract in the sense that it cannot restrict things that are explicitly allowed by law. Courts have previously ruled that reverse engineering for compatibility falls under fair use. However, reverse engineering for purposes other than compatibility is likely illegal. In any case, if I was on the Private Division legal team, I would be reluctant to provide an explicit permission in any case because it would reduce the options for potential litigation in the future. Given that the developer has already declared future support for mods, and given that the mod infrastructure present in the current build of the game relies on the same assemblies, I don’t think that the threat of litigation is very high. This is how most games without mod support are normally modded.

More context for this topic can be found here: https://www.eff.org/issues/coders/reverse-engineering-faq

Link to comment
Share on other sites

1 hour ago, antra said:

The asset bundle didn’t, but the Bepinex plugin did.  It used the assemblies from the Managed folder, which contains a lot of functionality of the base game. Basically, the asset bundle can be used to bring in prefabs, UI prefabs in my case, while the logic stays in the Bepinex plug-in. I can access maneouver node logic, which is what I’m aiming at. 
 

Basically, the bulk of the game logic one way or another referenced by the GameInstance singleton. All KerbalMonoBehavior components include a reference to it. You can iterate through the root objects of the active scene and most of them contain components that extend KerbalMonoBehavior, giving you access to the core singleton. I’m not sure if you can get access to parts logic this way, but the core game seems to be accessible and the assemblies provide a pretty straightforward API, including comments. 

I never said you can not use a bundle to load anything. I said that you can not load a bundle that reference a stock class, like a par model may require. This may be necessary to do a lot of the modding stuff we take for granted on KSP 1.

Link to comment
Share on other sites

3 hours ago, Nifty255 said:

The point of this post was to give as much info as possible without violating the EULA. If I didn't care, it'd be trivial to learn much more than that.

People overestimate the power of EULA. The KSP one looks to me as a standard end-user agreement used by the software companies. Thus, the rule to not decompile the game does not necessarily reflect the intent of Private Division. However, I'd be surprised if their legal department would give permission to avoid it. If I understand anything about legals (and I dare to believe I do), they will be ignoring any incoming requests for a permission to not follow EULA. The rule of thumb is common sense. As long as you don't commit a crime (and don't promote others to do so), nobody cares if you decompile the program or not. Without a good reason, the legal department won't be hunting people on the forums to prevent games code decompilation.

And for those who are still concerned, I'd like to highlight two bullets from EULA:

  1. You must be an adult to accept the EULA. If you're not, then you cannot play this game until your guardant accepted the EULA. I have doubts that this requirement is strictly followed by all the players.
  2. EULA explicitly states that all disputes are to be resolved in arbitration and not in court. That being said, you won't be dragged into court and put in jail if you decompiled the code just to take a look at it. The very first thing that should happen in this case (according to EULA) is the publisher contacting you and asking to stop. That's how arbitration always starts. So, instead of asking for permission to not follow EULA (which you will never get) just start doing whatever you have in mind and wait for the reaction.
Link to comment
Share on other sites

1 minute ago, IgorZ said:

People overestimate the power of EULA.

People underestimates the Legal Systems of different countries. :)

Very few Countries in the World follow the same Doctrines followed by USA's Common Law. Some Countries plain declare null and void the EULA's clausule about arbitration. Point.

A very few ones see Decompilation as a Felony and, so, you would be prosecuted under the Criminal Law, and not on the Civil one. I'm not telling I agree with this, but Law doesn't require my agreement, only my obedience.

Since PD probably wants to have KSP2 being sold everywhere, without risking any of the paying customers to be dragged on legal problems in their country by something published on this Official Forum, I'm not surprised the Add'ons publishing rules states what follows:

Quote

9. Legal boundaries

You may not decompile, modify or distribute any of the .dll files or other files KSP comes with beyond content of the GameData folder. Follow the EULA. For assemblies, you may only use exposed public or protected members of classes, and you may not examine the code within any member.

That said, it's up to the Forum administration to decide to apply the rule or not. But if the rule is not going to be applied, why it was written at first place?

Link to comment
Share on other sites

6 minutes ago, Lisias said:

But if the rule is not going to be applied, why it was written at first place?

The rule can be applied, but its not required to be applied. The reason why such rules were included in EULA at all was an attempt to prevent cracking of the software. Of course, it doesn't prevent cracking, but it makes such activity illegal.

And saying about how the law works: you cannot be sentenced just because someone said you were decompiling the code, even if that "someone" was yourself. The prosecution must prove the violation, and it's something that requires significant resources. As long as your actions don't harm the product nobody will be wasting time and resources on hunting you.

Link to comment
Share on other sites

7 minutes ago, IgorZ said:

And saying about how the law works: you cannot be sentenced just because someone said you were decompiling the code, even if that "someone" was yourself.

On countries where the thing is a Felony, the rules differs. Murderer is a Felony, as example. The mere accusation can trigger the police in seizing you and your digital assets.

 

10 minutes ago, IgorZ said:

The prosecution must prove the violation, and it's something that requires significant resources. As long as your actions don't harm the product nobody will be wasting time and resources on hunting you.

The prosecution must prove violation for keeping you in jail, not to seize your assets. Or even arrest you.

Yes, it requires significant resources, begin the reason such stunts are applied now and then to some few chosen ones. Anyone willing to play roulette?

In time - who decides if my actions harm the product? What's the criteria? How many years I need to worry about, if by some reason something I did is considered harmful?

Anyway.

Link to comment
Share on other sites

18 minutes ago, Lisias said:

The mere accusation can trigger the police in seizing you and your digital assets.

In the countries where "law" is not just a word "the mere accusation" is not enough. An arrest warrant is required. And the arrest warrant is issued by a judge on the basis of the evidence. No evidence, no warrant.

But. Anyway.

Link to comment
Share on other sites

3 hours ago, RuBisCO said:

I just want to start real simple at first: how to I install a new flag of my own design?

 

1 hour ago, Taki117 said:

Asking the real questions here. I too would like to know.

It appears without using an external code injector, you can't. But several unity-based injectors exist, including one released sometime within the last day, as well as a mod which will let you add custom flags.

Link to comment
Share on other sites

1 hour ago, Taki117 said:

Asking the real questions here. I too would like to know.

FOUND IT! 

https://www.reddit.com/r/KerbalSpaceProgram/comments/11c4bc9/custom_flags_mod_guide/

1. Download Space Warp Modloader by cheese3660 and unzip it anywhere. I had to disable Real-time protection setting on my Windows Virus & threat protection settings to download and run, so use at own risk. The modders on Discord and the forums have vouched for it, and I looked at the code myself.

2. Run the ksp2_mod_loader_patcher.exe to locate your KSP 2 folder and install the modloader.

3. Load up the game once and close it.

4. There should be a Mods folder in the Kerbal Space Program 2\KSP2_x64_Data folder.If you downloaded via Steam, it might be in: C:\Steam\steamapps\common\Kerbal Space Program 2\KSP2_x64_Data.

xnkg37tlegka1.jpg?width=734&format=pjpg&

5. Download Custom Flags mod by adamsogm.

6. Unzip the contents of the folder into the Mods folder from step 4. It should just be a folder called custom-flags and everything inside it.

8xaliaegegka1.jpg?width=794&format=pjpg&

7. Create a folder in the Kerbal Space Program 2 directory called flags. See image below for example.

kxl5omjmdgka1.jpg?width=649&format=pjpg&

8. Place your 512x300 .png flag files inside.

bxgpihv3egka1.jpg?width=670&format=pjpg&

Edited by RuBisCO
Link to comment
Share on other sites

1 hour ago, RuBisCO said:

FOUND IT! 

https://www.reddit.com/r/KerbalSpaceProgram/comments/11c4bc9/custom_flags_mod_guide/

1. Download Space Warp Modloader by cheese3660 and unzip it anywhere. I had to disable Real-time protection setting on my Windows Virus & threat protection settings to download and run, so use at own risk. The modders on Discord and the forums have vouched for it, and I looked at the code myself.

2. Run the ksp2_mod_loader_patcher.exe to locate your KSP 2 folder and install the modloader.

3. Load up the game once and close it.

4. There should be a Mods folder in the Kerbal Space Program 2\KSP2_x64_Data folder.If you downloaded via Steam, it might be in: C:\Steam\steamapps\common\Kerbal Space Program 2\KSP2_x64_Data.

xnkg37tlegka1.jpg?width=734&format=pjpg&

5. Download Custom Flags mod by adamsogm.

6. Unzip the contents of the folder into the Mods folder from step 4. It should just be a folder called custom-flags and everything inside it.

8xaliaegegka1.jpg?width=794&format=pjpg&

7. Create a folder in the Kerbal Space Program 2 directory called flags. See image below for example.

kxl5omjmdgka1.jpg?width=649&format=pjpg&

8. Place your 512x300 .png flag files inside.

bxgpihv3egka1.jpg?width=670&format=pjpg&

Games been out all of about 24 hours and there's already a mod for it. I love this community.

Link to comment
Share on other sites

6 hours ago, Taki117 said:

Games been out all of about 24 hours and there's already a mod for it. I love this community.

Well, it says

Quote

Will there be mods during Early Access?

We expect modders to dig into KSP2 on day one. We recognize that the modding community has played a big role in the longevity of KSP, and we continue to be impressed by the mods that are released. The intent with KSP 2 is to improve the modding experience even further, and we look forward to hearing feedback from modders over the course of early access.

in the FAQ at the bottom of https://www.kerbalspaceprogram.com/games-kerbal-space-program-2 .

I'm more puzzled by Private Division not releasing official mod tools/an API doc if they expect modders to dig into KSP 2 on day one, considering all the legal points brought up in this thread regarding de-compilation violating the EULA.

Link to comment
Share on other sites

4 hours ago, E3FxGaming said:

[snip]

I'm more puzzled by Private Division not releasing official mod tools/an API doc if they expect modders to dig into KSP 2 on day one, considering all the legal points brought up in this thread regarding de-compilation violating the EULA.

I noticed that too and also found it a bit strange considering their commitment to the modding community.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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