Jump to content


Photo

Help: (How to encrypt / decrypt INI files?)


  • Please log in to reply
17 replies to this topic

#1 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 29 April 2012 - 05:39 PM

Hey,

I'm quite new to INI files, but i picked up some interesting information from tutorials.

I want to use my INI files for achievements.
like, if attempts >= 500 {Get_achievement1 = 1)
i store the attempts in the ini file.

but that has nothing to do with my question actually, i want to know how do i secure my ini file?
so that other people can't change the value of it and get all the achievements easily.

i heard something about encryption and decryption, but i have no idea how this works.
I saw people posting scripts etc. but i don't know what to do with them, or where to start.
for example here: http://gmc.yoyogames...howtopic=455251

Can anyone tell me what i have to do with this script, and how i use it?

thanks in advanced
-DuTchEr95

PS: not sure if i posted this in the right section.

Edited by DuTchEr95, 30 April 2012 - 03:52 PM.

  • 0

#2 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3192 posts
  • Version:GM8.1

Posted 29 April 2012 - 05:45 PM

You might attach a codeword to each achievement and check in the game if the code is right.
  • 0

#3 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 29 April 2012 - 05:51 PM

You might attach a codeword to each achievement and check in the game if the code is right.

yes, i was thinking about that too, but i'm not sure how i make numbers attach to codewords.
like in the ini i would store for example:
attempts = 500

i can't make it like attempts = patatoes, because if i get +1 on attempts it won't go well. if you get what i mean.
  • 0

#4 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3192 posts
  • Version:GM8.1

Posted 29 April 2012 - 05:55 PM

So you can have multiple degrees in your achievements?
  • 0

#5 Rhodox

Rhodox

    GMC Member

  • GMC Member
  • 132 posts

Posted 29 April 2012 - 06:20 PM

You could try this: http://gmc.yoyogames...howtopic=245305
  • 0

#6 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 29 April 2012 - 07:25 PM

So you can have multiple degrees in your achievements?

what do you mean?
  • 0

#7 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 29 April 2012 - 07:27 PM

You could try this: http://gmc.yoyogames...howtopic=245305

Seems interesting, does it work to encrypt ini files? and how exactly do i use it, i'm not familiar with using dll files.
  • 0

#8 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1830 posts
  • Version:GM8.1

Posted 29 April 2012 - 07:54 PM

There are various posts about encrypting/decrypting. Just encrypt each value in ini file (for example change attempts = 1 to adkasdjlas = asdads) and decrypt them in game maker when you want to read the values. If a user changes the word 'asdads' which is the value of attempts it will probably result in an error in game maker; which is fine.

You could also change the extension of the .ini file to something else (e.g ".bla"). This way most users won't be able to open the file and read it (unless they manually change the extension back to .ini). Then inside game maker just before reading the ini file convert it back to the original .ini extension and after you finish reading it convert it back to the "fake" extension (".bla").

Hope this helps
  • 0

#9 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 29 April 2012 - 08:28 PM

There are various posts about encrypting/decrypting. Just encrypt each value in ini file (for example change attempts = 1 to adkasdjlas = asdads) and decrypt them in game maker when you want to read the values. If a user changes the word 'asdads' which is the value of attempts it will probably result in an error in game maker; which is fine.

You could also change the extension of the .ini file to something else (e.g ".bla"). This way most users won't be able to open the file and read it (unless they manually change the extension back to .ini). Then inside game maker just before reading the ini file convert it back to the original .ini extension and after you finish reading it convert it back to the "fake" extension (".bla").

Hope this helps

thanks for the post,
"Just encrypt each value in ini file (for example change attempts = 1 to adkasdjlas = asdads) and decrypt them in game maker when you want to read the values."
that's what i want, and that is my question, how do i do that?

"You could also change the extension of the .ini file to something else (e.g ".bla"). This way most users won't be able to open the file and read it (unless they manually change the extension back to .ini). Then inside game maker just before reading the ini file convert it back to the original .ini extension and after you finish reading it convert it back to the "fake" extension (".bla")."
how am i supposed to do that, the commands in game maker say ini_write / read, meaning you can only read or write things to an ini file, and my attempts will gain +1 the whole time.

can you explain those things a bit more clear for me please?
thanks :)
  • 0

#10 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3192 posts
  • Version:GM8.1

Posted 29 April 2012 - 09:53 PM

@loverock125, you can simply read almost any extension, using notebook or gamemaker or java ..., even though many people don't know that and wouldn't try it.
@DuTchEr95, you can also use other gamemaker functions to save into files other than ini files, but these are considered to be a bit more difficult.
I do not quit understand what you want to raise with one the whole time, but if you want to save a number encrypted in an ini file, there are many ways to achieve that, for example:
ini_write_string("section","key","codeword"+chr(100-yourvalue));
and
yourvalue=100-ord(string_char_at(ini_read_string("section",key",""),9));
  • 0

#11 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 30 April 2012 - 09:33 AM

@loverock125, you can simply read almost any extension, using notebook or gamemaker or java ..., even though many people don't know that and wouldn't try it.
@DuTchEr95, you can also use other gamemaker functions to save into files other than ini files, but these are considered to be a bit more difficult.
I do not quit understand what you want to raise with one the whole time, but if you want to save a number encrypted in an ini file, there are many ways to achieve that, for example:
ini_write_string("section","key","codeword"+chr(100-yourvalue));
and
yourvalue=100-ord(string_char_at(ini_read_string("section",key",""),9));

Thanks for this post!
I tried it out, it seems to work, but there are some problems/things that i don't understand:

Everytime i restart the game the number resets to 100 :/ so that means nothing is saved

What do i put at "codeword" ?

I tried putting something random there like: maker
and then i started it up and it game out attempts = maker²

i also tried changing that maker² to just 0
and restart it up from game maker, it gave me automaticly the number 100

so basicly i could change this value to anything and they still can get their achievements, is there a way to make sure that, if someone has changed the value that the game won't work anymore or something will happen against it?
and how do i make sure that the data is saved after restarting the game?

Edited by DuTchEr95, 30 April 2012 - 09:35 AM.

  • 0

#12 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 30 April 2012 - 09:44 AM

Here i will give you my file (it is just the ini testing file) and maybe you can see what i did wrong:
Link to my gmk for ini testing file

Edited by DuTchEr95, 30 April 2012 - 09:45 AM.

  • 0

#13 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3192 posts
  • Version:GM8.1

Posted 30 April 2012 - 09:45 AM

If you change the "codeword" to "maker", the 9 must become 6. That number is suppost to be the length of that codeword+1.
  • 0

#14 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 30 April 2012 - 09:55 AM

If you change the "codeword" to "maker", the 9 must become 6. That number is suppost to be the length of that codeword+1.

ok, i did that, now the value randomly changes every time i restart,
for example i just leave it at codeword, and then i change the value to for example 116, i come back (restart game) and it changed to a -140 or something.
and then next time i do something it changed to 100 again, or 140.


basicly this is what i have, 1 object within a room with in
step:
if (keyboard_check(vk_space))
{
global.attempts+=1;
}

game start:
ini_open("ini_attempts.ini");
global.attempts=100-ord(string_char_at(ini_read_string("Game","Attempts",""),9));
ini_close();

game end:
ini_open("ini_attempts.ini");
ini_write_string("Game","Attempts","codeword"+chr(100-global.attempts));
ini_close()

draw:
draw_text(50,50,global.attempts);


in the begin if i delete it, i start it up and it is 100, i add some to it, to like 128, i restart it, then it is -128, then add some to it to like 54, i come back it is still 54, until i restart and add some to it again, then it starts to get funky, and it all goes random


PS: where exactly is the 100- needed for?

Edited by DuTchEr95, 30 April 2012 - 10:05 AM.

  • 0

#15 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3192 posts
  • Version:GM8.1

Posted 30 April 2012 - 10:11 AM

My code was based on that you wouldn't use numbers higher than 100, if you need to do so though, just change the 100 in the code to 500 or something like that.
  • 0

#16 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 30 April 2012 - 10:21 AM

My code was based on that you wouldn't use numbers higher than 100, if you need to do so though, just change the 100 in the code to 500 or something like that.

ok, will it work if i remove the 100-? i mean can i have an infinite number? or will the script not work anymore

btw the number doesn't change anymore it stays at 100

EDIT: i found out that if you delete the ini file, it still stays at 100, but if you both delete the ini and re open the gmk file, then it works again.

This is quite good, since this makes it double secure! people going to change the number, and then it resets it, that learns that they don't cheat.


i also deleted the 100- and it just makes it 0, which is what i want, because it starts from 0 and it gains more and more, to infinite.

so, thanks so much for your help! i think it works now, now i have to put it in my game and see if it really works.

Edited by DuTchEr95, 30 April 2012 - 10:33 AM.

  • 0

#17 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 30 April 2012 - 02:51 PM

Ok, i tried it on my game, but it doesn't seem to save the global.attempts for some reason.

this is what i figured out:

I go in game, where the ini object is (persistent), which has the game start (to read the ini file) and game end (write ini file).
and then i have a controller that has the attempts of when i die, i click on the start button, to goto the game room(controller is placed in this room), so what i did was, in the controller, when the room ends, global.attempts = global.attempts + attempt.
so that can be from the beginning: 0 (global.attempts) + 4, would make global.attempts = 4.
then when i return back to the menu room. and goto the medal room. it does say the right ammount of global.attempts i have. then i go back to the menu. and click on the exit button to end the game, which means it should write global.attempts into the ini file, encrypted as seen in above reply code.

but when i re start the game, and goto the medals room, and click on the object, it says that the global.attempts = 0.

so i looked inside my ini file, and discovered 2 characters that cover my global.attempts. so that means that the game can't read my first character or something i guess. even though i left the codeword, as codeword, and the index to 9, so it should be correct.

short info:
ini file name: attempttestv2.ini
rooms: menu(contains iniobject which is persistant), game(contains controller object), medal(contains medalscontroller)
objects: iniobject(game start, and game end, which code is above, var: global.attempts), controller (game end: (global.attempts = global.attempts + attempt), var: attempt), medalscontroller (when clicked on object, shows the ammount of global.attempts).


does anyone know what went wrong?
can anyone help me please, i really need to get this fixed.

thanks in advanced

Edited by DuTchEr95, 30 April 2012 - 03:03 PM.

  • 0

#18 DuTchEr95

DuTchEr95

    GMC Member

  • GMC Member
  • 54 posts
  • Version:GM8

Posted 30 April 2012 - 05:45 PM

Here is the .gmk file, if someone would have a look at it, to see that it doesn't work.
This is basicly what is happening in my game aswell.

Please help me.

The gmk file of ini test
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users