diff --git a/src/replay_system.cpp b/src/replay_system.cpp index baa1a6b..2d088eb 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() { @@ -120,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) { 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