From 2a47e3eab7732700cc38a8c30dde8b94a924f4d6 Mon Sep 17 00:00:00 2001 From: maxnut <54683950+maxnut@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:18:50 +0100 Subject: [PATCH] fix audiochannelcontrol bugs --- src/Hacks/AudioChannelControl.cpp | 37 ++++++++++++++----------------- src/Hacks/AudioChannelControl.h | 4 +--- src/Macrobot/Macrobot.cpp | 7 +++--- src/main.cpp | 1 - 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/Hacks/AudioChannelControl.cpp b/src/Hacks/AudioChannelControl.cpp index 2f636da..9cc1566 100644 --- a/src/Hacks/AudioChannelControl.cpp +++ b/src/Hacks/AudioChannelControl.cpp @@ -13,48 +13,47 @@ using namespace geode::prelude; FMOD_RESULT AudioChannelControl::setVolumeHook(FMOD::Channel* channel, float volume) { - audioChannel = channel; - - if (speed != 1.f) - setFrequency(channel, speed); + channel->setFrequency(44100 * speed); return channel->setVolume(volume); } void AudioChannelControl::set(float frequency) { - if (audioChannel == nullptr) - return; - speed = frequency; - setFrequency(audioChannel, frequency); + + FMOD::Channel* audioChannel; + + for(int i = 0; i < 2; i++) + { + FMODAudioEngine::sharedEngine()->m_system->getChannel(126 + i, &audioChannel); + if(audioChannel) + audioChannel->setFrequency(44100 * frequency); + } } void AudioChannelControl::setPitch(float pitch) { auto system = FMODAudioEngine::sharedEngine()->m_system; + FMOD::ChannelGroup* group; + system->getMasterChannelGroup(&group); - if (!audioChannel || !system) - return; - - static FMOD::DSP* pitchShifter; + static FMOD::DSP* pitchShifter = nullptr; if (pitchShifter) { - audioChannel->removeDSP(pitchShifter); + group->removeDSP(pitchShifter); pitchShifter->release(); pitchShifter = nullptr; } - + if (pitch == 1.f) return; - + system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &pitchShifter); - pitchShifter->setParameterFloat(FMOD_DSP_PITCHSHIFT_FFTSIZE, 4096); pitchShifter->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, pitch); - - audioChannel->addDSP(0, pitchShifter); + group->addDSP(0, pitchShifter); } class $modify(PlayLayer) @@ -68,8 +67,6 @@ class $modify(PlayLayer) $execute { - AudioChannelControl::setFrequency = reinterpret_cast(GetProcAddress( - reinterpret_cast(util::fmod_base), "?setPitch@ChannelControl@FMOD@@QAG?AW4FMOD_RESULT@@M@Z")); void* setVolumeAddress = reinterpret_cast(GetProcAddress( reinterpret_cast(util::fmod_base), "?setVolume@ChannelControl@FMOD@@QAG?AW4FMOD_RESULT@@M@Z")); diff --git a/src/Hacks/AudioChannelControl.h b/src/Hacks/AudioChannelControl.h index 13398ea..4d01e8b 100644 --- a/src/Hacks/AudioChannelControl.h +++ b/src/Hacks/AudioChannelControl.h @@ -5,11 +5,9 @@ namespace AudioChannelControl { - static FMOD::Channel* audioChannel; - static float speed = 1.f; + inline float speed = 1.f; FMOD_RESULT setVolumeHook(FMOD::Channel*, float); - inline void* (__stdcall* setFrequency)(FMOD::Channel*, float); void set(float); void setPitch(float); diff --git a/src/Macrobot/Macrobot.cpp b/src/Macrobot/Macrobot.cpp index 6c1a1fe..b306456 100644 --- a/src/Macrobot/Macrobot.cpp +++ b/src/Macrobot/Macrobot.cpp @@ -39,7 +39,7 @@ class $modify(CCKeyboardDispatcher){ class $modify(PlayLayer){ void loadFromCheckpoint(CheckpointObject * checkpoint) { - if (playerMode != -1 && playerObject1) + if (checkpoints.contains(checkpoint) && playerMode != -1 && playerObject1) { CheckpointData checkpointData = checkpoints[checkpoint]; const auto check = [&](const Action &action) -> bool { return action.time >= checkpointData.time; }; @@ -175,8 +175,6 @@ void Macrobot::GJBaseGameLayerProcessCommands(GJBaseGameLayer *self) double currentTime = *((double *)GameManager::get()->getPlayLayer() + 1412); gameTime = currentTime; - int correctionType = Mod::get()->getSavedValue("macrobot/corrections", 0); - if (playerMode == 0 && macro.inputs.size() > 0 && actionIndex < macro.inputs.size() && gameTime >= macro.inputs[actionIndex].time) { @@ -187,6 +185,9 @@ void Macrobot::GJBaseGameLayerProcessCommands(GJBaseGameLayer *self) GameManager::get()->getPlayLayer()->handleButton(true, ac.button, !ac.player2); else GameManager::get()->getPlayLayer()->handleButton(false, ac.button, !ac.player2); + + int correctionType = Mod::get()->getSavedValue("macrobot/corrections", 0); + if (correctionType > 0 && ac.correction.has_value()) { Correction &co = ac.correction.value(); diff --git a/src/main.cpp b/src/main.cpp index 8f9ffb8..5f4d9cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,6 @@ void init() Common::calculateFramerate(); Common::setPriority(); Common::onAudioSpeedChange(); - Common::onAudioPitchChange(); Common::loadIcons(); Clickpacks::init(); SafeMode::updateState();