Improve libreborn

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_item_extra = (ItemInstance_constructor_extra_t) 0x99960;
static uint32_t ItemInstance_count_property_offset = 0x0;
static uint32_t ItemInstance_id_property_offset = 0x4;
static uint32_t ItemInstance_auxilary_property_offset = 0x8;
static uint32_t ItemInstance_count_property_offset = 0x0; // int32_t
static uint32_t ItemInstance_id_property_offset = 0x4; // int32_t
static uint32_t ItemInstance_auxilary_property_offset = 0x8; // int32_t
// 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);
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
#ifdef __cplusplus

View File

@ -15,13 +15,14 @@
// BL Instruction Magic Number
#define BL_INSTRUCTION 0xeb
#define B_INSTRUCTION 0xea
// 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;
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;
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) {
unsigned char *addr = ((unsigned char *) section) + i;
if (addr[3] == BL_INSTRUCTION) {
uint32_t check_instruction = generate_bl_instruction(addr, args->target);
int use_b_instruction = addr[3] == B_INSTRUCTION;
// 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;
// Check If Instruction Calls Target
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);
args->found++;
}
@ -92,7 +97,7 @@ void _overwrite_call(const char *file, int line, void *start, void *target) {
// Add New Target To Code Block
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);
// 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);
}
}
// Fix Toolbar Rendering
GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
// Call Original Method
float ret = (*ItemRenderer_renderGuiItemCorrect)(font, textures, carried_item_instance != NULL ? carried_item_instance : item_instance, param_1, param_2);
// Revert GL State Changes
if (depth_test_was_enabled) {
glEnable(GL_DEPTH_TEST);
}
// Free Carried Item Instance Variant
if (carried_item_instance != NULL) {
::operator delete(carried_item_instance);
}
// Return
return ret;
}