I don't want players changing for example money to like 2.5 million or something like that |
Why not?
If there are real security concerns (e.g., this is a multiplayer game) then such attempts at control are perhaps warranted. Otherwise, you shouldn't attempt to control the user. Still, you can (and should) perform your validation of user actions on the server without sacrificing transparency. This is roughly how most anti-cheating systems work.
Would it be possible to make the file holding all the stuff not be able to be opened or sense if it is edited other other than the game. |
Not easily. Using a binary format instead of a text format simply means a curious user needs a hex editor instead of a text editor. More effective techniques for control can be borrowed from DRM implementations. For instance, you can encrypt the user's content and require a keypair from a first-party server to access it.
This document contains an overview of how such a process could work:
https://knowledge.kaltura.com/universal-drm-udrm-technical-specification
FWIW, my personal opinion is that these sorts of controls are terribly unethical violations of the rights to information and privacy. But the decision is up to you.
Other sorts of obfuscation are quite possible. Create dummy files, make the format entirely non-intuitive. Take checksums, and write your text files in Yiddish, backwards. Yes, you can embed an encryption key in the executable.
Even with such measures, your program runs on the user's computer. If the user has sufficient expertise, you won't be able to stop them from tinkering. The idea is that the user (in theory) entirely controls the environment in which the program exists. The best you can do is make it not worth their time to break.
How would you make it so it can read what you have in the save file?
|
Given the trivial format above, you could do something like this:
1 2 3 4 5 6 7 8 9 10
|
std::string directive, value;
while (file >> directive >> value) {
if (directive == "equipment") // add equipment to inventory by name
add_item(value);
else if (directive == "health") // set health to value
health_remaining = std::stoi(value);
else
std::cerr << "unrecognized directive "
<< std::quoted(directive) << '\n';
}
|
You can find plenty of examples regarding how to read text files with C++. But the standard streams can be quite awkward.
For parsing more complicated formats, Boost.Spirit has become my preferred choice. Similarly, if you choose to use a serialization library, Boost.Serialization is the way to go.