@@ -49,8 +49,6 @@ void error(const char* str) {
4949}
5050
5151void debug (const char * str) {
52- OutputDebugString (str);
53- fprintf (stderr, " %s\n " , str);
5452 spdlog::debug (str);
5553}
5654}
@@ -956,6 +954,18 @@ void ScriptRunner::hook_battle_rule() {
956954}
957955
958956void ScriptRunner::on_frame () {
957+ if (!m_console_startup_checked) {
958+ // Delay because C# API hides it
959+ if (m_console_startup_delay_frames > 0 ) {
960+ m_console_startup_delay_frames--;
961+ } else {
962+ m_console_startup_checked = true ;
963+
964+ if (m_open_debug_console_at_startup->value ()) {
965+ g_framework->open_console ();
966+ }
967+ }
968+ }
959969 if (!m_scene_okay) try {
960970 if (!m_checked_scene_once) {
961971 m_checked_scene_once = true ;
@@ -1088,15 +1098,13 @@ void ScriptRunner::on_draw_ui() {
10881098 ImGui::SameLine ();
10891099
10901100 if (ImGui::Button (" Spawn Debug Console" )) {
1091- if (!m_console_spawned) {
1092- AllocConsole ();
1093- freopen (" CONIN$" , " r" , stdin);
1094- freopen (" CONOUT$" , " w" , stdout);
1095- freopen (" CONOUT$" , " w" , stderr);
1101+ g_framework->open_console ();
1102+ }
10961103
1097- m_console_spawned = true ;
1098- }
1104+ if (m_open_debug_console_at_startup-> draw ( " Open Debug Console at Startup " )) {
1105+ g_framework-> request_save_config ();
10991106 }
1107+
11001108 // Garbage collection currently only showing from main lua state, might rework to show total later?
11011109 if (ImGui::TreeNode (" Garbage Collection Stats" )) {
11021110 std::scoped_lock _{ m_access_mutex };
@@ -1284,11 +1292,7 @@ void ScriptRunner::on_gui_draw_element(REComponent* gui_element, void* primitive
12841292}
12851293
12861294void ScriptRunner::spew_error (const std::string& p) {
1287- OutputDebugString (p.c_str ());
1288-
1289- if (m_console_spawned) {
1290- fprintf (stderr, " %s\n " , p.c_str ());
1291- }
1295+ fprintf (stderr, " %s\n " , p.c_str ());
12921296
12931297 if (m_log_to_disk->value ()) {
12941298 spdlog::error (p);
0 commit comments