mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37:19 +02:00
Move PatcherCache.init() to patchFunctionBind()
This commit is contained in:
parent
438afe086a
commit
f945a3adde
@ -520,8 +520,14 @@ const ALL_PATCHES = [...PATCH_ORDERS, ...PLAYING_PATCH_ORDERS];
|
|||||||
export class Patcher {
|
export class Patcher {
|
||||||
static #patchFunctionBind() {
|
static #patchFunctionBind() {
|
||||||
const nativeBind = Function.prototype.bind;
|
const nativeBind = Function.prototype.bind;
|
||||||
Function.prototype.bind = function () {
|
Function.prototype.bind = function() {
|
||||||
let valid = false;
|
let valid = false;
|
||||||
|
|
||||||
|
// Looking for these criteria:
|
||||||
|
// - Variable name <= 2 characters
|
||||||
|
// - Has 2 params:
|
||||||
|
// - The first one is null
|
||||||
|
// - The second one is either 0 or a function
|
||||||
if (this.name.length <= 2 && arguments.length === 2 && arguments[0] === null) {
|
if (this.name.length <= 2 && arguments.length === 2 && arguments[0] === null) {
|
||||||
if (arguments[1] === 0 || (typeof arguments[1] === 'function')) {
|
if (arguments[1] === 0 || (typeof arguments[1] === 'function')) {
|
||||||
valid = true;
|
valid = true;
|
||||||
@ -533,6 +539,8 @@ export class Patcher {
|
|||||||
return nativeBind.apply(this, arguments);
|
return nativeBind.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PatcherCache.init();
|
||||||
|
|
||||||
if (typeof arguments[1] === 'function') {
|
if (typeof arguments[1] === 'function') {
|
||||||
BxLogger.info(LOG_TAG, 'Restored Function.prototype.bind()');
|
BxLogger.info(LOG_TAG, 'Restored Function.prototype.bind()');
|
||||||
Function.prototype.bind = nativeBind;
|
Function.prototype.bind = nativeBind;
|
||||||
@ -635,6 +643,8 @@ export class PatcherCache {
|
|||||||
|
|
||||||
static #CACHE: any;
|
static #CACHE: any;
|
||||||
|
|
||||||
|
static #isInitialized = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get patch's signature
|
* Get patch's signature
|
||||||
*/
|
*/
|
||||||
@ -664,9 +674,6 @@ export class PatcherCache {
|
|||||||
window.localStorage.setItem(PatcherCache.#KEY_SIGNATURE, currentSig.toString());
|
window.localStorage.setItem(PatcherCache.#KEY_SIGNATURE, currentSig.toString());
|
||||||
|
|
||||||
PatcherCache.clear();
|
PatcherCache.clear();
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
window.location.reload(true);
|
|
||||||
} else {
|
} else {
|
||||||
BxLogger.info(LOG_TAG, 'Signature unchanged');
|
BxLogger.info(LOG_TAG, 'Signature unchanged');
|
||||||
}
|
}
|
||||||
@ -711,6 +718,13 @@ export class PatcherCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static init() {
|
static init() {
|
||||||
|
if (PatcherCache.#isInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PatcherCache.#isInitialized = true;
|
||||||
|
|
||||||
|
PatcherCache.checkSignature();
|
||||||
|
|
||||||
// Read cache from storage
|
// Read cache from storage
|
||||||
PatcherCache.#CACHE = JSON.parse(window.localStorage.getItem(PatcherCache.#KEY_CACHE) || '{}');
|
PatcherCache.#CACHE = JSON.parse(window.localStorage.getItem(PatcherCache.#KEY_CACHE) || '{}');
|
||||||
BxLogger.info(LOG_TAG, PatcherCache.#CACHE);
|
BxLogger.info(LOG_TAG, PatcherCache.#CACHE);
|
||||||
@ -729,11 +743,3 @@ export class PatcherCache {
|
|||||||
BxLogger.info(LOG_TAG, PLAYING_PATCH_ORDERS.slice(0));
|
BxLogger.info(LOG_TAG, PLAYING_PATCH_ORDERS.slice(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('readystatechange', e => {
|
|
||||||
if (document.readyState === 'interactive') {
|
|
||||||
PatcherCache.checkSignature();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
PatcherCache.init();
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user