Advertisement
Josiahiscool73

Aim assist V6(Best version rn) for Xbox cloud gaming, READ THE TOP

Apr 4th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 KB | None | 0 0
  1. // == Xbox Cloud Gaming Keyboard/Mouse to Controller Mapper v6 ==
  2. // == !! EXPERIMENTAL - Periodic Connection Event Dispatch (Timer-based) !! ==
  3. // == to shoot use Z for optimal aim assist, r for reloading and to pick up items, building and editing isn't gonna be here rn since its beta and v6 and I'm working on builds, q for ADs(sorry for kbm users I'm just on touch pad and this feels better then trying to right click on touchpad) shift, space, Ctrl for running jumping and crouching all work also it sometimes doesn't lock on but most the time it does also sometimes it bugs since ur constantly switching and acts like a full on aimbot but that's sometimes but its still not that rare so enjoy ==
  4. // == Use external software like reWASD for a stable solution(this has lesser delay tho lol) ==
  5. // Run this in the browser console AFTER A HARD REFRESH (Ctrl+Shift+R)
  6.  
  7. (function() {
  8. console.log("Initializing Experimental KBM Mapper v6 (Periodic Dispatch)...");
  9. console.warn("WARNING: Experimental. Ensure you did a HARD REFRESH first!");
  10.  
  11. // --- Configuration ---
  12. const MOUSE_SENSITIVITY_X = 0.0025; const MOUSE_SENSITIVITY_Y = 0.0025;
  13. const MOUSE_DECAY = 0.85;
  14. const STATE_POLLING_RATE_MS = 16; // ~60fps for state updates
  15. const CONNECTION_DISPATCH_RATE_MS = 100; // Dispatch connected event 10x per second
  16. const AXIS_DEADZONE = 0.05;
  17.  
  18. // --- Fortnite Builder Pro Mapping --- (Same as V4)
  19. const keyMap = { /* ... same as v4 ... */
  20. '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},' ':{t:'b',i:0},'control':{t:'b',i:11},'shift':{t:'b',i:10},'f':{t:'b',i:1},'e':{t:'b',i:7},'r':{t:'b',i:2},'q':{t:'b',i:6},'z':{t:'b',i:7},'x':{t:'b',i:5},'c':{t:'b',i:6},'v':{t:'b',i:4},'1':{t:'b',i:3},'2':{t:'b',i:12},'3':{t:'b',i:14},'4':{t:'b',i:13},'5':{t:'b',i:15},'6':{t:'b',i:8},'tab':{t:'b',i:8},'escape':{t:'b',i:9}
  21. }; // Shortened for brevity - use full map from V4
  22. const mouseMap = { /* ... same as v4 ... */ 0:{t:'b',i:7},2:{t:'b',i:6} };
  23.  
  24. // --- State Tracking --- (Same as V4)
  25. const controllerState = { axes:[0,0,0,0], buttons:Array(17).fill(false), axisKeyPresses:{0:{neg:false,pos:false},1:{neg:false,pos:false}}, mouseDeltaX:0, mouseDeltaY:0, isConnected:true, timestamp:performance.now() };
  26. let pointerLocked = false;
  27. let stateIntervalId = null; // For updating state
  28. let connectionIntervalId = null; // For dispatching connection events
  29. let gameAreaElement = null;
  30.  
  31. // --- Gamepad Object Construction --- (Same as V4)
  32. function createGamepadObject() { /* ... same function ... */
  33. const axes = controllerState.axes.map(val => Math.abs(val) < AXIS_DEADZONE ? 0.0 : val);
  34. return { axes: axes, buttons: controllerState.buttons.map((p, i) => ({ pressed: p, touched: p, value: p ? 1.0 : 0.0, index: i })),
  35. connected: controllerState.isConnected, id: "KBM Emulated Xbox Controller v6 (Standard)", index: 0, mapping: "standard", timestamp: controllerState.timestamp, };
  36. }
  37. // --- Core Simulation Function (Updates State) --- (Same as V4)
  38. function updateAndSimulateGamepad() { /* ... same function ... */
  39. let cRX=controllerState.axes[2],cRY=controllerState.axes[3];if(pointerLocked){cRX*=MOUSE_DECAY;cRY*=MOUSE_DECAY;cRX+=controllerState.mouseDeltaX;cRY+=controllerState.mouseDeltaY;controllerState.mouseDeltaX=0;controllerState.mouseDeltaY=0}else{cRX=0;cRY=0;controllerState.mouseDeltaX=0;controllerState.mouseDeltaY=0}
  40. 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,cRX));controllerState.axes[3]=Math.max(-1,Math.min(1,cRY));
  41. controllerState.timestamp=performance.now();navigator.getGamepads=function(){return[createGamepadObject(),null,null,null]};
  42. }
  43. // --- Event Handlers (Key/Mouse Up/Down) --- (Same as V4)
  44. function handleKeyDown(event){const k=event.key.toLowerCase(),mk=(k==='controlleft'||k==='controlright')?'control':k,m=keyMap[mk];if(!m)return;event.preventDefault();event.stopPropagation();if(m.t==='b'){if(!controllerState.buttons[m.i])controllerState.buttons[m.i]=!0}else if(m.t==='a'){const s=controllerState.axisKeyPresses[m.a];if(m.v<0)s.neg=!0;else s.pos=!0;controllerState.axes[m.a]=(s.neg&&s.pos)?0:(s.neg?-1:1)}}
  45. function handleKeyUp(event){const k=event.key.toLowerCase(),mk=(k==='controlleft'||k==='controlright')?'control':k,m=keyMap[mk];if(!m)return;event.preventDefault();event.stopPropagation();if(m.t==='b')controllerState.buttons[m.i]=!1;else if(m.t==='a'){const s=controllerState.axisKeyPresses[m.a];if(m.v<0)s.neg=!1;else s.pos=!1;controllerState.axes[m.a]=(s.neg?-1:(s.pos?1:0))}}
  46. function handleMouseDown(event){const m=mouseMap[event.button];if(!m||(!pointerLocked&&event.target!==gameAreaElement))return;event.preventDefault();event.stopPropagation();if(m.t==='b'&&!controllerState.buttons[m.i])controllerState.buttons[m.i]=!0}
  47. function handleMouseUp(event){const m=mouseMap[event.button];if(!m)return;event.preventDefault();event.stopPropagation();if(m.t==='b')controllerState.buttons[m.i]=!1}
  48. function handleMouseMove(event){if(!pointerLocked)return;event.preventDefault();event.stopPropagation();const dX=event.movementX||0,dY=event.movementY||0;controllerState.mouseDeltaX+=dX*MOUSE_SENSITIVITY_X;controllerState.mouseDeltaY+=dY*MOUSE_SENSITIVITY_Y} // No event dispatch here
  49. function handlePointerLockChange(){const lE=document.pointerLockElement,cAE=document.activeElement;console.log(`PointerLockChange. Locked:${lE?.id||lE?.tagName}, Active:${cAE?.id||cAE?.tagName}`);if(lE===gameAreaElement){console.log('%cPointer Locked','color:green;');pointerLocked=!0}else{console.warn(`Pointer Unlocked. Expected:${gameAreaElement?.id||gameAreaElement?.tagName}, Locked:${lE?.id||lE?.tagName}`);pointerLocked=!1;controllerState.axes[2]=0;controllerState.axes[3]=0;controllerState.mouseDeltaX=0;controllerState.mouseDeltaY=0;if(mouseMap[0])controllerState.buttons[mouseMap[0].i]=!1;if(mouseMap[2])controllerState.buttons[mouseMap[2].i]=!1}}
  50. function requestPointerLock(){if(!gameAreaElement)return;if(document.pointerLockElement!==gameAreaElement){console.log("Requesting lock:",gameAreaElement);gameAreaElement.requestPointerLock().then(()=>{}).catch(e=>{console.error("Lock failed:",e)})}}
  51.  
  52. // --- NEW Function: Dispatch Connection Event ---
  53. function dispatchConnectionEvent() {
  54. try {
  55. const gamepad = createGamepadObject(); // Get current state
  56. const gamepadConnectedEvent = new CustomEvent('gamepadconnected', { detail: { gamepad: gamepad } });
  57. gamepadConnectedEvent.gamepad = gamepad; // Add direct property
  58. window.dispatchEvent(gamepadConnectedEvent);
  59. // console.log("Dispatched periodic gamepadconnected event."); // VERY Noisy if uncommented
  60. } catch (e) {
  61. console.error("Error dispatching periodic event:", e);
  62. }
  63. }
  64.  
  65. // --- Initialization ---
  66. console.log("Performing Hard Refresh is STRONGLY recommended before running V6.");
  67. gameAreaElement = document.getElementById('game-stream') || /* ... */ document.querySelector('video') || document.body;
  68. if (!gameAreaElement) { console.error("CRITICAL: Could not find game area element."); gameAreaElement = document.body; } else { console.log("Found game area element:", gameAreaElement); }
  69. navigator.getGamepads = function() { return [createGamepadObject(), null, null, null]; }; console.log("Initial navigator.getGamepads override set.");
  70. // Add standard event listeners
  71. window.addEventListener('keydown', handleKeyDown, { capture: true }); window.addEventListener('keyup', handleKeyUp, { capture: true });
  72. const mouseEventTarget = gameAreaElement || window; mouseEventTarget.addEventListener('mousemove', handleMouseMove, { capture: true });
  73. mouseEventTarget.addEventListener('mousedown', handleMouseDown, { capture: true }); mouseEventTarget.addEventListener('mouseup', handleMouseUp, { capture: true });
  74. document.addEventListener('pointerlockchange', handlePointerLockChange, false);
  75. if (gameAreaElement) { gameAreaElement.addEventListener('click', requestPointerLock); console.log(">>> CLICK THE GAME AREA TO ENABLE MOUSE AIM <<<"); }
  76.  
  77. // Dispatch initial connection event once
  78. try { dispatchConnectionEvent(); console.log("Dispatched initial gamepadconnected event."); } catch (e) { /* handled in function */ }
  79.  
  80. // Start the TWO intervals
  81. stateIntervalId = setInterval(updateAndSimulateGamepad, STATE_POLLING_RATE_MS);
  82. connectionIntervalId = setInterval(dispatchConnectionEvent, CONNECTION_DISPATCH_RATE_MS); // NEW INTERVAL
  83.  
  84. console.log(`KBM Mapper Active! State polling ID: ${stateIntervalId}, Connection dispatch ID: ${connectionIntervalId}.`);
  85. console.log("To disable, refresh page or type: stopKbmMapper();");
  86.  
  87. // --- Cleanup function ---
  88. window.stopKbmMapper = function() {
  89. if (stateIntervalId) clearInterval(stateIntervalId);
  90. if (connectionIntervalId) clearInterval(connectionIntervalId); // Clear the new interval too
  91. // Remove listeners... (same as before)
  92. window.removeEventListener('keydown', handleKeyDown, { capture: true }); window.removeEventListener('keyup', handleKeyUp, { capture: true });
  93. mouseEventTarget.removeEventListener('mousemove', handleMouseMove, { capture: true }); mouseEventTarget.removeEventListener('mousedown', handleMouseDown, { capture: true }); mouseEventTarget.addEventListener('mouseup', handleMouseUp, { capture: true });
  94. document.removeEventListener('pointerlockchange', handlePointerLockChange, false);
  95. if (gameAreaElement) gameAreaElement.removeEventListener('click', requestPointerLock);
  96. if (document.pointerLockElement) document.exitPointerLock();
  97. console.log("KBM Mapper stopped. Refresh recommended."); location.reload();
  98. };
  99.  
  100. })(); // End of IIFE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement