This commit is contained in:
DepressedTWM 2026-08-05 19:29:09 +04:00
parent ee332bce1d
commit 660825aa3a
7 changed files with 20 additions and 104 deletions

View file

@ -480,7 +480,7 @@ static void runRMXPScripts(BacktraceData &btData){
}
/* Execute preloaded scripts */
for (std::set<std::string>::iterator i = conf.preloadScripts.begin();
for (std::set<std::string>::iterator i = preloadScripts.begin();
i != conf.preloadScripts.end(); ++i)
runCustomScript(*i);

View file

@ -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));
}

View file

@ -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

View file

@ -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")){

View file

@ -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

View file

@ -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 <iomanip>
#include <sstream>
#include <fstream>
#include <openssl/sha.h>
#include <SDL3/SDL_stdinc.h>
#include <locale>
#include <filesystem>
@ -27,49 +24,6 @@
#include <physfs.h>
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<int>( 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<std::string> mod_list = {};
try{
//1.check if any zip(mod) file, 2. calculate sha256 hash of zip(mod) files 3.mount mod via PhysFS
@ -93,8 +43,8 @@ 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();
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());
@ -102,13 +52,12 @@ void ModLoader(){
Debug() << "[MODLOADER] " << full;
mod_list.push_back(full);
mods_count++;
auto h = sha256_file(full);
buildID_tmp.append(h);
}else if(ext == ".rb"){
preloadScripts.insert(full);
Debug() << "[MODLOADER] Loading Preload Script: " << full;
preloaded_script_count++;
}
}
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());

View file

@ -1,5 +1,8 @@
//modloader bruh
#include <string>
#include <set>
void ModLoader();
inline bool modloader_is_enabled = false;
inline unsigned int mods_count = 0;
inline unsigned int preloaded_script_count = 0;
inline std::set<std::string> preloadScripts;