Compare commits

...

4 Commits

Author SHA1 Message Date
c0b5026221 Rename MineCon Badge Property
All checks were successful
minecraft-pi-docker/pipeline/head This commit looks good
2020-11-10 15:16:42 -05:00
054dcba425 Improve Error Reporting 2020-11-10 15:06:29 -05:00
dd539e434a Exit On GLFW Error 2020-11-10 12:46:42 -05:00
c21197324b Fix Sign Without Fix Bow & Arrow 2020-11-10 10:08:42 -05:00
7 changed files with 52 additions and 30 deletions

View File

@ -10,6 +10,9 @@ extern "C" {
#include <stdlib.h>
#include <dlfcn.h>
#define INFO(msg, ...) fprintf(stderr, "[INFO]: " msg "\n", __VA_ARGS__);
#define ERR(msg, ...) fprintf(stderr, "[ERR]: " msg "\n", __VA_ARGS__); exit(1);
#define HOOK(name, return_type, args) \
typedef return_type (*name##_t)args; \
static name##_t real_##name = NULL; \
@ -19,17 +22,13 @@ extern "C" {
dlerror(); \
real_##name = (name##_t) dlsym(RTLD_NEXT, #name); \
if (!real_##name) { \
fprintf(stderr, "Error Resolving Symbol: "#name": %s\n", dlerror()); \
exit(1); \
ERR("Error Resolving Symbol: "#name": %s", dlerror()); \
} \
} \
}; \
\
__attribute__((__used__)) return_type name args
#define INFO(msg, ...) fprintf(stderr, "[INFO]: " msg "\n", __VA_ARGS__);
#define ERR(msg, ...) fprintf(stderr, "[ERR]: " msg "\n", __VA_ARGS__); exit(1);
void _overwrite_calls(const char *file, int line, void *start, void *target);
#define overwrite_calls(start, target) _overwrite_calls(__FILE__, __LINE__, start, target);

View File

@ -190,8 +190,7 @@ HOOK(SDL_WM_SetCaption, void, (const char *title, __attribute__((unused)) const
glfwSetErrorCallback(glfw_error);
if (!glfwInit()) {
fprintf(stderr, "Unable To Initialize GLFW\n");
exit(1);
ERR("%s", "Unable To Initialize GLFW");
}
// Create OpenGL ES 1.1 Context
@ -202,8 +201,7 @@ HOOK(SDL_WM_SetCaption, void, (const char *title, __attribute__((unused)) const
glfw_window = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, title, NULL, NULL);
if (!glfw_window) {
fprintf(stderr, "Unable To Create GLFW Window\n");
exit(1);
ERR("%s", "Unable To Create GLFW Window");
}
// Don't Process Events In Server Mode

View File

@ -5,6 +5,7 @@
#include <sys/mman.h>
#include <stdint.h>
#include <elf.h>
#include <errno.h>
#include <libcore/libcore.h>
@ -75,18 +76,20 @@ struct overwrite_data {
int line;
void *target;
void *replacement;
int found;
};
static void overwrite_calls_callback(void *section, Elf32_Word size, void *data) {
struct overwrite_data args = *(struct overwrite_data *) data;
struct overwrite_data *args = (struct overwrite_data *) data;
for (uint32_t i = 0; i < size; i = i + 4) {
unsigned char *addr = ((unsigned char *) section) + i;
if (addr[3] == BL_INSTRUCTION) {
uint32_t check_instruction = generate_bl_instruction(addr, args.target);
uint32_t check_instruction = generate_bl_instruction(addr, args->target);
unsigned char *check_instruction_array = (unsigned char *) &check_instruction;
if (addr[0] == check_instruction_array[0] && addr[1] == check_instruction_array[1] && addr[2] == check_instruction_array[2]) {
uint32_t new_instruction = generate_bl_instruction(addr, args.replacement);
_patch(args.file, args.line, addr, (unsigned char *) &new_instruction);
uint32_t new_instruction = generate_bl_instruction(addr, args->replacement);
_patch(args->file, args->line, addr, (unsigned char *) &new_instruction);
args->found++;
}
}
}
@ -95,14 +98,22 @@ static void overwrite_calls_callback(void *section, Elf32_Word size, void *data)
// Limit To 512 overwrite_calls() Uses
#define CODE_BLOCK_SIZE 4096
static unsigned char *code_block = NULL;
#define CODE_SIZE 8
static int code_block_remaining = CODE_BLOCK_SIZE;
// Overwrite Function Calls
void _overwrite_calls(const char *file, int line, void *start, void *target) {
// BL Instructions Can Only Access A Limited Portion of Memory, So This Allocates Memory Closer To The Original Instruction, That When Run, Will Jump Into The Actual Target
if (code_block == NULL) {
code_block = mmap((void *) 0x200000, CODE_BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (code_block == MAP_FAILED) {
ERR("Unable To Allocate Code Block: %s", strerror(errno));
}
INFO("Code Block Allocated At: 0x%08x", (uint32_t) code_block);
}
if (code_block_remaining < CODE_SIZE) {
ERR("%s", "Maximum Amount Of overwrite_calls() Uses Reached");
}
_overwrite(NULL, -1, code_block, target);
struct overwrite_data data;
@ -110,9 +121,16 @@ void _overwrite_calls(const char *file, int line, void *start, void *target) {
data.line = line;
data.target = start;
data.replacement = code_block;
data.found = 0;
iterate_text_section(overwrite_calls_callback, &data);
code_block = code_block + 8;
code_block = code_block + CODE_SIZE;
code_block_remaining = code_block_remaining - CODE_SIZE;
if (data.found < 1) {
ERR("(%s:%i) Unable To Find Callsites For 0x%08x", file, line, (uint32_t) start);
}
}
// Overwrite Function

View File

@ -4,15 +4,17 @@
#include <string>
#include <libcore/libcore.h>
#include "cxx11_util.h"
// Convert A C-String into A C++11 String That Can be Acessed In C++03 Code
cxx11_string create_cxx11_string(const char *str) {
std::string *new_str = new std::string(str);
int32_t new_size = sizeof (cxx11_string);
int32_t old_size = sizeof *new_str;
int32_t old_size = sizeof (*new_str);
if (new_size != old_size) {
fprintf(stderr, "Mismatched String Size: Expected: %i Real: %i\n", new_size, old_size);
ERR("Mismatched String Size: Expected: %i Real: %i", new_size, old_size);
}
return *reinterpret_cast<cxx11_string *>(new_str);
}

View File

@ -24,13 +24,16 @@ static Minecraft_tickInput_t Minecraft_tickInput = (Minecraft_tickInput_t) 0x15f
typedef int (*Player_isUsingItem_t)(unsigned char *player);
static Player_isUsingItem_t Player_isUsingItem = (Player_isUsingItem_t) 0x8f15c;
// Enable Bow & Arrow Fix
static int fix_bow = 0;
static void Minecraft_tickInput_injection(unsigned char *minecraft) {
// Call Original Method
(*Minecraft_tickInput)(minecraft);
// GameMode Is Offset From minecraft By 0x160
// Player Is Offset From minecraft By 0x18c
if (!is_right_click) {
if (fix_bow && !is_right_click) {
// GameMode Is Offset From minecraft By 0x160
// Player Is Offset From minecraft By 0x18c
unsigned char *game_mode = *(unsigned char **) (minecraft + 0x160);
unsigned char *player = *(unsigned char **) (minecraft + 0x18c);
if (player != NULL && game_mode != NULL && (*Player_isUsingItem)(player)) {
@ -40,6 +43,7 @@ static void Minecraft_tickInput_injection(unsigned char *minecraft) {
}
}
// Clear Unused Sign Input
extra_clear_input();
}
@ -207,10 +211,10 @@ __attribute__((constructor)) static void init() {
// Disable Opening Inventory Using The Cursor When Cursor Is Hidden
overwrite_calls((void *) Gui_handleClick, Gui_handleClick_injection);
if (extra_has_feature("Fix Bow & Arrow")) {
// Fix Bow
overwrite_calls((void *) Minecraft_tickInput, Minecraft_tickInput_injection);
}
// Enable Bow & Arrow Fix
fix_bow = extra_has_feature("Fix Bow & Arrow");
// Fix Bow & Arrow + Clear Unused Sign Input
overwrite_calls((void *) Minecraft_tickInput, Minecraft_tickInput_injection);
if (extra_has_feature("Fix Attacking")) {
// Allow Attacking Mobs

View File

@ -149,7 +149,8 @@ extern "C" {
patch_address((void *) 0x10531c, (void *) Screen_updateEvents_injection);
}
if (extra_has_feature("Expand Creative Inventory")) {
int is_server = extra_get_mode() == 2;
if (!is_server && extra_has_feature("Expand Creative Inventory")) {
// Add Extra Items To Creative Inventory
overwrite_calls((void *) FillingContainer_addItem, (void *) FillingContainer_addItem_injection);
}

View File

@ -27,7 +27,7 @@ static ServerProperties &get_server_properties() {
// Default Server Properties
#define DEFAULT_MOTD "Minecraft Server"
#define DEFAULT_SHOW_MINECON_ICON "false"
#define DEFAULT_SHOW_MINECON_BADGE "false"
#define DEFAULT_GAME_MODE "0"
#define DEFAULT_PORT "19132"
#define DEFAULT_SEED ""
@ -464,8 +464,8 @@ void server_init() {
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 Icon Next To MOTD In Server List\n";
properties_file_output << "show-minecon-icon=" DEFAULT_SHOW_MINECON_ICON "\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 << "# Game Mode (0 = Survival, 1 = Creative)\n";
properties_file_output << "game-mode=" DEFAULT_GAME_MODE "\n";
properties_file_output << "# Port\n";
@ -528,10 +528,10 @@ void server_init() {
// Load Player Data
playerdata_init();
if (get_server_properties().get_bool("show-minecon-icon", DEFAULT_SHOW_MINECON_ICON)) {
if (get_server_properties().get_bool("show-minecon-badge", DEFAULT_SHOW_MINECON_BADGE)) {
// Show The MineCon Icon Next To MOTD In Server List
unsigned char minecon_icon_patch[4] = {0x04, 0x1a, 0x9f, 0xe5};
patch((void *) 0x737e4, minecon_icon_patch);
unsigned char minecon_badge_patch[4] = {0x04, 0x1a, 0x9f, 0xe5};
patch((void *) 0x737e4, minecon_badge_patch);
}
// Start Reading STDIN