@@ -9,50 +9,34 @@ const static std::regex geometryDashRegex = std::regex(R"(^.*(?:(?:Geometry ?Das
99const static std::regex terribleLoopRegex = std::regex(R"( ^[\w]+\.mp3$)" );
1010
1111class $modify(MenuLoopFMODHook, FMODAudioEngine) {
12- void playMusic (gd::string path, bool shouldLoop, float fadeInTime, int channel) {
13- SongManager& songManager = SongManager::get ();
14- const bool isLavaChicken = geode::utils::string::contains (static_cast <std::string>(path), " sawblade.steves_lava_chicken" );
15- songManager.setLavaChicken (isLavaChicken);
16- if (isLavaChicken) {
17- songManager.setCurrentSong (static_cast <std::string>(path));
12+ void update (float dt) {
13+ FMODAudioEngine::update (dt);
14+ if (!SongManager::get ().getConstantShuffleMode ()) return ;
15+ if (VANILLA_GD_MENU_LOOP_DISABLED) return ;
16+ if (GJBaseGameLayer::get () || SongManager::get ().isOriginalMenuLoop () || SongManager::get ().getSongsSize () < 2 ) return ;
17+ constexpr int channelNumber = 0 ;
18+ FMOD::Channel* menuLoopChannelProbably = FMODAudioEngine::get ()->getActiveMusicChannel (0 );
19+ const bool isSongManagerSong = FMODAudioEngine::get ()->getActiveMusic (channelNumber) == SongManager::get ().getCurrentSong ();
20+ log::info (" isSongManagerSong: {}" , isSongManagerSong);
21+ // unsigned int position = 0;
22+ bool isPlaying = true ;
23+ unsigned int position = 0 ;
24+ FMOD::Sound* sound;
25+ unsigned int length = 0 ;
26+ menuLoopChannelProbably->isPlaying (&isPlaying);
27+ menuLoopChannelProbably->getPosition (&position, 1 );
28+ menuLoopChannelProbably->getCurrentSound (&sound);
29+ sound->getLength (&length, 1 );
30+ log::info (" position: {}" , position);
31+ log::info (" isPlaying: {}" , isPlaying);
32+ log::info (" length - 50: {}" , length - 50 );
33+ log::info (" (length - 50) < position: {}" , (length - 50 ) < position);
34+ log::info (" ===========================" );
35+ if ((length - 50 ) < position) {
36+ geode::log::info (" song is probably finished. Switching songs." );
37+ Utils::removeCard ();
38+ Utils::constantShuffleModeNewSong ();
1839 Utils::newCardAndDisplayNameFromCurrentSong ();
1940 }
20- if (!Utils::getBool (" playlistMode" ) || isLavaChicken)
21- return FMODAudioEngine::get ()->playMusic (path, shouldLoop, fadeInTime, channel);
22- log::info (" Constant Shuffle Mode enabled.\n === Constant Shuffle Mode DEBUG INFO ===\n path: {}\n shouldLoop: {}\n fadeInTime: {}\n channel: {}" , path, shouldLoop, fadeInTime, channel);
23- if (CCScene* scene = CCScene::get (); Utils::getBool (" advancedLogs" ) && scene && scene->getChildren ()) {
24- for (CCObject* object : CCArrayExt<CCObject*>(scene->getChildren ())) {
25- const auto node = typeinfo_cast<CCNode*>(object);
26- if (node) log::info (" there is a CCNode with ID: \" {}\" " , node->getID ());
27- }
28- }
29- bool desiredShouldLoop = shouldLoop;
30- std::string gdStringSucks = path;
31- std::smatch smatch;
32- if (std::regex_match (gdStringSucks, smatch, terribleLoopRegex)) return log::info (" terrible loop detected while Constant Shuffle Mode is active: {}" , gdStringSucks);
33- const bool isMenuLoop = std::regex_match (gdStringSucks, smatch, geometryDashRegex);
34- if (GJBaseGameLayer::get () && !isMenuLoop) return FMODAudioEngine::get ()->playMusic (path, desiredShouldLoop, fadeInTime, channel);
35- if (fadeInTime == 0 && gdStringSucks == " shop.mp3" ) return ;
36- if (shouldLoop && fadeInTime == 1 .0f ) {
37- if (!isMenuLoop && !utils::string::contains (gdStringSucks, " /Library/Caches/" )) {
38- log::info (" non-menu loop found while constant shuffle mode is enabled: {}" , gdStringSucks);
39- return FMODAudioEngine::get ()->playMusic (path, desiredShouldLoop, fadeInTime, channel);
40- }
41- /*
42- if and ONLY if the song being is determined to be:
43- - not the original menuLoop.mp3
44- - is from Newgrounds, the Music Library, or config directory
45- then set loop to false for songmanager function to work properly
46- */
47- log::info (" menu loop detected." );
48- desiredShouldLoop = false ;
49- // T0D0: maybe ifdef these few lines. it works on macos intel
50- if (channel == 0 ) return log::info (" attempted to loop menu music on channel zero! see if on windows or not. aborting early." );
51- #ifdef GEODE_IS_WINDOWS
52- if (!songManager.getCalledOnce ()) songManager.setCalledOnce (true );
53- #endif
54- return FMODAudioEngine::get ()->playMusic (path, desiredShouldLoop, 0 .0f , channel);
55- }
56- FMODAudioEngine::get ()->playMusic (path, desiredShouldLoop, fadeInTime, channel);
5741 }
5842};
0 commit comments