Improve Code
minecraft-pi-docker/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-12-04 12:17:51 -05:00
parent f9e893d1c3
commit 4bf4cfee8e
5 changed files with 19 additions and 51 deletions

View File

@ -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)

View File

@ -291,14 +291,16 @@ static ItemRenderer_renderGuiItemCorrect_t ItemRenderer_renderGuiItemCorrect = (
#include <string>
#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

View File

@ -2,9 +2,9 @@
#include <fstream>
#include <streambuf>
#include <libcore/libcore.h>
#include <cstring>
#include "../util/cxx11_util.h"
#include <libcore/libcore.h>
#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<char>(stream)), std::istreambuf_iterator<char>());
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);

View File

@ -1,20 +0,0 @@
// Use C++11 ABI
#undef _GLIBCXX_USE_CXX11_ABI
#define _GLIBCXX_USE_CXX11_ABI 1
#include <string>
#include <libcore/libcore.h>
#include "cxx11_util.h"
// Convert A C-String into A C++11 String That Can be Acessed In C++03 Code
cxx11_string create_cxx11_string(const char *str) {
std::string *new_str = new std::string(str);
int32_t new_size = sizeof (cxx11_string);
int32_t old_size = sizeof (*new_str);
if (new_size != old_size) {
ERR("Mismatched String Size: Expected: %i Real: %i", new_size, old_size);
}
return *reinterpret_cast<cxx11_string *>(new_str);
}

View File

@ -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