Jump to content

DevOverlord

New Members
  • Posts

    3
  • Joined

  • Last visited

Reputation

0 Neutral
  1. Hello, There is a hobby project that I'd like to undertake and I need to some data from KSP that, based on my research, is only available whilst the game is running. I've spent about 3 days exploring various techniques of getting at the data (including trying to do it from my language of choice, GoLang) and after accepting defeat due to a lack of understanding of hooking into a DLL from Golang, finally settled on just writing a plugin, even though I believe it is probably overkill due to i think it being a one time thing. What I need is to serialize the `FlightGlobals.Bodies` list to JSON but also include the attributes from each of the Bodies PQSControllers. I want to generate Google Maps esq Maps of Kerbin, like what the https://github.com/Sigma88/Sigma-Cartographer Mod does but outside of the game. I'm struggling getting a JSON Serializer to work, and about to pull the very little amount of hair I have on my middle aged head out. Can somebody assist me? Below is a HelloWorld script that I've been trying to do this in. I want to wrap this up with I am not a C# Dev and I'm struggling to understand your ecosystem. So i apologize if I did something stupid already Code: using System.IO; using UnityEngine; using Newtonsoft.Json; namespace HelloKSC { [KSPAddon(KSPAddon.Startup.MainMenu, false)] public class HelloKerbal : MonoBehaviour { public void Start() { FlightGlobals.Bodies.ForEach(delegate (CelestialBody body) { string json = JsonConvert.SerializeObject(body); File.WriteAllText(@"C:\Users\<sanitized>\kerbinexcrements\" + body.name + ".txt", json); }); } } } [EXC 12:48:32.413] BadImageFormatException: Could not resolve field token 0x0400049e, due to: Could not load type of field 'Newtonsoft.Json.Utilities.EnumUtils+<>c:<>9__1_0' (1) due to: Could not load file or assembly 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. assembly:System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 type:<unknown type> member:(null) signature:<none> assembly:R:\SteamLibrary\steamapps\common\Kerbal Space Program\GameData\HelloKerbin\Newtonsoft.Json.dll type:<>c member:(null) signature:<none> Newtonsoft.Json.JsonWriter.BuildStateArray () (at <607e95f78559498690f968784b884761>:0) Newtonsoft.Json.JsonWriter..cctor () (at <607e95f78559498690f968784b884761>:0) Rethrow as TypeInitializationException: The type initializer for 'Newtonsoft.Json.JsonWriter' threw an exception. Newtonsoft.Json.JsonTextWriter..ctor (System.IO.TextWriter textWriter) (at <607e95f78559498690f968784b884761>:0) Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) (at <607e95f78559498690f968784b884761>:0) Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) (at <607e95f78559498690f968784b884761>:0) Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) (at <607e95f78559498690f968784b884761>:0) HelloKSC.HelloKerbal+<>c.<Start>b__0_0 (CelestialBody body) (at <2bce455990724ead90e1b3b0bf15f9b8>:0) System.Collections.Generic.List`1[T].ForEach (System.Action`1[T] action) (at <9577ac7a62ef43179789031239ba8798>:0) HelloKSC.HelloKerbal.Start () (at <2bce455990724ead90e1b3b0bf15f9b8>:0)
×
×
  • Create New...