diff --git a/Common/source/customskinloader/fake/FakeClientPlayer.java b/Common/source/customskinloader/fake/FakeClientPlayer.java new file mode 100644 index 0000000..91a8a2d --- /dev/null +++ b/Common/source/customskinloader/fake/FakeClientPlayer.java @@ -0,0 +1,60 @@ +package customskinloader.fake; + +import java.util.UUID; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ThreadDownloadImageData; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.SkinManager; +import net.minecraft.client.resources.SkinManager.SkinAvailableCallback; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; + +public class FakeClientPlayer { + //For Legacy Skin + public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username) + { + TextureManager textman = Minecraft.getMinecraft().getTextureManager(); + ITextureObject ito = textman.getTexture(resourceLocationIn); + + if (ito == null) + { + //if Legacy Skin for username not loaded yet + SkinManager skinman = Minecraft.getMinecraft().getSkinManager(); + UUID offlineUUID=EntityPlayer.getOfflineUUID(username); + GameProfile offlineProfile=new GameProfile(offlineUUID,username); + + skinman.loadProfileTextures(offlineProfile, new LegacyBuffer(resourceLocationIn), false); + } + + return (ThreadDownloadImageData)ito; + } + + public static ResourceLocation getLocationSkin(String username) + { + return new ResourceLocation("skins/" + username); + } + + private static class LegacyBuffer implements SkinAvailableCallback{ + ResourceLocation resourceLocationIn; + + public LegacyBuffer(ResourceLocation resourceLocationIn) { + this.resourceLocationIn=resourceLocationIn; + } + + @Override + public void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) { + if(typeIn!=Type.SKIN) + return; + TextureManager textman = Minecraft.getMinecraft().getTextureManager(); + ITextureObject ito = textman.getTexture(location); + textman.loadTexture(resourceLocationIn, ito); + } + + } +} diff --git a/Common/source/customskinloader/fake/FakeSkinManager.java b/Common/source/customskinloader/fake/FakeSkinManager.java index 796337f..dc02312 100644 --- a/Common/source/customskinloader/fake/FakeSkinManager.java +++ b/Common/source/customskinloader/fake/FakeSkinManager.java @@ -104,5 +104,4 @@ public class FakeSkinManager{ FakeSkinManager.makeCallback(callback,type, location, texture); } } - } diff --git a/Common/source/customskinloader/profile/ProfileCache.java b/Common/source/customskinloader/profile/ProfileCache.java index 51805ba..9fb028d 100644 --- a/Common/source/customskinloader/profile/ProfileCache.java +++ b/Common/source/customskinloader/profile/ProfileCache.java @@ -87,6 +87,7 @@ public class ProfileCache { } private void saveLocalProfile(String username,UserProfile profile){ String json=CustomSkinLoader.GSON.toJson(profile); + File localProfile=new File(PROFILE_CACHE_DIR,username+".json"); if(localProfile.exists()) localProfile.delete(); try { diff --git a/Forge/source/customskinloader/forge/SpectatorMenuTransformer.java b/Forge/source/customskinloader/forge/SpectatorMenuTransformer.java new file mode 100644 index 0000000..45f8a55 --- /dev/null +++ b/Forge/source/customskinloader/forge/SpectatorMenuTransformer.java @@ -0,0 +1,35 @@ +package customskinloader.forge; + +import java.util.ListIterator; + +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InsnList; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; + +import customskinloader.forge.TransformerManager.IMethodTransformer; +import customskinloader.forge.TransformerManager.TransformTarget; + +public class SpectatorMenuTransformer { + @TransformTarget(className="net.minecraft.client.gui.spectator.PlayerMenuObject", + methodNames={""}, + desc="(Lcom/mojang/authlib/GameProfile;)V") + public static class PlayerMenuObjectTransformer implements IMethodTransformer{ + + @Override + public void transform(ClassNode cn, MethodNode mn) { + InsnList il=mn.instructions; + ListIterator li=il.iterator(); + while(li.hasNext()) { + AbstractInsnNode nn=li.next(); + if(nn.getOpcode()!=Opcodes.INVOKESTATIC) + continue; + MethodInsnNode min=(MethodInsnNode)nn; + min.owner="customskinloader/fake/FakeClientPlayer"; + } + } + + } +}