diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index 6dc7645..c8f9616 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -39,3 +39,4 @@ TRUE Improved Button Hover Behavior TRUE Implement Create World Dialog FALSE Remove Forced GUI Lag (Can Break Joining Servers) TRUE Add Buckets +TRUE Classic HUD diff --git a/mods/src/misc/misc.c b/mods/src/misc/misc.c index c2ba0fe..ab77870 100644 --- a/mods/src/misc/misc.c +++ b/mods/src/misc/misc.c @@ -15,13 +15,54 @@ #include "misc-internal.h" #include -// Maximum Username Length -#define MAX_USERNAME_LENGTH 16 +// Classic HUD +#define DEFAULT_HUD_PADDING 2 +#define HUD_ELEMENT_WIDTH 82 +#define HUD_ELEMENT_HEIGHT 9 +#define DEFAULT_BUBBLES_PADDING 1 +#define NUMBER_OF_SLOTS 9 +static int use_classic_hud = 0; +static void Gui_renderHearts_GuiComponent_blit_hearts_injection(unsigned char *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { + unsigned char *minecraft = *(unsigned char **) (component + Gui_minecraft_property_offset); + x_dest -= DEFAULT_HUD_PADDING; + x_dest += NUMBER_OF_SLOTS * -10 + ((((float) *(int32_t *) (minecraft + Minecraft_screen_width_property_offset)) * *InvGuiScale) / 2); + y_dest -= DEFAULT_HUD_PADDING; + y_dest += (((float) *(int32_t *) (minecraft + Minecraft_screen_height_property_offset)) * *InvGuiScale) - 31; + // Call Original Method + (*GuiComponent_blit)(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); +} +static void Gui_renderHearts_GuiComponent_blit_armor_injection(unsigned char *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { + unsigned char *minecraft = *(unsigned char **) (component + Gui_minecraft_property_offset); + x_dest -= DEFAULT_HUD_PADDING + HUD_ELEMENT_WIDTH; + float width = ((float) *(int32_t *) (minecraft + Minecraft_screen_width_property_offset)) * *InvGuiScale; + x_dest += width - (NUMBER_OF_SLOTS * -10 + (width / 2)) - HUD_ELEMENT_WIDTH; + y_dest -= DEFAULT_HUD_PADDING; + y_dest += (((float) *(int32_t *) (minecraft + Minecraft_screen_height_property_offset)) * *InvGuiScale) - 31; + // Call Original Method + (*GuiComponent_blit)(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); +} +static void Gui_renderBubbles_GuiComponent_blit_injection(unsigned char *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { + unsigned char *minecraft = *(unsigned char **) (component + Gui_minecraft_property_offset); + x_dest -= DEFAULT_HUD_PADDING; + x_dest += NUMBER_OF_SLOTS * -10 + ((((float) *(int32_t *) (minecraft + Minecraft_screen_width_property_offset)) * *InvGuiScale) / 2); + y_dest -= DEFAULT_HUD_PADDING + DEFAULT_BUBBLES_PADDING + HUD_ELEMENT_HEIGHT; + y_dest += (((float) *(int32_t *) (minecraft + Minecraft_screen_height_property_offset)) * *InvGuiScale) - 31 - HUD_ELEMENT_HEIGHT; + // Call Original Method + (*GuiComponent_blit)(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); +} // Additional GUI Rendering static int hide_chat_messages = 0; static int render_selected_item_text = 0; static void Gui_renderChatMessages_injection(unsigned char *gui, int32_t y_offset, uint32_t max_messages, bool disable_fading, unsigned char *font) { + // Handle Classic HUD + if (use_classic_hud) { + unsigned char *minecraft = *(unsigned char **) (gui + Gui_minecraft_property_offset); + if (!(*Minecraft_isCreativeMode)(minecraft)) { + y_offset -= HUD_ELEMENT_HEIGHT * 2; + } + } + // Call Original Method if (!hide_chat_messages) { (*Gui_renderChatMessages)(gui, y_offset, max_messages, disable_fading, font); @@ -67,6 +108,7 @@ static void Inventory_selectSlot_injection(unsigned char *inventory, int32_t slo } // Sanitize Username +#define MAX_USERNAME_LENGTH 16 static void LoginPacket_read_injection(unsigned char *packet, unsigned char *bit_stream) { // Call Original Method (*LoginPacket_read)(packet, bit_stream); @@ -231,6 +273,16 @@ void init_misc() { patch((void *) 0x63c98, invalid_item_background_patch); } + // Classic HUD + if (feature_has("Classic HUD", server_disabled)) { + use_classic_hud = 1; + overwrite_call((void *) 0x266f8, (void *) Gui_renderHearts_GuiComponent_blit_hearts_injection); + overwrite_call((void *) 0x26758, (void *) Gui_renderHearts_GuiComponent_blit_hearts_injection); + overwrite_call((void *) 0x267c8, (void *) Gui_renderHearts_GuiComponent_blit_hearts_injection); + overwrite_call((void *) 0x2656c, (void *) Gui_renderHearts_GuiComponent_blit_armor_injection); + overwrite_call((void *) 0x268c4, (void *) Gui_renderBubbles_GuiComponent_blit_injection); + } + // Render Selected Item Text + Hide Chat Messages hide_chat_messages = feature_has("Hide Chat Messages", server_disabled); render_selected_item_text = feature_has("Render Selected Item Text", server_disabled); diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index 8d40ed1..ded0116 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -188,6 +188,7 @@ typedef void (*Minecraft_handleMouseDown_t)(unsigned char *minecraft, int param_ static Minecraft_handleMouseDown_t Minecraft_handleMouseDown = (Minecraft_handleMouseDown_t) 0x1584c; static uint32_t Minecraft_screen_width_property_offset = 0x20; // int32_t +static uint32_t Minecraft_screen_height_property_offset = 0x24; // int32_t static uint32_t Minecraft_network_handler_property_offset = 0x174; // NetEventCallback * static uint32_t Minecraft_rak_net_instance_property_offset = 0x170; // RakNetInstance * static uint32_t Minecraft_level_property_offset = 0x188; // Level *