From c816d66a984f3189302e24a6be644776b4b970ac Mon Sep 17 00:00:00 2001 From: Hallowizer <40325350+Hallowizer@users.noreply.github.com> Date: Fri, 13 Jul 2018 15:43:12 -0700 Subject: [PATCH 1/2] Update Launch.java --- .../net/minecraft/launchwrapper/Launch.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraft/launchwrapper/Launch.java b/src/main/java/net/minecraft/launchwrapper/Launch.java index 3fe49e7..0436fad 100644 --- a/src/main/java/net/minecraft/launchwrapper/Launch.java +++ b/src/main/java/net/minecraft/launchwrapper/Launch.java @@ -18,18 +18,39 @@ import org.apache.logging.log4j.Level; +/** + * The main class of the launch wrapper. + * + * @author cpw, Erik Broes, Mumfrey, and Nathan Adams + * + */ public class Launch { private static final String DEFAULT_TWEAK = "net.minecraft.launchwrapper.VanillaTweaker"; + + /** + * The game dir of Minecraft. + */ public static File minecraftHome; + + /** + * The asset dir of Minecraft. + */ public static File assetsDir; + + /** + * A map that contains information that tweakers can access. + */ public static Map blackboard; - + public static void main(String[] args) { new Launch().launch(args); } - + + /** + * The class loader to register transformers to. + */ public static LaunchClassLoader classLoader; - + private Launch() { final URLClassLoader ucl = (URLClassLoader) getClass().getClassLoader(); classLoader = new LaunchClassLoader(ucl.getURLs()); From bf212dee5a57869911d8c5b3dbe73ae800c3d3c4 Mon Sep 17 00:00:00 2001 From: Hallowizer <40325350+Hallowizer@users.noreply.github.com> Date: Sat, 18 Aug 2018 18:23:16 -0700 Subject: [PATCH 2/2] Add javadoc to all source files. --- .../launchwrapper/AlphaVanillaTweaker.java | 6 + .../launchwrapper/IClassNameTransformer.java | 22 +++- .../launchwrapper/IClassTransformer.java | 16 ++- .../net/minecraft/launchwrapper/ITweaker.java | 37 +++++- .../launchwrapper/IndevVanillaTweaker.java | 6 + .../net/minecraft/launchwrapper/Launch.java | 35 ++++-- .../launchwrapper/LaunchClassLoader.java | 81 +++++++++++-- .../minecraft/launchwrapper/LogWrapper.java | 110 ++++++++++++++++-- .../launchwrapper/VanillaTweaker.java | 6 + .../injector/AlphaVanillaTweakInjector.java | 20 +++- .../injector/IndevVanillaTweakInjector.java | 13 ++- .../injector/VanillaTweakInjector.java | 18 ++- 12 files changed, 323 insertions(+), 47 deletions(-) diff --git a/src/main/java/net/minecraft/launchwrapper/AlphaVanillaTweaker.java b/src/main/java/net/minecraft/launchwrapper/AlphaVanillaTweaker.java index a471a2b..fdaaf5e 100644 --- a/src/main/java/net/minecraft/launchwrapper/AlphaVanillaTweaker.java +++ b/src/main/java/net/minecraft/launchwrapper/AlphaVanillaTweaker.java @@ -3,6 +3,12 @@ import java.io.File; import java.util.List; +/** + * A tweaker for the Alpha versions of Minecraft. + * + * @author Nathan Adams + * + */ public class AlphaVanillaTweaker implements ITweaker { private List args; diff --git a/src/main/java/net/minecraft/launchwrapper/IClassNameTransformer.java b/src/main/java/net/minecraft/launchwrapper/IClassNameTransformer.java index c635831..d2c99d1 100644 --- a/src/main/java/net/minecraft/launchwrapper/IClassNameTransformer.java +++ b/src/main/java/net/minecraft/launchwrapper/IClassNameTransformer.java @@ -1,9 +1,25 @@ package net.minecraft.launchwrapper; +/** + * A transformer that transforms the names of classes. Please note that even though this interface does not extend {@link IClassTransformer}, name transformers registered to the class loader must implement it. + * + * @author Erik Broes + * + */ public interface IClassNameTransformer { - + /** + * Unmaps a class name. + * + * @param name The original name of the class. + * @return The unmapped name, which will become the name passed to {@link IClassTransformer#transform}. + */ String unmapClassName(String name); - + + /** + * Remaps a class name. + * + * @param name The original name of the class. + * @return The remapped name, which will become the transformedName passed tp {@link IClassTransformer#transform}. + */ String remapClassName(String name); - } diff --git a/src/main/java/net/minecraft/launchwrapper/IClassTransformer.java b/src/main/java/net/minecraft/launchwrapper/IClassTransformer.java index 229b278..dba0ea7 100644 --- a/src/main/java/net/minecraft/launchwrapper/IClassTransformer.java +++ b/src/main/java/net/minecraft/launchwrapper/IClassTransformer.java @@ -1,7 +1,19 @@ package net.minecraft.launchwrapper; +/** + * A transformer that modifies bytecode of classes loaded by the class loader. + * + * @author Erik Broes + * + */ public interface IClassTransformer { - + /** + * Transforms the bytecode of a class. + * + * @param name The untransformed name of the class, which is the result of {@link IClassNameTransformer#unmapClassName}, or the original name if no class name transformer is present. + * @param transformedName The transformed name of the class, which is the result of {@link IClassNameTransformer#remapClassName}, or the original name if no class name transformer is present. + * @param basicClass The bytecode of the class to transform. + * @return The transformed bytecode. + */ byte[] transform(String name, String transformedName, byte[] basicClass); - } diff --git a/src/main/java/net/minecraft/launchwrapper/ITweaker.java b/src/main/java/net/minecraft/launchwrapper/ITweaker.java index 91ede35..92d83d7 100644 --- a/src/main/java/net/minecraft/launchwrapper/ITweaker.java +++ b/src/main/java/net/minecraft/launchwrapper/ITweaker.java @@ -3,14 +3,41 @@ import java.io.File; import java.util.List; +/** + * A tweaker that changes parts of Minecraft. + * + * @author Erik Broes + * + */ public interface ITweaker { - + /** + * Provides the tweaker with options that may influence the behavior. + * + * @param args The arguments that were passed, excluding the gameDir, assetsDir, profile, and tweakClass arguments. + * @param gameDir The game directory that Minecraft is being launched in. + * @param assetsDir The directory that contains Minecraft's assets. + * @param profile The version that Minecraft is being launched in. + */ void acceptOptions(List args, File gameDir, final File assetsDir, String profile); - + + /** + * Performs injection into the class loader. Transformers are registered with {@link LaunchClassLoader#registerTransformer}. + * + * @param classLoader The class loader where transformers should be injected. The tweak class was not loaded with this class loader. + */ void injectIntoClassLoader(LaunchClassLoader classLoader); - + + /** + * Gets the main class that should be launched. This method is only invoked on the primary tweaker (the tweaker that appears first). + * + * @return The main class. + */ String getLaunchTarget(); - + + /** + * Gets a list of arguments. This list will be combined with arguments from other tweakers to form an uber list. Please note that the original launch args are not added automatically. + * + * @return A list of arguments to add. + */ String[] getLaunchArguments(); - } diff --git a/src/main/java/net/minecraft/launchwrapper/IndevVanillaTweaker.java b/src/main/java/net/minecraft/launchwrapper/IndevVanillaTweaker.java index 1bfc0ea..a5ad1f1 100644 --- a/src/main/java/net/minecraft/launchwrapper/IndevVanillaTweaker.java +++ b/src/main/java/net/minecraft/launchwrapper/IndevVanillaTweaker.java @@ -3,6 +3,12 @@ import java.io.File; import java.util.List; +/** + * A tweaker to inject into the Indev versions of Minecraft. + * + * @author Nathan Adams + * + */ public class IndevVanillaTweaker implements ITweaker { private List args; diff --git a/src/main/java/net/minecraft/launchwrapper/Launch.java b/src/main/java/net/minecraft/launchwrapper/Launch.java index 0436fad..9706f3a 100644 --- a/src/main/java/net/minecraft/launchwrapper/Launch.java +++ b/src/main/java/net/minecraft/launchwrapper/Launch.java @@ -28,12 +28,12 @@ public class Launch { private static final String DEFAULT_TWEAK = "net.minecraft.launchwrapper.VanillaTweaker"; /** - * The game dir of Minecraft. + * The game dir of Minecraft. Changing this will change the gameDir value passed to tweakers. */ public static File minecraftHome; /** - * The asset dir of Minecraft. + * The asset dir of Minecraft. Changing this will change the assetsDir value passed to tweakers. */ public static File assetsDir; @@ -42,49 +42,62 @@ public class Launch { */ public static Map blackboard; + /** + * The main method. Please don't invoke this. + * + * @param args The command line arguments. + */ public static void main(String[] args) { new Launch().launch(args); } /** - * The class loader to register transformers to. + * The class loader to register transformers to. Changing this will change the class loader passed to tweakers. */ public static LaunchClassLoader classLoader; + /** + * Creates a new instance of Launch. This is only used in the main method. + */ private Launch() { final URLClassLoader ucl = (URLClassLoader) getClass().getClassLoader(); classLoader = new LaunchClassLoader(ucl.getURLs()); blackboard = new HashMap(); Thread.currentThread().setContextClassLoader(classLoader); } - + + /** + * Runs the launch wrapper. This is only used in the main method. + * + * @param args The command line arguments. + */ private void launch(String[] args) { final OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); - + final OptionSpec profileOption = parser.accepts("version", "The version we launched with").withRequiredArg(); final OptionSpec gameDirOption = parser.accepts("gameDir", "Alternative game directory").withRequiredArg().ofType(File.class); final OptionSpec assetsDirOption = parser.accepts("assetsDir", "Assets directory").withRequiredArg().ofType(File.class); final OptionSpec tweakClassOption = parser.accepts("tweakClass", "Tweak class(es) to load").withRequiredArg().defaultsTo(DEFAULT_TWEAK); final OptionSpec nonOption = parser.nonOptions(); - + final OptionSet options = parser.parse(args); minecraftHome = options.valueOf(gameDirOption); assetsDir = options.valueOf(assetsDirOption); final String profileName = options.valueOf(profileOption); final List tweakClassNames = new ArrayList(options.valuesOf(tweakClassOption)); - + final List argumentList = new ArrayList(); // This list of names will be interacted with through tweakers. They can append to this list // any 'discovered' tweakers from their preferred mod loading mechanism // By making this object discoverable and accessible it's possible to perform // things like cascading of tweakers blackboard.put("TweakClasses", tweakClassNames); - + // This argument list will be constructed from all tweakers. It is visible here so // all tweakers can figure out if a particular argument is present, and add it if not blackboard.put("ArgumentList", argumentList); - + // This is to prevent duplicates - in case a tweaker decides to add itself or something final Set allTweakerNames = new HashSet(); // The 'definitive' list of tweakers @@ -127,7 +140,7 @@ private void launch(String[] args) { primaryTweaker = tweaker; } } - + // Now, iterate all the tweakers we just instantiated for (final Iterator it = tweakers.iterator(); it.hasNext(); ) { final ITweaker tweaker = it.next(); @@ -146,7 +159,7 @@ private void launch(String[] args) { for (final ITweaker tweaker : allTweakers) { argumentList.addAll(Arrays.asList(tweaker.getLaunchArguments())); } - + // Finally we turn to the primary tweaker, and let it tell us where to go to launch final String launchTarget = primaryTweaker.getLaunchTarget(); final Class clazz = Class.forName(launchTarget, false, classLoader); diff --git a/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java b/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java index 9a6c8eb..f240cb2 100644 --- a/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java +++ b/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java @@ -18,7 +18,16 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; +/** + * The class loader to inject transformers in to. + * + * @author cpw, Erik Broes, Mumfrey, and Nathan Adams + * + */ public class LaunchClassLoader extends URLClassLoader { + /** + * The size of the chunks when fully reading a stream. + */ public static final int BUFFER_SIZE = 1 << 12; private List sources; private ClassLoader parent = getClass().getClassLoader(); @@ -42,7 +51,12 @@ public class LaunchClassLoader extends URLClassLoader { private static final boolean DEBUG_FINER = DEBUG && Boolean.parseBoolean(System.getProperty("legacy.debugClassLoadingFiner", "false")); private static final boolean DEBUG_SAVE = DEBUG && Boolean.parseBoolean(System.getProperty("legacy.debugClassLoadingSave", "false")); private static File tempFolder = null; - + + /** + * Creates a new {@link LaunchClassLoader}. + * + * @param sources The URLs to load from. + */ public LaunchClassLoader(URL[] sources) { super(sources, null); this.sources = new ArrayList(Arrays.asList(sources)); @@ -78,7 +92,12 @@ public LaunchClassLoader(URL[] sources) { } } } - + + /** + * Registers a transformer. The transformer will be loaded with this class loader, not the parent one. + * + * @param transformerClassName The transformer to inject. + */ public void registerTransformer(String transformerClassName) { try { IClassTransformer transformer = (IClassTransformer) loadClass(transformerClassName).newInstance(); @@ -90,7 +109,12 @@ public void registerTransformer(String transformerClassName) { LogWrapper.log(Level.ERROR, e, "A critical problem occurred registering the ASM transformer class %s", transformerClassName); } } - + + /** + * Loads in a class. It is recommended to use {@link ClassLoader#loadClass} instead. + * + * @param name The name of the class to load. + */ @Override public Class findClass(final String name) throws ClassNotFoundException { if (invalidClasses.contains(name)) { @@ -275,13 +299,23 @@ private byte[] runTransformers(final String name, final String transformedName, } return basicClass; } - + + /** + * Adds a URL for the class loader to check. + * + * @param url The url to add. + */ @Override public void addURL(final URL url) { super.addURL(url); sources.add(url); } - + + /** + * Gets the URL list. + * + * @return A list of URLs that this class loader checks. + */ public List getSources() { return sources; } @@ -320,19 +354,41 @@ private byte[] getOrCreateBuffer() { } return buffer; } - + + /** + * Gets the transformers injected. + * + * @return An immutable list of transformers. + */ public List getTransformers() { return Collections.unmodifiableList(transformers); } - + + /** + * Adds the given prefix to the class loader exclusion list. Classes that have a prefix in this list will be loaded with the parent class loader. + * + * @param toExclude The prefix to exclude. + */ public void addClassLoaderExclusion(String toExclude) { classLoaderExceptions.add(toExclude); } - + + /** + * Adds the given prefix to the transformer exclusion list. Classes that have a prefix in this list will be loaded without transformers being run on them. + * + * @param toExclude The prefix to exclude. + */ public void addTransformerExclusion(String toExclude) { transformerExceptions.add(toExclude); } - + + /** + * Gets the bytecode of a class. + * + * @param name The name of the class. + * @return The untransformed bytecode of the class. + * @throws IOException If the class loader fails to open a connection to the URL. + */ public byte[] getClassBytes(String name) throws IOException { if (negativeResourceCache.contains(name)) { return null; @@ -380,7 +436,12 @@ private static void closeSilently(Closeable closeable) { } } } - + + /** + * Removes entries that were previously marked invalid. + * + * @param entriesToClear The entries to remove. + */ public void clearNegativeEntries(Set entriesToClear) { negativeResourceCache.removeAll(entriesToClear); } diff --git a/src/main/java/net/minecraft/launchwrapper/LogWrapper.java b/src/main/java/net/minecraft/launchwrapper/LogWrapper.java index 7037b74..9326bac 100644 --- a/src/main/java/net/minecraft/launchwrapper/LogWrapper.java +++ b/src/main/java/net/minecraft/launchwrapper/LogWrapper.java @@ -4,7 +4,16 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +/** + * A wrapper for the log4j logger. + * + * @author Erik Broes and cpw + * + */ public class LogWrapper { + /** + * The instance. + */ public static LogWrapper log = new LogWrapper(); private Logger myLog; @@ -14,58 +23,137 @@ private static void configureLogging() { log.myLog = LogManager.getLogger("LaunchWrapper"); configured = true; } - + + /** + * Redirects this logger. + * + * @param to The logger to redirect to. + */ public static void retarget(Logger to) { log.myLog = to; } + + /** + * Logs a message. + * + * @param logChannel The channel to log on. + * @param level The severity level to log at. + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void log(String logChannel, Level level, String format, Object... data) { makeLog(logChannel); LogManager.getLogger(logChannel).log(level, String.format(format, data)); } - + + /** + * Logs a message. + * + * @param level The severity level to log at. + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void log(Level level, String format, Object... data) { if (!configured) { configureLogging(); } log.myLog.log(level, String.format(format, data)); } - + + /** + * Logs a message. + * + * @param logChannel The channel to log on. + * @param level The severity level to log at. + * @param ex The exception that occurred. + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void log(String logChannel, Level level, Throwable ex, String format, Object... data) { makeLog(logChannel); LogManager.getLogger(logChannel).log(level, String.format(format, data), ex); } - + + /** + * Logs a message. + * + * @param level The severity level to log at. + * @param ex The exception that occurred. + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void log(Level level, Throwable ex, String format, Object... data) { if (!configured) { configureLogging(); } log.myLog.log(level, String.format(format, data), ex); } - + + /** + * Logs a message at level SEVERE. + * + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void severe(String format, Object... data) { log(Level.ERROR, format, data); } - + + /** + * Logs a message at level WARNING. + * + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void warning(String format, Object... data) { log(Level.WARN, format, data); } - + + /** + * Logs a message at level INFO. + * + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void info(String format, Object... data) { log(Level.INFO, format, data); } - + + /** + * Logs a message at level FINE. + * + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void fine(String format, Object... data) { log(Level.DEBUG, format, data); } - + + /** + * Logs a message at level FINER. + * + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void finer(String format, Object... data) { log(Level.TRACE, format, data); } - + + /** + * Logs a message at level FINEST. + * + * @param format The text. + * @param data The data to put in the placeholders. + */ public static void finest(String format, Object... data) { log(Level.TRACE, format, data); } - + + /** + * Initializes a channel. + * + * @param logChannel The channel to initialize. + */ public static void makeLog(String logChannel) { LogManager.getLogger(logChannel); } diff --git a/src/main/java/net/minecraft/launchwrapper/VanillaTweaker.java b/src/main/java/net/minecraft/launchwrapper/VanillaTweaker.java index 70f2414..0ece038 100644 --- a/src/main/java/net/minecraft/launchwrapper/VanillaTweaker.java +++ b/src/main/java/net/minecraft/launchwrapper/VanillaTweaker.java @@ -3,6 +3,12 @@ import java.io.File; import java.util.List; +/** + * A tweaker for beta versions, and release versions 1.5 and below. This is the default tweaker. + * + * @author Erik Broes and Nathan Adams + * + */ public class VanillaTweaker implements ITweaker { private List args; diff --git a/src/main/java/net/minecraft/launchwrapper/injector/AlphaVanillaTweakInjector.java b/src/main/java/net/minecraft/launchwrapper/injector/AlphaVanillaTweakInjector.java index 33aead0..021c8a0 100644 --- a/src/main/java/net/minecraft/launchwrapper/injector/AlphaVanillaTweakInjector.java +++ b/src/main/java/net/minecraft/launchwrapper/injector/AlphaVanillaTweakInjector.java @@ -18,15 +18,31 @@ import java.util.HashMap; import java.util.Map; +/** + * A transformer for the alpha versions of Minecraft. Even though this implements {@link IClassTransformer}, it does not make any adjustments to the bytecode. Currently, the only thing this class does is it has a custom launch target for indev/alpha versions of Minecraft. + * + * @author Nathan Adams and cpw + * + */ public class AlphaVanillaTweakInjector implements IClassTransformer { public AlphaVanillaTweakInjector() { } - + @Override public byte[] transform(final String name, final String transformedName, final byte[] bytes) { return bytes; } - + + /** + * Launches indev/alpha versions of Minecraft. + * + * @param args The launch arguments. + * @throws ClassNotFoundException If the applet class cannot be found. + * @throws NoSuchMethodException If the applet's constructor is not found. + * @throws IllegalAccessException If the applet's constructor is not visible. + * @throws InvocationTargetException If an exception occurs while instantiating the applet. + * @throws InstantiationException If the applet class is abstract. + */ public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { Class clazz; diff --git a/src/main/java/net/minecraft/launchwrapper/injector/IndevVanillaTweakInjector.java b/src/main/java/net/minecraft/launchwrapper/injector/IndevVanillaTweakInjector.java index 1846d34..435bc3e 100644 --- a/src/main/java/net/minecraft/launchwrapper/injector/IndevVanillaTweakInjector.java +++ b/src/main/java/net/minecraft/launchwrapper/injector/IndevVanillaTweakInjector.java @@ -11,6 +11,12 @@ import static org.objectweb.asm.Opcodes.*; +/** + * A transformer for the indev versions of Minecraft. + * + * @author Nathan Adams, LexManos, and cpw + * + */ public class IndevVanillaTweakInjector implements IClassTransformer { public IndevVanillaTweakInjector() { } @@ -79,7 +85,12 @@ public byte[] transform(final String name, final String transformedName, final b classNode.accept(writer); return writer.toByteArray(); } - + + /** + * A call hook for the transformed bytecode of Minecraft. + * + * @return The gameDir that was passed to the launch wrapper. + */ public static File inject() { // Speed up imageloading System.out.println("Turning off ImageIO disk-caching"); diff --git a/src/main/java/net/minecraft/launchwrapper/injector/VanillaTweakInjector.java b/src/main/java/net/minecraft/launchwrapper/injector/VanillaTweakInjector.java index 70d8070..fbb718f 100644 --- a/src/main/java/net/minecraft/launchwrapper/injector/VanillaTweakInjector.java +++ b/src/main/java/net/minecraft/launchwrapper/injector/VanillaTweakInjector.java @@ -20,6 +20,12 @@ import static org.objectweb.asm.Opcodes.*; +/** + * A transformer for beta versions, and release versions 1.5 and below. + * + * @author Erik Broes, Nathan Adams, cpw, and LexManos + * + */ public class VanillaTweakInjector implements IClassTransformer { public VanillaTweakInjector() { } @@ -74,7 +80,12 @@ public byte[] transform(final String name, final String transformedName, final b classNode.accept(writer); return writer.toByteArray(); } - + + /** + * A call hook for the transformed bytecode of Minecraft. + * + * @return The gameDir that was passed to the launch wrapper. + */ public static File inject() { // Speed up imageloading System.out.println("Turning off ImageIO disk-caching"); @@ -86,7 +97,10 @@ public static File inject() { System.out.println("Setting gameDir to: " + Launch.minecraftHome); return Launch.minecraftHome; } - + + /** + * Loads the frame icons from the disk. + */ public static void loadIconsOnFrames() { try { // Load icon from disk