Serialized Save File Format

I have used a text editor to read a save file created with:

BinaryFormatter.Serialize(fileStream, saveData);

and the format doesn’t appear to written in binary when interpreted by Notepad. What format is this binary data being written in here?

I’m not sure what you’re asking. The BinaryFormatter uses a very verbose binary format. It’s actually the remoting protocol that is used. I always recommend to not use the BinaryFormatter for save game files because:

  • The files get quite big due to the verbose information stored. The remoting protocol essentially stores the whole class / type descriptions of the objects saved.
  • Many just use it because it’s simple to use and they think the data is somewhat protected against user manipulations. Though since the format is a well known format it’s quite trivial to read / modify any value stored.
  • The BinaryFormatter is extremely sensitive to any kind of structural changes to the objects saved. So adding or removing any field to the class you save will break all previous save game files.

I can asure you that the data is stored in binary. However you might have the wrong idea what binary means. Text is also stored in binary. Notepad can’t really view, let alone editing binary formats since it interprets everything as text. Of course actual texts within the binary format would be viewed correctly. This is true for any binary formats. To view the file for debug purposes I would recommend to use a hexeditor. If you don’t have any hex editor installed you can use an online editor like this one. It also has a nice data inspector.

If you have any further questions regarding the format, feel free to get more concrete in your question. I can read the format pretty much directly. (I spend quite some time analysing the format ^^).

I’m interested in passing the data that has been written into a filestream format to a JSLIB method that will download it to a file. This is a formatted filestream written into a file by the binary formatter using a custom saveData struct:

ÿÿÿÿ FAssembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null PStructs.savedProblemRun nameinputChangesprintRunInt PStructs.problemRunData adamTest a a PStructs.problemRunData ûÿÿÿPStructs.problemRunData isEngagedoperatorChangedriveChangeregistrationLRChangeregistrationUDChange newAnilox €? €? ffæ?úÿÿÿûÿÿÿ ? ? ? ? Aùÿÿÿûÿÿÿ ? ? ? ?ffæ?øÿÿÿûÿÿÿ ? ? ? ?ffæ?÷ÿÿÿûÿÿÿ ? ? ? ?ffæ?öÿÿÿûÿÿÿ ? ? ? ?ffæ?õÿÿÿûÿÿÿ ? ? ? ?ffæ?

As you can see, there is plain text in this file. The following was created using a memorystream, the same saveData struct, and the binary formatter:

t3.crf # ««««««««««««««««) á e‘ Ãx›4à €¿ €¿ €? ÿ „4? y> Ëhºe‘ Ãjó0C €¿ €¿ €? ÿ „4? øœ> €ÿCËhºÔ7aCjó0C €¿ €¿ €? ÿ <A? øœ>øÿIËhºÔ7aCx›4à €¿ €¿ €? ÿ <A? y> €ÿIËhº €¿ €¿ €?ÿÿÿÿ €¿ €¿ €?ÿÿÿÿ €¿ €¿ €?ÿÿÿÿ €¿ €¿ €?ÿÿÿÿ 1 s ™ 9 9 7

WebGL has been a bit sensitive to the type of data i have been attempting to pass it. When I use File.ReadAllBytes on a freshly written formatted filestream I was getting all sorts of JS errors so I attempted to switch methods for creating the byte.

I suppose my question then becomes, how do I write a byte array with all of the verbosity to a byte array?