diff --git a/dependencies/symbol-processor/src b/dependencies/symbol-processor/src index 67c4adaa77..6ee26aad80 160000 --- a/dependencies/symbol-processor/src +++ b/dependencies/symbol-processor/src @@ -1 +1 @@ -Subproject commit 67c4adaa772445f919f37131d7605bd374c67845 +Subproject commit 6ee26aad80aa697fc332a51b38cf1c2e8d4513ed diff --git a/example-mods/chat-commands/chat-commands.cpp b/example-mods/chat-commands/chat-commands.cpp index 087a774be7..ce6eba3613 100644 --- a/example-mods/chat-commands/chat-commands.cpp +++ b/example-mods/chat-commands/chat-commands.cpp @@ -5,7 +5,7 @@ #include // The Actual Mod -HOOK(chat_handle_packet_send, void, (Minecraft *minecraft, ChatPacket *packet)) { +HOOK(_Z23chat_handle_packet_sendP9MinecraftP10ChatPacket, void, (Minecraft *minecraft, ChatPacket *packet)) { // Get Message const char *message = packet->message.c_str(); if (message[0] == '/') { @@ -15,10 +15,10 @@ HOOK(chat_handle_packet_send, void, (Minecraft *minecraft, ChatPacket *packet)) if (out.length() > 0 && out[out.length() - 1] == '\n') { out[out.length() - 1] = '\0'; } - misc_add_message(gui, out.c_str()); + gui->addMessage(&out); } else { // Call Original Method - ensure_chat_handle_packet_send(); - real_chat_handle_packet_send(minecraft, packet); + ensure__Z23chat_handle_packet_sendP9MinecraftP10ChatPacket(); + real__Z23chat_handle_packet_sendP9MinecraftP10ChatPacket(minecraft, packet); } } diff --git a/launcher/src/client/cache.cpp b/launcher/src/client/cache.cpp index afb08230bd..52b156e9f5 100644 --- a/launcher/src/client/cache.cpp +++ b/launcher/src/client/cache.cpp @@ -14,7 +14,7 @@ // Get Cache Path static std::string get_cache_path() { const char *home = getenv("HOME"); - if (home == NULL) { + if (home == nullptr) { IMPOSSIBLE(); } return std::string(home) + HOME_SUBDIRECTORY_FOR_GAME_DATA "/.launcher-cache"; diff --git a/libreborn/include/libreborn/patch.h b/libreborn/include/libreborn/patch.h index 63e617c9b0..9600011f25 100644 --- a/libreborn/include/libreborn/patch.h +++ b/libreborn/include/libreborn/patch.h @@ -10,55 +10,72 @@ extern "C" { void reborn_init_patch(); +// Replace Call Located At start With A Call To target void _overwrite_call(const char *file, int line, void *start, void *target); #define overwrite_call(start, target) _overwrite_call(__FILE__, __LINE__, start, target) -#define _setup_fancy_overwrite(start, name, target) \ - if (!_is_new_method_##name()) { \ - ERR("Method Is Not \"New\""); \ - } \ - static name##_t _original_for_##target = start; \ - static name##_t _helper_for_##target = _overwrite_helper_for_##name(target, _original_for_##target) - -#define _update_references(from, to) \ +#define _check_if_method_is_new(name) \ { \ - void *old_reference = (void *) from; \ - for (int i = 0; _all_method_symbols[i] != nullptr; i++) { \ - if (_all_method_symbols[i] == old_reference) { \ - _all_method_symbols[i] = (void *) to; \ - } \ + if (!__is_new_method_##name()) { \ + ERR("Method Is Not \"New\""); \ } \ } +#define _setup_fancy_overwrite(start, name, target) \ + _check_if_method_is_new(name); \ + static name##_t _original_for_##target = start; \ + static name##_t _helper_for_##target = __overwrite_helper_for_##name(target, _original_for_##target) + +// Replace All Calls To Method start With target void _overwrite_calls(const char *file, int line, void *start, void *target); #define overwrite_calls_manual(start, target) _overwrite_calls(__FILE__, __LINE__, start, target) #define overwrite_calls(start, target) \ { \ _setup_fancy_overwrite(start, start, target); \ overwrite_calls_manual((void *) start, (void *) _helper_for_##target); \ - _update_references(start, _helper_for_##target); \ + start = _helper_for_##target; \ } +// Replace All Calls To Virtual Method start With target #define overwrite_virtual_calls(start, target) \ { \ _setup_fancy_overwrite(*start##_vtable_addr, start, target); \ overwrite_calls_manual((void *) *start##_vtable_addr, (void *) _helper_for_##target); \ } +// Replace All Calls To start With target Within [to, from) void _overwrite_calls_within(const char *file, int line, void *from, void *to, void *start, void *target); #define overwrite_calls_within(from, to, start, target) _overwrite_calls_within(__FILE__, __LINE__, from, to, start, target) +// Get Target Address From BL Instruction void *extract_from_bl_instruction(unsigned char *from); +// Replace Method start With target void _overwrite(const char *file, int line, void *start, void *target); -#define overwrite(start, target) _overwrite(__FILE__, __LINE__, (void *) start, (void *) target) +#define overwrite_manual(start, target) _overwrite(__FILE__, __LINE__, (void *) start, (void *) target) +#define overwrite(start, target) \ + { \ + _check_if_method_is_new(start); \ + start##_t type_check = target; \ + overwrite_manual(start, (void *) type_check); \ + } +// Patch Instruction void _patch(const char *file, int line, void *start, unsigned char patch[4]); #define patch(start, patch) _patch(__FILE__, __LINE__, start, patch) +// Patch 4 Bytes Of Data void _patch_address(const char *file, int line, void *start, void *target); #define patch_address(start, target) _patch_address(__FILE__, __LINE__, (void *) start, (void *) target) +// Patch VTable Entry +// This does not affect sub-classes. +#define patch_vtable(start, target) \ + { \ + start##_t type_check = target; \ + patch_address(start##_vtable_addr, (void *) type_check); \ + } + #endif #ifdef __cplusplus diff --git a/mods/src/chat/chat.cpp b/mods/src/chat/chat.cpp index 66d62662e2..fa8b59cbfb 100644 --- a/mods/src/chat/chat.cpp +++ b/mods/src/chat/chat.cpp @@ -116,7 +116,7 @@ void init_chat() { // Manually Send (And Loopback) ChatPacket overwrite_call((void *) 0x6b518, (void *) CommandServer_parse_CommandServer_dispatchPacket_injection); // Re-Broadcast ChatPacket - patch_address(ServerSideNetworkHandler_handle_ChatPacket_vtable_addr, ServerSideNetworkHandler_handle_ChatPacket_injection); + patch_vtable(ServerSideNetworkHandler_handle_ChatPacket, ServerSideNetworkHandler_handle_ChatPacket_injection); #ifndef MCPI_HEADLESS_MODE // Send Messages On Input Tick input_run_on_tick(send_queued_messages); diff --git a/mods/src/death/death.cpp b/mods/src/death/death.cpp index c4efb614ae..d62c858446 100644 --- a/mods/src/death/death.cpp +++ b/mods/src/death/death.cpp @@ -73,11 +73,10 @@ static bool Mob_hurt_injection(Mob_hurt_t original, Mob *mob, Entity *source, in } // Death Message Logic -#define Player_die_injections(type) \ - static type##_die_t original_##type##_die; \ - static void type##_die_injection(type *player, Entity *cause) { \ +#define Player_die_injections(type, original_method_self) \ + static void type##_die_injection(original_method_self##_die_t original, type *player, Entity *cause) { \ /* Call Original Method */ \ - original_##type##_die(player, cause); \ + original((original_method_self *) player, cause); \ \ /* Get Variable */ \ RakNetInstance *rak_net_instance = player->minecraft->rak_net_instance; \ @@ -119,8 +118,8 @@ static bool Mob_hurt_injection(Mob_hurt_t original, Mob *mob, Entity *source, in } \ } -Player_die_injections(LocalPlayer) -Player_die_injections(ServerPlayer) +Player_die_injections(LocalPlayer, LocalPlayer) +Player_die_injections(ServerPlayer, Player) Player_actuallyHurt_injections(LocalPlayer) Player_actuallyHurt_injections(ServerPlayer) @@ -129,10 +128,12 @@ Player_actuallyHurt_injections(ServerPlayer) void init_death() { // Death Messages if (feature_has("Implement Death Messages", server_auto)) { - patch_address(ServerPlayer_die_vtable_addr, ServerPlayer_die_injection); - patch_address(LocalPlayer_die_vtable_addr, LocalPlayer_die_injection); - patch_address(LocalPlayer_actuallyHurt_vtable_addr, LocalPlayer_actuallyHurt_injection); - patch_address(ServerPlayer_actuallyHurt_vtable_addr, ServerPlayer_actuallyHurt_injection); + patch_vtable(ServerPlayer_die, [](ServerPlayer *player, Entity *cause) { + ServerPlayer_die_injection(*Player_die_vtable_addr, player, cause); + }); + overwrite_virtual_calls(LocalPlayer_die, LocalPlayer_die_injection); + patch_vtable(LocalPlayer_actuallyHurt, LocalPlayer_actuallyHurt_injection); + patch_vtable(ServerPlayer_actuallyHurt, ServerPlayer_actuallyHurt_injection); overwrite_virtual_calls(Mob_hurt, Mob_hurt_injection); } diff --git a/mods/src/game-mode/ui.cpp b/mods/src/game-mode/ui.cpp index ad5154d1c5..78c8c893ee 100644 --- a/mods/src/game-mode/ui.cpp +++ b/mods/src/game-mode/ui.cpp @@ -84,12 +84,12 @@ CUSTOM_VTABLE(create_world_screen, Screen) { original_render(super, x, y, param_1); // Title std::string title = "Create world"; - Screen_drawCenteredString(super, super->font, &title, super->width / 2, title_padding, 0xffffffff); + super->drawCenteredString(super->font, &title, super->width / 2, title_padding, 0xffffffff); // Game Mode Description CreateWorldScreen *self = (CreateWorldScreen *) super; bool is_creative = self->game_mode->text == CREATIVE_STR; std::string description = is_creative ? Strings_creative_mode_description : Strings_survival_mode_description; - Screen_drawString(super, super->font, &description, self->game_mode->x, self->game_mode->y + self->game_mode->height + description_padding, 0xa0a0a0); + super->drawString(super->font, &description, self->game_mode->x, self->game_mode->y + self->game_mode->height + description_padding, 0xa0a0a0); }; // Positioning static Screen_setupPositions_t original_setupPositions = vtable->setupPositions; diff --git a/mods/src/input/bow.cpp b/mods/src/input/bow.cpp index c24411e3e9..670292b06c 100644 --- a/mods/src/input/bow.cpp +++ b/mods/src/input/bow.cpp @@ -19,7 +19,7 @@ static void _handle_bow(Minecraft *minecraft) { if (fix_bow && !is_right_click) { GameMode *game_mode = minecraft->game_mode; LocalPlayer *player = minecraft->player; - if (player != nullptr && game_mode != nullptr && LocalPlayer_isUsingItem(player)) { + if (player != nullptr && game_mode != nullptr && player->isUsingItem()) { game_mode->vtable->releaseUsingItem(game_mode, (Player *) player); } } diff --git a/mods/src/input/drop.cpp b/mods/src/input/drop.cpp index fce6287bd0..2b4af75c74 100644 --- a/mods/src/input/drop.cpp +++ b/mods/src/input/drop.cpp @@ -59,8 +59,8 @@ static void _handle_drop(Minecraft *minecraft) { // Empty Slot If Needed if (inventory_item->count < 1) { - Inventory_release(inventory, selected_slot); - Inventory_compressLinkedSlotList(inventory, selected_slot); + inventory->release(selected_slot); + inventory->compressLinkedSlotList(selected_slot); } // Drop diff --git a/mods/src/input/misc.cpp b/mods/src/input/misc.cpp index a97c712eca..acfa03efda 100644 --- a/mods/src/input/misc.cpp +++ b/mods/src/input/misc.cpp @@ -103,9 +103,9 @@ void _init_misc() { enable_misc = feature_has("Miscellaneous Input Fixes", server_disabled); if (enable_misc) { // Fix OptionsScreen Ignoring The Back Button - patch_address(OptionsScreen_handleBackEvent_vtable_addr, OptionsScreen_handleBackEvent_injection); + patch_vtable(OptionsScreen_handleBackEvent, OptionsScreen_handleBackEvent_injection); // Fix "Sleeping Beauty" Bug - patch_address(InBedScreen_handleBackEvent_vtable_addr, InBedScreen_handleBackEvent_injection); + patch_vtable(InBedScreen_handleBackEvent, InBedScreen_handleBackEvent_injection); // Disable Opening Inventory Using The Cursor When Cursor Is Hidden overwrite_calls(Gui_handleClick, Gui_handleClick_injection); } diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index 5d06d6df0a..b2a5f08df4 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -24,7 +24,51 @@ #include "misc-internal.h" #include -// Heart food overlay +// Classic HUD +#define DEFAULT_HUD_PADDING 2 +#define NEW_HUD_PADDING 1 +#define HUD_ELEMENT_WIDTH 82 +#define HUD_ELEMENT_HEIGHT 9 +#define TOOLBAR_HEIGHT 22 +#define SLOT_WIDTH 20 +#define DEFAULT_BUBBLES_PADDING 1 +#define NUMBER_OF_SLOTS 9 +static int use_classic_hud = 0; +static void Gui_renderHearts_GuiComponent_blit_hearts_injection(GuiComponent *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { + Minecraft *minecraft = ((Gui *) component)->minecraft; + x_dest -= DEFAULT_HUD_PADDING; + float width = ((float) minecraft->screen_width) * Gui_InvGuiScale; + float height = ((float) minecraft->screen_height) * Gui_InvGuiScale; + x_dest += (width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2; + y_dest -= DEFAULT_HUD_PADDING; + y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - NEW_HUD_PADDING; + // Call Original Method + component->blit(x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); +} +static void Gui_renderHearts_GuiComponent_blit_armor_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { + Minecraft *minecraft = component->minecraft; + x_dest -= DEFAULT_HUD_PADDING + HUD_ELEMENT_WIDTH; + float width = ((float) minecraft->screen_width) * Gui_InvGuiScale; + float height = ((float) minecraft->screen_height) * Gui_InvGuiScale; + x_dest += width - ((width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2) - HUD_ELEMENT_WIDTH; + y_dest -= DEFAULT_HUD_PADDING; + y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - NEW_HUD_PADDING; + // Call Original Method + component->blit(x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); +} +static void Gui_renderBubbles_GuiComponent_blit_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { + Minecraft *minecraft = component->minecraft; + x_dest -= DEFAULT_HUD_PADDING; + float width = ((float) minecraft->screen_width) * Gui_InvGuiScale; + float height = ((float) minecraft->screen_height) * Gui_InvGuiScale; + x_dest += (width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2; + y_dest -= DEFAULT_HUD_PADDING + DEFAULT_BUBBLES_PADDING + HUD_ELEMENT_HEIGHT; + y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - HUD_ELEMENT_HEIGHT - NEW_HUD_PADDING; + // Call Original Method + component->blit(x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); +} + +// Heart Food Overlay static int heal_amount = 0, heal_amount_drawing = 0; static void Gui_renderHearts_injection(Gui_renderHearts_t original, Gui *gui) { // Get heal_amount @@ -45,86 +89,42 @@ static void Gui_renderHearts_injection(Gui_renderHearts_t original, Gui *gui) { // Call original original(gui); } - +static GuiComponent_blit_t get_blit_with_classic_hud_offset() { + return use_classic_hud ? Gui_renderHearts_GuiComponent_blit_hearts_injection : GuiComponent_blit; +} #define PINK_HEART_FULL 70 #define PINK_HEART_HALF 79 -static Gui_blit_t Gui_blit_renderHearts_original = nullptr; static void Gui_renderHearts_GuiComponent_blit_overlay_empty_injection(Gui *gui, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t w1, int32_t h1, int32_t w2, int32_t h2) { - // Call original - Gui_blit_renderHearts_original(gui, x1, y1, x2, y2, w1, h1, w2, h2); - // Render the overlay + // Call Original Method + get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, x2, y2, w1, h1, w2, h2); + // Render The Overlay if (heal_amount_drawing == 1) { - // Half heart - Gui_blit_renderHearts_original(gui, x1, y1, PINK_HEART_HALF, 0, w1, h1, w2, h2); + // Half Heart + get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, PINK_HEART_HALF, 0, w1, h1, w2, h2); heal_amount_drawing = 0; } else if (heal_amount_drawing > 0) { - // Full heart - Gui_blit_renderHearts_original(gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2); + // Full Heart + get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2); heal_amount_drawing -= 2; } } - static void Gui_renderHearts_GuiComponent_blit_overlay_hearts_injection(Gui *gui, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t w1, int32_t h1, int32_t w2, int32_t h2) { // Offset the overlay if (x2 == 52) { heal_amount_drawing += 2; } else if (x2 == 61 && heal_amount) { // Half heart, flipped - Gui_blit_renderHearts_original(gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2); + get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2); heal_amount_drawing += 1; - }; - // Call original - Gui_blit_renderHearts_original(gui, x1, y1, x2, y2, w1, h1, w2, h2); + } + // Call Original Method + get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, x2, y2, w1, h1, w2, h2); heal_amount_drawing = fmin(heal_amount_drawing, heal_amount); } -// Classic HUD -#define DEFAULT_HUD_PADDING 2 -#define NEW_HUD_PADDING 1 -#define HUD_ELEMENT_WIDTH 82 -#define HUD_ELEMENT_HEIGHT 9 -#define TOOLBAR_HEIGHT 22 -#define SLOT_WIDTH 20 -#define DEFAULT_BUBBLES_PADDING 1 -#define NUMBER_OF_SLOTS 9 -static int use_classic_hud = 0; -static void Gui_renderHearts_GuiComponent_blit_hearts_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { - Minecraft *minecraft = component->minecraft; - x_dest -= DEFAULT_HUD_PADDING; - float width = ((float) minecraft->screen_width) * Gui_InvGuiScale; - float height = ((float) minecraft->screen_height) * Gui_InvGuiScale; - x_dest += (width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2; - y_dest -= DEFAULT_HUD_PADDING; - y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - NEW_HUD_PADDING; - // Call Original Method - Gui_blit(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); -} -static void Gui_renderHearts_GuiComponent_blit_armor_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { - Minecraft *minecraft = component->minecraft; - x_dest -= DEFAULT_HUD_PADDING + HUD_ELEMENT_WIDTH; - float width = ((float) minecraft->screen_width) * Gui_InvGuiScale; - float height = ((float) minecraft->screen_height) * Gui_InvGuiScale; - x_dest += width - ((width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2) - HUD_ELEMENT_WIDTH; - y_dest -= DEFAULT_HUD_PADDING; - y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - NEW_HUD_PADDING; - // Call Original Method - Gui_blit(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); -} -static void Gui_renderBubbles_GuiComponent_blit_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) { - Minecraft *minecraft = component->minecraft; - x_dest -= DEFAULT_HUD_PADDING; - float width = ((float) minecraft->screen_width) * Gui_InvGuiScale; - float height = ((float) minecraft->screen_height) * Gui_InvGuiScale; - x_dest += (width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2; - y_dest -= DEFAULT_HUD_PADDING + DEFAULT_BUBBLES_PADDING + HUD_ELEMENT_HEIGHT; - y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - HUD_ELEMENT_HEIGHT - NEW_HUD_PADDING; - // Call Original Method - Gui_blit(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src); -} - // Additional GUI Rendering static int hide_chat_messages = 0; -bool is_in_chat = 0; +bool is_in_chat = false; static int render_selected_item_text = 0; static void Gui_renderChatMessages_injection(Gui_renderChatMessages_t original, Gui *gui, int32_t y_offset, uint32_t max_messages, bool disable_fading, Font *font) { // Handle Classic HUD @@ -417,7 +417,7 @@ static int32_t get_color(LevelSource *level_source, int32_t x, int32_t z) { return biome->color; } #define BIOME_BLEND_SIZE 7 -static int32_t GrassTile_getColor_injection(__attribute__((unused)) Tile *tile, LevelSource *level_source, int32_t x, __attribute__((unused)) int32_t y, int32_t z) { +static int32_t GrassTile_getColor_injection(__attribute__((unused)) GrassTile *tile, LevelSource *level_source, int32_t x, __attribute__((unused)) int32_t y, int32_t z) { int r_sum = 0; int g_sum = 0; int b_sum = 0; @@ -441,7 +441,7 @@ static int32_t GrassTile_getColor_injection(__attribute__((unused)) Tile *tile, static int32_t TallGrass_getColor_injection(TallGrass_getColor_t original, TallGrass *tile, LevelSource *level_source, int32_t x, int32_t y, int32_t z) { int32_t original_color = original(tile, level_source, x, y, z); if (original_color == 0x339933) { - return GrassTile_getColor_injection((Tile *) tile, level_source, x, y, z); + return GrassTile_getColor_injection(nullptr, level_source, x, y, z); } else { return original_color; } @@ -463,7 +463,8 @@ static void RandomLevelSource_buildSurface_injection(RandomLevelSource_buildSurf } // No Block Tinting -static int32_t Tile_getColor_injection() { +template +static int32_t Tile_getColor_injection(__attribute__((unused)) T original, __attribute__((unused)) S *self, __attribute__((unused)) LevelSource *level_source, __attribute__((unused)) int x, __attribute__((unused)) int y, __attribute__((unused)) int z) { return 0xffffff; } @@ -620,7 +621,7 @@ static void Player_stopUsingItem_injection(Player_stopUsingItem_t original, Play } // Java Light Ramp -static void Dimension_updateLightRamp_injection(Dimension *self) { +static void Dimension_updateLightRamp_injection(__attribute__((unused)) Dimension_updateLightRamp_t original, Dimension *self) { // https://github.com/ReMinecraftPE/mcpe/blob/d7a8b6baecf8b3b050538abdbc976f690312aa2d/source/world/level/Dimension.cpp#L92-L105 for (int i = 0; i <= 15; i++) { float f1 = 1.0f - (((float) i) / 15.0f); @@ -632,9 +633,9 @@ static void Dimension_updateLightRamp_injection(Dimension *self) { } // Read Asset File -static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) AppPlatform *app_platform, std::string const& path) { +static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) AppPlatform_readAssetFile_t original, __attribute__((unused)) AppPlatform *app_platform, std::string *path) { // Open File - std::ifstream stream("data/" + path, std::ios_base::binary | std::ios_base::ate); + std::ifstream stream("data/" + *path, std::ios_base::binary | std::ios_base::ate); if (!stream) { // Does Not Exist AppPlatform_readAssetFile_return_value ret; @@ -700,7 +701,7 @@ void PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_inje PaneCraftingScreen_recheckRecipes(self); } -ItemInstance *Item_getCraftingRemainingItem_injection(Item *self, ItemInstance *item_instance) { +ItemInstance *Item_getCraftingRemainingItem_injection(__attribute__((unused)) Item_getCraftingRemainingItem_t original, Item *self, ItemInstance *item_instance) { if (self->craftingRemainingItem != nullptr) { ItemInstance *ret = alloc_ItemInstance(); ret->id = self->craftingRemainingItem->id; @@ -765,7 +766,6 @@ void init_misc() { } // Classic HUD - Gui_blit_renderHearts_original = Gui_blit; if (feature_has("Classic HUD", server_disabled)) { use_classic_hud = 1; overwrite_call((void *) 0x26758, (void *) Gui_renderHearts_GuiComponent_blit_hearts_injection); @@ -773,7 +773,6 @@ void init_misc() { overwrite_call((void *) 0x268c4, (void *) Gui_renderBubbles_GuiComponent_blit_injection); overwrite_call((void *) 0x266f8, (void *) Gui_renderHearts_GuiComponent_blit_hearts_injection); overwrite_call((void *) 0x267c8, (void *) Gui_renderHearts_GuiComponent_blit_hearts_injection); - Gui_blit_renderHearts_original = Gui_renderHearts_GuiComponent_blit_hearts_injection; } // Food overlay @@ -823,10 +822,10 @@ void init_misc() { #ifdef MCPI_HEADLESS_MODE // Don't Render Game In Headless Mode - overwrite(GameRenderer_render, nop); - overwrite(NinecraftApp_initGLStates, nop); - overwrite(Gui_onConfigChanged, nop); - overwrite(LevelRenderer_generateSky, nop); + overwrite_manual(GameRenderer_render, nop); + overwrite_manual(NinecraftApp_initGLStates, nop); + overwrite_manual(Gui_onConfigChanged, nop); + overwrite_manual(LevelRenderer_generateSky, nop); #else // Improved Cursor Rendering if (feature_has("Improved Cursor Rendering", server_disabled)) { @@ -850,7 +849,7 @@ void init_misc() { // Remove Forced GUI Lag if (feature_has("Remove Forced GUI Lag (Can Break Joining Servers)", server_enabled)) { - overwrite(Common_sleepMs, nop); + overwrite_manual(Common_sleepMs, nop); } #ifndef MCPI_HEADLESS_MODE @@ -859,7 +858,7 @@ void init_misc() { #endif // Fix Graphics Bug When Switching To First-Person While Sneaking - patch_address(PlayerRenderer_render_vtable_addr, PlayerRenderer_render_injection); + patch_vtable(PlayerRenderer_render, PlayerRenderer_render_injection); // Disable Speed Bridging if (feature_has("Disable Speed Bridging", server_disabled)) { @@ -875,7 +874,7 @@ void init_misc() { // Change Grass Color if (feature_has("Add Biome Colors To Grass", server_disabled)) { - patch_address(GrassTile_getColor_vtable_addr, GrassTile_getColor_injection); + patch_vtable(GrassTile_getColor, GrassTile_getColor_injection); overwrite_virtual_calls(TallGrass_getColor, TallGrass_getColor_injection); } @@ -886,11 +885,11 @@ void init_misc() { // Disable Block Tinting if (feature_has("Disable Block Tinting", server_disabled)) { - patch_address(GrassTile_getColor_vtable_addr, Tile_getColor_injection); - patch_address(TallGrass_getColor_vtable_addr, Tile_getColor_injection); - patch_address(StemTile_getColor_vtable_addr, Tile_getColor_injection); - patch_address(LeafTile_getColor_vtable_addr, Tile_getColor_injection); - overwrite(*LiquidTile_getColor_vtable_addr, Tile_getColor_injection); + overwrite_virtual_calls(GrassTile_getColor, Tile_getColor_injection); + overwrite_virtual_calls(TallGrass_getColor, Tile_getColor_injection); + overwrite_virtual_calls(StemTile_getColor, Tile_getColor_injection); + overwrite_virtual_calls(LeafTile_getColor, Tile_getColor_injection); + overwrite_virtual_calls(LiquidTile_getColor, Tile_getColor_injection); } // Custom GUI Scale @@ -932,7 +931,7 @@ void init_misc() { #ifndef MCPI_HEADLESS_MODE // Replace Block Highlight With Outline if (feature_has("Replace Block Highlight With Outline", server_disabled)) { - overwrite((void *) LevelRenderer_renderHitSelect, (void *) LevelRenderer_renderHitOutline); + overwrite(LevelRenderer_renderHitSelect, LevelRenderer_renderHitOutline); unsigned char fix_outline_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" patch((void *) 0x4d830, fix_outline_patch); overwrite_call((void *) 0x4d764, (void *) glColor4f_injection); @@ -952,7 +951,7 @@ void init_misc() { // Java Light Ramp if (feature_has("Use Java Beta 1.3 Light Ramp", server_disabled)) { - overwrite(*Dimension_updateLightRamp_vtable_addr, Dimension_updateLightRamp_injection); + overwrite_virtual_calls(Dimension_updateLightRamp, Dimension_updateLightRamp_injection); } // Fix used items transferring durability @@ -971,7 +970,7 @@ void init_misc() { // Implement AppPlatform::readAssetFile So Translations Work if (feature_has("Load Language Files", server_enabled)) { - overwrite(*AppPlatform_readAssetFile_vtable_addr, AppPlatform_readAssetFile_injection); + overwrite_virtual_calls(AppPlatform_readAssetFile, AppPlatform_readAssetFile_injection); } // Fix Pause Menu @@ -982,16 +981,16 @@ void init_misc() { // Implement Crafting Remainders overwrite_call((void *) 0x2e230, (void *) PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_injection); - overwrite(*Item_getCraftingRemainingItem_vtable_addr, Item_getCraftingRemainingItem_injection); + overwrite_virtual_calls(Item_getCraftingRemainingItem, Item_getCraftingRemainingItem_injection); // Replace 2011 std::sort With Optimized(TM) Code if (feature_has("Optimized Chunk Sorting", server_enabled)) { - overwrite((void *) 0x51fac, (void *) sort_chunks); + overwrite_manual((void *) 0x51fac, (void *) sort_chunks); } // Display Date In Select World Screen if (feature_has("Display Date In Select World Screen", server_disabled)) { - patch_address(AppPlatform_linux_getDateString_vtable_addr, AppPlatform_linux_getDateString_injection); + patch_vtable(AppPlatform_linux_getDateString, AppPlatform_linux_getDateString_injection); } // Init Logging diff --git a/mods/src/options/options.cpp b/mods/src/options/options.cpp index 29367bfc27..86c8dd0ea7 100644 --- a/mods/src/options/options.cpp +++ b/mods/src/options/options.cpp @@ -11,7 +11,7 @@ #include // Force Mob Spawning -static bool LevelData_getSpawnMobs_injection(__attribute__((unused)) unsigned char *level_data) { +static bool LevelData_getSpawnMobs_injection(__attribute__((unused)) LevelData *level_data) { return true; } @@ -238,7 +238,7 @@ static void OptionButton_toggle_Options_save_injection(Options *self) { void init_options() { // Force Mob Spawning if (feature_has("Force Mob Spawning", server_auto)) { - overwrite((void *) LevelData_getSpawnMobs, (void *) LevelData_getSpawnMobs_injection); + overwrite(LevelData_getSpawnMobs, LevelData_getSpawnMobs_injection); } // Render Distance diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp index 469f4ffd71..cc34df1511 100644 --- a/mods/src/server/server.cpp +++ b/mods/src/server/server.cpp @@ -223,7 +223,7 @@ static void handle_server_stop(Minecraft *minecraft) { // Save And Exit Level *level = get_level(minecraft); if (level != nullptr) { - Level_saveLevelData_injection(level); + Level_saveLevelData(level); } Minecraft_leaveGame(minecraft, false); // Stop Game @@ -236,7 +236,7 @@ static void handle_server_stop(Minecraft *minecraft) { // Track TPS #define NANOSECONDS_IN_SECOND 1000000000ll static long long int get_time() { - struct timespec ts; + timespec ts = {}; clock_gettime(CLOCK_MONOTONIC_RAW, &ts); long long int a = (long long int) ts.tv_nsec; long long int b = ((long long int) ts.tv_sec) * NANOSECONDS_IN_SECOND; @@ -266,7 +266,7 @@ static volatile bool stdin_buffer_complete = false; static volatile char *stdin_buffer = nullptr; static void *read_stdin_thread(__attribute__((unused)) void *data) { // Loop - while (1) { + while (true) { int bytes_available; if (ioctl(fileno(stdin), FIONREAD, &bytes_available) == -1) { bytes_available = 0; @@ -433,7 +433,7 @@ static bool is_ip_in_blacklist(const char *ip) { } // Ban Players -static bool RakNet_RakPeer_IsBanned_injection(__attribute__((unused)) RakNet_RakPeer *rakpeer, const char *ip) { +static bool RakNet_RakPeer_IsBanned_injection(__attribute__((unused)) RakNet_RakPeer_IsBanned_t original, __attribute__((unused)) RakNet_RakPeer *rakpeer, const char *ip) { // Check List bool ret = is_ip_in_blacklist(ip); if (is_whitelist()) { @@ -576,7 +576,7 @@ static void server_init() { unsigned char max_players_patch[4] = {get_max_players(), 0x30, 0xa0, 0xe3}; // "mov r3, #MAX_PLAYERS" patch((void *) 0x166d0, max_players_patch); // Custom Banned IP List - patch_address(RakNet_RakPeer_IsBanned_vtable_addr, (void *) RakNet_RakPeer_IsBanned_injection); + overwrite_virtual_calls(RakNet_RakPeer_IsBanned, RakNet_RakPeer_IsBanned_injection); // Show The MineCon Icon Next To MOTD In Server List if (get_server_properties().get_bool("show-minecon-badge", DEFAULT_SHOW_MINECON_BADGE)) { diff --git a/mods/src/sign/sign.cpp b/mods/src/sign/sign.cpp index f9c3a98924..fbca2c03fc 100644 --- a/mods/src/sign/sign.cpp +++ b/mods/src/sign/sign.cpp @@ -49,7 +49,7 @@ void sign_key_press(char key) { void init_sign() { if (feature_has("Fix Sign Placement", server_disabled)) { // Fix Signs - patch_address(LocalPlayer_openTextEdit_vtable_addr, (void *) LocalPlayer_openTextEdit_injection); + patch_vtable(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection); } // Handle Backspace diff --git a/mods/src/sound/sound.cpp b/mods/src/sound/sound.cpp index 8b6ddbb6eb..9043374d34 100644 --- a/mods/src/sound/sound.cpp +++ b/mods/src/sound/sound.cpp @@ -66,11 +66,11 @@ static void play(std::string name, float x, float y, float z, float volume, floa media_audio_play(source.c_str(), resolved_name.c_str(), x, y, z, pitch, volume, is_ui); } } -static void SoundEngine_playUI_injection(__attribute__((unused)) unsigned char *sound_engine, std::string const& name, float volume, float pitch) { - play(name, 0, 0, 0, volume, pitch, true); +static void SoundEngine_playUI_injection(__attribute__((unused)) SoundEngine *sound_engine, std::string *name, float volume, float pitch) { + play(*name, 0, 0, 0, volume, pitch, true); } -static void SoundEngine_play_injection(__attribute__((unused)) unsigned char *sound_engine, std::string const& name, float x, float y, float z, float volume, float pitch) { - play(name, x, y, z, volume, pitch, false); +static void SoundEngine_play_injection(__attribute__((unused)) SoundEngine *sound_engine, std::string *name, float x, float y, float z, float volume, float pitch) { + play(*name, x, y, z, volume, pitch, false); } // Refresh Data diff --git a/mods/src/textures/headless.cpp b/mods/src/textures/headless.cpp index edfb3d83b0..b893af5414 100644 --- a/mods/src/textures/headless.cpp +++ b/mods/src/textures/headless.cpp @@ -3,7 +3,7 @@ #include // Disable Texture Loading -static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) AppPlatform_linux *app_platform, __attribute__((unused)) std::string *path, __attribute__((unused)) bool b) { +static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) AppPlatform_linux_loadTexture_t original, __attribute__((unused)) AppPlatform_linux *app_platform, __attribute__((unused)) std::string *path, __attribute__((unused)) bool b) { Texture out; out.width = 0; out.height = 0; @@ -19,5 +19,5 @@ static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) A // Init void init_textures() { // Disable Texture Loading - overwrite((void *) AppPlatform_linux_loadTexture_non_virtual, (void *) AppPlatform_linux_loadTexture_injection); + overwrite_virtual_calls(AppPlatform_linux_loadTexture, AppPlatform_linux_loadTexture_injection); } diff --git a/mods/src/textures/textures.cpp b/mods/src/textures/textures.cpp index bfe054c87d..31f80f905a 100644 --- a/mods/src/textures/textures.cpp +++ b/mods/src/textures/textures.cpp @@ -170,7 +170,7 @@ static void Textures_tick_glTexSubImage2D_injection(GLenum target, GLint level, } // Load Textures -static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) AppPlatform_linux *app_platform, std::string *path, bool b) { +static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) AppPlatform_linux_loadTexture_t original, __attribute__((unused)) AppPlatform_linux *app_platform, std::string *path, bool b) { Texture out; std::string real_path = *path; if (b) { @@ -234,5 +234,5 @@ void init_textures() { overwrite_call((void *) 0x53274, (void *) Textures_tick_glTexSubImage2D_injection); // Load Textures - overwrite(*AppPlatform_linux_loadTexture_vtable_addr, AppPlatform_linux_loadTexture_injection); + overwrite_virtual_calls(AppPlatform_linux_loadTexture, AppPlatform_linux_loadTexture_injection); } diff --git a/mods/src/title-screen/title-screen.cpp b/mods/src/title-screen/title-screen.cpp index 7467be931c..02a279a94d 100644 --- a/mods/src/title-screen/title-screen.cpp +++ b/mods/src/title-screen/title-screen.cpp @@ -18,7 +18,7 @@ static void StartMenuScreen_render_Screen_renderBackground_injection(Screen *scr Textures *textures = minecraft->textures; std::string texture = "gui/titleBG.png"; Textures_loadAndBindTexture(textures, &texture); - Screen_blit(screen, 0, 0, 0, 0, screen->width, screen->height, 0x100, 0x100); + screen->blit(0, 0, 0, 0, screen->width, screen->height, 0x100, 0x100); } // Add Buttons Back To Classic Start Screen @@ -109,7 +109,7 @@ static void StartMenuScreen_render_Screen_render_injection(Screen *screen, int x glScalef(scale, scale, scale); // Render static int line_height = 8; - Screen_drawCenteredString(screen, screen->font, ¤t_splash, 0, -(float(line_height) / 2), 0xffff00); + screen->drawCenteredString(screen->font, ¤t_splash, 0, -(float(line_height) / 2), 0xffff00); // Finish glPopMatrix(); } diff --git a/mods/src/touch/touch.cpp b/mods/src/touch/touch.cpp index 1520727702..2899c46c6a 100644 --- a/mods/src/touch/touch.cpp +++ b/mods/src/touch/touch.cpp @@ -65,7 +65,7 @@ void init_touch() { int touch_buttons = touch_gui; if (touch_gui) { // Main UI - overwrite((void *) Minecraft_isTouchscreen, (void *) Minecraft_isTouchscreen_injection); + overwrite(Minecraft_isTouchscreen, Minecraft_isTouchscreen_injection); // Force Correct Toolbar Size unsigned char toolbar_patch[4] = {0x01, 0x00, 0x50, 0xe3}; // "cmp r0, #0x1" @@ -98,7 +98,7 @@ void init_touch() { // Improved Button Hover Behavior if (touch_buttons && feature_has("Improved Button Hover Behavior", server_disabled)) { - overwrite((void *) Button_hovered, (void *) Button_hovered_injection); + overwrite(Button_hovered, Button_hovered_injection); overwrite_call((void *) 0x1ebd4, (void *) LargeImageButton_render_GuiComponent_drawCenteredString_injection); } diff --git a/mods/src/version/version.cpp b/mods/src/version/version.cpp index 54f2d6e327..a830854872 100644 --- a/mods/src/version/version.cpp +++ b/mods/src/version/version.cpp @@ -20,7 +20,7 @@ __attribute__((destructor)) static void _free_version() { } // Injection For Touch GUI Version -static std::string Common_getGameVersionString_injection(__attribute__((unused)) std::string const& version_suffix) { +static std::string Common_getGameVersionString_injection(__attribute__((unused)) std::string *version_suffix) { // Set Version return version_get(); } @@ -28,7 +28,7 @@ static std::string Common_getGameVersionString_injection(__attribute__((unused)) // Init void init_version() { // Touch GUI - overwrite((void *) Common_getGameVersionString, (void *) Common_getGameVersionString_injection); + overwrite(Common_getGameVersionString, Common_getGameVersionString_injection); // Normal GUI patch_address((void *) Strings_minecraft_pi_version_pointer, version_get()); diff --git a/symbols/CMakeLists.txt b/symbols/CMakeLists.txt index 55be867f3a..22beb9f4da 100644 --- a/symbols/CMakeLists.txt +++ b/symbols/CMakeLists.txt @@ -228,6 +228,8 @@ target_include_directories( # Disable C++11 String ABI target_compile_definitions(symbols PUBLIC -D_GLIBCXX_USE_CXX11_ABI=0) +# Fix Warning +target_compile_options(symbols PUBLIC -Wno-missing-field-initializers) # Install install(TARGETS symbols DESTINATION "${MCPI_LIB_DIR}") diff --git a/symbols/src/item/Item.def b/symbols/src/item/Item.def index 107f2cafd2..61fd3632a0 100644 --- a/symbols/src/item/Item.def +++ b/symbols/src/item/Item.def @@ -38,7 +38,7 @@ property Item *craftingRemainingItem = 0x1c; property std::string description_id = 0x20; // Globals -static-property-array Item *items = 0x17b250; +static-property Item *items[256] = 0x17b250; // Items static-property Item *flintAndSteel = 0x17ba70; diff --git a/symbols/src/level/Biome.def b/symbols/src/level/Biome.def index 3fed3d514c..8747634a67 100644 --- a/symbols/src/level/Biome.def +++ b/symbols/src/level/Biome.def @@ -17,4 +17,4 @@ property int color = 0x2c; property int leaf_color = 0x34; // This is a Biome*[64x64], temp x humidity -static-property-array Biome *map = 0x17c970; +static-property Biome *map[4096] = 0x17c970; diff --git a/symbols/src/level/Dimension.def b/symbols/src/level/Dimension.def index ee73739c0d..5620d46aef 100644 --- a/symbols/src/level/Dimension.def +++ b/symbols/src/level/Dimension.def @@ -2,4 +2,4 @@ vtable 0x110370; virtual-method void updateLightRamp() = 0x28; -property float light_ramp[16] = 0x10; +property float light_ramp[16] = 0x10; \ No newline at end of file diff --git a/symbols/src/level/Level.def b/symbols/src/level/Level.def index 797380f538..454eb2fc43 100644 --- a/symbols/src/level/Level.def +++ b/symbols/src/level/Level.def @@ -46,3 +46,4 @@ property bool done_generating = 0x12; property std::vector entities = 0x20; property std::vector tileentities = 0x50; property std::vector players = 0x60; +property Dimension *dimension = 0x74; \ No newline at end of file diff --git a/symbols/src/level/LevelData.def b/symbols/src/level/LevelData.def index f1d8cf55df..0f3758a3bf 100644 --- a/symbols/src/level/LevelData.def +++ b/symbols/src/level/LevelData.def @@ -1 +1 @@ -method uint getSpawnMobs() = 0xbabec; +method bool getSpawnMobs() = 0xbabec; diff --git a/symbols/src/misc/Common.def b/symbols/src/misc/Common.def index de81022c9d..d3c6b9bf5a 100644 --- a/symbols/src/misc/Common.def +++ b/symbols/src/misc/Common.def @@ -1,4 +1,4 @@ -static-method std::string *getGameVersionString(std::string *version_suffix) = 0x15068; +static-method std::string getGameVersionString(std::string *version_suffix) = 0x15068; // These are not actually part of "Common", but they have to go somewhere. static-method void renderCursor(float x, float y, Minecraft *minecraft) = 0x480c4; diff --git a/symbols/src/misc/Strings.def b/symbols/src/misc/Strings.def index 34d29536cd..fc3571d931 100644 --- a/symbols/src/misc/Strings.def +++ b/symbols/src/misc/Strings.def @@ -7,5 +7,5 @@ static-property char *options_txt_fopen_mode_when_loading = 0x19d24; // w static-property char *feedback_vibration_options_txt_name = 0x135d70; // feedback_vibration static-property char *gfx_lowquality_options_txt_name = 0x135d88; // gfx_lowquality static-property char *classic_create_button_text = 0x39bec; // Create -static-property-array char creative_mode_description = 0x104492; // Unlimited resources and flying -static-property-array char survival_mode_description = 0x104470; // Mobs, health and gather resources +static-property char creative_mode_description[31] = 0x104492; // Unlimited resources and flying +static-property char survival_mode_description[34] = 0x104470; // Mobs, health and gather resources diff --git a/symbols/src/tile/Tile.def b/symbols/src/tile/Tile.def index b147e0897c..abdf9a7a41 100644 --- a/symbols/src/tile/Tile.def +++ b/symbols/src/tile/Tile.def @@ -67,9 +67,9 @@ property int category = 0x3c; property AABB aabb = 0x40; // Globals, all of theses are 256 elements long -static-property-array Tile *tiles = 0x180e08; -static-property-array float lightEmission = 0x181214; -static-property-array bool isEntityTile = 0x181f20; +static-property Tile *tiles[256] = 0x180e08; +static-property float lightEmission[256] = 0x181214; +static-property bool isEntityTile[256] = 0x181f20; // Tiles static-property Tile *grass = 0x181b14;