Compare commits

...
Author SHA1 Message Date
Alexander Xia e9926cb292 Fix cache bug
Log more
2016-02-10 16:33:06 +08:00
Alexander Xia 09010f7fe5 1.8.8 2016-02-05 13:11:12 +08:00
Alexander Xia d8518588f2 Fix support for latest optifine 2016-02-03 19:00:52 +08:00
Alexander Xia cd72b9c484 fix 1.8 skin parse bug 2016-02-03 18:16:36 +08:00
Alexander Xia ddc11864fb Fix Mistakes 2016-02-03 17:53:37 +08:00
Alexander Xia 46f0167f72 Remove GUI 2016-02-03 14:51:15 +08:00
xfl03 35432b9791 Double layer skin support for 1.8-
Use Alex model in 1.8
2015-08-22 15:42:04 +08:00
xfl03 6207dc49f5 More Install Ways 2015-08-08 23:49:09 +08:00
xfl03 2e59f9db7c Better cache, less code 2015-08-01 22:15:14 +08:00
xfl03 f7b34f6296 Fix optine bug for 1.7.10 2015-07-01 21:36:09 +08:00
xfl03 c1d1528a96 Better and better cache (Use index) 2015-06-21 23:36:27 +08:00
xfl03 d446ef3863 Support optifine 2015-06-20 20:37:01 +08:00
xfl03 c786185b18 1.6.4 2015-06-07 11:44:53 +08:00
xfl03 bcbe2d2813 1.8 Support 2015-06-07 10:20:31 +08:00
xfl03 99779ceb90 fix a small bug about cache 2015-06-07 09:01:48 +08:00
xfl03 9b0837f313 Fix temp bug
in package GUI
2015-06-06 23:24:49 +08:00
xfl03 c0edc5c670 1.7.10 support 2015-06-06 17:55:23 +08:00
xfl03 e4e976dacc Better local storage
All things in a folder
Better logger
2015-06-05 22:47:45 +08:00
xfl03 2007ce5c70 Add function: load skin offline 2015-05-31 11:52:03 +08:00
Alexander Xia b303e43634 Update README.md 2014-05-01 10:59:08 +08:00
Alexander Xia 6225fd5aff GPL v3 2014-05-01 10:57:01 +08:00
xfl03 47d1259562 1.7.7 1.7.8 1.7.9 2014-04-28 18:08:02 +08:00
xfl03 a5c7413f99 1.7.6 supported..........Test only 2014-04-25 20:14:00 +08:00
xfl03 e702945538 Suppose 1.7.5!! 2014-04-25 19:09:15 +08:00
xfl03 0476bf25a8 1.7.4
Update to 1.7.4~~
2014-04-24 20:18:30 +08:00
xfl03 d228ae595b Update GUI 2014-04-23 20:08:09 +08:00
xfl03 1fbd41baa6 Add notice when open GUI 2014-04-22 17:49:08 +08:00
xfl03 68d4844b7f 10th revision
Try to recompile....
Fix some issues and lots of grammar mistakes
Add downloading GUI to edit urls
I will test it soon:)
2014-04-20 13:47:54 +08:00
xfl03 bc32560433 10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)10th revision
Add downloading GUI to edit Urls
Fix some issues....
Try to decompile
I will test it soon:)
2014-04-20 13:41:30 +08:00
xfl03 48c3b48bcb Add downloading GUI to edit URLS 2014-04-20 13:40:15 +08:00
xfl03 e576cee191 Remove Same URL 9.2
In old versions,
even though url repeated in skinurls/clokeurls,
it will be loaded again
2014-04-20 12:31:13 +08:00
xfl03 06c3dbb271 Ignore urls that are empty:) Still 9.2
Small Update.....
Only wants to fix some mistakes in coding
Just like meanless "\n"
It is not easy to remove.
2014-04-20 12:15:13 +08:00
xfl03 350904aeaf Fix a small issue made by myself.....
Forget to return URLS
2014-04-20 12:04:13 +08:00
xfl03 4d469e9d78 9th revision 2th subversion
Ignore Comment in SkinUrls/ClokeUrls
2014-04-20 11:58:46 +08:00
59 changed files with 7030 additions and 66 deletions

No files matched your search

@@ -0,0 +1,357 @@
package idv.jlchntoz;
import net.minecraft.src.Minecraft;
import java.io.*;
import java.math.BigInteger;
import java.net.*;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 12th Revision 9th Subversion 2016.2.10
*
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
*/
public class CustomSkinLoader {
public final static String VERSION="12.9";
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newResPattern = Pattern.compile("^http://textures.minecraft.net/texture/(.*?)?(Skin|Cloak)=(.*?)$"),
newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$"),
optifineCapeURLPattern = Pattern.compile("^http://s.optifine.net/capes/(.*?).png$");
public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"),
CACHE_DIR=new File(DATA_DIR,"caches"),
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"),
CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt");
public final static MainLogger logger = getLogger(LOG_FILE);
public final static String[] DEFAULT_SKIN_URLS={
"http://skins.minecraft.net/MinecraftSkins/*.png",
"http://minecrack.fr.nf/mc/skinsminecrackd/*.png",
"http://www.skinme.cc/MinecraftSkins/*.png"};
public final static String[] DEFAULT_CAPE_URLS={
"http://skins.minecraft.net/MinecraftCloaks/*.png",
"http://s.optifine.net/capes/*.png",
"http://minecrack.fr.nf/mc/cloaksminecrackd/*.png",
"http://www.skinme.cc/MinecraftCloaks/*.png"};
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
//Entrance
public InputStream getPlayerSkinStream(String path) {
if(!DATA_DIR.exists())
DATA_DIR.mkdir();
if(!CACHE_DIR.exists())
CACHE_DIR.mkdir();
logger.info("Get a request: "+path);
if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api
return getStream(path, false);
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//May be old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}else{
m = newResPattern.matcher(path);
if(m.matches()){
if (m.group(2).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(3));
else if (m.group(2).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(3));
}else{
m = optifineCapeURLPattern.matcher(path);
if(m.matches()){//Optifine Cape
logger.info("Ignore Optifine Cape.");
return null;//Not Load This
}
}
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if ((skinURLs == null|| skinURLs.length <= 0) && (cloakURLs == null || cloakURLs.length <= 0))
refreshSkinURL(); // If the list is blank or null, try to load again.
InputStream S=null;
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
S = getStream(loc, true);
if (S == null){
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin") + " found in " + loc);
}else{
logger.info("Succeessfully load " + (isCloak ? "cloak" : "skin") + " in " + loc);
return S;
}
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
boolean success=false;
File cacheFile=new File(CACHE_DIR,MD5(URL));
boolean alreadyCached=false;
if(cacheFile.exists()&&cacheFile.length()>1){
alreadyCached=true;
logger.info("Cache File Found (LastModified: "+cacheFile.lastModified()+" , Size: "+cacheFile.length()+")");
}
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setReadTimeout(15000);
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
logger.info("Response Code: "+C.getResponseCode());
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful to get skin.
if(C.getContentLength()<=0){//Nothing got
logger.info("Nothing got.");
return null;
}
logger.info("Successfully Get Resource (LastModified: "+C.getLastModified()+" , ContentLength: "+C.getContentLength()+")");
if(alreadyCached && C.getLastModified()==cacheFile.lastModified() && C.getContentLength()==cacheFile.length()){
logger.info("Not Modified.");
return getStreamFromCache(cacheFile);
}
InputStream IS=new BufferedInputStream(C.getInputStream());
if (!CheckPNG){ // If no need to check PNG header, just skip it.
success=true;
saveToCache(IS,cacheFile);
return IS;
}
//logger.info(C.getContentLength()+" "+IS.available());
IS.mark(C.getContentLength()+10);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N' && ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
success=true;
saveToCache(IS,cacheFile);
return IS;
}
}
} catch (Exception ex) {
success=false;
logger.log(Level.WARNING, ex.getMessage());
if(alreadyCached)
return getStreamFromCache(cacheFile);
}finally{
if(!success)
disconnect();
}
return null;
}
private InputStream getStreamFromCache(File cacheFile) {
try{
logger.info("Try load local cache in " + cacheFile.getAbsolutePath());
InputStream in = new FileInputStream(cacheFile);
BufferedInputStream bis=new BufferedInputStream(in);
if(bis.available()<=0){
logger.info("Cannot load local cache in " + cacheFile.getAbsolutePath());
return null;
}else{
logger.info("Successfully load cache in " + cacheFile.getAbsolutePath());
return bis;
}
}catch(Exception e){
logger.log(Level.WARNING, e.getMessage());
return null;
}
}
private void saveToCache(InputStream is,File to){
logger.info("Try save local cache to " + to.getAbsolutePath());
FileOutputStream fs=null;
int times=0;
try{//Save to Local Skin File
if(to.exists()){
to.delete();
}
fs = new FileOutputStream(to);
int byteRead = 0;
byte[] buffer = new byte[1024];
while (( byteRead = is.read(buffer)) != -1) {
times+=byteRead;
fs.write(buffer, 0, byteRead);
if(times>=C.getContentLength()){
//logger.info(times+" "+C.getContentLength());
break;
}
}
if(to.length()>1){
to.setLastModified(C.getLastModified());
logger.info("Cache saved to " + to.getAbsolutePath()+" (LastModified: "+to.lastModified()+" , Size: "+to.length()+")");
}else{
to.delete();
logger.info("Cannot save local cache to " + to.getAbsolutePath());
}
}catch(Exception e){
logger.warning(e.getMessage());
}finally{
try {
if(fs!=null)
fs.close();
is.reset();
} catch (IOException e) {
logger.warning(e.getMessage());
}
}
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
if(!SKIN_URL_FILE.exists()){
logger.log(Level.INFO, "SKIN config not found, create a new one.");
SKIN_URL_FILE.createNewFile();
}
if(!CAPE_URL_FILE.exists()){
logger.log(Level.INFO, "CAPE config not found, create a new one.");
CAPE_URL_FILE.createNewFile();
}
skinURLs = readAllLines(SKIN_URL_FILE);
cloakURLs = readAllLines(CAPE_URL_FILE);
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
if(skinURLs.length==0&&cloakURLs.length==0){
logger.info("No skinURLs and cloak URLS found, try to init and use default settings.");
initSkinURL();
refreshSkinURL();
}else{
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
}
private static void initSkinURL(){
//Init URL List
skinURLs=DEFAULT_SKIN_URLS;
writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs));
cloakURLs=DEFAULT_CAPE_URLS;
writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs));
}
private static String[] readAllLines(File F) {
try {
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))//Remove note
re[i]=null;
else{//Remove same URL
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
private static String parseArrayToText(String[] data){
StringBuilder temp=new StringBuilder();
for(int i=0;i<data.length-1;i++)
temp.append(data[i]).append("\r\n");
temp.append(data[data.length-1]);
return temp.toString();
}
private static boolean writeToFile(File file,String Data){
System.out.print("Write to "+file.getAbsolutePath()+" ");
FileWriter fw=null;
try{
fw = new FileWriter(file);
fw.write(Data,0,Data.length());
fw.flush();
fw.close();
}catch(Exception ex){
ex.printStackTrace();
System.out.println("failed.");
return false;
}
System.out.println("succeed.");
return true;
}
public String MD5(String str){
byte [] buf = str.getBytes();
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(buf);
byte [] tmp = md5.digest();
StringBuilder sb = new StringBuilder();
for (byte b:tmp) {
sb.append(Integer.toHexString(b&0xff));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
logger.warning(e.getMessage());
}
return "Fail";
}
private static MainLogger getLogger(File logFile){
MainLogger mainLogger = new MainLogger(logFile);
mainLogger.info("CustomSkinLoader " + VERSION);
return mainLogger;
}
}
@@ -0,0 +1,71 @@
package idv.jlchntoz;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
public class MainLogger {
private static final int LOWEST_DISPLAY_LEVEL=Level.INFO.intValue();
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private BufferedWriter writer;
public MainLogger(File logFile){
try {
if(!logFile.getParentFile().exists()){
logFile.getParentFile().mkdirs();
}
if(!logFile.exists())
logFile.createNewFile();
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(logFile), "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void close(){
if(writer!=null){
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void log(Level level,String msg){
if(level.intValue()>=LOWEST_DISPLAY_LEVEL)
System.out.println(msg);
try {
writer.write("[");
writer.write(DATE_FORMAT.format(new Date()));
writer.write(" ");
writer.write(Thread.currentThread().getName());
writer.write(" ");
writer.write(level.getName());
writer.write("] ");
writer.write(msg);
writer.write("\r\n");
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public void info(String msg){
log(Level.INFO,msg);
}
public void warning(String msg){
log(Level.WARNING,msg);
}
public void warning(Exception e){
log(Level.WARNING,"Exception occurs while running: "+e.getMessage());
StackTraceElement[] stes=e.getStackTrace();
for(StackTraceElement ste : stes){
log(Level.WARNING,ste.toString());
}
log(Level.WARNING,"");
}
}
@@ -0,0 +1,98 @@
package net.minecraft.src;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
public class ImageBufferDownload implements IImageBuffer
{
private int[] imageData;
private int imageWidth;
private int imageHeight;
public BufferedImage parseUserSkin(BufferedImage par1BufferedImage)
{
if (par1BufferedImage == null)
{
return null;
}
else
{
this.imageWidth = par1BufferedImage.getWidth();//Default: 64
this.imageHeight = par1BufferedImage.getHeight();//Default: 32
BufferedImage var2 = new BufferedImage(this.imageWidth, this.imageWidth / 2, 2);
Graphics var3 = var2.getGraphics();
if(imageWidth == imageHeight){
var3.drawImage(par1BufferedImage, 0, 0, this.imageWidth, this.imageWidth / 2, 0, 0, this.imageWidth, this.imageWidth / 2, (ImageObserver)null);
var3.drawImage(par1BufferedImage, 0, this.imageWidth / 4, this.imageWidth, this.imageWidth / 2, 0, this.imageWidth / 2 , this.imageWidth, this.imageWidth / 4 * 3, (ImageObserver)null);
imageHeight/=2;
}else{
var3.drawImage(par1BufferedImage, 0, 0, (ImageObserver)null);
}
var3.dispose();
this.imageData = ((DataBufferInt)var2.getRaster().getDataBuffer()).getData();
//this.setAreaOpaque(0, 0, 32, 16);
//this.setAreaTransparent(32, 0, 64, 32);
//this.setAreaOpaque(0, 16, 64, 32);
this.setAreaOpaque(0, 0, imageWidth / 2, imageHeight / 2);
this.setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight);
this.setAreaOpaque(0, imageHeight / 2, imageWidth, imageHeight);
return var2;
}
}
/**
* Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
* layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
* maker is just using an image editor without an alpha channel)
*/
private void setAreaTransparent(int par1, int par2, int par3, int par4)
{
if (!this.hasTransparency(par1, par2, par3, par4))
{
for (int var5 = par1; var5 < par3; ++var5)
{
for (int var6 = par2; var6 < par4; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] &= 16777215;
}
}
}
}
/**
* Makes the given area of the image opaque
*/
private void setAreaOpaque(int par1, int par2, int par3, int par4)
{
for (int var5 = par1; var5 < par3; ++var5)
{
for (int var6 = par2; var6 < par4; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] |= -16777216;
}
}
}
/**
* Returns true if the given area of the image contains transparent pixels
*/
private boolean hasTransparency(int par1, int par2, int par3, int par4)
{
for (int var5 = par1; var5 < par3; ++var5)
{
for (int var6 = par2; var6 < par4; ++var6)
{
int var7 = this.imageData[var5 + var6 * this.imageWidth];
if ((var7 >> 24 & 255) < 128)
{
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,81 @@
package net.minecraft.src;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class ThreadDownloadImageData extends AbstractTexture
{
private final String imageUrl;
private final IImageBuffer imageBuffer;
private BufferedImage bufferedImage;
private Thread imageThread;
private SimpleTexture imageLocation;
private boolean textureUploaded;
public boolean enabled;//For Optifine
public ThreadDownloadImageData(String par1Str, ResourceLocation par2ResourceLocation, IImageBuffer par3IImageBuffer)
{
this.imageUrl = par1Str;
this.imageBuffer = par3IImageBuffer;
this.imageLocation = par2ResourceLocation != null ? new SimpleTexture(par2ResourceLocation) : null;
}
public int getGlTextureId()
{
int var1 = super.getGlTextureId();
if (!this.textureUploaded && this.bufferedImage != null)
{
TextureUtil.uploadTextureImage(var1, this.bufferedImage);
this.textureUploaded = true;
}
return var1;
}
public void getBufferedImage(BufferedImage par1BufferedImage)
{
this.bufferedImage = par1BufferedImage;
}
public void loadTexture(ResourceManager par1ResourceManager) throws IOException
{
if (this.bufferedImage == null)
{
if (this.imageLocation != null)
{
this.imageLocation.loadTexture(par1ResourceManager);
this.glTextureId = this.imageLocation.getGlTextureId();
}
}
else
{
TextureUtil.uploadTextureImage(this.getGlTextureId(), this.bufferedImage);
}
if (this.imageThread == null)
{
this.imageThread = new ThreadDownloadImageDataINNER1(this);
this.imageThread.setDaemon(true);
//this.imageThread.setName("Skin downloader: " + this.imageUrl);
this.imageThread.start();
}
}
public boolean isTextureUploaded()
{
this.getGlTextureId();
return this.textureUploaded;
}
static String getImageUrl(ThreadDownloadImageData par0ThreadDownloadImageData)
{
return par0ThreadDownloadImageData.imageUrl;
}
static IImageBuffer getImageBuffer(ThreadDownloadImageData par0ThreadDownloadImageData)
{
return par0ThreadDownloadImageData.imageBuffer;
}
}
@@ -0,0 +1,63 @@
package net.minecraft.src;
import idv.jlchntoz.CustomSkinLoader;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
class ThreadDownloadImageDataINNER1 extends Thread
{
final ThreadDownloadImageData theThreadDownloadImageData;
ThreadDownloadImageDataINNER1(ThreadDownloadImageData par1ThreadDownloadImageData)
{
this.theThreadDownloadImageData = par1ThreadDownloadImageData;
}
public void run()
{
//HttpURLConnection var1 = null;
CustomSkinLoader loader=new CustomSkinLoader();
try
{
/*
var1 = (HttpURLConnection)(new URL(ThreadDownloadImageData.getImageUrl(this.theThreadDownloadImageData))).openConnection(Minecraft.getMinecraft().getProxy());
var1.setDoInput(true);
var1.setDoOutput(false);
var1.connect();
if (var1.getResponseCode() / 100 != 2)
{
return;
}
BufferedImage var2 = ImageIO.read(var1.getInputStream());
*/
BufferedImage var2 = ImageIO.read(loader.getPlayerSkinStream(
ThreadDownloadImageData.getImageUrl(this.theThreadDownloadImageData)));
if (ThreadDownloadImageData.getImageBuffer(this.theThreadDownloadImageData) != null)
{
var2 = ThreadDownloadImageData.getImageBuffer(this.theThreadDownloadImageData).parseUserSkin(var2);
}
this.theThreadDownloadImageData.getBufferedImage(var2);
}
catch (Exception var6)
{
var6.printStackTrace();
}
finally
{
/*
if (var1 != null)
{
var1.disconnect();
}*/
loader.disconnect();
}
}
}
@@ -0,0 +1,359 @@
package idv.jlchntoz;
import net.minecraft.client.Minecraft;
import java.io.*;
import java.math.BigInteger;
import java.net.*;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 12th Revision 8th Subversion 2016.2.3
*
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
*/
public class CustomSkinLoader {
public final static String VERSION="12.8";
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newResPattern = Pattern.compile("^http://textures.minecraft.net/texture/(.*?)?(Skin|Cloak)=(.*?)$"),
newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$"),
optifineCapeURLPattern = Pattern.compile("^http://s.optifine.net/capes/(.*?).png$");
public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"),
CACHE_DIR=new File(DATA_DIR,"caches"),
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"),
CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt");
public final static MainLogger logger = getLogger(LOG_FILE);
public final static String[] DEFAULT_SKIN_URLS={
"http://skins.minecraft.net/MinecraftSkins/*.png",
"http://minecrack.fr.nf/mc/skinsminecrackd/*.png",
"http://www.skinme.cc/MinecraftSkins/*.png"};
public final static String[] DEFAULT_CAPE_URLS={
"http://skins.minecraft.net/MinecraftCloaks/*.png",
"http://s.optifine.net/capes/*.png",
"http://minecrack.fr.nf/mc/cloaksminecrackd/*.png",
"http://www.skinme.cc/MinecraftCloaks/*.png"};
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
//Entrance
public InputStream getPlayerSkinStream(String path) {
if(!DATA_DIR.exists())
DATA_DIR.mkdir();
if(!CACHE_DIR.exists())
CACHE_DIR.mkdir();
logger.info("Get a request: "+path);
if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api
return getStream(path, false);
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//May be old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}else{
m = newResPattern.matcher(path);
if(m.matches()){
if (m.group(2).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(3));
else if (m.group(2).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(3));
}else{
m = optifineCapeURLPattern.matcher(path);
if(m.matches()){//Optifine Cape
logger.info("Ignore Optifine Cape.");
return null;//Not Load This
}
}
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load again.
InputStream S=null;
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
S = getStream(loc, true);
if (S == null){
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin") + " found in " + loc);
}else{
logger.info("Succeessfully load " + (isCloak ? "cloak" : "skin") + " in " + loc);
return S;
}
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
boolean success=false;
File cacheFile=new File(CACHE_DIR,MD5(URL));
boolean alreadyCached=false;
if(cacheFile.exists()&&cacheFile.length()>1){
alreadyCached=true;
logger.info("Cache File Found");
}
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setReadTimeout(15000);
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
logger.info("Response Code: "+C.getResponseCode());
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful to get skin.
if(alreadyCached && C.getLastModified()==cacheFile.lastModified()){
logger.info("Not Modified!");
return getStreamFromCache(cacheFile);
}
if(C.getContentLength()<=0){//Nothing to get
return null;
}
InputStream IS=new BufferedInputStream(C.getInputStream());
if (!CheckPNG){ // If no need to check PNG header, just skip it.
success=true;
saveToCache(IS,cacheFile);
return IS;
}
//logger.info(C.getContentLength()+" "+IS.available());
IS.mark(C.getContentLength()+10);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N' && ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
success=true;
saveToCache(IS,cacheFile);
return IS;
}
}
} catch (Exception ex) {
success=false;
logger.log(Level.WARNING, ex.getMessage());
if(alreadyCached)
return getStreamFromCache(cacheFile);
}finally{
if(!success)
disconnect();
}
return null;
}
private InputStream getStreamFromCache(File cacheFile) {
try{
logger.info("Try load local cache in " + cacheFile.getAbsolutePath());
InputStream in = new FileInputStream(cacheFile);
BufferedInputStream bis=new BufferedInputStream(in);
if(bis.available()<=0){
logger.info("Cannot load local cache in " + cacheFile.getAbsolutePath());
return null;
}else{
logger.info("Successfully load cache in " + cacheFile.getAbsolutePath());
return bis;
}
}catch(Exception e){
logger.log(Level.WARNING, e.getMessage());
return null;
}
}
private void saveToCache(InputStream is,File to){
logger.info("Try save local cache to " + to.getAbsolutePath());
FileOutputStream fs=null;
int times=0;
try{//Save to Local Skin File
if(to.exists()){
to.delete();
}
fs = new FileOutputStream(to);
int byteRead = 0;
byte[] buffer = new byte[1024];
while (( byteRead = is.read(buffer)) != -1) {
times+=byteRead;
fs.write(buffer, 0, byteRead);
if(times>=C.getContentLength()){
//logger.info(times+" "+C.getContentLength());
break;
}
}
if(to.length()>1){
logger.info("Successfully save cache to " + to.getAbsolutePath());
}else{
to.delete();
logger.info("Cannot save local cache to " + to.getAbsolutePath());
}
}catch(Exception e){
logger.warning(e.getMessage());
}finally{
try {
if(fs!=null)
fs.close();
is.reset();
logger.info("Cache size : "+is.available());
} catch (IOException e) {
logger.warning(e.getMessage());
}
if(to.exists()){
to.setLastModified(C.getLastModified());
}
}
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
if(!SKIN_URL_FILE.exists()){
logger.log(Level.INFO, "SKIN config not found, create a new one.");
SKIN_URL_FILE.createNewFile();
}
if(!CAPE_URL_FILE.exists()){
logger.log(Level.INFO, "CAPE config not found, create a new one.");
CAPE_URL_FILE.createNewFile();
}
skinURLs = readAllLines(SKIN_URL_FILE);
cloakURLs = readAllLines(CAPE_URL_FILE);
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
if(skinURLs.length==0&&cloakURLs.length==0){
logger.info("No skinURLs and cloak URLS found, try to init and use default settings.");
initSkinURL();
refreshSkinURL();
}else{
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
}
private static void initSkinURL(){
//TODO Init URL List
skinURLs=DEFAULT_SKIN_URLS;
writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs));
cloakURLs=DEFAULT_CAPE_URLS;
writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs));
}
private static String[] readAllLines(File F) {
try {
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))//Remove note
re[i]=null;
else{//Remove same URL
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
private static String parseArrayToText(String[] data){
StringBuilder temp=new StringBuilder();
for(int i=0;i<data.length-1;i++)
temp.append(data[i]).append("\r\n");
temp.append(data[data.length-1]);
return temp.toString();
}
private static boolean writeToFile(File file,String Data){
System.out.print("Write to "+file.getAbsolutePath()+" ");
FileWriter fw=null;
try{
fw = new FileWriter(file);
fw.write(Data,0,Data.length());
fw.flush();
fw.close();
}catch(Exception ex){
ex.printStackTrace();
System.out.println("failed.");
return false;
}
System.out.println("succeed.");
return true;
}
public String MD5(String str){
byte [] buf = str.getBytes();
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(buf);
byte [] tmp = md5.digest();
StringBuilder sb = new StringBuilder();
for (byte b:tmp) {
sb.append(Integer.toHexString(b&0xff));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
logger.warning(e.getMessage());
}
return "Fail";
}
private static MainLogger getLogger(File logFile){
MainLogger mainLogger = new MainLogger(logFile);
mainLogger.info("CustomSkinLoader " + VERSION);
return mainLogger;
}
}
@@ -0,0 +1,71 @@
package idv.jlchntoz;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
public class MainLogger {
private static final int LOWEST_DISPLAY_LEVEL=Level.INFO.intValue();
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private BufferedWriter writer;
public MainLogger(File logFile){
try {
if(!logFile.getParentFile().exists()){
logFile.getParentFile().mkdirs();
}
if(!logFile.exists())
logFile.createNewFile();
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(logFile), "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void close(){
if(writer!=null){
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void log(Level level,String msg){
if(level.intValue()>=LOWEST_DISPLAY_LEVEL)
System.out.println(msg);
try {
writer.write("[");
writer.write(DATE_FORMAT.format(new Date()));
writer.write(" ");
writer.write(Thread.currentThread().getName());
writer.write(" ");
writer.write(level.getName());
writer.write("] ");
writer.write(msg);
writer.write("\r\n");
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public void info(String msg){
log(Level.INFO,msg);
}
public void warning(String msg){
log(Level.WARNING,msg);
}
public void warning(Exception e){
log(Level.WARNING,"Exception occurs while running: "+e.getMessage());
StackTraceElement[] stes=e.getStackTrace();
for(StackTraceElement ste : stes){
log(Level.WARNING,ste.toString());
}
log(Level.WARNING,"");
}
}
@@ -0,0 +1,101 @@
package net.minecraft.client.renderer;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
public class ImageBufferDownload implements IImageBuffer
{
private int[] imageData;
private int imageWidth;
private int imageHeight;
private static final String __OBFID = "CL_00000956";
public BufferedImage parseUserSkin(BufferedImage p_78432_1_)
{
if (p_78432_1_ == null)
{
return null;
}
else
{
this.imageWidth = p_78432_1_.getWidth();//Default: 64
this.imageHeight = p_78432_1_.getHeight();//Default: 32
BufferedImage var2 = new BufferedImage(this.imageWidth, this.imageWidth / 2, 2);
Graphics var3 = var2.getGraphics();
if(imageWidth == imageHeight){
var3.drawImage(p_78432_1_, 0, 0, this.imageWidth, this.imageWidth / 2, 0, 0, this.imageWidth, this.imageWidth / 2, (ImageObserver)null);
var3.drawImage(p_78432_1_, 0, this.imageWidth / 4, this.imageWidth, this.imageWidth / 2, 0, this.imageWidth / 2 , this.imageWidth, this.imageWidth / 4 * 3, (ImageObserver)null);
imageHeight/=2;
}else{
var3.drawImage(p_78432_1_, 0, 0, (ImageObserver)null);
}
var3.dispose();
this.imageData = ((DataBufferInt)var2.getRaster().getDataBuffer()).getData();
//this.setAreaOpaque(0, 0, 32, 16);
//this.setAreaTransparent(32, 0, 64, 32);
//this.setAreaOpaque(0, 16, 64, 32);
this.setAreaOpaque(0, 0, imageWidth / 2, imageHeight / 2);
this.setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight);
this.setAreaOpaque(0, imageHeight / 2, imageWidth, imageHeight);
return var2;
}
}
public void func_152634_a() {}
/**
* Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
* layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
* maker is just using an image editor without an alpha channel)
*/
private void setAreaTransparent(int p_78434_1_, int p_78434_2_, int p_78434_3_, int p_78434_4_)
{
if (!this.hasTransparency(p_78434_1_, p_78434_2_, p_78434_3_, p_78434_4_))
{
for (int var5 = p_78434_1_; var5 < p_78434_3_; ++var5)
{
for (int var6 = p_78434_2_; var6 < p_78434_4_; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] &= 16777215;
}
}
}
}
/**
* Makes the given area of the image opaque
*/
private void setAreaOpaque(int p_78433_1_, int p_78433_2_, int p_78433_3_, int p_78433_4_)
{
for (int var5 = p_78433_1_; var5 < p_78433_3_; ++var5)
{
for (int var6 = p_78433_2_; var6 < p_78433_4_; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] |= -16777216;
}
}
}
/**
* Returns true if the given area of the image contains transparent pixels
*/
private boolean hasTransparency(int p_78435_1_, int p_78435_2_, int p_78435_3_, int p_78435_4_)
{
for (int var5 = p_78435_1_; var5 < p_78435_3_; ++var5)
{
for (int var6 = p_78435_2_; var6 < p_78435_4_; ++var6)
{
int var7 = this.imageData[var5 + var6 * this.imageWidth];
if ((var7 >> 24 & 255) < 128)
{
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,158 @@
package net.minecraft.client.renderer;
import idv.jlchntoz.CustomSkinLoader;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ThreadDownloadImageData extends SimpleTexture
{
private static final Logger logger = LogManager.getLogger();
private static final AtomicInteger field_147643_d = new AtomicInteger(0);
private final File field_152434_e;
private final String imageUrl;
private final IImageBuffer imageBuffer;
private BufferedImage bufferedImage;
private Thread imageThread;
private boolean textureUploaded;
private static final String __OBFID = "CL_00001049";
//For Optifine
public Boolean imageFound = null;
public boolean pipeline = false;
public ThreadDownloadImageData(File p_i1049_1_, String p_i1049_2_, ResourceLocation p_i1049_3_, IImageBuffer p_i1049_4_)
{
super(p_i1049_3_);
this.field_152434_e = p_i1049_1_;
this.imageUrl = p_i1049_2_;
this.imageBuffer = p_i1049_4_;
}
private void func_147640_e()
{
if (!this.textureUploaded)
{
if (this.bufferedImage != null)
{
if (this.textureLocation != null)
{
this.func_147631_c();
}
TextureUtil.uploadTextureImage(super.getGlTextureId(), this.bufferedImage);
this.textureUploaded = true;
}
}
}
public int getGlTextureId()
{
this.func_147640_e();
return super.getGlTextureId();
}
public void func_147641_a(BufferedImage p_147641_1_)
{
this.bufferedImage = p_147641_1_;
if (this.imageBuffer != null)
{
this.imageBuffer.func_152634_a();
}
}
public void loadTexture(IResourceManager p_110551_1_) throws IOException
{
if (this.bufferedImage == null && this.textureLocation != null)
{
super.loadTexture(p_110551_1_);
}
if (this.imageThread == null)
{
if (this.field_152434_e != null && this.field_152434_e.isFile())
{
logger.debug("Loading http texture from local cache ({})", new Object[] {this.field_152434_e});
try
{
this.bufferedImage = ImageIO.read(this.field_152434_e);
if (this.imageBuffer != null)
{
this.func_147641_a(this.imageBuffer.parseUserSkin(this.bufferedImage));
}
}
catch (IOException var3)
{
logger.error("Couldn\'t load skin " + this.field_152434_e, var3);
this.func_152433_a();
}
}
else
{
this.func_152433_a();
}
}
}
protected void func_152433_a()
{
this.imageThread = new Thread("Texture Downloader #" + field_147643_d.incrementAndGet())
{
private static final String __OBFID = "CL_00001050";
public void run()
{
ThreadDownloadImageData.logger.debug("Downloading http texture from {} to {}", new Object[] {ThreadDownloadImageData.this.imageUrl, ThreadDownloadImageData.this.field_152434_e});
try
{
CustomSkinLoader loader=new CustomSkinLoader();
InputStream var9=loader.getPlayerSkinStream(ThreadDownloadImageData.this.imageUrl);
BufferedImage var2;
/*
if (ThreadDownloadImageData.this.field_152434_e != null)
{
FileUtils.copyInputStreamToFile(var9, ThreadDownloadImageData.this.field_152434_e);
var2 = ImageIO.read(ThreadDownloadImageData.this.field_152434_e);
}
else
{
}*/
var2 = ImageIO.read(var9);
if (ThreadDownloadImageData.this.imageBuffer != null)
{
var2 = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(var2);
}
ThreadDownloadImageData.this.func_147641_a(var2);
loader.disconnect();
}
catch (Exception var6)
{
ThreadDownloadImageData.logger.error("Couldn\'t download http texture", var6);
}
}
};
this.imageThread.setDaemon(true);
this.imageThread.start();
}
}
@@ -0,0 +1,178 @@
package net.minecraft.client.resources;
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.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.ImageBufferDownload;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
public class SkinManager
{
public static final ResourceLocation field_152793_a = new ResourceLocation("textures/entity/steve.png");
private static final ExecutorService field_152794_b = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());
private final TextureManager field_152795_c;
private final File field_152796_d;
private final MinecraftSessionService field_152797_e;
private final LoadingCache field_152798_f;
private static final String __OBFID = "CL_00001830";
public SkinManager(TextureManager p_i1044_1_, File p_i1044_2_, MinecraftSessionService p_i1044_3_)
{
this.field_152795_c = p_i1044_1_;
this.field_152796_d = p_i1044_2_;
this.field_152797_e = p_i1044_3_;
this.field_152798_f = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).build(new CacheLoader()
{
private static final String __OBFID = "CL_00001829";
public Map func_152786_a(GameProfile p_152786_1_)
{
return Minecraft.getMinecraft().func_152347_ac().getTextures(p_152786_1_, false);
}
public Object load(Object p_load_1_)
{
return this.func_152786_a((GameProfile)p_load_1_);
}
});
}
public ResourceLocation func_152792_a(MinecraftProfileTexture p_152792_1_, Type p_152792_2_)
{
return this.func_152789_a(p_152792_1_, p_152792_2_, (SkinManager.SkinAvailableCallback)null);
}
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(p_152789_2_.name()+"/" + p_152789_1_.getHash());
//ITextureObject var5 = this.field_152795_c.getTexture(var4);
/*
if (var5 != null)
{
if (p_152789_3_ != null)
{
p_152789_3_.func_152121_a(p_152789_2_, var4);
}
}
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()
{
private static final String __OBFID = "CL_00001828";
public BufferedImage parseUserSkin(BufferedImage p_78432_1_)
{
if (var8 != null)
{
p_78432_1_ = var8.parseUserSkin(p_78432_1_);
}
return p_78432_1_;
}
public void func_152634_a()
{
if (var8 != null)
{
var8.func_152634_a();
}
if (p_152789_3_ != null)
{
p_152789_3_.func_152121_a(p_152789_2_, var4);
}
}
});
this.field_152795_c.loadTexture(var4, var9);
//}
return var4;
}
public void func_152790_a(final GameProfile p_152790_1_, final SkinManager.SkinAvailableCallback p_152790_2_, final boolean p_152790_3_)
{
field_152794_b.submit(new Runnable()
{
private static final String __OBFID = "CL_00001827";
public void run()
{
final HashMap var1 = Maps.newHashMap();
try
{
var1.putAll(SkinManager.this.field_152797_e.getTextures(p_152790_1_, p_152790_3_));
}
catch (InsecureTextureException var3)
{
;
}
if (var1.isEmpty() && p_152790_1_.getId().equals(Minecraft.getMinecraft().getSession().func_148256_e().getId()))
{
var1.putAll(SkinManager.this.field_152797_e.getTextures(SkinManager.this.field_152797_e.fillProfileProperties(p_152790_1_, false), false));
}
//CustomSkinLoader Begin
HashMap var2 = Maps.newHashMap();
if (var1.containsKey(Type.SKIN)){
var2.put(Type.SKIN, new MinecraftProfileTexture(((MinecraftProfileTexture)var1.get(Type.SKIN)).getUrl()+"?Skin="+p_152790_1_.getName()));
}else{
var2.put(Type.SKIN,new MinecraftProfileTexture( "http://skins.minecraft.net/MinecraftSkins/"+p_152790_1_.getName()+".png"));
}
if (var1.containsKey(Type.CAPE)){
var2.put(Type.CAPE, new MinecraftProfileTexture(((MinecraftProfileTexture)var1.get(Type.CAPE)).getUrl()+"?Cloak="+p_152790_1_.getName()));
}else{
var2.put(Type.CAPE,new MinecraftProfileTexture( "http://skins.minecraft.net/MinecraftCloaks/"+p_152790_1_.getName()+".png"));
}
var1.clear();
var1.putAll(var2);
//CustomSkinLoader End
Minecraft.getMinecraft().func_152344_a(new Runnable()
{
private static final String __OBFID = "CL_00001826";
public void run()
{
if (var1.containsKey(Type.SKIN))
{
SkinManager.this.func_152789_a((MinecraftProfileTexture)var1.get(Type.SKIN), Type.SKIN, p_152790_2_);
}
if (var1.containsKey(Type.CAPE))
{
SkinManager.this.func_152789_a((MinecraftProfileTexture)var1.get(Type.CAPE), Type.CAPE, p_152790_2_);
}
}
});
}
});
}
public Map func_152788_a(GameProfile p_152788_1_)
{
return (Map)this.field_152798_f.getUnchecked(p_152788_1_);
}
public interface SkinAvailableCallback
{
void func_152121_a(Type p_152121_1_, ResourceLocation p_152121_2_);
}
}
@@ -1,94 +1,229 @@
package idv.jlchntoz;
import net.minecraft.client.Minecraft;
import java.io.*;
import java.math.BigInteger;
import java.net.*;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 9th Revision 2014.4.15
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
* @version 12th Revision 9th Subversion 2016.2.10
*
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
*/
public class CustomSkinLoader {
public final static String VERSION="12.9";
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private final static Pattern newResPattern = Pattern.compile("^http://textures.minecraft.net/texture/(.*?)?(Skin|Cloak)=(.*?)$"),
newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$"),
optifineCapeURLPattern = Pattern.compile("^http://s.optifine.net/capes/(.*?).png$");
public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"),
CACHE_DIR=new File(DATA_DIR,"caches"),
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"),
CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt");
public final static MainLogger logger = getLogger(LOG_FILE);
public final static String[] DEFAULT_SKIN_URLS={
"http://skins.minecraft.net/MinecraftSkins/*.png",
"http://minecrack.fr.nf/mc/skinsminecrackd/*.png",
"http://www.skinme.cc/MinecraftSkins/*.png"};
public final static String[] DEFAULT_CAPE_URLS={
"http://skins.minecraft.net/MinecraftCloaks/*.png",
"http://s.optifine.net/capes/*.png",
"http://minecrack.fr.nf/mc/cloaksminecrackd/*.png",
"http://www.skinme.cc/MinecraftCloaks/*.png"};
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
//Entrance
public InputStream getPlayerSkinStream(String path) {
if(!DATA_DIR.exists())
DATA_DIR.mkdir();
if(!CACHE_DIR.exists())
CACHE_DIR.mkdir();
logger.info("Get a request: "+path);
if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api
return getStream(path, false);
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
m = oldURLPattern.matcher(path);//May be old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}else{
m = newResPattern.matcher(path);
if(m.matches()){
if (m.group(2).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(3));
else if (m.group(2).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(3));
}else{
m = optifineCapeURLPattern.matcher(path);
if(m.matches()){//Optifine Cape
logger.info("Ignore Optifine Cape.");
return null;//Not Load This
}
}
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
if ((skinURLs == null|| skinURLs.length <= 0) && (cloakURLs == null || cloakURLs.length <= 0))
refreshSkinURL(); // If the list is blank or null, try to load again.
InputStream S=null;
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
S = getStream(loc, true);
if (S == null){
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin") + " found in " + loc);
}else{
logger.info("Succeessfully load " + (isCloak ? "cloak" : "skin") + " in " + loc);
return S;
}
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
boolean success=false;
File cacheFile=new File(CACHE_DIR,MD5(URL));
boolean alreadyCached=false;
if(cacheFile.exists()&&cacheFile.length()>1){
alreadyCached=true;
logger.info("Cache File Found (LastModified: "+cacheFile.lastModified()+" , Size: "+cacheFile.length()+")");
}
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setReadTimeout(15000);
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
logger.info("Response Code: "+C.getResponseCode());
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
if (respcode != 4 && respcode != 5) { // Successful to get skin.
if(C.getContentLength()<=0){//Nothing got
logger.info("Nothing got.");
return null;
}
logger.info("Successfully Get Resource (LastModified: "+C.getLastModified()+" , ContentLength: "+C.getContentLength()+")");
if(alreadyCached && C.getLastModified()==cacheFile.lastModified() && C.getContentLength()==cacheFile.length()){
logger.info("Not Modified.");
return getStreamFromCache(cacheFile);
}
InputStream IS=new BufferedInputStream(C.getInputStream());
if (!CheckPNG){ // If no need to check PNG header, just skip it.
success=true;
saveToCache(IS,cacheFile);
return IS;
IS.mark(0);
}
//logger.info(C.getContentLength()+" "+IS.available());
IS.mark(C.getContentLength()+10);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N' && ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
success=true;
saveToCache(IS,cacheFile);
return IS;
}
}
} catch (Exception ex) {
success=false;
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
if(alreadyCached)
return getStreamFromCache(cacheFile);
}finally{
if(!success)
disconnect();
}
return null;
}
private InputStream getStreamFromCache(File cacheFile) {
try{
logger.info("Try load local cache in " + cacheFile.getAbsolutePath());
InputStream in = new FileInputStream(cacheFile);
BufferedInputStream bis=new BufferedInputStream(in);
if(bis.available()<=0){
logger.info("Cannot load local cache in " + cacheFile.getAbsolutePath());
return null;
}else{
logger.info("Successfully load cache in " + cacheFile.getAbsolutePath());
return bis;
}
}catch(Exception e){
logger.log(Level.WARNING, e.getMessage());
return null;
}
}
private void saveToCache(InputStream is,File to){
logger.info("Try save local cache to " + to.getAbsolutePath());
FileOutputStream fs=null;
int times=0;
try{//Save to Local Skin File
if(to.exists()){
to.delete();
}
fs = new FileOutputStream(to);
int byteRead = 0;
byte[] buffer = new byte[1024];
while (( byteRead = is.read(buffer)) != -1) {
times+=byteRead;
fs.write(buffer, 0, byteRead);
if(times>=C.getContentLength()){
//logger.info(times+" "+C.getContentLength());
break;
}
}
if(to.length()>1){
to.setLastModified(C.getLastModified());
logger.info("Cache saved to " + to.getAbsolutePath()+" (LastModified: "+to.lastModified()+" , Size: "+to.length()+")");
}else{
to.delete();
logger.info("Cannot save local cache to " + to.getAbsolutePath());
}
}catch(Exception e){
logger.warning(e.getMessage());
}finally{
try {
if(fs!=null)
fs.close();
is.reset();
} catch (IOException e) {
logger.warning(e.getMessage());
}
}
}
public void disconnect() {
if (C != null)
C.disconnect();
@@ -96,26 +231,41 @@ public class CustomSkinLoader {
private static void refreshSkinURL() {
try {
File mcdir = Minecraft.getMinecraft().mcDataDir;
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
if(!SKIN_URL_FILE.exists()){
logger.log(Level.INFO, "SKIN config not found, create a new one.");
SKIN_URL_FILE.createNewFile();
}
if(!CAPE_URL_FILE.exists()){
logger.log(Level.INFO, "CAPE config not found, create a new one.");
CAPE_URL_FILE.createNewFile();
}
skinURLs = readAllLines(SKIN_URL_FILE);
cloakURLs = readAllLines(CAPE_URL_FILE);
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
if(skinURLs.length==0&&cloakURLs.length==0){
logger.info("No skinURLs and cloak URLS found, try to init and use default settings.");
initSkinURL();
refreshSkinURL();
}else{
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
}
private static void initSkinURL(){
//Init URL List
skinURLs=DEFAULT_SKIN_URLS;
writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs));
cloakURLs=DEFAULT_CAPE_URLS;
writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs));
}
private static String[] readAllLines(File mcdir, String path) {
private static String[] readAllLines(File F) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
F.createNewFile();
return new String[0];
} else if (F.length() <= 0) {
if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
@@ -125,8 +275,23 @@ public class CustomSkinLoader {
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
return str_replace("\r", "\n",
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))//Remove note
re[i]=null;
else{//Remove same URL
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
@@ -142,4 +307,51 @@ public class CustomSkinLoader {
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
private static String parseArrayToText(String[] data){
StringBuilder temp=new StringBuilder();
for(int i=0;i<data.length-1;i++)
temp.append(data[i]).append("\r\n");
temp.append(data[data.length-1]);
return temp.toString();
}
private static boolean writeToFile(File file,String Data){
System.out.print("Write to "+file.getAbsolutePath()+" ");
FileWriter fw=null;
try{
fw = new FileWriter(file);
fw.write(Data,0,Data.length());
fw.flush();
fw.close();
}catch(Exception ex){
ex.printStackTrace();
System.out.println("failed.");
return false;
}
System.out.println("succeed.");
return true;
}
public String MD5(String str){
byte [] buf = str.getBytes();
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(buf);
byte [] tmp = md5.digest();
StringBuilder sb = new StringBuilder();
for (byte b:tmp) {
sb.append(Integer.toHexString(b&0xff));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
logger.warning(e.getMessage());
}
return "Fail";
}
private static MainLogger getLogger(File logFile){
MainLogger mainLogger = new MainLogger(logFile);
mainLogger.info("CustomSkinLoader " + VERSION);
return mainLogger;
}
}
@@ -0,0 +1,71 @@
package idv.jlchntoz;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
public class MainLogger {
private static final int LOWEST_DISPLAY_LEVEL=Level.INFO.intValue();
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private BufferedWriter writer;
public MainLogger(File logFile){
try {
if(!logFile.getParentFile().exists()){
logFile.getParentFile().mkdirs();
}
if(!logFile.exists())
logFile.createNewFile();
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(logFile), "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void close(){
if(writer!=null){
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void log(Level level,String msg){
if(level.intValue()>=LOWEST_DISPLAY_LEVEL)
System.out.println(msg);
try {
writer.write("[");
writer.write(DATE_FORMAT.format(new Date()));
writer.write(" ");
writer.write(Thread.currentThread().getName());
writer.write(" ");
writer.write(level.getName());
writer.write("] ");
writer.write(msg);
writer.write("\r\n");
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public void info(String msg){
log(Level.INFO,msg);
}
public void warning(String msg){
log(Level.WARNING,msg);
}
public void warning(Exception e){
log(Level.WARNING,"Exception occurs while running: "+e.getMessage());
StackTraceElement[] stes=e.getStackTrace();
for(StackTraceElement ste : stes){
log(Level.WARNING,ste.toString());
}
log(Level.WARNING,"");
}
}
@@ -0,0 +1,99 @@
package net.minecraft.client.renderer;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
public class ImageBufferDownload implements IImageBuffer
{
private int[] imageData;
private int imageWidth;
private int imageHeight;
private static final String __OBFID = "CL_00000956";
public BufferedImage parseUserSkin(BufferedImage par1BufferedImage)
{
if (par1BufferedImage == null)
{
return null;
}
else
{
this.imageWidth = par1BufferedImage.getWidth();//Default: 64
this.imageHeight = par1BufferedImage.getHeight();//Default: 32
BufferedImage var2 = new BufferedImage(this.imageWidth, this.imageWidth / 2, 2);
Graphics var3 = var2.getGraphics();
if(imageWidth == imageHeight){
var3.drawImage(par1BufferedImage, 0, 0, this.imageWidth, this.imageWidth / 2, 0, 0, this.imageWidth, this.imageWidth / 2, (ImageObserver)null);
var3.drawImage(par1BufferedImage, 0, this.imageWidth / 4, this.imageWidth, this.imageWidth / 2, 0, this.imageWidth / 2 , this.imageWidth, this.imageWidth / 4 * 3, (ImageObserver)null);
imageHeight/=2;
}else{
var3.drawImage(par1BufferedImage, 0, 0, (ImageObserver)null);
}
var3.dispose();
this.imageData = ((DataBufferInt)var2.getRaster().getDataBuffer()).getData();
//this.setAreaOpaque(0, 0, 32, 16);
//this.setAreaTransparent(32, 0, 64, 32);
//this.setAreaOpaque(0, 16, 64, 32);
this.setAreaOpaque(0, 0, imageWidth / 2, imageHeight / 2);
this.setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight);
this.setAreaOpaque(0, imageHeight / 2, imageWidth, imageHeight);
return var2;
}
}
/**
* Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
* layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
* maker is just using an image editor without an alpha channel)
*/
private void setAreaTransparent(int par1, int par2, int par3, int par4)
{
if (!this.hasTransparency(par1, par2, par3, par4))
{
for (int var5 = par1; var5 < par3; ++var5)
{
for (int var6 = par2; var6 < par4; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] &= 16777215;
}
}
}
}
/**
* Makes the given area of the image opaque
*/
private void setAreaOpaque(int par1, int par2, int par3, int par4)
{
for (int var5 = par1; var5 < par3; ++var5)
{
for (int var6 = par2; var6 < par4; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] |= -16777216;
}
}
}
/**
* Returns true if the given area of the image contains transparent pixels
*/
private boolean hasTransparency(int par1, int par2, int par3, int par4)
{
for (int var5 = par1; var5 < par3; ++var5)
{
for (int var6 = par2; var6 < par4; ++var6)
{
int var7 = this.imageData[var5 + var6 * this.imageWidth];
if ((var7 >> 24 & 255) < 128)
{
return true;
}
}
}
return false;
}
}
@@ -26,6 +26,9 @@ public class ThreadDownloadImageData extends SimpleTexture
private Thread imageThread;
private boolean textureUploaded;
private static final String __OBFID = "CL_00001049";
public CustomSkinLoader customSkinLoader=new CustomSkinLoader();
public boolean enabled;//For Optifine
public ThreadDownloadImageData(String par1Str, ResourceLocation par2ResourceLocation, IImageBuffer par3IImageBuffer)
{
@@ -76,30 +79,25 @@ public class ThreadDownloadImageData extends SimpleTexture
private static final String __OBFID = "CL_00001050";
public void run()
{
try
{
BufferedImage var2 = ImageIO.read(
ThreadDownloadImageData.this.customSkinLoader.getPlayerSkinStream(
ThreadDownloadImageData.this.imageUrl));
if (ThreadDownloadImageData.this.imageBuffer != null){
var2 = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(var2);
}
ThreadDownloadImageData.this.func_147641_a(var2);
customSkinLoader.disconnect();
}catch (Exception var6){
ThreadDownloadImageData.logger.error("Couldn\'t download http texture", var6);
return;
}
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(ThreadDownloadImageData.this.imageUrl));
if (ThreadDownloadImageData.this.imageBuffer != null)
{
var2 = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(var2);
}
ThreadDownloadImageData.this.func_147641_a(var2);
}
catch (Exception var6)
{
ThreadDownloadImageData.logger.error("Couldn\'t download http texture", var6);
return;
}
}
};
}
};
this.imageThread.setDaemon(true);
this.imageThread.setName("Skin downloader: " + this.imageUrl);
//this.imageThread.setName("Skin downloader: " + this.imageUrl);
this.imageThread.start();
}
}
+382
View File
@@ -0,0 +1,382 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import org.lwjgl.opengl.GL11;
public class bpi extends bpa
{
private static final brq a = new brq("textures/entity/steve.png");
private bih f;
private bih g;
private bih h;
public bpi()
{
super(new bih(0.0F), 0.5F);
f = (bih)i;
g = new bih(1.0F);
h = new bih(0.5F);
}
protected int a(bma bma1, int i, float f1)
{
abu abu1 = bma1.bm.d(3 - i);
if (abu1 != null)
{
abs abs1 = abu1.b();
if (abs1 instanceof zs)
{
zs zs1 = (zs)abs1;
a(bop.a(zs1, i));
bih bih1 = i != 2 ? g : h;
bih1.c.j = i == 0;
bih1.d.j = i == 0;
bih1.e.j = i == 1 || i == 2;
bih1.f.j = i == 1;
bih1.g.j = i == 1;
bih1.h.j = i == 2 || i == 3;
bih1.i.j = i == 2 || i == 3;
a(((bim) (bih1)));
bih1.p = this.i.p;
bih1.q = this.i.q;
bih1.s = this.i.s;
if (zs1.m_() == zu.a)
{
int j = zs1.b(abu1);
float f2 = (float)(j >> 16 & 0xff) / 255F;
float f3 = (float)(j >> 8 & 0xff) / 255F;
float f4 = (float)(j & 0xff) / 255F;
GL11.glColor3f(f2, f3, f4);
return !abu1.y() ? 16 : 31;
}
GL11.glColor3f(1.0F, 1.0F, 1.0F);
return !abu1.y() ? 1 : 15;
}
}
return -1;
}
protected void b(bma bma1, int i, float f1)
{
abu abu1 = bma1.bm.d(3 - i);
if (abu1 != null)
{
abs abs1 = abu1.b();
if (abs1 instanceof zs)
{
a(bop.a((zs)abs1, i, "overlay"));
GL11.glColor3f(1.0F, 1.0F, 1.0F);
}
}
}
public void a(bma bma1, double d, double d1, double d2,
float f1, float f2)
{
GL11.glColor3f(1.0F, 1.0F, 1.0F);
abu abu1 = bma1.bm.h();
g.m = h.m = f.m = abu1 == null ? 0 : 1;
if (abu1 != null && bma1.bw() > 0)
{
acz acz1 = abu1.o();
if (acz1 == acz.d)
g.m = h.m = f.m = 3;
else
if (acz1 == acz.e)
g.o = h.o = f.o = true;
}
g.n = h.n = f.n = bma1.am();
double d3 = d1 - (double)bma1.L;
if (bma1.am() && !(bma1 instanceof bmd))
d3 -= 0.125D;
super.a(bma1, d, d3, d2, f1, f2);
g.o = h.o = f.o = false;
g.n = h.n = f.n = false;
g.m = h.m = f.m = 0;
}
protected brq a(bma bma1)
{
return bma1.t();
}
protected void a(bma bma1, float f1)
{
GL11.glColor3f(1.0F, 1.0F, 1.0F);
super.c(bma1, f1);
super.e(bma1, f1);
abu abu1 = bma1.bm.d(3);
if (abu1 != null)
{
GL11.glPushMatrix();
f.c.c(0.0625F);
if (abu1.b() instanceof zy)
{
if (bmf.a(ahz.a(abu1.b()).b()))
{
float f2 = 0.625F;
GL11.glTranslatef(0.0F, -0.25F, 0.0F);
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
GL11.glScalef(f2, -f2, -f2);
}
b.f.a(bma1, abu1, 0);
} else
if (abu1.b() == abv.bL)
{
float f3 = 1.0625F;
GL11.glScalef(f3, -f3, -f3);
String s = "";
if (abu1.p() && abu1.q().b("SkullOwner", 8))
s = abu1.q().j("SkullOwner");
bnl.b.a(-0.5F, 0.0F, -0.5F, 1, 180F, abu1.k(), s);
}
GL11.glPopMatrix();
}
if (bma1.b_().equals("deadmau5") && bma1.r().a())
{
a(bma1.t());
for (int i = 0; i < 2; i++)
{
float f4 = (bma1.A + (bma1.y - bma1.A) * f1) - (bma1.aN + (bma1.aM - bma1.aN) * f1);
float f5 = bma1.B + (bma1.z - bma1.B) * f1;
GL11.glPushMatrix();
GL11.glRotatef(f4, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(f5, 1.0F, 0.0F, 0.0F);
GL11.glTranslatef(0.375F * (float)(i * 2 - 1), 0.0F, 0.0F);
GL11.glTranslatef(0.0F, -0.375F, 0.0F);
GL11.glRotatef(-f5, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(-f4, 0.0F, 1.0F, 0.0F);
float f6 = 1.333333F;
GL11.glScalef(f6, f6, f6);
f.b(0.0625F);
GL11.glPopMatrix();
}
}
boolean flag = bma1.s().a();
if (flag && !bma1.ao() && !bma1.bS())
{
a(bma1.u());
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, 0.0F, 0.125F);
double d = (bma1.bu + (bma1.bx - bma1.bu) * (double)f1) - (bma1.p + (bma1.s - bma1.p) * (double)f1);
double d1 = (bma1.bv + (bma1.by - bma1.bv) * (double)f1) - (bma1.q + (bma1.t - bma1.q) * (double)f1);
double d2 = (bma1.bw + (bma1.bz - bma1.bw) * (double)f1) - (bma1.r + (bma1.u - bma1.r) * (double)f1);
float f16 = bma1.aN + (bma1.aM - bma1.aN) * f1;
double d3 = oy.a((f16 * 3.141593F) / 180F);
double d4 = -oy.b((f16 * 3.141593F) / 180F);
float f18 = (float)d1 * 10F;
if (f18 < -6F)
f18 = -6F;
if (f18 > 32F)
f18 = 32F;
float f19 = (float)(d * d3 + d2 * d4) * 100F;
float f20 = (float)(d * d4 - d2 * d3) * 100F;
if (f19 < 0.0F)
f19 = 0.0F;
float f21 = bma1.br + (bma1.bs - bma1.br) * f1;
f18 += oy.a((bma1.O + (bma1.P - bma1.O) * f1) * 6F) * 32F * f21;
if (bma1.am())
f18 += 25F;
GL11.glRotatef(6F + f19 / 2.0F + f18, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(f20 / 2.0F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(-f20 / 2.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
f.c(0.0625F);
GL11.glPopMatrix();
}
abu abu2 = bma1.bm.h();
if (abu2 != null)
{
GL11.glPushMatrix();
f.f.c(0.0625F);
GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);
if (bma1.bK != null)
abu2 = new abu(abv.y);
acz acz1 = null;
if (bma1.bw() > 0)
acz1 = abu2.o();
if ((abu2.b() instanceof zy) && bmf.a(ahz.a(abu2.b()).b()))
{
float f7 = 0.5F;
GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
f7 *= 0.75F;
GL11.glRotatef(20F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F);
GL11.glScalef(-f7, -f7, f7);
} else
if (abu2.b() == abv.f)
{
float f8 = 0.625F;
GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
GL11.glRotatef(-20F, 0.0F, 1.0F, 0.0F);
GL11.glScalef(f8, -f8, f8);
GL11.glRotatef(-100F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F);
} else
if (abu2.b().f())
{
float f9 = 0.625F;
if (abu2.b().g())
{
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(0.0F, -0.125F, 0.0F);
}
if (bma1.bw() > 0 && acz1 == acz.d)
{
GL11.glTranslatef(0.05F, 0.0F, -0.1F);
GL11.glRotatef(-50F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-10F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(-60F, 0.0F, 0.0F, 1.0F);
}
GL11.glTranslatef(0.0F, 0.1875F, 0.0F);
GL11.glScalef(f9, -f9, f9);
GL11.glRotatef(-100F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F);
} else
{
float f10 = 0.375F;
GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
GL11.glScalef(f10, f10, f10);
GL11.glRotatef(60F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(-90F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(20F, 0.0F, 0.0F, 1.0F);
}
if (abu2.b().b())
{
for (int j = 0; j <= 1; j++)
{
int l = abu2.b().a(abu2, j);
float f12 = (float)(l >> 16 & 0xff) / 255F;
float f14 = (float)(l >> 8 & 0xff) / 255F;
float f17 = (float)(l & 0xff) / 255F;
GL11.glColor4f(f12, f14, f17, 1.0F);
b.f.a(bma1, abu2, j);
}
} else
{
int k = abu2.b().a(abu2, 0);
float f11 = (float)(k >> 16 & 0xff) / 255F;
float f13 = (float)(k >> 8 & 0xff) / 255F;
float f15 = (float)(k & 0xff) / 255F;
GL11.glColor4f(f11, f13, f15, 1.0F);
b.f.a(bma1, abu2, 0);
}
GL11.glPopMatrix();
}
}
protected void b(bma bma1, float f1)
{
float f2 = 0.9375F;
GL11.glScalef(f2, f2, f2);
}
protected void a(bma bma1, double d, double d1, double d2,
String s, float f1, double d3)
{
if (d3 < 100D)
{
ayw ayw1 = bma1.bT();
ayr ayr1 = ayw1.a(2);
if (ayr1 != null)
{
ayt ayt1 = ayw1.a(bma1.b_(), ayr1);
if (bma1.bl())
a(((qr) (bma1)), (new StringBuilder()).append(ayt1.c()).append(" ").append(ayr1.d()).toString(), d, d1 - 1.5D, d2, 64);
else
a(((qr) (bma1)), (new StringBuilder()).append(ayt1.c()).append(" ").append(ayr1.d()).toString(), d, d1, d2, 64);
d1 += (float)c().a * 1.15F * f1;
}
}
super.a(bma1, d, d1, d2, s, f1, d3);
}
public void a(xq xq)
{
float f1 = 1.0F;
GL11.glColor3f(f1, f1, f1);
f.p = 0.0F;
f.a(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, xq);
f.f.a(0.0625F);
}
protected void a(bma bma1, double d, double d1, double d2)
{
if (bma1.Y() && bma1.bl())
super.a(bma1, d + (double)bma1.bC, d1 + (double)bma1.cc, d2 + (double)bma1.bD);
else
super.a(bma1, d, d1, d2);
}
protected void a(bma bma1, float f1, float f2, float f3)
{
if (bma1.Y() && bma1.bl())
{
GL11.glRotatef(bma1.bJ(), 0.0F, 1.0F, 0.0F);
GL11.glRotatef(a(((rm) (bma1))), 0.0F, 0.0F, 1.0F);
GL11.glRotatef(270F, 0.0F, 1.0F, 0.0F);
} else
{
super.a(bma1, f1, f2, f3);
}
}
protected volatile void a(rm rm, double d, double d1, double d2,
String s, float f1, double d3)
{
a((bma)rm, d, d1, d2, s, f1, d3);
}
protected void a(rm rm, float f1)
{
b((bma)rm, f1);
}
protected void c(rm rm, int i, float f1)
{
b((bma)rm, i, f1);
}
protected volatile int a(rm rm, int i, float f1)
{
return a((bma)rm, i, f1);
}
protected void c(rm rm, float f1)
{
a((bma)rm, f1);
}
protected volatile void a(rm rm, float f1, float f2, float f3)
{
a((bma)rm, f1, f2, f3);
}
protected volatile void a(rm rm, double d, double d1, double d2)
{
a((bma)rm, d, d1, d2);
}
public volatile void a(rm rm, double d, double d1, double d2,
float f1, float f2)
{
a((bma)rm, d, d1, d2, f1, f2);
}
protected volatile brq a(qr qr)
{
return a((bma)qr);
}
public volatile void a(qr qr, double d, double d1, double d2,
float f1, float f2)
{
a((bma)qr, d, d1, d2, f1, f2);
}
}
+80
View File
@@ -0,0 +1,80 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.util.concurrent.atomic.AtomicInteger;
public class bqk extends bqn
{
private static final AtomicInteger d = new AtomicInteger(0);
private final String e;
private final bmq f;
private BufferedImage g;
private Thread h;
private boolean i;
public bqk(String s, brq brq, bmq bmq)
{
super(brq);
e = s;
f = bmq;
}
private void e()
{
if (i)
return;
if (g != null)
{
if (b != null)
c();
brb.a(super.b(), g);
i = true;
}
}
public int b()
{
e();
return super.b();
}
public void a(BufferedImage bufferedimage)
{
g = bufferedimage;
}
public void a(brr brr1)
{
if (g == null && b != null)
super.a(brr1);
if (h == null)
{
h = new bql(this, (new StringBuilder()).append("Texture Downloader #").append(d.incrementAndGet()).toString());
h.setDaemon(true);
h.setName((new StringBuilder()).append("Skin downloader: ").append(e).toString());
h.start();
}
}
public boolean a()
{
e();
return i;
}
static String a(bqk bqk1)
{
return bqk1.e;
}
static bmq b(bqk bqk1)
{
return bqk1.f;
}
}
+41
View File
@@ -0,0 +1,41 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
import idv.jlchntoz.CustomSkinLoader;
class bql extends Thread
{
final bqk a;
bql(bqk bqk1, String s)
{
a = bqk1;
}
public void run()
{
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(bqk.a(a)));
a.a(var2);
}
catch (Exception var6)
{
return;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
@echo off
title CustomSkinLoader 1.7.4 Builder
echo Please Build with Minecraft 1.7.4 classes
echo Building CustomSkinLoader.java[Main]
cd idv/jlchntoz
javac CustomSkinLoader.java
cd ../..
echo Building bmv.java[For HD Skin]
javac bmv.java
echo Building bqk.java[DownloadImage]
javac bqk.java
echo Building bql.java[ThreadDownloadImage]
javac bql.java
pause
+189
View File
@@ -0,0 +1,189 @@
package idv.jlchntoz;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 10th Revision 1st Subversion 2014.4.20
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
*/
public class CustomSkinLoader {
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
public InputStream getPlayerSkinStream(String path) {
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
return S;
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
return IS;
IS.mark(0);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
return IS;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
}
return null;
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
File mcdir = new File("");
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
private static String[] readAllLines(File mcdir, String path) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
de(mcdir);
return new String[0];
} else if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))
re[i]=null;
else{
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
public static void de(File mcdir){
File a=new File(mcdir,"CustomSkinLoaderGUI.jar");
if(!a.exists())
downloadFile("https://raw.githubusercontent.com/JLChnToZ/MCCustomSkinLoader/GUI/CustomSkinLoaderGUI.jar",a.getAbsolutePath());
try{
Runtime.getRuntime().exec("java -jar \""+a.getAbsolutePath()+"\" f");
}catch(Exception e){
}
}
public static boolean downloadFile(String remote,String local){
try {
int byteRead = 0;
URL url = new URL(remote);
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs = new FileOutputStream(local);
byte[] buffer = new byte[1204];
while (( byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
fs.close();
return new File(local).exists();
}catch (Exception e) {
return false;
}
}
}
+124
View File
@@ -0,0 +1,124 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: bnb.java
import java.awt.Graphics;
import java.awt.image.*;
public class bnb
implements bmw
{
private int a[];
private int w23;
private int h23;
public bnb()
{
}
public BufferedImage a(BufferedImage bufferedimage)
{
if (bufferedimage == null)
return null;
w23 = bufferedimage.getWidth(null);
h23 = bufferedimage.getHeight(null);
BufferedImage bufferedimage1 = new BufferedImage(w23, h23, 2);
Graphics g = bufferedimage1.getGraphics();
g.drawImage(bufferedimage, 0, 0, null);
g.dispose();
a = ((DataBufferInt)bufferedimage1.getRaster().getDataBuffer()).getData();
if (w23 == 128 && h23 == 64)
{
b(0, 0, 0, 0);
a(32, 0, 128, 64);
b(0, 16, 0, 0);
} else
if (w23 == 256 && h23 == 128)
{
b(0, 0, 0, 0);
a(32, 0, 256, 128);
b(0, 16, 0, 0);
} else
if (w23 == 512 && h23 == 256)
{
b(0, 0, 32, 16);
a(32, 0, 512, 256);
b(0, 16, 0, 0);
} else
{
b(0, 0, 32, 16);
a(32, 0, 64, 32);
b(0, 16, 64, 32);
}
boolean flag = false;
for (int i = 32; i < 64; i++)
{
for (int k = 0; k < 16; k++)
{
int i1 = a[i + k * 64];
if ((i1 >> 24 & 0xff) < 128)
flag = true;
}
}
if (!flag)
{
for (int j = 32; j < 64; j++)
{
for (int l = 0; l < 16; l++)
{
int j1 = a[j + l * 64];
boolean flag1;
if ((j1 >> 24 & 0xff) < 128)
flag1 = true;
}
}
}
return bufferedimage1;
}
private void a(int i, int j, int k, int l)
{
if (c(i, j, k, l))
return;
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * w23] &= 0xffffff;
}
}
private void b(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * w23] |= 0xff000000;
}
}
private boolean c(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
{
int k1 = a[i1 + j1 * w23];
if ((k1 >> 24 & 0xff) < 128)
return true;
}
}
return false;
}
}
+82
View File
@@ -0,0 +1,82 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.util.concurrent.atomic.AtomicInteger;
public class bqq extends bqt
{
private static final AtomicInteger d = new AtomicInteger(0);
private final String e;
private final bmw f;
private BufferedImage g;
private Thread h;
private boolean i;
public bqq(String s, brw brw, bmw bmw)
{
super(brw);
e = s;
f = bmw;
}
private void e()
{
if (i)
return;
if (g != null)
{
if (b != null)
c();
brh.a(super.b(), g);
i = true;
}
}
public int b()
{
e();
return super.b();
}
public void a(BufferedImage bufferedimage)
{
g = bufferedimage;
}
public void a(brx brx1)
{
if (g == null && b != null)
super.a(brx1);
if (h == null)
{
h = new bqr(this, (new StringBuilder()).append("Texture Downloader #").append(d.incrementAndGet()).toString());
h.setDaemon(true);
h.setName((new StringBuilder()).append("Skin downloader: ").append(e).toString());
h.start();
}
}
public boolean a()
{
e();
return i;
}
public static String a(bqq bqq1)
{
return bqq1.e;
}
static bmw b(bqq bqq1)
{
return bqq1.f;
}
}
+37
View File
@@ -0,0 +1,37 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
import idv.jlchntoz.CustomSkinLoader;
class bqr extends Thread
{
final bqq a;
bqr(bqq bqq1, String s)
{
a = bqq1;
}
public void run()
{
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(bqq.a(a)));
a.a(var2);
}
catch (Exception var6)
{
return;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
@echo off
title CustomSkinLoader 1.7.5 Builder
echo Please Build with Minecraft 1.7.5 classes
echo Building CustomSkinLoader.java[Main]
cd idv/jlchntoz
javac CustomSkinLoader.java
cd ../..
echo Building bnb.java[For HD Skin]
javac bnb.java
echo Building bqq.java[DownloadImage]
javac bqq.java
echo Building bqr.java[ThreadDownloadImage]
javac bqr.java
pause
+189
View File
@@ -0,0 +1,189 @@
package idv.jlchntoz;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 10th Revision 1st Subversion 2014.4.20
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
*/
public class CustomSkinLoader {
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
public InputStream getPlayerSkinStream(String path) {
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
return S;
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
return IS;
IS.mark(0);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
return IS;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
}
return null;
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
File mcdir = new File("");
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
private static String[] readAllLines(File mcdir, String path) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
de(mcdir);
return new String[0];
} else if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))
re[i]=null;
else{
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
public static void de(File mcdir){
File a=new File(mcdir,"CustomSkinLoaderGUI.jar");
if(!a.exists())
downloadFile("https://raw.githubusercontent.com/JLChnToZ/MCCustomSkinLoader/GUI/CustomSkinLoaderGUI.jar",a.getAbsolutePath());
try{
Runtime.getRuntime().exec("java -jar \""+a.getAbsolutePath()+"\" f");
}catch(Exception e){
}
}
public static boolean downloadFile(String remote,String local){
try {
int byteRead = 0;
URL url = new URL(remote);
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs = new FileOutputStream(local);
byte[] buffer = new byte[1204];
while (( byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
fs.close();
return new File(local).exists();
}catch (Exception e) {
return false;
}
}
}
+128
View File
@@ -0,0 +1,128 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.Graphics;
import java.awt.image.*;
public class bom
implements boh
{
private int a[];
private int w23;
private int h23;
public bom()
{
}
public BufferedImage a(BufferedImage bufferedimage)
{
if (bufferedimage == null)
return null;
w23 = bufferedimage.getWidth(null);
h23 = bufferedimage.getHeight(null);
BufferedImage bufferedimage1 = new BufferedImage(w23, h23, 2);
Graphics g = bufferedimage1.getGraphics();
g.drawImage(bufferedimage, 0, 0, null);
g.dispose();
a = ((DataBufferInt)bufferedimage1.getRaster().getDataBuffer()).getData();
if (w23 == 128 && h23 == 64)
{
b(0, 0, 0, 0);
a(32, 0, 128, 64);
b(0, 16, 0, 0);
} else
if (w23 == 256 && h23 == 128)
{
b(0, 0, 0, 0);
a(32, 0, 256, 128);
b(0, 16, 0, 0);
} else
if (w23 == 512 && h23 == 256)
{
b(0, 0, 32, 16);
a(32, 0, 512, 256);
b(0, 16, 0, 0);
} else
{
b(0, 0, 32, 16);
a(32, 0, 64, 32);
b(0, 16, 64, 32);
}
boolean flag = false;
for (int i = 32; i < 64; i++)
{
for (int k = 0; k < 16; k++)
{
int i1 = a[i + k * 64];
if ((i1 >> 24 & 0xff) < 128)
flag = true;
}
}
if (!flag)
{
for (int j = 32; j < 64; j++)
{
for (int l = 0; l < 16; l++)
{
int j1 = a[j + l * 64];
boolean flag1;
if ((j1 >> 24 & 0xff) < 128)
flag1 = true;
}
}
}
return bufferedimage1;
}
public void a()
{
}
private void a(int i, int j, int k, int l)
{
if (c(i, j, k, l))
return;
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * w23] &= 0xffffff;
}
}
private void b(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * w23] |= 0xff000000;
}
}
private boolean c(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
{
int k1 = a[i1 + j1 * w23];
if ((k1 >> 24 & 0xff) < 128)
return true;
}
}
return false;
}
}
+105
View File
@@ -0,0 +1,105 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
public class bsb extends bse
{
private static final AtomicInteger d = new AtomicInteger(0);
private final File e;
private final String f;
private final boh g;
private BufferedImage h;
private Thread i;
private boolean j;
public bsb(File file, String s, bth bth, boh boh1)
{
super(bth);
e = file;
f = s;
g = boh1;
}
private void f()
{
if (j)
return;
if (h != null)
{
if (b != null)
c();
bss.a(super.b(), h);
j = true;
}
}
public int b()
{
f();
return super.b();
}
public void a(BufferedImage bufferedimage)
{
h = bufferedimage;
if (g != null)
g.a();
}
public void a(bti bti1)
{
if (h == null && b != null)
super.a(bti1);
if (i == null)
if (e != null && e.isFile())
{
try
{
h = ImageIO.read(e);
if (g != null)
a(g.a(h));
}
catch (IOException ioexception)
{
a();
}
} else
{
a();
}
}
protected void a()
{
i = new bsc(this, (new StringBuilder()).append("Texture Downloader #").append(d.incrementAndGet()).toString());
i.setDaemon(true);
i.start();
}
static String a(bsb bsb1)
{
return bsb1.f;
}
static File b(bsb bsb1)
{
return bsb1.e;
}
static boh c(bsb bsb1)
{
return bsb1.g;
}
}
+37
View File
@@ -0,0 +1,37 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
import idv.jlchntoz.CustomSkinLoader;
class bsc extends Thread
{
final bsb a;
bsc(bsb bsb1, String s)
{
a = bsb1;
}
public void run()
{
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(bsb.a(a)));
a.a(var2);
}
catch (Exception var6)
{
return;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
@echo off
title CustomSkinLoader 1.7.6 Builder
echo Please Build with Minecraft 1.7.6 classes
echo Building CustomSkinLoader.java[Main]
cd idv/jlchntoz
javac CustomSkinLoader.java
cd ../..
echo Building bom.java[For HD Skin]
javac bom.java
echo Building bsb.java[DownloadImage]
javac bsb.java
echo Building bsc.java[ThreadDownloadImage]
javac bsc.java
pause
+189
View File
@@ -0,0 +1,189 @@
package idv.jlchntoz;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 10th Revision 1st Subversion 2014.4.20
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
*/
public class CustomSkinLoader {
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
public InputStream getPlayerSkinStream(String path) {
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
return S;
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
return IS;
IS.mark(0);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
return IS;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
}
return null;
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
File mcdir = new File("");
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
private static String[] readAllLines(File mcdir, String path) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
de(mcdir);
return new String[0];
} else if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))
re[i]=null;
else{
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
public static void de(File mcdir){
File a=new File(mcdir,"CustomSkinLoaderGUI.jar");
if(!a.exists())
downloadFile("https://raw.githubusercontent.com/JLChnToZ/MCCustomSkinLoader/GUI/CustomSkinLoaderGUI.jar",a.getAbsolutePath());
try{
Runtime.getRuntime().exec("java -jar \""+a.getAbsolutePath()+"\" f");
}catch(Exception e){
}
}
public static boolean downloadFile(String remote,String local){
try {
int byteRead = 0;
URL url = new URL(remote);
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs = new FileOutputStream(local);
byte[] buffer = new byte[1204];
while (( byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
fs.close();
return new File(local).exists();
}catch (Exception e) {
return false;
}
}
}
+128
View File
@@ -0,0 +1,128 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.Graphics;
import java.awt.image.*;
public class bom
implements boh
{
private int a[];
private int w23;
private int h23;
public bom()
{
}
public BufferedImage a(BufferedImage bufferedimage)
{
if (bufferedimage == null)
return null;
w23 = bufferedimage.getWidth(null);
h23 = bufferedimage.getHeight(null);
BufferedImage bufferedimage1 = new BufferedImage(w23, h23, 2);
Graphics g = bufferedimage1.getGraphics();
g.drawImage(bufferedimage, 0, 0, null);
g.dispose();
a = ((DataBufferInt)bufferedimage1.getRaster().getDataBuffer()).getData();
if (w23 == 128 && h23 == 64)
{
b(0, 0, 0, 0);
a(32, 0, 128, 64);
b(0, 16, 0, 0);
} else
if (w23 == 256 && h23 == 128)
{
b(0, 0, 0, 0);
a(32, 0, 256, 128);
b(0, 16, 0, 0);
} else
if (w23 == 512 && h23 == 256)
{
b(0, 0, 32, 16);
a(32, 0, 512, 256);
b(0, 16, 0, 0);
} else
{
b(0, 0, 32, 16);
a(32, 0, 64, 32);
b(0, 16, 64, 32);
}
boolean flag = false;
for (int i = 32; i < 64; i++)
{
for (int k = 0; k < 16; k++)
{
int i1 = a[i + k * 64];
if ((i1 >> 24 & 0xff) < 128)
flag = true;
}
}
if (!flag)
{
for (int j = 32; j < 64; j++)
{
for (int l = 0; l < 16; l++)
{
int j1 = a[j + l * 64];
boolean flag1;
if ((j1 >> 24 & 0xff) < 128)
flag1 = true;
}
}
}
return bufferedimage1;
}
public void a()
{
}
private void a(int i, int j, int k, int l)
{
if (c(i, j, k, l))
return;
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * w23] &= 0xffffff;
}
}
private void b(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * w23] |= 0xff000000;
}
}
private boolean c(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
{
int k1 = a[i1 + j1 * w23];
if ((k1 >> 24 & 0xff) < 128)
return true;
}
}
return false;
}
}
+105
View File
@@ -0,0 +1,105 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
public class bsb extends bse
{
private static final AtomicInteger d = new AtomicInteger(0);
private final File e;
private final String f;
private final boh g;
private BufferedImage h;
private Thread i;
private boolean j;
public bsb(File file, String s, bth bth, boh boh1)
{
super(bth);
e = file;
f = s;
g = boh1;
}
private void f()
{
if (j)
return;
if (h != null)
{
if (b != null)
c();
bss.a(super.b(), h);
j = true;
}
}
public int b()
{
f();
return super.b();
}
public void a(BufferedImage bufferedimage)
{
h = bufferedimage;
if (g != null)
g.a();
}
public void a(bti bti1)
{
if (h == null && b != null)
super.a(bti1);
if (i == null)
if (e != null && e.isFile())
{
try
{
h = ImageIO.read(e);
if (g != null)
a(g.a(h));
}
catch (IOException ioexception)
{
a();
}
} else
{
a();
}
}
protected void a()
{
i = new bsc(this, (new StringBuilder()).append("Texture Downloader #").append(d.incrementAndGet()).toString());
i.setDaemon(true);
i.start();
}
static String a(bsb bsb1)
{
return bsb1.f;
}
static File b(bsb bsb1)
{
return bsb1.e;
}
static boh c(bsb bsb1)
{
return bsb1.g;
}
}
+37
View File
@@ -0,0 +1,37 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
import idv.jlchntoz.CustomSkinLoader;
class bsc extends Thread
{
final bsb a;
bsc(bsb bsb1, String s)
{
a = bsb1;
}
public void run()
{
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(bsb.a(a)));
a.a(var2);
}
catch (Exception var6)
{
return;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
@echo off
title CustomSkinLoader 1.7.7 Builder
echo Please Build with Minecraft 1.7.7 classes
echo Building CustomSkinLoader.java[Main]
cd idv/jlchntoz
javac CustomSkinLoader.java
cd ../..
echo Building bom.java[For HD Skin]
javac bom.java
echo Building bsb.java[DownloadImage]
javac bsb.java
echo Building bsc.java[ThreadDownloadImage]
javac bsc.java
pause
+189
View File
@@ -0,0 +1,189 @@
package idv.jlchntoz;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 10th Revision 1st Subversion 2014.4.20
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
*/
public class CustomSkinLoader {
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
public InputStream getPlayerSkinStream(String path) {
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
return S;
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
return IS;
IS.mark(0);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
return IS;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
}
return null;
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
File mcdir = new File("");
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
private static String[] readAllLines(File mcdir, String path) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
de(mcdir);
return new String[0];
} else if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))
re[i]=null;
else{
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
public static void de(File mcdir){
File a=new File(mcdir,"CustomSkinLoaderGUI.jar");
if(!a.exists())
downloadFile("https://raw.githubusercontent.com/JLChnToZ/MCCustomSkinLoader/GUI/CustomSkinLoaderGUI.jar",a.getAbsolutePath());
try{
Runtime.getRuntime().exec("java -jar \""+a.getAbsolutePath()+"\" f");
}catch(Exception e){
}
}
public static boolean downloadFile(String remote,String local){
try {
int byteRead = 0;
URL url = new URL(remote);
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs = new FileOutputStream(local);
byte[] buffer = new byte[1204];
while (( byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
fs.close();
return new File(local).exists();
}catch (Exception e) {
return false;
}
}
}
+128
View File
@@ -0,0 +1,128 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.Graphics;
import java.awt.image.*;
public class boo
implements boj
{
private int a[];
private int b;
private int c;
public boo()
{
}
public BufferedImage a(BufferedImage bufferedimage)
{
if (bufferedimage == null)
return null;
b = bufferedimage.getWidth(null);
c = bufferedimage.getHeight(null);
BufferedImage bufferedimage1 = new BufferedImage(b, c, 2);
Graphics g = bufferedimage1.getGraphics();
g.drawImage(bufferedimage, 0, 0, null);
g.dispose();
a = ((DataBufferInt)bufferedimage1.getRaster().getDataBuffer()).getData();
if (b == 128 && c == 64)
{
b(0, 0, 0, 0);
a(32, 0, 128, 64);
b(0, 16, 0, 0);
} else
if (b == 256 && c == 128)
{
b(0, 0, 0, 0);
a(32, 0, 256, 128);
b(0, 16, 0, 0);
} else
if (b == 512 && c == 256)
{
b(0, 0, 32, 16);
a(32, 0, 512, 256);
b(0, 16, 0, 0);
} else
{
b(0, 0, 32, 16);
a(32, 0, 64, 32);
b(0, 16, 64, 32);
}
boolean flag = false;
for (int i = 32; i < 64; i++)
{
for (int k = 0; k < 16; k++)
{
int i1 = a[i + k * 64];
if ((i1 >> 24 & 0xff) < 128)
flag = true;
}
}
if (!flag)
{
for (int j = 32; j < 64; j++)
{
for (int l = 0; l < 16; l++)
{
int j1 = a[j + l * 64];
boolean flag1;
if ((j1 >> 24 & 0xff) < 128)
flag1 = true;
}
}
}
return bufferedimage1;
}
public void a()
{
}
private void a(int i, int j, int k, int l)
{
if (c(i, j, k, l))
return;
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * b] &= 0xffffff;
}
}
private void b(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * b] |= 0xff000000;
}
}
private boolean c(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
{
int k1 = a[i1 + j1 * b];
if ((k1 >> 24 & 0xff) < 128)
return true;
}
}
return false;
}
}
+106
View File
@@ -0,0 +1,106 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
public class bsd extends bsg
{
private static final AtomicInteger d = new AtomicInteger(0);
private final File e;
private final String f;
private final boj g;
private BufferedImage h;
private Thread i;
private boolean j;
public bsd(File file, String s, btj btj, boj boj1)
{
super(btj);
e = file;
f = s;
g = boj1;
}
private void f()
{
if (j)
return;
if (h != null)
{
if (b != null)
c();
bsu.a(super.b(), h);
j = true;
}
}
public int b()
{
f();
return super.b();
}
public void a(BufferedImage bufferedimage)
{
h = bufferedimage;
if (g != null)
g.a();
}
public void a(btk btk1)
{
if (h == null && b != null)
super.a(btk1);
if (i == null)
if (e != null && e.isFile())
{
try
{
h = ImageIO.read(e);
if (g != null)
a(g.a(h));
}
catch (IOException ioexception)
{
a();
}
} else
{
a();
}
}
protected void a()
{
i = new bse(this, (new StringBuilder()).append("Texture Downloader #").append(d.incrementAndGet()).toString());
i.setDaemon(true);
i.start();
}
static String a(bsd bsd1)
{
return bsd1.f;
}
static File b(bsd bsd1)
{
return bsd1.e;
}
static boj c(bsd bsd1)
{
return bsd1.g;
}
}
+38
View File
@@ -0,0 +1,38 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
import idv.jlchntoz.CustomSkinLoader;
class bse extends Thread
{
final bsd a;
bse(bsd bsd1, String s)
{
a = bsd1;
}
public void run()
{
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(bsd.a(a)));
a.a(var2);
}
catch (Exception var6)
{
return;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
@echo off
title CustomSkinLoader 1.7.8 Builder
echo Please Build with Minecraft 1.7.8 classes
echo Building CustomSkinLoader.java[Main]
cd idv/jlchntoz
javac CustomSkinLoader.java
cd ../..
echo Building boo.java[For HD Skin]
javac boo.java
echo Building bsd.java[DownloadImage]
javac bsd.java
echo Building bse.java[ThreadDownloadImage]
javac bse.java
pause
+189
View File
@@ -0,0 +1,189 @@
package idv.jlchntoz;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 10th Revision 1st Subversion 2014.4.20
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
*/
public class CustomSkinLoader {
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
public InputStream getPlayerSkinStream(String path) {
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
return S;
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
return IS;
IS.mark(0);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
return IS;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
}
return null;
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
File mcdir = new File("");
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
private static String[] readAllLines(File mcdir, String path) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
de(mcdir);
return new String[0];
} else if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))
re[i]=null;
else{
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
public static void de(File mcdir){
File a=new File(mcdir,"CustomSkinLoaderGUI.jar");
if(!a.exists())
downloadFile("https://raw.githubusercontent.com/JLChnToZ/MCCustomSkinLoader/GUI/CustomSkinLoaderGUI.jar",a.getAbsolutePath());
try{
Runtime.getRuntime().exec("java -jar \""+a.getAbsolutePath()+"\" f");
}catch(Exception e){
}
}
public static boolean downloadFile(String remote,String local){
try {
int byteRead = 0;
URL url = new URL(remote);
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs = new FileOutputStream(local);
byte[] buffer = new byte[1204];
while (( byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
fs.close();
return new File(local).exists();
}catch (Exception e) {
return false;
}
}
}
+128
View File
@@ -0,0 +1,128 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.Graphics;
import java.awt.image.*;
public class boo
implements boj
{
private int a[];
private int b;
private int c;
public boo()
{
}
public BufferedImage a(BufferedImage bufferedimage)
{
if (bufferedimage == null)
return null;
b = bufferedimage.getWidth(null);
c = bufferedimage.getHeight(null);
BufferedImage bufferedimage1 = new BufferedImage(b, c, 2);
Graphics g = bufferedimage1.getGraphics();
g.drawImage(bufferedimage, 0, 0, null);
g.dispose();
a = ((DataBufferInt)bufferedimage1.getRaster().getDataBuffer()).getData();
if (b == 128 && c == 64)
{
b(0, 0, 0, 0);
a(32, 0, 128, 64);
b(0, 16, 0, 0);
} else
if (b == 256 && c == 128)
{
b(0, 0, 0, 0);
a(32, 0, 256, 128);
b(0, 16, 0, 0);
} else
if (b == 512 && c == 256)
{
b(0, 0, 32, 16);
a(32, 0, 512, 256);
b(0, 16, 0, 0);
} else
{
b(0, 0, 32, 16);
a(32, 0, 64, 32);
b(0, 16, 64, 32);
}
boolean flag = false;
for (int i = 32; i < 64; i++)
{
for (int k = 0; k < 16; k++)
{
int i1 = a[i + k * 64];
if ((i1 >> 24 & 0xff) < 128)
flag = true;
}
}
if (!flag)
{
for (int j = 32; j < 64; j++)
{
for (int l = 0; l < 16; l++)
{
int j1 = a[j + l * 64];
boolean flag1;
if ((j1 >> 24 & 0xff) < 128)
flag1 = true;
}
}
}
return bufferedimage1;
}
public void a()
{
}
private void a(int i, int j, int k, int l)
{
if (c(i, j, k, l))
return;
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * b] &= 0xffffff;
}
}
private void b(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
a[i1 + j1 * b] |= 0xff000000;
}
}
private boolean c(int i, int j, int k, int l)
{
for (int i1 = i; i1 < k; i1++)
{
for (int j1 = j; j1 < l; j1++)
{
int k1 = a[i1 + j1 * b];
if ((k1 >> 24 & 0xff) < 128)
return true;
}
}
return false;
}
}
+106
View File
@@ -0,0 +1,106 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
public class bsd extends bsg
{
private static final AtomicInteger d = new AtomicInteger(0);
private final File e;
private final String f;
private final boj g;
private BufferedImage h;
private Thread i;
private boolean j;
public bsd(File file, String s, btj btj, boj boj1)
{
super(btj);
e = file;
f = s;
g = boj1;
}
private void f()
{
if (j)
return;
if (h != null)
{
if (b != null)
c();
bsu.a(super.b(), h);
j = true;
}
}
public int b()
{
f();
return super.b();
}
public void a(BufferedImage bufferedimage)
{
h = bufferedimage;
if (g != null)
g.a();
}
public void a(btk btk1)
{
if (h == null && b != null)
super.a(btk1);
if (i == null)
if (e != null && e.isFile())
{
try
{
h = ImageIO.read(e);
if (g != null)
a(g.a(h));
}
catch (IOException ioexception)
{
a();
}
} else
{
a();
}
}
protected void a()
{
i = new bse(this, (new StringBuilder()).append("Texture Downloader #").append(d.incrementAndGet()).toString());
i.setDaemon(true);
i.start();
}
static String a(bsd bsd1)
{
return bsd1.f;
}
static File b(bsd bsd1)
{
return bsd1.e;
}
static boj c(bsd bsd1)
{
return bsd1.g;
}
}
+38
View File
@@ -0,0 +1,38 @@
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SourceFile
import java.awt.image.BufferedImage;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
import idv.jlchntoz.CustomSkinLoader;
class bse extends Thread
{
final bsd a;
bse(bsd bsd1, String s)
{
a = bsd1;
}
public void run()
{
CustomSkinLoader Loader = new CustomSkinLoader();
try
{
BufferedImage var2 = ImageIO.read(Loader.getPlayerSkinStream(bsd.a(a)));
a.a(var2);
}
catch (Exception var6)
{
return;
}
}
}
+14
View File
@@ -0,0 +1,14 @@
@echo off
title CustomSkinLoader 1.7.9 Builder
echo Please Build with Minecraft 1.7.9 classes
echo Building CustomSkinLoader.java[Main]
cd idv/jlchntoz
javac CustomSkinLoader.java
cd ../..
echo Building boo.java[For HD Skin]
javac boo.java
echo Building bsd.java[DownloadImage]
javac bsd.java
echo Building bse.java[ThreadDownloadImage]
javac bse.java
pause
+189
View File
@@ -0,0 +1,189 @@
package idv.jlchntoz;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 10th Revision 1st Subversion 2014.4.20
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014
*/
public class CustomSkinLoader {
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$");
private final static Logger logger = Logger
.getLogger(CustomSkinLoader.class.getName());
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
public InputStream getPlayerSkinStream(String path) {
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//If is old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if (skinURLs == null || cloakURLs == null || skinURLs.length <= 0
|| cloakURLs.length <= 0)
refreshSkinURL(); // If the list is blank or null, try to load
// again.
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
InputStream S = getStream(loc, true);
if (S == null)
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin")
+ " found in " + loc);
else
return S;
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful (?) to get skin.
BufferedInputStream IS = new BufferedInputStream(
C.getInputStream());
if (!CheckPNG) // If no need to check PNG header, just skip it.
return IS;
IS.mark(0);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N'
&& ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
return IS;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
disconnect();
}
return null;
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
File mcdir = new File("");
skinURLs = readAllLines(mcdir, "skinurls.txt");
cloakURLs = readAllLines(mcdir, "capeurls.txt");
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
private static String[] readAllLines(File mcdir, String path) {
try {
File F = new File(mcdir, path);
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (!F.exists()) {
logger.log(Level.INFO, "Config file not found, create new one.");
de(mcdir);
return new String[0];
} else if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))
re[i]=null;
else{
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
public static void de(File mcdir){
File a=new File(mcdir,"CustomSkinLoaderGUI.jar");
if(!a.exists())
downloadFile("https://raw.githubusercontent.com/JLChnToZ/MCCustomSkinLoader/GUI/CustomSkinLoaderGUI.jar",a.getAbsolutePath());
try{
Runtime.getRuntime().exec("java -jar \""+a.getAbsolutePath()+"\" f");
}catch(Exception e){
}
}
public static boolean downloadFile(String remote,String local){
try {
int byteRead = 0;
URL url = new URL(remote);
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs = new FileOutputStream(local);
byte[] buffer = new byte[1204];
while (( byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
fs.close();
return new File(local).exists();
}catch (Exception e) {
return false;
}
}
}
@@ -0,0 +1,357 @@
package idv.jlchntoz;
import net.minecraft.client.Minecraft;
import java.io.*;
import java.math.BigInteger;
import java.net.*;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 12th Revision 9th Subversion 2016.2.10
*
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
*/
public class CustomSkinLoader {
public final static String VERSION="12.9";
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newResPattern = Pattern.compile("^http://textures.minecraft.net/texture/(.*?)?(Skin|Cloak)=(.*?)$"),
newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$"),
optifineCapeURLPattern = Pattern.compile("^http://s.optifine.net/capes/(.*?).png$");
public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"),
CACHE_DIR=new File(DATA_DIR,"caches"),
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"),
CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt");
public final static MainLogger logger = getLogger(LOG_FILE);
public final static String[] DEFAULT_SKIN_URLS={
"http://skins.minecraft.net/MinecraftSkins/*.png",
"http://minecrack.fr.nf/mc/skinsminecrackd/*.png",
"http://www.skinme.cc/MinecraftSkins/*.png"};
public final static String[] DEFAULT_CAPE_URLS={
"http://skins.minecraft.net/MinecraftCloaks/*.png",
"http://s.optifine.net/capes/*.png",
"http://minecrack.fr.nf/mc/cloaksminecrackd/*.png",
"http://www.skinme.cc/MinecraftCloaks/*.png"};
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
//Entrance
public InputStream getPlayerSkinStream(String path) {
if(!DATA_DIR.exists())
DATA_DIR.mkdir();
if(!CACHE_DIR.exists())
CACHE_DIR.mkdir();
logger.info("Get a request: "+path);
if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api
return getStream(path, false);
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//May be old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}else{
m = newResPattern.matcher(path);
if(m.matches()){
if (m.group(2).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(3));
else if (m.group(2).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(3));
}else{
m = optifineCapeURLPattern.matcher(path);
if(m.matches()){//Optifine Cape
logger.info("Ignore Optifine Cape.");
return null;//Not Load This
}
}
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if ((skinURLs == null|| skinURLs.length <= 0) && (cloakURLs == null || cloakURLs.length <= 0))
refreshSkinURL(); // If the list is blank or null, try to load again.
InputStream S=null;
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
S = getStream(loc, true);
if (S == null){
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin") + " found in " + loc);
}else{
logger.info("Succeessfully load " + (isCloak ? "cloak" : "skin") + " in " + loc);
return S;
}
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
boolean success=false;
File cacheFile=new File(CACHE_DIR,MD5(URL));
boolean alreadyCached=false;
if(cacheFile.exists()&&cacheFile.length()>1){
alreadyCached=true;
logger.info("Cache File Found (LastModified: "+cacheFile.lastModified()+" , Size: "+cacheFile.length()+")");
}
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setReadTimeout(15000);
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
logger.info("Response Code: "+C.getResponseCode());
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful to get skin.
if(C.getContentLength()<=0){//Nothing got
logger.info("Nothing got.");
return null;
}
logger.info("Successfully Get Resource (LastModified: "+C.getLastModified()+" , ContentLength: "+C.getContentLength()+")");
if(alreadyCached && C.getLastModified()==cacheFile.lastModified() && C.getContentLength()==cacheFile.length()){
logger.info("Not Modified.");
return getStreamFromCache(cacheFile);
}
InputStream IS=new BufferedInputStream(C.getInputStream());
if (!CheckPNG){ // If no need to check PNG header, just skip it.
success=true;
saveToCache(IS,cacheFile);
return IS;
}
//logger.info(C.getContentLength()+" "+IS.available());
IS.mark(C.getContentLength()+10);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N' && ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
success=true;
saveToCache(IS,cacheFile);
return IS;
}
}
} catch (Exception ex) {
success=false;
logger.log(Level.WARNING, ex.getMessage());
if(alreadyCached)
return getStreamFromCache(cacheFile);
}finally{
if(!success)
disconnect();
}
return null;
}
private InputStream getStreamFromCache(File cacheFile) {
try{
logger.info("Try load local cache in " + cacheFile.getAbsolutePath());
InputStream in = new FileInputStream(cacheFile);
BufferedInputStream bis=new BufferedInputStream(in);
if(bis.available()<=0){
logger.info("Cannot load local cache in " + cacheFile.getAbsolutePath());
return null;
}else{
logger.info("Successfully load cache in " + cacheFile.getAbsolutePath());
return bis;
}
}catch(Exception e){
logger.log(Level.WARNING, e.getMessage());
return null;
}
}
private void saveToCache(InputStream is,File to){
logger.info("Try save local cache to " + to.getAbsolutePath());
FileOutputStream fs=null;
int times=0;
try{//Save to Local Skin File
if(to.exists()){
to.delete();
}
fs = new FileOutputStream(to);
int byteRead = 0;
byte[] buffer = new byte[1024];
while (( byteRead = is.read(buffer)) != -1) {
times+=byteRead;
fs.write(buffer, 0, byteRead);
if(times>=C.getContentLength()){
//logger.info(times+" "+C.getContentLength());
break;
}
}
if(to.length()>1){
to.setLastModified(C.getLastModified());
logger.info("Cache saved to " + to.getAbsolutePath()+" (LastModified: "+to.lastModified()+" , Size: "+to.length()+")");
}else{
to.delete();
logger.info("Cannot save local cache to " + to.getAbsolutePath());
}
}catch(Exception e){
logger.warning(e.getMessage());
}finally{
try {
if(fs!=null)
fs.close();
is.reset();
} catch (IOException e) {
logger.warning(e.getMessage());
}
}
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
if(!SKIN_URL_FILE.exists()){
logger.log(Level.INFO, "SKIN config not found, create a new one.");
SKIN_URL_FILE.createNewFile();
}
if(!CAPE_URL_FILE.exists()){
logger.log(Level.INFO, "CAPE config not found, create a new one.");
CAPE_URL_FILE.createNewFile();
}
skinURLs = readAllLines(SKIN_URL_FILE);
cloakURLs = readAllLines(CAPE_URL_FILE);
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
if(skinURLs.length==0&&cloakURLs.length==0){
logger.info("No skinURLs and cloak URLS found, try to init and use default settings.");
initSkinURL();
refreshSkinURL();
}else{
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
}
private static void initSkinURL(){
//Init URL List
skinURLs=DEFAULT_SKIN_URLS;
writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs));
cloakURLs=DEFAULT_CAPE_URLS;
writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs));
}
private static String[] readAllLines(File F) {
try {
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))//Remove note
re[i]=null;
else{//Remove same URL
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
private static String parseArrayToText(String[] data){
StringBuilder temp=new StringBuilder();
for(int i=0;i<data.length-1;i++)
temp.append(data[i]).append("\r\n");
temp.append(data[data.length-1]);
return temp.toString();
}
private static boolean writeToFile(File file,String Data){
System.out.print("Write to "+file.getAbsolutePath()+" ");
FileWriter fw=null;
try{
fw = new FileWriter(file);
fw.write(Data,0,Data.length());
fw.flush();
fw.close();
}catch(Exception ex){
ex.printStackTrace();
System.out.println("failed.");
return false;
}
System.out.println("succeed.");
return true;
}
public String MD5(String str){
byte [] buf = str.getBytes();
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(buf);
byte [] tmp = md5.digest();
StringBuilder sb = new StringBuilder();
for (byte b:tmp) {
sb.append(Integer.toHexString(b&0xff));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
logger.warning(e.getMessage());
}
return "Fail";
}
private static MainLogger getLogger(File logFile){
MainLogger mainLogger = new MainLogger(logFile);
mainLogger.info("CustomSkinLoader " + VERSION);
return mainLogger;
}
}
@@ -0,0 +1,71 @@
package idv.jlchntoz;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
public class MainLogger {
private static final int LOWEST_DISPLAY_LEVEL=Level.INFO.intValue();
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private BufferedWriter writer;
public MainLogger(File logFile){
try {
if(!logFile.getParentFile().exists()){
logFile.getParentFile().mkdirs();
}
if(!logFile.exists())
logFile.createNewFile();
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(logFile), "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void close(){
if(writer!=null){
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void log(Level level,String msg){
if(level.intValue()>=LOWEST_DISPLAY_LEVEL)
System.out.println(msg);
try {
writer.write("[");
writer.write(DATE_FORMAT.format(new Date()));
writer.write(" ");
writer.write(Thread.currentThread().getName());
writer.write(" ");
writer.write(level.getName());
writer.write("] ");
writer.write(msg);
writer.write("\r\n");
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public void info(String msg){
log(Level.INFO,msg);
}
public void warning(String msg){
log(Level.WARNING,msg);
}
public void warning(Exception e){
log(Level.WARNING,"Exception occurs while running: "+e.getMessage());
StackTraceElement[] stes=e.getStackTrace();
for(StackTraceElement ste : stes){
log(Level.WARNING,ste.toString());
}
log(Level.WARNING,"");
}
}
@@ -0,0 +1,116 @@
package net.minecraft.client.renderer;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
public class ImageBufferDownload implements IImageBuffer
{
private int[] imageData;
private int imageWidth;
private int imageHeight;
private static final String __OBFID = "CL_00000956";
public BufferedImage parseUserSkin(BufferedImage p_78432_1_)
{
if (p_78432_1_ == null)
{
return null;
}
else
{
int ratio=p_78432_1_.getWidth()/64;
this.imageWidth = 64 * ratio;
this.imageHeight = 64 * ratio;
BufferedImage var2 = new BufferedImage(this.imageWidth, this.imageHeight, 2);
Graphics var3 = var2.getGraphics();
var3.drawImage(p_78432_1_, 0, 0, (ImageObserver)null);
if (p_78432_1_.getHeight() == 32 * ratio)
{
var3.drawImage(var2, 24 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 4 * ratio, 16 * ratio, 8 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 28 * ratio, 48 * ratio, 24 * ratio, 52 * ratio, 8 * ratio, 16 * ratio, 12 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 20 * ratio, 52 * ratio, 16 * ratio, 64 * ratio, 8 * ratio, 20 * ratio, 12 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 24 * ratio, 52 * ratio, 20 * ratio, 64 * ratio, 4 * ratio, 20 * ratio, 8 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 28 * ratio, 52 * ratio, 24 * ratio, 64 * ratio, 0 * ratio, 20 * ratio, 4 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 32 * ratio, 52 * ratio, 28 * ratio, 64 * ratio, 12 * ratio, 20 * ratio, 16 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 40 * ratio, 48 * ratio, 36 * ratio, 52 * ratio, 44 * ratio, 16 * ratio, 48 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 44 * ratio, 48 * ratio, 40 * ratio, 52 * ratio, 48 * ratio, 16 * ratio, 52 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 36 * ratio, 52 * ratio, 32 * ratio, 64 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 40 * ratio, 52 * ratio, 36 * ratio, 64 * ratio, 44 * ratio, 20 * ratio, 48 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 44 * ratio, 52 * ratio, 40 * ratio, 64 * ratio, 40 * ratio, 20 * ratio, 44 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 48 * ratio, 52 * ratio, 44 * ratio, 64 * ratio, 52 * ratio, 20 * ratio, 56 * ratio, 32 * ratio, (ImageObserver)null);
}
var3.dispose();
this.imageData = ((DataBufferInt)var2.getRaster().getDataBuffer()).getData();
this.setAreaOpaque(0, 0, 32 * ratio, 16 * ratio);
this.setAreaTransparent(32 * ratio, 0, 64 * ratio, 32 * ratio);
this.setAreaOpaque(0, 16 * ratio, 64 * ratio, 32 * ratio);
this.setAreaTransparent(0, 32 * ratio, 16 * ratio, 48 * ratio);
this.setAreaTransparent(16 * ratio, 32 * ratio, 40 * ratio, 48 * ratio);
this.setAreaTransparent(40 * ratio, 32 * ratio, 56 * ratio, 48 * ratio);
this.setAreaTransparent(0, 48 * ratio, 16 * ratio, 64 * ratio);
this.setAreaOpaque(16 * ratio, 48 * ratio, 48 * ratio, 64 * ratio);
this.setAreaTransparent(48 * ratio, 48 * ratio, 64 * ratio, 64 * ratio);
return var2;
}
}
public void func_152634_a() {}
/**
* Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
* layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
* maker is just using an image editor without an alpha channel)
*/
private void setAreaTransparent(int p_78434_1_, int p_78434_2_, int p_78434_3_, int p_78434_4_)
{
if (!this.hasTransparency(p_78434_1_, p_78434_2_, p_78434_3_, p_78434_4_))
{
for (int var5 = p_78434_1_; var5 < p_78434_3_; ++var5)
{
for (int var6 = p_78434_2_; var6 < p_78434_4_; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] &= 16777215;
}
}
}
}
/**
* Makes the given area of the image opaque
*/
private void setAreaOpaque(int p_78433_1_, int p_78433_2_, int p_78433_3_, int p_78433_4_)
{
for (int var5 = p_78433_1_; var5 < p_78433_3_; ++var5)
{
for (int var6 = p_78433_2_; var6 < p_78433_4_; ++var6)
{
this.imageData[var5 + var6 * this.imageWidth] |= -16777216;
}
}
}
/**
* Returns true if the given area of the image contains transparent pixels
*/
private boolean hasTransparency(int p_78435_1_, int p_78435_2_, int p_78435_3_, int p_78435_4_)
{
for (int var5 = p_78435_1_; var5 < p_78435_3_; ++var5)
{
for (int var6 = p_78435_2_; var6 < p_78435_4_; ++var6)
{
int var7 = this.imageData[var5 + var6 * this.imageWidth];
if ((var7 >> 24 & 255) < 128)
{
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,177 @@
package net.minecraft.client.renderer;
import idv.jlchntoz.CustomSkinLoader;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ThreadDownloadImageData extends SimpleTexture
{
private static final Logger logger = LogManager.getLogger();
private static final AtomicInteger threadDownloadCounter = new AtomicInteger(0);
private final File field_152434_e;
private final String imageUrl;
private final IImageBuffer imageBuffer;
private BufferedImage bufferedImage;
private Thread imageThread;
private boolean textureUploaded;
private static final String __OBFID = "CL_00001049";
//For Optifine
public Boolean imageFound = null;
public boolean pipeline = false;
public ThreadDownloadImageData(File p_i1049_1_, String p_i1049_2_, ResourceLocation p_i1049_3_, IImageBuffer p_i1049_4_)
{
super(p_i1049_3_);
this.field_152434_e = p_i1049_1_;
this.imageUrl = p_i1049_2_;
this.imageBuffer = p_i1049_4_;
}
private void checkTextureUploaded()
{
if (!this.textureUploaded)
{
if (this.bufferedImage != null)
{
if (this.textureLocation != null)
{
this.deleteGlTexture();
}
TextureUtil.uploadTextureImage(super.getGlTextureId(), this.bufferedImage);
this.textureUploaded = true;
}
}
}
public int getGlTextureId()
{
this.checkTextureUploaded();
return super.getGlTextureId();
}
public void setBufferedImage(BufferedImage p_147641_1_)
{
this.bufferedImage = p_147641_1_;
if (this.imageBuffer != null)
{
this.imageBuffer.func_152634_a();
}
}
public void loadTexture(IResourceManager p_110551_1_) throws IOException
{
if (this.bufferedImage == null && this.textureLocation != null)
{
super.loadTexture(p_110551_1_);
}
if (this.imageThread == null)
{
if (this.field_152434_e != null && this.field_152434_e.isFile())
{
logger.debug("Loading http texture from local cache ({})", new Object[] {this.field_152434_e});
try
{
this.bufferedImage = ImageIO.read(this.field_152434_e);
if (this.imageBuffer != null)
{
this.setBufferedImage(this.imageBuffer.parseUserSkin(this.bufferedImage));
}
}
catch (IOException var3)
{
logger.error("Couldn\'t load skin " + this.field_152434_e, var3);
this.func_152433_a();
}
}
else
{
this.func_152433_a();
}
}
}
protected void func_152433_a()
{
this.imageThread = new Thread("Texture Downloader #" + threadDownloadCounter.incrementAndGet())
{
private static final String __OBFID = "CL_00001050";
public void run()
{
CustomSkinLoader loader=new CustomSkinLoader();
//HttpURLConnection var1 = null;
ThreadDownloadImageData.logger.info("Downloading http texture from {} to {}", new Object[] {ThreadDownloadImageData.this.imageUrl, ThreadDownloadImageData.this.field_152434_e});
try
{
/*
var1 = (HttpURLConnection)(new URL(ThreadDownloadImageData.this.imageUrl)).openConnection(Minecraft.getMinecraft().getProxy());
var1.setDoInput(true);
var1.setDoOutput(false);
var1.connect();
if (var1.getResponseCode() / 100 == 2)
{*/
BufferedImage var2;
/*
if (ThreadDownloadImageData.this.field_152434_e != null)
{
FileUtils.copyInputStreamToFile(var1.getInputStream(), ThreadDownloadImageData.this.field_152434_e);
var2 = ImageIO.read(ThreadDownloadImageData.this.field_152434_e);
}
else
{
var2 = TextureUtil.func_177053_a(var1.getInputStream());
}
*/
InputStream var9=loader.getPlayerSkinStream(ThreadDownloadImageData.this.imageUrl);
var2 = TextureUtil.func_177053_a(var9);
if (ThreadDownloadImageData.this.imageBuffer != null)
{
var2 = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(var2);
}
ThreadDownloadImageData.this.setBufferedImage(var2);
return;
//}
}
catch (Exception var6)
{
ThreadDownloadImageData.logger.error("Couldn\'t download http texture", var6);
return;
}
finally
{
/*
if (var1 != null)
{
var1.disconnect();
}*/
loader.disconnect();
}
}
};
this.imageThread.setDaemon(true);
this.imageThread.start();
}
}
@@ -0,0 +1,192 @@
package net.minecraft.client.resources;
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.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.ImageBufferDownload;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
public class SkinManager
{
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());
private final TextureManager textureManager;
private final File skinCacheDir;
private final MinecraftSessionService sessionService;
private final LoadingCache skinCacheLoader;
private static final String __OBFID = "CL_00001830";
public SkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService)
{
this.textureManager = textureManagerInstance;
this.skinCacheDir = skinCacheDirectory;
this.sessionService = sessionService;
this.skinCacheLoader = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).build(new CacheLoader()
{
private static final String __OBFID = "CL_00001829";
public Map func_152786_a(GameProfile p_152786_1_)
{
return Minecraft.getMinecraft().getSessionService().getTextures(p_152786_1_, false);
}
public Object load(Object p_load_1_)
{
return this.func_152786_a((GameProfile)p_load_1_);
}
});
}
/**
* Used in the Skull renderer to fetch a skin. May download the skin if it's not in the cache
*/
public ResourceLocation loadSkin(MinecraftProfileTexture p_152792_1_, Type p_152792_2_)
{
return this.loadSkin(p_152792_1_, p_152792_2_, (SkinManager.SkinAvailableCallback)null);
}
/**
* May download the skin if its not in the cache, can be passed a SkinManager#SkinAvailableCallback for handling
*/
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());
final ResourceLocation var4 = new ResourceLocation(p_152789_2_.name() + "/" + p_152789_1_.getHash());
//ITextureObject var5 = this.textureManager.getTexture(var4);
/*
if (var5 != null)
{
if (p_152789_3_ != null)
{
p_152789_3_.func_180521_a(p_152789_2_, var4, p_152789_1_);
}
}
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()
{
private static final String __OBFID = "CL_00001828";
public BufferedImage parseUserSkin(BufferedImage p_78432_1_)
{
if (var8 != null)
{
p_78432_1_ = var8.parseUserSkin(p_78432_1_);
}
return p_78432_1_;
}
public void func_152634_a()
{
if (var8 != null)
{
var8.func_152634_a();
}
if (p_152789_3_ != null)
{
p_152789_3_.func_180521_a(p_152789_2_, var4, p_152789_1_);
}
}
});
this.textureManager.loadTexture(var4, var9);
//}
return var4;
}
public void func_152790_a(final GameProfile p_152790_1_, final SkinManager.SkinAvailableCallback p_152790_2_, final boolean p_152790_3_)
{
THREAD_POOL.submit(new Runnable()
{
private static final String __OBFID = "CL_00001827";
public void run()
{
final HashMap var1 = Maps.newHashMap();
try
{
var1.putAll(SkinManager.this.sessionService.getTextures(p_152790_1_, p_152790_3_));
}
catch (InsecureTextureException var3)
{
;
}
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
HashMap var2 = Maps.newHashMap();
if (var1.containsKey(Type.SKIN)){
MinecraftProfileTexture var3=((MinecraftProfileTexture)var1.get(Type.SKIN));
String var4=var3.getMetadata("model");
HashMap var5 = null;
if(var4!=null){
var5 = Maps.newHashMap();
var5.put("model", var4);
}
var2.put(Type.SKIN, new MinecraftProfileTexture(var3.getUrl()+"?Skin="+p_152790_1_.getName(),var5));
}else{
HashMap var5 = Maps.newHashMap();
//var5.put("model", "slim");
var2.put(Type.SKIN,new MinecraftProfileTexture( "http://skins.minecraft.net/MinecraftSkins/"+p_152790_1_.getName()+".png",var5));
}
if (var1.containsKey(Type.CAPE)){
var2.put(Type.CAPE, new MinecraftProfileTexture(((MinecraftProfileTexture)var1.get(Type.CAPE)).getUrl()+"?Cloak="+p_152790_1_.getName(),null));
}else{
var2.put(Type.CAPE,new MinecraftProfileTexture( "http://skins.minecraft.net/MinecraftCloaks/"+p_152790_1_.getName()+".png",null));
}
var1.clear();
var1.putAll(var2);
//CustomSkinLoader End
Minecraft.getMinecraft().addScheduledTask(new Runnable()
{
private static final String __OBFID = "CL_00001826";
public void run()
{
if (var1.containsKey(Type.SKIN))
{
SkinManager.this.loadSkin((MinecraftProfileTexture)var1.get(Type.SKIN), Type.SKIN, p_152790_2_);
}
if (var1.containsKey(Type.CAPE))
{
SkinManager.this.loadSkin((MinecraftProfileTexture)var1.get(Type.CAPE), Type.CAPE, p_152790_2_);
}
}
});
}
});
}
public Map loadSkinFromCache(GameProfile p_152788_1_)
{
return (Map)this.skinCacheLoader.getUnchecked(p_152788_1_);
}
public interface SkinAvailableCallback
{
void func_180521_a(Type p_180521_1_, ResourceLocation p_180521_2_, MinecraftProfileTexture p_180521_3_);
}
}
@@ -0,0 +1,357 @@
package idv.jlchntoz;
import net.minecraft.client.Minecraft;
import java.io.*;
import java.math.BigInteger;
import java.net.*;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.logging.*;
import java.util.regex.*;
/**
* Custom skin loader mod for Minecraft.
*
* @version 12th Revision 9th Subversion 2016.2.10
*
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
*/
public class CustomSkinLoader {
public final static String VERSION="12.9";
public final static String DefaultSkinURL = "http://skins.minecraft.net/MinecraftSkins/*.png";
public final static String DefaultCloakURL = "http://skins.minecraft.net/MinecraftCloaks/*.png";
private final static Pattern newResPattern = Pattern.compile("^http://textures.minecraft.net/texture/(.*?)?(Skin|Cloak)=(.*?)$"),
newURLPattern = Pattern.compile("^http://skins.minecraft.net/Minecraft(Skin|Cloak)s/(.*?).png$"),
oldURLPattern = Pattern.compile("^http://s3.amazonaws.com/Minecraft(Skin|Cloak)s/(.*?).png$"),
optifineCapeURLPattern = Pattern.compile("^http://s.optifine.net/capes/(.*?).png$");
public final static File DATA_DIR=new File(Minecraft.getMinecraft().mcDataDir,"CustomSkinLoader"),
CACHE_DIR=new File(DATA_DIR,"caches"),
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
SKIN_URL_FILE=new File(DATA_DIR,"skinurls.txt"),
CAPE_URL_FILE=new File(DATA_DIR,"capeurls.txt");
public final static MainLogger logger = getLogger(LOG_FILE);
public final static String[] DEFAULT_SKIN_URLS={
"http://skins.minecraft.net/MinecraftSkins/*.png",
"http://minecrack.fr.nf/mc/skinsminecrackd/*.png",
"http://www.skinme.cc/MinecraftSkins/*.png"};
public final static String[] DEFAULT_CAPE_URLS={
"http://skins.minecraft.net/MinecraftCloaks/*.png",
"http://s.optifine.net/capes/*.png",
"http://minecrack.fr.nf/mc/cloaksminecrackd/*.png",
"http://www.skinme.cc/MinecraftCloaks/*.png"};
private static String[] cloakURLs = null, skinURLs = null;
private HttpURLConnection C = null;
//Entrance
public InputStream getPlayerSkinStream(String path) {
if(!DATA_DIR.exists())
DATA_DIR.mkdir();
if(!CACHE_DIR.exists())
CACHE_DIR.mkdir();
logger.info("Get a request: "+path);
if(path.contains("NOCSL"))//Not to use CSL to load, prepared for json api
return getStream(path, false);
Matcher m = newURLPattern.matcher(path);
if (!m.matches())//Is not new url
{
m = oldURLPattern.matcher(path);//May be old url
}
if (m.matches()) {
if (m.group(1).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(2));
else if (m.group(1).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(2));
}else{
m = newResPattern.matcher(path);
if(m.matches()){
if (m.group(2).contains("Skin")) // Skin
return getPlayerSkinStream(false, m.group(3));
else if (m.group(2).contains("Cloak")) // Cloak
return getPlayerSkinStream(true, m.group(3));
}else{
m = optifineCapeURLPattern.matcher(path);
if(m.matches()){//Optifine Cape
logger.info("Ignore Optifine Cape.");
return null;//Not Load This
}
}
}
return getStream(path, false); // Neither skin nor cloak...
}
public InputStream getPlayerSkinStream(Boolean isCloak, String playerName) {
if ((skinURLs == null|| skinURLs.length <= 0) && (cloakURLs == null || cloakURLs.length <= 0))
refreshSkinURL(); // If the list is blank or null, try to load again.
InputStream S=null;
for (String l : isCloak ? cloakURLs : skinURLs) {
if(l==null||l.equalsIgnoreCase(""))
continue;
String loc = str_replace("*", playerName, l);
logger.log(Level.INFO, "Try to load " + (isCloak ? "cloak" : "skin") + " in " + loc);
S = getStream(loc, true);
if (S == null){
logger.log(Level.INFO, "No " + (isCloak ? "cloak" : "skin") + " found in " + loc);
}else{
logger.info("Succeessfully load " + (isCloak ? "cloak" : "skin") + " in " + loc);
return S;
}
}
logger.log(Level.INFO, "Try to load skin in default URL instead.");
return getStream(str_replace("*", playerName, isCloak ? DefaultCloakURL : DefaultSkinURL), true);
}
private InputStream getStream(String URL, Boolean CheckPNG) {
boolean success=false;
File cacheFile=new File(CACHE_DIR,MD5(URL));
boolean alreadyCached=false;
if(cacheFile.exists()&&cacheFile.length()>1){
alreadyCached=true;
logger.info("Cache File Found (LastModified: "+cacheFile.lastModified()+" , Size: "+cacheFile.length()+")");
}
try {
URL U = new URL(URL);
C = (HttpURLConnection) U.openConnection();
C.setReadTimeout(15000);
C.setDoInput(true);
C.setDoOutput(false);
C.connect();
logger.info("Response Code: "+C.getResponseCode());
int respcode = C.getResponseCode() / 100;
if (respcode != 4 && respcode != 5) { // Successful to get skin.
if(C.getContentLength()<=0){//Nothing got
logger.info("Nothing got.");
return null;
}
logger.info("Successfully Get Resource (LastModified: "+C.getLastModified()+" , ContentLength: "+C.getContentLength()+")");
if(alreadyCached && C.getLastModified()==cacheFile.lastModified() && C.getContentLength()==cacheFile.length()){
logger.info("Not Modified.");
return getStreamFromCache(cacheFile);
}
InputStream IS=new BufferedInputStream(C.getInputStream());
if (!CheckPNG){ // If no need to check PNG header, just skip it.
success=true;
saveToCache(IS,cacheFile);
return IS;
}
//logger.info(C.getContentLength()+" "+IS.available());
IS.mark(C.getContentLength()+10);
byte[] ib = new byte[4];
IS.read(ib);
if (ib[1] == (byte) 'P' && ib[2] == (byte) 'N' && ib[3] == (byte) 'G') { // Check PNG Header if needed
IS.reset();
success=true;
saveToCache(IS,cacheFile);
return IS;
}
}
} catch (Exception ex) {
success=false;
logger.log(Level.WARNING, ex.getMessage());
if(alreadyCached)
return getStreamFromCache(cacheFile);
}finally{
if(!success)
disconnect();
}
return null;
}
private InputStream getStreamFromCache(File cacheFile) {
try{
logger.info("Try load local cache in " + cacheFile.getAbsolutePath());
InputStream in = new FileInputStream(cacheFile);
BufferedInputStream bis=new BufferedInputStream(in);
if(bis.available()<=0){
logger.info("Cannot load local cache in " + cacheFile.getAbsolutePath());
return null;
}else{
logger.info("Successfully load cache in " + cacheFile.getAbsolutePath());
return bis;
}
}catch(Exception e){
logger.log(Level.WARNING, e.getMessage());
return null;
}
}
private void saveToCache(InputStream is,File to){
logger.info("Try save local cache to " + to.getAbsolutePath());
FileOutputStream fs=null;
int times=0;
try{//Save to Local Skin File
if(to.exists()){
to.delete();
}
fs = new FileOutputStream(to);
int byteRead = 0;
byte[] buffer = new byte[1024];
while (( byteRead = is.read(buffer)) != -1) {
times+=byteRead;
fs.write(buffer, 0, byteRead);
if(times>=C.getContentLength()){
//logger.info(times+" "+C.getContentLength());
break;
}
}
if(to.length()>1){
to.setLastModified(C.getLastModified());
logger.info("Cache saved to " + to.getAbsolutePath()+" (LastModified: "+to.lastModified()+" , Size: "+to.length()+")");
}else{
to.delete();
logger.info("Cannot save local cache to " + to.getAbsolutePath());
}
}catch(Exception e){
logger.warning(e.getMessage());
}finally{
try {
if(fs!=null)
fs.close();
is.reset();
} catch (IOException e) {
logger.warning(e.getMessage());
}
}
}
public void disconnect() {
if (C != null)
C.disconnect();
}
private static void refreshSkinURL() {
try {
if(!SKIN_URL_FILE.exists()){
logger.log(Level.INFO, "SKIN config not found, create a new one.");
SKIN_URL_FILE.createNewFile();
}
if(!CAPE_URL_FILE.exists()){
logger.log(Level.INFO, "CAPE config not found, create a new one.");
CAPE_URL_FILE.createNewFile();
}
skinURLs = readAllLines(SKIN_URL_FILE);
cloakURLs = readAllLines(CAPE_URL_FILE);
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
} finally {
if(skinURLs.length==0&&cloakURLs.length==0){
logger.info("No skinURLs and cloak URLS found, try to init and use default settings.");
initSkinURL();
refreshSkinURL();
}else{
logger.log(Level.INFO, "Skin URLs Refreshed. Skin count = "
+ skinURLs.length + ", Cloak count = " + cloakURLs.length);
}
}
}
private static void initSkinURL(){
//Init URL List
skinURLs=DEFAULT_SKIN_URLS;
writeToFile(new File(DATA_DIR,"skinurls.txt"),parseArrayToText(skinURLs));
cloakURLs=DEFAULT_CAPE_URLS;
writeToFile(new File(DATA_DIR,"capeurls.txt"),parseArrayToText(cloakURLs));
}
private static String[] readAllLines(File F) {
try {
logger.log(Level.INFO, "Config file: " + F.getAbsolutePath());
if (F.length() <= 0) {
logger.log(Level.INFO, "Config file is blank, skipped.");
return new String[0];
} else {
byte[] b = new byte[(int) F.length()];
BufferedInputStream S = new BufferedInputStream(
new FileInputStream(F));
S.read(b);
S.close();
logger.log(Level.INFO, "Config file loaded.");
String[] re= str_replace("\r", "\n",
str_replace("\r\n", "\n", new String(b))).split("\n");
for(int i=0;i<re.length;i++){
if(re[i].startsWith("#"))//Remove note
re[i]=null;
else{//Remove same URL
for(int g=0;g<re.length;g++){
if(i==g)
continue;
if(re[i].equalsIgnoreCase(re[g])){
re[i]=null;
break;
}
}
}
}
return re;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
return new String[0];
}
}
private static String str_replace(String search, String replace,
String subject) {
StringBuffer result = new StringBuffer(subject);
int pos;
while ((pos = result.indexOf(search)) != -1)
result.replace(pos, pos + search.length(), replace);
return result.toString();
}
private static String parseArrayToText(String[] data){
StringBuilder temp=new StringBuilder();
for(int i=0;i<data.length-1;i++)
temp.append(data[i]).append("\r\n");
temp.append(data[data.length-1]);
return temp.toString();
}
private static boolean writeToFile(File file,String Data){
System.out.print("Write to "+file.getAbsolutePath()+" ");
FileWriter fw=null;
try{
fw = new FileWriter(file);
fw.write(Data,0,Data.length());
fw.flush();
fw.close();
}catch(Exception ex){
ex.printStackTrace();
System.out.println("failed.");
return false;
}
System.out.println("succeed.");
return true;
}
public String MD5(String str){
byte [] buf = str.getBytes();
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(buf);
byte [] tmp = md5.digest();
StringBuilder sb = new StringBuilder();
for (byte b:tmp) {
sb.append(Integer.toHexString(b&0xff));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
logger.warning(e.getMessage());
}
return "Fail";
}
private static MainLogger getLogger(File logFile){
MainLogger mainLogger = new MainLogger(logFile);
mainLogger.info("CustomSkinLoader " + VERSION);
return mainLogger;
}
}
@@ -0,0 +1,71 @@
package idv.jlchntoz;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
public class MainLogger {
private static final int LOWEST_DISPLAY_LEVEL=Level.INFO.intValue();
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private BufferedWriter writer;
public MainLogger(File logFile){
try {
if(!logFile.getParentFile().exists()){
logFile.getParentFile().mkdirs();
}
if(!logFile.exists())
logFile.createNewFile();
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(logFile), "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
}
public void close(){
if(writer!=null){
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void log(Level level,String msg){
if(level.intValue()>=LOWEST_DISPLAY_LEVEL)
System.out.println(msg);
try {
writer.write("[");
writer.write(DATE_FORMAT.format(new Date()));
writer.write(" ");
writer.write(Thread.currentThread().getName());
writer.write(" ");
writer.write(level.getName());
writer.write("] ");
writer.write(msg);
writer.write("\r\n");
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public void info(String msg){
log(Level.INFO,msg);
}
public void warning(String msg){
log(Level.WARNING,msg);
}
public void warning(Exception e){
log(Level.WARNING,"Exception occurs while running: "+e.getMessage());
StackTraceElement[] stes=e.getStackTrace();
for(StackTraceElement ste : stes){
log(Level.WARNING,ste.toString());
}
log(Level.WARNING,"");
}
}
@@ -0,0 +1,117 @@
package net.minecraft.client.renderer;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.ImageObserver;
public class ImageBufferDownload implements IImageBuffer
{
private int[] imageData;
private int imageWidth;
private int imageHeight;
public BufferedImage parseUserSkin(BufferedImage image)
{
if (image == null)
{
return null;
}
else
{
int ratio=image.getWidth()/64;
this.imageWidth = 64 * ratio;
this.imageHeight = 64 * ratio;
BufferedImage var2 = new BufferedImage(this.imageWidth, this.imageHeight, 2);
Graphics var3 = var2.getGraphics();
var3.drawImage(image, 0, 0, (ImageObserver)null);
if (image.getHeight() == 32 * ratio)
{
var3.drawImage(var2, 24 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 4 * ratio, 16 * ratio, 8 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 28 * ratio, 48 * ratio, 24 * ratio, 52 * ratio, 8 * ratio, 16 * ratio, 12 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 20 * ratio, 52 * ratio, 16 * ratio, 64 * ratio, 8 * ratio, 20 * ratio, 12 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 24 * ratio, 52 * ratio, 20 * ratio, 64 * ratio, 4 * ratio, 20 * ratio, 8 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 28 * ratio, 52 * ratio, 24 * ratio, 64 * ratio, 0 * ratio, 20 * ratio, 4 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 32 * ratio, 52 * ratio, 28 * ratio, 64 * ratio, 12 * ratio, 20 * ratio, 16 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 40 * ratio, 48 * ratio, 36 * ratio, 52 * ratio, 44 * ratio, 16 * ratio, 48 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 44 * ratio, 48 * ratio, 40 * ratio, 52 * ratio, 48 * ratio, 16 * ratio, 52 * ratio, 20 * ratio, (ImageObserver)null);
var3.drawImage(var2, 36 * ratio, 52 * ratio, 32 * ratio, 64 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 40 * ratio, 52 * ratio, 36 * ratio, 64 * ratio, 44 * ratio, 20 * ratio, 48 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 44 * ratio, 52 * ratio, 40 * ratio, 64 * ratio, 40 * ratio, 20 * ratio, 44 * ratio, 32 * ratio, (ImageObserver)null);
var3.drawImage(var2, 48 * ratio, 52 * ratio, 44 * ratio, 64 * ratio, 52 * ratio, 20 * ratio, 56 * ratio, 32 * ratio, (ImageObserver)null);
}
var3.dispose();
this.imageData = ((DataBufferInt)var2.getRaster().getDataBuffer()).getData();
this.setAreaOpaque(0, 0, 32 * ratio, 16 * ratio);
this.setAreaTransparent(32 * ratio, 0, 64 * ratio, 32 * ratio);
this.setAreaOpaque(0, 16 * ratio, 64 * ratio, 32 * ratio);
this.setAreaTransparent(0, 32 * ratio, 16 * ratio, 48 * ratio);
this.setAreaTransparent(16 * ratio, 32 * ratio, 40 * ratio, 48 * ratio);
this.setAreaTransparent(40 * ratio, 32 * ratio, 56 * ratio, 48 * ratio);
this.setAreaTransparent(0, 48 * ratio, 16 * ratio, 64 * ratio);
this.setAreaOpaque(16 * ratio, 48 * ratio, 48 * ratio, 64 * ratio);
this.setAreaTransparent(48 * ratio, 48 * ratio, 64 * ratio, 64 * ratio);
return var2;
}
}
public void skinAvailable()
{
}
/**
* Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
* layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
* maker is just using an image editor without an alpha channel)
*/
private void setAreaTransparent(int p_78434_1_, int p_78434_2_, int p_78434_3_, int p_78434_4_)
{
if (!this.hasTransparency(p_78434_1_, p_78434_2_, p_78434_3_, p_78434_4_))
{
for (int i = p_78434_1_; i < p_78434_3_; ++i)
{
for (int j = p_78434_2_; j < p_78434_4_; ++j)
{
this.imageData[i + j * this.imageWidth] &= 16777215;
}
}
}
}
/**
* Makes the given area of the image opaque
*/
private void setAreaOpaque(int p_78433_1_, int p_78433_2_, int p_78433_3_, int p_78433_4_)
{
for (int i = p_78433_1_; i < p_78433_3_; ++i)
{
for (int j = p_78433_2_; j < p_78433_4_; ++j)
{
this.imageData[i + j * this.imageWidth] |= -16777216;
}
}
}
/**
* Returns true if the given area of the image contains transparent pixels
*/
private boolean hasTransparency(int p_78435_1_, int p_78435_2_, int p_78435_3_, int p_78435_4_)
{
for (int i = p_78435_1_; i < p_78435_3_; ++i)
{
for (int j = p_78435_2_; j < p_78435_4_; ++j)
{
int k = this.imageData[i + j * this.imageWidth];
if ((k >> 24 & 255) < 128)
{
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,148 @@
package net.minecraft.client.renderer;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import idv.jlchntoz.CustomSkinLoader;
public class ThreadDownloadImageData extends SimpleTexture
{
private static final Logger logger = LogManager.getLogger();
private static final AtomicInteger threadDownloadCounter = new AtomicInteger(0);
private final File cacheFile;
private final String imageUrl;
private final IImageBuffer imageBuffer;
private BufferedImage bufferedImage;
private Thread imageThread;
private boolean textureUploaded;
//For Optifine
public Boolean imageFound = null;
public boolean pipeline = false;
public ThreadDownloadImageData(File cacheFileIn, String imageUrlIn, ResourceLocation textureResourceLocation, IImageBuffer imageBufferIn)
{
super(textureResourceLocation);
this.cacheFile = cacheFileIn;
this.imageUrl = imageUrlIn;
this.imageBuffer = imageBufferIn;
}
private void checkTextureUploaded()
{
if (!this.textureUploaded)
{
if (this.bufferedImage != null)
{
if (this.textureLocation != null)
{
this.deleteGlTexture();
}
TextureUtil.uploadTextureImage(super.getGlTextureId(), this.bufferedImage);
this.textureUploaded = true;
}
}
}
public int getGlTextureId()
{
this.checkTextureUploaded();
return super.getGlTextureId();
}
public void setBufferedImage(BufferedImage bufferedImageIn)
{
this.bufferedImage = bufferedImageIn;
if (this.imageBuffer != null)
{
this.imageBuffer.skinAvailable();
}
}
public void loadTexture(IResourceManager resourceManager) throws IOException
{
if (this.bufferedImage == null && this.textureLocation != null)
{
super.loadTexture(resourceManager);
}
if (this.imageThread == null)
{
if (this.cacheFile != null && this.cacheFile.isFile())
{
logger.info("Loading http texture from local cache ({})", new Object[] {this.cacheFile});
try
{
this.bufferedImage = ImageIO.read(this.cacheFile);
if (this.imageBuffer != null)
{
this.setBufferedImage(this.imageBuffer.parseUserSkin(this.bufferedImage));
}
}
catch (IOException ioexception)
{
logger.error((String)("Couldn\'t load skin " + this.cacheFile), (Throwable)ioexception);
this.loadTextureFromServer();
}
}
else
{
this.loadTextureFromServer();
}
}
}
protected void loadTextureFromServer()
{
this.imageThread = new Thread("Texture Downloader #" + threadDownloadCounter.incrementAndGet())
{
public void run()
{
CustomSkinLoader loader=new CustomSkinLoader();
ThreadDownloadImageData.logger.info("Downloading http texture from {} to {}", new Object[] {ThreadDownloadImageData.this.imageUrl, ThreadDownloadImageData.this.cacheFile});
try
{
BufferedImage bufferedimage;
bufferedimage = TextureUtil.readBufferedImage(loader.getPlayerSkinStream(ThreadDownloadImageData.this.imageUrl));
if (ThreadDownloadImageData.this.imageBuffer != null)
{
bufferedimage = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(bufferedimage);
}
ThreadDownloadImageData.this.setBufferedImage(bufferedimage);
return;
}
catch (Exception exception)
{
ThreadDownloadImageData.logger.error((String)"Couldn\'t download http texture", (Throwable)exception);
return;
}
finally
{
loader.disconnect();
}
}
};
this.imageThread.setDaemon(true);
this.imageThread.start();
}
}
@@ -0,0 +1,184 @@
package net.minecraft.client.resources;
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;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.ImageBufferDownload;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
public class SkinManager
{
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());
private final TextureManager textureManager;
private final File skinCacheDir;
private final MinecraftSessionService sessionService;
private final LoadingCache<GameProfile, Map<Type, MinecraftProfileTexture>> skinCacheLoader;
public SkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService)
{
this.textureManager = textureManagerInstance;
this.skinCacheDir = skinCacheDirectory;
this.sessionService = sessionService;
this.skinCacheLoader = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).<GameProfile, Map<Type, MinecraftProfileTexture>>build(new CacheLoader<GameProfile, Map<Type, MinecraftProfileTexture>>()
{
public Map<Type, MinecraftProfileTexture> load(GameProfile p_load_1_) throws Exception
{
return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false);
}
});
}
/**
* Used in the Skull renderer to fetch a skin. May download the skin if it's not in the cache
*/
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type p_152792_2_)
{
return this.loadSkin(profileTexture, p_152792_2_, (SkinManager.SkinAvailableCallback)null);
}
/**
* May download the skin if its not in the cache, can be passed a SkinManager#SkinAvailableCallback for handling
*/
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type p_152789_2_, final SkinManager.SkinAvailableCallback skinAvailableCallback)
{
final ResourceLocation resourcelocation = new ResourceLocation(p_152789_2_.name() + "/" + profileTexture.getHash());
/*Remove cache
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
if (itextureobject != null)
{
if (skinAvailableCallback != null)
{
skinAvailableCallback.skinAvailable(p_152789_2_, resourcelocation, profileTexture);
}
}
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()
{
public BufferedImage parseUserSkin(BufferedImage image)
{
if (iimagebuffer != null)
{
image = iimagebuffer.parseUserSkin(image);
}
return image;
}
public void skinAvailable()
{
if (iimagebuffer != null)
{
iimagebuffer.skinAvailable();
}
if (skinAvailableCallback != null)
{
skinAvailableCallback.skinAvailable(p_152789_2_, resourcelocation, profileTexture);
}
}
});
this.textureManager.loadTexture(resourcelocation, threaddownloadimagedata);
//}
return resourcelocation;
}
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure)
{
THREAD_POOL.submit(new Runnable()
{
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().func_181037_M());
map.putAll(SkinManager.this.sessionService.getTextures(profile, false));
}
//CustomSkinLoader Begin
Map<Type, MinecraftProfileTexture> var2 = Maps.<Type, MinecraftProfileTexture>newHashMap();
if (map.containsKey(Type.SKIN)){
MinecraftProfileTexture var3=((MinecraftProfileTexture)map.get(Type.SKIN));
String var4=var3.getMetadata("model");
Map var5 = null;
if(var4!=null){
var5 = Maps.newHashMap();
var5.put("model", var4);
}
var2.put(Type.SKIN, new MinecraftProfileTexture(var3.getUrl()+"?Skin="+profile.getName(),var5));
}else{
Map var5 = Maps.newHashMap();
//var5.put("model", "slim");
var2.put(Type.SKIN,new MinecraftProfileTexture( "http://skins.minecraft.net/MinecraftSkins/"+profile.getName()+".png",var5));
}
if (map.containsKey(Type.CAPE)){
var2.put(Type.CAPE, new MinecraftProfileTexture(((MinecraftProfileTexture)map.get(Type.CAPE)).getUrl()+"?Cloak="+profile.getName(),null));
}else{
var2.put(Type.CAPE,new MinecraftProfileTexture( "http://skins.minecraft.net/MinecraftCloaks/"+profile.getName()+".png",null));
}
map.clear();
map.putAll(var2);
//CustomSkinLoader End
Minecraft.getMinecraft().addScheduledTask(new Runnable()
{
public void run()
{
if (map.containsKey(Type.SKIN))
{
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN, skinAvailableCallback);
}
if (map.containsKey(Type.CAPE))
{
SkinManager.this.loadSkin((MinecraftProfileTexture)map.get(Type.CAPE), Type.CAPE, skinAvailableCallback);
}
}
});
}
});
}
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile)
{
return (Map)this.skinCacheLoader.getUnchecked(profile);
}
public interface SkinAvailableCallback
{
void skinAvailable(Type p_180521_1_, ResourceLocation location, MinecraftProfileTexture profileTexture);
}
}
+3
View File
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
TweakClass: idv.jlchntoz.tweaker.ForgeTweaker
TweakOrder: -10
@@ -0,0 +1,99 @@
package idv.jlchntoz.tweaker;
import idv.jlchntoz.CustomSkinLoader;
import java.io.*;
import java.net.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import net.minecraft.launchwrapper.IClassTransformer;
public class ClassTransformer implements IClassTransformer {
private ZipFile zipFile = null;
public ClassTransformer() {
ForgeTweaker.logger.info("ClassTransformer Begin");
try {
URLClassLoader ucl = (URLClassLoader)idv.jlchntoz.tweaker.ClassTransformer.class.getClassLoader();
URL urls[] = ucl.getURLs();
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
ZipFile tempZipFile = getZipFile(url);
if (tempZipFile == null)
continue;
zipFile = tempZipFile;
ForgeTweaker.logger.info("Jar File URL: " + url);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
if (zipFile == null) {
ForgeTweaker.logger.info("Can not find needed JAR in the classpath.");
}
}
private static ZipFile getZipFile(URL url)
{
ZipFile zipFile0;
try {
URI uri = url.toURI();
File file = new File(uri);
zipFile0 = new ZipFile(file);
if (zipFile0.getEntry("idv/jlchntoz/tweaker/ClassTransformer.class") != null){
ForgeTweaker.logger.info("JAR Found!");
return zipFile0;
}
zipFile0.close();
} catch (Exception e) {
}
return null;
}
public byte[] transform(String name, String transformedName, byte bytes[]) {
byte diBytes[] = getClass(name);
if (diBytes != null) {
ForgeTweaker.logger.info("Class '" + name + "' transformed.");
return diBytes;
}
else
return bytes;
}
private byte[] getClass(String name) {
if (zipFile == null)
return null;
String fullName = name + ".class";
ZipEntry ze = zipFile.getEntry(fullName);
if (ze == null)
return null;
try {
InputStream in = zipFile.getInputStream(ze);
byte[] bytes = readAll(in);
if ((long)bytes.length == ze.getSize())
return bytes;
ForgeTweaker.logger.info("Failed: " + fullName + " " + bytes.length + " / " + ze.getSize());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static byte[] readAll(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte buffer[] = new byte[1024];
do {
int len = is.read(buffer);
if (len >= 0) {
baos.write(buffer, 0, len);
} else {
is.close();
byte bytes[] = baos.toByteArray();
return bytes;
}
} while (true);
}
}
@@ -0,0 +1,39 @@
package idv.jlchntoz.tweaker;
import idv.jlchntoz.MainLogger;
import java.io.File;
import java.util.List;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.LaunchClassLoader;
public class ForgeTweaker implements ITweaker {
private static final File TWEAKER_LOG_FILE = new File("CustomSkinLoader/Tweaker.log");
public static MainLogger logger = new MainLogger(TWEAKER_LOG_FILE);
public ForgeTweaker() {
logger.info("Using ForgeTweaker");
}
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
logger.info("ForgeTweaker: acceptOptions");
}
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
logger.info("ForgeTweaker: injectIntoClassLoader");
classLoader.registerTransformer("idv.jlchntoz.tweaker.ClassTransformer");
logger.info("ClassTransformer Registered");
}
public String getLaunchTarget() {
logger.info("ForgeTweaker: getLaunchTarget");
return "net.minecraft.client.main.Main";
}
public String[] getLaunchArguments() {
logger.info("ForgeTweaker: getLaunchArguments");
return new String[0];
}
}
@@ -0,0 +1,54 @@
package idv.jlchntoz.tweaker;
import idv.jlchntoz.MainLogger;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.LaunchClassLoader;
public class Tweaker implements ITweaker {
private List args;
private String gameDir;
private String assetsDir;
private String profile;
private static final File TWEAKER_LOG_FILE = new File("CustomSkinLoader/Tweaker.log");
public static MainLogger logger = new MainLogger(TWEAKER_LOG_FILE);
public Tweaker() {
logger.info("Using Tweaker");
}
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
logger.info("Tweaker: acceptOptions");
this.args = new ArrayList(args);
this.gameDir = gameDir.getAbsolutePath();
this.assetsDir = assetsDir.getAbsolutePath();
this.profile = profile;
}
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
logger.info("Tweaker: injectIntoClassLoader");
logger.info("Loaded as a library.");
}
public String getLaunchTarget() {
logger.info("Tweaker: getLaunchTarget");
return "net.minecraft.client.main.Main";
}
public String[] getLaunchArguments() {
logger.info("Tweaker: getLaunchArguments");
this.args.add("--gameDir");
this.args.add(gameDir);
this.args.add("--assetsDir");
this.args.add(assetsDir);
this.args.add("--version");
this.args.add(profile);
return (String[])args.toArray(new String[args.size()]);
}
}
+14
View File
@@ -1,3 +1,17 @@
MCCustomSkinLoader
==================
版权所有(C) 2013-2016 JLChnToZ xfl03
这一程序是自由软件,你可以遵照自由软件基金会出版的GNU通用公共许可证条款来修改和重新发布这一程序。或者用许可证的第三版,或者(根据你的选择)用任何更新的版本。
发布这一程序的目的是希望它有用,但没有任何担保。甚至没有适合特定目的的隐含的担保。更详细的情况请参阅GNU通用公共许可证。
Copyright(C) 2013-2016 JLChnToZ xfl03
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
GPLv3: http://www.gnu.org/licenses/gpl.html