refactor: Cleanup develhook logic

> refactor hooks::devel to work better with hooks::wmisc
> minor naming consistency changes
This commit is contained in:
[ ]
2025-12-17 00:00:40 +09:00
parent 7f63b77ab3
commit 56e8e7456b
6 changed files with 253 additions and 205 deletions
+113 -98
View File
@@ -12,75 +12,84 @@
#include <sstream>
namespace hooks::devel::thumbnail
{
typedef int (*BmswSymlink_t)(const char *srcwpath, const char *dstwpath, int canonic);
static BmswSymlink_t BmswSymlink;
void run()
{
HMODULE bmsw_ = nullptr;
if ((bmsw_ = libutils::try_library(MODULE_PATH / "bmsound-wine.dll")))
{
BmswSymlink = (BmswSymlink_t) GetProcAddress(bmsw_, "BmswSymlink");
}
log_warning("hooks::devel::thumbnail", "Forcing thumbnail patch..");
hooks::wmisc::apply_performance_hacks(avs::game::DLL_INSTANCE, "LDJ", "20250825");
}
}
namespace hooks::devel::avs_fs
{
static constexpr char needle_[] = ""; // set to "" to print all
static avs::core::AVS_FS_LSTAT_T avs_fs_lstat_;
static avs::core::AVS_FS_MOUNT_T avs_fs_mount_;
static avs::core::AVS_FS_OPEN_T avs_fs_open_;
int on_avs_fs_lstat(const char *path, struct avs::core::avs_stat *stat)
{
if (strstr(path, needle_))
{
log_info("hooks::devel", "{}({})", __FUNCTION__, path);
}
return avs_fs_lstat_(path, stat);
}
avs::core::avs_file_t on_avs_fs_mount(const char *mountpoint, const char *fsroot, const char *fstype, void *data)
{
if (strstr(fsroot, needle_))
{
log_info("hooks::devel", "{}({}=>{}) @{} :nullptr data?{} ", __FUNCTION__, fsroot, mountpoint, fstype, data == nullptr);
}
return avs_fs_mount_(mountpoint, fsroot, fstype, data);
}
avs::core::avs_file_t on_avs_fs_open(const char *name, uint16_t mode, int flags)
{
if (strstr(name, needle_))
{
log_info("hooks::devel", "{}({}::{}) @{}", __FUNCTION__, name, mode, flags);
}
return avs_fs_open_(name, mode, flags);
}
void run()
{
detour::trampoline(reinterpret_cast<void *>(avs::core::avs_fs_lstat), reinterpret_cast<void *>(on_avs_fs_lstat), reinterpret_cast<void **>(&avs_fs_lstat_));
detour::trampoline(reinterpret_cast<void *>(avs::core::avs_fs_mount), reinterpret_cast<void *>(on_avs_fs_mount), reinterpret_cast<void **>(&avs_fs_mount_));
detour::trampoline(reinterpret_cast<void *>(avs::core::avs_fs_open), reinterpret_cast<void *>(on_avs_fs_open), reinterpret_cast<void **>(&avs_fs_open_));
}
}
namespace hooks::devel
{
void (*routine_cb_[devel_routine_last])() ={
[avs_fs_detour] = avs_fs::run,
[sndb_test] = nullptr,
[thum_test] = thumbnail::run
};
static class Thumbnail : public Routine
{
public:
using Routine::Routine;
void entry_main() override
{
log_warning("hooks::devel::thumbnail", "Forcing thumbnail patch..");
hooks::wmisc::apply_performance_hacks(avs::game::DLL_INSTANCE, "FORCE", "thumbnail");
}
} thumbnail_("thum_test");
static class Msacm : public Routine
{
public:
using Routine::Routine;
void entry_main() override
{
log_warning("hooks::devel::msacm", "Forcing msacm patch..");
hooks::wmisc::apply_performance_hacks(avs::game::DLL_INSTANCE, "FORCE", "msacm");
}
} msacm_("acm_test");
static class Wmisc : public Routine
{
public:
using Routine::Routine;
void attach() override
{
log_warning("hooks::devel::wmisc", "Disabling auto-patching..");
hooks::wmisc::skip_patching_by_model(true);
}
} wmisc_("wmisc_test");
static class Avs_fs : public Routine
{
private:
static constexpr char needle_[] = ""; // set to "" to print all
inline static avs::core::AVS_FS_LSTAT_T avs_fs_lstat_;
inline static avs::core::AVS_FS_MOUNT_T avs_fs_mount_;
inline static avs::core::AVS_FS_OPEN_T avs_fs_open_;
static int on_avs_fs_lstat(const char *path, struct avs::core::avs_stat *stat)
{
if (strstr(path, needle_))
{
log_info("hooks::devel", "{}({})", __FUNCTION__, path);
}
return avs_fs_lstat_(path, stat);
}
static avs::core::avs_file_t on_avs_fs_mount(const char *mountpoint, const char *fsroot, const char *fstype, void *data)
{
if (strstr(fsroot, needle_))
{
log_info("hooks::devel", "{}({}=>{}) @{} :nullptr data?{} ", __FUNCTION__, fsroot, mountpoint, fstype, data == nullptr);
}
return avs_fs_mount_(mountpoint, fsroot, fstype, data);
}
static avs::core::avs_file_t on_avs_fs_open(const char *name, uint16_t mode, int flags)
{
if (strstr(name, needle_))
{
log_info("hooks::devel", "{}({}::{}) @{}", __FUNCTION__, name, mode, flags);
}
return avs_fs_open_(name, mode, flags);
}
public:
using Routine::Routine;
void entry_main() override
{
detour::trampoline(reinterpret_cast<void *>(avs::core::avs_fs_lstat), reinterpret_cast<void *>(on_avs_fs_lstat), reinterpret_cast<void **>(&avs_fs_lstat_));
detour::trampoline(reinterpret_cast<void *>(avs::core::avs_fs_mount), reinterpret_cast<void *>(on_avs_fs_mount), reinterpret_cast<void **>(&avs_fs_mount_));
detour::trampoline(reinterpret_cast<void *>(avs::core::avs_fs_open), reinterpret_cast<void *>(on_avs_fs_open), reinterpret_cast<void **>(&avs_fs_open_));
}
} avs_fs_("avs_fs_detour");
//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;
@@ -94,50 +103,56 @@ std::vector<std::string> from_env(const char *str)
return r;
}
static devel_routine_t routines()
static std::vector<Routine*> &routines()
{
static devel_routine_t routines_ = -1;
if (routines_ == static_cast<devel_routine_t>(-1))
static std::vector<Routine*> routines_;
if (routines_.empty())
{
routines_ = 0;
for (const auto &routine: from_env("SPICE_DEVEL"))
{
switch (to_hash(routine.c_str()))
{
case to_hash("avs_fs_detour"):
routines_ |= 1 << avs_fs_detour;
break;
case to_hash("sndb_test"):
routines_ |= 1 << sndb_test;
break;
case to_hash("thum_test"):
routines_ |= 1 << thum_test;
break;
case to_hash("acm_test"):
routines_ |= 1 << acm_test;
break;
default:
break;
}
}
//Default routines
routines_.push_back(&avs_fs_);
routines_.push_back(&thumbnail_);
routines_.push_back(&msacm_);
routines_.push_back(&wmisc_);
}
return routines_;
}
bool active_routine(hooks::devel::devel_routine_t val)
Routine *active_routine(const char *name)
{
return routines() & (1 << val);
unsigned int hash = to_hash(name);
for (auto &routine: routines())
{
if (routine->hash() == hash)
return routine;
}
return nullptr;
}
void bind_routine(devel_routine_t val, void (*cb)())
void bind_routine(Routine *routine)
{
routine_cb_[val] = cb;
routines().push_back(routine);
}
void log_environment()
{
log_warning("hooks::devel", "WINEDLLOVERRIDES: '{}'", getenv("WINEDLLOVERRIDES") ? getenv("WINEDLLOVERRIDES") : "null");
}
void entry_main()
{
if (routines()) log_info("hooks::devel", "Processing subroutines..");
for (devel_routine_t i = 0; i < devel_routine_last; i++)
log_environment();
const auto rnames = from_env("SPICE_DEVEL");
if (!rnames.empty()) log_info("hooks::devel", "Run subroutines..");
for (const auto &routinename: from_env("SPICE_DEVEL"))
{
if (active_routine(i) && routine_cb_[i]) routine_cb_[i]();
Routine *routine = active_routine(routinename.c_str());
if (routine) routine->entry_main();
}
}
void attach()
{
const auto rnames = from_env("SPICE_DEVEL");
if (!rnames.empty()) log_info("hooks::devel", "Attach subroutines..");
for (const auto &rname: rnames)
{
Routine *routine = active_routine(rname.c_str());
if (routine) routine->attach();
}
}
}