Author Topic: Avoiding corrupted saved game catastrophe using Git  (Read 3978 times)

Offline WildLemur

  • Nooboo
  • *
  • Posts: 4
Avoiding corrupted saved game catastrophe using Git
« on: March 01, 2014, 05:04:15 PM »
This is not so much a question as it is a description of the workaround I use to avoid losing The Sims 3 game data.  It also turns out to be a handy way to turn back the clock if you want to.  I don't expect this to be helpful to most people, but maybe to a few, so I decided to post.  I hope this is an appropriate forum to use.

I just had my first experience with a corrupted save.  Restoring from the <my game>.backup directory exhibited the same issue (no panels, no way to select an active sim, etc.), so after an hour or so of Googling and tinkering, I decided to give up and start over.  This made all the hours I'd spent on the game seem like rather a waste of time.  Moreover, there was no hint from the game that a serious problem had occurred.  I had saved and quit, just I've done probably hundreds of times, and the game seemed to shutdown fine.  I no longer had confidence that my saved game were really being saved, to the extent that I was sometimes tempted to load it up again after quitting, just to check.

Of course, shame on me for not keeping a backup, but I've been playing this game for years and had never had this happen before.  Plus, it's just a Windows computer that I keep solely for playing games.  All my important stuff lives much more safely elsewhere.  But lesson learned; if I don't want to lose too much when there's a file save glitch, then I need a backup plan.

So here is how I typically play The Sims 3 now...

We use Git (http://en.wikipedia.org/wiki/Git_(software)) at work for revision control, so I'm pretty comfortable with it.  I think even non-technical people can get used to Git, since it really boils down to knowing just a few good commands, but I wouldn't blame anyone if they stopped reading right now.  Basically it's a simple tool used to snapshot sets of files within a directory on your computer, and by simple, I mean it's low-level and can be quite powerful.  You can download Git for Windows here: http://msysgit.github.io/.  It comes with a great command line tool called Git Bash.  Now whenever I open The Sims 3, I also open Git Bash and use it to take a snapshot after each save in the game.  From these snapshots, I can easily travel backward and forward to various points in Sim time, even branching out to play with alternate Sim histories.

Step 0. Setting up Git

a. Open Git Bash

b. Set your name and e-mail.  Git is generally used for collaboration, so sharing your name and how to be reached usually makes sense.  But for purposes of just doing local backups, these can be fictitious:

    $ git config --global user.name "Me"
    $ git config --global user.email "[email protected]"

Step 1. Initialize a Git repository (usually abbreviated as a "repo") in the Sims Saves directory:

a. Open Git Bash

b. Change to the Saves directory:

    $ cd ~/Documents/Electronic\ Arts/The\ Sims\ 3/Saves
   
c. Initialize the directory for Git:

    $ git init
    Initialized empty Git repository in c:/<path to Saves>/.git/
   
d. Take your first snapshot (this is called a "commit"):

    $ git add -A
    $ git commit -m "Initial snapshot"
   
    "git add -A" tells git to gather information about all new, deleted or changed files in the directory.  This "stages" changes to be applied to the next commit.  "git commit -m <message>" makes the actual commit and attaches the message given by the -m argument.

Step 2. Play The Sims 3!!!

a. After (or before!) some significant event, save your game.

b. After The Sims 3 finishes saving, hop over to Git Bash.

c. (optional) Check for changes:

    $ git status
    On branch master
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working d

            modified:   SimsSave.sims3.backup/Sims University_0x0e41c9
            modified:   SimsSave.sims3/Sims University_0x0e41c954.nhd

    no changes added to commit (use "git add" and/or "git commit -a")
   
    We expect to see a few files displayed here, since they were just updated by the game.  The file names on your system may be different, depending on what you named your saved game.
   
d. Stage changes:

    $ git add -A
   
e. Take snapshot:

    $ git commit -m "Before enrolling in university"
   
    You just saved this point in Sim time as a commit.  Now, assuming The Sims 3 didn't corrupt its save earlier, you can come back and play from here again later.
   
To see a list of commits:

    $ git log
    commit 9687a1c05d71c88c84ee95456a42b52da845a092
    Author: Me <[email protected]>
    Date:   Sat Mar 1 12:33:30 2014 -0800

        Before enrolling in university

    commit 6691b3ec6f3b6ef1ec7e31ae819c1c5818ea0fa3
    Author: Me <[email protected]>
    Date:   Sat Mar 1 09:56:57 2014 -0800

        Initial commit

This post is probably already too long, so I won't go into all the things you can do with The Sims 3 + Git, but I will quickly show how to travel back in time.  You might do this if your last game was corrupted, or if you just don't like how things have been going in the game lately.

Suppose your commit history (from the "git log" command) looks something like this:

    $ git log
    commit d6da1d69ebd97a74bc67d10b863560bd01d9ffac
    Author: Me <[email protected]>
    Date:   Sat Mar 1 12:52:08 2014 -0800

        Just totally failed that exam

    commit 40ca94998c1c5efcd3fe54c1ac7aa16aeaec31b5
    Author: Me <[email protected]>
    Date:   Sat Mar 1 12:51:05 2014 -0800

        Holy Moly that was a great party!

    commit 26bb901dabf8098ddcf0faf93b1fae7581795d63
    Author: Me <[email protected]>
    Date:   Sat Mar 1 12:50:45 2014 -0800

        Wow, another great party!

    commit 47e4d6937366b92d082f6fd6ffc3976ce6af1bf3
    Author: Me <[email protected]>
    Date:   Sat Mar 1 12:49:55 2014 -0800

        Wow, great party!

    commit 668e71853d10651e652ad3992bf71b89798e0248
    Author: Me <[email protected]>
    Date:   Sat Mar 1 12:48:47 2014 -0800

        Went to first class at university

    commit e141279fa7b59ecf787ad016a77b2a810d53d84c
    Author: Me <[email protected]>
    Date:   Sat Mar 1 12:48:00 2014 -0800

        Before enrolling in university
       
You'd sure like to have that week back and possibly get a better grade on the exam.  Let's go back to commit 668e71853d10651e652ad3992bf71b89798e0248, which is probably where things started to go wrong (or right, depending on how you look at it).

a. First, quit The Sims 3.  (It seems okay to make changes to the Saves directory while the game is running and then simply return to the main menu, and given the time it takes to load the game from scratch, may be worth the risk.  But to be cautious, go ahead and close the game.)

b. Update The Sims 3 saved game data from the desired commit:

    $ git checkout -b try-for-better-grades 668e71853d10651e652ad3992bf71b89798e0248
   
    This command does two things: 1) replaces the contents of the Saves directory with the snapshot you took after saving the game when your Sim went to their first class, and 2) creates a "branch" with the name try-for-better-grades.
   
    Think of a branch as an alternate history.  Commits along a branch can remain completely independent of those in another branch if you never decide to merge them, which I won't go into here.  Merging branches is usually a normal part of using Git, but in this case I can't really see how it would make sense and might even end in disaster.
   
    You can always see a list of existing branches, including what branch you're currently on:
   
    $ git branch -a
      master
    * try-for-better-grades
   
    "master" is the default branch that Git created when you ran "git init", and whatever branch has the asterisk to its left is the branch you're on.  "git status" also shows what branch you're on:
   
    $ git status
    On branch try-for-better-grades <-- see, it says!
    nothing to commit, working directory clean
   
c. Start The Sims 3.  The main menu should display the set of saved games that existed at the time the commit you just branched from was created (ouch, that hurt to write).

I don't think it pays to get too fancy with this.  It's mainly just another way to backup The Sims 3 Saves directory.  There are certainly downsides, disk usage being the one that comes to mind first off.  There will be a .git subdirectory within Saves that can grow quite large over time, I think because of the way Git treats binary files.  I like to use the git rebase command to "squash" commits I know I'll never never need.  You can also delete whole branches that no longer interest you:

    $ git branch -D pursue-career-in-crime

This allows Git's own garbage control to shrink the repository eventually.  Or to shrink it immediately, you can run:

    $ git gc --prune=now --aggressive
   
So that's it for now.  I hope this may be useful to someone.

Update 2014-03-02

I use WinDirStat to keep track of the Saves/.git directory size.  https://windirstat.info/

Offline jesirose

  • Occult
  • ****
  • Posts: 406
Re: Avoiding corrupted saved game catastrohpes
« Reply #1 on: March 01, 2014, 05:18:10 PM »
OMG using Git to manage saved games may be the most brilliant thing I have ever seen. *bows*
- Jessica



Registered members do not see ads on this Forum. Register here.