// Mad Catz R.A.T. 8+ (USB 12CF:0C05), no vendor software needed. // Live colours use a firmware command the vendor app never sends (found by disassembling // firmware v18): [12, 0xC4, 3, 4, 1, zone, R, G, B] writes straight to the LED driver, // with no storage writes, so it can run at full frame rate. The first such command pauses // the mouse's own effect; [12, 0xC4, 3, 3, 3] hands the LEDs back to it. // Profile commands (from the vendor app, RAT8P.dll) are only used for "Save to mouse". export function Name() { return "Mad Catz R.A.T. 8+"; } export function VendorId() { return 0x12CF; } export function ProductId() { return 0x0C05; } export function Publisher() { return "Custom"; } export function Size() { return [3, 3]; } export function DefaultPosition() { return [240, 120]; } export function DefaultScale() { return 8.0; } export function DeviceType() { return "mouse"; } export function Validate(endpoint) { return endpoint.interface === 1; } export function ImageUrl() { return "https://assets.signalrgb.com/devices/default/misc/usb-drive-render.png"; } /* global LightingMode:readonly forcedColor:readonly shutdownMode:readonly shutdownColor:readonly */ export function ControllableParameters() { return [ {property:"LightingMode", group:"lighting", label:"Lighting Mode", description:"Canvas follows the active effect, Forced uses one fixed colour", type:"combobox", values:["Canvas", "Forced"], default:"Canvas"}, {property:"forcedColor", group:"lighting", label:"Forced Color", min:"0", max:"360", type:"color", default:"#009bde"}, {property:"shutdownMode", group:"lighting", label:"On Exit", description:"What the mouse shows when SignalRGB closes. 'Save last colours' stores them in the active profile (one storage write), so they survive replugging", type:"combobox", values:["Mouse's own lighting", "Shutdown Color", "Save last colours to mouse"], default:"Mouse's own lighting"}, {property:"shutdownColor", group:"lighting", label:"Shutdown Color", min:"0", max:"360", type:"color", default:"#000000"}, ]; } // Zones: 0 = under the scroll wheel, 1 = palm logo, 2 = DPI button const vLedNames = ["Scroll Wheel", "DPI Button", "Palm Logo"]; const vLedPositions = [[1, 0], [1, 1], [1, 2]]; const vZoneForLed = [0, 2, 1]; const FEAT_LEN = 2053; const PROFILE_LEN = 733; const LED_OFFSET = 160; const LED_ZONE_LEN = 191; const SLOT_CHECK_MS = 3000; const RESEND_MS = 1000; // resend unchanged colours this often, in case the mouse reset them let sent = [null, null, null]; let lastSend = 0; let slot = -1; let lastSlotCheck = 0; export function LedNames() { return vLedNames; } export function LedPositions() { return vLedPositions; } export function Initialize() { device.set_endpoint(1, 0x004B, 0x0008, 0x0003); device.setName("Mad Catz R.A.T. 8+"); device.setControllableLeds(vLedNames, vLedPositions); slot = readActiveSlot(); } export function Render() { const now = Date.now(); // A profile switch on the mouse reloads its own lighting; release and retake // control so the firmware pauses its effect again if (now - lastSlotCheck > SLOT_CHECK_MS) { lastSlotCheck = now; const s = readActiveSlot(); if (s >= 0 && s !== slot) { slot = s; releaseLeds(); sent = [null, null, null]; } } const colors = currentColors(); const resend = now - lastSend > RESEND_MS; for (let z = 0; z < 3; z++) { if (resend || !sameColor(colors[z], sent[z])) { setZone(z, colors[z]); } } if (resend) { lastSend = now; } } export function Shutdown(SystemSuspending) { if (shutdownMode === "Shutdown Color") { const c = hexToRgb(shutdownColor); for (let z = 0; z < 3; z++) { setZone(z, c); } return; } if (shutdownMode === "Save last colours to mouse" && sent[0]) { saveToProfile(sent); } releaseLeds(); } function setZone(zone, c) { device.send_report([12, 0xC4, 3, 4, 1, zone, c[0], c[1], c[2]], FEAT_LEN); sent[zone] = c; } function releaseLeds() { device.send_report([12, 0xC4, 3, 3, 3], FEAT_LEN); } function currentColors() { const out = [null, null, null]; for (let i = 0; i < vLedPositions.length; i++) { const [x, y] = vLedPositions[i]; out[vZoneForLed[i]] = LightingMode === "Forced" ? hexToRgb(forcedColor) : device.color(x, y); } return out; } function sameColor(a, b) { return !!a && !!b && a[0] === b[0] && a[1] === b[1] && a[2] === b[2]; } function readActiveSlot() { device.send_report([12, 0xC4, 22], FEAT_LEN); for (let i = 0; i < 10; i++) { device.pause(10); const r = device.get_report([12], FEAT_LEN); if (r[0] === 0xB0 && r[1] === 0xC6) { return r[2]; } } return -1; } // One profile write: read the active profile, put static colours in, write it back function saveToProfile(colors) { const s = readActiveSlot(); if (s < 0) { return; } device.send_report([12, 0xC4, 12, s], FEAT_LEN); let profile = null; for (let i = 0; i < 10 && !profile; i++) { device.pause(50); const r = device.get_report([5], FEAT_LEN); if (r[0] === 5 && r[1] === 0xB0 && r[2] === s && r[3] !== 0 && r[3] === checksum(r, 4, 736)) { profile = r.slice(4, 4 + PROFILE_LEN); } } if (!profile) { device.log(`R.A.T. 8+: could not read profile ${s}, colours not saved`); return; } for (let z = 0; z < 3; z++) { const o = LED_OFFSET + z * LED_ZONE_LEN; profile[o] = 1; // static profile[o + 1] = 255; // brightness profile[o + 2] = colors[z][0]; profile[o + 3] = colors[z][1]; profile[o + 4] = colors[z][2]; } device.send_report([5, 0, s, checksum(profile, 0, PROFILE_LEN)].concat(profile), FEAT_LEN); for (let i = 0; i < 25; i++) { device.pause(20); const r = device.get_report([12], FEAT_LEN); if (r[0] === 0xB0 && r[1] === 5 && r[2] === s && r[3] === r[4]) { device.send_report([12, 0xC4, 0], FEAT_LEN); // reload return; } } device.log("R.A.T. 8+: mouse did not confirm the profile write"); } function checksum(data, start, length) { let sum = 0; for (let i = start; i < start + length; i++) { sum = (sum + data[i]) & 0xFF; } return (256 - sum) & 0xFF; } function hexToRgb(hex) { const r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return [parseInt(r[1], 16), parseInt(r[2], 16), parseInt(r[3], 16)]; }