Compare commits

...

2 Commits

Author SHA1 Message Date
f53f405bdd The Compiler Strikes Back!
All checks were successful
CI / Build (AMD64, Server) (push) Successful in 17m14s
CI / Build (AMD64, Client) (push) Successful in 17m16s
CI / Build (ARM64, Server) (push) Successful in 18m11s
CI / Build (ARM64, Client) (push) Successful in 20m30s
CI / Build (ARMHF, Server) (push) Successful in 13m28s
CI / Build (ARMHF, Client) (push) Successful in 16m48s
CI / Test (Server) (push) Successful in 17m56s
CI / Test (Client) (push) Successful in 19m32s
CI / Release (push) Has been skipped
CI / Build Example Mods (push) Successful in 13m42s
2024-05-24 04:44:53 -04:00
60a5accff2 Fix Another Link 2024-05-22 02:57:00 -04:00
18 changed files with 114 additions and 125 deletions

@ -1 +1 @@
Subproject commit eb49f25fa45842ebff448cbadd347c883e66efb6
Subproject commit 8249a305df07a0b087b44341afa8c3b27ad7a156

View File

@ -4,6 +4,9 @@
#if defined(REBORN_HAS_PATCH_CODE) && defined(__cplusplus)
#include <string>
#include <functional>
// Init
void reborn_init_patch();
@ -12,58 +15,25 @@ void _overwrite_call(const char *file, int line, void *start, void *target);
#define overwrite_call(...) \
_overwrite_call(__FILE__, __LINE__, __VA_ARGS__)
// Make Sure Function Is Only Called Once
template <int>
static void _only_call_once() {
static bool _has_run = false;
if (_has_run) {
ERR("\"Fancy\" overwrite*() Functions Can Only Be Called Once");
}
_has_run = true;
}
// Replace All Calls To Method start With target
void *_overwrite_calls_manual(const char *file, int line, void *start, void *target);
#define overwrite_calls_manual(...) \
_overwrite_calls_manual(__FILE__, __LINE__, __VA_ARGS__)
template <int call_id, typename start_t, typename overwrite_t>
static void _overwrite_calls(const char *file, int line, start_t (*create_helper)(overwrite_t, start_t), start_t &start, overwrite_t target) {
_only_call_once<call_id>();
start_t helper = create_helper(target, start);
start = (start_t) _overwrite_calls_manual(file, line, (void *) start, (void *) helper);
template <typename overwrite_t>
static void _overwrite_calls(const char *file, int line, std::string (*set_overwrite)(const overwrite_t &, const std::function<void *(void *, void *)> &), const overwrite_t &target) {
std::string ret = set_overwrite(target, [&file, &line](void *start, void *target2) {
return _overwrite_calls_manual(file, line, start, target2);
});
if (!ret.empty()) {
ERR("%s", ret.c_str());
}
}
#define overwrite_calls(start, ...) \
_overwrite_calls< \
__COUNTER__, \
start##_t, \
__overwrite_##start##_t \
>( \
__FILE__, __LINE__, \
__create_overwrite_helper_for_##start, \
start, \
__VA_ARGS__ \
)
// Replace All Calls To Virtual Method start With target
template <int call_id, typename start_t, typename overwrite_t>
static void _overwrite_virtual_calls(const char *file, int line, start_t (*create_helper)(overwrite_t, start_t), bool (*is_overwritable)(), start_t start, overwrite_t target) {
_only_call_once<call_id>();
if (!is_overwritable()) {
ERR("Virtual Method Is Not Overwritable");
}
start_t helper = create_helper(target, start);
_overwrite_calls_manual(file, line, (void *) start, (void *) helper);
}
#define overwrite_virtual_calls(start, ...) \
_overwrite_virtual_calls< \
__COUNTER__, \
start##_t, \
__overwrite_##start##_t \
>( \
__FILE__, __LINE__, \
__create_overwrite_helper_for_##start, \
__is_overwritable_##start, \
*start##_vtable_addr, \
__set_overwrite_for_##start, \
__VA_ARGS__ \
)
@ -77,7 +47,7 @@ void _overwrite_calls_within(const char *file, int line, void *from, void *to, s
}
#define overwrite_calls_within(from, to, start, ...) \
_overwrite_calls_within< \
start##_t \
__raw_##start##_t \
>( \
__FILE__, __LINE__, \
from, to, \
@ -98,7 +68,7 @@ void _overwrite(const char *file, int line, start_t start, start_t target) {
}
#define overwrite(start, ...) \
_overwrite< \
start##_t \
__raw_##start##_t \
>( \
__FILE__, __LINE__, \
start, \
@ -123,7 +93,7 @@ void _patch_vtable(const char *file, int line, start_t *start, start_t target) {
}
#define patch_vtable(start, ...) \
_patch_vtable< \
start##_t \
__raw_##start##_t \
>( \
__FILE__, __LINE__, \
start##_vtable_addr, \

View File

@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <functional>
#include <symbols/minecraft.h>
@ -14,47 +15,11 @@ void misc_run_on_creative_inventory_setup(misc_update_function_FillingContainer_
extern bool is_in_chat;
}
#define misc_run_on_update(...) \
overwrite_virtual_calls(Minecraft_update, [](Minecraft_update_t _original, Minecraft *_self) { \
_original(_self); \
(__VA_ARGS__)(_self); \
})
#define misc_run_on_tick(...) \
overwrite_calls(Minecraft_tick, [](Minecraft_tick_t _original, Minecraft *_self, int _tick, int _max_ticks) { \
_original(_self, _tick, _max_ticks); \
(__VA_ARGS__)(_self); \
})
#define misc_run_on_recipes_setup(...) \
overwrite_calls(Recipes_constructor, [](Recipes_constructor_t _original, Recipes *_self) { \
_original(_self); \
(__VA_ARGS__)(_self); \
return _self; \
})
#define misc_run_on_furnace_recipes_setup(...) \
overwrite_calls(FurnaceRecipes_constructor, [](FurnaceRecipes_constructor_t _original, FurnaceRecipes *_self) { \
_original(_self); \
(__VA_ARGS__)(_self); \
return _self; \
})
#define misc_run_on_tiles_setup(...) \
overwrite_calls(Tile_initTiles, [](Tile_initTiles_t _original) { \
(__VA_ARGS__)(); \
_original(); \
})
#define misc_run_on_items_setup(...) \
overwrite_calls(Item_initItems, [](Item_initItems_t _original) { \
_original(); \
(__VA_ARGS__)(); \
})
#define misc_run_on_language_setup(...) \
overwrite_calls(I18n_loadLanguage, [](I18n_loadLanguage_t _original, AppPlatform *_self, std::string _language_name) { \
_original(_self, _language_name); \
(__VA_ARGS__)(); \
})
#define misc_run_on_game_key_press(...) \
overwrite_calls(Gui_handleKeyPressed, [](Gui_handleKeyPressed_t _original, Gui *_self, int _key) { \
if ((__VA_ARGS__)(_self->minecraft, _key)) { \
return; \
} \
_original(_self, _key); \
})
void misc_run_on_update(const std::function<void(Minecraft *)> &func);
void misc_run_on_tick(const std::function<void(Minecraft *)> &func);
void misc_run_on_recipes_setup(const std::function<void(Recipes *)> &func);
void misc_run_on_furnace_recipes_setup(const std::function<void(FurnaceRecipes *)> &func);
void misc_run_on_tiles_setup(const std::function<void()> &func);
void misc_run_on_items_setup(const std::function<void()> &func);
void misc_run_on_language_setup(const std::function<void()> &func);
void misc_run_on_game_key_press(const std::function<bool(Minecraft *, int)> &func);

View File

@ -355,7 +355,7 @@ void init_bucket() {
// Change Max Stack Size Based On Auxiliary
overwrite_calls(ItemInstance_getMaxStackSize, ItemInstance_getMaxStackSize_injection);
// Enable milking
overwrite_virtual_calls(Cow_interact, Cow_interact_injection);
overwrite_calls(Cow_interact, Cow_interact_injection);
// Creative Inventory
misc_run_on_creative_inventory_setup(Inventory_setupDefault_FillingContainer_addItem_call_injection);
// Make Liquids Selectable

View File

@ -36,7 +36,7 @@ static void TripodCamera_tick_Level_addParticle_call_injection(Level *level, std
// Init
void init_camera() {
// Implement AppPlatform_linux::saveScreenshot So Cameras Work
overwrite_virtual_calls(AppPlatform_saveScreenshot, AppPlatform_saveScreenshot_injection);
overwrite_calls(AppPlatform_saveScreenshot, AppPlatform_saveScreenshot_injection);
// Fix Camera Rendering
if (feature_has("Fix Camera Rendering", server_disabled)) {

View File

@ -131,10 +131,10 @@ void init_death() {
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);
overwrite_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);
overwrite_calls(Mob_hurt, Mob_hurt_injection);
}
// Fix TNT

View File

@ -252,6 +252,6 @@ create_SelectWorldScreen_tick_injection(Touch_)
// Init
void _init_game_mode_ui() {
// Hijack Create World Button
overwrite_virtual_calls(SelectWorldScreen_tick, SelectWorldScreen_tick_injection);
overwrite_virtual_calls(Touch_SelectWorldScreen_tick, Touch_SelectWorldScreen_tick_injection);
overwrite_calls(SelectWorldScreen_tick, SelectWorldScreen_tick_injection);
overwrite_calls(Touch_SelectWorldScreen_tick, Touch_SelectWorldScreen_tick_injection);
}

View File

@ -56,7 +56,7 @@ static ItemInstance *Player_attack_Inventory_getSelected_injection(Inventory *in
void _init_attack() {
// Allow Attacking Mobs
if (feature_has("Fix Attacking", server_disabled)) {
overwrite_virtual_calls(MouseBuildInput_tickBuild, MouseBuildInput_tickBuild_injection);
overwrite_calls(MouseBuildInput_tickBuild, MouseBuildInput_tickBuild_injection);
// Fix Holding Attack
overwrite_call((void *) 0x8fc1c, (void *) Player_attack_Entity_hurt_injection);

View File

@ -38,6 +38,60 @@ static void Inventory_setupDefault_FillingContainer_addItem_call_injection(Filli
handle_misc_creative_inventory_setup(filling_container);
}
// API
void misc_run_on_update(const std::function<void(Minecraft *)> &func) {
overwrite_calls(Minecraft_update, [func](Minecraft_update_t original, Minecraft *self) {
original(self);
func(self);
});
}
void misc_run_on_tick(const std::function<void(Minecraft *)> &func) {
overwrite_calls(Minecraft_tick, [func](Minecraft_tick_t original, Minecraft *self, int tick, int max_ticks) {
original(self, tick, max_ticks);
func(self);
});
}
void misc_run_on_recipes_setup(const std::function<void(Recipes *)> &func) {
overwrite_calls(Recipes_constructor, [func](Recipes_constructor_t original, Recipes *self) {
original(self);
func(self);
return self;
});
}
void misc_run_on_furnace_recipes_setup(const std::function<void(FurnaceRecipes *)> &func) {
overwrite_calls(FurnaceRecipes_constructor, [func](FurnaceRecipes_constructor_t original, FurnaceRecipes *self) {
original(self);
func(self);
return self;
});
}
void misc_run_on_tiles_setup(const std::function<void()> &func) {
overwrite_calls(Tile_initTiles, [func](Tile_initTiles_t original) {
func();
original();
});
}
void misc_run_on_items_setup(const std::function<void()> &func) {
overwrite_calls(Item_initItems, [func](Item_initItems_t original) {
original();
func();
});
}
void misc_run_on_language_setup(const std::function<void()> &func) {
overwrite_calls(I18n_loadLanguage, [func](I18n_loadLanguage_t original, AppPlatform *self, std::string language_name) {
original(self, language_name);
func();
});
}
void misc_run_on_game_key_press(const std::function<bool(Minecraft *, int)> &func) {
overwrite_calls(Gui_handleKeyPressed, [func](Gui_handleKeyPressed_t original, Gui *self, int key) {
if (func(self->minecraft, key)) {
return;
}
original(self, key);
});
}
// Render Fancy Background
void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height) {
// https://github.com/ReMinecraftPE/mcpe/blob/f0d65eaecec1b3fe9c2f2b251e114a890c54ab77/source/client/gui/components/RolledSelectionList.cpp#L169-L179

View File

@ -463,8 +463,8 @@ static void RandomLevelSource_buildSurface_injection(RandomLevelSource_buildSurf
}
// No Block Tinting
template <typename T, typename S>
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) {
template <typename T>
static int32_t Tile_getColor_injection(__attribute__((unused)) std::function<int(T *, LevelSource *, int, int, int)> original, __attribute__((unused)) T *self, __attribute__((unused)) LevelSource *level_source, __attribute__((unused)) int x, __attribute__((unused)) int y, __attribute__((unused)) int z) {
return 0xffffff;
}
@ -796,10 +796,10 @@ void init_misc() {
}
// Fix Screen Rendering When GUI is Hidden
overwrite_virtual_calls(Screen_render, Screen_render_injection);
overwrite_calls(Screen_render, Screen_render_injection);
// Sanitize Username
overwrite_virtual_calls(LoginPacket_read, LoginPacket_read_injection);
overwrite_calls(LoginPacket_read, LoginPacket_read_injection);
// Fix RakNet::RakString Security Bug
overwrite_calls_manual((void *) RakNet_RakString_constructor, (void *) RakNet_RakString_injection);
@ -812,7 +812,7 @@ void init_misc() {
// Close Current Screen On Death To Prevent Bugs
if (feature_has("Close Current Screen On Death", server_disabled)) {
overwrite_virtual_calls(LocalPlayer_die, LocalPlayer_die_injection);
overwrite_calls(LocalPlayer_die, LocalPlayer_die_injection);
}
// Fix Furnace Not Checking Item Auxiliary When Inserting New Item
@ -875,7 +875,7 @@ void init_misc() {
// Change Grass Color
if (feature_has("Add Biome Colors To Grass", server_disabled)) {
patch_vtable(GrassTile_getColor, GrassTile_getColor_injection);
overwrite_virtual_calls(TallGrass_getColor, TallGrass_getColor_injection);
overwrite_calls(TallGrass_getColor, TallGrass_getColor_injection);
}
// Generate Caves
@ -885,11 +885,11 @@ void init_misc() {
// Disable Block Tinting
if (feature_has("Disable Block Tinting", server_disabled)) {
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);
overwrite_calls(GrassTile_getColor, Tile_getColor_injection<GrassTile>);
overwrite_calls(TallGrass_getColor, Tile_getColor_injection<TallGrass>);
overwrite_calls(StemTile_getColor, Tile_getColor_injection<StemTile>);
overwrite_calls(LeafTile_getColor, Tile_getColor_injection<LeafTile>);
overwrite_calls(LiquidTile_getColor, Tile_getColor_injection<LiquidTile>);
}
// Custom GUI Scale
@ -924,7 +924,7 @@ void init_misc() {
// Animation
overwrite_calls(ContainerMenu_constructor, ContainerMenu_injection);
overwrite_virtual_calls(ContainerMenu_destructor_complete, ContainerMenu_destructor_injection);
overwrite_calls(ContainerMenu_destructor_complete, ContainerMenu_destructor_injection);
}
patch_address((void *) 0x115b48, (void *) ChestTileEntity_shouldSave_injection);
@ -951,7 +951,7 @@ void init_misc() {
// Java Light Ramp
if (feature_has("Use Java Beta 1.3 Light Ramp", server_disabled)) {
overwrite_virtual_calls(Dimension_updateLightRamp, Dimension_updateLightRamp_injection);
overwrite_calls(Dimension_updateLightRamp, Dimension_updateLightRamp_injection);
}
// Fix used items transferring durability
@ -970,18 +970,18 @@ void init_misc() {
// Implement AppPlatform::readAssetFile So Translations Work
if (feature_has("Load Language Files", server_enabled)) {
overwrite_virtual_calls(AppPlatform_readAssetFile, AppPlatform_readAssetFile_injection);
overwrite_calls(AppPlatform_readAssetFile, AppPlatform_readAssetFile_injection);
}
// Fix Pause Menu
if (feature_has("Fix Pause Menu", server_disabled)) {
// Add Missing Buttons To Pause Menu
overwrite_virtual_calls(PauseScreen_init, PauseScreen_init_injection);
overwrite_calls(PauseScreen_init, PauseScreen_init_injection);
}
// Implement Crafting Remainders
overwrite_call((void *) 0x2e230, (void *) PaneCraftingScreen_craftSelectedItem_PaneCraftingScreen_recheckRecipes_injection);
overwrite_virtual_calls(Item_getCraftingRemainingItem, Item_getCraftingRemainingItem_injection);
overwrite_calls(Item_getCraftingRemainingItem, Item_getCraftingRemainingItem_injection);
// Replace 2011 std::sort With Optimized(TM) Code
if (feature_has("Optimized Chunk Sorting", server_enabled)) {

View File

@ -130,6 +130,6 @@ static void RakNetInstance_pingForHosts_injection(RakNetInstance_pingForHosts_t
void init_multiplayer() {
// Inject Code
if (feature_has("External Server Support", server_disabled)) {
overwrite_virtual_calls(RakNetInstance_pingForHosts, RakNetInstance_pingForHosts_injection);
overwrite_calls(RakNetInstance_pingForHosts, RakNetInstance_pingForHosts_injection);
}
}

View File

@ -78,7 +78,7 @@ static info_line info[] = {
.get_text = []() {
return std::string("Sound Data: ") + info_sound_data_state;
},
.button_url = MCPI_DOCUMENTATION "SOUND.md",
.button_url = MCPI_DOCUMENTATION "GETTING_STARTED.md#sound",
.button_text = "More Info"
},
};

View File

@ -167,7 +167,7 @@ void init_options() {
// Set Options
overwrite_calls(Options_initDefaultValue, Options_initDefaultValue_injection);
overwrite_virtual_calls(Minecraft_init, Minecraft_init_injection);
overwrite_calls(Minecraft_init, Minecraft_init_injection);
// Change Username
const char *username = get_username();

View File

@ -186,12 +186,12 @@ void _init_options_ui() {
// Info Button
if (feature_has("Add Reborn Info To Options", server_disabled)) {
// Add Button
overwrite_virtual_calls(OptionsScreen_init, OptionsScreen_init_injection);
overwrite_calls(OptionsScreen_init, OptionsScreen_init_injection);
// Position Button
overwrite_virtual_calls(OptionsScreen_setupPositions, OptionsScreen_setupPositions_injection);
overwrite_calls(OptionsScreen_setupPositions, OptionsScreen_setupPositions_injection);
// Handle Click
overwrite_virtual_calls(OptionsScreen_buttonClicked, OptionsScreen_buttonClicked_injection);
overwrite_calls(OptionsScreen_buttonClicked, OptionsScreen_buttonClicked_injection);
// Cleanup
overwrite_virtual_calls(OptionsScreen_removed, OptionsScreen_removed_injection);
overwrite_calls(OptionsScreen_removed, OptionsScreen_removed_injection);
}
}

View File

@ -568,7 +568,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
overwrite_virtual_calls(RakNet_RakPeer_IsBanned, RakNet_RakPeer_IsBanned_injection);
overwrite_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)) {

View File

@ -19,5 +19,5 @@ static Texture AppPlatform_linux_loadTexture_injection(__attribute__((unused)) A
// Init
void init_textures() {
// Disable Texture Loading
overwrite_virtual_calls(AppPlatform_linux_loadTexture, AppPlatform_linux_loadTexture_injection);
overwrite_calls(AppPlatform_linux_loadTexture, AppPlatform_linux_loadTexture_injection);
}

View File

@ -234,5 +234,5 @@ void init_textures() {
overwrite_call((void *) 0x53274, (void *) Textures_tick_glTexSubImage2D_injection);
// Load Textures
overwrite_virtual_calls(AppPlatform_linux_loadTexture, AppPlatform_linux_loadTexture_injection);
overwrite_calls(AppPlatform_linux_loadTexture, AppPlatform_linux_loadTexture_injection);
}

View File

@ -133,7 +133,7 @@ void init_title_screen() {
// Improved Classic Title Screen
if (feature_has("Improved Classic Title Screen", server_disabled)) {
// Add Options Button Back To Classic Start Screen
overwrite_virtual_calls(StartMenuScreen_init, StartMenuScreen_init_injection);
overwrite_calls(StartMenuScreen_init, StartMenuScreen_init_injection);
// Fix Classic UI Button Size
unsigned char classic_button_height_patch[4] = {0x18, 0x30, 0xa0, 0xe3}; // "mov r3, #0x18"
@ -157,7 +157,7 @@ void init_title_screen() {
patch_address((void *) &Strings::classic_create_button_text, (void *) "Quit");
// Add Functionality To Quit Button
overwrite_virtual_calls(StartMenuScreen_buttonClicked, StartMenuScreen_buttonClicked_injection);
overwrite_calls(StartMenuScreen_buttonClicked, StartMenuScreen_buttonClicked_injection);
}
// Add Splashes