diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 4af157cde..1fee14166 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -154,6 +154,7 @@ void Config::ReadValues() { // Scripted Input Settings::values.script_name = sdl2_config->Get("ScriptedInput", "script_name", ""); + Settings::values.close_at_end = sdl2_config->GetBoolean("ScriptedInput", "close_at_end", false); // Web Service Settings::values.telemetry_endpoint_url = sdl2_config->Get( diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index e9a75d86f..d63a9d109 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -172,6 +172,9 @@ gdbstub_port=24689 [ScriptedInput] # Script file to load for simulated input script_name= +# Whether to close the emulator when the script has finished +# 0 (default): Don't Close, 1: Close +close_at_end= [WebService] # Endpoint URL for submitting telemetry data diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 558969851..b2b1e1fed 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -36,7 +36,7 @@ void Apply() { Service::HID::ReloadInputDevices(); Service::IR::ReloadInputDevices(); - ScriptedInput::LoadScript(values.script_name); + ScriptedInput::LoadScript(values.script_name, values.close_at_end); } } // namespace diff --git a/src/core/settings.h b/src/core/settings.h index 678ac0792..2e0013437 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -129,6 +129,7 @@ struct Values { // ScriptedInput std::string script_name; + bool close_at_end; // WebService std::string telemetry_endpoint_url; diff --git a/src/scripted_input/CMakeLists.txt b/src/scripted_input/CMakeLists.txt index b5526a605..5c4e304a2 100644 --- a/src/scripted_input/CMakeLists.txt +++ b/src/scripted_input/CMakeLists.txt @@ -14,4 +14,4 @@ create_directory_groups(${SRCS} ${HEADERS}) add_library(scripted_input STATIC ${SRCS} ${HEADERS}) target_link_libraries(scripted_input PUBLIC common core) -target_link_libraries(scripted_input PRIVATE glad) \ No newline at end of file +target_link_libraries(scripted_input PRIVATE glad SDL2) \ No newline at end of file diff --git a/src/scripted_input/script_runner.cpp b/src/scripted_input/script_runner.cpp index eeb0152e9..8781c9614 100644 --- a/src/scripted_input/script_runner.cpp +++ b/src/scripted_input/script_runner.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include "common/logging/log.h" @@ -16,7 +17,9 @@ void ScriptRunner::SetButtons(std::shared_ptr buttons) { scripted_buttons = buttons; } -void ScriptRunner::LoadScript(std::string script_name) { +void ScriptRunner::LoadScript(std::string script_name, bool close) { + close_at_end = close; + FILE* file = fopen(script_name.c_str(), "r"); if (!file) { LOG_ERROR(ScriptedInput, "script_file %s does not exist", script_name.c_str()); @@ -108,6 +111,11 @@ void ScriptRunner::NotifyFrameFinished() { if (script_index >= script.size()) { LOG_INFO(ScriptedInput, "Scripted Input finished at frame %i", frame_number); + if (close_at_end) { + SDL_Event sdlevent; + sdlevent.type = SDL_QUIT; + SDL_PushEvent(&sdlevent); + } } } diff --git a/src/scripted_input/script_runner.h b/src/scripted_input/script_runner.h index e7a4d49c4..f1c5ab75b 100644 --- a/src/scripted_input/script_runner.h +++ b/src/scripted_input/script_runner.h @@ -27,7 +27,7 @@ public: class ScriptRunner final { public: void SetButtons(std::shared_ptr buttons); - void LoadScript(std::string script_name); + void LoadScript(std::string script_name, bool close_at_end); bool HasScript() const; void NotifyFrameFinished(); @@ -39,6 +39,7 @@ private: int script_frame{0}; std::shared_ptr scripted_buttons; + bool close_at_end; void SaveScreenshot(); }; diff --git a/src/scripted_input/scripted_input.cpp b/src/scripted_input/scripted_input.cpp index 4a58f0aa6..4aac34bad 100644 --- a/src/scripted_input/scripted_input.cpp +++ b/src/scripted_input/scripted_input.cpp @@ -19,9 +19,9 @@ void Init() { script_runner.SetButtons(scripted_buttons); } -void LoadScript(std::string script_name) { +void LoadScript(std::string script_name, bool close_at_end) { if (script_name.length() > 0) { - script_runner.LoadScript(script_name); + script_runner.LoadScript(script_name, close_at_end); ScriptedButtons::OverrideControlsSettings(); } diff --git a/src/scripted_input/scripted_input.h b/src/scripted_input/scripted_input.h index 0a10460c4..0100bbe0b 100644 --- a/src/scripted_input/scripted_input.h +++ b/src/scripted_input/scripted_input.h @@ -11,7 +11,7 @@ namespace ScriptedInput { /// Initializes and registers the input device factories. void Init(); -void LoadScript(std::string script_name); +void LoadScript(std::string script_name, bool close_at_end); /// Deregisters the input device factories and shuts them down. void Shutdown();