diff --git a/src/exception.h b/src/exception.h index d932cbe..a427212 100644 --- a/src/exception.h +++ b/src/exception.h @@ -31,6 +31,7 @@ struct Exception{ RUBYError, NoFileError, IOError, + ShaderError, /* Already defined by ruby */ TypeError, diff --git a/src/meow.cpp b/src/meow.cpp index d764748..c70b5ae 100644 --- a/src/meow.cpp +++ b/src/meow.cpp @@ -76,14 +76,41 @@ void crash(Exception::Type t, const char *fmt, ...) { SDL_vsnprintf(crash_message, sizeof(crash_message), fmt, args); va_end(args); + //TODO: rewrite to use switch :3 if (t == Exception::ModLoaderError) { crash_reason = "Broken mod"; crash_possible_solution = "Fix mode manualy or ask developer to fix it or delete mod"; } else if (t == Exception::NoFileError) { crash_reason = "Broken installation"; crash_possible_solution = "Try reinstall game"; - } - + } else if (t == Exception::ShaderError) { + crash_reason = "Broken Shader"; + crash_possible_solution = "Try reinstall game"; + } else if (t == Exception::RGSSError) { + crash_reason = "Internal Error"; + crash_possible_solution = "Try reinstall game or disable some mods"; + } else if (t == Exception::RUBYError) { + crash_reason = "Internal Error"; + crash_possible_solution = "Try reinstall game or disable some mods"; + } else if (t == Exception::IOError) { + crash_reason = "Broken installation"; + crash_possible_solution = "Try reinstall game"; + } else if (t == Exception::TypeError) { + crash_reason = "Internal Error"; + crash_possible_solution = "Try reinstall game or disable some mods"; + } else if (t == Exception::ArgumentError) { + crash_reason = "Internal error"; + crash_possible_solution = "Try reinstall game or disable some mods"; + } else if (t == Exception::PHYSFSError) { + crash_reason = "Internal error"; + crash_possible_solution = "Maybe you tryed load corrupted mod via modloader, try delete it"; + } else if (t == Exception::SDLError) { + crash_reason = "Internal error"; + crash_possible_solution = "Internal Engine Error, maybe something wrong with your device or operating system"; + } else if (t == Exception::MKXPError) { + crash_reason = "Internal error"; + crash_possible_solution = "Try reinstall game or disable some mods"; + } show_crash_sceen = true; rb_exit(-1); } @@ -228,6 +255,8 @@ void crash_screen(SDL_Window* win){ SDL_RenderDebugText(ren, 10, 40, msg2); SDL_RenderDebugText(ren, 10, 50, msg3); SDL_RenderDebugText(ren, 10, 60, msg4); + SDL_RenderDebugText(ren, 10, 70, "If you are sure that the problem is not in your modifications,"); + SDL_RenderDebugText(ren, 10, 80, "your hands or in your device - please report the bug to the developers"); SDL_RenderPresent(ren); } } diff --git a/src/modloader.cpp b/src/modloader.cpp index 7b90b36..4fbee9b 100644 --- a/src/modloader.cpp +++ b/src/modloader.cpp @@ -1,65 +1,54 @@ -//https://stackoverflow.com/questions/15347123/how-to-construct-a-stdstring-from-a-stdvectorstring -//https://stackoverflow.com/questions/1673445/how-to-convert-unsigned-char-to-stdstring-in-c -//https://www.geeksforgeeks.org/cpp/cpp-program-to-read-and-print-all-files-from-a-zip-file/ #include "modloader.h" #include "debugwriter.h" #include "meow.h" #include "config.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #include #include #include -#include #include -#include + #include + namespace fs = std::filesystem; -void ModLoader(){ - 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)){ - Debug() << "[MODLOADER] Mods directory empty, skip."; - return; - } - 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 - for (const auto &entry : fs::directory_iterator(path, fs::directory_options::skip_permission_denied)) { - std::error_code ec; - auto p = entry.path(); - if (!fs::is_regular_file(p, ec) || ec) continue; - auto ext = p.extension().string(); - std::string full = p.string(); - if (ext == ".zip"){ - int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0); - if (!ok) { - //crash(Exception::ModLoaderError, "PhysFS_mount failed: %s", PHYSFS_getLastError()); - } - Debug() << "[MODLOADER] " << full; - mod_list.push_back(full); - mods_count++; - }else if(ext == ".rb"){ - preloadScripts.insert(full); - Debug() << "[MODLOADER] Loading Preload Script: " << full; - preloaded_script_count++; - } - } - modloader_is_enabled = true; - }catch(const std::exception& e){ - crash(Exception::ModLoaderError, "Something is wrong, Exception: %s ", e.what()); - } +void ModLoader() { + 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)) { + Debug() << "[MODLOADER] Mods directory empty, skip."; + return; + } + + 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 + for (const auto &entry : fs::directory_iterator(path, fs::directory_options::skip_permission_denied)) { + std::error_code ec; + auto p = entry.path(); + if (!fs::is_regular_file(p, ec) || ec) continue; + + auto ext = p.extension().string(); + std::string full = p.string(); + + if (ext == ".zip") { + int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0); + (void)ok; // если не используете ok дальше + Debug() << "[MODLOADER] " << full; + mod_list.push_back(full); + mods_count++; + } else if (ext == ".rb") { + preloadScripts.insert(full); + Debug() << "[MODLOADER] Loading Preload Script: " << full; + preloaded_script_count++; + } + } + modloader_is_enabled = true; + } catch (const std::exception& e) { + crash(Exception::ModLoaderError, "Something is wrong, Exception: %s ", e.what()); + } } diff --git a/src/shader.cpp b/src/shader.cpp index 8b0609c..ac1a110 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -153,7 +153,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printShaderLog(vertShader); - crash(Exception::MKXPError, "GLSL: An error occured while compiling vertex shader '%s' in program '%s'", vertName, programName); + crash(Exception::ShaderError, "GLSL: An error occured while compiling vertex shader '%s' in program '%s'", vertName, programName); } /* Compile fragment shader */ @@ -164,7 +164,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printShaderLog(fragShader); - crash(Exception::MKXPError, "GLSL: An error occured while compiling fragment shader '%s' in program '%s'", fragName, programName); + crash(Exception::ShaderError, "GLSL: An error occured while compiling fragment shader '%s' in program '%s'", fragName, programName); } /* Link shader program */ @@ -181,7 +181,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char * if (!success){ printProgramLog(program); - crash(Exception::MKXPError, "GLSL: An error occured while linking program '%s' (vertex '%s', fragment '%s')", programName, vertName, fragName); + crash(Exception::ShaderError, "GLSL: An error occured while linking program '%s' (vertex '%s', fragment '%s')", programName, vertName, fragName); } }