Perfect Fix Attacking Patch + Seperate Mappings

This commit is contained in:
TheBrokenRail 2020-11-21 16:52:27 -05:00
parent bc442034e2
commit f2c2799f7e
7 changed files with 357 additions and 196 deletions

View File

@ -161,10 +161,6 @@ static void click(int button, int up) {
event.button.state = up ? SDL_RELEASED : SDL_PRESSED;
event.button.button = button;
SDL_PushEvent(&event);
if (button == SDL_BUTTON_RIGHT) {
extra_set_is_right_click(!up);
}
}
// Pass Mouse Click To SDL
@ -352,6 +348,12 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) {
extra_third_person();
handled = 1;
}
} else if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
if (event->button.button == SDL_BUTTON_RIGHT) {
extra_set_is_right_click(event->button.state != SDL_RELEASED);
} else if (event->button.button == SDL_BUTTON_LEFT) {
extra_set_is_left_click(event->button.state != SDL_RELEASED);
}
}
if (handled) {

View File

@ -6,6 +6,8 @@
#include "extra.h"
#include "server/server.h"
#include "minecraft.h"
static int mob_spawning = 0;
// Override Mob Spawning
static uint32_t LevelData_getSpawnMobs_injection(__attribute__((unused)) unsigned char *level_data) {
@ -18,14 +20,6 @@ void extra_set_is_right_click(int val) {
is_right_click = val;
}
typedef void (*releaseUsingItem_t)(unsigned char *game_mode, unsigned char *player);
typedef void (*Minecraft_tickInput_t)(unsigned char *minecraft);
static Minecraft_tickInput_t Minecraft_tickInput = (Minecraft_tickInput_t) 0x15ffc;
typedef int (*Player_isUsingItem_t)(unsigned char *player);
static Player_isUsingItem_t Player_isUsingItem = (Player_isUsingItem_t) 0x8f15c;
// Enable Bow & Arrow Fix
static int fix_bow = 0;
@ -51,8 +45,8 @@ static void Minecraft_tickInput_injection(unsigned char *minecraft) {
unsigned char *player = *(unsigned char **) (minecraft + 0x18c);
if (player != NULL && game_mode != NULL && (*Player_isUsingItem)(player)) {
unsigned char *game_mode_vtable = *(unsigned char **) game_mode;
releaseUsingItem_t releaseUsingItem = *(releaseUsingItem_t *) (game_mode_vtable + 0x5c);
(*releaseUsingItem)(game_mode, player);
GameMode_releaseUsingItem_t GameMode_releaseUsingItem = *(GameMode_releaseUsingItem_t *) (game_mode_vtable + 0x5c);
(*GameMode_releaseUsingItem)(game_mode, player);
}
}
@ -73,9 +67,6 @@ static void Minecraft_tickInput_injection(unsigned char *minecraft) {
third_person_toggle = 0;
}
typedef void (*Gui_tickItemDrop_t)(unsigned char *);
static Gui_tickItemDrop_t Gui_tickItemDrop = (Gui_tickItemDrop_t) 0x27778;
#include <SDL/SDL_events.h>
// Block UI Interaction When Mouse Is Locked
@ -86,9 +77,6 @@ static void Gui_tickItemDrop_injection(unsigned char *this) {
}
}
typedef void (*Gui_handleClick_t)(unsigned char *this, int32_t param_2, int32_t param_3, int32_t param_4);
static Gui_handleClick_t Gui_handleClick = (Gui_handleClick_t) 0x2599c;
// Block UI Interaction When Mouse Is Locked
static void Gui_handleClick_injection(unsigned char *this, int32_t param_2, int32_t param_3, int32_t param_4) {
if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) {
@ -99,10 +87,6 @@ static void Gui_handleClick_injection(unsigned char *this, int32_t param_2, int3
static int is_survival = -1;
static void *Creator = (void *) 0x1a044;
static void *SurvivalMode = (void *) 0x1b7d8;
static void *CreativeMode = (void *) 0x1b258;
// Patch Game Mode
static void set_is_survival(int new_is_survival) {
if (is_survival != new_is_survival) {
@ -116,16 +100,13 @@ static void set_is_survival(int new_is_survival) {
unsigned char size_patch[4] = {new_is_survival ? 0x24 : 0x18, 0x00, 0xa0, 0xe3};
patch((void *) 0x16ee4, size_patch);
// Replace Creator Constructor With CreatorMode Or SurvivalMode Constructor
// Replace Creator Constructor With CreativeMode Or SurvivalMode Constructor
overwrite(Creator, new_is_survival ? SurvivalMode : CreativeMode);
is_survival = new_is_survival;
}
}
typedef void (*Minecraft_setIsCreativeMode_t)(unsigned char *, int32_t);
static Minecraft_setIsCreativeMode_t Minecraft_setIsCreativeMode = (Minecraft_setIsCreativeMode_t) 0x16ec4;
// Handle Gamemode Switching
static void Minecraft_setIsCreativeMode_injection(unsigned char *this, int32_t new_game_mode) {
set_is_survival(!new_game_mode);
@ -143,9 +124,6 @@ static char *get_username() {
return username;
}
typedef void (*Minecraft_init_t)(unsigned char *this);
static Minecraft_init_t Minecraft_init = (Minecraft_init_t) 0x1700c;
static int fancy_graphics;
static int peaceful_mode;
static int anaglyph;
@ -208,7 +186,7 @@ int extra_get_mode() {
}
// Enable Touch GUI
static int32_t Minecraft_isTouchscreen(__attribute__((unused)) unsigned char *minecraft) {
static int32_t Minecraft_isTouchscreen_injection(__attribute__((unused)) unsigned char *minecraft) {
return 1;
}
@ -218,6 +196,31 @@ int extra_get_smooth_lighting() {
return smooth_lighting;
}
// Store Left Click (0 = Not Pressed, 1 = Pressed, 2 = Repeat)
// This Is Set To Repeat After First Attempted Left-Click Build Interaction
static int is_left_click = 0;
void extra_set_is_left_click(int val) {
if ((is_left_click == 0 && val == 1) || (is_left_click != 0 && val == 0) || (is_left_click == 1 && val == 2)) {
is_left_click = val;
}
}
// Add Attacking To MouseBuildInput
static int32_t MouseBuildInput_tickBuild_injection(unsigned char *mouse_build_input, unsigned char *player, uint32_t *build_action_intention_return) {
// Call Original Method
int32_t ret = (*MouseBuildInput_tickBuild)(mouse_build_input, player, build_action_intention_return);
// Use Attack BuildActionIntention If No Other Valid BuildActionIntention Is Available And The Stored Left Click Mode Is Pressed (Not Repeat)
if (ret != 0 && is_left_click == 1 && *build_action_intention_return == 0xa) {
// Change BuildActionIntention To Attack On First Left Click
*build_action_intention_return = 0x8;
// Block Repeat Attacks Without Releasing Button
is_left_click = 2;
}
return ret;
}
__attribute__((constructor)) static void init() {
is_server = extra_get_mode() == 2;
if (is_server) {
@ -227,7 +230,7 @@ __attribute__((constructor)) static void init() {
int touch_gui = !is_server && extra_has_feature("Touch GUI");
if (touch_gui) {
// Main UI
overwrite((void *) 0x1639c, Minecraft_isTouchscreen);
overwrite((void *) Minecraft_isTouchscreen, Minecraft_isTouchscreen_injection);
// Force Correct Toolbar Size
unsigned char toolbar_patch[4] = {0x01, 0x00, 0x50, 0xe3};
patch((void *) 0x257b0, toolbar_patch);
@ -259,14 +262,7 @@ __attribute__((constructor)) static void init() {
if (extra_has_feature("Fix Attacking")) {
// Allow Attacking Mobs
unsigned char attacking_patch[4] = {0x00, 0xf0, 0x20, 0xe3};
patch((void *) 0x162d4, attacking_patch);
// Fix Instamining When Using This Patch
unsigned char instamine_patch[4] = {0x61, 0x00, 0x00, 0xea};
patch((void *) 0x15b0c, instamine_patch);
// Fix Excessive Hand Swinging When Using This Patch
unsigned char excessive_swing_patch[4] = {0x06, 0x00, 0x00, 0xea};
patch((void *) 0x1593c, excessive_swing_patch);
patch_address(MouseBuildInput_tickBuild_vtable_addr, (void *) MouseBuildInput_tickBuild_injection);
}
if (is_server) {
@ -275,7 +271,7 @@ __attribute__((constructor)) static void init() {
mob_spawning = extra_has_feature("Mob Spawning");
}
// Set Mob Spawning
overwrite((void *) 0xbabec, LevelData_getSpawnMobs_injection);
overwrite((void *) LevelData_getSpawnMobs, LevelData_getSpawnMobs_injection);
// Replace CreatorLevel With ServerLevel (This Fixes Beds And Mob Spawning)
unsigned char level_patch[4] = {0x68, 0x7e, 0x01, 0xeb};
@ -308,7 +304,6 @@ __attribute__((constructor)) static void init() {
username = get_username();
INFO("Setting Username: %s", username);
}
char **default_username = (char **) 0x18fd4;
if (strcmp(*default_username, "StevePi") != 0) {
ERR("%s", "Default Username Is Invalid");
}

View File

@ -10,11 +10,13 @@
#include "extra.h"
#include "cxx11_util.h"
#include "minecraft.h"
#include <cstdio>
extern "C" {
// Read Asset File
static cxx11_string AppPlatform_readAssetFile(__attribute__((unused)) unsigned char *app_platform, std::string const& path) {
static cxx11_string AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) {
std::string full_path("./data/");
full_path.append(path);
std::ifstream stream(full_path);
@ -22,14 +24,8 @@ extern "C" {
return create_cxx11_string(str.c_str());
}
typedef unsigned char *(*TextEditScreen_t)(unsigned char *, unsigned char *);
static TextEditScreen_t TextEditScreen = (TextEditScreen_t) 0x3a840;
typedef void (*Minecraft_setScreen_t)(unsigned char *, unsigned char *);
static Minecraft_setScreen_t Minecraft_setScreen = (Minecraft_setScreen_t) 0x15d6c;
// Open Sign Screen
static void LocalPlayer_openTextEdit(unsigned char *local_player, unsigned char *sign) {
static void LocalPlayer_openTextEdit_injection(unsigned char *local_player, unsigned char *sign) {
if (*(int *)(sign + 0x18) == 4) {
unsigned char *minecraft = *(unsigned char **) (local_player + 0xc90);
unsigned char *screen = (unsigned char *) ::operator new(0xd0);
@ -55,14 +51,8 @@ extern "C" {
input.clear();
}
typedef void (*Screen_updateEvents_t)(unsigned char *screen);
static Screen_updateEvents_t Screen_updateEvents = (Screen_updateEvents_t) 0x28eb8;
typedef void (*Screen_keyboardNewChar_t)(unsigned char *screen, char key);
typedef void (*Screen_keyPressed_t)(unsigned char *screen, int32_t key);
// Handle Text Input
static void Screen_updateEvents_injection(unsigned char *screen) {
static void TextEditScreen_updateEvents_injection(unsigned char *screen) {
// Call Original Method
(*Screen_updateEvents)(screen);
@ -81,37 +71,12 @@ extern "C" {
extra_clear_input();
}
typedef unsigned char *(*ItemInstance_t)(unsigned char *item_instance, unsigned char *item);
static ItemInstance_t ItemInstance_item = (ItemInstance_t) 0x9992c;
static ItemInstance_t ItemInstance_tile = (ItemInstance_t) 0x998e4;
typedef unsigned char *(*ItemInstance_damage_t)(unsigned char *item_instance, unsigned char *item, int32_t count, int32_t damage);
static ItemInstance_damage_t ItemInstance_damage = (ItemInstance_damage_t) 0x99960;
typedef int32_t (*FillingContainer_addItem_t)(unsigned char *filling_container, unsigned char *item_instance);
static FillingContainer_addItem_t FillingContainer_addItem = (FillingContainer_addItem_t) 0x92aa0;
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);
}
// Items
static unsigned char **item_flintAndSteel = (unsigned char **) 0x17ba70;
static unsigned char **item_snowball = (unsigned char **) 0x17bbb0;
static unsigned char **item_shears = (unsigned char **) 0x17bbf0;
static unsigned char **item_egg = (unsigned char **) 0x17bbd0;
static unsigned char **item_dye_powder = (unsigned char **) 0x17bbe0;
// Tiles
static unsigned char **tile_water = (unsigned char **) 0x181b3c;
static unsigned char **tile_lava = (unsigned char **) 0x181cc8;
static unsigned char **tile_calmWater = (unsigned char **) 0x181b40;
static unsigned char **tile_calmLava = (unsigned char **) 0x181ccc;
static unsigned char **tile_glowingObsidian = (unsigned char **) 0x181dcc;
static unsigned char **tile_topSnow = (unsigned char **) 0x181b30;
static unsigned char **tile_ice = (unsigned char **) 0x181d80;
static unsigned char **tile_invisible_bedrock = (unsigned char **) 0x181d94;
static int32_t FillingContainer_addItem_injection(unsigned char *filling_container, unsigned char *item_instance) {
// Call Original
int32_t ret = (*FillingContainer_addItem)(filling_container, item_instance);
@ -139,12 +104,6 @@ extern "C" {
return ret;
}
typedef void (*Minecraft_tick_t)(unsigned char *minecraft, int32_t param_1, int32_t param_2);
static Minecraft_tick_t Minecraft_tick = (Minecraft_tick_t) 0x16934;
typedef void (*Textures_tick_t)(unsigned char *textures, bool param_1);
static Textures_tick_t Textures_tick = (Textures_tick_t) 0x531c4;
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);
@ -157,13 +116,13 @@ extern "C" {
}
__attribute((constructor)) static void init() {
// Implement AppPlatform::AppPlatform_AppPlatform_readAssetFile So Translations Work
overwrite((void *) 0x12b10, (void *) AppPlatform_readAssetFile);
// Implement AppPlatform::readAssetFile So Translations Work
overwrite((void *) AppPlatform_readAssetFile, (void *) AppPlatform_readAssetFile_injection);
if (extra_has_feature("Fix Sign Placement")) {
// Fix Signs
patch_address((void *) 0x106460, (void *) LocalPlayer_openTextEdit);
patch_address((void *) 0x10531c, (void *) Screen_updateEvents_injection);
patch_address(LocalPlayer_openTextEdit_vtable_addr, (void *) LocalPlayer_openTextEdit_injection);
patch_address(TextEditScreen_updateEvents_vtable_addr, (void *) TextEditScreen_updateEvents_injection);
}
if (extra_has_feature("Expand Creative Inventory")) {

View File

@ -16,6 +16,8 @@ void extra_set_is_right_click(int val);
void extra_hide_gui();
void extra_third_person();
void extra_set_is_left_click(int val);
int extra_get_smooth_lighting();
#ifdef __cplusplus

289
mods/src/minecraft.h Normal file
View File

@ -0,0 +1,289 @@
#ifndef MINECRAFT_H
#define MINECRAFT_H
#include <stdint.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
// Globals
static char **default_username = (char **) 0x18fd4;
static unsigned char **item_flintAndSteel = (unsigned char **) 0x17ba70;
static unsigned char **item_snowball = (unsigned char **) 0x17bbb0;
static unsigned char **item_shears = (unsigned char **) 0x17bbf0;
static unsigned char **item_egg = (unsigned char **) 0x17bbd0;
static unsigned char **item_dye_powder = (unsigned char **) 0x17bbe0;
static unsigned char **tile_water = (unsigned char **) 0x181b3c;
static unsigned char **tile_lava = (unsigned char **) 0x181cc8;
static unsigned char **tile_calmWater = (unsigned char **) 0x181b40;
static unsigned char **tile_calmLava = (unsigned char **) 0x181ccc;
static unsigned char **tile_glowingObsidian = (unsigned char **) 0x181dcc;
static unsigned char **tile_topSnow = (unsigned char **) 0x181b30;
static unsigned char **tile_ice = (unsigned char **) 0x181d80;
static unsigned char **tile_invisible_bedrock = (unsigned char **) 0x181d94;
typedef long int (*getRemainingFileSize_t)(FILE *file);
static getRemainingFileSize_t getRemainingFileSize = (getRemainingFileSize_t) 0xba520;
// Structures
struct LevelSettings {
unsigned long seed;
int32_t game_type;
};
struct RakNet_RakNetGUID {
unsigned char data[10];
};
struct RakNet_SystemAddress {
unsigned char data[20];
};
struct RakNet_BitStream {
unsigned char data[273];
};
struct RakDataOutput {
unsigned char data[8];
};
struct RakDataInput {
unsigned char data[8];
};
// GameMode
typedef void (*GameMode_releaseUsingItem_t)(unsigned char *game_mode, unsigned char *player);
// Minecraft
typedef void (*Minecraft_init_t)(unsigned char *minecraft);
static Minecraft_init_t Minecraft_init = (Minecraft_init_t) 0x1700c;
typedef void (*Minecraft_tickInput_t)(unsigned char *minecraft);
static Minecraft_tickInput_t Minecraft_tickInput = (Minecraft_tickInput_t) 0x15ffc;
typedef void (*Minecraft_setIsCreativeMode_t)(unsigned char *, int32_t);
static Minecraft_setIsCreativeMode_t Minecraft_setIsCreativeMode = (Minecraft_setIsCreativeMode_t) 0x16ec4;
typedef int32_t (*Minecraft_isTouchscreen_t)(unsigned char *minecraft);
static Minecraft_isTouchscreen_t Minecraft_isTouchscreen = (Minecraft_isTouchscreen_t) 0x1639c;
typedef void (*Minecraft_setScreen_t)(unsigned char *minecraft, unsigned char *screen);
static Minecraft_setScreen_t Minecraft_setScreen = (Minecraft_setScreen_t) 0x15d6c;
typedef void (*Minecraft_tick_t)(unsigned char *minecraft, int32_t param_1, int32_t param_2);
static Minecraft_tick_t Minecraft_tick = (Minecraft_tick_t) 0x16934;
typedef void (*Minecraft_update_t)(unsigned char *minecraft);
static Minecraft_update_t Minecraft_update = (Minecraft_update_t) 0x16b74;
typedef void (*Minecraft_hostMultiplayer_t)(unsigned char *minecraft, int32_t port);
static Minecraft_hostMultiplayer_t Minecraft_hostMultiplayer = (Minecraft_hostMultiplayer_t) 0x16664;
typedef const char *(*Minecraft_getProgressMessage_t)(unsigned char *minecraft);
static Minecraft_getProgressMessage_t Minecraft_getProgressMessage = (Minecraft_getProgressMessage_t) 0x16e58;
typedef uint32_t (*Minecraft_isLevelGenerated_t)(unsigned char *minecraft);
static Minecraft_isLevelGenerated_t Minecraft_isLevelGenerated = (Minecraft_isLevelGenerated_t) 0x16e6c;
// MouseBuildInput
typedef int32_t (*MouseBuildInput_tickBuild_t)(unsigned char *mouse_build_input, unsigned char *player, uint32_t *build_action_intention_return);
static MouseBuildInput_tickBuild_t MouseBuildInput_tickBuild = (MouseBuildInput_tickBuild_t) 0x17c98;
static void *MouseBuildInput_tickBuild_vtable_addr = (void *) 0x102564;
// Player
typedef int (*Player_isUsingItem_t)(unsigned char *player);
static Player_isUsingItem_t Player_isUsingItem = (Player_isUsingItem_t) 0x8f15c;
typedef void (*Player_setArmor_t)(unsigned char *player, int32_t slot, unsigned char *item);
static Player_setArmor_t Player_setArmor = (Player_setArmor_t) 0x8fde0;
// Player
static void *LocalPlayer_openTextEdit_vtable_addr = (void *) 0x106460;
// Gui
typedef void (*Gui_tickItemDrop_t)(unsigned char *gui);
static Gui_tickItemDrop_t Gui_tickItemDrop = (Gui_tickItemDrop_t) 0x27778;
typedef void (*Gui_handleClick_t)(unsigned char *gui, int32_t param_2, int32_t param_3, int32_t param_4);
static Gui_handleClick_t Gui_handleClick = (Gui_handleClick_t) 0x2599c;
// GameMode Constructors
static void *Creator = (void *) 0x1a044;
static void *SurvivalMode = (void *) 0x1b7d8;
static void *CreativeMode = (void *) 0x1b258;
// LevelData
typedef uint32_t (*LevelData_getSpawnMobs_t)(unsigned char *level_data);
static LevelData_getSpawnMobs_t LevelData_getSpawnMobs = (LevelData_getSpawnMobs_t) 0xbabec;
// Level
typedef void (*Level_saveLevelData_t)(unsigned char *level);
static Level_saveLevelData_t Level_saveLevelData = (Level_saveLevelData_t) 0xa2e94;
// TextEditScreen
typedef unsigned char *(*TextEditScreen_t)(unsigned char *text_edit_screen, unsigned char *sign);
static TextEditScreen_t TextEditScreen = (TextEditScreen_t) 0x3a840;
static void *TextEditScreen_updateEvents_vtable_addr = (void *) 0x10531c;
// ProgressScreen
typedef void *(*ProgressScreen_t)(unsigned char *obj);
static ProgressScreen_t ProgressScreen = (ProgressScreen_t) 0x37044;
// Screen
typedef void (*Screen_updateEvents_t)(unsigned char *screen);
static Screen_updateEvents_t Screen_updateEvents = (Screen_updateEvents_t) 0x28eb8;
typedef void (*Screen_keyboardNewChar_t)(unsigned char *screen, char key);
typedef void (*Screen_keyPressed_t)(unsigned char *screen, int32_t key);
// ItemInstance
typedef unsigned char *(*ItemInstance_t)(unsigned char *item_instance, unsigned char *item);
static ItemInstance_t ItemInstance_item = (ItemInstance_t) 0x9992c;
static ItemInstance_t ItemInstance_tile = (ItemInstance_t) 0x998e4;
typedef unsigned char *(*ItemInstance_damage_t)(unsigned char *item_instance, unsigned char *item, int32_t count, int32_t damage);
static ItemInstance_damage_t ItemInstance_damage = (ItemInstance_damage_t) 0x99960;
// FillingContainer
typedef int32_t (*FillingContainer_addItem_t)(unsigned char *filling_container, unsigned char *item_instance);
static FillingContainer_addItem_t FillingContainer_addItem = (FillingContainer_addItem_t) 0x92aa0;
// RakNet::RakPeer
typedef struct RakNet_SystemAddress (*RakNet_RakPeer_GetSystemAddressFromGuid_t)(unsigned char *rak_peer, struct RakNet_RakNetGUID guid);
// RakNet::BitStream
typedef unsigned char *(*RakNet_BitStream_constructor_t)(struct RakNet_BitStream *stream);
static RakNet_BitStream_constructor_t RakNet_BitStream_constructor = (RakNet_BitStream_constructor_t) 0xd3b84;
typedef void (*RakNet_BitStream_destructor_t)(struct RakNet_BitStream *stream);
static RakNet_BitStream_destructor_t RakNet_BitStream_destructor = (RakNet_BitStream_destructor_t) 0xd3ce8;
// RakDataOutput
static unsigned char *RakDataOutput_vtable = (unsigned char *) 0x109628;
// RakDataInput
static unsigned char *RakDataInput_vtable = (unsigned char *) 0x1095c8;
// ServerSideNetworkHandler
typedef void (*ServerSideNetworkHandler_onDisconnect_t)(unsigned char *server_side_network_handler, unsigned char *guid);
static ServerSideNetworkHandler_onDisconnect_t ServerSideNetworkHandler_onDisconnect = (ServerSideNetworkHandler_onDisconnect_t) 0x75164;
static void *ServerSideNetworkHandler_onDisconnect_vtable_addr = (void *) 0x109bb0;
typedef unsigned char *(*ServerSideNetworkHandler_getPlayer_t)(unsigned char *server_side_network_handler, unsigned char *guid);
static ServerSideNetworkHandler_getPlayer_t ServerSideNetworkHandler_getPlayer = (ServerSideNetworkHandler_getPlayer_t) 0x75464;
// CompoundTag
typedef unsigned char *(*CompoundTag_t)(unsigned char *tag);
static CompoundTag_t CompoundTag = (CompoundTag_t) 0xb9920;
// Tag
typedef void (*Tag_writeNamedTag_t)(unsigned char *tag, struct RakDataOutput *output);
static Tag_writeNamedTag_t Tag_writeNamedTag = (Tag_writeNamedTag_t) 0x6850c;
typedef void (*Tag_deleteChildren_t)(unsigned char *tag);
typedef void (*Tag_destructor_t)(unsigned char *tag);
// Entity
typedef void (*Entity_saveWithoutId_t)(unsigned char *entity, unsigned char *tag);
typedef void (*Entity_load_t)(unsigned char *entity, unsigned char *tag);
typedef void (*Entity_moveTo_t)(unsigned char *entity, float param_1, float param_2, float param_3, float param_4, float param_5);
static Entity_moveTo_t Entity_moveTo = (Entity_moveTo_t) 0x7a834;
// ServerPlayer
static void *ServerPlayer_moveTo_vtable_addr = (void *) 0x109e54;
// NbtIo
typedef unsigned char *(*NbtIo_read_t)(struct RakDataInput *input);
static NbtIo_read_t NbtIo_read = (NbtIo_read_t) 0xb98cc;
// Inventory
typedef void (*Inventory_clearInventoryWithDefault_t)(unsigned char *inventory);
static Inventory_clearInventoryWithDefault_t Inventory_clearInventoryWithDefault = (Inventory_clearInventoryWithDefault_t) 0x8e7c8;
// Method That Require C++ Types
#ifdef __cplusplus
#include <string>
#include "cxx11_util.h"
// AppPlatform
typedef cxx11_string (*AppPlatform_readAssetFile_t)(unsigned char *app_platform, std::string const& path);
static AppPlatform_readAssetFile_t AppPlatform_readAssetFile = (AppPlatform_readAssetFile_t) 0x12b10;
// Minecraft
typedef void (*Minecraft_selectLevel_t)(unsigned char *minecraft, std::string const& level_dir, std::string const& level_name, LevelSettings const& vsettings);
static Minecraft_selectLevel_t Minecraft_selectLevel = (Minecraft_selectLevel_t) 0x16f38;
typedef void (*Minecraft_leaveGame_t)(unsigned char *minecraft, bool save_remote_level);
static Minecraft_leaveGame_t Minecraft_leaveGame = (Minecraft_leaveGame_t) 0x15ea0;
// Gui
typedef void (*Gui_addMessage_t)(unsigned char *gui, std::string const& text);
static Gui_addMessage_t Gui_addMessage = (Gui_addMessage_t) 0x27820;
// Textures
typedef void (*Textures_tick_t)(unsigned char *textures, bool param_1);
static Textures_tick_t Textures_tick = (Textures_tick_t) 0x531c4;
// RakNet::RakPeer
typedef bool (*RakNet_RakPeer_IsBanned_t)(unsigned char *rakpeer, const char *ip);
static RakNet_RakPeer_IsBanned_t RakNet_RakPeer_IsBanned = (RakNet_RakPeer_IsBanned_t) 0xda3b4;
// RakNet::BitStream
typedef struct RakNet_BitStream *(*RakNet_BitStream_constructor_with_data_t)(struct RakNet_BitStream *stream, unsigned char *data, uint32_t size, bool copyData);
static RakNet_BitStream_constructor_with_data_t RakNet_BitStream_constructor_with_data = (RakNet_BitStream_constructor_with_data_t) 0xd3c30;
// RakNet::SystemAddress
typedef char *(*RakNet_SystemAddress_ToString_t)(struct RakNet_SystemAddress *system_address, bool print_delimiter, char delimiter);
static RakNet_SystemAddress_ToString_t RakNet_SystemAddress_ToString = (RakNet_SystemAddress_ToString_t) 0xd6198;
// ServerSideNetworkHandler
typedef void (*ServerSideNetworkHandler_displayGameMessage_t)(unsigned char *server_side_network_handler, std::string const& message);
static ServerSideNetworkHandler_displayGameMessage_t ServerSideNetworkHandler_displayGameMessage = (ServerSideNetworkHandler_displayGameMessage_t) 0x750c4;
#endif
#pragma GCC diagnostic pop
#endif

View File

@ -3,29 +3,7 @@
#include "playerdata.h"
#include "server_internal.h"
struct RakNet_BitStream {
unsigned char data[273];
};
typedef unsigned char *(*RakNet_BitStream_constructor_t)(RakNet_BitStream *stream);
static RakNet_BitStream_constructor_t RakNet_BitStream_constructor = (RakNet_BitStream_constructor_t) 0xd3b84;
typedef void (*RakNet_BitStream_destructor_t)(RakNet_BitStream *stream);
static RakNet_BitStream_destructor_t RakNet_BitStream_destructor = (RakNet_BitStream_destructor_t) 0xd3ce8;
struct RakDataOutput {
unsigned char data[8];
};
static unsigned char *RakDataOutput_vtable = (unsigned char *) 0x109628;
typedef unsigned char *(*CompoundTag_t)(unsigned char *tag);
static CompoundTag_t CompoundTag = (CompoundTag_t) 0xb9920;
typedef void (*Tag_writeNamedTag_t)(unsigned char *tag, RakDataOutput *output);
static Tag_writeNamedTag_t Tag_writeNamedTag = (Tag_writeNamedTag_t) 0x6850c;
typedef void (*Entity_saveWithoutId_t)(unsigned char *entity, unsigned char *tag);
typedef void (*Tag_deleteChildren_t)(unsigned char *tag);
typedef void (*Tag_destructor_t)(unsigned char *tag);
#include "../minecraft.h"
// Execute Command Without LD_PRELOAD
static void exec_without_preload(std::string str) {
@ -104,21 +82,14 @@ static void save_player_callback(std::string username, unsigned char *player) {
fclose(file);
}
struct RakDataInput {
unsigned char data[8];
};
static unsigned char *RakDataInput_vtable = (unsigned char *) 0x1095c8;
typedef long int (*getRemainingFileSize_t)(FILE *file);
static getRemainingFileSize_t getRemainingFileSize = (getRemainingFileSize_t) 0xba520;
typedef RakNet_BitStream *(*RakNet_BitStream_constructor_with_data_t)(RakNet_BitStream *stream, unsigned char *data, uint32_t size, bool copyData);
static RakNet_BitStream_constructor_with_data_t RakNet_BitStream_constructor_with_data = (RakNet_BitStream_constructor_with_data_t) 0xd3c30;
typedef unsigned char *(*NbtIo_read_t)(RakDataInput *input);
static NbtIo_read_t NbtIo_read = (NbtIo_read_t) 0xb98cc;
typedef void (*Entity_load_t)(unsigned char *entity, unsigned char *tag);
// Clear Player Inventory And Armor
static void clear_inventory(unsigned char *player) {
unsigned char *inventory = *(unsigned char **) (player + 0xbe0);
(*Inventory_clearInventoryWithDefault)(inventory);
for (int i = 0; i < 4; i++) {
(*Player_setArmor)(player, i, NULL);
}
}
// Load Player Callback
static void load_player_callback(std::string username, unsigned char *player) {
@ -168,6 +139,9 @@ static void load_player_callback(std::string username, unsigned char *player) {
Entity_load_t Entity_load = *(Entity_load_t *) (player_vtable + 0xd0);
(*Entity_load)(player, tag);
// Clear Inventory Because The Client Will Also Have An Empty Inventory
clear_inventory(player);
// Destruct tag
destruct_tag(tag);
}
@ -186,9 +160,6 @@ static void load_player_callback(std::string username, unsigned char *player) {
}
}
typedef void (*Entity_moveTo_t)(unsigned char *entity, float param_1, float param_2, float param_3, float param_4, float param_5);
static Entity_moveTo_t Entity_moveTo = (Entity_moveTo_t) 0x7a834;
static uint32_t get_entity_id(unsigned char *entity) {
return *(uint32_t *) (entity + 0x1c);
}
@ -226,12 +197,6 @@ void playerdata_save(unsigned char *level) {
}
}
typedef void (*ServerSideNetworkHandler_onDisconnect_t)(unsigned char *server_side_network_handler, unsigned char *guid);
static ServerSideNetworkHandler_onDisconnect_t ServerSideNetworkHandler_onDisconnect = (ServerSideNetworkHandler_onDisconnect_t) 0x75164;
typedef unsigned char *(*ServerSideNetworkHandler_getPlayer_t)(unsigned char *server_side_network_handler, unsigned char *guid);
static ServerSideNetworkHandler_getPlayer_t ServerSideNetworkHandler_getPlayer = (ServerSideNetworkHandler_getPlayer_t) 0x75464;
static void ServerSideNetworkHandler_onDisconnect_injection(unsigned char *server_side_network_handler, unsigned char *guid) {
// Save Player Data
unsigned char *player = (*ServerSideNetworkHandler_getPlayer)(server_side_network_handler, guid);
@ -246,7 +211,7 @@ static void ServerSideNetworkHandler_onDisconnect_injection(unsigned char *serve
void playerdata_init() {
// Load Player NBT
patch_address((void *) 0x109e54, (void *) ServerPlayer_moveTo_injection);
patch_address(ServerPlayer_moveTo_vtable_addr, (void *) ServerPlayer_moveTo_injection);
// Save On Logout
patch_address((void *) 0x109bb0, (void *) ServerSideNetworkHandler_onDisconnect_injection);
patch_address(ServerSideNetworkHandler_onDisconnect_vtable_addr, (void *) ServerSideNetworkHandler_onDisconnect_injection);
}

View File

@ -19,6 +19,8 @@
#include "server_properties.h"
#include "playerdata.h"
#include "../minecraft.h"
// Server Properties
static ServerProperties &get_server_properties() {
static ServerProperties properties;
@ -60,26 +62,6 @@ static void *read_stdin_thread(__attribute__((unused)) void *data) {
}
}
typedef void (*Minecraft_update_t)(unsigned char *minecraft);
static Minecraft_update_t Minecraft_update = (Minecraft_update_t) 0x16b74;
struct LevelSettings {
unsigned long seed;
int32_t game_type;
};
typedef void (*Minecraft_selectLevel_t)(unsigned char *minecraft, std::string const& level_dir, std::string const& level_name, LevelSettings const& vsettings);
static Minecraft_selectLevel_t Minecraft_selectLevel = (Minecraft_selectLevel_t) 0x16f38;
typedef void (*Minecraft_hostMultiplayer_t)(unsigned char *minecraft, int32_t port);
static Minecraft_hostMultiplayer_t Minecraft_hostMultiplayer = (Minecraft_hostMultiplayer_t) 0x16664;
typedef void *(*ProgressScreen_t)(unsigned char *obj);
static ProgressScreen_t ProgressScreen = (ProgressScreen_t) 0x37044;
typedef void (*Minecraft_setScreen_t)(unsigned char *minecraft, unsigned char *screen);
static Minecraft_setScreen_t Minecraft_setScreen = (Minecraft_setScreen_t) 0x15d6c;
// Get World Name
std::string server_internal_get_world_name() {
return get_server_properties().get_string("world-name", DEFAULT_WORLD_NAME);
@ -107,15 +89,8 @@ static void start_world(unsigned char *minecraft) {
(*Minecraft_setScreen)(minecraft, (unsigned char *) screen);
}
typedef const char *(*Minecraft_getProgressMessage_t)(unsigned char *minecraft);
static Minecraft_getProgressMessage_t Minecraft_getProgressMessage = (Minecraft_getProgressMessage_t) 0x16e58;
typedef int32_t (*Minecraft_isLevelGenerated_t)(unsigned char *minecraft);
static Minecraft_isLevelGenerated_t Minecraft_isLevelGenerated = (Minecraft_isLevelGenerated_t) 0x16e6c;
#define SIGNIFICANT_PROGRESS 5
// Check If Two Percentages Are Different Enough To Be Logged
#define SIGNIFICANT_PROGRESS 5
static bool is_progress_difference_significant(int32_t new_val, int32_t old_val) {
if (new_val != old_val) {
if (new_val == -1 || old_val == -1) {
@ -159,20 +134,6 @@ static void print_progress(unsigned char *minecraft) {
}
}
struct RakNet_RakNetGUID {
unsigned char data[10];
};
struct RakNet_SystemAddress {
unsigned char data[20];
};
typedef RakNet_SystemAddress (*RakNet_RakPeer_GetSystemAddressFromGuid_t)(unsigned char *rak_peer, RakNet_RakNetGUID guid);
typedef void (*ServerSideNetworkHandler_displayGameMessage_t)(unsigned char *server_side_network_handler, std::string const& message);
static ServerSideNetworkHandler_displayGameMessage_t ServerSideNetworkHandler_displayGameMessage = (ServerSideNetworkHandler_displayGameMessage_t) 0x750c4;
typedef char *(*RakNet_SystemAddress_ToString_t)(RakNet_SystemAddress *system_address, bool print_delimiter, char delimiter);
static RakNet_SystemAddress_ToString_t RakNet_SystemAddress_ToString = (RakNet_SystemAddress_ToString_t) 0xd6198;
static std::string get_banned_ips_file() {
std::string file(getenv("HOME"));
file.append("/.minecraft/banned-ips.txt");
@ -270,9 +231,6 @@ static void list_callback(unsigned char *minecraft, std::string username, unsign
INFO(" - %s (%s)", username.c_str(), get_player_ip(minecraft, player));
}
typedef void (*Level_saveLevelData_t)(unsigned char *level);
static Level_saveLevelData_t Level_saveLevelData = (Level_saveLevelData_t) 0xa2e94;
static void Level_saveLevelData_injection(unsigned char *level) {
// Print Log Message
INFO("%s", "Saving Game");
@ -284,9 +242,6 @@ static void Level_saveLevelData_injection(unsigned char *level) {
playerdata_save(level);
}
typedef void (*Minecraft_leaveGame_t)(unsigned char *minecraft, bool save_remote_level);
static Minecraft_leaveGame_t Minecraft_leaveGame = (Minecraft_leaveGame_t) 0x15ea0;
// Stop Server
static bool exit_requested = false;
static void exit_handler(__attribute__((unused)) int data) {
@ -391,9 +346,6 @@ static void Minecraft_update_injection(unsigned char *minecraft) {
handle_server_stop(minecraft);
}
typedef void (*Gui_addMessage_t)(unsigned char *gui, std::string const& text);
static Gui_addMessage_t Gui_addMessage = (Gui_addMessage_t) 0x27820;
static void Gui_addMessage_injection(unsigned char *gui, std::string const& text) {
// Print Log Message
fprintf(stderr, "[CHAT]: %s\n", text.c_str());
@ -402,9 +354,6 @@ static void Gui_addMessage_injection(unsigned char *gui, std::string const& text
(*Gui_addMessage)(gui, text);
}
typedef bool (*RakNet_RakPeer_IsBanned_t)(unsigned char *rakpeer, const char *ip);
static RakNet_RakPeer_IsBanned_t RakNet_RakPeer_IsBanned = (RakNet_RakPeer_IsBanned_t) 0xda3b4;
static bool RakNet_RakPeer_IsBanned_injection(__attribute__((unused)) unsigned char *rakpeer, const char *ip) {
// Check banned-ips.txt
std::string banned_ips_file_path = get_banned_ips_file();