mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Map the Share button on Xbox Series controller with the capturing screenshot feature
This commit is contained in:
parent
3bfe11280e
commit
a376f443ef
@ -192,6 +192,10 @@ window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
|||||||
GameBar.getInstance().disable();
|
GameBar.getInstance().disable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, e => {
|
||||||
|
Screenshot.takeScreenshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
// Monkey patches
|
// Monkey patches
|
||||||
|
@ -155,15 +155,37 @@ if (!!window.BX_REMOTE_PLAY_CONFIG) {
|
|||||||
return str.replace(text, 'this.shouldCollectStats=!1');
|
return str.replace(text, 'this.shouldCollectStats=!1');
|
||||||
},
|
},
|
||||||
|
|
||||||
blockGamepadStatsCollector(str: string) {
|
patchPollGamepads(str: string) {
|
||||||
const text = 'this.inputPollingIntervalStats.addValue';
|
const index = str.indexOf('},this.pollGamepads=()=>{');
|
||||||
if (!str.includes(text)) {
|
if (index === -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str.replace('this.inputPollingIntervalStats.addValue', '');
|
const nextIndex = str.indexOf('setTimeout(this.pollGamepads', index);
|
||||||
str = str.replace('this.inputPollingDurationStats.addValue', '');
|
if (nextIndex === -1) {
|
||||||
return str;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let codeBlock = str.substring(index, nextIndex);
|
||||||
|
|
||||||
|
// Block gamepad stats collecting
|
||||||
|
if (getPref(PrefKey.BLOCK_TRACKING)) {
|
||||||
|
codeBlock = codeBlock.replaceAll('this.inputPollingIntervalStats.addValue', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map the Share button on Xbox Series controller with the capturing screenshot feature
|
||||||
|
const match = codeBlock.match(/this\.gamepadTimestamps\.set\((\w+)\.index/);
|
||||||
|
if (match) {
|
||||||
|
const gamepadVar = match[1];
|
||||||
|
const newCode = `
|
||||||
|
if (${gamepadVar}.buttons[17] && ${gamepadVar}.buttons[17].value === 1) {
|
||||||
|
window.dispatchEvent(new Event('${BxEvent.CAPTURE_SCREENSHOT}'));
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
||||||
|
}
|
||||||
|
|
||||||
|
return str.substring(0, index) + codeBlock + str.substring(nextIndex);
|
||||||
},
|
},
|
||||||
|
|
||||||
enableXcloudLogger(str: string) {
|
enableXcloudLogger(str: string) {
|
||||||
@ -619,7 +641,7 @@ let PLAYING_PATCH_ORDERS: PatchArray = [
|
|||||||
|
|
||||||
BX_FLAGS.EnableXcloudLogging && 'enableConsoleLogging',
|
BX_FLAGS.EnableXcloudLogging && 'enableConsoleLogging',
|
||||||
|
|
||||||
getPref(PrefKey.BLOCK_TRACKING) && 'blockGamepadStatsCollector',
|
'patchPollGamepads',
|
||||||
|
|
||||||
getPref(PrefKey.STREAM_COMBINE_SOURCES) && 'streamCombineSources',
|
getPref(PrefKey.STREAM_COMBINE_SOURCES) && 'streamCombineSources',
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ export enum BxEvent {
|
|||||||
|
|
||||||
GAME_BAR_ACTION_ACTIVATED = 'bx-game-bar-action-activated',
|
GAME_BAR_ACTION_ACTIVATED = 'bx-game-bar-action-activated',
|
||||||
MICROPHONE_STATE_CHANGED = 'bx-microphone-state-changed',
|
MICROPHONE_STATE_CHANGED = 'bx-microphone-state-changed',
|
||||||
|
|
||||||
|
CAPTURE_SCREENSHOT = 'bx-capture-screenshot',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum XcloudEvent {
|
export enum XcloudEvent {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user