0

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:

  1. IntPtr expr_06 = arg_0F_0 = "test"; underlined arg_0F_0 = "test"

Cannot convert source type 'string' to target type 'System.IntPtr'

  1. if (expr_06 != 0) underlined expr_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.

Karlovsky120
  • 6,212
  • 8
  • 41
  • 94
  • I'm writing a profile editor for a game that saves strings using their hash value and the on load checks if it matches on of the options. So I control only one side. Besides, it seems that I was looking at the wrong code, it's working for me now. But still doesn't explain why the code above won't compile since it was written in C# and is being compiled in C#. – Karlovsky120 Jan 03 '16 at 01:01
  • Are you targeting 64 bit CPU? – Tony Jan 03 '16 at 04:40

0 Answers0