This commit is contained in:
DepressedTWM 2026-08-10 13:46:34 +04:00
parent bd55231a64
commit ab88b293a7
4 changed files with 77 additions and 58 deletions

View File

@ -31,6 +31,7 @@ struct Exception{
RUBYError, RUBYError,
NoFileError, NoFileError,
IOError, IOError,
ShaderError,
/* Already defined by ruby */ /* Already defined by ruby */
TypeError, TypeError,

View File

@ -76,14 +76,41 @@ void crash(Exception::Type t, const char *fmt, ...) {
SDL_vsnprintf(crash_message, sizeof(crash_message), fmt, args); SDL_vsnprintf(crash_message, sizeof(crash_message), fmt, args);
va_end(args); va_end(args);
//TODO: rewrite to use switch :3
if (t == Exception::ModLoaderError) { if (t == Exception::ModLoaderError) {
crash_reason = "Broken mod"; crash_reason = "Broken mod";
crash_possible_solution = "Fix mode manualy or ask developer to fix it or delete mod"; crash_possible_solution = "Fix mode manualy or ask developer to fix it or delete mod";
} else if (t == Exception::NoFileError) { } else if (t == Exception::NoFileError) {
crash_reason = "Broken installation"; crash_reason = "Broken installation";
crash_possible_solution = "Try reinstall game"; 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; show_crash_sceen = true;
rb_exit(-1); rb_exit(-1);
} }
@ -228,6 +255,8 @@ void crash_screen(SDL_Window* win){
SDL_RenderDebugText(ren, 10, 40, msg2); SDL_RenderDebugText(ren, 10, 40, msg2);
SDL_RenderDebugText(ren, 10, 50, msg3); SDL_RenderDebugText(ren, 10, 50, msg3);
SDL_RenderDebugText(ren, 10, 60, msg4); 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); SDL_RenderPresent(ren);
} }
} }

View File

@ -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 "modloader.h"
#include "debugwriter.h" #include "debugwriter.h"
#include "meow.h" #include "meow.h"
#include "config.h" #include "config.h"
#include <cctype>
#include <string>
#include <iostream>
#include <filesystem>
#include <vector>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <SDL3/SDL_stdinc.h>
#include <locale>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <vector> #include <vector>
#include <algorithm>
#include <system_error> #include <system_error>
#include <SDL3/SDL_system.h>
#include <physfs.h> #include <physfs.h>
namespace fs = std::filesystem; namespace fs = std::filesystem;
void ModLoader(){ void ModLoader() {
std::string path = "mods"; std::string path = "mods";
if (!fs::exists(path) || !fs::is_directory(path)) { if (!fs::exists(path) || !fs::is_directory(path)) {
Debug() << "[MODLOADER] Mods directory not found, skip."; Debug() << "[MODLOADER] Mods directory not found, skip.";
return; return;
} }
if (fs::is_empty(path)){ if (fs::is_empty(path)) {
Debug() << "[MODLOADER] Mods directory empty, skip."; Debug() << "[MODLOADER] Mods directory empty, skip.";
return; return;
} }
std::vector<std::string> mod_list = {}; std::vector<std::string> mod_list = {};
try{ try {
//1.check if any zip(mod) file, 2. calculate sha256 hash of zip(mod) files 3.mount mod via PhysFS // 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)) { for (const auto &entry : fs::directory_iterator(path, fs::directory_options::skip_permission_denied)) {
std::error_code ec; std::error_code ec;
auto p = entry.path(); auto p = entry.path();
if (!fs::is_regular_file(p, ec) || ec) continue; if (!fs::is_regular_file(p, ec) || ec) continue;
auto ext = p.extension().string(); auto ext = p.extension().string();
std::string full = p.string(); std::string full = p.string();
if (ext == ".zip"){
if (ext == ".zip") {
int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0); int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0);
if (!ok) { (void)ok; // если не используете ok дальше
//crash(Exception::ModLoaderError, "PhysFS_mount failed: %s", PHYSFS_getLastError());
}
Debug() << "[MODLOADER] " << full; Debug() << "[MODLOADER] " << full;
mod_list.push_back(full); mod_list.push_back(full);
mods_count++; mods_count++;
}else if(ext == ".rb"){ } else if (ext == ".rb") {
preloadScripts.insert(full); preloadScripts.insert(full);
Debug() << "[MODLOADER] Loading Preload Script: " << full; Debug() << "[MODLOADER] Loading Preload Script: " << full;
preloaded_script_count++; preloaded_script_count++;
} }
} }
modloader_is_enabled = true; modloader_is_enabled = true;
}catch(const std::exception& e){ } catch (const std::exception& e) {
crash(Exception::ModLoaderError, "Something is wrong, Exception: %s ", e.what()); crash(Exception::ModLoaderError, "Something is wrong, Exception: %s ", e.what());
} }
} }

View File

@ -153,7 +153,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char *
if (!success){ if (!success){
printShaderLog(vertShader); 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 */ /* Compile fragment shader */
@ -164,7 +164,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char *
if (!success){ if (!success){
printShaderLog(fragShader); 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 */ /* Link shader program */
@ -181,7 +181,7 @@ void Shader::init(const unsigned char *vert, int vertSize, const unsigned char *
if (!success){ if (!success){
printProgramLog(program); 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);
} }
} }