Skip to content

Commit c42a1c5

Browse files
committed
Check early logger state before starting the game!
1 parent 8c879fb commit c42a1c5

5 files changed

Lines changed: 34 additions & 5 deletions

File tree

launcher/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ compileJava {
124124
ClassNode classNode = new ClassNode()
125125
ClassReader classReader = new ClassReader(hypertaleJavaPlugin.bytes)
126126
classReader.accept(classNode, 0)
127+
if (classNode.permittedSubclasses != null) {
128+
classNode.permittedSubclasses.clear()
129+
}
127130
classNode.visitPermittedSubclass("com/hypixel/hytale/server/core/plugin/JavaPlugin")
128131
classNode.visitPermittedSubclass("com/hypixel/hytale/plugin/early/ClassTransformer")
129132
ClassWriter classWriter = new ClassWriter(0)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static void loadDependency(Dependency dependency) {
127127
}
128128
} else {
129129
if (!justDownloaded) {
130-
// Assume file is corrupted if load failed.
130+
// Assume the file is corrupted if the load failed.
131131
if (file.exists() && !file.delete()) file.deleteOnExit();
132132
loadDependency(dependency);
133133
return;

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void main(String[] args) throws IOException, InterruptedException {
126126
EarlyLogger.log("Pre-patching the game with " + mainClass);
127127
method.invoke(null, (Object) new String[]{input.getAbsolutePath(),
128128
HypertalePaths.hypertalePrePatched.getAbsolutePath()});
129-
if (HypertalePaths.hypertalePrePatched.isFile()) {
129+
if (MainPlus.checkHytaleJarFile(HypertalePaths.hypertalePrePatched)) {
130130
input = HypertalePaths.hypertalePrePatched;
131131
}
132132
} catch (Exception e) {
@@ -177,11 +177,11 @@ static void main(String[] args) throws IOException, InterruptedException {
177177
EarlyLogger.start(false);
178178
EarlyLogger.log("Version " + BuildConfig.HYPERTALE_VERSION);
179179
File hytaleJar = HypertalePaths.getHytaleJar();
180-
if (!hytaleJar.exists()) {
180+
if (!hytaleJar.isFile()) {
181181
EarlyLogger.log("Cannot find original HytaleServer.jar");
182+
EarlyLogger.stop();
182183
return;
183184
}
184-
// TODO: Detect singleplayer mode
185185
HypertaleConfig.load();
186186
HypertaleData cachedData = null;
187187
if (HypertalePaths.hypertaleCacheJar.exists() &&
@@ -242,14 +242,21 @@ private static void launchGame(String[] args, boolean dev) throws IOException {
242242
}
243243
}
244244
}
245-
if (HypertalePaths.hypertaleCacheJar.exists()) {
245+
if (HypertalePaths.hypertaleCacheJar.isFile()) {
246+
if (!MainPlus.checkHytaleJarFile(HypertalePaths.hypertaleCacheJar)) {
247+
EarlyLogger.log("Patched jar is invalid, or corrupted!");
248+
return;
249+
}
246250
DependencyHelper.addFileToClasspath(HypertalePaths.hypertaleCacheJar);
247251
} else if (!dev) {
248252
throw new FileNotFoundException("Failed to get ./.hypertale/HytaleServer.jar");
249253
}
250254
for (DependencyHelper.Dependency dependency : DependencyHelper.patcherDependencies) {
251255
DependencyHelper.loadDependency(dependency);
252256
}
257+
if (MainPlus.checkHaltLaunchGame(args)) {
258+
return;
259+
}
253260
MixinLoader.preInitializeMixin();
254261
PatchHelper.install();
255262
if (modGatherer.getModSyncBootstrap() != null &&

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
*/
2424
package com.fox2code.hypertale.launcher;
2525

26+
import com.fox2code.hypertale.loader.HypertaleConfig;
27+
28+
import java.io.File;
2629
import java.io.IOException;
2730
import java.lang.instrument.Instrumentation;
2831

@@ -48,4 +51,15 @@ static void patchAsClassPath() throws IOException {
4851
static void launchPatchedAsClassPath(String[] args) throws IOException {
4952
throw new IOException("Only premium versions of Hypertale can use this feature!");
5053
}
54+
55+
static boolean checkHytaleJarFile(File file) {
56+
if (HypertaleConfig.checkJarValidity()) {
57+
throw new RuntimeException("Only premium versions of Hypertale can use this feature!");
58+
}
59+
return file.isFile();
60+
}
61+
62+
static boolean checkHaltLaunchGame(String[] args) {
63+
return false;
64+
}
5165
}

patcher/src/main/java/com/fox2code/hypertale/loader/HypertaleConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public final class HypertaleConfig {
4343
public static boolean optimizePluginOnlyAPIs = true;
4444
public static boolean aggressivelyOptimizePluginOnlyAPIs = false;
4545
public static boolean premiumHyperOptimizeClassPath = false;
46+
public static boolean premiumCheckJarValidity = true;
4647
public static int watchdogWarnLagAfter = 10;
4748
public static int watchdogExitAfter = 30;
4849

@@ -164,4 +165,8 @@ private static void fixupConfiguration() {
164165
public static boolean hyperOptimizeClassPath() {
165166
return HypertaleConfig.premiumHyperOptimizeClassPath && !PREMIUM;
166167
}
168+
169+
public static boolean checkJarValidity() {
170+
return HypertaleConfig.premiumCheckJarValidity && PREMIUM;
171+
}
167172
}

0 commit comments

Comments
 (0)