mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-25 01:44:24 +00:00
Use UTF-8 Charset
This commit is contained in:
1 parent
bbc355365a
commit
b08122913b
4 files changed
+30
-31
No files matched your search
@@ -8,6 +8,7 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -28,10 +29,10 @@ import customskinloader.utils.MinecraftUtil;
|
||||
/**
|
||||
* Custom skin loader mod for Minecraft.
|
||||
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
|
||||
* @version 14.3 (2016.8.9)
|
||||
* @version 14.4 (2016.8.13)
|
||||
*/
|
||||
public class CustomSkinLoader {
|
||||
public static final String CustomSkinLoader_VERSION="14.3";
|
||||
public static final String CustomSkinLoader_VERSION="14.4";
|
||||
public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir0(),"CustomSkinLoader"),
|
||||
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
|
||||
CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json");
|
||||
@@ -189,7 +190,7 @@ public class CustomSkinLoader {
|
||||
}
|
||||
try {
|
||||
logger.info("Try to load config.");
|
||||
String json=IOUtils.toString(new FileInputStream(CONFIG_FILE));
|
||||
String json=IOUtils.toString(new FileInputStream(CONFIG_FILE),Charsets.UTF_8);
|
||||
Config config=GSON.fromJson(json, Config.class);
|
||||
logger.info("Successfully load config.");
|
||||
return config;
|
||||
@@ -214,7 +215,7 @@ public class CustomSkinLoader {
|
||||
CONFIG_FILE.delete();
|
||||
try {
|
||||
CONFIG_FILE.createNewFile();
|
||||
IOUtils.write(json, new FileOutputStream(CONFIG_FILE));
|
||||
IOUtils.write(json, new FileOutputStream(CONFIG_FILE),Charsets.UTF_8);
|
||||
logger.info("Successfully "+(update?"update":"create")+" config.");
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed to "+(update?"update":"create")+" config.("+e.toString()+")");
|
||||
|
||||
@@ -26,11 +26,23 @@ public class ClassTransformer implements IClassTransformer {
|
||||
URLClassLoader ucl = (URLClassLoader)this.getClass().getClassLoader();
|
||||
URL urls[] = ucl.getURLs();
|
||||
for (URL url : urls) {
|
||||
ZipFile tempZipFile = getZipFile(url);
|
||||
if(tempZipFile==null)
|
||||
if(MinecraftUtil.isCoreFile(url)){
|
||||
ModSystemTweaker.logger.info(url.toString()+" : SKIP (is core file).");
|
||||
continue;
|
||||
}
|
||||
File file = new File(url.toURI());
|
||||
if(file==null||!file.isFile()){
|
||||
ModSystemTweaker.logger.info(url.toString()+" : SKIP (file not found).");
|
||||
continue;
|
||||
}
|
||||
ZipFile tempZipFile = getZipFile(file);
|
||||
if(tempZipFile==null){
|
||||
ModSystemTweaker.logger.info(url.toString()+" : SKIP (^^^Exception^^^).");
|
||||
continue;
|
||||
}
|
||||
if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){
|
||||
tempZipFile.close();
|
||||
ModSystemTweaker.logger.info(url.toString()+" : SKIP (is not target).");
|
||||
continue;
|
||||
}
|
||||
zipFile = tempZipFile;
|
||||
@@ -39,13 +51,13 @@ public class ClassTransformer implements IClassTransformer {
|
||||
while(entries.hasMoreElements()){
|
||||
ZipEntry entry=entries.nextElement();
|
||||
String name=entry.getName();
|
||||
if(name.endsWith(".class")&&!name.contains("/")){
|
||||
if(name.endsWith(".class")&&(!name.contains("/")||name.startsWith("net"))){
|
||||
classes.add(name);
|
||||
sb.append(" ");
|
||||
sb.append(name);
|
||||
}
|
||||
}
|
||||
ModSystemTweaker.logger.info("Jar File URL: " + url);
|
||||
ModSystemTweaker.logger.info(url.toString()+" : CHOOSE.");
|
||||
ModSystemTweaker.logger.info("Classes:" + sb.toString());
|
||||
break;
|
||||
}
|
||||
@@ -57,15 +69,10 @@ public class ClassTransformer implements IClassTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
private static ZipFile getZipFile(URL url)
|
||||
private static ZipFile getZipFile(File file)
|
||||
{
|
||||
if(MinecraftUtil.isCoreFile(url))
|
||||
return null;
|
||||
ZipFile zipFile0=null;
|
||||
try {
|
||||
File file = new File(url.toURI());
|
||||
if(!file.exists()||!file.isFile())
|
||||
return null;
|
||||
zipFile0 = new ZipFile(file);
|
||||
return zipFile0;
|
||||
} catch (Exception e) {
|
||||
@@ -78,7 +85,7 @@ public class ClassTransformer implements IClassTransformer {
|
||||
if (zipFile == null)
|
||||
return bytes;
|
||||
|
||||
String fullName = name + ".class";
|
||||
String fullName = name.replaceAll(".", "/") + ".class";
|
||||
if(!classes.contains(fullName))
|
||||
return bytes;
|
||||
ZipEntry ze = zipFile.getEntry(fullName);
|
||||
|
||||
@@ -7,15 +7,14 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
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 String[] args;
|
||||
|
||||
public static Logger logger = new Logger();
|
||||
|
||||
@@ -26,10 +25,8 @@ public class Tweaker implements ITweaker {
|
||||
|
||||
logger.info("Using Tweaker");
|
||||
logger.info("Tweaker: acceptOptions");
|
||||
this.args = new ArrayList(args);
|
||||
this.gameDir = gameDir.getAbsolutePath();
|
||||
this.assetsDir = assetsDir.getAbsolutePath();
|
||||
this.profile = profile;
|
||||
String[] temp={"--gameDir",gameDir.getAbsolutePath(),"--assetsDir",assetsDir.getAbsolutePath(),"--version",profile};
|
||||
this.args=ArrayUtils.addAll((String[])args.toArray(), temp);
|
||||
}
|
||||
|
||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
@@ -44,12 +41,6 @@ public class Tweaker implements ITweaker {
|
||||
|
||||
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()]);
|
||||
return args;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class HttpUtil0 {
|
||||
* Get faked url after redirect.
|
||||
* Using this method, can also check if it is exist.
|
||||
* @param url - before redirect
|
||||
* @return url - faked after redirect (null for not exist)
|
||||
* @return url - faked url after redirect (null for not exist)
|
||||
* @since 14.1
|
||||
*/
|
||||
public static String getFakeUrl(String url,String userAgent){
|
||||
|
||||
Reference in new issue
Block a user