Jump to content
LaunchBox Community Forums

AHK script to save a game folder after a game quits. Is it possible and if so how?


Kinglifer

Recommended Posts

I am going back to my kid days by installing Transformers War / Fight for Cybertron (Two awesome PC games made by Activision). The main issue is both games put the save games in the exact same spot with the exact same name.

"C:\Users\GamerPC\Documents\My Games\Transformers\TransGame\"

Even if you do nothing the save game becomes corrupt if you load the other game out of the two. You then loose the saves from the previous game. So the file must be moved or renamed to keep it intact.

I was trying to use Display Fusion Pro (It has scripts to copy files etc.) but the Load before and Load after section in Additional Apps is not working. I did a test run to show a pop up while the script is running so I know it does it but somehow the game just boots back to the original startup (as if there was never a save game). If I do it manually it works obviously. (Copy the file then start the game).

Is there a script that can do this for me and how would I set it up? 

 

game path ..\TRANSFORMERS.War.for.Cybertron\TRANSFORMERS - War for Cybertron\Binaries\TWFC.exe

my back up save path is ..\TRANSFORMERS.War.for.Cybertron\TRANSFORMERS - War for Cybertron\

 

and for the other game... 

game path ..\Transformers.Fall.of.Cybertron.Incl.ALL.DLCs\Transformers - Fall of Cybertron\Binaries\TFOC.exe

back up save path is ..\Transformers.Fall.of.Cybertron.Incl.ALL.DLCs\Transformers - Fall of Cybertron\Binaries\

 

both games save the game progress in "C:\Users\GamerPC\Documents\My Games\Transformers\TransGame\"

exact same name so that is where the conflict happens.

 

Even a renaming process could work instead of moving the folder like "WOCsavegame" and "FOCsavegame" and returns that folder back to "TransGame" before whatever game starts.

 

HELP!

 

Edited by Kinglifer
typo
Link to comment
Share on other sites

well that is some of the worst file management I've ever heard of from so called professionals 🤦‍♂️. you can use a script to move/copy the file(s) around as needed to keep things sorted for yourself.

Lets consider the structure of what you need done here. I'll call them game A and game B for the ex. When game A boots it first needs to look for a game A specific save file. It will take this game A save file and copy it to the normal save file location with the normal file name. Now the game uses this game A save file that was placed in the normal location and you play the game. After exiting the game the save file that was just created in the normal save file location must be copied to overwrite the previous game A specific save file. Rinse and repeat each time this game is launched. Then change things accordingly for game B and you're done

I assumed for the example here that the save file is called savefile.dat and recommend keeping these files in the normal save location. change out the save file and game exe as needed. You will need a separate script for each game. Please note this script needs to run before the main application since you need to make sure the game specific save file is copied to the normal save file location prior to the game booting. This script also requires you have already created the game specific save files manually prior to first using it.

in the end this means you will have three save files in the same folder: normal save file, game A specific save file, and game B specific save file.  they all get copied and overwritten as needed per the scripts. I have that sleep bit in there because who knows when the game is actually writing the save file, if anything waits until the game exits it needs a brief moment to finish making the write. so this may not be needed, but it's there out of an abundance of caution

 

;will copy the game specific save file to normal save file location with normal/shared file name
;1 value = the file will be overwritten if it already exists
FileCopy, C:\Users\GamerPC\Documents\My Games\Transformers\TransGame\TWFCsavefile.dat, C:\Users\GamerPC\Documents\My Games\Transformers\TransGame\savefile.dat, 1

;Waits for game to exist - insert game's exe file name
WinWait, TWFC.exe

;Waits for game to exit - insert game's exe file name
WinWaitClose, TWFC.exe

;Pauses script to ensure enough time has passed for the save file to be written prior to copying it
Sleep, 5000

;will take the game save that was made at exit of current session and overwrite the specific game A or game B save file
;1 value = the file will be overwritten if it already exists
FileCopy, C:\Users\GamerPC\Documents\My Games\Transformers\TransGame\savefile.dat, C:\Users\GamerPC\Documents\My Games\Transformers\TransGame\TWFCsavefile.dat, 1

 

Link to comment
Share on other sites

  • 2 weeks later...
On 2/1/2023 at 2:28 PM, Kinglifer said:

will this work with folders? the save game is a folder

 yes, AHK can manipulate folders. I'll transpose my previous example to use FileCopyDir. This does the same thing but with folders instead

 

;at boot of game copy the game specific save folder to normal/shared location with normal/shared name
;1st parameter = source / 2nd parameter = destination / 3rd parameter = overwrite (1 = will overwrite / 0 = will not overwrite)
FileCopyDir, C:\Users\*USER-NAME*\Documents\My Games\Transformers\TransGame\*GAME SPECFIC SAVE FOLDER*, C:\Users\*USER-NAME*\Documents\My Games\Transformers\TransGame\SaveData, 1

;Waits for game to exist
WinWait, *GAME EXE NAME*.exe

;Waits for game to exit
WinWaitClose, *GAME EXE NAME*.exe

;Pauses script to ensure enough time has passed for the save file to be written prior to copying it
Sleep, 5000

;will take the save folder in the normal/shared location that was made at exit of current game session and overwrite the game specific save folder
;1st parameter = source / 2nd parameter = destination / 3rd parameter = overwrite (1 = will overwrite / 0 = will not overwrite)
FileCopyDir, C:\Users\*USER-NAME*\Documents\My Games\Transformers\TransGame\SaveData, C:\Users\*USER-NAME*\Documents\My Games\Transformers\TransGame\*GAME SPECFIC SAVE FOLDER*, 1

this is just an example since you will need to fill in the * marked stuff. when all is said and done, in the "TransGame" folder you will now for ex have three folders 1) SaveData 2) TWFC Saves 3) TFOC Saves

 

 

On 2/1/2023 at 2:28 PM, Kinglifer said:

Wish I could just kick out code like this on the fly. That is awesome. 

if you want to learn, doing something basic like copying a folder or file around would be an excellent first training mission for you! here's these commands doc pages for reference.  I do think It's better to teach a man to fish rather than to give a man a fish as the saying goes

https://www.autohotkey.com/docs/v1/lib/FileCopy.htm

https://www.autohotkey.com/docs/v1/lib/FileCopyDir.htm

 

Check this out

https://www.pcgamingwiki.com/wiki/Transformers:_War_for_Cybertron

https://www.pcgamingwiki.com/wiki/Transformers:_Fall_of_Cybertron

According to PCGamingWiki this suggests you would also have a problem with the "configuration file" being overwritten by each game because it says they are both in the same location. but maybe both games were developed so similar that whatever data they are after in the config file is the same. nothing to worry about since you haven't noticed a problem, just thought it's funny they did the same mistake to more files. also according to their database the save file(s) are in a folder called "SaveData" with the full path being %USERPROFILE%\Documents\My Games\Transformers\TransGame\SaveData. the script I shared here uses this directory path since I'm assuming you just accidentally left off the SaveData part

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...