From 0a0c3d2a6abf20ec1d946a920343ee1f9d98eec2 Mon Sep 17 00:00:00 2001 From: FalsePattern <30945458+FalsePattern@users.noreply.github.com> Date: Wed, 4 Jan 2023 01:20:24 +0100 Subject: [PATCH] forgot to add these --- dependencies.gradle | 2 +- .../lib/internal/asm/FPTransformer.java | 2 +- .../asm/GasStationValidatorTransformer.java | 55 ++++++++++++++++++ .../com/falsepattern/lib/mixin/MixinInfo.java | 58 +++++++++---------- 4 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/falsepattern/lib/internal/asm/GasStationValidatorTransformer.java diff --git a/dependencies.gradle b/dependencies.gradle index d432b42..7286317 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,5 +1,5 @@ dependencies { - compileOnly("org.projectlombok:lombok:1.18.22") { + compileOnly("org.projectlombok:lombok:1.18.24") { transitive = false } compileOnly("org.spongepowered:mixin:0.8.3-gasstation") diff --git a/src/main/java/com/falsepattern/lib/internal/asm/FPTransformer.java b/src/main/java/com/falsepattern/lib/internal/asm/FPTransformer.java index d40cd66..e4e8dc9 100644 --- a/src/main/java/com/falsepattern/lib/internal/asm/FPTransformer.java +++ b/src/main/java/com/falsepattern/lib/internal/asm/FPTransformer.java @@ -45,6 +45,6 @@ public class FPTransformer implements SmartTransformer { private final Logger logger = LOG; public FPTransformer() { - transformers = Arrays.asList(new IMixinPluginTransformer(), new ITypeDiscovererTransformer(), new NonUpdateTransformer()); + transformers = Arrays.asList(new IMixinPluginTransformer(), new ITypeDiscovererTransformer(), new NonUpdateTransformer(), new GasStationValidatorTransformer()); } } diff --git a/src/main/java/com/falsepattern/lib/internal/asm/GasStationValidatorTransformer.java b/src/main/java/com/falsepattern/lib/internal/asm/GasStationValidatorTransformer.java new file mode 100644 index 0000000..391b89e --- /dev/null +++ b/src/main/java/com/falsepattern/lib/internal/asm/GasStationValidatorTransformer.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ + +package com.falsepattern.lib.internal.asm; + +import com.falsepattern.lib.asm.IClassNodeTransformer; +import org.objectweb.asm.tree.ClassNode; + +import static com.falsepattern.lib.mixin.MixinInfo.isClassPresentSafe; + +public class GasStationValidatorTransformer implements IClassNodeTransformer { + @Override + public String getName() { + return "GasStationValidatorTransformer"; + } + + @Override + public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) { + if (transformedName.equals("com.falsepattern.gasstation.GasStation")) { + //Make sure everything is loaded correctly, crash if gasstation is bugged + if (!isClassPresentSafe("com.falsepattern.gasstation.core.GasStationCore") || //Validate core class + !isClassPresentSafe("makamys.mixingasm.api.TransformerInclusions") || //Validate the mixingasm compat + !isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore") || //Validate the spongemixins compat + !isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin") || //Validate the MBL compat + (!isClassPresentSafe("org.spongepowered.asm.lib.Opcodes") || isClassPresentSafe("org.spongepowered.libraries.org.objectweb.asm.Opcodes")) //Validate correct mixins class + ) { + throw new Error("Failed to validate your GasStation mixin plugin installation. Please make sure you have the latest GasStation installed from the official source: https://github.com/FalsePattern/GasStation"); + } + } + return false; + } + + @Override + public void transform(ClassNode cn, String transformedName, boolean obfuscated) { + + } +} diff --git a/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java b/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java index fb735be..fcf4682 100644 --- a/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java +++ b/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java @@ -22,8 +22,12 @@ package com.falsepattern.lib.mixin; import com.falsepattern.lib.StableAPI; +import lombok.val; import org.spongepowered.asm.launch.MixinBootstrap; +import net.minecraft.launchwrapper.Launch; + +import java.io.IOException; import java.util.Optional; @StableAPI(since = "0.10.2") @@ -59,6 +63,11 @@ public final class MixinInfo { return mixinBootstrapper == MixinBootstrapperType.MixinBooterLegacy; } + @StableAPI.Expose(since = "0.10.14") + public static boolean isGasStation() { + return mixinBootstrapper == MixinBootstrapperType.GasStation; + } + @StableAPI.Expose public static MixinBootstrapperType bootstrapperType() { return mixinBootstrapper; @@ -73,38 +82,29 @@ public final class MixinInfo { return MixinBootstrap.VERSION; } - private static MixinBootstrapperType detect() { + public static boolean isClassPresentSafe(String clazz) { try { - Class.forName("org.spongepowered.asm.launch.MixinBootstrap"); - } catch (ClassNotFoundException ignored) { - return MixinBootstrapperType.None; - } - try { - Class.forName("com.falsepattern.gasstation.core.GasStationCore"); - return MixinBootstrapperType.GasStation; - } catch (ClassNotFoundException ignored) { - } - try { - Class.forName("ru.timeconqueror.spongemixins.core.SpongeMixinsCore"); - return MixinBootstrapperType.SpongeMixins; - } catch (ClassNotFoundException ignored) { - } - try { - Class.forName("io.github.crucible.grimoire.Grimoire"); - return MixinBootstrapperType.Grimoire; - } catch (ClassNotFoundException ignored) { - } - try { - Class.forName("io.github.crucible.grimoire.common.GrimoireCore"); - return MixinBootstrapperType.Grimoire; - } catch (ClassNotFoundException ignored) { - } - try { - Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin"); - return MixinBootstrapperType.MixinBooterLegacy; - } catch (ClassNotFoundException ignored) { + val bytes = Launch.classLoader.getClassBytes(clazz); + if (bytes == null || bytes.length == 0) { + return false; + } + } catch (IOException e) { + return false; } + return true; + } + private static MixinBootstrapperType detect() { + if (!isClassPresentSafe("org.spongepowered.asm.launch.MixinBootstrap")) + return MixinBootstrapperType.None; + if (isClassPresentSafe("com.falsepattern.gasstation.GasStation")) + return MixinBootstrapperType.GasStation; + if (isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore")) + return MixinBootstrapperType.SpongeMixins; + if (isClassPresentSafe("io.github.crucible.grimoire.Grimoire") || isClassPresentSafe("io.github.crucible.grimoire.common.GrimoireCore")) + return MixinBootstrapperType.Grimoire; + if (isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin")) + return MixinBootstrapperType.MixinBooterLegacy; return MixinBootstrapperType.Other; }