This commit is contained in:
TheBrokenRail 2021-01-27 16:26:19 -05:00
parent 62204aa1bf
commit 0ccc05ad90
45 changed files with 126 additions and 149 deletions

View File

@ -1,3 +1,3 @@
FROM thebrokenrail/minecraft-pi:client
FROM thebrokenrail/minecraft-pi-reborn:client
ENV MCPI_MODE=server

View File

@ -1,5 +1,5 @@
# Modding
Modding Minecraft: Pi Edition is possible by patching the binary at runtime. To make this easier ``minecraft-pi-reborn`` includes a library called ``libcore.so`` which provides several functions to help you patch the game.
Modding Minecraft: Pi Edition is possible by patching the binary at runtime. To make this easier ``minecraft-pi-reborn`` includes a library called ``libreborn.so`` which provides several functions to help you patch the game.
## Hex Addresses
Minecraft: Pi Edition has no symbols so you must patch the hex address of an instruction instead of using a function name. Hex addresses can be found using tools like [Ghidra](https://ghidra-sre.org) or [RetDec](https://retdec.com). To find out what a function does, you can find its equivalent in Minecraft: Pocket Edition 0.6.1 and use its name for reference because Minecraft: Pocket Edition 0.6.1 includes symbols.
@ -10,7 +10,7 @@ Minecraft: Pi Edition has no symbols so you must patch the hex address of an ins
## C++ Strings
Minecraft: Pi Edition was compiled with an old version of GCC, so when interacting with C++ strings, make sure you set ``-D_GLIBCXX_USE_CXX11_ABI=0``.
## ``libcore.so`` API
## ``libreborn.so`` API
Header files and the shared library can be download from [Jenkins](https://jenkins.thebrokenrail.com/job/minecraft-pi-reborn/job/master/lastSuccessfulBuild/artifact/out/lib).
### ``void overwrite(void *start, void *target)``

View File

@ -1,10 +1,11 @@
# Minecraft: Pi Edition: Reborn
Minecraft: Pi Edition Modding Project
## Setup
## Getting Started
1. Remove Old Minecraft: Pi Edition Package If Installed (``sudo apt remove minecraft-pi``)
2. Download Appropriate Package (See Table Below) From [Here](https://jenkins.thebrokenrail.com/job/minecraft-pi-reborn/job/master/lastSuccessfulBuild/artifact/out/deb/)
2. Download Appropriate Package From [Here](https://jenkins.thebrokenrail.com/job/minecraft-pi-reborn/job/master/lastSuccessfulBuild/artifact/out/deb/) (See Table Below)
3. Install With ``sudo apt install ./<Path To File>``
4. Have Fun!
### Packages
| Package | Description |
@ -18,9 +19,7 @@ Minecraft: Pi Edition Modding Project
#### Docker Versions
While the distribution-provided version of Docker is fine for most systems, in rare cases it can be outdated and cause bugs. Before reporting a bug, try using the official builds of Docker. These can be installed by following your distribution's instructions at https://docs.docker.com/engine/install.
### Specific Notes
#### Debian/Raspbian Buster
#### Debian/Raspbian Buster And ``libseccomp2``
By default Raspbian Buster ships an older version of the package ``libseccomp2``. This package is used to block certain dangerous system calls from running inside Docker containers. The included version accidentally blocks the system call ``clock_gettime64``, this causes bugs inside Minecraft: Pi Edition. However, the Debian ``buster-backports`` repo includes an updated version. You can enable the ``buster-backports`` repo and update ``libseccomp2`` by running:
```sh
@ -35,9 +34,6 @@ sudo apt update
sudo apt install -t buster-backports libseccomp2
```
### PinePhone (Mobian)
This supports running on a PinePhone using Mobian. However, you will need to attach a keyboard and mouse because Minecraft: Pi Edition does not have touch support.
## Troubleshooting Crashes
Game logs are located in ``/tmp/minecraft-pi``.

View File

@ -2,6 +2,17 @@
set -e
cd launcher
mkdir build
cd build
cmake ..
make -j$(nproc)
make install DESTDIR=../../minecraft-pi
cd ../../
cd mods
mkdir build
@ -9,11 +20,6 @@ cd build
cmake ..
make -j$(nproc)
make install DESTDIR=../../minecraft-pi
cd ../../
mkdir minecraft-pi/mods
cp mods/build/lib*.so minecraft-pi/mods
cp mods/build/core/lib*.so minecraft-pi
cp mods/build/core/launcher minecraft-pi

View File

@ -1,15 +0,0 @@
cmake_minimum_required(VERSION 3.1.0)
project(core)
add_compile_options(-Wall -Wextra -Werror)
add_library(bcm_host SHARED src/stubs/bcm_host.c)
add_library(EGL SHARED src/stubs/EGL.c)
# MCPI Links Against GLESv2 But Requires GLESv1_CM
add_library(GLESv2 SHARED src/stubs/GLESv2.c)
target_link_libraries(GLESv2 GLESv1_CM)
target_link_options(GLESv2 PRIVATE "-Wl,--no-as-needed")
add_executable(launcher src/launcher.c)

View File

@ -1,7 +1,7 @@
version: '3'
services:
minecraft-pi:
image: 'thebrokenrail/minecraft-pi:client'
image: 'thebrokenrail/minecraft-pi-reborn:client'
network_mode: 'host'
volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static

View File

@ -1,7 +1,7 @@
version: '3'
services:
minecraft-pi:
image: 'thebrokenrail/minecraft-pi:client'
image: 'thebrokenrail/minecraft-pi-reborn:client'
network_mode: 'host'
volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static

View File

@ -1,7 +1,7 @@
version: '3'
services:
minecraft-pi-server:
image: 'thebrokenrail/minecraft-pi:server'
image: 'thebrokenrail/minecraft-pi-reborn:server'
network_mode: 'host'
volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static

10
launcher/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1.0)
project(launcher)
add_compile_options(-Wall -Wextra -Werror)
add_executable(launcher src/launcher.c)
# Install
install(TARGETS launcher DESTINATION /)

View File

@ -111,9 +111,7 @@ int main(__attribute__((unused)) int argc, char *argv[]) {
char *ld_path = NULL;
// Start Configuring LD_LIBRARY_PATH
char *cwd = getcwd(NULL, 0);
asprintf(&ld_path, "%s:/usr/arm-linux-gnueabihf/lib", cwd);
free(cwd);
asprintf(&ld_path, "/usr/arm-linux-gnueabihf/lib");
// Start Configuring LD_PRELOAD
char *ld_preload = NULL;

13
libreborn/CMakeLists.txt Normal file
View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.13.0)
project(libreborn)
add_compile_options(-Wall -Wextra -Werror)
add_link_options(-Wl,--no-undefined)
add_library(reborn SHARED src/libreborn.c)
target_link_libraries(reborn dl)
target_include_directories(reborn PUBLIC include)
# Install
install(TARGETS reborn DESTINATION /mods)

View File

@ -1,6 +1,4 @@
#ifndef LIBLOADER_H
#define LIBLOADER_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -47,5 +45,3 @@ void _patch_address(const char *file, int line, void *start, void *target);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -7,7 +7,7 @@
#include <elf.h>
#include <errno.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
// Find And Iterate Over All .text Sections In Current Binary
typedef void (*text_section_callback)(void *section, Elf32_Word size, void *data);

View File

@ -2,60 +2,78 @@ cmake_minimum_required(VERSION 3.13.0)
project(mods)
## Setup
add_compile_options(-Wall -Wextra -Werror)
add_link_options(-Wl,--no-undefined)
# Disable C++11 String ABI
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_subdirectory(../core core)
# Add libreborn
add_subdirectory(../libreborn libreborn)
# Include Libraries Exported To Runtime Environment
include_directories(/app/export/include)
# Include Headers
include_directories(include)
# Find GLFW
find_package(glfw3 3.3 REQUIRED)
## Mods
add_library(compat SHARED src/compat/compat.c)
target_link_libraries(compat feature input screenshot SDL GLESv1_CM X11 dl glfw Xfixes)
add_library(readdir SHARED src/compat/readdir.c)
add_library(core SHARED src/core/core.c)
target_link_libraries(core dl)
add_library(readdir SHARED src/readdir/readdir.c)
add_library(feature SHARED src/feature/feature.c)
target_link_libraries(feature reborn)
add_library(server SHARED src/server/server.cpp src/server/server_properties.cpp)
target_link_libraries(server core feature dl SDL pthread)
target_link_libraries(server reborn feature dl SDL pthread)
add_library(screenshot SHARED src/screenshot/screenshot.c)
target_link_libraries(screenshot GLESv1_CM freeimage)
target_link_libraries(screenshot reborn GLESv1_CM freeimage)
add_library(camera SHARED src/camera/camera.cpp)
target_link_libraries(camera core screenshot)
target_link_libraries(camera reborn screenshot)
add_library(game_mode SHARED src/game_mode/game_mode.c src/game_mode/game_mode.cpp)
target_link_libraries(game_mode core)
target_link_libraries(game_mode reborn)
add_library(input SHARED src/input/input.c src/input/input.cpp)
target_link_libraries(input core feature SDL)
target_link_libraries(input reborn feature SDL)
add_library(misc SHARED src/misc/misc.c src/misc/misc.cpp)
target_link_libraries(misc core feature util)
target_link_libraries(misc reborn feature util)
add_library(options SHARED src/options/options.c)
target_link_libraries(options core feature)
target_link_libraries(options reborn feature)
add_library(override SHARED src/override/override.c)
target_link_libraries(override dl)
target_link_libraries(override reborn dl)
add_library(textures SHARED src/textures/textures.cpp)
target_link_libraries(textures core feature GLESv1_CM)
target_link_libraries(textures reborn feature GLESv1_CM)
add_library(test SHARED src/test/test.c)
target_link_libraries(test reborn)
add_library(init SHARED src/init/init.c)
target_link_libraries(init compat server game_mode camera input misc options textures test)
## Stubs
# Stub RPI-Specific Graphics
add_library(bcm_host SHARED src/stubs/bcm_host.c)
# Stub EGL
add_library(EGL SHARED src/stubs/EGL.c)
target_link_libraries(EGL compat)
# MCPI Links Against GLESv2 But Uses GLESv1_CM
add_library(GLESv2 SHARED src/stubs/GLESv2.c)
target_link_libraries(GLESv2 GLESv1_CM)
target_link_options(GLESv2 PRIVATE "-Wl,--no-as-needed")
## Install
install(TARGETS init compat readdir feature screenshot override server game_mode camera input misc options textures test bcm_host EGL GLESv2 DESTINATION /mods)

View File

@ -1,4 +1,4 @@
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../screenshot/screenshot.h"
#include "../init/init.h"

View File

@ -14,13 +14,15 @@
#include <GLES/gl.h>
#include <X11/Xlib.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "../input/input.h"
#include "../screenshot/screenshot.h"
#include "../init/init.h"
#include "compat.h"
static GLFWwindow *glfw_window;
static int is_server = 0;
@ -202,14 +204,11 @@ HOOK(SDL_WM_SetCaption, void, (const char *title, __attribute__((unused)) const
}
}
#include <EGL/egl.h>
HOOK(eglSwapBuffers, EGLBoolean, (__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface surface)) {
void compat_eglSwapBuffers() {
if (!is_server) {
// Don't Swap Buffers In A Context-Less Window
glfwSwapBuffers(glfw_window);
}
return EGL_TRUE;
}
static int is_fullscreen = 0;

3
mods/src/compat/compat.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void compat_eglSwapBuffers();

View File

@ -1,7 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "feature.h"

View File

@ -1,6 +1,4 @@
#ifndef FEATURE_H
#define FEATURE_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -12,5 +10,3 @@ int feature_get_mode();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,4 +1,4 @@
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "game_mode.h"
#include "../init/init.h"

View File

@ -1,4 +1,4 @@
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "game_mode.h"

View File

@ -1,6 +1,4 @@
#ifndef GAME_MODE_H
#define GAME_MODE_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -11,5 +9,3 @@ void init_game_mode_cpp();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,4 @@
#ifndef INIT_H
#define INIT_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -19,5 +17,3 @@ void init_textures();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,4 +1,4 @@
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "input.h"

View File

@ -1,6 +1,6 @@
#include <vector>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "input.h"

View File

@ -1,6 +1,4 @@
#ifndef INPUT_H
#define INPUT_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -20,5 +18,3 @@ void init_input_cpp();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,4 @@
#ifndef MINECRAFT_H
#define MINECRAFT_H
#pragma once
#include <stdint.h>
@ -368,5 +366,3 @@ static SelectWorldScreen_getUniqueLevelName_t Touch_SelectWorldScreen_getUniqueL
#endif
#pragma GCC diagnostic pop
#endif

View File

@ -1,4 +1,4 @@
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "misc.h"

View File

@ -4,7 +4,7 @@
#include <cstring>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "misc.h"

View File

@ -1,6 +1,4 @@
#ifndef MISC_H
#define MISC_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -11,5 +9,3 @@ void init_misc_cpp();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,6 @@
#include <string.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "../init/init.h"

View File

@ -8,7 +8,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
static int starts_with(const char *s, const char *t) {
return strncmp(s, t, strlen(t)) == 0;

View File

@ -9,7 +9,7 @@
#include <GLES/gl.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "screenshot.h"

View File

@ -1,6 +1,4 @@
#ifndef SCREENSHOT_H
#define SCREENSHOT_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -11,5 +9,3 @@ void take_screenshot();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -12,9 +12,8 @@
#include <SDL/SDL_events.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "server.h"
#include "server_internal.h"
#include "server_properties.h"

View File

@ -1,15 +0,0 @@
#ifndef SERVER_H
#define SERVER_H
#ifdef __cplusplus
extern "C" {
#endif\
const char *server_get_motd();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,4 @@
#ifndef SERVER_INTERNAL_H
#define SERVER_INTERNAL_H
#pragma once
#include <string>
#include <vector>
@ -10,5 +8,3 @@ unsigned char *server_internal_get_level(unsigned char *minecraft);
std::vector<unsigned char *> server_internal_get_players(unsigned char *level);
std::string server_internal_get_player_username(unsigned char *player);
unsigned char *server_internal_get_minecraft(unsigned char *player);
#endif

View File

@ -1,6 +1,4 @@
#ifndef SERVER_PROPERTIES_H
#define SERVER_PROPERTIES_H
#pragma once
#include <string>
#include <istream>
@ -18,5 +16,3 @@ public:
int get_int(std::string const& name, std::string const& def);
bool get_bool(std::string const& name, std::string const& def);
};
#endif

View File

@ -1,5 +1,7 @@
#include <EGL/egl.h>
#include "../compat/compat.h"
// EGL/SDL Is Replaced With GLFW
EGLDisplay eglGetDisplay(__attribute__((unused)) NativeDisplayType native_display) {
@ -32,6 +34,9 @@ EGLBoolean eglDestroyContext(__attribute__((unused)) EGLDisplay display, __attri
EGLBoolean eglTerminate(__attribute__((unused)) EGLDisplay display) {
return EGL_TRUE;
}
// Send Buffer Swap Request To GLFW
EGLBoolean eglSwapBuffers(__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface surface) {
compat_eglSwapBuffers();
return EGL_TRUE;
}

View File

@ -5,7 +5,7 @@
#include <sys/syscall.h>
#include <time.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../init/init.h"

View File

@ -1,6 +1,6 @@
#include <GLES/gl.h>
#include <libcore/libcore.h>
#include <libreborn/libreborn.h>
#include "../feature/feature.h"
#include "../init/init.h"

View File

@ -30,7 +30,7 @@ prepare_control() {
}
# Package Client DEBs
docker save thebrokenrail/minecraft-pi:client | gzip > debian/tmp/client-image.tar.gz
docker save thebrokenrail/minecraft-pi-reborn:client | gzip > debian/tmp/client-image.tar.gz
package_client() {
# Clean
rm -rf "debian/tmp/$1"
@ -46,7 +46,7 @@ package_client virgl
package_client native
# Package Server DEB
docker save thebrokenrail/minecraft-pi:server | gzip > debian/tmp/server-image.tar.gz
docker save thebrokenrail/minecraft-pi-reborn:server | gzip > debian/tmp/server-image.tar.gz
package_server() {
# Clean
rm -rf debian/tmp/server
@ -69,7 +69,7 @@ mkdir -p out/lib
cp -r mods/include out/lib/include
# Copy Shared Library
IMG_ID="$(docker create thebrokenrail/minecraft-pi:client)"
IMG_ID="$(docker create thebrokenrail/minecraft-pi-reborn:client)"
docker cp "${IMG_ID}":/app/minecraft-pi/mods/. ./out/lib/. || :
RET="$?"
docker rm -v "${IMG_ID}"