OK, here's very simple example of how to stop someone adding items they don't have to their inventory.
Basically, it generates a seed (key) for use with the random number generator, which is based on the ASCII values of each of the charatcers in the player's name. This is then multiplied by 1000 so that similar names don't generate similar keys.
When the program goes to save the profile it generates a random number for each item in the profile, regardless of whether the player has it or not. If the player does have the item, then this random number is stored instead of a simple 1. 0 is still used to say when an item is not in the player's inventory.
When the profile is loaded again, it gets the player's name from the profile and generates the same seed for the random number generator. When loading the items a check code is randomly generated for each item. If the value from the file is 0, the player doesn't have the item, so there's no problem. However, if the two values don't match, then the player has tried to add the item in NotePad (or similar) by guessing a random number and changing one of the 0's. The player is then not given the item and a flag is set to say that an attempt to cheat has been made. Otherwise, the player is given the item.
Things to note are that the cheating player could guess the correct value to put into the profile, so it's best to use a wide a range of randum numbers as possible to make this more unlikely (values between 1000 and 2000 were used above).
Also, this method will not prevent someone from removing items from a profile, which they might do with a friend's profile, for example. Something a little more complicated would be required, as you couldn't just XOR the encryption value with the item flag as a player would easily figure out that they would only need to change the value in the file by 1 to add or remove items from their inventory.
You might also want to include a player's score or other value that changes as they play when generating the key, so that the key itself changes over time, rather then remain static as this example does. If a player then tries to alter their score, they will end up with no items in their inventory as none of the values will match when it's loaded back in!
Hope that sort of points you in the right direction.
Type TPlayer Field name$,items[9] End Type Function ShowPlayer(player.TPlayer) Local i Print "Player: "+player\name Print Print "Items..." For i=0 To 9 If player\items[i]=1 Then Print " #"+i+": Have" Else Print " #"+i+": Don't have" EndIf Next Print End Function Function GenerateKey(playerName$) Local key,i For i=1 To Len(playerName) key=key+Asc(Mid(playerName,i,1)) Next Return key*1000 End Function Function SaveProfile(player.TPlayer) Local i,code,file=WriteFile(player\name+".ini") If file Then SeedRnd GenerateKey(player\name) WriteLine file,player\name For i=0 To 9 code=Rand(1000,2000) If player\items[i]=1 Then WriteLine file,code Else WriteLine file,0 EndIf Next EndIf CloseFile file SeedRnd MilliSecs() End Function Function LoadProfile(playerName$) Local loadStatus,code,i,file,check file=OpenFile(playerName+".ini") If file Then player.TPlayer=New TPlayer player\name=ReadLine(file) SeedRnd GenerateKey(player\name) For i=0 To 9 code=Rand(1000,2000) check=ReadLine(file) If check>0 Then If code<>check Then loadStatus=2 ; file amended check=0 ; don't give player this item Else check=1 EndIf EndIf player\items[i]=check Next CloseFile file If loadStatus<>2 Then loadStatus=1 Else loadStatus=0 ; file not found EndIf SeedRnd MilliSecs() Return loadStatus End Function Graphics 800,600 Global player.TPlayer=New TPlayer player\name="JazzieB" For i=0 To 9 If Rand(100)<50 Then player\items[i]=1 Else player\items[i]=0 Next Print "Player profile before saving:" Print ShowPlayer(player) SaveProfile(player) Print "Profile saved." Delete player Print "Profile deleted in memory." Print Print "Press a key to re-load profile (her's your chance to cheat!" WaitKey Print Print "Re-loading player profile..." Global success=LoadProfile("JazzieB") If success=0 Then Print "Unable to load profile." Else Print ShowPlayer(player) If success=1 Then Print "Profile loaded successfully." Else Print "Warning: Profile amended outside of program. Additional items removed." EndIf EndIf WaitKey End
Basically, it generates a seed (key) for use with the random number generator, which is based on the ASCII values of each of the charatcers in the player's name. This is then multiplied by 1000 so that similar names don't generate similar keys.
When the program goes to save the profile it generates a random number for each item in the profile, regardless of whether the player has it or not. If the player does have the item, then this random number is stored instead of a simple 1. 0 is still used to say when an item is not in the player's inventory.
When the profile is loaded again, it gets the player's name from the profile and generates the same seed for the random number generator. When loading the items a check code is randomly generated for each item. If the value from the file is 0, the player doesn't have the item, so there's no problem. However, if the two values don't match, then the player has tried to add the item in NotePad (or similar) by guessing a random number and changing one of the 0's. The player is then not given the item and a flag is set to say that an attempt to cheat has been made. Otherwise, the player is given the item.
Things to note are that the cheating player could guess the correct value to put into the profile, so it's best to use a wide a range of randum numbers as possible to make this more unlikely (values between 1000 and 2000 were used above).
Also, this method will not prevent someone from removing items from a profile, which they might do with a friend's profile, for example. Something a little more complicated would be required, as you couldn't just XOR the encryption value with the item flag as a player would easily figure out that they would only need to change the value in the file by 1 to add or remove items from their inventory.
You might also want to include a player's score or other value that changes as they play when generating the key, so that the key itself changes over time, rather then remain static as this example does. If a player then tries to alter their score, they will end up with no items in their inventory as none of the values will match when it's loaded back in!
Hope that sort of points you in the right direction.