-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhauled Project Structure and add Java Agent/ModLauncher Support (#2)
* feat: split project into subprojects - still wip also added support for ModLauncher (Forge 1.13+) and JVM agents * feat: change compile target to Java 7 to also support older minecraft versions * chore(actions): bump jdk version to 16 since it's the required version for modlauncher * chore: merge manifests of subprojects in bundleJar task * chore: compile modlauncher module with Java 8 to fix startup in 1.13-1.16 * fix: do not throw exception on attempted reinitialization * feat: prevent double-patching of mods when the agent is active * fix(modlauncher): add class locator so patched mods can find the patched OIS correctly * feat: add more patches to default config --------- Co-authored-by: Dogboy21 <[email protected]>
- Loading branch information
Showing
29 changed files
with
679 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
dependencies { | ||
implementation project(':core') | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes([ | ||
"Premain-Class": "io.dogboy.serializationisbad.agent.SerializationIsBadAgent", | ||
"Can-Redefine-Classes": "true", | ||
]) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
agent/src/main/java/io/dogboy/serializationisbad/agent/SIBTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.dogboy.serializationisbad.agent; | ||
|
||
import io.dogboy.serializationisbad.core.Patches; | ||
import io.dogboy.serializationisbad.core.SerializationIsBad; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
import java.lang.instrument.ClassFileTransformer; | ||
import java.lang.instrument.IllegalClassFormatException; | ||
import java.security.ProtectionDomain; | ||
|
||
public class SIBTransformer implements ClassFileTransformer { | ||
@Override | ||
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { | ||
String classNameDots = className.replace('/', '.'); | ||
|
||
if (Patches.getPatchModuleForClass(classNameDots) == null) return classfileBuffer; | ||
|
||
SerializationIsBad.logger.info("Applying patches to " + classNameDots); | ||
|
||
ClassNode classNode = Patches.readClassNode(classfileBuffer); | ||
Patches.applyPatches(classNameDots, classNode); | ||
return Patches.writeClassNode(classNode); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
agent/src/main/java/io/dogboy/serializationisbad/agent/SerializationIsBadAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.dogboy.serializationisbad.agent; | ||
|
||
import io.dogboy.serializationisbad.core.SerializationIsBad; | ||
|
||
import java.io.File; | ||
import java.lang.instrument.Instrumentation; | ||
|
||
public class SerializationIsBadAgent { | ||
|
||
public static void premain(String agentArgs, Instrumentation inst) { | ||
SerializationIsBad.init(new File(".")); | ||
inst.addTransformer(new SIBTransformer()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,32 @@ | ||
buildscript { | ||
repositories { | ||
maven { url = 'https://maven.minecraftforge.net/' } | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'net.minecraftforge.gradle:ForgeGradle:3.+' | ||
} | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
apply plugin: 'net.minecraftforge.gradle' | ||
apply plugin: 'eclipse' | ||
apply plugin: 'maven-publish' | ||
|
||
version = '1.1.1' | ||
group = 'io.dogboy.serializationisbad' | ||
archivesBaseName = 'serializationisbad' | ||
|
||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' | ||
|
||
minecraft { | ||
mappings channel: 'snapshot', version: '20171003-1.12' | ||
subprojects { | ||
apply plugin: 'java' | ||
|
||
runs { | ||
client { | ||
workingDirectory project.file('run') | ||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.7' | ||
|
||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' | ||
property 'forge.logging.console.level', 'debug' | ||
repositories { | ||
maven { | ||
url = 'https://maven.minecraftforge.net' | ||
} | ||
|
||
server { | ||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' | ||
property 'forge.logging.console.level', 'debug' | ||
maven { | ||
url = 'https://libraries.minecraft.net' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2860' | ||
} | ||
|
||
jar { | ||
exclude("cpw/mods/fml/relauncher/FMLInjectionData.class") | ||
task bundleJar(type: Jar, dependsOn: subprojects.assemble) { | ||
archivesBaseName = rootProject.name | ||
from project(':core').configurations.archives.allArtifacts.files.collect { zipTree(it) } | ||
from project(':legacyforge').configurations.archives.allArtifacts.files.collect { zipTree(it) } | ||
from project(':modlauncher').configurations.archives.allArtifacts.files.collect { zipTree(it) } | ||
from project(':agent').configurations.archives.allArtifacts.files.collect { zipTree(it) } | ||
|
||
manifest { | ||
attributes([ | ||
"Specification-Title": project.name, | ||
"Specification-Vendor": "dogboy21", | ||
"Specification-Version": "1", | ||
"Implementation-Title": project.name, | ||
"Implementation-Version": "${version}", | ||
"Implementation-Vendor" :"dogboy21", | ||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), | ||
"FMLCorePlugin": "io.dogboy.serializationisbad.SerializationIsBad", | ||
]) | ||
from subprojects.collect{ it.jar.manifest } | ||
} | ||
} | ||
|
||
jar.finalizedBy('reobfJar') | ||
build.dependsOn bundleJar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apply plugin: 'java-library' | ||
|
||
dependencies { | ||
implementation 'com.google.code.gson:gson:2.10.1' | ||
api 'org.apache.logging.log4j:log4j-api:2.20.0' | ||
api 'org.ow2.asm:asm-tree:9.5' | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes([ | ||
"Specification-Title": rootProject.name, | ||
"Specification-Vendor": "dogboy21", | ||
"Specification-Version": "1", | ||
"Implementation-Title": rootProject.name, | ||
"Implementation-Version": "${rootProject.version}", | ||
"Implementation-Vendor" : "dogboy21", | ||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
core/src/main/java/io/dogboy/serializationisbad/core/SerializationIsBad.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.dogboy.serializationisbad.core; | ||
|
||
import com.google.gson.Gson; | ||
import io.dogboy.serializationisbad.core.config.SIBConfig; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class SerializationIsBad { | ||
public static final Logger logger = LogManager.getLogger(SerializationIsBad.class); | ||
private static SerializationIsBad instance; | ||
private static boolean agentActive = false; | ||
|
||
public static SerializationIsBad getInstance() { | ||
return SerializationIsBad.instance; | ||
} | ||
|
||
public static void init(File minecraftDir) { | ||
if (SerializationIsBad.instance != null) { | ||
SerializationIsBad.logger.warn("Attempted to initialize SerializationIsBad twice, skipping"); | ||
return; | ||
} | ||
|
||
String implementationType = SerializationIsBad.getImplementationType(); | ||
if (implementationType.equals("agent")) { | ||
SerializationIsBad.agentActive = true; | ||
} | ||
SerializationIsBad.logger.info("Initializing SerializationIsBad, implementation type: " + implementationType); | ||
SerializationIsBad.instance = new SerializationIsBad(minecraftDir); | ||
} | ||
|
||
private final SIBConfig config; | ||
|
||
private SerializationIsBad(File minecraftDir) { | ||
this.config = SerializationIsBad.readConfig(minecraftDir); | ||
|
||
SerializationIsBad.logger.info("Loaded config file"); | ||
SerializationIsBad.logger.info(" Blocking Enabled: " + this.config.isExecuteBlocking()); | ||
SerializationIsBad.logger.info(" Loaded Patch Modules: " + this.config.getPatchModules().size()); | ||
} | ||
|
||
public SIBConfig getConfig() { | ||
return this.config; | ||
} | ||
|
||
private static SIBConfig readConfig(File minecraftDir) { | ||
File configFile = new File(new File(minecraftDir, "config"), "serializationisbad.json"); | ||
|
||
if (configFile.isFile()) { | ||
Gson gson = new Gson(); | ||
try (FileInputStream fileInputStream = new FileInputStream(configFile)) { | ||
return gson.fromJson(new InputStreamReader(fileInputStream, StandardCharsets.UTF_8), | ||
SIBConfig.class); | ||
} catch (Exception e) { | ||
SerializationIsBad.logger.error("Failed to load config file", e); | ||
} | ||
} | ||
|
||
return new SIBConfig(); | ||
} | ||
|
||
private static String getImplementationType() { | ||
for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) { | ||
if (stackTraceElement.getClassName().startsWith("io.dogboy.serializationisbad.") | ||
&& !stackTraceElement.getClassName().startsWith("io.dogboy.serializationisbad.core.")) { | ||
return stackTraceElement.getClassName().split("[.]")[3]; | ||
} | ||
} | ||
|
||
return "unknown"; | ||
} | ||
|
||
public static boolean isAgentActive() { | ||
return SerializationIsBad.agentActive; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...erializationisbad/config/PatchModule.java → ...izationisbad/core/config/PatchModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../serializationisbad/config/SIBConfig.java → ...alizationisbad/core/config/SIBConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# Sets default memory used for gradle commands. Can be overridden by user or command line properties. | ||
# This is required to provide enough memory for the Minecraft decompilation process. | ||
org.gradle.jvmargs=-Xmx3G | ||
org.gradle.daemon=false | ||
group=io.dogboy.serializationisbad | ||
name=serializationisbad | ||
version=1.2 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip |
Oops, something went wrong.