Browse Source

Fixes

pull/5/head
TheBrokenRail 5 months ago
parent
commit
0ccc05ad90
  1. 2
      Dockerfile.server
  2. 4
      MODDING.md
  3. 12
      README.md
  4. 16
      build/build-mods.sh
  5. 15
      core/CMakeLists.txt
  6. 2
      debian/client/native/usr/share/minecraft-pi/client/docker-compose.yml
  7. 2
      debian/client/virgl/usr/share/minecraft-pi/client/docker-compose.yml
  8. 2
      debian/server/usr/share/minecraft-pi/server/docker-compose.yml
  9. 10
      launcher/CMakeLists.txt
  10. 6
      launcher/src/launcher.c
  11. 13
      libreborn/CMakeLists.txt
  12. 6
      libreborn/include/libreborn/libreborn.h
  13. 2
      libreborn/src/libreborn.c
  14. 52
      mods/CMakeLists.txt
  15. 2
      mods/src/camera/camera.cpp
  16. 9
      mods/src/compat/compat.c
  17. 3
      mods/src/compat/compat.h
  18. 2
      mods/src/feature/feature.c
  19. 6
      mods/src/feature/feature.h
  20. 2
      mods/src/game_mode/game_mode.c
  21. 2
      mods/src/game_mode/game_mode.cpp
  22. 6
      mods/src/game_mode/game_mode.h
  23. 6
      mods/src/init/init.h
  24. 2
      mods/src/input/input.c
  25. 2
      mods/src/input/input.cpp
  26. 6
      mods/src/input/input.h
  27. 8
      mods/src/minecraft.h
  28. 2
      mods/src/misc/misc.c
  29. 2
      mods/src/misc/misc.cpp
  30. 6
      mods/src/misc/misc.h
  31. 2
      mods/src/options/options.c
  32. 2
      mods/src/override/override.c
  33. 0
      mods/src/readdir/readdir.c
  34. 2
      mods/src/screenshot/screenshot.c
  35. 6
      mods/src/screenshot/screenshot.h
  36. 3
      mods/src/server/server.cpp
  37. 15
      mods/src/server/server.h
  38. 8
      mods/src/server/server_internal.h
  39. 8
      mods/src/server/server_properties.h
  40. 5
      mods/src/stubs/EGL.c
  41. 0
      mods/src/stubs/GLESv2.c
  42. 0
      mods/src/stubs/bcm_host.c
  43. 2
      mods/src/test/test.c
  44. 2
      mods/src/textures/textures.cpp
  45. 6
      scripts/package.sh

2
Dockerfile.server

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

4
MODDING.md

@ -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)``

12
README.md

@ -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``.

16
build/build-mods.sh

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

15
core/CMakeLists.txt

@ -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)

2
debian/client/native/usr/share/minecraft-pi/client/docker-compose.yml

@ -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

2
debian/client/virgl/usr/share/minecraft-pi/client/docker-compose.yml

@ -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

2
debian/server/usr/share/minecraft-pi/server/docker-compose.yml

@ -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

@ -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 /)

6
core/src/launcher.c → launcher/src/launcher.c

@ -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;
@ -127,7 +125,7 @@ int main(__attribute__((unused)) int argc, char *argv[]) {
asprintf(&home_mods, "%s/.minecraft/mods/", getenv("HOME"));
load(&ld_path, &ld_preload, home_mods);
free(home_mods);
// Add Existing LD_LIBRARY_PATH
asprintf(&ld_path, "%s:%s", ld_path, get_env_safe("LD_LIBRARY_PATH"));

13
libreborn/CMakeLists.txt

@ -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)

6
mods/include/libcore/libcore.h → libreborn/include/libreborn/libreborn.h

@ -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

2
mods/src/core/core.c → libreborn/src/libreborn.c

@ -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);

52
mods/CMakeLists.txt

@ -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)

2
mods/src/camera/camera.cpp

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

9
mods/src/compat/compat.c

@ -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

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

2
mods/src/feature/feature.c

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

6
mods/src/feature/feature.h

@ -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

2
mods/src/game_mode/game_mode.c

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

2
mods/src/game_mode/game_mode.cpp

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

6
mods/src/game_mode/game_mode.h

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

6
mods/src/init/init.h

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

2
mods/src/input/input.c

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

2
mods/src/input/input.cpp

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

6
mods/src/input/input.h

@ -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

8
mods/src/minecraft.h

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

2
mods/src/misc/misc.c

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

2
mods/src/misc/misc.cpp

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

6
mods/src/misc/misc.h

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

2
mods/src/options/options.c

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

2
mods/src/override/override.c

@ -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;

0
mods/src/compat/readdir.c → mods/src/readdir/readdir.c

2
mods/src/screenshot/screenshot.c

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

6
mods/src/screenshot/screenshot.h

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

3
mods/src/server/server.cpp

@ -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"

15
mods/src/server/server.h

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

8
mods/src/server/server_internal.h

@ -1,6 +1,4 @@
#ifndef SERVER_INTERNAL_H
#define SERVER_INTERNAL_H
#pragma once
#include <string>
#include <vector>
@ -9,6 +7,4 @@ std::string server_internal_get_world_name();
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
unsigned char *server_internal_get_minecraft(unsigned char *player);

8
mods/src/server/server_properties.h

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

5
core/src/stubs/EGL.c → mods/src/stubs/EGL.c

@ -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;
}

0
core/src/stubs/GLESv2.c → mods/src/stubs/GLESv2.c

0
core/src/stubs/bcm_host.c → mods/src/stubs/bcm_host.c

2
mods/src/test/test.c

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

2
mods/src/textures/textures.cpp

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

6
scripts/package.sh

@ -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}"

Loading…
Cancel
Save