Fix Bugs When Disabling gui_blocks Atlas; Fix Selected Item Text
minecraft-pi-docker/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-12-02 16:29:04 -05:00
parent 6e18ee44fb
commit 43b1231153
5 changed files with 130 additions and 23 deletions

View File

@ -16,7 +16,7 @@ MCPI_FEATURES="$(zenity --class 'Minecraft - Pi edition' --list --checklist --co
FALSE 'Peaceful Mode' \
TRUE 'Animated Water' \
TRUE 'Remove Invalid Item Background' \
FALSE 'Disable gui_blocks Atlas' \
TRUE 'Disable gui_blocks Atlas' \
TRUE 'Smooth Lighting' \
FALSE '3D Anaglyph')"
MCPI_USERNAME="$(zenity --class 'Minecraft - Pi edition' --entry --text 'Minecraft Username:' --entry-text 'StevePi')"

View File

@ -20,7 +20,7 @@ add_library(screenshot SHARED src/screenshot/screenshot.c)
target_link_libraries(screenshot GLESv1_CM freeimage)
add_library(extra SHARED src/extra.c src/extra.cpp src/cxx11_util.cpp)
target_link_libraries(extra core dl server screenshot)
target_link_libraries(extra core dl server screenshot GLESv1_CM)
add_library(override SHARED src/override.c)
target_link_libraries(override dl)

View File

@ -70,10 +70,13 @@ static void Minecraft_tickInput_injection(unsigned char *minecraft) {
#include <SDL/SDL_events.h>
// Block UI Interaction When Mouse Is Locked
static void Gui_tickItemDrop_injection(unsigned char *this) {
static int32_t Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(unsigned char *minecraft) {
if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) {
// Call Original Method
(*Gui_tickItemDrop)(this);
return (*Minecraft_isCreativeMode)(minecraft);
} else {
// Disable Item Drop Ticking
return 1;
}
}
@ -242,7 +245,7 @@ __attribute__((constructor)) static void init() {
overwrite_calls((void *) Minecraft_setIsCreativeMode, Minecraft_setIsCreativeMode_injection);
// Disable Item Dropping Using The Cursor When Cursor Is Hidden
overwrite_calls((void *) Gui_tickItemDrop, Gui_tickItemDrop_injection);
overwrite_call((void *) 0x27800, Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection);
// Disable Opening Inventory Using The Cursor When Cursor Is Hidden
overwrite_calls((void *) Gui_handleClick, Gui_handleClick_injection);
@ -313,12 +316,6 @@ __attribute__((constructor)) static void init() {
patch((void *) 0x63c98, invalid_item_background_patch);
}
if (extra_has_feature("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};
patch((void *) 0x63c2c, disable_gui_blocks_atlas_patch);
}
smooth_lighting = extra_has_feature("Smooth Lighting");
if (smooth_lighting) {
// Enable Smooth Lighting

View File

@ -5,6 +5,8 @@
#include <unistd.h>
#include <GLES/gl.h>
#include <libcore/libcore.h>
#include "extra.h"
@ -77,13 +79,15 @@ extern "C" {
extra_clear_input();
}
#define ITEM_INSTANCE_SIZE 0xc
static void inventory_add_item(unsigned char *inventory, unsigned char *item, bool is_tile) {
unsigned char *item_instance = (unsigned char *) ::operator new(0xc);
item_instance = (*(is_tile ? ItemInstance_tile : ItemInstance_item))(item_instance, item);
unsigned char *item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE);
item_instance = (*(is_tile ? ItemInstance_constructor_tile : ItemInstance_constructor_item))(item_instance, item);
(*FillingContainer_addItem)(inventory, item_instance);
}
static int32_t FillingContainer_addItem_injection(unsigned char *filling_container, unsigned char *item_instance) {
static int32_t Inventory_setupDefault_FillingContainer_addItem_call_injection(unsigned char *filling_container, unsigned char *item_instance) {
// Call Original
int32_t ret = (*FillingContainer_addItem)(filling_container, item_instance);
@ -94,7 +98,7 @@ extern "C" {
inventory_add_item(filling_container, *Item_shears, false);
for (int i = 0; i < 15; i++) {
unsigned char *item_instance = (unsigned char *) ::operator new(0xc);
item_instance = (*ItemInstance_damage)(item_instance, *Item_dye_powder, 1, i);
item_instance = (*ItemInstance_constructor_item_extra)(item_instance, *Item_dye_powder, 1, i);
(*FillingContainer_addItem)(filling_container, item_instance);
}
inventory_add_item(filling_container, *Item_camera, false);
@ -186,6 +190,73 @@ extern "C" {
(*Level_addParticle)(level, particle, x, y + 0.5, z, deltaX, deltaY, deltaZ, count);
}
// 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 + 0x8);
int32_t grass_id = *(int32_t *) (*Tile_grass + 0x8);
// Replace Rendered Item With Carried Variant
unsigned char *carried_item_instance = NULL;
if (item_instance != NULL) {
int32_t id = *(int32_t *) (item_instance + 0x4);
int32_t count = *(int32_t *) item_instance;
int32_t auxilary = *(int32_t *) (item_instance + 0x8);
if (id == leaves_id) {
carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE);
(*ItemInstance_constructor_title_extra)(carried_item_instance, *Tile_leaves_carried, count, auxilary);
} else if (id == grass_id) {
carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE);
(*ItemInstance_constructor_title_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;
}
// Render Selected Item Text
static void Gui_renderChatMessages_injection(unsigned char *gui, int32_t param_1, uint32_t param_2, bool param_3, unsigned char *font) {
// Call Original Method
(*Gui_renderChatMessages)(gui, param_1, param_2, param_3, font);
// Calculate Selected Item Text Scale
unsigned char *minecraft = *(unsigned char **) (gui + 0x9f4);
int32_t screen_width = *(int32_t *) (minecraft + 0x20);
float scale = ((float) screen_width) * *InvGuiScale;
// Render Selected Item Text
(*Gui_renderOnSelectItemNameText)(gui, (int32_t) scale, font, param_1 - 0x13);
}
// Reset Selected Item Text Timer On Slot Select
static bool reset_selected_item_text_timer = false;
static void Gui_tick_injection(unsigned char *gui) {
// Call Original Method
(*Gui_tick)(gui);
// Handle Reset
float *selected_item_text_timer = (float *) (gui + 0x9fc);
if (reset_selected_item_text_timer) {
// Reset
*selected_item_text_timer = 0;
reset_selected_item_text_timer = false;
}
}
// Trigger Reset Selected Item Text Timer On Slot Select
static void Inventory_selectSlot_injection(unsigned char *inventory, int32_t slot) {
// Call Original Method
(*Inventory_selectSlot)(inventory, slot);
// Trigger Reset Selected Item Text Timer
reset_selected_item_text_timer = true;
}
__attribute((constructor)) static void init() {
// Implement AppPlatform::readAssetFile So Translations Work
overwrite((void *) AppPlatform_readAssetFile, (void *) AppPlatform_readAssetFile_injection);
@ -205,7 +276,7 @@ extern "C" {
if (extra_has_feature("Expand Creative Inventory")) {
// Add Extra Items To Creative Inventory (Only Replace Specific Function Call)
overwrite_call((void *) 0x8e0fc, (void *) FillingContainer_addItem_injection);
overwrite_call((void *) 0x8e0fc, (void *) Inventory_setupDefault_FillingContainer_addItem_call_injection);
}
if (extra_has_feature("Animated Water")) {
@ -219,5 +290,18 @@ extern "C" {
// Make The SimpleChooseLevelScreen Back Button Go To SelectWorldScreen Instead Of StartMenuScreen
unsigned char simple_choose_level_screen_back_button_patch[4] = {0x05, 0x10, 0xa0, 0xe3};
patch((void *) 0x31144, simple_choose_level_screen_back_button_patch);
if (extra_has_feature("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};
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 Selected Item Text
overwrite_calls((void *) Gui_renderChatMessages, (void *) Gui_renderChatMessages_injection);
overwrite_calls((void *) Gui_tick, (void *) Gui_tick_injection);
overwrite_calls((void *) Inventory_selectSlot, (void *) Inventory_selectSlot_injection);
}
}

View File

@ -28,6 +28,13 @@ static unsigned char **Tile_topSnow = (unsigned char **) 0x181b30;
static unsigned char **Tile_ice = (unsigned char **) 0x181d80;
static unsigned char **Tile_invisible_bedrock = (unsigned char **) 0x181d94;
static unsigned char **Tile_leaves = (unsigned char **) 0x18120c;
static unsigned char **Tile_leaves_carried = (unsigned char **) 0x181dd8;
static unsigned char **Tile_grass = (unsigned char **) 0x181b14;
static unsigned char **Tile_grass_carried = (unsigned char **) 0x181dd4;
static float *InvGuiScale = (float *) 0x135d98;
typedef long int (*getRemainingFileSize_t)(FILE *file);
static getRemainingFileSize_t getRemainingFileSize = (getRemainingFileSize_t) 0xba520;
@ -94,6 +101,9 @@ static Minecraft_getProgressMessage_t Minecraft_getProgressMessage = (Minecraft_
typedef uint32_t (*Minecraft_isLevelGenerated_t)(unsigned char *minecraft);
static Minecraft_isLevelGenerated_t Minecraft_isLevelGenerated = (Minecraft_isLevelGenerated_t) 0x16e6c;
typedef int32_t (*Minecraft_isCreativeMode_t)(unsigned char *minecraft);
static Minecraft_isCreativeMode_t Minecraft_isCreativeMode = (Minecraft_isCreativeMode_t) 0x17270;
// MouseBuildInput
typedef int32_t (*MouseBuildInput_tickBuild_t)(unsigned char *mouse_build_input, unsigned char *player, uint32_t *build_action_intention_return);
@ -114,12 +124,15 @@ static void *LocalPlayer_openTextEdit_vtable_addr = (void *) 0x106460;
// Gui
typedef void (*Gui_tickItemDrop_t)(unsigned char *gui);
static Gui_tickItemDrop_t Gui_tickItemDrop = (Gui_tickItemDrop_t) 0x27778;
typedef void (*Gui_tick_t)(unsigned char *gui);
static Gui_tick_t Gui_tick = (Gui_tick_t) 0x27778;
typedef void (*Gui_handleClick_t)(unsigned char *gui, int32_t param_2, int32_t param_3, int32_t param_4);
static Gui_handleClick_t Gui_handleClick = (Gui_handleClick_t) 0x2599c;
typedef void (*Gui_renderOnSelectItemNameText_t)(unsigned char *gui, int32_t param_1, unsigned char *font, int32_t param_2);
static Gui_renderOnSelectItemNameText_t Gui_renderOnSelectItemNameText = (Gui_renderOnSelectItemNameText_t) 0x26aec;
// GameMode Constructors
static void *Creator = (void *) 0x1a044;
@ -170,11 +183,13 @@ static void *Touch_SelectWorldScreen_tick_vtable_addr = (void *) 0x105780;
// ItemInstance
typedef unsigned char *(*ItemInstance_t)(unsigned char *item_instance, unsigned char *item);
static ItemInstance_t ItemInstance_item = (ItemInstance_t) 0x9992c;
static ItemInstance_t ItemInstance_tile = (ItemInstance_t) 0x998e4;
typedef unsigned char *(*ItemInstance_damage_t)(unsigned char *item_instance, unsigned char *item, int32_t count, int32_t damage);
static ItemInstance_damage_t ItemInstance_damage = (ItemInstance_damage_t) 0x99960;
typedef unsigned char *(*ItemInstance_constructor_t)(unsigned char *item_instance, unsigned char *item);
static ItemInstance_constructor_t ItemInstance_constructor_item = (ItemInstance_constructor_t) 0x9992c;
static ItemInstance_constructor_t ItemInstance_constructor_tile = (ItemInstance_constructor_t) 0x998e4;
typedef unsigned char *(*ItemInstance_constructor_extra_t)(unsigned char *item_instance, unsigned char *item, int32_t count, int32_t auxilary);
static ItemInstance_constructor_extra_t ItemInstance_constructor_title_extra = (ItemInstance_constructor_extra_t) 0x99918;
static ItemInstance_constructor_extra_t ItemInstance_constructor_item_extra = (ItemInstance_constructor_extra_t) 0x99960;
// FillingContainer
@ -248,6 +263,9 @@ static NbtIo_read_t NbtIo_read = (NbtIo_read_t) 0xb98cc;
typedef void (*Inventory_clearInventoryWithDefault_t)(unsigned char *inventory);
static Inventory_clearInventoryWithDefault_t Inventory_clearInventoryWithDefault = (Inventory_clearInventoryWithDefault_t) 0x8e7c8;
typedef void (*Inventory_selectSlot_t)(unsigned char *inventory, int32_t slot);
static Inventory_selectSlot_t Inventory_selectSlot = (Inventory_selectSlot_t) 0x8d13c;
// TripodCameraRenderer
typedef unsigned char *(*TripodCameraRenderer_t)(unsigned char *renderer);
@ -261,6 +279,11 @@ static EntityRenderDispatcher_t EntityRenderDispatcher = (EntityRenderDispatcher
typedef void (*EntityRenderDispatcher_assign_t)(unsigned char *dispatcher, unsigned char entity_id, unsigned char *renderer);
static EntityRenderDispatcher_assign_t EntityRenderDispatcher_assign = (EntityRenderDispatcher_assign_t) 0x6094c;
// ItemRenderer
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;
// Method That Require C++ Types
#ifdef __cplusplus
@ -294,6 +317,9 @@ static Level_addParticle_t Level_addParticle = (Level_addParticle_t) 0xa449c;
typedef void (*Gui_addMessage_t)(unsigned char *gui, std::string const& text);
static Gui_addMessage_t Gui_addMessage = (Gui_addMessage_t) 0x27820;
typedef void (*Gui_renderChatMessages_t)(unsigned char *gui, int32_t param_1, uint32_t param_2, bool param_3, unsigned char *font);
static Gui_renderChatMessages_t Gui_renderChatMessages = (Gui_renderChatMessages_t) 0x273d8;
// Textures
typedef void (*Textures_tick_t)(unsigned char *textures, bool param_1);