mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-22 00:22:16 +00:00
Fixed tweaker log
This commit is contained in:
1 parent
47f198b337
commit
fcb24315e5
6 files changed
+48
-43
No files matched your search
@@ -19,8 +19,11 @@ public class MinecraftUtil {
|
||||
return getMinecraftDataDir();
|
||||
}
|
||||
|
||||
private static String MINECRAFT_DATA_FOLDER=".minecraft";
|
||||
public static File minecraftDataFolder=null;
|
||||
private static final String MINECRAFT_DATA_FOLDER=".minecraft";
|
||||
public static File getMinecraftDataDir(){
|
||||
if(minecraftDataFolder!=null)
|
||||
return minecraftDataFolder;
|
||||
File temp=new File("");
|
||||
if(temp.getAbsolutePath().endsWith(MINECRAFT_DATA_FOLDER))
|
||||
return temp;
|
||||
@@ -11,7 +11,10 @@ import java.util.logging.Level;
|
||||
public class Logger {
|
||||
private static final int LOWEST_DISPLAY_LEVEL=Level.INFO.intValue();
|
||||
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private BufferedWriter writer;
|
||||
private BufferedWriter writer=null;
|
||||
public Logger(){
|
||||
//Logger isn't created.
|
||||
}
|
||||
public Logger(File logFile){
|
||||
try {
|
||||
if(!logFile.getParentFile().exists()){
|
||||
@@ -39,6 +42,8 @@ public class Logger {
|
||||
public void log(Level level,String msg){
|
||||
if(level.intValue()>=LOWEST_DISPLAY_LEVEL)
|
||||
System.out.println(msg);
|
||||
if(writer==null)
|
||||
return;
|
||||
try {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append("[");
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.net.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
public class ClassTransformer implements IClassTransformer {
|
||||
@@ -19,17 +21,19 @@ public class ClassTransformer implements IClassTransformer {
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
URL url = urls[i];
|
||||
ZipFile tempZipFile = getZipFile(url);
|
||||
if (tempZipFile == null)
|
||||
if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){
|
||||
tempZipFile.close();
|
||||
continue;
|
||||
}
|
||||
zipFile = tempZipFile;
|
||||
ForgeTweaker.logger.info("Jar File URL: " + url);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ForgeTweaker.logger.warning(e);
|
||||
}
|
||||
if (zipFile == null) {
|
||||
ForgeTweaker.logger.info("Can not find needed JAR in the classpath.");
|
||||
ForgeTweaker.logger.info("Can not find JAR in the classpath.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,61 +41,44 @@ public class ClassTransformer implements IClassTransformer {
|
||||
{
|
||||
ZipFile zipFile0;
|
||||
try {
|
||||
URI uri = url.toURI();
|
||||
File file = new File(uri);
|
||||
File file = new File(url.toURI());
|
||||
zipFile0 = new ZipFile(file);
|
||||
if (zipFile0.getEntry("customskinloader/tweaker/ClassTransformer.class") != null){
|
||||
ForgeTweaker.logger.info("JAR Found!");
|
||||
return zipFile0;
|
||||
}
|
||||
zipFile0.close();
|
||||
return zipFile0;
|
||||
} catch (Exception e) {
|
||||
ForgeTweaker.logger.warning(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] transform(String name, String transformedName, byte bytes[]) {
|
||||
byte diBytes[] = getClass(name);
|
||||
if (zipFile == null)
|
||||
return bytes;
|
||||
String fullName = name + ".class";
|
||||
ZipEntry ze = zipFile.getEntry(fullName);
|
||||
if (ze == null)
|
||||
return bytes;
|
||||
byte diBytes[] = getClass(ze);
|
||||
if (diBytes != null) {
|
||||
ForgeTweaker.logger.info("Class '" + name + "' transformed.");
|
||||
ForgeTweaker.logger.info("Class '" + name + "'("+transformedName+") 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);
|
||||
private byte[] getClass(ZipEntry ze) {
|
||||
if (ze == null)
|
||||
return null;
|
||||
try {
|
||||
InputStream in = zipFile.getInputStream(ze);
|
||||
byte[] bytes = readAll(in);
|
||||
InputStream is = zipFile.getInputStream(ze);
|
||||
byte[] bytes = IOUtils.toByteArray(is);
|
||||
if ((long)bytes.length == ze.getSize())
|
||||
return bytes;
|
||||
ForgeTweaker.logger.info("Failed: " + fullName + " " + bytes.length + " / " + ze.getSize());
|
||||
ForgeTweaker.logger.info("Failed: " + ze.getName() + " " + 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);
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,17 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
public class ForgeTweaker implements ITweaker {
|
||||
|
||||
private static final File TWEAKER_LOG_FILE = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log");
|
||||
public static Logger logger = new Logger(TWEAKER_LOG_FILE);
|
||||
public static Logger logger = new Logger();
|
||||
|
||||
public ForgeTweaker() {
|
||||
logger.info("Using ForgeTweaker");
|
||||
}
|
||||
|
||||
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
|
||||
MinecraftUtil.minecraftDataFolder=gameDir;
|
||||
File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log");
|
||||
logger = new Logger(tweakerLogFile);
|
||||
|
||||
logger.info("Using ForgeTweaker");
|
||||
logger.info("ForgeTweaker: acceptOptions");
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +17,18 @@ public class Tweaker implements ITweaker {
|
||||
private String assetsDir;
|
||||
private String profile;
|
||||
|
||||
private static final File TWEAKER_LOG_FILE = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log");
|
||||
public static Logger logger = new Logger(TWEAKER_LOG_FILE);
|
||||
public static Logger logger = new Logger();
|
||||
|
||||
public Tweaker() {
|
||||
logger.info("Using Tweaker");
|
||||
}
|
||||
|
||||
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
|
||||
MinecraftUtil.minecraftDataFolder=gameDir;
|
||||
File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log");
|
||||
logger = new Logger(tweakerLogFile);
|
||||
|
||||
logger.info("Using Tweaker");
|
||||
logger.info("Tweaker: acceptOptions");
|
||||
this.args = new ArrayList(args);
|
||||
this.gameDir = gameDir.getAbsolutePath();
|
||||
|
||||
@@ -19,8 +19,11 @@ public class MinecraftUtil {
|
||||
return net.minecraft.client.Minecraft.getMinecraft().mcDataDir;
|
||||
}
|
||||
|
||||
private static String MINECRAFT_DATA_FOLDER=".minecraft";
|
||||
public static File minecraftDataFolder=null;
|
||||
private static final String MINECRAFT_DATA_FOLDER=".minecraft";
|
||||
public static File getMinecraftDataDir(){
|
||||
if(minecraftDataFolder!=null)
|
||||
return minecraftDataFolder;
|
||||
File temp=new File("");
|
||||
if(temp.getAbsolutePath().endsWith(MINECRAFT_DATA_FOLDER))
|
||||
return temp;
|
||||
|
||||
Reference in new issue
Block a user