Browse Source

Get rid of InitHash

pull/2626/head
Vladimir Olteanu 5 years ago committed by Anders Jenbo
parent
commit
286eb7144a
  1. 2
      Source/diablo.cpp
  2. 32
      Source/encrypt.cpp
  3. 1
      Source/encrypt.h
  4. 2
      Source/mpqapi.cpp

2
Source/diablo.cpp

@ -1050,8 +1050,6 @@ void DiabloInit()
ReadOnlyTest();
InitHash();
DiabloInitScreen();
#ifndef NOSOUND

32
Source/encrypt.cpp

@ -6,6 +6,7 @@
#include <SDL.h>
#include <cctype>
#include <memory>
#include <array>
#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<std::array<uint32_t, 256>, 5> hashtable = []() {
uint32_t seed = 0x00100001;
std::array<std::array<uint32_t, 256>, 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<char[]> ptr { new char[CMP_BUFFER_SIZE] };

1
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);

2
Source/mpqapi.cpp

@ -627,8 +627,6 @@ bool OpenMPQ(const char *pszArchive)
{
_FILEHEADER fhdr;
InitHash();
if (!cur_archive.Open(pszArchive)) {
return false;
}

Loading…
Cancel
Save