Quick Start Guide KerbalData - KSP Data Unlocked!

The KerbalData API allows quick access to all of your KSP data with only a few lines of code. Simply create reference in your project to the KerbalData.dll and you are off to go.

Setup Project References

  1. The first step to using KerbalData is to add the reference to KerbalData to your project, this process varies depending on your heees. Be sure to select the correct version of KerbalData for your application environment. The Release package for KerbalData contains versions of KerbalData.dll for the following platforms:

    • .NET 4.5
    • .NET 4
    • .NET 3.5
    • Mono 2.10.x
  2. Once the correct project reference is set simply add the following namespaces to any codefile you want KerbalData access to.

                              // Base Namespace required for ALL usage of KerbalData 
    using KerbalData;
    
    // The Models namespace contains the loaded data models. This namespace is only needed when working with data 
    // Not in classes that are only handling load/unload (like ViewModels in WPF) 
    using KerbalData.Models;

Access all Files in a KSP Install

  • With the right Namespaces in place write the code you need to access and maniupulate your data.

                              // Use your own install path 
    var kd = KerbalData.Create(@"C:\KSP");
    
    // Load a save file using the same short name provided in the game UI 
    var sf = kd.Saves["testing"];
    
    // One of many helper methods, this one re-fills all ships
    sf.Game.FlightState.FillResources();
    
    // Setting the title of the save game, this will change in-game name display 
    // (still need to wire in dir name change)
    sf.Game.Title = "I AM IRON MAN";
    
    // Another helper method, this clears all vessels marked as debris or unknown vessel types.
    sf.Game.FlightState.ClearDebris();
    
    // Grabbing a vessel from the game 
    var sat =
    sf.Game.FlightState.Vessels.Where(v => v.Name.Contains("Beta Geo-Sat")).FirstOrDefault();
    
    // Changing the orbit (currently defaults to 100km above target)
    sat.Orbit.Change(Body.Bop);
    
    // Save file, includes data backup of original file
    sf.Save();

Load a single file

  • To load a single file use the KspData class from the Serialization namespace

                              // Use your own install path 
                  var data = KspData.LoadKspFile(@"C:\my\file\location\filename.ext");
    
                  // Load a save file using the same short name provided in the game UI 
                  var sf = kd.Saves["testing"];
    
                  // One of many helper methods, this one re-fills all ships
                  sf.Game.FlightState.FillResources();
    
                  // Setting the title of the save game, this will change in-game name display 
                  // (still need to wire in dir name change)
                  sf.Game.Title = "I AM IRON MAN";
    
                  // Another helper method, this clears all vessels marked as debris or unknown vessel types.
                  sf.Game.FlightState.ClearDebris();
    
                  // Grabbing a vessel from the game 
                  var sat =
                  sf.Game.FlightState.Vessels.Where(v => v.Name.Contains("Beta Geo-Sat")).FirstOrDefault();
    
                  // Changing the orbit (currently defaults to 100km above target)
                  sat.Orbit.Change(Body.Bop);
    
                  // Save file, includes data backup of original file
                  sf.Save();
See Also

Reference