From 5355eb9b049aba0851e2e23911004dba63dab489 Mon Sep 17 00:00:00 2001 From: cafeed28 Date: Wed, 28 Jul 2021 12:53:44 +0500 Subject: [PATCH 1/2] added click sounds --- src/replay_system.cpp | 27 +++++++++++++++++++++++++++ src/replay_system.hpp | 2 ++ src/utils.hpp | 17 +++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/replay_system.cpp b/src/replay_system.cpp index baa1a6b..0de08da 100644 --- a/src/replay_system.cpp +++ b/src/replay_system.cpp @@ -23,6 +23,33 @@ void ReplaySystem::play_action(const Action& action) { auto flip = gm->getGameVariable("0010"); auto func = action.hold ? Hooks::PlayLayer::pushButton : Hooks::PlayLayer::releaseButton; func(gm->getPlayLayer(), 0, !action.player2 ^ flip); + ReplaySystem::play_sound(action.hold); +} + +// Sounds must be in "Geometry Dash directory/clicks/" +// "down" - mouse down sounds +// "up" - mouse up sounds +void ReplaySystem::play_sound(bool hold) { + std::string path = std::filesystem::current_path().string() + "/clicks/"; + if (hold) + path += "down/"; + else + path += "up/"; + + srand(time(0)); + + int files = dir_files_count(path); + if (files == 0) { + return; + } + + int random = rand() % files; + + path += std::to_string(random) + ".ogg"; + + if (std::filesystem::is_regular_file(path)) { + gd::GameSoundManager::sharedState()->playSound(path); + } } unsigned ReplaySystem::get_frame() { diff --git a/src/replay_system.hpp b/src/replay_system.hpp index 461fe19..c715188 100644 --- a/src/replay_system.hpp +++ b/src/replay_system.hpp @@ -65,6 +65,8 @@ class ReplaySystem { void record_action(bool hold, bool player1, bool flip = true); void play_action(const Action& action); + + void play_sound(bool hold); void on_reset(); diff --git a/src/utils.hpp b/src/utils.hpp index 9d6c091..f3f8df9 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -22,4 +22,21 @@ inline void patch(void* loc, std::vector bytes) { VirtualProtect(loc, size, old_prot, &old_prot); } +inline int dir_files_count(std::filesystem::path path) { + if (std::filesystem::is_directory(path)) { + auto iter = std::filesystem::directory_iterator(path); + int count = 0; + + for (auto& entry : iter) { + if (entry.is_regular_file()) { + ++count; + } + } + + return count; + } + + return 0; +} + #endif \ No newline at end of file From 28d802b694335005ec3a4b70f5a2aa13abbb2594 Mon Sep 17 00:00:00 2001 From: cafeed28 Date: Wed, 28 Jul 2021 14:09:44 +0500 Subject: [PATCH 2/2] why you dont use STATUS_LABEL_TAG? --- src/replay_system.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/replay_system.cpp b/src/replay_system.cpp index 0de08da..2d088eb 100644 --- a/src/replay_system.cpp +++ b/src/replay_system.cpp @@ -147,7 +147,7 @@ auto _create_status_label(CCLayer* layer) { void ReplaySystem::_update_status_label() { auto play_layer = gd::GameManager::sharedState()->getPlayLayer(); if (play_layer) { - auto label = cast(play_layer->getChildByTag(10032)); + auto label = cast(play_layer->getChildByTag(STATUS_LABEL_TAG)); if (!label) label = _create_status_label(play_layer); switch (state) {