even more fixes

This commit is contained in:
FalsePattern committed 2022-08-23 20:52:50 +02:00
1 parent b493480585
commit d902e8eb78
9 files changed
+75 -20

No files matched your search

@@ -23,9 +23,11 @@ package com.falsepattern.lib.config;
import com.falsepattern.lib.DeprecationDetails;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.ReflectionUtil;
import com.falsepattern.lib.internal.impl.config.ConfigurationManagerImpl;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import lombok.val;
import cpw.mods.fml.client.config.IConfigElement;
@@ -48,6 +50,15 @@ public class ConfigurationManager {
initialize((a, b) -> {}, configClasses);
}
/**
* You can use this method in the static initializer of a config class to self-load it without extra effort.
*/
@StableAPI.Expose(since = "0.10.3")
@SneakyThrows
public static void selfInit() {
initialize(ReflectionUtil.getCallerClass());
}
@StableAPI.Expose(since = "0.10.0")
public static void initialize(BiConsumer<Class<?>, Field> validatorErrorCallback, Class<?>... configClasses)
throws ConfigException {
@@ -47,4 +47,9 @@ public class ReflectionUtil {
public static void jailBreak(Method method) {
method.setAccessible(true);
}
@SneakyThrows
public static Class<?> getCallerClass() {
return Class.forName(Thread.currentThread().getStackTrace()[3].getClassName());
}
}
@@ -26,6 +26,9 @@ import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.mixin.MixinInfo;
import lombok.val;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import java.util.ArrayList;
public class IMixinPluginTransformer implements IClassNodeTransformer {
@Override
@@ -41,18 +44,21 @@ public class IMixinPluginTransformer implements IClassNodeTransformer {
@Override
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
val methods = cn.methods;
val remove = new ArrayList<MethodNode>();
String name;
if (!MixinInfo.isMixinBooterLegacy()) {
FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Converting IMixinPlugin to legacy compat mode.");
for (val method : methods) {
if (method.name.equals("preApply") || method.name.equals("postApply")) {
method.desc = method.desc.replace("org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode",
"org/spongepowered/asm/lib/tree/ClassNode");
for (val local: method.localVariables) {
local.desc = local.desc.replace("org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode",
"org/spongepowered/asm/lib/tree/ClassNode");
}
}
FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Removing MBL compat code.");
name = "org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode";
} else {
FPTransformer.LOG.info("Detected MixinBooterLegacy. Removing SpongeMixins compat code.");
name = "org/spongepowered/asm/lib/tree/ClassNode";
}
for (val method: methods) {
if ((method.name.equals("preApply") || method.name.equals("postApply")) &&
method.desc.contains(name)) {
remove.add(method);
}
}
methods.removeAll(remove);
}
}
@@ -22,10 +22,14 @@ package com.falsepattern.lib.internal.config;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.Tags;
@Config(modid = Tags.MODID)
public class LibraryConfig {
static {
ConfigurationManager.selfInit();
}
@Config.Comment({"Used to control whether FalsePatternLib should check for outdated mods.",
"If you're building a public modpack, you should turn this off so that your users don't " +
"get nagged about outdated mods."})
@@ -22,6 +22,7 @@ package com.falsepattern.lib.internal.config;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.Tags;
import cpw.mods.fml.relauncher.Side;
@@ -31,6 +32,9 @@ import cpw.mods.fml.relauncher.SideOnly;
@Config(modid = Tags.MODID,
category = "toasts")
public class ToastConfig {
static {
ConfigurationManager.selfInit();
}
@Config.Comment("The maximum amount of toasts to show on the screen")
@Config.LangKey("config.falsepatternlib.maxtoasts")
@Config.DefaultInt(5)
@@ -58,11 +58,6 @@ public class ClientProxy extends CommonProxy {
@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
try {
ConfigurationManager.initialize(ToastConfig.class);
} catch (ConfigException ex) {
throw new RuntimeException(ex);
}
MinecraftForge.EVENT_BUS.register(this);
}
@@ -57,11 +57,6 @@ public class CommonProxy {
public void preInit(FMLPreInitializationEvent e) {
ConfigurationManagerImpl.registerBus();
try {
ConfigurationManager.initialize(LibraryConfig.class);
} catch (ConfigException ex) {
throw new RuntimeException(ex);
}
if (LibraryConfig.ENABLE_UPDATE_CHECKER) {
FalsePatternLib.getLog().info("Launching asynchronous update check.");
updatesFuture = UpdateChecker.fetchUpdatesAsync(FalsePatternLib.UPDATE_URL).thenApplyAsync(updates -> {
@@ -157,4 +157,14 @@ public interface IMixinPlugin extends IMixinConfigPlugin {
default void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
@StableAPI.Expose(since = "__INTERNAL__")
default void preApply(String targetClassName, com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
@StableAPI.Expose(since = "__INTERNAL__")
default void postApply(String targetClassName, com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree;
public class ClassNode {
}