Skip to content

Commit 0a0c3d2

Browse files
committed
forgot to add these
1 parent 7cf4049 commit 0a0c3d2

File tree

4 files changed

+83
-28
lines changed

4 files changed

+83
-28
lines changed

dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dependencies {
2-
compileOnly("org.projectlombok:lombok:1.18.22") {
2+
compileOnly("org.projectlombok:lombok:1.18.24") {
33
transitive = false
44
}
55
compileOnly("org.spongepowered:mixin:0.8.3-gasstation")

src/main/java/com/falsepattern/lib/internal/asm/FPTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public class FPTransformer implements SmartTransformer {
4545
private final Logger logger = LOG;
4646

4747
public FPTransformer() {
48-
transformers = Arrays.asList(new IMixinPluginTransformer(), new ITypeDiscovererTransformer(), new NonUpdateTransformer());
48+
transformers = Arrays.asList(new IMixinPluginTransformer(), new ITypeDiscovererTransformer(), new NonUpdateTransformer(), new GasStationValidatorTransformer());
4949
}
5050
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2022 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice, this permission notice and the word "SNEED"
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.falsepattern.lib.internal.asm;
23+
24+
import com.falsepattern.lib.asm.IClassNodeTransformer;
25+
import org.objectweb.asm.tree.ClassNode;
26+
27+
import static com.falsepattern.lib.mixin.MixinInfo.isClassPresentSafe;
28+
29+
public class GasStationValidatorTransformer implements IClassNodeTransformer {
30+
@Override
31+
public String getName() {
32+
return "GasStationValidatorTransformer";
33+
}
34+
35+
@Override
36+
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
37+
if (transformedName.equals("com.falsepattern.gasstation.GasStation")) {
38+
//Make sure everything is loaded correctly, crash if gasstation is bugged
39+
if (!isClassPresentSafe("com.falsepattern.gasstation.core.GasStationCore") || //Validate core class
40+
!isClassPresentSafe("makamys.mixingasm.api.TransformerInclusions") || //Validate the mixingasm compat
41+
!isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore") || //Validate the spongemixins compat
42+
!isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin") || //Validate the MBL compat
43+
(!isClassPresentSafe("org.spongepowered.asm.lib.Opcodes") || isClassPresentSafe("org.spongepowered.libraries.org.objectweb.asm.Opcodes")) //Validate correct mixins class
44+
) {
45+
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");
46+
}
47+
}
48+
return false;
49+
}
50+
51+
@Override
52+
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
53+
54+
}
55+
}

src/main/java/com/falsepattern/lib/mixin/MixinInfo.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
package com.falsepattern.lib.mixin;
2323

2424
import com.falsepattern.lib.StableAPI;
25+
import lombok.val;
2526
import org.spongepowered.asm.launch.MixinBootstrap;
2627

28+
import net.minecraft.launchwrapper.Launch;
29+
30+
import java.io.IOException;
2731
import java.util.Optional;
2832

2933
@StableAPI(since = "0.10.2")
@@ -59,6 +63,11 @@ public static boolean isMixinBooterLegacy() {
5963
return mixinBootstrapper == MixinBootstrapperType.MixinBooterLegacy;
6064
}
6165

66+
@StableAPI.Expose(since = "0.10.14")
67+
public static boolean isGasStation() {
68+
return mixinBootstrapper == MixinBootstrapperType.GasStation;
69+
}
70+
6271
@StableAPI.Expose
6372
public static MixinBootstrapperType bootstrapperType() {
6473
return mixinBootstrapper;
@@ -73,38 +82,29 @@ private static String getVerUnsafe() {
7382
return MixinBootstrap.VERSION;
7483
}
7584

76-
private static MixinBootstrapperType detect() {
85+
public static boolean isClassPresentSafe(String clazz) {
7786
try {
78-
Class.forName("org.spongepowered.asm.launch.MixinBootstrap");
79-
} catch (ClassNotFoundException ignored) {
80-
return MixinBootstrapperType.None;
87+
val bytes = Launch.classLoader.getClassBytes(clazz);
88+
if (bytes == null || bytes.length == 0) {
89+
return false;
90+
}
91+
} catch (IOException e) {
92+
return false;
8193
}
82-
try {
83-
Class.forName("com.falsepattern.gasstation.core.GasStationCore");
94+
return true;
95+
}
96+
97+
private static MixinBootstrapperType detect() {
98+
if (!isClassPresentSafe("org.spongepowered.asm.launch.MixinBootstrap"))
99+
return MixinBootstrapperType.None;
100+
if (isClassPresentSafe("com.falsepattern.gasstation.GasStation"))
84101
return MixinBootstrapperType.GasStation;
85-
} catch (ClassNotFoundException ignored) {
86-
}
87-
try {
88-
Class.forName("ru.timeconqueror.spongemixins.core.SpongeMixinsCore");
102+
if (isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore"))
89103
return MixinBootstrapperType.SpongeMixins;
90-
} catch (ClassNotFoundException ignored) {
91-
}
92-
try {
93-
Class.forName("io.github.crucible.grimoire.Grimoire");
94-
return MixinBootstrapperType.Grimoire;
95-
} catch (ClassNotFoundException ignored) {
96-
}
97-
try {
98-
Class.forName("io.github.crucible.grimoire.common.GrimoireCore");
104+
if (isClassPresentSafe("io.github.crucible.grimoire.Grimoire") || isClassPresentSafe("io.github.crucible.grimoire.common.GrimoireCore"))
99105
return MixinBootstrapperType.Grimoire;
100-
} catch (ClassNotFoundException ignored) {
101-
}
102-
try {
103-
Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin");
106+
if (isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin"))
104107
return MixinBootstrapperType.MixinBooterLegacy;
105-
} catch (ClassNotFoundException ignored) {
106-
}
107-
108108
return MixinBootstrapperType.Other;
109109
}
110110

0 commit comments

Comments
 (0)