From aeb63fcd41b7eb825544e5faad275418bb937c00 Mon Sep 17 00:00:00 2001 From: lax1dude Date: Thu, 30 May 2024 21:42:11 -0700 Subject: [PATCH] Update #32 - Fixed some bugs in the client --- client_version | 2 +- .../texture/AbstractTexture.edit.java | 27 +++++++++- .../renderer/texture/DynamicTexture.edit.java | 4 ++ .../texture/LayeredColorMaskTexture.edit.java | 4 ++ .../renderer/texture/LayeredTexture.edit.java | 4 ++ .../renderer/texture/SimpleTexture.edit.java | 4 ++ .../renderer/texture/TextureMap.edit.java | 16 ++++-- .../renderer/texture/TextureUtil.edit.java | 2 +- .../resources/ResourcePackListEntry.edit.java | 9 +++- .../ResourcePackListEntryDefault.edit.java | 8 +++ .../ResourcePackListEntryFound.edit.java | 8 +++ .../eaglercraft/v1_8/EaglercraftVersion.java | 6 +-- .../v1_8/internal/GLObjectMap.java | 4 ++ .../minecraft/EaglerFolderResourcePack.java | 49 +++++++++++------- .../v1_8/opengl/EaglercraftGPU.java | 11 ++++ .../v1_8/opengl/GlStateManager.java | 15 ++++-- .../ext/deferred/EaglerDeferredPipeline.java | 2 +- .../sp/server/export/WorldConverterMCA.java | 16 +++--- sources/resources/SignedClientTemplate.txt | 25 +++++++-- sources/resources/plugin_download.zip | Bin 255712 -> 255599 bytes sources/resources/plugin_version.json | 2 +- .../javascript/SignedClientTemplate.txt | 25 +++++++-- .../v1_8/internal/PlatformRuntime.java | 23 ++++++-- 23 files changed, 214 insertions(+), 52 deletions(-) diff --git a/client_version b/client_version index fca9ed6..c274cdd 100644 --- a/client_version +++ b/client_version @@ -1 +1 @@ -u31 \ No newline at end of file +u32 \ No newline at end of file diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/AbstractTexture.edit.java b/patches/minecraft/net/minecraft/client/renderer/texture/AbstractTexture.edit.java index ea5f80f..1c2f70a 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/AbstractTexture.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/texture/AbstractTexture.edit.java @@ -14,7 +14,11 @@ + import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU; + -> CHANGE 8 : 16 @ 8 : 10 +> INSERT 6 : 7 @ 6 + ++ protected boolean hasAllocated; + +> CHANGE 2 : 10 @ 2 : 4 ~ if (blur != parFlag || mipmap != parFlag2) { ~ this.blur = parFlag; @@ -30,4 +34,25 @@ ~ EaglercraftGPU.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, i); ~ EaglercraftGPU.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, short1); +> INSERT 15 : 16 @ 15 + ++ hasAllocated = false; + +> INSERT 12 : 26 @ 12 + ++ ++ /** ++ * This function is needed due to EaglercraftX's use of glTexStorage2D to ++ * allocate memory for textures, some OpenGL implementations don't like it when ++ * you call glTexStorage2D on the same texture object more than once ++ */ ++ protected void regenerateIfNotAllocated() { ++ if (this.glTextureId != -1) { ++ if (hasAllocated) { ++ EaglercraftGPU.regenerateTexture(glTextureId); ++ } ++ hasAllocated = true; ++ } ++ } + > EOF diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/DynamicTexture.edit.java b/patches/minecraft/net/minecraft/client/renderer/texture/DynamicTexture.edit.java index c149422..a51d347 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/DynamicTexture.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/texture/DynamicTexture.edit.java @@ -18,4 +18,8 @@ ~ this(bufferedImage.width, bufferedImage.height); ~ System.arraycopy(bufferedImage.pixels, 0, dynamicTextureData, 0, bufferedImage.pixels.length); +> INSERT 7 : 8 @ 7 + ++ this.hasAllocated = true; + > EOF diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/LayeredColorMaskTexture.edit.java b/patches/minecraft/net/minecraft/client/renderer/texture/LayeredColorMaskTexture.edit.java index ecc62a4..68efd3f 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/LayeredColorMaskTexture.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/texture/LayeredColorMaskTexture.edit.java @@ -54,4 +54,8 @@ ~ bufferedimage.drawLayer(bufferedimage2, 0, 0, bufferedimage2.width, bufferedimage2.height, 0, 0, ~ bufferedimage2.width, bufferedimage2.height); +> INSERT 8 : 9 @ 8 + ++ regenerateIfNotAllocated(); + > EOF diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/LayeredTexture.edit.java b/patches/minecraft/net/minecraft/client/renderer/texture/LayeredTexture.edit.java index 9dd3f54..099c835 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/LayeredTexture.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/texture/LayeredTexture.edit.java @@ -40,4 +40,8 @@ ~ bufferedimage.drawLayer(bufferedimage1, 0, 0, bufferedimage1.width, bufferedimage1.height, 0, 0, ~ bufferedimage1.width, bufferedimage1.height); +> INSERT 7 : 8 @ 7 + ++ regenerateIfNotAllocated(); + > EOF diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/SimpleTexture.edit.java b/patches/minecraft/net/minecraft/client/renderer/texture/SimpleTexture.edit.java index 5962940..8088c68 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/SimpleTexture.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/texture/SimpleTexture.edit.java @@ -20,4 +20,8 @@ ~ ImageData bufferedimage = TextureUtil.readBufferedImage(inputstream); +> INSERT 15 : 16 @ 15 + ++ regenerateIfNotAllocated(); + > EOF diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.edit.java b/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.edit.java index a3ebc43..184c9f1 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.edit.java @@ -43,7 +43,7 @@ ~ private final Map mapRegisteredSprites; ~ private final Map mapUploadedSprites; -> CHANGE 3 : 9 @ 3 : 4 +> CHANGE 3 : 10 @ 3 : 4 ~ private final EaglerTextureAtlasSprite missingImage; ~ private final EaglerTextureAtlasSpritePBR missingImagePBR; @@ -51,6 +51,7 @@ ~ private int height; ~ private boolean isEaglerPBRMode = false; ~ public int eaglerPBRMaterialTexture = -1; +~ private boolean hasAllocatedEaglerPBRMaterialTexture = false; > INSERT 1 : 7 @ 1 @@ -114,7 +115,7 @@ + } + -> INSERT 8 : 43 @ 8 +> INSERT 8 : 44 @ 8 + if (copyColorFramebuffer != null) { + for (int l = 0; l < copyColorFramebuffer.length; ++l) { @@ -126,6 +127,7 @@ + if (isEaglerPBRMode) { + if (eaglerPBRMaterialTexture == -1) { + eaglerPBRMaterialTexture = GlStateManager.generateTexture(); ++ hasAllocatedEaglerPBRMaterialTexture = false; + } + if (copyMaterialFramebuffer == null) { + GlStateManager.bindTexture(eaglerPBRMaterialTexture); @@ -302,9 +304,17 @@ ~ stitcher.addSprite(this.missingImage); ~ } -> INSERT 11 : 28 @ 11 +> INSERT 9 : 10 @ 9 + ++ regenerateIfNotAllocated(); + +> INSERT 2 : 23 @ 2 + if (isEaglerPBRMode) { ++ if (hasAllocatedEaglerPBRMaterialTexture) { ++ EaglercraftGPU.regenerateTexture(eaglerPBRMaterialTexture); ++ } ++ hasAllocatedEaglerPBRMaterialTexture = true; + TextureUtil.allocateTextureImpl(eaglerPBRMaterialTexture, this.mipmapLevels, stitcher.getCurrentWidth(), + stitcher.getCurrentHeight() * 2); + } diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/TextureUtil.edit.java b/patches/minecraft/net/minecraft/client/renderer/texture/TextureUtil.edit.java index afcfc8c..1dc6544 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/TextureUtil.edit.java +++ b/patches/minecraft/net/minecraft/client/renderer/texture/TextureUtil.edit.java @@ -111,7 +111,7 @@ + public static int[] convertComponentOrder(int[] arr) { + for (int i = 0; i < arr.length; ++i) { + int j = arr[i]; -+ arr[i] = (j & 0xFF000000) | ((j >> 16) & 0xFF) | (j & 0xFF00) | ((j << 16) & 0xFF0000); ++ arr[i] = ((j >> 16) & 0xFF) | (j & 0xFF00FF00) | ((j << 16) & 0xFF0000); + } + return arr; + } diff --git a/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntry.edit.java b/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntry.edit.java index 3331e88..a16f17e 100644 --- a/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntry.edit.java +++ b/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntry.edit.java @@ -15,7 +15,12 @@ > DELETE 6 @ 6 : 8 -> INSERT 128 : 158 @ 128 +> INSERT 104 : 106 @ 104 + ++ protected abstract String getEaglerFolderName(); ++ + +> INSERT 24 : 54 @ 24 + private void proceedWithBs(int l, boolean deleteInstead) { + if (!deleteInstead && l != 1) { @@ -40,7 +45,7 @@ + if (deleteInstead) { + this.mc.loadingScreen.eaglerShow(I18n.format("resourcePack.load.deleting"), this.func_148312_b()); + EaglerFolderResourcePack.deleteResourcePack(EaglerFolderResourcePack.RESOURCE_PACKS, -+ this.func_148312_b()); ++ this.getEaglerFolderName()); + } else { + this.resourcePacksGUI.getSelectedResourcePacks().add(0, this); + } diff --git a/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryDefault.edit.java b/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryDefault.edit.java index b53df97..03be68d 100644 --- a/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryDefault.edit.java +++ b/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryDefault.edit.java @@ -23,4 +23,12 @@ ~ } catch (JSONException jsonparseexception) { +> INSERT 35 : 40 @ 35 + ++ ++ @Override ++ protected String getEaglerFolderName() { ++ return null; ++ } + > EOF diff --git a/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryFound.edit.java b/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryFound.edit.java index 2dd9380..fda6d7f 100644 --- a/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryFound.edit.java +++ b/patches/minecraft/net/minecraft/client/resources/ResourcePackListEntryFound.edit.java @@ -11,4 +11,12 @@ ~ return this.field_148319_c.getResourcePackEaglerDisplayName(); +> INSERT 5 : 10 @ 5 + ++ ++ @Override ++ protected String getEaglerFolderName() { ++ return field_148319_c.getResourcePackName(); ++ } + > EOF 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 d81ec0f..3170036 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 = "u31"; + public static final String projectForkVersion = "u32"; public static final String projectForkVendor = "lax1dude"; public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; @@ -20,7 +20,7 @@ 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 = "u31"; + public static final String projectOriginVersion = "u32"; public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace @@ -31,7 +31,7 @@ public class EaglercraftVersion { public static final boolean enableUpdateService = true; public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client"; - public static final int updateBundlePackageVersionInt = 31; + public static final int updateBundlePackageVersionInt = 32; public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/GLObjectMap.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/GLObjectMap.java index f47b755..2c5acef 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/GLObjectMap.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/internal/GLObjectMap.java @@ -60,6 +60,10 @@ public class GLObjectMap { return (T) values[obj]; } + public void set(int obj, T val) { + values[obj] = val; + } + private void resize() { int oldSize = size; size += size / 2; 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 e45d36c..5a5ab3e 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 @@ -153,11 +153,12 @@ public class EaglerFolderResourcePack extends AbstractResourcePack { List fileNames = Lists.newArrayList(); logger.info("Counting files..."); - ZipInputStream ziss = new ZipInputStream(new EaglerInputStream(file)); ZipEntry zipEntry; - while ((zipEntry = ziss.getNextEntry()) != null) { - if (!zipEntry.isDirectory()) { - fileNames.add(zipEntry.getName()); + try(ZipInputStream ziss = new ZipInputStream(new EaglerInputStream(file))) { + while ((zipEntry = ziss.getNextEntry()) != null) { + if (!zipEntry.isDirectory()) { + fileNames.add(zipEntry.getName()); + } } } @@ -195,22 +196,30 @@ public class EaglerFolderResourcePack extends AbstractResourcePack { int totalSize = 0; int totalFiles = 0; int lastProg = 0; - ziss = new ZipInputStream(new EaglerInputStream(file)); - while ((zipEntry = ziss.getNextEntry()) != null) { - if (!zipEntry.isDirectory()) { - fn = zipEntry.getName(); - if(fn.length() > prefixLen) { - byte[] buffer = new byte[(int)zipEntry.getSize()]; - int i = 0, j; - while(i < buffer.length && (j = ziss.read(buffer, i, buffer.length - i)) != -1) { - i += j; - } - (new VFile2(prefix, folderName, fn.substring(prefixLen))).setAllBytes(buffer); - totalSize += buffer.length; - ++totalFiles; - if(totalSize - lastProg > 25000) { - lastProg = totalSize; - logger.info("Extracted {} files, {} bytes from ZIP file...", totalFiles, totalSize); + try(ZipInputStream ziss = new ZipInputStream(new EaglerInputStream(file))) { + int sz; + while ((zipEntry = ziss.getNextEntry()) != null) { + if (!zipEntry.isDirectory()) { + fn = zipEntry.getName(); + if(fn.length() > prefixLen) { + byte[] buffer; + sz = (int)zipEntry.getSize(); + if(sz >= 0) { + buffer = new byte[sz]; + int i = 0, j; + while(i < buffer.length && (j = ziss.read(buffer, i, buffer.length - i)) != -1) { + i += j; + } + }else { + buffer = EaglerInputStream.inputStreamToBytes(ziss); + } + (new VFile2(prefix, folderName, fn.substring(prefixLen))).setAllBytes(buffer); + totalSize += buffer.length; + ++totalFiles; + if(totalSize - lastProg > 25000) { + lastProg = totalSize; + logger.info("Extracted {} files, {} bytes from ZIP file...", totalFiles, totalSize); + } } } } diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java index 10b6bee..a5b60b2 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/EaglercraftGPU.java @@ -488,6 +488,17 @@ public class EaglercraftGPU { return mapTexturesGL.get(tex); } + public static final void regenerateTexture(int tex) { + ITextureGL webglTex = mapTexturesGL.get(tex); + if(webglTex != null) { + GlStateManager.unbindTextureIfCached(tex); + _wglDeleteTextures(webglTex); + mapTexturesGL.set(tex, _wglGenTextures()); + }else { + logger.error("Tried to regenerate a missing texture!"); + } + } + public static final void drawHighPoly(HighPolyMesh mesh) { if(mesh.vertexCount == 0 || mesh.indexCount == 0 || mesh.vertexArray == null) { return; diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java index 8886072..593fae8 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/GlStateManager.java @@ -589,18 +589,25 @@ public class GlStateManager { } public static final void deleteTexture(int texture) { + unbindTextureIfCached(texture); _wglDeleteTextures(EaglercraftGPU.mapTexturesGL.free(texture)); - boolean f = false; + } + + static final void unbindTextureIfCached(int texture) { + boolean f1, f2 = false; for(int i = 0; i < boundTexture.length; ++i) { if(boundTexture[i] == texture) { - _wglActiveTexture(GL_TEXTURE0 + i); + f1 = i != activeTexture; + if(f2 || f1) { + _wglActiveTexture(GL_TEXTURE0 + i); + f2 = f1; + } _wglBindTexture(GL_TEXTURE_2D, null); _wglBindTexture(GL_TEXTURE_3D, null); boundTexture[i] = -1; - f = true; } } - if(f) { + if(f2) { _wglActiveTexture(GL_TEXTURE0 + activeTexture); } } diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/EaglerDeferredPipeline.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/EaglerDeferredPipeline.java index f08117f..ffd3961 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/EaglerDeferredPipeline.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/opengl/ext/deferred/EaglerDeferredPipeline.java @@ -2058,7 +2058,7 @@ public class EaglerDeferredPipeline { GlStateManager.disableBlend(); - if(reprojectionEngineEnable || config.realisticWater) { + if(reprojectionEngineEnable || config.is_rendering_realisticWater) { // =========== SAVE REPROJECTION DATA FOR NEXT FRAME ============= // diff --git a/sources/main/java/net/lax1dude/eaglercraft/v1_8/sp/server/export/WorldConverterMCA.java b/sources/main/java/net/lax1dude/eaglercraft/v1_8/sp/server/export/WorldConverterMCA.java index b7a6d5b..0c058fb 100644 --- a/sources/main/java/net/lax1dude/eaglercraft/v1_8/sp/server/export/WorldConverterMCA.java +++ b/sources/main/java/net/lax1dude/eaglercraft/v1_8/sp/server/export/WorldConverterMCA.java @@ -74,13 +74,17 @@ public class WorldConverterMCA { if (f.isDirectory()) continue; String lowerName = f.getName().toLowerCase(); if (!(lowerName.endsWith(".dat") || lowerName.endsWith(".dat_old") || lowerName.endsWith(".mca") || lowerName.endsWith(".mcr") || lowerName.endsWith(".bmp"))) continue; - EaglerOutputStream baos = new EaglerOutputStream(); - int len; - while ((len = zis.read(bb)) != -1) { - baos.write(bb, 0, len); + byte[] b; + int sz = (int)f.getSize(); + if(sz >= 0) { + b = new byte[sz]; + int j = 0, k; + while(j < b.length && (k = zis.read(b, j, b.length - j)) != -1) { + j += k; + } + }else { + b = EaglerInputStream.inputStreamToBytes(zis); } - baos.close(); - byte[] b = baos.toByteArray(); String fileName = f.getName().substring(folderPrefixOffset); if (fileName.equals("level.dat") || fileName.equals("level.dat_old")) { NBTTagCompound worldDatNBT = CompressedStreamTools.readCompressed(new EaglerInputStream(b)); diff --git a/sources/resources/SignedClientTemplate.txt b/sources/resources/SignedClientTemplate.txt index 72ff330..32731d9 100644 --- a/sources/resources/SignedClientTemplate.txt +++ b/sources/resources/SignedClientTemplate.txt @@ -44,6 +44,27 @@ window.eaglercraftXOptsHints = {