feat: Resolve low framerate during song select for IIDX32+
> caused by bad code around thumbnail fetching logic including file checks in every draw call, see #4 > added `hooks::wmisc` for linux specific minor performance fixes and similar
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include "wmischook.h"
|
||||
#include "util/logging.h"
|
||||
#include "util/detour.h"
|
||||
#include "util/sigscan.h"
|
||||
|
||||
|
||||
namespace hooks::wmisc::thumbnail
|
||||
{
|
||||
typedef bool (*ThumExists_t)(void *titleUTF_getter, int32_t id, char flag);
|
||||
static ThumExists_t ThumExists;
|
||||
|
||||
bool on_thum_exists_(void *titleUTF_getter, int32_t id, char flag)
|
||||
{
|
||||
static std::unordered_map<int32_t, bool> thumids;
|
||||
auto it = thumids.find(id);
|
||||
if (it != thumids.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_misc("hooks::wmisc::thumbnail", "Caching state for [{}]", id);
|
||||
it = thumids.insert({id, ThumExists(titleUTF_getter, id, flag)}).first;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void run(HINSTANCE hmodule)
|
||||
{
|
||||
// Reverse lookup function head (PUSH RDI) for ThumExists() specific signature, quietly fail if invalid
|
||||
intptr_t beg, match, TX_ThumExists;
|
||||
TX_ThumExists = beg = match = find_pattern_from(hmodule, "83f801750c4084ff750732c0", "XXXXXXXXXXXX", 0, 0, 0);
|
||||
while (beg > sizeof(intptr_t) && match >= TX_ThumExists)
|
||||
{
|
||||
beg--;
|
||||
match = find_pattern_from(hmodule, "4057", "XX", 0, 0, beg - reinterpret_cast<intptr_t>(hmodule));
|
||||
}
|
||||
TX_ThumExists = match;
|
||||
log_info("hooks::wmisc::thumbnail", "Hooking ThumExists({})", reinterpret_cast<void *>(TX_ThumExists));
|
||||
detour::trampoline_try(reinterpret_cast<void *>(TX_ThumExists), reinterpret_cast<void *>(on_thum_exists_), reinterpret_cast<void **>(&ThumExists));
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
case by_model("LDJ"):
|
||||
thumbnail::run(hmodule);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user