From 8ea7f55a2e28f0884e014f2290bec9ead691dc1c Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Sun, 16 Aug 2026 20:30:06 +0400 Subject: [PATCH] af --- CMakeLists.txt | 1 + assets/the_modded_machine.png | Bin 0 -> 1428 bytes binding-mri/binding-mri.cpp | 7 +--- src/main.cpp | 4 +- src/meow.cpp | 10 ++--- src/meow.h | 1 + src/modloader.cpp | 74 +++++++++++++++++++++++++++++----- src/modloader.h | 4 +- 8 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 assets/the_modded_machine.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d3868e..b2ea3fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,7 @@ set(EMBEDDED_INPUT assets/icon.png assets/gamecontrollerdb.txt assets/crash.png + assets/the_modded_machine.png binding-mri/module_rpg1.rb ) diff --git a/assets/the_modded_machine.png b/assets/the_modded_machine.png new file mode 100644 index 0000000000000000000000000000000000000000..8f9805e12c8521cba7e021fc4d1f317544b1fda7 GIT binary patch literal 1428 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A1Qgk|*?TjPVk{1FcVfJGQl}osVM%xN zb!1@J*w6hZkrl{SNcITwWnidMV_;}#VPN #include #include +#include +#include +#include #include "meow.h" #include "eventthread.h" #include "exception.h" @@ -33,8 +36,6 @@ #include #include #include -#include -#include #include "sunshine.h" #ifdef unix_like #include @@ -43,8 +44,6 @@ #include #elif web #include -#elif dos - #include #endif #include "crash.png.xxd" using namespace std; @@ -145,7 +144,7 @@ void crash(Exception::Type t, const char *fmt, ...) { } void crash_screen(SDL_Window* win){ - // Skil Crash screen if failed initialize + // Skip Crash screen if failed initialize static bool skip_crash_screen = false; //creating render SDL_Renderer* ren = SDL_CreateRenderer(win, NULL); @@ -306,6 +305,7 @@ void crash_screen(SDL_Window* win){ SDL_RenderDebugTextFormat(ren, 10, 70, "If you are sure that the problem is not in your modifications,"); SDL_RenderDebugTextFormat(ren, 10, 80, "your hands or in your device - please report the bug to the developers"); SDL_RenderPresent(ren); + SDL_Delay(32); } SDL_DestroyTexture(tex); SDL_DestroyRenderer(ren); diff --git a/src/meow.h b/src/meow.h index 5344b76..e99ed4f 100644 --- a/src/meow.h +++ b/src/meow.h @@ -5,6 +5,7 @@ #include inline std::vector logs = {}; +inline std::vector modloader_logs = {}; inline bool show_crash_sceen = false; inline bool is_privacy_crashdump_enabled = false; diff --git a/src/modloader.cpp b/src/modloader.cpp index 4fbee9b..29b993a 100644 --- a/src/modloader.cpp +++ b/src/modloader.cpp @@ -7,23 +7,77 @@ #include #include #include - #include +#include +#include +#include +#include +#include + +#include "the_modded_machine.png.xxd" + namespace fs = std::filesystem; -void ModLoader() { +static bool stop_render = false; +const static std::size_t N = 46; + +static void modloader_add_to_log(const std::string data){ + Debug() << "[MODLOADER] " << data; + modloader_logs.push_back(data); +} + +static int renderer_thread(void* data){ + SDL_Window* win = static_cast(data); + SDL_Renderer* ren = SDL_CreateRenderer(win, NULL); + if (ren == nullptr) {return(0);} + SDL_Surface* crash_img = IMG_Load_IO(SDL_IOFromConstMem(assets_the_modded_machine_png, assets_the_modded_machine_png_len), true); + if (crash_img == nullptr){ + SDL_DestroyRenderer(ren); + return(0); + } + SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, crash_img); + SDL_DestroySurface(crash_img); + if (tex == nullptr) { + SDL_DestroyRenderer(ren); + return(0); + } + + int index_on_screen = 10; + while(!stop_render){ + index_on_screen = 10; + SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); + SDL_RenderClear(ren); + SDL_RenderTexture(ren, tex, NULL, NULL); + SDL_SetRenderDrawColor(ren, 109, 0, 198, 255); + std::size_t size = modloader_logs.size(); + std::size_t n = std::min(static_cast(N), size); + std::size_t start = size > n ? (size - n) : 0; + for (std::size_t i = start; i < size; ++i) { + SDL_RenderDebugTextFormat(ren, 10, index_on_screen, "%s", modloader_logs[i].c_str()); + index_on_screen += 10; + } + SDL_RenderPresent(ren); + SDL_Delay(16); + } + SDL_RenderClear(ren); + SDL_RenderPresent(ren); + SDL_DestroyTexture(tex); + SDL_DestroyRenderer(ren); + return(0); +} + +void ModLoader(Config conf, SDL_Window* win){ std::string path = "mods"; if (!fs::exists(path) || !fs::is_directory(path)) { Debug() << "[MODLOADER] Mods directory not found, skip."; return; - } - - if (fs::is_empty(path)) { + }else if (fs::is_empty(path)) { Debug() << "[MODLOADER] Mods directory empty, skip."; return; } - + + SDL_Thread* render_thread_pointer = SDL_CreateThread(renderer_thread, "ModRenderer", win); 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 @@ -37,16 +91,18 @@ void ModLoader() { if (ext == ".zip") { int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0); - (void)ok; // если не используете ok дальше - Debug() << "[MODLOADER] " << full; mod_list.push_back(full); + modloader_add_to_log("Added mod " + full); mods_count++; } else if (ext == ".rb") { preloadScripts.insert(full); - Debug() << "[MODLOADER] Loading Preload Script: " << full; + modloader_add_to_log("Added script " + full); preloaded_script_count++; } } + sleep(1); + stop_render = true; + SDL_WaitThread(render_thread_pointer, NULL); modloader_is_enabled = true; } catch (const std::exception& e) { crash(Exception::ModLoaderError, "Something is wrong, Exception: %s ", e.what()); diff --git a/src/modloader.h b/src/modloader.h index 36c7686..d7e1296 100644 --- a/src/modloader.h +++ b/src/modloader.h @@ -1,6 +1,8 @@ #include #include -void ModLoader(); +#include +#include "config.h" +void ModLoader(Config conf, SDL_Window* win); inline bool modloader_is_enabled = false; inline unsigned int mods_count = 0;