Fix Furnace Not Checking Item Auxiliary

This commit is contained in:
TheBrokenRail 2022-03-06 22:43:42 -05:00
parent 0fcda17120
commit e0ebc7fc32
3 changed files with 52 additions and 0 deletions

View File

@ -30,3 +30,4 @@ TRUE Load Language Files
TRUE Implement Sound Engine
TRUE Close Current Screen On Death
FALSE Disable Raw Mouse Motion (Not Recommended)
TRUE Fix Furnace Not Checking Item Auxiliary

View File

@ -145,6 +145,40 @@ static void LocalPlayer_die_injection(unsigned char *entity, unsigned char *caus
(*LocalPlayer_die)(entity, cause);
}
// Fix Furnace Not Checking Item Auxiliary When Inserting New Item
static int32_t FurnaceScreen_handleAddItem_injection(unsigned char *furnace_screen, int32_t slot, ItemInstance const *item) {
// Get Existing Item
unsigned char *tile_entity = *(unsigned char **) (furnace_screen + FurnaceScreen_tile_entity_property_offset);
unsigned char *tile_entity_vtable = *(unsigned char **) tile_entity;
FurnaceTileEntity_getItem_t FurnaceTileEntity_getItem = *(FurnaceTileEntity_getItem_t *) (tile_entity_vtable + FurnaceTileEntity_getItem_vtable_offset);
ItemInstance *existing_item = (*FurnaceTileEntity_getItem)(tile_entity, slot);
// Check Item
int valid;
if (item->id == existing_item->id && item->auxiliary == existing_item->auxiliary) {
// Item Matches, Is Valid
valid = 1;
} else {
// Item Doesn't Match, Check If Existing Item Is Empty
if ((existing_item->id | existing_item->count | existing_item->auxiliary) == 0) {
// Existing Item Is Empty, Is Valid
valid = 1;
} else {
// Existing Item Isn't Empty, Isn't Valid
valid = 0;
}
}
// Call Original Method
if (valid) {
// Valid
return (*FurnaceScreen_handleAddItem)(furnace_screen, slot, item);
} else {
// Invalid
return 0;
}
}
// Init
void init_misc() {
// Remove Invalid Item Background (A Red Background That Appears For Items That Are Not Included In The gui_blocks Atlas)
@ -177,6 +211,11 @@ void init_misc() {
patch_address(LocalPlayer_die_vtable_addr, (void *) LocalPlayer_die_injection);
}
// Fix Furnace Not Checking Item Auxiliary When Inserting New Item
if (feature_has("Fix Furnace Not Checking Item Auxiliary", 1)) {
overwrite_calls((void *) FurnaceScreen_handleAddItem, (void *) FurnaceScreen_handleAddItem_injection);
}
// Init C++ And Logging
_init_misc_cpp();
_init_misc_logging();

View File

@ -401,6 +401,18 @@ static ProgressScreen_t ProgressScreen = (ProgressScreen_t) 0x37044;
static void *OptionsScreen_handleBackEvent_vtable_addr = (void *) 0x10499c;
// FurnaceScreen
typedef int32_t (*FurnaceScreen_handleAddItem_t)(unsigned char *furnace_screen, int32_t slot, ItemInstance const *item);
static FurnaceScreen_handleAddItem_t FurnaceScreen_handleAddItem = (FurnaceScreen_handleAddItem_t) 0x327a0;
static uint32_t FurnaceScreen_tile_entity_property_offset = 0x1d0; // FurnaceTileEntity *
// FurnaceTileEntity
typedef ItemInstance *(*FurnaceTileEntity_getItem_t)(unsigned char *furnace_tile_entity, int32_t slot);
static uint32_t FurnaceTileEntity_getItem_vtable_offset = 0x2c;
// Screen
typedef void (*Screen_updateEvents_t)(unsigned char *screen);