Skip to content

Commit 83e16fa

Browse files
committed
Update 1.2.19
1 parent ecc55c8 commit 83e16fa

File tree

17 files changed

+301
-20
lines changed

17 files changed

+301
-20
lines changed

api/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
group 'com.fox2code'
2+
version project['foxloader.version']
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package net.minecraft.server.command;
2+
3+
// https://git.derekunavailable.direct/Dereku/ReIndevPatches
4+
public abstract class Command {
5+
6+
private final String commandLabel;
7+
private final String[] aliases;
8+
private IssuerRole canUseThisCommand = IssuerRole.BOTH;
9+
10+
public Command(final String name) {
11+
this.commandLabel = name;
12+
this.aliases = new String[0];
13+
}
14+
15+
public Command(final String name, final String[] aliases) {
16+
this.commandLabel = name;
17+
this.aliases = aliases;
18+
}
19+
20+
public abstract void execute(String commandLabel, String[] args, CommandSender commandSender);
21+
22+
public String getCommandLabel() {
23+
return commandLabel;
24+
}
25+
26+
public String[] getAliases() {
27+
return aliases;
28+
}
29+
30+
public boolean onlyForOperators() {
31+
return true;
32+
}
33+
34+
public boolean hideCommandArgs() {
35+
return false;
36+
}
37+
38+
public IssuerRole getRoleToUseThisCommand() {
39+
return canUseThisCommand;
40+
}
41+
42+
protected final void setIssuerRole(IssuerRole role) {
43+
this.canUseThisCommand = role;
44+
}
45+
46+
protected final int parseInt(String input, int value) {
47+
if (input.matches("-?[0-9]*")) {
48+
return Integer.parseInt(input);
49+
} else {
50+
return value;
51+
}
52+
}
53+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.minecraft.server.command;
2+
3+
import net.minecraft.server.plugin.JavaPlugin;
4+
5+
public class CommandRegistry {
6+
private static final CommandRegistry INSTANCE = new CommandRegistry();
7+
8+
private CommandRegistry() {}
9+
10+
public static CommandRegistry getInstance() {
11+
return INSTANCE;
12+
}
13+
14+
public boolean registerCommand(JavaPlugin owner, Command command, boolean override) {
15+
return true;
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package net.minecraft.server.command;
2+
3+
4+
// https://git.derekunavailable.direct/Dereku/ReIndevPatches
5+
public class CommandSender {
6+
public boolean isPlayer() {
7+
return false;
8+
}
9+
10+
public void sendMessage(String message) {}
11+
12+
/* public EntityPlayerMP getPlayer(); */
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.minecraft.server.command;
2+
3+
// https://git.derekunavailable.direct/Dereku/ReIndevPatches
4+
public enum IssuerRole {
5+
CONSOLE, PLAYER, BOTH
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.minecraft.server.plugin;
2+
3+
import net.minecraft.server.command.Command;
4+
import net.minecraft.server.command.CommandRegistry;
5+
6+
// https://git.derekunavailable.direct/Dereku/ReIndevPatches
7+
public class JavaPlugin {
8+
@Deprecated
9+
public String getName() {
10+
throw new UnsupportedOperationException();
11+
}
12+
13+
public boolean registerCommand(Command command, boolean override) {
14+
return CommandRegistry.getInstance().registerCommand(this, command, override);
15+
}
16+
}

common/src/main/java/com/fox2code/foxloader/launcher/FoxLauncher.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.net.URL;
88
import java.util.HashMap;
9+
import java.util.logging.Logger;
910

1011
public class FoxLauncher {
1112
static {
@@ -36,6 +37,7 @@ public class FoxLauncher {
3637
static File gameDir;
3738
public static String initialUsername;
3839
public static String initialSessionId;
40+
private static boolean hasLogger = false;
3941

4042
public static void markWronglyInstalled() {
4143
if (foxClassLoader == null) wronglyInstalled = true;
@@ -95,7 +97,7 @@ static void initForClientFromArgs(String[] args) {
9597
foxClassLoader.addTransformerExclusion("org.spongepowered.tools.");
9698
foxClassLoader.addTransformerExclusion("com.llamalad7.mixinextras.");
9799
foxClassLoader.addTransformerExclusion("com.fox2code.foxloader.loader.");
98-
installLoggerHelper(); // Install special logger before libraries loading
100+
installLoggerHelper(true); // Install special logger before libraries loading
99101
DependencyHelper.loadDependencies(true);
100102
}
101103

@@ -120,11 +122,12 @@ static void initForServerFromArgs(String[] args) {
120122
foxClassLoader.addTransformerExclusion("org.spongepowered.tools.");
121123
foxClassLoader.addTransformerExclusion("com.llamalad7.mixinextras.");
122124
foxClassLoader.addTransformerExclusion("com.fox2code.foxloader.loader.");
123-
installLoggerHelper(); // Install special logger before libraries loading
125+
installLoggerHelper(false); // Install special logger before libraries loading
124126
DependencyHelper.loadDependencies(false);
125127
}
126128

127-
private static void installLoggerHelper() {
129+
private static void installLoggerHelper(boolean client) {
130+
if (hasLogger) return;
128131
boolean installed = false;
129132
try {
130133
File logFile = new File(gameDir, (LoggerHelper.devEnvironment ?
@@ -134,6 +137,11 @@ private static void installLoggerHelper() {
134137
if (!installed) {
135138
System.out.println("Failed to install log helper!");
136139
}
140+
hasLogger = installed;
141+
}
142+
143+
public static void installLoggerHelperOn(Logger logger) {
144+
if (hasLogger) LoggerHelper.installOn(logger);
137145
}
138146

139147
public static void setEarlyMinecraftURL(URL url) {
@@ -145,9 +153,9 @@ public static void setEarlyMinecraftURL(URL url) {
145153
}
146154

147155
private static boolean isDirGradle(File file) {
148-
return new File(gameDir, "gradle").exists() && (
149-
new File(gameDir, "build.gradle.kts").exists() ||
150-
new File(gameDir, "build.gradle").exists());
156+
return new File(file, "gradle").exists() && (
157+
new File(file, "build.gradle.kts").exists() ||
158+
new File(file, "build.gradle").exists());
151159
}
152160

153161
static void runClientWithArgs(String[] args) throws ReflectiveOperationException {

common/src/main/java/com/fox2code/foxloader/launcher/LoggerHelper.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fox2code.foxloader.launcher;
22

3+
import com.fox2code.foxloader.launcher.utils.Platform;
34
import org.jetbrains.annotations.NotNull;
45
import org.jetbrains.annotations.Nullable;
56

@@ -16,9 +17,13 @@ final class LoggerHelper {
1617
FoxLauncher.foxLoaderFile.getAbsolutePath().replace('\\', '/').endsWith( // Also check for IDE launch.
1718
"/common/build/libs/common-" + BuildConfig.FOXLOADER_VERSION + ".jar");
1819
private static final boolean consoleSupportColor = devEnvironment ||
19-
Boolean.getBoolean("foxloader.console-support-color");
20+
Boolean.getBoolean("foxloader.console-support-color") ||
21+
(Platform.getPlatform() != Platform.WINDOWS && System.console() != null);
2022
private static final boolean disableLoggerHelper =
2123
Boolean.getBoolean("foxloader.disable-logger-helper");
24+
private static final FoxLoaderLogFormatter simpleFormatter = new FoxLoaderLogFormatter();
25+
private static SystemOutConsoleHandler systemOutConsoleHandler;
26+
private static DirectFileHandler directFileHandler;
2227

2328
static boolean install(File logFile) {
2429
if (disableLoggerHelper) {
@@ -37,7 +42,6 @@ static boolean install(File logFile) {
3742
}
3843
boolean installed = false;
3944
final SystemOutConsoleHandler systemOutConsoleHandler = new SystemOutConsoleHandler();
40-
final FoxLoaderLogFormatter simpleFormatter = new FoxLoaderLogFormatter();
4145
final Logger rootLogger = LogManager.getLogManager().getLogger("");
4246
final DirectFileHandler directFileHandler;
4347
try {
@@ -46,6 +50,8 @@ static boolean install(File logFile) {
4650
} catch (Exception ignored) {
4751
return false;
4852
}
53+
LoggerHelper.systemOutConsoleHandler = systemOutConsoleHandler;
54+
LoggerHelper.directFileHandler = directFileHandler;
4955
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
5056
directFileHandler.flush();
5157
systemOutConsoleHandler.flush();
@@ -57,7 +63,7 @@ static boolean install(File logFile) {
5763
rootLogger.removeHandler(handler);
5864
rootLogger.addHandler(systemOutConsoleHandler);
5965
} else {
60-
handler.setFormatter(simpleFormatter);
66+
handler.setFormatter(LoggerHelper.simpleFormatter);
6167
}
6268
}
6369
if (installed) {
@@ -69,6 +75,24 @@ static boolean install(File logFile) {
6975
return installed;
7076
}
7177

78+
static void installOn(Logger logger) {
79+
Handler[] handlers = logger.getHandlers();
80+
boolean hasDirectFileHandler = false;
81+
for (Handler handler : handlers) {
82+
if (handler instanceof ConsoleHandler) {
83+
if (handler != systemOutConsoleHandler) {
84+
logger.removeHandler(handler);
85+
logger.addHandler(systemOutConsoleHandler);
86+
}
87+
} else if (handler == directFileHandler) {
88+
hasDirectFileHandler = true;
89+
}
90+
}
91+
if (!logger.getUseParentHandlers() && !hasDirectFileHandler) {
92+
logger.addHandler(directFileHandler);
93+
}
94+
}
95+
7296
@SuppressWarnings({"UnnecessaryCallToStringValueOf", "StringOperationCanBeSimplified"})
7397
private static final class FoxLoaderLogPrintStream extends PrintStream {
7498
private final Logger rootLogger;
@@ -175,6 +199,12 @@ private static class DirectFileHandler extends StreamHandler {
175199
setOutputStream(Files.newOutputStream(file.toPath()));
176200
setLevel(Level.ALL);
177201
}
202+
203+
@Override
204+
public synchronized void publish(LogRecord record) {
205+
super.publish(record);
206+
flush();
207+
}
178208
}
179209

180210
private static class SystemOutConsoleHandler extends ConsoleHandler {

common/src/main/java/com/fox2code/foxloader/loader/PreLoader.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,25 @@ static void initializePrePatch(boolean client) {
128128
prePatchInitialized = true;
129129
preLoadMetaJarHash.freeze();
130130
final String currentHash = preLoadMetaJarHash.getHash();
131-
String previousHash = "";
131+
String previousHashAndSize = "";
132132
File configFolder = ModLoader.foxLoader.configFolder;
133133
if (!configFolder.exists() && !configFolder.mkdirs()) {
134134
ModLoader.foxLoader.logger.severe("Can't create FoxLoader config folder!");
135135
return;
136136
}
137137
File jar = new File(configFolder, client ? "PatchedMinecraftClient.jar" : "PatchedMinecraftServer.jar");
138138
File hash = new File(configFolder, client ? "PatchedMinecraftClient.hash" : "PatchedMinecraftServer.hash");
139+
String jarSize = "";
139140
if (jar.exists() && hash.exists()) {
140141
try {
141-
previousHash = new String(Files.readAllBytes(
142+
previousHashAndSize = new String(Files.readAllBytes(
142143
hash.toPath()), StandardCharsets.UTF_8);
144+
jarSize = String.format("%08X", jar.length());
143145
} catch (Exception ignored) {}
144146
}
147+
String expectedHashAndSize = currentHash + jarSize;
145148
ModLoader.foxLoader.logger.info("PreLoader hash: " + currentHash);
146-
if (currentHash.equals(previousHash) && !ignoreMinecraftCache) {
149+
if (expectedHashAndSize.equals(previousHashAndSize) && !ignoreMinecraftCache) {
147150
ModLoader.foxLoader.logger.info("Existing patched jar exists, using that!");
148151
try {
149152
FoxLauncher.getFoxClassLoader().setPatchedMinecraftURL(jar.toURI().toURL());
@@ -163,7 +166,8 @@ static void initializePrePatch(boolean client) {
163166
.getMinecraftSource().toURI().getPath());
164167
ModLoader.foxLoader.logger.info("Source jar file: " + sourceJar.getAbsolutePath());
165168
patchJar(sourceJar, jar, false);
166-
Files.write(hash.toPath(), currentHash.getBytes(StandardCharsets.UTF_8));
169+
jarSize = String.format("%08X", jar.length());
170+
Files.write(hash.toPath(), (currentHash + jarSize).getBytes(StandardCharsets.UTF_8));
167171
ModLoader.foxLoader.logger.info("Jar patched successfully, using that!");
168172
FoxLauncher.getFoxClassLoader().setPatchedMinecraftURL(jar.toURI().toURL());
169173
if (!ModLoader.DEV_MODE) ignoreMinecraft = true;
@@ -193,6 +197,8 @@ static void loadPrePatches(boolean client) {
193197
registerPrePatch(new FrustrumHelperTransformer());
194198
registerPrePatch(new NetworkMappingTransformer());
195199
registerPrePatch(new ClientOnlyInventoryTransformer());
200+
} else {
201+
registerPrePatch(new ConsoleLogManagerTransformer());
196202
}
197203
}
198204

@@ -382,7 +388,7 @@ public String getHash() {
382388
byte[] hash = makeHash();
383389
StringBuilder builder = new StringBuilder();
384390
for (byte b : hash) {
385-
builder.append(String.format("%02X ", b));
391+
builder.append(String.format("%02X", b));
386392
}
387393
return builder.toString();
388394
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fox2code.foxloader.loader.transformer;
2+
3+
import org.objectweb.asm.tree.*;
4+
5+
public class ConsoleLogManagerTransformer implements PreClassTransformer {
6+
@Override
7+
public void transform(ClassNode classNode, String className) {
8+
if (!"net.minecraft.src.server.ConsoleLogManager".equals(className)) return;
9+
MethodNode methodNode = TransformerUtils.findMethod(classNode, "init");
10+
if (methodNode == null) return;
11+
for (AbstractInsnNode abstractInsnNode : methodNode.instructions) {
12+
if (abstractInsnNode.getOpcode() == RETURN) {
13+
InsnList insnList = new InsnList();
14+
insnList.add(new FieldInsnNode(GETSTATIC,
15+
"net/minecraft/src/server/ConsoleLogManager",
16+
"logger", "Ljava/util/logging/Logger;"));
17+
insnList.add(new MethodInsnNode(INVOKESTATIC,
18+
"com/fox2code/foxloader/launcher/FoxLauncher",
19+
"installLoggerHelperOn", "(Ljava/util/logging/Logger;)V", false));
20+
methodNode.instructions.insertBefore(abstractInsnNode, insnList);
21+
}
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)