minecraft-pi-reborn/mods/src/home/home.c

38 lines
975 B
C
Raw Normal View History

#include <errno.h>
2021-06-17 21:32:24 +00:00
#include <libreborn/libreborn.h>
2021-09-12 03:18:12 +00:00
#include <symbols/minecraft.h>
2021-06-17 21:32:24 +00:00
#include "home.h"
#include "../init/init.h"
// 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" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME"));
2021-06-28 20:00:52 +00:00
}
// 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 *) HOME_SUBDIRECTORY_FOR_GAME_DATA);
// Change Directory To Binary Directory Manually
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
patch((void *) 0xe0ac, nop_patch);
char *binary_directory = get_binary_directory();
if (chdir(binary_directory) != 0) {
ERR("Unable To Change Directory: %s", strerror(errno));
}
free(binary_directory);
2021-06-17 21:32:24 +00:00
}