From 358efd4b9ec94d3f51ba54f1bbe23d7eedc13652 Mon Sep 17 00:00:00 2001 From: hamhub7 <38668528+hamhub7@users.noreply.github.com> Date: Mon, 24 May 2021 14:42:20 -0400 Subject: [PATCH] yuh sol works --- lua/main.lua | 38 +++--- lua/memtest.lua | 6 +- lua/sys/hidenum.lua | 312 ++++++++++++++++++++------------------------ source/main.cpp | 42 +++--- 4 files changed, 183 insertions(+), 215 deletions(-) diff --git a/lua/main.lua b/lua/main.lua index 2f63dc3..b127296 100644 --- a/lua/main.lua +++ b/lua/main.lua @@ -63,21 +63,21 @@ while true do if tasOn then -- Adding/removing controllers if tas.multiplayer then - if hid_KeyboardDown(hid.KeyboardScancode.Equal) and #controllers < 8 then + if hid_KeyboardDown(hid.KeyboardKey.Plus) and #controllers < 8 then table.insert(controllers, hiddbg_AttachController(bodyColor, buttonsColor, gripLColor, gripRColor)) - elseif hid_KeyboardDown(hid.KeyboardScancode.Minus) and attached(controllers, #controllers) then + elseif hid_KeyboardDown(hid.KeyboardKey.Minus) and attached(controllers, #controllers) then hiddbg_DetachController(controllers[#controllers]) end else - if hid_KeyboardDown(hid.KeyboardScancode.Equal) and #controllers < 1 then + if hid_KeyboardDown(hid.KeyboardKey.Plus) and #controllers < 1 then controllers[1] = hiddbg_AttachController(bodyColor, buttonsColor, gripLColor, gripRColor) - elseif hid_KeyboardDown(hid.KeyboardScancode.Minus) and attached(controllers, 1) then + elseif hid_KeyboardDown(hid.KeyboardKey.Minus) and attached(controllers, 1) then hiddbg_DetachController(controllers[1]) end end -- Running scripts - if hid_KeyboardDown(hid.KeyboardScancode.F1) then + if hid_KeyboardDown(hid.KeyboardKey.F1) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script1", controllers) @@ -87,7 +87,7 @@ while true do runScript("script1", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F2) then + elseif hid_KeyboardDown(hid.KeyboardKey.F2) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script2", controllers) @@ -97,7 +97,7 @@ while true do runScript("script2", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F3) then + elseif hid_KeyboardDown(hid.KeyboardKey.F3) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script3", controllers) @@ -107,7 +107,7 @@ while true do runScript("script3", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F4) then + elseif hid_KeyboardDown(hid.KeyboardKey.F4) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script4", controllers) @@ -117,7 +117,7 @@ while true do runScript("script4", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F5) then + elseif hid_KeyboardDown(hid.KeyboardKey.F5) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script5", controllers) @@ -127,7 +127,7 @@ while true do runScript("script5", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F6) then + elseif hid_KeyboardDown(hid.KeyboardKey.F6) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script6", controllers) @@ -137,7 +137,7 @@ while true do runScript("script6", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F7) then + elseif hid_KeyboardDown(hid.KeyboardKey.F7) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script7", controllers) @@ -147,7 +147,7 @@ while true do runScript("script7", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F8) then + elseif hid_KeyboardDown(hid.KeyboardKey.F8) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script8", controllers) @@ -157,7 +157,7 @@ while true do runScript("script8", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F9) then + elseif hid_KeyboardDown(hid.KeyboardKey.F9) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script9", controllers) @@ -167,7 +167,7 @@ while true do runScript("script9", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F10) then + elseif hid_KeyboardDown(hid.KeyboardKey.F10) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script10", controllers) @@ -177,7 +177,7 @@ while true do runScript("script10", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F11) then + elseif hid_KeyboardDown(hid.KeyboardKey.F11) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script11", controllers) @@ -187,7 +187,7 @@ while true do runScript("script11", controllers[1]) end end - elseif hid_KeyboardDown(hid.KeyboardScancode.F12) then + elseif hid_KeyboardDown(hid.KeyboardKey.F12) then if tas.multiplayer and #controllers > 1 then if attached(controllers, #controllers) then runMultiplayerScript("script12", controllers) @@ -200,12 +200,12 @@ while true do end -- Utility keybinds - if hid_KeyboardDown(hid.KeyboardScancode.Q) and #controllers > 0 then + if hid_KeyboardDown(hid.KeyboardKey.Q) and #controllers > 0 then hiddbg_SetButtons(controllers[1], hid.ControllerKeys.A) waitFrames(5) hiddbg_SetButtons(controllers[1], 0) waitFrames(5) - elseif hid_KeyboardDown(hid.KeyboardScancode.W) and #controllers > 0 then + elseif hid_KeyboardDown(hid.KeyboardKey.W) and #controllers > 0 then for i,v in ipairs(controllers) do hiddbg_SetButtons(v, hid.ControllerKeys.L | hid.ControllerKeys.R) waitFrames(5) @@ -215,7 +215,7 @@ while true do end end - if hid_KeyboardDown(hid.KeyboardScancode.Esc) then + if hid_KeyboardDown(hid.KeyboardKey.Escape) then tasOn = not tasOn end diff --git a/lua/memtest.lua b/lua/memtest.lua index 32e94e4..a48c8df 100644 --- a/lua/memtest.lua +++ b/lua/memtest.lua @@ -12,17 +12,17 @@ local size = 0x4 while true do hid_ScanInput() - if hid_KeyboardDown(hid.KeyboardScancode.F1) then + if hid_KeyboardDown(hid.KeyboardKey.F1) then local value = svc_ReadMemory(mainAddr, offsets, size) Log(value) end - if hid_KeyboardDown(hid.KeyboardScancode.F2) then + if hid_KeyboardDown(hid.KeyboardKey.F2) then mainAddr = svc_GetMainAddr() Log(mainAddr) end - if hid_KeyboardDown(hid.KeyboardScancode.F3) then + if hid_KeyboardDown(hid.KeyboardKey.F3) then mainAddr = svc_GetMainAddr() Log(mainAddr) local value = svc_ReadMemory(mainAddr, offsets, size) diff --git a/lua/sys/hidenum.lua b/lua/sys/hidenum.lua index ed88818..2cdb85c 100644 --- a/lua/sys/hidenum.lua +++ b/lua/sys/hidenum.lua @@ -12,191 +12,157 @@ hidenum.KeyboardModifier = { LCtrl = 1 << 0, LShift = 1 << 1, LAlt = 1 << 2, - LMeta = 1 << 3, - RCtrl = 1 << 4, - RShift = 1 << 5, - LAlt = 1 << 6, - RMeta = 1 << 7, + RAlt = 1 << 3, + Gui = 1 << 4, CapsLock = 1 << 8, ScrollLock = 1 << 9, - NumLock = 1 << 10 + NumLock = 1 << 10, + Katakan = 1 << 11, + Hiragana = 1 << 12 } -hidenum.KeyboardScancode = { - None = 0x00, - ErrOvf = 0x01, +hidenum.KeyboardKey = { + A = 4, + B = 5, + C = 6, + D = 7, + E = 8, + F = 9, + G = 10, + H = 11, + I = 12, + J = 13, + K = 14, + L = 15, + M = 16, + N = 17, + O = 18, + P = 19, + Q = 20, + R = 21, + S = 22, + T = 23, + U = 24, + V = 25, + W = 26, + X = 27, + Y = 28, + Z = 29, - A = 0x04, - B = 0x05, - C = 0x06, - D = 0x07, - E = 0x08, - F = 0x09, - G = 0x0a, - H = 0x0b, - I = 0x0c, - J = 0x0d, - K = 0x0e, - L = 0x0f, - M = 0x10, - N = 0x11, - O = 0x12, - P = 0x13, - Q = 0x14, - R = 0x15, - S = 0x16, - T = 0x17, - U = 0x18, - V = 0x19, - W = 0x1a, - X = 0x1b, - Y = 0x1c, - Z = 0x1d, + D1 = 30, + D2 = 31, + D3 = 32, + D4 = 33, + D5 = 34, + D6 = 35, + D7 = 36, + D8 = 37, + D9 = 38, + D0 = 39, - Num1 = 0x1e, - Num2 = 0x1f, - Num3 = 0x20, - Num4 = 0x21, - Num5 = 0x22, - Num6 = 0x23, - Num7 = 0x24, - Num8 = 0x25, - Num9 = 0x26, - Num0 = 0x27, + Return = 40, + Escape = 41, + Backspace = 42, + Tab = 43, + Space = 44, + Minus = 45, + Plus = 46, + OpenBracket = 47, + CloseBracket = 48, + Pipe = 49, + Tilde = 50, + Semicolon = 51, + Quote = 52, + Backquote = 53, + Comma = 54, + Period = 55, + Slash = 56, + CapsLock = 57, - Enter = 0x28, - Esc = 0x29, - Backspace = 0x2a, - Tab = 0x2b, - Space = 0x2c, - Minus = 0x2d, - Equal = 0x2e, - LeftBrace = 0x2f, - RightBrace = 0x30, - Backslash = 0x31, - HashTilde = 0x32, - Semicolon = 0x33, - Apostrophe = 0x34, - Grave = 0x35, - Comma = 0x36, - Dot = 0x37, - Slash = 0x38, - CapsLock = 0x39, + F1 = 58, + F2 = 59, + F3 = 60, + F4 = 61, + F5 = 62, + F6 = 63, + F7 = 64, + F8 = 65, + F9 = 66, + F10 = 67, + F11 = 68, + F12 = 69, - F1 = 0x3a, - F2 = 0x3b, - F3 = 0x3c, - F4 = 0x3d, - F5 = 0x3e, - F6 = 0x3f, - F7 = 0x40, - F8 = 0x41, - F9 = 0x42, - F10 = 0x43, - F11 = 0x44, - F12 = 0x45, + PrintScreen = 70, + ScrollLock = 71, + Pause = 72, + Insert = 73, + Home = 74, + PageUp = 75, + Delete = 76, + End = 77, + PageDown = 78, + RightArrow = 79, + LeftArrow = 80, + DownArrow = 81, + UpArrow = 82, - PrintScreen = 0x46, - ScrollLock = 0x47, - Pause = 0x48, - Insert = 0x49, - Home = 0x4a, - PageUp = 0x4b, - Delete = 0x4c, - End = 0x4d, - PageDown = 0x4e, - Right = 0x4f, - Left = 0x50, - Down = 0x51, - Up = 0x52, + NumLock = 83, + NumPadDivide = 84, + NumPadMultiply = 85, + NumPadSubtract = 86, + NumPadAdd = 87, + NumPadEnter = 88, + NumPad1 = 89, + NumPad2 = 90, + NumPad3 = 91, + NumPad4 = 92, + NumPad5 = 93, + NumPad6 = 94, + NumPad7 = 95, + NumPad8 = 96, + NumPad9 = 97, + NumPad0 = 98, + NumPadDot = 99, + Backslash = 100, + Application = 101, + Power = 102, + NumPadEquals = 103, - NumLock = 0x53, - NumpadSlash = 0x54, - NumpadAsterisk = 0x55, - NumpadMinus = 0x56, - NumpadPlus = 0x57, - NumpadEnter = 0x58, - Numpad1 = 0x59, - Numpad2 = 0x5a, - Numpad3 = 0x5b, - Numpad4 = 0x5c, - Numpad5 = 0x5d, - Numpad6 = 0x5e, - Numpad7 = 0x5f, - Numpad8 = 0x60, - Numpad9 = 0x61, - Numpad0 = 0x62, - NumpadDot = 0x63, + F13 = 104, + F14 = 105, + F15 = 106, + F16 = 107, + F17 = 108, + F18 = 109, + F19 = 110, + F20 = 111, + F21 = 112, + F22 = 113, + F23 = 114, + F24 = 115, - ND102 = 0x64, - Compose = 0x65, - Power = 0x66, - NumpadEqual = 0x67, + NumPadComma = 133, - F13 = 0x68, - F14 = 0x69, - F15 = 0x6a, - F16 = 0x6b, - F17 = 0x6c, - F18 = 0x6d, - F19 = 0x6e, - F20 = 0x6f, - F21 = 0x70, - F22 = 0x71, - F23 = 0x72, - F24 = 0x73, - - Open = 0x74, - Help = 0x75, - Props = 0x76, - Front = 0x77, - Stop = 0x78, - Again = 0x79, - Undo = 0x7a, - Cut = 0x7b, - Copy = 0x7c, - Paste = 0x7d, - Find = 0x7e, - Mute = 0x7f, - VolumeUp = 0x80, - VolumeDown = 0x81, - CapsLockActive = 0x82 , - NumLockActive = 0x83 , - ScrollLockActive = 0x84 , - NumpadComma = 0x85, - - NumpadLeftParen = 0xb6, - NumpadRightParen = 0xb7, - - LeftCtrl = 0xe0, - LeftShift = 0xe1, - LeftAlt = 0xe2, - LeftMeta = 0xe3, - RightCtrl = 0xe4, - RightShift = 0xe5, - RightAlt = 0xe6, - RightMeta = 0xe7, - - MediaPlayPause = 0xe8, - MediaStopCD = 0xe9, - MediaPerviousSong = 0xea, - MediaNextSong = 0xeb, - MediaEjected = 0xec, - MediaVolumeUp = 0xed, - MediaVolumeDown = 0xee, - MediaMute = 0xef, - MediaWWW = 0xf0, - Mediaback = 0xf1, - MediaForward = 0xf2, - MediStop = 0xf3, - MediaFind = 0xf4, - MediaScrollUp = 0xf5, - MediaScrollDown = 0xf6, - MediaEdit = 0xf7, - MediaSleep = 0xf8, - MediaCoffee = 0xf9, - MediaRefresh = 0xfa, - MediaCalc = 0xfb + Ro = 135, + KatakanaHiragana = 136, + Yen = 137, + Henkan = 138, + Muhenkan = 139, + NumPadCommaPc98 = 140, + HangulEnglish = 144, + Hanja = 145, + Katakana = 146, + Hiragana = 147, + ZenkakuHankaku = 148, + + LeftControl = 224, + LeftShift = 225, + LeftAlt = 226, + LeftGui = 227, + RightControl = 228, + RightShift = 229, + RightAlt = 230, + RightGui = 231 } hidenum.ControllerType = { diff --git a/source/main.cpp b/source/main.cpp index 55c37ac..e59b09d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -23,10 +23,10 @@ extern "C" // Sysmodules should not use applet*. u32 __nx_applet_type = AppletType_None; - // Adjust size as needed. - #define INNER_HEAP_SIZE 0x400000 +// Adjust size as needed. +#define INNER_HEAP_SIZE 0x400000 size_t nx_inner_heap_size = INNER_HEAP_SIZE; - char nx_inner_heap[INNER_HEAP_SIZE]; + char nx_inner_heap[INNER_HEAP_SIZE]; void __libnx_init_time(void); void __libnx_initheap(void); @@ -36,15 +36,15 @@ extern "C" void __libnx_initheap(void) { - void* addr = nx_inner_heap; - size_t size = nx_inner_heap_size; + void *addr = nx_inner_heap; + size_t size = nx_inner_heap_size; - // Newlib - extern char* fake_heap_start; - extern char* fake_heap_end; + // Newlib + extern char *fake_heap_start; + extern char *fake_heap_end; - fake_heap_start = (char*)addr; - fake_heap_end = (char*)addr + size; + fake_heap_start = (char *)addr; + fake_heap_end = (char *)addr + size; } // Init/exit services, update as needed. @@ -58,11 +58,12 @@ void __attribute__((weak)) __appInit(void) fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); rc = ldrDmntInitialize(); - if(R_FAILED(rc)) + if (R_FAILED(rc)) fatalThrow(rc); rc = setsysInitialize(); - if (R_SUCCEEDED(rc)) { + if (R_SUCCEEDED(rc)) + { SetSysFirmwareVersion fw; rc = setsysGetFirmwareVersion(&fw); if (R_SUCCEEDED(rc)) @@ -89,7 +90,7 @@ void __attribute__((weak)) __appInit(void) // vsync rc = viInitialize(ViServiceType_System); - if(R_FAILED(rc)) + if (R_FAILED(rc)) fatalThrow(rc); // time @@ -98,7 +99,7 @@ void __attribute__((weak)) __appInit(void) fatalThrow(rc); rc = pmdmntInitialize(); - if(R_FAILED(rc)) + if (R_FAILED(rc)) fatalThrow(rc); // Attach Work Buffer @@ -131,7 +132,7 @@ void logToSd(std::string message) { std::ofstream ofs; ofs.open(filepath, std::ofstream::out | std::ofstream::app); - if(ofs.is_open()) + if (ofs.is_open()) { ofs << message << std::endl; } @@ -144,7 +145,7 @@ void logToSd(std::string message) void lua_SetupLog(std::string logpath) { std::ofstream ofs; - + filepath = logpath; ofs.open(logpath, std::ofstream::out | std::ofstream::trunc); ofs.close(); @@ -160,17 +161,17 @@ void lua_Log(std::string msg) return; } -void registerUtility(sol::state& lua) +void registerUtility(sol::state &lua) { lua.set_function("SetupLog", lua_SetupLog); lua.set_function("Log", lua_Log); } // Main program entrypoint -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { sol::state lua; - lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::table); + lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::table, sol::lib::io, sol::lib::string); // Register Lua functions registerUtility(lua); @@ -182,7 +183,8 @@ int main(int argc, char* argv[]) // Your code / main loop goes here. sol::protected_function_result result = lua.safe_script_file("sdmc:/script/boot.lua"); - if(!result.valid()) { + if (!result.valid()) + { sol::error err = result; logToSd(err.what()); }