Background:
The Unity engine provides a number of PlayerPrefs.SetXxx
functions that can be used to save user data. However, it will automatically append a hash to the name of what you saved. For example, a call of
PlayerPrefs.SetString("justTesting", "TEST!");
will add a registry value of
justTesting_h3837386411
on Windows platform.
Problem:
I know it's actually djb2-xor, but I am still curious about how the hash function is implemented. By using dnSpy I found PlayerPrefs.SetString
, which is implemented in UnityEngine.CoreModule.dll
, finally calls a native method declared as
[NativeMethod("SetString")]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool TrySetSetString(string key, string value);
And I'm stuck here. There's indeed a string UnityEngine.PlayerPrefs::TrySetSetString
in .rdata
section of UnityPlayer.dll
, but I don't know where to find the actual code for it. What should I do next?