Add back the ability to use native MKB feature on unofficial titles

This commit is contained in:
redphx
2024-06-02 10:43:59 +07:00
parent 850afb4ca7
commit 2e0a59cbe1
6 changed files with 90 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ import { STATES } from "@utils/global";
import { getPref, PrefKey } from "@utils/preferences";
import { UserAgent } from "@utils/user-agent";
import { BxLogger } from "./bx-logger";
import { BX_FLAGS } from "./bx-flags";
export enum InputType {
CONTROLLER = 'Controller',
@@ -26,6 +27,8 @@ export const BxExposed = {
// Remove native MKB support on mobile browsers or by user's choice
if (getPref(PrefKey.NATIVE_MKB_DISABLED) || UserAgent.isMobile()) {
supportedInputTypes = supportedInputTypes.filter(i => i !== InputType.MKB);
} else if (BX_FLAGS.ForceNativeMkbTitles.includes(titleInfo.details.productId)) {
supportedInputTypes.push(InputType.MKB);
}
titleInfo.details.hasMkbSupport = supportedInputTypes.includes(InputType.MKB);

View File

@@ -1,12 +1,14 @@
type BxFlags = {
CheckForUpdate?: boolean;
PreloadRemotePlay?: boolean;
PreloadUi?: boolean;
EnableXcloudLogging?: boolean;
SafariWorkaround?: boolean;
type BxFlags = Partial<{
CheckForUpdate: boolean;
PreloadRemotePlay: boolean;
PreloadUi: boolean;
EnableXcloudLogging: boolean;
SafariWorkaround: boolean;
UseDevTouchLayout?: boolean;
}
UseDevTouchLayout: boolean;
ForceNativeMkbTitles: string[];
}>
// Setup flags
const DEFAULT_FLAGS: BxFlags = {
@@ -17,6 +19,8 @@ const DEFAULT_FLAGS: BxFlags = {
SafariWorkaround: true,
UseDevTouchLayout: false,
ForceNativeMkbTitles: [],
}
export const BX_FLAGS = Object.assign(DEFAULT_FLAGS, window.BX_FLAGS || {});

View File

@@ -1,4 +1,5 @@
export enum GamePassCloudGallery {
TOUCH = '9c86f07a-f3e8-45ad-82a0-a1f759597059',
ALL = '29a81209-df6f-41fd-a528-2ae6b91f719c',
NATIVE_MKB = '8fa264dd-124f-4af3-97e8-596fcdf4b486',
TOUCH = '9c86f07a-f3e8-45ad-82a0-a1f759597059',
}

View File

@@ -439,12 +439,20 @@ class XcloudInterceptor {
overrides.inputConfiguration = overrides.inputConfiguration || {};
overrides.inputConfiguration.enableVibration = true;
let overrideMkb: boolean | null = null;
if (getPref(PrefKey.NATIVE_MKB_DISABLED) || UserAgent.isMobile()) {
overrideMkb = false;
} else if (BX_FLAGS.ForceNativeMkbTitles.includes(STATES.currentStream.titleInfo!.details.productId)) {
overrideMkb = true;
}
if (overrideMkb !== null) {
overrides.inputConfiguration = Object.assign(overrides.inputConfiguration, {
enableMouseInput: false,
enableAbsoluteMouse: false,
enableKeyboardInput: false,
});
enableMouseInput: overrideMkb,
enableAbsoluteMouse: overrideMkb,
enableKeyboardInput: overrideMkb,
});
}
overrides.videoConfiguration = overrides.videoConfiguration || {};
@@ -614,6 +622,21 @@ export function interceptHttpRequests() {
return response;
}
if (BX_FLAGS.ForceNativeMkbTitles && url.includes('catalog.gamepass.com/sigls/') && url.includes(GamePassCloudGallery.NATIVE_MKB)) {
const response = await NATIVE_FETCH(request, init);
const obj = await response.clone().json();
try {
const newCustomList = BX_FLAGS.ForceNativeMkbTitles.map((item: string) => ({ id: item }));
obj.push(...newCustomList);
} catch (e) {
console.log(e);
}
response.json = () => Promise.resolve(obj);
return response;
}
let requestType: RequestType;
if (url.includes('/sessions/home') || url.includes('xhome.') || (STATES.remotePlay.isPlaying && url.endsWith('/inputconfigs'))) {
requestType = RequestType.XHOME;

View File

@@ -3,6 +3,7 @@ import { BxLogger } from "./bx-logger";
import { TouchController } from "@modules/touch-controller";
import { GamePassCloudGallery } from "./gamepass-gallery";
import { getPref, PrefKey } from "./preferences";
import { BX_FLAGS } from "./bx-flags";
const LOG_TAG = 'PreloadState';
@@ -37,6 +38,12 @@ export function overridePreloadState() {
// 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);
}