mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
add android fmod initialization check
relates to geode-sdk/android-launcher#13
This commit is contained in:
parent
363a028c1f
commit
06235634bd
1 changed files with 67 additions and 0 deletions
67
loader/src/hooks/AndroidFMODFix.cpp
Normal file
67
loader/src/hooks/AndroidFMODFix.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#ifdef GEODE_IS_ANDROID
|
||||
|
||||
#include <Geode/Geode.hpp>
|
||||
|
||||
using namespace geode::prelude;
|
||||
|
||||
auto g_systemInitialized = false;
|
||||
|
||||
FMOD_RESULT FMOD_System_init_hook(
|
||||
FMOD::System* system, int maxChannels, FMOD_INITFLAGS flags, void* extraData
|
||||
) {
|
||||
g_systemInitialized = true;
|
||||
return system->init(maxChannels, flags, extraData);
|
||||
}
|
||||
|
||||
FMOD_RESULT FMOD_ChannelControl_setVolume_hook(FMOD::ChannelControl* channel, float volume) {
|
||||
if (!g_systemInitialized) {
|
||||
return FMOD_ERR_UNINITIALIZED;
|
||||
}
|
||||
|
||||
return channel->setVolume(volume);
|
||||
}
|
||||
|
||||
$execute {
|
||||
// Workaround for a bug where FMOD::ChannelControl::setVolume is called with
|
||||
// uninitialized (invalid) channel pointers from FMODAudioEngine.
|
||||
// This creates a very annoying crash during load in some cases.
|
||||
|
||||
(void)geode::Mod::get()->hook(
|
||||
reinterpret_cast<void*>(geode::addresser::getNonVirtual(&FMOD::System::init)),
|
||||
&FMOD_System_init_hook,
|
||||
"FMOD::System::init"
|
||||
);
|
||||
|
||||
(void)geode::Mod::get()->hook(
|
||||
reinterpret_cast<void*>(geode::addresser::getNonVirtual(&FMOD::ChannelControl::setVolume)),
|
||||
&FMOD_ChannelControl_setVolume_hook,
|
||||
"FMOD::ChannelControl::setVolume"
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
// this hook requires a tuliphook update
|
||||
// (setEffectsVolume is too small to hook, so it overwrites the stopAllMusic call below it)
|
||||
|
||||
#include <Geode/modify/FMODAudioEngine.hpp>
|
||||
|
||||
struct AndroidFMODFix : Modify<AndroidFMODFix, FMODAudioEngine> {
|
||||
void setEffectsVolume(float volume) {
|
||||
if (this->m_system == nullptr) [[unlikely]] {
|
||||
return;
|
||||
}
|
||||
|
||||
FMODAudioEngine::setEffectsVolume(volume);
|
||||
}
|
||||
|
||||
void setBackgroundMusicVolume(float volume) {
|
||||
if (this->m_system == nullptr) [[unlikely]] {
|
||||
return;
|
||||
}
|
||||
|
||||
FMODAudioEngine::setBackgroundMusicVolume(volume);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue