Commit b36a1152480f6cbb7ec354f8810015cb28e837ff

Authored by Mumfrey
1 parent 6bcb9901

LiteLoader 1.6.4 - modified tweaker to support new argument list contract

java/com/mumfrey/liteloader/launch/LiteLoaderTweaker.java
@@ -29,15 +29,16 @@ public class LiteLoaderTweaker implements ITweaker @@ -29,15 +29,16 @@ public class LiteLoaderTweaker implements ITweaker
29 29
30 private String profile; 30 private String profile;
31 31
32 - private List<String> unClassifiedArgs = new ArrayList<String>(); 32 + private List<String> singularLaunchArgs = new ArrayList<String>();
33 33
34 - private Map<String, String> classifiedArgs = new HashMap<String, String>(); 34 + private Map<String, String> launchArgs;
35 35
36 private ArgumentAcceptingOptionSpec<String> modsOption; 36 private ArgumentAcceptingOptionSpec<String> modsOption;
37 private OptionSet parsedOptions; 37 private OptionSet parsedOptions;
38 38
39 private List<String> passThroughArgs; 39 private List<String> passThroughArgs;
40 40
  41 + @SuppressWarnings("unchecked")
41 @Override 42 @Override
42 public void acceptOptions(List<String> args, File gameDirectory, File assetsDirectory, String profile) 43 public void acceptOptions(List<String> args, File gameDirectory, File assetsDirectory, String profile)
43 { 44 {
@@ -57,6 +58,13 @@ public class LiteLoaderTweaker implements ITweaker @@ -57,6 +58,13 @@ public class LiteLoaderTweaker implements ITweaker
57 this.parsedOptions = optionParser.parse(args.toArray(new String[args.size()])); 58 this.parsedOptions = optionParser.parse(args.toArray(new String[args.size()]));
58 this.passThroughArgs = this.parsedOptions.valuesOf(nonOptions); 59 this.passThroughArgs = this.parsedOptions.valuesOf(nonOptions);
59 60
  61 + this.launchArgs = (Map<String, String>)Launch.blackboard.get("launchArgs");
  62 + if (this.launchArgs == null)
  63 + {
  64 + this.launchArgs = new HashMap<String, String>();
  65 + Launch.blackboard.put("launchArgs", this.launchArgs);
  66 + }
  67 +
60 // Parse out the arguments ourself because joptsimple doesn't really provide a good way to 68 // Parse out the arguments ourself because joptsimple doesn't really provide a good way to
61 // add arguments to the unparsed argument list after parsing 69 // add arguments to the unparsed argument list after parsing
62 this.parseArgs(this.passThroughArgs); 70 this.parseArgs(this.passThroughArgs);
@@ -76,29 +84,14 @@ public class LiteLoaderTweaker implements ITweaker @@ -76,29 +84,14 @@ public class LiteLoaderTweaker implements ITweaker
76 */ 84 */
77 public void provideRequiredArgs(File gameDirectory, File assetsDirectory) 85 public void provideRequiredArgs(File gameDirectory, File assetsDirectory)
78 { 86 {
79 - @SuppressWarnings("unchecked")  
80 - final List<String> argumentList = (List<String>)Launch.blackboard.get("ArgumentList"); 87 + if (!this.launchArgs.containsKey("--version"))
  88 + this.addClassifiedArg("--version", this.VERSION);
81 89
82 - if (argumentList != null)  
83 - {  
84 - if (!argumentList.contains("--version"))  
85 - {  
86 - argumentList.add("--version");  
87 - argumentList.add(this.VERSION);  
88 - }  
89 -  
90 - if (!argumentList.contains("--gameDir") && gameDirectory != null)  
91 - {  
92 - argumentList.add("--gameDir");  
93 - argumentList.add(gameDirectory.getAbsolutePath());  
94 - }  
95 -  
96 - if (!argumentList.contains("--assetsDir") && assetsDirectory != null)  
97 - {  
98 - argumentList.add("--assetsDir");  
99 - argumentList.add(assetsDirectory.getAbsolutePath());  
100 - }  
101 - } 90 + if (!this.launchArgs.containsKey("--gameDir") && gameDirectory != null)
  91 + this.addClassifiedArg("--gameDir", gameDirectory.getAbsolutePath());
  92 +
  93 + if (!this.launchArgs.containsKey("--assetsDir") && assetsDirectory != null)
  94 + this.addClassifiedArg("--assetsDir", assetsDirectory.getAbsolutePath());
102 } 95 }
103 96
104 private void parseArgs(List<String> args) 97 private void parseArgs(List<String> args)
@@ -121,14 +114,14 @@ public class LiteLoaderTweaker implements ITweaker @@ -121,14 +114,14 @@ public class LiteLoaderTweaker implements ITweaker
121 if (classifier != null) 114 if (classifier != null)
122 classifier = this.addClassifiedArg(classifier, arg); 115 classifier = this.addClassifiedArg(classifier, arg);
123 else 116 else
124 - this.unClassifiedArgs.add(arg); 117 + this.singularLaunchArgs.add(arg);
125 } 118 }
126 } 119 }
127 } 120 }
128 121
129 private String addClassifiedArg(String classifiedArg, String arg) 122 private String addClassifiedArg(String classifiedArg, String arg)
130 { 123 {
131 - this.classifiedArgs.put(classifiedArg, arg); 124 + this.launchArgs.put(classifiedArg, arg);
132 return null; 125 return null;
133 } 126 }
134 127
@@ -136,7 +129,7 @@ public class LiteLoaderTweaker implements ITweaker @@ -136,7 +129,7 @@ public class LiteLoaderTweaker implements ITweaker
136 public void injectIntoClassLoader(LaunchClassLoader classLoader) 129 public void injectIntoClassLoader(LaunchClassLoader classLoader)
137 { 130 {
138 LiteLoaderTransformer.launchClassLoader = classLoader; 131 LiteLoaderTransformer.launchClassLoader = classLoader;
139 - classLoader.registerTransformer("com.mumfrey.liteloader.launch.LiteLoaderTransformer"); 132 + classLoader.registerTransformer(LiteLoaderTransformer.class.getName());
140 } 133 }
141 134
142 @Override 135 @Override
@@ -150,15 +143,18 @@ public class LiteLoaderTweaker implements ITweaker @@ -150,15 +143,18 @@ public class LiteLoaderTweaker implements ITweaker
150 { 143 {
151 List<String> args = new ArrayList<String>(); 144 List<String> args = new ArrayList<String>();
152 145
153 - for (String unClassifiedArg : this.unClassifiedArgs) 146 + for (String unClassifiedArg : this.singularLaunchArgs)
154 args.add(unClassifiedArg); 147 args.add(unClassifiedArg);
155 148
156 - for (Entry<String, String> classifiedArg : this.classifiedArgs.entrySet()) 149 + for (Entry<String, String> launchArg : this.launchArgs.entrySet())
157 { 150 {
158 - args.add(classifiedArg.getKey().trim());  
159 - args.add(classifiedArg.getValue().trim()); 151 + args.add(launchArg.getKey().trim());
  152 + args.add(launchArg.getValue().trim());
160 } 153 }
161 154
  155 + this.singularLaunchArgs.clear();
  156 + this.launchArgs.clear();
  157 +
162 return args.toArray(new String[args.size()]); 158 return args.toArray(new String[args.size()]);
163 } 159 }
164 160