From a9940a9b9c24bbcebee303e357e7cb35d4b808c4 Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 09:59:33 -0400 Subject: [PATCH 1/8] Match imemcmp --- src/SB/Core/x/xWad5.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index 6f8e255..da0887a 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -468,6 +468,26 @@ S32 icompare(const substr& s1, const substr& s2) return result; } +S32 imemcmp(U8* d1, U8* d2, U32 size) +{ + U8* s1 = d1; + U8* s2 = 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; From 0e5f8f84829a91142cd077d51d4b99401262fce7 Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 12:37:47 -0400 Subject: [PATCH 2/8] Match xStrHash functions --- src/SB/Core/x/xWad5.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index da0887a..26c9139 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -510,7 +510,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; @@ -526,7 +526,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; @@ -539,7 +539,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++; } From a02bd324fbb9de6d73f0931f99e0cad82adfc6dd Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 14:13:02 -0400 Subject: [PATCH 3/8] xUtil work --- src/SB/Core/x/xWad5.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index 26c9139..8219222 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; From e858d28d83b2a3384a0804f964cc81a09c171e6e Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 14:14:33 -0400 Subject: [PATCH 4/8] Fix types in imemcmp --- src/SB/Core/x/xWad5.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index 8219222..192d72a 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -495,10 +495,10 @@ S32 icompare(const substr& s1, const substr& s2) return result; } -S32 imemcmp(U8* d1, U8* d2, U32 size) +S32 imemcmp(char* d1, char* d2, U32 size) { - U8* s1 = d1; - U8* s2 = d2; + char* s1 = d1; + char* s2 = d2; U32 i = 0; while (i < size) { From 884b5c22cf9b996e1fd1e04c91fa162c1e6835b7 Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 14:45:35 -0400 Subject: [PATCH 5/8] Fix tab/space inconsistency --- src/SB/Core/x/xWad5.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index 192d72a..c86f9d6 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -497,9 +497,9 @@ S32 icompare(const substr& s1, const substr& s2) S32 imemcmp(char* d1, char* d2, U32 size) { - char* s1 = d1; - char* s2 = d2; - U32 i = 0; + char* s1 = d1; + char* s2 = d2; + U32 i = 0; while (i < size) { S32 v1 = *s1 | ((*s1 >> 1) & 0x20); From 5d239e97ebae0ce4822c022acc05abe5a5036a30 Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:41:46 -0400 Subject: [PATCH 6/8] Match imemcmp --- src/SB/Core/x/xWad5.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index c86f9d6..b83e0c9 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -495,10 +495,10 @@ S32 icompare(const substr& s1, const substr& s2) return result; } -S32 imemcmp(char* d1, char* d2, U32 size) +S32 imemcmp(void* d1, void* d2, U32 size) { - char* s1 = d1; - char* s2 = d2; + char* s1 = (char*)d1; + char* s2 = (char*)d2; U32 i = 0; while (i < size) { From 00966ce8a54e60e69a387733d12987f49015bd9e Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:45:14 -0400 Subject: [PATCH 7/8] Fix arg types in imemcmp For real this time --- src/SB/Core/x/xWad5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index b83e0c9..4c3f389 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -495,7 +495,7 @@ S32 icompare(const substr& s1, const substr& s2) return result; } -S32 imemcmp(void* d1, void* d2, U32 size) +S32 imemcmp(const void* d1, const void* d2, U32 size) { char* s1 = (char*)d1; char* s2 = (char*)d2; From 367d701a706102e72f062c62ae722987b4376e21 Mon Sep 17 00:00:00 2001 From: bluisblu <53455507+bluisblu@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:50:41 -0400 Subject: [PATCH 8/8] Finally match imemcmp's args --- src/SB/Core/x/xWad5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SB/Core/x/xWad5.cpp b/src/SB/Core/x/xWad5.cpp index 4c3f389..d4315c7 100644 --- a/src/SB/Core/x/xWad5.cpp +++ b/src/SB/Core/x/xWad5.cpp @@ -495,7 +495,7 @@ S32 icompare(const substr& s1, const substr& s2) return result; } -S32 imemcmp(const void* d1, const void* d2, U32 size) +S32 imemcmp(const void* d1, const void* d2, unsigned long size) { char* s1 = (char*)d1; char* s2 = (char*)d2;