I'm writing a profile editor in Visual Studio 2015 for a game that was written in Unity. That means that my String.GetHashCode()
and the games String.GetHashCode()
are not the same.
The idea that I have is to simply find the games method and then use it to get hashcode for any strings that I need. However, this is proving to be quite difficult. This is the method:
public unsafe int GetHashCode()
{
IntPtr arg_0F_0;
IntPtr expr_06 = arg_0F_0 = "test";
if (expr_06 != 0)
{
arg_0F_0 = (IntPtr)((int)expr_06 + 12);
}
char* ptr = arg_0F_0;
int num = 352654597;
int num2 = num;
int* ptr2 = (int*)ptr;
for (int i = this.Length; i > 0; i -= 4)
{
num = ((num << 5) + num + (num >> 27) ^ *ptr2);
if (i <= 2)
{
break;
}
num2 = ((num2 << 5) + num2 + (num2 >> 27) ^ ptr2[1]);
ptr2 += 2;
}
return num + num2 * 1566083941;
}
I changed the 4th row from this
to "test"
so it doesn't throw a compile error on that, it's supposed to be a string anyway. But this won't compile, it's giving me several errors:
IntPtr expr_06 = arg_0F_0 = "test";
underlinedarg_0F_0 = "test"
Cannot convert source type 'string' to target type 'System.IntPtr'
if (expr_06 != 0)
underlinedexpr_06 != 0
Operator '!=' cannot be applied to operands of type 'System.IntPtr' and 'int'
This also threw an error char* ptr = arg_0F_0;
, but it went away when I changed it with this char* ptr = (char*) arg_0F_0;
.
So, any ideas? How do I make it work? I don't really care what happens inside the method as long as I get the same result.