From 82a70b76491145609f5f6c96a64c934766ac9d5c Mon Sep 17 00:00:00 2001 From: lax1dude Date: Thu, 26 Sep 2024 21:47:56 -0700 Subject: [PATCH] Update #39 - Fix various issues with the client --- README.md | 1 + client_version | 2 +- .../net/minecraft/client/Minecraft.edit.java | 2 +- .../client/settings/GameSettings.edit.java | 12 +- .../assets/minecraft/lang/en_US.edit.lang | 10 +- .../v1_8/internal/PlatformInput.java | 6 +- .../lax1dude/eaglercraft/v1_8/ArrayUtils.java | 2 +- .../eaglercraft/v1_8/EaglercraftVersion.java | 8 +- .../minecraft/EaglerFolderResourcePack.java | 6 +- .../v1_8/profile/EaglerProfile.java | 7 +- .../profile/GuiScreenDefaultUsernameNote.java | 61 +++++++ .../v1_8/profile/GuiScreenEditProfile.java | 6 +- sources/resources/EPKVersionIdentifier.txt | 1 + .../opts_template_eaglercraftX_1_8.txt | 3 +- .../opts_template_eaglercraftX_1_8_demo.txt | 3 +- ...template_eaglercraftX_1_8_html5Cursors.txt | 3 +- .../setup/workspace_template/CompileJS.bat | 2 +- .../boot_menu/teavm/BootMenuEntryPoint.java | 7 + .../v1_8/internal/PlatformInput.java | 8 +- .../v1_8/internal/PlatformRuntime.java | 36 ++-- .../internal/teavm/EPKDownloadHelper.java | 160 ++++++++++++++++++ .../teavm/TeaVMClientConfigAdapter.java | 8 + .../v1_8/internal/teavm/TeaVMFetchJS.java | 2 +- .../teavm/opts/JSEaglercraftXOptsRoot.java | 3 + 24 files changed, 314 insertions(+), 45 deletions(-) create mode 100644 sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenDefaultUsernameNote.java create mode 100644 sources/resources/EPKVersionIdentifier.txt create mode 100644 sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/EPKDownloadHelper.java diff --git a/README.md b/README.md index 5fcdc4b9..31abe10e 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ The default eaglercraftXOpts values is this: - `eaglerNoDelay:` can be used to disable "Vigg's Algorithm", an algorithm that delays and combines multiple EaglercraftX packets together if they are sent in the same tick (does not affect regular Minecraft 1.8 packets) - `ramdiskMode:` if worlds and resource packs should be stored in RAM instead of IndexedDB - `singleThreadMode:` if the game should run the client and integrated server in the same context instead of creating a worker object +- `enableEPKVersionCheck:` if the game should attempt to bypass the browser's cache and retry downloading assets.epk when its outdated - `hooks:` can be used to define JavaScript callbacks for certain events * `localStorageSaved:` JavaScript callback to save local storage keys (key, data) * `localStorageLoaded:` JavaScript callback to load local storage keys (key) returns data diff --git a/client_version b/client_version index 15bda99c..60582c56 100644 --- a/client_version +++ b/client_version @@ -1 +1 @@ -u38 \ No newline at end of file +u39 \ No newline at end of file diff --git a/patches/minecraft/net/minecraft/client/Minecraft.edit.java b/patches/minecraft/net/minecraft/client/Minecraft.edit.java index 1d14e426..aa054a85 100644 --- a/patches/minecraft/net/minecraft/client/Minecraft.edit.java +++ b/patches/minecraft/net/minecraft/client/Minecraft.edit.java @@ -866,7 +866,7 @@ ~ int j = Mouse.getEventDWheel(); ~ if (j != 0) { ~ if (this.isZoomKey) { -~ this.adjustedZoomValue = MathHelper.clamp_float(adjustedZoomValue - j * 4.0f, 5.0f, +~ this.adjustedZoomValue = MathHelper.clamp_float(adjustedZoomValue - j * 4.0f, 4.0f, ~ 32.0f); ~ } else if (this.thePlayer.isSpectator()) { ~ j = j < 0 ? -1 : 1; diff --git a/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java b/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java index b99e5cee..26e13455 100644 --- a/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java +++ b/patches/minecraft/net/minecraft/client/settings/GameSettings.edit.java @@ -95,7 +95,7 @@ ~ public int guiScale = 3; -> INSERT 3 : 22 @ 3 +> INSERT 3 : 23 @ 3 + public boolean hudFps = true; + public boolean hudCoords = true; @@ -116,6 +116,7 @@ + public boolean enableProfanityFilter = false; + public boolean hasShownProfanityFilter = false; + public float touchControlOpacity = 1.0f; ++ public boolean hideDefaultUsernameWarning = false; > CHANGE 1 : 15 @ 1 : 2 @@ -535,7 +536,7 @@ ~ for (EnumPlayerModelParts enumplayermodelparts : EnumPlayerModelParts._VALUES) { -> INSERT 4 : 66 @ 4 +> INSERT 4 : 70 @ 4 + + if (astring[0].equals("enableFNAWSkins")) { @@ -598,6 +599,10 @@ + touchControlOpacity = parseFloat(astring[1]); + } + ++ if (astring[0].equals("hideDefaultUsernameWarning")) { ++ this.hideDefaultUsernameWarning = astring[1].equals("true"); ++ } ++ + deferredShaderConf.readOption(astring[0], astring[1]); > CHANGE 6 : 23 @ 6 : 7 @@ -661,7 +666,7 @@ > DELETE 9 @ 9 : 20 -> INSERT 5 : 35 @ 5 +> INSERT 5 : 36 @ 5 + printwriter.println("hudFps:" + this.hudFps); + printwriter.println("hudWorld:" + this.hudWorld); @@ -693,6 +698,7 @@ + printwriter.println("screenRecordGameVolume:" + this.screenRecordGameVolume); + printwriter.println("screenRecordMicVolume:" + this.screenRecordMicVolume); + printwriter.println("touchControlOpacity:" + this.touchControlOpacity); ++ printwriter.println("hideDefaultUsernameWarning:" + this.hideDefaultUsernameWarning); > CHANGE 5 : 8 @ 5 : 6 diff --git a/patches/resources/assets/minecraft/lang/en_US.edit.lang b/patches/resources/assets/minecraft/lang/en_US.edit.lang index 26b05afe..3ca9626e 100644 --- a/patches/resources/assets/minecraft/lang/en_US.edit.lang +++ b/patches/resources/assets/minecraft/lang/en_US.edit.lang @@ -16,7 +16,7 @@ ~ eaglercraft.resourcePack.load.loading=Loading resource pack... ~ eaglercraft.resourcePack.load.deleting=Deleting resource pack... -> INSERT 1 : 231 @ 1 +> INSERT 1 : 239 @ 1 + eaglercraft.gui.exitKey=Use '%s' to close this screen! + eaglercraft.gui.exitKeyRetarded=Use Backtick (`) to close this screen! @@ -43,6 +43,14 @@ + + eaglercraft.editProfile.importExport=Import/Export + ++ eaglercraft.defaultUsernameDetected.title=Default Username Detected ++ eaglercraft.defaultUsernameDetected.text0=The username "%s" was auto-generated by Eaglercraft ++ eaglercraft.defaultUsernameDetected.text1=It may already be taken on the largest servers ++ eaglercraft.defaultUsernameDetected.text2=Would you like to pick a different username instead? ++ eaglercraft.defaultUsernameDetected.changeUsername=Change Username ++ eaglercraft.defaultUsernameDetected.continueAnyway=Continue Anyway ++ eaglercraft.defaultUsernameDetected.doNotShow=Do not show again ++ + eaglercraft.settingsBackup.importExport.title=What do you wanna do? + eaglercraft.settingsBackup.importExport.import=Import Profile and Settings... + eaglercraft.settingsBackup.importExport.export=Export Profile and Settings... diff --git a/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java b/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java index d8d15cd5..222ab469 100644 --- a/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java +++ b/sources/lwjgl/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java @@ -479,7 +479,11 @@ public class PlatformInput { } public static int mouseGetEventDWheel() { - return (int)currentMouseEvent.wheel; + return fixWheel(currentMouseEvent.wheel); + } + + private static int fixWheel(float val) { + return (val > 0.0f ? 1 : (val < 0.0f ? -1 : 0)); } public static int mouseGetX() { diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/ArrayUtils.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/ArrayUtils.java index 8335246e..7a90f358 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/ArrayUtils.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/ArrayUtils.java @@ -61,7 +61,7 @@ public class ArrayUtils { public static String hexString(byte[] bytesIn) { char[] ret = new char[bytesIn.length << 1]; for(int i = 0; i < bytesIn.length; ++i) { - ret[i << 1] = hex.charAt((bytesIn[i] >> 4) & 15); + ret[i << 1] = hex.charAt((bytesIn[i] >>> 4) & 15); ret[(i << 1) + 1] = hex.charAt(bytesIn[i] & 15); } return new String(ret); diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java index eb84d36b..bac19c67 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/EaglercraftVersion.java @@ -10,7 +10,7 @@ public class EaglercraftVersion { /// Customize these to fit your fork: public static final String projectForkName = "EaglercraftX"; - public static final String projectForkVersion = "u38"; + public static final String projectForkVersion = "u39"; public static final String projectForkVendor = "lax1dude"; public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; @@ -20,18 +20,20 @@ public class EaglercraftVersion { public static final String projectOriginName = "EaglercraftX"; public static final String projectOriginAuthor = "lax1dude"; public static final String projectOriginRevision = "1.8"; - public static final String projectOriginVersion = "u38"; + public static final String projectOriginVersion = "u39"; public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace + // EPK Version Identifier + public static final String EPKVersionIdentifier = "u39"; // Set to null to disable EPK version check // Updating configuration public static final boolean enableUpdateService = true; public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client"; - public static final int updateBundlePackageVersionInt = 38; + public static final int updateBundlePackageVersionInt = 39; public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/EaglerFolderResourcePack.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/EaglerFolderResourcePack.java index e8ccb4f1..9cc53046 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/EaglerFolderResourcePack.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/EaglerFolderResourcePack.java @@ -271,6 +271,7 @@ public class EaglerFolderResourcePack extends AbstractResourcePack { public static void loadRemoteResourcePack(String url, String hash, Consumer cb, Consumer ast, Runnable loading) { if (!isSupported || !hash.matches("^[a-f0-9]{40}$")) { + logger.error("Invalid character in resource pack hash! (is it lowercase?)"); cb.accept(null); return; } @@ -292,8 +293,9 @@ public class EaglerFolderResourcePack extends AbstractResourcePack { digest.update(arr, 0, arr.length); byte[] hashOut = new byte[20]; digest.doFinal(hashOut, 0); - if(!hash.equals(ArrayUtils.hexString(hashOut))) { - logger.error("Downloaded resource pack hash does not equal expected resource pack hash!"); + String hashOutStr = ArrayUtils.hexString(hashOut); + if(!hash.equals(hashOutStr)) { + logger.error("Downloaded resource pack hash does not equal expected resource pack hash! ({} != {})", hashOutStr, hash); cb.accept(null); return; } diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/EaglerProfile.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/EaglerProfile.java index d5edfaa0..9f89f6b8 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/EaglerProfile.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/EaglerProfile.java @@ -9,6 +9,7 @@ import net.lax1dude.eaglercraft.v1_8.EaglerInputStream; import net.lax1dude.eaglercraft.v1_8.EaglerOutputStream; import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom; import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID; +import net.lax1dude.eaglercraft.v1_8.HString; import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -464,7 +465,7 @@ public class EaglerProfile { rand = new EaglercraftRandom(); do { - username = defaultNames[rand.nextInt(defaultNames.length)] + defaultNames[rand.nextInt(defaultNames.length)] + (100 + rand.nextInt(900)); + username = HString.format("%s%s%04d", defaultNames[rand.nextInt(defaultNames.length)], defaultNames[rand.nextInt(defaultNames.length)], rand.nextInt(10000)); }while(username.length() > 16); setName(username); @@ -479,4 +480,8 @@ public class EaglerProfile { } + public static boolean isDefaultUsername(String str) { + return str.toLowerCase().matches("^(yeeish|yee|yeer|yeeler|eagler|eagl|darver|darvler|vool|vigg|deev|yigg|yeeg){2}\\d{2,4}$"); + } + } diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenDefaultUsernameNote.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenDefaultUsernameNote.java new file mode 100644 index 00000000..4ec30a1d --- /dev/null +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenDefaultUsernameNote.java @@ -0,0 +1,61 @@ +package net.lax1dude.eaglercraft.v1_8.profile; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.resources.I18n; + +/** + * Copyright (c) 2024 lax1dude. All Rights Reserved. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +public class GuiScreenDefaultUsernameNote extends GuiScreen { + + private final GuiScreen back; + private final GuiScreen cont; + + public GuiScreenDefaultUsernameNote(GuiScreen back, GuiScreen cont) { + this.back = back; + this.cont = cont; + } + + public void initGui() { + this.buttonList.clear(); + this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 6 + 112, I18n.format("defaultUsernameDetected.changeUsername"))); + this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 6 + 142, I18n.format("defaultUsernameDetected.continueAnyway"))); + this.buttonList.add(new GuiButton(2, this.width / 2 - 100, this.height / 6 + 172, I18n.format("defaultUsernameDetected.doNotShow"))); + } + + public void drawScreen(int par1, int par2, float par3) { + this.drawDefaultBackground(); + this.drawCenteredString(fontRendererObj, I18n.format("defaultUsernameDetected.title"), this.width / 2, 70, 11184810); + this.drawCenteredString(fontRendererObj, I18n.format("defaultUsernameDetected.text0", EaglerProfile.getName()), this.width / 2, 90, 16777215); + this.drawCenteredString(fontRendererObj, I18n.format("defaultUsernameDetected.text1"), this.width / 2, 105, 16777215); + this.drawCenteredString(fontRendererObj, I18n.format("defaultUsernameDetected.text2"), this.width / 2, 120, 16777215); + super.drawScreen(par1, par2, par3); + } + + @Override + protected void actionPerformed(GuiButton parGuiButton) { + if(parGuiButton.id == 0) { + this.mc.displayGuiScreen(back); + }else if(parGuiButton.id == 1) { + this.mc.displayGuiScreen(cont); + }else if(parGuiButton.id == 2) { + this.mc.gameSettings.hideDefaultUsernameWarning = true; + this.mc.gameSettings.saveOptions(); + this.mc.displayGuiScreen(cont); + } + } + +} diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenEditProfile.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenEditProfile.java index 4910f395..80b07297 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenEditProfile.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/profile/GuiScreenEditProfile.java @@ -315,7 +315,11 @@ public class GuiScreenEditProfile extends GuiScreen { if(par1GuiButton.id == 0) { safeProfile(); EaglerProfile.save(); - this.mc.displayGuiScreen((GuiScreen) parent); + if(!this.mc.gameSettings.hideDefaultUsernameWarning && EaglerProfile.isDefaultUsername(EaglerProfile.getName())) { + this.mc.displayGuiScreen(new GuiScreenDefaultUsernameNote(this, parent)); + }else { + this.mc.displayGuiScreen(parent); + } }else if(par1GuiButton.id == 1) { EagRuntime.displayFileChooser("image/png", "png"); }else if(par1GuiButton.id == 2) { diff --git a/sources/resources/EPKVersionIdentifier.txt b/sources/resources/EPKVersionIdentifier.txt new file mode 100644 index 00000000..60582c56 --- /dev/null +++ b/sources/resources/EPKVersionIdentifier.txt @@ -0,0 +1 @@ +u39 \ No newline at end of file diff --git a/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8.txt b/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8.txt index 0b43e98e..32811bd1 100644 --- a/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8.txt +++ b/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8.txt @@ -62,5 +62,6 @@ "disableBlobURLs": false, "eaglerNoDelay": false, "ramdiskMode": false, - "singleThreadMode": false + "singleThreadMode": false, + "enableEPKVersionCheck": true } \ No newline at end of file diff --git a/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_demo.txt b/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_demo.txt index e801ad14..6fbcd64d 100644 --- a/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_demo.txt +++ b/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_demo.txt @@ -62,5 +62,6 @@ "disableBlobURLs": false, "eaglerNoDelay": false, "ramdiskMode": false, - "singleThreadMode": false + "singleThreadMode": false, + "enableEPKVersionCheck": true } \ No newline at end of file diff --git a/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_html5Cursors.txt b/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_html5Cursors.txt index ce8c63fd..84070174 100644 --- a/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_html5Cursors.txt +++ b/sources/resources/assets/eagler/boot_menu/opts_template_eaglercraftX_1_8_html5Cursors.txt @@ -62,5 +62,6 @@ "disableBlobURLs": false, "eaglerNoDelay": false, "ramdiskMode": false, - "singleThreadMode": false + "singleThreadMode": false, + "enableEPKVersionCheck": true } \ No newline at end of file diff --git a/sources/setup/workspace_template/CompileJS.bat b/sources/setup/workspace_template/CompileJS.bat index 7969fc9b..b7f7fd27 100644 --- a/sources/setup/workspace_template/CompileJS.bat +++ b/sources/setup/workspace_template/CompileJS.bat @@ -1,4 +1,4 @@ @echo off title gradlew generateJavascript -gradlew generateJavascript +call gradlew generateJavascript pause \ No newline at end of file diff --git a/sources/teavm-boot-menu/java/net/lax1dude/eaglercraft/v1_8/boot_menu/teavm/BootMenuEntryPoint.java b/sources/teavm-boot-menu/java/net/lax1dude/eaglercraft/v1_8/boot_menu/teavm/BootMenuEntryPoint.java index b7879fe8..61090f30 100644 --- a/sources/teavm-boot-menu/java/net/lax1dude/eaglercraft/v1_8/boot_menu/teavm/BootMenuEntryPoint.java +++ b/sources/teavm-boot-menu/java/net/lax1dude/eaglercraft/v1_8/boot_menu/teavm/BootMenuEntryPoint.java @@ -60,12 +60,14 @@ public class BootMenuEntryPoint { return ((flag & 1) != 0 || IBootMenuConfigAdapter.instance.isShowBootMenuOnLaunch()) && !getHasAlreadyBooted(); } + private static boolean hasInit = false; private static byte[] signatureData = null; private static byte[] bundleData = null; public static void launchMenu(Window parentWindow, HTMLElement parentElement) { signatureData = PlatformUpdateSvc.getClientSignatureData(); bundleData = PlatformUpdateSvc.getClientBundleData(); + hasInit = true; BootMenuMain.launchMenu(parentWindow, parentElement); } @@ -83,6 +85,11 @@ public class BootMenuEntryPoint { } public static boolean isSignedClient() { + if(!hasInit) { + signatureData = PlatformUpdateSvc.getClientSignatureData(); + bundleData = PlatformUpdateSvc.getClientBundleData(); + hasInit = true; + } return signatureData != null && bundleData != null; } diff --git a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java index eb5fcec9..8d46ddff 100644 --- a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java +++ b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java @@ -597,7 +597,7 @@ public class PlatformInput { public void handleEvent(WheelEvent evt) { evt.preventDefault(); evt.stopPropagation(); - double delta = evt.getDeltaY(); + double delta = -evt.getDeltaY(); mouseDWheel += delta; if(hasShownPressAnyKey) { int eventX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI); @@ -1246,7 +1246,11 @@ public class PlatformInput { } public static int mouseGetEventDWheel() { - return (currentEvent.type == EVENT_MOUSE_WHEEL) ? (currentEvent.wheel == 0.0f ? 0 : (currentEvent.wheel > 0.0f ? -1 : 1)) : 0; + return (currentEvent.type == EVENT_MOUSE_WHEEL) ? fixWheel(currentEvent.wheel) : 0; + } + + private static int fixWheel(float val) { + return (val > 0.0f ? 1 : (val < 0.0f ? -1 : 0)); } public static int mouseGetX() { diff --git a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformRuntime.java b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformRuntime.java index 9b162e6b..60564210 100644 --- a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformRuntime.java +++ b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformRuntime.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -13,6 +14,7 @@ import java.util.function.Consumer; import net.lax1dude.eaglercraft.v1_8.EagRuntime; import net.lax1dude.eaglercraft.v1_8.EagUtils; import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID; +import net.lax1dude.eaglercraft.v1_8.EaglercraftVersion; import net.lax1dude.eaglercraft.v1_8.Filesystem; import net.lax1dude.eaglercraft.v1_8.boot_menu.teavm.BootMenuEntryPoint; import org.teavm.interop.Async; @@ -48,7 +50,6 @@ import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer; import net.lax1dude.eaglercraft.v1_8.internal.buffer.EaglerArrayBufferAllocator; import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer; import net.lax1dude.eaglercraft.v1_8.internal.buffer.IntBuffer; -import net.lax1dude.eaglercraft.v1_8.internal.teavm.EPKLoader; import net.lax1dude.eaglercraft.v1_8.internal.teavm.ES6ShimStatus; import net.lax1dude.eaglercraft.v1_8.internal.teavm.EarlyLoadScreen; import net.lax1dude.eaglercraft.v1_8.internal.teavm.EnumES6ShimStatus; @@ -58,8 +59,8 @@ import net.lax1dude.eaglercraft.v1_8.internal.teavm.ImmediateContinue; import net.lax1dude.eaglercraft.v1_8.internal.teavm.MessageChannel; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMBlobURLManager; import net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain; -import net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain.EPKFileEntry; import net.lax1dude.eaglercraft.v1_8.internal.teavm.DebugConsoleWindow; +import net.lax1dude.eaglercraft.v1_8.internal.teavm.EPKDownloadHelper; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMClientConfigAdapter; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMDataURLManager; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMEnterBootMenuException; @@ -426,29 +427,14 @@ public class PlatformRuntime { EarlyLoadScreen.paintScreen(glesVer, PlatformOpenGL.checkVAOCapable(), allowBootMenu); - EPKFileEntry[] epkFiles = ClientMain.configEPKFiles; - - for(int i = 0; i < epkFiles.length; ++i) { - String url = epkFiles[i].url; - String logURL = url.startsWith("data:") ? "" : url; - - logger.info("Downloading: {}", logURL); - - ArrayBuffer epkFileData = downloadRemoteURI(url); - - if(epkFileData == null) { - throw new RuntimeInitializationFailureException("Could not download EPK file \"" + url + "\""); - } - - logger.info("Decompressing: {}", logURL); - - try { - EPKLoader.loadEPK(epkFileData, epkFiles[i].path, PlatformAssets.assets); - }catch(Throwable t) { - throw new RuntimeInitializationFailureException("Could not extract EPK file \"" + url + "\"", t); - } + if(PlatformAssets.assets == null || !PlatformAssets.assets.isEmpty()) { + PlatformAssets.assets = new HashMap<>(); } + EPKDownloadHelper.downloadEPKFilesOfVersion(ClientMain.configEPKFiles, + teavmCfg.isEnableEPKVersionCheckTeaVM() ? EaglercraftVersion.EPKVersionIdentifier : null, + PlatformAssets.assets); + logger.info("Loaded {} resources from EPKs", PlatformAssets.assets.size()); if(allowBootMenu && BootMenuEntryPoint.checkShouldLaunchFlag(win)) { @@ -606,6 +592,10 @@ public class PlatformRuntime { } + public static boolean hasFetchSupportTeaVM() { + return hasFetchSupport; + } + public static void downloadRemoteURIByteArray(String assetPackageURI, final Consumer cb) { downloadRemoteURI(assetPackageURI, arr -> cb.accept(TeaVMUtils.wrapByteArrayBuffer(arr))); } diff --git a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/EPKDownloadHelper.java b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/EPKDownloadHelper.java new file mode 100644 index 00000000..ac822dca --- /dev/null +++ b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/EPKDownloadHelper.java @@ -0,0 +1,160 @@ +package net.lax1dude.eaglercraft.v1_8.internal.teavm; + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Map; + +import org.teavm.jso.browser.Window; +import org.teavm.jso.typedarrays.ArrayBuffer; + +import net.lax1dude.eaglercraft.v1_8.Base64; +import net.lax1dude.eaglercraft.v1_8.internal.PlatformApplication; +import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime; +import net.lax1dude.eaglercraft.v1_8.internal.RuntimeInitializationFailureException; +import net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain.EPKFileEntry; +import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; +import net.lax1dude.eaglercraft.v1_8.log4j.Logger; + +/** + * Copyright (c) 2024 lax1dude. All Rights Reserved. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +public class EPKDownloadHelper { + + private static final Logger logger = LogManager.getLogger("BrowserRuntime"); + + public static void downloadEPKFilesOfVersion(EPKFileEntry[] epkFiles, String expectedVersionIdentifier, + Map loadedFiles) { + byte[] bTrue = Base64.decodeBase64("true"); + boolean oldEPKInvalidFlag = Arrays.equals(bTrue, PlatformApplication.getLocalStorage("epkInvalidFlag", false)); + boolean epkInvalidFlag = oldEPKInvalidFlag; + attempt_loop: for(int a = 0; a < 3; ++a) { + if(a == 1 && !PlatformRuntime.hasFetchSupportTeaVM()) continue; + loadedFiles.clear(); + boolean canBeInvalid = expectedVersionIdentifier != null; + for(int i = 0; i < epkFiles.length; ++i) { + boolean noCache = false; + String url = null; + switch(a) { + case 0: + url = epkFiles[i].url; + noCache = false; + break; + case 1: + logger.warn("Failed to download one or more correct/valid files, attempting to bypass the browser's cache..."); + url = epkFiles[i].url; + noCache = true; + break; + case 2: + logger.warn("Failed to download one or more correct/valid files, attempting to bypass the server's cache..."); + url = injectCacheInvalidationHack(epkFiles[i].url, expectedVersionIdentifier); + noCache = true; + break; + } + boolean b = url.startsWith("data:"); + boolean c = !b && !url.startsWith("blob:"); + String toCheck = url.indexOf("://") != -1 ? url : PlatformRuntime.win.getLocation().getFullURL(); + boolean canBeCorrupt = c && (a < 1 || toCheck.startsWith("http:") || toCheck.startsWith("https:")); + canBeInvalid &= c; + String logURL = b ? "" : url; + + logger.info("Downloading: {}", logURL); + + ArrayBuffer epkFileData = PlatformRuntime.downloadRemoteURI(url, !noCache); + + if(epkFileData == null) { + if(a < 2 && canBeCorrupt) { + logger.error("Could not download EPK file \"{}\"", logURL); + continue attempt_loop; + }else { + throw new RuntimeInitializationFailureException("Could not download EPK file \"" + logURL + "\""); + } + } + + logger.info("Decompressing: {}", logURL); + + try { + EPKLoader.loadEPK(epkFileData, epkFiles[i].path, loadedFiles); + }catch(Throwable t) { + if(a < 2 && canBeCorrupt) { + logger.error("Could not extract EPK file \"{}\"", logURL); + continue attempt_loop; + }else { + throw new RuntimeInitializationFailureException("Could not extract EPK file \"" + logURL + "\"", t); + } + } + } + if(canBeInvalid) { + byte[] dat = loadedFiles.get("EPKVersionIdentifier.txt"); + if(dat != null) { + String epkStr = (new String(dat, StandardCharsets.UTF_8)).trim(); + if(expectedVersionIdentifier.equals(epkStr)) { + epkInvalidFlag = false; + break; + } + logger.error("EPK version identifier \"{}\" does not match the expected identifier \"{}\"", epkStr, expectedVersionIdentifier); + }else { + logger.error("Version identifier file is missing from the EPK, expecting \"{}\"", expectedVersionIdentifier); + } + if(epkInvalidFlag) { + break; + }else { + if(a < 2) { + continue; + }else { + logger.error("Nothing we can do about this, ignoring the invalid EPK version and setting invalid flag to true"); + epkInvalidFlag = true; + } + } + }else { + epkInvalidFlag = false; + break; + } + } + if(epkInvalidFlag != oldEPKInvalidFlag) { + PlatformApplication.setLocalStorage("epkInvalidFlag", epkInvalidFlag ? bTrue : null, false); + } + } + + private static String injectCacheInvalidationHack(String url, String cacheFixStr) { + if(cacheFixStr != null) { + cacheFixStr = Window.encodeURIComponent(cacheFixStr); + }else { + cacheFixStr = "t" + System.currentTimeMillis(); + } + String toCheck = url.indexOf("://") != -1 ? url : PlatformRuntime.win.getLocation().getFullURL(); + if(toCheck.startsWith("http:") || toCheck.startsWith("https:")) { + int i = url.indexOf('?'); + if(i == url.length() - 1) { + return url + "eaglerCacheFix=" + cacheFixStr; + }else if(i != -1) { + String s = url.substring(i + 1); + if(!s.startsWith("&") && !s.startsWith("#")) { + s = "&" + s; + } + return url.substring(0, i + 1) + "eaglerCacheFix=" + cacheFixStr + s; + }else { + i = url.indexOf('#'); + if(i != -1) { + return url.substring(0, i) + "?eaglerCacheFix=" + cacheFixStr + url.substring(i); + }else { + return url + "?eaglerCacheFix=" + cacheFixStr; + } + } + }else { + return url; + } + } + +} diff --git a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMClientConfigAdapter.java b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMClientConfigAdapter.java index 5e488aa5..062a9aa3 100644 --- a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMClientConfigAdapter.java +++ b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMClientConfigAdapter.java @@ -87,6 +87,7 @@ public class TeaVMClientConfigAdapter implements IClientConfigAdapter, IBootMenu private boolean eaglerNoDelay = false; private boolean ramdiskMode = false; private boolean singleThreadMode = false; + private boolean enableEPKVersionCheck = true; public void loadNative(JSObject jsObject) { integratedServerOpts = new JSONObject(); @@ -134,6 +135,7 @@ public class TeaVMClientConfigAdapter implements IClientConfigAdapter, IBootMenu eaglerNoDelay = eaglercraftXOpts.getEaglerNoDelay(false); ramdiskMode = eaglercraftXOpts.getRamdiskMode(false); singleThreadMode = eaglercraftXOpts.getSingleThreadMode(false); + enableEPKVersionCheck = eaglercraftXOpts.getEnableEPKVersionCheck(true); JSEaglercraftXOptsHooks hooksObj = eaglercraftXOpts.getHooks(); if(hooksObj != null) { hooks.loadHooks(hooksObj); @@ -263,6 +265,7 @@ public class TeaVMClientConfigAdapter implements IClientConfigAdapter, IBootMenu eaglerNoDelay = eaglercraftOpts.optBoolean("eaglerNoDelay", false); ramdiskMode = eaglercraftOpts.optBoolean("ramdiskMode", false); singleThreadMode = eaglercraftOpts.optBoolean("singleThreadMode", false); + enableEPKVersionCheck = eaglercraftOpts.optBoolean("enableEPKVersionCheck", true); defaultServers.clear(); JSONArray serversArray = eaglercraftOpts.optJSONArray("servers"); if(serversArray != null) { @@ -505,6 +508,10 @@ public class TeaVMClientConfigAdapter implements IClientConfigAdapter, IBootMenu return singleThreadMode; } + public boolean isEnableEPKVersionCheckTeaVM() { + return enableEPKVersionCheck; + } + @Override public boolean isShowBootMenuOnLaunch() { return showBootMenuOnLaunch; @@ -585,6 +592,7 @@ public class TeaVMClientConfigAdapter implements IClientConfigAdapter, IBootMenu jsonObject.put("eaglerNoDelay", eaglerNoDelay); jsonObject.put("ramdiskMode", ramdiskMode); jsonObject.put("singleThreadMode", singleThreadMode); + jsonObject.put("enableEPKVersionCheck", enableEPKVersionCheck); JSONArray serversArr = new JSONArray(); for(int i = 0, l = defaultServers.size(); i < l; ++i) { DefaultServer srv = defaultServers.get(i); diff --git a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMFetchJS.java b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMFetchJS.java index 2ba2c057..c0cb1a1d 100644 --- a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMFetchJS.java +++ b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/TeaVMFetchJS.java @@ -30,7 +30,7 @@ public class TeaVMFetchJS { @JSBody(params = { }, script = "return (typeof fetch === \"function\");") public static native boolean checkFetchSupport(); - @JSBody(params = { "uri", "forceCache", "callback" }, script = "fetch(uri, { cache: forceCache, mode: \"no-cors\" })" + @JSBody(params = { "uri", "forceCache", "callback" }, script = "fetch(uri, { cache: forceCache, mode: \"cors\" })" + ".then(function(res) { return res.arrayBuffer(); }).then(function(arr) { callback(arr); })" + ".catch(function(err) { console.error(err); callback(null); });") public static native void doFetchDownload(String uri, String forceCache, FetchHandler callback); diff --git a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/opts/JSEaglercraftXOptsRoot.java b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/opts/JSEaglercraftXOptsRoot.java index 9e4f472c..badc5242 100644 --- a/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/opts/JSEaglercraftXOptsRoot.java +++ b/sources/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/opts/JSEaglercraftXOptsRoot.java @@ -171,4 +171,7 @@ public abstract class JSEaglercraftXOptsRoot implements JSObject { @JSBody(params = { "def" }, script = "return (typeof this.singleThreadMode === \"boolean\") ? this.singleThreadMode : def;") public native boolean getSingleThreadMode(boolean deobfStackTraces); + @JSBody(params = { "def" }, script = "return (typeof this.enableEPKVersionCheck === \"boolean\") ? this.enableEPKVersionCheck : def;") + public native boolean getEnableEPKVersionCheck(boolean deobfStackTraces); + }