C++-Ification!
This commit is contained in:
parent
7739fb6b9b
commit
b2a7fe3eaf
@ -16,6 +16,11 @@
|
||||
}
|
||||
|
||||
// Hook Library Function
|
||||
#ifdef __cplusplus
|
||||
#define hooked_function_setup extern "C"
|
||||
#else
|
||||
#define hooked_function_setup
|
||||
#endif
|
||||
#define HOOK(name, return_type, args) \
|
||||
typedef return_type (*name##_t)args; \
|
||||
static name##_t real_##name = NULL; \
|
||||
@ -30,7 +35,7 @@
|
||||
} \
|
||||
} \
|
||||
\
|
||||
__attribute__((__used__)) return_type name args
|
||||
hooked_function_setup __attribute__((__used__)) return_type name args
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -3,14 +3,14 @@ project(mods)
|
||||
# Common Sources
|
||||
set(SRC
|
||||
# compat
|
||||
src/compat/compat.c
|
||||
src/compat/egl.c
|
||||
src/compat/x11.c
|
||||
src/compat/bcm_host.c
|
||||
src/compat/compat.cpp
|
||||
src/compat/egl.cpp
|
||||
src/compat/x11.cpp
|
||||
src/compat/bcm_host.cpp
|
||||
# readdir
|
||||
src/readdir/readdir.c
|
||||
src/readdir/readdir.cpp
|
||||
# feature
|
||||
src/feature/feature.c
|
||||
src/feature/feature.cpp
|
||||
# version
|
||||
src/version/version.cpp
|
||||
# chat
|
||||
@ -19,30 +19,28 @@ set(SRC
|
||||
# creative
|
||||
src/creative/creative.cpp
|
||||
# game-mode
|
||||
src/game-mode/game-mode.c
|
||||
src/game-mode/game-mode.cpp
|
||||
src/game-mode/ui.cpp
|
||||
# override
|
||||
src/override/override.c
|
||||
src/override/override.cpp
|
||||
# death
|
||||
src/death/death.cpp
|
||||
# misc
|
||||
src/misc/misc.c
|
||||
src/misc/misc.cpp
|
||||
src/misc/logging.cpp
|
||||
src/misc/api.cpp
|
||||
# options
|
||||
src/options/options.c
|
||||
src/options/options.cpp
|
||||
# bucket
|
||||
src/bucket/bucket.cpp
|
||||
# cake
|
||||
src/cake/cake.cpp
|
||||
# home
|
||||
src/home/home.c
|
||||
src/home/home.cpp
|
||||
# test
|
||||
src/test/test.c
|
||||
src/test/test.cpp
|
||||
# init
|
||||
src/init/init.c
|
||||
src/init/init.cpp
|
||||
)
|
||||
|
||||
# Server-Only Sources
|
||||
@ -76,10 +74,10 @@ else()
|
||||
src/camera/camera.cpp
|
||||
# input
|
||||
src/input/input.cpp
|
||||
src/input/bow.c
|
||||
src/input/attack.c
|
||||
src/input/toggle.c
|
||||
src/input/misc.c
|
||||
src/input/bow.cpp
|
||||
src/input/attack.cpp
|
||||
src/input/toggle.cpp
|
||||
src/input/misc.cpp
|
||||
src/input/drop.cpp
|
||||
src/input/crafting.cpp
|
||||
# sign
|
||||
@ -95,7 +93,7 @@ else()
|
||||
src/skin/skin.cpp
|
||||
src/skin/loader.cpp
|
||||
# screenshot
|
||||
src/screenshot/screenshot.c
|
||||
src/screenshot/screenshot.cpp
|
||||
# textures
|
||||
src/textures/textures.cpp
|
||||
src/textures/lava.cpp
|
||||
|
@ -2,12 +2,4 @@
|
||||
|
||||
#include <symbols/minecraft.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern bool buckets_enabled;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,22 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
#include <symbols/minecraft.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
// Send API Command
|
||||
std::string chat_send_api_command(Minecraft *minecraft, std::string str);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,12 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int compat_check_exit_requested();
|
||||
void compat_request_exit();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int creative_is_restricted();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
int creative_is_restricted();
|
@ -2,11 +2,7 @@
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int _feature_has(const char *name);
|
||||
bool _feature_has(const char *name);
|
||||
|
||||
#ifdef MCPI_SERVER_MODE
|
||||
#define _feature_has__server_defaul_is_server_disabled(name) 0
|
||||
@ -16,7 +12,3 @@ int _feature_has(const char *name);
|
||||
#else
|
||||
#define feature_has(name, server_default) _feature_has(name)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern double fps;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *home_get();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -2,10 +2,6 @@
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void run_tests();
|
||||
void init_version();
|
||||
void init_compat();
|
||||
@ -35,8 +31,4 @@ void init_options();
|
||||
void init_chat();
|
||||
void init_bucket();
|
||||
void init_cake();
|
||||
void init_home();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
void init_home();
|
@ -2,10 +2,6 @@
|
||||
|
||||
#include <symbols/minecraft.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*input_tick_function_t)(Minecraft *minecraft);
|
||||
void input_run_on_tick(input_tick_function_t function);
|
||||
|
||||
@ -17,7 +13,3 @@ void input_open_crafting();
|
||||
void input_set_is_left_click(int val);
|
||||
|
||||
void input_set_mouse_grab_state(int state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
#include <symbols/minecraft.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t misc_get_real_selected_slot(Player *player);
|
||||
|
||||
typedef void (*misc_update_function_Minecraft_t)(Minecraft *obj);
|
||||
@ -32,7 +28,3 @@ void Level_saveLevelData_injection(Level *level);
|
||||
void misc_add_message(Gui *gui, const char *text);
|
||||
|
||||
extern bool is_in_chat;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *override_get_path(const char *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void screenshot_take(char *home);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void sign_key_press(char key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
void sign_key_press(char key);
|
@ -2,12 +2,4 @@
|
||||
|
||||
#include <GLES/gl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void glTexSubImage2D_with_scaling(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei normal_texture_width, GLsizei normal_texture_height, GLenum format, GLenum type, const void *pixels);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -3,6 +3,4 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
void title_screen_load_splashes(std::vector<std::string> &splashes);
|
||||
}
|
||||
|
@ -1,11 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *version_get();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@ static void ItemRenderer_renderGuiItemCorrect_injection(Font *font, Textures *te
|
||||
// Replace Rendered Item With Carried Variant
|
||||
ItemInstance carried_item_instance;
|
||||
bool use_carried = false;
|
||||
if (item_instance != NULL) {
|
||||
if (item_instance != nullptr) {
|
||||
if (item_instance->id == leaves_id) {
|
||||
ItemInstance_constructor_tile_extra(&carried_item_instance, Tile_leaves_carried, item_instance->count, item_instance->auxiliary);
|
||||
use_carried = true;
|
||||
@ -91,7 +91,7 @@ static void FurnaceScreen_render_ItemRenderer_renderGuiItem_one_injection(Font *
|
||||
|
||||
// Init
|
||||
void init_atlas() {
|
||||
// Add Better NULL-Check (And More UI Fixes When The gui_blocks Atlas Is Disabled)
|
||||
// Add Better nullptr-Check (And More UI Fixes When The gui_blocks Atlas Is Disabled)
|
||||
overwrite_calls((void *) ItemRenderer_renderGuiItem_two, (void *) ItemRenderer_renderGuiItem_two_injection);
|
||||
|
||||
// Disable The gui_blocks Atlas Which Contains Pre-Rendered Textures For Blocks In The Inventory
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <mods/bucket/bucket.h>
|
||||
|
||||
// Items
|
||||
static FoodItem *bucket = NULL;
|
||||
static FoodItem *bucket = nullptr;
|
||||
|
||||
// Description And Texture
|
||||
static std::string BucketItem_getDescriptionId(__attribute__((unused)) FoodItem *item, ItemInstance *item_instance) {
|
||||
@ -111,7 +111,7 @@ static int32_t BucketItem_useOn(__attribute__((unused)) FoodItem *item, ItemInst
|
||||
// Get Current Tile
|
||||
bool valid = false;
|
||||
Material *material = level->vtable->getMaterial(level, x, y, z);
|
||||
if (material != NULL) {
|
||||
if (material != nullptr) {
|
||||
valid = !material->vtable->isSolid(material);
|
||||
}
|
||||
if (item_instance->auxiliary != Tile_water->id && item_instance->auxiliary != Tile_lava->id) {
|
||||
@ -161,7 +161,7 @@ static ItemInstance *BucketItem_use(FoodItem *item, ItemInstance *item_instance,
|
||||
|
||||
static ItemInstance *BucketItem_getCraftingRemainingItem(FoodItem *item, ItemInstance *item_instance) {
|
||||
if (item_instance->auxiliary == 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
ItemInstance *ret = alloc_ItemInstance();
|
||||
ret->id = item->id;
|
||||
@ -255,7 +255,7 @@ static HitResult Mob_pick_Level_clip_injection(Level *level, unsigned char *para
|
||||
}
|
||||
static void handle_tick(Minecraft *minecraft) {
|
||||
LocalPlayer *player = minecraft->player;
|
||||
if (player != NULL) {
|
||||
if (player != nullptr) {
|
||||
// Get Selected Slot
|
||||
int32_t selected_slot = misc_get_real_selected_slot((Player *) player);
|
||||
Inventory *inventory = player->inventory;
|
||||
@ -263,7 +263,7 @@ static void handle_tick(Minecraft *minecraft) {
|
||||
// Get Item
|
||||
ItemInstance *inventory_item = inventory->vtable->getItem(inventory, selected_slot);
|
||||
// Check
|
||||
is_holding_bucket = inventory_item != NULL && inventory_item->id == bucket->id && inventory_item->auxiliary == 0;
|
||||
is_holding_bucket = inventory_item != nullptr && inventory_item->id == bucket->id && inventory_item->auxiliary == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ static bool is_calm_liquid(int32_t id) {
|
||||
static void Minecraft_handleMouseDown_injection(Minecraft *minecraft, int param_1, bool can_destroy) {
|
||||
// Check
|
||||
Level *level = minecraft->level;
|
||||
if (level != NULL) {
|
||||
if (level != nullptr) {
|
||||
int32_t x = minecraft->hit_result.x;
|
||||
int32_t y = minecraft->hit_result.y;
|
||||
int32_t z = minecraft->hit_result.z;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <mods/misc/misc.h>
|
||||
#include <mods/bucket/bucket.h>
|
||||
|
||||
static Tile *cake = NULL;
|
||||
static Tile *cake = nullptr;
|
||||
|
||||
#define CAKE_LEN 0.0625F
|
||||
|
||||
|
@ -26,7 +26,7 @@ std::string chat_send_api_command(Minecraft *minecraft, std::string str) {
|
||||
client.str = "";
|
||||
client.time = 0;
|
||||
CommandServer *command_server = minecraft->command_server;
|
||||
if (command_server != NULL) {
|
||||
if (command_server != nullptr) {
|
||||
return CommandServer_parse(command_server, &client, &str);
|
||||
} else {
|
||||
return "";
|
||||
@ -36,7 +36,7 @@ std::string chat_send_api_command(Minecraft *minecraft, std::string str) {
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
// Send API Chat Command
|
||||
static void send_api_chat_command(Minecraft *minecraft, char *str) {
|
||||
char *command = NULL;
|
||||
char *command = nullptr;
|
||||
safe_asprintf(&command, "chat.post(%s)\n", str);
|
||||
chat_send_api_command(minecraft, command);
|
||||
free(command);
|
||||
@ -48,7 +48,7 @@ std::string _chat_get_prefix(char *username) {
|
||||
return std::string("<") + username + "> ";
|
||||
}
|
||||
void chat_send_message(ServerSideNetworkHandler *server_side_network_handler, char *username, char *message) {
|
||||
char *full_message = NULL;
|
||||
char *full_message = nullptr;
|
||||
safe_asprintf(&full_message, "%s%s", _chat_get_prefix(username).c_str(), message);
|
||||
sanitize_string(&full_message, MAX_CHAT_MESSAGE_LENGTH, 0);
|
||||
std::string cpp_string = full_message;
|
||||
@ -72,7 +72,7 @@ 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;
|
||||
if (minecraft != NULL) {
|
||||
if (minecraft != nullptr) {
|
||||
chat_handle_packet_send(minecraft, (ChatPacket *) packet);
|
||||
}
|
||||
}
|
||||
@ -80,7 +80,7 @@ static void CommandServer_parse_CommandServer_dispatchPacket_injection(CommandSe
|
||||
// Handle ChatPacket Server-Side
|
||||
static void ServerSideNetworkHandler_handle_ChatPacket_injection(ServerSideNetworkHandler *server_side_network_handler, RakNet_RakNetGUID *rak_net_guid, ChatPacket *chat_packet) {
|
||||
Player *player = ServerSideNetworkHandler_getPlayer(server_side_network_handler, rak_net_guid);
|
||||
if (player != NULL) {
|
||||
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);
|
||||
|
@ -95,7 +95,7 @@ CUSTOM_VTABLE(chat_screen, Screen) {
|
||||
}
|
||||
_chat_queue_message(text.c_str());
|
||||
}
|
||||
Minecraft_setScreen(super->minecraft, NULL);
|
||||
Minecraft_setScreen(super->minecraft, nullptr);
|
||||
} else if (key == 0x26) {
|
||||
// Up
|
||||
local_history.at(self->history_pos) = self->chat->getText();
|
||||
@ -147,7 +147,7 @@ static Screen *create_chat_screen() {
|
||||
void _init_chat_ui() {
|
||||
misc_run_on_game_key_press([](Minecraft *minecraft, int key) {
|
||||
if (key == 0x54) {
|
||||
if (Minecraft_isLevelGenerated(minecraft) && minecraft->screen == NULL) {
|
||||
if (Minecraft_isLevelGenerated(minecraft) && minecraft->screen == nullptr) {
|
||||
Minecraft_setScreen(minecraft, create_chat_screen());
|
||||
}
|
||||
return true;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
|
||||
#include <mods/compat/compat.h>
|
||||
#include <mods/screenshot/screenshot.h>
|
||||
@ -51,7 +51,7 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) {
|
||||
int ret = real_SDL_PollEvent(event);
|
||||
|
||||
// Handle Events
|
||||
if (ret == 1 && event != NULL) {
|
||||
if (ret == 1 && event != nullptr) {
|
||||
int handled = 0;
|
||||
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
@ -116,11 +116,10 @@ static void exit_handler(__attribute__((unused)) int data) {
|
||||
void init_compat() {
|
||||
// Install Signal Handlers
|
||||
signal(SIGINT, SIG_IGN);
|
||||
struct sigaction act_sigterm;
|
||||
memset((void *) &act_sigterm, 0, sizeof (struct sigaction));
|
||||
struct sigaction act_sigterm = {};
|
||||
act_sigterm.sa_flags = SA_RESTART;
|
||||
act_sigterm.sa_handler = &exit_handler;
|
||||
sigaction(SIGTERM, &act_sigterm, NULL);
|
||||
sigaction(SIGTERM, &act_sigterm, nullptr);
|
||||
// Patches
|
||||
_patch_egl_calls();
|
||||
_patch_x11_calls();
|
@ -6,13 +6,13 @@
|
||||
|
||||
// Functions That Have Their Return Values Used
|
||||
static EGLSurface eglCreateWindowSurface_injection(__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) NativeWindowType native_window, __attribute__((unused)) EGLint const *attrib_list) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
static EGLDisplay eglGetDisplay_injection(__attribute__((unused)) NativeDisplayType native_display) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
static EGLContext eglCreateContext_injection(__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLConfig config, __attribute__((unused)) EGLContext share_context, __attribute__((unused)) EGLint const *attrib_list) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
// Call media_swap_buffers()
|
||||
static EGLBoolean eglSwapBuffers_injection(__attribute__((unused)) EGLDisplay display, __attribute__((unused)) EGLSurface surface) {
|
@ -13,7 +13,7 @@ static int XTranslateCoordinates_injection(__attribute__((unused)) void *display
|
||||
}
|
||||
static int XGetWindowAttributes_injection(__attribute__((unused)) void *display, __attribute__((unused)) XID w, XWindowAttributes *window_attributes_return) {
|
||||
// Use MCPI Replacemnt Function
|
||||
XWindowAttributes attributes;
|
||||
XWindowAttributes attributes = {};
|
||||
attributes.x = 0;
|
||||
attributes.y = 0;
|
||||
media_get_framebuffer_size(&attributes.width, &attributes.height);
|
@ -110,7 +110,7 @@ static bool Mob_hurt_injection(Mob *mob, Entity *source, int dmg) {
|
||||
/* Check Health */ \
|
||||
if (new_health < 1 && old_health >= 1) { \
|
||||
/* Get Death Message */ \
|
||||
std::string message = get_death_message((Player *) player, NULL); \
|
||||
std::string message = get_death_message((Player *) player, nullptr); \
|
||||
\
|
||||
/* Post Death Message */ \
|
||||
ServerSideNetworkHandler *server_side_network_handler = (ServerSideNetworkHandler *) player->minecraft->network_handler; \
|
||||
@ -134,7 +134,7 @@ void init_death() {
|
||||
}
|
||||
|
||||
// Fix TNT
|
||||
// This changes PrimedTnt_explode from Level::explode(NULL, x, y, z, 3.1f) to Level::explode(this, x, y, z, 3.1f)
|
||||
// This changes PrimedTnt_explode from Level::explode(nullptr, x, y, z, 3.1f) to Level::explode(this, x, y, z, 3.1f)
|
||||
unsigned char cpy_r1_r0_patch[4] = {0x00, 0x10, 0xa0, 0xe1}; // "cpy r1, r0"
|
||||
patch((void *) 0x87998, cpy_r1_r0_patch);
|
||||
unsigned char ldr_r0_24_patch[4] = {0x24, 0x00, 0x90, 0xe5}; // "ldr r0, [r0, #0x24]"
|
||||
|
@ -6,18 +6,18 @@
|
||||
#include <mods/feature/feature.h>
|
||||
|
||||
// Check For Feature
|
||||
int _feature_has(const char *name) {
|
||||
bool _feature_has(const char *name) {
|
||||
// Get Value
|
||||
char *env = getenv("MCPI_FEATURE_FLAGS");
|
||||
char *features = strdup(env != NULL ? env : "");
|
||||
char *features = strdup(env != nullptr ? env : "");
|
||||
char *tok = strtok(features, "|");
|
||||
int ret = 0;
|
||||
while (tok != NULL) {
|
||||
bool ret = false;
|
||||
while (tok != nullptr) {
|
||||
if (strcmp(tok, name) == 0) {
|
||||
ret = 1;
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
tok = strtok(NULL, "|");
|
||||
tok = strtok(nullptr, "|");
|
||||
}
|
||||
free(features);
|
||||
|
@ -8,16 +8,16 @@
|
||||
static int is_survival = -1;
|
||||
|
||||
// Patch Game Mode
|
||||
static void set_is_survival(int new_is_survival) {
|
||||
static void set_is_survival(bool new_is_survival) {
|
||||
if (is_survival != new_is_survival) {
|
||||
DEBUG("Setting Game Mode: %s", new_is_survival ? "Survival" : "Creative");
|
||||
|
||||
// Correct Inventpry UI
|
||||
unsigned char inventory_patch[4] = {new_is_survival ? 0x00 : 0x01, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0" or "mov r3, #0x1"
|
||||
unsigned char inventory_patch[4] = {(unsigned char) (new_is_survival ? 0x00 : 0x01), 0x30, 0xa0, 0xe3}; // "mov r3, #0x0" or "mov r3, #0x1"
|
||||
patch((void *) 0x16efc, inventory_patch);
|
||||
|
||||
// Use Correct Size For GameMode Object
|
||||
unsigned char size_patch[4] = {new_is_survival ? SURVIVAL_MODE_SIZE : CREATOR_MODE_SIZE, 0x00, 0xa0, 0xe3}; // "mov r0, #SURVIVAL_MODE_SIZE" or "mov r0, #CREATOR_MODE_SIZE"
|
||||
unsigned char size_patch[4] = {(unsigned char) (new_is_survival ? SURVIVAL_MODE_SIZE : CREATOR_MODE_SIZE), 0x00, 0xa0, 0xe3}; // "mov r0, #SURVIVAL_MODE_SIZE" or "mov r0, #CREATOR_MODE_SIZE"
|
||||
patch((void *) 0x16ee4, size_patch);
|
||||
|
||||
// Replace Default CreatorMode Constructor With CreatorMode Or SurvivalMode Constructor
|
||||
@ -28,18 +28,18 @@ static void set_is_survival(int new_is_survival) {
|
||||
}
|
||||
|
||||
// Handle Gamemode Switching
|
||||
static void Minecraft_setIsCreativeMode_injection(Minecraft *this, int32_t new_game_mode) {
|
||||
static void Minecraft_setIsCreativeMode_injection(Minecraft *self, int32_t new_game_mode) {
|
||||
set_is_survival(!new_game_mode);
|
||||
|
||||
// Call Original Method
|
||||
Minecraft_setIsCreativeMode(this, new_game_mode);
|
||||
Minecraft_setIsCreativeMode(self, new_game_mode);
|
||||
}
|
||||
|
||||
// Disable CreatorMode-Specific API Features (Polling Block Hits) In SurvivalMode, This Is Preferable To Crashing
|
||||
static unsigned char *Minecraft_getCreator_injection(Minecraft *minecraft) {
|
||||
if (is_survival) {
|
||||
// SurvivalMode, Return NULL
|
||||
return NULL;
|
||||
// SurvivalMode, Return nullptr
|
||||
return nullptr;
|
||||
} else {
|
||||
// CreatorMode, Call Original Method
|
||||
return Minecraft_getCreator(minecraft);
|
||||
@ -50,7 +50,7 @@ static unsigned char *Minecraft_getCreator_injection(Minecraft *minecraft) {
|
||||
void init_game_mode() {
|
||||
// Dynamic Game Mode Switching
|
||||
if (feature_has("Implement Game-Mode Switching", server_enabled)) {
|
||||
set_is_survival(1);
|
||||
set_is_survival(true);
|
||||
overwrite_calls((void *) Minecraft_setIsCreativeMode, (void *) Minecraft_setIsCreativeMode_injection);
|
||||
|
||||
// Replace CreatorLevel With ServerLevel (This Fixes Beds And Mob Spawning)
|
@ -1,4 +1,4 @@
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
#include <symbols/minecraft.h>
|
||||
@ -8,9 +8,9 @@
|
||||
|
||||
// Get MCPI Home Directory
|
||||
char *home_get() {
|
||||
static char *dir = NULL;
|
||||
static char *dir = nullptr;
|
||||
// Load
|
||||
if (dir == NULL) {
|
||||
if (dir == nullptr) {
|
||||
safe_asprintf(&dir, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME"));
|
||||
}
|
||||
// Return
|
@ -45,7 +45,7 @@ static bool Player_attack_Entity_hurt_injection(Entity *entity, Entity *attacker
|
||||
static ItemInstance *Player_attack_Inventory_getSelected_injection(Inventory *inventory) {
|
||||
// Check If Attack Was Successful
|
||||
if (!last_player_attack_successful) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Call Original Method
|
@ -19,7 +19,7 @@ static void _handle_bow(Minecraft *minecraft) {
|
||||
if (fix_bow && !is_right_click) {
|
||||
GameMode *game_mode = minecraft->game_mode;
|
||||
LocalPlayer *player = minecraft->player;
|
||||
if (player != NULL && game_mode != NULL && LocalPlayer_isUsingItem(player)) {
|
||||
if (player != nullptr && game_mode != nullptr && LocalPlayer_isUsingItem(player)) {
|
||||
game_mode->vtable->releaseUsingItem(game_mode, (Player *) player);
|
||||
}
|
||||
}
|
@ -25,10 +25,10 @@ void input_drop(int drop_slot) {
|
||||
|
||||
// Handle Drop Item Presses
|
||||
static void _handle_drop(Minecraft *minecraft) {
|
||||
if ((minecraft->screen == NULL) && (!creative_is_restricted() || !Minecraft_isCreativeMode(minecraft)) && (drop_item_presses > 0 || drop_slot_pressed)) {
|
||||
if ((minecraft->screen == nullptr) && (!creative_is_restricted() || !Minecraft_isCreativeMode(minecraft)) && (drop_item_presses > 0 || drop_slot_pressed)) {
|
||||
// Get Player
|
||||
LocalPlayer *player = minecraft->player;
|
||||
if (player != NULL) {
|
||||
if (player != nullptr) {
|
||||
// Get Selected Slot
|
||||
int32_t selected_slot = misc_get_real_selected_slot((Player *) player);
|
||||
Inventory *inventory = player->inventory;
|
||||
@ -36,7 +36,7 @@ static void _handle_drop(Minecraft *minecraft) {
|
||||
// Get Item
|
||||
ItemInstance *inventory_item = inventory->vtable->getItem(inventory, selected_slot);
|
||||
// Check
|
||||
if (inventory_item != NULL && inventory_item->count > 0) {
|
||||
if (inventory_item != nullptr && inventory_item->count > 0) {
|
||||
// Copy
|
||||
ItemInstance *dropped_item = new ItemInstance;
|
||||
ALLOC_CHECK(dropped_item);
|
||||
|
@ -22,8 +22,8 @@ int input_back() {
|
||||
|
||||
// Handle Back Button Presses
|
||||
static void _handle_back(Minecraft *minecraft) {
|
||||
// If Minecraft's Level property is initialized, but Minecraft's Player property is NULL, then Minecraft::handleBack may crash.
|
||||
if (minecraft->level != NULL && minecraft->player == NULL) {
|
||||
// If Minecraft's Level property is initialized, but Minecraft's Player property is nullptr, then Minecraft::handleBack may crash.
|
||||
if (minecraft->level != nullptr && minecraft->player == nullptr) {
|
||||
// Unable to safely run Minecraft::handleBack, deferring until safe.
|
||||
return;
|
||||
}
|
||||
@ -38,7 +38,7 @@ static void _handle_back(Minecraft *minecraft) {
|
||||
static bool OptionsScreen_handleBackEvent_injection(OptionsScreen *screen, bool do_nothing) {
|
||||
if (!do_nothing) {
|
||||
Minecraft *minecraft = screen->minecraft;
|
||||
Minecraft_setScreen(minecraft, NULL);
|
||||
Minecraft_setScreen(minecraft, nullptr);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -48,10 +48,10 @@ static int32_t InBedScreen_handleBackEvent_injection(InBedScreen *screen, bool d
|
||||
if (!do_nothing) {
|
||||
// Close Screen
|
||||
Minecraft *minecraft = screen->minecraft;
|
||||
Minecraft_setScreen(minecraft, NULL);
|
||||
Minecraft_setScreen(minecraft, nullptr);
|
||||
// Stop Sleeping
|
||||
LocalPlayer *player = minecraft->player;
|
||||
if (player != NULL) {
|
||||
if (player != nullptr) {
|
||||
player->vtable->stopSleepInBed(player, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
@ -80,7 +80,7 @@ static void _handle_mouse_grab(Minecraft *minecraft) {
|
||||
|
||||
// Block UI Interaction When Mouse Is Locked
|
||||
static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(Minecraft *minecraft) {
|
||||
bool is_in_game = minecraft->screen == NULL || minecraft->screen->vtable == (Screen_vtable *) Touch_IngameBlockSelectionScreen_vtable_base;
|
||||
bool is_in_game = minecraft->screen == nullptr || minecraft->screen->vtable == (Screen_vtable *) Touch_IngameBlockSelectionScreen_vtable_base;
|
||||
if (!enable_misc || (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF && is_in_game)) {
|
||||
// Call Original Method
|
||||
return creative_is_restricted() && Minecraft_isCreativeMode(minecraft);
|
@ -32,7 +32,7 @@ static void _fix_third_person(Minecraft *minecraft) {
|
||||
|
||||
// Font-Facing View
|
||||
static void invert_rotation(Entity *entity) {
|
||||
if (entity != NULL) {
|
||||
if (entity != nullptr) {
|
||||
entity->yaw = 180.f + entity->yaw;
|
||||
entity->old_yaw = 180.f + entity->old_yaw;
|
||||
entity->pitch = -entity->pitch;
|
||||
@ -40,7 +40,7 @@ static void invert_rotation(Entity *entity) {
|
||||
}
|
||||
}
|
||||
static void revert_rotation(Entity *entity) {
|
||||
if (entity != NULL) {
|
||||
if (entity != nullptr) {
|
||||
entity->yaw = -180.f + entity->yaw;
|
||||
entity->old_yaw = -180.f + entity->old_yaw;
|
||||
entity->pitch = -entity->pitch;
|
||||
@ -48,7 +48,7 @@ static void revert_rotation(Entity *entity) {
|
||||
}
|
||||
}
|
||||
static int is_front_facing = 0;
|
||||
static LocalPlayer *stored_player = NULL;
|
||||
static LocalPlayer *stored_player = nullptr;
|
||||
static void GameRenderer_setupCamera_injection(GameRenderer *game_renderer, float param_1, int param_2) {
|
||||
// Get Objects
|
||||
Minecraft *minecraft = game_renderer->minecraft;
|
@ -89,7 +89,7 @@ SETUP_CALLBACK(tiles_setup, void);
|
||||
// Handle Custom Tiles Setup Behavior
|
||||
static void Tile_initTiles_injection() {
|
||||
// Run Functions
|
||||
handle_misc_tiles_setup(NULL);
|
||||
handle_misc_tiles_setup(nullptr);
|
||||
|
||||
// Call Original Method
|
||||
Tile_initTiles();
|
||||
@ -103,7 +103,7 @@ static void Item_initItems_injection() {
|
||||
Item_initItems();
|
||||
|
||||
// Run Functions
|
||||
handle_misc_items_setup(NULL);
|
||||
handle_misc_items_setup(nullptr);
|
||||
}
|
||||
|
||||
// Run Functions On Language Setup
|
||||
@ -114,7 +114,7 @@ static void I18n_loadLanguage_injection(AppPlatform *app, std::string language_n
|
||||
I18n_loadLanguage(app, language_name);
|
||||
|
||||
// Run Functions
|
||||
handle_misc_language_setup(NULL);
|
||||
handle_misc_language_setup(nullptr);
|
||||
}
|
||||
|
||||
// Run Functions On GUI Key Press
|
||||
|
@ -45,7 +45,7 @@ void misc_add_message(Gui *gui, const char *text) {
|
||||
|
||||
// Print Progress Reports
|
||||
static int last_progress = -1;
|
||||
static const char *last_message = NULL;
|
||||
static const char *last_message = nullptr;
|
||||
static void print_progress(Minecraft *minecraft) {
|
||||
const char *message = Minecraft_getProgressMessage(minecraft);
|
||||
int32_t progress = minecraft->progress;
|
||||
@ -53,7 +53,7 @@ static void print_progress(Minecraft *minecraft) {
|
||||
message = "Ready";
|
||||
progress = -1;
|
||||
}
|
||||
if (message != NULL) {
|
||||
if (message != nullptr) {
|
||||
bool message_different = message != last_message;
|
||||
bool progress_significant = is_progress_difference_significant(progress, last_progress);
|
||||
if (message_different || progress_significant) {
|
||||
@ -99,5 +99,5 @@ void _init_misc_logging() {
|
||||
overwrite_calls((void *) Level_saveLevelData, (void *) Level_saveLevelData_injection);
|
||||
|
||||
// Disable stdout Buffering
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__attribute__((visibility("internal"))) void _init_misc_cpp();
|
||||
__attribute__((visibility("internal"))) void _init_misc_logging();
|
||||
__attribute__((visibility("internal"))) void _init_misc_api();
|
||||
|
||||
|
@ -1,850 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
#include <GLES/gl.h>
|
||||
#endif
|
||||
|
||||
#include <libreborn/libreborn.h>
|
||||
#include <symbols/minecraft.h>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <media-layer/core.h>
|
||||
|
||||
#include <mods/init/init.h>
|
||||
#include <mods/feature/feature.h>
|
||||
#include "misc-internal.h"
|
||||
#include <mods/misc/misc.h>
|
||||
|
||||
// Heart food overlay
|
||||
static int heal_amount = 0, heal_amount_drawing = 0;
|
||||
void Gui_renderHearts_injection(Gui *gui) {
|
||||
// Get heal_amount
|
||||
heal_amount = heal_amount_drawing = 0;
|
||||
|
||||
Inventory *inventory = gui->minecraft->player->inventory;
|
||||
ItemInstance *held_ii = Inventory_getSelected(inventory);
|
||||
if (held_ii) {
|
||||
Item *held = Item_items[held_ii->id];
|
||||
if (held->vtable->isFood(held) && held_ii->id) {
|
||||
int nutrition = ((FoodItem *) held)->nutrition;
|
||||
int cur_health = gui->minecraft->player->health;
|
||||
int heal_num = fmin(cur_health + nutrition, 20) - cur_health;
|
||||
heal_amount = heal_amount_drawing = heal_num;
|
||||
}
|
||||
}
|
||||
|
||||
// Call original
|
||||
Gui_renderHearts(gui);
|
||||
}
|
||||
|
||||
#define PINK_HEART_FULL 70
|
||||
#define PINK_HEART_HALF 79
|
||||
Gui_blit_t Gui_blit_renderHearts_original = NULL;
|
||||
void Gui_renderHearts_GuiComponent_blit_overlay_empty_injection(Gui *gui, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t w1, int32_t h1, int32_t w2, int32_t h2) {
|
||||
// Call original
|
||||
Gui_blit_renderHearts_original(gui, x1, y1, x2, y2, w1, h1, w2, h2);
|
||||
// Render the overlay
|
||||
if (heal_amount_drawing == 1) {
|
||||
// Half heart
|
||||
Gui_blit_renderHearts_original(gui, x1, y1, PINK_HEART_HALF, 0, w1, h1, w2, h2);
|
||||
heal_amount_drawing = 0;
|
||||
} else if (heal_amount_drawing > 0) {
|
||||
// Full heart
|
||||
Gui_blit_renderHearts_original(gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2);
|
||||
heal_amount_drawing -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Gui_renderHearts_GuiComponent_blit_overlay_hearts_injection(Gui *gui, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t w1, int32_t h1, int32_t w2, int32_t h2) {
|
||||
// Offset the overlay
|
||||
if (x2 == 52) {
|
||||
heal_amount_drawing += 2;
|
||||
} else if (x2 == 61 && heal_amount) {
|
||||
// Half heart, flipped
|
||||
Gui_blit_renderHearts_original(gui, x1, y1, PINK_HEART_FULL, 0, w1, h1, w2, h2);
|
||||
heal_amount_drawing += 1;
|
||||
};
|
||||
// Call original
|
||||
Gui_blit_renderHearts_original(gui, x1, y1, x2, y2, w1, h1, w2, h2);
|
||||
heal_amount_drawing = fmin(heal_amount_drawing, heal_amount);
|
||||
}
|
||||
|
||||
// Classic HUD
|
||||
#define DEFAULT_HUD_PADDING 2
|
||||
#define NEW_HUD_PADDING 1
|
||||
#define HUD_ELEMENT_WIDTH 82
|
||||
#define HUD_ELEMENT_HEIGHT 9
|
||||
#define TOOLBAR_HEIGHT 22
|
||||
#define SLOT_WIDTH 20
|
||||
#define DEFAULT_BUBBLES_PADDING 1
|
||||
#define NUMBER_OF_SLOTS 9
|
||||
static int use_classic_hud = 0;
|
||||
static void Gui_renderHearts_GuiComponent_blit_hearts_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) {
|
||||
Minecraft *minecraft = component->minecraft;
|
||||
x_dest -= DEFAULT_HUD_PADDING;
|
||||
float width = ((float) minecraft->screen_width) * Gui_InvGuiScale;
|
||||
float height = ((float) minecraft->screen_height) * Gui_InvGuiScale;
|
||||
x_dest += (width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2;
|
||||
y_dest -= DEFAULT_HUD_PADDING;
|
||||
y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - NEW_HUD_PADDING;
|
||||
// Call Original Method
|
||||
Gui_blit(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src);
|
||||
}
|
||||
static void Gui_renderHearts_GuiComponent_blit_armor_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) {
|
||||
Minecraft *minecraft = component->minecraft;
|
||||
x_dest -= DEFAULT_HUD_PADDING + HUD_ELEMENT_WIDTH;
|
||||
float width = ((float) minecraft->screen_width) * Gui_InvGuiScale;
|
||||
float height = ((float) minecraft->screen_height) * Gui_InvGuiScale;
|
||||
x_dest += width - ((width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2) - HUD_ELEMENT_WIDTH;
|
||||
y_dest -= DEFAULT_HUD_PADDING;
|
||||
y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - NEW_HUD_PADDING;
|
||||
// Call Original Method
|
||||
Gui_blit(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src);
|
||||
}
|
||||
static void Gui_renderBubbles_GuiComponent_blit_injection(Gui *component, int32_t x_dest, int32_t y_dest, int32_t x_src, int32_t y_src, int32_t width_dest, int32_t height_dest, int32_t width_src, int32_t height_src) {
|
||||
Minecraft *minecraft = component->minecraft;
|
||||
x_dest -= DEFAULT_HUD_PADDING;
|
||||
float width = ((float) minecraft->screen_width) * Gui_InvGuiScale;
|
||||
float height = ((float) minecraft->screen_height) * Gui_InvGuiScale;
|
||||
x_dest += (width - (NUMBER_OF_SLOTS * SLOT_WIDTH)) / 2;
|
||||
y_dest -= DEFAULT_HUD_PADDING + DEFAULT_BUBBLES_PADDING + HUD_ELEMENT_HEIGHT;
|
||||
y_dest += height - HUD_ELEMENT_HEIGHT - TOOLBAR_HEIGHT - HUD_ELEMENT_HEIGHT - NEW_HUD_PADDING;
|
||||
// Call Original Method
|
||||
Gui_blit(component, x_dest, y_dest, x_src, y_src, width_dest, height_dest, width_src, height_src);
|
||||
}
|
||||
|
||||
// Additional GUI Rendering
|
||||
static int hide_chat_messages = 0;
|
||||
bool is_in_chat = 0;
|
||||
static int render_selected_item_text = 0;
|
||||
static void Gui_renderChatMessages_injection(Gui *gui, int32_t y_offset, uint32_t max_messages, bool disable_fading, Font *font) {
|
||||
// Handle Classic HUD
|
||||
if (use_classic_hud) {
|
||||
Minecraft *minecraft = gui->minecraft;
|
||||
if (!Minecraft_isCreativeMode(minecraft)) {
|
||||
y_offset -= (HUD_ELEMENT_HEIGHT * 2) + NEW_HUD_PADDING;
|
||||
}
|
||||
}
|
||||
|
||||
// Call Original Method
|
||||
if (!hide_chat_messages && !is_in_chat) {
|
||||
Gui_renderChatMessages(gui, y_offset, max_messages, disable_fading, font);
|
||||
}
|
||||
|
||||
// Render Selected Item Text
|
||||
if (render_selected_item_text) {
|
||||
// Fix GL Mode
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
#endif
|
||||
// Calculate Selected Item Text Scale
|
||||
Minecraft *minecraft = gui->minecraft;
|
||||
int32_t screen_width = minecraft->screen_width;
|
||||
float scale = ((float) screen_width) * Gui_InvGuiScale;
|
||||
// Render Selected Item Text
|
||||
Gui_renderOnSelectItemNameText(gui, (int32_t) scale, font, y_offset - 0x13);
|
||||
}
|
||||
}
|
||||
// Reset Selected Item Text Timer On Slot Select
|
||||
static uint32_t reset_selected_item_text_timer = 0;
|
||||
static void Gui_tick_injection(Gui *gui) {
|
||||
// Call Original Method
|
||||
Gui_tick(gui);
|
||||
|
||||
// Handle Reset
|
||||
if (render_selected_item_text) {
|
||||
float *selected_item_text_timer = &gui->selected_item_text_timer;
|
||||
if (reset_selected_item_text_timer) {
|
||||
// Reset
|
||||
*selected_item_text_timer = 0;
|
||||
reset_selected_item_text_timer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Trigger Reset Selected Item Text Timer On Slot Select
|
||||
static void Inventory_selectSlot_injection(Inventory *inventory, int32_t slot) {
|
||||
// Call Original Method
|
||||
Inventory_selectSlot(inventory, slot);
|
||||
|
||||
// Trigger Reset Selected Item Text Timer
|
||||
if (render_selected_item_text) {
|
||||
reset_selected_item_text_timer = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Translucent Toolbar
|
||||
static void Gui_renderToolBar_injection(Gui *gui, float param_1, int32_t param_2, int32_t param_3) {
|
||||
// Call Original Method
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
int was_blend_enabled = glIsEnabled(GL_BLEND);
|
||||
if (!was_blend_enabled) {
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
#endif
|
||||
Gui_renderToolBar(gui, param_1, param_2, param_3);
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
if (!was_blend_enabled) {
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
static void Gui_renderToolBar_glColor4f_injection(GLfloat red, GLfloat green, GLfloat blue, __attribute__((unused)) GLfloat alpha) {
|
||||
// Fix Alpha
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
glColor4f(red, green, blue, 1.0f);
|
||||
#else
|
||||
(void) red;
|
||||
(void) green;
|
||||
(void) blue;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Fix Screen Rendering When GUI is Hidden
|
||||
static void Screen_render_injection(Screen *screen, int32_t param_1, int32_t param_2, float param_3) {
|
||||
// Fix
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
#endif
|
||||
// Call Original Method
|
||||
Screen_render_non_virtual(screen, param_1, param_2, param_3);
|
||||
}
|
||||
|
||||
// Sanitize Username
|
||||
#define MAX_USERNAME_LENGTH 16
|
||||
static void LoginPacket_read_injection(LoginPacket *packet, RakNet_BitStream *bit_stream) {
|
||||
// Call Original Method
|
||||
LoginPacket_read_non_virtual(packet, bit_stream);
|
||||
|
||||
// Prepare
|
||||
RakNet_RakString *rak_string = &packet->username;
|
||||
// Get Original Username
|
||||
RakNet_RakString_SharedString *shared_string = rak_string->sharedString;
|
||||
char *c_str = shared_string->c_str;
|
||||
// Sanitize
|
||||
char *new_username = strdup(c_str);
|
||||
ALLOC_CHECK(new_username);
|
||||
sanitize_string(&new_username, MAX_USERNAME_LENGTH, 0);
|
||||
// Set New Username
|
||||
RakNet_RakString_Assign(rak_string, new_username);
|
||||
// Free
|
||||
free(new_username);
|
||||
}
|
||||
|
||||
// Fix RakNet::RakString Security Bug
|
||||
//
|
||||
// RakNet::RakString's format constructor is often given unsanitized user input and is never used for formatting,
|
||||
// this is a massive security risk, allowing clients to run arbitrary format specifiers, this disables the
|
||||
// formatting functionality.
|
||||
static RakNet_RakString *RakNet_RakString_injection(RakNet_RakString *rak_string, const char *format, ...) {
|
||||
// Call Original Method
|
||||
return RakNet_RakString_constructor(rak_string, "%s", format);
|
||||
}
|
||||
|
||||
// Print Error Message If RakNet Startup Fails
|
||||
static char *RAKNET_ERROR_NAMES[] = {
|
||||
"Success",
|
||||
"Already Started",
|
||||
"Invalid Socket Descriptors",
|
||||
"Invalid Max Connections",
|
||||
"Soc |