Jump to content

Multiple Sequential Savegames for KSP using AutoHotKey (AHK)


Recommended Posts

Ok, first off, I really don't know where to post this (can't do it in "How-to" and "Tutorials" because that's all about KSP and not some external operation), so I hope the mods can forgive me and move it to some other appropriate section.

This is a system (or think of it as "workaround" to the fact that KSP currently doesn't have multiple-sequential quicksave system akin to Orbiter Space Flight Simulator) which will allow you to save multiple "save states" of your current KSP game, by saving the "persistent.sfs" and "quicksave.sfs" into a series of folders with subfolders named "saveX", where X stands for a number of iterations (currently, the one I made allows for five save state slots, but you can increase this by modifying the AHK script), i.e. save1, save2, save3...etc.

Inspiration comes from an old DOS game called Starflight (which Scott Manley actually featured the other day). I played Starflight I and II back in the late eighties and I recalled tweaking the DOS batch file it had for saving multiple gamestates, and so I realized I can do it for KSP, but this time, instead of using DOS batch files, I used an open source program called AutoHotKey (http://www.autohotkey.com/).

Take note, this method works exclusively for Windows (7) based systems. Won't work for Mac or Linux.

So, here's the script I made, which does the job:


#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^S::
ErrorCount := CopyFilesAndFolders2("C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save4", "C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save5")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders2(SourcePattern2, DestinationFolder2, DoOverwrite2 = true)
{
FileCopy, %SourcePattern2%, %DestinationFolder2%, %DoOverwrite2%
ErrorCount := ErrorLevel
return ErrorCount
}

ErrorCount := CopyFilesAndFolders3("C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save3", "C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save4")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders3(SourcePattern3, DestinationFolder3, DoOverwrite3 = true)
{
FileCopy, %SourcePattern3%, %DestinationFolder3%, %DoOverwrite3%
ErrorCount := ErrorLevel
return ErrorCount
}

ErrorCount := CopyFilesAndFolders4("C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save2", "C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save3")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders4(SourcePattern4, DestinationFolder4, DoOverwrite4 = true)
{
FileCopy, %SourcePattern4%, %DestinationFolder4%, %DoOverwrite4%
ErrorCount := ErrorLevel
return ErrorCount
}

ErrorCount := CopyFilesAndFolders5("C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save1", "C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save2")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders5(SourcePattern5, DestinationFolder5, DoOverwrite5 = true)
{
FileCopy, %SourcePattern5%, %DestinationFolder5%, %DoOverwrite5%
ErrorCount := ErrorLevel
return ErrorCount
}

ErrorCount := CopyFilesAndFolders1("C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\saves\rodion\*.*", "C:\Program files(x86)\Steam\steamapps\common\Kerbal Space Program\savesbackup\rodion\save1")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders1(SourcePattern1, DestinationFolder1, DoOverwrite1 = true)
{
FileCopy, %SourcePattern1%, %DestinationFolder1%, %DoOverwrite1%
ErrorCount := ErrorLevel
return ErrorCount
}

Ok, that script should be saved in a file called ksp_save.ahk (or whatever you want to call it) and put in your desktop. After you've installed AHK, all you need to do is double-click on the ksp_save.ahk file, and the script will run in the background (you know it's running because of the tiny "H" icon on your "tasks running" area, bottom right corner of Windows screen). Now, when you're inside KSP, and doing missions, esp. if you keep doing QUICKSAVES, all you need to do, to ensure that you have multiple sequential instances of quicksaves is, after pressing F5, press CTRL-S, and the script runs in the background, automatically copying backups of your persisent.sfs and quicksave.sfs into the save folders, and it does this sequentially, meaning, the files in "save5" are the oldest *.sfs and the files in "save1" are the most recent.

So what's the logic in this? Well, for instance, you are on a long mission to Jool or a complicated mission to Mun, that has plenty of steps. It's nice if you can jump back "two or three quicksaves back" to a specific earlier point, because "you just didn't hit that burn right". So now, with this method, the whole thing is automated. All you have to do is to remember to press F5 and then CTRL-S. I chose CTRL-S, because in Orbiter Space Flight Simulator, I'm used to pressing this key combo to save my most recent Quicksave (but in Orbiter, of course, the provision for multiple quicksaves is already built-in).

This entire back up procedure is tedious and annoying if you do it manually. So with this system, it can aid in speeding up the task faster, and you don't even need to leave KSP to activate it.

SOME IMPORTANT NOTES:

1. The default folder/directory I placed in the script is only a sample--your actual path to KSP folders be different, so you gotta find that out yourself

2. Like I said, you can extend beyond "save5", but that means adding more line of code...again, up to you

3. I made no provision for "reloading" a particular save instance to be "current", but if you've figured out that AHK script, and know how to code, then it's simple as writing your own AHK script to "reload" an earlier persistent or quicksave game point.

4. And before I forget, you first have to manually create the empty "save" folders (save1, save2, save3, etc.) before running the script--you do this only once

Hope some of you find use for this.

Edited by rodion_herrera
Link to comment
Share on other sites

Nice work! I think alot of people will use this :)

Thanks. Currently in the process of create yet another AHK script that would load the quicksaves from a folder of your choice, by just pressing CTRL-1, CTRL-2, CTRL-3... etc, from within KSP (I don't think these keys are bound by default, to anything in KSP, unless a user made some custom keymaps, so it's a logical choice). So if you press CTRL-2 and then longpress F9, KSP should load your 2nd-to-last quicksaved gamestate. This way, everything will be truly "on the fly". I say "in the process" because I can't finish it...owing to fact that I feel drowsy due to sleep deprivation as a result of playing KSP (and hanging out in these forums ugh).

Link to comment
Share on other sites

Ok, here's the script format for retrieving specific quicksave files (1-5) back into KSP...


#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^1::
ErrorCount := CopyFilesAndFolders1("____your_backup_path_____\quicksave.sfs", "____your_KSP_path_____")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders1(SourcePattern1, DestinationFolder1, DoOverwrite1 = true)
{
FileCopy, %SourcePattern1%, %DestinationFolder1%, %DoOverwrite1%
ErrorCount := ErrorLevel
return ErrorCount
}
^2::
ErrorCount := CopyFilesAndFolders2("____your_backup_path_____\quicksave.sfs", "____your_KSP_path_____")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders2(SourcePattern2, DestinationFolder2, DoOverwrite2 = true)
{
FileCopy, %SourcePattern2%, %DestinationFolder2%, %DoOverwrite2%
ErrorCount := ErrorLevel
return ErrorCount
}
^3::
ErrorCount := CopyFilesAndFolders3("____your_backup_path_____\quicksave.sfs", "____your_KSP_path_____")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders3(SourcePattern3, DestinationFolder3, DoOverwrite3 = true)
{
FileCopy, %SourcePattern3%, %DestinationFolder3%, %DoOverwrite3%
ErrorCount := ErrorLevel
return ErrorCount
}
^4::
ErrorCount := CopyFilesAndFolders4("____your_backup_path_____\quicksave.sfs", "____your_KSP_path_____")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders4(SourcePattern4, DestinationFolder4, DoOverwrite4 = true)
{
FileCopy, %SourcePattern4%, %DestinationFolder4%, %DoOverwrite4%
ErrorCount := ErrorLevel
return ErrorCount
}
^5::
ErrorCount := CopyFilesAndFolders5("____your_backup_path_____\quicksave.sfs", "____your_KSP_path_____")
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders5(SourcePattern5, DestinationFolder5, DoOverwrite5 = true)
{
FileCopy, %SourcePattern5%, %DestinationFolder5%, %DoOverwrite5%
ErrorCount := ErrorLevel
return ErrorCount
}

So, to load the quicksave file in slot 3, I just press CTRL-3 inside KSP. Take note, you still have to LONGpress the F9 key, to actually load up the file (don't forget to do that!) Also, you need to replace the "____your_backup_path_____\quicksave.sfs" and "____your_KSP_path_____" with the path to saved backup and of course, your local KSP location/path

So you have two AHK files running in the background: The saver and the loader.

Edited by rodion_herrera
Link to comment
Share on other sites

I had a AHK script that would fly my craft from Launch pad to the Mun and land. A completely unassisted 'robot' doing a Mun landing. I won't tell you how long that took to 'code' - its embarrassing.

Link to comment
Share on other sites

I had a AHK script that would fly my craft from Launch pad to the Mun and land. A completely unassisted 'robot' doing a Mun landing. I won't tell you how long that took to 'code' - its embarrassing.

LOL but you should try and apply at JPL! Coding that Mun Landing as an AHK script is a superhuman feat! :D

Link to comment
Share on other sites

Ok, first off, I really don't know where to post this (can't do it in "How-to" and "Tutorials" because that's all about KSP and not some external operation), so I hope the mods can forgive me and move it to some other appropriate section.

Unforgivable placement, shame on you! :P

Moved to Tools & Applications

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