Fix Furnace UI With gui_blocks Disabled
All checks were successful
minecraft-pi-reborn/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2021-06-30 19:41:18 -04:00
parent b32c6013fb
commit a196581bbe
10 changed files with 142 additions and 62 deletions

View File

@ -1 +1 @@
2.0.8
2.0.9

View File

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

View File

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

View File

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

2
mods/src/atlas/README.md Normal file
View File

@ -0,0 +1,2 @@
# ``atlas`` Mod
This mod allows disabling the ``gui_blocks`` atlas.

117
mods/src/atlas/atlas.cpp Normal file
View File

@ -0,0 +1,117 @@
#include <GLES/gl.h>
#include <libreborn/libreborn.h>
#include <libreborn/minecraft.h>
#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);
}
}

View File

@ -17,6 +17,7 @@ __attribute__((constructor)) static void init() {
init_options();
init_touch();
init_textures();
init_atlas();
init_chat();
init_home();
init_version();

View File

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

View File

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

View File

@ -1,12 +1,10 @@
#include <GLES/gl.h>
#include <libreborn/libreborn.h>
#include <libreborn/minecraft.h>
#include "../feature/feature.h"
#include "../init/init.h"
#include <libreborn/minecraft.h>
// 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);
}
}