diff --git a/Common/customskinloader/CustomSkinLoader.java b/Common/customskinloader/CustomSkinLoader.java index 08ef39a..fbc9fb1 100644 --- a/Common/customskinloader/CustomSkinLoader.java +++ b/Common/customskinloader/CustomSkinLoader.java @@ -28,16 +28,17 @@ import customskinloader.utils.MinecraftUtil; /** * Custom skin loader mod for Minecraft. * @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016 - * @version 13.10 (2016.6.25) + * @version 13.11 (2016.7.3) */ public class CustomSkinLoader { - public static final String CustomSkinLoader_VERSION="13.10"; + public static final String CustomSkinLoader_VERSION="13.11"; public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir0(),"CustomSkinLoader"), LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json"); public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={ new SkinSiteProfile("Mojang","MojangAPI"), new SkinSiteProfile("BlessingSkin","CustomSkinAPI","https://skin.prinzeugen.net/csl/"), + new SkinSiteProfile("OneSkin","CustomSkinAPI","http://fleey.org/skin/skin_user/skin_json.php/"), //Minecrack could not load skin correctly //new SkinSiteProfile("Minecrack","Legacy","http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png","http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"), new SkinSiteProfile("SkinMe","UniSkinAPI","http://www.skinme.cc/uniskin/"), @@ -168,6 +169,10 @@ public class CustomSkinLoader { return config; }catch (Exception e) { logger.info("Failed to load config, use default instead.("+e.getMessage()+")"); + File brokenFile=new File(DATA_DIR,"BROKEN-CustomSkinLoader.json"); + if(brokenFile.exists()) + brokenFile.delete(); + CONFIG_FILE.renameTo(brokenFile); return initConfig(); } } diff --git a/Common/customskinloader/config/SkinSiteProfile.java b/Common/customskinloader/config/SkinSiteProfile.java index eeb85c2..9eed20a 100644 --- a/Common/customskinloader/config/SkinSiteProfile.java +++ b/Common/customskinloader/config/SkinSiteProfile.java @@ -7,6 +7,7 @@ public class SkinSiteProfile { public String skin; public String cape; public String model; + public String userAgent; //For MojangAPI public SkinSiteProfile(String name,String type){ diff --git a/Common/customskinloader/loader/CustomSkinAPILoader.java b/Common/customskinloader/loader/CustomSkinAPILoader.java index f1a07c2..4243220 100644 --- a/Common/customskinloader/loader/CustomSkinAPILoader.java +++ b/Common/customskinloader/loader/CustomSkinAPILoader.java @@ -19,7 +19,7 @@ public class CustomSkinAPILoader implements IProfileLoader { CustomSkinLoader.logger.info("Root not denined."); return null; } - String json=HttpUtil0.readHttp(ssp.root+username+".json"); + String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent); if(json==null||json.equals("")){ CustomSkinLoader.logger.info("Profile not found."); return null; diff --git a/Common/customskinloader/loader/LegacyLoader.java b/Common/customskinloader/loader/LegacyLoader.java index ea5ebe3..033c4d8 100644 --- a/Common/customskinloader/loader/LegacyLoader.java +++ b/Common/customskinloader/loader/LegacyLoader.java @@ -11,14 +11,14 @@ public class LegacyLoader implements IProfileLoader { public UserProfile loadProfile(SkinSiteProfile ssp, String username) throws Exception { UserProfile profile=new UserProfile(); if(ssp.skin!=null && !ssp.skin.equals("")){ - String skin=HttpUtil0.getRealUrl(ssp.skin.replaceAll(USERNAME_REGEX, username)); + String skin=HttpUtil0.getRealUrl(ssp.skin.replaceAll(USERNAME_REGEX, username),ssp.userAgent); if(skin!=null&&!skin.equals("")){ profile.skinUrl=skin; profile.model=(ssp.model==null?"default":ssp.model); } } if(ssp.cape!=null && !ssp.cape.equals("")){ - String cape=HttpUtil0.getRealUrl(ssp.cape.replaceAll(USERNAME_REGEX, username)); + String cape=HttpUtil0.getRealUrl(ssp.cape.replaceAll(USERNAME_REGEX, username),ssp.userAgent); if(cape!=null&&!cape.equals("")){ profile.capeUrl=cape; } diff --git a/Common/customskinloader/loader/MojangAPILoader.java b/Common/customskinloader/loader/MojangAPILoader.java index ccaffd1..b03b974 100644 --- a/Common/customskinloader/loader/MojangAPILoader.java +++ b/Common/customskinloader/loader/MojangAPILoader.java @@ -21,7 +21,7 @@ public class MojangAPILoader implements IProfileLoader { @Override public UserProfile loadProfile(SkinSiteProfile ssp, String username) throws Exception { //Get UUID Begin (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time) - String json0=HttpUtil0.readHttp("https://api.mojang.com/users/profiles/minecraft/"+username); + String json0=HttpUtil0.readHttp("https://api.mojang.com/users/profiles/minecraft/"+username,ssp.userAgent); if(json0==null||json0.equals("")){ CustomSkinLoader.logger.info("Profile not found.("+username+"'s UUID not found.)"); return null; @@ -34,7 +34,7 @@ public class MojangAPILoader implements IProfileLoader { } //Get UUID End //Get Profile Begin (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape) - String json1=HttpUtil0.readHttp("https://sessionserver.mojang.com/session/minecraft/profile/"+uuidProfile.id); + String json1=HttpUtil0.readHttp("https://sessionserver.mojang.com/session/minecraft/profile/"+uuidProfile.id,ssp.userAgent); if(json1==null||json1.equals("")){ CustomSkinLoader.logger.info("Profile not found.("+username+"'s Profile is empty.)"); return null; diff --git a/Common/customskinloader/loader/UniSkinAPILoader.java b/Common/customskinloader/loader/UniSkinAPILoader.java index 934e90a..d038e1c 100644 --- a/Common/customskinloader/loader/UniSkinAPILoader.java +++ b/Common/customskinloader/loader/UniSkinAPILoader.java @@ -19,7 +19,7 @@ public class UniSkinAPILoader implements IProfileLoader { CustomSkinLoader.logger.info("Root not denined."); return null; } - String json=HttpUtil0.readHttp(ssp.root+username+".json"); + String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent); if(json==null||json.equals("")){ CustomSkinLoader.logger.info("Profile not found."); return null; diff --git a/Common/customskinloader/tweaker/ClassTransformer.java b/Common/customskinloader/tweaker/ClassTransformer.java index f5d3de3..3f0fdeb 100644 --- a/Common/customskinloader/tweaker/ClassTransformer.java +++ b/Common/customskinloader/tweaker/ClassTransformer.java @@ -1,7 +1,12 @@ package customskinloader.tweaker; -import java.io.*; -import java.net.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -12,6 +17,7 @@ import net.minecraft.launchwrapper.IClassTransformer; public class ClassTransformer implements IClassTransformer { private ZipFile zipFile = null; + private ArrayList classes=new ArrayList(); public ClassTransformer() { ForgeTweaker.logger.info("ClassTransformer Begin"); @@ -26,7 +32,19 @@ public class ClassTransformer implements IClassTransformer { continue; } zipFile = tempZipFile; + Enumeration entries=(Enumeration) zipFile.entries(); + StringBuilder sb=new StringBuilder(); + while(entries.hasMoreElements()){ + ZipEntry entry=entries.nextElement(); + String name=entry.getName(); + if(name.endsWith(".class")&&!name.contains("/")){ + classes.add(name); + sb.append(" "); + sb.append(name); + } + } ForgeTweaker.logger.info("Jar File URL: " + url); + ForgeTweaker.logger.info("Classes:" + sb.toString()); break; } } catch (Exception e) { @@ -53,7 +71,10 @@ public class ClassTransformer implements IClassTransformer { public byte[] transform(String name, String transformedName, byte bytes[]) { if (zipFile == null) return bytes; + String fullName = name + ".class"; + if(!classes.contains(fullName)) + return bytes; ZipEntry ze = zipFile.getEntry(fullName); if (ze == null) return bytes; @@ -67,8 +88,6 @@ public class ClassTransformer implements IClassTransformer { } private byte[] getClass(ZipEntry ze) { - if (ze == null) - return null; try { InputStream is = zipFile.getInputStream(ze); byte[] bytes = IOUtils.toByteArray(is); diff --git a/Common/customskinloader/utils/HttpUtil0.java b/Common/customskinloader/utils/HttpUtil0.java index 952ea49..32f6154 100644 --- a/Common/customskinloader/utils/HttpUtil0.java +++ b/Common/customskinloader/utils/HttpUtil0.java @@ -14,11 +14,13 @@ import customskinloader.CustomSkinLoader; public class HttpUtil0 { /** * Read all text from http. + * @since 13.11 */ - public static String readHttp(String url){ + public static String readHttp(String url,String userAgent){ + HttpURLConnection c=null; try { - CustomSkinLoader.logger.info("Try to read '"+url+"'"); - HttpURLConnection c=createConnection(url); + CustomSkinLoader.logger.info("Try to read '"+url+"' with user agent '"+userAgent+"'."); + c=createConnection(url,userAgent); int res = c.getResponseCode()/100; if (res==4||res==5||c.getResponseCode()==HttpURLConnection.HTTP_NO_CONTENT) { CustomSkinLoader.logger.info("Failed to read (Response Code: "+c.getResponseCode()+")"); @@ -30,6 +32,9 @@ public class HttpUtil0 { } catch (Exception e) { CustomSkinLoader.logger.info("Failed to read (Exception: "+e.getMessage()+")"); return null; + } finally { + if(c!=null) + c.disconnect(); } } @@ -38,11 +43,13 @@ public class HttpUtil0 { * Using this method, can also check if it is exist. * @param url - before redirect * @return url - after redirect (null for not exist) + * @since 13.11 */ - public static String getRealUrl(String url){ + public static String getRealUrl(String url,String userAgent){ + HttpURLConnection c=null; try { - CustomSkinLoader.logger.info("Try to get real url of '"+url+"'."); - HttpURLConnection c=createConnection(url); + CustomSkinLoader.logger.info("Try to get real url of '"+url+"' with user agent '"+userAgent+"'."); + c=createConnection(url,userAgent); int res = c.getResponseCode()/100; if (res==4||res==5) { CustomSkinLoader.logger.info("Failed to get real url (Response Code: "+c.getResponseCode()+")"); @@ -56,13 +63,17 @@ public class HttpUtil0 { } catch (Exception e) { CustomSkinLoader.logger.info("Failed to get real url (Exception: "+e.getMessage()+")"); return null; + } finally{ + if(c!=null) + c.disconnect(); } } - - private static HttpURLConnection createConnection(String url) throws MalformedURLException, IOException{ + private static HttpURLConnection createConnection(String url,String userAgent) throws MalformedURLException, IOException{ HttpURLConnection c = (HttpURLConnection) (new URL(url)).openConnection(); c.setReadTimeout(1000 * 10); c.setConnectTimeout(1000 * 10); + if(userAgent!=null) + c.setRequestProperty("User-Agent",userAgent); c.setUseCaches(false); c.setInstanceFollowRedirects(true); c.connect(); diff --git a/README.md b/README.md index bee4ee7..0932188 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Fixed skull load bug. ##Default Load List - [Mojang](http://www.minecraft.net/) (Mojang API) - [Blessing Skin](https://skin.prinzeugen.net/) (CustomSkinAPI) +- [OneSkin] (http://fleey.org/skin/) (CustomSkinAPI) - SkinMe (UniSkinAPI) - [McSkin](https://www.mcskin.cc/) (CustomSkinAPI) If you want to apply to add other skin website to default list, please go to [issue](https://github.com/JLChnToZ/MCCustomSkinLoader/issues).