Sign in to follow this  

how to verify contents of a map file?

This topic is 4841 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

hi, im working on a 2d tile based RPG, and was wondering, is there anyway to verify that a map file is valid? surely there must be a way, because using other program's ive seen this sort of thing. im using binary file i/o using fstream::write/read. basically, lets say in my map editor i try to parse in a jpg file or an html file or something, how could i stop this from crashing the game? i know i could just make sure the extension is .map, but even then, what if the map file got currupted? anyway, thanks for any help.

Share this post


Link to post
Share on other sites
It depends on how you set out your map file, really you just need to code in lots of checks for invalid data. With a tile map when reading in the tile IDs for each tile in the map, say a certain tile says it uses ID 232058 but there's only 200 tile images then the file must be corrupt.

Another thing you can do is put a magic number in the file header. This is basically an arbitray number that you put somewhere in the header that is always the same, then when reading in the file if the magic number is not correct then the file is corrupt.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You could do a hash check (like MD5)

You got your .map file, then you take the hash code of it and put that as your "magic number". Then before loading the map you take again the hash of the (file - the magic number) if it's different then the file is corrupt.

MD5 creates a 32 character string no matter how long the input and as soon as 1 character of the original string is changed, the hash string changes aswell.

That could work I guess.

Share this post


Link to post
Share on other sites

This topic is 4841 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this