From 243664634a76f6fae3527d6bbf763f566e6eef97 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:51:02 -0600 Subject: [PATCH 01/23] Update eaglermobile.user.js --- eaglermobile.user.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 93050be..115d6b4 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,7 +6,7 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.2 +// @version 3.0.3-alpha-1 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start // ==/UserScript== @@ -54,8 +54,8 @@ Object.defineProperty(EventTarget.prototype, "addEventListener", { }); // Allows typing in #hiddenInput const _preventDefault = Event.prototype.preventDefault; -Event.prototype.preventDefault = function() { - if(document.activeElement.id != "hiddenInput") { +Event.prototype.preventDefault = function(shouldBypass) { + if(document.activeElement.id != "hiddenInput" || shouldBypass) { this._preventDefault = _preventDefault; this._preventDefault(); } @@ -367,11 +367,13 @@ function insertCanvasElements() { hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;"; hiddenInput.value = " " //Allows delete to be detected before input is changed hiddenInput.addEventListener("input", function(e) { - let inputData = e.data ?? "delete"; // backspace makes null + e.preventDefault(true); + let inputData = e.data == null ? "delete" : e.data.slice(-1); // backspace makes null window.lastKey = inputData hiddenInput.value = " "; // We need a character to detect deleting if(window.keyboardFix) { - if(e.inputType == 'insertText') { + const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof + if(sliceInputType== 'i') { let isShift = (inputData.toLowerCase() != inputData); if(isShift) { keyEvent("shift", "keydown") @@ -382,9 +384,9 @@ function insertCanvasElements() { keyEvent(inputData, "keydown"); keyEvent(inputData, "keyup"); } - } else if (e.inputType == 'deleteContentForward' || e.inputType == 'deleteContentBackward') { - keyEvent("backspace", "keydown") - keyEvent("backspace", "keyup") + } else if (sliceInputType == 'd') { + keyEvent("backspace", "keydown"); + keyEvent("backspace", "keyup"); } } }, false); @@ -393,8 +395,8 @@ function insertCanvasElements() { console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") window.keyboardFix = true; if(window.lastKey) { - keyEvent(window.lastKey, "keydown") - keyEvent(window.lastKey, "keyup") + keyEvent(window.lastKey, "keydown"); + keyEvent(window.lastKey, "keyup"); } } }, false); From c45e5da373faf8dba484747c215b79cf9a14d726 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:05:56 -0600 Subject: [PATCH 02/23] Update eaglermobile.user.js Added console logs so I can see what is happening on Android --- eaglermobile.user.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 115d6b4..ef3e0bf 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -368,7 +368,9 @@ function insertCanvasElements() { hiddenInput.value = " " //Allows delete to be detected before input is changed hiddenInput.addEventListener("input", function(e) { e.preventDefault(true); - let inputData = e.data == null ? "delete" : e.data.slice(-1); // backspace makes null + let inputData = e.data == null ? "delete" : e.data.slice(-1); + console.log("Received input!", inputData, e.inputType) + window.lastKey = inputData hiddenInput.value = " "; // We need a character to detect deleting if(window.keyboardFix) { From 0d1e55f58849ba0ab71aed77b973ba8c2e7036f1 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 19:12:00 -0600 Subject: [PATCH 03/23] Update eaglermobile.user.js Added temporary DOM log for troubleshooting --- eaglermobile.user.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index ef3e0bf..6084e01 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -31,6 +31,28 @@ window.keyboardFix = false; // temporarily set to true until I can figure out wh var previousTouchX = null; var previousTouchY = null; var startTouchX = null; +//TEMP REMOVE +function logManager() { + var self = this; + + self.init = function () { + console.log('logmanager initialized'); + var old = console.log; + self.logger = document.getElementById('log'); + console.log = function (message, options) { + if (typeof message == 'object') { + self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; + } else { + self.logger.innerHTML = message + '
' + self.logger.innerHTML; + } + } + } + self.toggleLogVisibility = function () { + return $(self.logger).toggle(); + }; +} + + // better charCodeAt function String.prototype.toKeyCode = function() { const keyCodeList = {"0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "backspace": 8, "tab": 9, "enter": 13, "shift": 16, "ctrl": 17, "alt": 18, "pause_break": 19, "caps_lock": 20, "escape": 27, " ": 32, "page_up": 33, "page_down": 34, "end": 35, "home": 36, "left_arrow": 37, "up_arrow": 38, "right_arrow": 39, "down_arrow": 40, "insert": 45, "delete": 46, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "left_window_key": 91, "right_window_key": 92, "select_key": 93, "numpad_0": 96, "numpad_1": 97, "numpad_2": 98, "numpad_3": 99, "numpad_4": 100, "numpad_5": 101, "numpad_6": 102, "numpad_7": 103, "numpad_8": 104, "numpad_9": 105, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "f1": 112, "f2": 113, "f3": 114, "f4": 115, "f5": 116, "f6": 117, "f7": 118, "f8": 119, "f9": 120, "f10": 121, "f11": 122, "f12": 123, "num_lock": 144, "scroll_lock": 145, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "`": 192, "[": 219, "\\": 220, "]": 221, "\"": 222}; @@ -488,7 +510,7 @@ function insertCanvasElements() { }, false); document.body.appendChild(screenshotButton); let coordinatesButton = createTouchButton("coordinatesButton", "inGame"); - coordinatesButton.style.cssText = "top: 0vh; margin: auto; left: 32vh; right: 0vh; width: 8vh; height: 8vh;" + coordinatesButton.style.cssText = "" coordinatesButton.addEventListener("touchstart", function(e) { keyEvent("f", "keydown"); keyEvent("3", "keydown"); @@ -498,6 +520,15 @@ function insertCanvasElements() { keyEvent("3", "keyup"); }, false); document.body.appendChild(coordinatesButton); + //TEMP REMOVE + var temp = document.createElement("div"); + temp.id = "log"; + temp.classList.add("log"); + temp.style.cssText= "position:absolute; top: 8vh; margin: auto; left: 0vh; right:0vh"; + temp.innerHtml = "Loading..." + document.body.appendChild(temp); + document.temp = new logManager(); + document.temp.init(); } // CSS for touch screen buttons, along with fixing iOS's issues with 100vh ignoring the naviagtion bar, and actually disabling zoom because safari ignores user-scalable=no :( let customStyle = document.createElement("style"); From 8afdb52f42481ea7c648a334dbb67050f89986e1 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 19:20:50 -0600 Subject: [PATCH 04/23] Updated height --- eaglermobile.user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 6084e01..d148aa8 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,7 +6,7 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.3-alpha-1 +// @version 3.0.3-alpha-2 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start // ==/UserScript== @@ -524,7 +524,7 @@ function insertCanvasElements() { var temp = document.createElement("div"); temp.id = "log"; temp.classList.add("log"); - temp.style.cssText= "position:absolute; top: 8vh; margin: auto; left: 0vh; right:0vh"; + temp.style.cssText= "position:absolute; top: 8vh; margin: auto; left: 0vh; right:0vh; height: 30vh;"; temp.innerHtml = "Loading..." document.body.appendChild(temp); document.temp = new logManager(); From 71571b3771ba0c1ede58ff49587d46ede4d8fa6c Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 19:25:00 -0600 Subject: [PATCH 05/23] Update eaglermobile.user.js Styling --- eaglermobile.user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index d148aa8..b5cd5e5 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,7 +6,7 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.3-alpha-2 +// @version 3.0.3-alpha-3 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start // ==/UserScript== @@ -524,7 +524,7 @@ function insertCanvasElements() { var temp = document.createElement("div"); temp.id = "log"; temp.classList.add("log"); - temp.style.cssText= "position:absolute; top: 8vh; margin: auto; left: 0vh; right:0vh; height: 30vh;"; + temp.style.cssText= "position: absolute; top: 8vh; margin: auto; left: 0vh; right: 0vh; height: auto; z-index:10; min-height:8vh; background:white"; temp.innerHtml = "Loading..." document.body.appendChild(temp); document.temp = new logManager(); From f561557c3ef56c922edb4654c74fbc39b4f79484 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 19:32:16 -0600 Subject: [PATCH 06/23] Updated temp log Sorry for the spam --- eaglermobile.user.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index b5cd5e5..5b12782 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -386,12 +386,15 @@ function insertCanvasElements() { hiddenInput.id = "hiddenInput" hiddenInput.classList.add("inMenu") // We are hiding the text input behind button because opacity was causing problems. - hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;"; + //TEMP REVERT + //hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;"; + + hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:10"; hiddenInput.value = " " //Allows delete to be detected before input is changed hiddenInput.addEventListener("input", function(e) { e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); - console.log("Received input!", inputData, e.inputType) + console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); window.lastKey = inputData hiddenInput.value = " "; // We need a character to detect deleting From d1e5364bac8c3205b86a8c2c447430eef7bc5ad2 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 19:39:23 -0600 Subject: [PATCH 07/23] Logger attempt 2 --- eaglermobile.user.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 5b12782..f6c7226 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -41,9 +41,9 @@ function logManager() { self.logger = document.getElementById('log'); console.log = function (message, options) { if (typeof message == 'object') { - self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; + self.logger.innerText = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; } else { - self.logger.innerHTML = message + '
' + self.logger.innerHTML; + self.logger.innerText = message + " " + self.logger.innerText; } } } @@ -524,7 +524,7 @@ function insertCanvasElements() { }, false); document.body.appendChild(coordinatesButton); //TEMP REMOVE - var temp = document.createElement("div"); + var temp = document.createElement("p"); temp.id = "log"; temp.classList.add("log"); temp.style.cssText= "position: absolute; top: 8vh; margin: auto; left: 0vh; right: 0vh; height: auto; z-index:10; min-height:8vh; background:white"; From 3a21f56e26f001242ad8492f8c4a082108e34300 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:00:32 -0600 Subject: [PATCH 08/23] Hack for unsafeWindow --- eaglermobile.user.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index f6c7226..9a1179f 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,12 +6,19 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.3-alpha-3 +// @version 3.0.3-alpha-4 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start // ==/UserScript== +// THIS IS LAZY AND CAN EXPOSE INTERNALS +// IN THE FUTURE, JUST INJECT A SCRIPT TAG +try { +window = unsafeWindow ?? window +} catch { + +} function isMobile() { try { document.createEvent("TouchEvent"); @@ -41,9 +48,9 @@ function logManager() { self.logger = document.getElementById('log'); console.log = function (message, options) { if (typeof message == 'object') { - self.logger.innerText = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; + self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; } else { - self.logger.innerText = message + " " + self.logger.innerText; + self.logger.innerHTML = message + '
' + self.logger.innerHTML; } } } @@ -524,7 +531,7 @@ function insertCanvasElements() { }, false); document.body.appendChild(coordinatesButton); //TEMP REMOVE - var temp = document.createElement("p"); + var temp = document.createElement("div"); temp.id = "log"; temp.classList.add("log"); temp.style.cssText= "position: absolute; top: 8vh; margin: auto; left: 0vh; right: 0vh; height: auto; z-index:10; min-height:8vh; background:white"; From f81d92da9d4394e7506cb9887714cb8c1867aca5 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:08:00 -0600 Subject: [PATCH 09/23] Temp fix for sandboxing --- eaglermobile.user.js | 57 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 9a1179f..ae02e8a 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,7 +6,7 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.3-alpha-4 +// @version 3.0.3-alpha-5 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start // ==/UserScript== @@ -14,11 +14,10 @@ // THIS IS LAZY AND CAN EXPOSE INTERNALS // IN THE FUTURE, JUST INJECT A SCRIPT TAG -try { -window = unsafeWindow ?? window -} catch { +var mobileScript = document.createElement("script"); +mobileScript.id = "mobileScript"; +mobileScript.textContent = ` -} function isMobile() { try { document.createEvent("TouchEvent"); @@ -62,7 +61,7 @@ function logManager() { // better charCodeAt function String.prototype.toKeyCode = function() { - const keyCodeList = {"0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "backspace": 8, "tab": 9, "enter": 13, "shift": 16, "ctrl": 17, "alt": 18, "pause_break": 19, "caps_lock": 20, "escape": 27, " ": 32, "page_up": 33, "page_down": 34, "end": 35, "home": 36, "left_arrow": 37, "up_arrow": 38, "right_arrow": 39, "down_arrow": 40, "insert": 45, "delete": 46, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "left_window_key": 91, "right_window_key": 92, "select_key": 93, "numpad_0": 96, "numpad_1": 97, "numpad_2": 98, "numpad_3": 99, "numpad_4": 100, "numpad_5": 101, "numpad_6": 102, "numpad_7": 103, "numpad_8": 104, "numpad_9": 105, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "f1": 112, "f2": 113, "f3": 114, "f4": 115, "f5": 116, "f6": 117, "f7": 118, "f8": 119, "f9": 120, "f10": 121, "f11": 122, "f12": 123, "num_lock": 144, "scroll_lock": 145, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "`": 192, "[": 219, "\\": 220, "]": 221, "\"": 222}; + const keyCodeList = {"0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "backspace": 8, "tab": 9, "enter": 13, "shift": 16, "ctrl": 17, "alt": 18, "pause_break": 19, "caps_lock": 20, "escape": 27, " ": 32, "page_up": 33, "page_down": 34, "end": 35, "home": 36, "left_arrow": 37, "up_arrow": 38, "right_arrow": 39, "down_arrow": 40, "insert": 45, "delete": 46, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "left_window_key": 91, "right_window_key": 92, "select_key": 93, "numpad_0": 96, "numpad_1": 97, "numpad_2": 98, "numpad_3": 99, "numpad_4": 100, "numpad_5": 101, "numpad_6": 102, "numpad_7": 103, "numpad_8": 104, "numpad_9": 105, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "f1": 112, "f2": 113, "f3": 114, "f4": 115, "f5": 116, "f6": 117, "f7": 118, "f8": 119, "f9": 120, "f10": 121, "f11": 122, "f12": 123, "num_lock": 144, "scroll_lock": 145, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "\`": 192, "[": 219, "\\": 220, "]": 221, "\"": 222}; return keyCodeList[this]; } // Ignores keydown events that don't have the isValid parameter set to true @@ -196,24 +195,6 @@ document.createElement = function(type, ignore) { return element; } -// Lazy way to hide touch controls through CSS. -let inGameStyle = document.createElement("style"); -inGameStyle.id = "inGameStyle"; -inGameStyle.textContent = ` - .inGame { - display: none; - }`; -document.documentElement.appendChild(inGameStyle); - -let inMenuStyle = document.createElement("style"); -inMenuStyle.id = "inMenuStyle"; -inMenuStyle.textContent = ` - .inMenu { - display: none; - }`; -document.documentElement.appendChild(inMenuStyle); - - // The canvas is created by the client after it finishes unzipping and loading. When the canvas is created, this applies any necessary event listeners function waitForElm(selector) { return new Promise(resolve => { @@ -385,8 +366,8 @@ function insertCanvasElements() { document.body.appendChild(inventoryButton); let exitButton = createTouchButton("exitButton", "inMenu"); exitButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right:8vh; width: 8vh; height: 8vh;" - exitButton.addEventListener("touchstart", function(e){keyEvent("`", "keydown")}, false); - exitButton.addEventListener("touchend", function(e){keyEvent("`", "keyup")}, false); + exitButton.addEventListener("touchstart", function(e){keyEvent("\`", "keydown")}, false); + exitButton.addEventListener("touchend", function(e){keyEvent("\`", "keyup")}, false); document.body.appendChild(exitButton); // input for keyboard button let hiddenInput = document.createElement('input', true); @@ -401,7 +382,7 @@ function insertCanvasElements() { hiddenInput.addEventListener("input", function(e) { e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); - console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); + console.log(\`Received input by ${e.inputType}: ${e.data} -> ${inputData}\`); window.lastKey = inputData hiddenInput.value = " "; // We need a character to detect deleting @@ -490,8 +471,8 @@ function insertCanvasElements() { document.body.appendChild(sprintButton); let pauseButton = createTouchButton("pauseButton", "inGame"); pauseButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right: 32vh; width: 8vh; height: 8vh;" - pauseButton.addEventListener("touchstart", function(e){keyEvent("`", "keydown")}, false); - pauseButton.addEventListener("touchend", function(e){keyEvent("`", "keyup")}, false); + pauseButton.addEventListener("touchstart", function(e){keyEvent("\`", "keydown")}, false); + pauseButton.addEventListener("touchend", function(e){keyEvent("\`", "keyup")}, false); document.body.appendChild(pauseButton); let chatButton = createTouchButton("chatButton", "inGame"); chatButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right: 16vh; width: 8vh; height: 8vh;" @@ -540,6 +521,24 @@ function insertCanvasElements() { document.temp = new logManager(); document.temp.init(); } +` +document.documentElement.appendChild(mobileScript) +// Lazy way to hide touch controls through CSS. +let inGameStyle = document.createElement("style"); +inGameStyle.id = "inGameStyle"; +inGameStyle.textContent = ` + .inGame { + display: none; + }`; +document.documentElement.appendChild(inGameStyle); + +let inMenuStyle = document.createElement("style"); +inMenuStyle.id = "inMenuStyle"; +inMenuStyle.textContent = ` + .inMenu { + display: none; + }`; +document.documentElement.appendChild(inMenuStyle); // CSS for touch screen buttons, along with fixing iOS's issues with 100vh ignoring the naviagtion bar, and actually disabling zoom because safari ignores user-scalable=no :( let customStyle = document.createElement("style"); customStyle.textContent = ` From 42a2e8b768da201893fe517bdeb3732231cb4078 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:19:44 -0600 Subject: [PATCH 10/23] Fix for escaping quotes --- eaglermobile.user.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index ae02e8a..759777b 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -61,7 +61,7 @@ function logManager() { // better charCodeAt function String.prototype.toKeyCode = function() { - const keyCodeList = {"0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "backspace": 8, "tab": 9, "enter": 13, "shift": 16, "ctrl": 17, "alt": 18, "pause_break": 19, "caps_lock": 20, "escape": 27, " ": 32, "page_up": 33, "page_down": 34, "end": 35, "home": 36, "left_arrow": 37, "up_arrow": 38, "right_arrow": 39, "down_arrow": 40, "insert": 45, "delete": 46, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "left_window_key": 91, "right_window_key": 92, "select_key": 93, "numpad_0": 96, "numpad_1": 97, "numpad_2": 98, "numpad_3": 99, "numpad_4": 100, "numpad_5": 101, "numpad_6": 102, "numpad_7": 103, "numpad_8": 104, "numpad_9": 105, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "f1": 112, "f2": 113, "f3": 114, "f4": 115, "f5": 116, "f6": 117, "f7": 118, "f8": 119, "f9": 120, "f10": 121, "f11": 122, "f12": 123, "num_lock": 144, "scroll_lock": 145, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "\`": 192, "[": 219, "\\": 220, "]": 221, "\"": 222}; + const keyCodeList = {"0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "backspace": 8, "tab": 9, "enter": 13, "shift": 16, "ctrl": 17, "alt": 18, "pause_break": 19, "caps_lock": 20, "escape": 27, " ": 32, "page_up": 33, "page_down": 34, "end": 35, "home": 36, "left_arrow": 37, "up_arrow": 38, "right_arrow": 39, "down_arrow": 40, "insert": 45, "delete": 46, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "left_window_key": 91, "right_window_key": 92, "select_key": 93, "numpad_0": 96, "numpad_1": 97, "numpad_2": 98, "numpad_3": 99, "numpad_4": 100, "numpad_5": 101, "numpad_6": 102, "numpad_7": 103, "numpad_8": 104, "numpad_9": 105, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "f1": 112, "f2": 113, "f3": 114, "f4": 115, "f5": 116, "f6": 117, "f7": 118, "f8": 119, "f9": 120, "f10": 121, "f11": 122, "f12": 123, "num_lock": 144, "scroll_lock": 145, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "\`": 192, "[": 219, "\\\": 220, "]": 221, "\\"": 222}; return keyCodeList[this]; } // Ignores keydown events that don't have the isValid parameter set to true @@ -382,7 +382,7 @@ function insertCanvasElements() { hiddenInput.addEventListener("input", function(e) { e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); - console.log(\`Received input by ${e.inputType}: ${e.data} -> ${inputData}\`); + console.log("Received input by " + e.inputType + ": " + e.data + " -> " + inputData); window.lastKey = inputData hiddenInput.value = " "; // We need a character to detect deleting @@ -522,7 +522,7 @@ function insertCanvasElements() { document.temp.init(); } ` -document.documentElement.appendChild(mobileScript) +document.documentElement.appendChild(mobileScript); // Lazy way to hide touch controls through CSS. let inGameStyle = document.createElement("style"); inGameStyle.id = "inGameStyle"; From 2a04b33729db3c63864f756797e727febbd31bc7 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:28:00 -0600 Subject: [PATCH 11/23] Reverted injection, trying unsafeWindow again --- eaglermobile.user.js | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 759777b..99e9fb8 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,17 +6,20 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.3-alpha-5 +// @version 3.0.3-alpha-4 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start +// @grant unsafeWindow // ==/UserScript== // THIS IS LAZY AND CAN EXPOSE INTERNALS // IN THE FUTURE, JUST INJECT A SCRIPT TAG -var mobileScript = document.createElement("script"); -mobileScript.id = "mobileScript"; -mobileScript.textContent = ` +try { +window = unsafeWindow ?? window +} catch { + +} function isMobile() { try { @@ -61,7 +64,8 @@ function logManager() { // better charCodeAt function String.prototype.toKeyCode = function() { - const keyCodeList = {"0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "backspace": 8, "tab": 9, "enter": 13, "shift": 16, "ctrl": 17, "alt": 18, "pause_break": 19, "caps_lock": 20, "escape": 27, " ": 32, "page_up": 33, "page_down": 34, "end": 35, "home": 36, "left_arrow": 37, "up_arrow": 38, "right_arrow": 39, "down_arrow": 40, "insert": 45, "delete": 46, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "left_window_key": 91, "right_window_key": 92, "select_key": 93, "numpad_0": 96, "numpad_1": 97, "numpad_2": 98, "numpad_3": 99, "numpad_4": 100, "numpad_5": 101, "numpad_6": 102, "numpad_7": 103, "numpad_8": 104, "numpad_9": 105, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "f1": 112, "f2": 113, "f3": 114, "f4": 115, "f5": 116, "f6": 117, "f7": 118, "f8": 119, "f9": 120, "f10": 121, "f11": 122, "f12": 123, "num_lock": 144, "scroll_lock": 145, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "\`": 192, "[": 219, "\\\": 220, "]": 221, "\\"": 222}; + const keyCodeList = {"0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "backspace": 8, "tab": 9, "enter": 13, "shift": 16, "ctrl": 17, "alt": 18, "pause_break": 19, "caps_lock": 20, "escape": 27, " ": 32, "page_up": 33, "page_down": 34, "end": 35, "home": 36, "left_arrow": 37, "up_arrow": 38, "right_arrow": 39, "down_arrow": 40, "insert": 45, "delete": 46, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "left_window_key": 91, "right_window_key": 92, "select_key": 93, "numpad_0": 96, "numpad_1": 97, "numpad_2": 98, "numpad_3": 99, "numpad_4": 100, "numpad_5": 101, "numpad_6": 102, "numpad_7": 103, "numpad_8": 104, "numpad_9": 105, "*": 106, "+": 107, "-": 109, ".": 110, "/": 111, "f1": 112, "f2": 113, "f3": 114, "f4": 115, "f5": 116, "f6": 117, "f7": 118, "f8": 119, "f9": 120, "f10": 121, "f11": 122, "f12": 123, "num_lock": 144, "scroll_lock": 145, ";": 186, "=": 187, ",": 188, "-": 189, ".": 190, "/": 191, "\u0060": 192, "[": 219, "\u005C": 220, "]": 221, "\u0022": 222}; + return keyCodeList[this]; } // Ignores keydown events that don't have the isValid parameter set to true @@ -195,6 +199,24 @@ document.createElement = function(type, ignore) { return element; } +// Lazy way to hide touch controls through CSS. +let inGameStyle = document.createElement("style"); +inGameStyle.id = "inGameStyle"; +inGameStyle.textContent = ` + .inGame { + display: none; + }`; +document.documentElement.appendChild(inGameStyle); + +let inMenuStyle = document.createElement("style"); +inMenuStyle.id = "inMenuStyle"; +inMenuStyle.textContent = ` + .inMenu { + display: none; + }`; +document.documentElement.appendChild(inMenuStyle); + + // The canvas is created by the client after it finishes unzipping and loading. When the canvas is created, this applies any necessary event listeners function waitForElm(selector) { return new Promise(resolve => { @@ -366,8 +388,8 @@ function insertCanvasElements() { document.body.appendChild(inventoryButton); let exitButton = createTouchButton("exitButton", "inMenu"); exitButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right:8vh; width: 8vh; height: 8vh;" - exitButton.addEventListener("touchstart", function(e){keyEvent("\`", "keydown")}, false); - exitButton.addEventListener("touchend", function(e){keyEvent("\`", "keyup")}, false); + exitButton.addEventListener("touchstart", function(e){keyEvent("`", "keydown")}, false); + exitButton.addEventListener("touchend", function(e){keyEvent("`", "keyup")}, false); document.body.appendChild(exitButton); // input for keyboard button let hiddenInput = document.createElement('input', true); @@ -382,7 +404,7 @@ function insertCanvasElements() { hiddenInput.addEventListener("input", function(e) { e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); - console.log("Received input by " + e.inputType + ": " + e.data + " -> " + inputData); + console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); window.lastKey = inputData hiddenInput.value = " "; // We need a character to detect deleting @@ -471,8 +493,8 @@ function insertCanvasElements() { document.body.appendChild(sprintButton); let pauseButton = createTouchButton("pauseButton", "inGame"); pauseButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right: 32vh; width: 8vh; height: 8vh;" - pauseButton.addEventListener("touchstart", function(e){keyEvent("\`", "keydown")}, false); - pauseButton.addEventListener("touchend", function(e){keyEvent("\`", "keyup")}, false); + pauseButton.addEventListener("touchstart", function(e){keyEvent("`", "keydown")}, false); + pauseButton.addEventListener("touchend", function(e){keyEvent("`", "keyup")}, false); document.body.appendChild(pauseButton); let chatButton = createTouchButton("chatButton", "inGame"); chatButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right: 16vh; width: 8vh; height: 8vh;" @@ -521,24 +543,6 @@ function insertCanvasElements() { document.temp = new logManager(); document.temp.init(); } -` -document.documentElement.appendChild(mobileScript); -// Lazy way to hide touch controls through CSS. -let inGameStyle = document.createElement("style"); -inGameStyle.id = "inGameStyle"; -inGameStyle.textContent = ` - .inGame { - display: none; - }`; -document.documentElement.appendChild(inGameStyle); - -let inMenuStyle = document.createElement("style"); -inMenuStyle.id = "inMenuStyle"; -inMenuStyle.textContent = ` - .inMenu { - display: none; - }`; -document.documentElement.appendChild(inMenuStyle); // CSS for touch screen buttons, along with fixing iOS's issues with 100vh ignoring the naviagtion bar, and actually disabling zoom because safari ignores user-scalable=no :( let customStyle = document.createElement("style"); customStyle.textContent = ` From dc446b317630257e7d3de761c5fad9b8739dc5ca Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:54:38 -0600 Subject: [PATCH 12/23] Unethically unsafe tampermonkey hack This is horrible and its only to test a check on Android This will be changed to simply injecting the script, I hope --- eaglermobile.user.js | 101 +++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 99e9fb8..5cf6461 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,7 +6,7 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.3-alpha-4 +// @version 3.0.3-alpha-5 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start // @grant unsafeWindow @@ -14,11 +14,19 @@ // THIS IS LAZY AND CAN EXPOSE INTERNALS // IN THE FUTURE, JUST INJECT A SCRIPT TAG - +//try { +//var window = unsafeWindow ?? window +//} catch { +// +//} try { -window = unsafeWindow ?? window + if(unsafeWindow) { + console.log("UNSAFE WINDOW RAGGHHH") + } } catch { - + Object.defineProperty(window, "unsafeWindow", { + value: window + }); } function isMobile() { @@ -32,10 +40,11 @@ function isMobile() { if(!isMobile()) { alert("WARNING: This script was created for mobile, and may break functionality in non-mobile browsers!"); } -window.keyboardEnabled = false; -window.crouchLock = false; -window.sprintLock = false; -window.keyboardFix = false; // temporarily set to true until I can figure out whats going wrong with the event listener in charge of switching it + +unsafeWindow.keyboardEnabled = false; +unsafeWindow.crouchLock = false; +unsafeWindow.sprintLock = false; +unsafeWindow.keyboardFix = false; // temporarily set to true until I can figure out whats going wrong with the event listener in charge of switching it // Used for changing touchmove events to mousemove events var previousTouchX = null; var previousTouchY = null; @@ -45,10 +54,10 @@ function logManager() { var self = this; self.init = function () { - console.log('logmanager initialized'); - var old = console.log; + unsafeWindow.console.log('logmanager initialized'); + var old = unsafeWindow.console.log; self.logger = document.getElementById('log'); - console.log = function (message, options) { + unsafeWindow.console.log = function (message, options) { if (typeof message == 'object') { self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; } else { @@ -74,7 +83,7 @@ Object.defineProperty(EventTarget.prototype, "addEventListener", { value: function (type, fn, ...rest) { if(type == 'keydown') { _addEventListener.call(this, type, function(...args) { - if(!args[0].isValid && window.keyboardFix) { + if(!args[0].isValid && unsafeWindow.keyboardFix) { return; } return fn.apply(this, args); @@ -105,7 +114,7 @@ function keyEvent(name, state) { which: charCode }); evt.isValid = true; // Disables fix for bad keyboard input - window.dispatchEvent(evt); + unsafeWindow.dispatchEvent(evt); } function mouseEvent(number, state, canvas) { canvas.dispatchEvent(new PointerEvent(state, {"button": number})) @@ -123,11 +132,11 @@ function setButtonVisibility(pointerLocked) { } // POINTERLOCK // When requestpointerlock is called, this dispatches an event, saves the requested element to window.fakelock, and unhides the touch controls -window.fakelock = null; +unsafeWindow.fakelock = null; Object.defineProperty(Element.prototype, "requestPointerLock", { value: function() { - window.fakelock = this + unsafeWindow.fakelock = this document.dispatchEvent(new Event('pointerlockchange')); setButtonVisibility(true); return true @@ -138,13 +147,13 @@ Object.defineProperty(Element.prototype, "requestPointerLock", { // Makes pointerLockElement return window.fakelock Object.defineProperty(Document.prototype, "pointerLockElement", { get: function() { - return window.fakelock; + return unsafeWindow.fakelock; } }); // When exitPointerLock is called, this dispatches an event, clears the Object.defineProperty(Document.prototype, "exitPointerLock", { value: function() { - window.fakelock = null + unsafeWindow.fakelock = null document.dispatchEvent(new Event('pointerlockchange')); setButtonVisibility(false); return true @@ -152,23 +161,23 @@ Object.defineProperty(Document.prototype, "exitPointerLock", { }); // FULLSCREEN -window.fakefull = null; +unsafeWindow.fakefull = null; // Stops the client from crashing when fullscreen is requested Object.defineProperty(Element.prototype, "requestFullscreen", { value: function() { - window.fakefull = this + unsafeWindow.fakefull = this document.dispatchEvent(new Event('fullscreenchange')); return true } }); Object.defineProperty(document, "fullscreenElement", { get: function() { - return window.fakefull; + return unsafeWindow.fakefull; } }); Object.defineProperty(Document.prototype, "exitFullscreen", { value: function() { - window.fakefull = null + unsafeWindow.fakefull = null document.dispatchEvent(new Event('fullscreenchange')); return true } @@ -188,7 +197,7 @@ document.createElement = function(type, ignore) { element.hidden = true; element.style.display = "none"; }, {passive: false, once: true}); - window.addEventListener('focus', function(e) { + unsafeWindow.addEventListener('focus', function(e) { setTimeout(() => { element.hidden = true; element.style.display = "none"; @@ -246,11 +255,11 @@ function createTouchButton(buttonClass, buttonDisplay, elementName) { function toggleKeyboard() { const keyboardInput = document.getElementById('hiddenInput'); - if (window.keyboardEnabled) { - window.keyboardEnabled = false; + if (unsafeWindow.keyboardEnabled) { + unsafeWindow.keyboardEnabled = false; keyboardInput.blur(); } else { - window.keyboardEnabled = true; + unsafeWindow.keyboardEnabled = true; keyboardInput.select(); } } @@ -269,7 +278,7 @@ function insertCanvasElements() { } e.movementX = touch.pageX - previousTouchX; e.movementY = touch.pageY - previousTouchY; - var evt = window.fakelock ? new MouseEvent("mousemove", {movementX: e.movementX, movementY: e.movementY}) : new WheelEvent("wheel", {"wheelDeltaY": e.movementY}); + var evt = unsafeWindow.fakelock ? new MouseEvent("mousemove", {movementX: e.movementX, movementY: e.movementY}) : new WheelEvent("wheel", {"wheelDeltaY": e.movementY}); canvas.dispatchEvent(evt); previousTouchX = touch.pageX; previousTouchY = touch.pageY; @@ -280,7 +289,7 @@ function insertCanvasElements() { previousTouchY = null; }, false) //Updates button visibility on load - setButtonVisibility(window.fakelock != null); + setButtonVisibility(unsafeWindow.fakelock != null); // Adds all of the touch screen controls // Theres probably a better way to do this but this works for now let strafeRightButton = createTouchButton("strafeRightButton", "inGame", "div"); @@ -306,13 +315,13 @@ function insertCanvasElements() { startTouchX = touch.pageX; } let movementX = touch.pageX - startTouchX; - if((movementX * 10) > window.innerHeight) { + if((movementX * 10) > unsafeWindow.innerHeight) { strafeRightButton.classList.add("active"); strafeLeftButton.classList.remove("active"); keyEvent("d", "keydown"); keyEvent("a", "keyup"); - } else if ((movementX * 10) < (0 - window.innerHeight)) { + } else if ((movementX * 10) < (0 - unsafeWindow.innerHeight)) { strafeLeftButton.classList.add("active"); strafeRightButton.classList.remove("active"); keyEvent("a", "keydown"); @@ -365,18 +374,18 @@ function insertCanvasElements() { crouchButton.style.cssText = "left:10vh;bottom:10vh;" crouchButton.addEventListener("touchstart", function(e){ keyEvent("shift", "keydown") - window.crouchLock = window.crouchLock ? null : false + unsafeWindow.crouchLock = unsafeWindow.crouchLock ? null : false crouchTimer = setTimeout(function(e) { - window.crouchLock = (window.crouchLock != null); + unsafeWindow.crouchLock = (unsafeWindow.crouchLock != null); crouchButton.classList.toggle('active'); }, 1000); }, false); crouchButton.addEventListener("touchend", function(e) { - if(!window.crouchLock) { + if(!unsafeWindow.crouchLock) { keyEvent("shift", "keyup") crouchButton.classList.remove('active'); - window.crouchLock = false + unsafeWindow.crouchLock = false } clearTimeout(crouchTimer); }, false); @@ -404,11 +413,11 @@ function insertCanvasElements() { hiddenInput.addEventListener("input", function(e) { e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); - console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); + unsafeWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); - window.lastKey = inputData + unsafeWindow.lastKey = inputData hiddenInput.value = " "; // We need a character to detect deleting - if(window.keyboardFix) { + if(unsafeWindow.keyboardFix) { const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof if(sliceInputType== 'i') { let isShift = (inputData.toLowerCase() != inputData); @@ -428,12 +437,12 @@ function insertCanvasElements() { } }, false); hiddenInput.addEventListener("keydown", function(e) { - if(!(e.key && e.keyCode && e.which) && !window.keyboardFix) { - console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") - window.keyboardFix = true; - if(window.lastKey) { - keyEvent(window.lastKey, "keydown"); - keyEvent(window.lastKey, "keyup"); + if(!(e.key && e.keyCode && e.which) && !unsafeWindow.keyboardFix) { + unsafeWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") + unsafeWindow.keyboardFix = true; + if(unsafeWindow.lastKey) { + keyEvent(unsafeWindow.lastKey, "keydown"); + keyEvent(unsafeWindow.lastKey, "keyup"); } } }, false); @@ -475,18 +484,18 @@ function insertCanvasElements() { sprintButton.style.cssText = "right:0vh;bottom:10vh;" sprintButton.addEventListener("touchstart", function(e) { keyEvent("r", "keydown"); - window.sprintLock = window.sprintLock ? null : false + unsafeWindow.sprintLock = unsafeWindow.sprintLock ? null : false sprintTimer = setTimeout(function(e) { - window.sprintLock = (window.sprintLock != null); + unsafeWindow.sprintLock = (unsafeWindow.sprintLock != null); sprintButton.classList.toggle('active'); }, 1000); }, false); sprintButton.addEventListener("touchend", function(e) { - if(!window.sprintLock) { + if(!unsafeWindow.sprintLock) { keyEvent("r", "keyup"); sprintButton.classList.remove('active'); - window.sprintLock = false + unsafeWindow.sprintLock = false } clearTimeout(sprintTimer); }, false); From e4411c09a8424916b1d3add003f9625bd0a495f8 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:07:31 -0600 Subject: [PATCH 13/23] Detecting 229 code --- eaglermobile.user.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 5cf6461..b939b2b 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -12,17 +12,10 @@ // @grant unsafeWindow // ==/UserScript== -// THIS IS LAZY AND CAN EXPOSE INTERNALS +// THIS IS LAZY AND DANGEROUS AND CAN EXPOSE USERSCRIPT INTERNALS SO PLEASE REMOVE // IN THE FUTURE, JUST INJECT A SCRIPT TAG -//try { -//var window = unsafeWindow ?? window -//} catch { -// -//} try { - if(unsafeWindow) { - console.log("UNSAFE WINDOW RAGGHHH") - } + unsafeWindow.console.log("UNSAFE WINDOW RAGGHHH") } catch { Object.defineProperty(window, "unsafeWindow", { value: window @@ -437,7 +430,7 @@ function insertCanvasElements() { } }, false); hiddenInput.addEventListener("keydown", function(e) { - if(!(e.key && e.keyCode && e.which) && !unsafeWindow.keyboardFix) { + if((e.keyCode = 229 || e.which = 229) && !unsafeWindow.keyboardFix) { unsafeWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") unsafeWindow.keyboardFix = true; if(unsafeWindow.lastKey) { From 54b32e6034acb0c4c86b524bcf4c82fb86c7805a Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:10:56 -0600 Subject: [PATCH 14/23] Fixed type check error --- eaglermobile.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index b939b2b..9811ebd 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -430,7 +430,7 @@ function insertCanvasElements() { } }, false); hiddenInput.addEventListener("keydown", function(e) { - if((e.keyCode = 229 || e.which = 229) && !unsafeWindow.keyboardFix) { + if((e.keyCode == 229 || e.which == 229) && !unsafeWindow.keyboardFix) { unsafeWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") unsafeWindow.keyboardFix = true; if(unsafeWindow.lastKey) { From 9b19b2c01fba81ca77b5e740154e79b06dcb353b Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:52:05 -0600 Subject: [PATCH 15/23] Added warning for testing --- eaglermobile.user.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 9811ebd..94d8995 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -16,6 +16,7 @@ // IN THE FUTURE, JUST INJECT A SCRIPT TAG try { unsafeWindow.console.log("UNSAFE WINDOW RAGGHHH") + alert("DANGER: This userscript is temporarily using unsafeWindow for testing purposes. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") } catch { Object.defineProperty(window, "unsafeWindow", { value: window @@ -404,6 +405,7 @@ function insertCanvasElements() { hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:10"; hiddenInput.value = " " //Allows delete to be detected before input is changed hiddenInput.addEventListener("input", function(e) { + e.stopImmediatePropagation(); e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); unsafeWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); From 4a786ae25c4b2c77ff3d81db776df957e81a2520 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:44:12 -0600 Subject: [PATCH 16/23] Fix for double input and view height --- eaglermobile.user.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 94d8995..583a26a 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -15,7 +15,7 @@ // THIS IS LAZY AND DANGEROUS AND CAN EXPOSE USERSCRIPT INTERNALS SO PLEASE REMOVE // IN THE FUTURE, JUST INJECT A SCRIPT TAG try { - unsafeWindow.console.log("UNSAFE WINDOW RAGGHHH") + unsafeWindow.console.log("UNSAFE WINDOW"); alert("DANGER: This userscript is temporarily using unsafeWindow for testing purposes. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") } catch { Object.defineProperty(window, "unsafeWindow", { @@ -411,7 +411,8 @@ function insertCanvasElements() { unsafeWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); unsafeWindow.lastKey = inputData - hiddenInput.value = " "; // We need a character to detect deleting + // TEMP ADD BACK +// hiddenInput.value = " "; // We need a character to detect deleting if(unsafeWindow.keyboardFix) { const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof if(sliceInputType== 'i') { @@ -590,7 +591,12 @@ customStyle.textContent = ` } html, body { + height: 100% !important; + height: 100dvh !important; height: -webkit-fill-available !important; + height: -moz-available !important; + height: fill-available !important; + height: stretch !important; touch-action: pan-x pan-y; } .hide { From e58d77cf024910031896bd787fcd7d4c5f9fd773 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:47:34 -0600 Subject: [PATCH 17/23] Removed dvh units --- eaglermobile.user.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 583a26a..22b0701 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -591,12 +591,8 @@ customStyle.textContent = ` } html, body { - height: 100% !important; - height: 100dvh !important; height: -webkit-fill-available !important; height: -moz-available !important; - height: fill-available !important; - height: stretch !important; touch-action: pan-x pan-y; } .hide { From 148885566aad72e212cf30b53dc1443449e99956 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:50:52 -0600 Subject: [PATCH 18/23] Removed moz-fill --- eaglermobile.user.js | 1 - 1 file changed, 1 deletion(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 22b0701..f615a61 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -592,7 +592,6 @@ customStyle.textContent = ` } html, body { height: -webkit-fill-available !important; - height: -moz-available !important; touch-action: pan-x pan-y; } .hide { From 693b37b7efcefd442bfca9d81210b572b9e752b2 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:52:11 -0600 Subject: [PATCH 19/23] Trying to fix crash --- eaglermobile.user.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index f615a61..8c20946 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -15,7 +15,7 @@ // THIS IS LAZY AND DANGEROUS AND CAN EXPOSE USERSCRIPT INTERNALS SO PLEASE REMOVE // IN THE FUTURE, JUST INJECT A SCRIPT TAG try { - unsafeWindow.console.log("UNSAFE WINDOW"); + unsafeWindow.console.log("UNSAFE WINDOW RAGGHHH") alert("DANGER: This userscript is temporarily using unsafeWindow for testing purposes. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") } catch { Object.defineProperty(window, "unsafeWindow", { @@ -411,8 +411,7 @@ function insertCanvasElements() { unsafeWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); unsafeWindow.lastKey = inputData - // TEMP ADD BACK -// hiddenInput.value = " "; // We need a character to detect deleting + //hiddenInput.value = " "; if(unsafeWindow.keyboardFix) { const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof if(sliceInputType== 'i') { From 5c6b049c39866f623a7c8356f9e895f9ae7f5342 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sat, 15 Jun 2024 16:38:50 -0600 Subject: [PATCH 20/23] Testing duplicate input blocking --- eaglermobile.user.js | 143 +++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 61 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 8c20946..039d09e 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -12,13 +12,14 @@ // @grant unsafeWindow // ==/UserScript== -// THIS IS LAZY AND DANGEROUS AND CAN EXPOSE USERSCRIPT INTERNALS SO PLEASE REMOVE -// IN THE FUTURE, JUST INJECT A SCRIPT TAG +// This is generally a bad practice, but we need to run scripts in the main context before the DOM loads. Because we are only matching eaglercraft.com, the use of unsafeWindow should be safe to use. try { - unsafeWindow.console.log("UNSAFE WINDOW RAGGHHH") - alert("DANGER: This userscript is temporarily using unsafeWindow for testing purposes. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") + unsafeWindow.console.warn("DANGER: This userscript is using unsafeWindow. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") + Object.defineProperty(window, "clientWindow", { + value: unsafeWindow + }); } catch { - Object.defineProperty(window, "unsafeWindow", { + Object.defineProperty(window, "clientWindow", { value: window }); } @@ -35,10 +36,12 @@ if(!isMobile()) { alert("WARNING: This script was created for mobile, and may break functionality in non-mobile browsers!"); } -unsafeWindow.keyboardEnabled = false; -unsafeWindow.crouchLock = false; -unsafeWindow.sprintLock = false; -unsafeWindow.keyboardFix = false; // temporarily set to true until I can figure out whats going wrong with the event listener in charge of switching it +clientWindow.keyboardEnabled = false; +clientWindow.crouchLock = false; +clientWindow.sprintLock = false; +clientWindow.keyboardFix = false; +clientWindow.inputFix = false; +clientWindow.blockNextInput = false; // Used for changing touchmove events to mousemove events var previousTouchX = null; var previousTouchY = null; @@ -48,10 +51,10 @@ function logManager() { var self = this; self.init = function () { - unsafeWindow.console.log('logmanager initialized'); - var old = unsafeWindow.console.log; + clientWindow.console.log('logmanager initialized'); + var old = clientWindow.console.log; self.logger = document.getElementById('log'); - unsafeWindow.console.log = function (message, options) { + clientWindow.console.log = function (message, options) { if (typeof message == 'object') { self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; } else { @@ -77,7 +80,7 @@ Object.defineProperty(EventTarget.prototype, "addEventListener", { value: function (type, fn, ...rest) { if(type == 'keydown') { _addEventListener.call(this, type, function(...args) { - if(!args[0].isValid && unsafeWindow.keyboardFix) { + if(!args[0].isValid && clientWindow.keyboardFix) { return; } return fn.apply(this, args); @@ -108,7 +111,7 @@ function keyEvent(name, state) { which: charCode }); evt.isValid = true; // Disables fix for bad keyboard input - unsafeWindow.dispatchEvent(evt); + clientWindow.dispatchEvent(evt); } function mouseEvent(number, state, canvas) { canvas.dispatchEvent(new PointerEvent(state, {"button": number})) @@ -125,12 +128,12 @@ function setButtonVisibility(pointerLocked) { inMenuStyle.disabled = !pointerLocked; } // POINTERLOCK -// When requestpointerlock is called, this dispatches an event, saves the requested element to window.fakelock, and unhides the touch controls -unsafeWindow.fakelock = null; +// When requestpointerlock is called, this dispatches an event, saves the requested element to clientWindow.fakelock, and unhides the touch controls +clientWindow.fakelock = null; Object.defineProperty(Element.prototype, "requestPointerLock", { value: function() { - unsafeWindow.fakelock = this + clientWindow.fakelock = this document.dispatchEvent(new Event('pointerlockchange')); setButtonVisibility(true); return true @@ -138,16 +141,16 @@ Object.defineProperty(Element.prototype, "requestPointerLock", { }); -// Makes pointerLockElement return window.fakelock +// Makes pointerLockElement return clientWindow.fakelock Object.defineProperty(Document.prototype, "pointerLockElement", { get: function() { - return unsafeWindow.fakelock; + return clientWindow.fakelock; } }); // When exitPointerLock is called, this dispatches an event, clears the Object.defineProperty(Document.prototype, "exitPointerLock", { value: function() { - unsafeWindow.fakelock = null + clientWindow.fakelock = null document.dispatchEvent(new Event('pointerlockchange')); setButtonVisibility(false); return true @@ -155,23 +158,23 @@ Object.defineProperty(Document.prototype, "exitPointerLock", { }); // FULLSCREEN -unsafeWindow.fakefull = null; +clientWindow.fakefull = null; // Stops the client from crashing when fullscreen is requested Object.defineProperty(Element.prototype, "requestFullscreen", { value: function() { - unsafeWindow.fakefull = this + clientWindow.fakefull = this document.dispatchEvent(new Event('fullscreenchange')); return true } }); Object.defineProperty(document, "fullscreenElement", { get: function() { - return unsafeWindow.fakefull; + return clientWindow.fakefull; } }); Object.defineProperty(Document.prototype, "exitFullscreen", { value: function() { - unsafeWindow.fakefull = null + clientWindow.fakefull = null document.dispatchEvent(new Event('fullscreenchange')); return true } @@ -191,7 +194,7 @@ document.createElement = function(type, ignore) { element.hidden = true; element.style.display = "none"; }, {passive: false, once: true}); - unsafeWindow.addEventListener('focus', function(e) { + clientWindow.addEventListener('focus', function(e) { setTimeout(() => { element.hidden = true; element.style.display = "none"; @@ -249,11 +252,11 @@ function createTouchButton(buttonClass, buttonDisplay, elementName) { function toggleKeyboard() { const keyboardInput = document.getElementById('hiddenInput'); - if (unsafeWindow.keyboardEnabled) { - unsafeWindow.keyboardEnabled = false; + if (clientWindow.keyboardEnabled) { + clientWindow.keyboardEnabled = false; keyboardInput.blur(); } else { - unsafeWindow.keyboardEnabled = true; + clientWindow.keyboardEnabled = true; keyboardInput.select(); } } @@ -272,7 +275,7 @@ function insertCanvasElements() { } e.movementX = touch.pageX - previousTouchX; e.movementY = touch.pageY - previousTouchY; - var evt = unsafeWindow.fakelock ? new MouseEvent("mousemove", {movementX: e.movementX, movementY: e.movementY}) : new WheelEvent("wheel", {"wheelDeltaY": e.movementY}); + var evt = clientWindow.fakelock ? new MouseEvent("mousemove", {movementX: e.movementX, movementY: e.movementY}) : new WheelEvent("wheel", {"wheelDeltaY": e.movementY}); canvas.dispatchEvent(evt); previousTouchX = touch.pageX; previousTouchY = touch.pageY; @@ -283,7 +286,7 @@ function insertCanvasElements() { previousTouchY = null; }, false) //Updates button visibility on load - setButtonVisibility(unsafeWindow.fakelock != null); + setButtonVisibility(clientWindow.fakelock != null); // Adds all of the touch screen controls // Theres probably a better way to do this but this works for now let strafeRightButton = createTouchButton("strafeRightButton", "inGame", "div"); @@ -309,13 +312,13 @@ function insertCanvasElements() { startTouchX = touch.pageX; } let movementX = touch.pageX - startTouchX; - if((movementX * 10) > unsafeWindow.innerHeight) { + if((movementX * 10) > clientWindow.innerHeight) { strafeRightButton.classList.add("active"); strafeLeftButton.classList.remove("active"); keyEvent("d", "keydown"); keyEvent("a", "keyup"); - } else if ((movementX * 10) < (0 - unsafeWindow.innerHeight)) { + } else if ((movementX * 10) < (0 - clientWindow.innerHeight)) { strafeLeftButton.classList.add("active"); strafeRightButton.classList.remove("active"); keyEvent("a", "keydown"); @@ -368,18 +371,18 @@ function insertCanvasElements() { crouchButton.style.cssText = "left:10vh;bottom:10vh;" crouchButton.addEventListener("touchstart", function(e){ keyEvent("shift", "keydown") - unsafeWindow.crouchLock = unsafeWindow.crouchLock ? null : false + clientWindow.crouchLock = clientWindow.crouchLock ? null : false crouchTimer = setTimeout(function(e) { - unsafeWindow.crouchLock = (unsafeWindow.crouchLock != null); + clientWindow.crouchLock = (clientWindow.crouchLock != null); crouchButton.classList.toggle('active'); }, 1000); }, false); crouchButton.addEventListener("touchend", function(e) { - if(!unsafeWindow.crouchLock) { + if(!clientWindow.crouchLock) { keyEvent("shift", "keyup") crouchButton.classList.remove('active'); - unsafeWindow.crouchLock = false + clientWindow.crouchLock = false } clearTimeout(crouchTimer); }, false); @@ -408,36 +411,54 @@ function insertCanvasElements() { e.stopImmediatePropagation(); e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); - unsafeWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); + if(!clientWindow.lastKey) { // If we get an event before any keys have been pressed, we know that setting the hiddenInput creates duplicate input events, so we can apply the fix + clientWindow.console.warn("Enabling blocking duplicate key events. Some functionality may be lost.") + // TEMP REMOVE + clientWindow.console.log("Enabling blocking duplicate key events. Some functionality may be lost.") + // TEMP + clientWindow.inputFix = true; + } + clientWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); - unsafeWindow.lastKey = inputData - //hiddenInput.value = " "; - if(unsafeWindow.keyboardFix) { - const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof + hiddenInput.value = " "; + if(clientWindow.keyboardFix) { + const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof, but its the easiest way to deal with Android if(sliceInputType== 'i') { - let isShift = (inputData.toLowerCase() != inputData); - if(isShift) { - keyEvent("shift", "keydown") - keyEvent(inputData, "keydown"); - keyEvent(inputData, "keyup"); - keyEvent("shift", "keyup") - } else { - keyEvent(inputData, "keydown"); - keyEvent(inputData, "keyup"); - } + const isDuplicate = (clientWindow.lastKey == inputData) && clientWindow.blockNextInput && clientWindow.inputFix; + if(isDuplicate) { + clientWindow.blockNextInput = false; + } else { + let isShift = (inputData.toLowerCase() != inputData); + if(isShift) { + keyEvent("shift", "keydown") + keyEvent(inputData, "keydown"); + keyEvent(inputData, "keyup"); + keyEvent("shift", "keyup") + } else { + keyEvent(inputData, "keydown"); + keyEvent(inputData, "keyup"); + } + clientWindow.blockNextInput = true; + } } else if (sliceInputType == 'd') { keyEvent("backspace", "keydown"); keyEvent("backspace", "keyup"); + clientWindow.blockNextInput = false; } } + clientWindow.lastKey = inputData + }, false); hiddenInput.addEventListener("keydown", function(e) { - if((e.keyCode == 229 || e.which == 229) && !unsafeWindow.keyboardFix) { - unsafeWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") - unsafeWindow.keyboardFix = true; - if(unsafeWindow.lastKey) { - keyEvent(unsafeWindow.lastKey, "keydown"); - keyEvent(unsafeWindow.lastKey, "keyup"); + if((e.keyCode == 229 || e.which == 229) && !clientWindow.keyboardFix) { + // TEMP REMOVE + clientWindow.console.log("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") + // TEMP + clientWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") + clientWindow.keyboardFix = true; + if(clientWindow.lastKey) { + keyEvent(clientWindow.lastKey, "keydown"); + keyEvent(clientWindow.lastKey, "keyup"); } } }, false); @@ -479,18 +500,18 @@ function insertCanvasElements() { sprintButton.style.cssText = "right:0vh;bottom:10vh;" sprintButton.addEventListener("touchstart", function(e) { keyEvent("r", "keydown"); - unsafeWindow.sprintLock = unsafeWindow.sprintLock ? null : false + clientWindow.sprintLock = clientWindow.sprintLock ? null : false sprintTimer = setTimeout(function(e) { - unsafeWindow.sprintLock = (unsafeWindow.sprintLock != null); + clientWindow.sprintLock = (clientWindow.sprintLock != null); sprintButton.classList.toggle('active'); }, 1000); }, false); sprintButton.addEventListener("touchend", function(e) { - if(!unsafeWindow.sprintLock) { + if(!clientWindow.sprintLock) { keyEvent("r", "keyup"); sprintButton.classList.remove('active'); - unsafeWindow.sprintLock = false + clientWindow.sprintLock = false } clearTimeout(sprintTimer); }, false); From 6f34ca6a761312f500724bc44e499a6ff3fef8ba Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sat, 15 Jun 2024 17:00:21 -0600 Subject: [PATCH 21/23] Remove temp scripts --- eaglermobile.user.js | 52 ++++++-------------------------------------- 1 file changed, 7 insertions(+), 45 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 039d09e..1289cfa 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -6,13 +6,14 @@ // @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @license Apache License 2.0 - http://www.apache.org/licenses/ // @match https://eaglercraft.com/mc/* -// @version 3.0.3-alpha-5 +// @version 3.0.3 // @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js // @run-at document-start // @grant unsafeWindow // ==/UserScript== // This is generally a bad practice, but we need to run scripts in the main context before the DOM loads. Because we are only matching eaglercraft.com, the use of unsafeWindow should be safe to use. +// If someone knows a better way of doing this, please create an issue try { unsafeWindow.console.warn("DANGER: This userscript is using unsafeWindow. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") Object.defineProperty(window, "clientWindow", { @@ -46,27 +47,6 @@ clientWindow.blockNextInput = false; var previousTouchX = null; var previousTouchY = null; var startTouchX = null; -//TEMP REMOVE -function logManager() { - var self = this; - - self.init = function () { - clientWindow.console.log('logmanager initialized'); - var old = clientWindow.console.log; - self.logger = document.getElementById('log'); - clientWindow.console.log = function (message, options) { - if (typeof message == 'object') { - self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '
' + self.logger.innerHTML; - } else { - self.logger.innerHTML = message + '
' + self.logger.innerHTML; - } - } - } - self.toggleLogVisibility = function () { - return $(self.logger).toggle(); - }; -} - // better charCodeAt function String.prototype.toKeyCode = function() { @@ -372,7 +352,7 @@ function insertCanvasElements() { crouchButton.addEventListener("touchstart", function(e){ keyEvent("shift", "keydown") clientWindow.crouchLock = clientWindow.crouchLock ? null : false - crouchTimer = setTimeout(function(e) { + clientWindow.crouchTimer = setTimeout(function(e) { clientWindow.crouchLock = (clientWindow.crouchLock != null); crouchButton.classList.toggle('active'); }, 1000); @@ -384,7 +364,7 @@ function insertCanvasElements() { crouchButton.classList.remove('active'); clientWindow.crouchLock = false } - clearTimeout(crouchTimer); + clearTimeout(clientWindow.crouchTimer); }, false); document.body.appendChild(crouchButton); let inventoryButton = createTouchButton("inventoryButton", "inGame"); @@ -402,10 +382,7 @@ function insertCanvasElements() { hiddenInput.id = "hiddenInput" hiddenInput.classList.add("inMenu") // We are hiding the text input behind button because opacity was causing problems. - //TEMP REVERT - //hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;"; - - hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:10"; + hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;"; hiddenInput.value = " " //Allows delete to be detected before input is changed hiddenInput.addEventListener("input", function(e) { e.stopImmediatePropagation(); @@ -413,9 +390,6 @@ function insertCanvasElements() { let inputData = e.data == null ? "delete" : e.data.slice(-1); if(!clientWindow.lastKey) { // If we get an event before any keys have been pressed, we know that setting the hiddenInput creates duplicate input events, so we can apply the fix clientWindow.console.warn("Enabling blocking duplicate key events. Some functionality may be lost.") - // TEMP REMOVE - clientWindow.console.log("Enabling blocking duplicate key events. Some functionality may be lost.") - // TEMP clientWindow.inputFix = true; } clientWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); @@ -451,9 +425,6 @@ function insertCanvasElements() { }, false); hiddenInput.addEventListener("keydown", function(e) { if((e.keyCode == 229 || e.which == 229) && !clientWindow.keyboardFix) { - // TEMP REMOVE - clientWindow.console.log("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") - // TEMP clientWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") clientWindow.keyboardFix = true; if(clientWindow.lastKey) { @@ -501,7 +472,7 @@ function insertCanvasElements() { sprintButton.addEventListener("touchstart", function(e) { keyEvent("r", "keydown"); clientWindow.sprintLock = clientWindow.sprintLock ? null : false - sprintTimer = setTimeout(function(e) { + clientWindow.sprintTimer = setTimeout(function(e) { clientWindow.sprintLock = (clientWindow.sprintLock != null); sprintButton.classList.toggle('active'); }, 1000); @@ -513,7 +484,7 @@ function insertCanvasElements() { sprintButton.classList.remove('active'); clientWindow.sprintLock = false } - clearTimeout(sprintTimer); + clearTimeout(clientWindow.sprintTimer); }, false); document.body.appendChild(sprintButton); let pauseButton = createTouchButton("pauseButton", "inGame"); @@ -558,15 +529,6 @@ function insertCanvasElements() { keyEvent("3", "keyup"); }, false); document.body.appendChild(coordinatesButton); - //TEMP REMOVE - var temp = document.createElement("div"); - temp.id = "log"; - temp.classList.add("log"); - temp.style.cssText= "position: absolute; top: 8vh; margin: auto; left: 0vh; right: 0vh; height: auto; z-index:10; min-height:8vh; background:white"; - temp.innerHtml = "Loading..." - document.body.appendChild(temp); - document.temp = new logManager(); - document.temp.init(); } // CSS for touch screen buttons, along with fixing iOS's issues with 100vh ignoring the naviagtion bar, and actually disabling zoom because safari ignores user-scalable=no :( let customStyle = document.createElement("style"); From 275ed426025fc53d230a99ab89a658929b1698b5 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sat, 15 Jun 2024 19:06:14 -0600 Subject: [PATCH 22/23] Update eaglermobile.user.js --- eaglermobile.user.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 1289cfa..355cf07 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -227,6 +227,7 @@ function createTouchButton(buttonClass, buttonDisplay, elementName) { touchButton.classList.add(buttonDisplay); touchButton.classList.add("mobileControl"); touchButton.addEventListener("touchmove", function(e){e.preventDefault()}, false); + touchButton.addEventListener(“contextmenu”, function(e){e.preventDefault()}); return touchButton; } @@ -550,6 +551,7 @@ customStyle.textContent = ` outline:none; box-shadow: none; border: none; + pointer-events: none !important; } .mobileControl:active, .mobileControl.active { position: absolute; @@ -570,11 +572,19 @@ customStyle.textContent = ` outline:none; box-shadow: none; border: none; - + pointer-events: none !important; } - html, body { + html, body, canvas { height: -webkit-fill-available !important; touch-action: pan-x pan-y; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + outline: none; + -webkit-tap-highlight-color: rgba(255, 255, 255, 0); } .hide { display: none; From e4b4a0be61ea391c671190c2949f42e19d814c9d Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Sat, 15 Jun 2024 19:22:49 -0600 Subject: [PATCH 23/23] Fixed formatting issues Detabbed --- eaglermobile.user.js | 136 +++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 355cf07..50805c0 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -15,14 +15,14 @@ // This is generally a bad practice, but we need to run scripts in the main context before the DOM loads. Because we are only matching eaglercraft.com, the use of unsafeWindow should be safe to use. // If someone knows a better way of doing this, please create an issue try { - unsafeWindow.console.warn("DANGER: This userscript is using unsafeWindow. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") + unsafeWindow.console.warn("DANGER: This userscript is using unsafeWindow. Unsafe websites could potentially use this to gain access to data and other content that the browser normally wouldn't allow!") Object.defineProperty(window, "clientWindow", { - value: unsafeWindow - }); + value: unsafeWindow + }); } catch { - Object.defineProperty(window, "clientWindow", { - value: window - }); + Object.defineProperty(window, "clientWindow", { + value: window + }); } function isMobile() { @@ -112,12 +112,12 @@ function setButtonVisibility(pointerLocked) { clientWindow.fakelock = null; Object.defineProperty(Element.prototype, "requestPointerLock", { - value: function() { - clientWindow.fakelock = this - document.dispatchEvent(new Event('pointerlockchange')); - setButtonVisibility(true); - return true - } + value: function() { + clientWindow.fakelock = this + document.dispatchEvent(new Event('pointerlockchange')); + setButtonVisibility(true); + return true + } }); @@ -129,23 +129,23 @@ Object.defineProperty(Document.prototype, "pointerLockElement", { }); // When exitPointerLock is called, this dispatches an event, clears the Object.defineProperty(Document.prototype, "exitPointerLock", { - value: function() { - clientWindow.fakelock = null - document.dispatchEvent(new Event('pointerlockchange')); - setButtonVisibility(false); - return true - } + value: function() { + clientWindow.fakelock = null + document.dispatchEvent(new Event('pointerlockchange')); + setButtonVisibility(false); + return true + } }); // FULLSCREEN clientWindow.fakefull = null; // Stops the client from crashing when fullscreen is requested Object.defineProperty(Element.prototype, "requestFullscreen", { - value: function() { - clientWindow.fakefull = this - document.dispatchEvent(new Event('fullscreenchange')); - return true - } + value: function() { + clientWindow.fakefull = this + document.dispatchEvent(new Event('fullscreenchange')); + return true + } }); Object.defineProperty(document, "fullscreenElement", { get: function() { @@ -153,11 +153,11 @@ Object.defineProperty(document, "fullscreenElement", { } }); Object.defineProperty(Document.prototype, "exitFullscreen", { - value: function() { - clientWindow.fakefull = null - document.dispatchEvent(new Event('fullscreenchange')); - return true - } + value: function() { + clientWindow.fakefull = null + document.dispatchEvent(new Event('fullscreenchange')); + return true + } }); // FILE UPLOADING @@ -168,16 +168,16 @@ document.createElement = function(type, ignore) { this._createElement = _createElement; var element = this._createElement(type); if(type == "input" && !ignore) { - document.querySelectorAll('#fileUpload').forEach(e => e.parentNode.removeChild(e)); - element.id = "fileUpload"; - element.addEventListener('change', function(e) { - element.hidden = true; - element.style.display = "none"; - }, {passive: false, once: true}); - clientWindow.addEventListener('focus', function(e) { + document.querySelectorAll('#fileUpload').forEach(e => e.parentNode.removeChild(e)); + element.id = "fileUpload"; + element.addEventListener('change', function(e) { + element.hidden = true; + element.style.display = "none"; + }, {passive: false, once: true}); + clientWindow.addEventListener('focus', function(e) { setTimeout(() => { element.hidden = true; - element.style.display = "none"; + element.style.display = "none"; }, 300) }, { once: true }) document.body.appendChild(element); @@ -387,34 +387,34 @@ function insertCanvasElements() { hiddenInput.value = " " //Allows delete to be detected before input is changed hiddenInput.addEventListener("input", function(e) { e.stopImmediatePropagation(); - e.preventDefault(true); + e.preventDefault(true); let inputData = e.data == null ? "delete" : e.data.slice(-1); if(!clientWindow.lastKey) { // If we get an event before any keys have been pressed, we know that setting the hiddenInput creates duplicate input events, so we can apply the fix - clientWindow.console.warn("Enabling blocking duplicate key events. Some functionality may be lost.") - clientWindow.inputFix = true; + clientWindow.console.warn("Enabling blocking duplicate key events. Some functionality may be lost.") + clientWindow.inputFix = true; } clientWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`); hiddenInput.value = " "; if(clientWindow.keyboardFix) { - const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof, but its the easiest way to deal with Android + const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof, but its the easiest way to deal with Android if(sliceInputType== 'i') { - const isDuplicate = (clientWindow.lastKey == inputData) && clientWindow.blockNextInput && clientWindow.inputFix; - if(isDuplicate) { - clientWindow.blockNextInput = false; - } else { - let isShift = (inputData.toLowerCase() != inputData); - if(isShift) { - keyEvent("shift", "keydown") - keyEvent(inputData, "keydown"); - keyEvent(inputData, "keyup"); - keyEvent("shift", "keyup") - } else { - keyEvent(inputData, "keydown"); - keyEvent(inputData, "keyup"); - } - clientWindow.blockNextInput = true; - } + const isDuplicate = (clientWindow.lastKey == inputData) && clientWindow.blockNextInput && clientWindow.inputFix; + if(isDuplicate) { + clientWindow.blockNextInput = false; + } else { + let isShift = (inputData.toLowerCase() != inputData); + if(isShift) { + keyEvent("shift", "keydown") + keyEvent(inputData, "keydown"); + keyEvent(inputData, "keyup"); + keyEvent("shift", "keyup") + } else { + keyEvent(inputData, "keydown"); + keyEvent(inputData, "keyup"); + } + clientWindow.blockNextInput = true; + } } else if (sliceInputType == 'd') { keyEvent("backspace", "keydown"); keyEvent("backspace", "keyup"); @@ -426,11 +426,11 @@ function insertCanvasElements() { }, false); hiddenInput.addEventListener("keydown", function(e) { if((e.keyCode == 229 || e.which == 229) && !clientWindow.keyboardFix) { - clientWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") + clientWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.") clientWindow.keyboardFix = true; if(clientWindow.lastKey) { - keyEvent(clientWindow.lastKey, "keydown"); - keyEvent(clientWindow.lastKey, "keyup"); + keyEvent(clientWindow.lastKey, "keydown"); + keyEvent(clientWindow.lastKey, "keyup"); } } }, false); @@ -572,7 +572,7 @@ customStyle.textContent = ` outline:none; box-shadow: none; border: none; - pointer-events: none !important; + pointer-events: none !important; } html, body, canvas { height: -webkit-fill-available !important; @@ -590,14 +590,14 @@ customStyle.textContent = ` display: none; } #fileUpload { - position: absolute; - left: 0; - right: 100vw; - top: 0; - bottom: 100vh; - width: 100vw; - height: 100vh; - background-color:rgba(255,255,255,0.5); + position: absolute; + left: 0; + right: 100vw; + top: 0; + bottom: 100vh; + width: 100vw; + height: 100vh; + background-color:rgba(255,255,255,0.5); } .strafeRightButton { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAAAWoAMABAAAAAEAAAAWAAAAAA78HUQAAAIwaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4yMjwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yMjwvZXhpZjpQaXhlbFhEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOkNvbG9yU3BhY2U+MTwvZXhpZjpDb2xvclNwYWNlPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KhDb0tQAAANRJREFUOBHVlMENwyAMRWnVHcqIjMEYzJAemlUidQh6aFZIApIt20FgUC/JxTb8/2wRgTFX+25i4E3UvSXyMDkIGeqc64VlfQgBfJnJwAC11oJIFWOMFJ6Zd+nshSZ/yXMCy0aj9aPH6L1HOc1xkSQqcAtCeJhWwSNAIA+dsaZhFawBwIQyVsFJLOGylkCom+ASHMy1WP151KidFDynieF6gkATSx42cYzf43o+TUnYajBNLyZh4LSzLB8mGC3YUczze5Rj1vXHvPTZTBt/e+hZl0sUO9qPMTJ6UlWFAAAAAElFTkSuQmCC");