diff --git a/Controllers/RoccatController/RoccatVulcanKeyboardController/RGBController_RoccatVulcanKeyboard.cpp b/Controllers/RoccatController/RoccatVulcanKeyboardController/RGBController_RoccatVulcanKeyboard.cpp index 426f76f42..870312e66 100644 --- a/Controllers/RoccatController/RoccatVulcanKeyboardController/RGBController_RoccatVulcanKeyboard.cpp +++ b/Controllers/RoccatController/RoccatVulcanKeyboardController/RGBController_RoccatVulcanKeyboard.cpp @@ -151,6 +151,9 @@ void RGBController_RoccatVulcanKeyboard::SetupZones() case ROCCAT_VULCAN_LAYOUT_FR: layout = ROCCAT_VULCAN_LAYOUT_UK; break; + case ROCCAT_VULCAN_LAYOUT_JP: + layout = ROCCAT_VULCAN_LAYOUT_JP; + break; case ROCCAT_VULCAN_LAYOUT_US: default: layout = ROCCAT_VULCAN_LAYOUT_US; @@ -167,7 +170,13 @@ void RGBController_RoccatVulcanKeyboard::SetupZones() if(pid == ROCCAT_VULCAN_II_MAX_PID) { - keyboard_size = 108; + /*---------------------------------------------------------*\ + | Dynamically calculate the main keyboard zone size by | + | subtracting the 40 secondary/palm rest LEDs from the | + | total layout size. This prevents JIS keys from overflow. | + \*---------------------------------------------------------*/ + keyboard_size = keyboard[layout].size - 40; + } zone keyboard_zone; diff --git a/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp b/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp index 576270024..1a482510c 100644 --- a/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp +++ b/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp @@ -84,6 +84,10 @@ device_info RoccatVulcanKeyboardController::InitDeviceInfo() memset(buf, 0x00, packet_length); buf[0] = report_id; + /*-------------------------------------------------------------*\ + | Store the actual read bytes to verify data availability | + \*-------------------------------------------------------------*/ + int res = hid_get_feature_report(dev_ctrl, buf, packet_length); hid_get_feature_report(dev_ctrl, buf, packet_length); /*-------------------------------------------------------------*\ @@ -107,11 +111,22 @@ device_info RoccatVulcanKeyboardController::InitDeviceInfo() } else { - dev_info.layout_type = buf[6]; + /*---------------------------------------------------------*\ + | Safe check for reported buffer length before accessing | + | buf[6] to prevent out-of-bounds array access. | + | Vulcan II Max (JP) returns 0x06 at buf[6] for JIS layout. | + \*---------------------------------------------------------*/ + if(res >= 7) + { + dev_info.layout_type = buf[6]; + LOG_DEBUG("[Roccat Vulcan Keyboard]: Detected layout '0x%02X'", buf[6]); + } + else + { + dev_info.layout_type = ROCCAT_VULCAN_LAYOUT_US; + LOG_DEBUG("[Roccat Vulcan Keyboard]: Failed to detect layout, falling back to US"); + } } - - LOG_DEBUG("[Roccat Vulcan Keyboard]: Detected layout '0x%02X'", buf[6]); - delete[] buf; return dev_info; } diff --git a/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardLayouts.h b/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardLayouts.h index 017f43ac4..32c2a1868 100644 --- a/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardLayouts.h +++ b/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardLayouts.h @@ -22,6 +22,7 @@ enum ROCCAT_VULCAN_LAYOUT_DE = 1, ROCCAT_VULCAN_LAYOUT_UK = 2, ROCCAT_VULCAN_LAYOUT_FR = 3, + ROCCAT_VULCAN_LAYOUT_JP = 6, /* Updated based on Vulcan II Max JIS firmware report value */ }; #define NA 0xFFFFFFFF @@ -815,6 +816,16 @@ static unsigned int ROCCAT_VULCAN_II_MAX_LAYOUT_KEYS_ANSI[6][24] = { 5, 8, 14, NA, NA, NA, 34, NA, NA, NA, 55, 61, 66, 74, NA, NA, 78, 83, 87, NA, 92, NA, 101, NA } }; +static unsigned int ROCCAT_VULCAN_II_MAX_LAYOUT_KEYS_JIS[6][24] = +{ + { 0, NA, 7, 13, 19, 25, NA, 35, 40, 45, 51, 57, 63, 69, 73, NA, 78, 82, 87, NA, 108, 109, 110, NA }, + { 1, 6, 8, 14, 20, 26, 30, 36, 41, 46, 52, 58, 64, 70, 74, NA, 79, 83, 88, NA, 91, 96, 100, 105 }, + { 2, NA, 9, 15, 21, 27, 31, 37, 42, 47, 53, 59, 65, 71, 75, NA, 80, 84, 89, NA, 92, 97, 101, 106 }, + { 3, NA, 10, 16, 22, 28, 32, 38, 43, 48, 54, 60, 66, 72, NA, NA, NA, NA, NA, NA, 93, 98, 102, NA }, + { 4, NA, 11, 17, 23, 29, 33, 39, 44, 49, 55, 61, 67, NA, 76, NA, NA, 85, NA, NA, 94, 99, 103, 107 }, + { 5, NA, 12, 18, 24, NA, 34, NA, NA, 50, 56, 62, 68, NA, 77, NA, 81, 86, 90, NA, 95, NA, 104, NA } +}; + static std::map RoccatVulcanIIMaxLayouts = { { @@ -1005,7 +1016,219 @@ static std::map RoccatVulcanIIMaxLayouts = { "Key: Left Windows LED 2", 0x83 }, /*-------------------------------------------------------------*\ - | Palm Rest LEDs (order approximate - needs verification) | + | Palm Rest LEDs (order approximate - needs verification) | + \*-------------------------------------------------------------*/ + { "Palm Rest LED 1", 0x96 }, + { "Palm Rest LED 2", 0xAD }, + { "Palm Rest LED 3", 0xA7 }, + { "Palm Rest LED 4", 0xA1 }, + { "Palm Rest LED 5", 0x9B }, + { "Palm Rest LED 6", 0x95 }, + { "Palm Rest LED 7", 0xAC }, + { "Palm Rest LED 8", 0xA6 }, + { "Palm Rest LED 9", 0xA0 }, + { "Palm Rest LED 10", 0x9A }, + { "Palm Rest LED 11", 0x94 }, + { "Palm Rest LED 12", 0xAB }, + { "Palm Rest LED 13", 0xA5 }, + { "Palm Rest LED 14", 0x9F }, + { "Palm Rest LED 15", 0x99 }, + { "Palm Rest LED 16", 0x93 } + } + } + }, + { + ROCCAT_VULCAN_LAYOUT_JP, + { + *ROCCAT_VULCAN_II_MAX_LAYOUT_KEYS_JIS, + 151, + 6, + 24, + { + { KEY_EN_ESCAPE, 0x03 }, + { KEY_JP_EJ, 0x02 }, + { KEY_EN_TAB, 0x04 }, + { KEY_EN_CAPS_LOCK, 0x05 }, + { KEY_EN_LEFT_SHIFT, 0x00 }, + { KEY_EN_LEFT_CONTROL, 0x01 }, + + { KEY_EN_1, 0x08 }, + + { KEY_EN_F1, 0x0D }, + { KEY_EN_2, 0x0E }, + { KEY_EN_Q, 0x09 }, + { KEY_EN_A, 0x0A }, + { KEY_EN_Z, 0x0B }, + { KEY_EN_LEFT_WINDOWS, 0x07 }, + + { KEY_EN_F2, 0x14 }, + { KEY_EN_3, 0x15 }, + { KEY_EN_W, 0x0F }, + { KEY_EN_S, 0x10 }, + { KEY_EN_X, 0x11 }, + { KEY_EN_LEFT_ALT, 0x0C }, + + { KEY_EN_F3, 0x19 }, + { KEY_EN_4, 0x1A }, + { KEY_EN_E, 0x16 }, + { KEY_EN_D, 0x17 }, + { KEY_EN_C, 0x18 }, + { KEY_JP_MUHENKAN, 0x12 }, + + { KEY_EN_F4, 0x1F }, + { KEY_EN_5, 0x1E }, + { KEY_EN_R, 0x1B }, + { KEY_EN_F, 0x1C }, + { KEY_EN_V, 0x21 }, + + { KEY_EN_6, 0x24 }, + { KEY_EN_T, 0x20 }, + { KEY_EN_G, 0x1D }, + { KEY_EN_B, 0x22 }, + { KEY_EN_SPACE, 0x28 }, + + { KEY_EN_F5, 0x23 }, + { KEY_EN_7, 0x29 }, + { KEY_EN_Y, 0x25 }, + { KEY_EN_H, 0x26 }, + { KEY_EN_N, 0x27 }, + + { KEY_EN_F6, 0x2F }, + { KEY_EN_8, 0x30 }, + { KEY_EN_U, 0x3D }, + { KEY_EN_J, 0x2B }, + { KEY_EN_M, 0x2C }, + + { KEY_EN_F7, 0x35 }, + { KEY_EN_9, 0x36 }, + { KEY_EN_I, 0x31 }, + { KEY_EN_K, 0x32 }, + { KEY_EN_COMMA, 0x33 }, + { KEY_JP_HENKAN, 0x2D }, + + { KEY_EN_F8, 0x3B }, + { KEY_EN_0, 0x3C }, + { KEY_EN_O, 0x37 }, + { KEY_EN_L, 0x38 }, + { KEY_EN_PERIOD, 0x39 }, + { KEY_JP_KANA, 0x34 }, + + { KEY_EN_F9, 0x41 }, + { KEY_EN_MINUS, 0x42 }, + { KEY_EN_P, 0x2A }, + { KEY_EN_SEMICOLON, 0x3E }, + { KEY_EN_FORWARD_SLASH, 0x3F }, + { KEY_EN_RIGHT_FUNCTION, 0x40 }, + + { KEY_EN_F10, 0x47 }, + { KEY_JP_CHEVRON, 0x48 }, + { KEY_JP_AT, 0x43 }, + { KEY_JP_COLON, 0x44 }, + { KEY_EN_BACK_SLASH, 0x45 }, + { KEY_EN_MENU, 0x46 }, + + { KEY_EN_F11, 0x4D }, + { KEY_JP_YEN, 0x4E }, + { KEY_EN_LEFT_BRACKET, 0x49 }, + { KEY_EN_RIGHT_BRACKET, 0x4A }, + + { KEY_EN_F12, 0x4F }, + { KEY_EN_BACKSPACE, 0x50 }, + { KEY_EN_ISO_ENTER, 0x52 }, + { KEY_EN_RIGHT_SHIFT, 0x4B }, + { KEY_EN_RIGHT_CONTROL, 0x4C }, + + { KEY_EN_PRINT_SCREEN, 0x53 }, + { KEY_EN_INSERT, 0x54 }, + { KEY_EN_DELETE, 0x55 }, + { KEY_EN_LEFT_ARROW, 0x56 }, + + { KEY_EN_SCROLL_LOCK, 0x57 }, + { KEY_EN_HOME, 0x58 }, + { KEY_EN_END, 0x59 }, + { KEY_EN_UP_ARROW, 0x5A }, + { KEY_EN_DOWN_ARROW, 0x5B }, + + { KEY_EN_PAUSE_BREAK, 0x5C }, + { KEY_EN_PAGE_UP, 0x5D }, + { KEY_EN_PAGE_DOWN, 0x5E }, + { KEY_EN_RIGHT_ARROW, 0x5F }, + + { KEY_EN_NUMPAD_LOCK, 0x60 }, + { KEY_EN_NUMPAD_7, 0x61 }, + { KEY_EN_NUMPAD_4, 0x62 }, + { KEY_EN_NUMPAD_1, 0x6C }, + { KEY_EN_NUMPAD_0, 0x64 }, + + { KEY_EN_NUMPAD_DIVIDE, 0x65 }, + { KEY_EN_NUMPAD_8, 0x66 }, + { KEY_EN_NUMPAD_5, 0x67 }, + { KEY_EN_NUMPAD_2, 0x68 }, + + { KEY_EN_NUMPAD_TIMES, 0x69 }, + { KEY_EN_NUMPAD_9, 0x6A }, + { KEY_EN_NUMPAD_6, 0x6B }, + { KEY_EN_NUMPAD_3, 0x63 }, + { KEY_EN_NUMPAD_PERIOD, 0x6D }, + + { KEY_EN_NUMPAD_MINUS, 0x6E }, + { KEY_EN_NUMPAD_PLUS, 0x6F }, + { KEY_EN_NUMPAD_ENTER, 0x71 }, + + { KEY_EN_MEDIA_PREVIOUS, 0x72 }, + { KEY_EN_MEDIA_PLAY_PAUSE, 0x73 }, + { KEY_EN_MEDIA_NEXT, 0x74 }, + + /*-------------------------------------------------------------*\ + | F-Key Indicators (secondary LEDs) | + \*-------------------------------------------------------------*/ + { "Key: F1 LED 2", 0x89 }, + { "Key: F2 LED 2", 0x7B }, + { "Key: F3 LED 2", 0x81 }, + { "Key: F4 LED 2", 0x87 }, + { "Key: F5 LED 2", 0x8D }, + { "Key: F6 LED 2", 0x76 }, + { "Key: F7 LED 2", 0x7C }, + { "Key: F8 LED 2", 0x82 }, + { "Key: F9 LED 2", 0x88 }, + { "Key: F10 LED 2", 0x8E }, + { "Key: F11 LED 2", 0x7A }, + { "Key: F12 LED 2", 0x80 }, + { "Key: Print Screen LED 2", 0x86 }, + { "Key: Scroll Lock LED 2", 0x8C }, + { "Key: Pause/Break LED 2", 0x92 }, + + /*-------------------------------------------------------------*\ + | Nav Cluster Indicators (secondary LEDs) | + \*-------------------------------------------------------------*/ + { "Key: Insert LED 2", 0x75 }, + { "Key: Home LED 2", 0x7E }, + { "Key: Page Up LED 2", 0x84 }, + + /*-------------------------------------------------------------*\ + | Num Lock Indicator (secondary LED) | + \*-------------------------------------------------------------*/ + { "Key: Num Lock LED 2", 0x8B }, + + /*-------------------------------------------------------------*\ + | Nav Cluster Indicators 2 (secondary LEDs) | + \*-------------------------------------------------------------*/ + { "Key: Delete LED 2", 0x78 }, + { "Key: End LED 2", 0x90 }, + { "Key: Page Down LED 2", 0x8A }, + + /*-------------------------------------------------------------*\ + | Caps Lock Indicator (secondary LED) | + \*-------------------------------------------------------------*/ + { "Key: Caps Lock LED 2", 0x7D }, + + /*-------------------------------------------------------------*\ + | Win Key Indicator (secondary LED) | + \*-------------------------------------------------------------*/ + { "Key: Left Windows LED 2", 0x83 }, + + /*-------------------------------------------------------------*\ + | Palm Rest LEDs (order approximate - needs verification) | \*-------------------------------------------------------------*/ { "Palm Rest LED 1", 0x96 }, { "Palm Rest LED 2", 0xAD },