Add Peaceful Mode
All checks were successful
minecraft-pi-docker/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-11-12 18:28:37 -05:00
parent 107fa29d8d
commit 1d14cc5059
2 changed files with 30 additions and 29 deletions

View File

@ -4,7 +4,7 @@ set -e
# Ensure Features Are Selected # Ensure Features Are Selected
if [ -z "${MCPI_SUBSHELL}" ]; then 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' FALSE 'Expand Creative Inventory')" 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' FALSE 'Peaceful Mode')"
MCPI_USERNAME="$(zenity --class 'Minecraft - Pi edition' --entry --text 'Minecraft Username:' --entry-text 'StevePi')" MCPI_USERNAME="$(zenity --class 'Minecraft - Pi edition' --entry --text 'Minecraft Username:' --entry-text 'StevePi')"
fi fi
export MCPI_FEATURES export MCPI_FEATURES

View File

@ -116,12 +116,19 @@ static char *get_username() {
typedef void (*Minecraft_init_t)(unsigned char *this); typedef void (*Minecraft_init_t)(unsigned char *this);
static Minecraft_init_t Minecraft_init = (Minecraft_init_t) 0x1700c; static Minecraft_init_t Minecraft_init = (Minecraft_init_t) 0x1700c;
static int fancy_graphics;
static int peaceful_mode;
static void Minecraft_init_injection(unsigned char *this) { static void Minecraft_init_injection(unsigned char *this) {
// Call Original Method // Call Original Method
(*Minecraft_init)(this); (*Minecraft_init)(this);
unsigned char *options = this + 0x3c;
// Enable Fancy Graphics // Enable Fancy Graphics
*(this + 83) = 1; *(options + 0x17) = fancy_graphics;
// Enable Crosshair In Touch GUI
*(options + 0x105) = 1;
// Peaceful Mode
*(int32_t *) (options + 0xe8) = peaceful_mode ? 0 : 2;
} }
// Is Dedicated Server // Is Dedicated Server
@ -165,31 +172,23 @@ int extra_get_mode() {
} }
} }
static int32_t Minecraft_isTouchscreen(__attribute__((unused)) unsigned char *minecraft) {
return 1;
}
__attribute__((constructor)) static void init() { __attribute__((constructor)) static void init() {
is_server = extra_get_mode() == 2; is_server = extra_get_mode() == 2;
if (is_server) { if (is_server) {
server_init(); server_init();
} }
if (!is_server && extra_has_feature("Touch GUI")) { int touch_gui = !is_server && extra_has_feature("Touch GUI");
if (touch_gui) {
// Main UI // Main UI
unsigned char touch_gui_patch[4] = {0x01, 0x00, 0x50, 0xe3}; overwrite((void *) 0x1639c, Minecraft_isTouchscreen);
patch((void *) 0x292fc, touch_gui_patch); // Force Correct Toolbar Size
// Invalid License UI unsigned char toolbar_patch[4] = {0x01, 0x00, 0x50, 0xe3};
patch((void *) 0x3a008, touch_gui_patch); patch((void *) 0x257b0, toolbar_patch);
// Disconnection UI
patch((void *) 0x371f0, touch_gui_patch);
// Pause UI
patch((void *) 0x36824, touch_gui_patch);
// Bed UI
patch((void *) 0x336d0, touch_gui_patch);
// Game Mode UI
patch((void *) 0x31474, touch_gui_patch);
// Death UI
patch((void *) 0x3055c, touch_gui_patch);
// Delete UI
unsigned char delete_touch_gui[4] = {0x01, 0x70, 0x50, 0xe2};
patch((void *) 0x2ad04, delete_touch_gui);
} }
// Dynamic Game Mode Switching // Dynamic Game Mode Switching
@ -244,10 +243,13 @@ __attribute__((constructor)) static void init() {
unsigned char level_size_patch[4] = {0x94, 0x0b, 0x00, 0x00}; unsigned char level_size_patch[4] = {0x94, 0x0b, 0x00, 0x00};
patch((void *) 0x17004, level_size_patch); patch((void *) 0x17004, level_size_patch);
if (extra_has_feature("Fancy Graphics")) {
// Enable Fancy Graphics // Enable Fancy Graphics
fancy_graphics = extra_has_feature("Fancy Graphics");
// Peaceful Mode
peaceful_mode = extra_has_feature("Peaceful Mode");
// Set Options
overwrite_calls((void *) Minecraft_init, Minecraft_init_injection); overwrite_calls((void *) Minecraft_init, Minecraft_init_injection);
}
// Allow Connecting To Non-Pi Servers // Allow Connecting To Non-Pi Servers
unsigned char server_patch[4] = {0x0f, 0x00, 0x00, 0xea}; unsigned char server_patch[4] = {0x0f, 0x00, 0x00, 0xea};
@ -274,9 +276,8 @@ __attribute__((constructor)) static void init() {
patch((void *) 0x44b90, autojump_patch); patch((void *) 0x44b90, autojump_patch);
} }
if (extra_has_feature("Show Block Outlines")) {
// Show Block Outlines // Show Block Outlines
unsigned char outline_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; int block_outlines = extra_has_feature("Show Block Outlines");
unsigned char outline_patch[4] = {block_outlines ? touch_gui : !touch_gui, 0xf0, 0x20, 0xe3};
patch((void *) 0x4a214, outline_patch); patch((void *) 0x4a214, outline_patch);
} }
}