Skip to content

Commit

Permalink
Use direct game jar accesses for game patch processing instead of goi…
Browse files Browse the repository at this point in the history
…ng through the class loader
  • Loading branch information
sfPlayer1 committed Sep 30, 2021
1 parent 099dfb3 commit c2a0a0e
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ public class MinecraftGameProvider implements GameProvider {
private boolean useGameJarForLogging;
private boolean hasModLoader = false;

public static final GameTransformer TRANSFORMER = new GameTransformer(it -> Arrays.asList(
new EntrypointPatch(it),
new BrandingPatch(it),
new EntrypointPatchFML125(it)
));
private static final GameTransformer TRANSFORMER = new GameTransformer(
new EntrypointPatch(),
new BrandingPatch(),
new EntrypointPatchFML125());

@Override
public String getGameId() {
Expand Down Expand Up @@ -444,6 +443,8 @@ public void initialize(FabricLauncher launcher) {

setupLog4jLogHandler(launcher, true);
}

TRANSFORMER.locateEntrypoints(launcher, gameJar);
}

private void setupLog4jLogHandler(FabricLauncher launcher, boolean useTargetCl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import net.minecraft.launchwrapper.IClassTransformer;

import net.fabricmc.api.EnvType;
import net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider;
import net.fabricmc.loader.impl.FabricLoaderImpl;
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
import net.fabricmc.loader.impl.transformer.FabricTransformer;

Expand All @@ -29,7 +29,7 @@ public byte[] transform(String name, String transformedName, byte[] bytes) {
boolean isDevelopment = FabricLauncherBase.getLauncher().isDevelopment();
EnvType envType = FabricLauncherBase.getLauncher().getEnvironmentType();

byte[] input = MinecraftGameProvider.TRANSFORMER.transform(name);
byte[] input = FabricLoaderImpl.INSTANCE.getGameProvider().getEntrypointTransformer().transform(name);

if (input != null) {
return FabricTransformer.transform(isDevelopment, envType, name, input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) {

launchClassLoader.registerTransformer(FabricClassTransformer.class.getName());
FabricLoaderImpl.INSTANCE.loadAccessWideners();
MinecraftGameProvider.TRANSFORMER.locateEntrypoints(this);

// Setup Mixin environment
MixinBootstrap.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package net.fabricmc.loader.impl.game.minecraft.patch;

import java.io.IOException;
import java.util.ListIterator;
import java.util.function.Consumer;
import java.util.function.Function;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
Expand All @@ -28,32 +29,23 @@

import net.fabricmc.loader.impl.game.minecraft.Hooks;
import net.fabricmc.loader.impl.game.patch.GamePatch;
import net.fabricmc.loader.impl.game.patch.GameTransformer;
import net.fabricmc.loader.impl.launch.FabricLauncher;
import net.fabricmc.loader.impl.util.log.Log;
import net.fabricmc.loader.impl.util.log.LogCategory;

public final class BrandingPatch extends GamePatch {
public BrandingPatch(GameTransformer transformer) {
super(transformer);
}

@Override
public void process(FabricLauncher launcher, Consumer<ClassNode> classEmitter) {
public void process(FabricLauncher launcher, Function<String, ClassReader> classSource, Consumer<ClassNode> classEmitter) {
for (String brandClassName : new String[] {
"net.minecraft.client.ClientBrandRetriever",
"net.minecraft.server.MinecraftServer"
}) {
try {
ClassNode brandClass = loadClass(launcher, brandClassName);
ClassNode brandClass = readClass(classSource.apply(brandClassName));

if (brandClass != null) {
if (applyBrandingPatch(brandClass)) {
classEmitter.accept(brandClass);
}
if (brandClass != null) {
if (applyBrandingPatch(brandClass)) {
classEmitter.accept(brandClass);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Expand Down
Loading

0 comments on commit c2a0a0e

Please sign in to comment.