From 6127f1d25cdc1f13d92f8617a054a77a2d2b775d Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Tue, 18 Aug 2026 20:22:54 +0400 Subject: [PATCH] a --- CMakeLists.txt | 13 +- binding-mri/journal-binding.cpp | 175 +++++--------------- changelogs/0.1.2.txt | 1 + journal/SDL/CMakeLists.txt | 2 +- journal/SDL/debugwriter.h | 71 ++++++++ journal/SDL/main.c | 75 --------- journal/SDL/main.cpp | 279 ++++++++++++++++++++++++++++++++ scripts/Data_Settings.rb | 2 +- src/config.cpp | 4 +- src/config.h | 8 +- src/debugwriter.h | 16 +- src/modloader.cpp | 3 + 12 files changed, 416 insertions(+), 233 deletions(-) create mode 100644 journal/SDL/debugwriter.h delete mode 100644 journal/SDL/main.c create mode 100644 journal/SDL/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b8be065..ffd87ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -416,10 +416,11 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE VERSION_STRING="${VERSION_STR find_package(PkgConfig REQUIRED) find_package(ZLIB REQUIRED) -find_package(SDL3 CONFIG) -find_package(SDL3_image CONFIG) -find_package(SDL3_mixer CONFIG REQUIRED) -find_package(SDL3_ttf CONFIG) +find_package(SDL3 CONFIG REQUIRED) +find_package(SDL3_image CONFIG REQUIRED) +find_package(SDL3_mixer CONFIG REQUIRED REQUIRED) +find_package(SDL3_ttf CONFIG REQUIRED) +find_package(SDL3_net CONFIG REQUIRED) find_package(Boost REQUIRED COMPONENTS program_options chrono) find_package(PhysFS) find_path(PIXMAN_INCLUDE_DIR NAMES pixman.h PATH_SUFFIXES pixman-1) @@ -432,10 +433,10 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE ${DEFINES}) target_include_directories(${PROJECT_NAME} PRIVATE src include ${PIXMAN_INCLUDE_DIR} ${SIGC2_INCLUDE_DIRS} ${Ruby_INCLUDE_DIRS} Boost::boost ${Boost_INCLUDE_DIRS} -${ZLIB_INCLUDE_DIRS} SDL3_mixer::SDL3_mixer) +${ZLIB_INCLUDE_DIRS} SDL3_mixer::SDL3_mixer SDL3_net::SDL3_net) target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image -SDL3_mixer::SDL3_mixer SDL3_ttf::SDL3_ttf +SDL3_mixer::SDL3_mixer SDL3_ttf::SDL3_ttf SDL3_net::SDL3_net physfs ${PIXMAN_LIBRARY} ${SIGC2_LIBRARIES} ${PLATFORM_LIBRARIES} ${Ruby_LIBRARIES} Boost::boost Boost::chrono ${Boost_LIBRARIES} ZLIB::ZLIB ${PLATFORM_LIBS}) diff --git a/binding-mri/journal-binding.cpp b/binding-mri/journal-binding.cpp index ce91ace..b346cba 100644 --- a/binding-mri/journal-binding.cpp +++ b/binding-mri/journal-binding.cpp @@ -4,145 +4,48 @@ #include "debugwriter.h" #include "i18n.h" #include "define.h" - -//OS-Specific code -#if defined _WIN32 - #define OS_W32 -#elif unix_like - #define LINUX - #ifdef __APPLE__ - #define OS_OSX - #else - #define OS_LINUX - #endif - - #include - #include - #include - #ifdef __linux__ - #include - #endif - #include - #include - #include - #include -#endif - #include +#include +#include -#define BUFFER_SIZE 256 +void SendRaw(const char *address, int port, const char *raw){ + NET_Address *addr = NET_ResolveHostname(address); + if (!addr) { + Debug() << "Failed to resolve " << address << " : " << SDL_GetError(); + return; + } -static SDL_Thread *thread = NULL; -static SDL_Mutex *mutex = NULL; -static volatile char lang_buffer[BUFFER_SIZE]; -static volatile char message_buffer[BUFFER_SIZE]; -static volatile bool active = false; -static volatile int message_len = 0; + if (NET_WaitUntilResolved(addr, -1) == NET_FAILURE) { + Debug() << "NET_FAILURE " << address << " : " << SDL_GetError(); + return; + } -#ifdef unix_like - static std::string PIPE_PATH = std::string(getpwuid(getuid())->pw_dir) + "/.oneshot-pipe"; - static volatile int out_pipe = -1; - void cleanup_pipe(){ - unlink(PIPE_PATH.c_str()); - remove(PIPE_PATH.c_str()); - } -#endif + NET_StreamSocket *socket = NET_CreateClient(addr, port, 0); + if (!socket) { + Debug() << "Failed to create connection: " << SDL_GetError(); + return; + } -int server_thread(void *data){ - (void)data; -#if defined OS_W32 - HANDLE pipe = CreateNamedPipeW(L"\\\\.\\pipe\\oneshot-journal-to-game", - PIPE_ACCESS_OUTBOUND, - PIPE_TYPE_BYTE | PIPE_WAIT, - PIPE_UNLIMITED_INSTANCES, - BUFFER_SIZE, - BUFFER_SIZE, - 0, - NULL); - for (;;) { - ConnectNamedPipe(pipe, NULL); - SDL_LockMutex(mutex); - DWORD written; - WriteFile(pipe, (const void*)message_buffer, BUFFER_SIZE, &written, NULL); - active = true; - SDL_UnlockMutex(mutex); - FlushFileBuffers(pipe); - DisconnectNamedPipe(pipe); - } - CloseHandle(pipe); -#else - if (access(PIPE_PATH.c_str(), F_OK) != -1){ - out_pipe = open(PIPE_PATH.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - SDL_LockMutex(mutex); - active = true; - if (message_len > 0){ - if (write(out_pipe, (char*)message_buffer, message_len) == -1){ - #ifdef DEBUG - Debug() << "[journal-binding>server_thread()]Failure writing to journal's pipe!"; - #endif - } - } - SDL_UnlockMutex(mutex); - } - return 0; -#endif + if (NET_WaitUntilConnected(socket, -1) == NET_FAILURE) { + Debug() << "Failed to connect to " << address << ":" << port << " " << SDL_GetError(); + NET_DestroyStreamSocket(socket); + return; + } + + int length = (int)SDL_strlen(raw); + + if (!NET_WriteToStreamSocket(socket, raw, length)) { + Debug() << "Failed to send: " << SDL_GetError(); + } else if (NET_WaitUntilStreamSocketDrained(socket, -1) < 0) { + Debug() << "Error: " << SDL_GetError(); + } + NET_DestroyStreamSocket(socket); } RB_METHOD(journalSet){ RB_UNUSED_PARAM; const char *name; rb_get_args(argc, argv, "z", &name RB_ARG_END); - // Record message - SDL_LockMutex(mutex); - message_len = SDL_strlen(name); - strcpy((char*)message_buffer, name); - if (message_len > 0) { - // in the case where journal is being sent empty string - // do not append the language suffix, because empty string - // is the signifier to terminate the journal - strcpy((char*)message_buffer + message_len, (char*)lang_buffer); - message_len += SDL_strlen((char*)lang_buffer); - } - SDL_UnlockMutex(mutex); - -#if defined _WIN32 - HANDLE pipe = CreateFileW(L"\\\\.\\pipe\\oneshot-game-to-journal", - GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL); - if (pipe != INVALID_HANDLE_VALUE) { - active = true; - DWORD written; - WriteFile(pipe, (const void*)message_buffer, BUFFER_SIZE, &written, NULL); - FlushFileBuffers(pipe); - CloseHandle(pipe); - } - if (thread == NULL) { - thread = SDL_CreateThread(server_thread, "journal", NULL); - } -#else - // Clean up connection thread - if (thread != NULL && out_pipe != -1) { - SDL_WaitThread(thread, NULL); - thread = NULL; - } - // Attempt to send it over the tubes - if (out_pipe != -1) { - // We have a connection, so send it over - if (write(out_pipe, (char*)message_buffer, message_len) <= 0) { - // In the case of an error, close - close(out_pipe); - out_pipe = -1; - } - } - if (out_pipe == -1) { - // We don't have a pipe open, so spawn the connection thread - thread = SDL_CreateThread(server_thread, "journal", NULL); - } -#endif return Qnil; } @@ -150,25 +53,19 @@ RB_METHOD(journalSetLang){ RB_UNUSED_PARAM; const char *lang; rb_get_args(argc, argv, "z", &lang RB_ARG_END); - strcpy((char*)lang_buffer+1, lang); - loadLocale(lang); + printf(lang); return Qnil; } RB_METHOD(journalActive){ RB_UNUSED_PARAM; - return active ? Qtrue : Qfalse; + return Qfalse; } void journalBindingInit(){ - mutex = SDL_CreateMutex(); - SDL_memset((char*)lang_buffer, 0, BUFFER_SIZE); - lang_buffer[0] = '_'; -#ifdef unix_like - mkfifo(PIPE_PATH.c_str(), 0666); - atexit(cleanup_pipe); -#endif - + if (!NET_Init()) { + Debug() << "NET_Init() failed: " << SDL_GetError(); + } VALUE module = rb_define_module("Journal"); _rb_define_module_function(module, "set", journalSet); _rb_define_module_function(module, "active?", journalActive); diff --git a/changelogs/0.1.2.txt b/changelogs/0.1.2.txt index f578fbc..9aa84bd 100644 --- a/changelogs/0.1.2.txt +++ b/changelogs/0.1.2.txt @@ -66,3 +66,4 @@ Added X11 Window Managers support GNOME support fixed Fixed small defect on cg_wake5 Added ModLoader loading screen +Added [Function():string number] debug information in logs diff --git a/journal/SDL/CMakeLists.txt b/journal/SDL/CMakeLists.txt index 54594c3..263fac8 100644 --- a/journal/SDL/CMakeLists.txt +++ b/journal/SDL/CMakeLists.txt @@ -41,7 +41,7 @@ foreach(item ${EMBEDDED_INPUT}) endforeach() source_group("Embedded Source" FILES ${EMBEDDED_INPUT} ${EMBEDDED_SOURCE}) -add_executable(${PROJECT_NAME} ${EMBEDDED_SOURCE} main.c) +add_executable(${PROJECT_NAME} ${EMBEDDED_SOURCE} main.cpp debugwriter.h) find_package(SDL3 CONFIG REQUIRED) find_package(SDL3_image CONFIG REQUIRED) find_package(SDL3_net CONFIG REQUIRED) diff --git a/journal/SDL/debugwriter.h b/journal/SDL/debugwriter.h new file mode 100644 index 0000000..8bca148 --- /dev/null +++ b/journal/SDL/debugwriter.h @@ -0,0 +1,71 @@ +/* +** debugwriter.h +** +** This file is part of mkxp. +** +** Copyright (C) 2013 Jonas Kulla +** +** mkxp is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** mkxp is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with mkxp. If not, see . +*/ + +#ifndef DEBUGWRITER_H +#define DEBUGWRITER_H + +#include +#include +#include + +#ifdef __ANDROID__ + #include +#elif __EMSCRIPTEN__ + #include +#endif + +class Debug{ +public: + Debug(){ + buf << std::boolalpha; + } + + template + Debug &operator<<(const T &t){ + buf << t; + buf << " "; + + return *this; + } + + template + Debug &operator<<(const std::vector &v){ + for (size_t i = 0; i < v.size(); ++i) + buf << v[i] << " "; + + return *this; + } + + ~Debug(){ +#ifdef __ANDROID__ + __android_log_write(ANDROID_LOG_DEBUG, "sunshine", buf.str().c_str()); +#elif __EMSCRIPTEN__ + emscripten_console_log(buf.str().c_str()); +#else + std::cout << buf.str() << "\n"; +#endif + } + +private: + std::stringstream buf; +}; + +#endif // DEBUGWRITER_H diff --git a/journal/SDL/main.c b/journal/SDL/main.c deleted file mode 100644 index 868c27d..0000000 --- a/journal/SDL/main.c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include "icon.png.xxd" -#include "default.png.xxd" - -char image[256] = "default" - -int LoadImage(SDL_Renderer* ren){ - if(image == "default"){ - SDL_Surface* img = IMG_Load_IO(SDL_IOFromConstMem(assets_the_modded_machine_png, assets_the_modded_machine_png_len), true); - }else{ - - } -} - -int main(int argc, char* argv[]) { - SDL_Init(SDL_INIT_VIDEO); - - SDL_Window* win = SDL_CreateWindow("SDL3 Image",640, 480, 0); - if (win == NULL) { - SDL_Log("SDL_CreateWindow Error: %s", SDL_GetError()); - SDL_Quit(); - return 1; - } - - SDL_Renderer* ren = SDL_CreateRenderer(win, NULL); - if (ren == NULL) { - SDL_Log("SDL_CreateRenderer Error: %s", SDL_GetError()); - SDL_DestroyWindow(win); - SDL_Quit(); - return 1; - } - - SDL_Surface* bmp = SDL_LoadBMP("lettuce.bmp"); - if (bmp == NULL) { - SDL_Log("Image loading Error: %s", SDL_GetError()); - SDL_DestroyRenderer(ren); - SDL_DestroyWindow(win); - SDL_Quit(); - return 1; - } - - SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, bmp); - SDL_DestroySurface(bmp); - - if (tex == NULL) { - std::cerr << "SDL_CreateTextureFromSurface Error: " << SDL_GetError() << std::endl; - SDL_DestroyRenderer(ren); - SDL_DestroyWindow(win); - SDL_Quit(); - return 1; - } - - SDL_Event e; - bool quit = false; - - while (!quit) { - while (SDL_PollEvent(&e)) { - if (e.type == SDL_EVENT_QUIT) { - quit = true; - } - } - - SDL_RenderClear(ren); - SDL_RenderTexture(ren, tex, NULL, NULL); - SDL_RenderPresent(ren); - } - - SDL_DestroyTexture(tex); - SDL_DestroyRenderer(ren); - SDL_DestroyWindow(win); - SDL_Quit(); - - return 0; -} diff --git a/journal/SDL/main.cpp b/journal/SDL/main.cpp new file mode 100644 index 0000000..9d5ce89 --- /dev/null +++ b/journal/SDL/main.cpp @@ -0,0 +1,279 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "debugwriter.h" + +#include "icon.png.xxd" +#include "default.png.xxd" + +static bool quit = false; +static char is_changed = false; +static char image[256] = "default"; +static char image_full_path[1024] = "default"; +static char gamedir_path[256] = ""; +static char address[64] = "127.0.0.1"; + +Uint16 server_port = 23821; +static void trim_crlf_inplace(char* s) { + if (!s) return; + size_t n = SDL_strlen(s); + while (n > 0 && (s[n - 1] == '\r' || s[n - 1] == '\n')) { + s[n - 1] = '\0'; + n--; + } +} + +static int network_thread(void* /*data*/) { + NET_Address* server_addr = NET_ResolveHostname("127.0.0.1"); + if (!server_addr || (NET_WaitUntilResolved(server_addr, -1) != NET_SUCCESS)) { + if (server_addr) { NET_UnrefAddress(server_addr); } + return 1; + } + + NET_Server* server = NET_CreateServer(server_addr, server_port, 0); + if (!server) { + SDL_Log("Failed to create server: %s", SDL_GetError()); + return 1; + } + + SDL_Log("Port %d!", (int)server_port); + + int num_vsockets = 1; + void* vsockets[128]; + SDL_zeroa(vsockets); + vsockets[0] = server; + int wait_timeout_ms = quit ? 10 : 50; + + while (!quit && NET_WaitUntilInputAvailable(vsockets, num_vsockets, wait_timeout_ms) >= 0) { + NET_StreamSocket* streamsocket = nullptr; + if (NET_AcceptClient(server, &streamsocket)) { + if (!quit && streamsocket) { + SDL_Log("New connection from %s!", NET_GetAddressString(NET_GetStreamSocketAddress(streamsocket))); + if (num_vsockets >= (int)(SDL_arraysize(vsockets) - 1)) { + SDL_Log(" (too many connections, though, so dropping immediately.)"); + NET_DestroyStreamSocket(streamsocket); + } else { + vsockets[num_vsockets++] = streamsocket; + } + } else if (streamsocket) { + NET_DestroyStreamSocket(streamsocket); + } + } + + for (int i = 1; i < num_vsockets; i++) { + if (quit) break; + + bool kill_socket = false; + streamsocket = (NET_StreamSocket*)vsockets[i]; + + if (!streamsocket) { + continue; + } + + char buffer[1024]; + const int br = NET_ReadFromStreamSocket( + streamsocket, buffer, (int)sizeof(buffer) - 1 + ); + + if (br < 0) { + kill_socket = true; + } else if (br > 0) { + buffer[br] = '\0'; + trim_crlf_inplace(buffer); + + if (buffer[0] != '\0') { + if (SDL_snprintf(image, sizeof(image), "%s", buffer) >= 0) { + is_changed = true; + } else { + Debug() << "SDL_snprintf error"; + } + } + kill_socket = true; + } + + if (kill_socket) { + SDL_Log("Dropping connection to '%s'", NET_GetAddressString(NET_GetStreamSocketAddress(streamsocket))); + NET_DestroyStreamSocket(streamsocket); + vsockets[i] = nullptr; + if (i < (num_vsockets - 1)) { + SDL_memmove(&vsockets[i], &vsockets[i + 1], sizeof(vsockets[0]) * ((num_vsockets - i) - 1)); + } + num_vsockets--; + i--; + } + } + } + for (int i = 1; i < num_vsockets; i++) { + if (vsockets[i]) { + NET_DestroyStreamSocket((NET_StreamSocket*)vsockets[i]); + vsockets[i] = nullptr; + } + } + NET_DestroyServer(server); + return 0; +} + + +int main(int argc, char* argv[]) { + // get game dir path + std::ifstream file(std::filesystem::temp_directory_path() / "sunshine"); + if (file.is_open()) { + std::string filePath; + std::getline(file, filePath); + SDL_strlcpy(gamedir_path, filePath.c_str(), sizeof(gamedir_path) - 1); + gamedir_path[sizeof(gamedir_path) - 1] = '\0'; + file.close(); + } else { + Debug() << "Unable to open file"; + } + Debug() << gamedir_path; + + for (int i = 1; i < argc; i++) { + const char* arg = argv[i]; + if ((SDL_strcmp(arg, "--port") == 0) && (i < (argc - 1))) { + server_port = (Uint16)SDL_atoi(argv[++i]); + } + if ((SDL_strcmp(arg, "--addr") == 0) && (i < (argc - 1))) { + strncpy(address, argv[++i], sizeof(address) - 1); + address[sizeof(address) - 1] = '\0'; + } + if ((SDL_strcmp(arg, "--game-path") == 0) && (i < (argc - 1))) { + strncpy(gamedir_path, argv[++i], sizeof(gamedir_path) - 1); + gamedir_path[sizeof(gamedir_path) - 1] = '\0'; + } + } + + // initialization + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + Debug() << "SDL_Init failed: " << SDL_GetError(); + return 1; + } + + if (!NET_Init()) { + Debug() << "NET_Init failed: " << SDL_GetError(); + SDL_Quit(); + return 1; + } + + // window / renderer + SDL_Window* win = SDL_CreateWindow("_______", 800, 600, SDL_WINDOW_TRANSPARENT); + if (win == NULL) { + Debug() << "SDL_CreateWindow Error: " << SDL_GetError(); + NET_Quit(); + SDL_Quit(); + return 1; + } + + SDL_Renderer* ren = SDL_CreateRenderer(win, NULL); + if (ren == NULL) { + Debug() << "SDL_CreateRenderer Error: " << SDL_GetError(); + SDL_DestroyWindow(win); + NET_Quit(); + SDL_Quit(); + return 1; + } + + // default image texture + SDL_Surface* img0 = IMG_Load_IO(SDL_IOFromConstMem(assets_default_png, assets_default_png_len), true); + if (!img0) { + Debug() << "IMG_Load_IO default failed: " << SDL_GetError(); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + NET_Quit(); + SDL_Quit(); + return 1; + } + + SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, img0); + SDL_DestroySurface(img0); + + if (tex == NULL) { + Debug() << "SDL_CreateTextureFromSurface Error: " << SDL_GetError(); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + NET_Quit(); + SDL_Quit(); + return 1; + } + + // start network thread + SDL_Thread* network_thread_pointer = SDL_CreateThread(network_thread, "network", NULL); + if (!network_thread_pointer) { + Debug() << "SDL_CreateThread failed"; + SDL_DestroyTexture(tex); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + NET_Quit(); + SDL_Quit(); + return 1; + } + + SDL_Event e; + while (!quit) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_EVENT_QUIT) { + quit = true; + }else if(e.type == SDL_EVENT_WINDOW_DESTROYED){ + quit = true; + } + } + + if (is_changed) { + char local_image[256]; + SDL_strlcpy(local_image, image, sizeof(local_image)); + SDL_Texture* new_tex = nullptr; + if (SDL_strcmp(local_image, "default") == 0) { + SDL_Surface* img = IMG_Load_IO(SDL_IOFromConstMem(assets_default_png, assets_default_png_len), true); + if (!img) { + Debug() << "IMG_Load_IO default failed: " << SDL_GetError(); + } else { + new_tex = SDL_CreateTextureFromSurface(ren, img); + SDL_DestroySurface(img); + if (!new_tex) { + Debug() << "SDL_CreateTextureFromSurface Error: " << SDL_GetError(); + } + } + } else { + if (SDL_snprintf(image_full_path, sizeof(image_full_path), "%s/%s", gamedir_path, local_image) < 0) { + Debug() << "SDL_snprintf error"; + } else { + SDL_Surface* img = IMG_Load(image_full_path); + if (!img) { + Debug() << "Image loading Error: " << SDL_GetError(); + } else { + new_tex = SDL_CreateTextureFromSurface(ren, img); + SDL_DestroySurface(img); + if (!new_tex) { + Debug() << "SDL_CreateTextureFromSurface Error: " << SDL_GetError(); + } + } + } + } + + if (new_tex) { + SDL_DestroyTexture(tex); + tex = new_tex; + } + is_changed = false; + } + SDL_RenderClear(ren); + SDL_RenderTexture(ren, tex, NULL, NULL); + SDL_RenderPresent(ren); + SDL_Delay(16); + } + SDL_WaitThread(network_thread_pointer, NULL); + SDL_DestroyTexture(tex); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + NET_Quit(); + SDL_Quit(); + return 0; +} diff --git a/scripts/Data_Settings.rb b/scripts/Data_Settings.rb index bbd488e..5b879d3 100644 --- a/scripts/Data_Settings.rb +++ b/scripts/Data_Settings.rb @@ -55,7 +55,7 @@ module Settings :debug_picture_names => false, :debug_lightmap => false, :SDL_HINT_SHUTDOWN_DBUS_ON_QUIT => false, - :profiler => false, + :profiler => false, } reset_controls! end diff --git a/src/config.cpp b/src/config.cpp index 6035f2b..1dc93b1 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -94,7 +94,9 @@ void Config::read(int argc, char *argv[]){ PO_DESC(Windows_AllocConsole, bool, false) \ PO_DESC(Modloader.use_default_save_path, bool, false) \ PO_DESC(pancakes, bool, false) \ - PO_DESC(SecurityEngine, bool, true) + PO_DESC(SecurityEngine, bool, true) \ + PO_DESC(journal_address, std::string, "127.0.0.1") \ + PO_DESC(journal_port, int, 23821) // Not gonna take your shit boost #define GUARD_ALL( SDL_exp ) try { SDL_exp } catch(...) {} diff --git a/src/config.h b/src/config.h index 75dfec4..d35190b 100644 --- a/src/config.h +++ b/src/config.h @@ -58,23 +58,23 @@ struct Config{ std::string iconPath; std::string wallpaperMode; + std::string journal_address; + int journal_port; struct{ int sourceCount; } SE; struct{ - std::string ModsDirPath; - bool use_default_save_path; + std::string ModsDirPath; + bool use_default_save_path; } Modloader; bool useScriptNames; std::string customScript; std::vector rtps; - std::vector fontSubs; - std::vector rubyLoadpaths; /* Game INI contents */ struct { diff --git a/src/debugwriter.h b/src/debugwriter.h index 7ff0744..6ef61d6 100644 --- a/src/debugwriter.h +++ b/src/debugwriter.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "meow.h" #undef vsnprintf #undef snprintf @@ -38,8 +39,8 @@ class Debug{ public: - Debug(){ - buf << std::boolalpha; + explicit Debug(const std::source_location location = std::source_location::current()) : location(location){ + buf << std::boolalpha; } template @@ -65,18 +66,21 @@ public: } ~Debug(){ + std::ostringstream result; + result << "[" << location.line() << ":" << location.function_name() << "] " << buf.str(); #ifdef __ANDROID__ - __android_log_write(ANDROID_LOG_DEBUG, "sunshine", buf.str().c_str()); + __android_log_write(ANDROID_LOG_DEBUG, "sunshine", result.str().c_str()); #elif __EMSCRIPTEN__ - emscripten_console_log(buf.str().c_str()); + emscripten_console_log(result.str().c_str()); #else - logs.push_back(buf.str()); - std::cout << buf.str() << "\n"; + logs.push_back(result.str()); + std::cout << result.str() << "\n"; #endif } private: std::stringstream buf; + std::source_location location; }; #endif // DEBUGWRITER_H diff --git a/src/modloader.cpp b/src/modloader.cpp index 9c44ad9..af763da 100644 --- a/src/modloader.cpp +++ b/src/modloader.cpp @@ -76,6 +76,9 @@ void ModLoader(Config conf, SDL_Window* win){ } SDL_Thread* render_thread_pointer = SDL_CreateThread(renderer_thread, "ModRenderer", win); + if (!render_thread_pointer) { + //TODO: Error handling + } std::vector mod_list = {}; try { // 1.check if any zip(mod) file, 2. calculate sha256 hash of zip(mod) files 3.mount mod via PhysFS