- Home /
Are PlayerPrefs save or hackable on android?
Hello guys, i made a game to save ints like the money of the player. So are the PlayerPrefs save on android and IOS or can you easy change it? And when you download the game do you have access to the PlayerPrefs when you look through the storage of the Phone where the game is at?
Thx for ur help!
Answer by xxmariofer · Apr 23, 2021 at 01:16 PM
Well, everything is hackable, but player prefs is a simple file in an android directory.
/data/data/pkg-name/shared_prefs/pkg-name.v2.playerprefs.xml
Is there an other secure way so save an int. So they are not readable?
You can save an encrypted file into a persistent data path on android using a binary formatter, or any serializer, that can convert C# objects into text/byte form. Here's a common example:
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
public class SaveData
{
public static void Save(PlayerData data)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, data);
var bytes = ms.ToArray();
var text = Encoding.ASCII.GetString(bytes);
// Writes data to a file
File.WriteAllText(Application.persistentDataPath + "/PlayerData.save", text);
}
public static PlayerData Load()
{
// Gets data from file
var text = File.ReadAllText(Application.persistentDataPath + "/PlayerData.save");
var bytes = Encoding.ASCII.GetBytes(text);
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream(bytes);
return (PlayerData)bf.Deserialize(data);
}
}
[System.Serializable]
public class PlayerData
{
public string Name;
public int Level;
}
Well, obviously the most secure way is using servers for login and retrieving data. But my suggestion, is unless you are planning a really big project, dont invest a ton of resources into making it unhackable, it will most likely be not worth it cost - benefit, creating a file in a no common directory, and using a simple encrypting agorithm would be enough usually
Answer by gigos22 · Apr 23, 2021 at 02:18 PM
Yes it is very "hackable" but just because anyone can edit it on their phone.
BUT... If the user doesn't know (which they shouldn't) that your game is saved this way, it shouldn't matter.. Because the average player doesn't go to check the directory the user above me mentioned with each game the download..