Archived

This topic is now archived and is closed to further replies.

Save/load game option for and rpg/adventure

This topic is 5981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites