From 3459233886f62f08bfe4d0e05398fc93bf1ce736 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Fri, 13 Dec 2024 11:42:01 -0500 Subject: [PATCH 1/3] Implement server texture packs --- .../net/minecraft/src/TexturePackList.java | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/minecraft/src/TexturePackList.java b/src/main/java/net/minecraft/src/TexturePackList.java index fc61a3b..c80011d 100644 --- a/src/main/java/net/minecraft/src/TexturePackList.java +++ b/src/main/java/net/minecraft/src/TexturePackList.java @@ -1,13 +1,19 @@ package net.minecraft.src; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; -import net.lax1dude.eaglercraft.EaglerProfile; +import net.lax1dude.eaglercraft.EPKDecompiler; +import net.lax1dude.eaglercraft.EaglerAdapter; +import net.lax1dude.eaglercraft.EaglerInputStream; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; import net.minecraft.client.Minecraft; @@ -81,26 +87,41 @@ public class TexturePackList var2 = var2.substring(0, var2.indexOf("?")); } - if (var2.endsWith(".zip")) + if (var2.toLowerCase().endsWith(".zip") || var2.toLowerCase().endsWith(".epk")) { - VFile var3 = new VFile(this.mpTexturePackFolder, var2); + VFile var3 = new VFile(this.mpTexturePackFolder, var2.replaceAll("[^A-Za-z0-9_]", "_")); this.downloadTexture(par1Str, var3); } } private void downloadTexture(String par1Str, VFile par2File) { - HashMap var3 = new HashMap(); - GuiProgress var4 = new GuiProgress(); - var3.put("X-Minecraft-Username", EaglerProfile.username); - var3.put("X-Minecraft-Version", "1.5.2"); - var3.put("X-Minecraft-Supported-Resolutions", "16"); this.isDownloading = true; - this.mc.displayGuiScreen(var4); - // todo: extract epk/zip to VFS, activate, and signal success - onDownloadFinished(); // temp - // SimpleStorage.set(par2File.replaceAll("[^A-Za-z0-9_]", "_"), par2File.toLowerCase().endsWith(".zip") ? zipToEpk(EaglerAdapter.downloadURL(par1Str)) : EaglerAdapter.downloadURL(par1Str)); - // HttpUtil.downloadTexturePack(par2File, par1Str, new TexturePackDownloadSuccess(this), var3, 10000000, var4); + try { + byte[] data = EaglerAdapter.downloadURL(par1Str); + if (data == null) throw new IOException("Unable to download texture pack!"); + if (par2File.getName().toLowerCase().endsWith(".epk")) { + EPKDecompiler epkDecompiler = new EPKDecompiler(data); + EPKDecompiler.FileEntry file; + while ((file = epkDecompiler.readFile()) != null) { + new VFile(par2File, file.name).setAllBytes(file.data); + } + } else { + try(ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(data))) { + ZipEntry entry; + while ((entry = zipInputStream.getNextEntry()) != null) { + if (entry.isDirectory()) continue; + new VFile(par2File, entry.getName()).setAllBytes(EaglerInputStream.inputStreamToBytesNoClose(zipInputStream)); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + if (this.isDownloading) { + setSelectedTexturePack(this, new TexturePackFolder(TexturePackList.generateTexturePackID(this, par2File), par2File, defaultTexturePack)); + this.mc.scheduleTexturePackRefresh(); + } } /** From 1e4d74a48ca7319133a388cec5ea5b3d0463ade3 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Fri, 13 Dec 2024 20:31:35 -0500 Subject: [PATCH 2/3] Optimize texture pack listing --- .../net/minecraft/src/GuiTexturePacks.java | 30 +++++++++++++++++-- .../net/minecraft/src/TexturePackList.java | 17 ++++------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/minecraft/src/GuiTexturePacks.java b/src/main/java/net/minecraft/src/GuiTexturePacks.java index 259ac1a..5156491 100644 --- a/src/main/java/net/minecraft/src/GuiTexturePacks.java +++ b/src/main/java/net/minecraft/src/GuiTexturePacks.java @@ -3,7 +3,6 @@ package net.minecraft.src; import net.lax1dude.eaglercraft.EPKDecompiler; import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerInputStream; -import net.lax1dude.eaglercraft.EaglerMisc; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; import java.io.ByteArrayInputStream; @@ -28,6 +27,8 @@ public class GuiTexturePacks extends GuiScreen { private GuiTexturePackSlot guiTexturePackSlot; private GameSettings field_96146_n; + protected static final VFile texturePackListFile = new VFile("__LIST__"); + public GuiTexturePacks(GuiScreen par1, GameSettings par2) { this.guiScreen = par1; this.field_96146_n = par2; @@ -107,6 +108,11 @@ public class GuiTexturePacks extends GuiScreen { isSelectingPack = false; String name = EaglerAdapter.getFileChooserResultName(); String safeName = name.replaceAll("[^A-Za-z0-9_]", "_"); + if (texturePackListFile.exists()) { + texturePackListFile.setAllChars(texturePackListFile.getAllChars() + "\n" + safeName); + } else { + texturePackListFile.setAllChars(safeName); + } try { if (name.toLowerCase().endsWith(".zip")) { try(ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(EaglerAdapter.getFileChooserResult()))) { @@ -138,10 +144,19 @@ public class GuiTexturePacks extends GuiScreen { List var3 = this.mc.texturePackList.availableTexturePacks(); if (par1) { - new VFile(fileLocation, ((ITexturePack) var3.get(par2)).getTexturePackFileName()).deleteAll(); this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0)); this.mc.renderEngine.refreshTextures(); this.mc.renderGlobal.loadRenderers(); + String safeName = ((ITexturePack) var3.get(par2)).getTexturePackFileName(); + new VFile(fileLocation, safeName).deleteAll(); + if (texturePackListFile.exists()) { + String res = texturePackListFile.getAllChars().replaceFirst(safeName, "").replace("\n\n", "\n"); + if (res.isEmpty()) { + texturePackListFile.delete(); + } else { + texturePackListFile.setAllChars(res); + } + } } else { try { this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2)); @@ -152,7 +167,16 @@ public class GuiTexturePacks extends GuiScreen { this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0)); this.mc.renderEngine.refreshTextures(); this.mc.renderGlobal.loadRenderers(); - new VFile(fileLocation, ((ITexturePack) var3.get(par2)).getTexturePackFileName()).deleteAll(); + String safeName = ((ITexturePack) var3.get(par2)).getTexturePackFileName(); + new VFile(fileLocation, safeName).deleteAll(); + if (texturePackListFile.exists()) { + String res = texturePackListFile.getAllChars().replaceFirst(safeName, "").replace("\n\n", "\n"); + if (res.isEmpty()) { + texturePackListFile.delete(); + } else { + texturePackListFile.setAllChars(res); + } + } } } } diff --git a/src/main/java/net/minecraft/src/TexturePackList.java b/src/main/java/net/minecraft/src/TexturePackList.java index c80011d..475f558 100644 --- a/src/main/java/net/minecraft/src/TexturePackList.java +++ b/src/main/java/net/minecraft/src/TexturePackList.java @@ -53,6 +53,7 @@ public class TexturePackList this.mc = par2Minecraft; this.texturePackDir = new VFile("texturepacks"); this.mpTexturePackFolder = new VFile("texturepacks-mp-cache"); + this.mpTexturePackFolder.deleteAll(); this.updateAvaliableTexturePacks(); } @@ -204,20 +205,12 @@ public class TexturePackList */ private List getTexturePackDirContents() { - // TODO: MAKE THIS MORE EFFICIENT!! THIS IS A TEMPORARY FIX BC IM TIRED - List strings = this.texturePackDir.list(); - List strings2 = new ArrayList<>(); + if (!GuiTexturePacks.texturePackListFile.exists()) return Collections.emptyList(); + String[] lines = GuiTexturePacks.texturePackListFile.getAllLines(); List files = new ArrayList<>(); - for (String name : strings) { - name = name.substring(this.texturePackDir.getPath().length() + 1); - name = name.substring(0, name.indexOf('/')); - name = this.texturePackDir.getPath() + "/" + name; - if (strings2.contains(name)) continue; - strings2.add(name); - files.add(new VFile(name)); + for (String line : lines) { + files.add(new VFile(this.texturePackDir, line)); } - strings2.clear(); - strings.clear(); return files; } From f926392249c086b9a46d44dea46476acc6f99612 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Fri, 13 Dec 2024 22:18:56 -0500 Subject: [PATCH 3/3] Fix desktop runtime --- .../adapter/EaglerAdapterImpl2.java | 12 +++ .../eaglercraft/adapter/vfs/VFile.java | 80 +++++++++++++++++++ .../net/minecraft/src/GuiTexturePacks.java | 2 +- .../net/minecraft/src/TexturePackFolder.java | 2 +- .../src/TexturePackImplementation.java | 3 +- .../net/minecraft/src/TexturePackList.java | 2 +- .../{teavm => }/vfs/BooleanResult.java | 2 +- .../adapter/{teavm => }/vfs/SYS.java | 2 +- .../adapter/{teavm => }/vfs/VFSIterator.java | 2 +- .../adapter/{teavm => }/vfs/VFile.java | 2 +- .../{teavm => }/vfs/VIteratorFile.java | 2 +- .../{teavm => }/vfs/VirtualFilesystem.java | 3 +- 12 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 src/lwjgl/java/net/lax1dude/eaglercraft/adapter/vfs/VFile.java rename src/teavm/java/net/lax1dude/eaglercraft/adapter/{teavm => }/vfs/BooleanResult.java (86%) rename src/teavm/java/net/lax1dude/eaglercraft/adapter/{teavm => }/vfs/SYS.java (86%) rename src/teavm/java/net/lax1dude/eaglercraft/adapter/{teavm => }/vfs/VFSIterator.java (83%) rename src/teavm/java/net/lax1dude/eaglercraft/adapter/{teavm => }/vfs/VFile.java (98%) rename src/teavm/java/net/lax1dude/eaglercraft/adapter/{teavm => }/vfs/VIteratorFile.java (99%) rename src/teavm/java/net/lax1dude/eaglercraft/adapter/{teavm => }/vfs/VirtualFilesystem.java (99%) diff --git a/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java b/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java index 9ffea1a..6d787a1 100644 --- a/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java +++ b/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java @@ -2010,4 +2010,16 @@ public class EaglerAdapterImpl2 { } } + public static final boolean immediateContinueSupported() { + return false; + } + + public static final void immediateContinue() { + // + } + + public static final List serverLANGetAllEvent(String clientId) { + return null; + } + } diff --git a/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/vfs/VFile.java b/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/vfs/VFile.java new file mode 100644 index 0000000..ea3d5ae --- /dev/null +++ b/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/vfs/VFile.java @@ -0,0 +1,80 @@ +package net.lax1dude.eaglercraft.adapter.vfs; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Comparator; +import java.util.stream.Stream; + +public class VFile extends File { + + public VFile(String pathname) { + super(pathname); + } + + public VFile(String parent, String child) { + super(parent, child); + } + + public VFile(File parent, String child) { + super(parent, child); + } + + public VFile(String parent, String child, String child2) { + super(new VFile(parent, child), child2); + } + + public InputStream getInputStream() { + try { + return Files.newInputStream(this.toPath()); + } catch (IOException e) { + return null; + } + } + + public String[] getAllLines() { + try { + return Files.readAllLines(this.toPath(), StandardCharsets.UTF_8).toArray(new String[0]); + } catch (IOException e) { + return null; + } + } + + public String getAllChars() { + try { + return Files.readString(this.toPath(), StandardCharsets.UTF_8); + } catch (IOException e) { + return null; + } + } + + public boolean setAllChars(String chars) { + return setAllBytes(chars.getBytes(StandardCharsets.UTF_8)); + } + + public boolean setAllBytes(byte[] bytes) { + try { + if (this.getParentFile() != null) { + this.getParentFile().mkdirs(); + } + Files.write(this.toPath(), bytes); + return true; + } catch (IOException e) { + return false; + } + } + + public int deleteAll() { + try (Stream pathStream = Files.walk(this.toPath())) { + pathStream.sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + return 1; + } catch (IOException e) { + return 0; + } + } +} diff --git a/src/main/java/net/minecraft/src/GuiTexturePacks.java b/src/main/java/net/minecraft/src/GuiTexturePacks.java index 5156491..e483c1a 100644 --- a/src/main/java/net/minecraft/src/GuiTexturePacks.java +++ b/src/main/java/net/minecraft/src/GuiTexturePacks.java @@ -3,7 +3,7 @@ package net.minecraft.src; import net.lax1dude.eaglercraft.EPKDecompiler; import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerInputStream; -import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; +import net.lax1dude.eaglercraft.adapter.vfs.VFile; import java.io.ByteArrayInputStream; import java.io.IOException; diff --git a/src/main/java/net/minecraft/src/TexturePackFolder.java b/src/main/java/net/minecraft/src/TexturePackFolder.java index 408e597..e59c756 100644 --- a/src/main/java/net/minecraft/src/TexturePackFolder.java +++ b/src/main/java/net/minecraft/src/TexturePackFolder.java @@ -1,6 +1,6 @@ package net.minecraft.src; -import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; +import net.lax1dude.eaglercraft.adapter.vfs.VFile; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/net/minecraft/src/TexturePackImplementation.java b/src/main/java/net/minecraft/src/TexturePackImplementation.java index 83408ab..f3e896d 100644 --- a/src/main/java/net/minecraft/src/TexturePackImplementation.java +++ b/src/main/java/net/minecraft/src/TexturePackImplementation.java @@ -8,8 +8,7 @@ import java.io.InputStreamReader; import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerImage; import net.lax1dude.eaglercraft.EaglerInputStream; -import net.lax1dude.eaglercraft.EaglerMisc; -import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; +import net.lax1dude.eaglercraft.adapter.vfs.VFile; public abstract class TexturePackImplementation implements ITexturePack { diff --git a/src/main/java/net/minecraft/src/TexturePackList.java b/src/main/java/net/minecraft/src/TexturePackList.java index 475f558..7c89d7c 100644 --- a/src/main/java/net/minecraft/src/TexturePackList.java +++ b/src/main/java/net/minecraft/src/TexturePackList.java @@ -14,7 +14,7 @@ import java.util.zip.ZipInputStream; import net.lax1dude.eaglercraft.EPKDecompiler; import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerInputStream; -import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; +import net.lax1dude.eaglercraft.adapter.vfs.VFile; import net.minecraft.client.Minecraft; public class TexturePackList diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/BooleanResult.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/BooleanResult.java similarity index 86% rename from src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/BooleanResult.java rename to src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/BooleanResult.java index c967763..a956837 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/BooleanResult.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/BooleanResult.java @@ -1,4 +1,4 @@ -package net.lax1dude.eaglercraft.adapter.teavm.vfs; +package net.lax1dude.eaglercraft.adapter.vfs; public class BooleanResult { diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/SYS.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/SYS.java similarity index 86% rename from src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/SYS.java rename to src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/SYS.java index 482e4f3..303b084 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/SYS.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/SYS.java @@ -1,4 +1,4 @@ -package net.lax1dude.eaglercraft.adapter.teavm.vfs; +package net.lax1dude.eaglercraft.adapter.vfs; public class SYS { diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VFSIterator.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VFSIterator.java similarity index 83% rename from src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VFSIterator.java rename to src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VFSIterator.java index 128582a..34b3d0e 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VFSIterator.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VFSIterator.java @@ -1,4 +1,4 @@ -package net.lax1dude.eaglercraft.adapter.teavm.vfs; +package net.lax1dude.eaglercraft.adapter.vfs; public interface VFSIterator { diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VFile.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VFile.java similarity index 98% rename from src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VFile.java rename to src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VFile.java index 849681d..857a5db 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VFile.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VFile.java @@ -1,4 +1,4 @@ -package net.lax1dude.eaglercraft.adapter.teavm.vfs; +package net.lax1dude.eaglercraft.adapter.vfs; import java.io.InputStream; import java.io.OutputStream; diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VIteratorFile.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VIteratorFile.java similarity index 99% rename from src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VIteratorFile.java rename to src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VIteratorFile.java index e179e70..2dfa631 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VIteratorFile.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VIteratorFile.java @@ -1,4 +1,4 @@ -package net.lax1dude.eaglercraft.adapter.teavm.vfs; +package net.lax1dude.eaglercraft.adapter.vfs; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VirtualFilesystem.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VirtualFilesystem.java similarity index 99% rename from src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VirtualFilesystem.java rename to src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VirtualFilesystem.java index c9bb56b..1195923 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/VirtualFilesystem.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/vfs/VirtualFilesystem.java @@ -1,6 +1,5 @@ -package net.lax1dude.eaglercraft.adapter.teavm.vfs; +package net.lax1dude.eaglercraft.adapter.vfs; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream;