Improve libreborn
minecraft-pi-reborn/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2021-06-30 18:38:43 -04:00
parent 1877996874
commit b32c6013fb
3 changed files with 28 additions and 10 deletions

View File

@ -321,9 +321,9 @@ typedef unsigned char *(*ItemInstance_constructor_extra_t)(unsigned char *item_i
static ItemInstance_constructor_extra_t ItemInstance_constructor_tile_extra = (ItemInstance_constructor_extra_t) 0x99918; static ItemInstance_constructor_extra_t ItemInstance_constructor_tile_extra = (ItemInstance_constructor_extra_t) 0x99918;
static ItemInstance_constructor_extra_t ItemInstance_constructor_item_extra = (ItemInstance_constructor_extra_t) 0x99960; static ItemInstance_constructor_extra_t ItemInstance_constructor_item_extra = (ItemInstance_constructor_extra_t) 0x99960;
static uint32_t ItemInstance_count_property_offset = 0x0; static uint32_t ItemInstance_count_property_offset = 0x0; // int32_t
static uint32_t ItemInstance_id_property_offset = 0x4; static uint32_t ItemInstance_id_property_offset = 0x4; // int32_t
static uint32_t ItemInstance_auxilary_property_offset = 0x8; static uint32_t ItemInstance_auxilary_property_offset = 0x8; // int32_t
// FillingContainer // FillingContainer
@ -414,6 +414,14 @@ static uint32_t TileEntity_id_property_offset = 0x18; // int32_t
typedef float (*ItemRenderer_renderGuiItemCorrect_t)(unsigned char *font, unsigned char *textures, unsigned char *item_instance, int32_t param_1, int32_t param_2); typedef float (*ItemRenderer_renderGuiItemCorrect_t)(unsigned char *font, unsigned char *textures, unsigned char *item_instance, int32_t param_1, int32_t param_2);
static ItemRenderer_renderGuiItemCorrect_t ItemRenderer_renderGuiItemCorrect = (ItemRenderer_renderGuiItemCorrect_t) 0x639a0; static ItemRenderer_renderGuiItemCorrect_t ItemRenderer_renderGuiItemCorrect = (ItemRenderer_renderGuiItemCorrect_t) 0x639a0;
// Tesselator
typedef void (*Tesselator_begin_t)(unsigned char *tesselator, int32_t mode);
static Tesselator_begin_t Tesselator_begin = (Tesselator_begin_t) 0x529d4;
typedef void (*Tesselator_colorABGR_t)(unsigned char *tesselator, int32_t color);
static Tesselator_colorABGR_t Tesselator_colorABGR = (Tesselator_colorABGR_t) 0x52b54;
// Method That Require C++ Types // Method That Require C++ Types
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -15,13 +15,14 @@
// BL Instruction Magic Number // BL Instruction Magic Number
#define BL_INSTRUCTION 0xeb #define BL_INSTRUCTION 0xeb
#define B_INSTRUCTION 0xea
// Generate A BL Instruction // Generate A BL Instruction
static uint32_t generate_bl_instruction(void *from, void *to) { static uint32_t generate_bl_instruction(void *from, void *to, int use_b_instruction) {
uint32_t instruction; uint32_t instruction;
unsigned char *instruction_array = (unsigned char *) &instruction; unsigned char *instruction_array = (unsigned char *) &instruction;
instruction_array[3] = BL_INSTRUCTION; instruction_array[3] = use_b_instruction ? B_INSTRUCTION : BL_INSTRUCTION;
unsigned char *pc = ((unsigned char *) from) + 8; unsigned char *pc = ((unsigned char *) from) + 8;
int32_t offset = (int32_t) to - (int32_t) pc; int32_t offset = (int32_t) to - (int32_t) pc;
@ -48,11 +49,15 @@ static void overwrite_calls_callback(void *section, Elf32_Word size, void *data)
for (uint32_t i = 0; i < size; i = i + 4) { for (uint32_t i = 0; i < size; i = i + 4) {
unsigned char *addr = ((unsigned char *) section) + i; unsigned char *addr = ((unsigned char *) section) + i;
if (addr[3] == BL_INSTRUCTION) { int use_b_instruction = addr[3] == B_INSTRUCTION;
uint32_t check_instruction = generate_bl_instruction(addr, args->target); // Check If Instruction is B Or BL
if (addr[3] == BL_INSTRUCTION || use_b_instruction) {
uint32_t check_instruction = generate_bl_instruction(addr, args->target, use_b_instruction);
unsigned char *check_instruction_array = (unsigned char *) &check_instruction; unsigned char *check_instruction_array = (unsigned char *) &check_instruction;
// Check If Instruction Calls Target
if (addr[0] == check_instruction_array[0] && addr[1] == check_instruction_array[1] && addr[2] == check_instruction_array[2]) { if (addr[0] == check_instruction_array[0] && addr[1] == check_instruction_array[1] && addr[2] == check_instruction_array[2]) {
uint32_t new_instruction = generate_bl_instruction(addr, args->replacement); // Patch Instruction
uint32_t new_instruction = generate_bl_instruction(addr, args->replacement, use_b_instruction);
_patch(args->file, args->line, addr, (unsigned char *) &new_instruction); _patch(args->file, args->line, addr, (unsigned char *) &new_instruction);
args->found++; args->found++;
} }
@ -92,7 +97,7 @@ void _overwrite_call(const char *file, int line, void *start, void *target) {
// Add New Target To Code Block // Add New Target To Code Block
update_code_block(target); update_code_block(target);
uint32_t new_instruction = generate_bl_instruction(start, code_block); uint32_t new_instruction = generate_bl_instruction(start, code_block, 0);
_patch(file, line, start, (unsigned char *) &new_instruction); _patch(file, line, start, (unsigned char *) &new_instruction);
// Increment Code Block Position // Increment Code Block Position

View File

@ -38,19 +38,24 @@ static float ItemRenderer_renderGuiItemCorrect_injection(unsigned char *font, un
(*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_grass_carried, count, auxilary); (*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_grass_carried, count, auxilary);
} }
} }
// Fix Toolbar Rendering // Fix Toolbar Rendering
GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST); GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
// Call Original Method // Call Original Method
float ret = (*ItemRenderer_renderGuiItemCorrect)(font, textures, carried_item_instance != NULL ? carried_item_instance : item_instance, param_1, param_2); float ret = (*ItemRenderer_renderGuiItemCorrect)(font, textures, carried_item_instance != NULL ? carried_item_instance : item_instance, param_1, param_2);
// Revert GL State Changes // Revert GL State Changes
if (depth_test_was_enabled) { if (depth_test_was_enabled) {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }
// Free Carried Item Instance Variant // Free Carried Item Instance Variant
if (carried_item_instance != NULL) { if (carried_item_instance != NULL) {
::operator delete(carried_item_instance); ::operator delete(carried_item_instance);
} }
// Return // Return
return ret; return ret;
} }
@ -68,4 +73,4 @@ void init_textures() {
// Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled // Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled
overwrite_calls((void *) ItemRenderer_renderGuiItemCorrect, (void *) ItemRenderer_renderGuiItemCorrect_injection); overwrite_calls((void *) ItemRenderer_renderGuiItemCorrect, (void *) ItemRenderer_renderGuiItemCorrect_injection);
} }
} }