Revision 14

Local skin supported
Local profile cache supported
Better profile cache
Swifter official profile loading
Better skull loading
Fix legacy loading bug
Fix bug while using ClassTransformer
This commit is contained in:
xfl03 committed 2016-07-31 22:00:46 +08:00
1 parent b34a5b3343
commit 5c12463c94
30 files changed
+766 -751

No files matched your search

@@ -1,22 +1,29 @@
package customskinloader.loader;
import java.io.File;
import java.io.FileInputStream;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.IOUtils;
import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import customskinloader.CustomSkinLoader;
import customskinloader.ModelManager0;
import customskinloader.UserProfile;
import customskinloader.config.SkinSiteProfile;
import customskinloader.profile.ModelManager0;
import customskinloader.profile.UserProfile;
import customskinloader.utils.HttpTextureUtil;
import customskinloader.utils.HttpUtil0;
public class CustomSkinAPILoader implements IProfileLoader {
public static final String TEXTURES="textures/";
@Override
public UserProfile loadProfile(SkinSiteProfile ssp, String username) throws Exception {
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
String username=gameProfile.getName();
if(ssp.root==null||ssp.root.equals("")){
CustomSkinLoader.logger.info("Root not denined.");
CustomSkinLoader.logger.info("Root not defined.");
return null;
}
String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent);
@@ -24,30 +31,7 @@ public class CustomSkinAPILoader implements IProfileLoader {
CustomSkinLoader.logger.info("Profile not found.");
return null;
}
CustomSkinAPI profile=new Gson().fromJson(json, CustomSkinAPI.class);
UserProfile p=new UserProfile();
if(profile.skins!=null && !profile.skins.isEmpty()){
Set<String> keys=profile.skins.keySet();
for(String s:keys){
//System.out.println(s+" "+ModelManager0.checkModel(s));
if(ModelManager0.checkModel(s)){
if(profile.skins.get(s)==null||profile.skins.get(s).equals(""))
continue;
p.skinUrl=ssp.root+TEXTURES+profile.skins.get(s);
p.model=s;
break;
}
}
if(p.skinUrl==null){
p.skinUrl=ssp.root+TEXTURES+profile.skins.get(keys.toArray()[0]);
p.model="default";
}
}else if(profile.skin!=null && !profile.skin.equals("")){
p.skinUrl=ssp.root+TEXTURES+profile.skin;
}
if(profile.cape!=null && !profile.cape.equals("")){
p.capeUrl=ssp.root+TEXTURES+profile.cape;
}
UserProfile p=toUserProfile(ssp.root,json,false);
if(p.isEmpty()){
CustomSkinLoader.logger.info("Both skin and cape not found.");
return null;
@@ -62,4 +46,62 @@ public class CustomSkinAPILoader implements IProfileLoader {
public String skin;
public String cape;
}
@Override
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
String username=gameProfile.getName();
if(ssp.root==null||ssp.root.equals("")){
CustomSkinLoader.logger.info("Root not defined.");
return null;
}
File jsonFile=new File(CustomSkinLoader.DATA_DIR,ssp.root+username+".json");
if(!jsonFile.exists()){
CustomSkinLoader.logger.info("Profile File not found.");
return null;
}
String json=IOUtils.toString(new FileInputStream(jsonFile));
if(json==null||json.equals("")){
CustomSkinLoader.logger.info("Profile not found.");
return null;
}
UserProfile p=toUserProfile(ssp.root,json,true);
if(p.isEmpty()){
CustomSkinLoader.logger.info("Both skin and cape not found.");
return null;
}else{
return p;
}
}
private UserProfile toUserProfile(String root,String json,boolean local){
CustomSkinAPI profile=CustomSkinLoader.GSON.fromJson(json, CustomSkinAPI.class);
UserProfile p=new UserProfile();
if(profile.skins!=null && !profile.skins.isEmpty()){
Set<String> keys=profile.skins.keySet();
for(String s:keys){
//System.out.println(s+" "+ModelManager0.checkModel(s));
if(ModelManager0.checkModel(s)){
if(profile.skins.get(s)==null||profile.skins.get(s).equals(""))
continue;
p.skinUrl=root+TEXTURES+profile.skins.get(s);
p.model=s;
break;
}
}
if(p.skinUrl==null){
p.skinUrl=root+TEXTURES+profile.skins.get(keys.toArray()[0]);
p.model="default";
}
}else if(profile.skin!=null && !profile.skin.equals("")){
p.skinUrl=root+TEXTURES+profile.skin;
if(local)
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
}
if(profile.cape!=null && !profile.cape.equals("")){
p.capeUrl=root+TEXTURES+profile.cape;
if(local)
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
}
return p;
}
}
@@ -1,8 +1,11 @@
package customskinloader.loader;
import customskinloader.UserProfile;
import com.mojang.authlib.GameProfile;
import customskinloader.config.SkinSiteProfile;
import customskinloader.profile.UserProfile;
public interface IProfileLoader {
public UserProfile loadProfile(SkinSiteProfile ssp,String username) throws Exception;
public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception;
public UserProfile loadLocalProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception;
}
@@ -1,24 +1,30 @@
package customskinloader.loader;
import java.io.File;
import com.mojang.authlib.GameProfile;
import customskinloader.CustomSkinLoader;
import customskinloader.UserProfile;
import customskinloader.config.SkinSiteProfile;
import customskinloader.profile.UserProfile;
import customskinloader.utils.HttpTextureUtil;
import customskinloader.utils.HttpUtil0;
public class LegacyLoader implements IProfileLoader {
public static final String USERNAME_REGEX="\\{USERNAME\\}";
@Override
public UserProfile loadProfile(SkinSiteProfile ssp, String username) 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("")){
String skin=HttpUtil0.getRealUrl(ssp.skin.replaceAll(USERNAME_REGEX, username),ssp.userAgent);
String skin=HttpUtil0.getFakeUrl(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),ssp.userAgent);
String cape=HttpUtil0.getFakeUrl(ssp.cape.replaceAll(USERNAME_REGEX, username),ssp.userAgent);
if(cape!=null&&!cape.equals("")){
profile.capeUrl=cape;
}
@@ -30,5 +36,35 @@ public class LegacyLoader implements IProfileLoader {
return profile;
}
}
@Override
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
String username=gameProfile.getName();
UserProfile profile=new UserProfile();
if(ssp.skin!=null && !ssp.skin.equals("")){
String skin=ssp.skin.replaceAll(USERNAME_REGEX, username);
if(skin!=null&&!skin.equals("")){
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()));
profile.model=(ssp.model==null?"default":ssp.model);
}
}
}
if(ssp.cape!=null && !ssp.cape.equals("")){
String cape=ssp.cape.replaceAll(USERNAME_REGEX, username);
if(cape!=null&&!cape.equals("")){
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()));
}
}
}
if(profile.isEmpty()){
CustomSkinLoader.logger.info("Both skin and cape not found.");
return null;
}else{
return profile;
}
}
}
@@ -1,78 +1,68 @@
package customskinloader.loader;
import java.util.Map;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import java.util.UUID;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
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.authlib.minecraft.MinecraftSessionService;
import com.mojang.util.UUIDTypeAdapter;
import customskinloader.CustomSkinLoader;
import customskinloader.ModelManager0;
import customskinloader.UserProfile;
import customskinloader.config.SkinSiteProfile;
import customskinloader.profile.ModelManager0;
import customskinloader.profile.UserProfile;
import customskinloader.utils.HttpUtil0;
import net.minecraft.client.Minecraft;
public class MojangAPILoader implements IProfileLoader {
public static MinecraftSessionService defaultSessionService=null;
@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,ssp.userAgent);
if(json0==null||json0.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s UUID not found.)");
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
if(defaultSessionService==null){
CustomSkinLoader.logger.warning("Session Service Not Exist.");
return null;
}
Gson gson=new Gson();
UUIDProfile uuidProfile=gson.fromJson(json0, UUIDProfile.class);
if(uuidProfile.id==null||uuidProfile.id.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s UUID is empty.)");
Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> map=defaultSessionService.getTextures(gameProfile, false);
if(!map.isEmpty()){
CustomSkinLoader.logger.info("Default profile will be used.");
return ModelManager0.toUserProfile(map);
}
String username=gameProfile.getName();
GameProfile newGameProfile=loadGameProfile(username);
if(newGameProfile==null){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s profile not found.)");
return null;
}
//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,ssp.userAgent);
if(json1==null||json1.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s Profile is empty.)");
return null;
defaultSessionService.fillProfileProperties(newGameProfile, false);
map=defaultSessionService.getTextures(newGameProfile, false);
if(!map.isEmpty()){
gameProfile.getProperties().putAll(newGameProfile.getProperties());
return ModelManager0.toUserProfile(map);
}
UserProfile0 profile= gson.fromJson(json1, UserProfile0.class);
//Get Profile End
//Get Texture Begin
Property p=profile.properties.length>=1?profile.properties[0]:null;
if(p==null){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s Profile doesn't have property for texture.)");
CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)");
return null;
}
public static GameProfile loadGameProfile(String username) throws JsonSyntaxException{
//Doc (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time)
String json0=HttpUtil0.readHttp("https://api.mojang.com/users/profiles/minecraft/"+username,null);
if(json0==null||json0.equals(""))
return null;
}
String texture=p.getValue();
if(texture==null||texture.equals("")){
CustomSkinLoader.logger.info("Profile not found.("+username+"'s texture not found.)");
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
GameProfile gameProfile=gson.fromJson(json0, GameProfile.class);
if(gameProfile.getId()==null)
return null;
}
String json2=new String(Base64.decodeBase64(texture));
UserTexture texture1=gson.fromJson(json2, UserTexture.class);
if(texture1.textures==null||texture1.textures.isEmpty()){
CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)");
return null;
}
//Get Texture End
return ModelManager0.toUserProfile(texture1.textures);
return new GameProfile(gameProfile.getId(),gameProfile.getName());
}
private class UUIDProfile{
public String id;
public String name;
}
private class UserProfile0{
public String id;
public String name;
public Property[] properties;
}
private class UserTexture{
public Map<Type,MinecraftProfileTexture> textures;
@Override
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
CustomSkinLoader.logger.warning("Local Skin couldn't load by MojangAPI.");
return loadProfile(ssp,gameProfile);
}
}
@@ -1,22 +1,29 @@
package customskinloader.loader;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import customskinloader.CustomSkinLoader;
import customskinloader.ModelManager0;
import customskinloader.UserProfile;
import customskinloader.config.SkinSiteProfile;
import customskinloader.profile.ModelManager0;
import customskinloader.profile.UserProfile;
import customskinloader.utils.HttpTextureUtil;
import customskinloader.utils.HttpUtil0;
public class UniSkinAPILoader implements IProfileLoader {
public static final String TEXTURES="textures/";
@Override
public UserProfile loadProfile(SkinSiteProfile ssp, String username) throws Exception {
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
String username=gameProfile.getName();
if(ssp.root==null||ssp.root.equals("")){
CustomSkinLoader.logger.info("Root not denined.");
CustomSkinLoader.logger.info("Root not defined.");
return null;
}
String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent);
@@ -24,38 +31,8 @@ public class UniSkinAPILoader implements IProfileLoader {
CustomSkinLoader.logger.info("Profile not found.");
return null;
}
UniSkinAPI profile=new Gson().fromJson(json, UniSkinAPI.class);
if(profile.errno!=0){
CustomSkinLoader.logger.info("Error: "+profile.msg);
return null;
}
UserProfile p=new UserProfile();
if(profile.skins!=null && !profile.skins.isEmpty()){
if(profile.model_preference!=null && !profile.model_preference.isEmpty()){
for(String s:profile.model_preference){
if(ModelManager0.checkModel(s)){
if(profile.skins.get(s)==null||profile.skins.get(s).equals(""))
continue;
p.skinUrl=ssp.root+TEXTURES+profile.skins.get(s);
p.model=s;
break;
}
}
}
if(p.skinUrl==null){
String s=profile.skins.get("default");
if(s!=null){
p.skinUrl=ssp.root+TEXTURES+s;
p.model="default";
}
}
}
if(profile.skins.get("cape")!=null && !profile.skins.get("cape").equals("")){
p.capeUrl=ssp.root+TEXTURES+profile.skins.get("cape");
}else if(profile.cape!=null && !profile.cape.equals("")){
p.capeUrl=ssp.root+TEXTURES+profile.cape;
}
if(p.isEmpty()){
UserProfile p=toUserProfile(ssp.root,json,false);
if(p==null||p.isEmpty()){
CustomSkinLoader.logger.info("Both skin and cape not found.");
return null;
}else{
@@ -77,4 +54,72 @@ public class UniSkinAPILoader implements IProfileLoader {
public int errno;
public String msg;
}
@Override
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
String username=gameProfile.getName();
if(ssp.root==null||ssp.root.equals("")){
CustomSkinLoader.logger.info("Root not defined.");
return null;
}
File jsonFile=new File(CustomSkinLoader.DATA_DIR,ssp.root+username+".json");
if(!jsonFile.exists()){
CustomSkinLoader.logger.info("Profile File not found.");
return null;
}
String json=IOUtils.toString(new FileInputStream(jsonFile));
if(json==null||json.equals("")){
CustomSkinLoader.logger.info("Profile not found.");
return null;
}
UserProfile p=toUserProfile(ssp.root,json,true);
if(p==null||p.isEmpty()){
CustomSkinLoader.logger.info("Both skin and cape not found.");
return null;
}else{
return p;
}
}
private UserProfile toUserProfile(String root,String json,boolean local){
UniSkinAPI profile=CustomSkinLoader.GSON.fromJson(json, UniSkinAPI.class);
if(profile.errno!=0){
CustomSkinLoader.logger.info("Error: "+profile.msg);
return null;
}
UserProfile p=new UserProfile();
if(profile.skins!=null && !profile.skins.isEmpty()){
if(profile.model_preference!=null && !profile.model_preference.isEmpty()){
for(String s:profile.model_preference){
if(ModelManager0.checkModel(s)){
if(profile.skins.get(s)==null||profile.skins.get(s).equals(""))
continue;
p.skinUrl=root+TEXTURES+profile.skins.get(s);
if(local)
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
p.model=s;
break;
}
}
}
if(p.skinUrl==null){
String s=profile.skins.get("default");
if(s!=null){
p.skinUrl=root+TEXTURES+s;
if(local)
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
p.model="default";
}
}
}
if(profile.skins.get("cape")!=null && !profile.skins.get("cape").equals("")){
p.capeUrl=root+TEXTURES+profile.skins.get("cape");
if(local)
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
}else if(profile.cape!=null && !profile.cape.equals("")){
p.capeUrl=root+TEXTURES+profile.cape;
if(local)
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
}
return p;
}
}