Ped hashes?
-
How are ped hashes generated? They're based on name, right? Like I want to know the hash for 'Rachel', for instace. Surprisingly, I found no tool for it.
Mind you, I don't want to do this in-game (like with Developers Tools, that can't copy to clipboard). I just want to generate a hash list of all my addon peds.
Thanks.
-
@meimeiriver There's a hash generator in OpenIV.
-
@LeeC2202 said in Ped hashes?:
@meimeiriver There's a hash generator in OpenIV.
LOL. That's rich! Can't believe I never saw that! It's doing precisely what it should do! Thanks a million!
-
If you want to know how these hashes are generated, take a look at this.
-
@Unknown-Modder I was going to say that's where the code I use came from but after comparing them, what I have is slightly different.
Can't remember if I got it off GTAForums or StackOverflow.
-
@LeeC2202 Actually, GTA V does this slightly different. I was on my phone so I couldn't post this.
Everything gets converted to lowercase and some characters get replaced, \ with / for example.
GTA V uses a lookup table for this:unsigned int __fastcall GET_HASH_KEY(char *string, unsigned int initialHash) { unsigned int v2; // er10@1 unsigned int v3; // er8@1 char *v4; // r9@1 unsigned __int8 *v5; // r9@3 unsigned __int8 i; // al@3 unsigned int v7; // er8@5 int j; // eax@8 __int64 v9; // rax@9 unsigned int v10; // er8@9 unsigned int v11; // edx@9 unsigned int v12; // er8@12 unsigned __int8 v13; // al@13 v2 = 0; v3 = initialHash; v4 = string; if ( string ) { if ( *string == '"' ) { v5 = string + 1; for ( i = string[1]; *v5; i = *v5 ) { if ( i == '"' ) break; ++v5; v7 = 1025 * (g_charLookupTable[i] + v3); v3 = (v7 >> 6) ^ v7; } } else { if ( !((unsigned __int8)string & 3) ) { for ( j = *(_DWORD *)string; !((j - 0x1010101) & 0x80808080); j = *(_DWORD *)v4 ) { v9 = *v4; v4 += 4; v10 = 1025 * (g_charLookupTable[v9] + v3); v11 = 1025 * ((1025 * ((v10 ^ (v10 >> 6)) + g_charLookupTable[*(v4 - 3)]) ^ (1025 * ((v10 ^ (v10 >> 6)) + g_charLookupTable[*(v4 - 3)]) >> 6)) + g_charLookupTable[*(v4 - 2)]); v3 = (1025 * ((v11 ^ (v11 >> 6)) + g_charLookupTable[*(v4 - 1)]) >> 6) ^ 1025 * ((v11 ^ (v11 >> 6)) + g_charLookupTable[*(v4 - 1)]); } } while ( 1 ) { v13 = *v4; if ( !*v4 ) break; ++v4; v12 = 1025 * (g_charLookupTable[v13] + v3); v3 = (v12 >> 6) ^ v12; } } v2 = v3; } return 32769 * ((9 * v2 >> 11) ^ 9 * v2); }
-
@Unknown-Modder Yeah, the version I have converts everything to LowerCase but it doesn't use any lookup tables though. This is the code I use
public static uint GetHash(string str) { uint hash, i; char[] key = str.ToLower().ToCharArray(); for (hash = i = 0; i < key.Length; i++) { hash += (uint)key[i]; hash += (hash << 10); hash ^= (hash >> 6); } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; }
And that seems to produce hash values that match what I see in the gxt2 files (for vehicles anyway). But that lookup table could explain why I have problems in the programme I have got that tries to fix hash_collision values in decrypted ymt files.
-
@LeeC2202 In that case, I recommend using this.
-
@Unknown-Modder Thank you, that could prove to be very useful.