From 2edfa62c25082410a4dd70c8d5793f20f54923ad Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 2 Oct 2022 15:58:15 -0400 Subject: [PATCH] Fix Holding Left-Click When Attacking --- mods/src/input/attack.c | 23 +++++++++++++++++++++++ symbols/include/symbols/minecraft.h | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/mods/src/input/attack.c b/mods/src/input/attack.c index f32cb15d..a6848506 100644 --- a/mods/src/input/attack.c +++ b/mods/src/input/attack.c @@ -35,10 +35,33 @@ static int32_t MouseBuildInput_tickBuild_injection(unsigned char *mouse_build_in return ret; } +// Fix Holding Right-Click +static bool last_player_attack_successful = 0; +static bool Player_attack_Entity_hurt_injection(unsigned char *entity, unsigned char *attacker, int32_t damage) { + // Call Original Method + unsigned char *entity_vtable = *(unsigned char **) entity; + Entity_hurt_t Entity_hurt = *(Entity_hurt_t *) (entity_vtable + Entity_hurt_vtable_offset); + last_player_attack_successful = (*Entity_hurt)(entity, attacker, damage); + return last_player_attack_successful; +} +static ItemInstance *Player_attack_Inventory_getSelected_injection(unsigned char *inventory) { + // Check If Attack Was Successful + if (!last_player_attack_successful) { + return NULL; + } + + // Call Original Method + return (*Inventory_getSelected)(inventory); +} + // Init void _init_attack() { // Allow Attacking Mobs if (feature_has("Fix Attacking", server_disabled)) { patch_address(MouseBuildInput_tickBuild_vtable_addr, (void *) MouseBuildInput_tickBuild_injection); + + // Fix Holding Right-Click + overwrite_call((void *) 0x8fc1c, (void *) Player_attack_Entity_hurt_injection); + overwrite_call((void *) 0x8fc24, (void *) Player_attack_Inventory_getSelected_injection); } } diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index 279344a2..f32f85e3 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -391,6 +391,9 @@ static uint32_t AuxDataTileItem_icon_tile_property_offset = 0x28; // Tile * // Entity +typedef bool (*Entity_hurt_t)(unsigned char *entity, unsigned char *attacker, int32_t damage); +static uint32_t Entity_hurt_vtable_offset = 0xa4; + static uint32_t Entity_x_property_offset = 0x4; // float static uint32_t Entity_y_property_offset = 0x8; // float static uint32_t Entity_z_property_offset = 0xc; // float @@ -759,6 +762,9 @@ static uint32_t ServerSideNetworkHandler_minecraft_property_offset = 0x8; // Min typedef void (*Inventory_selectSlot_t)(unsigned char *inventory, int32_t slot); static Inventory_selectSlot_t Inventory_selectSlot = (Inventory_selectSlot_t) 0x8d13c; +typedef ItemInstance *(*Inventory_getSelected_t)(unsigned char *inventory); +static Inventory_getSelected_t Inventory_getSelected = (Inventory_getSelected_t) 0x8d134; + static uint32_t Inventory_selectedSlot_property_offset = 0x28; // int32_t // TripodCameraRenderer