| 271 | #define SOUND_ENTRY_HASH_SEED 0x444F5441 |
| 272 | |
| 273 | uint32 GenerateSoundEntryHash(char const *pSoundEntry) |
| 274 | { |
| 275 | // First we need to convert the sound entry to lowercase before we calculate the hash |
| 276 | int nSoundEntryLength = strlen(pSoundEntry); |
| 277 | char *pSoundEntryLowerCase = (char *)stackalloc(nSoundEntryLength + 1); |
| 278 | |
| 279 | for (int nIndex = 0; nIndex < nSoundEntryLength; nIndex++) |
| 280 | pSoundEntryLowerCase[nIndex] = tolower(pSoundEntry[nIndex]); |
| 281 | |
| 282 | // Second we need to calculate the hash using the algorithm reconstructed from CS:GO |
| 283 | const uint32 nMagicNumber = 0x5bd1e995; |
| 284 | |
| 285 | uint32 nSoundHash = SOUND_ENTRY_HASH_SEED ^ nSoundEntryLength; |
| 286 | |
| 287 | unsigned char *pData = (unsigned char *)pSoundEntryLowerCase; |
| 288 | |
| 289 | while (nSoundEntryLength >= 4) |
| 290 | { |
| 291 | uint32 nLittleDWord = LittleDWord(*(uint32 *)pData); |
| 292 | |
| 293 | nLittleDWord *= nMagicNumber; |
| 294 | nLittleDWord ^= nLittleDWord >> 24; |
| 295 | nLittleDWord *= nMagicNumber; |
| 296 | |
| 297 | nSoundHash *= nMagicNumber; |
| 298 | nSoundHash ^= nLittleDWord; |
| 299 | |
| 300 | pData += 4; |
| 301 | nSoundEntryLength -= 4; |
| 302 | } |
| 303 | |
| 304 | switch (nSoundEntryLength) |
| 305 | { |
| 306 | case 3: nSoundHash ^= pData[2] << 16; |
| 307 | case 2: nSoundHash ^= pData[1] << 8; |
| 308 | case 1: nSoundHash ^= pData[0]; |
| 309 | nSoundHash *= nMagicNumber; |
| 310 | }; |
| 311 | |
| 312 | nSoundHash ^= nSoundHash >> 13; |
| 313 | nSoundHash *= nMagicNumber; |
| 314 | nSoundHash ^= nSoundHash >> 15; |
| 315 | |
| 316 | return nSoundHash; |
| 317 | } |
| 318 | #endif |
| 319 | |
| 320 | #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV |
no outgoing calls
no test coverage detected