// create the hash for that data block. // Data should be converted to Network byte order static void calcDataHash(uint8_t *pBuffer, uint32_t size, uint32_t index) { const uint32_t oldHash = DataHash[index]; if (!bMultiPlayer) { return; } DataHash[index] += hashBuffer(pBuffer, size); if (!DataHash[index] && oldHash) { debug(LOG_NET, "The new hash is 0, the old hash was %u. We added the negated value!", oldHash); } debug(LOG_NET, "DataHash[%2u] = %08x", index, DataHash[index]); return; }
// create the hash for that data block. // Data should be converted to Network byte order static void calcDataHash(uint8_t *pBuffer, uint32_t size, uint32_t index) { const uint32_t oldHash = DataHash[index]; if (!bMultiPlayer) { return; } DataHash[index] ^= PHYSFS_swapUBE32(hashBuffer(pBuffer, size)); if (!DataHash[index] && oldHash) { debug(LOG_NET, "The new hash is 0, the old hash was %u. We XOR'ed the same value!", oldHash); } debug(LOG_NET, "DataHash[%2u] = %08x", index, PHYSFS_swapUBE32(DataHash[index])); return; }
template <> inline U32 hashArray<F64> (const F64* ptr, int size) { return hashBuffer(ptr, size * (int)sizeof(F64)); }
template <> inline U32 hashArray<U16> (const U16* ptr, int size) { return hashBuffer(ptr, size * (int)sizeof(U16)); }
template <> inline U32 hashArray<F32> (const F32* ptr, int size) { return hashBuffer(ptr, size * (int)sizeof(F32)); }
template <> inline U32 hashArray<S8> (const S8* ptr, int size) { return hashBuffer(ptr, size * (int)sizeof(S8)); }
template <class T> inline U32 hash (const T& value) { return hashBuffer(&value, sizeof(T)); }
template <> inline U32 hash<std::string> (const std::string& value) { return hashBuffer(value.c_str(), value.length()); }
template <> inline U32 hash<GenericHashKey>(const GenericHashKey& value) { return hashBuffer(value.ptr, value.size); }
template <> inline U32 hash<String> (const String& value) { return hashBuffer(value.getPtr(), value.getLength()); }