Remove libreborn.h: Part 1

This commit is contained in:
TheBrokenRail 2024-11-21 22:36:05 -05:00
parent 454734ab68
commit fd26000fd4
38 changed files with 75 additions and 113 deletions

View File

@ -1,4 +1,4 @@
#include <libreborn/libreborn.h>
#include <libreborn/env.h>
#include "bootstrap.h"
#include "../util/util.h"

View File

@ -1,7 +1,10 @@
#include <string>
#include <vector>
#include <libreborn/libreborn.h>
#include <libreborn/log.h>
#include <libreborn/env.h>
#include <libreborn/util.h>
#include <libreborn/exec.h>
#include "../util/util.h"
#include "bootstrap.h"

View File

@ -1,4 +1,6 @@
#include <libreborn/libreborn.h>
#include <libreborn/log.h>
#include <libreborn/exec.h>
#include <libreborn/config.h>
#include "bootstrap.h"

View File

@ -3,9 +3,11 @@
#include <sys/stat.h>
#include <unistd.h>
#include <libreborn/libreborn.h>
#include <libreborn/log.h>
#include <libreborn/util.h>
#include "bootstrap.h"
#include "../util/util.h"
// Get All Mods In Folder
static void load(std::vector<std::string> &ld_preload, const std::string &folder, int recursion_limit = 128);
@ -18,10 +20,8 @@ static void handle_file(std::vector<std::string> &ld_preload, const std::string
load(ld_preload, std::string(file) + '/', recursion_limit - 1);
} else if (S_ISLNK(file_stat.st_mode)) {
// Resolve Symlink
char *resolved_file = realpath(file.c_str(), nullptr);
ALLOC_CHECK(resolved_file);
const std::string resolved_file = safe_realpath(file);
handle_file(ld_preload, resolved_file, recursion_limit);
free(resolved_file);
} else if (S_ISREG(file_stat.st_mode)) {
// Check If File Is Accessible
const int result = access(file.c_str(), R_OK);
@ -79,19 +79,13 @@ std::vector<std::string> bootstrap_mods(const std::string &binary_directory) {
// Prepare
std::vector<std::string> preload;
// ~/.minecraft-pi/mods
{
// Get Mods Folder
const std::string mods_folder = std::string(getenv(_MCPI_HOME_ENV)) + get_home_subdirectory_for_game_data() + SUBDIRECTORY_FOR_MODS;
// Load Mods From ./mods
load(preload, mods_folder);
}
// Built-In Mods
{
// Get Mods Folder
const std::string mods_folder = binary_directory + SUBDIRECTORY_FOR_MODS;
// Load Mods From ./mods
// Load
const std::vector folders = {
home_get(),
binary_directory
};
for (std::string mods_folder : folders) {
mods_folder += SUBDIRECTORY_FOR_MODS;
load(preload, mods_folder);
}

View File

@ -4,10 +4,8 @@
#include <LIEF/ELF.hpp>
#include <dlfcn.h>
#include <link.h>
#include <libreborn/libreborn.h>
#include <libreborn/util.h>
#include <libreborn/config.h>
#include "bootstrap.h"

View File

@ -6,18 +6,15 @@
#include <sys/stat.h>
#include <unistd.h>
#include <libreborn/libreborn.h>
#include <libreborn/log.h>
#include <libreborn/util.h>
#include "cache.h"
#include "configuration.h"
// Get Cache Path
static std::string get_cache_path() {
const char *home = getenv(_MCPI_HOME_ENV);
if (home == nullptr) {
IMPOSSIBLE();
}
return std::string(home) + get_home_subdirectory_for_game_data() + "/.launcher-cache";
return home_get() + "/.launcher-cache";
}
// Load

View File

@ -3,7 +3,7 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include <libreborn/libreborn.h>
#include <libreborn/env.h>
#include "../util/util.h"
#include "configuration.h"

View File

@ -1,6 +1,8 @@
#include <fstream>
#include <libreborn/libreborn.h>
#include <libreborn/util.h>
#include <libreborn/config.h>
#include <libreborn/exec.h>
#include "logger.h"
#include "../ui/frame.h"

View File

@ -4,14 +4,15 @@
#include <cstdlib>
#include <cstdio>
#include <csignal>
#include <poll.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <ctime>
#include <string>
#include <fcntl.h>
#include <libreborn/libreborn.h>
#include <libreborn/exec.h>
#include <libreborn/log.h>
#include <libreborn/util.h>
#include "logger.h"
@ -26,7 +27,7 @@ static void exit_handler(__attribute__((unused)) int signal) {
static std::string log_filename;
static int log_fd;
std::string get_logs_folder() {
const std::string home = std::string(getenv(_MCPI_HOME_ENV)) + get_home_subdirectory_for_game_data();
const std::string home = home_get();
ensure_directory(home.c_str());
const std::string logs = home + "/logs";
ensure_directory(logs.c_str());
@ -34,8 +35,6 @@ std::string get_logs_folder() {
}
static void setup_log_file() {
// Get Log Directory
const std::string home = std::string(getenv(_MCPI_HOME_ENV)) + get_home_subdirectory_for_game_data();
ensure_directory(home.c_str());
const std::string logs = get_logs_folder();
// Get Timestamp

View File

@ -1,5 +1,7 @@
#include <cstdlib>
#include <libreborn/libreborn.h>
#include <libreborn/env.h>
#include <libreborn/util.h>
#include "bootstrap/bootstrap.h"
#include "options/parser.h"

View File

@ -1,5 +1,7 @@
#include <argp.h>
#include <libreborn/config.h>
#include <libreborn/env.h>
#include <trampoline/types.h>
#include "parser.h"

View File

@ -1,7 +1,5 @@
#pragma once
#include <libreborn/libreborn.h>
#define OPTION(name, ...) bool name;
struct options_t {
#include "option-list.h"

View File

@ -5,7 +5,9 @@
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl2.h>
#include <libreborn/libreborn.h>
#include <libreborn/log.h>
#include <libreborn/glfw.h>
#include <libreborn/util.h>
// Init/Cleanup
Frame::Frame(const char *title, const int width, const int height) {

View File

@ -1,6 +1,10 @@
#include <cstring>
#include "util.h"
#include <libreborn/libreborn.h>
#include <libreborn/env.h>
#include <libreborn/util.h>
#include <libreborn/config.h>
// $PATH
void setup_path() {

View File

@ -1,4 +1,6 @@
#include <libreborn/libreborn.h>
#include <libreborn/log.h>
#include <libreborn/util.h>
#include <libreborn/config.h>
#include "../bootstrap/bootstrap.h"
#include "util.h"
@ -14,12 +16,12 @@
}
// Copy SDK Into ~/.minecraft-pi
#define HOME_SUBDIRECTORY_FOR_SDK (std::string(get_home_subdirectory_for_game_data()) + "/sdk")
#define HOME_SUBDIRECTORY_FOR_SDK "/sdk"
void copy_sdk(const std::string &binary_directory, const bool log_with_debug) {
// Ensure SDK Directory
std::string sdk_path;
{
sdk_path = std::string(getenv(_MCPI_HOME_ENV)) + HOME_SUBDIRECTORY_FOR_SDK;
sdk_path = home_get() + HOME_SUBDIRECTORY_FOR_SDK;
const char *const command[] = {"mkdir", "-p", sdk_path.c_str(), nullptr};
run_simple_command(command, "Unable To Create SDK Directory");
}

View File

@ -1,4 +1,5 @@
#include <libreborn/libreborn.h>
#include <libreborn/log.h>
#include <libreborn/exec.h>
#include "util.h"

View File

@ -3,7 +3,6 @@
#cmakedefine MCPI_IS_APPIMAGE_BUILD
#cmakedefine MCPI_IS_FLATPAK_BUILD
#cmakedefine MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN
#cmakedefine MCPI_APP_BASE_TITLE "@MCPI_APP_BASE_TITLE@"
#cmakedefine MCPI_APP_TITLE "@MCPI_APP_TITLE@"
#cmakedefine MCPI_APP_ID "@MCPI_APP_ID@"
#cmakedefine MCPI_VERSION "@MCPI_VERSION@"

View File

@ -1,6 +1,6 @@
#pragma once
#include <string>
#include "log.h"
// Patching Functions
#ifdef REBORN_HAS_PATCH_CODE

View File

@ -1,10 +1,8 @@
#pragma once
#include <unistd.h>
#include <cstring>
#include <cerrno>
#include <dlfcn.h>
#include <array>
#include <string>
#include "log.h"
@ -80,3 +78,6 @@ void safe_write(int fd, const void *buf, size_t size);
#define EMBEDDED_RESOURCE(name) \
extern unsigned char name[]; \
extern size_t name##_len
// Profile Directory
std::string home_get();

View File

@ -122,4 +122,13 @@ void safe_write(const int fd, const void *buf, const size_t size) {
if (bytes_written < 0) {
ERR("Unable To Write Data: %s", strerror(errno));
}
}
// Get MCPI Home Directory
std::string home_get() {
const char *home = getenv(_MCPI_HOME_ENV);
if (home == nullptr) {
IMPOSSIBLE();
}
return std::string(home) + std::string(get_home_subdirectory_for_game_data());
}

View File

@ -33,6 +33,7 @@ add_library(mods SHARED
src/misc/graphics.cpp
src/misc/ui.cpp
src/misc/tinting.cpp
src/misc/home.cpp
# extend
src/extend/Screen.cpp
src/extend/DynamicTexture.cpp
@ -44,15 +45,11 @@ add_library(mods SHARED
src/bucket/bucket.cpp
# cake
src/cake/cake.cpp
# home
src/home/home.cpp
# touch
src/touch/touch.cpp
# text-input-box
src/text-input-box/TextInputBox.cpp
src/text-input-box/TextInputScreen.cpp
# test
src/test/test.cpp
# sound
src/sound/sound.cpp
src/sound/repository.cpp

View File

@ -1,5 +0,0 @@
#pragma once
extern "C" {
const char *home_get();
}

View File

@ -1,7 +1,6 @@
#pragma once
extern "C" {
void run_tests();
void init_version();
void init_compat();
void init_server();
@ -25,7 +24,6 @@ void init_options();
void init_chat();
void init_bucket();
void init_cake();
void init_home();
void init_override();
void init_screenshot();
void init_f3();

View File

@ -1,4 +0,0 @@
# `home` Mod
This utility mod handles changing the location where world data is stored. This is so it doesn't conflict with Minecraft: Java Edition.
Normally, it changes it to `~/.minecraft-pi`, but in server mode it changes it to the launch directory.

View File

@ -6,7 +6,6 @@
__attribute__((constructor)) static void init() {
reborn_init_patch();
thunk_enabler = reborn_thunk_enabler;
run_tests();
init_version();
init_compat();
if (reborn_is_server()) {
@ -38,7 +37,6 @@ __attribute__((constructor)) static void init() {
init_chat();
init_bucket();
init_cake();
init_home();
init_override();
if (!reborn_is_server()) {
init_benchmark();

View File

@ -6,3 +6,4 @@ This mod has several miscellaneous mods that are too small to be their own mod,
* Loading the bundled language file.
* Printing chat messages to the log.
* Implementing crafting remainders.
* Correct the profile directory.

View File

@ -1,19 +1,9 @@
#include <libreborn/libreborn.h>
#include <libreborn/patch.h>
#include <libreborn/env.h>
#include <libreborn/util.h>
#include <symbols/minecraft.h>
#include <mods/home/home.h>
#include <mods/init/init.h>
// Get MCPI Home Directory
const char *home_get() {
static std::string dir = "";
// Load
if (dir.empty()) {
dir = std::string(getenv(_MCPI_HOME_ENV)) + std::string(get_home_subdirectory_for_game_data());
}
// Return
return dir.c_str();
}
#include "misc-internal.h"
// Use MCPI_HOME
static const char *getenv_HOME(__attribute__((unused)) const char *env) {
@ -21,7 +11,7 @@ static const char *getenv_HOME(__attribute__((unused)) const char *env) {
}
// Init
void init_home() {
void _init_misc_home() {
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
patch_address(&Strings::default_path, (void *) get_home_subdirectory_for_game_data());
// Use MCPI_HOME Instead Of $HOME

View File

@ -5,6 +5,7 @@ __attribute__((visibility("internal"))) void _init_misc_api();
__attribute__((visibility("internal"))) void _init_misc_graphics();
__attribute__((visibility("internal"))) void _init_misc_ui();
__attribute__((visibility("internal"))) void _init_misc_tinting();
__attribute__((visibility("internal"))) void _init_misc_home();
template <typename... Args>
static void nop(__attribute__((unused)) Args... args) {

View File

@ -611,4 +611,5 @@ void init_misc() {
_init_misc_logging();
_init_misc_api();
_init_misc_graphics();
_init_misc_home();
}

View File

@ -6,7 +6,6 @@
#include <symbols/minecraft.h>
#include <libreborn/libreborn.h>
#include <mods/home/home.h>
#include <mods/init/init.h>
#include <mods/feature/feature.h>

View File

@ -2,7 +2,6 @@
#include <symbols/minecraft.h>
#include <GLES/gl.h>
#include <mods/home/home.h>
#include <mods/touch/touch.h>
#include <mods/misc/misc.h>
#include <mods/options/info.h>

View File

@ -8,7 +8,6 @@
#include <mods/feature/feature.h>
#include <mods/init/init.h>
#include <mods/home/home.h>
#include "options-internal.h"

View File

@ -7,7 +7,6 @@
#include <libreborn/libreborn.h>
#include <mods/override/override.h>
#include <mods/home/home.h>
#include <mods/init/init.h>
// Hook Functions

View File

@ -14,7 +14,6 @@
#include <symbols/minecraft.h>
#include <mods/screenshot/screenshot.h>
#include <mods/home/home.h>
#include <mods/misc/misc.h>
#include <mods/input/input.h>
#include <mods/init/init.h>

View File

@ -16,7 +16,6 @@
#include <mods/server/server.h>
#include <mods/init/init.h>
#include <mods/home/home.h>
#include <mods/compat/compat.h>
#include <mods/misc/misc.h>
#include <mods/game-mode/game-mode.h>

View File

@ -1,2 +0,0 @@
# `test` Mod
This utility mod tests that the system is configured correctly before starting.

View File

@ -1,21 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libreborn/libreborn.h>
#include <mods/home/home.h>
#include <mods/init/init.h>
void run_tests() {
// Test ~/.minecraft-pi Permissions
{
const char *path = home_get();
int exists = access(path, F_OK) == 0;
int can_write = exists ? access(path, R_OK | W_OK) == 0 : 1;
if (!can_write) {
// Failure
ERR("Invalid Data Directory Permissions");
}
}
}

View File

@ -3,7 +3,6 @@
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include <mods/home/home.h>
#include <mods/touch/touch.h>
#include <mods/options/info.h>
#include <mods/misc/misc.h>