Skip to content

Commit

Permalink
Improve build. Fix Fabric in dev env. Fix splash screen patch in b1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Lassebq committed Sep 11, 2024
1 parent ff5e9ea commit 2b7c072
Show file tree
Hide file tree
Showing 23 changed files with 550 additions and 192 deletions.
68 changes: 32 additions & 36 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ archivesBaseName = 'launchwrapper'

project.ext.asm_version = 9.7

def ENV = System.getenv()

dependencies {
// implementation 'org.mcphackers.rdi:rdi:1.0'
implementation name: 'rdi-1.0-SNAPSHOT'
implementation "org.mcphackers.rdi:rdi:1.0"
implementation "org.ow2.asm:asm:${project.asm_version}"
implementation "org.ow2.asm:asm-util:${project.asm_version}"
implementation "org.ow2.asm:asm-tree:${project.asm_version}"
implementation 'org.json:json:20230311'
implementation "org.json:json:20230311"
// I'll bring discord RPC support later, when I have an environment to compile natives

testRuntimeOnly('org.junit.platform:junit-platform-launcher:1.5.2')
Expand All @@ -33,12 +35,13 @@ allprojects {
apply plugin: 'maven-publish'

group = 'org.mcphackers'
version = '1.0-SNAPSHOT'
project.version = '1.0'
if(!ENV.RELEASE.equals('1')) {
project.version += '-SNAPSHOT'
}

repositories {
flatDir {
dirs "libs"
}
mavenLocal()
maven {
url "https://libraries.minecraft.net/"
}
Expand All @@ -61,18 +64,12 @@ allprojects {
archives sourcesJar
}

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// Not possible due to unsafe usage
// if (JavaVersion.current().isJava9Compatible()) {
// it.options.release.set(8)
// }
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

compileJava {
options.encoding = "UTF-8"

// Minecraft is mostly compatible with java 5 up until the version we support, so why not?
if (JavaVersion.current().ordinal() <= JavaVersion.VERSION_1_8.ordinal()) {
sourceCompatibility = JavaVersion.VERSION_1_5
Expand All @@ -85,29 +82,28 @@ allprojects {
targetCompatibility = JavaVersion.VERSION_1_8
}

publishing {
publications {
mavenJava(MavenPublication) {
groupId = "${project.group}"
artifactId = "${project.archivesBaseName}"
version = "${project.version}"

artifact jar
artifact sourcesJar
afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = project.archivesBaseName
artifact jar
artifact sourcesJar
}
}
}

repositories {
mavenLocal()

def ENV = System.getenv()
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
if (ENV.MAVEN_USERNAME) {
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
repositories {
mavenLocal()
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
if (ENV.MAVEN_USERNAME) {
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions launchwrapper-fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ repositories {
maven {
url "https://maven.fabricmc.net/"
}
maven {
url "https://maven.glass-launcher.net/babric/"
}
}

archivesBaseName = 'launchwrapper-fabric'
Expand All @@ -17,9 +14,8 @@ compileJava {

dependencies {
implementation rootProject
implementation name: "rdi-1.0-SNAPSHOT"
implementation "babric:fabric-loader:0.14.24-babric.1"
// implementation 'org.mcphackers.rdi:rdi:1.0'
implementation "org.mcphackers.rdi:rdi:1.0"
implementation "net.fabricmc:fabric-loader:0.16.4"
implementation "org.ow2.asm:asm:${project.asm_version}"
implementation "org.ow2.asm:asm-tree:${project.asm_version}"
implementation "org.ow2.asm:asm-util:${project.asm_version}"
Expand Down
Binary file removed launchwrapper-fabric/libs/rdi-1.0-SNAPSHOT.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
import net.fabricmc.loader.impl.metadata.ModDependencyImpl;
import net.fabricmc.loader.impl.util.Arguments;
import net.fabricmc.loader.impl.util.ExceptionUtil;
import net.fabricmc.loader.impl.util.SystemProperties;

public class LWGameProvider implements GameProvider {

public LaunchConfig config = FabricBridge.getInstance().config;
public MainLaunchTarget target = null;

private Arguments arguments;
private Path gameJar;
private List<Path> lwjglJars = new ArrayList<>();
private Path launchwrapperJar;
Expand Down Expand Up @@ -102,6 +104,8 @@ private Path getLaunchwrapperSource() {
@Override
public boolean locateGame(FabricLauncher launcher, String[] args) {
this.envType = launcher.getEnvironmentType();
this.arguments = new Arguments();
arguments.parse(args);

String entrypoint = null;
try {
Expand Down Expand Up @@ -144,9 +148,11 @@ public boolean locateGame(FabricLauncher launcher, String[] args) {

ObjectShare share = FabricLoaderImpl.INSTANCE.getObjectShare();
share.put("fabric-loader:inputGameJar", gameJar); // deprecated
share.put("fabric-loader:inputGameJars", Collections.singleton(gameJar));
share.put("fabric-loader:inputGameJars", Collections.singletonList(gameJar));

versionData = McVersionLookup.getVersion(Collections.singletonList(gameJar), entrypoint, config.version.get());
String version = arguments.remove(Arguments.GAME_VERSION);
if (version == null) version = System.getProperty(SystemProperties.GAME_VERSION);
versionData = McVersionLookup.getVersion(Collections.singletonList(gameJar), entrypoint, version);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.function.Function;
import java.util.zip.ZipError;

import org.mcphackers.launchwrapper.loader.SafeClassWriter;
import org.mcphackers.launchwrapper.target.MainLaunchTarget;
import org.mcphackers.launchwrapper.tweak.Tweak;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
Expand Down Expand Up @@ -96,7 +97,8 @@ public byte[] transform(String className) {
}
// Fabric's GameTransformer did not compute max stack and local
// Tweaks rely on writer computing maxes for it
ClassWriter writer = new ClassWriter(COMPUTE_MAXS);
// Also don't trust existing frames
ClassWriter writer = new SafeClassWriter(this, COMPUTE_MAXS | COMPUTE_FRAMES);
node.accept(writer);
return writer.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.IntInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;

import net.fabricmc.loader.impl.game.minecraft.Hooks;

Expand Down Expand Up @@ -46,7 +46,7 @@ public boolean apply(ClassNodeSource source, LaunchConfig config) {
if(m.name.equals("<init>")) {
InsnList insns = new InsnList();
insns.add(getGameDirectory(config));
insns.add(new IntInsnNode(ALOAD, 0));
insns.add(new VarInsnNode(ALOAD, 0));
insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Hooks.INTERNAL_NAME, "startClient",
"(Ljava/io/File;Ljava/lang/Object;)V", false));
m.instructions.insertBefore(getLastReturn(m.instructions.getLast()), insns);
Expand Down
Binary file removed libs/rdi-1.0-SNAPSHOT.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include 'launchwrapper-fabric'
include 'launchwrapper-micromixin'
// include 'launchwrapper-micromixin'
1 change: 0 additions & 1 deletion src/main/java/org/mcphackers/launchwrapper/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected void setupDiscordRPC() {
// TODO
}

@Deprecated
public static Launch getInstance() {
return INSTANCE;
}
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/org/mcphackers/launchwrapper/LaunchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.mcphackers.launchwrapper.protocol.SkinType;
import org.mcphackers.launchwrapper.util.OS;

@SuppressWarnings("unused")
public class LaunchConfig {
private static final File defaultGameDir = getDefaultGameDir();
private Map<String, LaunchParameter<?>> parameters = new HashMap<String, LaunchParameter<?>>();
Expand Down Expand Up @@ -46,11 +47,13 @@ public class LaunchConfig {
public LaunchParameterString userType = new LaunchParameterString("userType");
public LaunchParameterString versionType = new LaunchParameterString("versionType");
public LaunchParameterSwitch applet = new LaunchParameterSwitch("applet", false);
public LaunchParameterSwitch haspaid = new LaunchParameterSwitch("haspaid", true);
public LaunchParameterSwitch haspaid = new LaunchParameterSwitch("haspaid", true);
private LaunchParameterSwitch unlicensedCopy = new LaunchParameterSwitchReverse("unlicensedCopy", haspaid);
public LaunchParameterString loadmap_user = new LaunchParameterString("loadmap_user");
public LaunchParameterNumber loadmap_id = new LaunchParameterNumber("loadmap_id");
public LaunchParameterString mppass = new LaunchParameterString("mppass", "");
public LaunchParameterSwitch lwjglFrame = new LaunchParameterSwitch("awtFrame", true, true);
public LaunchParameterSwitch lwjglFrame = new LaunchParameterSwitch("lwjglFrame", true, true);
private LaunchParameterSwitch awtFrame = new LaunchParameterSwitchReverse("awtFrame", lwjglFrame);
public LaunchParameterSwitch isom = new LaunchParameterSwitch("isom", false, true);
public LaunchParameterSwitch forceVsync = new LaunchParameterSwitch("forceVsync", false, true);
public LaunchParameterSwitch forceResizable = new LaunchParameterSwitch("forceResizable", false, true);
Expand Down Expand Up @@ -133,6 +136,7 @@ public LaunchConfig(String[] args) {
}
if(uuid.get() == null && username.get() != null) {
// Purely cosmetic change. Makes skins in modern versions when only provided with username
// FIXME could hang until connection timeout without running the game
uuid.set(SkinRequests.getUUIDfromName(username.get()));
}
}
Expand Down Expand Up @@ -303,6 +307,22 @@ public void setString(String argument) {
this.value = newValue;
}
}
public class LaunchParameterSwitchReverse extends LaunchParameterSwitch {
LaunchParameterSwitch parent;
public LaunchParameterSwitchReverse(String name, LaunchParameterSwitch parent) {
super(name, !parent.defaultValue, true);
this.parent = parent;
}

public void set(Boolean b) {
super.set(b);
parent.value = !value;
}

public Boolean get() {
return(!parent.value);
}
}

public class LaunchParameterSwitch extends LaunchParameter<Boolean> {
public LaunchParameterSwitch(String name) {
Expand Down Expand Up @@ -332,11 +352,11 @@ public void setString(String argument) {
}

public void setFlag() {
this.value = !defaultValue;
this.set(true);
}

public void toggle() {
this.value = !value;
this.set(!value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ private ProtectionDomain getProtectionDomain(String name) {
public void overrideClass(ClassNode node) {
if(node == null)
return;
saveDebugClass(node);
overridenClasses.put(className(node.name), node);
classNodeCache.put(node.name, node);
}
Expand All @@ -211,7 +210,7 @@ public void saveDebugClass(ClassNode node) {
try {
File cls = new File(debugOutput, node.name + ".class");
cls.getParentFile().mkdirs();
// TraceClassVisitor trace = new TraceClassVisitor(new java.io.PrintWriter(new File(debugOutput, node.name + ".dump")));
// org.objectweb.asm.util.TraceClassVisitor trace = new org.objectweb.asm.util.TraceClassVisitor(new java.io.PrintWriter(new File(debugOutput, node.name + ".dump")));
// node.accept(trace);
ClassWriter writer = new SafeClassWriter(this, COMPUTE_MAXS | COMPUTE_FRAMES);
node.accept(writer);
Expand Down Expand Up @@ -244,7 +243,7 @@ public ClassNode getClass(String name) {
}
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(is);
classReader.accept(classNode, 0);
classReader.accept(classNode, ClassReader.SKIP_FRAMES);
classNodeCache.put(classNode.name, classNode);
return classNode;
} catch (IOException e) {
Expand Down Expand Up @@ -319,9 +318,9 @@ private Class<?> transformedClass(String name) throws ClassNotFoundException {
if(tweak != null) {
if(tweak.tweakClass(this, classNodeName(name))) {
transformed = overridenClasses.get(name);
saveDebugClass(transformed);
}
}
saveDebugClass(transformed);
return redefineClass(transformed);
}
return redefineClass(name);
Expand Down Expand Up @@ -349,7 +348,7 @@ private static ClassNode getSystemClass(Class<?> cls) {
try {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(is);
classReader.accept(classNode, 0);
classReader.accept(classNode, ClassReader.SKIP_FRAMES);
return classNode;
} catch (IOException e) {
Util.closeSilently(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ protected URLConnection openConnection(URL url) throws IOException {
if(path.equals("/game/joinserver.jsp"))
// TODO: update this to use the "sessionserver.mojang.com" API instead?
return super.openConnection(new URL("https", "session.minecraft.net", file));
if(path.equals("/login/session.jsp"))
return new BasicResponseURLConnection(url, "ok");
if(host.equals("login.minecraft.net") && path.equals("/session"))
return new BasicResponseURLConnection(url, "ok");
if(path.equals("/login/session.jsp") || host.equals("login.minecraft.net") && path.equals("/session")) {
// UnlicensedCopyText injection does this instead. (It doesn't fire the check thread fro some reason)
if(config.haspaid.get()) {
return new BasicResponseURLConnection(url, "ok");
} else {
return new BasicResponseURLConnection(url, 400, "");
}
}
if(path.equals("/game/"))
return new BasicResponseURLConnection(url, "42069");
if(path.equals("/client"))
return new BasicResponseURLConnection(url, "idk");
return new BasicResponseURLConnection(url, "idk"); // TODO figure out what this API endpoint is for
if(path.equals("/haspaid.jsp"))
return new BasicResponseURLConnection(url, "true");
return new BasicResponseURLConnection(url, "true"); // TODO Where is this used?
if(path.contains("/level/save.html"))
return new SaveLevelURLConnection(url, config.gameDir.get());
if(path.contains("/level/load.html"))
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/org/mcphackers/launchwrapper/tweak/BTATweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
import org.mcphackers.launchwrapper.tweak.injection.legacy.FixShutdown;
import org.mcphackers.launchwrapper.tweak.injection.legacy.LegacyInit;
import org.mcphackers.launchwrapper.tweak.injection.legacy.ReplaceGameDir;
import org.mcphackers.launchwrapper.tweak.injection.legacy.SplashScreenFix;
import org.mcphackers.launchwrapper.tweak.injection.legacy.FixSplashScreen;

/**
* Based on LegacyTweak but less invasive in order to maintain compatibility
* with BTA. BTA provides some fixes so LaunchWrapper doesn't need to apply them
*/
public class BTATweak extends LegacyTweak {

public BTATweak(LaunchConfig launch) {
super(launch);
}

@Override
@Override
public List<Injection> getInjections() {
return Arrays.<Injection>asList(
new LegacyInit(context),
new SplashScreenFix(context),
new FixShutdown(context),
// new LWJGLPatch(context),
new ReplaceGameDir(context)
);
new LegacyInit(context),
new FixSplashScreen(context),
new FixShutdown(context),
// new LWJGLPatch(context),
new ReplaceGameDir(context));
}

}
Loading

0 comments on commit 2b7c072

Please sign in to comment.