Skip to content

Instantly share code, notes, and snippets.

@abaines
Last active November 6, 2020 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abaines/385712ed54e14e2793c40d7b480c1ef3 to your computer and use it in GitHub Desktop.
Save abaines/385712ed54e14e2793c40d7b480c1ef3 to your computer and use it in GitHub Desktop.
Detect quick saves in Dishonored
import os.path
import os
import threading
import hashlib
import shutil
import winsound
quickSaveFileName = 'quicksave.fos'
autoSaveFileName = 'autosave.fos'
def hashSave(saveFileName):
return hashlib.sha224(open(saveFileName,'rb').read()).hexdigest()
#global value of the quick save file hash
quickSaveHash = hashSave(quickSaveFileName)
autoSaveHash = hashSave(autoSaveFileName)
def nameFormat(n,saveFileName):
return str(n).zfill(5)+'.'+saveFileName
def checkAvailable(n,saveFileName):
return os.path.isfile(nameFormat(n,saveFileName))
def firstAvailable(saveFileName):
for x in range(1,9999):
y = checkAvailable(x,saveFileName)
if (not y):
return x
def saveExists(saveFileName):
return os.path.isfile(saveFileName)
def copyQuickSave(n,saveFileName):
shutil.copy2(saveFileName, nameFormat(n,saveFileName))
def compareSavedWithFile(saveHash,saveFileName):
if ( str(saveHash)==str( hashSave(saveFileName) ) ):
return True
else:
return False
def hashTread():
global quickSaveHash
global autoSaveHash
threading.Timer(3.0, hashTread).start()
# check see if a quick save file exists,
# and that it is different from what we have saved
if saveExists(quickSaveFileName) and not compareSavedWithFile(quickSaveHash,quickSaveFileName) :
winsound.Beep(120,60)
# record new quick save hash value
quickSaveHash = hashSave(quickSaveFileName)
# find next available save file location
n = firstAvailable(quickSaveFileName)
print(nameFormat(n,quickSaveFileName) + ' ' + quickSaveHash )
# copy the quicksave to next spot
copyQuickSave(n,quickSaveFileName)
winsound.Beep(320,60)
if saveExists(autoSaveFileName) and not compareSavedWithFile(autoSaveHash,autoSaveFileName) :
winsound.Beep(120,60)
# record new quick save hash value
autoSaveHash = hashSave(autoSaveFileName)
# find next available save file location
n = firstAvailable(autoSaveFileName)
print(nameFormat(n,autoSaveFileName) + ' ' + autoSaveHash )
# copy the quicksave to next spot
copyQuickSave(n,autoSaveFileName)
winsound.Beep(320,60)
hashTread()
print(quickSaveHash)
print(autoSaveHash)
@abaines
Copy link
Author

abaines commented Nov 6, 2020

Transformed into auto save detector for Fallout: New Vegas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment