mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-11 20:47:31 +00:00
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:
1 parent
b34a5b3343
commit
5c12463c94
30 files changed
+766
-751
No files matched your search
@@ -45,6 +45,9 @@ public class SkinManager
|
||||
return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false);
|
||||
}
|
||||
});
|
||||
//CustomSkinLoader Begin (Init Session Service)
|
||||
customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService;
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +63,10 @@ public class SkinManager
|
||||
*/
|
||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
||||
{
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + profileTexture.getHash());
|
||||
//CustomSkinLoader Begin (Parse HttpTextureInfo)
|
||||
customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(this.skinCacheDir, profileTexture.getUrl());
|
||||
//CustomSkinLoader End
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);//Modified
|
||||
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
||||
|
||||
if (itextureobject != null)
|
||||
@@ -72,10 +78,8 @@ public class SkinManager
|
||||
}
|
||||
else
|
||||
{
|
||||
File file1 = new File(this.skinCacheDir, profileTexture.getHash().length() > 2 ? profileTexture.getHash().substring(0, 2) : "xx");
|
||||
File file2 = new File(file1, profileTexture.getHash());
|
||||
final IImageBuffer iimagebuffer = textureType == Type.SKIN ? new ImageBufferDownload() : null;
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(file2, profileTexture.getUrl(), DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()//Modified
|
||||
{
|
||||
public BufferedImage parseUserSkin(BufferedImage image)
|
||||
{
|
||||
@@ -112,31 +116,14 @@ public class SkinManager
|
||||
public void run()
|
||||
{
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||
|
||||
try
|
||||
{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}
|
||||
catch (InsecureTextureException var3)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
if (map.isEmpty() && profile.getId().equals(Minecraft.getMinecraft().getSession().getProfile().getId()))
|
||||
{
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().putAll(Minecraft.getMinecraft().getProfileProperties());
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, false));
|
||||
}*/
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map);
|
||||
if(!newMap.isEmpty()){
|
||||
map.clear();
|
||||
map.putAll(newMap);
|
||||
}
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
}else{
|
||||
try{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}catch(InsecureTextureException var3){}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
@@ -163,8 +150,10 @@ 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.getName(),this.skinCacheLoader.getUnchecked(profile)):
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(profile):
|
||||
this.skinCacheLoader.getUnchecked(profile);
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package customskinloader;
|
||||
package customskinloader.profile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -53,6 +53,9 @@ public class SkinManager
|
||||
return this.func_152786_a((GameProfile)p_load_1_);
|
||||
}
|
||||
});
|
||||
//CustomSkinLoader Begin (Init Session Service)
|
||||
customskinloader.loader.MojangAPILoader.defaultSessionService=p_i1044_3_;
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
public ResourceLocation func_152792_a(MinecraftProfileTexture p_152792_1_, Type p_152792_2_)
|
||||
@@ -62,7 +65,10 @@ public class SkinManager
|
||||
|
||||
public ResourceLocation func_152789_a(MinecraftProfileTexture p_152789_1_, final Type p_152789_2_, final SkinManager.SkinAvailableCallback p_152789_3_)
|
||||
{
|
||||
final ResourceLocation var4 = new ResourceLocation("skins/" + p_152789_1_.getHash());
|
||||
//CustomSkinLoader Begin (Parse HttpTextureInfo)
|
||||
customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(this.field_152796_d, p_152789_1_.getUrl());
|
||||
//CustomSkinLoader End
|
||||
final ResourceLocation var4 = new ResourceLocation("skins/" + info.hash);//Modified
|
||||
ITextureObject var5 = this.field_152795_c.getTexture(var4);
|
||||
if (var5 != null)
|
||||
{
|
||||
@@ -73,10 +79,8 @@ public class SkinManager
|
||||
}
|
||||
else
|
||||
{
|
||||
File var6 = new File(this.field_152796_d, p_152789_1_.getHash().substring(0, 2));
|
||||
File var7 = new File(var6, p_152789_1_.getHash());
|
||||
final ImageBufferDownload var8 = p_152789_2_ == Type.SKIN ? new ImageBufferDownload() : null;
|
||||
ThreadDownloadImageData var9 = new ThreadDownloadImageData(var7, p_152789_1_.getUrl(), field_152793_a, new IImageBuffer()
|
||||
ThreadDownloadImageData var9 = new ThreadDownloadImageData(info.cacheFile, info.url, field_152793_a, new IImageBuffer()//Modified
|
||||
{
|
||||
private static final String __OBFID = "CL_00001828";
|
||||
public BufferedImage parseUserSkin(BufferedImage p_78432_1_)
|
||||
@@ -116,32 +120,13 @@ public class SkinManager
|
||||
{
|
||||
final HashMap var1 = Maps.newHashMap();
|
||||
|
||||
try
|
||||
{
|
||||
var1.putAll(SkinManager.this.field_152797_e.getTextures(p_152790_1_, p_152790_3_));
|
||||
}
|
||||
catch (InsecureTextureException var3)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
* If keep this, code below will not be executed.
|
||||
* p_152790_1_.getId() may be null, so NullPointerException may be thrown.
|
||||
* Minecraft.getMinecraft().getSession().func_148256_e().getId() also may be null, which makes it meaningless.
|
||||
if (var1.isEmpty() && p_152790_1_.getId().equals(Minecraft.getMinecraft().getSession().func_148256_e().getId()))
|
||||
{
|
||||
System.out.println("RUN3");
|
||||
var1.putAll(SkinManager.this.field_152797_e.getTextures(SkinManager.this.field_152797_e.fillProfileProperties(p_152790_1_, false), false));
|
||||
}*/
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(p_152790_1_.getName(), var1);
|
||||
if(!newMap.isEmpty()){
|
||||
var1.clear();
|
||||
var1.putAll(newMap);
|
||||
}
|
||||
var1.putAll(customskinloader.CustomSkinLoader.loadProfile(p_152790_1_));
|
||||
}else{
|
||||
try{
|
||||
var1.putAll(SkinManager.this.field_152797_e.getTextures(p_152790_1_, p_152790_3_));
|
||||
}catch(InsecureTextureException var3){}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
@@ -167,12 +152,14 @@ public class SkinManager
|
||||
|
||||
public Map func_152788_a(GameProfile p_152788_1_)
|
||||
{
|
||||
//CustomSkinLoader Begin (Skull Part)
|
||||
//return (Map)this.field_152798_f.getUnchecked(p_152788_1_);
|
||||
return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)?
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(p_152788_1_.getName(),(Map)this.field_152798_f.getUnchecked(p_152788_1_)):
|
||||
(Map)this.field_152798_f.getUnchecked(p_152788_1_);
|
||||
//CustomSkinLoader End
|
||||
//CustomSkinLoader Begin (Skull Part)
|
||||
//return (Map)this.skinCacheLoader.getUnchecked(profile);
|
||||
if(p_152788_1_.getName()==null)
|
||||
return (Map)this.field_152798_f.getUnchecked(p_152788_1_);
|
||||
return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)?
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(p_152788_1_):
|
||||
(Map)this.field_152798_f.getUnchecked(p_152788_1_);
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
public interface SkinAvailableCallback
|
||||
|
||||
@@ -51,6 +51,9 @@ public class SkinManager
|
||||
return this.func_152786_a((GameProfile)p_load_1_);
|
||||
}
|
||||
});
|
||||
//CustomSkinLoader Begin (Init Session Service)
|
||||
customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService;
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +69,10 @@ public class SkinManager
|
||||
*/
|
||||
public ResourceLocation loadSkin(final MinecraftProfileTexture p_152789_1_, final Type p_152789_2_, final SkinManager.SkinAvailableCallback p_152789_3_)
|
||||
{
|
||||
final ResourceLocation var4 = new ResourceLocation("skins/" + p_152789_1_.getHash());
|
||||
//CustomSkinLoader Begin (Parse HttpTextureInfo)
|
||||
customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(this.skinCacheDir, p_152789_1_.getUrl());
|
||||
//CustomSkinLoader End
|
||||
final ResourceLocation var4 = new ResourceLocation("skins/" + info.hash);//Modified
|
||||
ITextureObject var5 = this.textureManager.getTexture(var4);
|
||||
|
||||
if (var5 != null)
|
||||
@@ -78,10 +84,8 @@ public class SkinManager
|
||||
}
|
||||
else
|
||||
{
|
||||
File var6 = new File(this.skinCacheDir, p_152789_1_.getHash().substring(0, 2));
|
||||
File var7 = new File(var6, p_152789_1_.getHash());
|
||||
final ImageBufferDownload var8 = p_152789_2_ == Type.SKIN ? new ImageBufferDownload() : null;
|
||||
ThreadDownloadImageData var9 = new ThreadDownloadImageData(var7, p_152789_1_.getUrl(), DefaultPlayerSkin.func_177335_a(), new IImageBuffer()
|
||||
ThreadDownloadImageData var9 = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.func_177335_a(), new IImageBuffer()//Modified
|
||||
{
|
||||
private static final String __OBFID = "CL_00001828";
|
||||
public BufferedImage parseUserSkin(BufferedImage p_78432_1_)
|
||||
@@ -120,29 +124,14 @@ public class SkinManager
|
||||
public void run()
|
||||
{
|
||||
final HashMap var1 = Maps.newHashMap();
|
||||
|
||||
try
|
||||
{
|
||||
var1.putAll(SkinManager.this.sessionService.getTextures(p_152790_1_, p_152790_3_));
|
||||
}
|
||||
catch (InsecureTextureException var3)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/* May cause NullPointerException
|
||||
if (var1.isEmpty() && p_152790_1_.getId().equals(Minecraft.getMinecraft().getSession().getProfile().getId()))
|
||||
{
|
||||
var1.putAll(SkinManager.this.sessionService.getTextures(SkinManager.this.sessionService.fillProfileProperties(p_152790_1_, false), false));
|
||||
}*/
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(p_152790_1_.getName(), var1);
|
||||
if(!newMap.isEmpty()){
|
||||
var1.clear();
|
||||
var1.putAll(newMap);
|
||||
}
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
var1.putAll(customskinloader.CustomSkinLoader.loadProfile(p_152790_1_));
|
||||
}else{
|
||||
try{
|
||||
var1.putAll(SkinManager.this.sessionService.getTextures(p_152790_1_, p_152790_3_));
|
||||
}catch(InsecureTextureException var3){}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
@@ -168,12 +157,14 @@ public class SkinManager
|
||||
|
||||
public Map loadSkinFromCache(GameProfile p_152788_1_)
|
||||
{
|
||||
//CustomSkinLoader Begin (Skull Part)
|
||||
//return (Map)this.skinCacheLoader.getUnchecked(p_152788_1_);
|
||||
return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)?
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(p_152788_1_.getName(),(Map)this.skinCacheLoader.getUnchecked(p_152788_1_)):
|
||||
(Map)this.skinCacheLoader.getUnchecked(p_152788_1_);
|
||||
//CustomSkinLoader End
|
||||
//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 (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)?
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(p_152788_1_):
|
||||
(Map)this.skinCacheLoader.getUnchecked(p_152788_1_);
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
public interface SkinAvailableCallback
|
||||
|
||||
@@ -44,6 +44,9 @@ public class SkinManager
|
||||
return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false);
|
||||
}
|
||||
});
|
||||
//CustomSkinLoader Begin (Init Session Service)
|
||||
customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService;
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +62,10 @@ public class SkinManager
|
||||
*/
|
||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type p_152789_2_, final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
||||
{
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + profileTexture.getHash());
|
||||
//CustomSkinLoader Begin (Parse HttpTextureInfo)
|
||||
customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(this.skinCacheDir, profileTexture.getUrl());
|
||||
//CustomSkinLoader End
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);//Modified
|
||||
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
||||
|
||||
if (itextureobject != null)
|
||||
@@ -71,10 +77,8 @@ public class SkinManager
|
||||
}
|
||||
else
|
||||
{
|
||||
File file1 = new File(this.skinCacheDir, profileTexture.getHash().length() > 2 ? profileTexture.getHash().substring(0, 2) : "xx");
|
||||
File file2 = new File(file1, profileTexture.getHash());
|
||||
final IImageBuffer iimagebuffer = p_152789_2_ == Type.SKIN ? new ImageBufferDownload() : null;
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(file2, profileTexture.getUrl(), DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()//Modified
|
||||
{
|
||||
public BufferedImage parseUserSkin(BufferedImage image)
|
||||
{
|
||||
@@ -111,31 +115,14 @@ public class SkinManager
|
||||
public void run()
|
||||
{
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||
|
||||
try
|
||||
{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}
|
||||
catch (InsecureTextureException var3)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/* Avoid NullPointer
|
||||
if (map.isEmpty() && profile.getId().equals(Minecraft.getMinecraft().getSession().getProfile().getId()))
|
||||
{
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().putAll(Minecraft.getMinecraft().func_181037_M());
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, false));
|
||||
}*/
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map);
|
||||
if(!newMap.isEmpty()){
|
||||
map.clear();
|
||||
map.putAll(newMap);
|
||||
}
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
}else{
|
||||
try{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}catch(InsecureTextureException var3){}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
@@ -161,11 +148,13 @@ public class SkinManager
|
||||
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile)
|
||||
{
|
||||
//CustomSkinLoader Begin (Skull Part)
|
||||
//return (Map)this.skinCacheLoader.getUnchecked(profile);
|
||||
return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)?
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(profile.getName(),this.skinCacheLoader.getUnchecked(profile)):
|
||||
this.skinCacheLoader.getUnchecked(profile);
|
||||
//CustomSkinLoader End
|
||||
//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);
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
public interface SkinAvailableCallback
|
||||
|
||||
@@ -45,6 +45,9 @@ public class SkinManager
|
||||
return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false);
|
||||
}
|
||||
});
|
||||
//CustomSkinLoader Begin (Init Session Service)
|
||||
customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService;
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +63,10 @@ public class SkinManager
|
||||
*/
|
||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
||||
{
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + profileTexture.getHash());
|
||||
//CustomSkinLoader Begin (Parse HttpTextureInfo)
|
||||
customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(this.skinCacheDir, profileTexture.getUrl());
|
||||
//CustomSkinLoader End
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);//Modified
|
||||
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
||||
|
||||
if (itextureobject != null)
|
||||
@@ -72,10 +78,8 @@ public class SkinManager
|
||||
}
|
||||
else
|
||||
{
|
||||
File file1 = new File(this.skinCacheDir, profileTexture.getHash().length() > 2 ? profileTexture.getHash().substring(0, 2) : "xx");
|
||||
File file2 = new File(file1, profileTexture.getHash());
|
||||
final IImageBuffer iimagebuffer = textureType == Type.SKIN ? new ImageBufferDownload() : null;
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(file2, profileTexture.getUrl(), DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()//Modified
|
||||
{
|
||||
public BufferedImage parseUserSkin(BufferedImage image)
|
||||
{
|
||||
@@ -112,33 +116,17 @@ public class SkinManager
|
||||
public void run()
|
||||
{
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||
|
||||
try
|
||||
{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}
|
||||
catch (InsecureTextureException var3)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
if (map.isEmpty() && profile.getId().equals(Minecraft.getMinecraft().getSession().getProfile().getId()))
|
||||
{
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().putAll(Minecraft.getMinecraft().getProfileProperties());
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, false));
|
||||
}*/
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map);
|
||||
if(!newMap.isEmpty()){
|
||||
map.clear();
|
||||
map.putAll(newMap);
|
||||
}
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
}else{
|
||||
try{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}catch(InsecureTextureException var3){}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
Minecraft.getMinecraft().addScheduledTask(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@@ -162,8 +150,10 @@ 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.getName(),this.skinCacheLoader.getUnchecked(profile)):
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(profile):
|
||||
this.skinCacheLoader.getUnchecked(profile);
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
@echo off
|
||||
SET MC_VERSION=1.9.2
|
||||
SET CSL_VERSION=13.7a
|
||||
title CustomSkinLoader_%MC_VERSION%-%CSL_VERSION%
|
||||
echo !!!CustomSkinLoader for %MC_VERSION% will not be updated.!!!
|
||||
cd src
|
||||
javac -source 1.6 -target 1.6 -d ../bin -cp ;../lib/commons-codec-1.9.jar;../lib/commons-io-2.4.jar;../lib/gson-2.2.4.jar;../lib/guava-17.0.jar;../lib/authlib-1.5.22.jar;../%MC_VERSION%.jar *.java
|
||||
javac -source 1.6 -target 1.6 -d ../bin -cp ;../lib/commons-io-2.4.jar;../lib/launchwrapper-1.7.jar customskinloader/tweaker/*.java
|
||||
cd ../bin
|
||||
del ../out/CustomSkinLoader_%MC_VERSION%-%CSL_VERSION%.jar
|
||||
jar cfm ../out/CustomSkinLoader_%MC_VERSION%-%CSL_VERSION%.jar META-INF/MANIFEST.MF .
|
||||
pause
|
||||
@@ -1,91 +0,0 @@
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.ImageObserver;
|
||||
|
||||
public class bnm implements bng {
|
||||
private int[] a;//imageData
|
||||
private int b;//imageWidth
|
||||
private int c;//imageHeight
|
||||
|
||||
public BufferedImage a(BufferedImage image) {
|
||||
if(image == null) {
|
||||
return null;
|
||||
} else {
|
||||
int ratio = image.getWidth() / 64;
|
||||
this.b = 64 * ratio;
|
||||
this.c = 64 * ratio;
|
||||
BufferedImage bufferedimage = new BufferedImage(this.b, this.c, 2);
|
||||
Graphics graphics = bufferedimage.getGraphics();
|
||||
graphics.drawImage(image, 0, 0, (ImageObserver)null);
|
||||
if(image.getHeight() == 32 * ratio) {
|
||||
graphics.drawImage(bufferedimage, 24 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 4 * ratio, 16 * ratio, 8 * ratio, 20 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 28 * ratio, 48 * ratio, 24 * ratio, 52 * ratio, 8 * ratio, 16 * ratio, 12 * ratio, 20 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 20 * ratio, 52 * ratio, 16 * ratio, 64 * ratio, 8 * ratio, 20 * ratio, 12 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 24 * ratio, 52 * ratio, 20 * ratio, 64 * ratio, 4 * ratio, 20 * ratio, 8 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 28 * ratio, 52 * ratio, 24 * ratio, 64 * ratio, 0 * ratio, 20 * ratio, 4 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 32 * ratio, 52 * ratio, 28 * ratio, 64 * ratio, 12 * ratio, 20 * ratio, 16 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 40 * ratio, 48 * ratio, 36 * ratio, 52 * ratio, 44 * ratio, 16 * ratio, 48 * ratio, 20 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 44 * ratio, 48 * ratio, 40 * ratio, 52 * ratio, 48 * ratio, 16 * ratio, 52 * ratio, 20 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 36 * ratio, 52 * ratio, 32 * ratio, 64 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 40 * ratio, 52 * ratio, 36 * ratio, 64 * ratio, 44 * ratio, 20 * ratio, 48 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 44 * ratio, 52 * ratio, 40 * ratio, 64 * ratio, 40 * ratio, 20 * ratio, 44 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
graphics.drawImage(bufferedimage, 48 * ratio, 52 * ratio, 44 * ratio, 64 * ratio, 52 * ratio, 20 * ratio, 56 * ratio, 32 * ratio, (ImageObserver)null);
|
||||
}
|
||||
|
||||
graphics.dispose();
|
||||
this.a = ((DataBufferInt)bufferedimage.getRaster().getDataBuffer()).getData();
|
||||
if(!customskinloader.CustomSkinLoader.config.enableTransparentSkin){
|
||||
this.b( 0 * ratio, 0 * ratio, 32 * ratio, 16 * ratio);
|
||||
this.a(32 * ratio, 0 * ratio, 64 * ratio, 32 * ratio);
|
||||
this.b( 0 * ratio, 16 * ratio, 64 * ratio, 32 * ratio);
|
||||
this.a( 0 * ratio, 32 * ratio, 16 * ratio, 48 * ratio);
|
||||
this.a(16 * ratio, 32 * ratio, 40 * ratio, 48 * ratio);
|
||||
this.a(40 * ratio, 32 * ratio, 56 * ratio, 48 * ratio);
|
||||
this.a( 0 * ratio, 48 * ratio, 16 * ratio, 64 * ratio);
|
||||
this.b(16 * ratio, 48 * ratio, 48 * ratio, 64 * ratio);
|
||||
this.a(48 * ratio, 48 * ratio, 64 * ratio, 64 * ratio);
|
||||
}
|
||||
return bufferedimage;
|
||||
}
|
||||
}
|
||||
|
||||
public void a() {
|
||||
}
|
||||
|
||||
//setAreaTransparent
|
||||
private void a(int p1, int p2, int p3, int p4) {
|
||||
if(!this.c(p1, p2, p3, p4)) {
|
||||
for(int i = p1; i < p3; ++i) {
|
||||
for(int j = p2; j < p4; ++j) {
|
||||
this.a[i + j * this.b] &= 16777215;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//setAreaOpaque
|
||||
private void b(int p1, int p2, int p3, int p4) {
|
||||
for(int i = p1; i < p3; ++i) {
|
||||
for(int j = p2; j < p4; ++j) {
|
||||
this.a[i + j * this.b] |= -16777216;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//hasTransparency
|
||||
private boolean c(int p1, int p2, int p3, int p4) {
|
||||
for(int i = p1; i < p3; ++i) {
|
||||
for(int j = p2; j < p4; ++j) {
|
||||
int k = this.a[i + j * this.b];
|
||||
if((k >> 24 & 255) < 128) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.InsecureTextureException;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
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;
|
||||
|
||||
public class bwk {
|
||||
private static final ExecutorService a = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());//THREAD_POOL
|
||||
private final bvf b;//textureManager
|
||||
private final File c;//skinCacheDir
|
||||
private final MinecraftSessionService d;//sessionServive
|
||||
private final LoadingCache<GameProfile, Map<Type, MinecraftProfileTexture>> e;//skinCacheLoader
|
||||
|
||||
public bwk(bvf textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
||||
this.b = textureManagerInstance;
|
||||
this.c = skinCacheDirectory;
|
||||
this.d = sessionService;
|
||||
this.e = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).build(new CacheLoader<GameProfile, Map<Type, MinecraftProfileTexture>>() {
|
||||
//roolback
|
||||
public Map<Type, MinecraftProfileTexture> a(GameProfile p_load_1_) throws Exception {
|
||||
return bcc.z().X().getTextures(p_load_1_, false);
|
||||
}
|
||||
public Map<Type, MinecraftProfileTexture> load(GameProfile p_load_1_) throws Exception {
|
||||
return bcc.z().X().getTextures(p_load_1_, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public kk a(MinecraftProfileTexture profileTexture, Type textureType) {
|
||||
return this.a(profileTexture, textureType, (bwk.a)null);
|
||||
}
|
||||
|
||||
public kk a(final MinecraftProfileTexture profileTexture, final Type textureType, final bwk.a skinAvailableCallback) {
|
||||
final kk kk = new kk("skins/" + profileTexture.getHash());
|
||||
bvg bvg = this.b.b(kk);
|
||||
if(bvg != null) {
|
||||
if(skinAvailableCallback != null) {
|
||||
skinAvailableCallback.a(textureType, kk, profileTexture);
|
||||
}
|
||||
} else {
|
||||
File file1 = new File(this.c, profileTexture.getHash().length() > 2?profileTexture.getHash().substring(0, 2):"xx");
|
||||
File file2 = new File(file1, profileTexture.getHash());
|
||||
final bng bng = textureType == Type.SKIN?new bnm():null;
|
||||
buv buv = new buv(file2, profileTexture.getUrl(), bvt.a(), new bng() {
|
||||
public BufferedImage a(BufferedImage image) {
|
||||
if(bng != null) {
|
||||
image = bng.a(image);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public void a() {
|
||||
if(bng != null) {
|
||||
bng.a();
|
||||
}
|
||||
|
||||
if(skinAvailableCallback != null) {
|
||||
skinAvailableCallback.a(textureType, kk, profileTexture);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
this.b.a((kk)kk, (bvg)buv);
|
||||
}
|
||||
|
||||
return kk;
|
||||
}
|
||||
|
||||
public void a(final GameProfile profile, final bwk.a skinAvailableCallback, final boolean requireSecure) {
|
||||
a.submit(new Runnable() {
|
||||
public void run() {
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.newHashMap();
|
||||
|
||||
try {
|
||||
map.putAll(bwk.this.d.getTextures(profile, requireSecure));
|
||||
} catch (InsecureTextureException var3) {
|
||||
;
|
||||
}
|
||||
/*
|
||||
if(map.isEmpty() && profile.getId().equals(bcc.z().K().e().getId())) {
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().putAll(bcc.z().L());
|
||||
map.putAll(bwk.this.d.getTextures(profile, false));
|
||||
}*/
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map);
|
||||
if(!newMap.isEmpty()){
|
||||
map.clear();
|
||||
map.putAll(newMap);
|
||||
}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
bcc.z().a(new Runnable() {
|
||||
public void run() {
|
||||
if(map.containsKey(Type.SKIN)) {
|
||||
bwk.this.a((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN, skinAvailableCallback);
|
||||
}
|
||||
|
||||
if(map.containsKey(Type.CAPE)) {
|
||||
bwk.this.a((MinecraftProfileTexture)map.get(Type.CAPE), Type.CAPE, skinAvailableCallback);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Map<Type, MinecraftProfileTexture> a(GameProfile profile) {
|
||||
//CustomSkinLoader Begin (Skull Part)
|
||||
//return (Map)this.e.getUnchecked(profile);
|
||||
return (customskinloader.CustomSkinLoader.config.enable && customskinloader.CustomSkinLoader.config.enableSkull)?
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(profile.getName()):
|
||||
this.e.getUnchecked(profile);
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
public interface a {
|
||||
void a(Type var1, kk var2, MinecraftProfileTexture var3);
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package customskinloader.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* MinecraftUtil for non-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(){
|
||||
return getMinecraftDataDir();
|
||||
}
|
||||
|
||||
public static File minecraftDataFolder=null;
|
||||
private static final String MINECRAFT_DATA_FOLDER=".minecraft";
|
||||
public static File getMinecraftDataDir(){
|
||||
if(minecraftDataFolder!=null)
|
||||
return minecraftDataFolder;
|
||||
testProbe();
|
||||
if(minecraftDataFolder!=null)
|
||||
return minecraftDataFolder;
|
||||
File temp=new File("");
|
||||
if(temp.getAbsolutePath().endsWith(MINECRAFT_DATA_FOLDER))
|
||||
return temp;
|
||||
File temp0=new File(MINECRAFT_DATA_FOLDER);
|
||||
if(temp0.exists())
|
||||
return temp0;
|
||||
return temp;
|
||||
}
|
||||
|
||||
private static String minecraftVersion=null;
|
||||
public static String getMinecraftVersion(){
|
||||
if(minecraftVersion!=null)
|
||||
return minecraftVersion;
|
||||
testProbe();
|
||||
return minecraftVersion;
|
||||
}
|
||||
|
||||
private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/(.*?)/(.*?).jar$");
|
||||
private static void testProbe(){
|
||||
URLClassLoader ucl = (URLClassLoader)new MinecraftUtil().getClass().getClassLoader();
|
||||
URL urls[] = ucl.getURLs();
|
||||
for(URL url:urls){
|
||||
Matcher m = null;
|
||||
try{
|
||||
m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(m==null)
|
||||
continue;
|
||||
if(!m.matches())
|
||||
continue;
|
||||
if(minecraftDataFolder==null)
|
||||
minecraftDataFolder=new File(m.group(1));
|
||||
//System.out.println(url.getPath()+" "+minecraftDataFolder.getAbsolutePath());
|
||||
if(minecraftVersion==null)
|
||||
minecraftVersion=m.group(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,9 @@ public class SkinManager
|
||||
return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false);
|
||||
}
|
||||
});
|
||||
//CustomSkinLoader Begin (Init Session Service)
|
||||
customskinloader.loader.MojangAPILoader.defaultSessionService=sessionService;
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +63,10 @@ public class SkinManager
|
||||
*/
|
||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
||||
{
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + profileTexture.getHash());
|
||||
//CustomSkinLoader Begin (Parse HttpTextureInfo)
|
||||
customskinloader.utils.HttpTextureUtil.HttpTextureInfo info=customskinloader.utils.HttpTextureUtil.toHttpTextureInfo(this.skinCacheDir, profileTexture.getUrl());
|
||||
//CustomSkinLoader End
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);//Modified
|
||||
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
||||
|
||||
if (itextureobject != null)
|
||||
@@ -72,10 +78,8 @@ public class SkinManager
|
||||
}
|
||||
else
|
||||
{
|
||||
File file1 = new File(this.skinCacheDir, profileTexture.getHash().length() > 2 ? profileTexture.getHash().substring(0, 2) : "xx");
|
||||
File file2 = new File(file1, profileTexture.getHash());
|
||||
final IImageBuffer iimagebuffer = textureType == Type.SKIN ? new ImageBufferDownload() : null;
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(file2, profileTexture.getUrl(), DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer()//Modified
|
||||
{
|
||||
public BufferedImage parseUserSkin(BufferedImage image)
|
||||
{
|
||||
@@ -113,30 +117,13 @@ public class SkinManager
|
||||
{
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||
|
||||
try
|
||||
{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}
|
||||
catch (InsecureTextureException var3)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
if (map.isEmpty() && profile.getId().equals(Minecraft.getMinecraft().getSession().getProfile().getId()))
|
||||
{
|
||||
profile.getProperties().clear();
|
||||
profile.getProperties().putAll(Minecraft.getMinecraft().getProfileProperties());
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, false));
|
||||
}*/
|
||||
|
||||
//CustomSkinLoader Begin (User Skin/Cape Part)
|
||||
if(customskinloader.CustomSkinLoader.config.enable){
|
||||
Map newMap=customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map);
|
||||
if(!newMap.isEmpty()){
|
||||
map.clear();
|
||||
map.putAll(newMap);
|
||||
}
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
}else{
|
||||
try{
|
||||
map.putAll(SkinManager.this.sessionService.getTextures(profile, requireSecure));
|
||||
}catch(InsecureTextureException var3){}
|
||||
}
|
||||
//CustomSkinLoader End
|
||||
|
||||
@@ -163,8 +150,10 @@ 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.getName(),this.skinCacheLoader.getUnchecked(profile)):
|
||||
customskinloader.CustomSkinLoader.loadProfileFromCache(profile):
|
||||
this.skinCacheLoader.getUnchecked(profile);
|
||||
//CustomSkinLoader End
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Manifest-Version: 1.0
|
||||
TweakClass: customskinloader.tweaker.ForgeTweaker
|
||||
TweakClass: customskinloader.tweaker.ModSystemTweaker
|
||||
TweakName: CustomSkinLoader
|
||||
TweakAuthor: xfl03,JLChnToZ
|
||||
TweakOrder: -10
|
||||
@@ -13,6 +13,7 @@ import org.apache.commons.io.IOUtils;
|
||||
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;
|
||||
|
||||
@@ -23,35 +24,41 @@ import customskinloader.loader.IProfileLoader;
|
||||
import customskinloader.loader.LegacyLoader;
|
||||
import customskinloader.loader.MojangAPILoader;
|
||||
import customskinloader.loader.UniSkinAPILoader;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.ProfileCache;
|
||||
import customskinloader.profile.UserProfile;
|
||||
import customskinloader.utils.MinecraftUtil;
|
||||
|
||||
/**
|
||||
* Custom skin loader mod for Minecraft.
|
||||
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
|
||||
* @version 13.11 (2016.7.3)
|
||||
* @version 14.1 (2016.7.31)
|
||||
*/
|
||||
public class CustomSkinLoader {
|
||||
public static final String CustomSkinLoader_VERSION="13.11";
|
||||
public static final String CustomSkinLoader_VERSION="14.1";
|
||||
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/"),
|
||||
SkinSiteProfile.createMojangAPI("Mojang"),
|
||||
SkinSiteProfile.createCustomSkinAPI("BlessingSkin","https://skin.prinzeugen.net/csl/"),
|
||||
SkinSiteProfile.createCustomSkinAPI("OneSkin","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/"),
|
||||
new SkinSiteProfile("McSkin","CustomSkinAPI","http://www.mcskin.cc/")};
|
||||
//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")};
|
||||
public static final HashMap<String,IProfileLoader> LOADERS=initLoaders();
|
||||
|
||||
public static final Gson GSON=new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final Logger logger=initLogger();
|
||||
public static final Config config=loadConfig0();
|
||||
|
||||
private static final Map<String,UserProfile> profileCache=new HashMap<String,UserProfile>();
|
||||
private static final ProfileCache profileCache=new ProfileCache();
|
||||
|
||||
//Entrance
|
||||
public static Map loadProfile(String username,Map defaultProfile){
|
||||
//For User Skin
|
||||
public static Map loadProfile(GameProfile gameProfile){
|
||||
String username=gameProfile.getName();
|
||||
//Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
|
||||
if(username==null){
|
||||
logger.warning("Could not load profile: username is null.");
|
||||
@@ -59,28 +66,34 @@ public class CustomSkinLoader {
|
||||
}
|
||||
String tempName=Thread.currentThread().getName();
|
||||
Thread.currentThread().setName(username);//Change Thread Name
|
||||
UserProfile profile=loadProfile(username,ModelManager0.toUserProfile(defaultProfile));
|
||||
UserProfile profile=null;
|
||||
if(profileCache.isReady(username)){
|
||||
logger.info("Cached profile will be used.");
|
||||
profile=profileCache.getProfile(username);
|
||||
if(profile==null){
|
||||
logger.warning("(!Cached Profile is empty!) Expiry:"+profileCache.getExpiry(username));
|
||||
if(profileCache.isExpired(username)){//force load
|
||||
profileCache.setLoading(username, true);
|
||||
profile=loadProfile0(gameProfile);
|
||||
}
|
||||
}
|
||||
else
|
||||
logger.info(profile.toString(profileCache.getExpiry(username)));
|
||||
}else{
|
||||
profileCache.setLoading(username, true);
|
||||
profile=loadProfile0(gameProfile);
|
||||
}
|
||||
Thread.currentThread().setName(tempName);
|
||||
return ModelManager0.fromUserProfile(profile);
|
||||
}
|
||||
public static UserProfile loadProfile(String username,UserProfile defaultProfile){
|
||||
//Core
|
||||
public static UserProfile loadProfile0(GameProfile gameProfile){
|
||||
String username=gameProfile.getName();
|
||||
profileCache.setLoading(username, true);
|
||||
logger.info("Loading "+username+"'s profile.");
|
||||
if(config.enableCache&&profileCache.get(username)!=null){
|
||||
logger.info("Cached profile will be used.");
|
||||
UserProfile profile=profileCache.get(username);
|
||||
logger.info(profile.toString());
|
||||
return profile;
|
||||
}
|
||||
profileCache.put(username, null);
|
||||
for(int i=0;i<config.loadlist.length;i++){
|
||||
SkinSiteProfile ssp=config.loadlist[i];
|
||||
logger.info((i+1)+"/"+config.loadlist.length+" Try to load profile from '"+ssp.name+"'.");
|
||||
if(ssp.type.equalsIgnoreCase("MojangAPI") && defaultProfile!=null && !defaultProfile.isEmpty()){
|
||||
logger.info("Default profile will be used.");
|
||||
logger.info(defaultProfile.toString());
|
||||
profileCache.put(username, defaultProfile);
|
||||
return defaultProfile;//Create a new map instance
|
||||
}
|
||||
IProfileLoader loader=LOADERS.get(ssp.type.toLowerCase());
|
||||
if(loader==null){
|
||||
logger.info("Type '"+ssp.type+"' is not defined.");
|
||||
@@ -88,42 +101,60 @@ public class CustomSkinLoader {
|
||||
}
|
||||
UserProfile profile=null;
|
||||
try{
|
||||
profile=loader.loadProfile(ssp, username);
|
||||
if(ssp.local==null||ssp.local==false)
|
||||
profile=loader.loadProfile(ssp, gameProfile);
|
||||
else
|
||||
profile=loader.loadLocalProfile(ssp, gameProfile);
|
||||
}catch(Exception e){
|
||||
logger.info("Exception occurs while loading: "+e.getMessage());
|
||||
logger.warning("Exception occurs while loading.");
|
||||
logger.warning(e);
|
||||
}
|
||||
if(profile==null)
|
||||
continue;
|
||||
logger.info(username+"'s profile loaded.");
|
||||
logger.info(profile.toString());
|
||||
profileCache.put(username, profile);
|
||||
profileCache.updateCache(username, profile);
|
||||
profileCache.setLoading(username, false);
|
||||
logger.info(profile.toString(profileCache.getExpiry(username)));
|
||||
return profile;
|
||||
}
|
||||
logger.info(username+"'s profile not found.");
|
||||
return defaultProfile;
|
||||
logger.info(username+"'s profile not found in load list.");
|
||||
if(config.enableLocalProfileCache){
|
||||
UserProfile profile=profileCache.getLocalProfile(username);
|
||||
if(profile==null)
|
||||
logger.info(username+"'s LocalProfile not found.");
|
||||
else{
|
||||
profileCache.updateCache(username, profile, false);
|
||||
profileCache.setLoading(username, false);
|
||||
logger.info(username+"'s LocalProfile will be used.");
|
||||
logger.info(profile.toString(profileCache.getExpiry(username)));
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
profileCache.setLoading(username, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
//For Skull
|
||||
public static Map<Type, MinecraftProfileTexture> loadProfileFromCache(final String username,final Map defaultProfile) {
|
||||
if(defaultProfile!=null&&!defaultProfile.isEmpty())
|
||||
return defaultProfile;
|
||||
if(profileCache.containsKey(username)){
|
||||
UserProfile profile=profileCache.get(username);
|
||||
public static Map<Type, MinecraftProfileTexture> 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(config.enableUpdateSkull?profileCache.isReady(username):profileCache.isExist(username)){
|
||||
UserProfile profile=profileCache.getProfile(username);
|
||||
return ModelManager0.fromUserProfile(profile);
|
||||
}
|
||||
profileCache.put(username, null);
|
||||
//profileCache.setLoading(username, true);
|
||||
Thread loadThread=new Thread(){
|
||||
public void run(){
|
||||
loadProfile(username,ModelManager0.toUserProfile(defaultProfile));//Load in thread
|
||||
loadProfile0(gameProfile);//Load in thread
|
||||
}
|
||||
};
|
||||
loadThread.setName(username+"'s skull");
|
||||
loadThread.start();
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
public static Map<Type, MinecraftProfileTexture> loadProfileFromCache(final String username) {
|
||||
return loadProfileFromCache(username,null);
|
||||
}
|
||||
|
||||
private static Logger initLogger() {
|
||||
Logger logger=new Logger(LOG_FILE);
|
||||
@@ -144,10 +175,14 @@ public class CustomSkinLoader {
|
||||
|
||||
private static Config loadConfig0() {
|
||||
Config config=loadConfig();
|
||||
logger.info("Enable:"+config.enable+", EnableCache:"+config.enableCache+
|
||||
", EnableSkull:"+config.enableSkull+", EnableTranSkin:"+config.enableTransparentSkin+
|
||||
logger.info("Enable:"+config.enable+
|
||||
", EnableSkull:"+config.enableSkull+
|
||||
", EnableTranSkin:"+config.enableTransparentSkin+
|
||||
", CacheExpiry:"+config.cacheExpiry+
|
||||
", enableUpdateSkull:"+config.enableUpdateSkull+
|
||||
", LocalProfileCache:"+config.enableLocalProfileCache+
|
||||
", LoadList:"+(config.loadlist==null?0:config.loadlist.length));
|
||||
if(config.version==null||Float.parseFloat(config.version)<Float.parseFloat(CustomSkinLoader_VERSION)){
|
||||
if(config.version==null||Float.parseFloat(CustomSkinLoader_VERSION)-Float.parseFloat(config.version)>0.01){
|
||||
logger.info("Config File is out of date: "+config.version);
|
||||
config.version=CustomSkinLoader_VERSION;
|
||||
writeConfig(config,true);
|
||||
@@ -164,7 +199,7 @@ public class CustomSkinLoader {
|
||||
try {
|
||||
logger.info("Try to load config.");
|
||||
String json=IOUtils.toString(new FileInputStream(CONFIG_FILE));
|
||||
Config config=new Gson().fromJson(json, Config.class);
|
||||
Config config=GSON.fromJson(json, Config.class);
|
||||
logger.info("Successfully load config.");
|
||||
return config;
|
||||
}catch (Exception e) {
|
||||
@@ -183,8 +218,7 @@ public class CustomSkinLoader {
|
||||
return config;
|
||||
}
|
||||
private static void writeConfig(Config config,boolean update){
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String json=gson.toJson(config);
|
||||
String json=GSON.toJson(config);
|
||||
if(CONFIG_FILE.exists())
|
||||
CONFIG_FILE.delete();
|
||||
try {
|
||||
|
||||
@@ -5,9 +5,11 @@ import customskinloader.CustomSkinLoader;
|
||||
public class Config {
|
||||
public String version;
|
||||
public boolean enable=true;
|
||||
public boolean enableCache=true;
|
||||
public boolean enableSkull=true;
|
||||
public boolean enableTransparentSkin=false;
|
||||
public int cacheExpiry=10;
|
||||
public boolean enableUpdateSkull=false;
|
||||
public boolean enableLocalProfileCache=false;
|
||||
public SkinSiteProfile[] loadlist;
|
||||
|
||||
//Init config
|
||||
|
||||
@@ -3,31 +3,54 @@ package customskinloader.config;
|
||||
public class SkinSiteProfile {
|
||||
public String name;
|
||||
public String type;
|
||||
public Boolean local=null;
|
||||
public String root;
|
||||
public String skin;
|
||||
public String cape;
|
||||
public String model;
|
||||
public String userAgent;
|
||||
|
||||
//For MojangAPI
|
||||
public SkinSiteProfile(String name,String type){
|
||||
this.name=name;
|
||||
this.type=type;
|
||||
public static SkinSiteProfile createMojangAPI(String name){
|
||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
||||
ssp.name=name;
|
||||
ssp.type="MojangAPI";
|
||||
return ssp;
|
||||
}
|
||||
|
||||
//For CSL/USM API
|
||||
public SkinSiteProfile(String name,String type,String root){
|
||||
this.name=name;
|
||||
this.type=type;
|
||||
this.root=root;
|
||||
public static SkinSiteProfile createCustomSkinAPI(String name,String root){
|
||||
return createCustomSkinAPI(name,false,root);
|
||||
}
|
||||
|
||||
//for Legacy
|
||||
public SkinSiteProfile(String name,String type,String skin,String cape,String model){
|
||||
this.name=name;
|
||||
this.type=type;
|
||||
this.skin=skin;
|
||||
this.cape=cape;
|
||||
this.model=model;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package customskinloader;
|
||||
package customskinloader.profile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
@@ -0,0 +1,109 @@
|
||||
package customskinloader.profile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.Config;
|
||||
import customskinloader.utils.TimeUtil;
|
||||
|
||||
public class ProfileCache {
|
||||
public static File PROFILE_CACHE_DIR=new File(CustomSkinLoader.DATA_DIR,"ProfileCache");
|
||||
|
||||
private HashMap<String,CachedProfile> cachedProfiles=new HashMap<String,CachedProfile>();
|
||||
private HashMap<String,UserProfile> localProfiles=new HashMap<String,UserProfile>();
|
||||
|
||||
public ProfileCache(){
|
||||
if(!PROFILE_CACHE_DIR.exists())
|
||||
PROFILE_CACHE_DIR.mkdir();
|
||||
}
|
||||
|
||||
public boolean isExist(String username){
|
||||
return cachedProfiles.containsKey(username.toLowerCase());
|
||||
}
|
||||
public boolean isReady(String username){
|
||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||
return cp==null?false:(cp.loading||cp.expiryTime>TimeUtil.getCurrentUnixTimestamp());
|
||||
}
|
||||
public boolean isExpired(String username){
|
||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||
return cp==null?true:(cp.expiryTime<=TimeUtil.getCurrentUnixTimestamp());
|
||||
}
|
||||
|
||||
public UserProfile getProfile(String username){
|
||||
return getCachedProfile(username).profile;
|
||||
}
|
||||
public long getExpiry(String username){
|
||||
return getCachedProfile(username).expiryTime;
|
||||
}
|
||||
public UserProfile getLocalProfile(String username){
|
||||
if(localProfiles.containsKey(username.toLowerCase()))
|
||||
return localProfiles.get(username.toLowerCase());
|
||||
return loadLocalProfile(username);
|
||||
}
|
||||
|
||||
public void setLoading(String username,boolean loading){
|
||||
getCachedProfile(username).loading=loading;
|
||||
}
|
||||
public void updateCache(String username,UserProfile profile){
|
||||
updateCache(username,profile,CustomSkinLoader.config.enableLocalProfileCache);
|
||||
}
|
||||
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
||||
CachedProfile cp=getCachedProfile(username);
|
||||
cp.profile=profile;
|
||||
cp.expiryTime=TimeUtil.getUnixTimestampRandomDelay(CustomSkinLoader.config.cacheExpiry);
|
||||
if(!saveLocalProfile)
|
||||
return;
|
||||
saveLocalProfile(username,profile);
|
||||
}
|
||||
|
||||
private CachedProfile getCachedProfile(String username){
|
||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||
if(cp!=null)
|
||||
return cp;
|
||||
cp=new CachedProfile();
|
||||
cachedProfiles.put(username.toLowerCase(), cp);
|
||||
return cp;
|
||||
}
|
||||
private UserProfile loadLocalProfile(String username){
|
||||
File localProfile=new File(PROFILE_CACHE_DIR,username.toLowerCase()+".json");
|
||||
if(!localProfile.exists()){
|
||||
localProfiles.put(username.toLowerCase(), null);
|
||||
}
|
||||
try{
|
||||
String json=IOUtils.toString(new FileInputStream(localProfile));
|
||||
UserProfile profile=CustomSkinLoader.GSON.fromJson(json, UserProfile.class);
|
||||
localProfiles.put(username.toLowerCase(), profile);
|
||||
CustomSkinLoader.logger.info("Successfully load LocalProfile.");
|
||||
return profile;
|
||||
}catch(Exception e){
|
||||
CustomSkinLoader.logger.info("Failed to load LocalProfile.("+e.getMessage()+")");
|
||||
localProfiles.put(username.toLowerCase(), null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private void saveLocalProfile(String username,UserProfile profile){
|
||||
String json=CustomSkinLoader.GSON.toJson(profile);
|
||||
File localProfile=new File(PROFILE_CACHE_DIR,username.toLowerCase()+".json");
|
||||
if(localProfile.exists())
|
||||
localProfile.delete();
|
||||
try {
|
||||
localProfile.createNewFile();
|
||||
IOUtils.write(json, new FileOutputStream(localProfile));
|
||||
CustomSkinLoader.logger.info("Successfully save LocalProfile.");
|
||||
} catch (Exception e) {
|
||||
CustomSkinLoader.logger.info("Failed to save LocalProfile.("+e.getMessage()+")");
|
||||
}
|
||||
}
|
||||
}
|
||||
class CachedProfile{
|
||||
public UserProfile profile;
|
||||
public long expiryTime=0;
|
||||
public boolean loading=false;
|
||||
}
|
||||
+5
-2
@@ -1,4 +1,4 @@
|
||||
package customskinloader;
|
||||
package customskinloader.profile;
|
||||
|
||||
/**The instance to storage user's profile in memory temporarily.
|
||||
* In this manner, it could be easier to pass profile in program.
|
||||
@@ -30,7 +30,10 @@ public class UserProfile {
|
||||
*/
|
||||
@Override
|
||||
public String toString(){
|
||||
return "(SkinUrl: "+skinUrl+" , Model: "+model+" , CapeUrl: "+capeUrl+")";
|
||||
return toString(0);
|
||||
}
|
||||
public String toString(long expiry){
|
||||
return "(SkinUrl: "+skinUrl+" , Model: "+model+" , CapeUrl: "+capeUrl+(expiry==0?"":(" , Expiry: "+expiry))+")";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -12,6 +12,7 @@ import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import customskinloader.utils.MinecraftUtil;
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
public class ClassTransformer implements IClassTransformer {
|
||||
@@ -20,13 +21,14 @@ public class ClassTransformer implements IClassTransformer {
|
||||
private ArrayList<String> classes=new ArrayList<String>();
|
||||
|
||||
public ClassTransformer() {
|
||||
ForgeTweaker.logger.info("ClassTransformer Begin");
|
||||
ModSystemTweaker.logger.info("ClassTransformer Begin");
|
||||
try {
|
||||
URLClassLoader ucl = (URLClassLoader)this.getClass().getClassLoader();
|
||||
URL urls[] = ucl.getURLs();
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
URL url = urls[i];
|
||||
for (URL url : urls) {
|
||||
ZipFile tempZipFile = getZipFile(url);
|
||||
if(tempZipFile==null)
|
||||
continue;
|
||||
if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){
|
||||
tempZipFile.close();
|
||||
continue;
|
||||
@@ -43,27 +45,29 @@ public class ClassTransformer implements IClassTransformer {
|
||||
sb.append(name);
|
||||
}
|
||||
}
|
||||
ForgeTweaker.logger.info("Jar File URL: " + url);
|
||||
ForgeTweaker.logger.info("Classes:" + sb.toString());
|
||||
ModSystemTweaker.logger.info("Jar File URL: " + url);
|
||||
ModSystemTweaker.logger.info("Classes:" + sb.toString());
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ForgeTweaker.logger.warning(e);
|
||||
ModSystemTweaker.logger.warning(e);
|
||||
}
|
||||
if (zipFile == null) {
|
||||
ForgeTweaker.logger.info("Can not find JAR in the classpath.");
|
||||
ModSystemTweaker.logger.info("Can not find JAR in the classpath.");
|
||||
}
|
||||
}
|
||||
|
||||
private static ZipFile getZipFile(URL url)
|
||||
{
|
||||
if(MinecraftUtil.isCoreFile(url))
|
||||
return null;
|
||||
ZipFile zipFile0;
|
||||
try {
|
||||
File file = new File(url.toURI());
|
||||
zipFile0 = new ZipFile(file);
|
||||
return zipFile0;
|
||||
} catch (Exception e) {
|
||||
ForgeTweaker.logger.warning(e);
|
||||
ModSystemTweaker.logger.warning(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -80,7 +84,7 @@ public class ClassTransformer implements IClassTransformer {
|
||||
return bytes;
|
||||
byte diBytes[] = getClass(ze);
|
||||
if (diBytes != null) {
|
||||
ForgeTweaker.logger.info("Class '" + name + "'("+transformedName+") transformed.");
|
||||
ModSystemTweaker.logger.info("Class '" + name + "'("+transformedName+") transformed.");
|
||||
return diBytes;
|
||||
}
|
||||
else
|
||||
@@ -93,7 +97,7 @@ public class ClassTransformer implements IClassTransformer {
|
||||
byte[] bytes = IOUtils.toByteArray(is);
|
||||
if ((long)bytes.length == ze.getSize())
|
||||
return bytes;
|
||||
ForgeTweaker.logger.info("Failed: " + ze.getName() + " " + bytes.length + " / " + ze.getSize());
|
||||
ModSystemTweaker.logger.info("Failed: " + ze.getName() + " " + bytes.length + " / " + ze.getSize());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+6
-9
@@ -9,35 +9,32 @@ import java.util.List;
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
public class ForgeTweaker implements ITweaker {
|
||||
public class ModSystemTweaker implements ITweaker {
|
||||
|
||||
public static Logger logger = new Logger();
|
||||
|
||||
public ForgeTweaker() {
|
||||
}
|
||||
|
||||
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
|
||||
MinecraftUtil.minecraftDataFolder=gameDir;
|
||||
File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log");
|
||||
logger = new Logger(tweakerLogFile);
|
||||
|
||||
logger.info("Using ForgeTweaker");
|
||||
logger.info("ForgeTweaker: acceptOptions");
|
||||
logger.info("Using ModSystemTweaker");
|
||||
logger.info("ModSystemTweaker: acceptOptions");
|
||||
}
|
||||
|
||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
logger.info("ForgeTweaker: injectIntoClassLoader");
|
||||
logger.info("ModSystemTweaker: injectIntoClassLoader");
|
||||
classLoader.registerTransformer("customskinloader.tweaker.ClassTransformer");
|
||||
logger.info("ClassTransformer Registered");
|
||||
}
|
||||
|
||||
public String getLaunchTarget() {
|
||||
logger.info("ForgeTweaker: getLaunchTarget");
|
||||
logger.info("ModSystemTweaker: getLaunchTarget");
|
||||
return "net.minecraft.client.main.Main";
|
||||
}
|
||||
|
||||
public String[] getLaunchArguments() {
|
||||
logger.info("ForgeTweaker: getLaunchArguments");
|
||||
logger.info("ModSystemTweaker: getLaunchArguments");
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,6 @@ public class Tweaker implements ITweaker {
|
||||
|
||||
public static Logger logger = new Logger();
|
||||
|
||||
public Tweaker() {
|
||||
logger.info("Using Tweaker");
|
||||
}
|
||||
|
||||
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
|
||||
MinecraftUtil.minecraftDataFolder=gameDir;
|
||||
File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log");
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package customskinloader.utils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
|
||||
public class HttpTextureUtil {
|
||||
public static class HttpTextureInfo{
|
||||
public String url="";
|
||||
public File cacheFile;
|
||||
public String hash;
|
||||
}
|
||||
private static final String
|
||||
LEGACY_MARK="(LEGACY)",
|
||||
LOCAL_MARK="(LOCAL)",
|
||||
LOCAL_LEGACY_MARK="(LOCAL_LEGACY)";
|
||||
|
||||
public static HttpTextureInfo toHttpTextureInfo(File defaultCacheDir,String fakeUrl){
|
||||
HttpTextureInfo info=new HttpTextureInfo();
|
||||
if(fakeUrl.startsWith("http")){
|
||||
info.url=fakeUrl;
|
||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
||||
info.cacheFile=getCacheFile(defaultCacheDir,info.hash);
|
||||
return info;
|
||||
}
|
||||
if(fakeUrl.startsWith(LOCAL_LEGACY_MARK)){
|
||||
fakeUrl=fakeUrl.replaceFirst(LOCAL_LEGACY_MARK, "");
|
||||
String[] t=fakeUrl.split(",",2);
|
||||
if(t.length!=2)
|
||||
return info;
|
||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,t[1]);
|
||||
info.hash=t[0];
|
||||
return info;
|
||||
}
|
||||
if(fakeUrl.startsWith(LOCAL_MARK)){
|
||||
fakeUrl=fakeUrl.replaceFirst(LOCAL_MARK, "");
|
||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,fakeUrl);
|
||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
||||
return info;
|
||||
}
|
||||
if(fakeUrl.startsWith(LEGACY_MARK)){
|
||||
fakeUrl=fakeUrl.replaceFirst(LEGACY_MARK, "");
|
||||
String[] t=fakeUrl.split(",",2);
|
||||
if(t.length!=2)
|
||||
return info;
|
||||
info.url=t[1];
|
||||
info.hash=t[0];
|
||||
info.cacheFile=getCacheFile(defaultCacheDir,info.hash);
|
||||
return info;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public static String getLegacyFakeUrl(String url,String hash){
|
||||
return LEGACY_MARK+hash+","+url;
|
||||
}
|
||||
public static String getLocalFakeUrl(String path){
|
||||
return LOCAL_MARK+path;
|
||||
}
|
||||
public static String getLocalLegacyFakeUrl(String path,String hash){
|
||||
return LOCAL_LEGACY_MARK+hash+","+path;
|
||||
}
|
||||
public static String getHash(String url,long size,long lastModified){
|
||||
return DigestUtils.sha1Hex(size+url+lastModified);
|
||||
}
|
||||
|
||||
private static File getCacheFile(File cacheDir,String hash){
|
||||
return new File(new File(cacheDir,hash.length()>2?hash.substring(0,2):"xx"), hash);
|
||||
}
|
||||
}
|
||||
@@ -19,64 +19,65 @@ public class HttpUtil0 {
|
||||
public static String readHttp(String url,String userAgent){
|
||||
HttpURLConnection c=null;
|
||||
try {
|
||||
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()+")");
|
||||
return null;
|
||||
}
|
||||
CustomSkinLoader.logger.info("Successfully read (Response Code: "+c.getResponseCode()+" , Content Length: "+c.getContentLength()+")");
|
||||
InputStream is = c.getInputStream();
|
||||
return IOUtils.toString(is, Charsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
CustomSkinLoader.logger.info("Failed to read (Exception: "+e.getMessage()+")");
|
||||
return null;
|
||||
} finally {
|
||||
if(c!=null)
|
||||
c.disconnect();
|
||||
}
|
||||
CustomSkinLoader.logger.info("Try to read '"+url+(userAgent==null?" without user agent.":"' 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()+")");
|
||||
return null;
|
||||
}
|
||||
CustomSkinLoader.logger.info("Successfully read (Response Code: "+c.getResponseCode()+" , Content Length: "+c.getContentLength()+")");
|
||||
InputStream is = c.getInputStream();
|
||||
return IOUtils.toString(is, Charsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
CustomSkinLoader.logger.info("Failed to read (Exception: "+e.getMessage()+")");
|
||||
return null;
|
||||
} finally {
|
||||
if(c!=null)
|
||||
c.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url after redirect.
|
||||
* Get faked url after redirect.
|
||||
* 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
|
||||
* @return url - faked after redirect (null for not exist)
|
||||
* @since 14.1
|
||||
*/
|
||||
public static String getRealUrl(String url,String userAgent){
|
||||
public static String getFakeUrl(String url,String userAgent){
|
||||
HttpURLConnection c=null;
|
||||
try {
|
||||
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()+")");
|
||||
return null;
|
||||
}
|
||||
CustomSkinLoader.logger.info("Successfully get real url ("
|
||||
+ "Response Code: "+c.getResponseCode()+" , "
|
||||
+ "Content Length: "+c.getContentLength()+" , "
|
||||
+ "Real URL: "+c.getURL().toString()+")");
|
||||
return c.getURL().toString();
|
||||
} catch (Exception e) {
|
||||
CustomSkinLoader.logger.info("Failed to get real url (Exception: "+e.getMessage()+")");
|
||||
return null;
|
||||
} finally{
|
||||
if(c!=null)
|
||||
c.disconnect();
|
||||
}
|
||||
CustomSkinLoader.logger.info("Try to get fake 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 fake url (Response Code: "+c.getResponseCode()+")");
|
||||
return null;
|
||||
}
|
||||
String url1=c.getURL().toString();
|
||||
CustomSkinLoader.logger.info("Successfully get fake url ("
|
||||
+ "Response Code: "+c.getResponseCode()+" , "
|
||||
+ "Content Length: "+c.getContentLength()+" , "
|
||||
+ "Real URL: "+url1+")");
|
||||
return HttpTextureUtil.getLegacyFakeUrl(url1, HttpTextureUtil.getHash(url1, c.getContentLength(), c.getLastModified()));
|
||||
} catch (Exception e) {
|
||||
CustomSkinLoader.logger.info("Failed to get fake url (Exception: "+e.getMessage()+")");
|
||||
return null;
|
||||
} finally{
|
||||
if(c!=null)
|
||||
c.disconnect();
|
||||
}
|
||||
}
|
||||
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();
|
||||
return c;
|
||||
c.setReadTimeout(1000 * 10);
|
||||
c.setConnectTimeout(1000 * 10);
|
||||
if(userAgent!=null)
|
||||
c.setRequestProperty("User-Agent",userAgent);
|
||||
c.setUseCaches(false);
|
||||
c.setInstanceFollowRedirects(true);
|
||||
c.connect();
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -68,4 +68,16 @@ public class MinecraftUtil {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static boolean isCoreFile(URL url){
|
||||
Matcher m = null;
|
||||
try{
|
||||
m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
if(m==null)
|
||||
return false;
|
||||
return m.matches();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package customskinloader.utils;
|
||||
|
||||
public class TimeUtil {
|
||||
public static long getCurrentUnixTimestamp(){
|
||||
return System.currentTimeMillis()/1000l;
|
||||
}
|
||||
public static long getUnixTimestamp(long offset){
|
||||
return getCurrentUnixTimestamp()+offset;
|
||||
}
|
||||
public static long getUnixTimestampRandomDelay(long offset){
|
||||
return getCurrentUnixTimestamp()+offset+random(0,5);
|
||||
}
|
||||
|
||||
private static int random(int min,int max){
|
||||
return (int)(Math.random()*(max-min+1))+min;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user