This commit is contained in:
Bigjango13 2024-01-28 14:31:50 -05:00
commit a3e49a8e79
23 changed files with 351 additions and 334 deletions

View File

@ -23,18 +23,13 @@ jobs:
- ARMHF
name: Build
runs-on: ubuntu-latest
container: node:16-buster
container: node:lts-bullseye
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: true
# Dependencies
- name: Install CMake
run: |
echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/backports.list
apt-get update
apt-get install --no-install-recommends -y -t buster-backports cmake
- name: Install Dependencies
run: ./scripts/install-dependencies.sh ${{ matrix.arch }}
# Build
@ -55,18 +50,13 @@ jobs:
- Server
name: Test
runs-on: ubuntu-latest
container: node:16-buster
container: node:lts-bullseye
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: true
# Dependencies
- name: Install CMake
run: |
echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/backports.list
apt-get update
apt-get install --no-install-recommends -y -t buster-backports cmake
- name: Install Dependencies
run: ./scripts/install-dependencies.sh
- name: Install ARM Toolchain
@ -81,7 +71,7 @@ jobs:
needs: build
name: Release
runs-on: ubuntu-latest
container: node:16-buster
container: node:lts-bullseye
steps:
# Dependencies
- name: Install Go

View File

@ -70,7 +70,7 @@ add_compile_options(-ffast-math)
# Warnings
add_compile_options(-Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference)
if(CMAKE_C_COMPILER_ID STREQUAL \"GNU\")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
# Prevents False Positives
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 10.0)
add_compile_options(-Wno-stringop-overflow)

@ -1 +1 @@
Subproject commit b4c3ef9d0fdf46845f3e81e5d989dab06e71e6c1
Subproject commit 8e6c8d7effc54f8aecd30eda17069588298f4ada

View File

@ -8,6 +8,9 @@ If you run MCPI-Reborn with ``--version`` it will print its version to ``stdout`
### ``--debug``
This sets ``MCPI_DEBUG``.
### ``--copy-sdk``
This extracts the modding SDK and immediately exits. (This allows the SDK to be extracted without starting the game.)
### Client Mode Only
#### ``--print-available-feature-flags``

View File

@ -4,7 +4,7 @@
Download packages [here](https://gitea.thebrokenrail.com/minecraft-pi-reborn/minecraft-pi-reborn/releases).
### System Requirements
* Debian Buster/Ubuntu 18.04 Or Higher
* Debian Bullseye/Ubuntu 20.04 Or Higher
* FUSE 2
* Debian/Ubuntu: ``sudo apt install libfuse2``
* Arch: ``sudo pacman -S fuse2``

View File

@ -14,4 +14,4 @@ include("$ENV{HOME}/.minecraft-pi/sdk/lib/minecraft-pi-reborn-client/sdk/sdk.cma
# Build
add_library(chat-commands SHARED chat-commands.cpp)
target_link_libraries(chat-commands mods-headers reborn-patch symbols chat misc)
target_link_libraries(chat-commands mods reborn-patch symbols)

View File

@ -14,4 +14,4 @@ include("$ENV{HOME}/.minecraft-pi/sdk/lib/minecraft-pi-reborn-client/sdk/sdk.cma
# Build
add_library(expanded-creative SHARED expanded-creative.cpp)
target_link_libraries(expanded-creative mods-headers reborn-patch symbols misc)
target_link_libraries(expanded-creative mods reborn-patch symbols)

View File

@ -14,4 +14,4 @@ include("$ENV{HOME}/.minecraft-pi/sdk/lib/minecraft-pi-reborn-client/sdk/sdk.cma
# Build
add_library(recipes SHARED recipes.cpp)
target_link_libraries(recipes mods-headers reborn-util symbols misc)
target_link_libraries(recipes mods reborn-util symbols)

View File

@ -1,7 +1,7 @@
project(launcher)
# Launcher
add_executable(launcher src/bootstrap.c src/patchelf.cpp src/util.c src/crash-report.c)
add_executable(launcher src/bootstrap.c src/patchelf.cpp src/util.c src/crash-report.c src/sdk.c src/mods.c)
if(MCPI_SERVER_MODE)
target_sources(launcher PRIVATE src/server/launcher.c)
else()

View File

@ -1,13 +1,5 @@
#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 "util.h"
@ -15,77 +7,6 @@
#include "patchelf.h"
#include "crash-report.h"
// 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 Accessible
int result = access(name, R_OK);
if (result == 0) {
// Add To LD_PRELOAD
string_append(ld_preload, "%s%s", *ld_preload == NULL ? "" : ":", name);
} else if (result == -1 && errno != 0) {
// Fail
WARN("Unable To Access: %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_BINARY "minecraft-pi"
#define QEMU_BINARY "qemu-arm"
@ -182,11 +103,11 @@ void pre_bootstrap(int argc, char *argv[]) {
set_and_print_env("GTK_THEME", "Adwaita:dark");
#endif
// Configure PATH
{
// Get Binary Directory
char *binary_directory = get_binary_directory();
// Configure PATH
{
// Add Library Directory
char *new_path = NULL;
safe_asprintf(&new_path, "%s/bin", binary_directory);
@ -200,10 +121,21 @@ void pre_bootstrap(int argc, char *argv[]) {
// Set And Free
set_and_print_env("PATH", new_path);
free(new_path);
}
// Free Binary Directory
free(binary_directory);
}
// --copy-sdk
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--copy-sdk") == 0) {
char *binary_directory = get_binary_directory();
copy_sdk(binary_directory, 0);
free(binary_directory);
fflush(stdout);
exit(EXIT_SUCCESS);
}
}
// Setup Crash Reports
setup_crash_report();
@ -242,56 +174,6 @@ void pre_bootstrap(int argc, char *argv[]) {
print_debug_information();
}
// Copy SDK Into ~/.minecraft-pi
#define HOME_SUBDIRECTORY_FOR_SDK HOME_SUBDIRECTORY_FOR_GAME_DATA "/sdk"
static void copy_sdk(char *binary_directory) {
// Ensure SDK Directory
{
char *sdk_path = NULL;
safe_asprintf(&sdk_path, "%s" HOME_SUBDIRECTORY_FOR_SDK, getenv("HOME"));
const char *const command[] = {"mkdir", "-p", sdk_path, NULL};
run_simple_command(command, "Unable To Create SDK Directory");
}
// Lock File
char *lock_file_path = NULL;
safe_asprintf(&lock_file_path, "%s" HOME_SUBDIRECTORY_FOR_SDK "/.lock", getenv("HOME"));
int lock_file_fd = lock_file(lock_file_path);
// Output Directory
char *output = NULL;
safe_asprintf(&output, "%s" HOME_SUBDIRECTORY_FOR_SDK "/" MCPI_SDK_DIR, getenv("HOME"));
// Source Directory
char *source = NULL;
safe_asprintf(&source, "%s/sdk/.", binary_directory);
// Clean
{
const char *const command[] = {"rm", "-rf", output, NULL};
run_simple_command(command, "Unable To Clean SDK Output Directory");
}
// Make Directory
{
const char *const command[] = {"mkdir", "-p", output, NULL};
run_simple_command(command, "Unable To Create SDK Output Directory");
}
// Copy
{
const char *const command[] = {"cp", "-ar", source, output, NULL};
run_simple_command(command, "Unable To Copy SDK");
}
// Free
free(output);
free(source);
// Unlock File
unlock_file(lock_file_path, lock_file_fd);
free(lock_file_path);
}
// Bootstrap
void bootstrap(int argc, char *argv[]) {
INFO("Configuring Game...");
@ -301,7 +183,7 @@ void bootstrap(int argc, char *argv[]) {
DEBUG("Binary Directory: %s", binary_directory);
// Copy SDK
copy_sdk(binary_directory);
copy_sdk(binary_directory, 1);
// Set MCPI_REBORN_ASSETS_PATH
{
@ -432,44 +314,7 @@ void bootstrap(int argc, char *argv[]) {
set_and_print_env("MCPI_NATIVE_LD_PRELOAD", host_ld_preload);
// ARM Components
{
// Prepare
char *preload = NULL;
// ~/.minecraft-pi/mods
{
// Get Mods Folder
char *mods_folder = NULL;
safe_asprintf(&mods_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA "/mods/", getenv("HOME"));
// Load Mods From ./mods
load(&preload, mods_folder);
// Free Mods Folder
free(mods_folder);
}
// Built-In Mods
{
// Get Mods Folder
char *mods_folder = NULL;
safe_asprintf(&mods_folder, "%s/mods/", binary_directory);
// Load Mods From ./mods
load(&preload, mods_folder);
// Free Mods Folder
free(mods_folder);
}
// Add LD_PRELOAD
{
char *value = getenv("LD_PRELOAD");
if (value != NULL && strlen(value) > 0) {
string_append(&preload, ":%s", value);
}
}
// Set
set_and_print_env("MCPI_ARM_LD_PRELOAD", preload);
free(preload);
}
bootstrap_mods(binary_directory);
}
// Free Binary Directory

View File

@ -6,6 +6,8 @@ extern "C" {
void pre_bootstrap(int argc, char *argv[]);
void bootstrap(int argc, char *argv[]);
void copy_sdk(char *binary_directory, int log_with_debug);
void bootstrap_mods(char *binary_directory);
#ifdef __cplusplus
}

110
launcher/src/mods.c Normal file
View File

@ -0,0 +1,110 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#include <libreborn/libreborn.h>
#include "bootstrap.h"
// Get All Mods In Folder
static void load(char **ld_preload, const char *folder) {
int folder_name_length = strlen(folder);
// 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 Accessible
int result = access(name, R_OK);
if (result == 0) {
// Add To LD_PRELOAD
string_append(ld_preload, "%s%s", *ld_preload == NULL ? "" : ":", name);
} else if (result == -1 && errno != 0) {
// Fail
WARN("Unable To Access: %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);
} else if (errno == ENOENT) {
// Folder Doesn't Exist
} else {
// Unable To Open Folder
ERR("Error Opening Directory: %s: %s", folder, strerror(errno));
}
}
// Bootstrap Mods
void bootstrap_mods(char *binary_directory) {
// Prepare
char *preload = NULL;
// ~/.minecraft-pi/mods
{
// Get Mods Folder
char *mods_folder = NULL;
safe_asprintf(&mods_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA "/mods/", getenv("HOME"));
// Load Mods From ./mods
load(&preload, mods_folder);
// Free Mods Folder
free(mods_folder);
}
// Built-In Mods
{
// Get Mods Folder
char *mods_folder = NULL;
safe_asprintf(&mods_folder, "%s/mods/", binary_directory);
// Load Mods From ./mods
load(&preload, mods_folder);
// Free Mods Folder
free(mods_folder);
}
// Add LD_PRELOAD
{
char *value = getenv("LD_PRELOAD");
if (value != NULL && strlen(value) > 0) {
string_append(&preload, ":%s", value);
}
}
// Set
set_and_print_env("MCPI_ARM_LD_PRELOAD", preload);
free(preload);
}

67
launcher/src/sdk.c Normal file
View File

@ -0,0 +1,67 @@
#include <libreborn/libreborn.h>
#include "bootstrap.h"
#include "util.h"
// Log
#define LOG(is_debug, ...) \
{ \
if (is_debug) { \
DEBUG(__VA_ARGS__); \
} else { \
INFO(__VA_ARGS__); \
} \
}
// Copy SDK Into ~/.minecraft-pi
#define HOME_SUBDIRECTORY_FOR_SDK HOME_SUBDIRECTORY_FOR_GAME_DATA "/sdk"
void copy_sdk(char *binary_directory, int log_with_debug) {
// Ensure SDK Directory
{
char *sdk_path = NULL;
safe_asprintf(&sdk_path, "%s" HOME_SUBDIRECTORY_FOR_SDK, getenv("HOME"));
const char *const command[] = {"mkdir", "-p", sdk_path, NULL};
run_simple_command(command, "Unable To Create SDK Directory");
}
// Lock File
char *lock_file_path = NULL;
safe_asprintf(&lock_file_path, "%s" HOME_SUBDIRECTORY_FOR_SDK "/.lock", getenv("HOME"));
int lock_file_fd = lock_file(lock_file_path);
// Output Directory
char *output = NULL;
safe_asprintf(&output, "%s" HOME_SUBDIRECTORY_FOR_SDK "/" MCPI_SDK_DIR, getenv("HOME"));
// Source Directory
char *source = NULL;
safe_asprintf(&source, "%s/sdk/.", binary_directory);
// Clean
{
const char *const command[] = {"rm", "-rf", output, NULL};
run_simple_command(command, "Unable To Clean SDK Output Directory");
}
// Make Directory
{
const char *const command[] = {"mkdir", "-p", output, NULL};
run_simple_command(command, "Unable To Create SDK Output Directory");
}
// Copy
{
const char *const command[] = {"cp", "-ar", source, output, NULL};
run_simple_command(command, "Unable To Copy SDK");
}
// Log
LOG(log_with_debug, "Copied SDK To: %s", output);
// Free
free(output);
free(source);
// Unlock File
unlock_file(lock_file_path, lock_file_fd);
free(lock_file_path);
}

View File

@ -1,102 +1,109 @@
project(mods)
## Headers
add_library(mods-headers INTERFACE)
target_include_directories(
mods-headers
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${MCPI_SDK_INCLUDE_DIR}/mods>"
# Common Sources
set(SRC
# compat
src/compat/compat.c
src/compat/egl.c
src/compat/x11.c
src/compat/bcm_host.c
# readdir
src/readdir/readdir.c
# feature
src/feature/feature.c
# version
src/version/version.cpp
# chat
src/chat/chat.cpp
src/chat/ui.c
# creative
src/creative/creative.cpp
# game-mode
src/game-mode/game-mode.c
src/game-mode/ui.cpp
# override
src/override/override.c
# death
src/death/death.cpp
# misc
src/misc/misc.c
src/misc/misc.cpp
src/misc/logging.cpp
src/misc/api.cpp
# options
src/options/options.c
src/options/options.cpp
# bucket
src/bucket/bucket.cpp
# cake
src/cake/cake.cpp
# home
src/home/home.c
# test
src/test/test.c
# init
src/init/init.c
)
target_link_libraries(mods-headers INTERFACE symbols)
# SDK
install(TARGETS mods-headers EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
install(DIRECTORY "include/" DESTINATION "${MCPI_SDK_INCLUDE_DIR}/mods")
## Mods
add_library(compat SHARED src/compat/compat.c src/compat/egl.c src/compat/x11.c src/compat/bcm_host.c)
target_link_libraries(compat mods-headers reborn-patch media-layer-core)
if(NOT MCPI_HEADLESS_MODE)
target_link_libraries(compat screenshot input sign chat home dl)
endif()
add_library(readdir SHARED src/readdir/readdir.c)
add_library(feature SHARED src/feature/feature.c)
target_link_libraries(feature mods-headers reborn-patch)
add_library(version SHARED src/version/version.cpp)
target_link_libraries(version mods-headers reborn-patch symbols)
add_library(chat SHARED src/chat/chat.cpp src/chat/ui.c)
target_link_libraries(chat mods-headers reborn-patch symbols feature)
if(NOT MCPI_HEADLESS_MODE)
target_link_libraries(chat input media-layer-core pthread)
endif()
add_library(creative SHARED src/creative/creative.cpp)
target_link_libraries(creative mods-headers reborn-patch symbols feature misc)
add_library(game-mode SHARED src/game-mode/game-mode.c src/game-mode/ui.cpp)
target_link_libraries(game-mode mods-headers reborn-patch symbols feature)
if(NOT MCPI_SERVER_MODE)
target_link_libraries(game-mode pthread media-layer-core)
endif()
# Server-Only Sources
if(MCPI_SERVER_MODE)
add_library(server SHARED src/server/server.cpp src/server/server_properties.cpp)
target_link_libraries(server mods-headers reborn-patch symbols feature home misc compat dl media-layer-core pthread)
list(APPEND SRC
# server
src/server/server.cpp
src/server/server_properties.cpp
)
else()
add_library(multiplayer SHARED src/multiplayer/multiplayer.cpp)
target_link_libraries(multiplayer mods-headers reborn-patch symbols home feature)
add_library(benchmark SHARED src/benchmark/benchmark.cpp)
target_link_libraries(benchmark mods-headers reborn-patch symbols compat misc media-layer-core)
list(APPEND SRC
# multiplayer
src/multiplayer/multiplayer.cpp
# benchmark
src/benchmark/benchmark.cpp
)
endif()
if(NOT MCPI_HEADLESS_MODE)
add_library(sound SHARED src/sound/sound.cpp src/sound/repository.cpp)
target_link_libraries(sound mods-headers reborn-patch symbols feature override media-layer-core)
add_library(camera SHARED src/camera/camera.cpp)
target_link_libraries(camera mods-headers reborn-patch symbols feature home screenshot)
add_library(input SHARED src/input/input.cpp src/input/bow.c src/input/attack.c src/input/toggle.c src/input/misc.c src/input/drop.cpp src/input/crafting.cpp)
target_link_libraries(input mods-headers reborn-patch symbols creative feature misc media-layer-core)
add_library(sign SHARED src/sign/sign.cpp)
target_link_libraries(sign mods-headers reborn-patch symbols feature input media-layer-core)
add_library(touch SHARED src/touch/touch.cpp)
target_link_libraries(touch mods-headers reborn-patch symbols feature)
add_library(atlas SHARED src/atlas/atlas.cpp)
target_link_libraries(atlas mods-headers reborn-patch symbols feature media-layer-core)
add_library(title-screen SHARED src/title-screen/title-screen.cpp)
target_link_libraries(title-screen mods-headers reborn-patch symbols feature compat)
add_library(skin SHARED src/skin/skin.cpp src/skin/loader.cpp)
target_link_libraries(skin mods-headers reborn-patch symbols feature misc textures media-layer-core stb_image)
add_library(screenshot SHARED src/screenshot/screenshot.c)
target_link_libraries(screenshot mods-headers reborn-util media-layer-core stb_image)
endif()
if(NOT MCPI_HEADLESS_MODE)
add_library(textures SHARED src/textures/textures.cpp)
# Headless-Only Sources
if(MCPI_HEADLESS_MODE)
list(APPEND SRC
# textures
src/textures/headless.cpp
)
else()
add_library(textures SHARED src/textures/headless.cpp)
endif()
target_link_libraries(textures mods-headers reborn-patch symbols)
if(NOT MCPI_HEADLESS_MODE)
target_link_libraries(textures media-layer-core feature misc stb_image)
list(APPEND SRC
# sound
src/sound/sound.cpp
src/sound/repository.cpp
# camera
src/camera/camera.cpp
# input
src/input/input.cpp
src/input/bow.c
src/input/attack.c
src/input/toggle.c
src/input/misc.c
src/input/drop.cpp
src/input/crafting.cpp
# sign
src/sign/sign.cpp
# touch
src/touch/touch.cpp
# atlas
src/atlas/atlas.cpp
# title-screen
src/title-screen/title-screen.cpp
# skin
src/skin/skin.cpp
src/skin/loader.cpp
# screenshot
src/screenshot/screenshot.c
# textures
src/textures/textures.cpp
)
endif()
add_library(override SHARED src/override/override.c)
target_link_libraries(override mods-headers reborn-patch symbols dl home)
# Build
add_library(mods SHARED ${SRC})
==== BASE ====
add_library(death SHARED src/death/death.cpp)
target_link_libraries(death mods-headers reborn-patch symbols feature)
@ -109,28 +116,29 @@ target_link_libraries(options mods-headers reborn-patch symbols feature home)
add_library(bucket SHARED src/bucket/bucket.cpp)
target_link_libraries(bucket mods-headers reborn-patch symbols feature misc)
add_library(cake SHARED src/cake/cake.cpp)
target_link_libraries(cake mods-headers reborn-patch symbols feature misc)
add_library(home SHARED src/home/home.c)
target_link_libraries(home mods-headers reborn-patch symbols)
add_library(test SHARED src/test/test.c)
target_link_libraries(test mods-headers reborn-patch home)
==== BASE ====
==== BASE ====
add_library(init SHARED src/init/init.c)
target_link_libraries(init symbols mods-headers reborn-util compat game-mode misc death options chat creative bucket cake textures home version test media-layer-core)
target_link_libraries(init symbols mods-headers reborn-util compat game-mode misc death options chat creative bucket textures home version test media-layer-core)
if(MCPI_SERVER_MODE)
target_link_libraries(init server)
else()
target_link_libraries(init multiplayer benchmark)
endif()
==== BASE ====
if(NOT MCPI_HEADLESS_MODE)
target_link_libraries(init sound camera input sign touch atlas title-screen skin)
target_link_libraries(mods stb_image)
endif()
==== BASE ====
## Install Mods
set(MODS_TO_INSTALL init compat readdir feature game-mode misc override death options chat creative bucket cake textures home version test)
set(MODS_TO_INSTALL init compat readdir feature game-mode misc override death options chat creative bucket textures home version test)
if(MCPI_SERVER_MODE)
list(APPEND MODS_TO_INSTALL server)
else()
@ -140,5 +148,6 @@ if(NOT MCPI_HEADLESS_MODE)
list(APPEND MODS_TO_INSTALL sound camera input sign touch atlas title-screen skin screenshot)
endif()
install(TARGETS ${MODS_TO_INSTALL} DESTINATION "${MCPI_INSTALL_DIR}/mods")
==== BASE ====
# SDK
install(TARGETS ${MODS_TO_INSTALL} EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
install(DIRECTORY "include/" DESTINATION "${MCPI_SDK_INCLUDE_DIR}/mods")

View File

@ -13,7 +13,7 @@ void init_compat();
void init_server();
#else
void init_multiplayer();
void init_benchmark();
void init_benchmark(int argc, char *argv[]);
#endif
#ifndef MCPI_HEADLESS_MODE
void init_sound();

View File

@ -0,0 +1,5 @@
#pragma once
#include "server_properties.h"
ServerProperties &get_server_properties();

View File

@ -0,0 +1,6 @@
#pragma once
#include <unordered_map>
#include <vector>
extern std::unordered_map<std::string, std::vector<std::string>> sound_repository;

View File

@ -10,20 +10,6 @@
#include <mods/compat/compat.h>
#include <mods/misc/misc.h>
// --benchmark: Activate Benchmark
static bool active = false;
__attribute__((constructor)) static void _init_active(int argc, char *argv[]) {
// Iterate Arguments
for (int i = 1; i < argc; i++) {
// Check Argument
if (strcmp(argv[i], "--benchmark") == 0) {
// Enabled
active = true;
break;
}
}
}
// Constants
#define NANOSECONDS_IN_SECOND 1000000000ll
@ -172,7 +158,17 @@ static void Minecraft_update_injection(Minecraft *minecraft) {
}
// Init Benchmark
void init_benchmark() {
void init_benchmark(int argc, char *argv[]) {
// --benchmark: Activate Benchmark
bool active = false;
for (int i = 1; i < argc; i++) {
// Check Argument
if (strcmp(argv[i], "--benchmark") == 0) {
// Enabled
active = true;
break;
}
}
if (active) {
misc_run_on_update(Minecraft_update_injection);
// Track Ticks

View File

@ -6,7 +6,7 @@
#include <mods/misc/misc.h>
// Items
FoodItem *bucket = NULL;
static FoodItem *bucket = NULL;
// Description And Texture
static std::string BucketItem_getDescriptionId(__attribute__((unused)) FoodItem *item, ItemInstance *item_instance) {

View File

@ -3,7 +3,7 @@
#include <media-layer/core.h>
#include <symbols/minecraft.h>
__attribute__((constructor)) static void init() {
__attribute__((constructor)) static void init(int argc, char *argv[]) {
media_ensure_loaded();
run_tests();
init_symbols();
@ -35,6 +35,9 @@ __attribute__((constructor)) static void init() {
init_cake();
init_home();
#ifndef MCPI_SERVER_MODE
init_benchmark();
init_benchmark(argc, argv);
#else
(void) argc;
(void) argv;
#endif
}

View File

@ -21,7 +21,7 @@
#include <symbols/minecraft.h>
#include <mods/server/server_properties.h>
#include <mods/server/server.h>
#include <mods/feature/feature.h>
#include <mods/init/init.h>
@ -44,7 +44,7 @@ __attribute__((constructor)) static void _init_only_generate(int argc, char *arg
}
// Server Properties
static ServerProperties &get_server_properties() {
ServerProperties &get_server_properties() {
static ServerProperties properties;
return properties;
}

View File

@ -1,5 +1,3 @@
#include <unordered_map>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
@ -8,9 +6,10 @@
#include <media-layer/audio.h>
#include "sound-internal.h"
#include <mods/sound/sound.h>
// Sound Repository Extracted From MCPE 0.6.1 APK
static std::unordered_map<std::string, std::vector<std::string>> repository = {
std::unordered_map<std::string, std::vector<std::string>> sound_repository = {
{
{
"step.cloth",
@ -355,9 +354,9 @@ __attribute__((constructor)) static void init_rand_seed() {
}
// Pick Sound
std::string _sound_pick(std::string sound) {
if (repository.count(sound) > 0) {
if (sound_repository.count(sound) > 0) {
// Sound Exists
std::vector<std::string> &options = repository[sound];
std::vector<std::string> &options = sound_repository[sound];
return options[rand() % options.size()];
} else {
// Invalid Sound
@ -370,7 +369,7 @@ std::string _sound_pick(std::string sound) {
void _sound_resolve_all() {
std::string source = _sound_get_source_file();
if (source.size() > 0) {
for (auto &it : repository) {
for (auto &it : sound_repository) {
for (std::string &name : it.second) {
// Zero Volume Prevents An OpenAL Source From Being Allocated While Still Resolving The Sound
media_audio_play(source.c_str(), name.c_str(), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f);

View File

@ -20,9 +20,6 @@ run() {
sudo apt-get update
sudo apt-get dist-upgrade -y
# Architecture Detection
sudo apt-get install --no-install-recommends -y dpkg-dev
# Install Everything In One Go
PKG_QUEUE=''
queue_pkg() {
@ -44,22 +41,7 @@ run() {
# Architecture-Specific Dependencies
architecture_specific_pkg() {
# Compiler
if [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "$1" ]; then
queue_pkg \
gcc \
g++
else
case "$1" in
'armhf') GCC_TARGET='arm-linux-gnueabihf';;
'arm64') GCC_TARGET='aarch64-linux-gnu';;
'i386') GCC_TARGET='i686-linux-gnu';;
'amd64') GCC_TARGET='x86-64-linux-gnu';;
esac
queue_pkg \
"gcc-${GCC_TARGET}" \
libc6-dev-$1-cross \
"g++-${GCC_TARGET}"
fi
queue_pkg crossbuild-essential-$1
# Dependencies
queue_pkg \