mirror of
https://github.com/GTMEGA/EndlessIDs.git
synced 2026-11-16 21:05:01 +00:00
properly fix dragonapi compat
This commit is contained in:
3 files changed
+82
-2
No files matched your search
@@ -8,8 +8,10 @@ import lombok.Getter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class MixinPlugin implements IMixinPlugin {
|
||||
public static final Logger LOG = IMixinPlugin.createLogger(Tags.MODNAME);
|
||||
|
||||
@Getter
|
||||
private final Logger logger = IMixinPlugin.createLogger(Tags.MODNAME);
|
||||
private final Logger logger = LOG;
|
||||
|
||||
@Override
|
||||
public IMixin[] getMixinEnumValues() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.falsepattern.endlessids.mixin.plugin;
|
||||
|
||||
import com.falsepattern.endlessids.mixin.util.DragonAPICompat;
|
||||
import com.falsepattern.lib.mixin.ITargetedMod;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -15,7 +16,10 @@ public enum TargetedMod implements ITargetedMod {
|
||||
ATG("Alternate Terrain Generation", true, startsWith("atg")),
|
||||
BOP("Biomes O' Plenty", true, startsWith("biomesoplenty-")),
|
||||
COFHLIB("CoFH Lib", true, startsWith("cofhlib-")),
|
||||
DRAGONAPI("DragonAPI", false, startsWith("dragonapi")),
|
||||
DRAGONAPI("DragonAPI", false, startsWith("dragonapi").and((x) -> {
|
||||
DragonAPICompat.activate();
|
||||
return true;
|
||||
})),
|
||||
GALACTICRAFTCORE("GalactiCraftCore", false, startsWith("galacticraftcore")),
|
||||
MFQM("More Fun Quicksand Mod", false, startsWith("morefunquicksandmod-")),
|
||||
UBC("Underground Biomes Constructs", false, startsWith("undergroundbiomesconstructs-")),
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.falsepattern.endlessids.mixin.util;
|
||||
|
||||
import com.falsepattern.endlessids.mixin.plugin.MixinPlugin;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
|
||||
public class DragonAPICompat {
|
||||
private static boolean activated = false;
|
||||
|
||||
public static void activate() {
|
||||
if (activated) return;
|
||||
activated = true;
|
||||
Logger LOG = LogManager.getLogger(MixinPlugin.LOG.getName() + " DragonAPI Compat Patcher");
|
||||
LOG.info("DragonAPI detected. Activating very early compatibility patches.");
|
||||
int total = 1;
|
||||
int complete = 0;
|
||||
try {
|
||||
patchFML(LOG);
|
||||
complete++;
|
||||
} catch (Throwable t) {
|
||||
LOG.fatal("Failed to load early DragonAPI compat patches! Crash imminent! Successful: " + complete + ", Total: " + total, t);
|
||||
}
|
||||
LOG.info("DragonAPI early compat patching finished! Resuming normal loading.");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static void patchFML(Logger baseLog) {
|
||||
Logger LOG = LogManager.getLogger(baseLog.getName() + " FML Tweaker");
|
||||
LOG.info("Patching FML loader class...");
|
||||
try {
|
||||
LOG.info("Attempting to get a reference to " + Loader.class.getName() +
|
||||
".namedMods with reflection...");
|
||||
Field f;
|
||||
try {
|
||||
f = Loader.class.getDeclaredField("namedMods");
|
||||
LOG.info("[OK] Reference retrieved!");
|
||||
} catch (Throwable t) {
|
||||
LOG.error("[FAIL] Failed to retrieve the field!");
|
||||
throw t;
|
||||
}
|
||||
LOG.info("[INFO] Making the reference accessible...");
|
||||
try {
|
||||
f.setAccessible(true);
|
||||
LOG.info("[OK] Reference is now accessible!");
|
||||
} catch (Throwable t) {
|
||||
LOG.error("[FAIL] Failed to make the reference accessible!");
|
||||
throw t;
|
||||
}
|
||||
|
||||
LOG.info("[INFO] Inserting placeholder Collections.emptyMap() object into the field...");
|
||||
try {
|
||||
if (f.get(Loader.instance()) != null) {
|
||||
LOG.info("[OK] Field already had a value, not replacing.");
|
||||
} else {
|
||||
f.set(Loader.instance(), Collections.emptyMap());
|
||||
LOG.info("[OK] Successfully inserted placeholder object!");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
LOG.error("[FAIL] Failed to insert placeholder object!");
|
||||
throw t;
|
||||
}
|
||||
LOG.info("FML Loader class patched successfully!");
|
||||
} catch (Throwable t) {
|
||||
LOG.error("Failed to patch FML Loader class! Check the log file for debug info!");
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user