mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-08 22:27:44 +02:00
Add patch to modify __PRELOADED_STATE__
This commit is contained in:
@@ -20,7 +20,6 @@ import { Patcher } from "@modules/patcher";
|
||||
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
||||
import { onHistoryChanged, patchHistoryMethod } from "@utils/history";
|
||||
import { VibrationManager } from "@modules/vibration-manager";
|
||||
import { overridePreloadState } from "@utils/preload-state";
|
||||
import { disableAdobeAudienceManager, patchAudioContext, patchCanvasContext, patchMeControl, patchPointerLockApi, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
|
||||
import { AppInterface, STATES } from "@utils/global";
|
||||
import { BxLogger } from "@utils/bx-logger";
|
||||
@@ -362,7 +361,6 @@ function main() {
|
||||
if (isFullVersion()) {
|
||||
updatePollingRate();
|
||||
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
||||
overridePreloadState();
|
||||
|
||||
VibrationManager.initialSetup();
|
||||
|
||||
|
@@ -985,6 +985,16 @@ if (this.baseStorageKey in window.BX_EXPOSED.overrideSettings) {
|
||||
|
||||
return str;
|
||||
},
|
||||
|
||||
modifyPreloadedState(str: string) {
|
||||
let text = '=window.__PRELOADED_STATE__;';
|
||||
if (!str.includes(text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
str = str.replace(text, '=window.BX_EXPOSED.modifyPreloadedState(window.__PRELOADED_STATE__);');
|
||||
return str;
|
||||
},
|
||||
};
|
||||
|
||||
let PATCH_ORDERS: PatchArray = [
|
||||
@@ -995,6 +1005,8 @@ let PATCH_ORDERS: PatchArray = [
|
||||
'exposeInputSink',
|
||||
] : []),
|
||||
|
||||
'modifyPreloadedState',
|
||||
|
||||
'optimizeGameSlugGenerator',
|
||||
|
||||
'detectBrowserRouterReady',
|
||||
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
@@ -44,7 +44,6 @@ type BxStates = {
|
||||
isSignedIn: boolean;
|
||||
|
||||
isPlaying: boolean;
|
||||
appContext: any | null;
|
||||
|
||||
browser: {
|
||||
capabilities: {
|
||||
|
@@ -8,6 +8,8 @@ import { BX_FLAGS } from "./bx-flags";
|
||||
import { NavigationDialogManager } from "@/modules/ui/dialog/navigation-dialog";
|
||||
import { PrefKey } from "@/enums/pref-keys";
|
||||
import { getPref, StreamTouchController } from "./settings-storages/global-settings-storage";
|
||||
import { GamePassCloudGallery } from "@/enums/game-pass-gallery";
|
||||
import { TouchController } from "@/modules/touch-controller";
|
||||
|
||||
export enum SupportedInputType {
|
||||
CONTROLLER = 'Controller',
|
||||
@@ -22,6 +24,48 @@ export type SupportedInputTypeValue = (typeof SupportedInputType)[keyof typeof S
|
||||
export const BxExposed = {
|
||||
getTitleInfo: () => STATES.currentStream.titleInfo,
|
||||
|
||||
modifyPreloadedState: isFullVersion() && ((state: any) => {
|
||||
let LOG_TAG = 'PreloadState';
|
||||
|
||||
// Override User-Agent
|
||||
try {
|
||||
state.appContext.requestInfo.userAgent = window.navigator.userAgent;
|
||||
} catch (e) {
|
||||
BxLogger.error(LOG_TAG, e);
|
||||
}
|
||||
|
||||
// Add list of games with custom layouts to the official list
|
||||
try {
|
||||
const sigls = state.xcloud.sigls;
|
||||
if (STATES.userAgent.capabilities.touch) {
|
||||
// The list of custom touch controls
|
||||
let customList = TouchController.getCustomList();
|
||||
|
||||
// Remove non-cloud games from the official list
|
||||
const allGames = sigls[GamePassCloudGallery.ALL].data.products;
|
||||
customList = customList.filter(id => allGames.includes(id));
|
||||
|
||||
// Add to the official touchlist
|
||||
sigls[GamePassCloudGallery.TOUCH]?.data.products.push(...customList);
|
||||
}
|
||||
} catch (e) {
|
||||
BxLogger.error(LOG_TAG, e);
|
||||
}
|
||||
|
||||
// Add forced Native MKB titles to the official list
|
||||
try {
|
||||
const sigls = state.xcloud.sigls;
|
||||
if (BX_FLAGS.ForceNativeMkbTitles) {
|
||||
// Add to the official list
|
||||
sigls[GamePassCloudGallery.NATIVE_MKB]?.data.products.push(...BX_FLAGS.ForceNativeMkbTitles);
|
||||
}
|
||||
} catch (e) {
|
||||
BxLogger.error(LOG_TAG, e);
|
||||
}
|
||||
|
||||
return state;
|
||||
}),
|
||||
|
||||
modifyTitleInfo: isFullVersion() && function(titleInfo: XcloudTitleInfo): XcloudTitleInfo {
|
||||
// Clone the object since the original is read-only
|
||||
titleInfo = deepClone(titleInfo);
|
||||
|
@@ -23,7 +23,6 @@ export const STATES: BxStates = {
|
||||
isSignedIn: false,
|
||||
|
||||
isPlaying: false,
|
||||
appContext: {},
|
||||
|
||||
browser: {
|
||||
capabilities: {
|
||||
|
@@ -1,56 +0,0 @@
|
||||
import { deepClone, STATES } from "@utils/global";
|
||||
import { BxLogger } from "./bx-logger";
|
||||
import { TouchController } from "@modules/touch-controller";
|
||||
import { GamePassCloudGallery } from "../enums/game-pass-gallery";
|
||||
import { BX_FLAGS } from "./bx-flags";
|
||||
|
||||
const LOG_TAG = 'PreloadState';
|
||||
|
||||
export function overridePreloadState() {
|
||||
let _state: any;
|
||||
|
||||
Object.defineProperty(window, '__PRELOADED_STATE__', {
|
||||
configurable: true,
|
||||
get: () => {
|
||||
return _state;
|
||||
},
|
||||
set: state => {
|
||||
// Override User-Agent
|
||||
try {
|
||||
state.appContext.requestInfo.userAgent = window.navigator.userAgent;
|
||||
} catch (e) {
|
||||
BxLogger.error(LOG_TAG, e);
|
||||
}
|
||||
|
||||
// Add list of games with custom layouts to the official list
|
||||
if (STATES.userAgent.capabilities.touch) {
|
||||
try {
|
||||
const sigls = state.xcloud.sigls;
|
||||
if (GamePassCloudGallery.TOUCH in sigls) {
|
||||
let customList = TouchController.getCustomList();
|
||||
|
||||
const allGames = sigls[GamePassCloudGallery.ALL].data.products;
|
||||
|
||||
// Remove non-cloud games from the list
|
||||
customList = customList.filter(id => allGames.includes(id));
|
||||
|
||||
// Add to the official list
|
||||
sigls[GamePassCloudGallery.TOUCH]?.data.products.push(...customList);
|
||||
}
|
||||
|
||||
if (BX_FLAGS.ForceNativeMkbTitles && GamePassCloudGallery.NATIVE_MKB in sigls) {
|
||||
// Add to the official list
|
||||
sigls[GamePassCloudGallery.NATIVE_MKB]?.data.products.push(...BX_FLAGS.ForceNativeMkbTitles);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
BxLogger.error(LOG_TAG, e);
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
_state = state;
|
||||
STATES.appContext = deepClone(state.appContext);
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user