Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/codec/seadHashCRC16.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ class HashCRC16
};

static u32 calcHash(const void* ptr, u32 size);
#if SEAD_HASHCRC_WITHCONTEXT
static u32 calcHashWithContext(Context* context, const void* ptr, u32 size);
#endif

static u32 calcStringHash(const char* str);
static u32 calcStringHash(const SafeString& str) { return calcStringHash(str.cstr()); }
#if SEAD_HASHCRC_WITHCONTEXT
static u32 calcStringHashWithContext(Context* context, const char* str);
static u32 calcStringHashWithContext(Context* context, const SafeString& str)
{
return calcStringHashWithContext(context, str.cstr());
}
#endif

static void initialize();

Expand Down
4 changes: 4 additions & 0 deletions include/codec/seadHashCRC32.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ class HashCRC32
};

static u32 calcHash(const void* ptr, u32 size);
#if SEAD_HASHCRC_WITHCONTEXT
static u32 calcHashWithContext(Context* context, const void* ptr, u32 size);
#endif

static u32 calcStringHash(const char* str);
static u32 calcStringHash(const SafeString& str) { return calcStringHash(str.cstr()); }
#if SEAD_HASHCRC_WITHCONTEXT
static u32 calcStringHashWithContext(Context* context, const char* str);
static u32 calcStringHashWithContext(Context* context, const SafeString& str)
{
return calcStringHashWithContext(context, str.cstr());
}
#endif

static void initialize();

Expand Down
5 changes: 5 additions & 0 deletions include/seadVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
/// Add isExistFileImpl_() to sead::ArchiveRes
/// SEAD_ARCHIVERES_ISCONST
/// Make most functions in sead::ArchiveRes const
/// SEAD_HASHCRC_WITHCONTEXT:
/// Add calcHashWithContext and calcStringHashWithContext to HashCRC16/32

#if SEAD_VERSION == SEAD_VERSION_BOTW
#define SEAD_SAFESTRING_NONVIRTUAL 0
Expand All @@ -51,6 +53,7 @@
#define SEAD_ARCHIVERES_TRYGETFILEPATH 0
#define SEAD_ARCHIVERES_ISEXISTFILEIMPL 1
#define SEAD_ARCHIVERES_ISCONST 1
#define SEAD_HASHCRC_WITHCONTEXT 1
#elif SEAD_VERSION == SEAD_VERSION_SMO
#define SEAD_SAFESTRING_NONVIRTUAL 0
#define SEAD_RESOURCEMGR_TRYCREATE_NO_FACTORY_NAME 0
Expand All @@ -64,6 +67,7 @@
#define SEAD_ARCHIVERES_TRYGETFILEPATH 0
#define SEAD_ARCHIVERES_ISEXISTFILEIMPL 0
#define SEAD_ARCHIVERES_ISCONST 0
#define SEAD_HASHCRC_WITHCONTEXT 0
#elif SEAD_VERSION == SEAD_VERSION_SPL3 or SEAD_VERSION == SEAD_VERSION_TOTK or \
SEAD_VERSION == SEAD_VERSION_SMBW
#define SEAD_SAFESTRING_NONVIRTUAL 1
Expand All @@ -78,6 +82,7 @@
#define SEAD_ARCHIVERES_TRYGETFILEPATH 1
#define SEAD_ARCHIVERES_ISEXISTFILEIMPL 1
#define SEAD_ARCHIVERES_ISCONST 1
#define SEAD_HASHCRC_WITHCONTEXT 1
#endif

/// feature-specific macros
Expand Down
31 changes: 31 additions & 0 deletions modules/src/codec/seadHashCRC16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void HashCRC16::initialize()
sInitialized = true;
}

#if SEAD_HASHCRC_WITHCONTEXT
u32 HashCRC16::calcHash(const void* ptr, u32 size)
{
Context ctx;
Expand All @@ -38,6 +39,22 @@ u32 HashCRC16::calcHashWithContext(Context* context, const void* ptr, u32 size)
return hash;
}

#else

u32 HashCRC16::calcHash(const void* ptr, u32 size)
{
if (!sInitialized)
initialize();

u32 hash = 0;
const u8* data = static_cast<const u8*>(ptr);
for (u32 i = 0; i < size; i++)
hash = sTable[data[i] ^ (hash & 0xFF)] ^ (hash >> 8);
return hash;
}
#endif

#if SEAD_HASHCRC_WITHCONTEXT
u32 HashCRC16::calcStringHash(const char* str)
{
Context ctx;
Expand All @@ -56,4 +73,18 @@ u32 HashCRC16::calcStringHashWithContext(Context* context, const char* str)
return hash;
}

#else

u32 HashCRC16::calcStringHash(const char* str)
{
if (!sInitialized)
initialize();

u32 hash = 0;
while (*str)
hash = sTable[*str++ ^ (hash & 0xFF)] ^ (hash >> 8);
return hash;
}
#endif

} // namespace sead
31 changes: 31 additions & 0 deletions modules/src/codec/seadHashCRC32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void HashCRC32::initialize()
sInitialized = true;
}

#if SEAD_HASHCRC_WITHCONTEXT
u32 HashCRC32::calcHash(const void* ptr, u32 size)
{
Context ctx;
Expand All @@ -38,6 +39,22 @@ u32 HashCRC32::calcHashWithContext(Context* context, const void* ptr, u32 size)
return ~hash;
}

#else

u32 HashCRC32::calcHash(const void* ptr, u32 size)
{
if (!sInitialized)
initialize();

u32 hash = -1;
const u8* data = static_cast<const u8*>(ptr);
for (u32 i = 0; i < size; i++)
hash = sTable[data[i] ^ (hash & 0xFF)] ^ (hash >> 8);
return ~hash;
}
#endif

#if SEAD_HASHCRC_WITHCONTEXT
u32 HashCRC32::calcStringHash(const char* str)
{
Context ctx;
Expand All @@ -56,4 +73,18 @@ u32 HashCRC32::calcStringHashWithContext(Context* context, const char* str)
return ~hash;
}

#else

u32 HashCRC32::calcStringHash(const char* str)
{
if (!sInitialized)
initialize();

u32 hash = -1;
while (*str)
hash = sTable[*str++ ^ (hash & 0xFF)] ^ (hash >> 8);
return ~hash;
}
#endif

} // namespace sead