Jump to content

Editing persistent.sfs


Recommended Posts

Hi all,

I am currently working on a mod which (in theory) should allow players to create a kerbal from within the game, then let them add him to their crew. In order to do this, I need to be able to access the persistent.sfs file found in the save that the player is currently using, and then add in the kerbal. Problem is, I don't know how to access and edit the persistent.sfs file using my plugin. I have this code which works, but how would I be able to make it take the values and add them to persistent.sfs?

              if (GUI.Button(new Rect(7, 125, 150, 30), "Kreate Kustom Kerbal"))
{
Debug.Log("Kustom Kerbal Kreated.");
Debug.Log("Name: " + stringToEdit);
Debug.Log("Courage: " + sliderValue);
Debug.Log("Stupidity: " + sliderValue2);
Debug.Log("Badass: " + buttonState);
//KERBAL
//{
// name = stringToEdit
// type = Crew
// brave = sliderValue
// dumb = sliderValue2
// badS = buttonState
// state = Available
// ToD = 0
// idx = -1
// }

Also, is there any way to make it so that the player can't click buildings that are under the window? The way I have it now, you have to grab a corner then move it away from the buildings to be able to edit the fields.

Edited by Jetwave
Link to comment
Share on other sites

Just get the full URL of the persistence file and load it with ConfigNode.Load(node). You can find the current name of the save folder in HighLogic.currentGame iirc, and the rest can be done with System.IO. As for not clicking through, I don'T think you can. The editor has this feature, but I don't think it's implemented in the space center, and you might have to do GUI shennanigans for it to work.

Link to comment
Share on other sites

Also, is there any way to make it so that the player can't click buildings that are under the window? The way I have it now, you have to grab a corner then move it away from the buildings to be able to edit the fields.

I think [thread=69310]KCT[/thread] manages this. You could look at that code.

Link to comment
Share on other sites

Just get the full URL of the persistence file and load it with ConfigNode.Load(node). You can find the current name of the save folder in HighLogic.currentGame iirc, and the rest can be done with System.IO. As for not clicking through, I don'T think you can. The editor has this feature, but I don't think it's implemented in the space center, and you might have to do GUI shennanigans for it to work.

So I would do ConfigNode.Load(HighLogic.currentGame*persistence file*)? If so what do I put to make it load the persistence file?

Also, would something similar to this work?

using System.IO;
using UnityEngine;

public static class File

public static StreamWriter AppendText(ConfigNode.Load(HighLogic.CurrentGame*persistence file*))
{
if (createKerbal == true) //boolean set to true when player clicks create
{
StreamWriter
{
KERBAL
{
name = stringToEdit
type = Crew
brave = sliderValue
dumb = sliderValue2
badS = buttonState
state = Available
ToD = 0
idx = -1
}
}
createKerbal = false;
}
}

What I'm thinking with this is that it'll go in the extensions folder of my plugin as a new class, and whenever the player hits the create button, the createKerbal bool will be set to true, thus activating the code. Then once it's done copying to persistence.sfs, it'll set the bool to false again, until the player clicks create. Is that what will actually happen?

Edited by Jetwave
Link to comment
Share on other sites

No that wouldn't work.

First off, as I said you need the /full/ path. Not the local path.

Second, you'll want to add stuff to confignodes, and I recommend you learn how they work to start with. I reccomend a trip to #kspmodders for that, though I might be too asleep to be able to guide you around correctly. Someone might be able to help though.

Link to comment
Share on other sites

Wouldn't the path be different for different people though? Like wouldn't using steam vs using the launcher have different paths, and different OSes, whether the OS is x64 or x86, if the player uses a custom path.. etc.?

Link to comment
Share on other sites

Wouldn't the path be different for different people though? Like wouldn't using steam vs using the launcher have different paths, and different OSes, whether the OS is x64 or x86, if the player uses a custom path.. etc.?

That's why you should fetch the path, and don't try to guess it? :P

KSPUtil.ApplicationRootPath will return the full path to the KSP folder, but there's many ways to do it. You can do Assembly.GetExecutingAssembly().Location to get the path directly to your plugin folder, etc. C# is very well documented, googling any question not related to KSP will usually give you a nice answer easily.

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