From c0156336df4ea6db95f73e3efc675659f868984d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 20 Sep 2024 21:30:47 -0400 Subject: [PATCH] Modding Changes --- dependencies/symbol-processor/src | 2 +- media-layer/trampoline/src/guest/guest.cpp | 4 +- media-layer/trampoline/src/guest/guest.h | 2 +- media-layer/trampoline/src/host/host.h | 6 +- mods/include/mods/chat/chat.h | 4 +- mods/include/mods/input/key-list.h | 2 + mods/include/mods/misc/misc.h | 4 +- mods/include/mods/server/server_properties.h | 10 +- .../mods/text-input-box/TextInputBox.h | 11 +- .../mods/text-input-box/TextInputScreen.h | 29 ++- mods/include/mods/touch/touch.h | 2 +- mods/src/atlas/atlas.cpp | 14 +- mods/src/benchmark/benchmark.cpp | 4 +- mods/src/bucket/bucket.cpp | 22 +-- mods/src/cake/cake.cpp | 36 ++-- mods/src/camera/camera.cpp | 4 +- mods/src/chat/chat-internal.h | 4 +- mods/src/chat/chat.cpp | 20 +- mods/src/chat/ui.cpp | 96 +++++----- mods/src/game-mode/ui.cpp | 124 ++++++------- mods/src/input/keys.cpp | 2 +- mods/src/input/misc.cpp | 4 +- mods/src/input/toggle.cpp | 8 +- mods/src/misc/api.cpp | 8 +- mods/src/misc/misc.cpp | 4 +- mods/src/misc/ui.cpp | 8 +- mods/src/multidraw/glue.cpp | 2 +- mods/src/multidraw/storage.cpp | 2 +- mods/src/multidraw/storage.h | 6 +- mods/src/options/info.cpp | 22 +-- mods/src/options/options.cpp | 14 +- mods/src/options/ui.cpp | 9 +- mods/src/readdir/readdir.cpp | 4 +- mods/src/screenshot/screenshot.cpp | 4 +- mods/src/server/server.cpp | 46 ++--- mods/src/server/server_properties.cpp | 20 +- mods/src/sign/sign.cpp | 2 +- mods/src/skin/loader.cpp | 12 +- mods/src/skin/skin.cpp | 4 +- mods/src/sound/repository.cpp | 4 +- mods/src/text-input-box/TextInputBox.cpp | 56 +++--- mods/src/text-input-box/TextInputScreen.cpp | 80 +++----- mods/src/textures/lava.cpp | 174 +++++++++--------- mods/src/textures/textures.cpp | 8 +- mods/src/title-screen/title-screen.cpp | 6 +- mods/src/title-screen/welcome.cpp | 12 +- mods/src/touch/touch.cpp | 4 +- symbols/CMakeLists.txt | 2 - symbols/src/api/ConnectedClient.def | 2 + ...AppPlatform_readAssetFile_return_value.def | 4 +- symbols/src/item/ItemInstance.def | 2 + symbols/src/level/DistanceChunkSorter.def | 2 + symbols/src/level/LevelSettings.def | 4 +- symbols/src/level/LevelSummary.def | 2 + symbols/src/misc/AABB.def | 2 + symbols/src/misc/HitResult.def | 4 +- symbols/src/misc/Vec3.def | 4 +- .../src/network/raknet/RakNet_RakNetGUID.def | 7 +- .../network/raknet/RakNet_SystemAddress.def | 6 +- symbols/src/recipes/Recipes_Type.def | 4 +- symbols/src/textures/Texture.def | 4 +- 61 files changed, 501 insertions(+), 473 deletions(-) diff --git a/dependencies/symbol-processor/src b/dependencies/symbol-processor/src index 2a63f1ff..5d2b146b 160000 --- a/dependencies/symbol-processor/src +++ b/dependencies/symbol-processor/src @@ -1 +1 @@ -Subproject commit 2a63f1ff521087f3faf23bf281503cc07a50d2df +Subproject commit 5d2b146b08f48bc0e185d224eb69cb718c62bf72 diff --git a/media-layer/trampoline/src/guest/guest.cpp b/media-layer/trampoline/src/guest/guest.cpp index e48cadc9..672cdb51 100644 --- a/media-layer/trampoline/src/guest/guest.cpp +++ b/media-layer/trampoline/src/guest/guest.cpp @@ -8,7 +8,7 @@ // Syscall Method static uint32_t trampoline_syscall(const uint32_t id, const uint32_t length, const unsigned char *args) { // Make Syscall - long ret = syscall(TRAMPOLINE_SYSCALL, id, length, args); + const long ret = syscall(TRAMPOLINE_SYSCALL, id, length, args); if (ret == -1) { // Error ERR("Trampoline Error: %s", strerror(errno)); @@ -23,7 +23,7 @@ static int get_pipe(const char *env) { if (value == nullptr) { IMPOSSIBLE(); } - std::string str = value; + const std::string str = value; return std::stoi(str); } static uint32_t trampoline_pipe(const uint32_t id, const bool allow_early_return, const uint32_t length, const unsigned char *args) { diff --git a/media-layer/trampoline/src/guest/guest.h b/media-layer/trampoline/src/guest/guest.h index 7a7cf636..0ac1ab41 100644 --- a/media-layer/trampoline/src/guest/guest.h +++ b/media-layer/trampoline/src/guest/guest.h @@ -25,7 +25,7 @@ struct copy_array { this->size = length * sizeof(T); this->data = arr; } - copy_array(const char *str) { + explicit copy_array(const char *str) { this->size = str != nullptr ? (strlen(str) + 1) : 0; this->data = str; } diff --git a/media-layer/trampoline/src/host/host.h b/media-layer/trampoline/src/host/host.h index da4b91e7..6edc79fb 100644 --- a/media-layer/trampoline/src/host/host.h +++ b/media-layer/trampoline/src/host/host.h @@ -3,7 +3,7 @@ #include "../common/common.h" // Trampoline Function -extern "C" std::remove_pointer::type trampoline; +extern "C" std::remove_pointer_t trampoline; // Macro typedef uint32_t handler_t(trampoline_writer_t writer, const unsigned char *args); @@ -17,9 +17,9 @@ __attribute__((visibility("internal"))) void _add_handler(unsigned char id, hand __attribute__((unused)) TrampolineArguments args(raw_args); \ static typeof(name) *func = name; -// Arguemnts +// Arguments struct TrampolineArguments { - TrampolineArguments(const unsigned char *args) { + explicit TrampolineArguments(const unsigned char *args) { this->raw_args = args; this->position = 0; } diff --git a/mods/include/mods/chat/chat.h b/mods/include/mods/chat/chat.h index 85885b8e..1892b003 100644 --- a/mods/include/mods/chat/chat.h +++ b/mods/include/mods/chat/chat.h @@ -10,6 +10,6 @@ extern "C" { std::string chat_send_api_command(const Minecraft *minecraft, const std::string &str); // Override using the HOOK() macro to provide customized chat behavior. -void chat_send_message(ServerSideNetworkHandler *server_side_network_handler, char *username, char *message); -void chat_handle_packet_send(Minecraft *minecraft, ChatPacket *packet); +void chat_send_message(ServerSideNetworkHandler *server_side_network_handler, const char *username, const char *message); +void chat_handle_packet_send(const Minecraft *minecraft, ChatPacket *packet); } diff --git a/mods/include/mods/input/key-list.h b/mods/include/mods/input/key-list.h index a01fdbec..38252a04 100644 --- a/mods/include/mods/input/key-list.h +++ b/mods/include/mods/input/key-list.h @@ -2,7 +2,9 @@ KEY(BACKSPACE, 0x8) KEY(DELETE, 0x2e) KEY(LEFT, 0x25) +KEY(UP, 0x26) KEY(RIGHT, 0x27) +KEY(DOWN, 0x28) KEY(F1, 0x70) KEY(F2, 0x71) KEY(F3, 0x72) diff --git a/mods/include/mods/misc/misc.h b/mods/include/mods/misc/misc.h index 17733648..242e8e1f 100644 --- a/mods/include/mods/misc/misc.h +++ b/mods/include/mods/misc/misc.h @@ -6,8 +6,8 @@ #include extern "C" { -int32_t misc_get_real_selected_slot(Player *player); -void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height); +int32_t misc_get_real_selected_slot(const Player *player); +void misc_render_background(int color, const Minecraft *minecraft, int x, int y, int width, int height); extern bool is_in_chat; diff --git a/mods/include/mods/server/server_properties.h b/mods/include/mods/server/server_properties.h index 041817ac..c1544dfc 100644 --- a/mods/include/mods/server/server_properties.h +++ b/mods/include/mods/server/server_properties.h @@ -5,14 +5,12 @@ #include class ServerProperties { - -private: std::map properties; public: - void load(std::istream& fstream); + void load(std::istream &stream); - std::string get_string(std::string const& name, std::string const& def); - int get_int(std::string const& name, std::string const& def); - bool get_bool(std::string const& name, std::string const& def); + [[nodiscard]] std::string get_string(const std::string &name, const std::string &def) const; + [[nodiscard]] int get_int(const std::string &name, const std::string &def) const; + [[nodiscard]] bool get_bool(const std::string &name, const std::string &def) const; }; \ No newline at end of file diff --git a/mods/include/mods/text-input-box/TextInputBox.h b/mods/include/mods/text-input-box/TextInputBox.h index dbf4d505..db99c302 100644 --- a/mods/include/mods/text-input-box/TextInputBox.h +++ b/mods/include/mods/text-input-box/TextInputBox.h @@ -3,22 +3,23 @@ #include struct TextInputBox { - static TextInputBox *create(const std::string &placeholder = "", const std::string &text = ""); + explicit TextInputBox(const std::string &placeholder = "", const std::string &text = ""); + ~TextInputBox(); - GuiComponent super; + GuiComponent *component; void setSize(int x, int y, int width = 200, int height = 12); void init(Font *pFont); void setEnabled(bool bEnabled); void keyPressed(int key); - void charPressed(int chr); + void charPressed(int k); void render(); void tick(); void setFocused(bool b); void onClick(int x, int y); - [[nodiscard]] bool clicked(int x, int y) const; + [[nodiscard]] bool clicked(int xPos, int yPos) const; [[nodiscard]] std::string getText() const; - void setText(std::string text); + void setText(const std::string &text); [[nodiscard]] bool isFocused() const; void setMaxLength(int max_length); diff --git a/mods/include/mods/text-input-box/TextInputScreen.h b/mods/include/mods/text-input-box/TextInputScreen.h index c3c5ada2..414a7123 100644 --- a/mods/include/mods/text-input-box/TextInputScreen.h +++ b/mods/include/mods/text-input-box/TextInputScreen.h @@ -5,8 +5,31 @@ #include struct TextInputScreen { - Screen super; - std::vector *m_textInputs; + std::vector *m_textInputs = nullptr; - static void setup(Screen_vtable *vtable); + template + static void setup(Screen_vtable *vtable) { +#define PATCH_VTABLE(name) \ + static Screen_##name##_t original_##name = vtable->name; \ + vtable->name = [](Screen *super, auto... args) { \ + original_##name(super, std::forward(args)...); \ + T *self = (T *) super; \ + self->data.text_input.name(std::forward(args)...); \ + } + PATCH_VTABLE(keyPressed); + PATCH_VTABLE(keyboardNewChar); + PATCH_VTABLE(mouseClicked); + PATCH_VTABLE(render); + PATCH_VTABLE(init); + PATCH_VTABLE(removed); +#undef PATCH_VTABLE + } + +private: + void keyPressed(int key) const; + void keyboardNewChar(char key) const; + void mouseClicked(int x, int y, int param_1) const; + void render(int x, int y, float param_1) const; + void init(); + void removed() const; }; diff --git a/mods/include/mods/touch/touch.h b/mods/include/mods/touch/touch.h index d897efcc..f959e2ac 100644 --- a/mods/include/mods/touch/touch.h +++ b/mods/include/mods/touch/touch.h @@ -4,5 +4,5 @@ extern int touch_gui; extern "C" { -Button *touch_create_button(int id, std::string text); +Button *touch_create_button(int id, const std::string &text); } \ No newline at end of file diff --git a/mods/src/atlas/atlas.cpp b/mods/src/atlas/atlas.cpp index 8332354a..0cd2bf35 100644 --- a/mods/src/atlas/atlas.cpp +++ b/mods/src/atlas/atlas.cpp @@ -7,9 +7,9 @@ #include // Fix Grass And Leaves Inventory Rendering When The gui_blocks Atlas Is Disabled -static void ItemRenderer_renderGuiItemCorrect_injection_one(ItemRenderer_renderGuiItemCorrect_t original, Font *font, Textures *textures, const ItemInstance *item_instance, int32_t param_1, int32_t param_2) { - int32_t leaves_id = Tile::leaves->id; - int32_t grass_id = Tile::grass->id; +static void ItemRenderer_renderGuiItemCorrect_injection_one(ItemRenderer_renderGuiItemCorrect_t original, Font *font, Textures *textures, const ItemInstance *item_instance, const int32_t param_1, const int32_t param_2) { + const int32_t leaves_id = Tile::leaves->id; + const int32_t grass_id = Tile::grass->id; // Replace Rendered Item With Carried Variant ItemInstance carried_item_instance; bool use_carried = false; @@ -24,7 +24,7 @@ static void ItemRenderer_renderGuiItemCorrect_injection_one(ItemRenderer_renderG } // Fix Toolbar Rendering - GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST); + const GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST); // Call Original Method @@ -57,7 +57,7 @@ static void Tesselator_color_injection(Tesselator_color_t original, Tesselator * // Call Original Method original(tesselator, r, g, b, a); } -static void Tesselator_begin_injection(Tesselator_begin_t original, Tesselator *tesselator, int32_t mode) { +static void Tesselator_begin_injection(Tesselator_begin_t original, Tesselator *tesselator, const int32_t mode) { // Call Original Method original(tesselator, mode); @@ -74,7 +74,7 @@ static void InventoryPane_renderBatch_Tesselator_color_injection(Tesselator *tes // Enable Item Color Fix item_color_fix_mode = 2; } -static void ItemRenderer_renderGuiItem_two_injection_one(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, const ItemInstance *item_instance, float param_1, float param_2, float param_3, float param_4, bool param_5) { +static void ItemRenderer_renderGuiItem_two_injection_one(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, const ItemInstance *item_instance, const float param_1, const float param_2, const float param_3, const float param_4, const bool param_5) { // Call Original Method original(font, textures, item_instance, param_1, param_2, param_3, param_4, param_5); @@ -92,7 +92,7 @@ static void FurnaceScreen_render_ItemRenderer_renderGuiItem_one_injection(Font * // Smooth Scrolling static float target_x; static float target_y; -static void ItemRenderer_renderGuiItem_two_injection_two(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, const ItemInstance *item_instance, float x, float y, float w, float h, bool param_5) { +static void ItemRenderer_renderGuiItem_two_injection_two(ItemRenderer_renderGuiItem_two_t original, Font *font, Textures *textures, const ItemInstance *item_instance, const float x, const float y, const float w, const float h, const bool param_5) { target_x = x; target_y = y; original(font, textures, item_instance, x, y, w, h, param_5); diff --git a/mods/src/benchmark/benchmark.cpp b/mods/src/benchmark/benchmark.cpp index c51878b4..9c1686bf 100644 --- a/mods/src/benchmark/benchmark.cpp +++ b/mods/src/benchmark/benchmark.cpp @@ -40,7 +40,7 @@ static void start_world(Minecraft *minecraft) { minecraft->selectLevel(name, name, settings); // Open ProgressScreen - ProgressScreen *screen = new ProgressScreen; + ProgressScreen *screen = ProgressScreen::allocate(); ALLOC_CHECK(screen); screen = screen->constructor(); minecraft->setScreen((Screen *) screen); @@ -54,7 +54,7 @@ static void handle_swap_buffers() { // Track Ticks static unsigned long long int ticks = 0; -static void Minecraft_tick_injection(__attribute__((unused)) Minecraft *minecraft) { +static void Minecraft_tick_injection(__attribute__((unused)) const Minecraft *minecraft) { ticks++; } diff --git a/mods/src/bucket/bucket.cpp b/mods/src/bucket/bucket.cpp index c8736fab..dab3b6ad 100644 --- a/mods/src/bucket/bucket.cpp +++ b/mods/src/bucket/bucket.cpp @@ -184,9 +184,9 @@ CUSTOM_VTABLE(bucket, FoodItem) { } // Create Items -static FoodItem *create_bucket(int32_t id, int32_t texture_x, int32_t texture_y, std::string name) { +static FoodItem *create_bucket(const int32_t id, int32_t texture_x, int32_t texture_y, std::string name) { // Construct - FoodItem *item = new FoodItem; + FoodItem *item = FoodItem::allocate(); ALLOC_CHECK(item); Item_constructor->get(false)((Item *) item, id); // FoodItem's Constructor Was Inlined @@ -253,7 +253,7 @@ static HitResult Mob_pick_Level_clip_injection(Level *level, const Vec3 ¶m_1 // Call Original Method return level->clip(param_1, param_2, is_holding_bucket, clip_hitboxes); } -static void handle_tick(Minecraft *minecraft) { +static void handle_tick(const Minecraft *minecraft) { LocalPlayer *player = minecraft->player; if (player != nullptr) { // Get Selected Slot @@ -261,14 +261,14 @@ static void handle_tick(Minecraft *minecraft) { Inventory *inventory = player->inventory; // Get Item - ItemInstance *inventory_item = inventory->getItem(selected_slot); + const ItemInstance *inventory_item = inventory->getItem(selected_slot); // Check is_holding_bucket = inventory_item != nullptr && inventory_item->id == bucket->id && inventory_item->auxiliary == 0; } } // Prevent Breaking Liquid -static bool is_calm_liquid(int32_t id) { +static bool is_calm_liquid(const int32_t id) { if (id == Tile::calmWater->id) { return true; } else if (id == Tile::calmLava->id) { @@ -277,14 +277,14 @@ static bool is_calm_liquid(int32_t id) { return false; } } -static void Minecraft_handleMouseDown_injection(Minecraft_handleMouseDown_t original, Minecraft *minecraft, int param_1, bool can_destroy) { +static void Minecraft_handleMouseDown_injection(Minecraft_handleMouseDown_t original, Minecraft *minecraft, const int param_1, bool can_destroy) { // Check Level *level = minecraft->level; if (level != nullptr) { int32_t x = minecraft->hit_result.x; int32_t y = minecraft->hit_result.y; int32_t z = minecraft->hit_result.z; - int32_t tile = level->getTile(x, y, z); + const int32_t tile = level->getTile(x, y, z); if (is_calm_liquid(tile)) { can_destroy = false; } @@ -297,9 +297,9 @@ static void Minecraft_handleMouseDown_injection(Minecraft_handleMouseDown_t orig // Custom Crafting Recipes static void Recipes_injection(Recipes *recipes) { // Add - Recipes_Type type1 = { - .item = 0, - .tile = 0, + constexpr Recipes_Type type1 = { + .item = nullptr, + .tile = nullptr, .instance = { .count = 3, .id = 265, @@ -314,7 +314,7 @@ static void Recipes_injection(Recipes *recipes) { }; std::string line1 = "# #"; std::string line2 = " # "; - std::vector types = {type1}; + std::vector types = {type1}; recipes->addShapedRecipe_2(result, line1, line2, types); } diff --git a/mods/src/cake/cake.cpp b/mods/src/cake/cake.cpp index ea7128fd..c4f9333e 100644 --- a/mods/src/cake/cake.cpp +++ b/mods/src/cake/cake.cpp @@ -16,7 +16,7 @@ static std::string Cake_getDescriptionId(__attribute__((unused)) Tile *tile) { } // Textures -static int Cake_getTexture2(__attribute__((unused)) Tile *tile, int face, __attribute__((unused)) int data) { +static int Cake_getTexture2(__attribute__((unused)) Tile *tile, const int face, __attribute__((unused)) int data) { if (face == 1) { // Top texture return 121; @@ -28,10 +28,10 @@ static int Cake_getTexture2(__attribute__((unused)) Tile *tile, int face, __attr return 122; } -static int Cake_getTexture3(__attribute__((unused)) Tile *tile, LevelSource *level, int x, int y, int z, int face) { +static int Cake_getTexture3(__attribute__((unused)) Tile *tile, LevelSource *level, int x, int y, int z, const int face) { // Eaten face if (face == 3) { - int data = level->getData(x, y, z); + const int data = level->getData(x, y, z); if (data != 0 && data < 6) { // Sliced texture return 123; @@ -69,7 +69,7 @@ static AABB *Cake_getAABB(Tile *tile, Level *level, int x, int y, int z) { // Get the size of the slices int data = level->getData(x, y, z); if (data >= 6) data = 0; - float slice_size = (1.0 / 7.0) * (float) data; + const float slice_size = (1.0 / 7.0) * (float) data; // Corner 1 AABB *aabb = &tile->aabb; @@ -90,7 +90,7 @@ static void Cake_updateShape(Tile *tile, LevelSource *level, int x, int y, int z int data = level->getData(x, y, z); if (data >= 6) data = 0; // Get slice amount - float slice_size = (1.0 / 7.0) * (float) data; + const float slice_size = (1.0 / 7.0) * (float) data; tile->setShape( CAKE_LEN, 0.0, CAKE_LEN, 1.0 - CAKE_LEN, 0.5, (1.0 - CAKE_LEN) - slice_size @@ -116,7 +116,7 @@ static int Cake_use(__attribute__((unused)) Tile *tile, Level *level, int x, int // Makes the cakes static void make_cake() { // Construct - cake = new Tile; + cake = Tile::allocate(); ALLOC_CHECK(cake); int texture = 122; cake->constructor(92, texture, Material::dirt); @@ -170,9 +170,9 @@ static void Inventory_setupDefault_FillingContainer_addItem_call_injection(Filli // Recipe (only when buckets are enabled) static void Recipes_injection(Recipes *recipes) { // Sugar - Recipes_Type sugar = { - .item = 0, - .tile = 0, + constexpr Recipes_Type sugar = { + .item = nullptr, + .tile = nullptr, .instance = { .count = 1, .id = 353, @@ -181,9 +181,9 @@ static void Recipes_injection(Recipes *recipes) { .letter = 's' }; // Wheat - Recipes_Type wheat = { - .item = 0, - .tile = 0, + constexpr Recipes_Type wheat = { + .item = nullptr, + .tile = nullptr, .instance = { .count = 1, .id = 296, @@ -192,9 +192,9 @@ static void Recipes_injection(Recipes *recipes) { .letter = 'w' }; // Eggs - Recipes_Type eggs = { - .item = 0, - .tile = 0, + constexpr Recipes_Type eggs = { + .item = nullptr, + .tile = nullptr, .instance = { .count = 1, .id = 344, @@ -203,9 +203,9 @@ static void Recipes_injection(Recipes *recipes) { .letter = 'e' }; // Milk - Recipes_Type milk = { - .item = 0, - .tile = 0, + constexpr Recipes_Type milk = { + .item = nullptr, + .tile = nullptr, .instance = { .count = 1, .id = 325, diff --git a/mods/src/camera/camera.cpp b/mods/src/camera/camera.cpp index fb4c60ee..4bdcb577 100644 --- a/mods/src/camera/camera.cpp +++ b/mods/src/camera/camera.cpp @@ -16,7 +16,7 @@ static EntityRenderDispatcher *EntityRenderDispatcher_injection(EntityRenderDisp original(dispatcher); // Register TripodCameraRenderer - TripodCameraRenderer *renderer = new TripodCameraRenderer; + TripodCameraRenderer *renderer = TripodCameraRenderer::allocate(); ALLOC_CHECK(renderer); renderer->constructor(); dispatcher->assign((unsigned char) 0x5, (EntityRenderer *) renderer); @@ -25,7 +25,7 @@ static EntityRenderDispatcher *EntityRenderDispatcher_injection(EntityRenderDisp } // Display Smoke From TripodCamera Higher -static void TripodCamera_tick_Level_addParticle_call_injection(Level *level, const std::string &particle, float x, float y, float z, float deltaX, float deltaY, float deltaZ, int count) { +static void TripodCamera_tick_Level_addParticle_call_injection(Level *level, const std::string &particle, float x, const float y, float z, float deltaX, float deltaY, float deltaZ, int count) { // Call Original Method level->addParticle(particle, x, y + 0.5, z, deltaX, deltaY, deltaZ, count); } diff --git a/mods/src/chat/chat-internal.h b/mods/src/chat/chat-internal.h index 7adb8eae..ce082724 100644 --- a/mods/src/chat/chat-internal.h +++ b/mods/src/chat/chat-internal.h @@ -8,10 +8,10 @@ #define MAX_CHAT_MESSAGE_LENGTH 256 // Message Prefix -__attribute__((visibility("internal"))) std::string _chat_get_prefix(char *username); +__attribute__((visibility("internal"))) std::string _chat_get_prefix(const char *username); // Queue Message For Sending -__attribute__((visibility("internal"))) void _chat_send_message(Minecraft *minecraft, const char *message); +__attribute__((visibility("internal"))) void _chat_send_message(const Minecraft *minecraft, const char *message); // Init Chat UI __attribute__((visibility("internal"))) void _init_chat_ui(); \ No newline at end of file diff --git a/mods/src/chat/chat.cpp b/mods/src/chat/chat.cpp index 1def7311..21e15de7 100644 --- a/mods/src/chat/chat.cpp +++ b/mods/src/chat/chat.cpp @@ -25,16 +25,16 @@ std::string chat_send_api_command(const Minecraft *minecraft, const std::string } // Send API Chat Command -static void send_api_chat_command(Minecraft *minecraft, const char *str) { +static void send_api_chat_command(const Minecraft *minecraft, const char *str) { const std::string command = std::string("chat.post(") + str + ")\n"; chat_send_api_command(minecraft, command); } // Send Message To Players -std::string _chat_get_prefix(char *username) { +std::string _chat_get_prefix(const char *username) { return std::string("<") + username + "> "; } -void chat_send_message(ServerSideNetworkHandler *server_side_network_handler, char *username, char *message) { +void chat_send_message(ServerSideNetworkHandler *server_side_network_handler, const char *username, const char *message) { std::string full_message = _chat_get_prefix(username) + message; char *raw_str = strdup(full_message.c_str()); ALLOC_CHECK(raw_str); @@ -44,7 +44,7 @@ void chat_send_message(ServerSideNetworkHandler *server_side_network_handler, ch server_side_network_handler->displayGameMessage(full_message); } // Handle Chat packet Send -void chat_handle_packet_send(Minecraft *minecraft, ChatPacket *packet) { +void chat_handle_packet_send(const Minecraft *minecraft, ChatPacket *packet) { RakNetInstance *rak_net_instance = minecraft->rak_net_instance; if (rak_net_instance->isServer()) { // Hosting Multiplayer @@ -58,8 +58,8 @@ void chat_handle_packet_send(Minecraft *minecraft, ChatPacket *packet) { } // Manually Send (And Loopback) ChatPacket -static void CommandServer_parse_CommandServer_dispatchPacket_injection(CommandServer *command_server, Packet *packet) { - Minecraft *minecraft = command_server->minecraft; +static void CommandServer_parse_CommandServer_dispatchPacket_injection(const CommandServer *command_server, Packet *packet) { + const Minecraft *minecraft = command_server->minecraft; if (minecraft != nullptr) { chat_handle_packet_send(minecraft, (ChatPacket *) packet); } @@ -67,17 +67,17 @@ static void CommandServer_parse_CommandServer_dispatchPacket_injection(CommandSe // Handle ChatPacket Server-Side static void ServerSideNetworkHandler_handle_ChatPacket_injection(ServerSideNetworkHandler *server_side_network_handler, const RakNet_RakNetGUID &rak_net_guid, ChatPacket *chat_packet) { - Player *player = server_side_network_handler->getPlayer(rak_net_guid); + const Player *player = server_side_network_handler->getPlayer(rak_net_guid); if (player != nullptr) { const char *username = player->username.c_str(); const char *message = chat_packet->message.c_str(); - chat_send_message(server_side_network_handler, (char *) username, (char *) message); + chat_send_message(server_side_network_handler, username, message); } } // Send Message -void _chat_send_message(Minecraft *minecraft, const char *message) { - send_api_chat_command(minecraft, (char *) message); +void _chat_send_message(const Minecraft *minecraft, const char *message) { + send_api_chat_command(minecraft, message); } // Init diff --git a/mods/src/chat/ui.cpp b/mods/src/chat/ui.cpp index fd56f4e8..5b950473 100644 --- a/mods/src/chat/ui.cpp +++ b/mods/src/chat/ui.cpp @@ -15,14 +15,14 @@ static std::vector &get_history() { } // Structure -struct ChatScreen { - TextInputScreen super; +EXTEND_STRUCT(ChatScreen, Screen, struct { + TextInputScreen text_input; TextInputBox *chat; Button *send; int history_pos; -}; +}); CUSTOM_VTABLE(chat_screen, Screen) { - TextInputScreen::setup(vtable); + TextInputScreen::setup(vtable); // Init static std::vector local_history = {}; static Screen_init_t original_init = vtable->init; @@ -30,21 +30,21 @@ CUSTOM_VTABLE(chat_screen, Screen) { original_init(super); ChatScreen *self = (ChatScreen *) super; // Text Input - self->chat = TextInputBox::create(); - self->super.m_textInputs->push_back(self->chat); - self->chat->init(super->font); - self->chat->setFocused(true); - self->history_pos = get_history().size(); + self->data.chat = new TextInputBox; + self->data.text_input.m_textInputs->push_back(self->data.chat); + self->data.chat->init(super->font); + self->data.chat->setFocused(true); + self->data.history_pos = get_history().size(); local_history = get_history(); local_history.push_back(""); // Determine Max Length - std::string prefix = _chat_get_prefix(Strings::default_username); - int max_length = MAX_CHAT_MESSAGE_LENGTH - prefix.length(); - self->chat->setMaxLength(max_length); + const std::string prefix = _chat_get_prefix(Strings::default_username); + const int max_length = MAX_CHAT_MESSAGE_LENGTH - prefix.length(); + self->data.chat->setMaxLength(max_length); // Send Button - self->send = touch_create_button(1, "Send"); - super->rendered_buttons.push_back(self->send); - super->selectable_buttons.push_back(self->send); + self->data.send = touch_create_button(1, "Send"); + super->rendered_buttons.push_back(self->data.send); + super->selectable_buttons.push_back(self->data.send); // Hide Chat Messages is_in_chat = true; }; @@ -53,13 +53,13 @@ CUSTOM_VTABLE(chat_screen, Screen) { vtable->removed = [](Screen *super) { original_removed(super); is_in_chat = false; - ChatScreen *self = (ChatScreen *) super; - delete self->chat; - self->send->destructor_deleting(); + const ChatScreen *self = (ChatScreen *) super; + delete self->data.chat; + self->data.send->destructor_deleting(); }; // Rendering static Screen_render_t original_render = vtable->render; - vtable->render = [](Screen *super, int x, int y, float param_1) { + vtable->render = [](Screen *super, const int x, const int y, const float param_1) { // Background super->renderBackground(); // Render Chat @@ -71,46 +71,46 @@ CUSTOM_VTABLE(chat_screen, Screen) { static Screen_setupPositions_t original_setupPositions = vtable->setupPositions; vtable->setupPositions = [](Screen *super) { original_setupPositions(super); - ChatScreen *self = (ChatScreen *) super; - self->send->height = 24; - self->send->width = 40; - int x = 0; - int y = super->height - self->send->height; - int width = super->width - self->send->width; - self->chat->setSize(x, y, width, self->send->height); - self->send->y = super->height - self->send->height; - self->send->x = x + width; + const ChatScreen *self = (ChatScreen *) super; + self->data.send->height = 24; + self->data.send->width = 40; + constexpr int x = 0; + const int y = super->height - self->data.send->height; + const int width = super->width - self->data.send->width; + self->data.chat->setSize(x, y, width, self->data.send->height); + self->data.send->y = super->height - self->data.send->height; + self->data.send->x = x + width; }; // Key Presses static Screen_keyPressed_t original_keyPressed = vtable->keyPressed; - vtable->keyPressed = [](Screen *super, int key) { + vtable->keyPressed = [](Screen *super, const int key) { // Handle Enter ChatScreen *self = (ChatScreen *) super; - if (self->chat->isFocused()) { - if (key == 0x0d) { - if (self->chat->getText().length() > 0) { - std::string text = self->chat->getText(); + if (self->data.chat->isFocused()) { + if (key == MC_KEY_RETURN) { + if (self->data.chat->getText().length() > 0) { + const std::string text = self->data.chat->getText(); if (get_history().size() == 0 || text != get_history().back()) { get_history().push_back(text); } _chat_send_message(super->minecraft, text.c_str()); } super->minecraft->setScreen(nullptr); - } else if (key == 0x26) { + } else if (key == MC_KEY_UP) { // Up - local_history.at(self->history_pos) = self->chat->getText(); + local_history.at(self->data.history_pos) = self->data.chat->getText(); // Change - self->history_pos -= 1; - if (self->history_pos < 0) self->history_pos = local_history.size() - 1; - self->chat->setText(local_history.at(self->history_pos)); + self->data.history_pos -= 1; + if (self->data.history_pos < 0) self->data.history_pos = local_history.size() - 1; + self->data.chat->setText(local_history.at(self->data.history_pos)); return; - } else if (key == 0x28) { + } else if (key == MC_KEY_DOWN) { // Down - local_history.at(self->history_pos) = self->chat->getText(); + local_history.at(self->data.history_pos) = self->data.chat->getText(); // Change - self->history_pos += 1; - if (self->history_pos > int(local_history.size()) - 1) self->history_pos = 0; - self->chat->setText(local_history.at(self->history_pos)); + self->data.history_pos += 1; + if (self->data.history_pos > int(local_history.size()) - 1) self->data.history_pos = 0; + self->data.chat->setText(local_history.at(self->data.history_pos)); return; } } @@ -121,9 +121,9 @@ CUSTOM_VTABLE(chat_screen, Screen) { static Screen_buttonClicked_t original_buttonClicked = vtable->buttonClicked; vtable->buttonClicked = [](Screen *super, Button *button) { ChatScreen *self = (ChatScreen *) super; - if (button == self->send) { + if (button == self->data.send) { // Send - self->chat->setFocused(true); + self->data.chat->setFocused(true); super->keyPressed(0x0d); } else { // Call Original Method @@ -135,10 +135,10 @@ static Screen *create_chat_screen() { // Construct ChatScreen *screen = new ChatScreen; ALLOC_CHECK(screen); - screen->super.super.constructor(); + screen->super()->constructor(); // Set VTable - screen->super.super.vtable = get_chat_screen_vtable(); + screen->super()->vtable = get_chat_screen_vtable(); // Return return (Screen *) screen; @@ -146,7 +146,7 @@ static Screen *create_chat_screen() { // Init void _init_chat_ui() { - misc_run_on_game_key_press([](Minecraft *minecraft, int key) { + misc_run_on_game_key_press([](Minecraft *minecraft, const int key) { if (key == MC_KEY_t) { if (minecraft->isLevelGenerated() && minecraft->screen == nullptr) { minecraft->setScreen(create_chat_screen()); diff --git a/mods/src/game-mode/ui.cpp b/mods/src/game-mode/ui.cpp index e886ff99..99fe357e 100644 --- a/mods/src/game-mode/ui.cpp +++ b/mods/src/game-mode/ui.cpp @@ -17,17 +17,17 @@ #define CREATIVE_STR GAME_MODE_STR("Creative") // Structure -struct CreateWorldScreen { - TextInputScreen super; +EXTEND_STRUCT(CreateWorldScreen, Screen, struct { + TextInputScreen text_input; TextInputBox *name; TextInputBox *seed; Button *game_mode; Button *create; Button *back; -}; -static void create_world(Minecraft *minecraft, std::string name, bool is_creative, std::string seed); +}); +static void create_world(Minecraft *minecraft, std::string name, bool is_creative, std::string seed_str); CUSTOM_VTABLE(create_world_screen, Screen) { - TextInputScreen::setup(vtable); + TextInputScreen::setup(vtable); // Constants static int line_height = 8; static int bottom_padding = 4; @@ -43,42 +43,42 @@ CUSTOM_VTABLE(create_world_screen, Screen) { original_init(super); CreateWorldScreen *self = (CreateWorldScreen *) super; // Name - self->name = TextInputBox::create("World Name", "Unnamed world"); - self->super.m_textInputs->push_back(self->name); - self->name->init(super->font); - self->name->setFocused(true); + self->data.name = new TextInputBox("World Name", "Unnamed world"); + self->data.text_input.m_textInputs->push_back(self->data.name); + self->data.name->init(super->font); + self->data.name->setFocused(true); // Seed - self->seed = TextInputBox::create("Seed"); - self->super.m_textInputs->push_back(self->seed); - self->seed->init(super->font); - self->seed->setFocused(false); + self->data.seed = new TextInputBox("Seed"); + self->data.text_input.m_textInputs->push_back(self->data.seed); + self->data.seed->init(super->font); + self->data.seed->setFocused(false); // Game Mode - self->game_mode = touch_create_button(1, CREATIVE_STR); - super->rendered_buttons.push_back(self->game_mode); - super->selectable_buttons.push_back(self->game_mode); + self->data.game_mode = touch_create_button(1, CREATIVE_STR); + super->rendered_buttons.push_back(self->data.game_mode); + super->selectable_buttons.push_back(self->data.game_mode); // Create - self->create = touch_create_button(2, "Create"); - super->rendered_buttons.push_back(self->create); - super->selectable_buttons.push_back(self->create); + self->data.create = touch_create_button(2, "Create"); + super->rendered_buttons.push_back(self->data.create); + super->selectable_buttons.push_back(self->data.create); // Back - self->back = touch_create_button(3, "Back"); - super->rendered_buttons.push_back(self->back); - super->selectable_buttons.push_back(self->back); + self->data.back = touch_create_button(3, "Back"); + super->rendered_buttons.push_back(self->data.back); + super->selectable_buttons.push_back(self->data.back); }; // Removal static Screen_removed_t original_removed = vtable->removed; vtable->removed = [](Screen *super) { original_removed(super); CreateWorldScreen *self = (CreateWorldScreen *) super; - delete self->name; - delete self->seed; - self->game_mode->destructor_deleting(); - self->back->destructor_deleting(); - self->create->destructor_deleting(); + delete self->data.name; + delete self->data.seed; + self->data.game_mode->destructor_deleting(); + self->data.back->destructor_deleting(); + self->data.create->destructor_deleting(); }; // Rendering static Screen_render_t original_render = vtable->render; - vtable->render = [](Screen *super, int x, int y, float param_1) { + vtable->render = [](Screen *super, const int x, const int y, const float param_1) { // Background misc_render_background(80, super->minecraft, 0, 0, super->width, super->height); misc_render_background(32, super->minecraft, 0, content_y_offset_top, super->width, super->height - content_y_offset_top - content_y_offset_bottom); @@ -89,9 +89,9 @@ CUSTOM_VTABLE(create_world_screen, Screen) { 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; + const bool is_creative = self->data.game_mode->text == CREATIVE_STR; std::string description = is_creative ? Strings::creative_mode_description : Strings::survival_mode_description; - super->drawString(super->font, description, self->game_mode->x, self->game_mode->y + self->game_mode->height + description_padding, 0xa0a0a0); + super->drawString(super->font, description, self->data.game_mode->x, self->data.game_mode->y + self->data.game_mode->height + description_padding, 0xa0a0a0); }; // Positioning static Screen_setupPositions_t original_setupPositions = vtable->setupPositions; @@ -99,33 +99,33 @@ CUSTOM_VTABLE(create_world_screen, Screen) { original_setupPositions(super); CreateWorldScreen *self = (CreateWorldScreen *) super; // Height/Width - int width = 120; - int height = button_height; - self->create->width = self->back->width = self->game_mode->width = width; - int seed_width = self->game_mode->width; + constexpr int width = 120; + const int height = button_height; + self->data.create->width = self->data.back->width = self->data.game_mode->width = width; + int seed_width = self->data.game_mode->width; int name_width = width * 1.5f; - self->create->height = self->back->height = self->game_mode->height = height; - int text_box_height = self->game_mode->height; + self->data.create->height = self->data.back->height = self->data.game_mode->height = height; + int text_box_height = self->data.game_mode->height; // Find Center Y - int top = content_y_offset_top; - int bottom = super->height - content_y_offset_bottom; + const int top = content_y_offset_top; + const int bottom = super->height - content_y_offset_bottom; int center_y = ((bottom - top) / 2) + top; center_y -= (description_padding + line_height) / 2; // X/Y - self->create->y = self->back->y = super->height - bottom_padding - height; - self->create->x = self->game_mode->x = (super->width / 2) - inner_padding - width; - self->back->x = (super->width / 2) + inner_padding; - int seed_x = self->back->x; - int name_x = (super->width / 2) - (name_width / 2); - int name_y = center_y - inner_padding - height; - self->game_mode->y = center_y + inner_padding; - int seed_y = self->game_mode->y; + self->data.create->y = self->data.back->y = super->height - bottom_padding - height; + self->data.create->x = self->data.game_mode->x = (super->width / 2) - inner_padding - width; + self->data.back->x = (super->width / 2) + inner_padding; + const int seed_x = self->data.back->x; + const int name_x = (super->width / 2) - (name_width / 2); + const int name_y = center_y - inner_padding - height; + self->data.game_mode->y = center_y + inner_padding; + const int seed_y = self->data.game_mode->y; // Update Text Boxes - self->name->setSize(name_x, name_y, name_width, text_box_height); - self->seed->setSize(seed_x, seed_y, seed_width, text_box_height); + self->data.name->setSize(name_x, name_y, name_width, text_box_height); + self->data.seed->setSize(seed_x, seed_y, seed_width, text_box_height); }; // ESC - vtable->handleBackEvent = [](Screen *super, bool do_nothing) { + vtable->handleBackEvent = [](Screen *super, const bool do_nothing) { if (!do_nothing) { super->minecraft->screen_chooser.setScreen(5); } @@ -134,16 +134,16 @@ CUSTOM_VTABLE(create_world_screen, Screen) { // Button Click vtable->buttonClicked = [](Screen *super, Button *button) { CreateWorldScreen *self = (CreateWorldScreen *) super; - bool is_creative = self->game_mode->text == CREATIVE_STR; - if (button == self->game_mode) { + const bool is_creative = self->data.game_mode->text == CREATIVE_STR; + if (button == self->data.game_mode) { // Toggle Game Mode - self->game_mode->text = is_creative ? SURVIVAL_STR : CREATIVE_STR; - } else if (button == self->back) { + self->data.game_mode->text = is_creative ? SURVIVAL_STR : CREATIVE_STR; + } else if (button == self->data.back) { // Back super->handleBackEvent(false); - } else if (button == self->create) { + } else if (button == self->data.create) { // Create - create_world(super->minecraft, self->name->getText(), is_creative, self->seed->getText()); + create_world(super->minecraft, self->data.name->getText(), is_creative, self->data.seed->getText()); } }; } @@ -151,10 +151,10 @@ static Screen *create_create_world_screen() { // Construct CreateWorldScreen *screen = new CreateWorldScreen; ALLOC_CHECK(screen); - screen->super.super.constructor(); + screen->super()->constructor(); // Set VTable - screen->super.super.vtable = get_create_world_screen_vtable(); + screen->super()->vtable = get_create_world_screen_vtable(); // Return return (Screen *) screen; @@ -170,7 +170,7 @@ static std::string getUniqueLevelName(LevelStorageSource *source, const std::str maps.insert(ls.folder); } std::string out = in; - while (maps.find(out) != maps.end()) { + while (maps.contains(out)) { out += "-"; } return out; @@ -192,14 +192,14 @@ int get_seed_from_string(std::string str) { } return seed; } -static void create_world(Minecraft *minecraft, std::string name, bool is_creative, std::string seed_str) { +static void create_world(Minecraft *minecraft, std::string name, const bool is_creative, std::string seed_str) { // Get Seed - int seed = get_seed_from_string(std::move(seed_str)); + const int seed = get_seed_from_string(std::move(seed_str)); // Get Folder Name name = Util::stringTrim(name); std::string folder = ""; - for (char c : name) { + for (const char c : name) { if ( c >= ' ' && c <= '~' && c != '/' && @@ -233,7 +233,7 @@ static void create_world(Minecraft *minecraft, std::string name, bool is_creativ minecraft->hostMultiplayer(19132); // Open ProgressScreen - ProgressScreen *screen = new ProgressScreen; + ProgressScreen *screen = ProgressScreen::allocate(); ALLOC_CHECK(screen); screen = screen->constructor(); minecraft->setScreen((Screen *) screen); diff --git a/mods/src/input/keys.cpp b/mods/src/input/keys.cpp index 015022b7..84895326 100644 --- a/mods/src/input/keys.cpp +++ b/mods/src/input/keys.cpp @@ -6,7 +6,7 @@ #include "input-internal.h" // Translator -static int32_t sdl_key_to_minecraft_key_injection(Common_sdl_key_to_minecraft_key_t original, int32_t sdl_key) { +static int32_t sdl_key_to_minecraft_key_injection(Common_sdl_key_to_minecraft_key_t original, const int32_t sdl_key) { switch (sdl_key) { #define KEY(name, value) case SDLK_##name: return MC_KEY_##name; #include diff --git a/mods/src/input/misc.cpp b/mods/src/input/misc.cpp index 432e8c45..1d827462 100644 --- a/mods/src/input/misc.cpp +++ b/mods/src/input/misc.cpp @@ -23,7 +23,7 @@ static void _handle_back(Minecraft *minecraft) { } // Fix OptionsScreen Ignoring The Back Button -static bool OptionsScreen_handleBackEvent_injection(OptionsScreen *screen, bool do_nothing) { +static bool OptionsScreen_handleBackEvent_injection(OptionsScreen *screen, const bool do_nothing) { if (!do_nothing) { Minecraft *minecraft = screen->minecraft; minecraft->setScreen(nullptr); @@ -59,7 +59,7 @@ static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(Minecraft * } // Block UI Interaction When Mouse Is Locked -static void Gui_handleClick_injection(Gui_handleClick_t original, Gui *gui, int32_t param_2, int32_t param_3, int32_t param_4) { +static void Gui_handleClick_injection(Gui_handleClick_t original, Gui *gui, const int32_t param_2, const int32_t param_3, const int32_t param_4) { if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { // Call Original Method original(gui, param_2, param_3, param_4); diff --git a/mods/src/input/toggle.cpp b/mods/src/input/toggle.cpp index bd80019f..29493d1d 100644 --- a/mods/src/input/toggle.cpp +++ b/mods/src/input/toggle.cpp @@ -7,7 +7,7 @@ #include // Handle Toggle Options -static bool _handle_toggle_options(Minecraft *minecraft, int key) { +static bool _handle_toggle_options(Minecraft *minecraft, const int key) { Options *options = &minecraft->options; if (key == MC_KEY_F1) { // Toggle Hide GUI @@ -49,13 +49,13 @@ static void revert_rotation(Entity *entity) { } static bool is_front_facing = false; static LocalPlayer *stored_player = nullptr; -static void GameRenderer_setupCamera_injection(GameRenderer_setupCamera_t original, GameRenderer *game_renderer, float param_1, int param_2) { +static void GameRenderer_setupCamera_injection(GameRenderer_setupCamera_t original, GameRenderer *game_renderer, const float param_1, const int param_2) { // Get Objects Minecraft *minecraft = game_renderer->minecraft; stored_player = minecraft->player; // Check If In Third-Person - Options *options = &minecraft->options; + const Options *options = &minecraft->options; is_front_facing = (options->third_person == 2); // Invert Rotation @@ -71,7 +71,7 @@ static void GameRenderer_setupCamera_injection(GameRenderer_setupCamera_t origin revert_rotation((Entity *) stored_player); } } -static void ParticleEngine_render_injection(ParticleEngine_render_t original, ParticleEngine *particle_engine, Entity *entity, float param_2) { +static void ParticleEngine_render_injection(ParticleEngine_render_t original, ParticleEngine *particle_engine, Entity *entity, const float param_2) { // Invert Rotation if (is_front_facing && (Entity *) stored_player == entity) { invert_rotation((Entity *) stored_player); diff --git a/mods/src/misc/api.cpp b/mods/src/misc/api.cpp index aab11c44..48ee22fc 100644 --- a/mods/src/misc/api.cpp +++ b/mods/src/misc/api.cpp @@ -55,7 +55,7 @@ void misc_run_on_update(const std::function &func) { }); } void misc_run_on_tick(const std::function &func) { - overwrite_calls(Minecraft_tick, [func](Minecraft_tick_t original, Minecraft *self, int tick, int max_ticks) { + overwrite_calls(Minecraft_tick, [func](Minecraft_tick_t original, Minecraft *self, const int tick, const int max_ticks) { original(self, tick, max_ticks); func(self); }); @@ -93,7 +93,7 @@ void misc_run_on_language_setup(const std::function &func) { }); } void misc_run_on_game_key_press(const std::function &func) { - overwrite_calls(Gui_handleKeyPressed, [func](Gui_handleKeyPressed_t original, Gui *self, int key) { + overwrite_calls(Gui_handleKeyPressed, [func](Gui_handleKeyPressed_t original, Gui *self, const int key) { if (func(self->minecraft, key)) { return; } @@ -102,7 +102,7 @@ void misc_run_on_game_key_press(const std::function &fun } void misc_run_on_key_press(const std::function &func) { misc_run_on_game_key_press(func); - overwrite_calls(Screen_keyPressed, [func](Screen_keyPressed_t original, Screen *self, int key) { + overwrite_calls(Screen_keyPressed, [func](Screen_keyPressed_t original, Screen *self, const int key) { if (func(self->minecraft, key)) { return; } @@ -111,7 +111,7 @@ void misc_run_on_key_press(const std::function &func) { } // Render Fancy Background -void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height) { +void misc_render_background(int color, const Minecraft *minecraft, const int x, const int y, const int width, const int height) { // https://github.com/ReMinecraftPE/mcpe/blob/f0d65eaecec1b3fe9c2f2b251e114a890c54ab77/source/client/gui/components/RolledSelectionList.cpp#L169-L179 glColor4f(1, 1, 1, 1); minecraft->textures->loadAndBindTexture("gui/background.png"); diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index 8f1b4a3a..fe7afdd9 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -114,7 +114,7 @@ static int32_t FurnaceScreen_handleAddItem_injection(FurnaceScreen_handleAddItem } // Get Real Selected Slot -int32_t misc_get_real_selected_slot(Player *player) { +int32_t misc_get_real_selected_slot(const Player *player) { // Get Selected Slot const Inventory *inventory = player->inventory; int32_t selected_slot = inventory->selectedSlot; @@ -376,7 +376,7 @@ static void LocalPlayer_tick_injection(LocalPlayer_tick_t original, LocalPlayer const bool synced = self->getSharedFlag(FLAG_SNEAKING); if (real != synced) { // Send To Server - PlayerActionPacket *packet = new PlayerActionPacket; + PlayerActionPacket *packet = PlayerActionPacket::allocate(); Packet_constructor->get(false)((Packet *) packet); packet->vtable = PlayerActionPacket_vtable_base; packet->entity_id = self->id; diff --git a/mods/src/misc/ui.cpp b/mods/src/misc/ui.cpp index 5a55481c..1dd4f9b5 100644 --- a/mods/src/misc/ui.cpp +++ b/mods/src/misc/ui.cpp @@ -33,7 +33,7 @@ static void Gui_renderHearts_injection(Gui_renderHearts_t original, Gui *gui) { } #define PINK_HEART_FULL 70 #define PINK_HEART_HALF 79 -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) { +static void Gui_renderHearts_GuiComponent_blit_overlay_empty_injection(Gui *gui, const int32_t x1, const int32_t y1, const int32_t x2, const int32_t y2, const int32_t w1, const int32_t h1, const int32_t w2, const int32_t h2) { // Call Original Method get_blit_with_classic_hud_offset()((GuiComponent *) gui, x1, y1, x2, y2, w1, h1, w2, h2); // Render The Overlay @@ -47,7 +47,7 @@ static void Gui_renderHearts_GuiComponent_blit_overlay_empty_injection(Gui *gui, 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) { +static void Gui_renderHearts_GuiComponent_blit_overlay_hearts_injection(Gui *gui, const int32_t x1, const int32_t y1, const int32_t x2, const int32_t y2, const int32_t w1, const int32_t h1, const int32_t w2, const int32_t h2) { // Offset the overlay if (x2 == 52) { heal_amount_drawing += 2; @@ -100,7 +100,7 @@ static void Gui_tick_injection(Gui_tick_t original, Gui *gui) { } } // Trigger Reset Selected Item Text Timer On Slot Select -static void Inventory_selectSlot_injection(Inventory_selectSlot_t original, Inventory *inventory, int32_t slot) { +static void Inventory_selectSlot_injection(Inventory_selectSlot_t original, Inventory *inventory, const int32_t slot) { // Call Original Method original(inventory, slot); @@ -288,4 +288,4 @@ void _init_misc_ui() { uchar set_true_patch[] = {0x01, 0x30, 0xa0, 0x03}; // "moveq r3, #0x1" patch((void *) 0x4b93c, set_true_patch); } -} \ No newline at end of file +} diff --git a/mods/src/multidraw/glue.cpp b/mods/src/multidraw/glue.cpp index 737cdcaa..b9288328 100644 --- a/mods/src/multidraw/glue.cpp +++ b/mods/src/multidraw/glue.cpp @@ -15,7 +15,7 @@ // Setup static Storage *storage = nullptr; -static void setup_multidraw(int chunks, GLuint *buffers) { +static void setup_multidraw(const int chunks, GLuint *buffers) { delete storage; storage = new Storage(chunks); for (int i = 0; i < chunks; i++) { diff --git a/mods/src/multidraw/storage.cpp b/mods/src/multidraw/storage.cpp index 99732884..335f6464 100644 --- a/mods/src/multidraw/storage.cpp +++ b/mods/src/multidraw/storage.cpp @@ -37,7 +37,7 @@ void Storage::free_block(Block *block) { } // Find Block - std::vector::iterator it = std::find(used_blocks.begin(), used_blocks.end(), block); + std::vector::iterator it = std::ranges::find(used_blocks, block); if (it == used_blocks.end()) { return; } diff --git a/mods/src/multidraw/storage.h b/mods/src/multidraw/storage.h index ef4ae109..b056c335 100644 --- a/mods/src/multidraw/storage.h +++ b/mods/src/multidraw/storage.h @@ -26,14 +26,14 @@ struct Storage { Buffer *buffer; // Chunks - std::vector chunk_to_block; + std::vector chunk_to_block = {}; void upload(int chunk, ssize_t size, const void *data); // Management ssize_t total_size; ssize_t used_size; - std::vector free_blocks; - std::vector used_blocks; + std::vector free_blocks = {}; + std::vector used_blocks = {}; void free_block(Block *block); void recreate(ssize_t extra_size = 0); void check_fragmentation(); diff --git a/mods/src/options/info.cpp b/mods/src/options/info.cpp index 753cca58..e313b268 100644 --- a/mods/src/options/info.cpp +++ b/mods/src/options/info.cpp @@ -136,7 +136,7 @@ static void position_info(Font *font, int width, int height) { // Third Stage (Find Line Button Width) line_button_width = 0; for (int i = 0; i < info_size; i++) { - int text_width = font->width(info[i].button_text); + const int text_width = font->width(info[i].button_text); if (text_width > line_button_width) { line_button_width = text_width; } @@ -144,11 +144,11 @@ static void position_info(Font *font, int width, int height) { line_button_width += line_button_padding * 2; // Fourth Stage (Centering) - int info_height = y; - int info_width = info_text_width + padding + line_button_width; + const int info_height = y; + const int info_width = info_text_width + padding + line_button_width; content_height = height - content_y_offset_top - content_y_offset_bottom; - int info_y_offset = ((content_height - info_height) / 2) + content_y_offset_top; - int info_x_offset = (width - info_width) / 2; + const int info_y_offset = ((content_height - info_height) / 2) + content_y_offset_top; + const int info_x_offset = (width - info_width) / 2; for (int i = 0; i < info_size; i++) { positioned_info[i].button.x += info_x_offset; positioned_info[i].button.y += info_y_offset; @@ -195,9 +195,9 @@ CUSTOM_VTABLE(info_screen, Screen) { self->selectable_buttons.push_back(back); }; // Handle Back - vtable->handleBackEvent = [](Screen *self, bool do_nothing) { + vtable->handleBackEvent = [](Screen *self, const bool do_nothing) { if (!do_nothing) { - OptionsScreen *screen = new OptionsScreen; + OptionsScreen *screen = OptionsScreen::allocate(); ALLOC_CHECK(screen); screen->constructor(); self->minecraft->setScreen((Screen *) screen); @@ -206,7 +206,7 @@ CUSTOM_VTABLE(info_screen, Screen) { }; // Rendering static Screen_render_t original_render = vtable->render; - vtable->render = [](Screen *self, int x, int y, float param_1) { + vtable->render = [](Screen *self, const int x, const int y, const float param_1) { // Background misc_render_background(80, self->minecraft, 0, 0, self->width, self->height); misc_render_background(32, self->minecraft, 0, content_y_offset_top, self->width, content_height); @@ -224,7 +224,7 @@ CUSTOM_VTABLE(info_screen, Screen) { // Positioning vtable->setupPositions = [](Screen *self) { // Height/Width - int width = 120; + constexpr int width = 120; discord->width = back->width = width; discord->height = back->height = line_button_height; // X/Y @@ -257,7 +257,7 @@ CUSTOM_VTABLE(info_screen, Screen) { open_url(MCPI_DISCORD_INVITE); } else if (button->id >= INFO_ID_START) { // Open Info URL - int i = button->id - INFO_ID_START; + const int i = button->id - INFO_ID_START; open_url(info[i].button_url); } }; @@ -266,7 +266,7 @@ CUSTOM_VTABLE(info_screen, Screen) { // Create Screen Screen *_create_options_info_screen() { // Allocate - Screen *screen = new Screen; + Screen *screen = Screen::allocate(); ALLOC_CHECK(screen); screen->constructor(); diff --git a/mods/src/options/options.cpp b/mods/src/options/options.cpp index 2e97ace6..9aa7fcca 100644 --- a/mods/src/options/options.cpp +++ b/mods/src/options/options.cpp @@ -75,7 +75,7 @@ static void Minecraft_init_injection(Minecraft_init_t original, Minecraft *minec } // Smooth Lighting -static bool TileRenderer_tesselateBlockInWorld_injection(TileRenderer_tesselateBlockInWorld_t original, TileRenderer *tile_renderer, Tile *tile, int32_t x, int32_t y, int32_t z) { +static bool TileRenderer_tesselateBlockInWorld_injection(TileRenderer_tesselateBlockInWorld_t original, TileRenderer *tile_renderer, Tile *tile, const int32_t x, const int32_t y, const int32_t z) { // Set Variable Minecraft::useAmbientOcclusion = stored_options->ambient_occlusion; @@ -103,20 +103,20 @@ static void Options_save_Options_addOptionToSaveOutput_injection(Options *option // MCPI's OptionsFile::getOptionStrings is broken, this is the version in v0.7.0 static std::vector OptionsFile_getOptionStrings_injection(__attribute__((unused)) OptionsFile_getOptionStrings_t original, OptionsFile *options_file) { // Get options.txt Path - std::string path = options_file->options_txt_path; + const std::string path = options_file->options_txt_path; // Parse std::vector ret; FILE *stream = fopen(path.c_str(), "r"); - char line[128]; if (stream != nullptr) { + char line[128]; while (fgets(line, 0x80, stream) != nullptr) { - size_t sVar1 = strlen(line); + const size_t sVar1 = strlen(line); if (2 < sVar1) { std::stringstream string_stream(line); while (true) { std::string data; std::getline(string_stream, data, ':'); - int iVar2 = data.find_last_not_of(" \n\r\t"); + const int iVar2 = data.find_last_not_of(" \n\r\t"); data.erase(iVar2 + 1); if (data.length() == 0) { break; @@ -210,7 +210,7 @@ void init_options() { // Replace String patch_address((void *) &Strings::feedback_vibration_options_txt_name, (void *) "gfx_ao"); // Loading - unsigned char offset = (unsigned char) offsetof(Options, ambient_occlusion); + const unsigned char offset = (unsigned char) offsetof(Options, ambient_occlusion); unsigned char gfx_ao_loading_patch[4] = {offset, 0x10, 0x84, 0xe2}; // "add r1, r4, #OFFSET" patch((void *) 0x193b8, gfx_ao_loading_patch); // Saving @@ -223,7 +223,7 @@ void init_options() { // Replace String patch_address((void *) &Strings::gfx_lowquality_options_txt_name, (void *) "gfx_anaglyph"); // Loading - unsigned char offset = (unsigned char) offsetof(Options, anaglyph_3d); + const unsigned char offset = (unsigned char) offsetof(Options, anaglyph_3d); unsigned char gfx_anaglyph_loading_patch[4] = {offset, 0x10, 0x84, 0xe2}; // "add r1, r4, #OFFSET" patch((void *) 0x19400, gfx_anaglyph_loading_patch); // Disable Loading Side Effects diff --git a/mods/src/options/ui.cpp b/mods/src/options/ui.cpp index 24c4538a..1400b2ae 100644 --- a/mods/src/options/ui.cpp +++ b/mods/src/options/ui.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -22,9 +21,9 @@ static OptionButton *OptionsPane_unknown_toggle_creating_function_OptionButton_i } // 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) { +static void OptionsPane_unknown_toggle_creating_function_injection(OptionsPane_unknown_toggle_creating_function_t original, OptionsPane *options_pane, const uint32_t group_id, std::string *name_ptr, Options_Option *option) { // Modify - std::string name = *name_ptr; + const std::string name = *name_ptr; std::string new_name = name; if (name == "Fancy Graphics") { option = &Options_Option::GRAPHICS; @@ -97,7 +96,7 @@ static void OptionsScreen_init_injection(OptionsScreen_init_t original, OptionsS original(self); // Add Button - Touch_TButton *button = new Touch_TButton; + Touch_TButton *button = Touch_TButton::allocate(); ALLOC_CHECK(button); std::string name = "Reborn"; button->constructor(INFO_BUTTON_ID, name); @@ -109,7 +108,7 @@ static void OptionsScreen_setupPositions_injection(OptionsScreen_setupPositions_ original(self); // Find Button - Button *prevButton = nullptr; + const Button *prevButton = nullptr; Button *button = nullptr; for (Button *x : self->selectable_buttons) { if (x->id == INFO_BUTTON_ID) { diff --git a/mods/src/readdir/readdir.cpp b/mods/src/readdir/readdir.cpp index 077f565e..db5b53da 100644 --- a/mods/src/readdir/readdir.cpp +++ b/mods/src/readdir/readdir.cpp @@ -1,7 +1,5 @@ #define __USE_LARGEFILE64 -#include -#include #include // Minecraft: Pi Edition Was Not Compiled With 64-Bit Filesystem Support, So This Shims readdir() To Read Directories Properly @@ -9,7 +7,7 @@ #define FILENAME_SIZE 256 dirent *readdir(DIR *dirp) { - dirent64 *original = readdir64(dirp); + const dirent64 *original = readdir64(dirp); if (original == nullptr) { return nullptr; } diff --git a/mods/src/screenshot/screenshot.cpp b/mods/src/screenshot/screenshot.cpp index c2e6b940..d45c694c 100644 --- a/mods/src/screenshot/screenshot.cpp +++ b/mods/src/screenshot/screenshot.cpp @@ -31,7 +31,7 @@ static std::string get_screenshot(const std::string &filename) { } // Take Screenshot -static int save_png(const char *filename, unsigned char *pixels, int line_size, int width, int height) { +static int save_png(const char *filename, const unsigned char *pixels, const int line_size, const int width, const int height) { // Setup stbi_flip_vertically_on_write(1); @@ -110,7 +110,7 @@ void init_screenshot() { // Create Directory get_screenshot_dir(); // Take Screenshot On F2 - misc_run_on_key_press([](Minecraft *mc, int key) { + misc_run_on_key_press([](Minecraft *mc, const int key) { if (key == MC_KEY_F2) { screenshot_take(&mc->gui); return true; diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp index 45de3eef..88e951d8 100644 --- a/mods/src/server/server.cpp +++ b/mods/src/server/server.cpp @@ -50,7 +50,7 @@ ServerProperties &get_server_properties() { // Get World Name static std::string get_world_name() { - std::string name = get_server_properties().get_string("world-name", DEFAULT_WORLD_NAME); + const std::string name = get_server_properties().get_string("world-name", DEFAULT_WORLD_NAME); char *safe_name_c = to_cp437(name.c_str()); std::string safe_name = safe_name_c; free(safe_name_c); @@ -88,7 +88,7 @@ static void start_world(Minecraft *minecraft) { } // Open ProgressScreen - ProgressScreen *screen = new ProgressScreen; + ProgressScreen *screen = ProgressScreen::allocate(); ALLOC_CHECK(screen); screen = screen->constructor(); minecraft->setScreen((Screen *) screen); @@ -111,22 +111,22 @@ static std::vector get_players_in_level(Level *level) { } // Get Player's Username static std::string get_player_username(Player *player) { - std::string *username = &player->username; + const std::string *username = &player->username; char *safe_username_c = from_cp437(username->c_str()); std::string safe_username = safe_username_c; free(safe_username_c); return safe_username; } // Get Level From Minecraft -static Level *get_level(Minecraft *minecraft) { +static Level *get_level(const Minecraft *minecraft) { return minecraft->level; } // Find Players With Username And Run Callback typedef void (*player_callback_t)(Minecraft *minecraft, const std::string &username, Player *player); -static void find_players(Minecraft *minecraft, const std::string &target_username, player_callback_t callback, bool all_players) { +static void find_players(Minecraft *minecraft, const std::string &target_username, const player_callback_t callback, const bool all_players) { Level *level = get_level(minecraft); - std::vector players = get_players_in_level(level); + const std::vector players = get_players_in_level(level); bool found_player = false; for (std::size_t i = 0; i < players.size(); i++) { // Iterate Players @@ -151,19 +151,19 @@ static RakNet_SystemAddress get_system_address(RakNet_RakPeer *rak_peer, RakNet_ // Get SystemAddress return rak_peer->GetSystemAddressFromGuid(guid); } -static RakNet_RakPeer *get_rak_peer(Minecraft *minecraft) { +static RakNet_RakPeer *get_rak_peer(const Minecraft *minecraft) { return minecraft->rak_net_instance->peer; } -static char *get_rak_net_guid_ip(RakNet_RakPeer *rak_peer, RakNet_RakNetGUID guid) { +static char *get_rak_net_guid_ip(RakNet_RakPeer *rak_peer, const RakNet_RakNetGUID &guid) { RakNet_SystemAddress address = get_system_address(rak_peer, guid); // Get IP return address.ToString(false, '|'); } // Get IP From Player -static char *get_player_ip(Minecraft *minecraft, Player *player) { +static char *get_player_ip(const Minecraft *minecraft, Player *player) { RakNet_RakPeer *rak_peer = get_rak_peer(minecraft); - RakNet_RakNetGUID guid = get_rak_net_guid(player); + const RakNet_RakNetGUID guid = get_rak_net_guid(player); // Return return get_rak_net_guid_ip(rak_peer, guid); } @@ -206,17 +206,17 @@ static void list_callback(Minecraft *minecraft, const std::string &username, Pla static long long int get_time() { 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; + const long long int a = (long long int) ts.tv_nsec; + const long long int b = ((long long int) ts.tv_sec) * NANOSECONDS_IN_SECOND; return a + b; } static bool is_last_tick_time_set = false; static long long int last_tick_time; static double tps = 0; -static void Minecraft_tick_injection(__attribute__((unused)) Minecraft *minecraft) { - long long int time = get_time(); +static void Minecraft_tick_injection(__attribute__((unused)) const Minecraft *minecraft) { + const long long int time = get_time(); if (is_last_tick_time_set) { - long long int tick_time = time - last_tick_time; + const long long int tick_time = time - last_tick_time; tps = ((double) NANOSECONDS_IN_SECOND) / ((double) tick_time); } else { is_last_tick_time_set = true; @@ -225,7 +225,7 @@ static void Minecraft_tick_injection(__attribute__((unused)) Minecraft *minecraf } // Get ServerSideNetworkHandler From Minecraft -static ServerSideNetworkHandler *get_server_side_network_handler(Minecraft *minecraft) { +static ServerSideNetworkHandler *get_server_side_network_handler(const Minecraft *minecraft) { return (ServerSideNetworkHandler *) minecraft->network_handler; } @@ -289,18 +289,18 @@ static void handle_commands(Minecraft *minecraft) { static std::string help_command("help"); if (!is_whitelist() && data.rfind(ban_command, 0) == 0) { // IP-Ban Target Username - std::string ban_username = data.substr(ban_command.length()); + const std::string ban_username = data.substr(ban_command.length()); find_players(minecraft, ban_username, ban_callback, false); } else if (data == reload_command) { INFO("Reloading %s", is_whitelist() ? "Whitelist" : "Blacklist"); is_ip_in_blacklist(nullptr); } else if (data.rfind(kill_command, 0) == 0) { // Kill Target Username - std::string kill_username = data.substr(kill_command.length()); + const std::string kill_username = data.substr(kill_command.length()); find_players(minecraft, kill_username, kill_callback, false); } else if (data.rfind(say_command, 0) == 0) { // Format Message - std::string message = "[Server] " + data.substr(say_command.length()); + const std::string message = "[Server] " + data.substr(say_command.length()); char *safe_message = to_cp437(message.c_str()); std::string cpp_string = safe_message; // Post Message To Chat @@ -367,7 +367,7 @@ static bool is_ip_in_blacklist(const char *ip) { // Reload ips.clear(); // Check banned-ips.txt - std::string blacklist_file_path = get_blacklist_file(); + const std::string blacklist_file_path = get_blacklist_file(); std::ifstream blacklist_file(blacklist_file_path); if (blacklist_file) { if (blacklist_file.good()) { @@ -400,7 +400,7 @@ static bool is_ip_in_blacklist(const char *ip) { // Ban Players 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); + const bool ret = is_ip_in_blacklist(ip); if (is_whitelist()) { return !ret; } else { @@ -416,8 +416,8 @@ static Player *ServerSideNetworkHandler_onReady_ClientGeneration_ServerSideNetwo // Check If Player Is Null if (player != nullptr) { // Get Data - std::string *username = &player->username; - Minecraft *minecraft = server_side_network_handler->minecraft; + const std::string *username = &player->username; + const Minecraft *minecraft = server_side_network_handler->minecraft; RakNet_RakPeer *rak_peer = get_rak_peer(minecraft); char *ip = get_rak_net_guid_ip(rak_peer, guid); diff --git a/mods/src/server/server_properties.cpp b/mods/src/server/server_properties.cpp index 40948f15..1edfa0f1 100644 --- a/mods/src/server/server_properties.cpp +++ b/mods/src/server/server_properties.cpp @@ -4,33 +4,33 @@ static bool is_true(std::string const& val) { return (val == "true" || val == "yes" || val == "1"); } -void ServerProperties::load(std::istream& stream) { +void ServerProperties::load(std::istream &stream) { std::string line; while (std::getline(stream, line)) { if (line.length() > 0) { if (line[0] == '#') { continue; } - size_t i = line.find('='); + const size_t i = line.find('='); if (i == std::string::npos) { continue; } - properties.insert(std::pair(line.substr(0, i), line.substr(i + 1))); + properties.insert(std::pair(line.substr(0, i), line.substr(i + 1))); } } } -std::string ServerProperties::get_string(std::string const& name, std::string const& def) { - return properties.count(name) > 0 ? properties.at(name) : def; +std::string ServerProperties::get_string(const std::string &name, const std::string &def) const { + return properties.contains(name) ? properties.at(name) : def; } -int ServerProperties::get_int(std::string const& name, std::string const& def) { - return properties.count(name) > 0 ? std::stoi(properties.at(name)) : std::stoi(def); +int ServerProperties::get_int(const std::string &name, const std::string &def) const { + return properties.contains(name) ? std::stoi(properties.at(name)) : std::stoi(def); } -bool ServerProperties::get_bool(std::string const& name, std::string const& def) { - if (properties.count(name) > 0) { - std::string const& val = properties.at(name); +bool ServerProperties::get_bool(const std::string &name, const std::string &def) const { + if (properties.contains(name)) { + const std::string &val = properties.at(name); return is_true(val); } return is_true(def); diff --git a/mods/src/sign/sign.cpp b/mods/src/sign/sign.cpp index 0f469a37..1bf8e2c4 100644 --- a/mods/src/sign/sign.cpp +++ b/mods/src/sign/sign.cpp @@ -11,7 +11,7 @@ static void LocalPlayer_openTextEdit_injection(__attribute__((unused)) LocalPlayer_openTextEdit_t original, LocalPlayer *local_player, TileEntity *sign) { if (sign->type == 4) { Minecraft *minecraft = local_player->minecraft; - TextEditScreen *screen = new TextEditScreen; + TextEditScreen *screen = TextEditScreen::allocate(); ALLOC_CHECK(screen); screen = screen->constructor((SignTileEntity *) sign); minecraft->setScreen((Screen *) screen); diff --git a/mods/src/skin/loader.cpp b/mods/src/skin/loader.cpp index ff999c06..1415ee43 100644 --- a/mods/src/skin/loader.cpp +++ b/mods/src/skin/loader.cpp @@ -32,7 +32,7 @@ static void load_pending_skins(__attribute__((unused)) Minecraft *minecraft) { pthread_mutex_lock(&pending_skins_lock); // Loop - for (pending_skin &skin : get_pending_skins()) { + for (const pending_skin &skin : get_pending_skins()) { // Read PNG Info int width = 0, height = 0, channels = 0; stbi_uc *img = stbi_load_from_memory((unsigned char *) skin.data, skin.size, &width, &height, &channels, STBI_rgb_alpha); @@ -52,7 +52,7 @@ static void load_pending_skins(__attribute__((unused)) Minecraft *minecraft) { } // Free - for (pending_skin &skin : get_pending_skins()) { + for (const pending_skin &skin : get_pending_skins()) { free(skin.data); } @@ -80,10 +80,10 @@ struct loader_data { }; static void *loader_thread(void *user_data) { // Loader Data - loader_data *data = (loader_data *) user_data; + const loader_data *data = (loader_data *) user_data; // Download - std::string url = get_skin_server() + '/' + data->name + ".png"; + const std::string url = get_skin_server() + '/' + data->name + ".png"; int return_code; const char *command[] = {"wget", "-O", "-", url.c_str(), nullptr}; size_t output_size = 0; @@ -95,7 +95,7 @@ static void *loader_thread(void *user_data) { DEBUG("Downloaded Skin: %s", data->name.c_str()); // Add To Pending Skins - pending_skin skin; + pending_skin skin = {}; skin.texture_id = data->texture_id; skin.data = output; skin.size = (int) output_size; @@ -116,7 +116,7 @@ static void *loader_thread(void *user_data) { // Intercept Texture Creation static int32_t Textures_assignTexture_injection(Textures_assignTexture_t original, Textures *textures, const std::string &name, unsigned char *data) { // Call Original Method - int32_t id = original(textures, name, data); + const int32_t id = original(textures, name, data); // Load Skin if (starts_with(name.c_str(), "$")) { diff --git a/mods/src/skin/skin.cpp b/mods/src/skin/skin.cpp index 1e1407be..2fc8c259 100644 --- a/mods/src/skin/skin.cpp +++ b/mods/src/skin/skin.cpp @@ -18,8 +18,8 @@ static std::string base64_encode(const std::string &data) { '4', '5', '6', '7', '8', '9', '+', '/' }; - size_t in_len = data.size(); - size_t out_len = 4 * ((in_len + 2) / 3); + const size_t in_len = data.size(); + const size_t out_len = 4 * ((in_len + 2) / 3); std::string ret(out_len, '\0'); size_t i; char *p = const_cast(ret.c_str()); diff --git a/mods/src/sound/repository.cpp b/mods/src/sound/repository.cpp index 8383a656..b4473650 100644 --- a/mods/src/sound/repository.cpp +++ b/mods/src/sound/repository.cpp @@ -369,8 +369,8 @@ std::string _sound_pick(const std::string &sound) { void _sound_resolve_all() { const std::string source = _sound_get_source_file(); if (!source.empty()) { - for (auto &it : sound_repository) { - for (std::string &name : it.second) { + for (const std::pair> &it : sound_repository) { + for (const std::string &name : it.second) { // Zero Volume Prevents An OpenAL Source From Being Allocated While Still Resolving The Sound media_audio_play(source.c_str(), name.c_str(), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f); } diff --git a/mods/src/text-input-box/TextInputBox.cpp b/mods/src/text-input-box/TextInputBox.cpp index a84d4bb2..940fdfa1 100644 --- a/mods/src/text-input-box/TextInputBox.cpp +++ b/mods/src/text-input-box/TextInputBox.cpp @@ -3,29 +3,29 @@ #include #include -TextInputBox *TextInputBox::create(const std::string &placeholder, const std::string &text) { +TextInputBox::TextInputBox(const std::string &placeholder, const std::string &text) { // Construct - TextInputBox *self = new TextInputBox; - self->super.constructor(); + this->component = GuiComponent::allocate(); + this->component->constructor(); // Setup - self->m_xPos = 0; - self->m_yPos = 0; - self->m_width = 0; - self->m_height = 0; - self->m_placeholder = placeholder; - self->m_text = text; - self->m_bFocused = false; - self->m_bEnabled = true; - self->m_bCursorOn = true; - self->m_insertHead = 0; - self->m_lastFlashed = 0; - self->m_pFont = nullptr; - self->m_maxLength = -1; - self->m_scrollPos = 0; - - // Return - return self; + this->m_xPos = 0; + this->m_yPos = 0; + this->m_width = 0; + this->m_height = 0; + this->m_placeholder = placeholder; + this->m_text = text; + this->m_bFocused = false; + this->m_bEnabled = true; + this->m_bCursorOn = true; + this->m_insertHead = 0; + this->m_lastFlashed = 0; + this->m_pFont = nullptr; + this->m_maxLength = -1; + this->m_scrollPos = 0; +} +TextInputBox::~TextInputBox() { + component->destructor_deleting(); } void TextInputBox::setSize(const int x, const int y, const int width, const int height) { @@ -139,7 +139,7 @@ void TextInputBox::setFocused(const bool b) { } } -void TextInputBox::onClick(int x, int y) { +void TextInputBox::onClick(const int x, const int y) { setFocused(clicked(x, y)); } @@ -165,7 +165,7 @@ void TextInputBox::charPressed(const int k) { recalculateScroll(); } -static std::string get_rendered_text(Font *font, const int width, const int scroll_pos, std::string text) { +static std::string get_rendered_text(Font *font, const int width, const int scroll_pos, const std::string &text) { std::string rendered_text = text.substr(scroll_pos); const int max_width = width - (PADDING * 2); while (font->width(rendered_text) > max_width) { @@ -177,8 +177,8 @@ static std::string get_rendered_text(Font *font, const int width, const int scro static char CURSOR_CHAR = '_'; void TextInputBox::render() { - super.fill(m_xPos, m_yPos, m_xPos + m_width, m_yPos + m_height, 0xFFAAAAAA); - super.fill(m_xPos + 1, m_yPos + 1, m_xPos + m_width - 1, m_yPos + m_height - 1, 0xFF000000); + component->fill(m_xPos, m_yPos, m_xPos + m_width, m_yPos + m_height, 0xFFAAAAAA); + component->fill(m_xPos + 1, m_yPos + 1, m_xPos + m_width - 1, m_yPos + m_height - 1, 0xFF000000); int text_color; int scroll_pos; @@ -195,7 +195,7 @@ void TextInputBox::render() { rendered_text = get_rendered_text(m_pFont, m_width, scroll_pos, rendered_text); const int textYPos = (m_height - 8) / 2; - super.drawString(m_pFont, rendered_text, m_xPos + PADDING, m_yPos + textYPos, text_color); + component->drawString(m_pFont, rendered_text, m_xPos + PADDING, m_yPos + textYPos, text_color); if (m_bCursorOn) { const int cursor_pos = m_insertHead - m_scrollPos; @@ -205,7 +205,7 @@ void TextInputBox::render() { std::string str; str += CURSOR_CHAR; - super.drawString(m_pFont, str, m_xPos + xPos, m_yPos + textYPos + 2, 0xffffff); + component->drawString(m_pFont, str, m_xPos + xPos, m_yPos + textYPos + 2, 0xffffff); } } } @@ -286,8 +286,8 @@ std::string TextInputBox::getText() const { return m_text; } -void TextInputBox::setText(std::string str) { - m_text = str; +void TextInputBox::setText(const std::string &text) { + m_text = text; m_insertHead = int(m_text.size()); } diff --git a/mods/src/text-input-box/TextInputScreen.cpp b/mods/src/text-input-box/TextInputScreen.cpp index 41236d2e..a4f5558e 100644 --- a/mods/src/text-input-box/TextInputScreen.cpp +++ b/mods/src/text-input-box/TextInputScreen.cpp @@ -1,54 +1,34 @@ #include // VTable -void TextInputScreen::setup(Screen_vtable *vtable) { - static Screen_keyPressed_t original_keyPressed = vtable->keyPressed; - vtable->keyPressed = [](Screen *super2, const int key) { - original_keyPressed(super2, key); - TextInputScreen *self = (TextInputScreen *) super2; - for (int i = 0; i < int(self->m_textInputs->size()); i++) { - TextInputBox *textInput = (*self->m_textInputs)[i]; - textInput->keyPressed(key); - } - }; - static Screen_keyboardNewChar_t original_keyboardNewChar = vtable->keyboardNewChar; - vtable->keyboardNewChar = [](Screen *super2, const char key) { - original_keyboardNewChar(super2, key); - TextInputScreen *self = (TextInputScreen *) super2; - for (int i = 0; i < int(self->m_textInputs->size()); i++) { - TextInputBox *textInput = (*self->m_textInputs)[i]; - textInput->charPressed(key); - } - }; - static Screen_mouseClicked_t original_mouseClicked = vtable->mouseClicked; - vtable->mouseClicked = [](Screen *super2, const int x, const int y, const int param_1) { - original_mouseClicked(super2, x, y, param_1); - TextInputScreen *self = (TextInputScreen *) super2; - for (int i = 0; i < int(self->m_textInputs->size()); i++) { - TextInputBox *textInput = (*self->m_textInputs)[i]; - textInput->onClick(x, y); - } - }; - static Screen_render_t original_render = vtable->render; - vtable->render = [](Screen *super2, const int x, const int y, const float param_1) { - original_render(super2, x, y, param_1); - TextInputScreen *self = (TextInputScreen *) super2; - for (int i = 0; i < int(self->m_textInputs->size()); i++) { - TextInputBox *textInput = (*self->m_textInputs)[i]; - textInput->tick(); - textInput->render(); - } - }; - static Screen_init_t original_init = vtable->init; - vtable->init = [](Screen *super2) { - original_init(super2); - TextInputScreen *self = (TextInputScreen *) super2; - self->m_textInputs = new std::vector; - }; - static Screen_removed_t original_removed = vtable->removed; - vtable->removed = [](Screen *super2) { - original_removed(super2); - TextInputScreen *self = (TextInputScreen *) super2; - delete self->m_textInputs; - }; +void TextInputScreen::keyPressed(const int key) const { + for (int i = 0; i < int(m_textInputs->size()); i++) { + TextInputBox *textInput = (*m_textInputs)[i]; + textInput->keyPressed(key); + } +} +void TextInputScreen::keyboardNewChar(const char key) const { + for (int i = 0; i < int(m_textInputs->size()); i++) { + TextInputBox *textInput = (*m_textInputs)[i]; + textInput->charPressed(key); + } +} +void TextInputScreen::mouseClicked(const int x, const int y, __attribute__((unused)) int param_1) const { + for (int i = 0; i < int(m_textInputs->size()); i++) { + TextInputBox *textInput = (*m_textInputs)[i]; + textInput->onClick(x, y); + } +} +void TextInputScreen::render(__attribute__((unused)) int x, __attribute__((unused)) int y, __attribute__((unused)) float param_1) const { + for (int i = 0; i < int(m_textInputs->size()); i++) { + TextInputBox *textInput = (*m_textInputs)[i]; + textInput->tick(); + textInput->render(); + } +} +void TextInputScreen::init() { + m_textInputs = new std::vector; +} +void TextInputScreen::removed() const { + delete m_textInputs; } diff --git a/mods/src/textures/lava.cpp b/mods/src/textures/lava.cpp index 5f6bd377..4671f552 100644 --- a/mods/src/textures/lava.cpp +++ b/mods/src/textures/lava.cpp @@ -9,17 +9,15 @@ // See: https://github.com/ReMinecraftPE/mcpe // Structures -struct LavaTexture { - DynamicTexture super; +EXTEND_STRUCT(LavaTexture, DynamicTexture, struct { int field_14; int field_18; float m_data1[256]; float m_data2[256]; float m_data3[256]; float m_data4[256]; -}; -struct LavaSideTexture { - DynamicTexture super; +}); +EXTEND_STRUCT(LavaSideTexture, DynamicTexture, struct { int field_14; int field_18; int field_1C; @@ -27,13 +25,12 @@ struct LavaSideTexture { float m_data2[256]; float m_data3[256]; float m_data4[256]; -}; -struct FireTexture { - DynamicTexture super; +}); +EXTEND_STRUCT(FireTexture, DynamicTexture, struct { float m_data1[320]; float m_data2[320]; - Random m_random; -}; + Random *m_random; +}); // LavaTexture CUSTOM_VTABLE(lava_texture, DynamicTexture) { @@ -42,39 +39,39 @@ CUSTOM_VTABLE(lava_texture, DynamicTexture) { for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { float f = 0.0F; - int ax = int(Mth::sin((float(x) * float(M_PI) * 2) / 16.0f) * 1.2f); - int ay = int(Mth::sin((float(y) * float(M_PI) * 2) / 16.0f) * 1.2f); + const int ax = int(Mth::sin((float(x) * float(M_PI) * 2) / 16.0f) * 1.2f); + const int ay = int(Mth::sin((float(y) * float(M_PI) * 2) / 16.0f) * 1.2f); for (int bx = x - 1; bx <= x + 1; bx++) { for (int by = y - 1; by <= y + 1; by++) { - int k2 = (bx + ay) & 0xf; - int i3 = (by + ax) & 0xf; - f += self->m_data1[k2 + i3 * 16]; + const int k2 = (bx + ay) & 0xf; + const int i3 = (by + ax) & 0xf; + f += self->data.m_data1[k2 + i3 * 16]; } } - self->m_data2[x + y * 16] = f / 10.0f + ((self->m_data3[(x & 0xf) + ((y + 0) & 0xf) * 16] + self->m_data3[((x + 1) & 0xf) + (y & 0xf) * 16] + self->m_data3[((x + 1) & 0xf) + ((y + 1) & 0xf) * 16] + self->m_data3[(x & 0xf) + ((y + 1) & 0xf) * 16]) * 0.25f) * 0.8f; - self->m_data3[x + y * 16] += self->m_data4[x + y * 16] * 0.01f; - if (self->m_data3[x + y * 16] < 0.0f) { - self->m_data3[x + y * 16] = 0.0f; + self->data.m_data2[x + y * 16] = f / 10.0f + ((self->data.m_data3[(x & 0xf) + ((y + 0) & 0xf) * 16] + self->data.m_data3[((x + 1) & 0xf) + (y & 0xf) * 16] + self->data.m_data3[((x + 1) & 0xf) + ((y + 1) & 0xf) * 16] + self->data.m_data3[(x & 0xf) + ((y + 1) & 0xf) * 16]) * 0.25f) * 0.8f; + self->data.m_data3[x + y * 16] += self->data.m_data4[x + y * 16] * 0.01f; + if (self->data.m_data3[x + y * 16] < 0.0f) { + self->data.m_data3[x + y * 16] = 0.0f; } - self->m_data4[x + y * 16] -= 0.06f; + self->data.m_data4[x + y * 16] -= 0.06f; if (Mth::random() < 0.005f) { - self->m_data4[x + y * 16] = 1.5f; + self->data.m_data4[x + y * 16] = 1.5f; } } } - std::swap(self->m_data1, self->m_data2); + std::swap(self->data.m_data1, self->data.m_data2); for (int i = 0; i < 256; i++) { - float x1 = self->m_data1[i] * 2.0f; + float x1 = self->data.m_data1[i] * 2.0f; if (x1 > 1.0f) { x1 = 1.0f; } if (x1 < 0.0f) { x1 = 0.0f; } - self->super.pixels[i * 4 + 0] = int(155.0f + 100.0f * x1); - self->super.pixels[i * 4 + 1] = int(255.0f * x1 * x1); - self->super.pixels[i * 4 + 2] = int(128.0f * x1 * x1 * x1 * x1); - self->super.pixels[i * 4 + 3] = 255; + self->super()->pixels[i * 4 + 0] = int(155.0f + 100.0f * x1); + self->super()->pixels[i * 4 + 1] = int(255.0f * x1 * x1); + self->super()->pixels[i * 4 + 2] = int(128.0f * x1 * x1 * x1 * x1); + self->super()->pixels[i * 4 + 3] = 255; } }; } @@ -82,17 +79,17 @@ static DynamicTexture *create_lava_texture() { // Construct LavaTexture *texture = new LavaTexture; ALLOC_CHECK(texture); - texture->super.constructor(Tile::lava->texture); + texture->super()->constructor(Tile::lava->texture); // Set VTable - texture->super.vtable = get_lava_texture_vtable(); + texture->super()->vtable = get_lava_texture_vtable(); // Setup - texture->field_14 = 0; - texture->field_18 = 0; + texture->data.field_14 = 0; + texture->data.field_18 = 0; for (int i = 0; i < 256; i++) { - texture->m_data1[i] = 0.0f; - texture->m_data2[i] = 0.0f; - texture->m_data3[i] = 0.0f; - texture->m_data4[i] = 0.0f; + texture->data.m_data1[i] = 0.0f; + texture->data.m_data2[i] = 0.0f; + texture->data.m_data3[i] = 0.0f; + texture->data.m_data4[i] = 0.0f; } // Return return (DynamicTexture *) texture; @@ -102,43 +99,43 @@ static DynamicTexture *create_lava_texture() { CUSTOM_VTABLE(lava_side_texture, DynamicTexture) { vtable->tick = [](DynamicTexture *super) { LavaSideTexture *self = (LavaSideTexture *) super; - self->field_1C++; + self->data.field_1C++; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { float f = 0.0F; - int ax = int(Mth::sin((float(x) * float(M_PI) * 2) / 16.0f) * 1.2f); - int ay = int(Mth::sin((float(y) * float(M_PI) * 2) / 16.0f) * 1.2f); + const int ax = int(Mth::sin((float(x) * float(M_PI) * 2) / 16.0f) * 1.2f); + const int ay = int(Mth::sin((float(y) * float(M_PI) * 2) / 16.0f) * 1.2f); for (int bx = x - 1; bx <= x + 1; bx++) { for (int by = y - 1; by <= y + 1; by++) { - int k2 = (bx + ay) & 0xf; - int i3 = (by + ax) & 0xf; - f += self->m_data1[k2 + i3 * 16]; + const int k2 = (bx + ay) & 0xf; + const int i3 = (by + ax) & 0xf; + f += self->data.m_data1[k2 + i3 * 16]; } } - self->m_data2[x + y * 16] = f / 10.0f + ((self->m_data3[(x & 0xf) + ((y + 0) & 0xf) * 16] + self->m_data3[((x + 1) & 0xf) + (y & 0xf) * 16] + self->m_data3[((x + 1) & 0xf) + ((y + 1) & 0xf) * 16] + self->m_data3[(x & 0xf) + ((y + 1) & 0xf) * 16]) * 0.25f) * 0.8f; - self->m_data3[x + y * 16] += self->m_data4[x + y * 16] * 0.01f; - if (self->m_data3[x + y * 16] < 0.0f) { - self->m_data3[x + y * 16] = 0.0f; + self->data.m_data2[x + y * 16] = f / 10.0f + ((self->data.m_data3[(x & 0xf) + ((y + 0) & 0xf) * 16] + self->data.m_data3[((x + 1) & 0xf) + (y & 0xf) * 16] + self->data.m_data3[((x + 1) & 0xf) + ((y + 1) & 0xf) * 16] + self->data.m_data3[(x & 0xf) + ((y + 1) & 0xf) * 16]) * 0.25f) * 0.8f; + self->data.m_data3[x + y * 16] += self->data.m_data4[x + y * 16] * 0.01f; + if (self->data.m_data3[x + y * 16] < 0.0f) { + self->data.m_data3[x + y * 16] = 0.0f; } - self->m_data4[x + y * 16] -= 0.06f; + self->data.m_data4[x + y * 16] -= 0.06f; if (Mth::random() < 0.005f) { - self->m_data4[x + y * 16] = 1.5f; + self->data.m_data4[x + y * 16] = 1.5f; } } } - std::swap(self->m_data1, self->m_data2); + std::swap(self->data.m_data1, self->data.m_data2); for (int i = 0; i < 256; i++) { - float x1 = self->m_data1[(i - 16 * (self->field_1C / 3)) & 0xFF] * 2.0f; + float x1 = self->data.m_data1[(i - 16 * (self->data.field_1C / 3)) & 0xFF] * 2.0f; if (x1 > 1.0f) { x1 = 1.0f; } if (x1 < 0.0f) { x1 = 0.0f; } - self->super.pixels[i * 4 + 0] = int(155.0f + 100.0f * x1); - self->super.pixels[i * 4 + 1] = int(255.0f * x1 * x1); - self->super.pixels[i * 4 + 2] = int(128.0f * x1 * x1 * x1 * x1); - self->super.pixels[i * 4 + 3] = 255; + self->super()->pixels[i * 4 + 0] = int(155.0f + 100.0f * x1); + self->super()->pixels[i * 4 + 1] = int(255.0f * x1 * x1); + self->super()->pixels[i * 4 + 2] = int(128.0f * x1 * x1 * x1 * x1); + self->super()->pixels[i * 4 + 3] = 255; } }; } @@ -146,19 +143,19 @@ static DynamicTexture *create_lava_side_texture() { // Construct LavaSideTexture *texture = new LavaSideTexture; ALLOC_CHECK(texture); - texture->super.constructor(Tile::lava->texture + 1); + texture->super()->constructor(Tile::lava->texture + 1); // Set VTable - texture->super.vtable = get_lava_side_texture_vtable(); + texture->super()->vtable = get_lava_side_texture_vtable(); // Setup - texture->field_14 = 0; - texture->field_18 = 0; - texture->field_1C = 0; - texture->super.texture_size = 2; + texture->data.field_14 = 0; + texture->data.field_18 = 0; + texture->data.field_1C = 0; + texture->super()->texture_size = 2; for (int i = 0; i < 256; i++) { - texture->m_data1[i] = 0.0f; - texture->m_data2[i] = 0.0f; - texture->m_data3[i] = 0.0f; - texture->m_data4[i] = 0.0f; + texture->data.m_data1[i] = 0.0f; + texture->data.m_data2[i] = 0.0f; + texture->data.m_data3[i] = 0.0f; + texture->data.m_data4[i] = 0.0f; } // Return return (DynamicTexture *) texture; @@ -171,61 +168,62 @@ CUSTOM_VTABLE(fire_texture, DynamicTexture) { for (int i = 0; i < 16; i++) { for (int j = 0; j < 20; j++) { int l = 18; - float f1 = self->m_data1[i + ((j + 1) % 20) * 16] * l; + float f1 = self->data.m_data1[i + ((j + 1) % 20) * 16] * l; for (int i1 = i - 1; i1 <= i + 1; i1++) { for (int k1 = j; k1 <= j + 1; k1++) { - int i2 = i1; - int k2 = k1; + const int i2 = i1; + const int k2 = k1; if (i2 >= 0 && k2 >= 0 && i2 < 16 && k2 < 20) { - f1 += self->m_data1[i2 + k2 * 16]; + f1 += self->data.m_data1[i2 + k2 * 16]; } l++; } } - self->m_data2[i + j * 16] = f1 / 25.2f; + self->data.m_data2[i + j * 16] = f1 / 25.2f; if (j >= 19) { union { uint32_t x; uint8_t b[4]; - } a; - a.x = self->m_random.genrand_int32(); - self->m_data2[i + j * 16] = 0.2f + (((a.b[3] / 256.0f) * 0.1f) + ((((a.b[0] / 256.0f) * (a.b[1] / 256.0f)) * (a.b[2] / 256.0f)) * 4.0f)); + } a = {}; + a.x = self->data.m_random->genrand_int32(); + self->data.m_data2[i + j * 16] = 0.2f + (((a.b[3] / 256.0f) * 0.1f) + ((((a.b[0] / 256.0f) * (a.b[1] / 256.0f)) * (a.b[2] / 256.0f)) * 4.0f)); } } } - std::swap(self->m_data1, self->m_data2); + std::swap(self->data.m_data1, self->data.m_data2); for (int i = 0; i < 256; i++) { - float x = self->m_data1[i] * 1.8f; + float x = self->data.m_data1[i] * 1.8f; if (x > 1.0f) { x = 1.0f; } if (x < 0.0f) { x = 0.0f; } - self->super.pixels[4 * i + 0] = int(x * 155.0f + 100.0f); - self->super.pixels[4 * i + 1] = int(x * x * 255.0f); - self->super.pixels[4 * i + 2] = int(x * x * x * x * x * x * x * x * x * x * 255.0f); - self->super.pixels[4 * i + 3] = x >= 0.5f ? 255 : 0; + self->super()->pixels[4 * i + 0] = int(x * 155.0f + 100.0f); + self->super()->pixels[4 * i + 1] = int(x * x * 255.0f); + self->super()->pixels[4 * i + 2] = int(x * x * x * x * x * x * x * x * x * x * 255.0f); + self->super()->pixels[4 * i + 3] = x >= 0.5f ? 255 : 0; } }; } -static DynamicTexture *create_fire_texture(int a2) { +static DynamicTexture *create_fire_texture(const int a2) { // Construct FireTexture *texture = new FireTexture; ALLOC_CHECK(texture); - texture->super.constructor(Tile::fire->texture + (16 * a2)); + texture->super()->constructor(Tile::fire->texture + (16 * a2)); // Set VTable - texture->super.vtable = get_fire_texture_vtable(); + texture->super()->vtable = get_fire_texture_vtable(); // Setup Random - int seed = Common::getTimeMs(); - texture->m_random.seed = seed; - texture->m_random.param_1 = 0x271; - texture->m_random.param_2 = false; - texture->m_random.param_3 = 0; + texture->data.m_random = Random::allocate(); + const int seed = Common::getTimeMs(); + texture->data.m_random->seed = seed; + texture->data.m_random->param_1 = 0x271; + texture->data.m_random->param_2 = false; + texture->data.m_random->param_3 = 0; for (int i = 0; i < 320; i++) { - texture->m_data1[i] = 0.0f; - texture->m_data2[i] = 0.0f; + texture->data.m_data1[i] = 0.0f; + texture->data.m_data2[i] = 0.0f; } // Return return (DynamicTexture *) texture; @@ -253,7 +251,7 @@ static void Textures_addDynamicTexture_injection(Textures *textures, DynamicText } // Init -void _init_textures_lava(bool animated_water_param, bool animated_lava_param, bool animated_fire_param) { +void _init_textures_lava(const bool animated_water_param, const bool animated_lava_param, const bool animated_fire_param) { animated_water = animated_water_param; animated_lava = animated_lava_param; animated_fire = animated_fire_param; diff --git a/mods/src/textures/textures.cpp b/mods/src/textures/textures.cpp index 459b1b65..49c4e2dd 100644 --- a/mods/src/textures/textures.cpp +++ b/mods/src/textures/textures.cpp @@ -16,7 +16,7 @@ #include "stb_image.h" // Animated Water -static void Minecraft_tick_injection(Minecraft *minecraft) { +static void Minecraft_tick_injection(const Minecraft *minecraft) { // Tick Dynamic Textures Textures *textures = minecraft->textures; if (textures != nullptr) { @@ -36,7 +36,7 @@ static std::vector &get_texture_data() { } HOOK(glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) { // Store - texture_data data; + texture_data data = {}; glGetIntegerv(GL_TEXTURE_BINDING_2D, &data.id); data.width = width; data.height = height; @@ -52,7 +52,7 @@ HOOK(glDeleteTextures, void, (GLsizei n, const GLuint *textures)) { const GLint id = textures[i]; std::vector::iterator it = get_texture_data().begin(); while (it != get_texture_data().end()) { - texture_data data = *it; + const texture_data data = *it; if (data.id == id) { it = get_texture_data().erase(it); } else { @@ -69,7 +69,7 @@ static void get_texture_size(const GLint id, GLsizei *width, GLsizei *height) { // Iterate std::vector::iterator it = get_texture_data().begin(); while (it != get_texture_data().end()) { - texture_data data = *it; + const texture_data data = *it; if (data.id == id) { // Found *width = data.width; diff --git a/mods/src/title-screen/title-screen.cpp b/mods/src/title-screen/title-screen.cpp index dc00d9a2..e8dce2bf 100644 --- a/mods/src/title-screen/title-screen.cpp +++ b/mods/src/title-screen/title-screen.cpp @@ -16,7 +16,7 @@ // Improved Title Screen Background static void StartMenuScreen_render_Screen_renderBackground_injection(Screen *screen) { // Draw - Minecraft *minecraft = screen->minecraft; + const Minecraft *minecraft = screen->minecraft; Textures *textures = minecraft->textures; std::string texture = "gui/titleBG.png"; textures->loadAndBindTexture(texture); @@ -93,8 +93,8 @@ static void StartMenuScreen_render_Screen_render_injection(Screen *screen, int x const float multiplier = touch_gui ? 0.5f : 1.0f; const float splash_x = (float(screen->width) / 2.0f) + (94.0f * multiplier); const float splash_y = 4.0f + (36.0f * multiplier); - const float max_width = 86; - const float max_scale = 2.0f; + constexpr float max_width = 86; + constexpr float max_scale = 2.0f; // Draw (From https://github.com/ReMinecraftPE/mcpe/blob/d7a8b6baecf8b3b050538abdbc976f690312aa2d/source/client/gui/screens/StartMenuScreen.cpp#L699-L718) glPushMatrix(); // Position diff --git a/mods/src/title-screen/welcome.cpp b/mods/src/title-screen/welcome.cpp index db43c4b5..c5983c16 100644 --- a/mods/src/title-screen/welcome.cpp +++ b/mods/src/title-screen/welcome.cpp @@ -30,7 +30,7 @@ static bool should_show_welcome() { // Read Line std::string line; std::getline(stream, line); - bool invalid = line != MCPI_VERSION; + const bool invalid = line != MCPI_VERSION; // Close File stream.close(); // Return @@ -53,7 +53,7 @@ static Button *getting_started; static Button *changelog; static Button *proceed; static int text_y; -static void position_screen(int width, int height) { +static void position_screen(const int width, const int height) { // Width/Height getting_started->width = changelog->width = proceed->width = button_width; getting_started->height = changelog->height = proceed->height = button_height; @@ -66,8 +66,8 @@ static void position_screen(int width, int height) { getting_started->y = changelog->y = line_height + line_padding; proceed->y = getting_started->y + button_height + (button_padding * 2); // Center - int content_height = proceed->y + proceed->height; - int y_offset = (height - content_height) / 2; + const int content_height = proceed->y + proceed->height; + const int y_offset = (height - content_height) / 2; text_y += y_offset; getting_started->y += y_offset; changelog->y += y_offset; @@ -89,7 +89,7 @@ CUSTOM_VTABLE(welcome_screen, Screen) { }; // Rendering static Screen_render_t original_render = vtable->render; - vtable->render = [](Screen *self, int x, int y, float param_1) { + vtable->render = [](Screen *self, const int x, const int y, const float param_1) { // Background self->renderBackground(); // Call Original Method @@ -121,7 +121,7 @@ CUSTOM_VTABLE(welcome_screen, Screen) { } static Screen *create_welcome_screen() { // Allocate - Screen *screen = new Screen; + Screen *screen = Screen::allocate(); ALLOC_CHECK(screen); screen->constructor(); diff --git a/mods/src/touch/touch.cpp b/mods/src/touch/touch.cpp index f73dc6dd..5d990198 100644 --- a/mods/src/touch/touch.cpp +++ b/mods/src/touch/touch.cpp @@ -45,12 +45,12 @@ static void LargeImageButton_render_GuiComponent_drawCenteredString_injection(Gu int touch_gui = 0; template static Button *create_button(int id, std::string text) { - T *button = new T; + T *button = T::allocate(); ALLOC_CHECK(button); button->constructor(id, text); return (Button *) button; } -Button *touch_create_button(const int id, std::string text) { +Button *touch_create_button(const int id, const std::string &text) { if (touch_gui) { return create_button(id, text); } else { diff --git a/symbols/CMakeLists.txt b/symbols/CMakeLists.txt index 617d2a2d..8156679c 100644 --- a/symbols/CMakeLists.txt +++ b/symbols/CMakeLists.txt @@ -249,8 +249,6 @@ 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/api/ConnectedClient.def b/symbols/src/api/ConnectedClient.def index 91a43bfd..b23e6421 100644 --- a/symbols/src/api/ConnectedClient.def +++ b/symbols/src/api/ConnectedClient.def @@ -3,3 +3,5 @@ size 0xc; property uint sock = 0x0; property std::string str = 0x4; property int time = 0x8; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/app-platform/AppPlatform_readAssetFile_return_value.def b/symbols/src/app-platform/AppPlatform_readAssetFile_return_value.def index 5a27e66b..0d618b26 100644 --- a/symbols/src/app-platform/AppPlatform_readAssetFile_return_value.def +++ b/symbols/src/app-platform/AppPlatform_readAssetFile_return_value.def @@ -1,4 +1,6 @@ size 0x8; property char *data = 0x0; -property int length = 0x4; \ No newline at end of file +property int length = 0x4; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/item/ItemInstance.def b/symbols/src/item/ItemInstance.def index e2d805dc..e0ce994b 100644 --- a/symbols/src/item/ItemInstance.def +++ b/symbols/src/item/ItemInstance.def @@ -14,3 +14,5 @@ method bool isNull() = 0x999b0; property int count = 0x0; property int id = 0x4; property int auxiliary = 0x8; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/level/DistanceChunkSorter.def b/symbols/src/level/DistanceChunkSorter.def index b1b5eb52..a286fdf4 100644 --- a/symbols/src/level/DistanceChunkSorter.def +++ b/symbols/src/level/DistanceChunkSorter.def @@ -3,3 +3,5 @@ size 0x4; property Mob *mob = 0x0; method bool compare(Chunk *param_1, Chunk *param_2) = 0x5118c; // Actually Called _ZN19DistanceChunkSorterclEPK5ChunkS2_ + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/level/LevelSettings.def b/symbols/src/level/LevelSettings.def index 86c64c9f..a7297753 100644 --- a/symbols/src/level/LevelSettings.def +++ b/symbols/src/level/LevelSettings.def @@ -1,4 +1,6 @@ size 0x8; property int seed = 0x0; -property int game_type = 0x4; \ No newline at end of file +property int game_type = 0x4; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/level/LevelSummary.def b/symbols/src/level/LevelSummary.def index fc824269..2665e7f7 100644 --- a/symbols/src/level/LevelSummary.def +++ b/symbols/src/level/LevelSummary.def @@ -5,3 +5,5 @@ property std::string name = 0x4; property int seed = 0x8; property int game_mode = 0xc; property int param_5 = 0x10; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/misc/AABB.def b/symbols/src/misc/AABB.def index 87169159..ce44a82d 100644 --- a/symbols/src/misc/AABB.def +++ b/symbols/src/misc/AABB.def @@ -6,3 +6,5 @@ property float z1 = 0x8; property float x2 = 0xc; property float y2 = 0x10; property float z2 = 0x14; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/misc/HitResult.def b/symbols/src/misc/HitResult.def index 88934406..75dfe547 100644 --- a/symbols/src/misc/HitResult.def +++ b/symbols/src/misc/HitResult.def @@ -7,4 +7,6 @@ property int z = 0xc; property int side = 0x10; property Vec3 exact = 0x14; property Entity *entity = 0x20; -property uchar unknown = 0x24; \ No newline at end of file +property uchar unknown = 0x24; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/misc/Vec3.def b/symbols/src/misc/Vec3.def index b2d2c0ed..5ed176cd 100644 --- a/symbols/src/misc/Vec3.def +++ b/symbols/src/misc/Vec3.def @@ -2,4 +2,6 @@ size 0xc; property float x = 0x0; property float y = 0x4; -property float z = 0x8; \ No newline at end of file +property float z = 0x8; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/network/raknet/RakNet_RakNetGUID.def b/symbols/src/network/raknet/RakNet_RakNetGUID.def index 15346426..32f28d5b 100644 --- a/symbols/src/network/raknet/RakNet_RakNetGUID.def +++ b/symbols/src/network/raknet/RakNet_RakNetGUID.def @@ -1 +1,6 @@ -size 0xa; \ No newline at end of file +size 0x10; + +property unsigned long long param_1 = 0x0; +property ushort param_2 = 0x8; + +mark-as-simple; diff --git a/symbols/src/network/raknet/RakNet_SystemAddress.def b/symbols/src/network/raknet/RakNet_SystemAddress.def index d4cfc113..33fb22aa 100644 --- a/symbols/src/network/raknet/RakNet_SystemAddress.def +++ b/symbols/src/network/raknet/RakNet_SystemAddress.def @@ -1,3 +1,7 @@ size 0x14; -method char *ToString(bool print_delimiter, char delimiter) = 0xd6198; \ No newline at end of file +method char *ToString(bool print_delimiter, char delimiter) = 0xd6198; + +property uchar data[0x14] = 0x0; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/recipes/Recipes_Type.def b/symbols/src/recipes/Recipes_Type.def index a7d2fb54..fcac7c23 100644 --- a/symbols/src/recipes/Recipes_Type.def +++ b/symbols/src/recipes/Recipes_Type.def @@ -3,4 +3,6 @@ size 0x18; property Item *item = 0x0; property Tile *tile = 0x4; property ItemInstance instance = 0x8; -property char letter = 0x14; \ No newline at end of file +property char letter = 0x14; + +mark-as-simple; \ No newline at end of file diff --git a/symbols/src/textures/Texture.def b/symbols/src/textures/Texture.def index c9ac5f68..bee39786 100644 --- a/symbols/src/textures/Texture.def +++ b/symbols/src/textures/Texture.def @@ -7,4 +7,6 @@ property int field3_0xc = 0xc; property bool field4_0x10 = 0x10; property bool field5_0x11 = 0x11; property int field6_0x14 = 0x14; -property int field7_0x18 = 0x18; \ No newline at end of file +property int field7_0x18 = 0x18; + +mark-as-simple; \ No newline at end of file