diff --git a/src/modules/touch-controller.ts b/src/modules/touch-controller.ts index dfbc082..c48975b 100644 --- a/src/modules/touch-controller.ts +++ b/src/modules/touch-controller.ts @@ -10,8 +10,6 @@ import { BxLogger } from "@utils/bx-logger"; const LOG_TAG = 'TouchController'; -export const GALLERY_TOUCH_GAMES = '9c86f07a-f3e8-45ad-82a0-a1f759597059'; - export class TouchController { static readonly #EVENT_SHOW_DEFAULT_CONTROLLER = new MessageEvent('message', { data: '{"content":"{\\"layoutId\\":\\"\\"}","target":"/streaming/touchcontrols/showlayoutv2","type":"Message"}', diff --git a/src/utils/gamepass-gallery.ts b/src/utils/gamepass-gallery.ts new file mode 100644 index 0000000..c657b74 --- /dev/null +++ b/src/utils/gamepass-gallery.ts @@ -0,0 +1,4 @@ +export enum GamePassCloudGallery { + TOUCH = '9c86f07a-f3e8-45ad-82a0-a1f759597059', + ALL = '29a81209-df6f-41fd-a528-2ae6b91f719c', +} diff --git a/src/utils/network.ts b/src/utils/network.ts index 40e3f6f..541eb7a 100644 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -4,9 +4,10 @@ import { LoadingScreen } from "@modules/loading-screen"; import { PrefKey, getPref } from "@utils/preferences"; import { RemotePlay } from "@modules/remote-play"; import { StreamBadges } from "@modules/stream/stream-badges"; -import { GALLERY_TOUCH_GAMES, TouchController } from "@modules/touch-controller"; +import { TouchController } from "@modules/touch-controller"; import { STATES } from "@utils/global"; import { getPreferredServerRegion } from "@utils/region"; +import { GamePassCloudGallery } from "./gamepass-gallery"; export const NATIVE_FETCH = window.fetch; @@ -526,6 +527,8 @@ export function interceptHttpRequests() { return nativeXhrSend.apply(this, arguments); }; + let gamepassAllGames: string[] = []; + (window as any).BX_FETCH = window.fetch = async (request: RequestInfo | URL, init?: RequestInit): Promise => { let url = (typeof request === 'string') ? request : (request as Request).url; @@ -550,14 +553,27 @@ export function interceptHttpRequests() { } // Add list of games with custom layouts to the official list - if (url.includes('catalog.gamepass.com') && url.includes(GALLERY_TOUCH_GAMES)) { + if (STATES.hasTouchSupport && url.includes('catalog.gamepass.com/sigls/')) { const response = await NATIVE_FETCH(request, init); const obj = await response.clone().json(); - try { - const customList = TouchController.getCustomList().map(item => ({ id: item })); - obj.push(...customList); - } catch (e) {} + if (url.includes(GamePassCloudGallery.ALL)) { + debugger; + for (let i = 1; i < obj.length; i++) { + gamepassAllGames.push(obj[i].id); + } + } else if (url.includes(GamePassCloudGallery.TOUCH)) { + debugger; + try { + let customList = TouchController.getCustomList(); + + // Remove non-cloud games from the list + customList = customList.filter(id => gamepassAllGames.includes(id)); + + const newCustomList = customList.map(item => ({ id: item })); + obj.push(...newCustomList); + } catch (e) {} + } response.json = () => Promise.resolve(obj); return response; diff --git a/src/utils/preload-state.ts b/src/utils/preload-state.ts index 8b1db1e..5e1d2bb 100644 --- a/src/utils/preload-state.ts +++ b/src/utils/preload-state.ts @@ -1,7 +1,8 @@ import { STATES } from "@utils/global"; import { UserAgent } from "@utils/user-agent"; import { BxLogger } from "./bx-logger"; -import { GALLERY_TOUCH_GAMES, TouchController } from "@modules/touch-controller"; +import { TouchController } from "@modules/touch-controller"; +import { GamePassCloudGallery } from "./gamepass-gallery"; const LOG_TAG = 'PreloadState'; @@ -29,10 +30,19 @@ export function overridePreloadState() { // Add list of games with custom layouts to the official list if (STATES.hasTouchSupport) { TouchController.updateCustomList(); - const customList = TouchController.getCustomList(); + let customList = TouchController.getCustomList(); try { - state.xcloud.sigls[GALLERY_TOUCH_GAMES]?.data.products.push(...customList); + const sigls = state.xcloud.sigls; + if (GamePassCloudGallery.TOUCH in sigls) { + 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); + } } catch (e) { BxLogger.error(LOG_TAG, e); }