refactor: Handle optional experimental code better

> introduce `hooks::devel` to aggregate debug specific code
> fix support for IIDX31 (target LDJ-010 instead)
This commit is contained in:
[ ]
2025-06-02 21:34:28 +09:00
parent cd709f0a55
commit 7ceeda8bca
6 changed files with 140 additions and 28 deletions
+4 -27
View File
@@ -1,4 +1,5 @@
#include "sndbhook.h"
#include "hooks/develhook.h"
#include "util/logging.h"
#include "util/memutils.h"
#include "util/sigscan.h"
@@ -701,25 +702,6 @@ snd_bank *snd_bank::cache_ = nullptr;
size_t snd_bank::cachesz_ = 0;
avcodec::pcm_resampler_t snd_bank::resampler_ = avcodec::bmswac_resampler_s16;
static BmsbEnumValidSoundbanks_t BmsbEnumValidSoundbanks;
static avs::core::AVS_FS_LSTAT_T avs_fs_lstat_;
static avs::core::AVS_FS_MOUNT_T avs_fs_mount_;
int on_avs_fs_lstat(const char *path, struct avs::core::avs_stat *stat)
{
if (strstr(path, "29095"))
{
log_info("hooks::soundbank", "avs_fs_lstat_({})", 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, "29095"))
{
log_info("hooks::soundbank", "avs_fs_mount({}=>{}) @{} :nullptr data?{} ", fsroot, mountpoint, fstype, data == nullptr);
}
return avs_fs_mount_(mountpoint, fsroot, fstype, data);
}
void *on_enum_valid_soundbanks(void *song, int32_t difficulty, int32_t unk2)
{
// Keysounds populated into CtrlSound::Bank[2][X] = [0:s3p][1:2dx][2:_pre.2dx], always uses lowest i databank for resource confirmed valid by this function
@@ -788,8 +770,6 @@ void run_tests()
{
log_warning("hooks::soundbank", "MF initialization failed, skipping..");
}
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_));
// Filesystem tests, s3p unpacking
snprintf(avspath, sizeof(avspath), "data/sound/%05d", id);
@@ -921,7 +901,7 @@ void init(HINSTANCE hmodule, const char *ext)
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0xafd780;
break;
case offset_t::by_ext("2024082600"):
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x81dd40;
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x8eae40;
break;
default:
log_warning("hooks::soundbank", "Unsupported game version({}), skipping..", ext);
@@ -940,15 +920,12 @@ void init(HINSTANCE hmodule, const char *ext)
return;
}
// Setup on_enum_valid_ksbd
// Setup on_enum_valid_ksbd and optional tests
offset_.guard = new memutils::VProtectGuard((void *) offset_.RD_05d_2dx, SNDPATHFMTMAX);
detour::trampoline(reinterpret_cast<void *>(offset_.TX_BmsbEnumValidSoundbanks), reinterpret_cast<void *>(on_enum_valid_soundbanks), reinterpret_cast<void **>(&BmsbEnumValidSoundbanks));
hooks::devel::bind_routine(hooks::devel::sndb_test, run_tests);
log_info("hooks::soundbank", "Soundbank preprocessor ready");
// Tests
if (getenv("SPICE_TESTING"))
run_tests();
}
void deinit(HINSTANCE hmodule)
{