Compare commits

..

2 Commits
v1.0 ... main

4 changed files with 29 additions and 14 deletions

View File

@ -15,5 +15,5 @@ This is pretty straightforward, just make a `.jar` file with the contents of the
## Using
Simple, just add `-javaagent:path/to/the/built.jar` before `.jar` when you start the launcher located in the `~/paladium-games` folder.
Simple, just add `-javaagent:path/to/the/built.jar` before `-jar` when you start the launcher located in the `~/paladium-games` folder.
Also be sure to use Java 8 for better compatibility.

View File

@ -12,7 +12,6 @@
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -4,27 +4,45 @@ import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import java.lang.Class;
import java.lang.String;
import java.lang.Exception;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import net.x3f200c.pala4linux.launcherpatch.LauncherPatcher;
public class LauncherPatch {
public static void premain(String agentArgs, Instrumentation inst) {
try {
prepareCertificates();
} catch (Exception e) {
System.out.println("[PalaLauncher4Linux] Failed to prepare certificates. ");
}
patch(inst);
}
public static void agentmain(String agentArgs, Instrumentation inst) {
try {
prepareCertificates();
} catch (Exception e) {
System.out.println("[PalaLauncher4Linux] Failed to prepare certificates. ");
}
patch(inst);
}
public static void prepareCertificates() throws Exception {
URL apacheMavenRepository = new URL("https://repo.maven.apache.org");
HttpsURLConnection connection = (HttpsURLConnection) apacheMavenRepository.openConnection();
connection.connect();
connection.disconnect();
}
public static void patch(Instrumentation inst) {
Class<?> routeHandlerClass = null;
ClassLoader routeHandlerClassLoader = null;
try {
routeHandlerClass = Class.forName("fr.paladium.router.route.common.CommonRoute");
routeHandlerClassLoader = routeHandlerClass.getClassLoader();
} catch(ClassNotFoundException e) {
}
LauncherPatcher dt = new LauncherPatcher(routeHandlerClass.getName(), routeHandlerClassLoader);
LauncherPatcher dt = new LauncherPatcher(routeHandlerClass.getName());
inst.addTransformer(dt, true);

View File

@ -10,24 +10,22 @@ import javassist.NotFoundException;
import javassist.CannotCompileException;
class LauncherPatcher implements ClassFileTransformer {
private final String targetClassName;
private final String routeTargetClassName;
public LauncherPatcher(String className, ClassLoader classLoader) {
this.targetClassName = className;
public LauncherPatcher(String routerClassName) {
this.routeTargetClassName = routerClassName;
}
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> redefinedClass, ProtectionDomain protectionDomain, byte[] classBuffer) {
byte[] bytecode = classBuffer;
String finalTargetClassName = this.targetClassName.replaceAll("\\.", "/");
if (!className.equals(finalTargetClassName)) {
return bytecode;
}
if (className.equals(finalTargetClassName)) {
try {
ClassPool cp = ClassPool.getDefault();
String finalRouterClassName = this.routeTargetClassName.replaceAll("\\.", "/");
if (className.equals(finalRouterClassName)) {
try {
CtClass crClass = cp.get("fr.paladium.router.route.common.CommonRoute");
CtMethod osGetterMethod = crClass.getDeclaredMethod("handleGetOS");