Jump to content

[C# Plugin] Get the save file game was saved to, like quicksave.sfs, persistent.sfs, etc. and also get the loaded save file


Recommended Posts

Hello there! I'm making a plugin for KSP and I've run into an issue. How to get the save file game was saved to, like quicksave.sfs, persistent.sfs, etc.? For example, some settings need to be saved to SFS file, and when a player loads some save (persistent, quicksave or other), they'll need to load too.

GAME {
	(some game stuff)
}

MY_MOD {
	param1 = 1
    param2 = Some Parameter
    param3 = true
}

Thank you in advance for your answer :)

Link to comment
Share on other sites

Before you worry about the file name, you should try to use the built-in save/load functionality if at all possible. If your class inherits from ScenarioModule and has the KSPScenario attribute, its OnSave and OnLoad methods will be called when the game saves and loads, and the parameter is a ConfigNode that you can save to/load from, that will automatically be included in/retrieved from the save file.

 

Link to comment
Share on other sites

8 hours ago, HebaruSan said:

Before you worry about the file name, you should try to use the built-in save/load functionality if at all possible. If your class inherits from ScenarioModule and has the KSPScenario attribute, its OnSave and OnLoad methods will be called when the game saves and loads, and the parameter is a ConfigNode that you can save to/load from, that will automatically be included in/retrieved from the save file.

 

I worry about the file name because I'm making a salary mod and I'm afraid players will be able to bypass it. For example, a player quicksaved a game, paid to kerbals their salary and then quickloaded and saved funds. I'm new to mod development, so I don't know literally anything about saving data. Also, if a player loads a fairly old save, all settings should load too.

Edited by cymon4380
minor correction
Link to comment
Share on other sites

3 hours ago, cymon4380 said:

I worry about the file name because I'm making a salary mod and I'm afraid players will be able to bypass it. For example, a player quicksaved a game, paid to kerbals their salary and then quickloaded and saved funds.

That's probably impossible to prevent, given that the user controls the computer where the code runs.

It's probably also a bad idea to try to prevent it. What user would keep using a mod that didn't allow them to play the way they wanted to?

Link to comment
Share on other sites

55 minutes ago, HebaruSan said:

That's probably impossible to prevent, given that the user controls the computer where the code runs.

It's probably also a bad idea to try to prevent it. What user would keep using a mod that didn't allow them to play the way they wanted to?

Ok, I got it. Anyway, how can I know if the game was saved and then save mod settings into save file? And also load settings when loading save. Please reply ASAP, I wanna create my mod in a few days. Thank you.

Link to comment
Share on other sites

13 minutes ago, cymon4380 said:

Ok, I got it. Anyway, how can I know if the game was saved and then save mod settings into save file? And also load settings when loading save. Please reply ASAP, I wanna create my mod in a few days. Thank you.

You can try what I suggested earlier:

12 hours ago, HebaruSan said:

Before you worry about the file name, you should try to use the built-in save/load functionality if at all possible. If your class inherits from ScenarioModule and has the KSPScenario attribute, its OnSave and OnLoad methods will be called when the game saves and loads, and the parameter is a ConfigNode that you can save to/load from, that will automatically be included in/retrieved from the save file.

That last link is sample code that does exactly this for one of my mods.

Link to comment
Share on other sites

22 hours ago, HebaruSan said:

You can try what I suggested earlier:

That last link is sample code that does exactly this for one of my mods.

Thank you very much! It works! Now I can resume my mod development :)

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