Josiahiscool73

10.1v aim assist for xcloud(bad)

Apr 4th, 2025 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.15 KB | None | 0 0
  1. // == Xbox Cloud Gaming Keyboard/Mouse to Controller Mapper v10.1 ==
  2. // == !! EXPERIMENTAL - Weapon-Specific Anti-Recoil Strength (Corrected Keys) !! ==
  3. // == Adds simulated ADS Sens, Micro-Movements, and Anti-Recoil strength based on last weapon key (1-Pickaxe, 2-Shotgun, 3-AR, 4-SMG) pressed ==
  4. // == WARNING: Requires tuning ALL Anti-Recoil values. Micro-movements speculative. ==
  5. // == ADsing now adds a more sticky aim assist movement and is very good at predicting despite not knowing where people are ==
  6.  
  7. (function() {
  8. console.log("Initializing Experimental KBM Mapper v10.1 (Weapon-Specific Anti-Recoil - Corrected Keys)...");
  9. console.warn(">>> EXTREME WARNING: WEAPON-SPECIFIC ANTI-RECOIL & MICRO-MOVEMENTS ACTIVE. HIGH BAN RISK. TUNE VALUES. HARD REFRESH FIRST! <<<");
  10.  
  11. // --- Configuration ---
  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.  
  20. // --- Anti-Recoil Configuration ---
  21. const FIRE_BUTTON_INDEX = 7; // RT (Right Trigger)
  22. const ENABLE_ANTI_RECOIL = true; // Set to false to disable anti-recoil entirely
  23.  
  24. // --- WEAPON-SPECIFIC Anti-Recoil Strengths (TUNE THESE!) ---
  25. // Positive = Pull Down. Higher value = stronger pull.
  26. const ANTI_RECOIL_DEFAULT = 0.015; // Fallback value if no weapon key pressed yet
  27. const ANTI_RECOIL_PICKAXE = 0.0; // Slot '1' - Pickaxe (Likely no recoil)
  28. const ANTI_RECOIL_SHOTGUN = 0.003; // Slot '2' - Shotgun (Minimal recoil comp)
  29. const ANTI_RECOIL_AR = 0.015; // Slot '3' - AR (Standard recoil comp)
  30. const ANTI_RECOIL_SMG = 0.025; // Slot '4' - SMG (Stronger recoil comp)
  31.  
  32. // --- Micro-Movement Configuration ---
  33. const ADS_BUTTON_INDEX = 6; // LT (Left Trigger)
  34. const ENABLE_MICRO_MOVEMENTS = true; // Set to false to disable micro-movements
  35. const MICRO_MOVEMENT_RADIUS = 0.02; // Tune this! (0.01 - 0.05)
  36. const MICRO_MOVEMENT_SPEED = 0.1; // Tune this! (0.05 - 0.3)
  37.  
  38. // --- Key Mapping ---
  39. // Assuming 1, 2, 3, 4 correspond to D-Pad. ADJUST `i` IF NEEDED!
  40. // Standard D-Pad: Up=12, Down=13, Left=14, Right=15
  41. const keyMap = {
  42. // Movement & Core
  43. '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 },
  44. ' ': { t: 'b', i: 0 }, 'shift': { t: 'b', i: 10 }, 'control': { t: 'b', i: 11 },
  45. 'r': { t: 'b', i: 2 }, 'e': { t: 'b', i: 3 }, 'escape': { t: 'b', i: 9 }, 'tab': { t: 'b', i: 8 },
  46. // Combat
  47. 'q': { t: 'b', i: ADS_BUTTON_INDEX }, // ADS (LT)
  48. 'z': { t: 'b', i: FIRE_BUTTON_INDEX }, // Fire (RT)
  49. // Build (Examples)
  50. 'f': { t: 'b', i: 5 }, 'c': { t: 'b', i: 4 }, 'g': { t: 'b', i: 1 },
  51. // Weapon Slots (Also set anti-recoil profile) - USING DPAD MAPPINGS AS EXAMPLE
  52. '1': { t: 'b', i: 15 }, // Weapon Slot 1 (D-Pad Right?) -> Pickaxe Recoil
  53. '2': { t: 'b', i: 12 }, // Weapon Slot 2 (D-Pad Up?) -> Shotgun Recoil
  54. '3': { t: 'b', i: 14 }, // Weapon Slot 3 (D-Pad Left?) -> AR Recoil
  55. '4': { t: 'b', i: 13 }, // Weapon Slot 4 (D-Pad Down?) -> SMG Recoil
  56. // Add '5' etc. if needed, mapping them to buttons and potentially new recoil constants
  57. };
  58. const mouseMap = {
  59. 0: { t: 'b', i: FIRE_BUTTON_INDEX }, // Left Mouse -> Fire (RT)
  60. 2: { t: 'b', i: ADS_BUTTON_INDEX } // Right Mouse -> ADS (LT)
  61. };
  62.  
  63.  
  64. // --- State Tracking ---
  65. const controllerState = {
  66. axes: [0.0, 0.0, 0.0, 0.0],
  67. buttons: Array(17).fill(false).map((_, i) => ({ pressed: false, touched: false, value: 0.0, index: i })),
  68. axisKeyPresses: { 0: { neg: false, pos: false }, 1: { neg: false, pos: false } },
  69. mouseDeltaX: 0, mouseDeltaY: 0, isConnected: true, timestamp: performance.now(),
  70. microMovementAngle: 0,
  71. currentAntiRecoilStrength: ANTI_RECOIL_DEFAULT // Initialize with default value
  72. };
  73. let pointerLocked = false;
  74. let stateIntervalId = null;
  75. let connectionIntervalId = null;
  76. let gameAreaElement = null;
  77.  
  78. // --- Gamepad Object Construction --- (Same as V10)
  79. function createGamepadObject() { /* ... Same as V10 ... */
  80. const axes = controllerState.axes.map(val => Math.abs(val) < AXIS_DEADZONE ? 0.0 : val);
  81. return {
  82. axes: axes, buttons: controllerState.buttons, connected: controllerState.isConnected,
  83. id: "KBM Emulated Xbox Controller v10.1 (Wep AR)", index: 0, mapping: "standard", timestamp: controllerState.timestamp,
  84. };
  85. }
  86.  
  87. // --- Core Simulation Function (Updates State) --- (Same as V10)
  88. function updateAndSimulateGamepad() { /* ... Same logic as V10, uses controllerState.currentAntiRecoilStrength ... */
  89. let currentSensX = MOUSE_SENSITIVITY_X; let currentSensY = MOUSE_SENSITIVITY_Y;
  90. const isADS = controllerState.buttons[ADS_BUTTON_INDEX].pressed; const isFiring = controllerState.buttons[FIRE_BUTTON_INDEX].pressed;
  91. if (isADS) { currentSensX *= ADS_SENSITIVITY_MULTIPLIER; currentSensY *= ADS_SENSITIVITY_MULTIPLIER; }
  92. let targetRX = controllerState.axes[2]; let targetRY = controllerState.axes[3];
  93. if (pointerLocked) {
  94. targetRX *= MOUSE_DECAY; targetRY *= MOUSE_DECAY;
  95. targetRX += controllerState.mouseDeltaX * currentSensX; targetRY += controllerState.mouseDeltaY * currentSensY;
  96. 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); }
  97. if (ENABLE_ANTI_RECOIL && isFiring) { targetRY += controllerState.currentAntiRecoilStrength; } // Uses the dynamic strength
  98. controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0;
  99. } else { targetRX = 0; targetRY = 0; controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0; controllerState.microMovementAngle = 0; }
  100. controllerState.axes[0] = Math.max(-1, Math.min(1, controllerState.axes[0])); controllerState.axes[1] = Math.max(-1, Math.min(1, controllerState.axes[1]));
  101. controllerState.axes[2] = Math.max(-1, Math.min(1, targetRX)); controllerState.axes[3] = Math.max(-1, Math.min(1, targetRY));
  102. controllerState.timestamp = performance.now(); navigator.getGamepads = function() { return [createGamepadObject(), null, null, null]; };
  103. }
  104.  
  105. // --- Event Handlers ---
  106.  
  107. function handleKeyDown(event) {
  108. const key = event.key.toLowerCase();
  109. const mappedKey = (key === 'controlleft' || key === 'controlright') ? 'control' : key;
  110. const mapping = keyMap[mappedKey];
  111.  
  112. // --- Handle Weapon Select & Set Recoil Profile (Corrected) ---
  113. let weaponChanged = false;
  114. let profileName = "Default";
  115. switch (mappedKey) {
  116. case '1':
  117. controllerState.currentAntiRecoilStrength = ANTI_RECOIL_PICKAXE;
  118. profileName = "Pickaxe";
  119. weaponChanged = true;
  120. break;
  121. case '2':
  122. controllerState.currentAntiRecoilStrength = ANTI_RECOIL_SHOTGUN;
  123. profileName = "Shotgun";
  124. weaponChanged = true;
  125. break;
  126. case '3':
  127. controllerState.currentAntiRecoilStrength = ANTI_RECOIL_AR;
  128. profileName = "AR";
  129. weaponChanged = true;
  130. break;
  131. case '4':
  132. controllerState.currentAntiRecoilStrength = ANTI_RECOIL_SMG;
  133. profileName = "SMG";
  134. weaponChanged = true;
  135. break;
  136. // Add cases for '5' etc. if needed
  137. }
  138. if (weaponChanged) {
  139. console.log(`Anti-Recoil Profile set to ${profileName} (${controllerState.currentAntiRecoilStrength}) via key '${mappedKey}'`);
  140. }
  141. // --- End Weapon Select Logic ---
  142.  
  143. if (!mapping) return; // Continue only if the key has a standard mapping
  144.  
  145. event.preventDefault();
  146. event.stopPropagation();
  147.  
  148. // Standard Button/Axis Handling
  149. if (mapping.t === 'b') {
  150. const button = controllerState.buttons[mapping.i];
  151. if (!button.pressed) { button.pressed = true; button.touched = true; button.value = 1.0; }
  152. } else if (mapping.t === 'a') {
  153. const axisState = controllerState.axisKeyPresses[mapping.a];
  154. if (mapping.v < 0) axisState.neg = true; else axisState.pos = true;
  155. if (axisState.neg && axisState.pos) { controllerState.axes[mapping.a] = 0; }
  156. else { controllerState.axes[mapping.a] = axisState.neg ? -1 : 1; }
  157. }
  158. }
  159.  
  160. // handleKeyUp remains the same as V10
  161. function handleKeyUp(event) { /* ... Same as V10 ... */ 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; } } }
  162. // Other handlers remain the same as V10
  163. function handleMouseDown(event) { /* ... Same as V10 ... */ 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; } } }
  164. function handleMouseUp(event) { /* ... Same as V10 ... */ 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; } } }
  165. function handleMouseMove(event) { /* ... Same as V10 ... */ if (!pointerLocked) return; event.preventDefault(); event.stopPropagation(); const movementX = event.movementX || 0; const movementY = event.movementY || 0; controllerState.mouseDeltaX += movementX; controllerState.mouseDeltaY += movementY; }
  166. function handlePointerLockChange() { /* ... Same as V10 ... */ 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; } }); } }
  167. function requestPointerLock() { /* ... Same as V10 ... */ 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); }); } }
  168. function dispatchConnectionEvent() { /* ... Same as V10 ... */ 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); } }
  169.  
  170.  
  171. // --- Initialization --- (Same as V10)
  172. console.log("Attempting to find game area element...");
  173. gameAreaElement = document.getElementById('game-stream') || document.querySelector('video[playsinline]') || document.querySelector('video') || document.body;
  174. 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); }
  175. navigator.getGamepads = function() { return [createGamepadObject(), null, null, null]; };
  176. console.log("Initial navigator.getGamepads override set.");
  177. window.addEventListener('keydown', handleKeyDown, { capture: true }); window.addEventListener('keyup', handleKeyUp, { capture: true });
  178. const mouseEventTarget = gameAreaElement; mouseEventTarget.addEventListener('mousemove', handleMouseMove, { capture: true }); mouseEventTarget.addEventListener('mousedown', handleMouseDown, { capture: true }); mouseEventTarget.addEventListener('mouseup', handleMouseUp, { capture: true });
  179. document.addEventListener('pointerlockchange', handlePointerLockChange, false);
  180. 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); }
  181. try { dispatchConnectionEvent(); console.log("Dispatched initial gamepadconnected event."); } catch (e) { console.error("Error dispatching initial connection event:", e); }
  182. stateIntervalId = setInterval(updateAndSimulateGamepad, STATE_POLLING_RATE_MS);
  183. connectionIntervalId = setInterval(dispatchConnectionEvent, CONNECTION_DISPATCH_RATE_MS);
  184. console.log(`%cKBM Mapper V10.1 Active! State polling ID: ${stateIntervalId}, Connection dispatch ID: ${connectionIntervalId}.`, "color: cyan;");
  185. 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.");
  186. 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.");
  187. console.warn(">>> REMEMBER: HIGH BAN RISK with these features enabled. Tune values! Use responsibly! <<<");
  188. console.log("To disable, refresh page or type: stopKbmMapper();");
  189.  
  190. // --- Cleanup Function --- (Same as V10)
  191. window.stopKbmMapper = function() { /* ... Same as V10 ... */ console.log("Stopping KBM Mapper V10.1..."); 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."); };
  192.  
  193. })(); // End of IIFE
Add Comment
Please, Sign In to add comment