I am attempting to modify the Minecraft Launcher to store the games data in the current working directory. this is my first foray into java programing so i have no idea where to start. Here is the source of the offending class file: (the block that i think needs modifying starts on line 15)
File Util.class package net.minecraft;
import java.io.*;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.security.PublicKey;
import java.security.cert.Certificate;
import javax.net.ssl.HttpsURLConnection;
public class Util {
/* member class not found */
class OS {}
public Util() {
}
public static File getWorkingDirectory() {
if(workDir == null)
workDir = getWorkingDirectory("minecraft");
return workDir;
}
public static File getWorkingDirectory(String applicationName) {
String userHome = System.getProperty("user.home", ".");
File workingDirectory;
switch($SWITCH_TABLE$net$minecraft$Util$OS()[getPlatform().ordinal()]) {
case 1: // '\001'
case 2: // '\002'
workingDirectory = new File(userHome, (new StringBuilder(String.valueOf('.'))).append(applicationName).append('/').toString());
break;
case 3: // '\003'
String applicationData = System.getenv("APPDATA");
if(applicationData != null)
workingDirectory = new File(applicationData, (new StringBuilder(".")).append(applicationName).append('/').toString());
else
workingDirectory = new File(userHome, (new StringBuilder(String.valueOf('.'))).append(applicationName).append('/').toString());
break;
case 4: // '\004'
workingDirectory = new File(userHome, (new StringBuilder("Library/Application Support/")).append(applicationName).toString());
break;
default:
workingDirectory = new File(userHome, (new StringBuilder(String.valueOf(applicationName))).append('/').toString());
break;
}
if(!workingDirectory.exists() && !workingDirectory.mkdirs())
throw new RuntimeException((new StringBuilder("The working directory could not be created: ")).append(workingDirectory).toString());
else
return workingDirectory;
}
private static OS getPlatform() {
String osName = System.getProperty("os.name").toLowerCase();
if(osName.contains("win"))
return OS.windows;
if(osName.contains("mac"))
return OS.macos;
if(osName.contains("solaris"))
return OS.solaris;
if(osName.contains("sunos"))
return OS.solaris;
if(osName.contains("linux"))
return OS.linux;
if(osName.contains("unix"))
return OS.linux;
else
return OS.unknown;
}
public static String excutePost(String targetURL, String urlParameters) {
HttpsURLConnection connection = null;
String s;
URL url = new URL(targetURL);
connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", (new StringBuilder()).append(Integer.toString(urlParameters.getBytes().length)).toString());
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();
Certificate certs[] = connection.getServerCertificates();
byte bytes[] = new byte[294];
DataInputStream dis = new DataInputStream(net/minecraft/Util.getResourceAsStream("minecraft.key"));
dis.readFully(bytes);
dis.close();
Certificate c = certs[0];
PublicKey pk = c.getPublicKey();
byte data[] = pk.getEncoded();
for(int i = 0; i < data.length; i++)
if(data[i] != bytes[i])
throw new RuntimeException("Public key mismatch");
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
java.io.InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
StringBuffer response = new StringBuffer();
String line;
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
s = response.toString();
if(connection != null)
connection.disconnect();
return s;
Exception e;
e;
e.printStackTrace();
if(connection != null)
connection.disconnect();
return null;
Exception exception;
exception;
if(connection != null)
connection.disconnect();
throw exception;
}
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
public static void openLink(URI uri) {
try {
Object o = Class.forName("java.awt.Desktop").getMethod("getDesktop", new Class[0]).invoke(null, new Object[0]);
o.getClass().getMethod("browse", new Class[] {
java/net/URI
}).invoke(o, new Object[] {
uri
});
}
catch(Throwable e) {
System.out.println((new StringBuilder("Failed to open link ")).append(uri.toString()).toString());
}
}
static int[] $SWITCH_TABLE$net$minecraft$Util$OS() {
$SWITCH_TABLE$net$minecraft$Util$OS;
if($SWITCH_TABLE$net$minecraft$Util$OS == null) goto _L2; else goto _L1
_L1:
return;
_L2:
JVM INSTR pop ;
int ai[] = new int[OS.values().length];
try {
ai[OS.linux.ordinal()] = 1;
}
catch(NoSuchFieldError _ex) { }
try {
ai[OS.macos.ordinal()] = 4;
}
catch(NoSuchFieldError _ex) { }
try {
ai[OS.solaris.ordinal()] = 2;
}
catch(NoSuchFieldError _ex) { }
try {
ai[OS.unknown.ordinal()] = 5;
}
catch(NoSuchFieldError _ex) { }
try {
ai[OS.windows.ordinal()] = 3;
}
catch(NoSuchFieldError _ex) { }
return $SWITCH_TABLE$net$minecraft$Util$OS = ai;
}
private static File workDir = null;
private static int $SWITCH_TABLE$net$minecraft$Util$OS[];
}
I have done some research on getting the current working directory but i am not sure what needs modifing. If someone could at least explain what the various parts of the file mean that would be very helpful.
Im not too sure but I think this is what you should be modifying. It creates a .minecraft/ folder on the drive
case 3: // '\003'
String applicationData = System.getenv("APPDATA");
if(applicationData != null)
workingDirectory = new File(applicationData, (new StringBuilder(".")).append(applicationName).append('/').toString());
else
that's probably it, it looks like its checking the operating system in Util$OS(file located in the same directory) and sending it to this one or the other way around maybe? anyway it seems case 3 is the windows option. its probably complicated code there because it has to deal with the app data which is located in the users directory and the user's name is different for everyone. ill probably look into this more but have limited java knowledge myself. this should also bump this post for more helpful replies :biggrin.gif:
File Util.class package net.minecraft; import java.io.*; import java.lang.reflect.Method; import java.net.URI; import java.net.URL; import java.security.PublicKey; import java.security.cert.Certificate; import javax.net.ssl.HttpsURLConnection; public class Util { /* member class not found */ class OS {} public Util() { } public static File getWorkingDirectory() { if(workDir == null) workDir = getWorkingDirectory("minecraft"); return workDir; } public static File getWorkingDirectory(String applicationName) { String userHome = System.getProperty("user.home", "."); File workingDirectory; switch($SWITCH_TABLE$net$minecraft$Util$OS()[getPlatform().ordinal()]) { case 1: // '\001' case 2: // '\002' workingDirectory = new File(userHome, (new StringBuilder(String.valueOf('.'))).append(applicationName).append('/').toString()); break; case 3: // '\003' String applicationData = System.getenv("APPDATA"); if(applicationData != null) workingDirectory = new File(applicationData, (new StringBuilder(".")).append(applicationName).append('/').toString()); else workingDirectory = new File(userHome, (new StringBuilder(String.valueOf('.'))).append(applicationName).append('/').toString()); break; case 4: // '\004' workingDirectory = new File(userHome, (new StringBuilder("Library/Application Support/")).append(applicationName).toString()); break; default: workingDirectory = new File(userHome, (new StringBuilder(String.valueOf(applicationName))).append('/').toString()); break; } if(!workingDirectory.exists() && !workingDirectory.mkdirs()) throw new RuntimeException((new StringBuilder("The working directory could not be created: ")).append(workingDirectory).toString()); else return workingDirectory; } private static OS getPlatform() { String osName = System.getProperty("os.name").toLowerCase(); if(osName.contains("win")) return OS.windows; if(osName.contains("mac")) return OS.macos; if(osName.contains("solaris")) return OS.solaris; if(osName.contains("sunos")) return OS.solaris; if(osName.contains("linux")) return OS.linux; if(osName.contains("unix")) return OS.linux; else return OS.unknown; } public static String excutePost(String targetURL, String urlParameters) { HttpsURLConnection connection = null; String s; URL url = new URL(targetURL); connection = (HttpsURLConnection)url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", (new StringBuilder()).append(Integer.toString(urlParameters.getBytes().length)).toString()); connection.setRequestProperty("Content-Language", "en-US"); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); connection.connect(); Certificate certs[] = connection.getServerCertificates(); byte bytes[] = new byte[294]; DataInputStream dis = new DataInputStream(net/minecraft/Util.getResourceAsStream("minecraft.key")); dis.readFully(bytes); dis.close(); Certificate c = certs[0]; PublicKey pk = c.getPublicKey(); byte data[] = pk.getEncoded(); for(int i = 0; i < data.length; i++) if(data[i] != bytes[i]) throw new RuntimeException("Public key mismatch"); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); java.io.InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); StringBuffer response = new StringBuffer(); String line; while((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); s = response.toString(); if(connection != null) connection.disconnect(); return s; Exception e; e; e.printStackTrace(); if(connection != null) connection.disconnect(); return null; Exception exception; exception; if(connection != null) connection.disconnect(); throw exception; } public static boolean isEmpty(String str) { return str == null || str.length() == 0; } public static void openLink(URI uri) { try { Object o = Class.forName("java.awt.Desktop").getMethod("getDesktop", new Class[0]).invoke(null, new Object[0]); o.getClass().getMethod("browse", new Class[] { java/net/URI }).invoke(o, new Object[] { uri }); } catch(Throwable e) { System.out.println((new StringBuilder("Failed to open link ")).append(uri.toString()).toString()); } } static int[] $SWITCH_TABLE$net$minecraft$Util$OS() { $SWITCH_TABLE$net$minecraft$Util$OS; if($SWITCH_TABLE$net$minecraft$Util$OS == null) goto _L2; else goto _L1 _L1: return; _L2: JVM INSTR pop ; int ai[] = new int[OS.values().length]; try { ai[OS.linux.ordinal()] = 1; } catch(NoSuchFieldError _ex) { } try { ai[OS.macos.ordinal()] = 4; } catch(NoSuchFieldError _ex) { } try { ai[OS.solaris.ordinal()] = 2; } catch(NoSuchFieldError _ex) { } try { ai[OS.unknown.ordinal()] = 5; } catch(NoSuchFieldError _ex) { } try { ai[OS.windows.ordinal()] = 3; } catch(NoSuchFieldError _ex) { } return $SWITCH_TABLE$net$minecraft$Util$OS = ai; } private static File workDir = null; private static int $SWITCH_TABLE$net$minecraft$Util$OS[]; }I have done some research on getting the current working directory but i am not sure what needs modifing. If someone could at least explain what the various parts of the file mean that would be very helpful.
that's probably it, it looks like its checking the operating system in Util$OS(file located in the same directory) and sending it to this one or the other way around maybe? anyway it seems case 3 is the windows option. its probably complicated code there because it has to deal with the app data which is located in the users directory and the user's name is different for everyone. ill probably look into this more but have limited java knowledge myself. this should also bump this post for more helpful replies :biggrin.gif: