Skip to content

Commit

Permalink
Fix music on cancel + close button for popup
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5abe committed Aug 7, 2024
1 parent 00a134c commit fc286c1
Show file tree
Hide file tree
Showing 21 changed files with 241 additions and 51 deletions.
1 change: 1 addition & 0 deletions docs/PSF.hexpat
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ struct PSF {
CheckpointGameObjectPtr activatedCheckpoints[activatedCheckpointCount];
unordered_map<s32,s32> m_persistentItemCountMap;
unordered_set<s32> m_persistentTimerItemSet;
s32 m_attempts;
};

PSF file @ 0x0;
Binary file modified resources/saveButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/hooks/EditLevelLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "EditLevelLayer.hpp"
#include "hooks/FMODAudioEngine.hpp"

using namespace geode::prelude;
using namespace persistenceAPI;

unsigned long long s_editLevelLayerDelegate1 = 0;
unsigned long long s_editLevelLayerDelegate2 = 0;

// overrides

void PSEditLevelLayer::onPlay(cocos2d::CCObject* i_sender) {
// stupid way of not letting it unregister the keyboard delegates
s_editLevelLayerDelegate1 = reinterpret_cast<unsigned long long>(&m_bTouchEnabled)-3*sizeof(void*);
s_editLevelLayerDelegate2 = reinterpret_cast<unsigned long long>(&m_bTouchEnabled)-2*sizeof(void*);

PSFMODAudioEngine* l_audioEngine = static_cast<PSFMODAudioEngine*>(FMODAudioEngine::get());
l_audioEngine->m_fields->m_disableLoadMusic = true;
l_audioEngine->backupMusic();

EditLevelLayer::onPlay(i_sender);

l_audioEngine->restoreMusic();
// m_disableLoadMusic gets set to false before running PlayLayer::setupHasCompleted

s_editLevelLayerDelegate1 = 0;
s_editLevelLayerDelegate2 = 0;
}
15 changes: 15 additions & 0 deletions src/hooks/EditLevelLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <Geode/Geode.hpp>
#include <Geode/modify/EditLevelLayer.hpp>
#include <sabe.persistenceapi/include/PersistenceAPI.hpp>

extern unsigned long long s_editLevelLayerDelegate1;
extern unsigned long long s_editLevelLayerDelegate2;

class $modify(PSEditLevelLayer, EditLevelLayer) {
public:
// overrides

$override
void onPlay(cocos2d::CCObject* i_sender);
};
1 change: 1 addition & 0 deletions src/hooks/EndLevelLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class $modify(PSEndLevelLayer, EndLevelLayer) {
public:
// overrides

$override
void onMenu(cocos2d::CCObject* i_sender);
};
57 changes: 57 additions & 0 deletions src/hooks/FMODAudioEngine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "FMODAudioEngine.hpp"
#include "Geode/binding/FMODAudioEngine.hpp"

using namespace geode::prelude;
using namespace persistenceAPI;

unsigned long long s_FMODAudioEngineDelegate1 = 0;
unsigned long long s_FMODAudioEngineDelegate2 = 0;

// overrides

void PSFMODAudioEngine::fadeOutMusic(float i_time, int i_channel) {
if (m_fields->m_disableFadeOutMusic) {
return;
}
FMODAudioEngine::fadeOutMusic(i_time, i_channel);
}

void PSFMODAudioEngine::loadMusic(gd::string i_path, float i_speed, float i_p2, float i_volume, bool i_shouldLoop, int i_p5, int i_p6) {
if (m_fields->m_disableLoadMusic) {
return;
}
FMODAudioEngine::loadMusic(i_path, i_speed, i_p2, i_volume, i_shouldLoop, i_p5, i_p6);
}

// custom methods

void PSFMODAudioEngine::backupMusic() {
m_fields->m_backgroundMusicChannelBackup = m_backgroundMusicChannel;
m_backgroundMusicChannel = nullptr;
for (int i = 0; i < m_audioState.m_unkMapIntFloat7.size(); i++) {
m_fields->m_unkMapIntFloat7Backup[i] = m_audioState.m_unkMapIntFloat7[i];
}
for (int i = 0; i < m_audioState.m_unkMapIntFloat8.size(); i++) {
m_fields->m_unkMapIntFloat8Backup[i] = m_audioState.m_unkMapIntFloat8[i];
}
for (int i = 0; i < m_audioState.m_unkMapIntFloat9.size(); i++) {
m_fields->m_unkMapIntFloat9Backup[i] = m_audioState.m_unkMapIntFloat9[i];
}
}

void PSFMODAudioEngine::restoreMusic() {
m_backgroundMusicChannel = m_fields->m_backgroundMusicChannelBackup;
m_fields->m_backgroundMusicChannelBackup = nullptr;
for (int i = 0; i < m_fields->m_unkMapIntFloat7Backup.size(); i++) {
m_audioState.m_unkMapIntFloat7[i] = m_fields->m_unkMapIntFloat7Backup[i];
}
for (int i = 0; i < m_fields->m_unkMapIntFloat8Backup.size(); i++) {
m_audioState.m_unkMapIntFloat8[i] = m_fields->m_unkMapIntFloat8Backup[i];
}
for (int i = 0; i < m_fields->m_unkMapIntFloat9Backup.size(); i++) {
m_audioState.m_unkMapIntFloat9[i] = m_fields->m_unkMapIntFloat9Backup[i];
}
m_fields->m_unkMapIntFloat7Backup.clear();
m_fields->m_unkMapIntFloat8Backup.clear();
m_fields->m_unkMapIntFloat9Backup.clear();
}
31 changes: 31 additions & 0 deletions src/hooks/FMODAudioEngine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include "Geode/modify/Modify.hpp"
#include <Geode/Geode.hpp>
#include <Geode/modify/FMODAudioEngine.hpp>
#include <sabe.persistenceapi/include/PersistenceAPI.hpp>

class $modify(PSFMODAudioEngine, FMODAudioEngine) {
public:
struct Fields {
bool m_disableFadeOutMusic;
bool m_disableLoadMusic;
FMOD::Channel* m_backgroundMusicChannelBackup;
gd::unordered_map<int,float> m_unkMapIntFloat7Backup;
gd::unordered_map<int,float> m_unkMapIntFloat8Backup;
gd::unordered_map<int,float> m_unkMapIntFloat9Backup;
};

// overrides

$override
void fadeOutMusic(float i_time, int i_channel);

$override
void loadMusic(gd::string i_path, float i_speed, float i_p2, float i_volume, bool i_shouldLoop, int i_p5, int i_p6);

// custom methods

void backupMusic();

void restoreMusic();
};
18 changes: 18 additions & 0 deletions src/hooks/LevelAreaInnerLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "LevelAreaInnerLayer.hpp"
#include "hooks/FMODAudioEngine.hpp"

using namespace geode::prelude;
using namespace persistenceAPI;

// overrides

void PSLevelAreaInnerLayer::onDoor(cocos2d::CCObject* i_sender) {
PSFMODAudioEngine* l_audioEngine = static_cast<PSFMODAudioEngine*>(FMODAudioEngine::get());
l_audioEngine->m_fields->m_disableFadeOutMusic = true;
l_audioEngine->m_fields->m_disableLoadMusic = true;

LevelAreaInnerLayer::onDoor(i_sender);

l_audioEngine->m_fields->m_disableFadeOutMusic = false;
// m_disableLoadMusic gets set to false before running PlayLayer::setupHasCompleted or when cancelling level load
}
12 changes: 12 additions & 0 deletions src/hooks/LevelAreaInnerLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <Geode/Geode.hpp>
#include <Geode/modify/LevelAreaInnerLayer.hpp>
#include <sabe.persistenceapi/include/PersistenceAPI.hpp>

class $modify(PSLevelAreaInnerLayer, LevelAreaInnerLayer) {
public:
// overrides

$override
void onDoor(cocos2d::CCObject* i_sender);
};
8 changes: 8 additions & 0 deletions src/hooks/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "LevelInfoLayer.hpp"
#include "hooks/FMODAudioEngine.hpp"

using namespace geode::prelude;
using namespace persistenceAPI;
Expand All @@ -13,8 +14,15 @@ void PSLevelInfoLayer::onPlay(cocos2d::CCObject* i_sender) {
s_levelInfoLayerDelegate1 = reinterpret_cast<unsigned long long>(&m_bTouchEnabled)-3*sizeof(void*);
s_levelInfoLayerDelegate2 = reinterpret_cast<unsigned long long>(&m_bTouchEnabled)-2*sizeof(void*);

PSFMODAudioEngine* l_audioEngine = static_cast<PSFMODAudioEngine*>(FMODAudioEngine::get());
l_audioEngine->m_fields->m_disableLoadMusic = true;
l_audioEngine->backupMusic();

LevelInfoLayer::onPlay(i_sender);

l_audioEngine->restoreMusic();
// m_disableLoadMusic gets set to false before running PlayLayer::setupHasCompleted

s_levelInfoLayerDelegate1 = 0;
s_levelInfoLayerDelegate2 = 0;
}
6 changes: 1 addition & 5 deletions src/hooks/LevelInfoLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ extern unsigned long long s_levelInfoLayerDelegate2;

class $modify(PSLevelInfoLayer, LevelInfoLayer) {
public:
struct Fields {
unsigned long long m_keyboardDelegate1;
unsigned long long m_keyboardDelegate2;
};

// overrides

$override
void onPlay(cocos2d::CCObject* i_sender);
};
4 changes: 2 additions & 2 deletions src/hooks/PauseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ void PSPauseLayer::customSetup() {
PauseLayer::customSetup();

PSPlayLayer* l_playLayer = static_cast<PSPlayLayer*>(PlayLayer::get());
if (l_playLayer && l_playLayer->savesEnabled() && l_playLayer->m_isPlatformer) {
if (l_playLayer && l_playLayer->savesEnabled() && l_playLayer->m_isPlatformer && !Mod::get()->getSettingValue<bool>("auto-save")) {
CCMenu* l_leftButtonMenu = static_cast<CCMenu*>(getChildByID("left-button-menu"));
if (l_leftButtonMenu) {
m_fields->m_saveCheckpointsSprite = CircleButtonSprite::createWithSprite("saveButton.png"_spr, 1.6, CircleBaseColor::Green, CircleBaseSize::Medium);
m_fields->m_saveCheckpointsSprite = CircleButtonSprite::createWithSprite("saveButton.png"_spr, 1.5, CircleBaseColor::Green, CircleBaseSize::Medium);
m_fields->m_saveCheckpointsSprite->setScale(0.66);
CCSize l_contentSize = m_fields->m_saveCheckpointsSprite->getContentSize();
m_fields->m_saveCheckpointsSprite->setContentSize({l_contentSize.width, 49});
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Geode/binding/PlayLayer.hpp"
#include "domain/CheckpointGameObjectReference.hpp"
#include "hooks/PauseLayer.hpp"
#include "hooks/FMODAudioEngine.hpp"
#include <geode.custom-keybinds/include/Keybinds.hpp>
#include <util/algorithm.hpp>
#include <util/filesystem.hpp>
Expand Down Expand Up @@ -74,25 +75,25 @@ void PSPlayLayer::setupHasCompleted() {
//log::info("[setupHasCompleted] hasnt finished loading checkpoints");

loadGame();

//m_fields->m_loadingProgress += (m_fields->m_loadingProgress/8.0f);

//log::info("[setupHasCompleted] m_bytesRead: {}", m_fields->m_bytesRead);
//log::info("[setupHasCompleted] m_bytesToRead: {}", m_fields->m_bytesToRead);
if (m_fields->m_bytesToRead > 0) {
m_fields->m_loadingProgress = (static_cast<float>(m_fields->m_bytesRead)/static_cast<float>(m_fields->m_bytesToRead));
}
// if (m_fields->m_loadingProgress != 1.0f) {

m_loadingProgress = m_fields->m_loadingProgress;
// } else {
// m_loadingProgress = 0.99f;
// }
//log::info("[setupHasCompleted] m_loadingProgress: {}", m_loadingProgress);
}
if (m_fields->m_loadingState == LoadingState::Ready && !m_fields->m_cancelLevelLoad) {
m_loadingProgress = 1.0f;

// now reset the order of arrival that we're actually going into the level
CCNode::resetGlobalOrderOfArrival();

// restore loadMusic
PSFMODAudioEngine* l_audioEngine = static_cast<PSFMODAudioEngine*>(FMODAudioEngine::get());
l_audioEngine->m_fields->m_disableLoadMusic = false;

m_fields->m_inSetupHasCompleted = true;
PlayLayer::setupHasCompleted();
Expand Down Expand Up @@ -129,7 +130,7 @@ void PSPlayLayer::postUpdate(float i_unkFloat) {
CheckpointObject* PSPlayLayer::markCheckpoint() {
PSCheckpointObject* l_checkpointObject = static_cast<PSCheckpointObject*>(PlayLayer::markCheckpoint());

if (savesEnabled() && m_fields->m_inPostUpdate && !m_isPracticeMode) {
if (l_checkpointObject && savesEnabled() && m_fields->m_inPostUpdate && !m_isPracticeMode) {
if (m_fields->m_triedPlacingCheckpoint) {
m_fields->m_triedPlacingCheckpoint = false;
} else if (m_activatedCheckpoint != nullptr) {
Expand Down Expand Up @@ -254,7 +255,6 @@ void PSPlayLayer::setupSavingProgressCircleSprite() {

m_fields->m_savingProgressCircleSprite->runAction(CCRepeatForever::create(CCRotateBy::create(1.0f, 360.f)));
m_fields->m_savingProgressCircleSprite->pauseSchedulerAndActions();
//m_fields->m_savingProgressCircleSprite->setVisible(false);
}

void PSPlayLayer::showSavingProgressCircleSprite(bool i_show) {
Expand Down
Loading

0 comments on commit fc286c1

Please sign in to comment.