Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by The_Kakaze · May 19, 2020 at 03:10 PM · saveloadsave-to-file

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · May 20, 2020 at 01:02 AM

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 ^^).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image The_Kakaze · May 20, 2020 at 06:08 PM 0
Share

So say i wanted to produce the same hexidecimal stream in a way where the data was accessible in exactly the same format that binaryformatter produces, text bits and all. Any thoughts on how that might be done?

avatar image
0

Answer by The_Kakaze · May 20, 2020 at 12:04 PM

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 name inputChanges printRunInt PStructs.problemRunData[]   adamTest     PStructs.problemRunData ûÿÿÿPStructs.problemRunData isEngagedoperatorChange driveChangeregistrationLRChangeregistrationUDChange 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  # ««««««««««««««««) á   ‘ Ãx›4à €¿ €¿ €? ÿ „4? y> Ëhº‘ Ãjó0C €¿ €¿ €? ÿ „4? øœ> €ÿCËhºÔ7Cjó0C €¿ €¿ €? ÿ øÿIËhºÔ7Cx›4à €¿ €¿ €? ÿ €ÿ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?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · May 20, 2020 at 09:24 PM 0
Share

Well, first of all you should have mentioned your actual issue in your question. Second it's completely unclear what you're actually doing to "pass it to a JSLib". What do you actually want to do in the JSLib with the data? If you just want to initiate a download in the browser, I can recommend my download helper class for WebGL. It essentially encodes the data as a base64 string which is send to a JSLIB which will create a temporary anchor element with a data URL and simulate a click on it to initiate the download of the data.


Note that the script contains some editor code that will extract the JSLIB into the plugin folder. However for that to happen you have to click run at least once in the editor before building your application.

avatar image The_Kakaze Bunny83 · May 21, 2020 at 12:07 PM 0
Share

Thank you so much! I'm going to write this up in more detail on the other thread where I asked this question directly, but it turns out that all i was missing was two things: the byte array sent to JS as a Base64 string, and the back half of your $$anonymous$$I$$anonymous$$E type: 'charset=utf-8;base64,'

The reason why I wrote the question with the phrasing I did was that I believed I didn't understand how to write the output file in JavaScript: the 'format' of the $$anonymous$$I$$anonymous$$E type and of the BinaryFormatter output. $$anonymous$$y understanding of Java and computer science terms in general is pretty low, sadly

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

202 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Save location of created UI elements to JSON so it can load later 0 Answers

How To Save and Load player position using Serialization? 0 Answers

How to save and load game with checkpoints list.? 0 Answers

Writing save files (JavaScript) 0 Answers

Xml Serialization - Does not save anything. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges