diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index 6f8e255..d4315c7 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -266,14 +266,41 @@ char* xUtil_idtag2string(U32 srctag, S32 bufidx) S32 xUtilShutdown() { - return g_xutilinit--; + return --g_xutilinit; } S32 xUtilStartup() { if (!g_xutilinit++) { - xUtil_crc_init(); + // From xUtil_crc_init: + + S32 i, j; + U32 crc_accum; + + if (g_crc_needinit) + { + for (i = 0; i < 256; i++) + { + crc_accum = (U32)i << 24; + + for (j = 0; j < 8; j++) + { + if (crc_accum & (1 << 31)) + { + crc_accum = (crc_accum << 1) ^ 0x04C11DB7; + } + else + { + crc_accum = (crc_accum << 1); + } + } + + g_crc32_table[i] = crc_accum; + } + + g_crc_needinit = 0; + } } return g_xutilinit; @@ -468,6 +495,26 @@ S32 icompare(const substr& s1, const substr& s2) return result; } +S32 imemcmp(const void* d1, const void* d2, unsigned long size) +{ + char* s1 = (char*)d1; + char* s2 = (char*)d2; + U32 i = 0; + while (i < size) + { + S32 v1 = *s1 | ((*s1 >> 1) & 0x20); + S32 v2 = *s2 | ((*s2 >> 1) & 0x20); + if (v1 != v2) + { + return v1 - v2; + } + s1++; + s2++; + i++; + } + return 0; +} + char* xStrupr(char* string) { char* p = string; @@ -490,7 +537,7 @@ U32 xStrHashCat(U32 prefix, const char* str) while (i = *str, i != NULL) { str++; - hash = (i - (i & (S32)i >> 1 & 0x20) & 0xff) + hash * 0x83; + hash = (i - (i & (U8)i >> 1 & 0x20) & 0xff) + hash * 0x83; } return hash; @@ -506,7 +553,7 @@ U32 xStrHash(const char* str, size_t size) { i++; str++; - hash = (c - (c & (S32)c >> 1 & 0x20) & 0xff) + hash * 0x83; + hash = (c - (c & (U8)c >> 1 & 0x20) & 0xff) + hash * 0x83; } return hash; @@ -519,7 +566,7 @@ U32 xStrHash(const char* str) while (i = *str, i != NULL) { - hash = (i - (i & (S32)i >> 1 & 0x20) & 0xff) + hash * 0x83; + hash = (i - (i & (U8)i >> 1 & 0x20) & 0xff) + hash * 0x83; str++; }