2020-10-02 02:17:22 +00:00
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
#include <streambuf>
|
2020-10-04 00:30:15 +00:00
|
|
|
#include <vector>
|
2020-10-02 02:17:22 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2020-10-04 00:30:15 +00:00
|
|
|
#include <libcore/libcore.h>
|
|
|
|
|
|
|
|
#include "extra.h"
|
2020-10-10 23:02:13 +00:00
|
|
|
#include "cxx11_util.h"
|
|
|
|
|
2020-11-21 21:52:27 +00:00
|
|
|
#include "minecraft.h"
|
|
|
|
|
2020-10-10 23:02:13 +00:00
|
|
|
#include <cstdio>
|
2020-10-04 00:30:15 +00:00
|
|
|
|
2020-10-02 02:17:22 +00:00
|
|
|
extern "C" {
|
2020-11-20 21:38:23 +00:00
|
|
|
// Read Asset File
|
2020-11-21 21:52:27 +00:00
|
|
|
static cxx11_string AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) {
|
2020-10-02 02:17:22 +00:00
|
|
|
std::string full_path("./data/");
|
2020-10-10 23:02:13 +00:00
|
|
|
full_path.append(path);
|
2020-10-02 02:17:22 +00:00
|
|
|
std::ifstream stream(full_path);
|
|
|
|
std::string str((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
|
2020-10-10 23:02:13 +00:00
|
|
|
return create_cxx11_string(str.c_str());
|
2020-10-02 02:17:22 +00:00
|
|
|
}
|
2020-10-04 00:30:15 +00:00
|
|
|
|
2020-11-20 21:38:23 +00:00
|
|
|
// Open Sign Screen
|
2020-11-21 21:52:27 +00:00
|
|
|
static void LocalPlayer_openTextEdit_injection(unsigned char *local_player, unsigned char *sign) {
|
2020-10-04 00:30:15 +00:00
|
|
|
if (*(int *)(sign + 0x18) == 4) {
|
|
|
|
unsigned char *minecraft = *(unsigned char **) (local_player + 0xc90);
|
|
|
|
unsigned char *screen = (unsigned char *) ::operator new(0xd0);
|
|
|
|
screen = (*TextEditScreen)(screen, sign);
|
2020-11-02 14:58:43 +00:00
|
|
|
(*Minecraft_setScreen)(minecraft, screen);
|
2020-10-04 00:30:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BACKSPACE_KEY 8
|
|
|
|
|
|
|
|
static int is_valid_key(char key) {
|
|
|
|
return (key >= 32 && key <= 126) || key == BACKSPACE_KEY;
|
|
|
|
}
|
|
|
|
|
2020-11-20 21:38:23 +00:00
|
|
|
// Store Text Input
|
2020-10-04 00:30:15 +00:00
|
|
|
std::vector<char> input;
|
2020-10-14 17:40:32 +00:00
|
|
|
void extra_key_press(char key) {
|
2020-10-04 00:30:15 +00:00
|
|
|
if (is_valid_key(key)) {
|
2020-10-04 20:45:00 +00:00
|
|
|
input.push_back(key);
|
2020-10-04 00:30:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-14 17:40:32 +00:00
|
|
|
void extra_clear_input() {
|
2020-10-04 00:30:15 +00:00
|
|
|
input.clear();
|
|
|
|
}
|
|
|
|
|
2020-11-20 21:38:23 +00:00
|
|
|
// Handle Text Input
|
2020-11-21 21:52:27 +00:00
|
|
|
static void TextEditScreen_updateEvents_injection(unsigned char *screen) {
|
2020-11-20 21:38:23 +00:00
|
|
|
// Call Original Method
|
2020-11-02 14:58:43 +00:00
|
|
|
(*Screen_updateEvents)(screen);
|
2020-10-04 00:30:15 +00:00
|
|
|
|
|
|
|
if (*(char *)(screen + 4) == '\0') {
|
|
|
|
uint32_t vtable = *((uint32_t *) screen);
|
|
|
|
for (char key : input) {
|
|
|
|
if (key == BACKSPACE_KEY) {
|
|
|
|
// Handle Backspace
|
2020-11-02 14:58:43 +00:00
|
|
|
(*(Screen_keyPressed_t *) (vtable + 0x6c))(screen, BACKSPACE_KEY);
|
2020-10-04 00:30:15 +00:00
|
|
|
} else {
|
|
|
|
// Handle Nrmal Key
|
2020-11-02 14:58:43 +00:00
|
|
|
(*(Screen_keyboardNewChar_t *) (vtable + 0x70))(screen, key);
|
2020-10-04 00:30:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-14 17:40:32 +00:00
|
|
|
extra_clear_input();
|
2020-10-04 00:30:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 17:34:11 +00:00
|
|
|
static void inventory_add_item(unsigned char *inventory, unsigned char *item, bool is_tile) {
|
|
|
|
unsigned char *item_instance = (unsigned char *) ::operator new(0xc);
|
|
|
|
item_instance = (*(is_tile ? ItemInstance_tile : ItemInstance_item))(item_instance, item);
|
|
|
|
(*FillingContainer_addItem)(inventory, item_instance);
|
|
|
|
}
|
|
|
|
|
2020-11-02 17:42:06 +00:00
|
|
|
static int32_t FillingContainer_addItem_injection(unsigned char *filling_container, unsigned char *item_instance) {
|
2020-11-02 17:34:11 +00:00
|
|
|
// Call Original
|
2020-11-02 17:42:06 +00:00
|
|
|
int32_t ret = (*FillingContainer_addItem)(filling_container, item_instance);
|
2020-11-02 17:34:11 +00:00
|
|
|
|
2020-11-20 18:36:03 +00:00
|
|
|
// Add Items
|
|
|
|
inventory_add_item(filling_container, *item_flintAndSteel, false);
|
|
|
|
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++) {
|
|
|
|
unsigned char *item_instance = (unsigned char *) ::operator new(0xc);
|
|
|
|
item_instance = (*ItemInstance_damage)(item_instance, *item_dye_powder, 1, i);
|
|
|
|
(*FillingContainer_addItem)(filling_container, item_instance);
|
2020-11-02 17:34:11 +00:00
|
|
|
}
|
2020-11-20 18:36:03 +00:00
|
|
|
// Add Tiles
|
|
|
|
inventory_add_item(filling_container, *tile_water, true);
|
|
|
|
inventory_add_item(filling_container, *tile_lava, true);
|
|
|
|
inventory_add_item(filling_container, *tile_calmWater, true);
|
|
|
|
inventory_add_item(filling_container, *tile_calmLava, true);
|
|
|
|
inventory_add_item(filling_container, *tile_glowingObsidian, true);
|
|
|
|
inventory_add_item(filling_container, *tile_topSnow, true);
|
|
|
|
inventory_add_item(filling_container, *tile_ice, true);
|
|
|
|
inventory_add_item(filling_container, *tile_invisible_bedrock, true);
|
2020-11-02 17:42:06 +00:00
|
|
|
|
|
|
|
return ret;
|
2020-11-02 17:34:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 18:36:03 +00:00
|
|
|
static void Minecraft_tick_injection(unsigned char *minecraft, int32_t param_1, int32_t param_2) {
|
|
|
|
// Call Original Method
|
|
|
|
(*Minecraft_tick)(minecraft, param_1, param_2);
|
|
|
|
|
|
|
|
// Tick Dynamic Textures
|
|
|
|
unsigned char *textures = *(unsigned char **) (minecraft + 0x164);
|
|
|
|
if (textures != NULL) {
|
|
|
|
(*Textures_tick)(textures, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:30:15 +00:00
|
|
|
__attribute((constructor)) static void init() {
|
2020-11-21 21:52:27 +00:00
|
|
|
// Implement AppPlatform::readAssetFile So Translations Work
|
|
|
|
overwrite((void *) AppPlatform_readAssetFile, (void *) AppPlatform_readAssetFile_injection);
|
2020-10-04 00:30:15 +00:00
|
|
|
|
2020-10-14 17:40:32 +00:00
|
|
|
if (extra_has_feature("Fix Sign Placement")) {
|
2020-10-04 00:30:15 +00:00
|
|
|
// Fix Signs
|
2020-11-21 21:52:27 +00:00
|
|
|
patch_address(LocalPlayer_openTextEdit_vtable_addr, (void *) LocalPlayer_openTextEdit_injection);
|
|
|
|
patch_address(TextEditScreen_updateEvents_vtable_addr, (void *) TextEditScreen_updateEvents_injection);
|
2020-10-04 00:30:15 +00:00
|
|
|
}
|
2020-11-02 17:34:11 +00:00
|
|
|
|
2020-11-20 18:36:03 +00:00
|
|
|
if (extra_has_feature("Expand Creative Inventory")) {
|
|
|
|
// Add Extra Items To Creative Inventory (Only Replace Specific Function Call)
|
|
|
|
overwrite_call((void *) 0x8e0fc, (void *) FillingContainer_addItem_injection);
|
|
|
|
}
|
|
|
|
|
2020-11-20 18:37:54 +00:00
|
|
|
if (extra_has_feature("Animated Water")) {
|
2020-11-20 18:36:03 +00:00
|
|
|
// Tick Dynamic Textures (Animated Water)
|
|
|
|
overwrite_calls((void *) Minecraft_tick, (void *) Minecraft_tick_injection);
|
2020-11-02 17:34:11 +00:00
|
|
|
}
|
2020-10-04 00:30:15 +00:00
|
|
|
}
|
2020-10-02 02:17:22 +00:00
|
|
|
}
|