From eeef63d9ef115fcbabaa97ebcc9f7d6f9a361d49 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 9 May 2024 19:03:48 -0400 Subject: [PATCH] Improve Creative Restrictions Mod --- docs/CHANGELOG.md | 7 +++ launcher/src/client/available-feature-flags | 4 ++ libreborn/include/libreborn/patch.h | 2 +- mods/src/creative/creative.cpp | 55 +++++++++++-------- .../src/level/container/FillingContainer.def | 2 + symbols/src/level/container/Inventory.def | 2 + 6 files changed, 49 insertions(+), 23 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 854e4a8355..c52e532369 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,6 +16,13 @@ * Add `Optimized Chunk Sorting` Feature Flag (Enabled By Default) * Add `Add Cake` Feature Flag (Enabled By Default) * Add `Add Reborn Info To Options` Feature Flag (Enabled By Default) +* Add `Track FPS` Feature Flag (Disabled By Default) +* Split Up `Remove Creative Mode Restrictions` Feature Flag + * `Remove Creative Mode Restrictions` (Disabled By Default) + * `Display Slot Count In Creative Mode` (Disabled By Default) + * `Force Survival Mode Inventory UI` (Disabled By Default) + * `Force Survival Mode Inventory Behavior` (Disabled By Default) + * `Maximize Creative Mode Inventory Stack Size` (Disabled By Default) * Add Milk Buckets * Implement Crafting Remainders * Improve Death Messages diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index e365ed544f..838f39fb2e 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -8,6 +8,10 @@ TRUE Fix Sign Placement TRUE Show Block Outlines FALSE Expand Creative Mode Inventory FALSE Remove Creative Mode Restrictions +FALSE Display Slot Count In Creative Mode +FALSE Force Survival Mode Inventory UI +FALSE Force Survival Mode Inventory Behavior +FALSE Maximize Creative Mode Inventory Stack Size TRUE Animated Water TRUE Animated Lava TRUE Animated Fire diff --git a/libreborn/include/libreborn/patch.h b/libreborn/include/libreborn/patch.h index bb8fda3c22..fc35a45944 100644 --- a/libreborn/include/libreborn/patch.h +++ b/libreborn/include/libreborn/patch.h @@ -22,7 +22,6 @@ void _overwrite_call(const char *file, int line, void *start, void *target); } #define _setup_fancy_overwrite(start, name, target) \ - _check_if_method_is_new(name); \ static name##_t _original_for_##target = start; \ static name##_t _helper_for_##target = __overwrite_helper_for_##name(target, _original_for_##target) @@ -38,6 +37,7 @@ void *_overwrite_calls(const char *file, int line, void *start, void *target); // Replace All Calls To Virtual Method start With target #define overwrite_virtual_calls(start, target) \ { \ + _check_if_method_is_new(start); \ _setup_fancy_overwrite(*start##_vtable_addr, start, target); \ overwrite_calls_manual((void *) *start##_vtable_addr, (void *) _helper_for_##target); \ } diff --git a/mods/src/creative/creative.cpp b/mods/src/creative/creative.cpp index a0437edfa5..af24eb3874 100644 --- a/mods/src/creative/creative.cpp +++ b/mods/src/creative/creative.cpp @@ -127,38 +127,49 @@ void init_creative() { } // Remove Creative Mode Restrictions (Opening Chests, Crafting, Etc) + unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" if (feature_has("Remove Creative Mode Restrictions", server_enabled)) { - unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" // Remove Restrictions patch((void *) 0x43ee8, nop_patch); patch((void *) 0x43f3c, nop_patch); patch((void *) 0x43f8c, nop_patch); patch((void *) 0x43fd8, nop_patch); patch((void *) 0x99010, nop_patch); - // Fix UI - patch((void *) 0x341c0, nop_patch); - patch((void *) 0x3adb4, nop_patch); - patch((void *) 0x3b374, nop_patch); - // Fix Inventory - patch((void *) 0x8d080, nop_patch); - patch((void *) 0x8d090, nop_patch); - patch((void *) 0x91d48, nop_patch); - patch((void *) 0x92098, nop_patch); - unsigned char inv_creative_check_r3_patch[4] = {0x03, 0x00, 0x53, 0xe1}; // "cmp r3, r3" - patch((void *) 0x923c0, inv_creative_check_r3_patch); - patch((void *) 0x92828, nop_patch); - patch((void *) 0x92830, nop_patch); - // Display Slot Count - patch((void *) 0x1e3f4, nop_patch); - unsigned char slot_count_patch[4] = {0x18, 0x00, 0x00, 0xea}; // "b 0x27110" - patch((void *) 0x270a8, slot_count_patch); - patch((void *) 0x33954, nop_patch); - // Maximize Creative Inventory Stack Size - unsigned char maximize_stack_patch[4] = {0xff, 0xc0, 0xa0, 0xe3}; // "mov r12, 0xff" - patch((void *) 0x8e104, maximize_stack_patch); // Allow Nether Reactor patch((void *) 0xc0290, nop_patch); // Disable Other Restrictions is_restricted = 0; } + + // Inventory Behavior + if (feature_has("Force Survival Mode Inventory Behavior", server_enabled)) { + patch((void *) 0x8d080, nop_patch); // Inventory::add + patch((void *) 0x92828, nop_patch); // FillingContainer::add + patch((void *) 0x91d48, nop_patch); // FillingContainer::hasResource + patch((void *) 0x92098, nop_patch); // FillingContainer::removeResource(int) + unsigned char inv_creative_check_r3_patch[4] = {0x03, 0x00, 0x53, 0xe1}; // "cmp r3, r3" + patch((void *) 0x923c0, inv_creative_check_r3_patch); // FillingContainer::removeResource(ItemInstance const&, bool) + } + + // "Craft" And "Armor" Buttons + if (feature_has("Force Survival Mode Inventory UI", server_enabled)) { + patch((void *) 0x341c0, nop_patch); // Add "Armor" Button To Classic Inventory + unsigned char inv_creative_check_r5_patch[4] = {0x05, 0x00, 0x55, 0xe1}; // "cmp r5, r5" + patch((void *) 0x3adb0, inv_creative_check_r5_patch); // Reposition "Select blocks" In Touch Inventory + patch((void *) 0x3b374, nop_patch); // Add "Armor" And "Craft" Buttons To Touch Inventory + } + + // Display Slot Count + if (feature_has("Display Slot Count In Creative Mode", server_enabled)) { + patch((void *) 0x1e3f4, nop_patch); + unsigned char slot_count_patch[4] = {0x18, 0x00, 0x00, 0xea}; // "b 0x27110" + patch((void *) 0x270a8, slot_count_patch); + patch((void *) 0x33954, nop_patch); + } + + // Maximize Creative Inventory Stack Size + if (feature_has("Maximize Creative Mode Inventory Stack Size", server_enabled)) { + unsigned char maximize_stack_patch[4] = {0xff, 0xc0, 0xa0, 0xe3}; // "mov r12, 0xff" + patch((void *) 0x8e104, maximize_stack_patch); + } } diff --git a/symbols/src/level/container/FillingContainer.def b/symbols/src/level/container/FillingContainer.def index 6581905099..7607a6ffc5 100644 --- a/symbols/src/level/container/FillingContainer.def +++ b/symbols/src/level/container/FillingContainer.def @@ -1,5 +1,7 @@ extends Container; +vtable 0x10e250; + method void addItem(ItemInstance *item_instance) = 0x92aa0; method void clearSlot(int slot) = 0x922f8; method void release(int slot) = 0x92058; diff --git a/symbols/src/level/container/Inventory.def b/symbols/src/level/container/Inventory.def index 6a7441f38e..97be10c746 100644 --- a/symbols/src/level/container/Inventory.def +++ b/symbols/src/level/container/Inventory.def @@ -1,5 +1,7 @@ extends FillingContainer; +vtable 0x10de18; + method void selectSlot(int slot) = 0x8d13c; // It's just FillingContainer_getLinked but with selectedSlot as slot method ItemInstance *getSelected() = 0x8d134;