Advertisement
Sharlikran

readcosave

Sep 9th, 2017
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.60 KB | None | 0 0
  1. # Imports ---------------------------------------------------------------------
  2. import struct
  3. import io
  4.  
  5. path = 'Save70_A3AA8A36M4C696C6C79_Commonwealth_010659_20170908034503_16_2.f4se'
  6.  
  7. class FileReader(io.FileIO):
  8.     """File-object with convenience reading functions."""
  9.  
  10.     def unpack(self, fmt):
  11.         return struct.unpack(fmt, self.read(struct.calcsize(fmt)))
  12.  
  13.     def readUByte(self): return struct.unpack('B', self.read(1))[0]
  14.     def readUInt16(self): return struct.unpack('H', self.read(2))[0]
  15.     def readUInt32(self): return struct.unpack('I', self.read(4))[0]
  16.  
  17.     def readByte(self): return struct.unpack('b', self.read(1))[0]
  18.     def readInt16(self): return struct.unpack('h', self.read(2))[0]
  19.     def readInt32(self): return struct.unpack('i', self.read(4))[0]
  20.  
  21.     def readSig(self): return struct.unpack('4s', self.read(4))[0]
  22.     def readString8(self): return self.read(struct.unpack('B', self.read(1))[0])
  23.     def readString16(self): return self.read(struct.unpack('H', self.read(2))[0])
  24.     def readString32(self): return self.read(struct.unpack('I', self.read(4))[0])
  25.  
  26. def readChunk(file):
  27.     chunkType = FileReader.readSig(file).decode("utf-8")
  28.     chunkVersion = FileReader.readInt32(file)
  29.     chunkLength = FileReader.readInt32(file)
  30.     chunkData = file.read(chunkLength)
  31.     chunkValue = []
  32.     chunkValue.append(chunkType)
  33.     chunkValue.append(chunkVersion)
  34.     chunkValue.append(chunkLength)
  35.     chunkValue.append(chunkData)
  36.     print (chunkValue)
  37.     return chunkValue
  38.  
  39. def readChunks(file):
  40.     opcodeBase = FileReader.readInt32(file)
  41.     numChunks = FileReader.readInt32(file)
  42.     pluginLength = FileReader.readInt32(file)
  43.     chunkBlock = []
  44.     for x in range(numChunks):
  45.         chunkBlock.append(readChunk(file))
  46.     return chunkBlock
  47.  
  48.  
  49. def main():
  50.     """Main function, fires everything off."""
  51.     cosave_file = open(path,'rb')
  52.     signature = FileReader.readSig(cosave_file).decode("utf-8")
  53.     formatVersion = FileReader.readInt32(cosave_file)
  54.     obseVersion = FileReader.readInt16(cosave_file)
  55.     obseMinorVersion = FileReader.readInt16(cosave_file)
  56.     oblivionVersion = FileReader.readInt32(cosave_file)
  57.     numPlugins = FileReader.readInt32(cosave_file)
  58.  
  59.     print ("Signature: ", signature)
  60.     print ("formatVersion: ", formatVersion)
  61.     print ("obseVersion : ", obseVersion)
  62.     print ("obseMinorVersion: ", obseMinorVersion)
  63.     print ("oblivionVersion: ", oblivionVersion)
  64.     print ("numPlugins: ", numPlugins)
  65.     for x in range(numPlugins):
  66.         readChunks(cosave_file)
  67.     cosave_file.close()
  68.  
  69. if __name__=='__main__':
  70.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement