From 750fb06a63cca2c923d4a11b1a0cb8b5cc03513c Mon Sep 17 00:00:00 2001 From: Dregu Date: Sat, 11 Nov 2023 17:35:47 +0200 Subject: [PATCH 1/5] add RAW_KEY and forgotten pressed field in keyboard --- docs/game_data/lua_enums.txt | 119 +++++++++++++++++- docs/game_data/spel2.lua | 3 +- docs/game_data/vtable_sizes.csv | 6 +- docs/src/includes/_enums.md | 11 ++ docs/src/includes/_types.md | 3 +- src/game_api/game_manager.hpp | 4 +- src/game_api/script/usertypes/bucket_lua.cpp | 4 +- .../script/usertypes/game_manager_lua.cpp | 71 ++++++++++- 8 files changed, 211 insertions(+), 10 deletions(-) diff --git a/docs/game_data/lua_enums.txt b/docs/game_data/lua_enums.txt index 6f63cbe45..b107f6480 100644 --- a/docs/game_data/lua_enums.txt +++ b/docs/game_data/lua_enums.txt @@ -1879,6 +1879,7 @@ KEY = { ["6"] = 54, ["7"] = 55, ["8"] = 56, + ["9"] = 57, A = 65, ADD = 107, ALT = 18, @@ -1997,7 +1998,8 @@ KEY = { V = 86, W = 87, X = 88, - Y = 89 + Y = 89, + Z = 90 } LAYER = { BACK = 1, @@ -2028,6 +2030,12 @@ LEVEL_CONFIG = { MAX_LIQUID_PARTICLES = 15, MOUNT_CHANCE = 4 } +LIGHT_TYPE = { + FOLLOW_CAMERA = 1, + FOLLOW_ENTITY = 2, + NONE = 0, + ROOM_LIGHT = 4 +} LIQUID_POOL = { COARSE_LAVA = 4, COARSE_WATER = 2, @@ -2084,6 +2092,18 @@ MASK = { SHADOW = 2048, WATER = 8192 } +MENU_INPUT = { + BACK = 2, + DELETE = 4, + DOWN = 256, + JOURNAL = 16, + LEFT = 32, + NONE = 0, + RANDOM = 8, + RIGHT = 64, + SELECT = 1, + UP = 128 +} ON = { ARENA_INTRO = 25, ARENA_ITEMS = 23, @@ -2112,6 +2132,7 @@ ON = { ONLINE_LOBBY = 29, OPTIONS = 5, PLAYER_PROFILE = 6, + POST_GAME_LOOP = 156, POST_LAYER_CREATION = 148, POST_LAYER_DESTRUCTION = 152, POST_LEVEL_CREATION = 146, @@ -2119,8 +2140,10 @@ ON = { POST_LEVEL_GENERATION = 112, POST_LOAD_JOURNAL_CHAPTER = 139, POST_LOAD_SCREEN = 136, + POST_PROCESS_INPUT = 154, POST_ROOM_GENERATION = 111, POST_UPDATE = 143, + PRE_GAME_LOOP = 155, PRE_GET_FEAT = 140, PRE_GET_RANDOM_ROOM = 113, PRE_HANDLE_ROOM_TILES = 114, @@ -2132,6 +2155,7 @@ ON = { PRE_LOAD_JOURNAL_CHAPTER = 138, PRE_LOAD_LEVEL_FILES = 109, PRE_LOAD_SCREEN = 135, + PRE_PROCESS_INPUT = 153, PRE_SET_FEAT = 141, PRE_UPDATE = 142, PROLOGUE = 2, @@ -2544,6 +2568,99 @@ QUEST_FLAG = { VAULT_SPAWNED = 3, WADDLER_AGGROED = 10 } +RAW_KEY = { + ["0"] = 66, + ["1"] = 67, + ["2"] = 68, + ["3"] = 69, + ["4"] = 70, + ["5"] = 71, + ["6"] = 72, + ["7"] = 73, + ["8"] = 74, + ["9"] = 75, + A = 8, + ADD = 87, + ALT = 38, + B = 9, + BACKSPACE = 41, + C = 10, + COMMA = 94, + CTRL = 34, + D = 11, + DECIMAL = 91, + DELETE = 105, + DIVIDE = 89, + DOWN = 2, + E = 12, + END = 107, + ESCAPE = 5, + F = 13, + F1 = 42, + F2 = 43, + F3 = 44, + F4 = 45, + F5 = 46, + F6 = 47, + F7 = 48, + F8 = 49, + F9 = 50, + F10 = 51, + F11 = 52, + F12 = 53, + G = 14, + H = 15, + HOME = 109, + I = 16, + INSERT = 104, + J = 17, + K = 18, + L = 19, + LALT = 38, + LCONTROL = 34, + LEFT = 3, + LSHIFT = 36, + M = 20, + MINUS = 93, + MULTIPLY = 88, + N = 21, + NUMPAD0 = 76, + NUMPAD1 = 77, + NUMPAD2 = 78, + NUMPAD3 = 79, + NUMPAD4 = 80, + NUMPAD5 = 81, + NUMPAD6 = 82, + NUMPAD7 = 83, + NUMPAD8 = 84, + NUMPAD9 = 85, + O = 22, + P = 23, + PERIOD = 95, + PGDN = 106, + PGUP = 108, + PLUS = 99, + Q = 24, + R = 25, + RALT = 39, + RCONTROL = 35, + RETURN = 6, + RIGHT = 4, + RSHIFT = 37, + S = 26, + SHIFT = 36, + SPACE = 40, + SUBTRACT = 86, + T = 27, + TAB = 7, + U = 28, + UP = 1, + V = 29, + W = 30, + X = 31, + Y = 32, + Z = 33 +} RECURSIVE_MODE = { EXCLUSIVE = 0, INCLUSIVE = 1, diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 69fb710f0..5b9086e01 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -2297,11 +2297,12 @@ do ---@field input_index integer[] @size: 5 @Input index for players 1-4 and maybe for the menu controls. -1: disabled, 0..3: keyboards, 4..7: Xinput, 8..11: other controllers ---@class RawInput - ---@field keyboard KeyboardKey[] @size: 112 @State of all keyboard buttons in a random game order as usual + ---@field keyboard KeyboardKey[] @size: 112 @State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. ---@field controller ControllerInput[] @size: 12 @State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. ---@class KeyboardKey ---@field down boolean @Key is being held + ---@field pressed boolean @Key was just pressed down this frame ---@class ControllerInput ---@field buttons ControllerButton[] @size: 16 diff --git a/docs/game_data/vtable_sizes.csv b/docs/game_data/vtable_sizes.csv index 5ddfa2499..d013e5ecf 100644 --- a/docs/game_data/vtable_sizes.csv +++ b/docs/game_data/vtable_sizes.csv @@ -4,7 +4,7 @@ TypeID,Name,vtable offset,~Entity,create_rendering_info,handle_state_machine,kil 3,ENT_TYPE_FLOOR_BORDERTILE_OCTOPUS,8786,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 4,ENT_TYPE_FLOOR_GENERIC,8786,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 5,ENT_TYPE_FLOOR_SURFACE,8786,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 -6,ENT_TYPE_FLOOR_SURFACE_HIDDEN,48206,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,ret,0x2287cbd0,0x2287d100,ret 0,ret true,ret,ret,ret,ret,0x228bff80,0x2287d100,ret 0,0x228bfe80,ret,ret,0x228bfe90,0x2292e2c0,0x228bdfb0,ret true,ret 0,ret 0,ret,ret,0x228ee610,0x22997220,0x228bdfb0,0x228c4340,ret 0,ret 0,0x22999730,0x22999750,0x22999aa0,0x228c6ab0,0x22999f90,ret true,ret 0,ret 0,0x22999fc0,ret,0x2299a010,0x228c6ab0,0x228bdfb0,0x2289e280,0x2299bf40,0x2299d580,0x2299d8a0,0x229a3840,0x229a3b00,0xffff817e87880173,0xffff817f87880000,0x228a9670 +6,ENT_TYPE_FLOOR_SURFACE_HIDDEN,48206,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,ret,0x2287cbd0,0x2287d100,ret 0,ret true,ret,ret,ret,ret,0x228bff80,0x2287d100,ret 0,0x228bfe80,ret,ret,0x228bfe90,0x2292e2c0,0x228bdfb0,ret true,ret 0,ret 0,ret,ret,0x228ee610,0x22997220,0x228bdfb0,0x228c4340,ret 0,ret 0,0x22999730,0x22999750,0x22999aa0,0x228c6ab0,0x22999f90,ret true,ret 0,ret 0,0x22999fc0,ret,0x2299a010,0x228c6ab0,0x228bdfb0,0x2289e280,0x2299bf40,0x2299d580,0x2299d8a0,0x229a3840,0x229a3b00,0xffff817d33210173,0xffff817e33210000,0x228a9670 7,ENT_TYPE_FLOOR_BASECAMP_SINGLEBED,10626,0x2287aed0,0x227fcd90,ret,0x2297d3f0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x2297d600,0x2297d680,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 8,ENT_TYPE_FLOOR_BASECAMP_DININGTABLE,10626,0x2287aed0,0x227fcd90,ret,0x2297d3f0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x2297d600,0x2297d680,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 9,ENT_TYPE_FLOOR_BASECAMP_LONGTABLE,10626,0x2287aed0,0x227fcd90,ret,0x2297d3f0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x2297d600,0x2297d680,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 @@ -91,7 +91,7 @@ TypeID,Name,vtable offset,~Entity,create_rendering_info,handle_state_machine,kil 90,ENT_TYPE_FLOOR_FORCEFIELD_TOP,8786,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 91,ENT_TYPE_FLOOR_HORIZONTAL_FORCEFIELD,8946,0x2287aed0,0x227fcd90,0x22974270,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x22974960,0x227fd790,0x227fd930,0x227fd950,0x22974760,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22974240,END OF ENTITY,0x22928d00,ret,0x2287cbd0 92,ENT_TYPE_FLOOR_HORIZONTAL_FORCEFIELD_TOP,8786,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 -93,ENT_TYPE_FLOOR_PEN,48142,0x2287aed0,0x227fcd90,ret,0x22978910,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x22978990,0x90980158c8e000c,0x680118a8b030c,0x6801187920009,0x7801187920009,0x9801387900008,0x980138792000a,0xa80138793000b,0xbf7f80098793000b,0xffff8009c7080000 +93,ENT_TYPE_FLOOR_PEN,48142,0x2287aed0,0x227fcd90,ret,0x22978910,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x22978990,0x90980143827000c,0x680103624030c,0x68010332b0009,0x78010332b0009,0x9801233290008,0x98012332b000a,0xa8012332c000b,0xbf7f8008332c000b,0xffff800872a10000 94,ENT_TYPE_FLOOR_TOMB,8906,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x2298cc30,END OF ENTITY,0x22928d00,0x2292c410,0x2288b9e0 95,ENT_TYPE_FLOOR_YAMA_PLATFORM,8866,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x2288d9c0,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2287cbd0 96,ENT_TYPE_FLOOR_EMPRESS_GRAVE,8826,0x2287aed0,0x227fcd90,ret,0x22926290,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x22927b90,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,0x22927f40,ret,ret,0x22928420,ret,ret,0x227fe2f0,0x22928bd0,END OF ENTITY,0x22928d00,0x2292c410,0x2288b9e0 @@ -811,7 +811,7 @@ TypeID,Name,vtable offset,~Entity,create_rendering_info,handle_state_machine,kil 841,ENT_TYPE_BG_EGGSAC_STAINS,2460,0x2287aed0,0x227fcd90,ret,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,ret,END OF ENTITY 844,ENT_TYPE_LOGICAL_CONSTELLATION,2840,0x2287aed0,0x227fcd90,ret,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,0x229f53f0,END OF ENTITY 845,ENT_TYPE_LOGICAL_SHOOTING_STARS_SPAWNER,2802,0x2287aed0,0x227fcd90,0x22a004c0,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,0x22a004b0,END OF ENTITY -846,ENT_TYPE_LOGICAL_DOOR,48710,0x2287aed0,0x227fcd90,0x229f8090,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,ret,END OF ENTITY,0xffff8009c7080000,0x403f8009c7880000 +846,ENT_TYPE_LOGICAL_DOOR,48710,0x2287aed0,0x227fcd90,0x229f8090,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,ret,END OF ENTITY,0xffff800872a10000,0x403f800873210000 847,ENT_TYPE_LOGICAL_DOOR_AMBIENT_SOUND,2764,0x2287aed0,0x227fcd90,0x229f83c0,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,0x229f8360,END OF ENTITY 848,ENT_TYPE_LOGICAL_BLACKMARKET_DOOR,2726,0x2287aed0,0x227fcd90,0x229f8090,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,ret,ret 0,ret,ret,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,0x229f3af0,END OF ENTITY 849,ENT_TYPE_LOGICAL_ARROW_TRAP_TRIGGER,48672,0x2287aed0,0x227fcd90,0x229f35f0,0x227fcfd0,ret,0x227fd000,0x227fd0b0,0x227fd110,0x227fd150,0x227fd570,0x227fd580,ret 0,0x227fd5a0,0x227fd730,0x227fd740,0x227fd750,0x227fd770,0x227fd790,0x227fd930,0x227fd950,0x227fd960,0x227fe160,ret 0,0x229f3a20,ret 0,ret,0x229f3a40,ret 0,ret,ret,ret,ret,ret,ret,ret,0x227fe2f0,ret,END OF ENTITY diff --git a/docs/src/includes/_enums.md b/docs/src/includes/_enums.md index 352f23843..7d9009998 100644 --- a/docs/src/includes/_enums.md +++ b/docs/src/includes/_enums.md @@ -1019,6 +1019,17 @@ Name | Data | Description [STAR_CHALLENGE_SPAWNED](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=QUEST_FLAG.STAR_CHALLENGE_SPAWNED) | 26 | [SUN_CHALLENGE_SPAWNED](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=QUEST_FLAG.SUN_CHALLENGE_SPAWNED) | 27 | +## RAW_KEY + + +> Search script examples for [RAW_KEY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_KEY) + + +Name | Data | Description +---- | ---- | ----------- +[UP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_KEY.UP) | 1 | +...check [lua_enums.txt](game_data/lua_enums.txt)... | | + ## RECURSIVE_MODE diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index b64cb3428..fa3eeb2e4 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -758,6 +758,7 @@ int | [owner_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owner Type | Name | Description ---- | ---- | ----------- bool | [down](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=down) | Key is being held +bool | [pressed](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=pressed) | Key was just pressed down this frame ### Letter @@ -1095,7 +1096,7 @@ array<[PlayerSlotSettings](#PlayerSlotSettings), MAX_PLAYERS> | [player_se Type | Name | Description ---- | ---- | ----------- -array<[KeyboardKey](#KeyboardKey), 112> | [keyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyboard) | State of all keyboard buttons in a random game order as usual +array<[KeyboardKey](#KeyboardKey), 112> | [keyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyboard) | State of all keyboard buttons in a random game order as usual, most key indexes can be found in [RAW_KEY](#RAW_KEY). array<[ControllerInput](#ControllerInput), 12> | [controller](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=controller) | State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. ## Journal types diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index 036154fc8..7cfee3a43 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -74,6 +74,8 @@ struct KeyboardKey { /// Key is being held bool down; + /// Key was just pressed down this frame + bool pressed; size_t unknown; }; @@ -92,7 +94,7 @@ struct ControllerInput struct RawInput { - /// State of all keyboard buttons in a random game order as usual + /// State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. std::array keyboard; /// State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. std::array controller; diff --git a/src/game_api/script/usertypes/bucket_lua.cpp b/src/game_api/script/usertypes/bucket_lua.cpp index 1efbc5472..64f8e3aa1 100644 --- a/src/game_api/script/usertypes/bucket_lua.cpp +++ b/src/game_api/script/usertypes/bucket_lua.cpp @@ -130,9 +130,9 @@ void register_usertypes(sol::state& lua) lua["KEY"]["OEM_7"] = 0xDE; lua["KEY"]["OEM_8"] = 0xDF; lua["KEY"]["OEM_102"] = 0xE2; - for (char c = '0'; c < '9'; c++) + for (char c = '0'; c <= '9'; c++) lua["KEY"][std::string{c}] = (int)c; - for (char c = 'A'; c < 'Z'; c++) + for (char c = 'A'; c <= 'Z'; c++) lua["KEY"][std::string{c}] = (int)c; } }; // namespace NBucket diff --git a/src/game_api/script/usertypes/game_manager_lua.cpp b/src/game_api/script/usertypes/game_manager_lua.cpp index 5c9879ca3..cbb98b7c9 100644 --- a/src/game_api/script/usertypes/game_manager_lua.cpp +++ b/src/game_api/script/usertypes/game_manager_lua.cpp @@ -138,7 +138,9 @@ void register_usertypes(sol::state& lua) lua.new_usertype( "KeyboardKey", "down", - &KeyboardKey::down); + &KeyboardKey::down, + "pressed", + &KeyboardKey::pressed); lua.new_usertype( "ControllerInput", "buttons", @@ -152,5 +154,72 @@ void register_usertypes(sol::state& lua) /// Returns RawInput, a game structure for raw keyboard and controller state lua["get_raw_input"] = get_raw_input; + + /// Keycodes used specifically in RawInput.keyboard. There are more keys than this though, but I didn't want to figure out the OEM keys. + lua.create_named_table("RAW_KEY" + //, "UP", 1 + //, "", ...check__[lua_enums.txt]\[game_data/lua_enums.txt\]... + ); + + lua["RAW_KEY"]["BACKSPACE"] = 0x29; + lua["RAW_KEY"]["TAB"] = 0x07; + lua["RAW_KEY"]["RETURN"] = 0x06; + lua["RAW_KEY"]["SHIFT"] = 0x24; + lua["RAW_KEY"]["CTRL"] = 0x22; + lua["RAW_KEY"]["ALT"] = 0x26; + lua["RAW_KEY"]["RALT"] = 0x27; + lua["RAW_KEY"]["ESCAPE"] = 0x05; + lua["RAW_KEY"]["SPACE"] = 0x28; + lua["RAW_KEY"]["PGUP"] = 0x6C; + lua["RAW_KEY"]["PGDN"] = 0x6A; + lua["RAW_KEY"]["END"] = 0x6B; + lua["RAW_KEY"]["HOME"] = 0x6D; + lua["RAW_KEY"]["LEFT"] = 0x03; + lua["RAW_KEY"]["UP"] = 0x01; + lua["RAW_KEY"]["RIGHT"] = 0x04; + lua["RAW_KEY"]["DOWN"] = 0x02; + lua["RAW_KEY"]["INSERT"] = 0x68; + lua["RAW_KEY"]["DELETE"] = 0x69; + lua["RAW_KEY"]["NUMPAD0"] = 0x4C; + lua["RAW_KEY"]["NUMPAD1"] = 0x4D; + lua["RAW_KEY"]["NUMPAD2"] = 0x4E; + lua["RAW_KEY"]["NUMPAD3"] = 0x4F; + lua["RAW_KEY"]["NUMPAD4"] = 0x50; + lua["RAW_KEY"]["NUMPAD5"] = 0x51; + lua["RAW_KEY"]["NUMPAD6"] = 0x52; + lua["RAW_KEY"]["NUMPAD7"] = 0x53; + lua["RAW_KEY"]["NUMPAD8"] = 0x54; + lua["RAW_KEY"]["NUMPAD9"] = 0x55; + lua["RAW_KEY"]["MULTIPLY"] = 0x58; + lua["RAW_KEY"]["ADD"] = 0x57; + lua["RAW_KEY"]["SUBTRACT"] = 0x56; + lua["RAW_KEY"]["DECIMAL"] = 0x5B; + lua["RAW_KEY"]["DIVIDE"] = 0x59; + lua["RAW_KEY"]["F1"] = 0x2A; + lua["RAW_KEY"]["F2"] = 0x2B; + lua["RAW_KEY"]["F3"] = 0x2C; + lua["RAW_KEY"]["F4"] = 0x2D; + lua["RAW_KEY"]["F5"] = 0x2E; + lua["RAW_KEY"]["F6"] = 0x2F; + lua["RAW_KEY"]["F7"] = 0x30; + lua["RAW_KEY"]["F8"] = 0x31; + lua["RAW_KEY"]["F9"] = 0x32; + lua["RAW_KEY"]["F10"] = 0x33; + lua["RAW_KEY"]["F11"] = 0x34; + lua["RAW_KEY"]["F12"] = 0x35; + lua["RAW_KEY"]["LSHIFT"] = 0x24; + lua["RAW_KEY"]["RSHIFT"] = 0x25; + lua["RAW_KEY"]["LCONTROL"] = 0x22; + lua["RAW_KEY"]["RCONTROL"] = 0x23; + lua["RAW_KEY"]["LALT"] = 0x26; + lua["RAW_KEY"]["RALT"] = 0x27; + lua["RAW_KEY"]["PLUS"] = 0x63; + lua["RAW_KEY"]["COMMA"] = 0x5E; + lua["RAW_KEY"]["MINUS"] = 0x5D; + lua["RAW_KEY"]["PERIOD"] = 0x5F; + for (char c = '0'; c <= '9'; c++) + lua["RAW_KEY"][std::string{c}] = (int)c + 18; + for (char c = 'A'; c <= 'Z'; c++) + lua["RAW_KEY"][std::string{c}] = (int)c - 57; } }; // namespace NGM From 70a9142c9f62ea30022a7972fb9f25017b49bf06 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sat, 11 Nov 2023 18:10:52 +0200 Subject: [PATCH 2/5] fix indexing with input_mapping --- docs/game_data/lua_enums.txt | 183 +++++++++--------- docs/game_data/spel2.lua | 129 +++++++++++- docs/src/includes/_types.md | 6 +- src/game_api/game_manager.hpp | 5 +- .../script/usertypes/game_manager_lua.cpp | 126 ++++++------ 5 files changed, 288 insertions(+), 161 deletions(-) diff --git a/docs/game_data/lua_enums.txt b/docs/game_data/lua_enums.txt index b107f6480..0b52187a5 100644 --- a/docs/game_data/lua_enums.txt +++ b/docs/game_data/lua_enums.txt @@ -2569,97 +2569,98 @@ QUEST_FLAG = { WADDLER_AGGROED = 10 } RAW_KEY = { - ["0"] = 66, - ["1"] = 67, - ["2"] = 68, - ["3"] = 69, - ["4"] = 70, - ["5"] = 71, - ["6"] = 72, - ["7"] = 73, - ["8"] = 74, - ["9"] = 75, - A = 8, - ADD = 87, - ALT = 38, - B = 9, - BACKSPACE = 41, - C = 10, - COMMA = 94, - CTRL = 34, - D = 11, - DECIMAL = 91, - DELETE = 105, - DIVIDE = 89, - DOWN = 2, - E = 12, - END = 107, - ESCAPE = 5, - F = 13, - F1 = 42, - F2 = 43, - F3 = 44, - F4 = 45, - F5 = 46, - F6 = 47, - F7 = 48, - F8 = 49, - F9 = 50, - F10 = 51, - F11 = 52, - F12 = 53, - G = 14, - H = 15, - HOME = 109, - I = 16, - INSERT = 104, - J = 17, - K = 18, - L = 19, - LALT = 38, - LCONTROL = 34, - LEFT = 3, - LSHIFT = 36, - M = 20, - MINUS = 93, - MULTIPLY = 88, - N = 21, - NUMPAD0 = 76, - NUMPAD1 = 77, - NUMPAD2 = 78, - NUMPAD3 = 79, - NUMPAD4 = 80, - NUMPAD5 = 81, - NUMPAD6 = 82, - NUMPAD7 = 83, - NUMPAD8 = 84, - NUMPAD9 = 85, - O = 22, - P = 23, - PERIOD = 95, - PGDN = 106, - PGUP = 108, - PLUS = 99, - Q = 24, - R = 25, - RALT = 39, - RCONTROL = 35, - RETURN = 6, - RIGHT = 4, - RSHIFT = 37, - S = 26, - SHIFT = 36, - SPACE = 40, - SUBTRACT = 86, - T = 27, - TAB = 7, - U = 28, - UP = 1, - V = 29, - W = 30, - X = 31, - Y = 32, - Z = 33 + ["0"] = 65, + ["1"] = 66, + ["2"] = 67, + ["3"] = 68, + ["4"] = 69, + ["5"] = 70, + ["6"] = 71, + ["7"] = 72, + ["8"] = 73, + ["9"] = 74, + A = 9, + ADD = 86, + ALT = 37, + B = 10, + BACKSPACE = 40, + C = 11, + COMMA = 93, + CTRL = 33, + D = 12, + DECIMAL = 90, + DELETE = 104, + DIVIDE = 88, + DOWN = 1, + E = 13, + END = 106, + ESCAPE = 4, + F = 14, + F1 = 41, + F2 = 42, + F3 = 43, + F4 = 44, + F5 = 45, + F6 = 46, + F7 = 47, + F8 = 48, + F9 = 49, + F10 = 50, + F11 = 51, + F12 = 52, + G = 15, + H = 16, + HOME = 108, + I = 17, + INSERT = 103, + J = 18, + K = 19, + L = 20, + LALT = 37, + LCONTROL = 33, + LEFT = 2, + LSHIFT = 35, + M = 21, + MINUS = 92, + MULTIPLY = 87, + N = 22, + NUMPAD0 = 75, + NUMPAD1 = 76, + NUMPAD2 = 77, + NUMPAD3 = 78, + NUMPAD4 = 79, + NUMPAD5 = 80, + NUMPAD6 = 81, + NUMPAD7 = 82, + NUMPAD8 = 83, + NUMPAD9 = 84, + NUMPADENTER = 110, + O = 23, + P = 24, + PERIOD = 94, + PGDN = 105, + PGUP = 107, + PLUS = 98, + Q = 25, + R = 26, + RALT = 38, + RCONTROL = 34, + RETURN = 5, + RIGHT = 3, + RSHIFT = 36, + S = 27, + SHIFT = 35, + SPACE = 39, + SUBTRACT = 85, + T = 28, + TAB = 6, + U = 29, + UP = 0, + V = 30, + W = 31, + X = 32, + Y = 33, + Z = 34 } RECURSIVE_MODE = { EXCLUSIVE = 0, diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 5b9086e01..03c911d6f 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -2297,15 +2297,15 @@ do ---@field input_index integer[] @size: 5 @Input index for players 1-4 and maybe for the menu controls. -1: disabled, 0..3: keyboards, 4..7: Xinput, 8..11: other controllers ---@class RawInput - ---@field keyboard KeyboardKey[] @size: 112 @State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. - ---@field controller ControllerInput[] @size: 12 @State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. + ---@field keyboard KeyboardKey[] @size: 112 @State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. Zero-based indexing, i.e. use PlayerSlot.input_mapping_keyboard directly to index this. + ---@field controller ControllerInput[] @size: 12 @State of controller buttons per controller. Zero-based indexing, i.e. use GameProps.input_index directly to index this. ---@class KeyboardKey ---@field down boolean @Key is being held ---@field pressed boolean @Key was just pressed down this frame ---@class ControllerInput - ---@field buttons ControllerButton[] @size: 16 + ---@field buttons ControllerButton[] @size: 16 @Zero-based indexing, i.e. use PlayerSlot.input_mapping_controller directly to index this. ---@class ControllerButton ---@field down boolean @Button is being held @@ -8470,6 +8470,7 @@ KEY = { ["6"] = 54, ["7"] = 55, ["8"] = 56, + ["9"] = 57, A = 65, ADD = 107, ALT = 18, @@ -8588,7 +8589,8 @@ KEY = { V = 86, W = 87, X = 88, - Y = 89 + Y = 89, + Z = 90 } ---@alias KEY integer LAYER = { @@ -8622,6 +8624,13 @@ LEVEL_CONFIG = { MOUNT_CHANCE = 4 } ---@alias LEVEL_CONFIG integer +LIGHT_TYPE = { + FOLLOW_CAMERA = 1, + FOLLOW_ENTITY = 2, + NONE = 0, + ROOM_LIGHT = 4 +} +---@alias LIGHT_TYPE integer LIQUID_POOL = { COARSE_LAVA = 4, COARSE_WATER = 2, @@ -8681,6 +8690,19 @@ MASK = { WATER = 8192 } ---@alias MASK integer +MENU_INPUT = { + BACK = 2, + DELETE = 4, + DOWN = 256, + JOURNAL = 16, + LEFT = 32, + NONE = 0, + RANDOM = 8, + RIGHT = 64, + SELECT = 1, + UP = 128 +} +---@alias MENU_INPUT integer ON = { ARENA_INTRO = 25, ARENA_ITEMS = 23, @@ -8709,6 +8731,7 @@ ON = { ONLINE_LOBBY = 29, OPTIONS = 5, PLAYER_PROFILE = 6, + POST_GAME_LOOP = 156, POST_LAYER_CREATION = 148, POST_LAYER_DESTRUCTION = 152, POST_LEVEL_CREATION = 146, @@ -8716,8 +8739,10 @@ ON = { POST_LEVEL_GENERATION = 112, POST_LOAD_JOURNAL_CHAPTER = 139, POST_LOAD_SCREEN = 136, + POST_PROCESS_INPUT = 154, POST_ROOM_GENERATION = 111, POST_UPDATE = 143, + PRE_GAME_LOOP = 155, PRE_GET_FEAT = 140, PRE_GET_RANDOM_ROOM = 113, PRE_HANDLE_ROOM_TILES = 114, @@ -8729,6 +8754,7 @@ ON = { PRE_LOAD_JOURNAL_CHAPTER = 138, PRE_LOAD_LEVEL_FILES = 109, PRE_LOAD_SCREEN = 135, + PRE_PROCESS_INPUT = 153, PRE_SET_FEAT = 141, PRE_UPDATE = 142, PROLOGUE = 2, @@ -9150,6 +9176,101 @@ QUEST_FLAG = { WADDLER_AGGROED = 10 } ---@alias QUEST_FLAG integer +RAW_KEY = { + ["0"] = 65, + ["1"] = 66, + ["2"] = 67, + ["3"] = 68, + ["4"] = 69, + ["5"] = 70, + ["6"] = 71, + ["7"] = 72, + ["8"] = 73, + ["9"] = 74, + A = 9, + ADD = 86, + ALT = 37, + B = 10, + BACKSPACE = 40, + C = 11, + COMMA = 93, + CTRL = 33, + D = 12, + DECIMAL = 90, + DELETE = 104, + DIVIDE = 88, + DOWN = 1, + E = 13, + END = 106, + ESCAPE = 4, + F = 14, + F1 = 41, + F2 = 42, + F3 = 43, + F4 = 44, + F5 = 45, + F6 = 46, + F7 = 47, + F8 = 48, + F9 = 49, + F10 = 50, + F11 = 51, + F12 = 52, + G = 15, + H = 16, + HOME = 108, + I = 17, + INSERT = 103, + J = 18, + K = 19, + L = 20, + LALT = 37, + LCONTROL = 33, + LEFT = 2, + LSHIFT = 35, + M = 21, + MINUS = 92, + MULTIPLY = 87, + N = 22, + NUMPAD0 = 75, + NUMPAD1 = 76, + NUMPAD2 = 77, + NUMPAD3 = 78, + NUMPAD4 = 79, + NUMPAD5 = 80, + NUMPAD6 = 81, + NUMPAD7 = 82, + NUMPAD8 = 83, + NUMPAD9 = 84, + NUMPADENTER = 110, + O = 23, + P = 24, + PERIOD = 94, + PGDN = 105, + PGUP = 107, + PLUS = 98, + Q = 25, + R = 26, + RALT = 38, + RCONTROL = 34, + RETURN = 5, + RIGHT = 3, + RSHIFT = 36, + S = 27, + SHIFT = 35, + SPACE = 39, + SUBTRACT = 85, + T = 28, + TAB = 6, + U = 29, + UP = 0, + V = 30, + W = 31, + X = 32, + Y = 33, + Z = 34 +} +---@alias RAW_KEY integer RECURSIVE_MODE = { EXCLUSIVE = 0, INCLUSIVE = 1, diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index fa3eeb2e4..e7f05949a 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -1003,7 +1003,7 @@ tuple<float, float> | [split()](https://github.com/spelunky-fyi/overlunky/ Type | Name | Description ---- | ---- | ----------- -array<[ControllerButton](#ControllerButton), 16> | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) | +array<[ControllerButton](#ControllerButton), 16> | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) | Zero-based indexing, i.e. use [PlayerSlot](#PlayerSlot).input_mapping_controller directly to index this. ### Gamepad @@ -1096,8 +1096,8 @@ array<[PlayerSlotSettings](#PlayerSlotSettings), MAX_PLAYERS> | [player_se Type | Name | Description ---- | ---- | ----------- -array<[KeyboardKey](#KeyboardKey), 112> | [keyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyboard) | State of all keyboard buttons in a random game order as usual, most key indexes can be found in [RAW_KEY](#RAW_KEY). -array<[ControllerInput](#ControllerInput), 12> | [controller](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=controller) | State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. +array<[KeyboardKey](#KeyboardKey), 112> | [keyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyboard) | State of all keyboard buttons in a random game order as usual, most key indexes can be found in [RAW_KEY](#RAW_KEY). Zero-based indexing, i.e. use [PlayerSlot](#PlayerSlot).input_mapping_keyboard directly to index this. +array<[ControllerInput](#ControllerInput), 12> | [controller](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=controller) | State of controller buttons per controller. Zero-based indexing, i.e. use [GameProps](#GameProps).input_index directly to index this. ## Journal types diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index 7cfee3a43..4ed2a7c52 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -89,14 +89,15 @@ struct ControllerButton struct ControllerInput { + /// Zero-based indexing, i.e. use PlayerSlot.input_mapping_controller directly to index this. std::array buttons; }; struct RawInput { - /// State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. + /// State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. Zero-based indexing, i.e. use PlayerSlot.input_mapping_keyboard directly to index this. std::array keyboard; - /// State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. + /// State of controller buttons per controller. Zero-based indexing, i.e. use GameProps.input_index directly to index this. std::array controller; }; diff --git a/src/game_api/script/usertypes/game_manager_lua.cpp b/src/game_api/script/usertypes/game_manager_lua.cpp index cbb98b7c9..309fae496 100644 --- a/src/game_api/script/usertypes/game_manager_lua.cpp +++ b/src/game_api/script/usertypes/game_manager_lua.cpp @@ -130,7 +130,9 @@ void register_usertypes(sol::state& lua) lua.new_usertype( "RawInput", "keyboard", - &RawInput::keyboard, + //&RawInput::keyboard, + sol::property([](RawInput& r) + { return ZeroIndexArray(r.keyboard) /**/; }), "controller", //&RawInput::controller, sol::property([](RawInput& r) @@ -144,7 +146,9 @@ void register_usertypes(sol::state& lua) lua.new_usertype( "ControllerInput", "buttons", - &ControllerInput::buttons); + //&ControllerInput::buttons, + sol::property([](ControllerInput& r) + { return ZeroIndexArray(r.buttons) /**/; })); lua.new_usertype( "ControllerButton", "down", @@ -155,71 +159,71 @@ void register_usertypes(sol::state& lua) /// Returns RawInput, a game structure for raw keyboard and controller state lua["get_raw_input"] = get_raw_input; - /// Keycodes used specifically in RawInput.keyboard. There are more keys than this though, but I didn't want to figure out the OEM keys. + /// Keycodes used specifically in RawInput.keyboard. There are more keys than this though, but I didn't want to figure out the OEM keys. Because these are physical keys, SHIFT, CTRL and ALT are only mapped to the left keys. lua.create_named_table("RAW_KEY" //, "UP", 1 //, "", ...check__[lua_enums.txt]\[game_data/lua_enums.txt\]... ); - lua["RAW_KEY"]["BACKSPACE"] = 0x29; - lua["RAW_KEY"]["TAB"] = 0x07; - lua["RAW_KEY"]["RETURN"] = 0x06; - lua["RAW_KEY"]["SHIFT"] = 0x24; - lua["RAW_KEY"]["CTRL"] = 0x22; - lua["RAW_KEY"]["ALT"] = 0x26; - lua["RAW_KEY"]["RALT"] = 0x27; - lua["RAW_KEY"]["ESCAPE"] = 0x05; - lua["RAW_KEY"]["SPACE"] = 0x28; - lua["RAW_KEY"]["PGUP"] = 0x6C; - lua["RAW_KEY"]["PGDN"] = 0x6A; - lua["RAW_KEY"]["END"] = 0x6B; - lua["RAW_KEY"]["HOME"] = 0x6D; - lua["RAW_KEY"]["LEFT"] = 0x03; - lua["RAW_KEY"]["UP"] = 0x01; - lua["RAW_KEY"]["RIGHT"] = 0x04; - lua["RAW_KEY"]["DOWN"] = 0x02; - lua["RAW_KEY"]["INSERT"] = 0x68; - lua["RAW_KEY"]["DELETE"] = 0x69; - lua["RAW_KEY"]["NUMPAD0"] = 0x4C; - lua["RAW_KEY"]["NUMPAD1"] = 0x4D; - lua["RAW_KEY"]["NUMPAD2"] = 0x4E; - lua["RAW_KEY"]["NUMPAD3"] = 0x4F; - lua["RAW_KEY"]["NUMPAD4"] = 0x50; - lua["RAW_KEY"]["NUMPAD5"] = 0x51; - lua["RAW_KEY"]["NUMPAD6"] = 0x52; - lua["RAW_KEY"]["NUMPAD7"] = 0x53; - lua["RAW_KEY"]["NUMPAD8"] = 0x54; - lua["RAW_KEY"]["NUMPAD9"] = 0x55; - lua["RAW_KEY"]["MULTIPLY"] = 0x58; - lua["RAW_KEY"]["ADD"] = 0x57; - lua["RAW_KEY"]["SUBTRACT"] = 0x56; - lua["RAW_KEY"]["DECIMAL"] = 0x5B; - lua["RAW_KEY"]["DIVIDE"] = 0x59; - lua["RAW_KEY"]["F1"] = 0x2A; - lua["RAW_KEY"]["F2"] = 0x2B; - lua["RAW_KEY"]["F3"] = 0x2C; - lua["RAW_KEY"]["F4"] = 0x2D; - lua["RAW_KEY"]["F5"] = 0x2E; - lua["RAW_KEY"]["F6"] = 0x2F; - lua["RAW_KEY"]["F7"] = 0x30; - lua["RAW_KEY"]["F8"] = 0x31; - lua["RAW_KEY"]["F9"] = 0x32; - lua["RAW_KEY"]["F10"] = 0x33; - lua["RAW_KEY"]["F11"] = 0x34; - lua["RAW_KEY"]["F12"] = 0x35; - lua["RAW_KEY"]["LSHIFT"] = 0x24; - lua["RAW_KEY"]["RSHIFT"] = 0x25; - lua["RAW_KEY"]["LCONTROL"] = 0x22; - lua["RAW_KEY"]["RCONTROL"] = 0x23; - lua["RAW_KEY"]["LALT"] = 0x26; - lua["RAW_KEY"]["RALT"] = 0x27; - lua["RAW_KEY"]["PLUS"] = 0x63; - lua["RAW_KEY"]["COMMA"] = 0x5E; - lua["RAW_KEY"]["MINUS"] = 0x5D; - lua["RAW_KEY"]["PERIOD"] = 0x5F; + lua["RAW_KEY"]["BACKSPACE"] = 0x28; + lua["RAW_KEY"]["TAB"] = 0x06; + lua["RAW_KEY"]["RETURN"] = 0x05; + lua["RAW_KEY"]["SHIFT"] = 0x23; + lua["RAW_KEY"]["CTRL"] = 0x21; + lua["RAW_KEY"]["ALT"] = 0x25; + lua["RAW_KEY"]["ESCAPE"] = 0x04; + lua["RAW_KEY"]["SPACE"] = 0x27; + lua["RAW_KEY"]["PGUP"] = 0x6B; + lua["RAW_KEY"]["PGDN"] = 0x69; + lua["RAW_KEY"]["END"] = 0x6A; + lua["RAW_KEY"]["HOME"] = 0x6C; + lua["RAW_KEY"]["LEFT"] = 0x02; + lua["RAW_KEY"]["UP"] = 0x00; + lua["RAW_KEY"]["RIGHT"] = 0x03; + lua["RAW_KEY"]["DOWN"] = 0x01; + lua["RAW_KEY"]["INSERT"] = 0x67; + lua["RAW_KEY"]["DELETE"] = 0x68; + lua["RAW_KEY"]["NUMPAD0"] = 0x4B; + lua["RAW_KEY"]["NUMPAD1"] = 0x4C; + lua["RAW_KEY"]["NUMPAD2"] = 0x4D; + lua["RAW_KEY"]["NUMPAD3"] = 0x4E; + lua["RAW_KEY"]["NUMPAD4"] = 0x4F; + lua["RAW_KEY"]["NUMPAD5"] = 0x50; + lua["RAW_KEY"]["NUMPAD6"] = 0x51; + lua["RAW_KEY"]["NUMPAD7"] = 0x52; + lua["RAW_KEY"]["NUMPAD8"] = 0x53; + lua["RAW_KEY"]["NUMPAD9"] = 0x54; + lua["RAW_KEY"]["MULTIPLY"] = 0x57; + lua["RAW_KEY"]["ADD"] = 0x56; + lua["RAW_KEY"]["SUBTRACT"] = 0x55; + lua["RAW_KEY"]["DECIMAL"] = 0x5A; + lua["RAW_KEY"]["DIVIDE"] = 0x58; + lua["RAW_KEY"]["NUMPADENTER"] = 0x6E; + lua["RAW_KEY"]["F1"] = 0x29; + lua["RAW_KEY"]["F2"] = 0x2A; + lua["RAW_KEY"]["F3"] = 0x2B; + lua["RAW_KEY"]["F4"] = 0x2C; + lua["RAW_KEY"]["F5"] = 0x2D; + lua["RAW_KEY"]["F6"] = 0x2E; + lua["RAW_KEY"]["F7"] = 0x2F; + lua["RAW_KEY"]["F8"] = 0x30; + lua["RAW_KEY"]["F9"] = 0x31; + lua["RAW_KEY"]["F10"] = 0x32; + lua["RAW_KEY"]["F11"] = 0x33; + lua["RAW_KEY"]["F12"] = 0x34; + lua["RAW_KEY"]["LSHIFT"] = 0x23; + lua["RAW_KEY"]["RSHIFT"] = 0x24; + lua["RAW_KEY"]["LCONTROL"] = 0x21; + lua["RAW_KEY"]["RCONTROL"] = 0x22; + lua["RAW_KEY"]["LALT"] = 0x25; + lua["RAW_KEY"]["RALT"] = 0x26; + lua["RAW_KEY"]["PLUS"] = 0x62; + lua["RAW_KEY"]["COMMA"] = 0x5D; + lua["RAW_KEY"]["MINUS"] = 0x5C; + lua["RAW_KEY"]["PERIOD"] = 0x5E; for (char c = '0'; c <= '9'; c++) - lua["RAW_KEY"][std::string{c}] = (int)c + 18; + lua["RAW_KEY"][std::string{c}] = (int)c + 17; for (char c = 'A'; c <= 'Z'; c++) - lua["RAW_KEY"][std::string{c}] = (int)c - 57; + lua["RAW_KEY"][std::string{c}] = (int)c - 56; } }; // namespace NGM From e924f883cd9ca30acd72002246dc9f89c137cf15 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sat, 11 Nov 2023 18:37:38 +0200 Subject: [PATCH 3/5] add InputMapping array union --- docs/game_data/spel2.lua | 2 +- docs/src/includes/_home.md | 1 - docs/src/includes/_types.md | 1 + src/game_api/aliases.hpp | 3 +- src/game_api/script/usertypes/player_lua.cpp | 4 ++- src/game_api/state_structs.hpp | 32 ++++++++++++-------- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 03c911d6f..300992b6e 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -4920,6 +4920,7 @@ function CustomSound:play(paused, sound_type) end ---@field right integer ---@field up integer ---@field down integer + ---@field mapping RAW_KEY[] @size: 12 @Can be indexed with INPUT_FLAG, keyboard uses RAW_KEY values, controller just uses button numbers. ---@class PlayerInputs ---@field player_slots PlayerSlot[] @size: MAX_PLAYERS @@ -11240,4 +11241,3 @@ local MAX_PLAYERS = 4 ---@alias SHORT_TILE_CODE integer; ---@alias STRINGID integer; ---@alias FEAT integer; ----@alias KEY integer; diff --git a/docs/src/includes/_home.md b/docs/src/includes/_home.md index 122f45c2d..4efbe5a83 100644 --- a/docs/src/includes/_home.md +++ b/docs/src/includes/_home.md @@ -162,4 +162,3 @@ uColor | int; SHORT_TILE_CODE | int; STRINGID | int; FEAT | int; -KEY | int; diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index e7f05949a..a3fbfbe10 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -1073,6 +1073,7 @@ int | [left](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=left) | int | [right](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=right) | int | [up](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=up) | int | [down](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=down) | +array<[RAW_KEY](#RAW_KEY), 12> | [mapping](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=mapping) | Can be indexed with [INPUT_FLAG](#INPUT_FLAG), keyboard uses [RAW_KEY](#RAW_KEY) values, controller just uses button numbers. ### PlayerInputs diff --git a/src/game_api/aliases.hpp b/src/game_api/aliases.hpp index 64dc393cb..e201a7594 100644 --- a/src/game_api/aliases.hpp +++ b/src/game_api/aliases.hpp @@ -23,7 +23,8 @@ using WORLD_SHADER = uint8_t; // NoAlias using SHORT_TILE_CODE = uint8_t; using STRINGID = uint32_t; using FEAT = uint8_t; -using KEY = int64_t; +using KEY = int64_t; // NoAlias +using RAW_KEY = int8_t; // NoAlias inline constexpr uint8_t MAX_PLAYERS = 4; diff --git a/src/game_api/script/usertypes/player_lua.cpp b/src/game_api/script/usertypes/player_lua.cpp index f550c1c3b..ef11f6746 100644 --- a/src/game_api/script/usertypes/player_lua.cpp +++ b/src/game_api/script/usertypes/player_lua.cpp @@ -66,7 +66,9 @@ void register_usertypes(sol::state& lua) "up", sol::readonly(&InputMapping::up), "down", - sol::readonly(&InputMapping::down)); + sol::readonly(&InputMapping::down), + "mapping", + sol::readonly(&InputMapping::mapping)); /// Used in StateMemory lua.new_usertype( "PlayerInputs", diff --git a/src/game_api/state_structs.hpp b/src/game_api/state_structs.hpp index d8993bd95..3c2405240 100644 --- a/src/game_api/state_structs.hpp +++ b/src/game_api/state_structs.hpp @@ -21,18 +21,26 @@ struct RobinHoodTableEntry struct InputMapping { - uint8_t jump; - uint8_t attack; - uint8_t bomb; - uint8_t rope; - uint8_t walk_run; - uint8_t use_door_buy; - uint8_t pause_menu; - uint8_t journal; - uint8_t left; - uint8_t right; - uint8_t up; - uint8_t down; + union + { + struct + { + int8_t jump; + int8_t attack; + int8_t bomb; + int8_t rope; + int8_t walk_run; + int8_t use_door_buy; + int8_t pause_menu; + int8_t journal; + int8_t left; + int8_t right; + int8_t up; + int8_t down; + }; + /// Can be indexed with INPUT_FLAG, keyboard uses RAW_KEY values, controller just uses button numbers. + std::array mapping; + }; }; struct PlayerSlot From c8fcdab4923a1334a3161a726ebc462a3b20187b Mon Sep 17 00:00:00 2001 From: Dregu Date: Sat, 11 Nov 2023 18:51:35 +0200 Subject: [PATCH 4/5] add zero-based ImGuiIO.keys --- docs/game_data/spel2.lua | 3 ++- docs/src/includes/_globals.md | 2 +- docs/src/includes/_types.md | 7 ++++--- src/game_api/script/usertypes/gui_lua.cpp | 15 +++++++++++---- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 300992b6e..1b888e1f0 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -1681,7 +1681,7 @@ function mouse_position() end ---Returns: [ImGuiIO](https://spelunky-fyi.github.io/overlunky/#ImGuiIO) for raw keyboard, mouse and xinput gamepad stuff. --- ---- Note: The clicked/pressed actions only make sense in `ON.GUIFRAME`. ----- Note: Lua starts indexing at 1, you need `keysdown[string.byte('A') + 1]` to find the A key. +---- Note: You can use KEY or standard VK keycodes to index `keys` or the other functions. ---- Note: Overlunky/etc will eat all keys it is currently configured to use, your script will only get leftovers. ---- Note: Gamepad is basically [XINPUT_GAMEPAD](https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad) but variables are renamed and values are normalized to -1.0..1.0 range. ---@return ImGuiIO @@ -5071,6 +5071,7 @@ function GuiDrawContext:win_pushid(id) end ---@field framerate number ---@field wantkeyboard boolean ---@field keysdown boolean[] @size: ImGuiKey_COUNT + ---@field keys boolean[] @size: ImGuiKey_COUNT ---@field keydown fun(key: number | string): boolean ---@field keypressed fun(key: number | string, repeat?: boolean ): boolean ---@field keyreleased fun(key: number | string): boolean diff --git a/docs/src/includes/_globals.md b/docs/src/includes/_globals.md index d48d21207..42a0ed0e5 100644 --- a/docs/src/includes/_globals.md +++ b/docs/src/includes/_globals.md @@ -2087,7 +2087,7 @@ Converts (x, y, BUTTON) to [INPUTS](#INPUTS) Returns: [ImGuiIO](#ImGuiIO) for raw keyboard, mouse and xinput gamepad stuff. - Note: The clicked/pressed actions only make sense in `ON.GUIFRAME`. -- Note: Lua starts indexing at 1, you need `keysdown[string.byte('A') + 1]` to find the A key. +- Note: You can use [KEY](#KEY) or standard VK keycodes to index `keys` or the other functions. - Note: [Overlunky](#Overlunky)/etc will eat all keys it is currently configured to use, your script will only get leftovers. - Note: [Gamepad](#Gamepad) is basically [XINPUT_GAMEPAD](https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad) but variables are renamed and values are normalized to -1.0..1.0 range. diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index a3fbfbe10..28fc83a29 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -1030,9 +1030,10 @@ Type | Name | Description float | [framerate](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=framerate) | bool | [wantkeyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=wantkeyboard) | bool | [keysdown[ImGuiKey_COUNT]](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keysdown) | - | [keydown](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keydown) | bool keydown(int keycode)
bool keydown(char key)
- | [keypressed](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keypressed) | bool keypressed(int keycode, bool repeat = false)
bool keypressed(char key, bool repeat = false)
- | [keyreleased](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyreleased) | bool keyreleased(int keycode)
bool keyreleased(char key)
+bool | [keys[ImGuiKey_COUNT]](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keys) | ZeroIndexArray, use [KEY](#KEY) to index
+ | [keydown](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keydown) | bool keydown([KEY](#KEY) keycode)
bool keydown(char key)
+ | [keypressed](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keypressed) | bool keypressed([KEY](#KEY) keycode, bool repeat = false)
bool keypressed(char key, bool repeat = false)
+ | [keyreleased](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyreleased) | bool keyreleased([KEY](#KEY) keycode)
bool keyreleased(char key)
bool | [keyctrl](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyctrl) | bool | [keyshift](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyshift) | bool | [keyalt](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyalt) | diff --git a/src/game_api/script/usertypes/gui_lua.cpp b/src/game_api/script/usertypes/gui_lua.cpp index bac36a4a3..e76a28fb6 100644 --- a/src/game_api/script/usertypes/gui_lua.cpp +++ b/src/game_api/script/usertypes/gui_lua.cpp @@ -26,6 +26,7 @@ #include "script/handle_lua_function.hpp" // for handle_function #include "script/lua_backend.hpp" // for LuaBackend #include "script/script_util.hpp" // for screenify_fix, screenify, normalize +#include "script/sol_helper.hpp" // #include "window_api.hpp" // for hide_cursor, show_cursor typedef DWORD(WINAPI* PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*); @@ -818,9 +819,13 @@ void register_usertypes(sol::state& lua) &ImGuiIO::Framerate, "wantkeyboard", &ImGuiIO::WantCaptureKeyboard, + /// NoDoc "keysdown", sol::property([](ImGuiIO& io) { return std::ref(io.KeysDown) /**/; }), + "keys", + sol::property([](ImGuiIO& io) + { return ZeroIndexArray(io.KeysDown) /**/; }), "keydown", keydown, "keypressed", @@ -866,14 +871,16 @@ void register_usertypes(sol::state& lua) &ImGuiIO::MouseDrawCursor); /* ImGuiIO + // keys + // ZeroIndexArray, use KEY to index // keydown - // bool keydown(int keycode) + // bool keydown(KEY keycode) // bool keydown(char key) // keypressed - // bool keypressed(int keycode, bool repeat = false) + // bool keypressed(KEY keycode, bool repeat = false) // bool keypressed(char key, bool repeat = false) // keyreleased - // bool keyreleased(int keycode) + // bool keyreleased(KEY keycode) // bool keyreleased(char key) // gamepads // Gamepad gamepads(int index) @@ -889,7 +896,7 @@ void register_usertypes(sol::state& lua) /// Returns: [ImGuiIO](#ImGuiIO) for raw keyboard, mouse and xinput gamepad stuff. /// /// - Note: The clicked/pressed actions only make sense in `ON.GUIFRAME`. - /// - Note: Lua starts indexing at 1, you need `keysdown[string.byte('A') + 1]` to find the A key. + /// - Note: You can use KEY or standard VK keycodes to index `keys` or the other functions. /// - Note: Overlunky/etc will eat all keys it is currently configured to use, your script will only get leftovers. /// - Note: Gamepad is basically [XINPUT_GAMEPAD](https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad) but variables are renamed and values are normalized to -1.0..1.0 range. // lua["get_io"] = []() -> ImGuiIO From dd652db14a910611146e2f74023a0f4b8e73f04b Mon Sep 17 00:00:00 2001 From: Dregu Date: Sat, 11 Nov 2023 19:26:55 +0200 Subject: [PATCH 5/5] add raw button enums --- docs/game_data/lua_enums.txt | 36 +++++++++++++ docs/game_data/spel2.lua | 42 ++++++++++++++- docs/src/includes/_enums.md | 52 +++++++++++++++++++ docs/src/includes/_types.md | 4 +- src/game_api/game_manager.hpp | 2 +- .../script/usertypes/game_manager_lua.cpp | 4 ++ src/game_api/state_structs.hpp | 2 +- 7 files changed, 136 insertions(+), 6 deletions(-) diff --git a/docs/game_data/lua_enums.txt b/docs/game_data/lua_enums.txt index 0b52187a5..fa3e09018 100644 --- a/docs/game_data/lua_enums.txt +++ b/docs/game_data/lua_enums.txt @@ -2568,6 +2568,42 @@ QUEST_FLAG = { VAULT_SPAWNED = 3, WADDLER_AGGROED = 10 } +RAW_BUTTON = { + A = 4, + B = 5, + BACK = 14, + DOWN = 1, + LEFT = 2, + LEFT_SHOULDER = 8, + LEFT_THUMB = 12, + LEFT_TRIGGER = 10, + RIGHT = 3, + RIGHT_SHOULDER = 9, + RIGHT_THUMB = 13, + RIGHT_TRIGGER = 11, + START = 15, + UP = 0, + X = 6, + Y = 7 +} +RAW_DUALSHOCK = { + CIRCLE = 5, + CROSS = 4, + DOWN = 1, + L1 = 8, + L2 = 10, + L3 = 12, + LEFT = 2, + OPTIONS = 15, + R1 = 9, + R2 = 11, + R3 = 13, + RIGHT = 3, + SHARE = 14, + SQUARE = 6, + TRIANGLE = 7, + UP = 0 +} RAW_KEY = { ["0"] = 65, ["1"] = 66, diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 1b888e1f0..d5b6c8252 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -2305,7 +2305,7 @@ do ---@field pressed boolean @Key was just pressed down this frame ---@class ControllerInput - ---@field buttons ControllerButton[] @size: 16 @Zero-based indexing, i.e. use PlayerSlot.input_mapping_controller directly to index this. + ---@field buttons ControllerButton[] @size: 16 @Zero-based indexing. Use PlayerSlot.input_mapping_controller or RAW_BUTTON (or RAW_DUALSHOCK) to index this. ---@class ControllerButton ---@field down boolean @Button is being held @@ -4920,7 +4920,7 @@ function CustomSound:play(paused, sound_type) end ---@field right integer ---@field up integer ---@field down integer - ---@field mapping RAW_KEY[] @size: 12 @Can be indexed with INPUT_FLAG, keyboard uses RAW_KEY values, controller just uses button numbers. + ---@field mapping RAW_KEY[] @size: 12 @Can be indexed with INPUT_FLAG. Keyboard uses RAW_KEY values, controller uses RAW_BUTTON values. ---@class PlayerInputs ---@field player_slots PlayerSlot[] @size: MAX_PLAYERS @@ -9178,6 +9178,44 @@ QUEST_FLAG = { WADDLER_AGGROED = 10 } ---@alias QUEST_FLAG integer +RAW_BUTTON = { + A = 4, + B = 5, + BACK = 14, + DOWN = 1, + LEFT = 2, + LEFT_SHOULDER = 8, + LEFT_THUMB = 12, + LEFT_TRIGGER = 10, + RIGHT = 3, + RIGHT_SHOULDER = 9, + RIGHT_THUMB = 13, + RIGHT_TRIGGER = 11, + START = 15, + UP = 0, + X = 6, + Y = 7 +} +---@alias RAW_BUTTON integer +RAW_DUALSHOCK = { + CIRCLE = 5, + CROSS = 4, + DOWN = 1, + L1 = 8, + L2 = 10, + L3 = 12, + LEFT = 2, + OPTIONS = 15, + R1 = 9, + R2 = 11, + R3 = 13, + RIGHT = 3, + SHARE = 14, + SQUARE = 6, + TRIANGLE = 7, + UP = 0 +} +---@alias RAW_DUALSHOCK integer RAW_KEY = { ["0"] = 65, ["1"] = 66, diff --git a/docs/src/includes/_enums.md b/docs/src/includes/_enums.md index 7d9009998..95553ed59 100644 --- a/docs/src/includes/_enums.md +++ b/docs/src/includes/_enums.md @@ -1019,6 +1019,58 @@ Name | Data | Description [STAR_CHALLENGE_SPAWNED](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=QUEST_FLAG.STAR_CHALLENGE_SPAWNED) | 26 | [SUN_CHALLENGE_SPAWNED](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=QUEST_FLAG.SUN_CHALLENGE_SPAWNED) | 27 | +## RAW_BUTTON + + +> Search script examples for [RAW_BUTTON](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON) + + + +Name | Data | Description +---- | ---- | ----------- +[UP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.UP) | 0 | +[DOWN](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.DOWN) | 1 | +[LEFT](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.LEFT) | 2 | +[RIGHT](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.RIGHT) | 3 | +[A](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.A) | 4 | +[B](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.B) | 5 | +[X](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.X) | 6 | +[Y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.Y) | 7 | +[LEFT_SHOULDER](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.LEFT_SHOULDER) | 8 | +[RIGHT_SHOULDER](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.RIGHT_SHOULDER) | 9 | +[LEFT_TRIGGER](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.LEFT_TRIGGER) | 10 | +[RIGHT_TRIGGER](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.RIGHT_TRIGGER) | 11 | +[LEFT_THUMB](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.LEFT_THUMB) | 12 | +[RIGHT_THUMB](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.RIGHT_THUMB) | 13 | +[BACK](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.BACK) | 14 | +[START](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_BUTTON.START) | 15 | + +## RAW_DUALSHOCK + + +> Search script examples for [RAW_DUALSHOCK](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK) + + + +Name | Data | Description +---- | ---- | ----------- +[UP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.UP) | 0 | +[DOWN](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.DOWN) | 1 | +[LEFT](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.LEFT) | 2 | +[RIGHT](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.RIGHT) | 3 | +[CROSS](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.CROSS) | 4 | +[CIRCLE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.CIRCLE) | 5 | +[SQUARE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.SQUARE) | 6 | +[TRIANGLE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.TRIANGLE) | 7 | +[L1](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.L1) | 8 | +[R1](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.R1) | 9 | +[L2](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.L2) | 10 | +[R2](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.R2) | 11 | +[L3](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.L3) | 12 | +[R3](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.R3) | 13 | +[SHARE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.SHARE) | 14 | +[OPTIONS](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RAW_DUALSHOCK.OPTIONS) | 15 | + ## RAW_KEY diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index 28fc83a29..81aaf4d3e 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -1003,7 +1003,7 @@ tuple<float, float> | [split()](https://github.com/spelunky-fyi/overlunky/ Type | Name | Description ---- | ---- | ----------- -array<[ControllerButton](#ControllerButton), 16> | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) | Zero-based indexing, i.e. use [PlayerSlot](#PlayerSlot).input_mapping_controller directly to index this. +array<[ControllerButton](#ControllerButton), 16> | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) | Zero-based indexing. Use [PlayerSlot](#PlayerSlot).input_mapping_controller or [RAW_BUTTON](#RAW_BUTTON) (or RAW_DUALSHOCK) to index this. ### Gamepad @@ -1074,7 +1074,7 @@ int | [left](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=left) | int | [right](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=right) | int | [up](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=up) | int | [down](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=down) | -array<[RAW_KEY](#RAW_KEY), 12> | [mapping](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=mapping) | Can be indexed with [INPUT_FLAG](#INPUT_FLAG), keyboard uses [RAW_KEY](#RAW_KEY) values, controller just uses button numbers. +array<[RAW_KEY](#RAW_KEY), 12> | [mapping](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=mapping) | Can be indexed with [INPUT_FLAG](#INPUT_FLAG). Keyboard uses [RAW_KEY](#RAW_KEY) values, controller uses [RAW_BUTTON](#RAW_BUTTON) values. ### PlayerInputs diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index 4ed2a7c52..5fb677395 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -89,7 +89,7 @@ struct ControllerButton struct ControllerInput { - /// Zero-based indexing, i.e. use PlayerSlot.input_mapping_controller directly to index this. + /// Zero-based indexing. Use PlayerSlot.input_mapping_controller or RAW_BUTTON (or RAW_DUALSHOCK) to index this. std::array buttons; }; diff --git a/src/game_api/script/usertypes/game_manager_lua.cpp b/src/game_api/script/usertypes/game_manager_lua.cpp index 309fae496..82ddfce16 100644 --- a/src/game_api/script/usertypes/game_manager_lua.cpp +++ b/src/game_api/script/usertypes/game_manager_lua.cpp @@ -225,5 +225,9 @@ void register_usertypes(sol::state& lua) lua["RAW_KEY"][std::string{c}] = (int)c + 17; for (char c = 'A'; c <= 'Z'; c++) lua["RAW_KEY"][std::string{c}] = (int)c - 56; + + lua.create_named_table("RAW_BUTTON", "UP", 0, "DOWN", 1, "LEFT", 2, "RIGHT", 3, "A", 4, "B", 5, "X", 6, "Y", 7, "LEFT_SHOULDER", 8, "RIGHT_SHOULDER", 9, "LEFT_TRIGGER", 10, "RIGHT_TRIGGER", 11, "LEFT_THUMB", 12, "RIGHT_THUMB", 13, "BACK", 14, "START", 15); + + lua.create_named_table("RAW_DUALSHOCK", "UP", 0, "DOWN", 1, "LEFT", 2, "RIGHT", 3, "CROSS", 4, "CIRCLE", 5, "SQUARE", 6, "TRIANGLE", 7, "L1", 8, "R1", 9, "L2", 10, "R2", 11, "L3", 12, "R3", 13, "SHARE", 14, "OPTIONS", 15); } }; // namespace NGM diff --git a/src/game_api/state_structs.hpp b/src/game_api/state_structs.hpp index 3c2405240..c74a5d46d 100644 --- a/src/game_api/state_structs.hpp +++ b/src/game_api/state_structs.hpp @@ -38,7 +38,7 @@ struct InputMapping int8_t up; int8_t down; }; - /// Can be indexed with INPUT_FLAG, keyboard uses RAW_KEY values, controller just uses button numbers. + /// Can be indexed with INPUT_FLAG. Keyboard uses RAW_KEY values, controller uses RAW_BUTTON values. std::array mapping; }; };