net.minecraft.launchwrapper.LaunchClassLoader Java Examples

The following examples show how to use net.minecraft.launchwrapper.LaunchClassLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Meddle.java    From Meddle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Meddle()
{
	// Prevent classloader collisions, mostly due to keeping
	// the deprecated DynamicMappings class.
	Launch.classLoader.addClassLoaderExclusion("org.objectweb.asm.");

	blacklistedTweaks.add(Meddle.class.getName());

	// Launchwrapper adds the package without a period on the end, which
	// covers any similarly-named packages.  We could solve by putting
	// Meddle's tweak class in a deeper package, but this works too
	// while maintaining backwards compatibility.

	try {
		Field exceptionsField = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions");
		exceptionsField.setAccessible(true);
		classloaderExceptions = (Set<String>) exceptionsField.get(Launch.classLoader);
	} catch (Exception e) { e.printStackTrace(); }

	classloaderExceptions.remove("net.fybertech.meddle");
	classloaderExceptions.add("net.fybertech.meddle.");
}
 
Example #2
Source File: ObfHelper.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @return Whether or not the current environment contains obfuscated Minecraft code
 */
public static boolean isObfuscated()
{
	if (obfuscated == null)
	{
		try
		{
			byte[] bytes = ((LaunchClassLoader) ObfHelper.class.getClassLoader()).getClassBytes("net.minecraft.world.World");
			ObfHelper.setObfuscated(bytes == null);
		}
		catch (IOException e)
		{
			obfuscated = true;
		}
	}
	return obfuscated;
}
 
Example #3
Source File: ObfHelper.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @return Whether or not the current environment has been deobfuscated by FML
 */
public static boolean runsAfterDeobfRemapper()
{
	if (runsAfterDeobfRemapper == null)
	{
		try
		{
			byte[] bytes = ((LaunchClassLoader) ObfHelper.class.getClassLoader()).getClassBytes("net.minecraft.world.World");
			ObfHelper.setRunsAfterDeobfRemapper(bytes != null);
		}
		catch (IOException e)
		{
			runsAfterDeobfRemapper = false;
		}
	}
	return runsAfterDeobfRemapper;
}
 
Example #4
Source File: LegacyJavaFixer.java    From LegacyJavaFixer with MIT License 6 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader)
{
    if (!hasRun)
    {
        FMLRelaunchLog.log.info("[LegacyJavaFixer] Replacing sort");
        sort();
        URL is = FMLInjectionAndSortingTweaker.class.getResource("/cpw/mods/fml/common/launcher/TerminalTweaker.class");
        if (is != null)
        {
            FMLRelaunchLog.log.info("[LegacyJavaFixer] Detected TerminalTweaker");
            @SuppressWarnings("unchecked")
            List<String> newTweaks = (List<String>) Launch.blackboard.get("TweakClasses");
            newTweaks.add("cpw.mods.fml.common.launcher.TerminalTweaker");
        }
    }
    hasRun = true;
}
 
Example #5
Source File: MemoryHelper.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
@InvokeEvent
public void tickEvent(TickEvent event) {
    if (tickCounter % 20 * 60 == 0) {
        Minecraft.memoryReserve = new byte[0];
        try {
            Field resourceCache = LaunchClassLoader.class.getDeclaredField("resourceCache");
            resourceCache.setAccessible(true);
            ((Map) resourceCache.get(Launch.classLoader)).clear();

            Field packageManifests = LaunchClassLoader.class.getDeclaredField("packageManifests");
            packageManifests.setAccessible(true);
            ((Map) packageManifests.get(Launch.classLoader)).clear();
        } catch (IllegalAccessException | NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

    tickCounter++;
}
 
Example #6
Source File: LaunchClassLoaderUtil.java    From Mixin with MIT License 5 votes vote down vote up
/**
 * Singleton, use factory to get an instance
 * 
 * @param classLoader class loader
 */
LaunchClassLoaderUtil(LaunchClassLoader classLoader) {
    this.classLoader = classLoader;
    this.cachedClasses = LaunchClassLoaderUtil.<Map<String, Class<?>>>getField(classLoader, LaunchClassLoaderUtil.CACHED_CLASSES_FIELD);
    this.invalidClasses = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.INVALID_CLASSES_FIELD);
    this.classLoaderExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.CLASS_LOADER_EXCEPTIONS_FIELD);
    this.transformerExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.TRANSFORMER_EXCEPTIONS_FIELD);
}
 
Example #7
Source File: Meddle.java    From Meddle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader)
{
	// Register any transformer classes specified in mod manifests
	for (ModContainer mod : discoveredModsList)
	{
		if (mod.transformerClass != null) {
			try {
				Class.forName(mod.transformerClass, true, classLoader);
			} catch (ClassNotFoundException e) {}
			classLoader.registerTransformer(mod.transformerClass);
		}
	}
}
 
Example #8
Source File: ModIdentifier.java    From VanillaFix with MIT License 5 votes vote down vote up
private static String untransformName(LaunchClassLoader launchClassLoader, String className) {
    try {
        Method untransformNameMethod = LaunchClassLoader.class.getDeclaredMethod("untransformName", String.class);
        untransformNameMethod.setAccessible(true);
        return (String) untransformNameMethod.invoke(launchClassLoader, className);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
Example #9
Source File: PluginClassLoader.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
Class<?> findClass(String name, boolean checkGlobal) throws ClassNotFoundException {
    if (name.startsWith("net.minecraft.server.v1_12_R1")) {
        String remappedClass = jarMapping.classes.get(name.replaceAll("\\.", "\\/"));
        return ((LaunchClassLoader) MinecraftServer.getServerInstance().getClass().getClassLoader()).findClass(remappedClass);
    }

    if (name.startsWith("org.bukkit.")) {
        throw new ClassNotFoundException(name);
    }

    Class<?> result = classes.get(name);

    synchronized (name.intern()) {
        if (result == null) {
            if (checkGlobal) {
                result = loader.getClassByName(name);
            }

            if (result == null) {
                result = remappedFindClass(name);

                if (result != null) {
                    loader.setClass(name, result);
                }
            }

            if (result == null) {
                throw new ClassNotFoundException(name);
            }

            classes.put(name, result);
        }
    }
    return result;
}
 
Example #10
Source File: HyperiumTweaker.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
    Hyperium.LOGGER.info("[Addons] Loading Addons...");

    Hyperium.LOGGER.info("Initialising Bootstraps...");
    MixinBootstrap.init();
    AddonBootstrap.INSTANCE.init();

    Hyperium.LOGGER.info("Applying transformers...");

    MixinEnvironment environment = MixinEnvironment.getDefaultEnvironment();
    Mixins.addConfiguration("mixins.hyperium.json");

    if (isRunningOptifine) {
        environment.setObfuscationContext("notch"); // Switch's to notch mappings
    }

    if (environment.getObfuscationContext() == null) {
        environment.setObfuscationContext("notch"); // Switch's to notch mappings
    }

    try {
        classLoader.addURL(new File(System.getProperty("java.home"), "lib/ext/nashorn.jar").toURI().toURL());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    environment.setSide(MixinEnvironment.Side.CLIENT);
}
 
Example #11
Source File: TweakerMixinLoader.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
    System.out.println("[LiquidBounce] Injecting with TweakerMixinLoader.");

    MixinBootstrap.init();
    Mixins.addConfiguration("liquidbounce.vanilla.mixins.json");
    MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.CLIENT);

    classLoader.registerTransformer(AbstractJavaLinkerTransformer.class.getName());
}
 
Example #12
Source File: MixinPlatformAgentFMLLegacy.java    From Mixin with MIT License 5 votes vote down vote up
private ITweaker injectCorePlugin() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    String coreModName = this.handle.getAttribute(MixinPlatformAgentFMLLegacy.MFATT_FMLCOREPLUGIN);
    if (coreModName == null) {
        return null;
    }
    
    if (this.isAlreadyInjected(coreModName)) {
        MixinPlatformAgentAbstract.logger.debug("{} has core plugin {}. Skipping because it was already injected.", this.fileName, coreModName);
        return null;
    }
    
    MixinPlatformAgentAbstract.logger.debug("{} has core plugin {}. Injecting it into FML for co-initialisation:", this.fileName, coreModName);
    Method mdLoadCoreMod = this.clCoreModManager.getDeclaredMethod(GlobalProperties.getString(GlobalProperties.Keys.FML_LOAD_CORE_MOD,
            MixinPlatformAgentFMLLegacy.LOAD_CORE_MOD_METHOD), LaunchClassLoader.class, String.class, File.class);
    mdLoadCoreMod.setAccessible(true);
    ITweaker wrapper = (ITweaker)mdLoadCoreMod.invoke(null, Launch.classLoader, coreModName, this.file);
    if (wrapper == null) {
        MixinPlatformAgentAbstract.logger.debug("Core plugin {} could not be loaded.", coreModName);
        return null;
    }
    
    // If the injection tweaker is queued, we are most likely in development
    // and will NOT need to co-init the coremod
    this.initInjectionState = MixinPlatformAgentFMLLegacy.isTweakerQueued(MixinPlatformAgentFMLLegacy.FML_TWEAKER_INJECTION);

    MixinPlatformAgentFMLLegacy.loadedCoreMods.add(coreModName);
    return wrapper;
}
 
Example #13
Source File: LaunchClassLoaderUtil.java    From Mixin with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
    private static <T> T getField(LaunchClassLoader classLoader, String fieldName) {
        try {
            Field field = LaunchClassLoader.class.getDeclaredField(fieldName);
            field.setAccessible(true);
            return (T)field.get(classLoader);
        } catch (Exception ex) {
//            ex.printStackTrace();
        }
        return null;
    }
 
Example #14
Source File: DepLoader.java    From CodeChickenCore with MIT License 5 votes vote down vote up
private void loadJson(JsonObject node) throws IOException {
    boolean obfuscated = ((LaunchClassLoader) DepLoader.class.getClassLoader())
            .getClassBytes("net.minecraft.world.World") == null;

    String repo = node.has("repo") ? node.get("repo").getAsString() : null;
    String packed = node.has("packed") ? node.get("packed").getAsString() : null;
    String testClass = node.get("class").getAsString();

    String filename = node.get("file").getAsString();
    if (!obfuscated && node.has("dev"))
        filename = node.get("dev").getAsString();

    boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();

    Pattern pattern = null;
    try {
        if(node.has("pattern"))
            pattern = Pattern.compile(node.get("pattern").getAsString());
    } catch (PatternSyntaxException e) {
        logger.error("Invalid filename pattern: "+node.get("pattern"), e);
    }
    if(pattern == null)
        pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");

    VersionedFile file = new VersionedFile(filename, pattern);
    if (!file.matches())
        throw new RuntimeException("Invalid filename format for dependency: " + filename);

    addDep(new Dependency(scanning, repo, packed, file, testClass, coreLib));
}
 
Example #15
Source File: DelegatedTransformer.java    From CodeChickenCore with MIT License 5 votes vote down vote up
public DelegatedTransformer()
{
    delegatedTransformers = new ArrayList<IClassTransformer>();
    try
    {
        m_defineClass = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE);
        m_defineClass.setAccessible(true);
        f_cachedClasses = LaunchClassLoader.class.getDeclaredField("cachedClasses");
        f_cachedClasses.setAccessible(true);
    }
    catch(Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #16
Source File: DepLoader.java    From WirelessRedstone with MIT License 5 votes vote down vote up
private void addClasspath(String name) {
    try {
        ((LaunchClassLoader) DepLoader.class.getClassLoader()).addURL(new File(v_modsDir, name).toURI().toURL());
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
 
Example #17
Source File: DepLoader.java    From WirelessRedstone with MIT License 5 votes vote down vote up
private void loadJson(JsonObject node) throws IOException {
    boolean obfuscated = ((LaunchClassLoader) DepLoader.class.getClassLoader())
            .getClassBytes("net.minecraft.world.World") == null;

    String testClass = node.get("class").getAsString();
    if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null)
        return;

    String repo = node.get("repo").getAsString();
    String filename = node.get("file").getAsString();
    if (!obfuscated && node.has("dev"))
        filename = node.get("dev").getAsString();

    boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();

    Pattern pattern = null;
    try {
        if(node.has("pattern"))
            pattern = Pattern.compile(node.get("pattern").getAsString());
    } catch (PatternSyntaxException e) {
        System.err.println("Invalid filename pattern: "+node.get("pattern"));
        e.printStackTrace();
    }
    if(pattern == null)
        pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");

    VersionedFile file = new VersionedFile(filename, pattern);
    if (!file.matches())
        throw new RuntimeException("Invalid filename format for dependency: " + filename);

    addDep(new Dependency(repo, file, coreLib));
}
 
Example #18
Source File: FabricTweaker.java    From fabric-loader with Apache License 2.0 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) {
	isDevelopment = Boolean.parseBoolean(System.getProperty("fabric.development", "false"));
	Launch.blackboard.put("fabric.development", isDevelopment);
	setProperties(Launch.blackboard);

	this.launchClassLoader = launchClassLoader;
	launchClassLoader.addClassLoaderExclusion("org.objectweb.asm.");
	launchClassLoader.addClassLoaderExclusion("org.spongepowered.asm.");
	launchClassLoader.addClassLoaderExclusion("net.fabricmc.loader.");

	launchClassLoader.addClassLoaderExclusion("net.fabricmc.api.Environment");
	launchClassLoader.addClassLoaderExclusion("net.fabricmc.api.EnvType");

	GameProvider provider = new MinecraftGameProvider();
	provider.acceptArguments(arguments);

	if (!provider.locateGame(getEnvironmentType(), launchClassLoader)) {
		throw new RuntimeException("Could not locate Minecraft: provider locate failed");
	}

	@SuppressWarnings("deprecation")
	FabricLoader loader = FabricLoader.INSTANCE;
	loader.setGameProvider(provider);
	loader.load();
	loader.freeze();

	launchClassLoader.registerTransformer("net.fabricmc.loader.launch.FabricClassTransformer");

	if (!isDevelopment) {
		// Obfuscated environment
		Launch.blackboard.put("fabric.development", false);
		try {
			String target = getLaunchTarget();
			URL loc = launchClassLoader.findResource(target.replace('.', '/') + ".class");
			JarURLConnection locConn = (JarURLConnection) loc.openConnection();
			File jarFile = UrlUtil.asFile(locConn.getJarFileURL());
			if (!jarFile.exists()) {
				throw new RuntimeException("Could not locate Minecraft: " + jarFile.getAbsolutePath() + " not found");
			}

			FabricLauncherBase.deobfuscate(provider.getGameId(), provider.getNormalizedGameVersion(), provider.getLaunchDirectory(), jarFile.toPath(), this);
		} catch (IOException | UrlConversionException e) {
			throw new RuntimeException("Failed to deobfuscate Minecraft!", e);
		}
	}

	FabricLoader.INSTANCE.getAccessWidener().loadFromMods();

	MinecraftGameProvider.TRANSFORMER.locateEntrypoints(this);

	// Setup Mixin environment
	MixinBootstrap.init();
	FabricMixinBootstrap.init(getEnvironmentType(), FabricLoader.INSTANCE);
	MixinEnvironment.getDefaultEnvironment().setSide(getEnvironmentType() == EnvType.CLIENT ? MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER);

	EntrypointUtils.invoke("preLaunch", PreLaunchEntrypoint.class, PreLaunchEntrypoint::onPreLaunch);
}
 
Example #19
Source File: LaunchClassLoaderUtil.java    From Mixin with MIT License 4 votes vote down vote up
/**
 * Get the classloader
 */
LaunchClassLoader getClassLoader() {
    return this.classLoader;
}
 
Example #20
Source File: EnvironmentStateTweaker.java    From Mixin with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
    MixinBootstrap.getPlatform().inject();
}
 
Example #21
Source File: MixinTweaker.java    From Mixin with MIT License 4 votes vote down vote up
@Override
public final void injectIntoClassLoader(LaunchClassLoader classLoader) {
    MixinBootstrap.inject();
}
 
Example #22
Source File: Tweaker.java    From BoundingBoxOutlineReloaded with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
    MixinBootstrap.init();
    MixinEnvironment.getDefaultEnvironment().setSide(isClient() ? MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER);
    Mixins.addConfiguration("mixins.bbor.json");
}
 
Example #23
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}
 
Example #24
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}
 
Example #25
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}
 
Example #26
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}
 
Example #27
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}
 
Example #28
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}
 
Example #29
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}
 
Example #30
Source File: ClassTweaker.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
	classLoader.registerTransformer(Transformer.class.getName());
}