Fix Holding Left-Click When Attacking

This commit is contained in:
TheBrokenRail 2022-10-02 15:58:15 -04:00
parent 4870afcc7f
commit 2edfa62c25
2 changed files with 29 additions and 0 deletions

View File

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

View File

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