Jump to content

Reading save files?


Recommended Posts

Try using DotNetZip library, this is the way I'm reading and it always worked.

// Read the file headerusing (var reader = new BinaryReader(fileStream)){    saveData.FileHeader.Magic = reader.ReadInt32();    saveData.FileHeader._padd1 = reader.ReadChar();    saveData.FileHeader._padd2 = reader.ReadChar();    saveData.FileHeader._Unknown = reader.ReadInt32();    saveData.FileHeader.Encoded = reader.ReadChar();    using (var sreader = new StreamReader(fileStream))        remainingData = sreader.ReadToEnd();}if (saveData.FileHeader.Encoded == 'D'){    // We need to do base64 deconvert first    byte[] data = StringConvert.FromBase64ToBytes(remainingData);    // Create a new stream    var memStream = new MemoryStream(data);    // Read the save header    using (var reader = new BinaryReader(memStream))    {        saveData.SaveHeader.Version = reader.ReadInt32();        saveData.SaveHeader.HeaderSize = reader.ReadInt32();        saveData.SaveHeader.UncompressedSize = reader.ReadInt32();        saveData.SaveHeader.CompressedSize = reader.ReadInt32();        // Decompress the content        var zlibstream = new ZlibStream(memStream, CompressionMode.Decompress);        using (var sreader = new StreamReader(zlibstream))            remainingData = sreader.ReadToEnd();    }}// By here, remainingData contains the actual save file data

PS. FromBase64ToBytes is just a wrapper over System.Convert.FromBase64String

 

 

Thanks! That works!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...