Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Q] A way to protect my Save File :D  (Read 3087 times)

0 Members and 1 Guest are viewing this topic.

UchihaKite

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
[Q] A way to protect my Save File :D
« on: September 19, 2016, 05:36:09 am »
Good Evening Fellow Programmers!

If I come off a little loops, I apologize. It's finals week, so I am hard at work on my final for my programming class. After about 12 hours of programming, I thought to myself, hey, this might be a good time to call it a day :D

Anyway! So, I managed to figure out a way to save the highscore of my Asteroids game, which if you reopen the program, it shows the score to beat! However, I don't want people to just go into the txt file and edit the high score.

I stumbled across a cipher and XOR, but it doesn't seem like I am able to get it to work with my txt file. I'm saving numbers to my txt file, so, I don't know if that has something to do with it?

I was just wondering if their is a way to encrypt the contents of my txt file, and/or if their is a way to hide the file? So maybe the only way it can be accessed is through Visual Studios?

Thanks for taking the time to read this, hopefully someone knows of a good way to protect my save file. All the best!

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: [Q] A way to protect my Save File :D
« Reply #1 on: September 19, 2016, 07:30:17 am »
A silly solution could be:

1) Make the number an string. You can use itoa.
2) Encrypt the string.
3) Safe the file.

-->Reopening the game.

1) Decrypt the string.
2) Retrive the number using the decrypted string. You can use atoi.
3)Load the integer to the game.

PD: This is the SFML forums, for discuss SFML related things.

For game-dev/ general C++ questions there are a lot dedicated forums for this topic.
I would like a spanish/latin community...
Problems building for Android? Look here

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: [Q] A way to protect my Save File :D
« Reply #2 on: September 19, 2016, 10:34:05 am »
Don't over-complicate the whole thing, it's just some tiny offline game anyway. :)

I'd just try the following - it's not cryptographically secure or anything, but should be good enough to prevent quick manipulation:

  • Use an accumulator size_t i=0.
  • Iterate over all characters in the high score entry's name and add the character value to i.
  • Add the actual score value to i.
  • Save the accumulator value together with your high score as a checksum.
  • When loading high scores, recalculate the checksum. If it doesn't match, drop the high score entry.

K.F

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: [Q] A way to protect my Save File :D
« Reply #3 on: September 19, 2016, 12:46:35 pm »
Most people will - if they wanted to cheat - use memory editing programs like cheat engine, and good luck fighting that.

Best way I can think of that eliminates all these problem is saving a replay gameplay file with every high score - at least top 10 - , this will show other players how this score was accomplished - increasing competitiveness - and the players can report cheating high scores for you.

UchihaKite

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
Re: [Q] A way to protect my Save File :D
« Reply #4 on: September 19, 2016, 04:44:30 pm »
Thanks guys! I will look into all of these things and report back to you :D


PD: This is the SFML forums, for discuss SFML related things.

For game-dev/ general C++ questions there are a lot dedicated forums for this topic.

Sorry about that! Typically programming forums are all welcoming to noobs like me, but I find that people here explain things a lot better and less chance of getting the "get gewd" reply from people. I'll take general C++ questions elsewhere from now on though! I just didn't know if SFML had some security features or something, so I thought I would ask here :D

Edit(Update):
Thanks again for all of your help! I think those methods are a little above me right now, but I am going to look into those to educate myself. I decided to just go the route of making the file a binary file, and making it hidden. Not the best method, but it should be good enough to turn in as my final assignment.
« Last Edit: September 20, 2016, 04:54:47 am by UchihaKite »