minecraft-pi-reborn/mods/src/home/home.cpp
TheBrokenRail 97bc124d72
All checks were successful
CI / Build (AMD64, Server) (push) Successful in 14m16s
CI / Build (AMD64, Client) (push) Successful in 14m37s
CI / Build (ARM64, Server) (push) Successful in 13m0s
CI / Build (ARM64, Client) (push) Successful in 15m26s
CI / Build (ARMHF, Server) (push) Successful in 8m58s
CI / Build (ARMHF, Client) (push) Successful in 11m38s
CI / Test (Server) (push) Successful in 14m12s
CI / Test (Client) (push) Successful in 16m37s
CI / Release (push) Has been skipped
CI / Build Example Mods (push) Successful in 7m50s
Better Static Properties
2024-05-17 02:52:55 -04:00

34 lines
853 B
C++

#include <cerrno>
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include <mods/home/home.h>
#include <mods/init/init.h>
// Get MCPI Home Directory
char *home_get() {
static char *dir = nullptr;
// Load
if (dir == nullptr) {
safe_asprintf(&dir, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME"));
}
// Return
return dir;
}
// Free
__attribute__((destructor)) static void _free_home() {
free(home_get());
}
// Init
void init_home() {
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
patch_address((void *) &Strings::default_path, (void *) HOME_SUBDIRECTORY_FOR_GAME_DATA);
// 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);
}