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 0000000..8f9805e Binary files /dev/null and b/assets/the_modded_machine.png differ diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index e22860c..727e417 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -75,14 +75,12 @@ void windowVXBindingInit(); void tilemapVXBindingInit(); void TimeBindingInit(); void SignalConnectionBindingInit(); - void inputBindingInit(); void audioPlaybackBindingInit(); void audioBindingInit(); void graphicsBindingInit(); - void fileIntBindingInit(); - +void ModLoaderBindingInit(); void journalBindingInit(); void wallpaperBindingInit(); #ifdef unix_like @@ -93,7 +91,6 @@ void oneshotBindingInit(); void SunshineBindingInit(); void steamBindingInit(); void shaderBindingInit(); -void ModLoaderBindingInit(); void keybindingsBindingInit(); void lightmapBindingInit(); void ProfilerInit(); @@ -148,7 +145,6 @@ static void mriBindingInit(){ SunshineBindingInit(); steamBindingInit(); shaderBindingInit(); - ModLoader(); ModLoaderBindingInit(); keybindingsBindingInit(); lightmapBindingInit(); @@ -168,7 +164,6 @@ static void mriBindingInit(){ script[binding_mri_module_rpg1_rb_len] = '\0'; rb_eval_string(script); - SDL_free(script); VALUE mod = rb_define_module("MKXP"); diff --git a/src/main.cpp b/src/main.cpp index a4be5e9..49d7bd7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,6 +50,7 @@ #include "security.h" #include "sunshine.h" +#include "modloader.h" #include "define.h" #include "meow.h" @@ -272,7 +273,6 @@ int main(int argc, char *argv[]){ return 0; } } - extern int screenMain(Config &conf); if (conf.screenMode) return screenMain(conf); @@ -348,6 +348,8 @@ int main(int argc, char *argv[]){ SDL_GetWindowSize(win, &winW, &winH); // SDL_GL_GetDrawableSize(win, &winW, &winH); rtData.windowSizeMsg.post(Vec2i(winW, winH)); + ModLoader(conf, win); + /* Load and post key bindings */ rtData.bindingUpdateMsg.post(loadBindings(conf)); /* Start RGSS thread */ diff --git a/src/meow.cpp b/src/meow.cpp index ba563e7..ce69ee1 100644 --- a/src/meow.cpp +++ b/src/meow.cpp @@ -8,6 +8,9 @@ #include #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;