mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-13 08:29:18 +02:00
Patch createPortal
This commit is contained in:
@@ -25,7 +25,6 @@ import { BxLogger } from "@utils/bx-logger";
|
||||
import { GameBar } from "./modules/game-bar/game-bar";
|
||||
import { ScreenshotManager } from "./utils/screenshot-manager";
|
||||
import { NativeMkbHandler } from "./modules/mkb/native-mkb-handler";
|
||||
import { GuideMenu } from "./modules/ui/guide-menu";
|
||||
import { updateVideoPlayer } from "./modules/stream/stream-settings-utils";
|
||||
import { BlockFeature, NativeMkbMode, TouchControllerMode, UiSection } from "./enums/pref-values";
|
||||
import { HeaderSection } from "./modules/ui/header";
|
||||
@@ -36,7 +35,6 @@ import { GlobalPref, StreamPref } from "./enums/pref-keys";
|
||||
import { UserAgent } from "./utils/user-agent";
|
||||
import { XboxApi } from "./utils/xbox-api";
|
||||
import { StreamStatsCollector } from "./utils/stream-stats-collector";
|
||||
import { RootDialogObserver } from "./utils/root-dialog-observer";
|
||||
import { StreamSettings } from "./utils/stream-settings";
|
||||
import { KeyboardShortcutHandler } from "./modules/mkb/keyboard-shortcut-handler";
|
||||
import { GhPagesUtils } from "./utils/gh-pages";
|
||||
@@ -47,6 +45,8 @@ import { SettingsManager } from "./modules/settings-manager";
|
||||
import { Toast } from "./utils/toast";
|
||||
import { WebGPUPlayer } from "./modules/player/webgpu/webgpu-player";
|
||||
import { StreamUiHandler } from "./modules/stream/stream-ui";
|
||||
import { RootDialogObserver } from "./utils/root-dialog-observer";
|
||||
import { GuideMenu } from "./modules/ui/guide-menu";
|
||||
|
||||
SettingsManager.getInstance();
|
||||
|
||||
@@ -197,7 +197,7 @@ window.addEventListener('popstate', onHistoryChanged);
|
||||
window.history.pushState = patchHistoryMethod('pushState');
|
||||
window.history.replaceState = patchHistoryMethod('replaceState');
|
||||
|
||||
BxEventBus.Script.on('header.rendered', () => {
|
||||
BxEventBus.Script.on('ui.header.rendered', () => {
|
||||
HeaderSection.getInstance().checkHeader();
|
||||
});
|
||||
|
||||
@@ -260,7 +260,7 @@ BxEventBus.Stream.on('state.playing', payload => {
|
||||
updateVideoPlayer();
|
||||
});
|
||||
|
||||
BxEventBus.Script.on('error.rendered', () => {
|
||||
BxEventBus.Script.on('ui.error.rendered', () => {
|
||||
BxEventBus.Stream.emit('state.stopped', {});
|
||||
});
|
||||
|
||||
|
@@ -96,4 +96,11 @@ export class PatcherUtils {
|
||||
|
||||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
static injectUseEffect(str: string, index: number, group: 'Stream' | 'Script', eventName: string) {
|
||||
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.${group}.emit('${eventName}', {}));`;
|
||||
str = PatcherUtils.insertAt(str, index, newCode);
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,8 @@ import codeGameCardIcons from "./patches/game-card-icons.js" with { type: "text"
|
||||
import codeLocalCoOpEnable from "./patches/local-co-op-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" };
|
||||
import codeStreamHud from "./patches/streamhud.js" with { type: "text" };
|
||||
import codeStreamHud from "./patches/stream-hud.js" with { type: "text" };
|
||||
import codeCreatePortal from "./patches/create-portal.js" with { type: "text" };
|
||||
import { GlobalPref, StorageKey } from "@/enums/pref-keys.js";
|
||||
import { getGlobalPref } from "@/utils/pref-utils.js";
|
||||
import { GamePassCloudGallery } from "@/enums/game-pass-gallery";
|
||||
@@ -1140,9 +1141,7 @@ ${subsVar} = subs;
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.Script.emit('header.rendered', {}));`;
|
||||
str = PatcherUtils.insertAt(str, index, newCode);
|
||||
return str;
|
||||
return PatcherUtils.injectUseEffect(str, index, 'Script', 'ui.header.rendered');
|
||||
},
|
||||
|
||||
injectErrorPageUseEffect(str: string) {
|
||||
@@ -1152,9 +1151,7 @@ ${subsVar} = subs;
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.Script.emit('error.rendered', {}));`;
|
||||
str = PatcherUtils.insertAt(str, index, newCode);
|
||||
return str;
|
||||
return PatcherUtils.injectUseEffect(str, index, 'Script', 'ui.error.rendered');
|
||||
},
|
||||
|
||||
injectStreamMenuUseEffect(str: string) {
|
||||
@@ -1164,8 +1161,17 @@ ${subsVar} = subs;
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.Stream.emit('ui.streamMenu.rendered', {}));`;
|
||||
str = PatcherUtils.insertAt(str, index, newCode);
|
||||
return PatcherUtils.injectUseEffect(str, index, 'Stream', 'ui.streamMenu.rendered');
|
||||
},
|
||||
|
||||
injectCreatePortal(str: string) {
|
||||
let index = str.indexOf('.createPortal=function');
|
||||
index > -1 && (index = PatcherUtils.indexOf(str, '{', index, 50, true));
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
str = PatcherUtils.insertAt(str, index, codeCreatePortal);
|
||||
return str;
|
||||
},
|
||||
};
|
||||
@@ -1178,6 +1184,7 @@ let PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
|
||||
'exposeReactCreateComponent',
|
||||
|
||||
'injectCreatePortal',
|
||||
'injectHeaderUseEffect',
|
||||
'injectErrorPageUseEffect',
|
||||
|
||||
|
13
src/modules/patcher/patches/src/create-portal.ts
Normal file
13
src/modules/patcher/patches/src/create-portal.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// @ts-ignore
|
||||
declare const arguments: any;
|
||||
|
||||
const $dom = arguments[1];
|
||||
if ($dom && $dom instanceof HTMLElement && $dom.id === 'gamepass-dialog-root') {
|
||||
let showing = false;
|
||||
const $child = $dom.firstElementChild;
|
||||
const $dialog = $child?.firstElementChild;
|
||||
if ($dialog) {
|
||||
showing = !$dialog.className.includes('pageChangeExit');
|
||||
}
|
||||
window.BxEventBus.Script.emit(showing ? 'dialog.shown' : 'dialog.dismissed', {});
|
||||
}
|
@@ -36,8 +36,8 @@ type ScriptEvents = {
|
||||
|
||||
'webgpu.ready': {},
|
||||
|
||||
'header.rendered': {},
|
||||
'error.rendered': {},
|
||||
'ui.header.rendered': {},
|
||||
'ui.error.rendered': {},
|
||||
};
|
||||
|
||||
type StreamEvents = {
|
||||
|
Reference in New Issue
Block a user