Browse Source

2.0

pull/23/head
TheBrokenRail 4 months ago
parent
commit
d0c2b98ca6
  1. 9
      .dockerignore
  2. 5
      .gitignore
  3. 105
      CMakeLists.txt
  4. 3
      Dockerfile.build
  5. 52
      Dockerfile.client
  6. 3
      Dockerfile.server
  7. 39
      Jenkinsfile
  8. 14
      README.md
  9. 1
      VERSION
  10. 18
      build/build-libpng12.sh
  11. 25
      build/build-mods.sh
  12. 8
      build/download-minecraft-pi.sh
  13. 13
      cmake/armhf-toolchain.cmake
  14. 20
      cmake/util.cmake
  15. 7
      debian/client-arm
  16. 7
      debian/client-x86_64
  17. 6
      debian/client/common/DEBIAN/postinst
  18. 5
      debian/client/common/DEBIAN/prerm
  19. 56
      debian/client/common/usr/bin/minecraft-pi
  20. 27
      debian/client/common/usr/lib/minecraft-pi/pre-launch.sh
  21. 17
      debian/client/common/usr/share/minecraft-pi/client/features
  22. 9
      debian/client/native/DEBIAN/control
  23. 6
      debian/client/native/usr/lib/minecraft-pi/run.sh
  24. 20
      debian/client/native/usr/share/minecraft-pi/client/docker-compose.yml
  25. 9
      debian/client/virgl/DEBIAN/control
  26. 19
      debian/client/virgl/usr/lib/minecraft-pi/run.sh
  27. 19
      debian/client/virgl/usr/share/minecraft-pi/client/docker-compose.yml
  28. 4
      debian/server-arm
  29. 7
      debian/server-x86_64
  30. 6
      debian/server/DEBIAN/postinst
  31. 12
      debian/server/usr/bin/minecraft-pi-server
  32. 13
      debian/server/usr/share/minecraft-pi/server/docker-compose.yml
  33. 8
      dependencies/CMakeLists.txt
  34. 28
      dependencies/libpng/CMakeLists.txt
  35. 208
      dependencies/libpng/libpng.vers
  36. 17
      dependencies/minecraft-pi/CMakeLists.txt
  37. 23
      dependencies/zlib/CMakeLists.txt
  38. 103
      docs/ARCHITECTURE.md
  39. 63
      docs/BUILDING.md
  40. 29
      docs/DEDICATED_SERVER.md
  41. 74
      docs/INSTALL.md
  42. 116
      docs/MODDING.md
  43. 2
      docs/OVERRIDING_ASSETS.md
  44. 8
      docs/README.md
  45. 10
      docs/TERMINOLOGY.md
  46. 26
      docs/TROUBLESHOOTING.md
  47. 48
      launcher/CMakeLists.txt
  48. 16
      launcher/client-data/opt/minecraft-pi-reborn-client/available-feature-flags
  49. 6
      launcher/client-data/usr/share/applications/minecraft-pi-reborn-client.desktop
  50. 0
      launcher/client-data/usr/share/pixmaps/minecraft-pi-reborn-client.png
  51. 222
      launcher/src/bootstrap.c
  52. 4
      launcher/src/bootstrap.h
  53. 225
      launcher/src/client/launcher.cpp
  54. 156
      launcher/src/launcher.c
  55. 45
      launcher/src/ldconfig.cpp
  56. 11
      launcher/src/ldconfig.h
  57. 35
      launcher/src/run.sh
  58. 6
      launcher/src/server/launcher.c
  59. 18
      libreborn/CMakeLists.txt
  60. 67
      libreborn/include/libreborn/elf.h
  61. 71
      libreborn/include/libreborn/exec.h
  62. 42
      libreborn/include/libreborn/libreborn.h
  63. 9
      libreborn/include/libreborn/log.h
  64. 4
      libreborn/include/libreborn/minecraft.h
  65. 52
      libreborn/include/libreborn/string.h
  66. 51
      libreborn/include/libreborn/util.h
  67. 95
      libreborn/src/libreborn.c
  68. 40
      media-layer/CMakeLists.txt
  69. 29
      media-layer/core/CMakeLists.txt
  70. 12
      media-layer/core/src/base.cpp
  71. 326
      media-layer/core/src/media.c
  72. 32
      media-layer/core/src/screenshot.c
  73. 7
      media-layer/extras/CMakeLists.txt
  74. 41
      media-layer/extras/src/SDL.c
  75. 76
      media-layer/extras/src/X11.cpp
  76. 40
      media-layer/include/EGL/egl.h
  77. 86
      media-layer/include/GLES/gl.h
  78. 39
      media-layer/include/SDL/SDL.h
  79. 160
      media-layer/include/SDL/SDL_events.h
  80. 262
      media-layer/include/SDL/SDL_keysym.h
  81. 34
      media-layer/include/SDL/SDL_syswm.h
  82. 17
      media-layer/include/SDL/SDL_version.h
  83. 40
      media-layer/include/X11/Xlib.h
  84. 19
      media-layer/include/libreborn/media-layer/core.h
  85. 14
      media-layer/include/libreborn/media-layer/internal.h
  86. 35
      media-layer/proxy/CMakeLists.txt
  87. 1077
      media-layer/proxy/src/GLESv1_CM.c
  88. 86
      media-layer/proxy/src/client/client.cpp
  89. 13
      media-layer/proxy/src/client/client.h
  90. 142
      media-layer/proxy/src/common/common.c
  91. 60
      media-layer/proxy/src/common/common.h
  92. 351
      media-layer/proxy/src/media-layer-core.c
  93. 164
      media-layer/proxy/src/server/server.cpp
  94. 17
      media-layer/proxy/src/server/server.h
  95. 32
      media-layer/stubs/CMakeLists.txt
  96. 40
      media-layer/stubs/src/EGL.c
  97. 108
      media-layer/stubs/src/GLESv1_CM.c
  98. 0
      media-layer/stubs/src/bcm_host.c
  99. 0
      media-layer/stubs/src/nop.c
  100. 44
      mods/CMakeLists.txt

9
.dockerignore

@ -1,9 +0,0 @@
/.git
/.gitignore
/Dockerfile*
/Jenkinsfile
/out
/LICENSE
*.md
/debian
/scripts

5
.gitignore

@ -1,3 +1,6 @@
/out
/debian/tmp
/.vscode
/.vscode
/build
/CMakeLists.txt.user
*.autosave

105
CMakeLists.txt

@ -0,0 +1,105 @@
cmake_minimum_required(VERSION 3.13.0)
# Specify Options
option(MCPI_USE_MEDIA_LAYER_PROXY "Whether To Enable The Media Layer Proxy" FALSE)
option(MCPI_SERVER_MODE "Server Mode" FALSE)
set(MCPI_BUILD_MODE "both" CACHE STRING "\"arm\" = Build Only Code That Must Be ARN; \"native\" = Build Architecture-Independent Code; \"both\" = Build All Code As ARM")
set_property(CACHE MCPI_BUILD_MODE PROPERTY STRINGS "both" "arm" "native")
# Configure Build Mode
if(MCPI_BUILD_MODE STREQUAL "arm")
set(USE_ARM32_TOOLCHAIN TRUE)
set(BUILD_ARM_COMPONENTS TRUE)
set(BUILD_NATIVE_COMPONENTS FALSE)
elseif(MCPI_BUILD_MODE STREQUAL "native")
set(USE_ARM32_TOOLCHAIN FALSE)
set(BUILD_ARM_COMPONENTS FALSE)
set(BUILD_NATIVE_COMPONENTS TRUE)
elseif(MCPI_BUILD_MODE STREQUAL "both")
set(USE_ARM32_TOOLCHAIN TRUE)
set(BUILD_ARM_COMPONENTS TRUE)
set(BUILD_NATIVE_COMPONENTS TRUE)
else()
message(FATAL_ERROR "Invalid Mode")
endif()
# Use Clang By Default
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
# Setup ARM Cross Compilation
if(USE_ARM32_TOOLCHAIN)
include(cmake/armhf-toolchain.cmake)
endif()
# Use LLD When Using Clang
if(CMAKE_C_COMPILER STREQUAL "clang")
add_link_options("-fuse-ld=lld")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") # Fix try_compile()
endif()
# Utility Functions
include(cmake/util.cmake)
# Specify Variant Name
set(MCPI_VARIANT_NAME "minecraft-pi-reborn")
if(MCPI_SERVER_MODE)
set(MCPI_VARIANT_NAME "${MCPI_VARIANT_NAME}-server")
else()
set(MCPI_VARIANT_NAME "${MCPI_VARIANT_NAME}-client")
endif()
# Specify Installation Paths
set(MCPI_INSTALL_DIR "opt/${MCPI_VARIANT_NAME}")
set(MCPI_LIB_DIR "${MCPI_INSTALL_DIR}/lib")
set(MCPI_FALLBACK_LIB_DIR "${MCPI_INSTALL_DIR}/fallback-lib")
# Optimizations
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-O3)
else()
add_compile_options(-g)
add_definitions(-DDEBUG)
endif()
# Start Project
project(minecraft-pi-reborn)
# Specify Default Installation Prefix
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/" CACHE PATH "" FORCE)
endif()
# Buld LibPNG + ZLib + Download Minecraft: Pi Edition
if(BUILD_ARM_COMPONENTS)
add_subdirectory(dependencies)
endif()
# Warnings
add_compile_options(-Wall -Wextra -Werror)
add_link_options(-Wl,--no-undefined)
add_definitions(-D_GNU_SOURCE)
# Specify Constants
if(MCPI_SERVER_MODE)
add_definitions(-DMCPI_SERVER_MODE)
endif()
# Build libreborn
add_subdirectory(libreborn)
# Build Media Layer
add_subdirectory(media-layer)
# Build Launcher
if(BUILD_NATIVE_COMPONENTS)
add_subdirectory(launcher)
endif()
# Build Mods
if(BUILD_ARM_COMPONENTS)
add_subdirectory(mods)
endif()

3
Dockerfile.build

@ -1,3 +0,0 @@
FROM ubuntu:focal
RUN apt-get update && apt-get install -y docker.io rsync

52
Dockerfile.client

@ -1,52 +0,0 @@
# Runtime Base Environment
FROM arm32v7/debian:bullseye-slim AS runtime-base
ENV DEBIAN_FRONTEND noninteractive
RUN \
# Install Runtime Dependencies
apt-get update && \
apt-get install -y --no-install-recommends tini libgles1 libx11-6 zlib1g libfreeimage3 libglfw3 xinput libxfixes3 gosu tk && \
rm -rf /var/lib/apt/lists/*
# Compile Environment
FROM runtime-base AS build
ENV DEBIAN_FRONTEND noninteractive
RUN \
# Install Dependencies
apt-get update && \
apt-get install -y --no-install-recommends libgles-dev libx11-dev libxrandr-dev libsdl1.2-dev gcc g++ libc-dev make cmake zlib1g-dev git wget ca-certificates libfreeimage-dev libglfw3-dev xinput libxfixes-dev && \
rm -rf /var/lib/apt/lists/*
# Add Build Scripts
ADD ./build /app/build
WORKDIR /app
RUN \
# Download MCPI
./build/download-minecraft-pi.sh && \
# Build LibPNG12
./build/build-libpng12.sh
# Add Code
ADD . /app
# Build Mods
RUN ./build/build-mods.sh
# Runtime Environment
FROM runtime-base AS runtime
# Setup /home Permissions
RUN \
mkdir -p /home && \
chmod -R a+rw /home
# Copy Build
COPY --from=build /app/minecraft-pi /app/minecraft-pi
WORKDIR /app/minecraft-pi
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["./run.sh"]

3
Dockerfile.server

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

39
Jenkinsfile

@ -1,36 +1,33 @@
pipeline {
agent {
dockerfile {
filename 'Dockerfile.build'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
agent none
stages {
stage('Install QEMU') {
steps {
sh 'docker run --rm --privileged multiarch/qemu-user-static --reset -p yes'
stage('Build (Debian Bullseye)') {
agent {
docker {
image 'debian:bullseye'
}
}
}
stage('Build') {
steps {
sh 'DOCKER_BUILD_OPTIONS="--no-cache" ./scripts/build.sh'
sh './scripts/ci/run.sh'
}
}
stage('Publish') {
steps {
withCredentials([usernamePassword(credentialsId: 'docker_hub_login', usernameVariable: 'DOCKER_HUB_USERNAME', passwordVariable: 'DOCKER_HUB_PASSWORD')]) {
sh 'docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}"'
post {
success {
archiveArtifacts artifacts: 'out/*.deb', fingerprint: true
}
sh 'docker push thebrokenrail/minecraft-pi-reborn'
}
}
stage('Package') {
stage('Build (Debian Buster)') {
agent {
docker {
image 'debian:buster'
}
}
steps {
sh './scripts/package.sh'
sh './scripts/ci/run.sh'
}
post {
success {
archiveArtifacts artifacts: 'out/**', fingerprint: true
archiveArtifacts artifacts: 'out/*.deb', fingerprint: true
}
}
}

14
README.md

@ -5,17 +5,5 @@
# Minecraft: Pi Edition: Reborn
Minecraft: Pi Edition Modding Project
## Installation
### Option A: Pi-Apps (Raspberry Pi Only)
[![Pi-Apps](https://github.com/Botspot/pi-apps/blob/master/icons/badge.png?raw=true)](https://github.com/Botspot/pi-apps)
### Option B: Manual Installation
[View Manual Installation](docs/INSTALL.md)
## Documentation
- [View Overriding Assets](docs/OVERRIDING_ASSETS.md)
- [View Troubleshooting](docs/TROUBLESHOOTING.md)
- [View Dedicated Server](docs/DEDICATED_SERVER.md)
- [View Modding](docs/MODDING.md)
- [View Credits](docs/CREDITS.md)
[View Documentation](docs/README.md)

1
VERSION

@ -0,0 +1 @@
2.0.0

18
build/build-libpng12.sh

@ -1,18 +0,0 @@
#!/bin/sh
set -e
git clone --depth 1 https://git.code.sf.net/p/libpng/code libpng -b libpng12
cd libpng
./configure
make -j$(nproc)
mkdir -p ../minecraft-pi/lib
cp -L .libs/libpng12.so.0 ../minecraft-pi/lib
cd ../
rm -rf libpng

25
build/build-mods.sh

@ -1,25 +0,0 @@
#!/bin/sh
set -e
cd launcher
mkdir build
cd build
cmake ..
make -j$(nproc)
make install DESTDIR=../../minecraft-pi
cd ../../
cd mods
mkdir build
cd build
cmake ..
make -j$(nproc)
make install DESTDIR=../../minecraft-pi
cd ../../

8
build/download-minecraft-pi.sh

@ -1,8 +0,0 @@
#!/bin/sh
set -e
URL="https://www.minecraft.net/content/dam/minecraft/edition-pi/minecraft-pi-0.1.1.tar.gz"
mkdir minecraft-pi
wget -O - "${URL}" | tar -xz --strip-components 1 -C minecraft-pi

13
cmake/armhf-toolchain.cmake

@ -0,0 +1,13 @@
# Compile For ARM
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8b" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8l")
# Force 32-Bit Compile
add_compile_options("-m32")
elseif(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
# Use ARM Cross-Compiler
set(TARGET "arm-linux-gnueabihf")
set(CMAKE_C_COMPILER "${TARGET}-gcc")
set(CMAKE_CXX_COMPILER "${TARGET}-g++")
set(CMAKE_FIND_ROOT_PATH "/usr/${TARGET}" "/usr/lib/${TARGET}")
endif()
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm")

20
cmake/util.cmake

@ -0,0 +1,20 @@
# Symlink Function
function(install_symlink target link)
install(CODE "\
# Prepare\n \
set(file \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${link}\")\n \
\
# Create Directory\n \
get_filename_component(dir \"\${file}\" DIRECTORY)\n \
file(MAKE_DIRECTORY \${dir})\n \
\
# Create Symlink\n \
if(NOT EXISTS \"\${file}\")\n \
execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink ${target} \"\${file}\")\n \
message(\"-- Installing: \${file}\")\n \
else()\n \
message(\"-- Up-to-date: \${file}\")\n \
endif() \
")
endfunction()

7
debian/client-arm

@ -0,0 +1,7 @@
Package: minecraft-pi-reborn-client
Version: ${VERSION}
Maintainer: TheBrokenRail <connor24nolan@live.com>
Description: Fun with Blocks
Homepage: https://www.minecraft.net/en-us/edition/pi
Architecture: armhf
Depends: zenity, libgles1, libglfw3 | libglfw3-wayland, libfreeimage3

7
debian/client-x86_64

@ -0,0 +1,7 @@
Package: minecraft-pi-reborn-client
Version: ${VERSION}
Maintainer: TheBrokenRail <connor24nolan@live.com>
Description: Fun with Blocks
Homepage: https://www.minecraft.net/en-us/edition/pi
Architecture: amd64
Depends: zenity, libgles1, libglfw3 | libglfw3-wayland, libfreeimage3, libc6-armhf-cross, libstdc++6-armhf-cross, qemu-user-static

6
debian/client/common/DEBIAN/postinst

@ -1,6 +0,0 @@
#!/bin/sh
set -e
docker load < /usr/share/minecraft-pi/client/image.tar.gz
rm /usr/share/minecraft-pi/client/image.tar.gz

5
debian/client/common/DEBIAN/prerm

@ -1,5 +0,0 @@
#!/bin/sh
set -e
docker image rm -f thebrokenrail/minecraft-pi-reborn:client

56
debian/client/common/usr/bin/minecraft-pi

@ -1,56 +0,0 @@
#!/bin/sh
set -e
# All Feature Flags
export AVAILABLE_FEATURES="$(tr '\n' ' ' < /usr/share/minecraft-pi/client/features)"
# Print Feature Flags Option
if [ "$1" = "--print-features" ]; then
echo "${AVAILABLE_FEATURES}"
exit 0
fi
# Esnure User Is In docker Group
if ! id -nGz | grep -qzxF 'docker'; then
pkexec /usr/sbin/usermod -aG docker "$(id -un)"
fi
# Export Important Variables
export ZENITY_CLASS='Minecraft - Pi edition'
export DOCKER_COMPOSE_YML="/usr/share/minecraft-pi/client/docker-compose.yml"
# Ensure Features Are Selected
if [ -z "${MCPI_FEATURES+x}" ]; then
MCPI_FEATURES="$(eval "zenity --class \"${ZENITY_CLASS}\" --list --checklist --width 400 --height 400 --column 'Enabled' --column 'Feature' ${AVAILABLE_FEATURES}")"
fi
if [ -z "${MCPI_RENDER_DISTANCE+x}" ]; then
MCPI_RENDER_DISTANCE="$(zenity --class "${ZENITY_CLASS}" --list --radiolist --width 400 --height 400 --text 'Minecraft Render Distance:' --column 'Selected' --column 'Name' FALSE 'Far' FALSE 'Normal' TRUE 'Short' FALSE 'Tiny')"
fi
if [ -z "${MCPI_USERNAME+x}" ]; then
MCPI_USERNAME="$(zenity --class "${ZENITY_CLASS}" --entry --text 'Minecraft Username:' --entry-text 'StevePi')"
fi
export MCPI_FEATURES
export MCPI_RENDER_DISTANCE
export MCPI_USERNAME
# Prepare Environment
export USER_HOME="${HOME}"
export USER_UID="$(id -u)"
export USER_GID="$(id -g)"
get_gid() {
echo "$(getent group "$1" | cut -d : -f 3)"
}
export USER_OTHER_GIDS="$(get_gid video) $(get_gid render)"
# Run
set +e
sg docker /usr/lib/minecraft-pi/pre-launch.sh
RET=$?
set -e
# Handle Crash
if [ ${RET} -ne 0 ]; then
zenity --class "${ZENITY_CLASS}" --error --no-wrap --text 'Minecraft: Pi Edition has crashed!\n\nExit Code: '${RET}'\n\n<a href="file:///tmp/minecraft-pi">Open Log Folder</a>\n<a href="https://gitea.thebrokenrail.com/TheBrokenRail/minecraft-pi-reborn/src/branch/master/docs/TROUBLESHOOTING.md">Open Troubleshooting Guide</a>'
exit ${RET}
fi

27
debian/client/common/usr/lib/minecraft-pi/pre-launch.sh

@ -1,27 +0,0 @@
#!/bin/sh
set -e
# Prepare Data Folder
mkdir -p "${USER_HOME}/.minecraft-pi"
# Create Log Folder
rm -rf /tmp/minecraft-pi
mkdir -p /tmp/minecraft-pi
# Start Logging
touch /tmp/minecraft-pi/main.log
tail -f /tmp/minecraft-pi/main.log &
TAIL_PID=$!
# Run
set +e
/usr/lib/minecraft-pi/run.sh > /tmp/minecraft-pi/main.log 2>&1
RET=$?
set -e
# Kill Logging
kill ${TAIL_PID} > /dev/null 2>&1 || :
# Exit
exit ${RET}

17
debian/client/common/usr/share/minecraft-pi/client/features

@ -1,17 +0,0 @@
TRUE 'Touch GUI'
TRUE 'Fix Bow & Arrow'
TRUE 'Fix Attacking'
TRUE 'Mob Spawning'
TRUE 'Fancy Graphics'
TRUE 'Disable Autojump By Default'
TRUE 'Display Nametags 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 'Disable gui_blocks Atlas'
TRUE 'Smooth Lighting'
FALSE '3D Anaglyph'
FALSE 'Show FPS Monitor'

9
debian/client/native/DEBIAN/control

@ -1,9 +0,0 @@
Package: minecraft-pi-reborn-native
Version: ${VERSION}
Maintainer: TheBrokenRail <connor24nolan@live.com>
Description: Fun with Blocks
Homepage: https://www.minecraft.net/en-us/edition/pi
Architecture: all
Depends: ${DEPENDENCIES}
Recommends: ${RECOMMENDED_DEPENDENCIES}
Conflicts: minecraft-pi, minecraft-pi-reborn-virgl

6
debian/client/native/usr/lib/minecraft-pi/run.sh

@ -1,6 +0,0 @@
#!/bin/sh
set -e
# Launch Minecraft
exec docker-compose -f "${DOCKER_COMPOSE_YML}" run --rm minecraft-pi

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

@ -1,20 +0,0 @@
version: '3'
services:
minecraft-pi:
image: 'thebrokenrail/minecraft-pi-reborn:client'
network_mode: 'host'
volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static
- '/tmp/.X11-unix:/tmp/.X11-unix'
- '${USER_HOME}/.minecraft-pi:/home/.minecraft-pi'
devices:
- '/dev/dri:/dev/dri'
environment:
- 'DISPLAY=unix${DISPLAY}'
- 'MCPI_FEATURES=${MCPI_FEATURES}'
- 'MCPI_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}'
- 'MCPI_USERNAME=${MCPI_USERNAME}'
- 'MCPI_MODE=native'
- 'USER_UID=${USER_UID}'
- 'USER_GID=${USER_GID}'
- 'USER_OTHER_GIDS=${USER_OTHER_GIDS}'

9
debian/client/virgl/DEBIAN/control

@ -1,9 +0,0 @@
Package: minecraft-pi-reborn-virgl
Version: ${VERSION}
Maintainer: TheBrokenRail <connor24nolan@live.com>
Description: Fun with Blocks
Homepage: https://www.minecraft.net/en-us/edition/pi
Architecture: all
Depends: ${DEPENDENCIES}, virgl-server
Recommends: ${RECOMMENDED_DEPENDENCIES}
Conflicts: minecraft-pi, minecraft-pi-reborn-native

19
debian/client/virgl/usr/lib/minecraft-pi/run.sh

@ -1,19 +0,0 @@
#!/bin/sh
set -e
# Start VirGL
virgl_test_server > /tmp/minecraft-pi/virgl.log 2>&1 &
VIRGL_PID=$!
# Launch Minecraft
set +e
docker-compose -f "${DOCKER_COMPOSE_YML}" run --rm minecraft-pi
RET=$?
set -e
# Kill VirGL
kill ${VIRGL_PID} > /dev/null 2>&1 || :
# Exit
exit ${RET}

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

@ -1,19 +0,0 @@
version: '3'
services:
minecraft-pi:
image: 'thebrokenrail/minecraft-pi-reborn:client'
network_mode: 'host'
volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static
- '/tmp/.X11-unix:/tmp/.X11-unix'
- '/tmp/.virgl_test:/tmp/.virgl_test'
- '${USER_HOME}/.minecraft-pi:/home/.minecraft-pi'
environment:
- 'DISPLAY=unix${DISPLAY}'
- 'MCPI_FEATURES=${MCPI_FEATURES}'
- 'MCPI_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}'
- 'MCPI_USERNAME=${MCPI_USERNAME}'
- 'MCPI_MODE=virgl'
- 'USER_UID=${USER_UID}'
- 'USER_GID=${USER_GID}'
- 'USER_OTHER_GIDS=${USER_OTHER_GIDS}'

4
debian/server/DEBIAN/control → debian/server-arm

@ -3,6 +3,4 @@ Version: ${VERSION}
Maintainer: TheBrokenRail <connor24nolan@live.com>
Description: Fun with Blocks
Homepage: https://www.minecraft.net/en-us/edition/pi
Architecture: all
Depends: ${DEPENDENCIES}
Recommends: ${RECOMMENDED_DEPENDENCIES}
Architecture: armhf

7
debian/server-x86_64

@ -0,0 +1,7 @@
Package: minecraft-pi-reborn-server
Version: ${VERSION}
Maintainer: TheBrokenRail <connor24nolan@live.com>
Description: Fun with Blocks
Homepage: https://www.minecraft.net/en-us/edition/pi
Architecture: amd64
Depends: libc6-armhf-cross, libstdc++6-armhf-cross, qemu-user-static

6
debian/server/DEBIAN/postinst

@ -1,6 +0,0 @@
#!/bin/sh
set -e
docker load < /usr/share/minecraft-pi/server/image.tar.gz
rm /usr/share/minecraft-pi/server/image.tar.gz

12
debian/server/usr/bin/minecraft-pi-server

@ -1,12 +0,0 @@
#!/bin/sh
set -e
# Prepare Environment
export MCPI_ROOT="${PWD}"
export USER_UID="$(id -u)"
export USER_GID="$(id -g)"
# Launch Minecraft
DOCKER_COMPOSE_YML='/usr/share/minecraft-pi/server/docker-compose.yml'
docker-compose -f "${DOCKER_COMPOSE_YML}" run --rm minecraft-pi-server

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

@ -1,13 +0,0 @@
version: '3'
services:
minecraft-pi-server:
image: 'thebrokenrail/minecraft-pi-reborn:server'
network_mode: 'host'
stdin_open: true
tty: true
volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static
- '${MCPI_ROOT}:/home/.minecraft-pi'
environment:
- 'USER_UID=${USER_UID}'
- 'USER_GID=${USER_GID}'

8
dependencies/CMakeLists.txt

@ -0,0 +1,8 @@
project(dependencies)
# ZLib
add_subdirectory(zlib)
# LibPNG
add_subdirectory(libpng)
# Minecraft: Pi Edition
add_subdirectory(minecraft-pi)

28
dependencies/libpng/CMakeLists.txt

@ -0,0 +1,28 @@
project(libpng)
include(FetchContent)
# Silence Warnings
add_compile_options(-w)
## LibPNG
# Download
set(SKIP_INSTALL_ALL TRUE) # Skip Default LibPNG Installation
FetchContent_Declare(
libpng
GIT_REPOSITORY "https://git.code.sf.net/p/libpng/code"
GIT_TAG "v1.2.59"
)
FetchContent_Populate(libpng)
set(ZLIB_LIBRARY zlib)
set(ZLIB_INCLUDE_DIR "${zlib_SOURCE_DIR}" "${zlib_BINARY_DIR}")
set(CMAKE_POLICY_DEFAULT_CMP0054 OLD) # Silence Warning
add_subdirectory("${libpng_SOURCE_DIR}" "${libpng_BINARY_DIR}")
set(CMAKE_POLICY_DEFAULT_CMP0054 NEW) # Re-Enable New Behavior
set_target_properties(png12 PROPERTIES LINK_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers'") # Use Symbol Versioning
set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode
# Install
install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}")

208
dependencies/libpng/libpng.vers

@ -0,0 +1,208 @@
PNG12_0 {global:
png_libpng_ver;
png_pass_start;
png_pass_inc;
png_pass_ystart;
png_pass_yinc;
png_pass_mask;
png_pass_dsp_mask;
png_access_version_number;
png_set_sig_bytes;
png_sig_cmp;
png_check_sig;
png_create_read_struct;
png_create_write_struct;
png_get_compression_buffer_size;
png_set_compression_buffer_size;
png_reset_zstream;
png_create_read_struct_2;
png_create_write_struct_2;
png_write_chunk;
png_write_chunk_start;
png_write_chunk_data;
png_write_chunk_end;
png_create_info_struct;
png_info_init;
png_info_init_3;
png_write_info_before_PLTE;
png_write_info;
png_read_info;
png_convert_to_rfc1123;
png_convert_from_struct_tm;
png_convert_from_time_t;
png_set_expand;
png_set_expand_gray_1_2_4_to_8;
png_set_palette_to_rgb;
png_set_tRNS_to_alpha;
png_set_gray_1_2_4_to_8;
png_set_bgr;
png_set_gray_to_rgb;
png_set_rgb_to_gray;
png_set_rgb_to_gray_fixed;
png_get_rgb_to_gray_status;
png_build_grayscale_palette;
png_set_strip_alpha;
png_set_swap_alpha;
png_set_invert_alpha;
png_set_filler;
png_set_add_alpha;
png_set_swap;
png_set_packing;
png_set_packswap;
png_set_shift;
png_set_interlace_handling;
png_set_invert_mono;
png_set_background;
png_set_strip_16;
png_set_dither;
png_set_gamma;
png_permit_empty_plte;
png_set_flush;
png_write_flush;
png_start_read_image;
png_read_update_info;
png_read_rows;
png_read_row;
png_read_image;
png_write_row;
png_write_rows;
png_write_image;
png_write_end;
png_read_end;
png_destroy_info_struct;
png_destroy_read_struct;
png_destroy_write_struct;
png_set_crc_action;
png_set_filter;
png_set_filter_heuristics;
png_set_compression_level;
png_set_compression_mem_level;
png_set_compression_strategy;
png_set_compression_window_bits;
png_set_compression_method;
png_init_io;
png_set_error_fn;
png_get_error_ptr;
png_set_write_fn;
png_set_read_fn;
png_get_io_ptr;
png_set_read_status_fn;
png_set_write_status_fn;
png_set_mem_fn;
png_get_mem_ptr;
png_set_read_user_transform_fn;
png_set_write_user_transform_fn;
png_set_user_transform_info;
png_get_user_transform_ptr;
png_set_read_user_chunk_fn;
png_get_user_chunk_ptr;
png_set_progressive_read_fn;
png_get_progressive_ptr;
png_process_data;
png_progressive_combine_row;
png_malloc;
png_malloc_warn;
png_free;
png_free_data;
png_data_freer;
png_malloc_default;
png_free_default;
png_memcpy_check;
png_memset_check;
png_error;
png_chunk_error;
png_warning;
png_chunk_warning;
png_get_valid;
png_get_rowbytes;
png_get_rows;
png_set_rows;
png_get_channels;
png_get_image_width;
png_get_image_height;
png_get_bit_depth;
png_get_color_type;
png_get_filter_type;
png_get_interlace_type;
png_get_compression_type;
png_get_pixels_per_meter;
png_get_x_pixels_per_meter;
png_get_y_pixels_per_meter;
png_get_pixel_aspect_ratio;
png_get_x_offset_pixels;
png_get_y_offset_pixels;
png_get_x_offset_microns;
png_get_y_offset_microns;
png_get_signature;
png_get_bKGD;
png_set_bKGD;
png_get_cHRM;
png_get_cHRM_fixed;
png_set_cHRM;
png_set_cHRM_fixed;
png_get_gAMA;
png_get_gAMA_fixed;
png_set_gAMA;
png_set_gAMA_fixed;
png_get_hIST;
png_set_hIST;
png_get_IHDR;
png_set_IHDR;
png_get_oFFs;
png_set_oFFs;
png_get_pCAL;
png_set_pCAL;
png_get_pHYs;
png_set_pHYs;
png_get_PLTE;
png_set_PLTE;
png_get_sBIT;
png_set_sBIT;
png_get_sRGB;
png_set_sRGB;
png_set_sRGB_gAMA_and_cHRM;
png_get_iCCP;
png_set_iCCP;
png_get_sPLT;
png_set_sPLT;
png_get_text;
png_set_text;
png_get_tIME;
png_set_tIME;
png_get_tRNS;
png_set_tRNS;
png_get_sCAL;
png_set_sCAL;
png_set_keep_unknown_chunks;
png_handle_as_unknown;
png_set_unknown_chunks;
png_set_unknown_chunk_location;
png_get_unknown_chunks;
png_set_invalid;
png_read_png;
png_write_png;
png_get_copyright;
png_get_header_ver;
png_get_header_version;
png_get_libpng_ver;
png_permit_mng_features;
png_get_mmx_flagmask;
png_get_asm_flagmask;
png_get_asm_flags;
png_get_mmx_bitdepth_threshold;
png_get_mmx_rowbytes_threshold;
png_set_asm_flags;
png_set_mmx_thresholds;
png_mmx_support;
png_set_strip_error_numbers;
png_set_user_limits;
png_get_user_width_max;
png_get_user_height_max;
png_get_uint_32;
png_get_uint_16;
png_get_int_32;
png_get_uint_31;
png_save_uint_32;
png_save_int_32;
png_save_uint_16;
local: *; };

17
dependencies/minecraft-pi/CMakeLists.txt

@ -0,0 +1,17 @@
project(minecraft-pi)
include(FetchContent)
## Minecraft: Pi Edition
# Download
FetchContent_Declare(
minecraft-pi
URL "https://www.minecraft.net/content/dam/minecraft/edition-pi/minecraft-pi-0.1.1.tar.gz"
URL_HASH "SHA256=e0d68918874cdd403de1fd399380ae2930913fcefdbf60a3fbfebb62e2cfacab"
)
FetchContent_Populate(minecraft-pi)
# Install
install(DIRECTORY "${minecraft-pi_SOURCE_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}" USE_SOURCE_PERMISSIONS)

23
dependencies/zlib/CMakeLists.txt

@ -0,0 +1,23 @@
project(zlib)
include(FetchContent)
# Silence Warnings
add_compile_options(-w)
## zlib
# Download
set(SKIP_INSTALL_ALL TRUE) # Skip Default ZLib Installation
FetchContent_Declare(
zlib
GIT_REPOSITORY "https://github.com/madler/zlib.git"
GIT_TAG "v1.2.11"
)
FetchContent_Populate(zlib)
include_directories("${zlib_SOURCE_DIR}" "${zlib_BINARY_DIR}") # Fix ZLib Build
add_subdirectory("${zlib_SOURCE_DIR}" "${zlib_BINARY_DIR}")
# Install
install(TARGETS zlib DESTINATION "${MCPI_LIB_DIR}")

103
docs/ARCHITECTURE.md

@ -0,0 +1,103 @@
# Architecture
## Launch Sequence
### Client
1. The launcher is started by the user
1. The launcher starts several Zenity dialogs to configure MCPI-Reborn
2. The launcher replaces itself with MCPI
1. MCPI-Reborn components are loaded using ``LD_PRELOAD`` and ``LD_LIBRARY_PATH``
2. If the Media Layer Proxy is enabled, the Media Layer Proxy Client is started as a sub-process
### Server
1. The launcher is started by the user
2. The launcher replaces itself with MCPI
## Components
### Launcher
This component configures the various environmental variables required for MCPI-Reborn to work. When running in client-mode, this component will also launch several Zenity dialogs for interactive configuration.
The environmental variables configured by this component includes:
* ``LD_PRELOAD``
* ``LD_LIBRAR_PATH``
* ``MCPI_FEATURE_FLAGS``
* ``MCPI_RENDER_DISTANCE``
* ``MCPI_USERNAME``
This is always compiled for the host system's architecture.
### Media Layer
The Media Layer handles MCPI's graphics calls and user input. It replaces MCPI's native usage of SDL 1.2 with GLFW.
#### Core
This sub-component re-implements a subset of SDL 1.2 calls with GLFW. It also provides a few utility functions that are used internally by MCPI-Reborn.
The utility functions include:
* Taking Screenshots
* Fullscreen
* Etc
This is always compiled for the host system's architecture.
This was created because SDL 1.2 has numerous bugs and is in-general unsupported.
#### Proxy
This sub-component must be used if the host system's architecture isn't ARM. It uses UNIX pipes to cross architectural boundaries and allow MCPI to use the Media Layer Core (which is always compiled for the host system's architecture).
It is made of two parts:
* Media Layer Proxy Server
* Links To MCPI
* Creates The UNIX Pipes
* Same External API As The Media Layer Core
* Compiled For ARM
* Media Layer Proxy Client
* Links To The Media Layer Core
* Connects To The Media Layer Proxy Server
* Uses The System's Native GLES Driver (ie. Mesa)
* Compiled For The Host System's Architecture
While proxying all Media Layer Core API calls across UNIX pipes does hurt performance, it is better than emulating the entire graphics stack.
Using this in server-mode is redundant (and disallowed).
#### Extras
This sub-component contains code that must always be linked directly to MCPI.
This is always compiled for ARM.
#### Stubs
This sub-component implements stubs for various redundant libraries used by MCPI to silence linker errors.
This is always compiled for ARM.
##### What To Stub And What To Patch?
Most libraries (like ``bcm_host``) can just be replaced with stubs, because they don't need to do anything and aren't used by anything else. However, some libraries (like EGL) might be used by some of MCPI-Reborn's dependencies (like GLFW) so instead of being replaced by a stub, each call is manually patched out from MCPI. A stub is still generated just in case that library isn't present on the system to silence linker errors, but it is only loaded if no other version is available.
#### Headers
This sub-component includes headers for SDL, GLES, and EGL allowing easy (cross-)compilation.
### Mods
This component links directly to MCPI and patches it to modify its behavior.
This is always compiled for ARM.
### ``libreborn``
This component contains various utility functions including:
* Code Patching (ARM Only)
* Logging
* MCPI Symbols
* Etc
The code patching is ARM only because it relies on hard-coded ARM instructions. However, this is irrelevant since code patching is only needed in ARM code (to patch MCPI).
## Dependencies
MCPI-Reborn has several dependencies:
* MCPI (Bundled)
* GLFW (Only In Client Mode)
* ZLib (Required By LibPNG; Bundled)
* LibPNG (Bundled)
* FreeImage (Only In Client Mode)
* QEMU User Mode (Only On Non-ARM Hosts; Runtime Only)
* Zenity (Only In Client Mode; Runtime Only)

63
docs/BUILDING.md

@ -0,0 +1,63 @@
# Building
## Build Options
* ``MCPI_BUILD_MODE``
* ``arm``: Only Build ARM Components
* ``native``: Only Build Native Components
* ``both`` (Default): Build Both ARM And Native Components For ARM
* ``MCPI_SERVER_MODE``
* ``ON``: Enable Server Mode
* ``OFF`` (Default): Disable Server Mode
* ``MCPI_USE_MEDIA_LAYER_PROXY``
* ``ON``: Enable The Media Layer Proxy
* ``OFF`` (Default): Disable The Media Layer Proxy
## Build Dependencies
* Common
* ARM Compiler
* Host Compiler (Clang)
* CMake
* Host Architecture Dependencies
* Client Mode Only
* GLFW
* FreeImage
## Runtime Dependencies
* Non-ARM Host Architectures
* QEMU User-Mode Static
* Host Architecture Dependencies
* CLient Mode Only
* OpenGL ES 1.1
* GLFW
* FreeImage
* Zenity
## Two-Step Build
Use this when the host architecture is not ARM.
```sh
# Create Build Directory
mkdir build && cd build
# Build ARM Components
mkdir arm && cd arm
cmake -DMCPI_BUILD_MODE=arm ../..
make -j$(nproc) && sudo make install
# Build Native Components
mkdir native && cd native
cmake -DMCPI_BUILD_MODE=native ../..
make -j$(nproc) && sudo make install
```
## One-Step Build
Use this when the host architecture is ARM.
```sh
# Create Build Directory
mkdir build && cd build
# Build
cmake ..
make -j$(nproc) && sudo make install
```

29
docs/DEDICATED_SERVER.md

@ -6,27 +6,14 @@ This server is also compatible with MCPE Alpha v0.6.1.
## Setup
### Debian Package
To use, install the ``minecraft-pi-reborn-server`` package and run ``minecraft-pi-reborn-server`` or use. It will generate the world and ``server.properties`` in the current directory.
To use, install and run ``minecraft-pi-reborn-server``. It will generate the world and ``server.properties`` in the current directory.
### Docker Compose
Make sure you have ``qemu-user-static`` installed and ``binfmt`` setup.
```yml
version: "3.7"
## Server Limitations
* Player data is not saved because of limitations with MCPE LAN worlds
* An easy workaround is to place your inventory in a chest before logging off
* Survival Mode servers are incompatible with unmodded MCPI
services:
minecraft-pi:
image: thebrokenrail/minecraft-pi-reborn:server
volumes:
- ./minecraft-pi/data:/home/.minecraft-pi
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static
restart: always
stdin_open: true
tty: true
ports:
- "19132:19132/udp"
```
## Arguments
## Server Limitations
- Player data is not saved because of limitations with MCPE LAN worlds
- An easy workaround is to place your inventory in a chest before logging off
- Survival Mode servers are only compatible with ``minecraft-pi-reborn`` clients
### ``--only-generate``
If you run the server with ``--only-generate`` it will immediately exit once world generation has completed.

74
docs/INSTALL.md

@ -1,66 +1,26 @@
# Manual Installation
[Download Packages Here](https://jenkins.thebrokenrail.com/job/minecraft-pi-reborn/job/master/lastSuccessfulBuild/artifact/out/)
## System Requirements
- At Least Debian/Raspbian Buster Or Ubuntu 20.04
## Picking A Package
## Before You Install
<details>
<summary>Debian/Raspbian Buster</summary>
### ``libseccomp2``
``minecraft-pi-reborn`` requires a newer version of the package ``libseccomp2`` to be installed when using Debian/Raspbian Buster.
```sh
# Install Backports Key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 04EE7237B7D453EC
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 648ACFD622F3D138
# Install Backports Repository
echo 'deb http://deb.debian.org/debian buster-backports main' | sudo tee -a /etc/apt/sources.list
# Update APT Index
sudo apt update
# Install Updated libseccomp2
sudo apt install -t buster-backports libseccomp2
```
### Official Docker Package
``minecraft-pi-reborn`` requires the official Docker package when running Debian/Raspbian Buster instead of the Debian package (``docker.io``).
```sh
# Remove Debian Docker Package
sudo apt-get remove -y docker.io
# Install Official Docker Package
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
### Name Format
```
### Existing Installation
If you have un-modded ``minecraft-pi`` installed, you must remove it and transfer your existing worlds to ``minecraft-pi-reborn``'s folder.
```sh
# Transfer Worlds
mv ~/.minecraft ~/.minecraft-pi
# Remove Vanilla Minecraft Pi
sudo apt-get remove -y minecraft-pi
minecraft-pi-reborn-<Variant>_X.Y.Z~<Distribution>_<Architecture>
```
</details>
<details>
<summary>NVIDIA Users</summary>
The proprietary NVIDIA drivers are not supported, use either the open-source ``noveau`` drivers or use a different GPU (ie. Intel Integrated GPU).
### Picking A Variant
* ``client``: Client mode, use this if you want to play MCPI
* ``server``: Server mode, use this if you want to host an MCPI server
</details>
### Picking A Distribution
This specifies which version of Debian MCPI-Reborn was built against. Which one you should use depends on your current distribution. If your distribution supports it, you should use ``bullseye`` for better mouse sensitivity.
## Installing
1. Download Appropriate Package From [Here](https://jenkins.thebrokenrail.com/job/minecraft-pi-reborn/job/master/lastSuccessfulBuild/artifact/out/deb/) (See Table Below To Pick Correct Package)
2. Install With ``sudo apt install ./<Path To File>`` Or Your Preferred Package Installer
3. Have Fun!
* Ubuntu 20.04+: ``bullseye``
* Ubuntu 18.04: ``buster``
* Raspberry Pi OS Buster: ``buster``
* Debian Bullseye+: ``bullseye``
* Debian Buster: ``buster``
### Package Table
| Package | Description |
| --- | --- |
| ``minecraft-pi-reborn-virgl`` | Minecraft Pi Edition Using VirGL For Hardware Acceleration (Recommended For Desktop/Laptop) |
| ``minecraft-pi-reborn-native`` | Minecraft: Pi Edition Using Docker Device Mounting For GPU Acceleration (Recommended For ARM Devices (ie. Raspberry Pi, PinePhone, etc)) |
| ``minecraft-pi-reborn-server`` | Minecraft Pi Edition Modded Into A Dedicated Server |
### Picking An Architecture
* ``amd64``: x86_64, use this if you are using a device with an AMD or Intel processor
* ``armhf``: ARM, use this if you are using an ARM device (like a Raspberry Pi)

116
docs/MODDING.md

@ -1,116 +0,0 @@
# Modding
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.
## Loading Directories
``minecraft-pi-reborn`` loads mods from two locations, ``/app/minecraft-pi/mods``, and ``~/.minecraft-pi/mods``. The first location only exists in the Docker container and is immutable, so you should place your mods in ``~/.minecraft-pi/mods`` which is mounted on the host.
## 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``.
## ``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)``
This method replaces a function with another function.
#### Parameters
- **start:** The function you are replacing.
- **target:** The function you are replacing it with.
#### Return Value
None
#### Warning
This should never be used on functions that are only 1 byte long because it overwrites 2 bytes.
#### Example
```c
static int func_injection(int a, int b) {
return a + 4;
}
__attribute__((constructor)) static void init() {
overwrite((void *) 0xabcde, func_injection);
}
```
### ``void overwrite_call(void *start, void *original)``
This allows you to overwrite a specific call of a function rather than the function itself. This allows you to call the original function. However, this does not effect VTables.
#### Parameters
- **start:** The address of the function call to overwrite.
- **target:** The function call you are replacing it with.
#### Return Value
None
#### Warning
This method can only be safely used 512 times in total.
#### Example
```c
typedef int (*func_t)(int a, int b);
static func_t func = (func_t) 0xabcde;
static void *func_original = NULL;
static int func_injection(int a, int b) {
(*func)(a, b);
return a + 4;
}
__attribute__((constructor)) static void init() {
overwrite_call((void *) 0xabcd, func_injection);
}
```
### ``void overwrite_calls(void *start, void *original)``
This allows you to overwrite all calls of a function rather than the function itself. This allows you to call the original function. However, this does not effect VTables.
#### Parameters
- **start:** The function call to overwrite;
- **target:** The function call you are replacing it with.
#### Return Value
None
#### Warning
This method can only be safely used 512 times in total.
#### Example
```c
typedef int (*func_t)(int a, int b);
static func_t func = (func_t) 0xabcde;
static void *func_original = NULL;
static int func_injection(int a, int b) {
(*func)(a, b);
return a + 4;
}
__attribute__((constructor)) static void init() {
overwrite_calls((void *) func, func_injection);
}
```
### ``void patch(void *start, unsigned char patch[])``
This allows you to replace a specific instruction.
#### Parameters
- **start:** The target instruction.
- **patch:** The new instruction (array length must be 4).
#### Return Value
None
#### Example
```c
__attribute__((constructor)) static void init() {
unsigned char patch_data[4] = {0x00, 0x00, 0x00, 0x00};
patch((void *) 0xabcde, patch_data);
}
```

2
docs/OVERRIDING_ASSETS.md

@ -1,5 +1,5 @@
# Overriding Assets
Normally, Minecraft: Pi Edition assets can be easily overridden by physically replacing the file, however ``minecraft-pi-=reborn`` uses a Docker image making this much harder to do. To make overriding assets easier, ``minecraft-pi-reborn`` provides an overrides folder. Any file located in Minecraft: Pi Edition's ``data`` folder can be overridden by placing a file with the same name and path in the overrides folder. The overrides folder is located at ``~/.minecraft-pi/overrides``.
To make overriding assets easier, MCPI-Reborn provides an overrides folder. Any file located in Minecraft: Pi Edition's ``data`` folder can be overridden by placing a file with the same name and path in the overrides folder. The overrides folder is located at ``~/.minecraft-pi/overrides``.
## Examples
- ``data/images/terrain.png`` -> ``~/.minecraft-pi/overrides/images/terrain.png``

8
docs/README.md

@ -0,0 +1,8 @@
# Documentation
* [View Manual Installation](docs/INSTALL.md)
* [View Overriding Assets](OVERRIDING_ASSETS.md)
* [View Dedicated Server](DEDICATED_SERVER.md)
* [View Credits](CREDITS.md)
* [View Terminology](TERMINOLOGY.md)
* [View Building](BUILDING.md)
* [View Architecture](ARCHITECTURE.md)

10
docs/TERMINOLOGY.md

@ -0,0 +1,10 @@
# Terminology
| Name | Description |
| --- | --- |
| MCPI | Shorthand for Minecraft: Pi Edition |
| Host Architecture | The native architecture of the CPU that MCPi-Reborn will be running on |
| Native Component | A component that *can* be compiled for the host architecture |
| ARM Component | A component that *must* be compiled for ARM |
| Server Mode | A mode where MCPI is patched into behaving like a dedicated server |
| Client Mode | The normal behavior of MCPI |
| Stub | An implementation of a library where all functions either do nothing or error |

26
docs/TROUBLESHOOTING.md

@ -1,26 +0,0 @@
# Troubleshooting
Game logs are located in ``/tmp/minecraft-pi``.
## ``Couldn't connect to Docker daemon at http+docker://localhost - is it running?``
Start Docker if it isn't running:
```sh
sudo service docker start
```
## ``Error response from daemon: error gathering device information while adding custom device "/dev/dri": no such file or directory``
Make sure you are using the correct GPU drivers for your system.
If you are using a Raspberry Pi, make sure your GPU driver is set to ``Full KMS`` or ``Fake KMS`` in ``raspi-config``.
## ``Segmentation Fault`` (Exit Code: ``139``)
Report an issue with reproduction instructions and system details.
## ``[ERR]: Invalid ~/.minecraft-pi Permissions``
Update ``~/.minecraft-pi`` permissions:
```sh
sudo chown -R "$(id -u):$(id -g)" ~/.minecraft-pi
chmod -R u+rw ~/.minecraft-pi
```
## Other
If you experience a crash/error not listed above, report it on the issue tracker **with your game log attached**.

48
launcher/CMakeLists.txt

@ -1,34 +1,18 @@
cmake_minimum_required(VERSION 3.1.0)
project(launcher)
add_compile_options(-Wall -Wextra -Werror)
## Launcher
add_executable(launcher src/launcher.c)
# Install
install(TARGETS launcher DESTINATION /)
install(PROGRAMS src/run.sh DESTINATION /)
## 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)
# Stub SDL
add_library(SDL-1.2 SHARED src/stubs/SDL.cpp)
target_link_libraries(SDL-1.2 pthread)
set_target_properties(SDL-1.2 PROPERTIES SOVERSION "0")
# 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 Stubs
install(TARGETS bcm_host EGL SDL-1.2 GLESv2 DESTINATION /lib)
# Launcher
if(BUILD_NATIVE_COMPONENTS)
add_executable(launcher src/bootstrap.c src/ldconfig.cpp)
if(MCPI_SERVER_MODE)
target_sources(launcher PRIVATE src/server/launcher.c)
else()
target_sources(launcher PRIVATE src/client/launcher.cpp)
endif()
target_link_libraries(launcher reborn-headers)
# Install
install(TARGETS launcher DESTINATION "${MCPI_INSTALL_DIR}")
install_symlink("../../${MCPI_INSTALL_DIR}/launcher" "usr/bin/${MCPI_VARIANT_NAME}")
if(NOT MCPI_SERVER_MODE)
install(DIRECTORY "client-data/" DESTINATION ".")
endif()
endif()

16
launcher/client-data/opt/minecraft-pi-reborn-client/available-feature-flags

@ -0,0 +1,16 @@
TRUE Touch GUI
TRUE Fix Bow & Arrow
TRUE Fix Attacking
TRUE Mob Spawning
TRUE Fancy Graphics
TRUE Disable Autojump By Default
TRUE Display Nametags 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 Disable gui_blocks Atlas
TRUE Smooth Lighting
FALSE 3D Anaglyph

6
debian/client/common/usr/share/applications/minecraft-pi.desktop → launcher/client-data/usr/share/applications/minecraft-pi-reborn-client.desktop

@ -1,10 +1,10 @@
[Desktop Entry]
Name=Minecraft: Pi Edition
Name=Minecraft: Pi Edition: Reborn
Comment=Fun with Blocks
Icon=/usr/share/pixmaps/minecraft-pi.png
Icon=/usr/share/pixmaps/minecraft-pi-reborn-client.png
StartupNotify=false
StartupWMClass=Minecraft - Pi edition
Exec=/usr/bin/minecraft-pi
Exec=/usr/bin/minecraft-pi-reborn-client
Terminal=false
Type=Application
Categories=Application;Game;

0
debian/client/common/usr/share/pixmaps/minecraft-pi.png → launcher/client-data/usr/share/pixmaps/minecraft-pi-reborn-client.png

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

222
launcher/src/bootstrap.c

@ -0,0 +1,222 @@
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <libreborn/libreborn.h>
#include "bootstrap.h"
#include "ldconfig.h"
// Set Environmental Variable
#define PRESERVE_ENVIRONMENTAL_VARIABLE(name) \
{ \
char *original_env_value = getenv(name); \
if (original_env_value != NULL) { \
setenv("ORIGINAL_" name, original_env_value, 1); \
} \
}
static void trim(char **value) {
// Remove Trailing Colon
int length = strlen(*value);
if ((*value)[length - 1] == ':') {
(*value)[length - 1] = '\0';
}
if ((*value)[0] == ':') {
*value = &(*value)[1];
}
}
static void set_and_print_env(const char *name, char *value) {
// Set Variable With No Trailing Colon
trim(&value);
#ifdef DEBUG
// Print New Value
INFO("Set %s = %s", name, value);
#endif
// Set The Value
setenv(name, value, 1);
}
// Get Environmental Variable
static char *get_env_safe(const char *name) {
// Get Variable Or Blank String If Not Set
char *ret = getenv(name);
return ret != NULL ? ret : "";
}
// Get All Mods In Folder
static void load(char **ld_preload, char *folder) {
int folder_name_length = strlen(folder);
// Retry Until Successful
while (1) {
// Open Folder
DIR *dp = opendir(folder);
if (dp != NULL) {
// Loop Through Folder
struct dirent *entry = NULL;
errno = 0;
while (1) {
errno = 0;
entry = readdir(dp);
if (entry != NULL) {
// Check If File Is Regular
if (entry->d_type == DT_REG) {
// Get Full Name
int name_length = strlen(entry->d_name);
int total_length = folder_name_length + name_length;
char name[total_length + 1];
// Concatenate Folder Name And File Name
for (int i = 0; i < folder_name_length; i++) {
name[i] = folder[i];
}
for (int i = 0; i < name_length; i++) {
name[folder_name_length + i] = entry->d_name[i];
}
// Add Terminator
name[total_length] = '\0';
// Check If File Is Executable
int result = access(name, R_OK);
if (result == 0) {
// Add To LD_PRELOAD
string_append(ld_preload, ":%s", name);
} else if (result == -1 && errno != 0) {
// Fail
INFO("Unable To Acesss: %s: %s", name, strerror(errno));
errno = 0;
}
}
} else if (errno != 0) {
// Error Reading Contents Of Folder
ERR("Error Reading Directory: %s: %s", folder, strerror(errno));
} else {
// Done!
break;
}
}
// Close Folder
closedir(dp);
// Exit Function
return;
} else if (errno == ENOENT) {
// Folder Doesn't Exists, Attempt Creation
int ret = mkdir(folder, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (ret != 0) {
// Unable To Create Folder
ERR("Error Creating Directory: %s: %s", folder, strerror(errno));
}
// Continue Retrying
} else {
// Unable To Open Folder
ERR("Error Opening Directory: %s: %s", folder, strerror(errno));
}
}
}
#define MCPI_NAME "minecraft-pi"
// Bootstrap
void bootstrap(int argc, char *argv[]) {
INFO("%s", "Configuring Game...");
// Get Binary Directory
char *binary_directory = get_binary_directory();
// Configure LD_LIBRARY_PATH
{
PRESERVE_ENVIRONMENTAL_VARIABLE("LD_LIBRARY_PATH");
// Add Library Directory
char *new_ld_path;
safe_asprintf(&new_ld_path, "%s/lib", binary_directory);
// Add Existing LD_LIBRAR_PATH
{
char *value = get_env_safe("LD_LIBRARY_PATH");
if (strlen(value) > 0) {
string_append(&new_ld_path, ":%s", value);
}