minecraft-pi-reborn/mods/src/textures/textures.cpp

71 lines
3.2 KiB
C++
Raw Normal View History

2020-12-02 23:18:49 +00:00
#include <GLES/gl.h>
2021-01-27 21:26:19 +00:00
#include <libreborn/libreborn.h>
2020-12-02 23:18:49 +00:00
#include "../feature/feature.h"
#include "../init/init.h"
2021-02-03 22:00:02 +00:00
#include <libreborn/minecraft.h>
2020-12-02 23:18:49 +00:00
static void Minecraft_tick_injection(unsigned char *minecraft, int32_t param_1, int32_t param_2) {
// Call Original Method
(*Minecraft_tick)(minecraft, param_1, param_2);
// Tick Dynamic Textures
2020-12-18 03:22:56 +00:00
unsigned char *textures = *(unsigned char **) (minecraft + Minecraft_textures_property_offset);
2020-12-02 23:18:49 +00:00
if (textures != NULL) {
(*Textures_tick)(textures, true);
}
}
// Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled
static float ItemRenderer_renderGuiItemCorrect_injection(unsigned char *font, unsigned char *textures, unsigned char *item_instance, int32_t param_1, int32_t param_2) {
2020-12-18 03:22:56 +00:00
int32_t leaves_id = *(int32_t *) (*Tile_leaves + Tile_id_property_offset);
int32_t grass_id = *(int32_t *) (*Tile_grass + Tile_id_property_offset);
2020-12-02 23:18:49 +00:00
// Replace Rendered Item With Carried Variant
unsigned char *carried_item_instance = NULL;
if (item_instance != NULL) {
2020-12-18 03:22:56 +00:00
int32_t id = *(int32_t *) (item_instance + ItemInstance_id_property_offset);
int32_t count = *(int32_t *) (item_instance + ItemInstance_count_property_offset);
int32_t auxilary = *(int32_t *) (item_instance + ItemInstance_auxilary_property_offset);
2020-12-02 23:18:49 +00:00
if (id == leaves_id) {
carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE);
2021-02-16 17:26:40 +00:00
ALLOC_CHECK(carried_item_instance);
2021-02-10 21:24:47 +00:00
(*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_leaves_carried, count, auxilary);
2020-12-02 23:18:49 +00:00
} else if (id == grass_id) {
carried_item_instance = (unsigned char *) ::operator new(ITEM_INSTANCE_SIZE);
2021-02-16 17:26:40 +00:00
ALLOC_CHECK(carried_item_instance);
2021-02-10 21:24:47 +00:00
(*ItemInstance_constructor_tile_extra)(carried_item_instance, *Tile_grass_carried, count, auxilary);
2020-12-02 23:18:49 +00:00
}
}
// 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;
}
void init_textures() {
if (feature_has("Animated Water")) {
// Tick Dynamic Textures (Animated Water)
overwrite_calls((void *) Minecraft_tick, (void *) Minecraft_tick_injection);
}
if (feature_has("Disable gui_blocks Atlas")) {
// Disable gui_blocks Atlas Which Contains Pre-Rendered Textures For Blocks In The Inventory
2021-03-05 00:27:24 +00:00
unsigned char disable_gui_blocks_atlas_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
2020-12-02 23:18:49 +00:00
patch((void *) 0x63c2c, disable_gui_blocks_atlas_patch);
// Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled
overwrite_calls((void *) ItemRenderer_renderGuiItemCorrect, (void *) ItemRenderer_renderGuiItemCorrect_injection);
}
}