refactor: Ambiguous game version support for hooks::soundbank

> user supplied sndbhook offset through `prop/linux.json`
> fix tests
This commit is contained in:
[ ]
2025-06-02 23:34:42 +09:00
parent 7ceeda8bca
commit 127d07ed31
+17 -4
View File
@@ -22,9 +22,11 @@ enum pcm_resampler : int8_t
}; };
typedef enum pcm_resampler pcm_resampler_t; typedef enum pcm_resampler pcm_resampler_t;
typedef void (*BmswConfigInit_t)(const char *path); typedef void (*BmswConfigInit_t)(const char *path);
typedef uint64_t (*BmswEnumValidSoundbanksAddr_t)();
typedef int (*BmswSymlink_t)(const char *srcwpath, const char *dstwpath, int canonic); typedef int (*BmswSymlink_t)(const char *srcwpath, const char *dstwpath, int canonic);
typedef int (*BmswTranscoderAsfToWav_t)(const uint8_t *srcasf, uint32_t srcsz, uint8_t **dstwav, uint32_t *dstsz, pcm_resampler_t resampler); typedef int (*BmswTranscoderAsfToWav_t)(const uint8_t *srcasf, uint32_t srcsz, uint8_t **dstwav, uint32_t *dstsz, pcm_resampler_t resampler);
static BmswConfigInit_t BmswConfigInit; static BmswConfigInit_t BmswConfigInit;
BmswEnumValidSoundbanksAddr_t BmswEnumValidSoundbanksAddr;
static BmswSymlink_t BmswSymlink; static BmswSymlink_t BmswSymlink;
static BmswTranscoderAsfToWav_t BmswTranscoderAsfToWav; static BmswTranscoderAsfToWav_t BmswTranscoderAsfToWav;
static HMODULE bmsw_ = nullptr; static HMODULE bmsw_ = nullptr;
@@ -33,9 +35,12 @@ bool init()
log_info("hooks::soundbank::avcodec", "{}", __FUNCTION__); log_info("hooks::soundbank::avcodec", "{}", __FUNCTION__);
// Initialize bmsound-wine.dll once // Initialize bmsound-wine.dll once
if (!bmsw_ && (bmsw_ = libutils::try_library(MODULE_PATH / "bmsound-wine.dll"))) if (bmsw_)
return true;
if ((bmsw_ = libutils::try_library(MODULE_PATH / "bmsound-wine.dll")))
{ {
BmswConfigInit = (BmswConfigInit_t) GetProcAddress(bmsw_, "BmswConfigInit"); BmswConfigInit = (BmswConfigInit_t) GetProcAddress(bmsw_, "BmswConfigInit");
BmswEnumValidSoundbanksAddr = (BmswEnumValidSoundbanksAddr_t) GetProcAddress(bmsw_, "BmswEnumValidSoundbanksAddr");
BmswSymlink = (BmswSymlink_t) GetProcAddress(bmsw_, "BmswSymlink"); BmswSymlink = (BmswSymlink_t) GetProcAddress(bmsw_, "BmswSymlink");
BmswTranscoderAsfToWav = (BmswTranscoderAsfToWav_t) GetProcAddress(bmsw_, "BmswTranscoderAsfToWav"); BmswTranscoderAsfToWav = (BmswTranscoderAsfToWav_t) GetProcAddress(bmsw_, "BmswTranscoderAsfToWav");
@@ -840,10 +845,11 @@ void run_tests()
// Caching and intermediate 2dx storage detection // Caching and intermediate 2dx storage detection
BmsbEnumValidSoundbanks_t t = BmsbEnumValidSoundbanks; BmsbEnumValidSoundbanks_t t = BmsbEnumValidSoundbanks;
BmsbEnumValidSoundbanks = [](void *, int32_t, int32_t) -> void * { return nullptr; }; BmsbEnumValidSoundbanks = [](void *, int32_t, int32_t) -> void * { return nullptr; };
char *tmp = (char *) malloc(0x3b0 + sizeof(int32_t)); char *tmp = (char *) malloc(0x3b8 + strlen("00000000") + 1);
int arr[6] = {25073, 24016, 26057, 25073, 26087, 29095}; int arr[6] = {25073, 24016, 26057, 25073, 26087, 29095};
strcpy(tmp, "SJISTITLE"); strcpy(tmp, "SJISTITLE");
strcpy(tmp + 0xc0, "SJISARTIST"); strcpy(tmp + 0xc0, "SJISARTIST");
strcpy(tmp + 0x3b8, "00000000");
for (int it: arr) for (int it: arr)
{ {
*(int32_t *) (tmp + 0x3b0) = it; *(int32_t *) (tmp + 0x3b0) = it;
@@ -904,8 +910,15 @@ void init(HINSTANCE hmodule, const char *ext)
offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x8eae40; offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x8eae40;
break; break;
default: default:
log_warning("hooks::soundbank", "Unsupported game version({}), skipping..", ext); offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + (int64_t) avcodec::BmswEnumValidSoundbanksAddr();
return; offset_.DAT_song_id = strtol(ext, nullptr, 10) < 2019100800 ? 0x1C8 : offset_.DAT_song_id;
snd_bank::resampler_ = strtol(ext, nullptr, 10) < 2019100800 ? avcodec::bmswac_resampler_s16_ad : snd_bank::resampler_;
if (offset_.TX_BmsbEnumValidSoundbanks == (intptr_t) hmodule)
{
log_warning("hooks::soundbank", "Unsupported game version({}), skipping..", ext);
return;
}
log_info("hooks::soundbank", "Using user supplied offsets({}), support may be limited..", offset_.TX_BmsbEnumValidSoundbanks);
} }
log_info("hooks::soundbank", "Supported game version({})", ext); log_info("hooks::soundbank", "Supported game version({})", ext);