Define types for Patcher

This commit is contained in:
redphx 2025-02-08 09:57:42 +07:00
parent 2f8c776133
commit b463e4f014
5 changed files with 112 additions and 84 deletions

View File

@ -5186,8 +5186,7 @@ class PatcherUtils {
var LOG_TAG2 = "Patcher", PATCHES = {
disableAiTrack(str) {
let text = ".track=function(", index = str.indexOf(text);
if (index < 0) return !1;
if (PatcherUtils.indexOf(str, '"AppInsightsCore', index, 200) < 0) return !1;
if (index < 0 || PatcherUtils.indexOf(str, '"AppInsightsCore', index, 200) < 0) return !1;
return PatcherUtils.replaceWith(str, index, text, ".track=function(e){},!!function(");
},
disableTelemetry(str) {
@ -5734,32 +5733,32 @@ ${subsVar} = subs;
] : [],
"exposeReactCreateComponent",
"injectCreatePortal",
"injectGuideHomeUseEffect",
"injectHeaderUseEffect",
"injectErrorPageUseEffect",
"injectAchievementsProgressUseEffect",
"injectAchievementsDetailUseEffect",
"gameCardCustomIcons",
"broadcastPollingMode",
getGlobalPref("ui.gameCard.waitTime.show") && "patchSetCurrentFocus",
"patchGamepadPolling",
"optimizeGameSlugGenerator",
"modifyPreloadedState",
"detectBrowserRouterReady",
"exposeStreamSession",
"supportLocalCoOp",
"disableStreamGate",
"exposeDialogRoutes",
...getGlobalPref("ui.imageQuality") < 90 ? [
"setImageQuality"
] : [],
"modifyPreloadedState",
"optimizeGameSlugGenerator",
"detectBrowserRouterReady",
"patchRequestInfoCrash",
"disableStreamGate",
"broadcastPollingMode",
"patchGamepadPolling",
"exposeStreamSession",
"exposeDialogRoutes",
"homePageBeforeLoad",
"productDetailPageBeforeLoad",
"injectErrorPageUseEffect",
"streamPageBeforeLoad",
"injectGuideHomeUseEffect",
"injectAchievementsProgressUseEffect",
"injectAchievementsDetailUseEffect",
"guideAchievementsDefaultLocked",
"injectHeaderUseEffect",
"homePageBeforeLoad",
"gameCardCustomIcons",
"productDetailPageBeforeLoad",
"enableTvRoutes",
"supportLocalCoOp",
"overrideStorageGetSettings",
getGlobalPref("ui.gameCard.waitTime.show") && "patchSetCurrentFocus",
getGlobalPref("ui.layout") !== "default" && "websiteLayout",
getGlobalPref("game.fortnite.forceConsole") && "forceFortniteConsole",
...STATES.userAgent.capabilities.touch ? [
@ -5773,11 +5772,11 @@ ${subsVar} = subs;
"disableTelemetryProvider"
] : [],
...getGlobalPref("xhome.enabled") ? [
"remotePlayKeepAlive",
"remotePlayDirectConnectUrl",
"remotePlayKeepAlive",
"remotePlayWebTitle",
"remotePlayDisableAchievementToast",
"remotePlayRecentlyUsedTitleIds",
"remotePlayWebTitle",
STATES.userAgent.capabilities.touch && "patchUpdateInputConfigurationAsync"
] : [],
...BX_FLAGS.EnableXcloudLogging ? [
@ -5785,16 +5784,14 @@ ${subsVar} = subs;
"enableXcloudLogger"
] : []
]), hideSections = getGlobalPref("ui.hideSections"), HOME_PAGE_PATCH_ORDERS = PatcherUtils.filterPatches([
hideSections.includes("news") && "ignoreNewsSection",
(getGlobalPref("block.features").includes("friends") || hideSections.includes("friends")) && "ignorePlayWithFriendsSection",
hideSections.includes("all-games") && "ignoreAllGamesSection",
hideSections.includes("genres") && "ignoreGenresSection",
!getGlobalPref("block.features").includes("byog") && hideSections.includes("byog") && "ignoreByogSection",
STATES.browser.capabilities.touch && hideSections.includes("touch") && "ignorePlayWithTouchSection",
getGlobalPref("ui.imageQuality") < 90 && "setBackgroundImageQuality",
hideSections.some((value) => ["native-mkb", "most-popular"].includes(value)) && "ignoreSiglSections",
...getGlobalPref("ui.imageQuality") < 90 ? [
"setBackgroundImageQuality"
] : [],
hideSections.includes("news") && "ignoreNewsSection",
(getGlobalPref("block.features").includes("friends") || hideSections.includes("friends")) && "ignorePlayWithFriendsSection",
hideSections.includes("all-games") && "ignoreAllGamesSection",
...blockSomeNotifications() ? [
"changeNotificationsSubscription"
] : []

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,4 @@
import type { ScriptEvents, StreamEvents } from "@/utils/bx-event-bus";
import type { PatchArray, PatchName, PatchPage } from "./patcher";
export class PatcherUtils {
@ -35,7 +36,7 @@ export class PatcherUtils {
return txt.substring(0, index) + toString + txt.substring(index + fromString.length);
}
static filterPatches(patches: Array<string | false>): PatchArray {
static filterPatches(patches: Array<PatchName | false>): PatchArray {
return patches.filter((item): item is PatchName => !!item);
}
@ -97,7 +98,7 @@ export class PatcherUtils {
return str.substring(start, end);
}
static injectUseEffect(str: string, index: number, group: 'Stream' | 'Script', eventName: string) {
static injectUseEffect<T extends 'Stream' | 'Script'>(str: string, index: number, group: T, eventName: T extends 'Stream' ? keyof StreamEvents : keyof ScriptEvents) {
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.${group}.emit('${eventName}', {}), []);`;
str = PatcherUtils.insertAt(str, index, newCode);

View File

@ -23,6 +23,7 @@ import { PatcherUtils } from "./patcher-utils.js";
export type PatchName = keyof typeof PATCHES;
export type PatchArray = PatchName[];
export type PatchPage = 'home' | 'stream' | 'product-detail';
type PatchFunction = (str: string) => string | false;
const LOG_TAG = 'Patcher';
@ -31,11 +32,7 @@ const PATCHES = {
disableAiTrack(str: string) {
let text = '.track=function(';
const index = str.indexOf(text);
if (index < 0) {
return false;
}
if (PatcherUtils.indexOf(str, '"AppInsightsCore', index, 200) < 0) {
if (index < 0 || PatcherUtils.indexOf(str, '"AppInsightsCore', index, 200) < 0) {
return false;
}
@ -1204,62 +1201,95 @@ ${subsVar} = subs;
return PatcherUtils.injectUseEffect(str, index, 'Script', 'ui.guideAchievementDetail.rendered');
},
};
/*
patchBasicGameInfo(str: string) {
let index = str.indexOf('.ChildXboxTitleIds,offerings');
index > -1 && (index = PatcherUtils.lastIndexOf(str, 'return{', index, 1000));
if (index < 0) {
return false;
}
const varName = PatcherUtils.getVariableNameBefore(str, PatcherUtils.lastIndexOf(str, '=>{', index));
if (!varName) {
return false;
}
const newCode = `
const info = ${varName};
if (info.ProductTitle.includes('Xbox One')) {
return {};
}
`;
str = PatcherUtils.insertAt(str, index, newCode);
return str;
},
*/
} as const satisfies { [key: string]: PatchFunction };
let PATCH_ORDERS = PatcherUtils.filterPatches([
...(AppInterface && getGlobalPref(GlobalPref.NATIVE_MKB_MODE) === NativeMkbMode.ON ? [
'enableNativeMkb',
'disableAbsoluteMouse',
] : []),
] : []) as PatchArray,
'exposeReactCreateComponent',
'injectCreatePortal',
'injectGuideHomeUseEffect',
'injectHeaderUseEffect',
'broadcastPollingMode',
getGlobalPref(GlobalPref.UI_GAME_CARD_SHOW_WAIT_TIME) && 'patchSetCurrentFocus',
'patchGamepadPolling',
'optimizeGameSlugGenerator',
'modifyPreloadedState',
'detectBrowserRouterReady',
'exposeStreamSession',
'supportLocalCoOp',
'disableStreamGate',
'exposeDialogRoutes',
...(getGlobalPref(GlobalPref.UI_IMAGE_QUALITY) < 90 ? [
'setImageQuality',
] : []) as PatchArray,
'patchRequestInfoCrash',
'injectErrorPageUseEffect',
'streamPageBeforeLoad',
'injectGuideHomeUseEffect',
'injectAchievementsProgressUseEffect',
'injectAchievementsDetailUseEffect',
'guideAchievementsDefaultLocked',
'injectHeaderUseEffect',
'homePageBeforeLoad',
'gameCardCustomIcons',
// 'gameCardPassTitle',
...(getGlobalPref(GlobalPref.UI_IMAGE_QUALITY) < 90 ? [
'setImageQuality',
] : []),
'modifyPreloadedState',
'optimizeGameSlugGenerator',
'detectBrowserRouterReady',
'patchRequestInfoCrash',
'disableStreamGate',
'broadcastPollingMode',
'patchGamepadPolling',
'exposeStreamSession',
'exposeDialogRoutes',
'homePageBeforeLoad',
'productDetailPageBeforeLoad',
'streamPageBeforeLoad',
'guideAchievementsDefaultLocked',
'enableTvRoutes',
'supportLocalCoOp',
'overrideStorageGetSettings',
getGlobalPref(GlobalPref.UI_GAME_CARD_SHOW_WAIT_TIME) && 'patchSetCurrentFocus',
getGlobalPref(GlobalPref.UI_LAYOUT) !== UiLayout.DEFAULT && 'websiteLayout',
getGlobalPref(GlobalPref.GAME_FORTNITE_FORCE_CONSOLE) && 'forceFortniteConsole',
...(STATES.userAgent.capabilities.touch ? [
'disableTouchContextMenu',
] : []),
] : []) as PatchArray,
...(getGlobalPref(GlobalPref.BLOCK_TRACKING) ? [
'disableAiTrack',
@ -1269,41 +1299,41 @@ let PATCH_ORDERS = PatcherUtils.filterPatches([
'disableIndexDbLogging',
'disableTelemetryProvider',
] : []),
] : []) as PatchArray,
...(getGlobalPref(GlobalPref.REMOTE_PLAY_ENABLED) ? [
'remotePlayKeepAlive',
'remotePlayDirectConnectUrl',
'remotePlayKeepAlive',
'remotePlayWebTitle',
'remotePlayDisableAchievementToast',
'remotePlayRecentlyUsedTitleIds',
'remotePlayWebTitle',
STATES.userAgent.capabilities.touch && 'patchUpdateInputConfigurationAsync',
] : []),
] : []) as PatchArray,
...(BX_FLAGS.EnableXcloudLogging ? [
'enableConsoleLogging',
'enableXcloudLogger',
] : []),
] : []) as PatchArray,
]);
const hideSections = getGlobalPref(GlobalPref.UI_HIDE_SECTIONS);
let HOME_PAGE_PATCH_ORDERS = PatcherUtils.filterPatches([
hideSections.includes(UiSection.NEWS) && 'ignoreNewsSection',
(getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.FRIENDS) || hideSections.includes(UiSection.FRIENDS)) && 'ignorePlayWithFriendsSection',
hideSections.includes(UiSection.ALL_GAMES) && 'ignoreAllGamesSection',
hideSections.includes(UiSection.GENRES) && 'ignoreGenresSection',
!getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.BYOG) && hideSections.includes(UiSection.BOYG) && 'ignoreByogSection',
STATES.browser.capabilities.touch && hideSections.includes(UiSection.TOUCH) && 'ignorePlayWithTouchSection',
getGlobalPref(GlobalPref.UI_IMAGE_QUALITY) < 90 && 'setBackgroundImageQuality',
hideSections.some(value => [UiSection.NATIVE_MKB, UiSection.MOST_POPULAR].includes(value)) && 'ignoreSiglSections',
...(getGlobalPref(GlobalPref.UI_IMAGE_QUALITY) < 90 ? [
'setBackgroundImageQuality',
] : []),
hideSections.includes(UiSection.NEWS) && 'ignoreNewsSection',
(getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.FRIENDS) || hideSections.includes(UiSection.FRIENDS)) && 'ignorePlayWithFriendsSection',
hideSections.includes(UiSection.ALL_GAMES) && 'ignoreAllGamesSection',
...(blockSomeNotifications() ? [
'changeNotificationsSubscription',
] : []),
] : []) as PatchArray,
]);
// Only when playing
@ -1335,7 +1365,7 @@ let STREAM_PAGE_PATCH_ORDERS = PatcherUtils.filterPatches([
(getGlobalPref(GlobalPref.TOUCH_CONTROLLER_MODE) === TouchControllerMode.OFF || getGlobalPref(GlobalPref.TOUCH_CONTROLLER_AUTO_OFF)) && 'disableTakRenderer',
getGlobalPref(GlobalPref.TOUCH_CONTROLLER_DEFAULT_OPACITY) !== 100 && 'patchTouchControlDefaultOpacity',
(getGlobalPref(GlobalPref.TOUCH_CONTROLLER_MODE) !== TouchControllerMode.OFF && (getGlobalPref(GlobalPref.MKB_ENABLED) || getGlobalPref(GlobalPref.NATIVE_MKB_MODE) === NativeMkbMode.ON)) && 'patchBabylonRendererClass',
] : []),
] : []) as PatchArray,
BX_FLAGS.EnableXcloudLogging && 'enableConsoleLogging',
@ -1346,13 +1376,13 @@ let STREAM_PAGE_PATCH_ORDERS = PatcherUtils.filterPatches([
...(getGlobalPref(GlobalPref.REMOTE_PLAY_ENABLED) ? [
'patchRemotePlayMkb',
'remotePlayConnectMode',
] : []),
] : []) as PatchArray,
// Native MKB
...(AppInterface && getGlobalPref(GlobalPref.NATIVE_MKB_MODE) === NativeMkbMode.ON ? [
'patchMouseAndKeyboardEnabled',
'disableNativeRequestPointerLock',
] : []),
] : []) as PatchArray,
]);
let PRODUCT_DETAIL_PAGE_PATCH_ORDERS = PatcherUtils.filterPatches([

View File

@ -7,7 +7,7 @@ import type { SpeakerState } from "@/modules/shortcuts/sound-shortcut";
type EventCallback<T = any> = (payload: T) => void;
type ScriptEvents = {
export type ScriptEvents = {
'xcloud.server': {
status: 'ready' | 'unavailable' | 'signed-out',
};
@ -44,7 +44,7 @@ type ScriptEvents = {
'ui.guideAchievementDetail.rendered': {},
};
type StreamEvents = {
export type StreamEvents = {
'state.loading': {};
'state.starting': {};
'state.playing': { $video?: HTMLVideoElement };