我在使用这个模数时遇到了很大的困难。C 版本输出我想要的但不是正确的值。我的 C# 输出我不想要的,但输出正确的值。如何获取 C# 版本以输出 C 版本?
C
typedef unsigned long long u64;
typedef unsigned char u8;
static u64 pfd_calculate_hash_table_entry_index(const char *file_name) {
u64 hash, len, i;
if (!file_name)
return -1;
len = strlen(file_name);
hash = 0;
for (i = 0; i < len; ++i)
hash = (hash << 5) - hash + (u8)file_name[i];
printf( "%X ", hash);
printf( "mod ");
printf( "%X ", 0x39);
printf( "= %X\n", hash % 0x39 );
return hash % 0x39;
}
C#
public ulong pfd_calculate_hash_table_entry_index(char[] file_name)
{
uint hash, len, i;
hash = 0;
len = (uint)Array.IndexOf(file_name, '\0');
for (i = 0; i < len; ++i)
hash = (hash << 5) - hash + (byte)file_name[i];
MessageBox.Show(hash.ToString("X") + " mod 0x39 = " + (hash % 0x39).ToString("X"));
return ((ulong)hash % 0x39);
}
C#
#1: char[] file_name = "PARAM.SFO";
#2: char[] file_name = "RAGE.SAV"
C
#1: char* file_name = "RAGE.SAV";
#2: char* file_name = "PARAM.SFO"
C 哈希
#1: 0x319FFDA7
#2: 0x1A8C4B5B
C# 哈希
#2: 0x319FFDA7
#1: 0x1A8C4B5B
C 输出
#1: 0x319FFDA7 % 0x39 = 0x21;
#2: 0x1A8C4B5B % 0x39 = 0x8;
C# 输出
#1: 0x319FFDA7 % 0x39 = 0xA;
#2: 0x1A8C4B5B % 0x39 = 0xE;
图片...
C
C#