Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
fix crash and fix some filesystem stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnut committed Feb 1, 2024
1 parent 5cd728e commit 66c4079
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
13 changes: 13 additions & 0 deletions src/Hacks/Labels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <Geode/modify/PlayLayer.hpp>
#include <Geode/modify/PlayerObject.hpp>
#include <Geode/modify/LevelEditorLayer.hpp>

#include <Geode/Geode.hpp>

Expand Down Expand Up @@ -190,8 +191,20 @@ class $modify(PlayLayer)
}
};

class $modify(LevelEditorLayer)
{
bool init(GJGameLevel* level, bool unk)
{
labels.clear();

return LevelEditorLayer::init(level, unk);
}
};

void Labels::GJBaseGameLayerProcessCommands(GJBaseGameLayer *self)
{
if (!GameManager::sharedState()->getPlayLayer()) return;

if (labelsCreated)
{
for (Label& l : labels)
Expand Down
5 changes: 4 additions & 1 deletion src/Hacks/Speedhack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ class $modify(CCScheduler)

if (Record::recorder.m_recording)
{
float framerate;
float framerate = 60.f;

if (Settings::get<bool>("general/fps/enabled"))
framerate = Settings::get<float>("general/fps/value", 60.f);
else
framerate = GameManager::get()->m_customFPSTarget;

if(framerate < 1)
framerate = 1;

dt = 1.0f / (framerate * speedhack);
dt *= speedhack;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Macrobot/Macrobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ void Macrobot::save(const std::string& file)
return;
}

if(file == "")
{
FLAlertLayer::create("Error", "Macro name is empty!", "Ok")->show();
return;
}

std::ofstream f(Mod::get()->getSaveDir() / "macros" / (file + ".gdr"), std::ios::binary);

if(!f)
Expand Down
34 changes: 17 additions & 17 deletions src/Macrobot/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,26 @@ void Recorder::start()

GameManager::get()->getPlayLayer()->resetLevel();

std::string level_id = std::to_string(GameManager::get()->getPlayLayer()->m_level->m_levelID.value());
std::string level_id = GameManager::get()->getPlayLayer()->m_level->m_levelName.c_str() + ("_" + std::to_string(GameManager::get()->getPlayLayer()->m_level->m_levelID.value()));
auto bg_volume = 1;
auto sfx_volume = 1;

auto song_offset = m_song_start_offset;

if (!ghc::filesystem::is_directory(Mod::get()->getSaveDir().string() + "/renders/" + level_id) ||
!ghc::filesystem::exists(Mod::get()->getSaveDir().string() + "/renders/" + level_id))
if (!ghc::filesystem::is_directory(Mod::get()->getSaveDir() / "renders" / level_id) ||
!ghc::filesystem::exists(Mod::get()->getSaveDir() / "renders" / level_id))
{
ghc::filesystem::create_directory(Mod::get()->getSaveDir().string() + "/renders/" + level_id);
ghc::filesystem::create_directory(Mod::get()->getSaveDir() / "renders" / level_id);
}

if (m_recording_audio)
return;

std::thread([&, bg_volume, sfx_volume, song_offset, level_id]()
{
auto finalpath = (Mod::get()->getSaveDir().string() + "/renders/" + level_id + "/final.mp4");
auto notfinalpath = (Mod::get()->getSaveDir().string() + "/renders/" + level_id + "/rendered_video.mp4");
auto clickpath = (Mod::get()->getSaveDir().string() + "/renders/" + level_id + "/rendered_clicks.wav");
auto finalpath = (Mod::get()->getSaveDir() / "renders" / level_id / "final.mp4");
auto notfinalpath = (Mod::get()->getSaveDir() / "renders" / level_id / "rendered_video.mp4");
auto clickpath = (Mod::get()->getSaveDir() / "renders" / level_id / "rendered_clicks.wav");

{
std::stringstream stream;
Expand All @@ -170,7 +170,7 @@ void Recorder::start()
else
stream << "-pix_fmt yuv420p ";

stream << "-vf \"vflip\" -an \"" << notfinalpath << "\" "; // i hope just putting it in "" escapes it
stream << "-vf \"vflip\" -an " << notfinalpath; // i hope just putting it in "" escapes it
auto process = subprocess::Popen(stream.str());
while (m_recording || m_frame_has_data)
{
Expand Down Expand Up @@ -199,13 +199,13 @@ void Recorder::start()
if (!Settings::get<bool>("recorder/clicks/enabled", false))
return;

generate_clicks(clickpath);
generate_clicks(string::wideToUtf8(clickpath.wstring()));

{
float clickVolume = Settings::get<float>("clickpacks/click/volume", 1.f);
std::stringstream f;
f << '"' << m_ffmpeg_path << '"' << " -y -i " << '"' << notfinalpath << '"' << " -i " << '"' << clickpath
<< '"' << " -c:v copy -map 0:v -map 1:a " << '"' << finalpath << '"';
f << '"' << m_ffmpeg_path << '"' << " -y -i " << notfinalpath << " -i " << clickpath
<< " -c:v copy -map 0:v -map 1:a " << finalpath;
std::cout << f.str() << std::endl;
auto process = subprocess::Popen(f.str());
try
Expand Down Expand Up @@ -298,16 +298,16 @@ void Recorder::stop_audio()
->getPlayLayer()
->m_level; // MBO(gd::GJGameLevel*, GameManager::get()->getPlayLayer(), 1504); // found in playlayer_init

std::string level_id = std::to_string(level->m_levelID.value());
std::string level_id = GameManager::get()->getPlayLayer()->m_level->m_levelName.c_str() + ("_" + std::to_string(GameManager::get()->getPlayLayer()->m_level->m_levelID.value()));

std::string video_path = Mod::get()->getSaveDir().string() + "/renders/" + level_id + "/final.mp4";
ghc::filesystem::path video_path = Mod::get()->getSaveDir() / "renders" / level_id / "final.mp4";

bool clicks = ghc::filesystem::exists(video_path);

if (!clicks)
video_path = Mod::get()->getSaveDir().string() + "/renders/" + level_id + "/rendered_video.mp4";
video_path = Mod::get()->getSaveDir() / "renders" / level_id / "rendered_video.mp4";

std::string temp_path = Mod::get()->getSaveDir().string() + "/renders/" + level_id + "/music.mp4";
ghc::filesystem::path temp_path = Mod::get()->getSaveDir() / "renders" / level_id / "music.mp4";

std::stringstream ss;

Expand Down Expand Up @@ -337,8 +337,8 @@ void Recorder::stop_audio()

ghc::filesystem::remove("fmodoutput.wav");

ghc::filesystem::remove(widen(video_path));
ghc::filesystem::rename(temp_path, widen(video_path));
ghc::filesystem::remove(video_path);
ghc::filesystem::rename(temp_path,video_path);
}

void Recorder::handle_recording_audio(GJBaseGameLayer *play_layer, float dt)
Expand Down

0 comments on commit 66c4079

Please sign in to comment.