mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Create PatcherUtils
This commit is contained in:
parent
a77460e242
commit
8c7e4650d4
46
dist/better-xcloud.user.js
vendored
46
dist/better-xcloud.user.js
vendored
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud
|
// @name Better xCloud
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 5.5.2
|
// @version 5.5.3-beta
|
||||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||||
// @author redphx
|
// @author redphx
|
||||||
// @license MIT
|
// @license MIT
|
||||||
@ -120,7 +120,7 @@ function deepClone(obj) {
|
|||||||
return {};
|
return {};
|
||||||
return JSON.parse(JSON.stringify(obj));
|
return JSON.parse(JSON.stringify(obj));
|
||||||
}
|
}
|
||||||
var SCRIPT_VERSION = "5.5.2", AppInterface = window.AppInterface;
|
var SCRIPT_VERSION = "5.5.3-beta", AppInterface = window.AppInterface;
|
||||||
UserAgent.init();
|
UserAgent.init();
|
||||||
var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = {
|
var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = {
|
||||||
supportedRegion: !0,
|
supportedRegion: !0,
|
||||||
@ -3592,14 +3592,34 @@ if (getPref("block_social_features"))
|
|||||||
if (BX_FLAGS.FeatureGates)
|
if (BX_FLAGS.FeatureGates)
|
||||||
FeatureGates = Object.assign(BX_FLAGS.FeatureGates, FeatureGates);
|
FeatureGates = Object.assign(BX_FLAGS.FeatureGates, FeatureGates);
|
||||||
|
|
||||||
|
class PatcherUtils {
|
||||||
|
static indexOf(txt, searchString, startIndex, maxRange) {
|
||||||
|
const index = txt.indexOf(searchString, startIndex);
|
||||||
|
if (index < 0 || maxRange && index - startIndex > maxRange)
|
||||||
|
return -1;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
static lastIndexOf(txt, searchString, startIndex, maxRange) {
|
||||||
|
const index = txt.lastIndexOf(searchString, startIndex);
|
||||||
|
if (index < 0 || maxRange && startIndex - index > maxRange)
|
||||||
|
return -1;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
static insertAt(txt, index, insertString) {
|
||||||
|
return txt.substring(0, index) + insertString + txt.substring(index);
|
||||||
|
}
|
||||||
|
static replaceWith(txt, index, fromString, toString) {
|
||||||
|
return txt.substring(0, index) + toString + txt.substring(index + fromString.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
var ENDING_CHUNKS_PATCH_NAME = "loadingEndingChunks", LOG_TAG3 = "Patcher", PATCHES = {
|
var ENDING_CHUNKS_PATCH_NAME = "loadingEndingChunks", LOG_TAG3 = "Patcher", PATCHES = {
|
||||||
disableAiTrack(str) {
|
disableAiTrack(str) {
|
||||||
const index = str.indexOf(".track=function(");
|
const index = str.indexOf(".track=function(");
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
if (str.substring(0, index + 200).includes('"AppInsightsCore'))
|
if (PatcherUtils.indexOf(str, '"AppInsightsCore', index, 200) < 0)
|
||||||
return !1;
|
return !1;
|
||||||
return str.substring(0, index) + ".track=function(e){},!!function(" + str.substring(index + ".track=function(".length);
|
return PatcherUtils.replaceWith(str, ".track=function(", ".track=function(e){},!!function(", index);
|
||||||
},
|
},
|
||||||
disableTelemetry(str) {
|
disableTelemetry(str) {
|
||||||
if (!str.includes(".disableTelemetry=function(){return!1}"))
|
if (!str.includes(".disableTelemetry=function(){return!1}"))
|
||||||
@ -3953,31 +3973,33 @@ true,this._connectionType=`;
|
|||||||
let index = str.indexOf('location:"PlayWithFriendsRow",');
|
let index = str.indexOf('location:"PlayWithFriendsRow",');
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
if (index = str.indexOf("return", index - 50), index < 0)
|
if (index = PatcherUtils.lastIndexOf(str, "return", index, 50), index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
return str = str.substring(0, index) + "return null;" + str.substring(index + 6), str;
|
return str = PatcherUtils.replaceWith(str, index, "return", "return null;"), str;
|
||||||
},
|
},
|
||||||
ignoreAllGamesSection(str) {
|
ignoreAllGamesSection(str) {
|
||||||
let index = str.indexOf('className:"AllGamesRow-module__allGamesRowContainer');
|
let index = str.indexOf('className:"AllGamesRow-module__allGamesRowContainer');
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
if (index = str.indexOf("grid:!0,", index), index > -1 && (index = str.indexOf("(0,", index - 70)), index < 0)
|
if (index = PatcherUtils.indexOf(str, "grid:!0,", index, 1500), index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
return str = str.substring(0, index) + "true ? null :" + str.substring(index), str;
|
if (index = PatcherUtils.lastIndexOf(str, "(0,", index, 70), index < 0)
|
||||||
|
return !1;
|
||||||
|
return str = PatcherUtils.insertAt(str, index, "true ? null :"), str;
|
||||||
},
|
},
|
||||||
ignorePlayWithTouchSection(str) {
|
ignorePlayWithTouchSection(str) {
|
||||||
let index = str.indexOf('("Play_With_Touch"),');
|
let index = str.indexOf('("Play_With_Touch"),');
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
if (index = str.indexOf("const ", index - 30), index < 0)
|
if (index = PatcherUtils.lastIndexOf(str, "const ", index, 30), index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
return str = str.substring(0, index) + "return null;" + str.substring(index), str;
|
return str = PatcherUtils.insertAt(str, index, "return null;"), str;
|
||||||
},
|
},
|
||||||
ignoreSiglSections(str) {
|
ignoreSiglSections(str) {
|
||||||
let index = str.indexOf("SiglRow-module__heroCard___");
|
let index = str.indexOf("SiglRow-module__heroCard___");
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
if (index = str.indexOf("const[", index - 300), index < 0)
|
if (index = PatcherUtils.lastIndexOf(str, "const[", index, 300), index < 0)
|
||||||
return !1;
|
return !1;
|
||||||
const PREF_HIDE_SECTIONS = getPref("ui_hide_sections"), siglIds = [], sections = {
|
const PREF_HIDE_SECTIONS = getPref("ui_hide_sections"), siglIds = [], sections = {
|
||||||
"native-mkb": "8fa264dd-124f-4af3-97e8-596fcdf4b486",
|
"native-mkb": "8fa264dd-124f-4af3-97e8-596fcdf4b486",
|
||||||
@ -3995,7 +4017,7 @@ if (e && e.id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
return str = str.substring(0, index) + newCode + str.substring(index), str;
|
return str = PatcherUtils.insertAt(str, index, newCode), str;
|
||||||
},
|
},
|
||||||
overrideStorageGetSettings(str) {
|
overrideStorageGetSettings(str) {
|
||||||
if (!str.includes("}getSetting(e){"))
|
if (!str.includes("}getSetting(e){"))
|
||||||
|
@ -20,8 +20,35 @@ import { GamePassCloudGallery } from "@/enums/game-pass-gallery.js";
|
|||||||
|
|
||||||
type PatchArray = (keyof typeof PATCHES)[];
|
type PatchArray = (keyof typeof PATCHES)[];
|
||||||
|
|
||||||
const ENDING_CHUNKS_PATCH_NAME = 'loadingEndingChunks';
|
class PatcherUtils {
|
||||||
|
static indexOf(txt: string, searchString: string, startIndex: number, maxRange: number): number {
|
||||||
|
const index = txt.indexOf(searchString, startIndex);
|
||||||
|
if (index < 0 || (maxRange && index - startIndex > maxRange)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
static lastIndexOf(txt: string, searchString: string, startIndex: number, maxRange: number): number {
|
||||||
|
const index = txt.lastIndexOf(searchString, startIndex);
|
||||||
|
if (index < 0 || (maxRange && startIndex - index > maxRange)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
static insertAt(txt: string, index: number, insertString: string): string {
|
||||||
|
return txt.substring(0, index) + insertString + txt.substring(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static replaceWith(txt: string, index: number, fromString: string, toString: string): string {
|
||||||
|
return txt.substring(0, index) + toString + txt.substring(index + fromString.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ENDING_CHUNKS_PATCH_NAME = 'loadingEndingChunks';
|
||||||
const LOG_TAG = 'Patcher';
|
const LOG_TAG = 'Patcher';
|
||||||
|
|
||||||
const PATCHES = {
|
const PATCHES = {
|
||||||
@ -33,11 +60,11 @@ const PATCHES = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str.substring(0, index + 200).includes('"AppInsightsCore')) {
|
if (PatcherUtils.indexOf(str, '"AppInsightsCore', index, 200) < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.substring(0, index) + '.track=function(e){},!!function(' + str.substring(index + text.length);
|
return PatcherUtils.replaceWith(str, text, '.track=function(e){},!!function(', index);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set disableTelemetry() to true
|
// Set disableTelemetry() to true
|
||||||
@ -716,12 +743,12 @@ true` + text;
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = str.indexOf('return', index - 50);
|
index = PatcherUtils.lastIndexOf(str, 'return', index, 50);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str.substring(0, index) + 'return null;' + str.substring(index + 6);
|
str = PatcherUtils.replaceWith(str, index, 'return', 'return null;');
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -732,14 +759,17 @@ true` + text;
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = str.indexOf('grid:!0,', index);
|
index = PatcherUtils.indexOf(str, 'grid:!0,', index, 1500);
|
||||||
index > -1 && (index = str.indexOf('(0,', index - 70));
|
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str.substring(0, index) + 'true ? null :' + str.substring(index);
|
index = PatcherUtils.lastIndexOf(str, '(0,', index, 70);
|
||||||
|
if (index < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = PatcherUtils.insertAt(str, index, 'true ? null :');
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -750,12 +780,12 @@ true` + text;
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = str.indexOf('const ', index - 30);
|
index = PatcherUtils.lastIndexOf(str, 'const ', index, 30);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str.substring(0, index) + 'return null;' + str.substring(index);
|
str = PatcherUtils.insertAt(str, index, 'return null;');
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -766,7 +796,7 @@ true` + text;
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = str.indexOf('const[', index - 300);
|
index = PatcherUtils.lastIndexOf(str, 'const[', index, 300);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -794,7 +824,7 @@ if (e && e.id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
str = str.substring(0, index) + newCode + str.substring(index);
|
str = PatcherUtils.insertAt(str, index, newCode);
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user