Merge PR + WIP Refactor

Co-authored-by: Bigjango13 <bigjango13@gmail.com>
This commit is contained in:
TheBrokenRail 2024-07-17 03:44:41 -04:00
parent 036d0a0653
commit 5f2923b789
14 changed files with 131 additions and 20 deletions

View File

@ -70,3 +70,9 @@ FALSE Log FPS
TRUE Add Welcome Screen TRUE Add Welcome Screen
TRUE F3 Debug Information TRUE F3 Debug Information
TRUE Multidraw Rendering TRUE Multidraw Rendering
TRUE Add Missing Language Strings
TRUE Fix Pigmen Burning In The Sun
TRUE Fix Carried Grass's Bottom Texture
TRUE Hide Crosshair In Third-Person
TRUE Fix Camera Legs
TRUE Implement Crafting Remainders

View File

@ -3,10 +3,11 @@
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
#include "patch-internal.h" #include "patch-internal.h"
// Limit To 512 overwrite_calls() Uses // Limit Amount Of overwrite_calls() Calls
#define CODE_BLOCK_SIZE 4096 #define MAX_OVERWRITE_CALLS 4096
static unsigned char *code_block = nullptr; static unsigned char *code_block = nullptr;
#define CODE_SIZE 8 #define CODE_SIZE 8
#define CODE_BLOCK_SIZE (MAX_OVERWRITE_CALLS * CODE_SIZE)
static int code_block_remaining = CODE_BLOCK_SIZE; static int code_block_remaining = CODE_BLOCK_SIZE;
// Create Long Overwrite At Current Position // Create Long Overwrite At Current Position

View File

@ -30,6 +30,23 @@ static void TripodCamera_tick_Level_addParticle_call_injection(Level *level, con
level->addParticle(particle, x, y + 0.5, z, deltaX, deltaY, deltaZ, count); level->addParticle(particle, x, y + 0.5, z, deltaX, deltaY, deltaZ, count);
} }
// Fix Camera Legs
static void TripodCameraRenderer_render_EntityRenderer_bindTexture_injection(EntityRenderer *self, __attribute__((unused)) const std::string &file) {
self->bindTexture("item/camera.png");
}
static void TripodCameraRenderer_render_TileRenderer_tesselateCrossTexture_injection() {
Tesselator *t = &Tesselator::instance;
for (const float a : {-1.f, 1.f}) {
for (const float b : {-1.f, 1.f}) {
constexpr float size = 0.45f;
t->vertexUV(size * a, 0.5, size * b, 0.75, 0.5);
t->vertexUV(size * a, -0.5, size * b, 0.75, 1);
t->vertexUV(size * -a, -0.5, size * -b, 1, 1);
t->vertexUV(size * -a, 0.5, size * -b, 1, 0.5);
}
}
}
// Init // Init
void init_camera() { void init_camera() {
// Implement AppPlatform_linux::saveScreenshot So Cameras Work // Implement AppPlatform_linux::saveScreenshot So Cameras Work
@ -42,4 +59,9 @@ void init_camera() {
// Display Smoke From TripodCamera Higher // Display Smoke From TripodCamera Higher
overwrite_call((void *) 0x87dc4, (void *) TripodCamera_tick_Level_addParticle_call_injection); overwrite_call((void *) 0x87dc4, (void *) TripodCamera_tick_Level_addParticle_call_injection);
} }
// Camera Legs
if (feature_has("Fix Camera Legs", server_disabled)) {
overwrite_call((void *) 0x659dc, (void *) TripodCameraRenderer_render_EntityRenderer_bindTexture_injection);
overwrite_call((void *) 0x65a08, (void *) TripodCameraRenderer_render_TileRenderer_tesselateCrossTexture_injection);
}
} }

View File

@ -4,9 +4,9 @@
#include <symbols/minecraft.h> #include <symbols/minecraft.h>
__attribute__((constructor)) static void init() { __attribute__((constructor)) static void init() {
thunk_enabler = reborn_thunk_enabler;
media_ensure_loaded(); media_ensure_loaded();
reborn_init_patch(); reborn_init_patch();
enable_all_thunks(reborn_thunk_enabler);
run_tests(); run_tests();
init_version(); init_version();
init_compat(); init_compat();

View File

@ -47,7 +47,7 @@ static void revert_rotation(Entity *entity) {
entity->old_pitch = -entity->old_pitch; entity->old_pitch = -entity->old_pitch;
} }
} }
static int is_front_facing = 0; static bool is_front_facing = false;
static LocalPlayer *stored_player = nullptr; static LocalPlayer *stored_player = nullptr;
static void GameRenderer_setupCamera_injection(GameRenderer_setupCamera_t original, GameRenderer *game_renderer, float param_1, int param_2) { static void GameRenderer_setupCamera_injection(GameRenderer_setupCamera_t original, GameRenderer *game_renderer, float param_1, int param_2) {
// Get Objects // Get Objects
@ -86,6 +86,13 @@ static void ParticleEngine_render_injection(ParticleEngine_render_t original, Pa
} }
} }
// Hide Crosshair
static void Gui_renderProgressIndicator_GuiComponent_blit_injection(GuiComponent *self, int x1, int y1, int x2, int y2, int w1, int h1, int w2, int h2) {
if (((Gui *) self)->minecraft->options.third_person == 0) {
self->blit(x1, y1, x2, y2, w1, h1, w2, h2);
}
}
// Init // Init
void _init_toggle() { void _init_toggle() {
if (feature_has("Bind Common Toggleable Options To Function Keys", server_disabled)) { if (feature_has("Bind Common Toggleable Options To Function Keys", server_disabled)) {
@ -96,4 +103,7 @@ void _init_toggle() {
overwrite_calls(GameRenderer_setupCamera, GameRenderer_setupCamera_injection); overwrite_calls(GameRenderer_setupCamera, GameRenderer_setupCamera_injection);
overwrite_calls(ParticleEngine_render, ParticleEngine_render_injection); overwrite_calls(ParticleEngine_render, ParticleEngine_render_injection);
} }
if (feature_has("Hide Crosshair In Third-Person", server_disabled)) {
overwrite_call((void *) 0x261b8, (void *) Gui_renderProgressIndicator_GuiComponent_blit_injection);
}
} }

View File

@ -659,7 +659,7 @@ static void PauseScreen_init_injection(PauseScreen_init_t original, PauseScreen
} }
// Implement crafting remainders // Implement crafting remainders
void PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_injection(PaneCraftingScreen *self) { static void PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_injection(PaneCraftingScreen *self) {
// Check for crafting remainders // Check for crafting remainders
CItem *item = self->item; CItem *item = self->item;
for (size_t i = 0; i < item->ingredients.size(); i++) { for (size_t i = 0; i < item->ingredients.size(); i++) {
@ -678,8 +678,7 @@ void PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_inje
// Call Original Method // Call Original Method
self->recheckRecipes(); self->recheckRecipes();
} }
static ItemInstance *Item_getCraftingRemainingItem_injection(__attribute__((unused)) Item_getCraftingRemainingItem_t original, Item *self, ItemInstance *item_instance) {
ItemInstance *Item_getCraftingRemainingItem_injection(__attribute__((unused)) Item_getCraftingRemainingItem_t original, Item *self, ItemInstance *item_instance) {
if (self->craftingRemainingItem != nullptr) { if (self->craftingRemainingItem != nullptr) {
ItemInstance *ret = new ItemInstance; ItemInstance *ret = new ItemInstance;
ret->id = self->craftingRemainingItem->id; ret->id = self->craftingRemainingItem->id;
@ -699,7 +698,7 @@ struct chunk_data {
static chunk_data data[MAX_CHUNKS_SIZE]; static chunk_data data[MAX_CHUNKS_SIZE];
static void sort_chunks(Chunk **chunks_begin, Chunk **chunks_end, DistanceChunkSorter sorter) { static void sort_chunks(Chunk **chunks_begin, Chunk **chunks_end, DistanceChunkSorter sorter) {
// Calculate Distances // Calculate Distances
int chunks_size = chunks_end - chunks_begin; const int chunks_size = chunks_end - chunks_begin;
if (chunks_size > MAX_CHUNKS_SIZE) { if (chunks_size > MAX_CHUNKS_SIZE) {
IMPOSSIBLE(); IMPOSSIBLE();
} }
@ -733,6 +732,50 @@ static std::string AppPlatform_linux_getDateString_injection(__attribute__((unus
return std::string(buf); return std::string(buf);
} }
// Missing Strings
static void add_missing_string(const std::string &key, const std::string &value) {
if (!I18n::_strings.contains(key)) {
I18n::_strings[key] = value;
}
}
static void Language_injection() {
// Fix Language Strings
add_missing_string("tile.waterStill.name", "Still Water");
add_missing_string("tile.lavaStill.name", "Still Lava");
add_missing_string("tile.grassCarried.name", "Carried Grass");
add_missing_string("tile.leavesCarried.name", "Carried Leaves");
add_missing_string("tile.invBedrock.name", "Invisible Bedrock");
// Missing Language Strings
add_missing_string("item.camera.name", "Camera");
add_missing_string("item.seedsMelon.name", "Melon Seeds");
add_missing_string("tile.pumpkinStem.name", "Pumpkin Stem");
add_missing_string("tile.stoneSlab.name", "Double Stone Slab");
}
// Invisible Bedrock
static Tile *Tile_initTiles_Tile_init_invBedrock_injection(Tile *t) {
Tile *ret = t->init();
t->setDescriptionId("invBedrock");
return ret;
}
// Append "Still" Suffix To Liquid Description Keys
static std::string *Tile_initTiles_std_string_constructor(std::string *self, const char *from, const std::string::allocator_type &alloc) {
new (self) std::string(from, alloc);
self->append("Still");
return self;
}
// Fix Pigmen Burning In The Sun
static float Zombie_aiStep_getBrightness_injection(Entity *self, float param_1) {
if (self->getEntityTypeId() == 36) return 0;
return self->getBrightness(param_1);
}
// Fix grass_carried's Bottom Texture
static int CarriedTile_getTexture2_injection(CarriedTile_getTexture2_t original, CarriedTile *self, int face, int metadata) {
if (face == 0) return 2;
return original(self, face, metadata);
}
// Init // Init
template <typename... Args> template <typename... Args>
static void nop(__attribute__((unused)) Args... args) { static void nop(__attribute__((unused)) Args... args) {
@ -867,7 +910,7 @@ void init_misc() {
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
patch((void *) 0x173e8, nop_patch); patch((void *) 0x173e8, nop_patch);
patch((void *) 0x173f0, nop_patch); patch((void *) 0x173f0, nop_patch);
float gui_scale = strtof(gui_scale_str, nullptr); const float gui_scale = strtof(gui_scale_str, nullptr);
uint32_t gui_scale_raw; uint32_t gui_scale_raw;
memcpy(&gui_scale_raw, &gui_scale, sizeof (gui_scale_raw)); memcpy(&gui_scale_raw, &gui_scale, sizeof (gui_scale_raw));
patch_address((void *) 0x17520, (void *) gui_scale_raw); patch_address((void *) 0x17520, (void *) gui_scale_raw);
@ -949,8 +992,10 @@ void init_misc() {
} }
// Implement Crafting Remainders // Implement Crafting Remainders
if (feature_has("Implement Crafting Remainders", server_enabled)) {
overwrite_call((void *) 0x2e230, (void *) PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_injection); overwrite_call((void *) 0x2e230, (void *) PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_injection);
overwrite_calls(Item_getCraftingRemainingItem, Item_getCraftingRemainingItem_injection); overwrite_calls(Item_getCraftingRemainingItem, Item_getCraftingRemainingItem_injection);
}
// Replace 2011 std::sort With Optimized(TM) Code // Replace 2011 std::sort With Optimized(TM) Code
if (feature_has("Optimized Chunk Sorting", server_enabled)) { if (feature_has("Optimized Chunk Sorting", server_enabled)) {
@ -962,7 +1007,7 @@ void init_misc() {
patch_vtable(AppPlatform_linux_getDateString, AppPlatform_linux_getDateString_injection); patch_vtable(AppPlatform_linux_getDateString, AppPlatform_linux_getDateString_injection);
} }
// Don't Wrap Text On '\r' Or '\t' Because THey Are Actual Characters In MCPI // Don't Wrap Text On '\r' Or '\t' Because They Are Actual Characters In MCPI
patch_address(&Strings::text_wrapping_delimiter, (void *) " \n"); patch_address(&Strings::text_wrapping_delimiter, (void *) " \n");
// Fullscreen // Fullscreen
@ -975,6 +1020,29 @@ void init_misc() {
} }
}); });
// Fix/Update Language Strings
if (feature_has("Add Missing Language Strings", server_disabled)) {
misc_run_on_language_setup(Language_injection);
// Water/Lava Language Strings
overwrite_call((void *) 0xc3b54, (void *) Tile_initTiles_std_string_constructor);
overwrite_call((void *) 0xc3c7c, (void *) Tile_initTiles_std_string_constructor);
// Carried Tile Language Strings
patch_address((void *) 0xc6674, (void *) "grassCarried");
patch_address((void *) 0xc6684, (void *) "leavesCarried");
// Invisible Bedrock Language String
overwrite_call((void *) 0xc5f04, (void *) Tile_initTiles_Tile_init_invBedrock_injection);
}
// Fix pigmen from burning in the sun
if (feature_has("Fix Pigmen Burning In The Sun", server_enabled)) {
overwrite_call((void *) 0x89a1c, (void *) Zombie_aiStep_getBrightness_injection);
}
// Fix grass_carried's bottom texture
if (feature_has("Fix Grass's Bottom Texture", server_disabled)) {
overwrite_calls(CarriedTile_getTexture2, CarriedTile_getTexture2_injection);
}
// Init Logging // Init Logging
_init_misc_logging(); _init_misc_logging();
_init_misc_api(); _init_misc_api();

View File

@ -151,6 +151,7 @@ set(SRC
src/tile/StemTile.def src/tile/StemTile.def
src/tile/Tile_SoundType.def src/tile/Tile_SoundType.def
src/tile/TileRenderer.def src/tile/TileRenderer.def
src/tile/CarriedTile.def
src/tile/GrassTile.def src/tile/GrassTile.def
src/tile/HeavyTile.def src/tile/HeavyTile.def
src/tile/EntityTile.def src/tile/EntityTile.def

View File

@ -7,7 +7,7 @@ size 0x24;
constructor (int id) = 0x99488; constructor (int id) = 0x99488;
virtual-method int getIcon(int auxiliary) = 0x14; virtual-method int getIcon(int auxiliary) = 0x14;
virtual-method void setIcon(int texture_x, int texture_y) = 0x18; virtual-method Item *setIcon(int texture_x, int texture_y) = 0x18;
virtual-method int useOn(ItemInstance *item_instance, Player *player, Level *level, int x, int y, int z, int hit_side, float hit_x, float hit_y, float hit_z) = 0x20; virtual-method int useOn(ItemInstance *item_instance, Player *player, Level *level, int x, int y, int z, int hit_side, float hit_x, float hit_y, float hit_z) = 0x20;
// Normally returns 0 // Normally returns 0
virtual-method int getUseDuration(ItemInstance *item_instance) = 0x24; virtual-method int getUseDuration(ItemInstance *item_instance) = 0x24;
@ -20,7 +20,7 @@ virtual-method bool mineBlock(ItemInstance *instance, int tile_id, int x, int y,
virtual-method void interactEnemy(ItemInstance *item_instance, Mob *mob) = 0x54; virtual-method void interactEnemy(ItemInstance *item_instance, Mob *mob) = 0x54;
virtual-method bool isFood() = 0x64; virtual-method bool isFood() = 0x64;
virtual-method bool isArmor() = 0x68; virtual-method bool isArmor() = 0x68;
virtual-method void setDescriptionId(const std::string &name) = 0x6c; virtual-method Item *setDescriptionId(const std::string &name) = 0x6c;
virtual-method std::string getDescriptionId(const ItemInstance *item_instance) = 0x7c; virtual-method std::string getDescriptionId(const ItemInstance *item_instance) = 0x7c;
// This returns an Item*, but it's never called normally so it doesn't matter if we invent a better system over top of it // This returns an Item*, but it's never called normally so it doesn't matter if we invent a better system over top of it
virtual-method ItemInstance *getCraftingRemainingItem(ItemInstance *item_instance) = 0x84; virtual-method ItemInstance *getCraftingRemainingItem(ItemInstance *item_instance) = 0x84;

View File

@ -7,7 +7,7 @@ constructor item_extra(const Item *item, int count, int auxiliary) = 0x99960;
static-method ItemInstance *fromTag(CompoundTag *tag) = 0x9a124; static-method ItemInstance *fromTag(CompoundTag *tag) = 0x9a124;
method void save(CompoundTag *tag) = 0x9a31c; method CompoundTag *save(CompoundTag *tag) = 0x9a31c;
method int getMaxStackSize() = 0x99ac8; method int getMaxStackSize() = 0x99ac8;
method bool isNull() = 0x999b0; method bool isNull() = 0x999b0;

View File

@ -2,7 +2,7 @@ extends Container;
vtable 0x10e250; vtable 0x10e250;
method void addItem(ItemInstance *item_instance) = 0x92aa0; method int addItem(ItemInstance *item_instance) = 0x92aa0;
method void clearSlot(int slot) = 0x922f8; method void clearSlot(int slot) = 0x922f8;
method void release(int slot) = 0x92058; method void release(int slot) = 0x92058;
method void compressLinkedSlotList(int slot) = 0x92280; method void compressLinkedSlotList(int slot) = 0x92280;

View File

@ -2,7 +2,7 @@ extends Tag;
vtable-size 0x34; vtable-size 0x34;
size 0x24; size 0x24;
constructor (std::string name) = 0x69740; constructor (const std::string &name) = 0x69740;
method bool getBoolean(const std::string &name) = 0xd1b28; method bool getBoolean(const std::string &name) = 0xd1b28;
method char getByte(const std::string &name) = 0x7f00c; method char getByte(const std::string &name) = 0x7f00c;

View File

@ -1 +1 @@
constructor () = 0x684e0; constructor (const std::string &name) = 0x684e0;

View File

@ -0,0 +1,3 @@
extends Tile;
vtable 0x114798;

View File

@ -23,7 +23,7 @@ virtual-method void addAABBs(Level *level, int x, int y, int z, const AABB *inte
virtual-method bool isSolidRender() = 0x40; virtual-method bool isSolidRender() = 0x40;
virtual-method bool mayPlace(Level *level, int x, int y, int z, uchar face) = 0x4c; virtual-method bool mayPlace(Level *level, int x, int y, int z, uchar face) = 0x4c;
virtual-method bool mayPlace2(Level *level, int x, int y, int z) = 0x50; virtual-method bool mayPlace2(Level *level, int x, int y, int z) = 0x50;
virtual-method void tick(Level *level, int x, int y, int z) = 0x58; virtual-method void tick(Level *level, int x, int y, int z, Random *random) = 0x58;
virtual-method void neighborChanged(Level *level, int x, int y, int z, int neighborId) = 0x64; virtual-method void neighborChanged(Level *level, int x, int y, int z, int neighborId) = 0x64;
virtual-method void onPlace(Level *level, int x, int y, int z) = 0x68; virtual-method void onPlace(Level *level, int x, int y, int z) = 0x68;
virtual-method void onRemove(Level *level, int x, int y, int z) = 0x6c; virtual-method void onRemove(Level *level, int x, int y, int z) = 0x6c;