refactor: Unify string hashing

> moved to util/utils.h
This commit is contained in:
[ ]
2025-12-15 23:53:18 +09:00
parent 42689377e6
commit 7f63b77ab3
4 changed files with 32 additions and 36 deletions
+12 -8
View File
@@ -2,6 +2,7 @@
#include "util/logging.h"
#include "util/detour.h"
#include "util/libutils.h"
#include "util/utils.h"
#include "avs/core.h"
#include "avs/game.h"
#include "hooks/wmischook.h"
@@ -76,10 +77,10 @@ void (*routine_cb_[devel_routine_last])() ={
[thum_test] = thumbnail::run
};
static constexpr unsigned int by_str(const char *str, int h = 0)
{
return !str[h] ? 5381 : (by_str(str, h + 1) * 33) ^ str[h];
}
//static constexpr unsigned int to_hash(const char *str, int h = 0)
//{
// return !str[h] ? 5381 : (to_hash(str, h + 1) * 33) ^ str[h];
//}
std::vector<std::string> from_env(const char *str)
{
std::vector<std::string> r;
@@ -101,17 +102,20 @@ static devel_routine_t routines()
routines_ = 0;
for (const auto &routine: from_env("SPICE_DEVEL"))
{
switch (by_str(routine.c_str()))
switch (to_hash(routine.c_str()))
{
case by_str("avs_fs_detour"):
case to_hash("avs_fs_detour"):
routines_ |= 1 << avs_fs_detour;
break;
case by_str("sndb_test"):
case to_hash("sndb_test"):
routines_ |= 1 << sndb_test;
break;
case by_str("thum_test"):
case to_hash("thum_test"):
routines_ |= 1 << thum_test;
break;
case to_hash("acm_test"):
routines_ |= 1 << acm_test;
break;
default:
break;
}
+12 -16
View File
@@ -5,6 +5,7 @@
#include "util/sigscan.h"
#include "util/detour.h"
#include "util/libutils.h"
#include "util/utils.h"
#include "avs/core.h"
#include <cstring>
@@ -698,11 +699,6 @@ static struct offset_t
intptr_t DAT_song_id;
bool is_lstr_wchar;
memutils::VProtectGuard *guard;
static constexpr unsigned int by_ext(const char *ext, int h = 0)
{
return !ext[h] ? 5381 : (by_ext(ext, h + 1) * 33) ^ ext[h];
}
} offset_;
snd_bank *snd_bank::cache_ = nullptr;
size_t snd_bank::cachesz_ = 0;
@@ -909,34 +905,34 @@ void init(HINSTANCE hmodule, const char *model, const char *ext)
offset_.DAT_song_id = 0x67c;
offset_.is_lstr_wchar = true;
}
switch (offset_t::by_ext(ext))
switch (to_hash(ext))
{
case offset_t::by_ext("2018091900"):
case to_hash("2018091900"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x1170b0;
break;
case offset_t::by_ext("2019090200"):
case offset_t::by_ext("2019100700"):
case to_hash("2019090200"):
case to_hash("2019100700"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x37a540;
break;
case offset_t::by_ext("2020092900"):
case to_hash("2020092900"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x5ac460;
break;
case offset_t::by_ext("2021083000"):
case to_hash("2021083000"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x766bc0;
break;
case offset_t::by_ext("2021091500"):
case to_hash("2021091500"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x766c60;
break;
case offset_t::by_ext("2022082400"):
case to_hash("2022082400"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x46e160;
break;
case offset_t::by_ext("2023090500"):
case to_hash("2023090500"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0xafd780;
break;
case offset_t::by_ext("2024082600"):
case to_hash("2024082600"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x8eae40;
break;
case offset_t::by_ext("2025082500"):
case to_hash("2025082500"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x969fb0;
break;
default:
+3 -12
View File
@@ -3,6 +3,7 @@
#include "util/detour.h"
#include "util/sigscan.h"
#include "util/libutils.h"
#include "util/utils.h"
#include <mmsystem.h>
@@ -106,22 +107,12 @@ void run(HINSTANCE hmodule)
namespace hooks::wmisc
{
static constexpr unsigned int by_model(const char *model, int h = 0)
{
return !model[h] ? 5381 : (by_model(model, h + 1) * 33) ^ model[h];
}
static constexpr unsigned int by_ext(const char *ext, int h = 0)
{
return !ext[h] ? 5381 : (by_ext(ext, h + 1) * 33) ^ ext[h];
}
void apply_performance_hacks(HINSTANCE hmodule, const char *model, const char *ext)
{
log_info("hooks::wmisc", "Enabling performance patches for {}-{}", model, ext);
switch (by_model(model))
switch (to_hash(model))
{
case by_model("LDJ"):
case to_hash("LDJ"):
thumbnail::run(hmodule);
msacm::run(hmodule);
break;