refactor: Unify string hashing
> moved to util/utils.h
This commit is contained in:
+12
-8
@@ -2,6 +2,7 @@
|
|||||||
#include "util/logging.h"
|
#include "util/logging.h"
|
||||||
#include "util/detour.h"
|
#include "util/detour.h"
|
||||||
#include "util/libutils.h"
|
#include "util/libutils.h"
|
||||||
|
#include "util/utils.h"
|
||||||
#include "avs/core.h"
|
#include "avs/core.h"
|
||||||
#include "avs/game.h"
|
#include "avs/game.h"
|
||||||
#include "hooks/wmischook.h"
|
#include "hooks/wmischook.h"
|
||||||
@@ -76,10 +77,10 @@ void (*routine_cb_[devel_routine_last])() ={
|
|||||||
[thum_test] = thumbnail::run
|
[thum_test] = thumbnail::run
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr unsigned int by_str(const char *str, int h = 0)
|
//static constexpr unsigned int to_hash(const char *str, int h = 0)
|
||||||
{
|
//{
|
||||||
return !str[h] ? 5381 : (by_str(str, h + 1) * 33) ^ str[h];
|
// 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> from_env(const char *str)
|
||||||
{
|
{
|
||||||
std::vector<std::string> r;
|
std::vector<std::string> r;
|
||||||
@@ -101,17 +102,20 @@ static devel_routine_t routines()
|
|||||||
routines_ = 0;
|
routines_ = 0;
|
||||||
for (const auto &routine: from_env("SPICE_DEVEL"))
|
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;
|
routines_ |= 1 << avs_fs_detour;
|
||||||
break;
|
break;
|
||||||
case by_str("sndb_test"):
|
case to_hash("sndb_test"):
|
||||||
routines_ |= 1 << sndb_test;
|
routines_ |= 1 << sndb_test;
|
||||||
break;
|
break;
|
||||||
case by_str("thum_test"):
|
case to_hash("thum_test"):
|
||||||
routines_ |= 1 << thum_test;
|
routines_ |= 1 << thum_test;
|
||||||
break;
|
break;
|
||||||
|
case to_hash("acm_test"):
|
||||||
|
routines_ |= 1 << acm_test;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-16
@@ -5,6 +5,7 @@
|
|||||||
#include "util/sigscan.h"
|
#include "util/sigscan.h"
|
||||||
#include "util/detour.h"
|
#include "util/detour.h"
|
||||||
#include "util/libutils.h"
|
#include "util/libutils.h"
|
||||||
|
#include "util/utils.h"
|
||||||
#include "avs/core.h"
|
#include "avs/core.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@@ -698,11 +699,6 @@ static struct offset_t
|
|||||||
intptr_t DAT_song_id;
|
intptr_t DAT_song_id;
|
||||||
bool is_lstr_wchar;
|
bool is_lstr_wchar;
|
||||||
memutils::VProtectGuard *guard;
|
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_;
|
} offset_;
|
||||||
snd_bank *snd_bank::cache_ = nullptr;
|
snd_bank *snd_bank::cache_ = nullptr;
|
||||||
size_t snd_bank::cachesz_ = 0;
|
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_.DAT_song_id = 0x67c;
|
||||||
offset_.is_lstr_wchar = true;
|
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;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x1170b0;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2019090200"):
|
case to_hash("2019090200"):
|
||||||
case offset_t::by_ext("2019100700"):
|
case to_hash("2019100700"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x37a540;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x37a540;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2020092900"):
|
case to_hash("2020092900"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x5ac460;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x5ac460;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2021083000"):
|
case to_hash("2021083000"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x766bc0;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x766bc0;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2021091500"):
|
case to_hash("2021091500"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x766c60;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x766c60;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2022082400"):
|
case to_hash("2022082400"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x46e160;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x46e160;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2023090500"):
|
case to_hash("2023090500"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0xafd780;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0xafd780;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2024082600"):
|
case to_hash("2024082600"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x8eae40;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x8eae40;
|
||||||
break;
|
break;
|
||||||
case offset_t::by_ext("2025082500"):
|
case to_hash("2025082500"):
|
||||||
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x969fb0;
|
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x969fb0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
+3
-12
@@ -3,6 +3,7 @@
|
|||||||
#include "util/detour.h"
|
#include "util/detour.h"
|
||||||
#include "util/sigscan.h"
|
#include "util/sigscan.h"
|
||||||
#include "util/libutils.h"
|
#include "util/libutils.h"
|
||||||
|
#include "util/utils.h"
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -106,22 +107,12 @@ void run(HINSTANCE hmodule)
|
|||||||
|
|
||||||
namespace hooks::wmisc
|
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)
|
void apply_performance_hacks(HINSTANCE hmodule, const char *model, const char *ext)
|
||||||
{
|
{
|
||||||
log_info("hooks::wmisc", "Enabling performance patches for {}-{}", model, 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);
|
thumbnail::run(hmodule);
|
||||||
msacm::run(hmodule);
|
msacm::run(hmodule);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ static const char HEX_LOOKUP_UPPERCASE[16] = {
|
|||||||
|
|
||||||
const char *inet_ntop(short af, const void *src, char *dst, DWORD size);
|
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) {
|
static inline bool string_begins_with(const std::string &s, const std::string &prefix) {
|
||||||
return s.compare(0, prefix.size(), prefix) == 0;
|
return s.compare(0, prefix.size(), prefix) == 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user