From 4bf4cfee8e9139da22557c6a8fe211832b72b39a Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 4 Dec 2020 12:17:51 -0500 Subject: [PATCH] Improve Code --- mods/CMakeLists.txt | 2 -- mods/src/minecraft.h | 8 +++++--- mods/src/misc/misc.cpp | 19 ++++++++++++++----- mods/src/util/cxx11_util.cpp | 20 -------------------- mods/src/util/cxx11_util.h | 21 --------------------- 5 files changed, 19 insertions(+), 51 deletions(-) delete mode 100644 mods/src/util/cxx11_util.cpp delete mode 100644 mods/src/util/cxx11_util.h diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 5431e9838..afd10f007 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -39,8 +39,6 @@ target_link_libraries(game_mode core) add_library(input SHARED src/input/input.c src/input/input.cpp) target_link_libraries(input core feature SDL) -add_library(util SHARED src/util/cxx11_util.cpp) - add_library(misc SHARED src/misc/misc.c src/misc/misc.cpp) target_link_libraries(misc core feature util) diff --git a/mods/src/minecraft.h b/mods/src/minecraft.h index f65413e84..7ebccdd7d 100644 --- a/mods/src/minecraft.h +++ b/mods/src/minecraft.h @@ -291,14 +291,16 @@ static ItemRenderer_renderGuiItemCorrect_t ItemRenderer_renderGuiItemCorrect = ( #include -#include "util/cxx11_util.h" - // AppPlatform typedef void (*AppPlatform_saveScreenshot_t)(unsigned char *app_platform, std::string const& param1, std::string const& param_2); static void *AppPlatform_linux_saveScreenshot_vtable_addr = (void *) 0x102160; -typedef cxx11_string (*AppPlatform_readAssetFile_t)(unsigned char *app_platform, std::string const& path); +struct AppPlatform_readAssetFile_return_value { + char *data; + int32_t length; +}; +typedef AppPlatform_readAssetFile_return_value (*AppPlatform_readAssetFile_t)(unsigned char *app_platform, std::string const& path); static AppPlatform_readAssetFile_t AppPlatform_readAssetFile = (AppPlatform_readAssetFile_t) 0x12b10; // Minecraft diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index b1cdf281a..23a088099 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -2,9 +2,9 @@ #include #include -#include +#include -#include "../util/cxx11_util.h" +#include #include "../feature/feature.h" #include "misc.h" @@ -12,12 +12,17 @@ #include "../minecraft.h" // Read Asset File -static cxx11_string AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) { +static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) { + // Read File std::string full_path("./data/"); full_path.append(path); std::ifstream stream(full_path); std::string str((std::istreambuf_iterator(stream)), std::istreambuf_iterator()); - return create_cxx11_string(str.c_str()); + // Return String + AppPlatform_readAssetFile_return_value ret; + ret.length = str.length(); + ret.data = strdup(str.c_str()); + return ret; } static void inventory_add_item(unsigned char *inventory, unsigned char *item, bool is_tile) { @@ -35,7 +40,11 @@ static int32_t Inventory_setupDefault_FillingContainer_addItem_call_injection(un inventory_add_item(filling_container, *Item_snowball, false); inventory_add_item(filling_container, *Item_egg, false); inventory_add_item(filling_container, *Item_shears, false); - for (int i = 0; i < 15; i++) { + for (int i = 0; i < 16; i++) { + if (i == 15) { + // Bonemeal Is Already In The Creative Inventory + continue; + } unsigned char *item_instance = (unsigned char *) ::operator new(0xc); item_instance = (*ItemInstance_constructor_item_extra)(item_instance, *Item_dye_powder, 1, i); (*FillingContainer_addItem)(filling_container, item_instance); diff --git a/mods/src/util/cxx11_util.cpp b/mods/src/util/cxx11_util.cpp deleted file mode 100644 index aff0c55eb..000000000 --- a/mods/src/util/cxx11_util.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Use C++11 ABI -#undef _GLIBCXX_USE_CXX11_ABI -#define _GLIBCXX_USE_CXX11_ABI 1 - -#include - -#include - -#include "cxx11_util.h" - -// Convert A C-String into A C++11 String That Can be Acessed In C++03 Code -cxx11_string create_cxx11_string(const char *str) { - std::string *new_str = new std::string(str); - int32_t new_size = sizeof (cxx11_string); - int32_t old_size = sizeof (*new_str); - if (new_size != old_size) { - ERR("Mismatched String Size: Expected: %i Real: %i", new_size, old_size); - } - return *reinterpret_cast(new_str); -} diff --git a/mods/src/util/cxx11_util.h b/mods/src/util/cxx11_util.h deleted file mode 100644 index 4275d7244..000000000 --- a/mods/src/util/cxx11_util.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CXX_11_UTIL_H - -#define CXX_11_UTIL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define CXX11_STRING_SIZE 24 - -struct cxx11_string { - unsigned char data[CXX11_STRING_SIZE]; -}; - -cxx11_string create_cxx11_string(const char *str); - -#ifdef __cplusplus -} -#endif - -#endif