From 1558ec819a4175ff2e8aa83774764efe18f87dc3 Mon Sep 17 00:00:00 2001 From: Alexander Xia Date: Sun, 24 Jun 2018 22:59:46 +0800 Subject: [PATCH] Fix Crash in Spectator Menu --- .gitignore | 3 +- .../config/SkinSiteProfile.java | 6 - .../fake/FakeClientPlayer.java | 115 +++++++++--------- .../customskinloader/fake/FakeSkinBuffer.java | 4 +- .../fake/FakeSkinManager.java | 13 +- .../customskinloader/loader/LegacyLoader.java | 4 +- 6 files changed, 69 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index e8837f9..001d86c 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ build/ # IDEA .idea/ -*.iml \ No newline at end of file +*.iml +out/ \ No newline at end of file diff --git a/Common/source/customskinloader/config/SkinSiteProfile.java b/Common/source/customskinloader/config/SkinSiteProfile.java index f5b63fb..528bfb4 100644 --- a/Common/source/customskinloader/config/SkinSiteProfile.java +++ b/Common/source/customskinloader/config/SkinSiteProfile.java @@ -55,10 +55,4 @@ public class SkinSiteProfile { ssp.elytra=elytra; return ssp; } - public static SkinSiteProfile createElfSkin(String name){ - SkinSiteProfile ssp=new SkinSiteProfile(); - ssp.name=name; - ssp.type="ElfSkin"; - return ssp; - } } diff --git a/Common/source/customskinloader/fake/FakeClientPlayer.java b/Common/source/customskinloader/fake/FakeClientPlayer.java index 0e46f8a..949cad5 100644 --- a/Common/source/customskinloader/fake/FakeClientPlayer.java +++ b/Common/source/customskinloader/fake/FakeClientPlayer.java @@ -20,67 +20,64 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; public class FakeClientPlayer { - //For Legacy Skin - public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username) - { - //CustomSkinLoader.logger.debug("FakeClientPlayer/getDownloadImageSkin "+username); + //For Legacy Skin + public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username) { + //CustomSkinLoader.logger.debug("FakeClientPlayer/getDownloadImageSkin "+username); + TextureManager textman = Minecraft.getMinecraft().getTextureManager(); + ITextureObject ito = textman.getTexture(resourceLocationIn); + + if (ito == null || !(ito instanceof ThreadDownloadImageData)) { + //if Legacy Skin for username not loaded yet + SkinManager skinman = Minecraft.getMinecraft().getSkinManager(); + UUID offlineUUID = EntityPlayer.getOfflineUUID(username); + GameProfile offlineProfile = new GameProfile(offlineUUID, username); + + //Load Default Skin + ResourceLocation defaultSkin = DefaultPlayerSkin.getDefaultSkin(offlineUUID); + ITextureObject defaultSkinObj = new SimpleTexture(defaultSkin); + textman.loadTexture(resourceLocationIn, defaultSkinObj); + + //Load Skin from SkinManager + skinman.loadProfileTextures(offlineProfile, new LegacyBuffer(resourceLocationIn), false); + } + + if (ito instanceof ThreadDownloadImageData) + return (ThreadDownloadImageData) ito; + else + return null; + } + + public static ResourceLocation getLocationSkin(String username) { + //CustomSkinLoader.logger.debug("FakeClientPlayer/getLocationSkin "+username); + return new ResourceLocation("skins/legacy-" + StringUtils.stripControlCodes(username)); + } + + private static class LegacyBuffer implements SkinAvailableCallback { + ResourceLocation resourceLocationIn; + boolean loaded = false; + + public LegacyBuffer(ResourceLocation resourceLocationIn) { + CustomSkinLoader.logger.debug("Loading Legacy Texture (" + resourceLocationIn + ")"); + this.resourceLocationIn = resourceLocationIn; + } + + @Override + public void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) { + if (typeIn != Type.SKIN || loaded) + return; + + loaded = true; + + TextureManager textman = Minecraft.getMinecraft().getTextureManager(); - ITextureObject ito = textman.getTexture(resourceLocationIn); + ITextureObject ito = textman.getTexture(location); - if (ito == null || !(ito instanceof ThreadDownloadImageData)) - { - //if Legacy Skin for username not loaded yet - SkinManager skinman = Minecraft.getMinecraft().getSkinManager(); - UUID offlineUUID=EntityPlayer.getOfflineUUID(username); - GameProfile offlineProfile=new GameProfile(offlineUUID,username); - - //Load Default Skin - ResourceLocation defaultSkin=DefaultPlayerSkin.getDefaultSkin(offlineUUID); - ITextureObject defaultSkinObj=new SimpleTexture(defaultSkin); - textman.loadTexture(resourceLocationIn, defaultSkinObj); - - //Load Skin from SkinManager - skinman.loadProfileTextures(offlineProfile, new LegacyBuffer(resourceLocationIn), false); - } - - if(ito instanceof ThreadDownloadImageData) - return (ThreadDownloadImageData)ito; - else - return null; + if (ito != null) + textman.loadTexture(resourceLocationIn, ito); + CustomSkinLoader.logger.debug("Legacy Texture (" + resourceLocationIn + ") Loaded as " + + (ito == null ? null : ito.toString()) + " (" + location + ")"); + //textman.bindTexture(resourceLocationIn); } - public static ResourceLocation getLocationSkin(String username) - { - //CustomSkinLoader.logger.debug("FakeClientPlayer/getLocationSkin "+username); - return new ResourceLocation("skins/legacy-" + StringUtils.stripControlCodes(username)); - } - - private static class LegacyBuffer implements SkinAvailableCallback{ - ResourceLocation resourceLocationIn; - boolean loaded=false; - - public LegacyBuffer(ResourceLocation resourceLocationIn) { - CustomSkinLoader.logger.debug("Loading Legacy Texture ("+resourceLocationIn+")"); - this.resourceLocationIn=resourceLocationIn; - } - - @Override - public void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) { - if(typeIn!=Type.SKIN || loaded) - return; - - loaded=true; - - - TextureManager textman = Minecraft.getMinecraft().getTextureManager(); - ITextureObject ito = textman.getTexture(location); - - if(ito!=null) - textman.loadTexture(resourceLocationIn, ito); - CustomSkinLoader.logger.debug("Legacy Texture ("+resourceLocationIn+") Loaded as "+ - ito==null?null:ito.toString()+" ("+location+")"); - //textman.bindTexture(resourceLocationIn); - } - - } + } } diff --git a/Common/source/customskinloader/fake/FakeSkinBuffer.java b/Common/source/customskinloader/fake/FakeSkinBuffer.java index 143b6e0..7bd635f 100644 --- a/Common/source/customskinloader/fake/FakeSkinBuffer.java +++ b/Common/source/customskinloader/fake/FakeSkinBuffer.java @@ -20,7 +20,7 @@ public class FakeSkinBuffer implements net.minecraft.client.renderer.IImageBuffe Graphics graphics = bufferedimage.getGraphics(); graphics.setColor(new Color(0,0,0,0)); graphics.fillRect(0,0,64,64); - graphics.drawImage(image,0,0,(ImageObserver)null); + graphics.drawImage(image, 0, 0, null); if (image.getHeight() == 32 * ratio){//Single Layer //Revert to original algorithm //Right Leg -> Left Leg @@ -67,7 +67,7 @@ public class FakeSkinBuffer implements net.minecraft.client.renderer.IImageBuffe * @since 14.9 */ public String judgeType(){ - if (this.imageData==null) + if (this.imageData == null) return null; if (((this.imageData[getPosition(55, 20)] & B) >>> 24) == 0)//if (55,20) is transparent return "slim"; diff --git a/Common/source/customskinloader/fake/FakeSkinManager.java b/Common/source/customskinloader/fake/FakeSkinManager.java index 97adbbe..3ef34e3 100644 --- a/Common/source/customskinloader/fake/FakeSkinManager.java +++ b/Common/source/customskinloader/fake/FakeSkinManager.java @@ -98,13 +98,14 @@ public class FakeSkinManager{ return buffer==null?image:buffer.parseUserSkin(image); } public void skinAvailable(){ - if (buffer != null) + if (buffer != null){ buffer.skinAvailable(); - if ("auto".equals(texture.getMetadata("model")) && buffer instanceof FakeSkinBuffer){ - //Auto judge skin type - Map metadata = Maps.newHashMap(); - metadata.put("model", ((FakeSkinBuffer) buffer).judgeType()); - texture = new MinecraftProfileTexture(texture.getUrl(), metadata); + if ("auto".equals(texture.getMetadata("model")) && buffer instanceof FakeSkinBuffer){ + //Auto judge skin type + Map metadata = Maps.newHashMap(); + metadata.put("model", ((FakeSkinBuffer) buffer).judgeType()); + texture = new MinecraftProfileTexture(texture.getUrl(), metadata); + } } FakeSkinManager.makeCallback(callback,type, location, texture); diff --git a/Common/source/customskinloader/loader/LegacyLoader.java b/Common/source/customskinloader/loader/LegacyLoader.java index 53999b8..6bca551 100644 --- a/Common/source/customskinloader/loader/LegacyLoader.java +++ b/Common/source/customskinloader/loader/LegacyLoader.java @@ -30,7 +30,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if(skinFile.exists()&&skinFile.isFile()) profile.skinUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified())); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(90)); + HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); if(responce.success) profile.skinUrl=HttpTextureUtil.getLegacyFakeUrl(skin); } @@ -43,7 +43,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if(capeFile.exists()&&capeFile.isFile()) profile.capeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified())); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(90)); + HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); if(responce.success) profile.capeUrl=HttpTextureUtil.getLegacyFakeUrl(cape); }