Revert Earlier Username Decision

This commit is contained in:
TheBrokenRail 2022-04-12 20:38:44 -04:00
parent a3eef9fc3b
commit 50eb4801a0
4 changed files with 43 additions and 8 deletions

View File

@ -216,6 +216,17 @@ int main(int argc, char *argv[]) {
// Run // Run
run_zenity_and_set_env("MCPI_RENDER_DISTANCE", command); run_zenity_and_set_env("MCPI_RENDER_DISTANCE", command);
} }
// Setup MCPI_USERNAME
{
std::vector<std::string> command;
command.push_back("--entry");
command.push_back("--text");
command.push_back("Minecraft Username:");
command.push_back("--entry-text");
command.push_back("StevePi");
// Run
run_zenity_and_set_env("MCPI_USERNAME", command);
}
// Bootstrap // Bootstrap
bootstrap(argc, argv); bootstrap(argc, argv);

View File

@ -33,6 +33,15 @@ static int get_render_distance() {
} }
#endif #endif
// Get Custom Username
static char *get_username() {
char *username = getenv("MCPI_USERNAME");
if (username == NULL) {
username = "StevePi";
}
return username;
}
static int anaglyph; static int anaglyph;
static int render_distance; static int render_distance;
// Configure Options // Configure Options
@ -85,6 +94,16 @@ void init_options() {
// Set Options // Set Options
overwrite_calls((void *) Options_initDefaultValue, (void *) Options_initDefaultValue_injection); overwrite_calls((void *) Options_initDefaultValue, (void *) Options_initDefaultValue_injection);
// Change Username
const char *username = get_username();
#ifndef MCPI_SERVER_MODE
INFO("Setting Username: %s", username);
#endif
if (strcmp(*default_username, "StevePi") != 0) {
ERR("%s", "Default Username Is Invalid");
}
patch_address((void *) default_username, (void *) username);
// Disable Autojump By Default // Disable Autojump By Default
if (feature_has("Disable Autojump By Default", server_disabled)) { if (feature_has("Disable Autojump By Default", server_disabled)) {
unsigned char autojump_patch[4] = {0x00, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0" unsigned char autojump_patch[4] = {0x00, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0"

View File

@ -33,14 +33,6 @@ static void Options_save_Options_addOptionToSaveOutput_injection(unsigned char *
// Save Fancy Graphics // Save Fancy Graphics
(*Options_addOptionToSaveOutput)(options, data, "gfx_fancygraphics", *(options + Options_fancy_graphics_property_offset)); (*Options_addOptionToSaveOutput)(options, data, "gfx_fancygraphics", *(options + Options_fancy_graphics_property_offset));
// Save Username
{
std::string entry = "mp_username:";
std::string username = *(std::string *) (options + Options_username_property_offset);
entry += username;
data.push_back(entry);
}
// Save File // Save File
unsigned char *options_file = options + Options_options_file_property_offset; unsigned char *options_file = options + Options_options_file_property_offset;
(*OptionsFile_save)(options_file, data); (*OptionsFile_save)(options_file, data);
@ -204,6 +196,9 @@ void _init_options_cpp() {
patch((void *) 0x19378, cmp_r0_r0_patch); patch((void *) 0x19378, cmp_r0_r0_patch);
patch((void *) 0x197cc, nop_patch); patch((void *) 0x197cc, nop_patch);
// Custom Username Is Loaded Manually, Disable Loading From options.txt
patch((void *) 0x192ac, nop_patch);
// Replace "feedback_vibration" Loading/Saving With "gfx_ao" // Replace "feedback_vibration" Loading/Saving With "gfx_ao"
{ {
// Replace String // Replace String

View File

@ -48,6 +48,7 @@ static ServerProperties &get_server_properties() {
} }
// Default Server Properties // Default Server Properties
#define DEFAULT_MOTD "Minecraft Server"
#define DEFAULT_SHOW_MINECON_BADGE "false" #define DEFAULT_SHOW_MINECON_BADGE "false"
#define DEFAULT_GAME_MODE "0" #define DEFAULT_GAME_MODE "0"
#define DEFAULT_PORT "19132" #define DEFAULT_PORT "19132"
@ -402,6 +403,12 @@ static unsigned char *ServerSideNetworkHandler_onReady_ClientGeneration_ServerSi
return player; return player;
} }
// Get MOTD
static std::string get_motd() {
std::string motd(get_server_properties().get_string("motd", DEFAULT_MOTD));
return motd;
}
// Get Feature Flags // Get Feature Flags
static bool loaded_features = false; static bool loaded_features = false;
static const char *get_features() { static const char *get_features() {
@ -442,6 +449,8 @@ static void server_init() {
if (!properties_file.good()) { if (!properties_file.good()) {
// Write Defaults // Write Defaults
std::ofstream properties_file_output(file); std::ofstream properties_file_output(file);
properties_file_output << "# Message Of The Day\n";
properties_file_output << "motd=" DEFAULT_MOTD "\n";
properties_file_output << "# Show The MineCon Badge Next To MOTD In Server List\n"; properties_file_output << "# Show The MineCon Badge Next To MOTD In Server List\n";
properties_file_output << "show-minecon-badge=" DEFAULT_SHOW_MINECON_BADGE "\n"; properties_file_output << "show-minecon-badge=" DEFAULT_SHOW_MINECON_BADGE "\n";
properties_file_output << "# Game Mode (0 = Survival, 1 = Creative)\n"; properties_file_output << "# Game Mode (0 = Survival, 1 = Creative)\n";
@ -516,4 +525,5 @@ static void server_init() {
void init_server() { void init_server() {
server_init(); server_init();
setenv("MCPI_FEATURE_FLAGS", get_features(), 1); setenv("MCPI_FEATURE_FLAGS", get_features(), 1);
setenv("MCPI_USERNAME", get_motd().c_str(), 1);
} }