Save/load game option for and rpg/adventure

Started by
6 comments, last by Afterlife 22 years, 9 months ago
There''s a whole bunch of global variables and structures that I need to store to a save game file. Now, I was going to do it so that I just store the values of each variable/structure member to a file and use some symbols to notify the changing to the next variable. Then I''d just load the file by getting the values in the same order. The savegame file would look something like this : 0;1;0;2;12;6 ... Now, this would of course be damn easy to edit; to change the game''s events and what items you have in your inventory, what stats the player has ect. Not very good way, you wouldn''t even have to use a hex editor to hack it :p. That brings me to my question: Does anyone have a better idea for saving games?
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
Advertisement
You could write the file in binary. At least then you''d need a hex editor. If you were really worried, you could then encrypt the file (or encrypting it in text-form is possible also)

War Worlds - A 3D Real-Time Strategy game in development.
How do I make a binary file? Is there a tutorial or something on it or is there just a simple way to transform int and char types into binary? Oh and is binary the 0,1...,9,a,b,c,d,e,f,10,11... thingy?
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
I am also interested in making good and flexible save games.
I would like to serialize the game object and all player objects though I really want a high level of security so that it is hard tamper with the save files. Are there any tutorials on this matter or does anyone have any experience the would like to share? Is it easier to encrypt the saves or to make lots of checksums?



Johan Torp - http://www.destruction.nu
Johan Torp - http://www.destruction.nu
to make a binary file in C++ you first have to create a struct with al data, like this:

struct myData{
int level;
char name[15];
char whatever[10];
int ammo;
};

and then write to the file wich you whant to save it with the "write()" function (and if you whant to read ir use the "read()" func. ), using it like this:

myData something = { 4, "jakovo", "yeah", 99 }; // put something

saveFile.write( reinterpret_cast( &something ), sizeof( myData ) );

then all the data you are using will be saved as its in memorry, just a bunch of binary code...

and when you load the information just use:

saveFile.read( reinterpret_cast( &something ), sizeof( myData );

an that's it... you'll have on the "something" struct all your information back.


nice day!

jakovo

Edited by - jakovo on July 28, 2001 1:05:15 PM
"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"
Can you make this work with an already existing class so that you don''t have to choose which variables to save?

Johan Torp - http://www.destruction.nu
Johan Torp - http://www.destruction.nu
hmm... good question, I've never used classes instead of structs to save info', but I guess it could work too, maybe the only diference is that it would probably save the function pointers from that class... I guess.

try it and tell me what you got

jakovo

Edited by - jakovo on July 30, 2001 9:55:05 AM
"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"
In C++ classes and structs are the same thing (there is one difference: the default access modifier in a class is ''private'' while the default is ''public'' in a struct). And no, the function pointers would not be saved (Well, if you declare a function pointer explicitly in the class it will be saved, just as normal data, the vtable function pointers will however not be saved (the vtable only exists if you have at least one ''virtual'' method in your class)).

The "0,1...,9,a,b,c,d,e,f,10,11... thingy" as you called it is called hexadecimal (base 16). Binary has only two numbers: 0 and 1.

e.g.
10011 in binary converted to deciaml would be:
(1*2^4 + 0*2^3 + 0*2^2 + 1*2^1 + 1*2^0)
=> (16 + 0 + 0 + 2 + 1)
=> 19

(i.e. multiply each binary digit with 2^(the position of the digit) then add all the products).

Binary is the native format of the computer. everything is stored in binary in memory and on disk, then it''s up to each program to interpret the bits (bit == binary digit).

I know I''m not too good at explaining these kinds of things. please ask if it''s unclear.

This topic is closed to new replies.

Advertisement