diff --git a/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags b/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags index 97d0d3a..f7224e1 100644 --- a/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags +++ b/launcher/data/client/lib/minecraft-pi-reborn-client/available-feature-flags @@ -1,4 +1,4 @@ -TRUE Touch GUI +FALSE Full Touch GUI TRUE Fix Bow & Arrow TRUE Fix Attacking FALSE Force Mob Spawning @@ -31,6 +31,8 @@ TRUE Fix Furnace Not Checking Item Auxiliary TRUE Improved Cursor Rendering FALSE Disable V-Sync TRUE Fix Options Screen -FALSE Force Touch Inventory +TRUE Force Touch GUI Inventory TRUE Fix Pause Menu TRUE Improved Title Background +TRUE Force Touch GUI Button Behavior +TRUE Improved Button Hover Behavior diff --git a/mods/src/touch/touch.cpp b/mods/src/touch/touch.cpp index 57fc454..4136049 100644 --- a/mods/src/touch/touch.cpp +++ b/mods/src/touch/touch.cpp @@ -15,9 +15,35 @@ static unsigned char *operator_new_IngameBlockSelectionScreen_injection(__attrib return (unsigned char *) ::operator new(TOUCH_INGAME_BLOCK_SELECTION_SCREEN_SIZE); } +// Improved Button Hover Behavior +static int32_t Button_hovered_injection(__attribute__((unused)) unsigned char *button, __attribute__((unused)) unsigned char *minecraft, __attribute__((unused)) int32_t click_x, __attribute__((unused)) int32_t click_y) { + // Get Mouse Position + int32_t x = (*Mouse_getX)() * (*InvGuiScale); + int32_t y = (*Mouse_getY)() * (*InvGuiScale); + + // Get Button Position + int32_t button_x1 = *(int32_t *) (button + Button_x_property_offset); + int32_t button_y1 = *(int32_t *) (button + Button_y_property_offset); + int32_t button_x2 = button_x1 + (*(int32_t *) (button + Button_width_property_offset)); + int32_t button_y2 = button_y1 + (*(int32_t *) (button + Button_height_property_offset)); + + // Check + return x >= button_x1 && x <= button_x2 && y >= button_y1 && y <= button_y2; +} +static void LargeImageButton_render_GuiComponent_drawCenteredString_injection(unsigned char *component, unsigned char *font, std::string const& text, int32_t x, int32_t y, int32_t color) { + // Change Color On Hover + if (Button_hovered_injection(component, NULL, 0, 0)) { + color = 0x000ffffa0; + } + + // Call Original Method + (*GuiComponent_drawCenteredString)(component, font, text, x, y, color); +} + // Init void init_touch() { - int touch_gui = feature_has("Touch GUI", server_disabled); + int touch_gui = feature_has("Full Touch GUI", server_disabled); + int touch_buttons = touch_gui; if (touch_gui) { // Main UI overwrite((void *) Minecraft_isTouchscreen, (void *) Minecraft_isTouchscreen_injection); @@ -25,16 +51,37 @@ void init_touch() { // Force Correct Toolbar Size unsigned char toolbar_patch[4] = {0x01, 0x00, 0x50, 0xe3}; // "cmp r0, #0x1" patch((void *) 0x257b0, toolbar_patch); + } else { + // Force Touch Inventory + if (feature_has("Force Touch GUI Inventory", server_disabled)) { + overwrite_call((void *) 0x2943c, (void *) operator_new_IngameBlockSelectionScreen_injection); + overwrite_call((void *) 0x29444, (void *) Touch_IngameBlockSelectionScreen); + } + + // Force Touch Button Behavior + if (feature_has("Force Touch GUI Button Behavior", server_disabled)) { + touch_buttons = 1; + overwrite_call((void *) 0x1baf4, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x1be40, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x1c470, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x1e868, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x290b8, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x29168, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x3e314, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x2cbc0, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x2ea7c, (void *) Minecraft_isTouchscreen_injection); + overwrite_call((void *) 0x4a438, (void *) Minecraft_isTouchscreen_injection); + } + } + + // Improved Button Hover Behavior + if (touch_buttons && feature_has("Improved Button Hover Behavior", server_disabled)) { + overwrite((void *) Button_hovered, (void *) Button_hovered_injection); + overwrite_call((void *) 0x1ebd4, (void *) LargeImageButton_render_GuiComponent_drawCenteredString_injection); } // Show Block Outlines int block_outlines = feature_has("Show Block Outlines", 0); unsigned char outline_patch[4] = {(unsigned char) (block_outlines ? !touch_gui : touch_gui), 0x00, 0x50, 0xe3}; // "cmp r0, #0x1" or "cmp r0, #0x0" patch((void *) 0x4a210, outline_patch); - - // Force Touch Inventory - if (feature_has("Force Touch Inventory", server_disabled)) { - overwrite_call((void *) 0x2943c, (void *) operator_new_IngameBlockSelectionScreen_injection); - overwrite_call((void *) 0x29444, (void *) Touch_IngameBlockSelectionScreen); - } } diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index 22def5b..000e950 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -497,6 +497,16 @@ static uint32_t Screen_selectable_buttons_property_offset = 0x30; // std::vector static uint32_t Screen_width_property_offset = 0x8; // int32_t static uint32_t Screen_height_property_offset = 0xc; // int32_t +// Button + +typedef int32_t (*Button_hovered_t)(unsigned char *button, unsigned char *minecraft, int32_t click_x, int32_t click_y); +static Button_hovered_t Button_hovered = (Button_hovered_t) 0x1be2c; + +static uint32_t Button_width_property_offset = 0x14; // int32_t +static uint32_t Button_height_property_offset = 0x18; // int32_t +static uint32_t Button_x_property_offset = 0xc; // int32_t +static uint32_t Button_y_property_offset = 0x10; // int32_t + // StartMenuScreen static Screen_init_t StartMenuScreen_init = (Screen_init_t) 0x39cc0; @@ -764,6 +774,11 @@ 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; +// GuiComponent + +typedef void (*GuiComponent_drawCenteredString_t)(unsigned char *component, unsigned char *font, std::string const& text, int32_t x, int32_t y, int32_t color); +static GuiComponent_drawCenteredString_t GuiComponent_drawCenteredString = (GuiComponent_drawCenteredString_t) 0x2821c; + // ServerSideNetworkHandler typedef void (*ServerSideNetworkHandler_displayGameMessage_t)(unsigned char *server_side_network_handler, std::string const& message);