Access Transformer. Starting to try and launch things.
This commit is contained in:
parent
c38d2e48cd
commit
7e5bd4ecdb
8 changed files with 142 additions and 9 deletions
|
@ -19,16 +19,44 @@
|
|||
|
||||
package net.minecraftforge.fml;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import cpw.mods.modlauncher.Launcher;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class LaunchTesting
|
||||
{
|
||||
public static void main(String... args) throws InterruptedException
|
||||
{
|
||||
Configurator.setRootLevel(Level.DEBUG);
|
||||
Launcher.main("--launchTarget", "fml","--gameDir", "projects/run");
|
||||
hackNatives();
|
||||
Launcher.main("--launchTarget", "devfml","--gameDir", "projects/run", "--accessToken", "blah", "--version", "FMLDev");
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
|
||||
private static void hackNatives()
|
||||
{
|
||||
String paths = System.getProperty("java.library.path");
|
||||
String nativesDir = "/home/cpw/.gradle/caches/minecraft/net/minecraft/natives/1.12.2";
|
||||
|
||||
if (Strings.isNullOrEmpty(paths))
|
||||
paths = nativesDir;
|
||||
else
|
||||
paths += File.pathSeparator + nativesDir;
|
||||
|
||||
System.setProperty("java.library.path", paths);
|
||||
|
||||
// hack the classloader now.
|
||||
try
|
||||
{
|
||||
final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
|
||||
sysPathsField.setAccessible(true);
|
||||
sysPathsField.set(null, null);
|
||||
}
|
||||
catch(Throwable t) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.loading;
|
||||
|
||||
import cpw.mods.modlauncher.api.ILaunchHandlerService;
|
||||
import net.minecraft.client.main.Main;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class FMLDevLaunchProvider implements ILaunchHandlerService
|
||||
{
|
||||
@Override
|
||||
public String name()
|
||||
{
|
||||
return "devfml";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path[] identifyTransformationTargets()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Path[] {
|
||||
Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().toURI())
|
||||
};
|
||||
}
|
||||
catch (URISyntaxException e)
|
||||
{
|
||||
throw new RuntimeException("I can't find myself!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Callable<Void> launchService(String[] arguments, ClassLoader launchClassLoader)
|
||||
{
|
||||
return () -> {
|
||||
Main.main(arguments);
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
package net.minecraftforge.fml.loading;
|
||||
|
||||
import cpw.mods.modlauncher.api.ILaunchHandlerService;
|
||||
import net.minecraft.client.main.Main;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -41,6 +42,8 @@ public class FMLLaunchProvider implements ILaunchHandlerService
|
|||
@Override
|
||||
public Callable<Void> launchService(String[] arguments, ClassLoader launchClassLoader)
|
||||
{
|
||||
return () -> { return null; };
|
||||
return () -> {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,18 @@ import cpw.mods.modlauncher.api.ITransformationService;
|
|||
import cpw.mods.modlauncher.api.IncompatibleEnvironmentException;
|
||||
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.fml.common.FMLPaths;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
import net.minecraftforge.forgespi.ICoreModProvider;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -81,7 +89,7 @@ public class FMLLoader
|
|||
languageLoadingProvider = new LanguageLoadingProvider();
|
||||
}
|
||||
|
||||
public static void load()
|
||||
public static void beginModScan()
|
||||
{
|
||||
fmlLog.debug(SCAN,"Scanning for Mod Locators");
|
||||
modDiscoverer = new ModDiscoverer();
|
||||
|
@ -96,4 +104,28 @@ public class FMLLoader
|
|||
{
|
||||
return languageLoadingProvider;
|
||||
}
|
||||
|
||||
public static void loadAccessTransformer()
|
||||
{
|
||||
final URL resource = FMLLoader.class.getClassLoader().getResource("forge_at.cfg");
|
||||
if (resource == null) {
|
||||
throw new RuntimeException("Missing forge_at.cfg file");
|
||||
}
|
||||
try
|
||||
{
|
||||
fmlLog.debug(CORE, "Loading forge_at.cfg into access transformer");
|
||||
accessTransformer.addResource(Paths.get(resource.toURI()), "forge_at.cfg");
|
||||
}
|
||||
catch (URISyntaxException e)
|
||||
{
|
||||
fmlLog.error("Error loading forge_at.cfg file", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addAccessTransformer(Path atPath, ModFile modName)
|
||||
{
|
||||
fmlLog.debug(SCAN, "Adding Access Transformer in {}", modName.getFilePath());
|
||||
accessTransformer.addResource(atPath, modName.getFileName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,17 +25,14 @@ import cpw.mods.modlauncher.api.ITransformer;
|
|||
import cpw.mods.modlauncher.api.IncompatibleEnvironmentException;
|
||||
import joptsimple.ArgumentAcceptingOptionSpec;
|
||||
import joptsimple.OptionSpecBuilder;
|
||||
import net.minecraftforge.coremod.CoreModEngine;
|
||||
import net.minecraftforge.fml.FMLConfig;
|
||||
import net.minecraftforge.fml.common.FMLPaths;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
@ -62,7 +59,9 @@ public class FMLServiceProvider implements ITransformationService
|
|||
fmlLog.debug(CORE,"Loading configuration");
|
||||
FMLConfig.load();
|
||||
fmlLog.debug(CORE,"Initiating mod scan");
|
||||
FMLLoader.load();
|
||||
FMLLoader.beginModScan();
|
||||
fmlLog.debug(CORE, "Loading access transformers");
|
||||
FMLLoader.loadAccessTransformer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,9 +23,11 @@ import cpw.mods.modlauncher.ServiceLoaderStreamUtils;
|
|||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.LanguageLoadingProvider;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -62,6 +64,7 @@ public class ModDiscoverer {
|
|||
mods.forEach(ModFile::identifyMods);
|
||||
fmlLog.debug(SCAN,"Found {} mod files with {} mods", mods::size, ()->mods.stream().mapToInt(mf -> mf.getModInfos().size()).sum());
|
||||
mods.stream().map(ModFile::getCoreMods).flatMap(List::stream).forEach(FMLLoader.getCoreModProvider()::addCoreMod);
|
||||
mods.forEach(mod -> mod.getAccessTransformer().ifPresent(path -> FMLLoader.addAccessTransformer(path, mod)));
|
||||
mods.forEach(backgroundScanHandler::submitForScanning);
|
||||
return backgroundScanHandler;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package net.minecraftforge.fml.loading.moddiscovery;
|
|||
import net.minecraftforge.fml.loading.IModLanguageProvider;
|
||||
|
||||
import javax.swing.text.html.Option;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -47,6 +48,7 @@ public class ModFile
|
|||
DEFAULTMANIFEST.getMainAttributes().putValue("FMLModType", "MOD");
|
||||
}
|
||||
|
||||
|
||||
public void claimLanguage(String modId, IModLanguageProvider.IModLanguageLoader loader)
|
||||
{
|
||||
this.modInfoMap.get(modId).setLoader(loader);
|
||||
|
@ -64,6 +66,7 @@ public class ModFile
|
|||
private ScanResult fileScanResult;
|
||||
private CompletableFuture<ScanResult> futureScanResult;
|
||||
private List<CoreModFile> coreMods;
|
||||
private Path accessTransformer;
|
||||
|
||||
private static final Attributes.Name TYPE = new Attributes.Name("FMLModType");
|
||||
|
||||
|
@ -89,12 +92,16 @@ public class ModFile
|
|||
return modInfos;
|
||||
}
|
||||
|
||||
public Optional<Path> getAccessTransformer() {
|
||||
return Optional.ofNullable(Files.exists(accessTransformer) ? accessTransformer : null);
|
||||
}
|
||||
public void identifyMods() {
|
||||
this.modInfos = ModFileParser.readModList(this);
|
||||
this.modInfos.forEach(mi-> fmlLog.debug(LOADING,"Found mod {} for language {}", mi.getModId(), mi.getModLoader()));
|
||||
this.modInfoMap = this.modInfos.stream().collect(Collectors.toMap(ModInfo::getModId, Function.identity()));
|
||||
this.coreMods = ModFileParser.getCoreMods(this);
|
||||
this.coreMods.forEach(mi-> fmlLog.debug(LOADING,"Found coremod {}", mi.getPath()));
|
||||
this.accessTransformer = locator.findPath(this, "META-INF", "accesstransformer.cfg");
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,7 +119,6 @@ public class ModFile
|
|||
public void scanFile(Consumer<Path> pathConsumer) {
|
||||
locator.scanFile(this, pathConsumer);
|
||||
}
|
||||
|
||||
public void setFutureScanResult(CompletableFuture<ScanResult> future)
|
||||
{
|
||||
this.futureScanResult = future;
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
net.minecraftforge.fml.loading.FMLLaunchProvider
|
||||
net.minecraftforge.fml.loading.FMLDevLaunchProvider
|
Loading…
Reference in a new issue