2021-06-17 21:32:24 +00:00
|
|
|
#include <libreborn/libreborn.h>
|
|
|
|
#include <libreborn/minecraft.h>
|
|
|
|
|
|
|
|
#include "home.h"
|
|
|
|
#include "../init/init.h"
|
|
|
|
|
|
|
|
// Minecraft Pi User Data Root
|
|
|
|
#ifndef MCPI_SERVER_MODE
|
|
|
|
// Store Game Data In "~/.minecraft-pi" Instead Of "~/.minecraft" To Avoid Conflicts
|
|
|
|
#define NEW_PATH "/.minecraft-pi"
|
|
|
|
#else
|
|
|
|
// Store Game Data In Launch Directory
|
|
|
|
#define NEW_PATH ""
|
|
|
|
|
2021-06-28 02:16:37 +00:00
|
|
|
// Store Launch Directory
|
2021-06-17 21:32:24 +00:00
|
|
|
static char *launch_directory = NULL;
|
|
|
|
__attribute__((constructor)) static void init_launch_directory() {
|
|
|
|
launch_directory = getcwd(NULL, 0);
|
|
|
|
}
|
|
|
|
|
2021-06-28 02:16:37 +00:00
|
|
|
// Pretend $HOME Is Launch Directory
|
2021-06-17 21:32:24 +00:00
|
|
|
HOOK(getenv, char *, (const char *name)) {
|
|
|
|
if (strcmp(name, "HOME") == 0) {
|
|
|
|
return launch_directory;
|
|
|
|
} else {
|
|
|
|
ensure_getenv();
|
|
|
|
return (*real_getenv)(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Get MCPI Home Directory
|
|
|
|
char *home_get() {
|
2021-06-28 20:00:52 +00:00
|
|
|
static char *dir = NULL;
|
|
|
|
// Load
|
|
|
|
if (dir == NULL) {
|
|
|
|
safe_asprintf(&dir, "%s/" NEW_PATH, getenv("HOME"));
|
|
|
|
}
|
|
|
|
// Return
|
2021-06-17 21:32:24 +00:00
|
|
|
return dir;
|
|
|
|
}
|
2021-06-28 20:00:52 +00:00
|
|
|
// Free
|
|
|
|
__attribute__((destructor)) static void _free_home() {
|
|
|
|
free(home_get());
|
|
|
|
}
|
2021-06-17 21:32:24 +00:00
|
|
|
|
|
|
|
// Init
|
|
|
|
void init_home() {
|
|
|
|
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
|
|
|
|
patch_address((void *) default_path, (void *) NEW_PATH);
|
|
|
|
}
|