From 286eb7144aa2fb5c042ac6c1f2610eec076290d7 Mon Sep 17 00:00:00 2001 From: Vladimir Olteanu Date: Wed, 18 Aug 2021 20:55:36 +0300 Subject: [PATCH] Get rid of InitHash --- Source/diablo.cpp | 2 -- Source/encrypt.cpp | 32 ++++++++++++++++---------------- Source/encrypt.h | 1 - Source/mpqapi.cpp | 2 -- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index f2217ef27..1f2ce7068 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1050,8 +1050,6 @@ void DiabloInit() ReadOnlyTest(); - InitHash(); - DiabloInitScreen(); #ifndef NOSOUND diff --git a/Source/encrypt.cpp b/Source/encrypt.cpp index 54ad4e9c4..013c08fb3 100644 --- a/Source/encrypt.cpp +++ b/Source/encrypt.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "encrypt.h" #include "pkware.h" @@ -39,9 +40,22 @@ void PkwareBufferWrite(char *buf, unsigned int *size, void *param) // NOLINT(rea pInfo->destOffset += *size; } -} // namespace +const std::array, 5> hashtable = []() { + uint32_t seed = 0x00100001; + std::array, 5> ret = {}; + + for (int i = 0; i < 256; i++) { + for (int j = 0; j < 5; j++) { // NOLINT(modernize-loop-convert) + seed = (125 * seed + 3) % 0x2AAAAB; + uint32_t ch = (seed & 0xFFFF); + seed = (125 * seed + 3) % 0x2AAAAB; + ret[j][i] = ch << 16 | (seed & 0xFFFF); + } + } + return ret; +}(); -static uint32_t hashtable[5][256]; +} // namespace void Decrypt(uint32_t *castBlock, uint32_t size, uint32_t key) { @@ -85,20 +99,6 @@ uint32_t Hash(const char *s, int type) return seed1; } -void InitHash() -{ - uint32_t seed = 0x00100001; - - for (int i = 0; i < 256; i++) { - for (int j = 0; j < 5; j++) { // NOLINT(modernize-loop-convert) - seed = (125 * seed + 3) % 0x2AAAAB; - uint32_t ch = (seed & 0xFFFF); - seed = (125 * seed + 3) % 0x2AAAAB; - hashtable[j][i] = ch << 16 | (seed & 0xFFFF); - } - } -} - uint32_t PkwareCompress(byte *srcData, uint32_t size) { std::unique_ptr ptr { new char[CMP_BUFFER_SIZE] }; diff --git a/Source/encrypt.h b/Source/encrypt.h index df043b419..6dfdbbbaf 100644 --- a/Source/encrypt.h +++ b/Source/encrypt.h @@ -22,7 +22,6 @@ struct TDataInfo { void Decrypt(uint32_t *castBlock, uint32_t size, uint32_t key); void Encrypt(uint32_t *castBlock, uint32_t size, uint32_t key); uint32_t Hash(const char *s, int type); -void InitHash(); uint32_t PkwareCompress(byte *srcData, uint32_t size); void PkwareDecompress(byte *inBuff, int recvSize, int maxBytes); diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 4a7b22d0c..9266c0c32 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -627,8 +627,6 @@ bool OpenMPQ(const char *pszArchive) { _FILEHEADER fhdr; - InitHash(); - if (!cur_archive.Open(pszArchive)) { return false; }