Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // == Xbox Cloud Gaming KBM Mapper v10.9 ==
- // • Inventory 2–4 switch your recoil preset automatically
- // • 1,5,6 remain pure inventory slots (pickaxe/heals)
- // • Mouse side buttons → slots 5/6
- // • All v10.8 features preserved
- // == End = toggle, Home = full teardown ==
- (function(){
- // --- Flags & State ---
- let enabled = true,
- pointerLocked = false,
- gameArea = null,
- stateInt, dispatchInt;
- const TOGGLE_KEY = 'end',
- KILL_KEY = 'home';
- console.log('⚙️ KBM Mapper v10.9 – [End]=Toggle, [Home]=Kill');
- // --- Config ---
- const POLL_MS = 16,
- DISPATCH_MS = 100,
- AXIS_DEADZONE = 0.05;
- const BASE_SENS_X = 0.025,
- BASE_SENS_Y = 0.025,
- ADS_MULT = 1.75,
- MOUSE_DECAY = 0.0;
- const ENABLE_SMOOTH = true,
- SMOOTH_BASE = 0.5,
- SMOOTH_PEAK = 0.9,
- SMOOTH_RAMP_MS = 300;
- const ENABLE_MICRO = true,
- MICRO_RAD = 0.02,
- MICRO_SPD = 0.15;
- const ENABLE_RECOIL = true,
- FIRE_IDX = 7; // RT
- // Recoil presets (F1–F7 still available for manual override)
- const RECOIL_PRESETS = {
- scar: 0.020,
- m16: 0.017,
- compact_smg: 0.030,
- pump_shotgun: 0.005,
- bolt_sniper: 0.008,
- tac_shotgun: 0.007,
- heavy_sniper: 0.010
- };
- const RECOIL_KEYS = ['f1','f2','f3','f4','f5','f6','f7'];
- const RECOIL_NAMES = ['scar','m16','compact_smg','pump_shotgun','bolt_sniper','tac_shotgun','heavy_sniper'];
- let currentPreset = 'scar';
- // --- Controller State ---
- const state = {
- axes: [0,0,0,0],
- buttons: Array(17).fill().map((_,i)=>({
- pressed:false, touched:false, value:0, index:i
- })),
- axisKey: {0:{neg:false,pos:false},1:{neg:false,pos:false}},
- dx: 0, dy:0,
- ts: performance.now(),
- microAngle: 0,
- adsStart: 0
- };
- // --- Mappings ---
- const ADS_IDX = 6; // LT
- const keyMap = {
- w:{t:'a',a:1,v:-1}, s:{t:'a',a:1,v:1},
- a:{t:'a',a:0,v:-1}, d:{t:'a',a:0,v:1},
- ' ':{t:'b',i:0}, shift:{t:'b',i:10}, control:{t:'b',i:11},
- r:{t:'b',i:2}, e:{t:'b',i:3}, f:{t:'b',i:5}, g:{t:'b',i:1},
- escape:{t:'b',i:9}, tab:{t:'b',i:8}, m:{t:'b',i:8},
- z:{t:'b',i:14}, x:{t:'b',i:15}, c:{t:'b',i:13}, v:{t:'b',i:12}
- // no '1'–'4' here: we’ll intercept them below
- };
- const mouseMap = {
- 0:{t:'b',i:FIRE_IDX}, // Left click → Fire
- 2:{t:'b',i:ADS_IDX} // Right click → ADS
- };
- // --- Build Gamepad object ---
- function makeGamepad() {
- const axes = state.axes.map(v=>Math.abs(v)<AXIS_DEADZONE?0:v);
- const btns = state.buttons.map(b=>({
- pressed:b.pressed, touched:b.touched, value:b.value, index:b.index
- }));
- return {
- axes, buttons: btns, connected:true,
- id: "KBM Mapper v10.9", index:0,
- mapping:"standard", timestamp:state.ts
- };
- }
- // --- Core update loop ---
- function updateState() {
- if (!enabled || !pointerLocked) return;
- const now = performance.now();
- const isADS = state.buttons[ADS_IDX].pressed;
- const isFire = state.buttons[FIRE_IDX].pressed;
- // ADS ramp timer
- if (isADS && state.adsStart===0) state.adsStart = now;
- if (!isADS) state.adsStart = 0;
- // base sensitivity + decay
- let sx = BASE_SENS_X, sy = BASE_SENS_Y;
- if (isADS) { sx*=ADS_MULT; sy*=ADS_MULT; }
- let rx = state.axes[2]*MOUSE_DECAY + state.dx*sx;
- let ry = state.axes[3]*MOUSE_DECAY + state.dy*sy;
- // circular micro-movement
- if (ENABLE_MICRO && isADS) {
- rx += Math.cos(state.microAngle)*MICRO_RAD;
- ry += Math.sin(state.microAngle)*MICRO_RAD;
- state.microAngle = (state.microAngle + MICRO_SPD) % (2*Math.PI);
- }
- // anti-recoil
- if (ENABLE_RECOIL && isFire) {
- ry += RECOIL_PRESETS[currentPreset] || 0;
- }
- // smoothing ramp
- if (ENABLE_SMOOTH && isADS) {
- const held = now - state.adsStart;
- const t = Math.min(1, held/SMOOTH_RAMP_MS);
- const factor = SMOOTH_BASE*(1-t) + SMOOTH_PEAK*t;
- rx = state.axes[2]*factor + rx*(1-factor);
- ry = state.axes[3]*factor + ry*(1-factor);
- }
- // clamp & assign
- state.axes[2] = Math.max(-1,Math.min(1,rx));
- state.axes[3] = Math.max(-1,Math.min(1,ry));
- state.dx = state.dy = 0;
- state.ts = now;
- }
- // --- Dispatch real GamepadEvent ---
- function dispatchPad() {
- if (!enabled) return;
- const gp = makeGamepad();
- try {
- const evt = new GamepadEvent('gamepadconnected',{ gamepad: gp });
- window.dispatchEvent(evt);
- } catch(e) {
- console.error('GamepadEvent failed:', e);
- }
- }
- // --- Helpers ---
- function prevent(e){ e.preventDefault(); e.stopPropagation(); }
- function shouldCapture(key, code){
- if ([TOGGLE_KEY,KILL_KEY].includes(key)) return false;
- if (/^[a-z0-9]$/.test(key)) return true;
- if ("`-=[]\\;',./~_+{}|:\"<>?".includes(key)) return true;
- return ['Tab','Enter','Escape','ArrowUp','ArrowDown','ArrowLeft','ArrowRight']
- .includes(code);
- }
- function sendSlotKey(k){
- document.dispatchEvent(new KeyboardEvent('keydown',{key:k}));
- document.dispatchEvent(new KeyboardEvent('keyup',{key:k}));
- console.log(`→ Inventory Slot ${k}`);
- }
- // --- Key Handlers ---
- function onKeyDown(e){
- const k = e.key.toLowerCase();
- // full teardown
- if (k===KILL_KEY){ teardown(); return prevent(e); }
- // toggle mapper
- if (k===TOGGLE_KEY){ toggle(); return prevent(e); }
- // Inventory slots 1–4:
- // • 1 = pickaxe
- // • 2 = shotgun → set recoil
- // • 3 = AR → set recoil
- // • 4 = SMG → set recoil
- if (['1','2','3','4'].includes(k)){
- // allow native switch
- if (k==='2') { currentPreset='pump_shotgun'; console.log('🔫 Recoil → pump_shotgun'); }
- if (k==='3') { currentPreset='scar'; console.log('🔫 Recoil → scar'); }
- if (k==='4') { currentPreset='compact_smg'; console.log('🔫 Recoil → compact_smg'); }
- return;
- }
- if (!enabled) return;
- // Anti-recoil can still be manually overridden via F1–F7
- if (ENABLE_RECOIL && RECOIL_KEYS.includes(k)){
- const idx = RECOIL_KEYS.indexOf(k);
- currentPreset = RECOIL_NAMES[idx];
- console.log(`🔫 Recoil → ${currentPreset}`);
- return prevent(e);
- }
- const m = keyMap[k];
- if (m){
- prevent(e);
- if (m.t==='b'){
- const btn = state.buttons[m.i];
- btn.pressed=btn.touched=true; btn.value=1;
- } else {
- const ax = state.axisKey[m.a];
- m.v<0?ax.neg=true:ax.pos=true;
- state.axes[m.a] = ax.neg&&ax.pos?0:(ax.neg?-1:1);
- }
- } else if (shouldCapture(k,e.code)){
- prevent(e);
- }
- }
- function onKeyUp(e){
- const k = e.key.toLowerCase();
- // don’t block 1–4 / toggles
- if ([KILL_KEY,TOGGLE_KEY,'1','2','3','4'].includes(k)) return prevent(e);
- if (!enabled) return;
- if (ENABLE_RECOIL && RECOIL_KEYS.includes(k)) return prevent(e);
- const m = keyMap[k];
- if (m){
- prevent(e);
- if (m.t==='b'){
- const btn = state.buttons[m.i];
- btn.pressed=btn.touched=false; btn.value=0;
- } else {
- const ax = state.axisKey[m.a];
- m.v<0?ax.neg=false:ax.pos=false;
- state.axes[m.a] = ax.neg?-1:ax.pos?1:0;
- }
- } else if (shouldCapture(k,e.code)){
- prevent(e);
- }
- }
- // --- Mouse Handlers ---
- function onMouseDown(e){
- if (!enabled) return;
- // side buttons → slots 5 & 6
- if (e.button===3){ prevent(e); sendSlotKey('5'); return; }
- if (e.button===4){ prevent(e); sendSlotKey('6'); return; }
- const m = mouseMap[e.button];
- if (!m) return;
- prevent(e);
- const btn = state.buttons[m.i];
- btn.pressed=btn.touched=true; btn.value=1;
- }
- function onMouseUp(e){
- if (!enabled) return;
- const m = mouseMap[e.button];
- if (!m) return;
- prevent(e);
- const btn = state.buttons[m.i];
- btn.pressed=btn.touched=false; btn.value=0;
- }
- function onMouseMove(e){
- if (!enabled || !pointerLocked) return;
- prevent(e);
- state.dx += e.movementX||0;
- state.dy += e.movementY||0;
- }
- // --- Pointer Lock ---
- function onPointerLockChange(){
- pointerLocked = (document.pointerLockElement===gameArea);
- console.log(pointerLocked?'🔒 Pointer Locked':'🔓 Pointer Unlocked');
- if (!pointerLocked){
- state.axes[2]=state.axes[3]=0;
- state.microAngle=0;
- }
- }
- function requestLock(){ gameArea?.requestPointerLock?.(); }
- // --- Toggle & Teardown ---
- function toggle(){
- enabled = !enabled;
- console.log(enabled? '%cMapper ON':'%cMapper OFF',
- 'font-weight:bold;color:'+(enabled?'lightgreen':'orange'));
- if (!enabled){
- state.axes=[0,0,0,0];
- state.buttons.forEach(b=>b.pressed=b.touched=false,b.value=0);
- state.axisKey={0:{neg:false,pos:false},1:{neg:false,pos:false}};
- currentPreset='scar';
- if (pointerLocked) document.exitPointerLock();
- }
- }
- function teardown(){
- enabled=false;
- clearInterval(stateInt); clearInterval(dispatchInt);
- window.removeEventListener('keydown', onKeyDown, true);
- window.removeEventListener('keyup', onKeyUp, true);
- gameArea.removeEventListener('mousedown', onMouseDown, true);
- gameArea.removeEventListener('mouseup', onMouseUp, true);
- gameArea.removeEventListener('mousemove', onMouseMove, true);
- gameArea.removeEventListener('click', requestLock);
- document.removeEventListener('pointerlockchange', onPointerLockChange);
- navigator.getGamepads = ()=>[];
- console.warn('%cKBM Mapper v10.9 TERMINATED – refresh to reload','color:red;font-weight:bold;');
- }
- // --- Initialization ---
- (function init(){
- gameArea = document.getElementById('game-stream')
- || document.querySelector('video[playsinline]')
- || document.querySelector('video')
- || document.body;
- navigator.getGamepads = ()=> enabled
- ? [ makeGamepad() ]
- : [];
- window.addEventListener('keydown', onKeyDown, true);
- window.addEventListener('keyup', onKeyUp, true);
- gameArea.addEventListener('mousedown', onMouseDown, true);
- gameArea.addEventListener('mouseup', onMouseUp, true);
- gameArea.addEventListener('mousemove', onMouseMove, true);
- gameArea.addEventListener('click', requestLock, false);
- document.addEventListener('pointerlockchange', onPointerLockChange, false);
- stateInt = setInterval(updateState, POLL_MS);
- dispatchInt = setInterval(dispatchPad, DISPATCH_MS);
- console.log('▶️ KBM Mapper v10.9 ACTIVE – click to lock pointer');
- console.log('🔫 Slots 2–4 auto-set recoil, F1–F7 manual override');
- })();
- })();
Add Comment
Please, Sign In to add comment