From 25c864b11b2454db7e819f81970854de29ea64ac Mon Sep 17 00:00:00 2001 From: xfl03 Date: Sat, 10 Sep 2016 21:00:53 +0800 Subject: [PATCH] Dynamic Skull Test --- .../client/resources/SkinManager.java | 7 +- 1.7.10-mcp908/build.gradle | 2 +- .../profile/ModelManager0.java | 11 +- .../client/resources/SkinManager.java | 7 +- .../client/resources/SkinManager.java | 5 +- .../client/resources/SkinManager.java | 5 +- .../client/resources/SkinManager.java | 5 +- .../client/resources/SkinManager.java | 5 +- Common/customskinloader/CustomSkinLoader.java | 12 +- Common/customskinloader/config/Config.java | 9 +- .../config/SkinSiteProfile.java | 15 --- .../loader/JsonAPILoader.java | 6 +- .../customskinloader/loader/LegacyLoader.java | 14 +- .../loader/MojangAPILoader.java | 9 +- .../loader/ProfileLoader.java | 2 +- .../profile/DynamicSkullManager.java | 124 ++++++++++++++++++ .../profile/ModelManager0.java | 16 ++- .../utils/HttpTextureUtil.java | 14 +- Common/customskinloader/utils/HttpUtil0.java | 30 +++++ README.md | 5 +- build.properties | 4 +- common.gradle | 21 ++- 22 files changed, 248 insertions(+), 80 deletions(-) create mode 100644 Common/customskinloader/profile/DynamicSkullManager.java diff --git a/1.10-mcp931/src/minecraft/net/minecraft/client/resources/SkinManager.java b/1.10-mcp931/src/minecraft/net/minecraft/client/resources/SkinManager.java index 9d5ea75..c51a04c 100644 --- a/1.10-mcp931/src/minecraft/net/minecraft/client/resources/SkinManager.java +++ b/1.10-mcp931/src/minecraft/net/minecraft/client/resources/SkinManager.java @@ -45,8 +45,9 @@ public class SkinManager return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false); } }); - //CustomSkinLoader Begin (Init Session Service) + //CustomSkinLoader Begin (Init) customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService; + customskinloader.utils.HttpTextureUtil.defaultCacheDir=skinCacheDirectory; //CustomSkinLoader End } @@ -64,7 +65,7 @@ public class SkinManager public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback) { //CustomSkinLoader Begin (Parse HttpTextureInfo) - customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(this.skinCacheDir, profileTexture.getUrl()); + customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl()); //CustomSkinLoader End final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);//Modified ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation); @@ -150,8 +151,6 @@ public class SkinManager { //CustomSkinLoader Begin (Skull Part) //return (Map)this.skinCacheLoader.getUnchecked(profile); - if(profile.getName()==null) - return this.skinCacheLoader.getUnchecked(profile); return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)? customskinloader.CustomSkinLoader.loadProfileFromCache(profile): this.skinCacheLoader.getUnchecked(profile); diff --git a/1.7.10-mcp908/build.gradle b/1.7.10-mcp908/build.gradle index dbf2446..aaaa1bc 100644 --- a/1.7.10-mcp908/build.gradle +++ b/1.7.10-mcp908/build.gradle @@ -36,7 +36,7 @@ configFile.withReader { project.ext.config = new ConfigSlurper().parse prop } //Example: 14.4a-SNAPSHOT-20160820 -version = rootConfig.version + rootConfig.dev_version + (rootConfig.snapshot_version==''?'':('-SNAPSHOT-'+rootConfig.snapshot_version)) +version = rootConfig.version + rootConfig.dev_version + (rootConfig.snapshot==''?'':('-SNAPSHOT-'+System.getenv("BUILD_NUMBER"))) group = config.group archivesBaseName = rootConfig.name+"_"+config.minecraft_version diff --git a/1.7.10-mcp908/src/minecraft/customskinloader/profile/ModelManager0.java b/1.7.10-mcp908/src/minecraft/customskinloader/profile/ModelManager0.java index b31b554..3d94bb6 100644 --- a/1.7.10-mcp908/src/minecraft/customskinloader/profile/ModelManager0.java +++ b/1.7.10-mcp908/src/minecraft/customskinloader/profile/ModelManager0.java @@ -58,20 +58,21 @@ public class ModelManager0 { if(profile==null) return map; if(profile.skinUrl!=null) - map.put(Type.SKIN, getProfileTexture(profile.skinUrl)); + map.put(Type.SKIN, getProfileTexture(profile.skinUrl,null)); if(profile.capeUrl!=null) - map.put(Type.CAPE, getProfileTexture(profile.capeUrl)); + map.put(Type.CAPE, getProfileTexture(profile.capeUrl,null)); return map; } /** * Parse url to MinecraftProfileTexture - * Fix authlib 21 bug + * Fix authlib 21 bug for 1.7.10 * @param url - textureUrl + * metadata - metadata * @return MinecraftProfileTexture - * @since 13.2 + * @since 14.5 */ - public static MinecraftProfileTexture getProfileTexture(String url){ + public static MinecraftProfileTexture getProfileTexture(String url,Map metadata){ Map hashMap=new HashMap(); hashMap.put("url", url); Gson gson=new Gson(); diff --git a/1.7.10-mcp908/src/minecraft/net/minecraft/client/resources/SkinManager.java b/1.7.10-mcp908/src/minecraft/net/minecraft/client/resources/SkinManager.java index 3699218..43b97c5 100644 --- a/1.7.10-mcp908/src/minecraft/net/minecraft/client/resources/SkinManager.java +++ b/1.7.10-mcp908/src/minecraft/net/minecraft/client/resources/SkinManager.java @@ -53,8 +53,9 @@ public class SkinManager return this.func_152786_a((GameProfile)p_load_1_); } }); - //CustomSkinLoader Begin (Init Session Service) + //CustomSkinLoader Begin (Init) customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService; + customskinloader.utils.HttpTextureUtil.defaultCacheDir=skinCacheDirectory; //CustomSkinLoader End } @@ -159,9 +160,7 @@ public class SkinManager public Map loadSkinFromCache(GameProfile p_152788_1_) { //CustomSkinLoader Begin (Skull Part) - //return (Map)this.skinCacheLoader.getUnchecked(profile); - if(p_152788_1_.getName()==null) - return (Map)this.skinCacheLoader.getUnchecked(p_152788_1_); + //return (Map)this.skinCacheLoader.getUnchecked(p_152788_1_); return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)? customskinloader.CustomSkinLoader.loadProfileFromCache(p_152788_1_): (Map)this.skinCacheLoader.getUnchecked(p_152788_1_); diff --git a/1.8-mcp910/src/minecraft/net/minecraft/client/resources/SkinManager.java b/1.8-mcp910/src/minecraft/net/minecraft/client/resources/SkinManager.java index 58b997d..3e97d00 100644 --- a/1.8-mcp910/src/minecraft/net/minecraft/client/resources/SkinManager.java +++ b/1.8-mcp910/src/minecraft/net/minecraft/client/resources/SkinManager.java @@ -51,8 +51,9 @@ public class SkinManager return this.func_152786_a((GameProfile)p_load_1_); } }); - //CustomSkinLoader Begin (Init Session Service) + //CustomSkinLoader Begin (Init) customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService; + customskinloader.utils.HttpTextureUtil.defaultCacheDir=skinCacheDirectory; //CustomSkinLoader End } @@ -159,8 +160,6 @@ public class SkinManager { //CustomSkinLoader Begin (Skull Part) //return (Map)this.skinCacheLoader.getUnchecked(profile); - if(profile.getName()==null) - return (Map)this.skinCacheLoader.getUnchecked(profile); return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)? customskinloader.CustomSkinLoader.loadProfileFromCache(profile): (Map)this.skinCacheLoader.getUnchecked(profile); diff --git a/1.8.8-mcp918/src/minecraft/net/minecraft/client/resources/SkinManager.java b/1.8.8-mcp918/src/minecraft/net/minecraft/client/resources/SkinManager.java index 4b2a787..e86cc91 100644 --- a/1.8.8-mcp918/src/minecraft/net/minecraft/client/resources/SkinManager.java +++ b/1.8.8-mcp918/src/minecraft/net/minecraft/client/resources/SkinManager.java @@ -44,8 +44,9 @@ public class SkinManager return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false); } }); - //CustomSkinLoader Begin (Init Session Service) + //CustomSkinLoader Begin (Init) customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService; + customskinloader.utils.HttpTextureUtil.defaultCacheDir=skinCacheDirectory; //CustomSkinLoader End } @@ -149,8 +150,6 @@ public class SkinManager { //CustomSkinLoader Begin (Skull Part) //return (Map)this.skinCacheLoader.getUnchecked(profile); - if(profile.getName()==null) - return this.skinCacheLoader.getUnchecked(profile); return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)? customskinloader.CustomSkinLoader.loadProfileFromCache(profile): this.skinCacheLoader.getUnchecked(profile); diff --git a/1.9-mcp924/src/minecraft/net/minecraft/client/resources/SkinManager.java b/1.9-mcp924/src/minecraft/net/minecraft/client/resources/SkinManager.java index 49a2225..439a571 100644 --- a/1.9-mcp924/src/minecraft/net/minecraft/client/resources/SkinManager.java +++ b/1.9-mcp924/src/minecraft/net/minecraft/client/resources/SkinManager.java @@ -45,8 +45,9 @@ public class SkinManager return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false); } }); - //CustomSkinLoader Begin (Init Session Service) + //CustomSkinLoader Begin (Init) customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService; + customskinloader.utils.HttpTextureUtil.defaultCacheDir=skinCacheDirectory; //CustomSkinLoader End } @@ -150,8 +151,6 @@ public class SkinManager { //CustomSkinLoader Begin (Skull Part) //return (Map)this.skinCacheLoader.getUnchecked(profile); - if(profile.getName()==null) - return this.skinCacheLoader.getUnchecked(profile); return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)? customskinloader.CustomSkinLoader.loadProfileFromCache(profile): this.skinCacheLoader.getUnchecked(profile); diff --git a/1.9.4-mcp928/src/minecraft/net/minecraft/client/resources/SkinManager.java b/1.9.4-mcp928/src/minecraft/net/minecraft/client/resources/SkinManager.java index 1c36f8e..73a6cb0 100644 --- a/1.9.4-mcp928/src/minecraft/net/minecraft/client/resources/SkinManager.java +++ b/1.9.4-mcp928/src/minecraft/net/minecraft/client/resources/SkinManager.java @@ -45,8 +45,9 @@ public class SkinManager return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false); } }); - //CustomSkinLoader Begin (Init Session Service) + //CustomSkinLoader Begin (Init) customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService; + customskinloader.utils.HttpTextureUtil.defaultCacheDir=skinCacheDirectory; //CustomSkinLoader End } @@ -150,8 +151,6 @@ public class SkinManager { //CustomSkinLoader Begin (Skull Part) //return (Map)this.skinCacheLoader.getUnchecked(profile); - if(profile.getName()==null) - return this.skinCacheLoader.getUnchecked(profile); return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)? customskinloader.CustomSkinLoader.loadProfileFromCache(profile): this.skinCacheLoader.getUnchecked(profile); diff --git a/Common/customskinloader/CustomSkinLoader.java b/Common/customskinloader/CustomSkinLoader.java index aa8dc7a..94ed013 100644 --- a/Common/customskinloader/CustomSkinLoader.java +++ b/Common/customskinloader/CustomSkinLoader.java @@ -21,6 +21,7 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import customskinloader.config.Config; import customskinloader.config.SkinSiteProfile; import customskinloader.loader.*; +import customskinloader.profile.DynamicSkullManager; import customskinloader.profile.ModelManager0; import customskinloader.profile.ProfileCache; import customskinloader.profile.UserProfile; @@ -45,13 +46,14 @@ public class CustomSkinLoader { //SkinSiteProfile.creatLegacy("Minecrack","http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png","http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"), SkinSiteProfile.createUniSkinAPI("SkinMe","http://www.skinme.cc/uniskin/"), SkinSiteProfile.createCustomSkinAPI("McSkin","http://www.mcskin.cc/"), - SkinSiteProfile.createLegacy("LocalSkin", true, "LocalSkin/skins/{USERNAME}.png", "LocalSkin/capes/{USERNAME}.png")}; + SkinSiteProfile.createLegacy("LocalSkin", "LocalSkin/skins/{USERNAME}.png", "LocalSkin/capes/{USERNAME}.png")}; public static final Gson GSON=new GsonBuilder().setPrettyPrinting().create(); public static final Logger logger=initLogger(); public static final Config config=Config.loadConfig0(); private static final ProfileCache profileCache=new ProfileCache(); + private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager(); //For User Skin public static Map loadProfile(GameProfile gameProfile){ @@ -96,7 +98,7 @@ public class CustomSkinLoader { } UserProfile profile=null; try{ - profile=loader.loadProfile(ssp, gameProfile,(ssp.local==null?false:ssp.local==true)); + profile=loader.loadProfile(ssp, gameProfile); }catch(Exception e){ logger.warning("Exception occurs while loading."); logger.warning(e); @@ -129,10 +131,8 @@ public class CustomSkinLoader { //For Skull public static Map loadProfileFromCache(final GameProfile gameProfile) { String username=gameProfile.getName(); - if(username==null){ - logger.warning("Could not load profile from cache: username is null."); - return Maps.newHashMap(); - } + if(username==null) + return dynamicSkullManager.getTexture(gameProfile); if(config.enableUpdateSkull?profileCache.isReady(username):profileCache.isExist(username)){ UserProfile profile=profileCache.getProfile(username); return ModelManager0.fromUserProfile(profile); diff --git a/Common/customskinloader/config/Config.java b/Common/customskinloader/config/Config.java index 15e1a7e..01610c4 100644 --- a/Common/customskinloader/config/Config.java +++ b/Common/customskinloader/config/Config.java @@ -16,6 +16,7 @@ public class Config { public String version; public boolean enable=true; public boolean enableSkull=true; + public boolean enableDynamicSkull=true; public boolean enableTransparentSkin=true; public int cacheExpiry=10; public boolean enableUpdateSkull=false; @@ -38,7 +39,13 @@ public class Config { ", enableUpdateSkull:"+config.enableUpdateSkull+ ", LocalProfileCache:"+config.enableLocalProfileCache+ ", LoadList:"+(config.loadlist==null?0:config.loadlist.length)); - if(config.version==null||Float.parseFloat(CustomSkinLoader.CustomSkinLoader_VERSION)-Float.parseFloat(config.version)>0.01){ + float floatVersion=0f; + try{ + floatVersion=Float.parseFloat(CustomSkinLoader.CustomSkinLoader_VERSION); + }catch (Exception e){ + CustomSkinLoader.logger.warning("Exception occurs while parsing version: "+e.toString()); + } + if(config.version==null||floatVersion-Float.parseFloat(config.version)>0.01){ CustomSkinLoader.logger.info("Config File is out of date: "+config.version); config.version=CustomSkinLoader.CustomSkinLoader_VERSION; writeConfig(config,true); diff --git a/Common/customskinloader/config/SkinSiteProfile.java b/Common/customskinloader/config/SkinSiteProfile.java index f1725f2..f02004a 100644 --- a/Common/customskinloader/config/SkinSiteProfile.java +++ b/Common/customskinloader/config/SkinSiteProfile.java @@ -17,38 +17,23 @@ public class SkinSiteProfile { return ssp; } public static SkinSiteProfile createCustomSkinAPI(String name,String root){ - return createCustomSkinAPI(name,false,root); - } - public static SkinSiteProfile createCustomSkinAPI(String name,boolean local,String root){ SkinSiteProfile ssp=new SkinSiteProfile(); ssp.name=name; ssp.type="CustomSkinAPI"; - if(local) - ssp.local=true; ssp.root=root; return ssp; } public static SkinSiteProfile createUniSkinAPI(String name,String root){ - return createUniSkinAPI(name,false,root); - } - public static SkinSiteProfile createUniSkinAPI(String name,boolean local,String root){ SkinSiteProfile ssp=new SkinSiteProfile(); ssp.name=name; ssp.type="UniSkinAPI"; - if(local) - ssp.local=true; ssp.root=root; return ssp; } public static SkinSiteProfile createLegacy(String name,String skin,String cape){ - return createLegacy(name,false,skin,cape); - } - public static SkinSiteProfile createLegacy(String name,boolean local,String skin,String cape){ SkinSiteProfile ssp=new SkinSiteProfile(); ssp.name=name; ssp.type="Legacy"; - if(local) - ssp.local=true; ssp.skin=skin; ssp.cape=cape; return ssp; diff --git a/Common/customskinloader/loader/JsonAPILoader.java b/Common/customskinloader/loader/JsonAPILoader.java index b3a4663..7555977 100644 --- a/Common/customskinloader/loader/JsonAPILoader.java +++ b/Common/customskinloader/loader/JsonAPILoader.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Set; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import com.mojang.authlib.GameProfile; @@ -37,8 +38,9 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { this.type=type; } @Override - public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile, boolean local) throws Exception { + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { String username=gameProfile.getName(); + boolean local=HttpUtil0.isLocal(ssp.root); if(ssp.root==null||ssp.root.equals("")){ CustomSkinLoader.logger.info("Root not defined."); return null; @@ -69,7 +71,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { } @Override public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) { - return ssp0.root.equalsIgnoreCase(ssp1.root); + return StringUtils.isNoneEmpty(ssp0.root)?ssp0.root.equalsIgnoreCase(ssp1.root):true; } @Override public String getName() { diff --git a/Common/customskinloader/loader/LegacyLoader.java b/Common/customskinloader/loader/LegacyLoader.java index 521c9a0..3c47531 100644 --- a/Common/customskinloader/loader/LegacyLoader.java +++ b/Common/customskinloader/loader/LegacyLoader.java @@ -2,6 +2,8 @@ package customskinloader.loader; import java.io.File; +import org.apache.commons.lang3.StringUtils; + import com.mojang.authlib.GameProfile; import customskinloader.CustomSkinLoader; @@ -14,12 +16,12 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { public static final String USERNAME_REGEX="\\{USERNAME\\}"; @Override - public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile, boolean local) throws Exception { + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { String username=gameProfile.getName(); UserProfile profile=new UserProfile(); - if(ssp.skin!=null && !ssp.skin.equals("")){ + if(StringUtils.isNoneEmpty(ssp.skin)){ String skin=ssp.skin.replaceAll(USERNAME_REGEX, username); - if(local){ + if(HttpUtil0.isLocal(ssp.skin)){ File skinFile=new File(CustomSkinLoader.DATA_DIR,skin); if(skinFile.exists()&&skinFile.isFile()) profile.skinUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified())); @@ -30,9 +32,9 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { } profile.model=profile.hasSkinUrl()?ssp.model:null; } - if(ssp.cape!=null && !ssp.cape.equals("")){ + if(StringUtils.isNoneEmpty(ssp.cape)){ String cape=ssp.cape.replaceAll(USERNAME_REGEX, username); - if(local){ + if(HttpUtil0.isLocal(ssp.cape)){ File capeFile=new File(CustomSkinLoader.DATA_DIR,cape); if(capeFile.exists()&&capeFile.isFile()) profile.capeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified())); @@ -51,7 +53,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { @Override public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) { - return ssp0.skin.equalsIgnoreCase(ssp1.skin) || ssp0.cape.equalsIgnoreCase(ssp1.cape); + return (StringUtils.isNoneEmpty(ssp0.skin)?ssp0.skin.equalsIgnoreCase(ssp1.skin):true) || (StringUtils.isNoneEmpty(ssp0.cape)?ssp0.cape.equalsIgnoreCase(ssp1.cape):true); } @Override public String getName() { diff --git a/Common/customskinloader/loader/MojangAPILoader.java b/Common/customskinloader/loader/MojangAPILoader.java index ab0e827..836b096 100644 --- a/Common/customskinloader/loader/MojangAPILoader.java +++ b/Common/customskinloader/loader/MojangAPILoader.java @@ -6,6 +6,7 @@ import java.util.UUID; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringUtils; import com.google.common.collect.Iterables; import com.google.gson.Gson; @@ -30,9 +31,7 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { public static MinecraftSessionService defaultSessionService=null; @Override - public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile, boolean local) throws Exception { - if(local) - CustomSkinLoader.logger.warning("!!Local Skin couldn't load by MojangAPI.!!"); + public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { if(defaultSessionService==null){ CustomSkinLoader.logger.warning("Session Service Not Exist."); return null; @@ -74,11 +73,11 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { if (textureProperty==null) return new HashMap(); String value=textureProperty.getValue(); - if(value==null||value.equals("")) + if(StringUtils.isBlank(value)) return new HashMap(); String json=new String(Base64.decodeBase64(value),Charsets.UTF_8); Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create(); - MinecraftTexturesPayload result=(MinecraftTexturesPayload)gson.fromJson(json,MinecraftTexturesPayload.class); + MinecraftTexturesPayload result=gson.fromJson(json,MinecraftTexturesPayload.class); if (result==null||result.getTextures()==null) return new HashMap(); return result.getTextures(); diff --git a/Common/customskinloader/loader/ProfileLoader.java b/Common/customskinloader/loader/ProfileLoader.java index 51b91c8..5be30e9 100644 --- a/Common/customskinloader/loader/ProfileLoader.java +++ b/Common/customskinloader/loader/ProfileLoader.java @@ -25,7 +25,7 @@ public class ProfileLoader { } public interface IProfileLoader { - public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile,boolean local) throws Exception; + public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception; public boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1); public String getName(); } diff --git a/Common/customskinloader/profile/DynamicSkullManager.java b/Common/customskinloader/profile/DynamicSkullManager.java new file mode 100644 index 0000000..af8c4bf --- /dev/null +++ b/Common/customskinloader/profile/DynamicSkullManager.java @@ -0,0 +1,124 @@ +package customskinloader.profile; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.codec.Charsets; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; +import com.mojang.authlib.properties.Property; +import com.mojang.util.UUIDTypeAdapter; + +import customskinloader.CustomSkinLoader; +import customskinloader.utils.HttpTextureUtil; +import customskinloader.utils.HttpUtil0; + +public class DynamicSkullManager { + public static class SkullTexture{ + public Map textures; + public ArrayList skins; + public int interval; + public boolean fromZero; + //For program + public long startTime=0; + public int period=1; + } + private Map dynamicTextures=new HashMap(); + private Map> staticTextures=new HashMap>(); + private List loadingList=new ArrayList(); + + private void parseGameProfile(GameProfile profile){ + Property textureProperty=(Property)Iterables.getFirst(profile.getProperties().get("textures"), null); + if (textureProperty==null){ + staticTextures.put(profile, new HashMap()); + return; + } + String value=textureProperty.getValue(); + if(StringUtils.isBlank(value)){ + staticTextures.put(profile, new HashMap()); + return; + } + String json=new String(Base64.decodeBase64(value),Charsets.UTF_8); + Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create(); + SkullTexture result=gson.fromJson(json,SkullTexture.class); + if(result==null){ + staticTextures.put(profile, new HashMap()); + return; + } + staticTextures.put(profile, result.textures==null?new HashMap():result.textures); + if(!CustomSkinLoader.config.enableDynamicSkull||result.skins==null||result.skins.isEmpty()) + return; + + for(int i=0;i0){ + //Skin found + String fakeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified())); + result.skins.set(i, fakeUrl); + }else{ + //Could not find skin + result.skins.remove(i--); + continue; + } + }else{ + //Online Skin + if(!HttpUtil0.saveHttp(skin, HttpTextureUtil.getCacheFile(FilenameUtils.getBaseName(skin)))){ + //Could not load skin + result.skins.remove(i--); + continue; + } + } + } + + if(result.skins.isEmpty())//Nothing loaded + return; + result.interval=Math.min(result.interval, 50); + if(result.fromZero) + result.startTime=System.currentTimeMillis(); + result.period=result.interval*result.skins.size(); + dynamicTextures.put(profile, result); + staticTextures.remove(profile); + } + + public Map getTexture(final GameProfile profile){ + if(staticTextures.get(profile)!=null) + return staticTextures.get(profile); + if(loadingList.contains(profile)) + return new HashMap(); + if(dynamicTextures.containsKey(profile)){ + SkullTexture texture=dynamicTextures.get(profile); + long time=System.currentTimeMillis()-texture.startTime; + int index=(int)Math.floor((time%texture.period)/texture.skins.size()); + Map map=Maps.newHashMap(); + map.put(Type.SKIN, ModelManager0.getProfileTexture(texture.skins.get(index), null)); + return map; + } + + loadingList.add(profile); + Thread loadThread=new Thread(){ + public void run(){ + parseGameProfile(profile);//Load in thread + loadingList.remove(profile); + } + }; + loadThread.setName(profile.toString()+"'s dynamic skull"); + loadThread.start(); + return new HashMap(); + } +} diff --git a/Common/customskinloader/profile/ModelManager0.java b/Common/customskinloader/profile/ModelManager0.java index 3c69281..f1d2c67 100644 --- a/Common/customskinloader/profile/ModelManager0.java +++ b/Common/customskinloader/profile/ModelManager0.java @@ -63,13 +63,25 @@ public class ModelManager0 { metadata = Maps.newHashMap(); metadata.put("model", "slim"); } - map.put(Type.SKIN, new MinecraftProfileTexture(profile.skinUrl,metadata)); + map.put(Type.SKIN, getProfileTexture(profile.skinUrl,metadata)); } if(profile.capeUrl!=null) - map.put(Type.CAPE, new MinecraftProfileTexture(profile.capeUrl,null)); + map.put(Type.CAPE, getProfileTexture(profile.capeUrl,null)); return map; } + /** + * Parse url to MinecraftProfileTexture + * + * @param url - textureUrl + * metadata - metadata + * @return MinecraftProfileTexture + * @since 14.5 + */ + public static MinecraftProfileTexture getProfileTexture(String url,Map metadata){ + return new MinecraftProfileTexture(url,metadata); + } + private static void refreshModels(){ models=new ArrayList(); models.add("default"); diff --git a/Common/customskinloader/utils/HttpTextureUtil.java b/Common/customskinloader/utils/HttpTextureUtil.java index ed3b30b..7e58bcf 100644 --- a/Common/customskinloader/utils/HttpTextureUtil.java +++ b/Common/customskinloader/utils/HttpTextureUtil.java @@ -17,13 +17,13 @@ public class HttpTextureUtil { LEGACY_MARK="(LEGACY)", LOCAL_MARK="(LOCAL)", LOCAL_LEGACY_MARK="(LOCAL_LEGACY)"; - - public static HttpTextureInfo toHttpTextureInfo(File defaultCacheDir,String fakeUrl){ + public static File defaultCacheDir; + public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){ HttpTextureInfo info=new HttpTextureInfo(); if(fakeUrl.startsWith("http")){ info.url=fakeUrl; info.hash=FilenameUtils.getBaseName(fakeUrl); - info.cacheFile=getCacheFile(defaultCacheDir,info.hash); + info.cacheFile=getCacheFile(info.hash); return info; } if(fakeUrl.startsWith(LOCAL_LEGACY_MARK)){ @@ -48,7 +48,7 @@ public class HttpTextureUtil { return info; info.url=t[1]; info.hash=t[0]; - info.cacheFile=getCacheFile(defaultCacheDir,info.hash); + info.cacheFile=getCacheFile(info.hash); return info; } return info; @@ -66,8 +66,10 @@ public class HttpTextureUtil { public static String getHash(String url,long size,long lastModified){ return DigestUtils.sha1Hex(size+url+lastModified); } - - private static File getCacheFile(File cacheDir,String hash){ + public static File getCacheFile(String hash){ + return getCacheFile(defaultCacheDir,hash); + } + public static File getCacheFile(File cacheDir,String hash){ return new File(new File(cacheDir,hash.length()>2?hash.substring(0,2):"xx"), hash); } } diff --git a/Common/customskinloader/utils/HttpUtil0.java b/Common/customskinloader/utils/HttpUtil0.java index d8f4bee..e450d82 100644 --- a/Common/customskinloader/utils/HttpUtil0.java +++ b/Common/customskinloader/utils/HttpUtil0.java @@ -1,5 +1,6 @@ package customskinloader.utils; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; @@ -7,6 +8,7 @@ import java.net.MalformedURLException; import java.net.URL; import org.apache.commons.io.Charsets; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import customskinloader.CustomSkinLoader; @@ -38,6 +40,30 @@ public class HttpUtil0 { } } + public static boolean saveHttp(String url,File target){ + HttpURLConnection c=null; + try { + CustomSkinLoader.logger.info("Try to save '"+url+"' to '"+target.getAbsolutePath()+"'."); + c=createConnection(url,null); + int res = c.getResponseCode()/100; + if (res==4||res==5||c.getResponseCode()==HttpURLConnection.HTTP_NO_CONTENT) { + CustomSkinLoader.logger.info("Failed to save (Response Code: "+c.getResponseCode()+")"); + return false; + } + CustomSkinLoader.logger.info("Successfully save (Response Code: "+c.getResponseCode()+" , Content Length: "+c.getContentLength()+")"); + InputStream is = c.getInputStream(); + byte [] bytes = IOUtils.toByteArray(is); + FileUtils.writeByteArrayToFile(target,bytes); + return target.exists(); + } catch (Exception e) { + CustomSkinLoader.logger.info("Failed to save (Exception: "+e.toString()+")"); + return false; + } finally { + if(c!=null) + c.disconnect(); + } + } + /** * Get faked url after redirect. * Using this method, can also check if it is exist. @@ -80,4 +106,8 @@ public class HttpUtil0 { c.connect(); return c; } + + public static boolean isLocal(String url){ + return url==null? false : !url.startsWith("http"); + } } diff --git a/README.md b/README.md index b4eb188..c4252f4 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ You can easily to get a better view in skin. ###Skull Support Fixed skull load bug. +Dynamic skull supported. ###Profile Cache - Decrease frenquency of using network. @@ -39,10 +40,10 @@ You can load local skin by using any API(excluding MojangAPI). ###Extra List A json file generated by supported skin server. -To add server to load list, users just need to put file into `.minecraft/CustomSkinLoader/ExtraList` . +To add server to load list, users just need to put file into `.minecraft/CustomSkinLoader/ExtraList` . ###Transparent Skin Support -*Should be open in configratulation file. +The problem of rendering incorrect texture has been fixed. ##Default Load List - [Mojang](http://www.minecraft.net/) (Mojang API) diff --git a/build.properties b/build.properties index b96b913..0ed2574 100644 --- a/build.properties +++ b/build.properties @@ -2,5 +2,5 @@ name=CustomSkinLoader group=customskinloader version=14.4 dev_version= -#RELEASE: snapshot_version= -snapshot_version=20160829-1 \ No newline at end of file +#RELEASE: snapshot=0 +snapshot=1 \ No newline at end of file diff --git a/common.gradle b/common.gradle index 1f01b37..809224c 100644 --- a/common.gradle +++ b/common.gradle @@ -30,7 +30,7 @@ configFile.withReader { project.ext.config = new ConfigSlurper().parse prop } //Example: 14.4a-SNAPSHOT-20160820 -version = rootProject.ext.config.version + rootProject.ext.config.dev_version + (rootProject.ext.config.snapshot_version==''?'':('-SNAPSHOT-'+rootProject.ext.config.snapshot_version)) +version = rootProject.ext.config.version + rootProject.ext.config.dev_version + (rootProject.ext.config.snapshot==0?'':('-SNAPSHOT-'+System.getenv("BUILD_NUMBER"))) group = config.group archivesBaseName = rootProject.ext.config.name+"_"+config.minecraft_version @@ -100,16 +100,22 @@ build.finalizedBy afterBuild //notch pack void reobfSrgToNotch(){ def srgName = "${archivesBaseName}-${version}-srg.jar" - def mcpName = srgName.replace('-srg', '-dev') - applySpecialSource(srgName,mcpName,"srg-mcp") def notchName = srgName.replace('-srg', '') - applySpecialSource(mcpName,notchName,"mcp-notch") + if(config.srg_notch_map==null||config.srg_notch_map==""){ + //Default Map + def mcpName = srgName.replace('-srg', '-dev') + applySpecialSource(srgName,mcpName,getDefaultMap("srg-mcp")) + applySpecialSource(mcpName,notchName,getDefaultMap("mcp-notch")) + }else{ + //Custom Map + applySpecialSource(srgName,notchName,config.srg_notch_map) + } } -void applySpecialSource(String inputName,String outputName,String srgType){ +void applySpecialSource(String inputName,String outputName,String mapFile){ def mcpVersion = minecraft.mappings.replace('_',"/") def mapping = new net.md_5.specialsource.JarMapping() - def srgFile = file(System.getProperty('user.home') + "/.gradle/caches/minecraft/de/oceanlabs/mcp/mcp_${mcpVersion}/${config.forge_mc_version}/srgs/${srgType}.srg") + def srgFile = file() def inputFile = file("build/libs/${inputName}") def outputFile = file("build/libs/${outputName}") def remapper = new net.md_5.specialsource.JarRemapper(null, mapping) @@ -120,4 +126,7 @@ void applySpecialSource(String inputName,String outputName,String srgType){ mapping.loadMappings(srgFile) mapping.setFallbackInheritanceProvider(inheritanceProviders) remapper.remapJar(inputJar, outputFile) +} +String getDefaultMap(String srgType){ + return System.getProperty('user.home') + "/.gradle/caches/minecraft/de/oceanlabs/mcp/mcp_${mcpVersion}/${config.forge_mc_version}/srgs/${srgType}.srg" } \ No newline at end of file