Allow Opening Crafting With Controller

master
TheBrokenRail 2 months ago
parent 5d65b4092f
commit f3dc145d4a
  1. 5
      docs/CONTROLS.md
  2. 7
      media-layer/core/src/media.c
  3. 3
      media-layer/include/SDL/SDL_keysym.h
  4. 2
      mods/CMakeLists.txt
  5. 1
      mods/include/mods/input/input.h
  6. 4
      mods/src/compat/compat.c
  7. 30
      mods/src/input/crafting.cpp
  8. 1
      mods/src/input/input-internal.h
  9. 3
      mods/src/input/input.cpp
  10. 7
      symbols/include/symbols/minecraft.h

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

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

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

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

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

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

@ -0,0 +1,30 @@
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include "input-internal.h"
#include <mods/input/input.h>
#include <mods/creative/creative.h>
// 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);
}

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

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

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

Loading…
Cancel
Save