Skip to content

Commit 924d24b

Browse files
committed
Final polish before initial release!
1 parent c42a1c5 commit 924d24b

5 files changed

Lines changed: 54 additions & 14 deletions

File tree

dev/src/main/groovy/com/fox2code/hypertale/dev/HypertaleGradlePlugin.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class HypertaleGradlePlugin implements Plugin<Project> {
9898
group = "Hypertale"
9999
description = "Run Hypertale with your mod loaded"
100100
dependsOn(project.tasks.assemble)
101+
// We must cap Hytale server RAM usage so it does not crash Linux machines!
102+
jvmArgs("-Xmx6G")
101103
}
102104
project.tasks.register("generateBuildConfig").configure {
103105
group = "Hypertale"

init/src/main/java/com/fox2code/hypertale/init/late/HookClassLoader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class HookClassLoader extends URLClassLoader {
3535
private final Package hytaleExamplePackage;
3636
private final Object packageMakeLock = new Object();
3737
private BiFunction<String, byte[], byte[]> classTransformer;
38-
private Class<?> firstHytaleClass = null;
38+
private volatile Class<?> firstHytaleClass = null;
3939

4040
public HookClassLoader(URL[] urls, Package hytaleExamplePackage) {
4141
super(urls, ClassLoader.getSystemClassLoader().getParent());
@@ -108,4 +108,8 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
108108
public void setClassTransformer(BiFunction<String, byte[], byte[]> classTransformer) {
109109
this.classTransformer = classTransformer;
110110
}
111+
112+
static {
113+
ClassLoader.registerAsParallelCapable();
114+
}
111115
}

launcher/src/main/java/com/fox2code/hypertale/launcher/Main.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static void main(String[] args) throws IOException, InterruptedException {
167167
return;
168168
} else if (args.length == 1 && "--patch-class-path".equals(args[0])) {
169169
if (Boolean.getBoolean("hypertale.premium")) {
170-
EarlyLogger.start(false);
170+
EarlyLogger.start(true);
171171
MainPlus.patchAsClassPath();
172172
} else {
173173
System.out.println("This feature is only available on premium builds of Hypertale!");
@@ -231,6 +231,11 @@ private static void launchGame(String[] args, boolean dev) throws IOException {
231231
HypertaleModGatherer modGatherer = dev ?
232232
HypertaleModGatherer.gatherModsDev() :
233233
HypertaleModGatherer.gatherMods(args);
234+
if (modGatherer.isUsingMixins()) {
235+
EarlyLogger.log("Detected Mixin usage! (Mixin system will be enabled)");
236+
} else {
237+
EarlyLogger.log("No Mixin usage detected! (Mixin system will be disabled)");
238+
}
234239
if (args.length == 0) {
235240
if (HypertalePaths.hytaleAssets.exists()) {
236241
args = new String[]{"--assets", "Assets.zip"};
@@ -257,8 +262,10 @@ private static void launchGame(String[] args, boolean dev) throws IOException {
257262
if (MainPlus.checkHaltLaunchGame(args)) {
258263
return;
259264
}
260-
MixinLoader.preInitializeMixin();
261-
PatchHelper.install();
265+
if (modGatherer.isUsingMixins()) {
266+
MixinLoader.preInitializeMixin();
267+
}
268+
PatchHelper.install(modGatherer.isUsingMixins());
262269
if (modGatherer.getModSyncBootstrap() != null &&
263270
// Don't run modSyncBootstrap twice if init already called it!
264271
!Boolean.getBoolean("hypertale.modSyncBootstrapInit")) {
@@ -267,9 +274,13 @@ private static void launchGame(String[] args, boolean dev) throws IOException {
267274
Class.forName(HypertaleCompatibility.classModSyncBootstrap, true, urlClassLoader);
268275
} catch (LinkageError | ClassNotFoundException _) {}
269276
}
270-
MixinLoader.initialize();
277+
if (modGatherer.isUsingMixins()) {
278+
MixinLoader.initialize();
279+
}
271280
HypertaleModLoader.loadHypertaleMods(modGatherer);
272-
MixinLoader.postInitialize();
281+
if (modGatherer.isUsingMixins()) {
282+
MixinLoader.postInitialize();
283+
}
273284
startHytale(args);
274285
}
275286

launcher/src/main/java/com/fox2code/hypertale/launcher/PatchHelper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private PatchHelper() {}
4545
(Consumer<BiFunction<String, byte[], byte[]>>)
4646
System.getProperties().get("hypertale.initCLSetClassTransformer");
4747

48-
static void install() {
48+
static void install(final boolean useMixins) {
4949
if (installed) return;
5050
installed = true;
5151
Instrumentation instrumentation = HypertaleAgent.getInstrumentation();
@@ -55,7 +55,7 @@ static void install() {
5555
@Override
5656
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
5757
ProtectionDomain protectionDomain, byte[] classfileBuffer) {
58-
if (className.startsWith("com/hypixel/hytale/")) {
58+
if (useMixins && className.startsWith("com/hypixel/hytale/")) {
5959
classfileBuffer = MixinLoader.transformClass(className.replace('/', '.'), classfileBuffer);
6060
}
6161
if (loader == null || loader == Optimizer.class.getClassLoader() ||
@@ -74,7 +74,9 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
7474
});
7575
} else if (initCLSetClassTransformer != null) {
7676
EarlyLogger.log("Using late transformer for patching!");
77-
initCLSetClassTransformer.accept(MixinLoader::transformClass);
77+
if (useMixins) {
78+
initCLSetClassTransformer.accept(MixinLoader::transformClass);
79+
}
7880
} else {
7981
throw new IllegalStateException("Unsupported environment!");
8082
}

launcher/src/main/java/com/fox2code/hypertale/loader/HypertaleModGatherer.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@ public final class HypertaleModGatherer {
4444
private final File modSyncBootstrap;
4545
private final int modHash;
4646
private final List<ClassPathModCandidate> classPathManifests;
47+
private final boolean usingMixins;
4748

4849
private HypertaleModGatherer(List<File> hypertaleMods, List<File> mods, List<File> libraries,
49-
File modSyncBootstrap, int modHash, List<ClassPathModCandidate> classPathManifests) {
50+
File modSyncBootstrap, int modHash, List<ClassPathModCandidate> classPathManifests,
51+
boolean usingMixins) {
5052
this.hypertaleMods = hypertaleMods;
5153
this.mods = mods;
5254
this.libraries = libraries;
5355
this.modSyncBootstrap = modSyncBootstrap;
5456
this.modHash = modHash;
5557
this.classPathManifests = classPathManifests;
58+
this.usingMixins = usingMixins;
5659
}
5760

5861
public List<File> getHypertaleMods() {
@@ -79,12 +82,17 @@ public List<ClassPathModCandidate> getClassPathManifests() {
7982
return this.classPathManifests;
8083
}
8184

85+
public boolean isUsingMixins() {
86+
return this.usingMixins;
87+
}
88+
8289
public static HypertaleModGatherer gatherModsDev() {
8390
return gatherMods(EmptyArrays.EMPTY_STRING_ARRAY);
8491
}
8592

8693
public static HypertaleModGatherer gatherMods(String[] args) {
8794
// TODO: Process launch arguments
95+
boolean[] useMixins = new boolean[]{false};
8896
ArrayList<File> mods = new ArrayList<>();
8997
ArrayList<File> hypertaleMods = new ArrayList<>();
9098
ArrayList<File> libraries = new ArrayList<>();
@@ -93,7 +101,7 @@ public static HypertaleModGatherer gatherMods(String[] args) {
93101
modSyncBootstrap = appendEarlyLoaderMods(mods);
94102
}
95103
if (HypertalePaths.hytaleMods.isDirectory()) {
96-
appendMods(hypertaleMods, mods, libraries);
104+
appendMods(hypertaleMods, mods, libraries, useMixins);
97105
}
98106
long[] fileSizes = new long[mods.size()];
99107
for (int i = 0; i < fileSizes.length; i++) {
@@ -103,10 +111,10 @@ public static HypertaleModGatherer gatherMods(String[] args) {
103111
return new HypertaleModGatherer(Collections.unmodifiableList(hypertaleMods),
104112
Collections.unmodifiableList(mods), Collections.unmodifiableList(libraries),
105113
modSyncBootstrap, Arrays.hashCode(fileSizes),
106-
Collections.unmodifiableList(gatherClassPathMods()));
114+
Collections.unmodifiableList(gatherClassPathMods(useMixins)), useMixins[0]);
107115
}
108116

109-
private static List<ClassPathModCandidate> gatherClassPathMods() {
117+
private static List<ClassPathModCandidate> gatherClassPathMods(boolean[] useMixins) {
110118
try {
111119
Enumeration<URL> urlEnumeration = HypertaleModGatherer.class.getClassLoader().getResources("manifest.json");
112120
ArrayList<ClassPathModCandidate> classPathManifests = new ArrayList<>();
@@ -128,6 +136,15 @@ private static List<ClassPathModCandidate> gatherClassPathMods() {
128136
}
129137
}
130138
}
139+
if (!useMixins[0]) {
140+
try (InputStream inputStream = url.openStream()) {
141+
byte[] manifestData = IOUtils.readAllBytes(inputStream);
142+
String modInfo = new String(manifestData, StandardCharsets.UTF_8);
143+
if (modInfo.contains("\"HypertaleMixinConfig\"")) {
144+
useMixins[0] = true;
145+
}
146+
}
147+
}
131148
}
132149
return classPathManifests;
133150
} catch (Exception e) {
@@ -151,7 +168,8 @@ private static File appendEarlyLoaderMods(ArrayList<File> mods) {
151168
return modSyncBootstrap;
152169
}
153170

154-
private static void appendMods(ArrayList<File> hypertaleMods, ArrayList<File> mods, ArrayList<File> libraries) {
171+
private static void appendMods(ArrayList<File> hypertaleMods, ArrayList<File> mods,
172+
ArrayList<File> libraries, boolean[] useMixins) {
155173
for (File file : Objects.requireNonNull(HypertalePaths.hytaleMods.listFiles())) {
156174
if (file.isFile() && file.getName().endsWith(".jar") &&
157175
!file.getName().equals(HypertalePaths.hypertaleJar.getName())) {
@@ -168,6 +186,9 @@ private static void appendMods(ArrayList<File> hypertaleMods, ArrayList<File> mo
168186
} catch (RuntimeException _) {
169187
modInfo = "";
170188
}
189+
if (modInfo.contains("\"HypertaleMixinConfig\"")) {
190+
useMixins[0] = true;
191+
}
171192
if (modInfo.contains("\"Hypertale")) {
172193
hypertaleMods.add(file);
173194
mods.add(file);

0 commit comments

Comments
 (0)