-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMixinInfo.java
More file actions
146 lines (127 loc) · 4.51 KB
/
MixinInfo.java
File metadata and controls
146 lines (127 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib 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, only version 3 of the License.
*
* FalsePatternLib 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.mixin;
import lombok.val;
import org.jetbrains.annotations.ApiStatus;
import org.spongepowered.asm.launch.MixinBootstrap;
import net.minecraft.launchwrapper.Launch;
import java.io.IOException;
import java.util.Optional;
/**
* @since 0.10.2
*/
public final class MixinInfo {
public static final MixinBootstrapperType mixinBootstrapper;
static {
MixinInfoCompatCompanion.mixinInfoClassLoaded = true;
mixinBootstrapper = detect();
}
public static boolean isMixinsInstalled() {
return mixinBootstrapper != MixinBootstrapperType.None;
}
public static boolean isOfficialSpongeMixins() {
return (mixinBootstrapper == MixinBootstrapperType.SpongeMixins) && getVerUnsafe().equals("0.7.11");
}
/**
* The nh fork of spongemixins breaks some stuff since 1.5.0.
*/
public static boolean isTamperedSpongeMixins() {
return (mixinBootstrapper == MixinBootstrapperType.SpongeMixins) && getVerUnsafe().equals("0.7.12");
}
public static boolean isGrimoire() {
return mixinBootstrapper == MixinBootstrapperType.Grimoire;
}
public static boolean isMixinBooterLegacy() {
return mixinBootstrapper == MixinBootstrapperType.MixinBooterLegacy;
}
/**
* @since 0.10.14
*/
public static boolean isGasStation() {
return mixinBootstrapper == MixinBootstrapperType.GasStation;
}
/**
* @since 0.10.15
*/
public static boolean isUniMixin() {
return mixinBootstrapper == MixinBootstrapperType.UniMixin;
}
public static MixinBootstrapperType bootstrapperType() {
return mixinBootstrapper;
}
public static Optional<String> mixinVersion() {
return mixinBootstrapper != MixinBootstrapperType.None ? Optional.of(getVerUnsafe()) : Optional.empty();
}
private static String getVerUnsafe() {
return MixinBootstrap.VERSION;
}
@ApiStatus.Internal
public static boolean isClassPresentSafe(String clazz) {
try {
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;
}
for (val candidate : MixinInfoCompatCompanion.UNIMIXIN_CANDIDATES) {
if (isClassPresentSafe(candidate)) {
return MixinBootstrapperType.UniMixin;
}
}
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;
}
/**
* @since 0.10.2
*/
public enum MixinBootstrapperType {
None,
/** @since 0.10.9 */
GasStation,
SpongeMixins,
Grimoire,
MixinBooterLegacy,
Other,
/** @since 0.10.15 */
UniMixin
}
}