diff --git a/hooks/sndbhook.cpp b/hooks/sndbhook.cpp index b2e81a4..77175f6 100644 --- a/hooks/sndbhook.cpp +++ b/hooks/sndbhook.cpp @@ -22,9 +22,11 @@ enum pcm_resampler : int8_t }; typedef enum pcm_resampler pcm_resampler_t; 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 (*BmswTranscoderAsfToWav_t)(const uint8_t *srcasf, uint32_t srcsz, uint8_t **dstwav, uint32_t *dstsz, pcm_resampler_t resampler); static BmswConfigInit_t BmswConfigInit; +BmswEnumValidSoundbanksAddr_t BmswEnumValidSoundbanksAddr; static BmswSymlink_t BmswSymlink; static BmswTranscoderAsfToWav_t BmswTranscoderAsfToWav; static HMODULE bmsw_ = nullptr; @@ -33,9 +35,12 @@ bool init() log_info("hooks::soundbank::avcodec", "{}", __FUNCTION__); // 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"); + BmswEnumValidSoundbanksAddr = (BmswEnumValidSoundbanksAddr_t) GetProcAddress(bmsw_, "BmswEnumValidSoundbanksAddr"); BmswSymlink = (BmswSymlink_t) GetProcAddress(bmsw_, "BmswSymlink"); BmswTranscoderAsfToWav = (BmswTranscoderAsfToWav_t) GetProcAddress(bmsw_, "BmswTranscoderAsfToWav"); @@ -840,10 +845,11 @@ void run_tests() // Caching and intermediate 2dx storage detection BmsbEnumValidSoundbanks_t t = BmsbEnumValidSoundbanks; 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}; strcpy(tmp, "SJISTITLE"); strcpy(tmp + 0xc0, "SJISARTIST"); + strcpy(tmp + 0x3b8, "00000000"); for (int it: arr) { *(int32_t *) (tmp + 0x3b0) = it; @@ -904,8 +910,15 @@ void init(HINSTANCE hmodule, const char *ext) offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + 0x8eae40; break; default: - log_warning("hooks::soundbank", "Unsupported game version({}), skipping..", ext); - return; + offset_.TX_BmsbEnumValidSoundbanks = (intptr_t) hmodule + (int64_t) avcodec::BmswEnumValidSoundbanksAddr(); + 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);