Commit 47e1f2f2e41ccbae12932d87101eeee88a02127a

Authored by Mumfrey
1 parent 0b584ff1

Fix applying brand when loading as a forge mod

src/client/resources/mixins.liteloader.client.preinit.json
1 1 {
2   - "required": true,
  2 + "required": false,
3 3 "minVersion": "0.7.4",
4 4 "compatibilityLevel": "JAVA_8",
5 5 "target": "@env(PREINIT)",
... ... @@ -7,8 +7,5 @@
7 7 "refmap": "mixins.liteloader.client.refmap.json",
8 8 "mixins": [
9 9 "MixinClientBrandRetriever"
10   - ],
11   - "injectors": {
12   - "defaultRequire": 1
13   - }
  10 + ]
14 11 }
15 12 \ No newline at end of file
... ...
src/main/java/com/mumfrey/liteloader/core/LiteLoader.java
... ... @@ -896,6 +896,8 @@ public final class LiteLoader
896 896 */
897 897 void onStartupComplete()
898 898 {
  899 + LiteLoaderBootstrap.onStartupComplete();
  900 +
899 901 this.coreProviders.all().onStartupComplete();
900 902  
901 903 if (this.panelManager != null)
... ...
src/main/java/com/mumfrey/liteloader/core/LiteLoaderBootstrap.java
... ... @@ -12,7 +12,9 @@ import java.io.FileWriter;
12 12 import java.io.IOException;
13 13 import java.io.InputStream;
14 14 import java.io.Serializable;
  15 +import java.lang.reflect.Field;
15 16 import java.util.List;
  17 +import java.util.Map;
16 18 import java.util.Properties;
17 19  
18 20 import org.apache.commons.io.Charsets;
... ... @@ -22,6 +24,7 @@ import org.apache.logging.log4j.core.appender.FileAppender;
22 24 import org.apache.logging.log4j.core.layout.PatternLayout;
23 25 import org.spongepowered.asm.mixin.MixinEnvironment;
24 26  
  27 +import com.google.common.collect.ImmutableMap;
25 28 import com.mumfrey.liteloader.api.LiteAPI;
26 29 import com.mumfrey.liteloader.api.manager.APIAdapter;
27 30 import com.mumfrey.liteloader.api.manager.APIProvider;
... ... @@ -40,6 +43,7 @@ import com.mumfrey.liteloader.util.ObfuscationUtilities;
40 43 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
41 44 import com.mumfrey.liteloader.util.log.LiteLoaderLogger.Verbosity;
42 45  
  46 +import net.minecraft.client.ClientBrandRetriever;
43 47 import net.minecraft.launchwrapper.ITweaker;
44 48 import net.minecraft.launchwrapper.LaunchClassLoader;
45 49  
... ... @@ -768,6 +772,56 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP
768 772 {
769 773 return this.branding;
770 774 }
  775 +
  776 + /**
  777 + * Check that the branding was applied and if not, attempt to set it in the
  778 + * fml branding directly using reflection
  779 + */
  780 + @SuppressWarnings("unchecked")
  781 + static void onStartupComplete()
  782 + {
  783 + try
  784 + {
  785 + // If this field exists, the mixin was successfully applied so we can stop
  786 +
  787 + try
  788 + {
  789 + ClientBrandRetriever.class.getDeclaredField("BRANDING_LITELOADER");
  790 + return;
  791 + }
  792 + catch (NoSuchFieldException ex)
  793 + {
  794 + // Field doesn't exist so the mixin was not applied
  795 + }
  796 +
  797 + // Get loader
  798 + Class<?> clLoader = Class.forName("net.minecraftforge.fml.common.Loader");
  799 +
  800 + // Get instance
  801 + Object instance = clLoader.getMethod("instance").invoke(null);
  802 +
  803 + // Get branding properties
  804 + Map<String, String> properties = (Map<String, String>)clLoader.getMethod("getFMLBrandingProperties").invoke(instance);
  805 +
  806 + // Retrieve the current snooper branding
  807 + String branding = properties.get("snooperbranding");
  808 +
  809 + // If it's blank, set ourself, if it's already set then append ourself
  810 + branding = branding == null ? "LiteLoader" : branding + ",LiteLoader";
  811 +
  812 + // Find the field in Loader
  813 + Field fdProperties = clLoader.getDeclaredField("fmlBrandingProperties");
  814 + fdProperties.setAccessible(true);
  815 +
  816 + // Set new properties into field
  817 + fdProperties.set(instance, ImmutableMap.<String, String>builder().putAll(properties).put("snooperbranding", branding).build());
  818 + }
  819 + catch (Exception ex)
  820 + {
  821 + // Oh well, we tried
  822 + ex.printStackTrace();
  823 + }
  824 + }
771 825  
772 826 /* (non-Javadoc)
773 827 * @see com.mumfrey.liteloader.launch.LoaderBootstrap
... ...
src/main/java/com/mumfrey/liteloader/crashreport/CrashSectionLiteLoaderBrand.java
... ... @@ -31,7 +31,7 @@ public class CrashSectionLiteLoaderBrand
31 31 }
32 32 catch (Exception ex)
33 33 {
34   - brand = "LiteLoader startup failed";
  34 + brand = "LiteLoader startup incomplete";
35 35 }
36 36 return brand == null ? "Unknown / None" : brand;
37 37 }
... ...
src/main/java/com/mumfrey/liteloader/crashreport/CrashSectionLiteLoaderMods.java
... ... @@ -30,7 +30,7 @@ public class CrashSectionLiteLoaderMods
30 30 }
31 31 catch (Exception ex)
32 32 {
33   - return "LiteLoader startup failed";
  33 + return "LiteLoader startup incomplete";
34 34 }
35 35 }
36 36 }
... ...