Jump to content

Humbly Requesting Assistance from somebody more experienced then me


Recommended Posts

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)

 

Edited by DevOverlord
Title
Link to comment
Share on other sites

The important part of that error is:

5 hours ago, DevOverlord said:
Could not load file or assembly 'System.Runtime.Serialization

I think that's because System.Runtime.Serialization.dll isn't included in the DLLs that come with the game:

j9jQx1y.png

Try copying it  to your mod's folder in GameData. It's probably already in one of your system folders.

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