Commit cffaacc682924d96028c90e0adf73b336973b9c5

Authored by Mumfrey
1 parent 97de196e

clean up LiteLoaderTweaker a bit and don't rely on singleton for some public contracts

java/common/com/mumfrey/liteloader/core/LiteLoaderBootstrap.java
... ... @@ -17,6 +17,7 @@ import org.apache.logging.log4j.core.Logger;
17 17 import org.apache.logging.log4j.core.appender.FileAppender;
18 18 import org.apache.logging.log4j.core.layout.PatternLayout;
19 19  
  20 +import net.minecraft.launchwrapper.ITweaker;
20 21 import net.minecraft.launchwrapper.Launch;
21 22 import net.minecraft.launchwrapper.LaunchClassLoader;
22 23  
... ... @@ -120,6 +121,10 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP
120 121 private String branding = null;
121 122  
122 123 private boolean loadTweaks = true;
  124 +
  125 + private LaunchClassLoader classLoader;
  126 +
  127 + private final ITweaker tweaker;
123 128  
124 129 private final APIRegistry apiRegistry;
125 130  
... ... @@ -140,13 +145,13 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP
140 145 private EnabledModsList enabledModsList;
141 146  
142 147 /**
143   - * @param gameDirectory
144   - * @param assetsDirectory
145   - * @param profile
  148 + * @param env
  149 + * @param tweaker
146 150 */
147   - public LiteLoaderBootstrap(StartupEnvironment env)
  151 + public LiteLoaderBootstrap(StartupEnvironment env, ITweaker tweaker)
148 152 {
149 153 this.environmentType = EnvironmentType.values()[env.getEnvironmentTypeId()];
  154 + this.tweaker = tweaker;
150 155  
151 156 this.apiRegistry = new APIRegistry(this.getEnvironment(), this.getProperties());
152 157  
... ... @@ -255,12 +260,19 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP
255 260 return this;
256 261 }
257 262  
  263 + @Override
  264 + public ITweaker getTweaker()
  265 + {
  266 + return this.tweaker;
  267 + }
  268 +
258 269 /* (non-Javadoc)
259 270 * @see com.mumfrey.liteloader.launch.ILoaderBootstrap#preInit(net.minecraft.launchwrapper.LaunchClassLoader, boolean)
260 271 */
261 272 @Override
262 273 public void preInit(LaunchClassLoader classLoader, boolean loadTweaks, List<String> modsToLoad)
263 274 {
  275 + this.classLoader = classLoader;
264 276 this.loadTweaks = loadTweaks;
265 277  
266 278 LiteLoaderLogger.info("LiteLoader begin PREINIT...");
... ... @@ -315,12 +327,12 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP
315 327 * @see com.mumfrey.liteloader.launch.ILoaderBootstrap#init(java.util.List, net.minecraft.launchwrapper.LaunchClassLoader)
316 328 */
317 329 @Override
318   - public void init(LaunchClassLoader classLoader)
  330 + public void init()
319 331 {
320 332 // PreInit failed
321 333 if (this.enumerator == null) return;
322 334  
323   - LiteLoader.createInstance(this.getEnvironment(), this.getProperties(), classLoader);
  335 + LiteLoader.createInstance(this.getEnvironment(), this.getProperties(), this.classLoader);
324 336 LiteLoader.invokeInit();
325 337 }
326 338  
... ...
java/common/com/mumfrey/liteloader/core/LiteLoaderEnumerator.java
... ... @@ -69,6 +69,8 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
69 69 private final LoaderEnvironment environment;
70 70  
71 71 private final LoaderProperties properties;
  72 +
  73 + private final LiteLoaderTweaker tweaker;
72 74  
73 75 /**
74 76 * Reference to the launch classloader
... ... @@ -124,6 +126,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
124 126 {
125 127 this.environment = environment;
126 128 this.properties = properties;
  129 + this.tweaker = (LiteLoaderTweaker)environment.getTweaker();
127 130 this.classLoader = classLoader;
128 131 this.supportedPrefixes = this.getSupportedPrefixes(environment);
129 132  
... ... @@ -548,7 +551,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
548 551 String tweakClass = container.getTweakClassName();
549 552 int tweakPriority = container.getTweakPriority();
550 553 LiteLoaderLogger.info("Mod file '%s' provides tweakClass '%s', adding to Launch queue with priority %d", container.getName(), tweakClass, tweakPriority);
551   - if (LiteLoaderTweaker.addCascadedTweaker(tweakClass, tweakPriority))
  554 + if (this.tweaker.addCascadedTweaker(tweakClass, tweakPriority))
552 555 {
553 556 LiteLoaderLogger.info("tweakClass '%s' was successfully added", tweakClass);
554 557 container.injectIntoClassPath(this.classLoader, true);
... ... @@ -589,7 +592,7 @@ public class LiteLoaderEnumerator implements LoaderEnumerator
589 592 for (String classTransformerClass : classTransformerClasses)
590 593 {
591 594 LiteLoaderLogger.info("Mod file '%s' provides classTransformer '%s', adding to class loader", container.getName(), classTransformerClass);
592   - if (LiteLoaderTweaker.getTransformerManager().injectTransformer(classTransformerClass))
  595 + if (this.tweaker.getTransformerManager().injectTransformer(classTransformerClass))
593 596 {
594 597 LiteLoaderLogger.info("classTransformer '%s' was successfully added", classTransformerClass);
595 598 container.injectIntoClassPath(this.classLoader, true);
... ...
java/common/com/mumfrey/liteloader/core/LiteLoaderMods.java
... ... @@ -59,6 +59,11 @@ public class LiteLoaderMods
59 59 protected final LoaderEnumerator enumerator;
60 60  
61 61 /**
  62 + * Tweaker
  63 + */
  64 + private final LiteLoaderTweaker tweaker;
  65 +
  66 + /**
62 67 * Configuration manager
63 68 */
64 69 private final ConfigManager configManager;
... ... @@ -100,6 +105,7 @@ public class LiteLoaderMods
100 105 this.loader = loader;
101 106 this.environment = environment;
102 107 this.enumerator = environment.getEnumerator();
  108 + this.tweaker = (LiteLoaderTweaker)environment.getTweaker();
103 109 this.properties = properties;
104 110 this.configManager = configManager;
105 111 }
... ... @@ -681,7 +687,7 @@ public class LiteLoaderMods
681 687 */
682 688 private void validateModTransformers()
683 689 {
684   - ClassTransformerManager transformerManager = LiteLoaderTweaker.getTransformerManager();
  690 + ClassTransformerManager transformerManager = this.tweaker.getTransformerManager();
685 691 Set<String> injectedTransformers = transformerManager.getInjectedTransformers();
686 692  
687 693 for (Mod mod : this.loadedMods)
... ... @@ -737,7 +743,7 @@ public class LiteLoaderMods
737 743 {
738 744 if (!mod.hasClassTransformers()) return false;
739 745  
740   - Set<String> injectedTransformers = LiteLoaderTweaker.getTransformerManager().getInjectedTransformers();
  746 + Set<String> injectedTransformers = this.tweaker.getTransformerManager().getInjectedTransformers();
741 747 List<String> modTransformers = ((TweakContainer<?>)mod.getContainer()).getClassTransformerClassNames();
742 748  
743 749 for (String modTransformer : modTransformers)
... ...
java/common/com/mumfrey/liteloader/launch/LiteLoaderTweaker.java
... ... @@ -14,7 +14,6 @@ import net.minecraft.launchwrapper.ITweaker;
14 14 import net.minecraft.launchwrapper.Launch;
15 15 import net.minecraft.launchwrapper.LaunchClassLoader;
16 16  
17   -import com.google.common.base.Throwables;
18 17 import com.mumfrey.liteloader.util.SortableValue;
19 18 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
20 19  
... ... @@ -162,16 +161,39 @@ public class LiteLoaderTweaker implements ITweaker
162 161 }
163 162 }
164 163  
165   - private static LiteLoaderTweaker instance;
  164 + /**
  165 + * Singleton instance, mainly for delegating from injected callbacks which need a static method to call
  166 + */
  167 + protected static LiteLoaderTweaker instance;
166 168  
167   - protected URL jarUrl;
  169 + /**
  170 + * Approximate location of the minecraft jar, used for "base" injection position in ClassPathUtilities
  171 + */
  172 + protected static URL jarUrl;
168 173  
  174 + /**
  175 + * "Order" value for inserted tweakers, used as disambiguating sort criteria for injected tweakers which have the same priority
  176 + */
169 177 protected int tweakOrder = 0;
  178 +
  179 + /**
  180 + * All tweakers, used to avoid injecting duplicates
  181 + */
170 182 protected Set<String> allCascadingTweaks = new HashSet<String>();
  183 +
  184 + /**
  185 + * Sorted list of tweakers, used to sort tweakers before injecting
  186 + */
171 187 protected Set<SortableValue<String>> sortedCascadingTweaks = new TreeSet<SortableValue<String>>();
172 188  
  189 + /**
  190 + * True if this is the primary tweak, not known until at least PREJOINGAME
  191 + */
173 192 protected boolean isPrimary;
174 193  
  194 + /**
  195 + * Startup environment information, used to store info about the current startup in one place, also handles parsing command line arguments
  196 + */
175 197 protected StartupEnvironment env;
176 198  
177 199 /**
... ... @@ -179,22 +201,78 @@ public class LiteLoaderTweaker implements ITweaker
179 201 */
180 202 protected LoaderBootstrap bootstrap;
181 203  
182   - protected LoaderProperties properties;
183   -
184 204 /**
185 205 * Transformer manager
186 206 */
187 207 protected ClassTransformerManager transformerManager;
188 208  
  209 + /* (non-Javadoc)
  210 + * @see net.minecraft.launchwrapper.ITweaker#acceptOptions(java.util.List, java.io.File, java.io.File, java.lang.String)
  211 + */
189 212 @Override
190 213 public void acceptOptions(List<String> args, File gameDirectory, File assetsDirectory, String profile)
191 214 {
192 215 Launch.classLoader.addClassLoaderExclusion("com.google.common.");
193 216 LiteLoaderTweaker.instance = this;
194 217  
195   - this.prepare(args, gameDirectory, assetsDirectory, profile);
  218 + this.onPrepare(args, gameDirectory, assetsDirectory, profile);
196 219  
197   - this.preInit();
  220 + this.onPreInit();
  221 + }
  222 +
  223 + /* (non-Javadoc)
  224 + * @see net.minecraft.launchwrapper.ITweaker#injectIntoClassLoader(net.minecraft.launchwrapper.LaunchClassLoader)
  225 + */
  226 + @Override
  227 + public void injectIntoClassLoader(LaunchClassLoader classLoader)
  228 + {
  229 + classLoader.addClassLoaderExclusion("com.mumfrey.liteloader.core.runtime.Obf");
  230 + classLoader.addClassLoaderExclusion("com.mumfrey.liteloader.core.runtime.Packets");
  231 +
  232 + this.transformerManager.injectUpstreamTransformers(classLoader);
  233 +
  234 + for (String transformerClassName : this.bootstrap.getRequiredDownstreamTransformers())
  235 + {
  236 + LiteLoaderLogger.info("Queuing required class transformer '%s'", transformerClassName);
  237 + this.transformerManager.injectTransformer(transformerClassName);
  238 + }
  239 + }
  240 +
  241 + /* (non-Javadoc)
  242 + * @see net.minecraft.launchwrapper.ITweaker#getLaunchTarget()
  243 + */
  244 + @Override
  245 + public String getLaunchTarget()
  246 + {
  247 + this.isPrimary = true;
  248 + this.onPreBeginGame();
  249 +
  250 + return "net.minecraft.client.main.Main";
  251 + }
  252 +
  253 + /* (non-Javadoc)
  254 + * @see net.minecraft.launchwrapper.ITweaker#getLaunchArguments()
  255 + */
  256 + @Override
  257 + public String[] getLaunchArguments()
  258 + {
  259 + return this.env.getLaunchArguments();
  260 + }
  261 +
  262 + /**
  263 + * Return true if this is the primary tweaker
  264 + */
  265 + public boolean isPrimary()
  266 + {
  267 + return this.isPrimary;
  268 + }
  269 +
  270 + /**
  271 + * Get the class transformer manager
  272 + */
  273 + public ClassTransformerManager getTransformerManager()
  274 + {
  275 + return this.transformerManager;
198 276 }
199 277  
200 278 /**
... ... @@ -203,7 +281,7 @@ public class LiteLoaderTweaker implements ITweaker
203 281 * @param profile
204 282 * @param apisToLoad
205 283 */
206   - private void prepare(List<String> args, File gameDirectory, File assetsDirectory, String profile)
  284 + private void onPrepare(List<String> args, File gameDirectory, File assetsDirectory, String profile)
207 285 {
208 286 LiteLoaderLogger.info("Bootstrapping LiteLoader " + LiteLoaderTweaker.VERSION);
209 287  
... ... @@ -212,7 +290,6 @@ public class LiteLoaderTweaker implements ITweaker
212 290 this.initEnvironment(args, gameDirectory, assetsDirectory, profile);
213 291  
214 292 this.bootstrap = this.spawnBootstrap(LiteLoaderTweaker.bootstrapClassName, Launch.classLoader);
215   - this.properties = this.bootstrap.getProperties();
216 293  
217 294 this.transformerManager = new ClassTransformerManager(this.bootstrap.getRequiredTransformers());
218 295 this.transformerManager.injectTransformers(this.bootstrap.getPacketTransformers());
... ... @@ -228,7 +305,7 @@ public class LiteLoaderTweaker implements ITweaker
228 305 /**
229 306 * Do the first stage of loader startup, which enumerates mod sources and finds tweakers
230 307 */
231   - private void preInit()
  308 + private void onPreInit()
232 309 {
233 310 StartupState.PREINIT.gotoState();
234 311  
... ... @@ -245,13 +322,16 @@ public class LiteLoaderTweaker implements ITweaker
245 322 }
246 323 }
247 324  
248   - public static void preBeginGame()
  325 + /**
  326 + *
  327 + */
  328 + private void onPreBeginGame()
249 329 {
250 330 StartupState.BEGINGAME.gotoState();
251 331 try
252 332 {
253   - LiteLoaderTweaker.instance.transformerManager.injectDownstreamTransformers(Launch.classLoader);
254   - LiteLoaderTweaker.instance.bootstrap.preBeginGame();
  333 + this.transformerManager.injectDownstreamTransformers(Launch.classLoader);
  334 + this.bootstrap.preBeginGame();
255 335 StartupState.BEGINGAME.completed();
256 336 }
257 337 catch (Throwable th)
... ... @@ -263,13 +343,13 @@ public class LiteLoaderTweaker implements ITweaker
263 343 /**
264 344 * Do the second stage of loader startup
265 345 */
266   - public static void init()
  346 + private void onInit()
267 347 {
268 348 StartupState.INIT.gotoState();
269 349  
270 350 try
271 351 {
272   - LiteLoaderTweaker.instance.bootstrap.init(Launch.classLoader);
  352 + this.bootstrap.init();
273 353 StartupState.INIT.completed();
274 354 }
275 355 catch (Throwable th)
... ... @@ -281,13 +361,13 @@ public class LiteLoaderTweaker implements ITweaker
281 361 /**
282 362 * Do the second stage of loader startup
283 363 */
284   - public static void postInit()
  364 + private void onPostInit()
285 365 {
286 366 StartupState.POSTINIT.gotoState();
287 367  
288 368 try
289 369 {
290   - LiteLoaderTweaker.instance.bootstrap.postInit();
  370 + this.bootstrap.postInit();
291 371 StartupState.POSTINIT.completed();
292 372  
293 373 StartupState.DONE.gotoState();
... ... @@ -298,81 +378,25 @@ public class LiteLoaderTweaker implements ITweaker
298 378 }
299 379 }
300 380  
301   - protected void initEnvironment(List<String> args, File gameDirectory, File assetsDirectory, String profile)
  381 + /**
  382 + * Set up the startup environment
  383 + *
  384 + * @param args
  385 + * @param gameDirectory
  386 + * @param assetsDirectory
  387 + * @param profile
  388 + */
  389 + private void initEnvironment(List<String> args, File gameDirectory, File assetsDirectory, String profile)
302 390 {
303   - this.env = new StartupEnvironment(args, gameDirectory, assetsDirectory, profile)
304   - {
305   - @Override
306   - public void registerCoreAPIs(List<String> apisToLoad)
307   - {
308   - apisToLoad.add(0, "com.mumfrey.liteloader.client.api.LiteLoaderCoreAPIClient");
309   - }
310   -
311   - @Override
312   - public int getEnvironmentTypeId()
313   - {
314   - return LiteLoaderTweaker.ENV_TYPE_CLIENT;
315   - }
316   - };
  391 + this.env = this.spawnStartupEnvironment(args, gameDirectory, assetsDirectory, profile);
317 392  
318 393 URL[] urls = Launch.classLoader.getURLs();
319   - this.jarUrl = urls[urls.length - 1]; // probably?
320   - }
321   -
322   - @Override
323   - public void injectIntoClassLoader(LaunchClassLoader classLoader)
324   - {
325   - classLoader.addClassLoaderExclusion("com.mumfrey.liteloader.core.runtime.Obf");
326   - classLoader.addClassLoaderExclusion("com.mumfrey.liteloader.core.runtime.Packets");
327   -
328   - LiteLoaderTweaker.instance.transformerManager.injectUpstreamTransformers(classLoader);
329   -
330   - for (String transformerClassName : this.bootstrap.getRequiredDownstreamTransformers())
331   - {
332   - LiteLoaderLogger.info("Queuing required class transformer '%s'", transformerClassName);
333   - LiteLoaderTweaker.instance.transformerManager.injectTransformer(transformerClassName);
334   - }
335   - }
336   -
337   - @Override
338   - public String getLaunchTarget()
339   - {
340   - this.isPrimary = true;
341   - LiteLoaderTweaker.preBeginGame();
342   -
343   - return "net.minecraft.client.main.Main";
344   - }
345   -
346   - @Override
347   - public String[] getLaunchArguments()
348   - {
349   - return this.env.getLaunchArguments();
350   - }
351   -
352   - public static boolean addCascadedTweaker(String tweakClass, int priority)
353   - {
354   - return LiteLoaderTweaker.instance.addTweakToSortedList(tweakClass, priority);
355   - }
356   -
357   - private boolean addTweakToSortedList(String tweakClass, int priority)
358   - {
359   - if (tweakClass != null && !this.allCascadingTweaks.contains(tweakClass))
360   - {
361   - if (this.getClass().getName().equals(tweakClass))
362   - return false;
363   -
364   - if (LiteLoaderTweaker.isTweakAlreadyEnqueued(tweakClass))
365   - return false;
366   -
367   - this.allCascadingTweaks.add(tweakClass);
368   - this.sortedCascadingTweaks.add(new SortableValue<String>(priority, this.tweakOrder++, tweakClass));
369   - return true;
370   - }
371   -
372   - return false;
  394 + LiteLoaderTweaker.jarUrl = urls[urls.length - 1]; // probably?
373 395 }
374 396  
375   - @SuppressWarnings("unchecked")
  397 + /**
  398 + * Injects discovered tweak classes
  399 + */
376 400 private void injectDiscoveredTweakClasses()
377 401 {
378 402 if (this.sortedCascadingTweaks.size() > 0)
... ... @@ -385,7 +409,9 @@ public class LiteLoaderTweaker implements ITweaker
385 409  
386 410 LiteLoaderLogger.info("Injecting cascaded tweakers...");
387 411  
  412 + @SuppressWarnings("unchecked")
388 413 List<String> tweakClasses = (List<String>)Launch.blackboard.get("TweakClasses");
  414 + @SuppressWarnings("unchecked")
389 415 List<ITweaker> tweakers = (List<ITweaker>)Launch.blackboard.get("Tweaks");
390 416 if (tweakClasses != null && tweakers != null)
391 417 {
... ... @@ -420,32 +446,37 @@ public class LiteLoaderTweaker implements ITweaker
420 446 tweakClasses.add(tweakClass);
421 447 }
422 448 }
423   -
  449 +
424 450 /**
425   - * @param url URL to add
  451 + * @param tweakClass
  452 + * @param priority
  453 + * @return
426 454 */
427   - public static boolean addURLToParentClassLoader(URL url)
  455 + public boolean addCascadedTweaker(String tweakClass, int priority)
428 456 {
429   - if (StartupState.getCurrent() == StartupState.PREINIT && StartupState.PREINIT.isInState())
  457 + if (tweakClass != null && !this.allCascadingTweaks.contains(tweakClass))
430 458 {
431   - try
432   - {
433   - URLClassLoader classLoader = (URLClassLoader)Launch.class.getClassLoader();
434   - Method mAddUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
435   - mAddUrl.setAccessible(true);
436   - mAddUrl.invoke(classLoader, url);
437   -
438   - return true;
439   - }
440   - catch (Exception ex)
441   - {
442   - LiteLoaderLogger.warning(ex, "addURLToParentClassLoader failed: %s", ex.getMessage());
443   - }
444   - }
  459 + if (this.getClass().getName().equals(tweakClass))
  460 + return false;
445 461  
  462 + if (LiteLoaderTweaker.isTweakAlreadyEnqueued(tweakClass))
  463 + return false;
  464 +
  465 + this.allCascadingTweaks.add(tweakClass);
  466 + this.sortedCascadingTweaks.add(new SortableValue<String>(priority, this.tweakOrder++, tweakClass));
  467 + return true;
  468 + }
  469 +
446 470 return false;
447 471 }
448 472  
  473 + /**
  474 + * The bootstrap object has to be spawned using reflection for obvious reasons,
  475 + *
  476 + * @param bootstrapClassName
  477 + * @param classLoader
  478 + * @return
  479 + */
449 480 protected LoaderBootstrap spawnBootstrap(String bootstrapClassName, ClassLoader classLoader)
450 481 {
451 482 if (!StartupState.PREPARE.isInState())
... ... @@ -464,27 +495,72 @@ public class LiteLoaderTweaker implements ITweaker
464 495 }
465 496 catch (Throwable th)
466 497 {
467   - Throwables.propagate(th);
  498 + throw new RuntimeException(th);
468 499 }
469   -
470   - return null;
471 500 }
472   -
473   - public static URL getJarUrl()
  501 +
  502 + /**
  503 + * @param args
  504 + * @param gameDirectory
  505 + * @param assetsDirectory
  506 + * @param profile
  507 + * @return
  508 + */
  509 + protected StartupEnvironment spawnStartupEnvironment(List<String> args, File gameDirectory, File assetsDirectory, String profile)
474 510 {
475   - return LiteLoaderTweaker.instance.jarUrl;
  511 + return new StartupEnvironment(args, gameDirectory, assetsDirectory, profile)
  512 + {
  513 + @Override
  514 + public void registerCoreAPIs(List<String> apisToLoad)
  515 + {
  516 + apisToLoad.add(0, "com.mumfrey.liteloader.client.api.LiteLoaderCoreAPIClient");
  517 + }
  518 +
  519 + @Override
  520 + public int getEnvironmentTypeId()
  521 + {
  522 + return LiteLoaderTweaker.ENV_TYPE_CLIENT;
  523 + }
  524 + };
476 525 }
477   -
478   - public static boolean isPrimary()
  526 +
  527 + /**
  528 + * @return
  529 + */
  530 + public static URL getJarUrl()
479 531 {
480   - return LiteLoaderTweaker.instance.isPrimary;
  532 + return LiteLoaderTweaker.jarUrl;
481 533 }
482 534  
483   - public static ClassTransformerManager getTransformerManager()
  535 + /**
  536 + * @param url URL to add
  537 + */
  538 + public static boolean addURLToParentClassLoader(URL url)
484 539 {
485   - return LiteLoaderTweaker.instance.transformerManager;
  540 + if (StartupState.getCurrent() == StartupState.PREINIT && StartupState.PREINIT.isInState())
  541 + {
  542 + try
  543 + {
  544 + URLClassLoader classLoader = (URLClassLoader)Launch.class.getClassLoader();
  545 + Method mAddUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
  546 + mAddUrl.setAccessible(true);
  547 + mAddUrl.invoke(classLoader, url);
  548 +
  549 + return true;
  550 + }
  551 + catch (Exception ex)
  552 + {
  553 + LiteLoaderLogger.warning(ex, "addURLToParentClassLoader failed: %s", ex.getMessage());
  554 + }
  555 + }
  556 +
  557 + return false;
486 558 }
487   -
  559 +
  560 + /**
  561 + * @param clazz
  562 + * @return
  563 + */
488 564 @SuppressWarnings("unchecked")
489 565 private static boolean isTweakAlreadyEnqueued(String clazz)
490 566 {
... ... @@ -510,8 +586,36 @@ public class LiteLoaderTweaker implements ITweaker
510 586 return false;
511 587 }
512 588  
  589 + /**
  590 + * @return
  591 + */
513 592 public static boolean loadingBarEnabled()
514 593 {
515   - return LiteLoaderTweaker.instance.properties != null ? LiteLoaderTweaker.instance.properties.getBooleanProperty("loadingbar") : false;
  594 + LoaderProperties properties = LiteLoaderTweaker.instance.bootstrap.getProperties();
  595 + return properties != null && properties.getBooleanProperty("loadingbar");
  596 + }
  597 +
  598 + /**
  599 + * Callback from the "Main" class, do the PREBEGINGAME steps (inject "downstream" transformers)
  600 + */
  601 + public static void preBeginGame()
  602 + {
  603 + LiteLoaderTweaker.instance.onPreBeginGame();
  604 + }
  605 +
  606 + /**
  607 + * Callback from Minecraft::startGame() do early mod initialisation
  608 + */
  609 + public static void init()
  610 + {
  611 + LiteLoaderTweaker.instance.onInit();
  612 + }
  613 +
  614 + /**
  615 + * Callback from Minecraft::startGame() do late mod initialisation
  616 + */
  617 + public static void postInit()
  618 + {
  619 + LiteLoaderTweaker.instance.onPostInit();
516 620 }
517 621 }
518 622 \ No newline at end of file
... ...
java/common/com/mumfrey/liteloader/launch/LiteLoaderTweakerServer.java
1 1 package com.mumfrey.liteloader.launch;
2 2  
3 3 import java.io.File;
4   -import java.net.URL;
5 4 import java.util.List;
6 5  
7   -import net.minecraft.launchwrapper.Launch;
8   -
9 6 public class LiteLoaderTweakerServer extends LiteLoaderTweaker
10 7 {
11 8 @Override
12   - protected void initEnvironment(List<String> args, File gameDirectory, File assetsDirectory, String profile)
  9 + protected StartupEnvironment spawnStartupEnvironment(List<String> args, File gameDirectory, File assetsDirectory, String profile)
13 10 {
14   - this.env = new StartupEnvironment(args, gameDirectory, assetsDirectory, profile)
  11 + return new StartupEnvironment(args, gameDirectory, assetsDirectory, profile)
15 12 {
16 13 @Override
17 14 public void registerCoreAPIs(List<String> apisToLoad)
... ... @@ -25,9 +22,6 @@ public class LiteLoaderTweakerServer extends LiteLoaderTweaker
25 22 return LiteLoaderTweaker.ENV_TYPE_DEDICATEDSERVER;
26 23 }
27 24 };
28   -
29   - URL[] urls = Launch.classLoader.getURLs();
30   - this.jarUrl = urls[urls.length - 1]; // probably?
31 25 }
32 26  
33 27 @Override
... ...
java/common/com/mumfrey/liteloader/launch/LoaderBootstrap.java
... ... @@ -30,7 +30,7 @@ public interface LoaderBootstrap
30 30 /**
31 31 * Init, create the loader instance and load mods
32 32 */
33   - public abstract void init(LaunchClassLoader classLoader);
  33 + public abstract void init();
34 34  
35 35 /**
36 36 * Post-init, initialise loaded mods
... ...
java/common/com/mumfrey/liteloader/launch/LoaderEnvironment.java
... ... @@ -2,6 +2,8 @@ package com.mumfrey.liteloader.launch;
2 2  
3 3 import java.io.File;
4 4  
  5 +import net.minecraft.launchwrapper.ITweaker;
  6 +
5 7 import com.mumfrey.liteloader.api.manager.APIAdapter;
6 8 import com.mumfrey.liteloader.api.manager.APIProvider;
7 9 import com.mumfrey.liteloader.core.EnabledModsList;
... ... @@ -73,4 +75,9 @@ public interface LoaderEnvironment extends GameEnvironment
73 75 * @return
74 76 */
75 77 public abstract File inflectVersionedConfigPath(LiteLoaderVersion version);
  78 +
  79 + /**
  80 + * Get the tweaker
  81 + */
  82 + public abstract ITweaker getTweaker();
76 83 }
... ...