Animated Chests

This commit is contained in:
TheBrokenRail 2023-11-24 17:57:39 -05:00
parent 168b825bf4
commit 71b11b314b
3 changed files with 60 additions and 0 deletions

View File

@ -307,6 +307,7 @@ void bootstrap(int argc, char *argv[]) {
// Get Binary Directory
char *binary_directory = get_binary_directory();
DEBUG("Binary Directory: %s", binary_directory);
// Copy SDK
copy_sdk(binary_directory);

View File

@ -461,6 +461,38 @@ static bool ChestTileEntity_shouldSave_injection(__attribute__((unused)) unsigne
return 1;
}
// Animated 3D Chest
static unsigned char *ContainerMenu_injection(unsigned char *container_menu, unsigned char *container, int32_t param_1) {
// Call Original Method
(*ContainerMenu)(container_menu, container, param_1);
// Play Animation
unsigned char *tile_entity = container - ChestTileEntity_container_property_offset;
bool is_client = *(bool *) (tile_entity + TileEntity_is_client_property_offset);
if (!is_client) {
unsigned char *container_vtable = *(unsigned char **) container;
Container_startOpen_t Container_startOpen = *(Container_startOpen_t *) (container_vtable + Container_startOpen_vtable_offset);
(*Container_startOpen)(container);
}
// Return
return container_menu;
}
static unsigned char *ContainerMenu_destructor_injection(unsigned char *container_menu) {
// Play Animation
unsigned char *container = *(unsigned char **) (container_menu + ContainerMenu_container_property_offset);
unsigned char *tile_entity = container - ChestTileEntity_container_property_offset;
bool is_client = *(bool *) (tile_entity + TileEntity_is_client_property_offset);
if (!is_client) {
unsigned char *container_vtable = *(unsigned char **) container;
Container_stopOpen_t Container_stopOpen = *(Container_stopOpen_t *) (container_vtable + Container_stopOpen_vtable_offset);
(*Container_stopOpen)(container);
}
// Call Original Method
return (*ContainerMenu_destructor)(container_menu);
}
// Init
static void nop() {
}
@ -615,6 +647,11 @@ void init_misc() {
patch((void *) 0x66fc8, chest_model_patch);
unsigned char chest_color_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
patch((void *) 0x66404, chest_color_patch);
// Animation
overwrite_calls((void *) ContainerMenu, (void *) ContainerMenu_injection);
overwrite_calls((void *) ContainerMenu_destructor, (void *) ContainerMenu_destructor_injection);
patch_address(ContainerMenu_destructor_vtable_addr, (void *) ContainerMenu_destructor_injection);
}
patch_address((void *) 0x115b48, (void *) ChestTileEntity_shouldSave_injection);

View File

@ -835,17 +835,39 @@ static EntityRenderDispatcher_assign_t EntityRenderDispatcher_assign = (EntityRe
static uint32_t TileEntity_id_property_offset = 0x18; // int32_t
static uint32_t TileEntity_renderer_id_property_offset = 0x24; // int32_t
static uint32_t TileEntity_is_client_property_offset = 0x20; // bool
// ChestTileEntity
typedef unsigned char *(*ChestTileEntity_t)(unsigned char *tile_entity);
static ChestTileEntity_t ChestTileEntity = (ChestTileEntity_t) 0xcfa78;
static uint32_t ChestTileEntity_container_property_offset = 0x30; // Container
// ModelPart
typedef void (*ModelPart_render_t)(unsigned char *model_part, float scale);
static ModelPart_render_t ModelPart_render = (ModelPart_render_t) 0x416dc;
// Container
typedef void (*Container_startOpen_t)(unsigned char *container);
static uint32_t Container_startOpen_vtable_offset = 0x24;
typedef Container_startOpen_t Container_stopOpen_t;
static uint32_t Container_stopOpen_vtable_offset = 0x28;
// ContainerMenu
typedef unsigned char *(*ContainerMenu_t)(unsigned char *container_menu, unsigned char *container, int32_t param_1);
static ContainerMenu_t ContainerMenu = (ContainerMenu_t) 0x919a8;
typedef unsigned char *(*ContainerMenu_destructor_t)(unsigned char *container_menu);
static ContainerMenu_destructor_t ContainerMenu_destructor = (ContainerMenu_destructor_t) 0x91a74;
static void *ContainerMenu_destructor_vtable_addr = (void *) 0x10e1b8;
static uint32_t ContainerMenu_container_property_offset = 0x1c; // Container *
// ItemRenderer
typedef void (*ItemRenderer_renderGuiItem_one_t)(unsigned char *font, unsigned char *textures, ItemInstance *item_instance, float param_1, float param_2, bool param_3);