diff --git a/src/main/java/net/lax1dude/eaglercraft/EaglerInflater.java b/src/main/java/net/lax1dude/eaglercraft/EaglerMisc.java similarity index 61% rename from src/main/java/net/lax1dude/eaglercraft/EaglerInflater.java rename to src/main/java/net/lax1dude/eaglercraft/EaglerMisc.java index 4601d78..ba5be90 100644 --- a/src/main/java/net/lax1dude/eaglercraft/EaglerInflater.java +++ b/src/main/java/net/lax1dude/eaglercraft/EaglerMisc.java @@ -4,10 +4,11 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.Charset; import com.jcraft.jzlib.InflaterInputStream; -public class EaglerInflater { +public class EaglerMisc { public static byte[] uncompress(byte[] input) throws IOException { return getBytesFromInputStream(new InflaterInputStream(new ByteArrayInputStream(input))); @@ -21,5 +22,18 @@ public class EaglerInflater { } return os.toByteArray(); } - + + public static String bytesToString(byte[] bb) { + if (bb == null) return ""; + return new String(bb, Charset.forName("UTF-8")); + } + + public static String[] bytesToLines(byte[] bb) { + String contents = bytesToString(bb); + if(contents.isEmpty()) { + return new String[0]; + }else { + return contents.replace("\r\n", "\n").split("[\r\n]"); + } + } } diff --git a/src/main/java/net/lax1dude/eaglercraft/TextureTerrainMap.java b/src/main/java/net/lax1dude/eaglercraft/TextureTerrainMap.java index c837a97..7797c26 100644 --- a/src/main/java/net/lax1dude/eaglercraft/TextureTerrainMap.java +++ b/src/main/java/net/lax1dude/eaglercraft/TextureTerrainMap.java @@ -207,8 +207,8 @@ public class TextureTerrainMap implements IconRegister { EaglerAdapter.GL_RGBA, EaglerAdapter.GL_UNSIGNED_BYTE, uploadBuffer); EaglerAdapter.glTexParameteri(EaglerAdapter.GL_TEXTURE_2D, EaglerAdapter.GL_TEXTURE_MAX_LEVEL, 4); - - String dat = EaglerAdapter.fileContents("/" + map.basePath + name + ".txt"); + + String dat = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/" + map.basePath + name + ".txt")); if(dat != null) System.out.println("Found animation info for: " + map.basePath + name + ".png"); if(dat == null || (dat = dat.trim()).isEmpty()) { framesIdx = new int[divs]; diff --git a/src/main/java/net/minecraft/src/AchievementMap.java b/src/main/java/net/minecraft/src/AchievementMap.java index 78c273f..79bb024 100644 --- a/src/main/java/net/minecraft/src/AchievementMap.java +++ b/src/main/java/net/minecraft/src/AchievementMap.java @@ -3,7 +3,8 @@ package net.minecraft.src; import java.util.HashMap; import java.util.Map; -import net.lax1dude.eaglercraft.EaglerAdapter; +import net.lax1dude.eaglercraft.EaglerMisc; +import net.minecraft.client.Minecraft; public class AchievementMap { /** Holds the singleton instance of AchievementMap. */ @@ -14,7 +15,8 @@ public class AchievementMap { private AchievementMap() { try { - for(String str : EaglerAdapter.fileContentsLines("/achievement/map.txt")) { + String[] strs = EaglerMisc.bytesToLines(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/achievement/map.txt")); + for(String str : strs) { String[] var3 = str.split(","); int var4 = Integer.parseInt(var3[0]); this.guidMap.put(Integer.valueOf(var4), var3[1]); diff --git a/src/main/java/net/minecraft/src/GuiMainMenu.java b/src/main/java/net/minecraft/src/GuiMainMenu.java index 2d69e39..c80c89d 100644 --- a/src/main/java/net/minecraft/src/GuiMainMenu.java +++ b/src/main/java/net/minecraft/src/GuiMainMenu.java @@ -13,6 +13,7 @@ import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading; import net.lax1dude.eaglercraft.IntegratedServer; import net.lax1dude.eaglercraft.LocalStorageManager; import net.lax1dude.eaglercraft.TextureLocation; +import net.lax1dude.eaglercraft.EaglerMisc; import net.lax1dude.eaglercraft.adapter.Tessellator; import net.minecraft.client.Minecraft; @@ -175,7 +176,7 @@ public class GuiMainMenu extends GuiScreen { if(this.ackLines.isEmpty()) { int width = 315; - String file = EaglerAdapter.fileContents("/credits.txt"); + String file = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/credits.txt")); if(file == null) { for(int i = 0; i < 30; ++i) { this.ackLines.add(" -- file not found -- "); diff --git a/src/main/java/net/minecraft/src/GuiTexturePacks.java b/src/main/java/net/minecraft/src/GuiTexturePacks.java index 96b556a..497e149 100644 --- a/src/main/java/net/minecraft/src/GuiTexturePacks.java +++ b/src/main/java/net/minecraft/src/GuiTexturePacks.java @@ -2,7 +2,7 @@ package net.minecraft.src; import net.lax1dude.eaglercraft.EPKDecompiler; import net.lax1dude.eaglercraft.EaglerAdapter; -import net.lax1dude.eaglercraft.EaglerInflater; +import net.lax1dude.eaglercraft.EaglerMisc; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; import java.io.ByteArrayInputStream; @@ -112,7 +112,7 @@ public class GuiTexturePacks extends GuiScreen { ZipEntry entry; while ((entry = zipInputStream.getNextEntry()) != null) { if (entry.isDirectory()) continue; - new VFile(fileLocation, safeName, entry.getName()).setAllBytes(EaglerInflater.getBytesFromInputStream(zipInputStream)); + new VFile(fileLocation, safeName, entry.getName()).setAllBytes(EaglerMisc.getBytesFromInputStream(zipInputStream)); } zipInputStream.close(); } else { @@ -138,6 +138,9 @@ public class GuiTexturePacks extends GuiScreen { 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(); } else { try { this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2)); diff --git a/src/main/java/net/minecraft/src/GuiWinGame.java b/src/main/java/net/minecraft/src/GuiWinGame.java index 356ea9a..a5de9de 100644 --- a/src/main/java/net/minecraft/src/GuiWinGame.java +++ b/src/main/java/net/minecraft/src/GuiWinGame.java @@ -7,6 +7,7 @@ import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerProfile; import net.lax1dude.eaglercraft.EaglercraftRandom; import net.lax1dude.eaglercraft.TextureLocation; +import net.lax1dude.eaglercraft.EaglerMisc; import net.lax1dude.eaglercraft.adapter.Tessellator; public class GuiWinGame extends GuiScreen { @@ -70,7 +71,8 @@ public class GuiWinGame extends GuiScreen { EaglercraftRandom var5 = new EaglercraftRandom(8124371L); int var6; - for(String str : EaglerAdapter.fileContentsLines("/title/win.txt")) { + String[] strs = EaglerMisc.bytesToLines(mc.texturePackList.getSelectedTexturePack().getResourceAsBytes("/title/win.txt")); + for(String str : strs) { String var7; String var8; @@ -88,7 +90,8 @@ public class GuiWinGame extends GuiScreen { this.lines.add(""); } - for(String str : EaglerAdapter.fileContentsLines("/title/credits.txt")) { + strs = EaglerMisc.bytesToLines(mc.texturePackList.getSelectedTexturePack().getResourceAsBytes("/title/credits.txt")); + for(String str : strs) { var1 = var1.replaceAll("PLAYERNAME", EaglerProfile.username); var1 = var1.replaceAll("\t", " "); this.lines.addAll(this.mc.fontRenderer.listFormattedStringToWidth(var1, var3)); diff --git a/src/main/java/net/minecraft/src/Packet51MapChunk.java b/src/main/java/net/minecraft/src/Packet51MapChunk.java index 049a0da..0f6cc9d 100644 --- a/src/main/java/net/minecraft/src/Packet51MapChunk.java +++ b/src/main/java/net/minecraft/src/Packet51MapChunk.java @@ -4,7 +4,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import net.lax1dude.eaglercraft.EaglerInflater; +import net.lax1dude.eaglercraft.EaglerMisc; public class Packet51MapChunk extends Packet { /** The x-position of the transmitted chunk, in chunk coordinates. */ @@ -82,7 +82,7 @@ public class Packet51MapChunk extends Packet { var3 += 256; } - this.compressedChunkData = EaglerInflater.uncompress(temp); + this.compressedChunkData = EaglerMisc.uncompress(temp); }else { this.tempLength &= 0xFFFFFFF; this.compressedChunkData = new byte[this.tempLength]; diff --git a/src/main/java/net/minecraft/src/Packet56MapChunks.java b/src/main/java/net/minecraft/src/Packet56MapChunks.java index dcac33d..17ee282 100644 --- a/src/main/java/net/minecraft/src/Packet56MapChunks.java +++ b/src/main/java/net/minecraft/src/Packet56MapChunks.java @@ -5,7 +5,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.List; -import net.lax1dude.eaglercraft.EaglerInflater; +import net.lax1dude.eaglercraft.EaglerMisc; public class Packet56MapChunks extends Packet { private int[] chunkPostX; @@ -56,7 +56,7 @@ public class Packet56MapChunks extends Packet { chunkDataNotCompressed = new byte[this.dataLength]; } par1DataInputStream.readFully(chunkDataNotCompressed, 0, this.dataLength); - var3 = EaglerInflater.uncompress(chunkDataNotCompressed); + var3 = EaglerMisc.uncompress(chunkDataNotCompressed); } int var5 = 0; diff --git a/src/main/java/net/minecraft/src/StringTranslate.java b/src/main/java/net/minecraft/src/StringTranslate.java index 3ac56d7..5087647 100644 --- a/src/main/java/net/minecraft/src/StringTranslate.java +++ b/src/main/java/net/minecraft/src/StringTranslate.java @@ -5,7 +5,8 @@ import java.util.IllegalFormatException; import java.util.Properties; import java.util.TreeMap; -import net.lax1dude.eaglercraft.EaglerAdapter; +import net.lax1dude.eaglercraft.EaglerMisc; +import net.minecraft.client.Minecraft; public class StringTranslate { /** Is the private singleton instance of StringTranslate. */ @@ -42,7 +43,7 @@ public class StringTranslate { } private void loadLanguage(Properties par1Properties, String par2Str) throws IOException { - String[] var3 = EaglerAdapter.fileContents("/lang/" + par2Str + ".lang").replace('\r', '\n') + String[] var3 = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/lang/" + par2Str + ".lang")).replace('\r', '\n') .replaceAll("\n+", "\n").split("\n"); for (String var4 : var3) { diff --git a/src/main/java/net/minecraft/src/TexturePackImplementation.java b/src/main/java/net/minecraft/src/TexturePackImplementation.java index 9ca4b1c..7708cf7 100644 --- a/src/main/java/net/minecraft/src/TexturePackImplementation.java +++ b/src/main/java/net/minecraft/src/TexturePackImplementation.java @@ -7,7 +7,7 @@ import java.io.InputStreamReader; import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerImage; -import net.lax1dude.eaglercraft.EaglerInflater; +import net.lax1dude.eaglercraft.EaglerMisc; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; public abstract class TexturePackImplementation implements ITexturePack @@ -77,7 +77,9 @@ public abstract class TexturePackImplementation implements ITexturePack try { var1 = this.func_98137_a("/pack.png", false); - this.thumbnailImage = EaglerImage.loadImage(EaglerInflater.getBytesFromInputStream(var1)); + if (var1 != null) { + this.thumbnailImage = EaglerImage.loadImage(EaglerMisc.getBytesFromInputStream(var1)); + } } catch (IOException var11) { @@ -163,11 +165,24 @@ public abstract class TexturePackImplementation implements ITexturePack */ public byte[] getResourceAsBytes(String par1Str) { + InputStream is = null; + byte[] res = null; try { - return EaglerInflater.getBytesFromInputStream(this.func_98137_a(par1Str, true)); + is = this.func_98137_a(par1Str, true); + if (is == null) return null; + res = EaglerMisc.getBytesFromInputStream(is); } catch (IOException e) { return null; + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException ignored) { + // + } + } } + return res; } protected abstract InputStream func_98139_b(String var1) throws IOException; diff --git a/src/main/java/net/minecraft/src/TextureStitched.java b/src/main/java/net/minecraft/src/TextureStitched.java index f4c41c6..fbac366 100644 --- a/src/main/java/net/minecraft/src/TextureStitched.java +++ b/src/main/java/net/minecraft/src/TextureStitched.java @@ -3,7 +3,8 @@ package net.minecraft.src; import java.util.ArrayList; import java.util.List; -import net.lax1dude.eaglercraft.EaglerAdapter; +import net.lax1dude.eaglercraft.EaglerMisc; +import net.minecraft.client.Minecraft; public class TextureStitched implements Icon { private final String textureName; @@ -171,7 +172,7 @@ public class TextureStitched implements Icon { public void readAnimationInfo(String path) { ArrayList var2 = new ArrayList(); try { - String var3 = EaglerAdapter.fileContents(path).trim(); + String var3 = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes(path)).trim(); if (var3.length() > 0) { String[] var4 = var3.split(","); diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/SYS.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/SYS.java index b46a910..482e4f3 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/SYS.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/teavm/vfs/SYS.java @@ -6,7 +6,7 @@ public class SYS { static { - VirtualFilesystem.VFSHandle vh = VirtualFilesystem.openVFS("_net_lax1dude_eaglercraft_adapter_teavm_vfs_VirtualFilesystem_1_5_2_eagStorage"); + VirtualFilesystem.VFSHandle vh = VirtualFilesystem.openVFS("eagStorage2"); if(vh.vfs == null) { System.err.println("Could not init filesystem!");