From 660825aa3aba7ab4c3ca23b7ba31e5b81a8b8be1 Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Wed, 5 Aug 2026 19:29:09 +0400 Subject: [PATCH] g --- binding-mri/binding-mri.cpp | 2 +- binding-mri/modloader-binding.cpp | 1 + scripts/Scene_Title.rb | 3 +- src/config.cpp | 22 --------- src/config.h | 16 ------- src/modloader.cpp | 75 +++++-------------------------- src/modloader.h | 5 ++- 7 files changed, 20 insertions(+), 104 deletions(-) diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 7b7b5f0..407f518 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -480,7 +480,7 @@ static void runRMXPScripts(BacktraceData &btData){ } /* Execute preloaded scripts */ - for (std::set::iterator i = conf.preloadScripts.begin(); + for (std::set::iterator i = preloadScripts.begin(); i != conf.preloadScripts.end(); ++i) runCustomScript(*i); diff --git a/binding-mri/modloader-binding.cpp b/binding-mri/modloader-binding.cpp index 01e8cac..fc033c8 100644 --- a/binding-mri/modloader-binding.cpp +++ b/binding-mri/modloader-binding.cpp @@ -63,4 +63,5 @@ void ModLoaderBindingInit(){ rb_define_module_function(klass, "hooks", RUBY_METHOD_FUNC(hooks), -1); rb_define_const(klass, "IS_ENABLED", modloader_is_enabled ? Qtrue : Qfalse); rb_define_const(klass, "COUNT", INT2NUM(mods_count)); + rb_define_const(klass, "PRELOAD_SCRIPTS_COUNT", INT2NUM(preloaded_script_count)); } diff --git a/scripts/Scene_Title.rb b/scripts/Scene_Title.rb index 031569b..675e3f9 100644 --- a/scripts/Scene_Title.rb +++ b/scripts/Scene_Title.rb @@ -190,7 +190,8 @@ class Scene_Title @debug.bitmap.draw_text(0, ENTRY_HEIGHT * 2, 200, ENTRY_HEIGHT, tr("Sunshine") + " " + SunshineVer) @debug.bitmap.draw_text(0, ENTRY_HEIGHT * 3, 200, ENTRY_HEIGHT, tr("sec_#{Sunshine::SECURITYSTATE}")) if ModLoader::IS_ENABLED - @debug.bitmap.draw_text(0, ENTRY_HEIGHT * 5, 200, ENTRY_HEIGHT, tr("Mods loaded:") + " " + ModLoader::COUNT.to_s) + @debug.bitmap.draw_text(0, ENTRY_HEIGHT * 4, 200, ENTRY_HEIGHT, tr("Mods loaded: ") + ModLoader::COUNT.to_s) + @debug.bitmap.draw_text(0, ENTRY_HEIGHT * 5, 200, ENTRY_HEIGHT, tr("Preload Scripts loaded: ") + ModLoader::PRELOAD_SCRIPTS_COUNT.to_s) end end diff --git a/src/config.cpp b/src/config.cpp index 1e4b2a8..1f83c48 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -184,29 +184,7 @@ void Config::read(int argc, char *argv[]){ resolutionOverridden = defScreenW > 0 || defScreenH > 0; defScreenW = defScreenW <= 0 ? 640 : defScreenW; defScreenH = defScreenH <= 0 ? 480 : defScreenH; -/* - #define ASPECT_SELECT(id, x, y, rubyConst) \ - case id: { \ - defScreenW = x; \ - defScreenH = y; \ - AspectPresetRubyConst = #rubyConst;\ - break; \ - } - - if (defScreenW == 640 && defScreenH == 480) - switch (AspectPreset) { - RESOLUTIONS_LIST(ASPECT_SELECT) - default: { - AspectPreset = 1; - AspectPresetRubyConst = "_4_3"; - defScreenW = 640; - defScreenH = 480; - break; - } - } - #undef ASPECT_SELECT -*/ #ifdef STEAM /* Override fullscreen config if Big Picture */ if (const char *env = SDL_getenv("SteamTenfoot")){ diff --git a/src/config.h b/src/config.h index 9eb7935..a52c709 100644 --- a/src/config.h +++ b/src/config.h @@ -99,20 +99,4 @@ struct Config{ void read(int argc, char *argv[]); }; -// 0 - 3:2 - 720:480 -// 1 - 4:3 - 640x480 (default) -// 2 - 16:9 - 960x540 -// 3 - 16:10 - 960x600 -// 4 - 16:9 HD - 1280x720 X -// 5 - 16:9 FHD - 1920x1080 X - -// Value X Y Ruby const -#define RESOLUTIONS_LIST(X) \ - X(0, 720, 480, _3_2) \ - X(1, 640, 480, _4_3) \ - X(2, 960, 540, _16_9) \ - X(3, 960, 600, _16_10) \ - X(4, 1280, 720, _16_9_hd) \ - X(5, 1920, 1080, _16_9_fhd) - #endif // CONFIG_H diff --git a/src/modloader.cpp b/src/modloader.cpp index 17d488f..23a858d 100644 --- a/src/modloader.cpp +++ b/src/modloader.cpp @@ -1,6 +1,4 @@ -//https://terminalroot.com/how-to-generate-sha256-hash-with-cpp-and-openssl/ //https://stackoverflow.com/questions/15347123/how-to-construct-a-stdstring-from-a-stdvectorstring -//https://stackoverflow.com/questions/54260184/how-to-sha256-hash-a-text-file-in-chunks-with-openssl-sha-h //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" @@ -15,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -27,49 +24,6 @@ #include namespace fs = std::filesystem; -std::string sha512(const std::string str){ - unsigned char hash[SHA512_DIGEST_LENGTH]; - - SHA512_CTX sha512; - SHA512_Init(&sha512); - SHA512_Update(&sha512, str.c_str(), str.size()); - SHA512_Final(hash, &sha512); - - std::stringstream ss; - - for(int i = 0; i < SHA512_DIGEST_LENGTH; i++){ - ss << std::hex << std::setw(2) << std::setfill('0') << static_cast( hash[i] ); - } - return ss.str(); -} - -std::string sha256_file(const std::string &fn) { - FILE *file = fopen(fn.c_str(), "rb"); - if (!file) { - crash(Exception::IOError, true, "Failed to load mod, filesystem error."); - } - - unsigned char buf[1024]; - unsigned char hash[SHA256_DIGEST_LENGTH]; - size_t len; - SHA256_CTX ctx; - SHA256_Init(&ctx); - while ((len = fread(buf, 1, sizeof buf, file)) != 0){ - SHA256_Update(&ctx, buf, len); - } - fclose(file); - SHA256_Final(hash, &ctx); - - std::string out; - out.reserve(SHA256_DIGEST_LENGTH * 2); - char hex[3] = {0}; - for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) { - SDL_snprintf(hex, sizeof hex, "%02x", hash[i]); - out += hex; - } - return out; -} - void ModLoader(){ std::string path = "mods"; if (!fs::exists(path) || !fs::is_directory(path)) { @@ -81,10 +35,6 @@ void ModLoader(){ Debug() << "[MODLOADER] Mods directory empty, skip."; return; } - - //buildID - unique ID of a certain combination of mods - std::string buildID = ""; - std::string buildID_tmp = ""; 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 @@ -93,22 +43,21 @@ void ModLoader(){ auto p = entry.path(); if (!fs::is_regular_file(p, ec) || ec) continue; auto ext = p.extension().string(); - if (ext != ".zip") continue; std::string full = p.string(); - int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0); - if (!ok) { - crash(Exception::ModLoaderError, false, "PhysFS_mount failed: %s", PHYSFS_getLastError()); + if (ext == ".zip"){ + int ok = PHYSFS_mount(full.c_str(), "/mod-storage", 0); + if (!ok) { + crash(Exception::ModLoaderError, false, "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++; } - Debug() << "[MODLOADER] " << full; - mod_list.push_back(full); - mods_count++; - - auto h = sha256_file(full); - buildID_tmp.append(h); } - - buildID = sha512(buildID_tmp); - Debug() << "[MODLOADER] BuildID: " << buildID; modloader_is_enabled = true; }catch(const std::exception& e){ crash(Exception::ModLoaderError, true, "Something is wrong, Exception: %s ", e.what()); diff --git a/src/modloader.h b/src/modloader.h index 4d82416..36c7686 100644 --- a/src/modloader.h +++ b/src/modloader.h @@ -1,5 +1,8 @@ -//modloader bruh +#include +#include void ModLoader(); inline bool modloader_is_enabled = false; inline unsigned int mods_count = 0; +inline unsigned int preloaded_script_count = 0; +inline std::set preloadScripts;