Advertisement
Josiahiscool73

kbm AA(added Virtural Cronus Zen)

Jun 23rd, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.12 KB | None | 0 0
  1. /**
  2. * @name KBM AA
  3. * @description Emulates an Xbox controller
  4. * Press PageUp to open/close the settings menu.(entire script is made with ai except this top part)
  5. * improvements are mouse movement feels more normal and fixed deadzone making it feel weird also pls use builder pro and use pageup on your keyboard to open/close the GUI for customizing binds and sensitivity
  6. */
  7. (function() {
  8. 'use strict';
  9.  
  10. // --- Primary Toggle ---
  11. const KBM_AA_ENABLED = true;
  12.  
  13. // --- Default Configuration ---
  14. const DEFAULT_KEY_BINDS = {
  15. FIRE: 'mouse0', ADS: 't', JUMP: ' ', SPRINT: 'shift', CROUCH: 'control',
  16. RELOAD: 'r', USE: 'e', EDIT: 'g', WALL: 'z', RAMP: 'x', FLOOR: 'c', ROOF: 'v',
  17. };
  18. const DEFAULT_SENSITIVITY = { X: 8.5, Y: 8.5, ADS_MULTIPLIER: 85 };
  19.  
  20. // --- "Virtual Cronus Zen" (Movement-Based Aim Assist) ---
  21. const VIRTUAL_ZEN_SETTINGS = {
  22. ENABLE_STRAFE_AIM_ASSIST: true, STRAFE_AIM_ASSIST_KEY: 'q', STRAFE_AIM_ASSIST_STRENGTH: 0.05,
  23. STRAFE_AIM_ASSIST_ADS_MULTIPLIER: 1.3, ENABLE_MOVEMENT_VERTICAL_AIM_ASSIST: true,
  24. FORWARD_AIM_DOWN_STRENGTH: 0.09, BACKWARD_AIM_UP_STRENGTH: 0.09, STRAFE_LOOK_STRENGTH: 0.10,
  25. };
  26.  
  27. // --- Backend ---
  28. const ADVANCED = { POLLING_RATE_MS: 16, CONNECTION_DISPATCH_RATE_MS: 100, SENS_BASE_MULTIPLIER: 0.0018 };
  29. const CONTROLLER_BUTTON_MAP = {
  30. A: 0, B: 1, X: 2, Y: 3, LB: 4, RB: 5, LT: 6, RT: 7, L_STICK: 10, R_STICK: 11,
  31. };
  32. const BIND_ACTION_TO_BUTTON = {
  33. JUMP: CONTROLLER_BUTTON_MAP.A, EDIT: CONTROLLER_BUTTON_MAP.B, RELOAD: CONTROLLER_BUTTON_MAP.X,
  34. USE: CONTROLLER_BUTTON_MAP.X, WALL: CONTROLLER_BUTTON_MAP.RT, ADS: CONTROLLER_BUTTON_MAP.LT,
  35. RAMP: CONTROLLER_BUTTON_MAP.LT, ROOF: CONTROLLER_BUTTON_MAP.LB, FLOOR: CONTROLLER_BUTTON_MAP.RB,
  36. SPRINT: CONTROLLER_BUTTON_MAP.L_STICK, CROUCH: CONTROLLER_BUTTON_MAP.R_STICK,
  37. FIRE: CONTROLLER_BUTTON_MAP.RT,
  38. };
  39.  
  40. // --- Script State ---
  41. let keyMap = {}, mouseMap = {}, currentBinds = {}, currentSens = {};
  42. const controllerState = {
  43. axes: [0.0, 0.0, 0.0, 0.0],
  44. buttons: Array(17).fill(false).map((_, i) => ({ pressed: false, touched: false, value: 0.0, index: i })),
  45. axisKeyPresses: { 0: { neg: false, pos: false }, 1: { neg: false, pos: false } },
  46. mouseDeltaX: 0, mouseDeltaY: 0, isConnected: true, timestamp: performance.now(),
  47. isAimAssistMacroActive: false,
  48. };
  49. let pointerLocked = false, stateIntervalId = null, connectionIntervalId = null, gameAreaElement = null;
  50. const originalGetGamepads = navigator.getGamepads?.bind(navigator);
  51.  
  52. // --- Core Logic ---
  53. function generateMappings() {
  54. keyMap = {
  55. 'w': { t: 'a', a: 1, v: -1 }, 'a': { t: 'a', a: 0, v: -1 },
  56. 's': { t: 'a', a: 1, v: 1 }, 'd': { t: 'a', a: 0, v: 1 },
  57. };
  58. mouseMap = {};
  59. for (const action in currentBinds) {
  60. const key = currentBinds[action].toLowerCase();
  61. const buttonIndex = BIND_ACTION_TO_BUTTON[action];
  62. if (buttonIndex !== undefined) {
  63. if (key.startsWith('mouse')) {
  64. mouseMap[parseInt(key.replace('mouse', ''), 10)] = { t: 'b', i: buttonIndex };
  65. } else {
  66. keyMap[key] = { t: 'b', i: buttonIndex };
  67. }
  68. }
  69. }
  70. }
  71.  
  72. function createGamepadObject() {
  73. return {
  74. axes: controllerState.axes, buttons: controllerState.buttons, connected: controllerState.isConnected,
  75. id: "Xbox Controller (XInput STANDARD GAMEPAD)", index: 0, mapping: "standard", timestamp: controllerState.timestamp,
  76. };
  77. }
  78.  
  79. function updateAndSimulateGamepad() {
  80. let scriptSensX = currentSens.X * ADVANCED.SENS_BASE_MULTIPLIER, scriptSensY = currentSens.Y * ADVANCED.SENS_BASE_MULTIPLIER;
  81. const isADS = controllerState.buttons[BIND_ACTION_TO_BUTTON.ADS]?.pressed || false;
  82. if (isADS) { const m = currentSens.ADS_MULTIPLIER / 100; scriptSensX *= m; scriptSensY *= m; }
  83. let finalTargetRX = 0, finalTargetRY = 0;
  84. if (pointerLocked) {
  85. finalTargetRX = controllerState.mouseDeltaX * scriptSensX; finalTargetRY = controllerState.mouseDeltaY * scriptSensY;
  86. if (VIRTUAL_ZEN_SETTINGS.ENABLE_STRAFE_AIM_ASSIST && controllerState.isAimAssistMacroActive) {
  87. const s = VIRTUAL_ZEN_SETTINGS.STRAFE_AIM_ASSIST_STRENGTH * (isADS ? VIRTUAL_ZEN_SETTINGS.STRAFE_AIM_ASSIST_ADS_MULTIPLIER : 1);
  88. if (controllerState.axisKeyPresses[0].neg) finalTargetRX += s; else if (controllerState.axisKeyPresses[0].pos) finalTargetRX -= s;
  89. }
  90. if (VIRTUAL_ZEN_SETTINGS.ENABLE_MOVEMENT_VERTICAL_AIM_ASSIST) {
  91. if (controllerState.axisKeyPresses[1].neg) finalTargetRY += VIRTUAL_ZEN_SETTINGS.FORWARD_AIM_DOWN_STRENGTH;
  92. else if (controllerState.axisKeyPresses[1].pos) finalTargetRY -= VIRTUAL_ZEN_SETTINGS.BACKWARD_AIM_UP_STRENGTH;
  93. }
  94. if (controllerState.axisKeyPresses[0].neg) finalTargetRX += VIRTUAL_ZEN_SETTINGS.STRAFE_LOOK_STRENGTH;
  95. else if (controllerState.axisKeyPresses[0].pos) finalTargetRX -= VIRTUAL_ZEN_SETTINGS.STRAFE_LOOK_STRENGTH;
  96. controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0;
  97. }
  98. controllerState.axes[2] = Math.max(-1, Math.min(1, finalTargetRX));
  99. controllerState.axes[3] = Math.max(-1, Math.min(1, finalTargetRY));
  100. controllerState.timestamp = performance.now();
  101. }
  102.  
  103. // --- Event Handlers (Unified and Bulletproofed) ---
  104. function handleKeyEvent(event, isDown) {
  105. if (event.key === 'PageUp' && isDown) { toggleUI(); return; }
  106. const gui = document.getElementById('kbm-aa-gui');
  107. if (gui && gui.style.display === 'flex') { if (event.key === 'Escape') { toggleUI(); } return; }
  108. const key = event.key.toLowerCase();
  109. if (key === VIRTUAL_ZEN_SETTINGS.STRAFE_AIM_ASSIST_KEY) {
  110. event.preventDefault(); event.stopPropagation();
  111. controllerState.isAimAssistMacroActive = isDown; return;
  112. }
  113. const mappedKey = (key.startsWith('control') ? 'control' : key);
  114. const mapping = keyMap[mappedKey];
  115. if (mapping) {
  116. event.preventDefault(); event.stopPropagation();
  117. if (mapping.t === 'b') {
  118. const button = controllerState.buttons[mapping.i];
  119. if (button.pressed !== isDown) { button.pressed = isDown; button.touched = isDown; button.value = isDown ? 1.0 : 0.0; }
  120. } else if (mapping.t === 'a') {
  121. const axisState = controllerState.axisKeyPresses[mapping.a];
  122. if (mapping.v < 0) axisState.neg = isDown; else axisState.pos = isDown;
  123. controllerState.axes[mapping.a] = axisState.neg ? -1 : (axisState.pos ? 1 : 0);
  124. }
  125. }
  126. }
  127.  
  128. function handleMouseEvent(event, isDown) {
  129. const gui = document.getElementById('kbm-aa-gui');
  130. if (gui && gui.style.display === 'flex') return;
  131. const mapping = mouseMap[event.button];
  132. if (mapping) {
  133. event.preventDefault(); event.stopPropagation();
  134. if (!pointerLocked && isDown) return;
  135. const button = controllerState.buttons[mapping.i];
  136. if (button.pressed !== isDown) { button.pressed = isDown; button.touched = isDown; button.value = isDown ? 1.0 : 0.0; }
  137. }
  138. }
  139.  
  140. function handleMouseMove(event) {
  141. const gui = document.getElementById('kbm-aa-gui');
  142. if (gui && gui.style.display === 'flex') return;
  143. if (pointerLocked) {
  144. controllerState.mouseDeltaX += event.movementX || 0;
  145. controllerState.mouseDeltaY += event.movementY || 0;
  146. }
  147. }
  148.  
  149. function handlePointerLockChange() {
  150. pointerLocked = (document.pointerLockElement === gameAreaElement);
  151. if (!pointerLocked) {
  152. Object.assign(controllerState, { mouseDeltaX: 0, mouseDeltaY: 0, isAimAssistMacroActive: false });
  153. Object.values(mouseMap).forEach(m => { const b = controllerState.buttons[m.i]; b.pressed = b.touched = false; b.value = 0.0; });
  154. }
  155. }
  156.  
  157. function requestPointerLock() {
  158. if (!pointerLocked) {
  159. gameAreaElement.requestPointerLock().catch(e => console.error("Pointer lock failed:", e));
  160. }
  161. }
  162.  
  163. // --- GUI Functions ---
  164. function toggleUI() { const gui = document.getElementById('kbm-aa-gui'); if (gui) { gui.style.display = gui.style.display === 'flex' ? 'none' : 'flex'; } }
  165. function saveSettings() {
  166. for (const action in DEFAULT_KEY_BINDS) { currentBinds[action] = document.getElementById(`bind-${action}`).value; }
  167. currentSens.X = parseFloat(document.getElementById('sens-x').value);
  168. currentSens.Y = parseFloat(document.getElementById('sens-y').value);
  169. currentSens.ADS_MULTIPLIER = parseFloat(document.getElementById('sens-ads').value);
  170. localStorage.setItem('kbm-aa-binds', JSON.stringify(currentBinds));
  171. localStorage.setItem('kbm-aa-sens', JSON.stringify(currentSens));
  172. generateMappings();
  173. const saveButton = document.getElementById('kbm-aa-save-btn');
  174. saveButton.textContent = 'Saved!';
  175. setTimeout(() => { saveButton.textContent = 'Save and Close'; toggleUI(); }, 1000);
  176. }
  177. function loadSettings() {
  178. const savedBinds = localStorage.getItem('kbm-aa-binds'); const savedSens = localStorage.getItem('kbm-aa-sens');
  179. currentBinds = savedBinds ? JSON.parse(savedBinds) : { ...DEFAULT_KEY_BINDS };
  180. currentSens = savedSens ? JSON.parse(savedSens) : { ...DEFAULT_SENSITIVITY };
  181. }
  182. function createConfigUI() {
  183. if (document.getElementById('kbm-aa-gui')) return;
  184. let bindsHTML = '';
  185. for (const action in DEFAULT_KEY_BINDS) { bindsHTML += `<div class="kbm-aa-row"><label>${action}</label><input type="text" id="bind-${action}" value="${currentBinds[action] || ''}"></div>`; }
  186. const uiHTML = `<div id="kbm-aa-gui-content"><h2>KBM AA Settings</h2><p>Press PageUp to toggle menu. Settings are saved automatically.</p><div class="kbm-aa-section"><h3>Sensitivity</h3><div class="kbm-aa-row"><label>X Sensitivity (%)</label><input type="range" id="sens-x" min="1" max="30" step="0.1" value="${currentSens.X}"><span id="sens-x-val">${currentSens.X}</span></div><div class="kbm-aa-row"><label>Y Sensitivity (%)</label><input type="range" id="sens-y" min="1" max="30" step="0.1" value="${currentSens.Y}"><span id="sens-y-val">${currentSens.Y}</span></div><div class="kbm-aa-row"><label>ADS Multiplier (%)</label><input type="range" id="sens-ads" min="10" max="100" step="1" value="${currentSens.ADS_MULTIPLIER}"><span id="sens-ads-val">${currentSens.ADS_MULTIPLIER}</span></div></div><div class="kbm-aa-section"><h3>Key Binds</h3>${bindsHTML}</div><button id="kbm-aa-save-btn">Save and Close</button></div>`;
  187. const style = document.createElement('style');
  188. style.id = 'kbm-aa-style';
  189. style.textContent = `#kbm-aa-gui { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); justify-content: center; align-items: center; z-index: 99999; color: #fff; font-family: sans-serif; } #kbm-aa-gui-content { background: #1c1c1c; padding: 20px; border-radius: 8px; width: 400px; max-height: 80vh; overflow-y: auto; border: 1px solid #444; } .kbm-aa-section { margin-bottom: 20px; } .kbm-aa-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; } .kbm-aa-row label { flex-basis: 40%; } .kbm-aa-row input[type="text"] { width: 100px; padding: 5px; background: #333; border: 1px solid #555; color: #fff; border-radius: 4px; } .kbm-aa-row input[type="range"] { flex-grow: 1; } #kbm-aa-save-btn { width: 100%; padding: 10px; background: #5a9; border: none; color: #fff; border-radius: 4px; cursor: pointer; font-size: 16px; }`;
  190. document.head.appendChild(style);
  191. const guiContainer = document.createElement('div'); guiContainer.id = 'kbm-aa-gui'; guiContainer.innerHTML = uiHTML; document.body.appendChild(guiContainer);
  192. document.getElementById('kbm-aa-save-btn').addEventListener('click', saveSettings);
  193. document.getElementById('sens-x').addEventListener('input', (e) => { document.getElementById('sens-x-val').textContent = e.target.value; });
  194. document.getElementById('sens-y').addEventListener('input', (e) => { document.getElementById('sens-y-val').textContent = e.target.value; });
  195. document.getElementById('sens-ads').addEventListener('input', (e) => { document.getElementById('sens-ads-val').textContent = e.target.value; });
  196. }
  197.  
  198. // --- Initialization & Shutdown ---
  199. function initialize() {
  200. gameAreaElement = document.getElementById('game-stream') || document.querySelector('video') || document.body;
  201. if (!gameAreaElement) { console.error("KBM AA Script: Could not find a suitable game element to attach to."); return; }
  202. loadSettings(); createConfigUI(); generateMappings();
  203. navigator.getGamepads = () => [createGamepadObject(), null, null, null];
  204. window.addEventListener('keydown', (e) => handleKeyEvent(e, true), true); window.addEventListener('keyup', (e) => handleKeyEvent(e, false), true);
  205. gameAreaElement.addEventListener('mousemove', handleMouseMove, true);
  206. gameAreaElement.addEventListener('mousedown', (e) => handleMouseEvent(e, true), true); gameAreaElement.addEventListener('mouseup', (e) => handleMouseEvent(e, false), true);
  207. document.addEventListener('pointerlockchange', handlePointerLockChange, false);
  208. gameAreaElement.addEventListener('click', requestPointerLock, false);
  209. stateIntervalId = setInterval(updateAndSimulateGamepad, ADVANCED.POLLING_RATE_MS);
  210. connectionIntervalId = setInterval(() => { window.dispatchEvent(new CustomEvent('gamepadconnected', { detail: { gamepad: createGamepadObject() } })) }, ADVANCED.CONNECTION_DISPATCH_RATE_MS);
  211. }
  212.  
  213. window.stopKbmAa = function() {
  214. if (!stateIntervalId) return;
  215. clearInterval(stateIntervalId); clearInterval(connectionIntervalId); stateIntervalId = null; connectionIntervalId = null;
  216. // Listeners are now anonymous, so we can't remove them one by one. A page refresh is the cleanest way to stop.
  217. // For a true "stop", a more complex listener management system would be needed, but this prevents errors.
  218. if (originalGetGamepads) navigator.getGamepads = originalGetGamepads; else delete navigator.getGamepads;
  219. const gui = document.getElementById('kbm-aa-gui'); if (gui) gui.remove();
  220. const style = document.getElementById('kbm-aa-style'); if (style) style.remove();
  221. if (document.pointerLockElement) document.exitPointerLock();
  222. // The most reliable way to stop is to reload the page, but for a soft stop we just nullify the intervals.
  223. };
  224.  
  225. if (KBM_AA_ENABLED) {
  226. if (document.readyState === 'complete' || document.readyState === 'interactive') { setTimeout(initialize, 500); }
  227. else { document.addEventListener('DOMContentLoaded', () => setTimeout(initialize, 500)); }
  228. }
  229. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement