2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
|
|
|
* Copyright (c) 2016.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
package net.minecraftforge.fml.common.launcher;
|
2013-06-14 21:21:49 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
2013-06-15 00:45:52 +00:00
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
2013-06-14 21:21:49 +00:00
|
|
|
import java.util.List;
|
2013-09-27 14:01:39 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2013-06-15 00:45:52 +00:00
|
|
|
|
2013-11-10 16:49:06 +00:00
|
|
|
import net.minecraft.launchwrapper.ITweaker;
|
|
|
|
import net.minecraft.launchwrapper.Launch;
|
|
|
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
2014-09-23 05:01:24 +00:00
|
|
|
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
|
|
|
|
import net.minecraftforge.fml.relauncher.FMLSecurityManager;
|
2013-07-07 02:26:03 +00:00
|
|
|
|
2013-12-16 16:47:48 +00:00
|
|
|
import org.apache.logging.log4j.Level;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
|
2013-06-15 00:45:52 +00:00
|
|
|
import com.google.common.base.Throwables;
|
2013-07-07 02:26:03 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2013-09-27 14:01:39 +00:00
|
|
|
import com.google.common.collect.Maps;
|
2013-06-14 21:21:49 +00:00
|
|
|
|
|
|
|
public class FMLTweaker implements ITweaker {
|
2013-11-10 16:49:06 +00:00
|
|
|
private File gameDir;
|
2013-09-27 14:01:39 +00:00
|
|
|
private Map<String, String> launchArgs;
|
|
|
|
private List<String> standaloneArgs;
|
2013-06-15 00:45:52 +00:00
|
|
|
private static URI jarLocation;
|
2013-06-14 21:21:49 +00:00
|
|
|
|
2014-06-15 20:37:42 +00:00
|
|
|
public FMLTweaker()
|
|
|
|
{
|
2014-07-07 16:29:34 +00:00
|
|
|
System.setProperty("java.net.preferIPv4Stack", "true"); //Lets do this as early as possible. Vanilla does it in Main.main
|
2014-06-15 20:37:42 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
System.setSecurityManager(new FMLSecurityManager());
|
|
|
|
}
|
|
|
|
catch (SecurityException se)
|
|
|
|
{
|
|
|
|
throw new RuntimeException("FML was unable to install the security manager. The game will not start", se);
|
|
|
|
}
|
|
|
|
}
|
2013-11-10 16:49:06 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2013-06-14 21:21:49 +00:00
|
|
|
@Override
|
|
|
|
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile)
|
|
|
|
{
|
2013-06-29 17:33:14 +00:00
|
|
|
this.gameDir = (gameDir == null ? new File(".") : gameDir);
|
2013-09-27 14:01:39 +00:00
|
|
|
|
|
|
|
this.launchArgs = (Map<String, String>)Launch.blackboard.get("launchArgs");
|
|
|
|
|
|
|
|
this.standaloneArgs = Lists.newArrayList();
|
|
|
|
if (this.launchArgs == null)
|
|
|
|
{
|
|
|
|
this.launchArgs = Maps.newHashMap();
|
|
|
|
Launch.blackboard.put("launchArgs", this.launchArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
String classifier = null;
|
|
|
|
|
|
|
|
for (String arg : args)
|
|
|
|
{
|
|
|
|
if (arg.startsWith("-"))
|
|
|
|
{
|
|
|
|
if (classifier != null)
|
|
|
|
{
|
|
|
|
classifier = launchArgs.put(classifier, "");
|
|
|
|
}
|
|
|
|
else if (arg.contains("="))
|
|
|
|
{
|
|
|
|
classifier = launchArgs.put(arg.substring(0, arg.indexOf('=')), arg.substring(arg.indexOf('=') + 1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
classifier = arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (classifier != null)
|
|
|
|
{
|
|
|
|
classifier = launchArgs.put(classifier, arg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.standaloneArgs.add(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.launchArgs.containsKey("--version"))
|
|
|
|
{
|
2013-09-29 19:51:24 +00:00
|
|
|
launchArgs.put("--version", profile != null ? profile : "UnknownFMLProfile");
|
2013-09-27 14:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.launchArgs.containsKey("--gameDir") && gameDir != null)
|
|
|
|
{
|
|
|
|
launchArgs.put("--gameDir", gameDir.getAbsolutePath());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.launchArgs.containsKey("--assetsDir") && assetsDir != null)
|
|
|
|
{
|
|
|
|
launchArgs.put("--assetsDir", assetsDir.getAbsolutePath());
|
|
|
|
}
|
|
|
|
|
2014-01-15 00:49:03 +00:00
|
|
|
Yggdrasil.login(launchArgs);
|
|
|
|
|
2013-06-15 00:45:52 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
jarLocation = getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
|
|
|
|
}
|
|
|
|
catch (URISyntaxException e)
|
|
|
|
{
|
2013-12-16 16:47:48 +00:00
|
|
|
LogManager.getLogger("FMLTWEAK").log(Level.ERROR, "Missing URI information for FML tweak");
|
2013-06-15 00:45:52 +00:00
|
|
|
throw Throwables.propagate(e);
|
|
|
|
}
|
2013-06-14 21:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void injectIntoClassLoader(LaunchClassLoader classLoader)
|
|
|
|
{
|
|
|
|
FMLLaunchHandler.configureForClientLaunch(classLoader, this);
|
2013-07-11 19:12:23 +00:00
|
|
|
FMLLaunchHandler.appendCoreMods();
|
2013-07-07 02:26:03 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 21:21:49 +00:00
|
|
|
@Override
|
|
|
|
public String getLaunchTarget()
|
|
|
|
{
|
2014-08-31 17:35:38 +00:00
|
|
|
// Remove the extraneous mods and modListFile args
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
Map<String,String> args = (Map<String, String>) Launch.blackboard.get("launchArgs");
|
|
|
|
args.remove("--modListFile");
|
|
|
|
args.remove("--mods");
|
2013-06-29 17:33:14 +00:00
|
|
|
return "net.minecraft.client.main.Main";
|
2013-06-14 21:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getLaunchArguments()
|
|
|
|
{
|
2013-09-27 14:01:39 +00:00
|
|
|
List<String> args = Lists.newArrayList();
|
|
|
|
args.addAll(standaloneArgs);
|
2013-06-29 17:33:14 +00:00
|
|
|
|
2013-09-27 14:01:39 +00:00
|
|
|
for (Entry<String, String> arg : launchArgs.entrySet())
|
2013-08-16 20:28:55 +00:00
|
|
|
{
|
2013-09-27 14:01:39 +00:00
|
|
|
args.add(arg.getKey());
|
|
|
|
args.add(arg.getValue());
|
2013-08-16 20:28:55 +00:00
|
|
|
}
|
2013-09-27 14:01:39 +00:00
|
|
|
launchArgs.clear();
|
2013-08-16 20:28:55 +00:00
|
|
|
|
2013-09-27 14:01:39 +00:00
|
|
|
return args.toArray(new String[args.size()]);
|
2013-06-14 21:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public File getGameDir()
|
|
|
|
{
|
|
|
|
return gameDir;
|
|
|
|
}
|
|
|
|
|
2013-06-15 00:45:52 +00:00
|
|
|
public static URI getJarLocation()
|
|
|
|
{
|
|
|
|
return jarLocation;
|
|
|
|
}
|
|
|
|
|
2013-10-27 17:28:50 +00:00
|
|
|
public void injectCascadingTweak(String tweakClassName)
|
2013-07-11 19:12:23 +00:00
|
|
|
{
|
2013-11-10 16:49:06 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2013-08-23 14:42:26 +00:00
|
|
|
List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses");
|
2013-10-27 17:28:50 +00:00
|
|
|
tweakClasses.add(tweakClassName);
|
2013-07-11 19:12:23 +00:00
|
|
|
}
|
2013-06-14 21:21:49 +00:00
|
|
|
}
|