mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-13 08:29:18 +02:00
Show local co-op icon in game card
This commit is contained in:
@@ -50,4 +50,50 @@ export class PatcherUtils {
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
private static isVarCharacter(char: string) {
|
||||
const code = char.charCodeAt(0);
|
||||
|
||||
// Check for uppercase letters (A-Z)
|
||||
const isUppercase = code >= 65 && code <= 90;
|
||||
|
||||
// Check for lowercase letters (a-z)
|
||||
const isLowercase = code >= 97 && code <= 122;
|
||||
|
||||
// Check for digits (0-9)
|
||||
const isDigit = code >= 48 && code <= 57;
|
||||
|
||||
// Check for special characters '_' and '$'
|
||||
const isSpecial = char === '_' || char === '$';
|
||||
|
||||
return isUppercase || isLowercase || isDigit || isSpecial;
|
||||
}
|
||||
|
||||
static getVariableNameBefore(str: string, index: number) {
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const end = index;
|
||||
let start = end - 1;
|
||||
while (PatcherUtils.isVarCharacter(str[start])) {
|
||||
start -= 1;
|
||||
}
|
||||
|
||||
return str.substring(start + 1, end);
|
||||
}
|
||||
|
||||
static getVariableNameAfter(str: string, index: number) {
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const start = index;
|
||||
let end = start + 1;
|
||||
while (PatcherUtils.isVarCharacter(str[end])) {
|
||||
end += 1;
|
||||
}
|
||||
|
||||
return str.substring(start, end);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import { BxEvent } from "@/utils/bx-event";
|
||||
import codeControllerCustomization from "./patches/controller-customization.js" with { type: "text" };
|
||||
import codePollGamepad from "./patches/poll-gamepad.js" with { type: "text" };
|
||||
import codeExposeStreamSession from "./patches/expose-stream-session.js" with { type: "text" };
|
||||
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" };
|
||||
@@ -1003,6 +1004,56 @@ ${subsVar} = subs;
|
||||
str = PatcherUtils.insertAt(str, index, newCode);
|
||||
return str;
|
||||
},
|
||||
|
||||
exposeReactCreateComponent(str: string) {
|
||||
let index = str.indexOf('.prototype.isReactComponent={}');
|
||||
|
||||
index > -1 && (index = PatcherUtils.indexOf(str, '.createElement=', index));
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = 'window.BX_EXPOSED.reactCreateElement=';
|
||||
str = PatcherUtils.insertAt(str, index - 1, newCode);
|
||||
|
||||
return str;
|
||||
},
|
||||
|
||||
// 27.0.6-hotfix.1, 73704.js
|
||||
gameCardCustomIcons(str: string) {
|
||||
let initialIndex = str.indexOf('const{supportedInputIcons:');
|
||||
if (initialIndex < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const returnIndex = PatcherUtils.lastIndexOf(str, 'return ', str.indexOf('SupportedInputsBadge'));
|
||||
if (returnIndex < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find function's parameter
|
||||
const arrowIndex = PatcherUtils.lastIndexOf(str, '=>{', initialIndex, 300);
|
||||
if (arrowIndex < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const paramVar = PatcherUtils.getVariableNameBefore(str, arrowIndex);
|
||||
|
||||
// Find supportedInputIcons and title var names
|
||||
const supportedInputIconsVar = PatcherUtils.getVariableNameAfter(str, PatcherUtils.indexOf(str, 'supportedInputIcons:', initialIndex, 100, true));
|
||||
|
||||
if (!paramVar || !supportedInputIconsVar) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = renderString(codeGameCardIcons, {
|
||||
param: paramVar,
|
||||
supportedInputIcons: supportedInputIconsVar,
|
||||
});
|
||||
|
||||
str = PatcherUtils.insertAt(str, returnIndex, newCode);
|
||||
return str;
|
||||
},
|
||||
};
|
||||
|
||||
let PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
@@ -1012,6 +1063,9 @@ let PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
'disableAbsoluteMouse',
|
||||
] : []),
|
||||
|
||||
'exposeReactCreateComponent',
|
||||
'gameCardCustomIcons',
|
||||
|
||||
'modifyPreloadedState',
|
||||
|
||||
'optimizeGameSlugGenerator',
|
||||
|
9
src/modules/patcher/patches/src/game-card-icons.ts
Normal file
9
src/modules/patcher/patches/src/game-card-icons.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
declare const $supportedInputIcons$: Array<any>;
|
||||
declare const $param$: { productId: string };
|
||||
|
||||
const supportedInputIcons = $supportedInputIcons$;
|
||||
const { productId } = $param$;
|
||||
|
||||
if (window.BX_EXPOSED.localCoOpManager.isSupported(productId)) {
|
||||
supportedInputIcons.push(() => window.BX_EXPOSED.createReactLocalCoOpIcon());
|
||||
}
|
Reference in New Issue
Block a user