35 lines
860 B
C++
Raw Normal View History

2024-04-02 19:22:01 -04:00
#include <cerrno>
2021-06-17 17:32:24 -04:00
#include <libreborn/libreborn.h>
2021-09-11 23:18:12 -04:00
#include <symbols/minecraft.h>
2021-06-17 17:32:24 -04:00
2022-06-25 17:30:08 -04:00
#include <mods/home/home.h>
#include <mods/init/init.h>
2021-06-17 17:32:24 -04:00
// Get MCPI Home Directory
char *home_get() {
2024-04-02 19:22:01 -04:00
static char *dir = nullptr;
2021-06-28 16:00:52 -04:00
// Load
2024-04-02 19:22:01 -04:00
if (dir == nullptr) {
safe_asprintf(&dir, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME"));
2021-06-28 16:00:52 -04:00
}
// Return
2021-06-17 17:32:24 -04:00
return dir;
}
2021-06-28 16:00:52 -04:00
// Free
__attribute__((destructor)) static void _free_home() {
free(home_get());
}
2021-06-17 17:32:24 -04:00
// Init
void init_home() {
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
2024-01-07 02:59:04 -05:00
patch_address((void *) Strings_default_path_pointer, (void *) HOME_SUBDIRECTORY_FOR_GAME_DATA);
2022-04-22 19:38:15 -04:00
// The override code resolves assets manually,
// making changing directory redundant.
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
patch((void *) 0xe0ac, nop_patch);
2021-06-17 17:32:24 -04:00
}
2024-05-15 05:02:19 -04:00