Skip to content

Commit

Permalink
Add backwards compatibility with 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Apr 20, 2024
1 parent fe204f0 commit ffce32c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/main/java/cpw/mods/modlauncher/LaunchServiceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

import cpw.mods.modlauncher.api.ILaunchHandlerService;
import cpw.mods.modlauncher.api.IModuleLayerManager.Layer;
import cpw.mods.modlauncher.api.ServiceRunner;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static cpw.mods.modlauncher.LogMarkers.MODLAUNCHER;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -20,6 +24,7 @@
import java.util.Optional;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.concurrent.Callable;

/**
* Identifies the launch target and dispatches to it
Expand All @@ -46,12 +51,30 @@ public Optional<ILaunchHandlerService> findLaunchHandler(final String name) {
}

private void launch(String target, String[] arguments, ModuleLayer gameLayer, TransformingClassLoader classLoader, LaunchPluginHandler launchPluginHandler) {
var launchServiceHandlerDecorator = handlers.get(target);
var paths = launchServiceHandlerDecorator.getPaths();
var service = handlers.get(target);
var paths = service.getPaths();
launchPluginHandler.announceLaunch(classLoader, paths);
LOGGER.info(MODLAUNCHER, "Launching target '{}' with arguments {}", target, hideAccessToken(arguments));

ServiceRunner runner = null;

try {
launchServiceHandlerDecorator.launchService(arguments, gameLayer).run();
runner = service.launchService(arguments, gameLayer);
} catch (AbstractMethodError e) {
var lookup = MethodHandles.lookup();
var type = MethodType.methodType(Callable.class, String[].class, ModuleLayer.class);
try {
var virtual = lookup.findVirtual(service.getClass(), "launchService", type);
Callable<Void> callable = (Callable<Void>)virtual.invokeExact(arguments, gameLayer);
runner = () -> callable.call();
} catch (Throwable t) {
sneak(t);
}
}

try {

runner.run();
} catch (Throwable e) {
sneak(e);
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/cpw/mods/modlauncher/TransformTargetLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

import cpw.mods.modlauncher.api.ITransformer;

import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

Expand Down Expand Up @@ -124,5 +126,17 @@ public <T> Supplier<TransformList<T>> mapSupplier(EnumMap<LabelType, TransformLi
return () -> (TransformList<T>) transformers.get(this);
}

/**
* Only here for backwards compatibility with < 10.0, Nobody should ever use this.
*/
@Deprecated(forRemoval = true, since = "10.0")
public static List<LabelType> getTypeFor(java.lang.reflect.Type type) {
switch (type.getTypeName()) {
case "org.objectweb.asm.tree.FieldNode": return List.of(FIELD);
case "org.objectweb.asm.tree.MethodNode": return List.of(METHOD);
case "org.objectweb.asm.tree.ClassNode": return List.of(CLASS, PRE_CLASS);
}
return Collections.emptyList();
}
}
}

0 comments on commit ffce32c

Please sign in to comment.