Josiahiscool73

v10.2 aim assist

Apr 5th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.50 KB | None | 0 0
  1. // == Xbox Cloud Gaming Keyboard/Mouse to Controller Mapper v10.2 ==
  2. // == !! EXPERIMENTAL - Fixed Weapon Switching & Weapon-Specific Anti-Recoil !! ==
  3. // == Fixes issue where 2/3/4 might not switch weapons. Ensures button press happens THEN recoil profile updates. ==
  4. // == WARNING: Requires tuning ALL Anti-Recoil values. Micro-movements speculative. HIGH BAN RISK. ==
  5. // == >>> VERIFY D-PAD MAPPINGS ('1'-'4' in keyMap) <<< HARD REFRESH first! ==
  6.  
  7. (function() {
  8. console.log("Initializing Experimental KBM Mapper v10.2 (Fix Weapon Switch & Wep AR)...");
  9. console.warn(">>> EXTREME WARNING: WEAPON-SPECIFIC ANTI-RECOIL & MICRO-MOVEMENTS ACTIVE. HIGH BAN RISK. TUNE VALUES. VERIFY D-PAD MAPS. HARD REFRESH FIRST! <<<");
  10.  
  11. // --- Configuration --- (Same as 10.1)
  12. const MOUSE_SENSITIVITY_X = 0.0025;
  13. const MOUSE_SENSITIVITY_Y = 0.0025;
  14. const ADS_SENSITIVITY_MULTIPLIER = 0.75;
  15. const MOUSE_DECAY = 0.85;
  16. const STATE_POLLING_RATE_MS = 16;
  17. const CONNECTION_DISPATCH_RATE_MS = 100;
  18. const AXIS_DEADZONE = 0.05;
  19. const FIRE_BUTTON_INDEX = 7;
  20. const ENABLE_ANTI_RECOIL = true;
  21. const ADS_BUTTON_INDEX = 6;
  22. const ENABLE_MICRO_MOVEMENTS = true;
  23. const MICRO_MOVEMENT_RADIUS = 0.02;
  24. const MICRO_MOVEMENT_SPEED = 0.1;
  25.  
  26. // --- WEAPON-SPECIFIC Anti-Recoil Strengths (TUNE THESE!) --- (Same as 10.1)
  27. const ANTI_RECOIL_DEFAULT = 0.015;
  28. const ANTI_RECOIL_PICKAXE = 0.0; // Slot '1'
  29. const ANTI_RECOIL_SHOTGUN = 0.003; // Slot '2'
  30. const ANTI_RECOIL_AR = 0.015; // Slot '3'
  31. const ANTI_RECOIL_SMG = 0.025; // Slot '4'
  32.  
  33. // --- Key Mapping ---
  34. // !!! CRITICAL: VERIFY these 'i' values match your game's D-Pad bindings for weapon slots 1-4 !!!
  35. // Standard D-Pad: Up=12, Down=13, Left=14, Right=15. These are JUST EXAMPLES.
  36. const keyMap = {
  37. // Movement & Core
  38. 'w': { t: 'a', a: 1, v: -1 }, 'a': { t: 'a', a: 0, v: -1 }, 's': { t: 'a', a: 1, v: 1 }, 'd': { t: 'a', a: 0, v: 1 },
  39. ' ': { t: 'b', i: 0 }, 'shift': { t: 'b', i: 10 }, 'control': { t: 'b', i: 11 },
  40. 'r': { t: 'b', i: 2 }, 'e': { t: 'b', i: 3 }, 'escape': { t: 'b', i: 9 }, 'tab': { t: 'b', i: 8 },
  41. // Combat
  42. 'q': { t: 'b', i: ADS_BUTTON_INDEX }, // ADS (LT)
  43. 'z': { t: 'b', i: FIRE_BUTTON_INDEX }, // Fire (RT)
  44. // Build (Examples)
  45. 'f': { t: 'b', i: 5 }, 'c': { t: 'b', i: 4 }, 'g': { t: 'b', i: 1 },
  46. // Weapon Slots (Map to D-Pad buttons AND set anti-recoil profile)
  47. '1': { t: 'b', i: 15 }, // Weapon Slot 1 (D-Pad Right?) -> Pickaxe Recoil --- VERIFY i:15 ---
  48. '2': { t: 'b', i: 12 }, // Weapon Slot 2 (D-Pad Up?) -> Shotgun Recoil --- VERIFY i:12 ---
  49. '3': { t: 'b', i: 14 }, // Weapon Slot 3 (D-Pad Left?) -> AR Recoil --- VERIFY i:14 ---
  50. '4': { t: 'b', i: 13 }, // Weapon Slot 4 (D-Pad Down?) -> SMG Recoil --- VERIFY i:13 ---
  51. };
  52. const mouseMap = { /* ... Same ... */
  53. 0: { t: 'b', i: FIRE_BUTTON_INDEX }, 2: { t: 'b', i: ADS_BUTTON_INDEX }
  54. };
  55.  
  56. // --- State Tracking --- (Same as 10.1)
  57. const controllerState = { /* ... Same ... */
  58. axes: [0.0, 0.0, 0.0, 0.0], buttons: Array(17).fill(false).map((_, i) => ({ pressed: false, touched: false, value: 0.0, index: i })),
  59. axisKeyPresses: { 0: { neg: false, pos: false }, 1: { neg: false, pos: false } }, mouseDeltaX: 0, mouseDeltaY: 0, isConnected: true,
  60. timestamp: performance.now(), microMovementAngle: 0, currentAntiRecoilStrength: ANTI_RECOIL_DEFAULT
  61. };
  62. let pointerLocked = false; /* ... Same ... */ let stateIntervalId = null; let connectionIntervalId = null; let gameAreaElement = null;
  63.  
  64. // --- Gamepad Object Construction --- (Same as 10.1)
  65. function createGamepadObject() { /* ... Same ... */
  66. const axes = controllerState.axes.map(val => Math.abs(val) < AXIS_DEADZONE ? 0.0 : val);
  67. return { axes: axes, buttons: controllerState.buttons, connected: controllerState.isConnected, id: "KBM Emulated Xbox Controller v10.2 (Wep AR Fix)", index: 0, mapping: "standard", timestamp: controllerState.timestamp };
  68. }
  69.  
  70. // --- Core Simulation Function (Updates State) --- (Same as 10.1)
  71. function updateAndSimulateGamepad() { /* ... Same logic as 10.1 ... */
  72. let currentSensX = MOUSE_SENSITIVITY_X; let currentSensY = MOUSE_SENSITIVITY_Y; const isADS = controllerState.buttons[ADS_BUTTON_INDEX].pressed; const isFiring = controllerState.buttons[FIRE_BUTTON_INDEX].pressed; if (isADS) { currentSensX *= ADS_SENSITIVITY_MULTIPLIER; currentSensY *= ADS_SENSITIVITY_MULTIPLIER; } let targetRX = controllerState.axes[2]; let targetRY = controllerState.axes[3]; if (pointerLocked) { targetRX *= MOUSE_DECAY; targetRY *= MOUSE_DECAY; targetRX += controllerState.mouseDeltaX * currentSensX; targetRY += controllerState.mouseDeltaY * currentSensY; if (ENABLE_MICRO_MOVEMENTS && isADS) { const angle = controllerState.microMovementAngle; targetRX += Math.cos(angle) * MICRO_MOVEMENT_RADIUS; targetRY += Math.sin(angle) * MICRO_MOVEMENT_RADIUS; controllerState.microMovementAngle = (angle + MICRO_MOVEMENT_SPEED) % (2 * Math.PI); } if (ENABLE_ANTI_RECOIL && isFiring) { targetRY += controllerState.currentAntiRecoilStrength; } controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0; } else { targetRX = 0; targetRY = 0; controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0; controllerState.microMovementAngle = 0; } controllerState.axes[0] = Math.max(-1, Math.min(1, controllerState.axes[0])); controllerState.axes[1] = Math.max(-1, Math.min(1, controllerState.axes[1])); controllerState.axes[2] = Math.max(-1, Math.min(1, targetRX)); controllerState.axes[3] = Math.max(-1, Math.min(1, targetRY)); controllerState.timestamp = performance.now(); navigator.getGamepads = function() { return [createGamepadObject(), null, null, null]; };
  73. }
  74.  
  75. // --- Event Handlers ---
  76.  
  77. // *** REVISED handleKeyDown ***
  78. function handleKeyDown(event) {
  79. const key = event.key.toLowerCase();
  80. const mappedKey = (key === 'controlleft' || key === 'controlright') ? 'control' : key;
  81. const mapping = keyMap[mappedKey]; // Check mapping FIRST
  82.  
  83. if (!mapping) return; // Exit if the key isn't mapped at all
  84.  
  85. // Key is mapped, proceed with simulation
  86. event.preventDefault();
  87. event.stopPropagation();
  88.  
  89. // 1. Simulate the primary button press or axis move based on keyMap
  90. if (mapping.t === 'b') { // Button press
  91. const button = controllerState.buttons[mapping.i];
  92. if (!button.pressed) {
  93. button.pressed = true;
  94. button.touched = true;
  95. button.value = 1.0;
  96. // Add specific log for weapon keys to confirm button press attempt
  97. if (['1', '2', '3', '4'].includes(mappedKey)) {
  98. console.log(`Attempting button press for weapon key '${mappedKey}': Button index ${mapping.i}`);
  99. }
  100. }
  101. } else if (mapping.t === 'a') { // Axis movement
  102. const axisState = controllerState.axisKeyPresses[mapping.a];
  103. if (mapping.v < 0) axisState.neg = true; else axisState.pos = true;
  104. if (axisState.neg && axisState.pos) { controllerState.axes[mapping.a] = 0; }
  105. else { controllerState.axes[mapping.a] = axisState.neg ? -1 : 1; }
  106. }
  107.  
  108. // 2. Check if this key ALSO needs to update the anti-recoil profile
  109. let profileName = "";
  110. let newRecoilStrength = controllerState.currentAntiRecoilStrength; // Keep current if not changed
  111. switch (mappedKey) {
  112. case '1': newRecoilStrength = ANTI_RECOIL_PICKAXE; profileName = "Pickaxe"; break;
  113. case '2': newRecoilStrength = ANTI_RECOIL_SHOTGUN; profileName = "Shotgun"; break;
  114. case '3': newRecoilStrength = ANTI_RECOIL_AR; profileName = "AR"; break;
  115. case '4': newRecoilStrength = ANTI_RECOIL_SMG; profileName = "SMG"; break;
  116. }
  117.  
  118. // Update and log only if the strength actually changed
  119. if (newRecoilStrength !== controllerState.currentAntiRecoilStrength) {
  120. controllerState.currentAntiRecoilStrength = newRecoilStrength;
  121. console.log(`Anti-Recoil Profile set to ${profileName} (${controllerState.currentAntiRecoilStrength})`);
  122. }
  123. }
  124.  
  125. // handleKeyUp remains the same - releases the button/axis correctly
  126. function handleKeyUp(event) { /* ... Same as 10.1 ... */ const key = event.key.toLowerCase(); const mappedKey = (key === 'controlleft' || key === 'controlright') ? 'control' : key; const mapping = keyMap[mappedKey]; if (!mapping) return; event.preventDefault(); event.stopPropagation(); if (mapping.t === 'b') { const button = controllerState.buttons[mapping.i]; if (button.pressed) { button.pressed = false; button.touched = false; button.value = 0.0; } } else if (mapping.t === 'a') { const axisState = controllerState.axisKeyPresses[mapping.a]; if (mapping.v < 0) axisState.neg = false; else axisState.pos = false; if (axisState.neg) { controllerState.axes[mapping.a] = -1; } else if (axisState.pos) { controllerState.axes[mapping.a] = 1; } else { controllerState.axes[mapping.a] = 0; } } }
  127. // Other handlers remain the same
  128. function handleMouseDown(event) { /* ... Same ... */ const mapping = mouseMap[event.button]; if (!mapping || (!pointerLocked && event.target !== gameAreaElement)) return; event.preventDefault(); event.stopPropagation(); if (mapping.t === 'b') { const button = controllerState.buttons[mapping.i]; if (!button.pressed) { button.pressed = true; button.touched = true; button.value = 1.0; } } }
  129. function handleMouseUp(event) { /* ... Same ... */ const mapping = mouseMap[event.button]; if (!mapping) return; event.preventDefault(); event.stopPropagation(); if (mapping.t === 'b') { const button = controllerState.buttons[mapping.i]; if (button.pressed) { button.pressed = false; button.touched = false; button.value = 0.0; } } }
  130. function handleMouseMove(event) { /* ... Same ... */ if (!pointerLocked) return; event.preventDefault(); event.stopPropagation(); const movementX = event.movementX || 0; const movementY = event.movementY || 0; controllerState.mouseDeltaX += movementX; controllerState.mouseDeltaY += movementY; }
  131. function handlePointerLockChange() { /* ... Same ... */ const lockedElement = document.pointerLockElement; if (lockedElement === gameAreaElement) { console.log('%cPointer Locked', 'color: lightgreen; font-weight: bold;'); pointerLocked = true; } else { console.warn(`Pointer Unlocked. Was locked to: ${gameAreaElement?.id || gameAreaElement?.tagName}`); pointerLocked = false; controllerState.axes[2] = 0; controllerState.axes[3] = 0; controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0; controllerState.microMovementAngle = 0; Object.values(mouseMap).forEach(mapping => { if (mapping.t === 'b') { const button = controllerState.buttons[mapping.i]; button.pressed = false; button.touched = false; button.value = 0.0; } }); } }
  132. function requestPointerLock() { /* ... Same ... */ if (!gameAreaElement) { console.error("Cannot request pointer lock: Game area element not found."); return; } if (document.pointerLockElement !== gameAreaElement) { console.log("Requesting pointer lock on:", gameAreaElement); gameAreaElement.requestPointerLock().catch(e => { console.error("Pointer lock request failed:", e); }); } }
  133. function dispatchConnectionEvent() { /* ... Same ... */ try { const gamepad = createGamepadObject(); const gamepadConnectedEvent = new CustomEvent('gamepadconnected', { detail: { gamepad: gamepad } }); gamepadConnectedEvent.gamepad = gamepad; window.dispatchEvent(gamepadConnectedEvent); } catch (e) { console.error("Error dispatching periodic connection event:", e); } }
  134.  
  135. // --- Initialization --- (Same as 10.1)
  136. console.log("Attempting to find game area element..."); gameAreaElement = document.getElementById('game-stream') || document.querySelector('video[playsinline]') || document.querySelector('video') || document.body; if (!gameAreaElement || gameAreaElement === document.body) { console.warn("Could not find specific game stream element, using document.body."); gameAreaElement = document.body; } else { console.log("Found game area element:", gameAreaElement); } navigator.getGamepads = function() { return [createGamepadObject(), null, null, null]; }; console.log("Initial navigator.getGamepads override set."); window.addEventListener('keydown', handleKeyDown, { capture: true }); window.addEventListener('keyup', handleKeyUp, { capture: true }); const mouseEventTarget = gameAreaElement; mouseEventTarget.addEventListener('mousemove', handleMouseMove, { capture: true }); mouseEventTarget.addEventListener('mousedown', handleMouseDown, { capture: true }); mouseEventTarget.addEventListener('mouseup', handleMouseUp, { capture: true }); document.addEventListener('pointerlockchange', handlePointerLockChange, false); if (gameAreaElement && gameAreaElement !== document.body) { gameAreaElement.addEventListener('click', requestPointerLock); console.log(">>> CLICK THE GAME AREA TO ENABLE MOUSE AIM <<<"); } else { console.warn("Game area is body or not found. Click anywhere on the page body to attempt pointer lock."); document.body.addEventListener('click', requestPointerLock); } try { dispatchConnectionEvent(); console.log("Dispatched initial gamepadconnected event."); } catch (e) { console.error("Error dispatching initial connection event:", e); } stateIntervalId = setInterval(updateAndSimulateGamepad, STATE_POLLING_RATE_MS); connectionIntervalId = setInterval(dispatchConnectionEvent, CONNECTION_DISPATCH_RATE_MS); console.log(`%cKBM Mapper V10.2 Active! State polling ID: ${stateIntervalId}, Connection dispatch ID: ${connectionIntervalId}.`, "color: cyan;"); if (ENABLE_ANTI_RECOIL) console.log(`Weapon-Specific Anti-Recoil ACTIVE. Initial/Default: ${controllerState.currentAntiRecoilStrength}. Press 1/2/3/4 to change.`); else console.log("Anti-Recoil DISABLED."); if (ENABLE_MICRO_MOVEMENTS) console.log(`Micro-Movements ACTIVE when ADS. Radius: ${MICRO_MOVEMENT_RADIUS}, Speed: ${MICRO_MOVEMENT_SPEED}.`); else console.log("Micro-Movements DISABLED."); console.warn(">>> REMEMBER: HIGH BAN RISK with these features enabled. Tune values! VERIFY D-PAD MAPS (keys 1-4)! Use responsibly! <<<"); console.log("To disable, refresh page or type: stopKbmMapper();");
  137.  
  138. // --- Cleanup Function --- (Same as 10.1)
  139. window.stopKbmMapper = function() { /* ... Same as 10.1 ... */ console.log("Stopping KBM Mapper V10.2..."); if (stateIntervalId) clearInterval(stateIntervalId); if (connectionIntervalId) clearInterval(connectionIntervalId); stateIntervalId = null; connectionIntervalId = null; window.removeEventListener('keydown', handleKeyDown, { capture: true }); window.removeEventListener('keyup', handleKeyUp, { capture: true }); mouseEventTarget.removeEventListener('mousemove', handleMouseMove, { capture: true }); mouseEventTarget.removeEventListener('mousedown', handleMouseDown, { capture: true }); mouseEventTarget.removeEventListener('mouseup', handleMouseUp, { capture: true }); document.removeEventListener('pointerlockchange', handlePointerLockChange, false); if (gameAreaElement) gameAreaElement.removeEventListener('click', requestPointerLock); if (document.body && gameAreaElement === document.body) document.body.removeEventListener('click', requestPointerLock); if (document.pointerLockElement) { document.exitPointerLock(); } navigator.getGamepads = function() { return [null, null, null, null]; }; console.log("KBM Mapper stopped. Event listeners removed. Gamepad override disabled. Refresh recommended."); };
  140.  
  141. })(); // End of IIFE
Add Comment
Please, Sign In to add comment