Add Expand Creative Inventory

This commit is contained in:
TheBrokenRail 2020-11-02 12:34:11 -05:00
parent 56d84d0133
commit fd12a27a51
2 changed files with 51 additions and 1 deletions

View File

@ -4,7 +4,7 @@ set -e
# Ensure Features Are Selected
if [ -z "${MCPI_SUBSHELL}" ]; then
MCPI_FEATURES="$(zenity --class 'Minecraft - Pi edition' --list --checklist --column 'Enabled' --column 'Feature' TRUE 'Touch GUI' FALSE 'Survival Mode' TRUE 'Fix Bow & Arrow' TRUE 'Fix Attacking' TRUE 'Mob Spawning' TRUE 'Fancy Graphics' TRUE 'Disable Autojump By Default' TRUE 'Fix Sign Placement' TRUE 'Show Block Outlines')"
MCPI_FEATURES="$(zenity --class 'Minecraft - Pi edition' --list --checklist --column 'Enabled' --column 'Feature' TRUE 'Touch GUI' FALSE 'Survival Mode' TRUE 'Fix Bow & Arrow' TRUE 'Fix Attacking' TRUE 'Mob Spawning' TRUE 'Fancy Graphics' TRUE 'Disable Autojump By Default' TRUE 'Fix Sign Placement' TRUE 'Show Block Outlines' FALSE 'Expand Creative Inventory')"
MCPI_USERNAME="$(zenity --class 'Minecraft - Pi edition' --entry --text 'Minecraft Username:' --entry-text 'StevePi')"
fi
export MCPI_FEATURES

View File

@ -80,6 +80,51 @@ extern "C" {
extra_clear_input();
}
typedef unsigned char *(*ItemInstance_t)(unsigned char *item_instance, unsigned char *item);
static ItemInstance_t ItemInstance_item = (ItemInstance_t) 0x9992c;
static ItemInstance_t ItemInstance_tile = (ItemInstance_t) 0x998e4;
typedef void (*FillingContainer_addItem_t)(unsigned char *filling_container, unsigned char *item_instance);
static FillingContainer_addItem_t FillingContainer_addItem = (FillingContainer_addItem_t) 0x92aa0;
static void *FillingContainer_addItem_original = NULL;
static void inventory_add_item(unsigned char *inventory, unsigned char *item, bool is_tile) {
unsigned char *item_instance = (unsigned char *) ::operator new(0xc);
item_instance = (*(is_tile ? ItemInstance_tile : ItemInstance_item))(item_instance, item);
(*FillingContainer_addItem)(inventory, item_instance);
}
// Items
static unsigned char **item_flintAndSteel = (unsigned char **) 0x17ba70;
static unsigned char **item_snowball = (unsigned char **) 0x17bbb0;
static unsigned char **item_shears = (unsigned char **) 0x17bbf0;
static unsigned char **item_sign = (unsigned char **) 0x17bba4;
// Tiles
static unsigned char **tile_water = (unsigned char **) 0x181b3c;
static unsigned char **tile_lava = (unsigned char **) 0x181cc8;
static unsigned char **tile_glowing_obsidian = (unsigned char **) 0x181dcc;
static unsigned char **tile_invisible_bedrock = (unsigned char **) 0x181d94;
static void FillingContainer_addItem_injection(unsigned char *filling_container, unsigned char *item_instance) {
// Call Original
revert_overwrite((void *) FillingContainer_addItem, FillingContainer_addItem_original);
(*FillingContainer_addItem)(filling_container, item_instance);
revert_overwrite((void *) FillingContainer_addItem, FillingContainer_addItem_original);
// Add After Sign
if (*(int32_t *) (item_instance + 0x4) == *(int32_t *) (*item_sign + 0x4)) {
// Add Items
inventory_add_item(filling_container, *item_flintAndSteel, false);
inventory_add_item(filling_container, *item_snowball, false);
inventory_add_item(filling_container, *item_shears, false);
// Add Tiles
inventory_add_item(filling_container, *tile_water, true);
inventory_add_item(filling_container, *tile_lava, true);
inventory_add_item(filling_container, *tile_glowing_obsidian, true);
inventory_add_item(filling_container, *tile_invisible_bedrock, true);
}
}
__attribute((constructor)) static void init() {
// Implement AppPlatform::readAssetFile So Translations Work
overwrite((void *) 0x12b10, (void *) readAssetFile);
@ -89,5 +134,10 @@ extern "C" {
patch_address((void *) 0x106460, (void *) openTextEdit);
Screen_updateEvents_original = overwrite((void *) Screen_updateEvents, (void *) Screen_updateEvents_injection);
}
if (extra_has_feature("Expand Creative Inventory")) {
// Add Extra Items To Creative Inventory
FillingContainer_addItem_original = overwrite((void *) FillingContainer_addItem, (void *) FillingContainer_addItem_injection);
}
}
}