1
\$\begingroup\$

I am building a game using Monogame 3.6 and Visual Studio Community 2017. Up until this point I have been serializing the data using BinarySerialization and created a custom ContentImporter and ContentProcessor.

My question is what is the standard used for saving game data and where is it saved? I attempted to use the IntermediateSerializer class, but that was stored in XML and is easily modified. I would like to store the game data in a file that is more difficult to tamper with, which is why I chose binary serialization.

I would also like to see an example of code that uses the standard for file paths when saving to the file system. On my development system, I can save anywhere because I am Administrator. But I would like to understand which parts of the framework are available for me to get file path information and save the data.

\$\endgroup\$
2
  • \$\begingroup\$ Are you asking where you should save game data? \$\endgroup\$ Jul 20, 2018 at 3:24
  • \$\begingroup\$ Yes I am asking where the standard place is to save game data and what an example of that looks like. \$\endgroup\$
    – Greg Kidd
    Jul 20, 2018 at 15:02

1 Answer 1

1
\$\begingroup\$

I'm going to assume from your question that you are working on a Windows game. The recommended location for most gamesaves would be under your users's AppData/Roaming folder. If you are using UWP then this is fairly easy to do as you can use the ApplicationData.Current.RoamingFolder to access it using the storage classes in UWP. The docs on this have a good example of saving a file.

Now that's just for Windows, each platform will have different locations and requirements for storing this kind of information. One tip I would have is have a common function for writing to files, like so:

public void SaveGame(string filename, string data) {
#if WINDOWS
    // save game on Windows
#elseif ANDROID
    // save game on Android
#elseif OTHER
    // ...
#endif
}

This reduces the hassle of maintaining file systems. As for the format of the file, that is essentially up to you, I can't think of any reason you can't format it however you want.

\$\endgroup\$
1
  • \$\begingroup\$ Does (in Windows) the exe also have permission by default in the ‘workingdir’ System.IO.Directory.GetCurrentDirectory()? Many games have a ‘Saves’ folder in their folder structure. \$\endgroup\$
    – Felsir
    Nov 17, 2018 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .