diff --git a/Common/source/customskinloader/CustomSkinLoader.java b/Common/source/customskinloader/CustomSkinLoader.java index 6f94c3e..21e251c 100644 --- a/Common/source/customskinloader/CustomSkinLoader.java +++ b/Common/source/customskinloader/CustomSkinLoader.java @@ -28,7 +28,7 @@ public class CustomSkinLoader { public static final String CustomSkinLoader_VERSION="@MOD_VERSION@"; public static final String CustomSkinLoader_FULL_VERSION="@MOD_FULL_VERSION@"; - public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir0(),"CustomSkinLoader"), + public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader"), LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json"); public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={ diff --git a/Common/source/customskinloader/config/Config.java b/Common/source/customskinloader/config/Config.java index e81fda7..cdeee6b 100644 --- a/Common/source/customskinloader/config/Config.java +++ b/Common/source/customskinloader/config/Config.java @@ -17,7 +17,6 @@ import customskinloader.utils.HttpUtil0; public class Config { //Program public String version; - public boolean enable=true; public List loadlist; //Function @@ -63,8 +62,7 @@ public class Config { } //Output config - CustomSkinLoader.logger.info("Enable:"+config.enable+ - ", EnableSkull:"+config.enableSkull+ + CustomSkinLoader.logger.info("EnableSkull:"+config.enableSkull+ ", EnableDynamicSkull:"+config.enableDynamicSkull+ ", EnableTranSkin:"+config.enableTransparentSkin+ ", IgnoreHttpsCertificate:"+config.ignoreHttpsCertificate+ diff --git a/Common/source/customskinloader/renderer/SkinBuffer.java b/Common/source/customskinloader/fake/FakeSkinBuffer.java similarity index 97% rename from Common/source/customskinloader/renderer/SkinBuffer.java rename to Common/source/customskinloader/fake/FakeSkinBuffer.java index ace6e88..cf659c6 100644 --- a/Common/source/customskinloader/renderer/SkinBuffer.java +++ b/Common/source/customskinloader/fake/FakeSkinBuffer.java @@ -1,4 +1,4 @@ -package customskinloader.renderer; +package customskinloader.fake; import java.awt.Color; import java.awt.Graphics; @@ -6,7 +6,7 @@ import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.ImageObserver; -public class SkinBuffer implements net.minecraft.client.renderer.IImageBuffer { +public class FakeSkinBuffer implements net.minecraft.client.renderer.IImageBuffer { private int[] imageData; private int ratio=1; diff --git a/Common/source/customskinloader/fake/FakeSkinManager.java b/Common/source/customskinloader/fake/FakeSkinManager.java new file mode 100644 index 0000000..3a7cdb8 --- /dev/null +++ b/Common/source/customskinloader/fake/FakeSkinManager.java @@ -0,0 +1,115 @@ +package customskinloader.fake; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import com.google.common.collect.Maps; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; +import com.mojang.authlib.minecraft.MinecraftSessionService; + +import customskinloader.CustomSkinLoader; +import customskinloader.utils.HttpTextureUtil; +import customskinloader.utils.HttpTextureUtil.HttpTextureInfo; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IImageBuffer; +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.DefaultPlayerSkin; +import net.minecraft.client.resources.SkinManager; +import net.minecraft.util.ResourceLocation; + +public class FakeSkinManager extends SkinManager { + private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue()); + private final TextureManager textureManager; + + public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) { + super(textureManagerInstance, skinCacheDirectory, sessionService); + this.textureManager=textureManagerInstance; + HttpTextureUtil.defaultCacheDir=skinCacheDirectory; + } + + @Override + public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType){ + return this.loadSkin(profileTexture, textureType, null); + } + @Override + public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, final SkinAvailableCallback skinAvailableCallback){ + HttpTextureInfo info=HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl()); + + final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash); + ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation); + + if (itextureobject != null)//Have already loaded + makeCallback(skinAvailableCallback,textureType, resourcelocation, profileTexture); + else{ + ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), + new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture)); + this.textureManager.loadTexture(resourcelocation, threaddownloadimagedata); + } + return resourcelocation; + } + @Override + public void loadProfileTextures(final GameProfile profile, final SkinAvailableCallback skinAvailableCallback, final boolean requireSecure){ + THREAD_POOL.submit(new Runnable(){ + public void run(){ + final Map map = Maps.newHashMap(); + map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile)); + + Minecraft.getMinecraft().addScheduledTask(new Runnable(){ + public void run(){ + for(Type type:Type.values()) + if(map.containsKey(type)) + FakeSkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback); + } + }); + } + }); + } + @Override + public Map loadSkinFromCache(GameProfile profile){ + return CustomSkinLoader.config.enableSkull? + CustomSkinLoader.loadProfileFromCache(profile): + super.loadSkinFromCache(profile); + } + + private static void makeCallback(SkinAvailableCallback callback,Type type, ResourceLocation location, MinecraftProfileTexture texture){ + if(callback!=null) + callback.skinAvailable(type, location, texture); + } + private class BaseBuffer implements IImageBuffer{ + private IImageBuffer buffer; + + private SkinAvailableCallback callback; + private Type type; + private ResourceLocation location; + private MinecraftProfileTexture texture; + public BaseBuffer(SkinAvailableCallback callback,Type type,ResourceLocation location,MinecraftProfileTexture texture){ + this.buffer=(type==Type.SKIN?new FakeSkinBuffer():null); + + this.callback=callback; + this.type=type; + this.location=location; + this.texture=texture; + } + + public BufferedImage parseUserSkin(BufferedImage image){ + return buffer==null?image:buffer.parseUserSkin(image); + } + public void skinAvailable(){ + if (buffer != null) + buffer.skinAvailable(); + + FakeSkinManager.makeCallback(callback,type, location, texture); + } + } + +} diff --git a/Common/source/customskinloader/forge/FMLMod.java b/Common/source/customskinloader/forge/FMLMod.java new file mode 100644 index 0000000..4008408 --- /dev/null +++ b/Common/source/customskinloader/forge/FMLMod.java @@ -0,0 +1,8 @@ +package customskinloader.forge; + +import net.minecraftforge.fml.common.Mod; + +@Mod(modid = "customskinloader", name = "CustomSkinLoader", version = "@MOD_FULL_VERSION@", clientSideOnly=true) +public class FMLMod{ + +} \ No newline at end of file diff --git a/Common/source/customskinloader/loader/ElfSkinLoader.java b/Common/source/customskinloader/loader/ElfSkinLoader.java index 0778444..5cb7785 100644 --- a/Common/source/customskinloader/loader/ElfSkinLoader.java +++ b/Common/source/customskinloader/loader/ElfSkinLoader.java @@ -77,7 +77,7 @@ public class ElfSkinLoader implements IProfileLoader { } public static void makeLogout(String ip,String username){ String url=LOGOUT_URL.replaceAll("%SERVER_IP%", ip).replaceAll("%USERNAME%", username); - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(url).setCacheTime(-1)); + HttpRequestUtil.makeHttpRequest(new HttpRequest(url).setCacheTime(-1)); } public static Profile getProfile(String ip,String username){ String url=PROFILE_URL.replaceAll("%SERVER_IP%", ip).replaceAll("%USERNAME%", username); diff --git a/Common/source/customskinloader/loader/MojangAPILoader.java b/Common/source/customskinloader/loader/MojangAPILoader.java index 4d409fa..2e8dc5e 100644 --- a/Common/source/customskinloader/loader/MojangAPILoader.java +++ b/Common/source/customskinloader/loader/MojangAPILoader.java @@ -25,16 +25,13 @@ import customskinloader.profile.UserProfile; import customskinloader.utils.HttpRequestUtil; import customskinloader.utils.HttpRequestUtil.HttpRequest; import customskinloader.utils.HttpRequestUtil.HttpResponce; +import customskinloader.utils.MinecraftUtil; public class MojangAPILoader implements ProfileLoader.IProfileLoader { - public static MinecraftSessionService defaultSessionService=null; + public static final MinecraftSessionService defaultSessionService=MinecraftUtil.getSessionService(); @Override public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { - if(defaultSessionService==null){ - CustomSkinLoader.logger.warning("Session Service Not Exist."); - return null; - } Map map=getTextures(gameProfile); if(!map.isEmpty()){ CustomSkinLoader.logger.info("Default profile will be used."); diff --git a/Common/source/customskinloader/tweaker/ClassTransformer.java b/Common/source/customskinloader/tweaker/ClassTransformer.java index 9cc1abf..fada590 100644 --- a/Common/source/customskinloader/tweaker/ClassTransformer.java +++ b/Common/source/customskinloader/tweaker/ClassTransformer.java @@ -27,11 +27,11 @@ public class ClassTransformer implements IClassTransformer { URL urls[] = ucl.getURLs(); for (URL url : urls) { if(MinecraftUtil.isCoreFile(url)){ - ModSystemTweaker.logger.info(url.toString()+" : SKIP (core file)."); + ModSystemTweaker.logger.debug(url.toString()+" : SKIP (core file)."); continue; } if(MinecraftUtil.isLibraryFile(url)){ - ModSystemTweaker.logger.info(url.toString()+" : SKIP (library file)."); + ModSystemTweaker.logger.debug(url.toString()+" : SKIP (library file)."); continue; } File file = new File(url.toURI()); @@ -46,7 +46,7 @@ public class ClassTransformer implements IClassTransformer { } if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){ tempZipFile.close(); - ModSystemTweaker.logger.info(url.toString()+" : FINISH (not target)."); + ModSystemTweaker.logger.debug(url.toString()+" : FINISH (not target)."); continue; } zipFile = tempZipFile; diff --git a/Common/source/customskinloader/tweaker/ModSystemTweaker.java b/Common/source/customskinloader/tweaker/ModSystemTweaker.java index 9b0ac92..9d3af04 100644 --- a/Common/source/customskinloader/tweaker/ModSystemTweaker.java +++ b/Common/source/customskinloader/tweaker/ModSystemTweaker.java @@ -1,7 +1,6 @@ package customskinloader.tweaker; import customskinloader.Logger; -import customskinloader.utils.MinecraftUtil; import java.io.File; import java.util.List; @@ -14,8 +13,7 @@ public class ModSystemTweaker implements ITweaker { public static Logger logger = new Logger(); public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { - MinecraftUtil.minecraftDataFolder=gameDir; - File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log"); + File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log"); logger = new Logger(tweakerLogFile); logger.info("Using ModSystemTweaker"); diff --git a/Common/source/customskinloader/tweaker/Tweaker.java b/Common/source/customskinloader/tweaker/Tweaker.java index 182dfe3..dcc899f 100644 --- a/Common/source/customskinloader/tweaker/Tweaker.java +++ b/Common/source/customskinloader/tweaker/Tweaker.java @@ -1,7 +1,6 @@ package customskinloader.tweaker; import customskinloader.Logger; -import customskinloader.utils.MinecraftUtil; import java.io.File; import java.util.List; @@ -18,8 +17,7 @@ public class Tweaker implements ITweaker { public static Logger logger = new Logger(); public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { - MinecraftUtil.minecraftDataFolder=gameDir; - File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log"); + File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log"); logger = new Logger(tweakerLogFile); logger.info("Using Tweaker"); diff --git a/Common/source/customskinloader/utils/HttpTextureUtil.java b/Common/source/customskinloader/utils/HttpTextureUtil.java index 108d1ff..7569d6e 100644 --- a/Common/source/customskinloader/utils/HttpTextureUtil.java +++ b/Common/source/customskinloader/utils/HttpTextureUtil.java @@ -24,6 +24,9 @@ public class HttpTextureUtil { defaultCacheDir.mkdirs(); } } + public static File getCacheDir(){ + return defaultCacheDir==null?new File(MinecraftUtil.getMinecraftDataDir(),"assets/skins"):defaultCacheDir; + } public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){ HttpTextureInfo info=new HttpTextureInfo(); diff --git a/Common/source/customskinloader/utils/MinecraftUtil.java b/Common/source/customskinloader/utils/MinecraftUtil.java index a2bdb6d..baaa7cb 100644 --- a/Common/source/customskinloader/utils/MinecraftUtil.java +++ b/Common/source/customskinloader/utils/MinecraftUtil.java @@ -10,27 +10,24 @@ import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; +import com.mojang.authlib.minecraft.MinecraftSessionService; + +import net.minecraft.client.renderer.texture.TextureManager; + /** - * MinecraftUtil for mcp version. - * It is the only class in package 'customskinloader' which has differences in mcp/non-mcp version. - * * @author Alexander Xia * @since 13.6 * */ public class MinecraftUtil { - public static File getMinecraftDataDir0(){ + public static File getMinecraftDataDir(){ return net.minecraft.client.Minecraft.getMinecraft().mcDataDir; } - - public static File minecraftDataFolder=null; - public static File getMinecraftDataDir(){ - if(minecraftDataFolder!=null) - return minecraftDataFolder; - testProbe(); - if(minecraftDataFolder!=null) - return minecraftDataFolder; - return new File(""); + public static MinecraftSessionService getSessionService(){ + return net.minecraft.client.Minecraft.getMinecraft().getSessionService(); + } + public static TextureManager getTextureManager(){ + return net.minecraft.client.Minecraft.getMinecraft().getTextureManager(); } private static ArrayList minecraftVersion=new ArrayList(); @@ -98,11 +95,10 @@ public class MinecraftUtil { } if(m==null || !m.matches()) continue; - if(minecraftDataFolder==null) - minecraftDataFolder=new File(m.group(1)); minecraftVersion.add(m.group(2)); } } + public static boolean isCoreFile(URL url){ Matcher m = null; try{ diff --git a/Forge/build.gradle b/Forge/build.gradle index a82bdd9..376bdf8 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -16,7 +16,6 @@ apply plugin: 'net.minecraftforge.gradle.forge' ext.MINECRAFT_VERSION="1.10.2" ext.FORGE_VERSION="12.18.2.2099" ext.MAPPING_VERSION="stable_29" -ext.MCP_SOURCE="1.10-mcp931" ext.MINECRAFT_FULL_VERSIONS="1.8,1.8.8,1.8.9,1.9,1.9.4,1.10,1.10.2,1.11" ext.snapshot = !(rootProject.ext.config.snapshot==""||rootProject.ext.config.snapshot=="0"||rootProject.ext.config.snapshot==0) @@ -62,7 +61,6 @@ minecraft { task mergeSource { doLast { copy { from '../Common/source' - from '../'+MCP_SOURCE+"/src/minecraft/" from 'source' into 'MergedSource' } diff --git a/Forge/source/customskinloader/forge/FMLPlugin.java b/Forge/source/customskinloader/forge/FMLPlugin.java index 033f707..a02c744 100644 --- a/Forge/source/customskinloader/forge/FMLPlugin.java +++ b/Forge/source/customskinloader/forge/FMLPlugin.java @@ -8,7 +8,7 @@ public class FMLPlugin implements IFMLLoadingPlugin { @Override public String[] getASMTransformerClass() { - return new String[] {customskinloader.tweaker.ClassTransformer.class.getName()}; + return new String[] {TransformerManager.class.getName()}; } @Override diff --git a/Forge/source/customskinloader/forge/TransformerManager.java b/Forge/source/customskinloader/forge/TransformerManager.java new file mode 100644 index 0000000..613f924 --- /dev/null +++ b/Forge/source/customskinloader/forge/TransformerManager.java @@ -0,0 +1,81 @@ +package customskinloader.forge; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.MethodNode; + +import net.minecraft.launchwrapper.IClassTransformer; +import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; +import net.minecraftforge.fml.relauncher.FMLRelaunchLog; + +public class TransformerManager implements IClassTransformer { + public static class TransformTarget{ + public String className; + public String srgName; + public String mcpName; + public String desc; + public TransformTarget(String className,String srgName,String mcpName,String desc){ + this.className=className; + this.srgName=srgName; + this.mcpName=mcpName; + this.desc=desc; + } + } + public interface IMethodTransformer{ + public TransformTarget getTarget(); + public void transform(MethodNode mn); + } + private static final IMethodTransformer[] TRANFORMERS={new Transformers.SkinManagerTransformer()}; + private Map> map; + public TransformerManager(){ + map = new HashMap>(); + for(IMethodTransformer t:TRANFORMERS) + addMethodTransformer(t.getTarget(),t); + } + private void addMethodTransformer(TransformTarget target, IMethodTransformer transformer) { + if (!map.containsKey(target.className)) + map.put(target.className, new HashMap()); + map.get(target.className).put(target.srgName + target.desc, transformer); + map.get(target.className).put(target.mcpName + target.desc, transformer); + } + + //From: https://github.com/RecursiveG/UniSkinMod/blob/1.9.4/src/main/java/org/devinprogress/uniskinmod/coremod/BaseAsmTransformer.java + @Override + public byte[] transform(String obfClassName, String className, byte[] bytes) { + if (!map.containsKey(className)) return bytes; + Map transMap = map.get(className); + + ClassReader cr = new ClassReader(bytes); + ClassNode cn = new ClassNode(); + cr.accept(cn, 0); + + // NOTE: `map` = convert obfuscated name to srgName; + List ml = new ArrayList(); + ml.addAll(cn.methods); + for (MethodNode mn : ml) { + String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(obfClassName, mn.name, mn.desc); + String methodDesc = FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(mn.desc); + if (transMap.containsKey(methodName + methodDesc)) { + try { + FMLRelaunchLog.info("Transforming method %s in class %s(%s)", methodName + methodDesc, obfClassName, className); + transMap.get(methodName + methodDesc).transform(mn); + FMLRelaunchLog.info("Successfully transformed method %s in class %s(%s)", methodName + methodDesc, obfClassName, className); + } catch (Exception e) { + FMLRelaunchLog.warning("An error happened when transforming method %s in class %s(%s). The whole class was not modified.", methodName + methodDesc, obfClassName, className); + e.printStackTrace(); + return bytes; + } + } + } + + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cn.accept(cw); + return cw.toByteArray(); + } +} diff --git a/Forge/source/customskinloader/forge/Transformers.java b/Forge/source/customskinloader/forge/Transformers.java new file mode 100644 index 0000000..4a76d21 --- /dev/null +++ b/Forge/source/customskinloader/forge/Transformers.java @@ -0,0 +1,23 @@ +package customskinloader.forge; + +import org.objectweb.asm.tree.MethodNode; + +import customskinloader.forge.TransformerManager.IMethodTransformer; +import customskinloader.forge.TransformerManager.TransformTarget; + +public class Transformers { + public static class SkinManagerTransformer implements IMethodTransformer{ + TransformTarget target=new TransformTarget("net.minecraft.client.Minecraft","init","func_71384_a","()V"); + @Override + public TransformTarget getTarget() { + return target; + } + + @Override + public void transform(MethodNode mn) { + //TODO + } + + } + +}