mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Move some patch code to external files
This commit is contained in:
parent
88df490c50
commit
e18e05589a
@ -6,6 +6,11 @@ import { BxLogger } from "@utils/bx-logger";
|
||||
import { hashCode } from "@utils/utils";
|
||||
import { BxEvent } from "@/utils/bx-event";
|
||||
|
||||
import codeLocalCoOpEnable from "./patches/local-co-op-enable.js" with { type: "text" };
|
||||
import codeRemotePlayEnable from "./patches/remote-play-enable.js" with { type: "text" };
|
||||
import codeRemotePlayKeepAlive from "./patches/remote-play-keep-alive.js" with { type: "text" };
|
||||
import codeVibrationAdjust from "./patches/vibration-adjust.js" with { type: "text" };
|
||||
|
||||
type PatchArray = (keyof typeof PATCHES)[];
|
||||
|
||||
const ENDING_CHUNKS_PATCH_NAME = 'loadingEndingChunks';
|
||||
@ -92,31 +97,24 @@ const PATCHES = {
|
||||
},
|
||||
|
||||
remotePlayKeepAlive(str: string) {
|
||||
if (!str.includes('onServerDisconnectMessage(e){')) {
|
||||
const text = 'onServerDisconnectMessage(e){';
|
||||
if (!str.includes(text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
str = str.replace('onServerDisconnectMessage(e){', `onServerDisconnectMessage(e) {
|
||||
const msg = JSON.parse(e);
|
||||
if (msg.reason === 'WarningForBeingIdle' && !window.location.pathname.includes('/launch/')) {
|
||||
try {
|
||||
this.sendKeepAlive();
|
||||
return;
|
||||
} catch (ex) { console.log(ex); }
|
||||
}
|
||||
`);
|
||||
str = str.replace(text, text + codeRemotePlayKeepAlive);
|
||||
|
||||
return str;
|
||||
},
|
||||
|
||||
// Enable Remote Play feature
|
||||
remotePlayConnectMode(str: string) {
|
||||
const text = 'connectMode:"cloud-connect"';
|
||||
const text = 'connectMode:"cloud-connect",';
|
||||
if (!str.includes(text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return str.replace(text, `connectMode:window.BX_REMOTE_PLAY_CONFIG?"xhome-connect":"cloud-connect",remotePlayServerId:(window.BX_REMOTE_PLAY_CONFIG&&window.BX_REMOTE_PLAY_CONFIG.serverId)||''`);
|
||||
return str.replace(text, codeRemotePlayEnable);
|
||||
},
|
||||
|
||||
// Disable achievement toast in Remote Play
|
||||
@ -215,20 +213,8 @@ if (${gamepadVar}.buttons[17] && ${gamepadVar}.buttons[17].value === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = `
|
||||
if (!window.BX_ENABLE_CONTROLLER_VIBRATION) {
|
||||
return void(0);
|
||||
}
|
||||
if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
|
||||
e.leftMotorPercent = e.leftMotorPercent * window.BX_VIBRATION_INTENSITY;
|
||||
e.rightMotorPercent = e.rightMotorPercent * window.BX_VIBRATION_INTENSITY;
|
||||
e.leftTriggerMotorPercent = e.leftTriggerMotorPercent * window.BX_VIBRATION_INTENSITY;
|
||||
e.rightTriggerMotorPercent = e.rightTriggerMotorPercent * window.BX_VIBRATION_INTENSITY;
|
||||
}
|
||||
`;
|
||||
|
||||
VibrationManager.updateGlobalVars();
|
||||
str = str.replaceAll(text, text + newCode);
|
||||
str = str.replaceAll(text, text + codeVibrationAdjust);
|
||||
return str;
|
||||
},
|
||||
|
||||
@ -324,27 +310,7 @@ window.dispatchEvent(new Event("${BxEvent.TOUCH_LAYOUT_MANAGER_READY}"));
|
||||
return false;
|
||||
}
|
||||
|
||||
let patchstr = `
|
||||
let match;
|
||||
let onGamepadChangedStr = this.onGamepadChanged.toString();
|
||||
|
||||
onGamepadChangedStr = onGamepadChangedStr.replaceAll('0', 'arguments[1]');
|
||||
eval(\`this.onGamepadChanged = function \${onGamepadChangedStr}\`);
|
||||
|
||||
let onGamepadInputStr = this.onGamepadInput.toString();
|
||||
|
||||
match = onGamepadInputStr.match(/(\\w+\\.GamepadIndex)/);
|
||||
if (match) {
|
||||
const gamepadIndexVar = match[0];
|
||||
onGamepadInputStr = onGamepadInputStr.replace('this.gamepadStates.get(', \`this.gamepadStates.get(\${gamepadIndexVar},\`);
|
||||
eval(\`this.onGamepadInput = function \${onGamepadInputStr}\`);
|
||||
BxLogger.info('supportLocalCoOp', '✅ Successfully patched local co-op support');
|
||||
} else {
|
||||
BxLogger.error('supportLocalCoOp', '❌ Unable to patch local co-op support');
|
||||
}
|
||||
`;
|
||||
|
||||
const newCode = `true; ${patchstr}; true,`;
|
||||
const newCode = `true; ${codeLocalCoOpEnable}; true,`;
|
||||
|
||||
str = str.replace(text, text + newCode);
|
||||
return str;
|
||||
|
17
src/modules/patches/local-co-op-enable.js
Normal file
17
src/modules/patches/local-co-op-enable.js
Normal file
@ -0,0 +1,17 @@
|
||||
let match;
|
||||
let onGamepadChangedStr = this.onGamepadChanged.toString();
|
||||
|
||||
onGamepadChangedStr = onGamepadChangedStr.replaceAll('0', 'arguments[1]');
|
||||
eval(`this.onGamepadChanged = function ${onGamepadChangedStr}`);
|
||||
|
||||
let onGamepadInputStr = this.onGamepadInput.toString();
|
||||
|
||||
match = onGamepadInputStr.match(/(\w+\.GamepadIndex)/);
|
||||
if (match) {
|
||||
const gamepadIndexVar = match[0];
|
||||
onGamepadInputStr = onGamepadInputStr.replace('this.gamepadStates.get(', `this.gamepadStates.get(${gamepadIndexVar},`);
|
||||
eval(`this.onGamepadInput = function ${onGamepadInputStr}`);
|
||||
BxLogger.info('supportLocalCoOp', '✅ Successfully patched local co-op support');
|
||||
} else {
|
||||
BxLogger.error('supportLocalCoOp', '❌ Unable to patch local co-op support');
|
||||
}
|
2
src/modules/patches/remote-play-enable.js
Normal file
2
src/modules/patches/remote-play-enable.js
Normal file
@ -0,0 +1,2 @@
|
||||
connectMode: window.BX_REMOTE_PLAY_CONFIG ? "xhome-connect" : "cloud-connect",
|
||||
remotePlayServerId: (window.BX_REMOTE_PLAY_CONFIG && window.BX_REMOTE_PLAY_CONFIG.serverId) || '',
|
7
src/modules/patches/remote-play-keep-alive.js
Normal file
7
src/modules/patches/remote-play-keep-alive.js
Normal file
@ -0,0 +1,7 @@
|
||||
const msg = JSON.parse(e);
|
||||
if (msg.reason === 'WarningForBeingIdle' && !window.location.pathname.includes('/launch/')) {
|
||||
try {
|
||||
this.sendKeepAlive();
|
||||
return;
|
||||
} catch (ex) { console.log(ex); }
|
||||
}
|
11
src/modules/patches/vibration-adjust.js
Normal file
11
src/modules/patches/vibration-adjust.js
Normal file
@ -0,0 +1,11 @@
|
||||
if (!window.BX_ENABLE_CONTROLLER_VIBRATION) {
|
||||
return void(0);
|
||||
}
|
||||
|
||||
const intensity = window.BX_VIBRATION_INTENSITY;
|
||||
if (intensity && intensity < 1) {
|
||||
e.leftMotorPercent *= intensity;
|
||||
e.rightMotorPercent *= intensity;
|
||||
e.leftTriggerMotorPercent *= intensity;
|
||||
e.rightTriggerMotorPercent *= intensity;
|
||||
}
|
5
src/types/index.d.ts
vendored
5
src/types/index.d.ts
vendored
@ -73,5 +73,6 @@ type XcloudTitleInfo = {
|
||||
};
|
||||
};
|
||||
|
||||
declare module "*.svg";
|
||||
declare module "*.styl";
|
||||
declare module '*.js';
|
||||
declare module '*.svg';
|
||||
declare module '*.styl';
|
||||
|
Loading…
x
Reference in New Issue
Block a user