103 lines
3.1 KiB
C
103 lines
3.1 KiB
C
#include <string.h>
|
|
|
|
#include <libreborn/libreborn.h>
|
|
#include <symbols/minecraft.h>
|
|
|
|
#include "../feature/feature.h"
|
|
#include "../init/init.h"
|
|
#include "options.h"
|
|
|
|
// Force Mob Spawning
|
|
static bool LevelData_getSpawnMobs_injection(__attribute__((unused)) unsigned char *level_data) {
|
|
return 1;
|
|
}
|
|
|
|
#ifndef MCPI_SERVER_MODE
|
|
// 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);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
static int anaglyph;
|
|
static int render_distance;
|
|
// Configure Options
|
|
unsigned char *stored_options = NULL;
|
|
static void Options_initDefaultValue_injection(unsigned char *options) {
|
|
// Call Original Method
|
|
(*Options_initDefaultValue)(options);
|
|
|
|
// Enable Crosshair In Touch GUI
|
|
*(options + Options_split_controls_property_offset) = 1;
|
|
// 3D Anaglyph
|
|
*(options + Options_3d_anaglyph_property_offset) = anaglyph;
|
|
// Render Distance
|
|
*(int32_t *) (options + Options_render_distance_property_offset) = render_distance;
|
|
|
|
// Store
|
|
stored_options = options;
|
|
}
|
|
|
|
// Smooth Lighting
|
|
static void TileRenderer_tesselateBlockInWorld_injection(unsigned char *tile_renderer, unsigned char *tile, int32_t x, int32_t y, int32_t z) {
|
|
// Set Variable
|
|
*Minecraft_useAmbientOcclusion = *(stored_options + Options_ambient_occlusion_property_offset);
|
|
|
|
// Call Original Method
|
|
(*TileRenderer_tesselateBlockInWorld)(tile_renderer, tile, x, y, z);
|
|
}
|
|
|
|
// Init
|
|
void init_options() {
|
|
// Force Mob Spawning
|
|
if (feature_has("Force Mob Spawning", server_auto)) {
|
|
overwrite((void *) LevelData_getSpawnMobs, (void *) LevelData_getSpawnMobs_injection);
|
|
}
|
|
|
|
// 3D Anaglyph
|
|
anaglyph = feature_has("3D Anaglyph", server_disabled);
|
|
// Render Distance
|
|
#ifndef MCPI_SERVER_MODE
|
|
render_distance = get_render_distance();
|
|
INFO("Setting Render Distance: %i", render_distance);
|
|
#else
|
|
render_distance = 3;
|
|
#endif
|
|
|
|
// Set Options
|
|
overwrite_calls((void *) Options_initDefaultValue, (void *) Options_initDefaultValue_injection);
|
|
|
|
// Disable Autojump By Default
|
|
if (feature_has("Disable Autojump By Default", server_disabled)) {
|
|
unsigned char autojump_patch[4] = {0x00, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0"
|
|
patch((void *) 0x44b90, autojump_patch);
|
|
}
|
|
// Display Nametags By Default
|
|
if (feature_has("Display Nametags By Default", server_disabled)) {
|
|
// r6 = 0x1
|
|
// r5 = 0x0
|
|
unsigned char display_nametags_patch[4] = {0x1d, 0x60, 0xc0, 0xe5}; // "strb r6, [r0, #0x1d]"
|
|
patch((void *) 0xa6628, display_nametags_patch);
|
|
}
|
|
|
|
// Smooth Lighting
|
|
overwrite_calls((void *) TileRenderer_tesselateBlockInWorld, (void *) TileRenderer_tesselateBlockInWorld_injection);
|
|
|
|
// Init C++
|
|
_init_options_cpp();
|
|
}
|