Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/replay_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<CCLabelBMFont*>(play_layer->getChildByTag(10032));
auto label = cast<CCLabelBMFont*>(play_layer->getChildByTag(STATUS_LABEL_TAG));
if (!label)
label = _create_status_label(play_layer);
switch (state) {
Expand Down
2 changes: 2 additions & 0 deletions src/replay_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
17 changes: 17 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@ inline void patch(void* loc, std::vector<std::uint8_t> 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