From 1aff0121d5b91da24f9c2d9adbbfd1c22215c96d Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Fri, 7 May 2021 21:55:52 +0000 Subject: [PATCH] [WIP] Fixed loaded of multiple addons at the same time --- src/moon/mod-engine/engine.cpp | 47 +++++++++++++++++-- src/moon/mod-engine/engine.h | 12 +++-- src/moon/mod-engine/interfaces/bit-module.h | 1 + .../screens/options/categories/mtextures.cpp | 32 +++++++++++++ .../ui/screens/options/categories/mtextures.h | 13 +++++ src/moon/ui/screens/options/main-view.cpp | 2 + 6 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/moon/ui/screens/options/categories/mtextures.cpp create mode 100644 src/moon/ui/screens/options/categories/mtextures.h diff --git a/src/moon/mod-engine/engine.cpp b/src/moon/mod-engine/engine.cpp index 59bd1945..bc0df039 100644 --- a/src/moon/mod-engine/engine.cpp +++ b/src/moon/mod-engine/engine.cpp @@ -1,6 +1,6 @@ +#include "engine.h" #include "moon/mod-engine/interfaces/mod-module.h" #include "moon/mod-engine/modules/test-module.h" -#include "moon/mod-engine/interfaces/bit-module.h" #include "interfaces/file-entry.h" #include "moon/wrapper.h" @@ -14,7 +14,6 @@ using json = nlohmann::json; #include #include #include -#include #include using namespace std; @@ -45,7 +44,6 @@ void Moon_LoadDefaultAddon(){ Moon_LoadAddonTextures(bit); } - void Moon_LoadAddon(string path){ miniz_cpp::zip_file file(path); @@ -68,6 +66,15 @@ void Moon_LoadAddon(string path){ std::cout << file.read(bit->main) << std::endl; } + if(file.has_file(bit->icon)){ + vector allowedTextures = {"png", "jpg", "jpeg"}; + if(std::count(allowedTextures.begin(), allowedTextures.end(), string(get_filename_ext(bit->icon.c_str())))){ + TextureFileEntry *entry = new TextureFileEntry(); + file.read_texture(bit->icon, &entry); + bit->textures.insert(pair("mod-icons://"+bit->name, entry)); + } + } + if(file.has_file("assets/")){ for(auto &name : file.namelist()){ string graphicsPath = "assets/graphics/"; @@ -159,10 +166,42 @@ TextureData* Moon_GetTexture(string texture){ return textureMap.find(texture) != textureMap.end() ? textureMap.find(texture)->second : nullptr; } +void Moon_TextFlyLoad(int id){ + switch(id){ + case 0: + Moon_LoadDefaultAddon(); + break; + case 1: + Moon_LoadDefaultAddon(); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/mc.bit"); + + Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit"); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit"); + break; + case 2: + Moon_LoadDefaultAddon(); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/owo.bit"); + + Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit"); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit"); + break; + case 3: + Moon_LoadDefaultAddon(); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/r96-hd.bit"); + + Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit"); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit"); + break; + } +} + void Moon_PreInitModEngine(){ Moon_LoadDefaultAddon(); - // Moon_LoadAddon("/home/alex/disks/uwu/Projects/UnderVolt/example.bit"); Moon_LoadAddon("/home/alex/Downloads/packs/converted/mc.bit"); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/owo.bit"); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/r96-hd.bit"); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit"); + Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit"); } void Moon_InitModEngine(){ diff --git a/src/moon/mod-engine/engine.h b/src/moon/mod-engine/engine.h index c90e51f4..faf20aed 100644 --- a/src/moon/mod-engine/engine.h +++ b/src/moon/mod-engine/engine.h @@ -1,15 +1,21 @@ #ifndef Moon64ModEngine #define Moon64ModEngine +#include "moon/mod-engine/interfaces/bit-module.h" +#include + extern "C" { #include "pc/gfx/gfx_pc.h" } -void Moon_SaveTexture(TextureData* data, string tex); -TextureData* Moon_GetTexture(string texture); +extern std::vector addons; + +void Moon_SaveTexture(TextureData* data, std::string tex); +TextureData* Moon_GetTexture(std::string texture); void Moon_PreInitModEngine(); void Moon_InitModEngine(); -void Moon_LoadBaseTexture(char* data, long size, string texture); +void Moon_LoadBaseTexture(char* data, long size, std::string texture); +void Moon_TextFlyLoad(int id); #endif \ No newline at end of file diff --git a/src/moon/mod-engine/interfaces/bit-module.h b/src/moon/mod-engine/interfaces/bit-module.h index 2a986105..2e684574 100644 --- a/src/moon/mod-engine/interfaces/bit-module.h +++ b/src/moon/mod-engine/interfaces/bit-module.h @@ -21,6 +21,7 @@ public: std::map textures; // GFXTextureCache* textureCache; bool readOnly; + bool enabled; }; #endif \ No newline at end of file diff --git a/src/moon/ui/screens/options/categories/mtextures.cpp b/src/moon/ui/screens/options/categories/mtextures.cpp new file mode 100644 index 00000000..36a54a12 --- /dev/null +++ b/src/moon/ui/screens/options/categories/mtextures.cpp @@ -0,0 +1,32 @@ +#include "mtextures.h" + +#include "moon/network/moon-consumer.h" +#include "moon/texts/moon-loader.h" +#include "moon/ui/widgets/mw-value.h" +#include "moon/mod-engine/engine.h" + +using namespace std; + +extern "C" { +#include "pc/configfile.h" +} + +MTexturesCategory::MTexturesCategory() : MoonCategory("TEXT_OPT_AUDIO"){ + int idx = 0; + // for(auto &addon : addons){ + // this->catOptions.push_back(new MWValue(22, 57 + (17 * idx), addon->name, {.bvar = &addon->enabled}, false)); + // idx++; + // } + this->catOptions.push_back(new MWValue(22, 57, "Load main pack", {.btn = [](){ + Moon_TextFlyLoad(0); + }}, false)); + this->catOptions.push_back(new MWValue(22, 57 + (17 * 1), "Load minecraft pack", {.btn = [](){ + Moon_TextFlyLoad(1); + }}, false)); + this->catOptions.push_back(new MWValue(22, 57 + (17 * 2), "Load owo pack", {.btn = [](){ + Moon_TextFlyLoad(2); + }}, false)); + this->catOptions.push_back(new MWValue(22, 57 + (17 * 3), "Load Render96 pack", {.btn = [](){ + Moon_TextFlyLoad(2); + }}, false)); +} \ No newline at end of file diff --git a/src/moon/ui/screens/options/categories/mtextures.h b/src/moon/ui/screens/options/categories/mtextures.h new file mode 100644 index 00000000..1589f010 --- /dev/null +++ b/src/moon/ui/screens/options/categories/mtextures.h @@ -0,0 +1,13 @@ +#ifndef MoonTexturesCategory +#define MoonTexturesCategory + +#include "mcategory.h" +#include +#include + +class MTexturesCategory : public MoonCategory { +public: + MTexturesCategory(); +}; + +#endif \ No newline at end of file diff --git a/src/moon/ui/screens/options/main-view.cpp b/src/moon/ui/screens/options/main-view.cpp index 52e36646..145dcc69 100644 --- a/src/moon/ui/screens/options/main-view.cpp +++ b/src/moon/ui/screens/options/main-view.cpp @@ -14,6 +14,7 @@ #ifdef BETTERCAMERA #include "moon/ui/screens/options/categories/mcamera.h" #endif +#include "moon/ui/screens/options/categories/mtextures.h" #include "moon/io/moon-io.h" #include "moon/io/modules/mouse-io.h" @@ -49,6 +50,7 @@ void MoonOptMain::Mount(){ categories.push_back(new MVideoCategory()); categories.push_back(new MAudioCategory()); categories.push_back(new MCheatsCategory()); + categories.push_back(new MTexturesCategory()); this->setCategory(categoryIndex); MoonScreen::Mount(); }