Skip to content

Commit 6187d79

Browse files
committed
Merge branch 'main' into dev6
2 parents 2bd2c69 + c14e37a commit 6187d79

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

src/SB/Core/x/xWad5.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,41 @@ char* xUtil_idtag2string(U32 srctag, S32 bufidx)
266266

267267
S32 xUtilShutdown()
268268
{
269-
return g_xutilinit--;
269+
return --g_xutilinit;
270270
}
271271

272272
S32 xUtilStartup()
273273
{
274274
if (!g_xutilinit++)
275275
{
276-
xUtil_crc_init();
276+
// From xUtil_crc_init:
277+
278+
S32 i, j;
279+
U32 crc_accum;
280+
281+
if (g_crc_needinit)
282+
{
283+
for (i = 0; i < 256; i++)
284+
{
285+
crc_accum = (U32)i << 24;
286+
287+
for (j = 0; j < 8; j++)
288+
{
289+
if (crc_accum & (1 << 31))
290+
{
291+
crc_accum = (crc_accum << 1) ^ 0x04C11DB7;
292+
}
293+
else
294+
{
295+
crc_accum = (crc_accum << 1);
296+
}
297+
}
298+
299+
g_crc32_table[i] = crc_accum;
300+
}
301+
302+
g_crc_needinit = 0;
303+
}
277304
}
278305

279306
return g_xutilinit;
@@ -468,6 +495,26 @@ S32 icompare(const substr& s1, const substr& s2)
468495
return result;
469496
}
470497

498+
S32 imemcmp(const void* d1, const void* d2, unsigned long size)
499+
{
500+
char* s1 = (char*)d1;
501+
char* s2 = (char*)d2;
502+
U32 i = 0;
503+
while (i < size)
504+
{
505+
S32 v1 = *s1 | ((*s1 >> 1) & 0x20);
506+
S32 v2 = *s2 | ((*s2 >> 1) & 0x20);
507+
if (v1 != v2)
508+
{
509+
return v1 - v2;
510+
}
511+
s1++;
512+
s2++;
513+
i++;
514+
}
515+
return 0;
516+
}
517+
471518
char* xStrupr(char* string)
472519
{
473520
char* p = string;
@@ -490,7 +537,7 @@ U32 xStrHashCat(U32 prefix, const char* str)
490537
while (i = *str, i != NULL)
491538
{
492539
str++;
493-
hash = (i - (i & (S32)i >> 1 & 0x20) & 0xff) + hash * 0x83;
540+
hash = (i - (i & (U8)i >> 1 & 0x20) & 0xff) + hash * 0x83;
494541
}
495542

496543
return hash;
@@ -506,7 +553,7 @@ U32 xStrHash(const char* str, size_t size)
506553
{
507554
i++;
508555
str++;
509-
hash = (c - (c & (S32)c >> 1 & 0x20) & 0xff) + hash * 0x83;
556+
hash = (c - (c & (U8)c >> 1 & 0x20) & 0xff) + hash * 0x83;
510557
}
511558

512559
return hash;
@@ -519,7 +566,7 @@ U32 xStrHash(const char* str)
519566

520567
while (i = *str, i != NULL)
521568
{
522-
hash = (i - (i & (S32)i >> 1 & 0x20) & 0xff) + hash * 0x83;
569+
hash = (i - (i & (U8)i >> 1 & 0x20) & 0xff) + hash * 0x83;
523570
str++;
524571
}
525572

0 commit comments

Comments
 (0)