Split Up Options Mod
This commit is contained in:
parent
4523935d62
commit
09bae1cf3e
@ -31,6 +31,7 @@ set(SRC
|
||||
src/misc/api.cpp
|
||||
# options
|
||||
src/options/options.cpp
|
||||
src/options/ui.cpp
|
||||
# bucket
|
||||
src/bucket/bucket.cpp
|
||||
# cake
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
|
||||
// Message Limitations
|
||||
#define MAX_CHAT_MESSAGE_LENGTH 256
|
||||
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__attribute__((visibility("internal"))) void _init_game_mode_ui();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,16 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__attribute__((visibility("internal"))) void _init_attack();
|
||||
__attribute__((visibility("internal"))) void _init_bow();
|
||||
__attribute__((visibility("internal"))) void _init_misc();
|
||||
__attribute__((visibility("internal"))) void _init_toggle();
|
||||
__attribute__((visibility("internal"))) void _init_drop();
|
||||
__attribute__((visibility("internal"))) void _init_crafting();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,12 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__attribute__((visibility("internal"))) void _init_misc_logging();
|
||||
__attribute__((visibility("internal"))) void _init_misc_api();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
4
mods/src/options/options-internal.h
Normal file
4
mods/src/options/options-internal.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
__attribute__((visibility("internal"))) void _init_options_ui();
|
||||
__attribute__((visibility("internal"))) extern Options *stored_options;
|
@ -10,6 +10,8 @@
|
||||
#include <mods/init/init.h>
|
||||
#include <mods/home/home.h>
|
||||
|
||||
#include "options-internal.h"
|
||||
|
||||
// Force Mob Spawning
|
||||
static bool LevelData_getSpawnMobs_injection(__attribute__((unused)) LevelData *level_data) {
|
||||
return true;
|
||||
@ -49,7 +51,7 @@ __attribute__((destructor)) static void _free_safe_username() {
|
||||
|
||||
static int render_distance;
|
||||
// Configure Options
|
||||
static Options *stored_options = nullptr;
|
||||
Options *stored_options = nullptr;
|
||||
static void Options_initDefaultValue_injection(Options_initDefaultValue_t original, Options *options) {
|
||||
// Call Original Method
|
||||
original(options);
|
||||
@ -83,19 +85,6 @@ static bool TileRenderer_tesselateBlockInWorld_injection(TileRenderer_tesselateB
|
||||
return original(tile_renderer, tile, x, y, z);
|
||||
}
|
||||
|
||||
// Fix Initial Option Button Rendering
|
||||
// The calling function doesn't exist in MCPE v0.6.1, so its name is unknown.
|
||||
static OptionButton *OptionsPane_unknown_toggle_creating_function_OptionButton_injection(OptionButton *option_button, Options_Option *option) {
|
||||
// Call Original Method
|
||||
OptionButton *ret = OptionButton_constructor(option_button, option);
|
||||
|
||||
// Setup Image
|
||||
OptionButton_updateImage(option_button, stored_options);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Actually Save options.txt
|
||||
// Hook Last Options::addOptionToSaveOutput Call
|
||||
static void Options_save_Options_addOptionToSaveOutput_injection(Options *options, std::vector<std::string> *data, std::string option, int32_t value) {
|
||||
@ -165,75 +154,6 @@ static char *get_new_options_txt_path() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Modify Option Toggles
|
||||
static void OptionsPane_unknown_toggle_creating_function_injection(OptionsPane_unknown_toggle_creating_function_t original, OptionsPane *options_pane, uint32_t group_id, std::string *name_ptr, Options_Option *option) {
|
||||
// Modify
|
||||
std::string name = *name_ptr;
|
||||
std::string new_name = name;
|
||||
if (name == "Fancy Graphics") {
|
||||
option = &Options_Option_GRAPHICS;
|
||||
} else if (name == "Soft shadows") {
|
||||
option = &Options_Option_AMBIENT_OCCLUSION;
|
||||
} else if (name == "Fancy Skies" || name == "Animated water") {
|
||||
// These have no corresponding option, so disable the toggle.
|
||||
return;
|
||||
} else if (name == "Third person camera") {
|
||||
// This isn't saved/loaded, so disable the toggle.
|
||||
return;
|
||||
} else if (name == "Lefty" || name == "Use touch screen" || name == "Split touch controls") {
|
||||
// These toggles require touch support, so disable them.
|
||||
return;
|
||||
} else if (name == "Vibrate on destroy") {
|
||||
// This toggle requires vibration support, so disable it.
|
||||
return;
|
||||
} else if (name == "Invert X-axis") {
|
||||
// Fix Incorrect Name
|
||||
new_name = "Invert Y-axis";
|
||||
}
|
||||
|
||||
// Call Original Method
|
||||
original(options_pane, group_id, &new_name, option);
|
||||
|
||||
// Add 3D Anaglyph
|
||||
if (option == &Options_Option_GRAPHICS) {
|
||||
std::string cpp_string = "3D Anaglyph";
|
||||
original(options_pane, group_id, &cpp_string, &Options_Option_ANAGLYPH);
|
||||
}
|
||||
|
||||
// Add Peaceful Mode
|
||||
if (option == &Options_Option_SERVER_VISIBLE) {
|
||||
std::string cpp_string = "Peaceful mode";
|
||||
original(options_pane, group_id, &cpp_string, &Options_Option_DIFFICULTY);
|
||||
}
|
||||
}
|
||||
|
||||
// Add Missing Options To Options::getBooleanValue
|
||||
static bool Options_getBooleanValue_injection(Options_getBooleanValue_t original, Options *options, Options_Option *option) {
|
||||
// Check
|
||||
if (option == &Options_Option_GRAPHICS) {
|
||||
return options->fancy_graphics;
|
||||
} else if (option == &Options_Option_DIFFICULTY) {
|
||||
return options->game_difficulty == 0;
|
||||
} else {
|
||||
// Call Original Method
|
||||
return original(options, option);
|
||||
}
|
||||
}
|
||||
|
||||
// Fix Difficulty When Toggling
|
||||
static void OptionButton_toggle_Options_save_injection(Options *self) {
|
||||
// Fix Value
|
||||
if (self->game_difficulty == 1) {
|
||||
// Disable Peaceful
|
||||
self->game_difficulty = 2;
|
||||
} else if (self->game_difficulty == 3) {
|
||||
// Switch To Peaceful
|
||||
self->game_difficulty = 0;
|
||||
}
|
||||
// Call Original Method
|
||||
Options_save(self);
|
||||
}
|
||||
|
||||
// Init
|
||||
void init_options() {
|
||||
// Force Mob Spawning
|
||||
@ -277,30 +197,6 @@ void init_options() {
|
||||
// NOP
|
||||
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
||||
|
||||
// Fix Options Screen
|
||||
if (feature_has("Fix Options Screen", server_disabled)) {
|
||||
// Fix Initial Option Button Rendering
|
||||
overwrite_call((void *) 0x24510, (void *) OptionsPane_unknown_toggle_creating_function_OptionButton_injection);
|
||||
|
||||
// "Gui Scale" slider is broken, so disable it.
|
||||
patch((void *) 0x35a10, nop_patch);
|
||||
// "Vibrate on destroy" is disabled, so "Feedback" is empty, so disable it.
|
||||
patch((void *) 0x35960, nop_patch);
|
||||
|
||||
// Disconnect "This works?" Slider From Difficulty
|
||||
unsigned char this_works_slider_patch[4] = {0x00, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0"
|
||||
patch((void *) 0x3577c, this_works_slider_patch);
|
||||
|
||||
// Modify Option Toggles
|
||||
overwrite_calls(OptionsPane_unknown_toggle_creating_function, OptionsPane_unknown_toggle_creating_function_injection);
|
||||
|
||||
// Add Missing Options To Options::getBooleanValue
|
||||
overwrite_calls(Options_getBooleanValue, Options_getBooleanValue_injection);
|
||||
|
||||
// Fix Difficulty When Toggling
|
||||
overwrite_call((void *) 0x1cd00, (void *) OptionButton_toggle_Options_save_injection);
|
||||
}
|
||||
|
||||
// Actually Save options.txt
|
||||
overwrite_call((void *) 0x197fc, (void *) Options_save_Options_addOptionToSaveOutput_injection);
|
||||
// Fix options.txt Path
|
||||
@ -347,4 +243,7 @@ void init_options() {
|
||||
patch((void *) 0x19414, nop_patch);
|
||||
patch((void *) 0x1941c, nop_patch);
|
||||
}
|
||||
|
||||
// UI
|
||||
_init_options_ui();
|
||||
}
|
||||
|
118
mods/src/options/ui.cpp
Normal file
118
mods/src/options/ui.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
#include <string>
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
#include <symbols/minecraft.h>
|
||||
|
||||
#include <mods/feature/feature.h>
|
||||
|
||||
#include "options-internal.h"
|
||||
|
||||
// Fix Initial Option Button Rendering
|
||||
// The calling function doesn't exist in MCPE v0.6.1, so its name is unknown.
|
||||
static OptionButton *OptionsPane_unknown_toggle_creating_function_OptionButton_injection(OptionButton *option_button, Options_Option *option) {
|
||||
// Call Original Method
|
||||
OptionButton *ret = OptionButton_constructor(option_button, option);
|
||||
|
||||
// Setup Image
|
||||
OptionButton_updateImage(option_button, stored_options);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Modify Option Toggles
|
||||
static void OptionsPane_unknown_toggle_creating_function_injection(OptionsPane_unknown_toggle_creating_function_t original, OptionsPane *options_pane, uint32_t group_id, std::string *name_ptr, Options_Option *option) {
|
||||
// Modify
|
||||
std::string name = *name_ptr;
|
||||
std::string new_name = name;
|
||||
if (name == "Fancy Graphics") {
|
||||
option = &Options_Option_GRAPHICS;
|
||||
} else if (name == "Soft shadows") {
|
||||
option = &Options_Option_AMBIENT_OCCLUSION;
|
||||
} else if (name == "Fancy Skies" || name == "Animated water") {
|
||||
// These have no corresponding option, so disable the toggle.
|
||||
return;
|
||||
} else if (name == "Third person camera") {
|
||||
// This isn't saved/loaded, so disable the toggle.
|
||||
return;
|
||||
} else if (name == "Lefty" || name == "Use touch screen" || name == "Split touch controls") {
|
||||
// These toggles require touch support, so disable them.
|
||||
return;
|
||||
} else if (name == "Vibrate on destroy") {
|
||||
// This toggle requires vibration support, so disable it.
|
||||
return;
|
||||
} else if (name == "Invert X-axis") {
|
||||
// Fix Incorrect Name
|
||||
new_name = "Invert Y-axis";
|
||||
}
|
||||
|
||||
// Call Original Method
|
||||
original(options_pane, group_id, &new_name, option);
|
||||
|
||||
// Add 3D Anaglyph
|
||||
if (option == &Options_Option_GRAPHICS) {
|
||||
std::string cpp_string = "3D Anaglyph";
|
||||
original(options_pane, group_id, &cpp_string, &Options_Option_ANAGLYPH);
|
||||
}
|
||||
|
||||
// Add Peaceful Mode
|
||||
if (option == &Options_Option_SERVER_VISIBLE) {
|
||||
std::string cpp_string = "Peaceful mode";
|
||||
original(options_pane, group_id, &cpp_string, &Options_Option_DIFFICULTY);
|
||||
}
|
||||
}
|
||||
|
||||
// Add Missing Options To Options::getBooleanValue
|
||||
static bool Options_getBooleanValue_injection(Options_getBooleanValue_t original, Options *options, Options_Option *option) {
|
||||
// Check
|
||||
if (option == &Options_Option_GRAPHICS) {
|
||||
return options->fancy_graphics;
|
||||
} else if (option == &Options_Option_DIFFICULTY) {
|
||||
return options->game_difficulty == 0;
|
||||
} else {
|
||||
// Call Original Method
|
||||
return original(options, option);
|
||||
}
|
||||
}
|
||||
|
||||
// Fix Difficulty When Toggling
|
||||
static void OptionButton_toggle_Options_save_injection(Options *self) {
|
||||
// Fix Value
|
||||
if (self->game_difficulty == 1) {
|
||||
// Disable Peaceful
|
||||
self->game_difficulty = 2;
|
||||
} else if (self->game_difficulty == 3) {
|
||||
// Switch To Peaceful
|
||||
self->game_difficulty = 0;
|
||||
}
|
||||
// Call Original Method
|
||||
Options_save(self);
|
||||
}
|
||||
|
||||
// Init
|
||||
void _init_options_ui() {
|
||||
// Fix Options Screen
|
||||
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
||||
if (feature_has("Fix Options Screen", server_disabled)) {
|
||||
// Fix Initial Option Button Rendering
|
||||
overwrite_call((void *) 0x24510, (void *) OptionsPane_unknown_toggle_creating_function_OptionButton_injection);
|
||||
|
||||
// "Gui Scale" slider is broken, so disable it.
|
||||
patch((void *) 0x35a10, nop_patch);
|
||||
// "Vibrate on destroy" is disabled, so "Feedback" is empty, so disable it.
|
||||
patch((void *) 0x35960, nop_patch);
|
||||
|
||||
// Disconnect "This works?" Slider From Difficulty
|
||||
unsigned char this_works_slider_patch[4] = {0x00, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0"
|
||||
patch((void *) 0x3577c, this_works_slider_patch);
|
||||
|
||||
// Modify Option Toggles
|
||||
overwrite_calls(OptionsPane_unknown_toggle_creating_function, OptionsPane_unknown_toggle_creating_function_injection);
|
||||
|
||||
// Add Missing Options To Options::getBooleanValue
|
||||
overwrite_calls(Options_getBooleanValue, Options_getBooleanValue_injection);
|
||||
|
||||
// Fix Difficulty When Toggling
|
||||
overwrite_call((void *) 0x1cd00, (void *) OptionButton_toggle_Options_save_injection);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user