diff --git a/hooks/develhook.cpp b/hooks/develhook.cpp index 16ffd99..fddf0fd 100644 --- a/hooks/develhook.cpp +++ b/hooks/develhook.cpp @@ -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 from_env(const char *str) { std::vector 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; } diff --git a/hooks/sndbhook.cpp b/hooks/sndbhook.cpp index 19fb232..5945a4b 100644 --- a/hooks/sndbhook.cpp +++ b/hooks/sndbhook.cpp @@ -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 @@ -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: diff --git a/hooks/wmischook.cpp b/hooks/wmischook.cpp index 55addd3..ccf2694 100644 --- a/hooks/wmischook.cpp +++ b/hooks/wmischook.cpp @@ -3,6 +3,7 @@ #include "util/detour.h" #include "util/sigscan.h" #include "util/libutils.h" +#include "util/utils.h" #include @@ -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; diff --git a/util/utils.h b/util/utils.h index 52d1132..8e0f15c 100644 --- a/util/utils.h +++ b/util/utils.h @@ -27,6 +27,11 @@ static const char HEX_LOOKUP_UPPERCASE[16] = { const char *inet_ntop(short af, const void *src, char *dst, DWORD size); +static inline constexpr unsigned int to_hash(const char *str, int h = 0) +{ + return !str[h] ? 5381 : (to_hash(str, h + 1) * 33) ^ str[h]; +} + static inline bool string_begins_with(const std::string &s, const std::string &prefix) { return s.compare(0, prefix.size(), prefix) == 0; }