Fix touch control not showing when using "caches" as variable name

This commit is contained in:
redphx 2024-05-04 11:21:18 +07:00
parent 176e86c9bb
commit f36c77e727
2 changed files with 39 additions and 31 deletions

View File

@ -549,23 +549,23 @@ export class Patcher {
}; };
} }
static length() { return PATCH_ORDERS.length; };
static patch(item: [[number], { [key: string]: () => {} }]) { static patch(item: [[number], { [key: string]: () => {} }]) {
// !!! Use "caches" as variable name will break touch controller???
// console.log('patch', '-----'); // console.log('patch', '-----');
let patchesToCheck: PatchArray; let patchesToCheck: PatchArray;
let appliedPatches; let appliedPatches: PatchArray;
const caches: { [key: string]: string[] } = {};
const patchesMap: { [key: string]: PatchArray } = {};
for (let id in item[1]) { for (let id in item[1]) {
appliedPatches = []; appliedPatches = [];
const cachedPatches = PatcherCache.getPatches(id); const cachedPatches = PatcherCache.getPatches(id);
if (cachedPatches) { if (cachedPatches) {
patchesToCheck = cachedPatches; patchesToCheck = cachedPatches.slice(0);
patchesToCheck.push(...PATCH_ORDERS); patchesToCheck.push(...PATCH_ORDERS);
} else { } else {
patchesToCheck = PATCH_ORDERS; patchesToCheck = PATCH_ORDERS.slice(0);
} }
// Empty patch list // Empty patch list
@ -573,20 +573,21 @@ export class Patcher {
continue; continue;
} }
// console.log(patchesToCheck);
const func = item[1][id]; const func = item[1][id];
let str = func.toString(); let str = func.toString();
// console.log(id, str); let modified = false;
for (let groupIndex = 0; groupIndex < patchesToCheck.length; groupIndex++) {
const patchName = patchesToCheck[groupIndex];
let modified = false;
for (let patchIndex = 0; patchIndex < patchesToCheck.length; patchIndex++) {
const patchName = patchesToCheck[patchIndex];
if (appliedPatches.indexOf(patchName) > -1) { if (appliedPatches.indexOf(patchName) > -1) {
continue; continue;
} }
if (!PATCHES[patchName]) {
continue;
}
// Check function against patch // Check function against patch
const patchedStr = PATCHES[patchName].call(null, str); const patchedStr = PATCHES[patchName].call(null, str);
@ -602,24 +603,24 @@ export class Patcher {
appliedPatches.push(patchName); appliedPatches.push(patchName);
// Remove patch // Remove patch
patchesToCheck.splice(groupIndex, 1); patchesToCheck.splice(patchIndex, 1);
groupIndex--; patchIndex--;
PATCH_ORDERS = PATCH_ORDERS.filter(item => item != patchName); PATCH_ORDERS = PATCH_ORDERS.filter(item => item != patchName);
}
// Apply patched functions // Apply patched functions
if (modified) { if (modified) {
item[1][id] = eval(str); item[1][id] = eval(str);
}
} }
// Save to cache // Save to cache
if (appliedPatches.length) { if (appliedPatches.length) {
caches[id] = appliedPatches; patchesMap[id] = appliedPatches;
} }
} }
if (Object.keys(caches).length) { if (Object.keys(patchesMap).length) {
PatcherCache.saveToCache(caches); PatcherCache.saveToCache(patchesMap);
} }
} }
@ -628,7 +629,7 @@ export class Patcher {
} }
} }
class PatcherCache { export class PatcherCache {
static #KEY_CACHE = 'better_xcloud_patches_cache'; static #KEY_CACHE = 'better_xcloud_patches_cache';
static #KEY_SIGNATURE = 'better_xcloud_patches_cache_signature'; static #KEY_SIGNATURE = 'better_xcloud_patches_cache_signature';
@ -647,18 +648,25 @@ class PatcherCache {
return sig; return sig;
} }
static clear() {
// Clear cache
window.localStorage.removeItem(PatcherCache.#KEY_CACHE);
PatcherCache.#CACHE = {};
}
static checkSignature() { static checkSignature() {
const storedSig = window.localStorage.getItem(PatcherCache.#KEY_SIGNATURE) || 0; const storedSig = window.localStorage.getItem(PatcherCache.#KEY_SIGNATURE) || 0;
const currentSig = PatcherCache.#getSignature(); const currentSig = PatcherCache.#getSignature();
if (currentSig !== parseInt(storedSig as string)) { if (currentSig !== parseInt(storedSig as string)) {
BxLogger.warning(LOG_TAG, 'Signature changed');
// Clear cache
window.localStorage.setItem(PatcherCache.#KEY_CACHE, '{}');
// Save new signature // Save new signature
BxLogger.warning(LOG_TAG, 'Signature changed');
window.localStorage.setItem(PatcherCache.#KEY_SIGNATURE, currentSig.toString()); window.localStorage.setItem(PatcherCache.#KEY_SIGNATURE, currentSig.toString());
PatcherCache.clear();
// @ts-ignore
window.location.reload(true);
} else { } else {
BxLogger.info(LOG_TAG, 'Signature unchanged'); BxLogger.info(LOG_TAG, 'Signature unchanged');
} }
@ -682,7 +690,7 @@ class PatcherCache {
return PatcherCache.#CACHE[id]; return PatcherCache.#CACHE[id];
} }
static saveToCache(subCache: { [key: string]: string[] }) { static saveToCache(subCache: { [key: string]: PatchArray }) {
for (const id in subCache) { for (const id in subCache) {
const patchNames = subCache[id]; const patchNames = subCache[id];

View File

@ -73,9 +73,9 @@ export const BxExposed = {
// Pre-check supported input types // Pre-check supported input types
titleInfo.details.hasMkbSupport = supportedInputTypes.includes(InputType.MKB); titleInfo.details.hasMkbSupport = supportedInputTypes.includes(InputType.MKB);
titleInfo.details.hasTouchSupport = supportedInputTypes.includes(InputType.NATIVE_TOUCH) && titleInfo.details.hasTouchSupport = supportedInputTypes.includes(InputType.NATIVE_TOUCH) ||
!supportedInputTypes.includes(InputType.CUSTOM_TOUCH_OVERLAY) && supportedInputTypes.includes(InputType.CUSTOM_TOUCH_OVERLAY) ||
!supportedInputTypes.includes(InputType.GENERIC_TOUCH); supportedInputTypes.includes(InputType.GENERIC_TOUCH);
if (!titleInfo.details.hasTouchSupport && touchControllerAvailability === 'all') { if (!titleInfo.details.hasTouchSupport && touchControllerAvailability === 'all') {
// Add generic touch support for non touch-supported games // Add generic touch support for non touch-supported games