diff --git a/docs/CONTROLS.md b/docs/CONTROLS.md index c71b3c4..bef9e51 100644 --- a/docs/CONTROLS.md +++ b/docs/CONTROLS.md @@ -29,10 +29,11 @@ | Action | Function | | --- | --- | | A | Jump | -| D-Pad Down | Drop Item | | Y | Open Inventory | -| D-Pad Up | Change Perspective | | B | Sneak[^1] | +| X | Open Crafting | +| D-Pad Up | Change Perspective | +| D-Pad Down | Drop Item | | D-Pad Right | Open Chat | | Left/Right Bumper | Cycle Selected Item In Toolbar | | Left Trigger | Attack/Destroy | diff --git a/media-layer/core/src/media.c b/media-layer/core/src/media.c index 2c9b2a9..b57a530 100644 --- a/media-layer/core/src/media.c +++ b/media-layer/core/src/media.c @@ -60,6 +60,7 @@ static void character_event(char c) { } // Convert GLFW Key To SDL Key +#define IMAGINARY_GLFW_CRAFTING_KEY GLFW_KEY_LAST static SDLKey glfw_key_to_sdl_key(int key) { switch (key) { // Movement @@ -136,6 +137,9 @@ static SDLKey glfw_key_to_sdl_key(int key) { // Chat case GLFW_KEY_T: return SDLK_t; + // Crafting + case IMAGINARY_GLFW_CRAFTING_KEY: + return SDLK_WORLD_0; // Unknown default: return SDLK_UNKNOWN; @@ -293,6 +297,9 @@ static SDLKey glfw_controller_button_to_key(int button) { case GLFW_GAMEPAD_BUTTON_START: case GLFW_GAMEPAD_BUTTON_BACK: return GLFW_KEY_ESCAPE; + // Crafting + case GLFW_GAMEPAD_BUTTON_X: + return IMAGINARY_GLFW_CRAFTING_KEY; // Unknown default: return GLFW_KEY_UNKNOWN; diff --git a/media-layer/include/SDL/SDL_keysym.h b/media-layer/include/SDL/SDL_keysym.h index a489b93..a6397c5 100644 --- a/media-layer/include/SDL/SDL_keysym.h +++ b/media-layer/include/SDL/SDL_keysym.h @@ -38,7 +38,8 @@ typedef enum { SDLK_F11 = 292, SDLK_F12 = 293, SDLK_RSHIFT = 303, - SDLK_LSHIFT = 304 + SDLK_LSHIFT = 304, + SDLK_WORLD_0 = 160 // Used For Controller Crafting Button } SDLKey; typedef enum { diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index b1d393c..ab2ac3b 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -62,7 +62,7 @@ else() target_link_libraries(camera screenshot) endif() - add_library(input SHARED src/input/input.cpp src/input/bow.c src/input/attack.c src/input/toggle.c src/input/misc.c src/input/drop.cpp) + add_library(input SHARED src/input/input.cpp src/input/bow.c src/input/attack.c src/input/toggle.c src/input/misc.c src/input/drop.cpp src/input/crafting.cpp) target_link_libraries(input mods-headers reborn-patch symbols creative feature misc media-layer-core) add_library(sign SHARED src/sign/sign.cpp) diff --git a/mods/include/mods/input/input.h b/mods/include/mods/input/input.h index 1771a2f..7822216 100644 --- a/mods/include/mods/input/input.h +++ b/mods/include/mods/input/input.h @@ -12,6 +12,7 @@ void input_hide_gui(); void input_third_person(); int input_back(); void input_drop(int drop_slot); +void input_open_crafting(); void input_set_is_left_click(int val); diff --git a/mods/src/compat/compat.c b/mods/src/compat/compat.c index 29e8f5f..06ccd57 100644 --- a/mods/src/compat/compat.c +++ b/mods/src/compat/compat.c @@ -84,6 +84,10 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) { // Drop Item input_drop((event->key.keysym.mod & KMOD_CTRL) != 0); handled = 1; + } else if (event->key.keysym.sym == SDLK_WORLD_0) { + // Crafting + input_open_crafting(); + handled = 1; } break; } diff --git a/mods/src/input/crafting.cpp b/mods/src/input/crafting.cpp new file mode 100644 index 0000000..b3975a7 --- /dev/null +++ b/mods/src/input/crafting.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include "input-internal.h" +#include +#include + +// Store Should Open Crafting Menu +static int should_open_crafting = 0; +void input_open_crafting() { + should_open_crafting = 1; +} +static void _handle_open_crafting(unsigned char *minecraft) { + if (should_open_crafting) { + should_open_crafting = 0; + + // Set Screen + if (!creative_is_restricted() || !(*Minecraft_isCreativeMode)(minecraft)) { + unsigned char *screen = (unsigned char *) ::operator new(WORKBENCH_SCREEN_SIZE); + ALLOC_CHECK(screen); + screen = (*WorkbenchScreen)(screen, 0); + (*Minecraft_setScreen)(minecraft, screen); + } + } +} + +// Init +void _init_crafting() { + input_run_on_tick(_handle_open_crafting); +} diff --git a/mods/src/input/input-internal.h b/mods/src/input/input-internal.h index 2b081c8..f7943ec 100644 --- a/mods/src/input/input-internal.h +++ b/mods/src/input/input-internal.h @@ -9,6 +9,7 @@ __attribute__((visibility("internal"))) void _init_bow(); __attribute__((visibility("internal"))) void _init_misc(); __attribute__((visibility("internal"))) void _init_toggle(); __attribute__((visibility("internal"))) void _init_drop(); +__attribute__((visibility("internal"))) void _init_crafting(); #ifdef __cplusplus } diff --git a/mods/src/input/input.cpp b/mods/src/input/input.cpp index 34303b5..3cc410f 100644 --- a/mods/src/input/input.cpp +++ b/mods/src/input/input.cpp @@ -49,6 +49,9 @@ void init_input() { // Allow Attacking Mobs _init_attack(); + // Allow Opening Crafting With Controller + _init_crafting(); + // Disable Raw Mouse Motion if (feature_has("Disable Raw Mouse Motion (Not Recommended)", server_disabled)) { media_set_raw_mouse_motion_enabled(0); diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index f32f85e..dec17e3 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -854,6 +854,13 @@ static uint32_t HumanoidModel_is_sneaking_property_offset = 0x236; // bool static void *PlayerRenderer_render_vtable_addr = (void *) 0x107f08; +// WorkbenchScreen + +#define WORKBENCH_SCREEN_SIZE 0x180 + +typedef unsigned char *(*WorkbenchScreen_t)(unsigned char *screen, int32_t param_1); +static WorkbenchScreen_t WorkbenchScreen = (WorkbenchScreen_t) 0x301cc; + // Method That Require C++ Types #ifdef __cplusplus