From a196581bbe16673c0707b733ab8182945437dd2d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 30 Jun 2021 19:41:18 -0400 Subject: [PATCH] Fix Furnace UI With gui_blocks Disabled --- VERSION | 2 +- docs/CHANGELOG.md | 3 + libreborn/include/libreborn/minecraft.h | 6 ++ mods/CMakeLists.txt | 9 +- mods/src/atlas/README.md | 2 + mods/src/atlas/atlas.cpp | 117 ++++++++++++++++++++++++ mods/src/init/init.c | 1 + mods/src/init/init.h | 1 + mods/src/textures/README.md | 4 +- mods/src/textures/textures.cpp | 59 +----------- 10 files changed, 142 insertions(+), 62 deletions(-) create mode 100644 mods/src/atlas/README.md create mode 100644 mods/src/atlas/atlas.cpp diff --git a/VERSION b/VERSION index 815e68dd2..09843e3be 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.8 +2.0.9 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 38e933718..59e2c84c8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**2.0.9** +* Fix Translucent Preview Items In Furnace UI Being Fully Opaque When The ``gui_blocks`` Atlas Is Disabled + **2.0.8** * Use Default Port In ``servers.txt`` If Not Specified diff --git a/libreborn/include/libreborn/minecraft.h b/libreborn/include/libreborn/minecraft.h index 2c9fa32d7..d20dc2025 100644 --- a/libreborn/include/libreborn/minecraft.h +++ b/libreborn/include/libreborn/minecraft.h @@ -411,6 +411,9 @@ static uint32_t TileEntity_id_property_offset = 0x18; // int32_t // ItemRenderer +typedef float (*ItemRenderer_renderGuiItem_t)(unsigned char *font, unsigned char *textures, unsigned char *item_instance, float param_1, float param_2, bool param_3); +static ItemRenderer_renderGuiItem_t ItemRenderer_renderGuiItem = (ItemRenderer_renderGuiItem_t) 0x63e58; + typedef float (*ItemRenderer_renderGuiItemCorrect_t)(unsigned char *font, unsigned char *textures, unsigned char *item_instance, int32_t param_1, int32_t param_2); static ItemRenderer_renderGuiItemCorrect_t ItemRenderer_renderGuiItemCorrect = (ItemRenderer_renderGuiItemCorrect_t) 0x639a0; @@ -422,6 +425,9 @@ static Tesselator_begin_t Tesselator_begin = (Tesselator_begin_t) 0x529d4; typedef void (*Tesselator_colorABGR_t)(unsigned char *tesselator, int32_t color); static Tesselator_colorABGR_t Tesselator_colorABGR = (Tesselator_colorABGR_t) 0x52b54; +typedef void (*Tesselator_color_t)(unsigned char *tesselator, int32_t r, int32_t g, int32_t b, int32_t a); +static Tesselator_color_t Tesselator_color = (Tesselator_color_t) 0x52a48; + // Method That Require C++ Types #ifdef __cplusplus diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 322ce4c92..04b650bcc 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -54,7 +54,10 @@ add_library(override SHARED src/override/override.c) target_link_libraries(override reborn dl home) add_library(textures SHARED src/textures/textures.cpp) -target_link_libraries(textures reborn feature GLESv1_CM) +target_link_libraries(textures reborn feature) + +add_library(atlas SHARED src/atlas/atlas.cpp) +target_link_libraries(atlas reborn feature GLESv1_CM) add_library(chat SHARED src/chat/chat.cpp src/chat/ui.c) target_link_libraries(chat reborn pthread) @@ -66,7 +69,7 @@ add_library(test SHARED src/test/test.c) target_link_libraries(test reborn home) add_library(init SHARED src/init/init.c) -target_link_libraries(init compat game-mode camera input sign misc death options touch textures chat home version test) +target_link_libraries(init compat game-mode camera input sign misc death options touch textures atlas chat home version test) if(MCPI_SERVER_MODE) target_link_libraries(init server) else() @@ -74,7 +77,7 @@ else() endif() ## Install Mods -install(TARGETS init compat readdir feature override game-mode camera input sign misc death options touch textures chat home version test DESTINATION "${MCPI_INSTALL_DIR}/mods") +install(TARGETS init compat readdir feature override game-mode camera input sign misc death options touch textures atlas chat home version test DESTINATION "${MCPI_INSTALL_DIR}/mods") if(MCPI_SERVER_MODE) install(TARGETS server DESTINATION "${MCPI_INSTALL_DIR}/mods") else() diff --git a/mods/src/atlas/README.md b/mods/src/atlas/README.md new file mode 100644 index 000000000..eb0bb9ecf --- /dev/null +++ b/mods/src/atlas/README.md @@ -0,0 +1,2 @@ +# ``atlas`` Mod +This mod allows disabling the ``gui_blocks`` atlas. diff --git a/mods/src/atlas/atlas.cpp b/mods/src/atlas/atlas.cpp new file mode 100644 index 000000000..dbea0fa69 --- /dev/null +++ b/mods/src/atlas/atlas.cpp @@ -0,0 +1,117 @@ +#include + +#include +#include + +#include "../feature/feature.h" +#include "../init/init.h" + +// Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled +static float ItemRenderer_renderGuiItemCorrect_injection(unsigned char *font, unsigned char *textures, unsigned char *item_instance, int32_t param_1, int32_t param_2) { + int32_t leaves_id = *(int32_t *) (*Tile_leaves + Tile_id_property_offset); + int32_t grass_id = *(int32_t *) (*Tile_grass + Tile_id_property_offset); + // Replace Rendered Item With Carried Variant + unsigned char *carried_item_instance = NULL; + if (item_instance != NULL) { + int32_t id = *(int32_t *) (item_instance + ItemInstance_id_property_offset); + int32_t count = *(int32_t *) (item_instance + ItemInstance_count_property_offset); + int32_t auxilary = *(int32_t *) (item_instance + ItemInstance_auxilary_property_offset); + if (id == leaves_id) { + carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE); + ALLOC_CHECK(carried_item_instance); + (*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_leaves_carried, count, auxilary); + } else if (id == grass_id) { + carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE); + ALLOC_CHECK(carried_item_instance); + (*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_grass_carried, count, auxilary); + } + } + + // Fix Toolbar Rendering + GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST); + glDisable(GL_DEPTH_TEST); + + // Call Original Method + float ret = (*ItemRenderer_renderGuiItemCorrect)(font, textures, carried_item_instance != NULL ? carried_item_instance : item_instance, param_1, param_2); + + // Revert GL State Changes + if (depth_test_was_enabled) { + glEnable(GL_DEPTH_TEST); + } + + // Free Carried Item Instance Variant + if (carried_item_instance != NULL) { + ::operator delete(carried_item_instance); + } + + // Return + return ret; +} + +// Fix Translucent Preview Items In Furnace UI Being Fully Opaque When The gui_blocks Atlas Is Disabled +static bool use_furnace_fix = false; +#define FURNACE_ITEM_TRANSPARENCY 0x33 +static void Tesselator_colorABGR_injection(unsigned char *tesselator, int32_t color) { + // Fix Furnace UI + if (use_furnace_fix) { + // Force Translucent + int32_t a = FURNACE_ITEM_TRANSPARENCY; + int32_t b = (color & 0x00ff0000) >> 16; + int32_t g = (color & 0x0000ff00) >> 8; + int32_t r = (color & 0x000000ff) >> 0; + // New Color + color = r | (g << 8) | (b << 16) | (a << 24); + } + + // Call Original Method + (*Tesselator_colorABGR)(tesselator, color); +} +static void Tesselator_begin_injection(unsigned char *tesselator, int32_t mode) { + // Call Original Method + (*Tesselator_begin)(tesselator, mode); + + // Fix Furnace UI + if (use_furnace_fix) { + // Implict Translucent + (*Tesselator_colorABGR_injection)(tesselator, 0xffffffff); + } +} +static void Tesselator_color_injection(unsigned char *tesselator, int32_t r, int32_t g, int32_t b, int32_t a) { + // Fix Furnace UI + if (use_furnace_fix) { + // Force Translucent + a = FURNACE_ITEM_TRANSPARENCY; + } + + // Call Original Method + (*Tesselator_color)(tesselator, r, g, b, a); +} +static float FurnaceScreen_render_ItemRenderer_renderGuiItem_injection(unsigned char *font, unsigned char *textures, unsigned char *item_instance, float param_1, float param_2, bool param_3) { + // Enable Furnace UI Fix + use_furnace_fix = true; + + // Call Original Method + float ret = (*ItemRenderer_renderGuiItem)(font, textures, item_instance, param_1, param_2, param_3); + + // Disable Furnace UI Fix + use_furnace_fix = false; + + // Return + return ret; +} + +// Init +void init_atlas() { + // Disable The gui_blocks Atlas Which Contains Pre-Rendered Textures For Blocks In The Inventory + if (feature_has("Disable gui_blocks Atlas")) { + unsigned char disable_gui_blocks_atlas_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" + patch((void *) 0x63c2c, disable_gui_blocks_atlas_patch); + // Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled + overwrite_calls((void *) ItemRenderer_renderGuiItemCorrect, (void *) ItemRenderer_renderGuiItemCorrect_injection); + // Fix Furnace UI + overwrite_calls((void *) Tesselator_colorABGR, (void *) Tesselator_colorABGR_injection); + overwrite_calls((void *) Tesselator_begin, (void *) Tesselator_begin_injection); + overwrite_calls((void *) Tesselator_color, (void *) Tesselator_color_injection); + overwrite_call((void *) 0x32324, (void *) FurnaceScreen_render_ItemRenderer_renderGuiItem_injection); + } +} diff --git a/mods/src/init/init.c b/mods/src/init/init.c index 65c7ae8f3..6c61606d3 100644 --- a/mods/src/init/init.c +++ b/mods/src/init/init.c @@ -17,6 +17,7 @@ __attribute__((constructor)) static void init() { init_options(); init_touch(); init_textures(); + init_atlas(); init_chat(); init_home(); init_version(); diff --git a/mods/src/init/init.h b/mods/src/init/init.h index 95e6668db..ecde1af72 100644 --- a/mods/src/init/init.h +++ b/mods/src/init/init.h @@ -20,6 +20,7 @@ void init_camera(); void init_options(); void init_touch(); void init_textures(); +void init_atlas(); void init_chat(); void init_home(); void init_version(); diff --git a/mods/src/textures/README.md b/mods/src/textures/README.md index 8b9cce4a3..49ffa51a8 100644 --- a/mods/src/textures/README.md +++ b/mods/src/textures/README.md @@ -1,4 +1,2 @@ # ``textures`` Mod -This mod includes various features involving textures, including: -- Animated Water -- Disabling The ``gui_blocks`` Atlas +This mod enables the animated water texture. diff --git a/mods/src/textures/textures.cpp b/mods/src/textures/textures.cpp index 1007e64da..2aefe9d5d 100644 --- a/mods/src/textures/textures.cpp +++ b/mods/src/textures/textures.cpp @@ -1,12 +1,10 @@ -#include - #include +#include #include "../feature/feature.h" #include "../init/init.h" -#include - +// Animated Water static void Minecraft_tick_injection(unsigned char *minecraft, int32_t param_1, int32_t param_2) { // Call Original Method (*Minecraft_tick)(minecraft, param_1, param_2); @@ -18,59 +16,10 @@ static void Minecraft_tick_injection(unsigned char *minecraft, int32_t param_1, } } -// Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled -static float ItemRenderer_renderGuiItemCorrect_injection(unsigned char *font, unsigned char *textures, unsigned char *item_instance, int32_t param_1, int32_t param_2) { - int32_t leaves_id = *(int32_t *) (*Tile_leaves + Tile_id_property_offset); - int32_t grass_id = *(int32_t *) (*Tile_grass + Tile_id_property_offset); - // Replace Rendered Item With Carried Variant - unsigned char *carried_item_instance = NULL; - if (item_instance != NULL) { - int32_t id = *(int32_t *) (item_instance + ItemInstance_id_property_offset); - int32_t count = *(int32_t *) (item_instance + ItemInstance_count_property_offset); - int32_t auxilary = *(int32_t *) (item_instance + ItemInstance_auxilary_property_offset); - if (id == leaves_id) { - carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE); - ALLOC_CHECK(carried_item_instance); - (*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_leaves_carried, count, auxilary); - } else if (id == grass_id) { - carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE); - ALLOC_CHECK(carried_item_instance); - (*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_grass_carried, count, auxilary); - } - } - - // Fix Toolbar Rendering - GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST); - glDisable(GL_DEPTH_TEST); - - // Call Original Method - float ret = (*ItemRenderer_renderGuiItemCorrect)(font, textures, carried_item_instance != NULL ? carried_item_instance : item_instance, param_1, param_2); - - // Revert GL State Changes - if (depth_test_was_enabled) { - glEnable(GL_DEPTH_TEST); - } - - // Free Carried Item Instance Variant - if (carried_item_instance != NULL) { - ::operator delete(carried_item_instance); - } - - // Return - return ret; -} - +// Init void init_textures() { + // Tick Dynamic Textures (Animated Water) if (feature_has("Animated Water")) { - // Tick Dynamic Textures (Animated Water) overwrite_calls((void *) Minecraft_tick, (void *) Minecraft_tick_injection); } - - if (feature_has("Disable gui_blocks Atlas")) { - // Disable gui_blocks Atlas Which Contains Pre-Rendered Textures For Blocks In The Inventory - unsigned char disable_gui_blocks_atlas_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" - patch((void *) 0x63c2c, disable_gui_blocks_atlas_patch); - // Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled - overwrite_calls((void *) ItemRenderer_renderGuiItemCorrect, (void *) ItemRenderer_renderGuiItemCorrect_injection); - } }