2020-12-02 23:18:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-01-27 21:26:19 +00:00
|
|
|
#include <libreborn/libreborn.h>
|
2020-12-02 23:18:49 +00:00
|
|
|
|
|
|
|
#include "../feature/feature.h"
|
|
|
|
#include "../init/init.h"
|
|
|
|
|
2021-02-03 22:00:02 +00:00
|
|
|
#include <libreborn/minecraft.h>
|
2020-12-02 23:18:49 +00:00
|
|
|
|
|
|
|
static int mob_spawning = 0;
|
|
|
|
// Override Mob Spawning
|
|
|
|
static uint32_t LevelData_getSpawnMobs_injection(__attribute__((unused)) unsigned char *level_data) {
|
|
|
|
return mob_spawning;
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:32:24 +00:00
|
|
|
#ifndef MCPI_SERVER_MODE
|
2021-02-02 00:35:30 +00:00
|
|
|
// Get Custom Render Distance
|
|
|
|
static int get_render_distance() {
|
|
|
|
char *distance_str = getenv("MCPI_RENDER_DISTANCE");
|
|
|
|
if (distance_str == NULL) {
|
|
|
|
distance_str = "Short";
|
|
|
|
}
|
|
|
|
if (strcmp("Far", distance_str) == 0) {
|
|
|
|
return 0;
|
|
|
|
} else if (strcmp("Normal", distance_str) == 0) {
|
|
|
|
return 1;
|
|
|
|
} else if (strcmp("Short", distance_str) == 0) {
|
|
|
|
return 2;
|
|
|
|
} else if (strcmp("Tiny", distance_str) == 0) {
|
|
|
|
return 3;
|
|
|
|
} else {
|
|
|
|
ERR("Invalid Render Distance: %s", distance_str);
|
|
|
|
}
|
|
|
|
}
|
2021-06-17 21:32:24 +00:00
|
|
|
#endif // #ifndef MCPI_SERVER_MODE
|
|
|
|
|
2020-12-02 23:18:49 +00:00
|
|
|
// Get Custom Username
|
|
|
|
static char *get_username() {
|
|
|
|
char *username = getenv("MCPI_USERNAME");
|
|
|
|
if (username == NULL) {
|
|
|
|
username = "StevePi";
|
|
|
|
}
|
|
|
|
return username;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fancy_graphics;
|
|
|
|
static int peaceful_mode;
|
|
|
|
static int anaglyph;
|
|
|
|
static int smooth_lighting;
|
2021-02-02 00:35:30 +00:00
|
|
|
static int render_distance;
|
2020-12-02 23:18:49 +00:00
|
|
|
// Configure Options
|
|
|
|
static void Minecraft_init_injection(unsigned char *this) {
|
|
|
|
// Call Original Method
|
|
|
|
(*Minecraft_init)(this);
|
|
|
|
|
2020-12-18 03:22:56 +00:00
|
|
|
unsigned char *options = this + Minecraft_options_property_offset;
|
2020-12-02 23:18:49 +00:00
|
|
|
// Enable Fancy Graphics
|
2020-12-18 03:22:56 +00:00
|
|
|
*(options + Options_fancy_graphics_property_offset) = fancy_graphics;
|
2020-12-02 23:18:49 +00:00
|
|
|
// Enable Crosshair In Touch GUI
|
2020-12-18 03:22:56 +00:00
|
|
|
*(options + Options_split_controls_property_offset) = 1;
|
2020-12-02 23:18:49 +00:00
|
|
|
// Peaceful Mode
|
2020-12-18 03:22:56 +00:00
|
|
|
*(int32_t *) (options + Options_split_controls_property_offset) = peaceful_mode ? 0 : 2;
|
2020-12-02 23:18:49 +00:00
|
|
|
// 3D Anaglyph
|
2020-12-18 03:22:56 +00:00
|
|
|
*(options + Options_3d_anaglyph_property_offset) = anaglyph;
|
2020-12-02 23:18:49 +00:00
|
|
|
// Smooth Lighting
|
2020-12-18 03:22:56 +00:00
|
|
|
*(options + Options_ambient_occlusion_property_offset) = smooth_lighting;
|
2021-02-02 00:35:30 +00:00
|
|
|
// Render Distance
|
|
|
|
*(int32_t *) (options + Options_render_distance_property_offset) = render_distance;
|
2020-12-02 23:18:49 +00:00
|
|
|
}
|
|
|
|
|
2021-06-19 23:07:09 +00:00
|
|
|
// Init
|
2020-12-02 23:18:49 +00:00
|
|
|
void init_options() {
|
|
|
|
mob_spawning = feature_has("Mob Spawning");
|
|
|
|
// Set Mob Spawning
|
|
|
|
overwrite((void *) LevelData_getSpawnMobs, LevelData_getSpawnMobs_injection);
|
|
|
|
|
|
|
|
// Enable Fancy Graphics
|
|
|
|
fancy_graphics = feature_has("Fancy Graphics");
|
|
|
|
// Peaceful Mode
|
|
|
|
peaceful_mode = feature_has("Peaceful Mode");
|
|
|
|
// 3D Anaglyph
|
|
|
|
anaglyph = feature_has("3D Anaglyph");
|
2021-02-02 00:35:30 +00:00
|
|
|
// Render Distance
|
2021-06-17 21:32:24 +00:00
|
|
|
#ifndef MCPI_SERVER_MODE
|
|
|
|
render_distance = get_render_distance();
|
|
|
|
INFO("Setting Render Distance: %i", render_distance);
|
|
|
|
#else // #ifndef MCPI_SERVER_MODE
|
|
|
|
render_distance = 3;
|
|
|
|
#endif // #ifndef MCPI_SERVER_MODE
|
2020-12-02 23:18:49 +00:00
|
|
|
|
|
|
|
// Set Options
|
|
|
|
overwrite_calls((void *) Minecraft_init, Minecraft_init_injection);
|
|
|
|
|
|
|
|
// Change Username
|
|
|
|
const char *username = get_username();
|
2021-06-17 21:32:24 +00:00
|
|
|
#ifndef MCPI_SERVER_MODE
|
|
|
|
INFO("Setting Username: %s", username);
|
|
|
|
#endif // #ifndef MCPI_SERVER_MODE
|
2020-12-02 23:18:49 +00:00
|
|
|
if (strcmp(*default_username, "StevePi") != 0) {
|
|
|
|
ERR("%s", "Default Username Is Invalid");
|
|
|
|
}
|
|
|
|
patch_address((void *) default_username, (void *) username);
|
|
|
|
|
|
|
|
if (feature_has("Disable Autojump By Default")) {
|
|
|
|
// Disable Autojump By Default
|
2021-03-05 00:27:24 +00:00
|
|
|
unsigned char autojump_patch[4] = {0x00, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0"
|
2020-12-02 23:18:49 +00:00
|
|
|
patch((void *) 0x44b90, autojump_patch);
|
|
|
|
}
|
2021-02-04 01:58:43 +00:00
|
|
|
if (feature_has("Display Nametags By Default")) {
|
|
|
|
// Display Nametags By Default
|
2021-03-05 00:27:24 +00:00
|
|
|
unsigned char display_nametags_patch[4] = {0x1d, 0x60, 0xc0, 0xe5}; // "strb r6, [r0, #0x1d]"
|
2021-02-04 01:58:43 +00:00
|
|
|
patch((void *) 0xa6628, display_nametags_patch);
|
|
|
|
}
|
2020-12-02 23:18:49 +00:00
|
|
|
|
|
|
|
smooth_lighting = feature_has("Smooth Lighting");
|
|
|
|
if (smooth_lighting) {
|
|
|
|
// Enable Smooth Lighting
|
2021-03-05 00:27:24 +00:00
|
|
|
unsigned char smooth_lighting_patch[4] = {0x01, 0x00, 0x53, 0xe3}; // "cmp r3, #0x1"
|
2020-12-02 23:18:49 +00:00
|
|
|
patch((void *) 0x59ea4, smooth_lighting_patch);
|
|
|
|
}
|
2021-06-19 23:07:09 +00:00
|
|
|
}
|