From 98c4ee306da9c31faad0104ecdb446f9678a9a8e Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 17 Jul 2024 06:42:58 -0400 Subject: [PATCH] It Works! --- dependencies/symbol-processor/src | 2 +- libreborn/include/libreborn/patch.h | 13 +++++++----- mods/src/atlas/atlas.cpp | 28 +++++++++++++++++++++----- mods/src/bucket/bucket.cpp | 6 +++--- mods/src/death/death.cpp | 26 +++++++++++++++--------- mods/src/feature/feature.cpp | 2 +- mods/src/game-mode/game-mode.cpp | 4 ++-- mods/src/init/init.cpp | 2 +- mods/src/misc/misc.cpp | 4 ++-- mods/src/sign/sign.cpp | 4 ++-- mods/src/title-screen/title-screen.cpp | 2 +- mods/src/touch/touch.cpp | 6 +++--- 12 files changed, 63 insertions(+), 36 deletions(-) diff --git a/dependencies/symbol-processor/src b/dependencies/symbol-processor/src index 6f792dfb..10026e9a 160000 --- a/dependencies/symbol-processor/src +++ b/dependencies/symbol-processor/src @@ -1 +1 @@ -Subproject commit 6f792dfb167e48e2e80b8484ac51261ab976b22d +Subproject commit 10026e9a0419ff1cea1ddb80f5ccddf6a53818d3 diff --git a/libreborn/include/libreborn/patch.h b/libreborn/include/libreborn/patch.h index 65732955..228b29d5 100644 --- a/libreborn/include/libreborn/patch.h +++ b/libreborn/include/libreborn/patch.h @@ -16,9 +16,9 @@ void overwrite_call(void *start, void *target); void *overwrite_calls_manual(void *start, void *target, bool allow_no_callsites = false); template void overwrite_calls(T *target, typename T::overwrite_type replacement) { - DEBUG("Overwriting Method: %s", target->get_name()); + DEBUG("Overwriting Method: %s", target->name); if (!target->overwrite(replacement)) { - ERR("Unable To Overwrite Method: %s", target->get_name()); + ERR("Unable To Overwrite Method!"); } } @@ -28,8 +28,8 @@ void *reborn_thunk_enabler(void *target, void *thunk); // Replace All Calls To start With target Within [to, from) void overwrite_calls_within_manual(void *from, void *to, void *start, void *target); template -void _overwrite_calls_within(void *from, void *to, const T &start, typename T::ptr_type target) { - overwrite_calls_within_manual(from, to, (void *) start, (void *) target); +void _overwrite_calls_within(void *from, void *to, T *start, typename T::ptr_type target) { + overwrite_calls_within_manual(from, to, (void *) start->get(), (void *) target); } // Get Target Address From BL Instruction @@ -45,7 +45,10 @@ void patch_address(void *start, void *target); // This does not affect subclasses. template void patch_vtable(const T *start, typename T::ptr_type target) { - DEBUG("Patching VTable: %s", start->get_name()); + DEBUG("Patching VTable: %s", start->name); + if (start->enabled) { + WARN("Use overwrite_calls() Instead!"); + } patch_address((void *) start->get_vtable_addr(), (void *) target); } diff --git a/mods/src/atlas/atlas.cpp b/mods/src/atlas/atlas.cpp index 4a6b0316..8332354a 100644 --- a/mods/src/atlas/atlas.cpp +++ b/mods/src/atlas/atlas.cpp @@ -7,7 +7,7 @@ #include // Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled -static void ItemRenderer_renderGuiItemCorrect_injection(ItemRenderer_renderGuiItemCorrect_t original, Font *font, Textures *textures, const ItemInstance *item_instance, int32_t param_1, int32_t param_2) { +static void ItemRenderer_renderGuiItemCorrect_injection_one(ItemRenderer_renderGuiItemCorrect_t original, Font *font, Textures *textures, const ItemInstance *item_instance, int32_t param_1, int32_t param_2) { int32_t leaves_id = Tile::leaves->id; int32_t grass_id = Tile::grass->id; // Replace Rendered Item With Carried Variant @@ -63,7 +63,7 @@ static void Tesselator_begin_injection(Tesselator_begin_t original, Tesselator * // Fix Furnace UI if (item_color_fix_mode != 0) { - // Implict Translucent + // Implicit Translucent tesselator->color(0xff, 0xff, 0xff, 0xff); } } @@ -74,7 +74,7 @@ static void InventoryPane_renderBatch_Tesselator_color_injection(Tesselator *tes // Enable Item Color Fix item_color_fix_mode = 2; } -static void ItemRenderer_renderGuiItem_two_injection(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, const ItemInstance *item_instance, float param_1, float param_2, float param_3, float param_4, bool param_5) { +static void ItemRenderer_renderGuiItem_two_injection_one(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, const ItemInstance *item_instance, float param_1, float param_2, float param_3, float param_4, bool param_5) { // Call Original Method original(font, textures, item_instance, param_1, param_2, param_3, param_4, param_5); @@ -89,6 +89,21 @@ static void FurnaceScreen_render_ItemRenderer_renderGuiItem_one_injection(Font * ItemRenderer::renderGuiItem_one(font, textures, item_instance, param_1, param_2, param_3); } +// Smooth Scrolling +static float target_x; +static float target_y; +static void ItemRenderer_renderGuiItem_two_injection_two(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, const ItemInstance *item_instance, float x, float y, float w, float h, bool param_5) { + target_x = x; + target_y = y; + original(font, textures, item_instance, x, y, w, h, param_5); +} +static void ItemRenderer_renderGuiItemCorrect_injection_two(ItemRenderer_renderGuiItemCorrect_t original, Font *font, Textures *textures, const ItemInstance *item_instance, __attribute__((unused)) int x, __attribute__((unused)) int y) { + glPushMatrix(); + glTranslatef(target_x, target_y, 0); + original(font, textures, item_instance, 0, 0); + glPopMatrix();; +} + // Init void init_atlas() { // Disable The gui_blocks Atlas Which Contains Pre-Rendered Textures For Blocks In The Inventory @@ -96,12 +111,15 @@ void init_atlas() { unsigned char disable_gui_blocks_atlas_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" patch((void *) 0x63c2c, disable_gui_blocks_atlas_patch); // Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled - overwrite_calls(ItemRenderer_renderGuiItemCorrect, ItemRenderer_renderGuiItemCorrect_injection); + overwrite_calls(ItemRenderer_renderGuiItemCorrect, ItemRenderer_renderGuiItemCorrect_injection_one); // Fix Furnace UI overwrite_calls(Tesselator_begin, Tesselator_begin_injection); overwrite_calls(Tesselator_color, Tesselator_color_injection); overwrite_call((void *) 0x32324, (void *) FurnaceScreen_render_ItemRenderer_renderGuiItem_one_injection); overwrite_call((void *) 0x1e21c, (void *) InventoryPane_renderBatch_Tesselator_color_injection); - overwrite_calls(ItemRenderer_renderGuiItem_two, ItemRenderer_renderGuiItem_two_injection); + overwrite_calls(ItemRenderer_renderGuiItem_two, ItemRenderer_renderGuiItem_two_injection_one); + // Fix Inventory Scrolling + overwrite_calls(ItemRenderer_renderGuiItem_two, ItemRenderer_renderGuiItem_two_injection_two); + overwrite_calls(ItemRenderer_renderGuiItemCorrect, ItemRenderer_renderGuiItemCorrect_injection_two); } } diff --git a/mods/src/bucket/bucket.cpp b/mods/src/bucket/bucket.cpp index 6f45beb3..c8736fab 100644 --- a/mods/src/bucket/bucket.cpp +++ b/mods/src/bucket/bucket.cpp @@ -136,7 +136,7 @@ static int BucketItem_getUseDuration(__attribute__((unused)) FoodItem *item, Ite static ItemInstance BucketItem_useTimeDepleted(FoodItem *item, ItemInstance *item_instance, Level *level, Player *player) { if (item_instance->auxiliary == 1) { - *item_instance = FoodItem_useTimeDepleted->get()(item, item_instance, level, player); + *item_instance = FoodItem_useTimeDepleted->get(false)(item, item_instance, level, player); // Set it to a empty bucket item_instance->auxiliary = 0; item_instance->count = 1; @@ -154,7 +154,7 @@ static bool BucketItem_isFood(__attribute__((unused)) FoodItem *item) { static ItemInstance *BucketItem_use(FoodItem *item, ItemInstance *item_instance, __attribute__((unused)) Level *level, Player *player) { if (item_instance->auxiliary == 1) { - return FoodItem_use->get()(item, item_instance, level, player); + return FoodItem_use->get(false)(item, item_instance, level, player); } return item_instance; } @@ -188,7 +188,7 @@ static FoodItem *create_bucket(int32_t id, int32_t texture_x, int32_t texture_y, // Construct FoodItem *item = new FoodItem; ALLOC_CHECK(item); - Item_constructor->get()((Item *) item, id); // FoodItem's Constructor Was Inlined + Item_constructor->get(false)((Item *) item, id); // FoodItem's Constructor Was Inlined // Set VTable item->vtable = get_bucket_vtable(); diff --git a/mods/src/death/death.cpp b/mods/src/death/death.cpp index 792066a2..5df8079b 100644 --- a/mods/src/death/death.cpp +++ b/mods/src/death/death.cpp @@ -8,7 +8,7 @@ // Death Messages static const char *monster_names[] = {"Zombie", "Creeper", "Skeleton", "Spider", "Zombie Pigman"}; -std::string get_death_message(Player *player, Entity *cause, bool was_shot = false) { +std::string get_death_message(Player *player, Entity *cause, const bool was_shot = false) { // Prepare Death Message std::string message = player->username; if (cause) { @@ -62,9 +62,9 @@ std::string get_death_message(Player *player, Entity *cause, bool was_shot = fal } static bool is_hurt = false; -static bool Mob_hurt_injection(Mob_hurt_t original, Mob *mob, Entity *source, int dmg) { +static bool Mob_hurt_injection(Mob_hurt_t original, Mob *mob, Entity *source, const int dmg) { is_hurt = true; - bool ret = original(mob, source, dmg); + const bool ret = original(mob, source, dmg); is_hurt = false; return ret; } @@ -87,19 +87,19 @@ static void Player_die_injection(std::function ori server_side_network_handler->displayGameMessage(message); } } -template -static void Player_actuallyHurt_injection(Self *player, int32_t damage) { +template +static void Player_actuallyHurt_injection(std::function original, Self *player, int32_t damage) { // Store Old Health int32_t old_health = player->health; // Call Original Method - Mob_actuallyHurt->get()((Mob *) player, damage); + original((OriginalSelf *) player, damage); if (is_hurt) { return; } // Store New Health - int32_t new_health = player->health; + const int32_t new_health = player->health; // Get Variables RakNetInstance *rak_net_instance = player->minecraft->rak_net_instance; @@ -116,17 +116,23 @@ static void Player_actuallyHurt_injection(Self *player, int32_t damage) { } } } +static void ServerPlayer_actuallyHurt_injection(ServerPlayer *player, const int32_t damage) { + Player_actuallyHurt_injection(Mob_actuallyHurt->get(false), player, damage); +} +static void LocalPlayer_actuallyHurt_injection(LocalPlayer_actuallyHurt_t original, LocalPlayer *player, const int32_t damage) { + Player_actuallyHurt_injection(std::move(original), player, damage); +} // Init void init_death() { // Death Messages if (feature_has("Implement Death Messages", server_auto)) { patch_vtable(ServerPlayer_die, [](ServerPlayer *player, Entity *cause) { - Player_die_injection(Player_die->get(), player, cause); + Player_die_injection(Player_die->get(false), player, cause); }); overwrite_calls(LocalPlayer_die, Player_die_injection); - patch_vtable(LocalPlayer_actuallyHurt, Player_actuallyHurt_injection); - patch_vtable(ServerPlayer_actuallyHurt, Player_actuallyHurt_injection); + overwrite_calls(LocalPlayer_actuallyHurt, LocalPlayer_actuallyHurt_injection); + patch_vtable(ServerPlayer_actuallyHurt, ServerPlayer_actuallyHurt_injection); overwrite_calls(Mob_hurt, Mob_hurt_injection); } diff --git a/mods/src/feature/feature.cpp b/mods/src/feature/feature.cpp index 90cb26ea..056e7fcc 100644 --- a/mods/src/feature/feature.cpp +++ b/mods/src/feature/feature.cpp @@ -6,7 +6,7 @@ #include // Check For Feature -bool _feature_has(const char *name, int server_default) { +bool _feature_has(const char *name, const int server_default) { // Server Handling if (reborn_is_server() && server_default != -1) { return server_default > 0; diff --git a/mods/src/game-mode/game-mode.cpp b/mods/src/game-mode/game-mode.cpp index c5d32129..d23a7180 100644 --- a/mods/src/game-mode/game-mode.cpp +++ b/mods/src/game-mode/game-mode.cpp @@ -21,7 +21,7 @@ static void set_is_survival(bool new_is_survival) { patch((void *) 0x16ee4, size_patch); // Replace Default CreatorMode Constructor With CreatorMode Or SurvivalMode Constructor - overwrite_call((void *) 0x16ef4, new_is_survival ? (void *) SurvivalMode_constructor->get() : (void *) CreatorMode_constructor->get()); + overwrite_call((void *) 0x16ef4, new_is_survival ? (void *) SurvivalMode_constructor->get(true) : (void *) CreatorMode_constructor->get(true)); is_survival = new_is_survival; } @@ -54,7 +54,7 @@ void init_game_mode() { overwrite_calls(Minecraft_setIsCreativeMode, Minecraft_setIsCreativeMode_injection); // Replace CreatorLevel With ServerLevel (This Fixes Beds And Mob Spawning) - overwrite_call((void *) 0x16f84, (void *) ServerLevel_constructor->get()); + overwrite_call((void *) 0x16f84, (void *) ServerLevel_constructor->get(true)); // Allocate Correct Size For ServerLevel uint32_t level_size = sizeof(ServerLevel); diff --git a/mods/src/init/init.cpp b/mods/src/init/init.cpp index ff3280a6..bffb9fb6 100644 --- a/mods/src/init/init.cpp +++ b/mods/src/init/init.cpp @@ -6,7 +6,7 @@ __attribute__((constructor)) static void init() { media_ensure_loaded(); reborn_init_patch(); - enable_all_thunks(reborn_thunk_enabler); + thunk_enabler = reborn_thunk_enabler; run_tests(); init_version(); init_compat(); diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index c505730a..3e2c2344 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -90,7 +90,7 @@ static void Gui_renderHearts_injection(Gui_renderHearts_t original, Gui *gui) { original(gui); } static GuiComponent_blit_t get_blit_with_classic_hud_offset() { - return use_classic_hud ? Gui_renderHearts_GuiComponent_blit_hearts_injection : GuiComponent_blit->get(); + return use_classic_hud ? Gui_renderHearts_GuiComponent_blit_hearts_injection : GuiComponent_blit->get(false); } #define PINK_HEART_FULL 70 #define PINK_HEART_HALF 79 @@ -1039,7 +1039,7 @@ void init_misc() { } // Fix grass_carried's bottom texture - if (feature_has("Fix Grass's Bottom Texture", server_disabled)) { + if (feature_has("Fix Carried Grass's Bottom Texture", server_disabled)) { overwrite_calls(CarriedTile_getTexture2, CarriedTile_getTexture2_injection); } diff --git a/mods/src/sign/sign.cpp b/mods/src/sign/sign.cpp index ba40ecde..0f469a37 100644 --- a/mods/src/sign/sign.cpp +++ b/mods/src/sign/sign.cpp @@ -8,7 +8,7 @@ #include // Open Sign Screen -static void LocalPlayer_openTextEdit_injection(LocalPlayer *local_player, TileEntity *sign) { +static void LocalPlayer_openTextEdit_injection(__attribute__((unused)) LocalPlayer_openTextEdit_t original, LocalPlayer *local_player, TileEntity *sign) { if (sign->type == 4) { Minecraft *minecraft = local_player->minecraft; TextEditScreen *screen = new TextEditScreen; @@ -27,6 +27,6 @@ void sign_key_press(const char key) { void init_sign() { if (feature_has("Fix Sign Placement", server_disabled)) { // Fix Signs - patch_vtable(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection); + overwrite_calls(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection); } } diff --git a/mods/src/title-screen/title-screen.cpp b/mods/src/title-screen/title-screen.cpp index 9d33ea39..dc00d9a2 100644 --- a/mods/src/title-screen/title-screen.cpp +++ b/mods/src/title-screen/title-screen.cpp @@ -70,7 +70,7 @@ static Screen *last_screen = nullptr; static std::string current_splash; static void StartMenuScreen_render_Screen_render_injection(Screen *screen, int x, int y, float param_1) { // Call Original Method - Screen_render->get()(screen, x, y, param_1); + Screen_render->get(false)(screen, x, y, param_1); // Load Splashes static std::vector splashes; diff --git a/mods/src/touch/touch.cpp b/mods/src/touch/touch.cpp index 4dc9cd96..16ecd22d 100644 --- a/mods/src/touch/touch.cpp +++ b/mods/src/touch/touch.cpp @@ -73,10 +73,10 @@ void init_touch() { // Force Touch Inventory if (feature_has("Force Touch GUI Inventory", server_disabled)) { overwrite_call((void *) 0x2943c, (void *) operator_new_IngameBlockSelectionScreen_injection); - overwrite_call((void *) 0x29444, (void *) Touch_IngameBlockSelectionScreen_constructor->get()); + overwrite_call((void *) 0x29444, (void *) Touch_IngameBlockSelectionScreen_constructor->get(true)); // Make "Craft" And "Armor" Buttons Use Classic GUI Style (Button And TButton Have The Same Size) - overwrite_call((void *) 0x3b060, (void *) Button_constructor->get()); - overwrite_call((void *) 0x3b08c, (void *) Button_constructor->get()); + overwrite_call((void *) 0x3b060, (void *) Button_constructor->get(true)); + overwrite_call((void *) 0x3b08c, (void *) Button_constructor->get(true)); } // Force Touch Button Behavior