diff --git a/CREDITS.md b/CREDITS.md new file mode 100644 index 0000000..d3ad775 --- /dev/null +++ b/CREDITS.md @@ -0,0 +1,10 @@ +# Credits +| Project | Reason | +| --- | --- | +| [mhsjlw/mcpilauncher](https://github.com/mhsjlw/mcpilauncher/blob/master/trampoline/trampoline.c) | Information On Getting Minecraft: Pi Eiditon To Run On Desktop Linux | +| [Phirel's Survival Patch](https://www.minecraftforum.net/forums/minecraft-editions/minecraft-pi-edition/1960005-survival-mode-patch) | Information On Survival Mode Support | +| [zhuowei/MinecraftPEModWiki](https://github.com/zhuowei/MinecraftPEModWiki/wiki/How-some-unlocks-are-made) | Information On Smooth Lighting Support | +| [Ghidra](https://ghidra-sre.org) | Used For Decompiling Minecraft: Pi Edition | +| [RetDec](https://retdec.com) | Used For Decompiling Minecraft: Pi Edition | +| [minecraft-linux/mcpelauncher-core](https://github.com/minecraft-linux/mcpelauncher-core/blob/6b5e17b5685a612143297ae4595bdd12327284f3/src/patch_utils.cpp#L42) | Original Function Overwrite Code | +| [Hooking C Functions at Runtime - Thomas Finch](http://thomasfinch.me/blog/2015/07/24/Hooking-C-Functions-At-Runtime.html) | Original Patching Code | \ No newline at end of file diff --git a/debian/client/common/usr/bin/minecraft-pi b/debian/client/common/usr/bin/minecraft-pi index 2855257..497eb2a 100755 --- a/debian/client/common/usr/bin/minecraft-pi +++ b/debian/client/common/usr/bin/minecraft-pi @@ -4,7 +4,21 @@ 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' FALSE 'Expand Creative Inventory' FALSE 'Peaceful Mode' TRUE 'Animated Water' TRUE 'Remove Invalid Item Background')" + 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' \ + TRUE 'Animated Water' \ + TRUE 'Remove Invalid Item Background' \ + TRUE 'Smooth Lighting')" MCPI_USERNAME="$(zenity --class 'Minecraft - Pi edition' --entry --text 'Minecraft Username:' --entry-text 'StevePi')" fi export MCPI_FEATURES diff --git a/mods/src/compat.c b/mods/src/compat.c index 6e98fcf..78f4508 100644 --- a/mods/src/compat.c +++ b/mods/src/compat.c @@ -455,6 +455,12 @@ HOOK(SDL_GetWMInfo, int, (SDL_SysWMinfo *info)) { return 1; } +// Force Smooth Shading In Smooth Lighting Mode +HOOK(glShadeModel, void, (GLenum mode)) { + ensure_glShadeModel(); + (*real_glShadeModel)(extra_get_smooth_lighting() ? GL_SMOOTH : mode); +} + #include // Use VirGL diff --git a/mods/src/extra.c b/mods/src/extra.c index 4dbf8d3..4c5d42b 100644 --- a/mods/src/extra.c +++ b/mods/src/extra.c @@ -7,10 +7,12 @@ #include "server/server.h" static int mob_spawning = 0; +// Override Mob Spawning static uint32_t LevelData_getSpawnMobs_injection(__attribute__((unused)) unsigned char *level_data) { return mob_spawning; } +// Store Right-Click Status static int is_right_click = 0; void extra_set_is_right_click(int val) { is_right_click = val; @@ -27,6 +29,7 @@ static Player_isUsingItem_t Player_isUsingItem = (Player_isUsingItem_t) 0x8f15c; // Enable Bow & Arrow Fix static int fix_bow = 0; +// Handle Input Fixes static void Minecraft_tickInput_injection(unsigned char *minecraft) { // Call Original Method (*Minecraft_tickInput)(minecraft); @@ -52,6 +55,7 @@ static Gui_tickItemDrop_t Gui_tickItemDrop = (Gui_tickItemDrop_t) 0x27778; #include +// Block UI Interaction When Mouse Is Locked static void Gui_tickItemDrop_injection(unsigned char *this) { if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) { // Call Original Method @@ -62,6 +66,7 @@ static void Gui_tickItemDrop_injection(unsigned char *this) { typedef void (*Gui_handleClick_t)(unsigned char *this, int32_t param_2, int32_t param_3, int32_t param_4); static Gui_handleClick_t Gui_handleClick = (Gui_handleClick_t) 0x2599c; +// Block UI Interaction When Mouse Is Locked static void Gui_handleClick_injection(unsigned char *this, int32_t param_2, int32_t param_3, int32_t param_4) { if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) { // Call Original Method @@ -98,6 +103,7 @@ static void set_is_survival(int new_is_survival) { typedef void (*Minecraft_setIsCreativeMode_t)(unsigned char *, int32_t); static Minecraft_setIsCreativeMode_t Minecraft_setIsCreativeMode = (Minecraft_setIsCreativeMode_t) 0x16ec4; +// Handle Gamemode Switching static void Minecraft_setIsCreativeMode_injection(unsigned char *this, int32_t new_game_mode) { set_is_survival(!new_game_mode); @@ -105,6 +111,7 @@ static void Minecraft_setIsCreativeMode_injection(unsigned char *this, int32_t n (*Minecraft_setIsCreativeMode)(this, new_game_mode); } +// Get Custom Username static char *get_username() { char *username = getenv("MCPI_USERNAME"); if (username == NULL) { @@ -118,6 +125,7 @@ static Minecraft_init_t Minecraft_init = (Minecraft_init_t) 0x1700c; static int fancy_graphics; static int peaceful_mode; +// Configure Options static void Minecraft_init_injection(unsigned char *this) { // Call Original Method (*Minecraft_init)(this); @@ -157,6 +165,7 @@ int extra_has_feature(const char *name) { } } +// Get Graphics Mode int extra_get_mode() { char *mode = getenv("MCPI_MODE"); if (mode == NULL) { @@ -172,10 +181,17 @@ int extra_get_mode() { } } +// Enable Touch GUI static int32_t Minecraft_isTouchscreen(__attribute__((unused)) unsigned char *minecraft) { return 1; } +// Store Smooth Lighting +static int smooth_lighting; +int extra_get_smooth_lighting() { + return smooth_lighting; +} + __attribute__((constructor)) static void init() { is_server = extra_get_mode() == 2; if (is_server) { @@ -286,4 +302,11 @@ __attribute__((constructor)) static void init() { unsigned char invalid_item_background_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; patch((void *) 0x63c98, invalid_item_background_patch); } + + smooth_lighting = extra_has_feature("Smooth Lighting"); + if (smooth_lighting) { + // Enable Smooth Lighting + unsigned char smooth_lighting_patch[4] = {0x01, 0x00, 0x53, 0xe3}; + patch((void *) 0x59ea4, smooth_lighting_patch); + } } diff --git a/mods/src/extra.cpp b/mods/src/extra.cpp index 2d62348..8302f76 100644 --- a/mods/src/extra.cpp +++ b/mods/src/extra.cpp @@ -13,6 +13,7 @@ #include extern "C" { + // Read Asset File static cxx11_string AppPlatform_readAssetFile(__attribute__((unused)) unsigned char *app_platform, std::string const& path) { std::string full_path("./data/"); full_path.append(path); @@ -27,6 +28,7 @@ extern "C" { typedef void (*Minecraft_setScreen_t)(unsigned char *, unsigned char *); static Minecraft_setScreen_t Minecraft_setScreen = (Minecraft_setScreen_t) 0x15d6c; + // Open Sign Screen static void LocalPlayer_openTextEdit(unsigned char *local_player, unsigned char *sign) { if (*(int *)(sign + 0x18) == 4) { unsigned char *minecraft = *(unsigned char **) (local_player + 0xc90); @@ -42,6 +44,7 @@ extern "C" { return (key >= 32 && key <= 126) || key == BACKSPACE_KEY; } + // Store Text Input std::vector input; void extra_key_press(char key) { if (is_valid_key(key)) { @@ -58,8 +61,9 @@ extern "C" { typedef void (*Screen_keyboardNewChar_t)(unsigned char *screen, char key); typedef void (*Screen_keyPressed_t)(unsigned char *screen, int32_t key); + // Handle Text Input static void Screen_updateEvents_injection(unsigned char *screen) { - // Call Original + // Call Original Method (*Screen_updateEvents)(screen); if (*(char *)(screen + 4) == '\0') { diff --git a/mods/src/extra.h b/mods/src/extra.h index 146e0e8..2bb45d4 100644 --- a/mods/src/extra.h +++ b/mods/src/extra.h @@ -14,6 +14,8 @@ void extra_clear_input(); void extra_set_is_right_click(int val); +int extra_get_smooth_lighting(); + #ifdef __cplusplus } #endif