Update better-xcloud.user.js

This commit is contained in:
redphx 2024-10-21 08:15:49 +07:00 committed by GitHub
parent 79c7af10d4
commit 2d8361ba73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,7 +18,7 @@ class BxLogger {
static warning = (tag, ...args) => BxLogger.log("#c1a404", tag, ...args); static warning = (tag, ...args) => BxLogger.log("#c1a404", tag, ...args);
static error = (tag, ...args) => BxLogger.log("#c10404", tag, ...args); static error = (tag, ...args) => BxLogger.log("#c10404", tag, ...args);
static log(color, tag, ...args) { static log(color, tag, ...args) {
console.log("%c[BxC]", `color:${color};font-weight:bold;`, tag, "//", ...args); BX_FLAGS.Debug && console.log("%c[BxC]", `color:${color};font-weight:bold;`, tag, "//", ...args);
} }
} }
window.BxLogger = BxLogger; window.BxLogger = BxLogger;
@ -958,6 +958,7 @@ class BaseSettingsStore {
class StreamStatsCollector { class StreamStatsCollector {
static instance; static instance;
static getInstance = () => StreamStatsCollector.instance ?? (StreamStatsCollector.instance = new StreamStatsCollector); static getInstance = () => StreamStatsCollector.instance ?? (StreamStatsCollector.instance = new StreamStatsCollector);
LOG_TAG = "StreamStatsCollector";
static INTERVAL_BACKGROUND = 60000; static INTERVAL_BACKGROUND = 60000;
calculateGrade(value, grades) { calculateGrade(value, grades) {
return value > grades[2] ? "bad" : value > grades[1] ? "ok" : value > grades[0] ? "good" : ""; return value > grades[2] ? "bad" : value > grades[1] ? "ok" : value > grades[0] ? "good" : "";
@ -1057,6 +1058,9 @@ class StreamStatsCollector {
} }
}; };
lastVideoStat; lastVideoStat;
constructor() {
BxLogger.info(this.LOG_TAG, "constructor()");
}
async collect() { async collect() {
let stats = await STATES.currentStream.peerConnection?.getStats(); let stats = await STATES.currentStream.peerConnection?.getStats();
if (!stats) return; if (!stats) return;
@ -1788,11 +1792,12 @@ STORAGE.Global = globalSettings;
class ScreenshotManager { class ScreenshotManager {
static instance; static instance;
static getInstance = () => ScreenshotManager.instance ?? (ScreenshotManager.instance = new ScreenshotManager); static getInstance = () => ScreenshotManager.instance ?? (ScreenshotManager.instance = new ScreenshotManager);
LOG_TAG = "ScreenshotManager";
$download; $download;
$canvas; $canvas;
canvasContext; canvasContext;
constructor() { constructor() {
this.$download = CE("a"), this.$canvas = CE("canvas", { class: "bx-gone" }), this.canvasContext = this.$canvas.getContext("2d", { BxLogger.info(this.LOG_TAG, "constructor()"), this.$download = CE("a"), this.$canvas = CE("canvas", { class: "bx-gone" }), this.canvasContext = this.$canvas.getContext("2d", {
alpha: !1, alpha: !1,
willReadFrequently: !1 willReadFrequently: !1
}); });
@ -1864,6 +1869,7 @@ var MouseMapTo;
class StreamStats { class StreamStats {
static instance; static instance;
static getInstance = () => StreamStats.instance ?? (StreamStats.instance = new StreamStats); static getInstance = () => StreamStats.instance ?? (StreamStats.instance = new StreamStats);
LOG_TAG = "StreamStats";
intervalId; intervalId;
REFRESH_INTERVAL = 1000; REFRESH_INTERVAL = 1000;
stats = { stats = {
@ -1919,7 +1925,7 @@ class StreamStats {
$container; $container;
quickGlanceObserver; quickGlanceObserver;
constructor() { constructor() {
this.render(); BxLogger.info(this.LOG_TAG, "constructor()"), this.render();
} }
async start(glancing = !1) { async start(glancing = !1) {
if (!this.isHidden() || glancing && this.isGlancing()) return; if (!this.isHidden() || glancing && this.isGlancing()) return;
@ -2004,43 +2010,52 @@ class StreamStats {
} }
} }
class Toast { class Toast {
static $wrapper; static instance;
static $msg; static getInstance = () => Toast.instance ?? (Toast.instance = new Toast);
static $status; LOG_TAG = "Toast";
static stack = []; $wrapper;
static isShowing = !1; $msg;
static timeout; $status;
static DURATION = 3000; stack = [];
static show(msg, status, options = {}) { isShowing = !1;
timeoutId;
DURATION = 3000;
constructor() {
BxLogger.info(this.LOG_TAG, "constructor()"), this.$wrapper = CE("div", { class: "bx-toast bx-offscreen" }, this.$msg = CE("span", { class: "bx-toast-msg" }), this.$status = CE("span", { class: "bx-toast-status" })), this.$wrapper.addEventListener("transitionend", (e) => {
let classList = this.$wrapper.classList;
if (classList.contains("bx-hide")) classList.remove("bx-offscreen", "bx-hide"), classList.add("bx-offscreen"), this.showNext();
}), document.documentElement.appendChild(this.$wrapper);
}
show(msg, status, options = {}) {
options = options || {}; options = options || {};
let args = Array.from(arguments); let args = Array.from(arguments);
if (options.instant) Toast.stack = [args], Toast.showNext(); if (options.instant) this.stack = [args], this.showNext();
else Toast.stack.push(args), !Toast.isShowing && Toast.showNext(); else this.stack.push(args), !this.isShowing && this.showNext();
} }
static showNext() { showNext() {
if (!Toast.stack.length) { if (!this.stack.length) {
Toast.isShowing = !1; this.isShowing = !1;
return; return;
} }
Toast.isShowing = !0, Toast.timeout && clearTimeout(Toast.timeout), Toast.timeout = window.setTimeout(Toast.hide, Toast.DURATION); this.isShowing = !0, this.timeoutId && clearTimeout(this.timeoutId), this.timeoutId = window.setTimeout(this.hide.bind(this), this.DURATION);
let [msg, status, options] = Toast.stack.shift(); let [msg, status, options] = this.stack.shift();
if (options && options.html) Toast.$msg.innerHTML = msg; if (options && options.html) this.$msg.innerHTML = msg;
else Toast.$msg.textContent = msg; else this.$msg.textContent = msg;
if (status) Toast.$status.classList.remove("bx-gone"), Toast.$status.textContent = status; if (status) this.$status.classList.remove("bx-gone"), this.$status.textContent = status;
else Toast.$status.classList.add("bx-gone"); else this.$status.classList.add("bx-gone");
let classList = Toast.$wrapper.classList; let classList = this.$wrapper.classList;
classList.remove("bx-offscreen", "bx-hide"), classList.add("bx-show"); classList.remove("bx-offscreen", "bx-hide"), classList.add("bx-show");
} }
static hide() { hide() {
Toast.timeout = null; this.timeoutId = null;
let classList = Toast.$wrapper.classList; let classList = this.$wrapper.classList;
classList.remove("bx-show"), classList.add("bx-hide"); classList.remove("bx-show"), classList.add("bx-hide");
} }
static setup() { static show(msg, status, options = {}) {
Toast.$wrapper = CE("div", { class: "bx-toast bx-offscreen" }, Toast.$msg = CE("span", { class: "bx-toast-msg" }), Toast.$status = CE("span", { class: "bx-toast-status" })), Toast.$wrapper.addEventListener("transitionend", (e) => { Toast.getInstance().show(msg, status, options);
let classList = Toast.$wrapper.classList; }
if (classList.contains("bx-hide")) classList.remove("bx-offscreen", "bx-hide"), classList.add("bx-offscreen"), Toast.showNext(); static showNext() {
}), document.documentElement.appendChild(Toast.$wrapper); Toast.getInstance().showNext();
} }
} }
class MicrophoneShortcut { class MicrophoneShortcut {
@ -2348,7 +2363,7 @@ class MkbPreset {
let mouseMapTo = MouseMapTo[mouse["map_to"]]; let mouseMapTo = MouseMapTo[mouse["map_to"]];
if (typeof mouseMapTo !== "undefined") mouse["map_to"] = mouseMapTo; if (typeof mouseMapTo !== "undefined") mouse["map_to"] = mouseMapTo;
else mouse["map_to"] = MkbPreset.MOUSE_SETTINGS["map_to"].default; else mouse["map_to"] = MkbPreset.MOUSE_SETTINGS["map_to"].default;
return console.log(obj), obj; return obj;
} }
} }
class KeyHelper { class KeyHelper {
@ -2378,18 +2393,21 @@ class KeyHelper {
return KeyHelper.#NON_PRINTABLE_KEYS[code] || code.startsWith("Key") && code.substring(3) || code.startsWith("Digit") && code.substring(5) || code.startsWith("Numpad") && "Numpad " + code.substring(6) || code.startsWith("Arrow") && "Arrow " + code.substring(5) || code.endsWith("Lock") && code.replace("Lock", " Lock") || code.endsWith("Left") && "Left " + code.replace("Left", "") || code.endsWith("Right") && "Right " + code.replace("Right", "") || code; return KeyHelper.#NON_PRINTABLE_KEYS[code] || code.startsWith("Key") && code.substring(3) || code.startsWith("Digit") && code.substring(5) || code.startsWith("Numpad") && "Numpad " + code.substring(6) || code.startsWith("Arrow") && "Arrow " + code.substring(5) || code.endsWith("Lock") && code.replace("Lock", " Lock") || code.endsWith("Left") && "Left " + code.replace("Left", "") || code.endsWith("Right") && "Right " + code.replace("Right", "") || code;
} }
} }
var LOG_TAG = "PointerClient";
class PointerClient { class PointerClient {
static instance; static instance;
static getInstance = () => PointerClient.instance ?? (PointerClient.instance = new PointerClient); static getInstance = () => PointerClient.instance ?? (PointerClient.instance = new PointerClient);
LOG_TAG = "PointerClient";
socket; socket;
mkbHandler; mkbHandler;
constructor() {
BxLogger.info(this.LOG_TAG, "constructor()");
}
start(port, mkbHandler) { start(port, mkbHandler) {
if (!port) throw new Error("PointerServer port is 0"); if (!port) throw new Error("PointerServer port is 0");
this.mkbHandler = mkbHandler, this.socket = new WebSocket(`ws://localhost:${port}`), this.socket.binaryType = "arraybuffer", this.socket.addEventListener("open", (event) => { this.mkbHandler = mkbHandler, this.socket = new WebSocket(`ws://localhost:${port}`), this.socket.binaryType = "arraybuffer", this.socket.addEventListener("open", (event) => {
BxLogger.info(LOG_TAG, "connected"); BxLogger.info(this.LOG_TAG, "connected");
}), this.socket.addEventListener("error", (event) => { }), this.socket.addEventListener("error", (event) => {
BxLogger.error(LOG_TAG, event), Toast.show("Cannot setup mouse: " + event); BxLogger.error(this.LOG_TAG, event), Toast.show("Cannot setup mouse: " + event);
}), this.socket.addEventListener("close", (event) => { }), this.socket.addEventListener("close", (event) => {
this.socket = null; this.socket = null;
}), this.socket.addEventListener("message", (event) => { }), this.socket.addEventListener("message", (event) => {
@ -2455,6 +2473,7 @@ class MkbHandler {}
class NativeMkbHandler extends MkbHandler { class NativeMkbHandler extends MkbHandler {
static instance; static instance;
static getInstance = () => NativeMkbHandler.instance ?? (NativeMkbHandler.instance = new NativeMkbHandler); static getInstance = () => NativeMkbHandler.instance ?? (NativeMkbHandler.instance = new NativeMkbHandler);
LOG_TAG = "NativeMkbHandler";
#pointerClient; #pointerClient;
#enabled = !1; #enabled = !1;
#mouseButtonsPressed = 0; #mouseButtonsPressed = 0;
@ -2464,6 +2483,10 @@ class NativeMkbHandler extends MkbHandler {
#mouseHorizontalMultiply = 0; #mouseHorizontalMultiply = 0;
#inputSink; #inputSink;
#$message; #$message;
constructor() {
super();
BxLogger.info(this.LOG_TAG, "constructor()");
}
#onKeyboardEvent(e) { #onKeyboardEvent(e) {
if (e.type === "keyup" && e.code === "F8") { if (e.type === "keyup" && e.code === "F8") {
e.preventDefault(), this.toggle(); e.preventDefault(), this.toggle();
@ -2662,7 +2685,12 @@ class LocalDb {
class MkbPresetsDb extends LocalDb { class MkbPresetsDb extends LocalDb {
static instance; static instance;
static getInstance = () => MkbPresetsDb.instance ?? (MkbPresetsDb.instance = new MkbPresetsDb); static getInstance = () => MkbPresetsDb.instance ?? (MkbPresetsDb.instance = new MkbPresetsDb);
LOG_TAG = "MkbPresetsDb";
TABLE_PRESETS = "mkb_presets"; TABLE_PRESETS = "mkb_presets";
constructor() {
super();
BxLogger.info(this.LOG_TAG, "constructor()");
}
onUpgradeNeeded(e) { onUpgradeNeeded(e) {
let db = e.target.result; let db = e.target.result;
switch (e.oldVersion) { switch (e.oldVersion) {
@ -2710,7 +2738,7 @@ class MkbPresetsDb extends LocalDb {
}); });
} }
} }
var LOG_TAG2 = "MkbHandler", PointerToMouseButton = { var PointerToMouseButton = {
1: 0, 1: 0,
2: 2, 2: 2,
4: 1 4: 1
@ -2772,6 +2800,7 @@ class PointerLockMouseDataProvider extends MouseDataProvider {
class EmulatedMkbHandler extends MkbHandler { class EmulatedMkbHandler extends MkbHandler {
static instance; static instance;
static getInstance = () => EmulatedMkbHandler.instance ?? (EmulatedMkbHandler.instance = new EmulatedMkbHandler); static getInstance = () => EmulatedMkbHandler.instance ?? (EmulatedMkbHandler.instance = new EmulatedMkbHandler);
static LOG_TAG = "EmulatedMkbHandler";
#CURRENT_PRESET_DATA = MkbPreset.convert(MkbPreset.DEFAULT_PRESET); #CURRENT_PRESET_DATA = MkbPreset.convert(MkbPreset.DEFAULT_PRESET);
static DEFAULT_PANNING_SENSITIVITY = 0.001; static DEFAULT_PANNING_SENSITIVITY = 0.001;
static DEFAULT_DEADZONE_COUNTERWEIGHT = 0.01; static DEFAULT_DEADZONE_COUNTERWEIGHT = 0.01;
@ -2803,7 +2832,7 @@ class EmulatedMkbHandler extends MkbHandler {
#RIGHT_STICK_Y = []; #RIGHT_STICK_Y = [];
constructor() { constructor() {
super(); super();
this.#STICK_MAP = { BxLogger.info(EmulatedMkbHandler.LOG_TAG, "constructor()"), this.#STICK_MAP = {
102: [this.#LEFT_STICK_X, 0, -1], 102: [this.#LEFT_STICK_X, 0, -1],
103: [this.#LEFT_STICK_X, 0, 1], 103: [this.#LEFT_STICK_X, 0, 1],
100: [this.#LEFT_STICK_Y, 1, -1], 100: [this.#LEFT_STICK_Y, 1, -1],
@ -3020,7 +3049,7 @@ class EmulatedMkbHandler extends MkbHandler {
window.addEventListener(BxEvent.STREAM_PLAYING, () => { window.addEventListener(BxEvent.STREAM_PLAYING, () => {
if (STATES.currentStream.titleInfo?.details.hasMkbSupport) { if (STATES.currentStream.titleInfo?.details.hasMkbSupport) {
if (AppInterface && getPref("native_mkb_enabled") === "on") AppInterface && NativeMkbHandler.getInstance().init(); if (AppInterface && getPref("native_mkb_enabled") === "on") AppInterface && NativeMkbHandler.getInstance().init();
} else if (getPref("mkb_enabled") && (AppInterface || !UserAgent.isMobile())) BxLogger.info(LOG_TAG2, "Emulate MKB"), EmulatedMkbHandler.getInstance().init(); } else if (getPref("mkb_enabled") && (AppInterface || !UserAgent.isMobile())) BxLogger.info(EmulatedMkbHandler.LOG_TAG, "Emulate MKB"), EmulatedMkbHandler.getInstance().init();
}); });
} }
} }
@ -3055,6 +3084,7 @@ class NavigationDialog {
class NavigationDialogManager { class NavigationDialogManager {
static instance; static instance;
static getInstance = () => NavigationDialogManager.instance ?? (NavigationDialogManager.instance = new NavigationDialogManager); static getInstance = () => NavigationDialogManager.instance ?? (NavigationDialogManager.instance = new NavigationDialogManager);
LOG_TAG = "NavigationDialogManager";
static GAMEPAD_POLLING_INTERVAL = 50; static GAMEPAD_POLLING_INTERVAL = 50;
static GAMEPAD_KEYS = [ static GAMEPAD_KEYS = [
12, 12,
@ -3095,7 +3125,7 @@ class NavigationDialogManager {
$container; $container;
dialog = null; dialog = null;
constructor() { constructor() {
if (this.$overlay = CE("div", { class: "bx-navigation-dialog-overlay bx-gone" }), this.$overlay.addEventListener("click", (e) => { if (BxLogger.info(this.LOG_TAG, "constructor()"), this.$overlay = CE("div", { class: "bx-navigation-dialog-overlay bx-gone" }), this.$overlay.addEventListener("click", (e) => {
e.preventDefault(), e.stopPropagation(), this.hide(); e.preventDefault(), e.stopPropagation(), this.hide();
}), document.documentElement.appendChild(this.$overlay), this.$container = CE("div", { class: "bx-navigation-dialog bx-gone" }), document.documentElement.appendChild(this.$container), window.addEventListener(BxEvent.XCLOUD_GUIDE_MENU_SHOWN, (e) => this.hide()), getPref("ui_controller_friendly")) }), document.documentElement.appendChild(this.$overlay), this.$container = CE("div", { class: "bx-navigation-dialog bx-gone" }), document.documentElement.appendChild(this.$container), window.addEventListener(BxEvent.XCLOUD_GUIDE_MENU_SHOWN, (e) => this.hide()), getPref("ui_controller_friendly"))
new MutationObserver((mutationList) => { new MutationObserver((mutationList) => {
@ -3403,6 +3433,7 @@ class MkbRemapper {
]; ];
static instance; static instance;
static getInstance = () => MkbRemapper.instance ?? (MkbRemapper.instance = new MkbRemapper); static getInstance = () => MkbRemapper.instance ?? (MkbRemapper.instance = new MkbRemapper);
LOG_TAG = "MkbRemapper";
STATE = { STATE = {
currentPresetId: 0, currentPresetId: 0,
presets: {}, presets: {},
@ -3417,7 +3448,7 @@ class MkbRemapper {
allMouseElements = {}; allMouseElements = {};
bindingDialog; bindingDialog;
constructor() { constructor() {
this.STATE.currentPresetId = getPref("mkb_default_preset_id"), this.bindingDialog = new Dialog({ BxLogger.info(this.LOG_TAG, "constructor()"), this.STATE.currentPresetId = getPref("mkb_default_preset_id"), this.bindingDialog = new Dialog({
className: "bx-binding-dialog", className: "bx-binding-dialog",
content: CE("div", {}, CE("p", {}, t("press-to-bind")), CE("i", {}, t("press-esc-to-cancel"))), content: CE("div", {}, CE("p", {}, t("press-to-bind")), CE("i", {}, t("press-esc-to-cancel"))),
hideCloseButton: !0 hideCloseButton: !0
@ -3621,7 +3652,7 @@ class MkbRemapper {
return this.$wrapper.appendChild($actionButtons), this.toggleEditing(!1), this.refresh(), this.$wrapper; return this.$wrapper.appendChild($actionButtons), this.toggleEditing(!1), this.refresh(), this.$wrapper;
} }
} }
var LOG_TAG3 = "TouchController"; var LOG_TAG = "TouchController";
class TouchController { class TouchController {
static #EVENT_SHOW_DEFAULT_CONTROLLER = new MessageEvent("message", { static #EVENT_SHOW_DEFAULT_CONTROLLER = new MessageEvent("message", {
data: JSON.stringify({ data: JSON.stringify({
@ -3716,12 +3747,12 @@ class TouchController {
} }
let xboxTitleId = TouchController.#xboxTitleId; let xboxTitleId = TouchController.#xboxTitleId;
if (!xboxTitleId) { if (!xboxTitleId) {
BxLogger.error(LOG_TAG3, "Invalid xboxTitleId"); BxLogger.error(LOG_TAG, "Invalid xboxTitleId");
return; return;
} }
if (!layoutId) layoutId = TouchController.#customLayouts[xboxTitleId]?.default_layout || null; if (!layoutId) layoutId = TouchController.#customLayouts[xboxTitleId]?.default_layout || null;
if (!layoutId) { if (!layoutId) {
BxLogger.error(LOG_TAG3, "Invalid layoutId, show default controller"), TouchController.#enabled && TouchController.#showDefault(); BxLogger.error(LOG_TAG, "Invalid layoutId, show default controller"), TouchController.#enabled && TouchController.#showDefault();
return; return;
} }
let layoutChanged = TouchController.#currentLayoutId !== layoutId; let layoutChanged = TouchController.#currentLayoutId !== layoutId;
@ -3804,7 +3835,7 @@ class TouchController {
TouchController.setXboxTitleId(parseInt(json.titleid, 16).toString()); TouchController.setXboxTitleId(parseInt(json.titleid, 16).toString());
} }
} catch (e2) { } catch (e2) {
BxLogger.error(LOG_TAG3, "Load custom layout", e2); BxLogger.error(LOG_TAG, "Load custom layout", e2);
} }
}); });
}); });
@ -3913,7 +3944,7 @@ class PatcherUtils {
return txt.substring(0, index) + toString + txt.substring(index + fromString.length); return txt.substring(0, index) + toString + txt.substring(index + fromString.length);
} }
} }
var ENDING_CHUNKS_PATCH_NAME = "loadingEndingChunks", LOG_TAG4 = "Patcher", PATCHES = { var ENDING_CHUNKS_PATCH_NAME = "loadingEndingChunks", LOG_TAG2 = "Patcher", PATCHES = {
disableAiTrack(str) { disableAiTrack(str) {
let text = ".track=function(", index = str.indexOf(text); let text = ".track=function(", index = str.indexOf(text);
if (index < 0) return !1; if (index < 0) return !1;
@ -4043,7 +4074,7 @@ logFunc(logTag, '//', logMessage);
loadingEndingChunks(str) { loadingEndingChunks(str) {
let text = '"FamilySagaManager"'; let text = '"FamilySagaManager"';
if (!str.includes(text)) return !1; if (!str.includes(text)) return !1;
return BxLogger.info(LOG_TAG4, "Remaining patches:", PATCH_ORDERS), PATCH_ORDERS = PATCH_ORDERS.concat(PLAYING_PATCH_ORDERS), str; return BxLogger.info(LOG_TAG2, "Remaining patches:", PATCH_ORDERS), PATCH_ORDERS = PATCH_ORDERS.concat(PLAYING_PATCH_ORDERS), str;
}, },
disableStreamGate(str) { disableStreamGate(str) {
let index = str.indexOf('case"partially-ready":'); let index = str.indexOf('case"partially-ready":');
@ -4418,7 +4449,7 @@ class Patcher {
if (arguments[1] === 0 || typeof arguments[1] === "function") valid = !0; if (arguments[1] === 0 || typeof arguments[1] === "function") valid = !0;
} }
if (!valid) return nativeBind.apply(this, arguments); if (!valid) return nativeBind.apply(this, arguments);
if (PatcherCache.init(), typeof arguments[1] === "function") BxLogger.info(LOG_TAG4, "Restored Function.prototype.bind()"), Function.prototype.bind = nativeBind; if (PatcherCache.init(), typeof arguments[1] === "function") BxLogger.info(LOG_TAG2, "Restored Function.prototype.bind()"), Function.prototype.bind = nativeBind;
let orgFunc = this, newFunc = (a, item2) => { let orgFunc = this, newFunc = (a, item2) => {
Patcher.patch(item2), orgFunc(a, item2); Patcher.patch(item2), orgFunc(a, item2);
}; };
@ -4440,12 +4471,12 @@ class Patcher {
if (!PATCHES[patchName]) continue; if (!PATCHES[patchName]) continue;
let tmpStr = PATCHES[patchName].call(null, patchedFuncStr); let tmpStr = PATCHES[patchName].call(null, patchedFuncStr);
if (!tmpStr) continue; if (!tmpStr) continue;
modified = !0, patchedFuncStr = tmpStr, BxLogger.info(LOG_TAG4, `${patchName}`), appliedPatches.push(patchName), patchesToCheck.splice(patchIndex, 1), patchIndex--, PATCH_ORDERS = PATCH_ORDERS.filter((item2) => item2 != patchName); modified = !0, patchedFuncStr = tmpStr, BxLogger.info(LOG_TAG2, `${patchName}`), appliedPatches.push(patchName), patchesToCheck.splice(patchIndex, 1), patchIndex--, PATCH_ORDERS = PATCH_ORDERS.filter((item2) => item2 != patchName);
} }
if (modified) try { if (modified) try {
item[1][id] = eval(patchedFuncStr); item[1][id] = eval(patchedFuncStr);
} catch (e) { } catch (e) {
if (e instanceof Error) BxLogger.error(LOG_TAG4, "Error", appliedPatches, e.message, patchedFuncStr); if (e instanceof Error) BxLogger.error(LOG_TAG2, "Error", appliedPatches, e.message, patchedFuncStr);
} }
if (appliedPatches.length) patchesMap[id] = appliedPatches; if (appliedPatches.length) patchesMap[id] = appliedPatches;
} }
@ -4469,8 +4500,8 @@ class PatcherCache {
} }
static checkSignature() { static checkSignature() {
let storedSig = window.localStorage.getItem(PatcherCache.#KEY_SIGNATURE) || 0, currentSig = PatcherCache.#getSignature(); let storedSig = window.localStorage.getItem(PatcherCache.#KEY_SIGNATURE) || 0, currentSig = PatcherCache.#getSignature();
if (currentSig !== parseInt(storedSig)) BxLogger.warning(LOG_TAG4, "Signature changed"), window.localStorage.setItem(PatcherCache.#KEY_SIGNATURE, currentSig.toString()), PatcherCache.clear(); if (currentSig !== parseInt(storedSig)) BxLogger.warning(LOG_TAG2, "Signature changed"), window.localStorage.setItem(PatcherCache.#KEY_SIGNATURE, currentSig.toString()), PatcherCache.clear();
else BxLogger.info(LOG_TAG4, "Signature unchanged"); else BxLogger.info(LOG_TAG2, "Signature unchanged");
} }
static #cleanupPatches(patches) { static #cleanupPatches(patches) {
return patches.filter((item2) => { return patches.filter((item2) => {
@ -4493,17 +4524,18 @@ class PatcherCache {
} }
static init() { static init() {
if (PatcherCache.#isInitialized) return; if (PatcherCache.#isInitialized) return;
if (PatcherCache.#isInitialized = !0, PatcherCache.checkSignature(), PatcherCache.#CACHE = JSON.parse(window.localStorage.getItem(PatcherCache.#KEY_CACHE) || "{}"), BxLogger.info(LOG_TAG4, PatcherCache.#CACHE), window.location.pathname.includes("/play/")) PATCH_ORDERS.push(...PLAYING_PATCH_ORDERS); if (PatcherCache.#isInitialized = !0, PatcherCache.checkSignature(), PatcherCache.#CACHE = JSON.parse(window.localStorage.getItem(PatcherCache.#KEY_CACHE) || "{}"), BxLogger.info(LOG_TAG2, PatcherCache.#CACHE), window.location.pathname.includes("/play/")) PATCH_ORDERS.push(...PLAYING_PATCH_ORDERS);
else PATCH_ORDERS.push(ENDING_CHUNKS_PATCH_NAME); else PATCH_ORDERS.push(ENDING_CHUNKS_PATCH_NAME);
PATCH_ORDERS = PatcherCache.#cleanupPatches(PATCH_ORDERS), PLAYING_PATCH_ORDERS = PatcherCache.#cleanupPatches(PLAYING_PATCH_ORDERS), BxLogger.info(LOG_TAG4, PATCH_ORDERS.slice(0)), BxLogger.info(LOG_TAG4, PLAYING_PATCH_ORDERS.slice(0)); PATCH_ORDERS = PatcherCache.#cleanupPatches(PATCH_ORDERS), PLAYING_PATCH_ORDERS = PatcherCache.#cleanupPatches(PLAYING_PATCH_ORDERS), BxLogger.info(LOG_TAG2, PATCH_ORDERS.slice(0)), BxLogger.info(LOG_TAG2, PLAYING_PATCH_ORDERS.slice(0));
} }
} }
class FullscreenText { class FullscreenText {
static instance; static instance;
static getInstance = () => FullscreenText.instance ?? (FullscreenText.instance = new FullscreenText); static getInstance = () => FullscreenText.instance ?? (FullscreenText.instance = new FullscreenText);
LOG_TAG = "FullscreenText";
$text; $text;
constructor() { constructor() {
this.$text = CE("div", { BxLogger.info(this.LOG_TAG, "constructor()"), this.$text = CE("div", {
class: "bx-fullscreen-text bx-gone" class: "bx-fullscreen-text bx-gone"
}), document.documentElement.appendChild(this.$text); }), document.documentElement.appendChild(this.$text);
} }
@ -4517,6 +4549,7 @@ class FullscreenText {
class SettingsNavigationDialog extends NavigationDialog { class SettingsNavigationDialog extends NavigationDialog {
static instance; static instance;
static getInstance = () => SettingsNavigationDialog.instance ?? (SettingsNavigationDialog.instance = new SettingsNavigationDialog); static getInstance = () => SettingsNavigationDialog.instance ?? (SettingsNavigationDialog.instance = new SettingsNavigationDialog);
LOG_TAG = "SettingsNavigationDialog";
$container; $container;
$tabs; $tabs;
$tabContents; $tabContents;
@ -4976,7 +5009,7 @@ class SettingsNavigationDialog extends NavigationDialog {
}; };
constructor() { constructor() {
super(); super();
this.renderFullSettings = STATES.supportedRegion && STATES.isSignedIn, this.setupDialog(); BxLogger.info(this.LOG_TAG, "constructor()"), this.renderFullSettings = STATES.supportedRegion && STATES.isSignedIn, this.setupDialog();
} }
getDialog() { getDialog() {
return this; return this;
@ -5527,7 +5560,7 @@ class ControllerShortcut {
} }
if (empty) delete ControllerShortcut.ACTIONS[key]; if (empty) delete ControllerShortcut.ACTIONS[key];
} }
window.localStorage.setItem(ControllerShortcut.STORAGE_KEY, JSON.stringify(ControllerShortcut.ACTIONS)), console.log(ControllerShortcut.ACTIONS); window.localStorage.setItem(ControllerShortcut.STORAGE_KEY, JSON.stringify(ControllerShortcut.ACTIONS));
} }
static updateProfileList(e) { static updateProfileList(e) {
let { $selectProfile: $select, $container } = ControllerShortcut, $fragment = document.createDocumentFragment(); let { $selectProfile: $select, $container } = ControllerShortcut, $fragment = document.createDocumentFragment();
@ -5773,6 +5806,7 @@ class HeaderSection {
class RemotePlayNavigationDialog extends NavigationDialog { class RemotePlayNavigationDialog extends NavigationDialog {
static instance; static instance;
static getInstance = () => RemotePlayNavigationDialog.instance ?? (RemotePlayNavigationDialog.instance = new RemotePlayNavigationDialog); static getInstance = () => RemotePlayNavigationDialog.instance ?? (RemotePlayNavigationDialog.instance = new RemotePlayNavigationDialog);
LOG_TAG = "RemotePlayNavigationDialog";
STATE_LABELS = { STATE_LABELS = {
On: t("powered-on"), On: t("powered-on"),
Off: t("powered-off"), Off: t("powered-off"),
@ -5782,7 +5816,7 @@ class RemotePlayNavigationDialog extends NavigationDialog {
$container; $container;
constructor() { constructor() {
super(); super();
this.setupDialog(); BxLogger.info(this.LOG_TAG, "constructor()"), this.setupDialog();
} }
setupDialog() { setupDialog() {
let $fragment = CE("div", { class: "bx-remote-play-container" }), $settingNote = CE("p", {}), currentResolution = getPref("xhome_resolution"), $resolutions = CE("select", {}, CE("option", { value: "1080p" }, "1080p"), CE("option", { value: "720p" }, "720p")); let $fragment = CE("div", { class: "bx-remote-play-container" }), $settingNote = CE("p", {}), currentResolution = getPref("xhome_resolution"), $resolutions = CE("select", {}, CE("option", { value: "1080p" }, "1080p"), CE("option", { value: "720p" }, "720p"));
@ -5834,20 +5868,23 @@ class RemotePlayNavigationDialog extends NavigationDialog {
$btnConnect && $btnConnect.focus(); $btnConnect && $btnConnect.focus();
} }
} }
var LOG_TAG5 = "RemotePlay";
class RemotePlayManager { class RemotePlayManager {
static instance; static instance;
static getInstance = () => RemotePlayManager.instance ?? (RemotePlayManager.instance = new RemotePlayManager); static getInstance = () => RemotePlayManager.instance ?? (RemotePlayManager.instance = new RemotePlayManager);
LOG_TAG = "RemotePlayManager";
isInitialized = !1; isInitialized = !1;
XCLOUD_TOKEN; XCLOUD_TOKEN;
XHOME_TOKEN; XHOME_TOKEN;
consoles; consoles;
regions = []; regions = [];
constructor() {
BxLogger.info(this.LOG_TAG, "constructor()");
}
initialize() { initialize() {
if (this.isInitialized) return; if (this.isInitialized) return;
this.isInitialized = !0, this.getXhomeToken(() => { this.isInitialized = !0, this.getXhomeToken(() => {
this.getConsolesList(() => { this.getConsolesList(() => {
BxLogger.info(LOG_TAG5, "Consoles", this.consoles), STATES.supportedRegion && HeaderSection.showRemotePlayButton(), BxEvent.dispatch(window, BxEvent.REMOTE_PLAY_READY); BxLogger.info(this.LOG_TAG, "Consoles", this.consoles), STATES.supportedRegion && HeaderSection.showRemotePlayButton(), BxEvent.dispatch(window, BxEvent.REMOTE_PLAY_READY);
}); });
}); });
} }
@ -6344,6 +6381,7 @@ class GuideMenu {
class StreamBadges { class StreamBadges {
static instance; static instance;
static getInstance = () => StreamBadges.instance ?? (StreamBadges.instance = new StreamBadges); static getInstance = () => StreamBadges.instance ?? (StreamBadges.instance = new StreamBadges);
LOG_TAG = "StreamBadges";
serverInfo = {}; serverInfo = {};
badges = { badges = {
playtime: { playtime: {
@ -6385,6 +6423,9 @@ class StreamBadges {
$container; $container;
intervalId; intervalId;
REFRESH_INTERVAL = 3000; REFRESH_INTERVAL = 3000;
constructor() {
BxLogger.info(this.LOG_TAG, "constructor()");
}
setRegion(region) { setRegion(region) {
this.serverInfo.server = { this.serverInfo.server = {
region region
@ -6609,9 +6650,7 @@ function clearDbLogs(dbName, table) {
let db = e.target.result; let db = e.target.result;
try { try {
let objectStoreRequest = db.transaction(table, "readwrite").objectStore(table).clear(); let objectStoreRequest = db.transaction(table, "readwrite").objectStore(table).clear();
objectStoreRequest.onsuccess = function() { objectStoreRequest.onsuccess = () => BxLogger.info("clearDbLogs", `Cleared ${dbName}.${table}`);
console.log(`[Better xCloud] Cleared ${dbName}.${table}`);
};
} catch (ex) {} } catch (ex) {}
}; };
} }
@ -6801,7 +6840,7 @@ function onHistoryChanged(e) {
if ($settings) $settings.classList.add("bx-gone"); if ($settings) $settings.classList.add("bx-gone");
NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), window.setTimeout(HeaderSection.watchHeader, 2000), BxEvent.dispatch(window, BxEvent.STREAM_STOPPED); NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), window.setTimeout(HeaderSection.watchHeader, 2000), BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
} }
var LOG_TAG6 = "PreloadState"; var LOG_TAG3 = "PreloadState";
function overridePreloadState() { function overridePreloadState() {
let _state; let _state;
Object.defineProperty(window, "__PRELOADED_STATE__", { Object.defineProperty(window, "__PRELOADED_STATE__", {
@ -6813,7 +6852,7 @@ function overridePreloadState() {
try { try {
state.appContext.requestInfo.userAgent = window.navigator.userAgent; state.appContext.requestInfo.userAgent = window.navigator.userAgent;
} catch (e) { } catch (e) {
BxLogger.error(LOG_TAG6, e); BxLogger.error(LOG_TAG3, e);
} }
if (STATES.userAgent.capabilities.touch) try { if (STATES.userAgent.capabilities.touch) try {
let sigls = state.xcloud.sigls; let sigls = state.xcloud.sigls;
@ -6823,7 +6862,7 @@ function overridePreloadState() {
} }
if (BX_FLAGS.ForceNativeMkbTitles && "8fa264dd-124f-4af3-97e8-596fcdf4b486" in sigls) sigls["8fa264dd-124f-4af3-97e8-596fcdf4b486"]?.data.products.push(...BX_FLAGS.ForceNativeMkbTitles); if (BX_FLAGS.ForceNativeMkbTitles && "8fa264dd-124f-4af3-97e8-596fcdf4b486" in sigls) sigls["8fa264dd-124f-4af3-97e8-596fcdf4b486"]?.data.products.push(...BX_FLAGS.ForceNativeMkbTitles);
} catch (e) { } catch (e) {
BxLogger.error(LOG_TAG6, e); BxLogger.error(LOG_TAG3, e);
} }
_state = state, STATES.appContext = deepClone(state.appContext); _state = state, STATES.appContext = deepClone(state.appContext);
} }
@ -7401,12 +7440,14 @@ class RendererAction extends BaseGameBarAction {
class GameBar { class GameBar {
static instance; static instance;
static getInstance = () => GameBar.instance ?? (GameBar.instance = new GameBar); static getInstance = () => GameBar.instance ?? (GameBar.instance = new GameBar);
LOG_TAG = "GameBar";
static VISIBLE_DURATION = 2000; static VISIBLE_DURATION = 2000;
$gameBar; $gameBar;
$container; $container;
timeoutId = null; timeoutId = null;
actions = []; actions = [];
constructor() { constructor() {
BxLogger.info(this.LOG_TAG, "constructor()");
let $container, position = getPref("game_bar_position"), $gameBar = CE("div", { id: "bx-game-bar", class: "bx-gone", "data-position": position }, $container = CE("div", { class: "bx-game-bar-container bx-offscreen" }), createSvgIcon(position === "bottom-left" ? BxIcon.CARET_RIGHT : BxIcon.CARET_LEFT)); let $container, position = getPref("game_bar_position"), $gameBar = CE("div", { id: "bx-game-bar", class: "bx-gone", "data-position": position }, $container = CE("div", { class: "bx-game-bar-container bx-offscreen" }), createSvgIcon(position === "bottom-left" ? BxIcon.CARET_RIGHT : BxIcon.CARET_LEFT));
if (this.actions = [ if (this.actions = [
new ScreenshotAction, new ScreenshotAction,
@ -7455,8 +7496,12 @@ class GameBar {
class XcloudApi { class XcloudApi {
static instance; static instance;
static getInstance = () => XcloudApi.instance ?? (XcloudApi.instance = new XcloudApi); static getInstance = () => XcloudApi.instance ?? (XcloudApi.instance = new XcloudApi);
LOG_TAG = "XcloudApi";
CACHE_TITLES = {}; CACHE_TITLES = {};
CACHE_WAIT_TIME = {}; CACHE_WAIT_TIME = {};
constructor() {
BxLogger.info(this.LOG_TAG, "constructor()");
}
async getTitleInfo(id2) { async getTitleInfo(id2) {
if (id2 in this.CACHE_TITLES) return this.CACHE_TITLES[id2]; if (id2 in this.CACHE_TITLES) return this.CACHE_TITLES[id2];
let baseUri = STATES.selectedRegion.baseUri; let baseUri = STATES.selectedRegion.baseUri;
@ -7870,7 +7915,7 @@ window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, (e) => {
function main() { function main() {
if (getPref("game_msfs2020_force_native_mkb")) BX_FLAGS.ForceNativeMkbTitles.push("9PMQDM08SNK9"); if (getPref("game_msfs2020_force_native_mkb")) BX_FLAGS.ForceNativeMkbTitles.push("9PMQDM08SNK9");
if (patchRtcPeerConnection(), patchRtcCodecs(), interceptHttpRequests(), patchVideoApi(), patchCanvasContext(), AppInterface && patchPointerLockApi(), getPref("audio_enable_volume_control") && patchAudioContext(), getPref("block_tracking")) patchMeControl(), disableAdobeAudienceManager(); if (patchRtcPeerConnection(), patchRtcCodecs(), interceptHttpRequests(), patchVideoApi(), patchCanvasContext(), AppInterface && patchPointerLockApi(), getPref("audio_enable_volume_control") && patchAudioContext(), getPref("block_tracking")) patchMeControl(), disableAdobeAudienceManager();
if (RootDialogObserver.waitForRootDialog(), addCss(), Toast.setup(), GuideMenu.addEventListeners(), StreamStatsCollector.setupEvents(), StreamBadges.setupEvents(), StreamStats.setupEvents(), STATES.userAgent.capabilities.touch && TouchController.updateCustomList(), overridePreloadState(), VibrationManager.initialSetup(), BX_FLAGS.CheckForUpdate && checkForUpdate(), Patcher.init(), disablePwa(), getPref("xhome_enabled")) RemotePlayManager.detect(); if (RootDialogObserver.waitForRootDialog(), addCss(), GuideMenu.addEventListeners(), StreamStatsCollector.setupEvents(), StreamBadges.setupEvents(), StreamStats.setupEvents(), STATES.userAgent.capabilities.touch && TouchController.updateCustomList(), overridePreloadState(), VibrationManager.initialSetup(), BX_FLAGS.CheckForUpdate && checkForUpdate(), Patcher.init(), disablePwa(), getPref("xhome_enabled")) RemotePlayManager.detect();
if (getPref("stream_touch_controller") === "all") TouchController.setup(); if (getPref("stream_touch_controller") === "all") TouchController.setup();
if (getPref("mkb_enabled") && AppInterface) STATES.pointerServerPort = AppInterface.startPointerServer() || 9269, BxLogger.info("startPointerServer", "Port", STATES.pointerServerPort.toString()); if (getPref("mkb_enabled") && AppInterface) STATES.pointerServerPort = AppInterface.startPointerServer() || 9269, BxLogger.info("startPointerServer", "Port", STATES.pointerServerPort.toString());
if (getPref("ui_game_card_show_wait_time") && GameTile.setup(), EmulatedMkbHandler.setupEvents(), getPref("controller_show_connection_status")) window.addEventListener("gamepadconnected", (e) => showGamepadToast(e.gamepad)), window.addEventListener("gamepaddisconnected", (e) => showGamepadToast(e.gamepad)); if (getPref("ui_game_card_show_wait_time") && GameTile.setup(), EmulatedMkbHandler.setupEvents(), getPref("controller_show_connection_status")) window.addEventListener("gamepadconnected", (e) => showGamepadToast(e.gamepad)), window.addEventListener("gamepaddisconnected", (e) => showGamepadToast(e.gamepad));