vicawoo
Chieftain
- Joined
- Feb 12, 2007
- Messages
- 3,226
pickle.loads(loadDataStr)
I'm trying to unpickle Civ 4 BTS save files, that is, extract it from a data file into the game object.
I'm assuming you can use pickle.loads to load save files, because in CvAppInterface.py, it uses
and correspondingly it stores data using
Since I have no idea what I'm doing, I copied this pickling code from docs.python.org
where I renamed a BTS save file datasave
and I get an error
Certainly there's a lot that could have gone wrong. For now, I want to load the save in the correct format.
pickle.loads(loadDataStr), it seems so close to unravelling the BTS save format. Help?
I'm trying to unpickle Civ 4 BTS save files, that is, extract it from a data file into the game object.
I'm assuming you can use pickle.loads to load save files, because in CvAppInterface.py, it uses
Code:
def onLoad(argsList):
'Called when a file is loaded'
import pickle
import CvEventInterface
loadDataStr=argsList[0]
if len(loadDataStr):
CvEventInterface.onEvent( ('OnLoad',pickle.loads(loadDataStr),0,0,0,0,0 ) )
and correspondingly it stores data using
Code:
def onSave():
'Here is your chance to save data. This function should return a string'
import CvWBDesc
import pickle
import CvEventInterface
# if the tutorial is active, it will save out the Shown Messages list
saveDataStr = pickle.dumps( CvEventInterface.onEvent( ('OnSave',0,0,0,0,0 ) ) )
return saveDataStr
Since I have no idea what I'm doing, I copied this pickling code from docs.python.org
Code:
import pprint, pickle
pkl_file = open('datasave', 'r')
data1 = pickle.loads(pkl_file)
pprint.pprint(data1)
data2 = pickle.load(pkl_file)
pprint.pprint(data2)
pkl_file.close()
where I renamed a BTS save file datasave
and I get an error
Code:
Traceback (most recent call last):
File "C:\Python24\pickle_test.py", line 5, in -toplevel-
data1 = pickle.loads(pkl_file)
File "C:\Python24\lib\pickle.py", line 1393, in loads
file = StringIO(str)
TypeError: expected read buffer, file found
Certainly there's a lot that could have gone wrong. For now, I want to load the save in the correct format.
pickle.loads(loadDataStr), it seems so close to unravelling the BTS save format. Help?