Skip to content

Commit

Permalink
Update 1.2.19
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Oct 3, 2023
1 parent ecc55c8 commit 83e16fa
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 20 deletions.
2 changes: 2 additions & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group 'com.fox2code'
version project['foxloader.version']
53 changes: 53 additions & 0 deletions api/src/main/java/net/minecraft/server/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.minecraft.server.command;

// https://git.derekunavailable.direct/Dereku/ReIndevPatches
public abstract class Command {

private final String commandLabel;
private final String[] aliases;
private IssuerRole canUseThisCommand = IssuerRole.BOTH;

public Command(final String name) {
this.commandLabel = name;
this.aliases = new String[0];
}

public Command(final String name, final String[] aliases) {
this.commandLabel = name;
this.aliases = aliases;
}

public abstract void execute(String commandLabel, String[] args, CommandSender commandSender);

public String getCommandLabel() {
return commandLabel;
}

public String[] getAliases() {
return aliases;
}

public boolean onlyForOperators() {
return true;
}

public boolean hideCommandArgs() {
return false;
}

public IssuerRole getRoleToUseThisCommand() {
return canUseThisCommand;
}

protected final void setIssuerRole(IssuerRole role) {
this.canUseThisCommand = role;
}

protected final int parseInt(String input, int value) {
if (input.matches("-?[0-9]*")) {
return Integer.parseInt(input);
} else {
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.minecraft.server.command;

import net.minecraft.server.plugin.JavaPlugin;

public class CommandRegistry {
private static final CommandRegistry INSTANCE = new CommandRegistry();

private CommandRegistry() {}

public static CommandRegistry getInstance() {
return INSTANCE;
}

public boolean registerCommand(JavaPlugin owner, Command command, boolean override) {
return true;
}
}
13 changes: 13 additions & 0 deletions api/src/main/java/net/minecraft/server/command/CommandSender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.minecraft.server.command;


// https://git.derekunavailable.direct/Dereku/ReIndevPatches
public class CommandSender {
public boolean isPlayer() {
return false;
}

public void sendMessage(String message) {}

/* public EntityPlayerMP getPlayer(); */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.minecraft.server.command;

// https://git.derekunavailable.direct/Dereku/ReIndevPatches
public enum IssuerRole {
CONSOLE, PLAYER, BOTH
}
16 changes: 16 additions & 0 deletions api/src/main/java/net/minecraft/server/plugin/JavaPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.minecraft.server.plugin;

import net.minecraft.server.command.Command;
import net.minecraft.server.command.CommandRegistry;

// https://git.derekunavailable.direct/Dereku/ReIndevPatches
public class JavaPlugin {
@Deprecated
public String getName() {
throw new UnsupportedOperationException();
}

public boolean registerCommand(Command command, boolean override) {
return CommandRegistry.getInstance().registerCommand(this, command, override);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.logging.Logger;

public class FoxLauncher {
static {
Expand Down Expand Up @@ -36,6 +37,7 @@ public class FoxLauncher {
static File gameDir;
public static String initialUsername;
public static String initialSessionId;
private static boolean hasLogger = false;

public static void markWronglyInstalled() {
if (foxClassLoader == null) wronglyInstalled = true;
Expand Down Expand Up @@ -95,7 +97,7 @@ static void initForClientFromArgs(String[] args) {
foxClassLoader.addTransformerExclusion("org.spongepowered.tools.");
foxClassLoader.addTransformerExclusion("com.llamalad7.mixinextras.");
foxClassLoader.addTransformerExclusion("com.fox2code.foxloader.loader.");
installLoggerHelper(); // Install special logger before libraries loading
installLoggerHelper(true); // Install special logger before libraries loading
DependencyHelper.loadDependencies(true);
}

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

private static void installLoggerHelper() {
private static void installLoggerHelper(boolean client) {
if (hasLogger) return;
boolean installed = false;
try {
File logFile = new File(gameDir, (LoggerHelper.devEnvironment ?
Expand All @@ -134,6 +137,11 @@ private static void installLoggerHelper() {
if (!installed) {
System.out.println("Failed to install log helper!");
}
hasLogger = installed;
}

public static void installLoggerHelperOn(Logger logger) {
if (hasLogger) LoggerHelper.installOn(logger);
}

public static void setEarlyMinecraftURL(URL url) {
Expand All @@ -145,9 +153,9 @@ public static void setEarlyMinecraftURL(URL url) {
}

private static boolean isDirGradle(File file) {
return new File(gameDir, "gradle").exists() && (
new File(gameDir, "build.gradle.kts").exists() ||
new File(gameDir, "build.gradle").exists());
return new File(file, "gradle").exists() && (
new File(file, "build.gradle.kts").exists() ||
new File(file, "build.gradle").exists());
}

static void runClientWithArgs(String[] args) throws ReflectiveOperationException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fox2code.foxloader.launcher;

import com.fox2code.foxloader.launcher.utils.Platform;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

static boolean install(File logFile) {
if (disableLoggerHelper) {
Expand All @@ -37,7 +42,6 @@ static boolean install(File logFile) {
}
boolean installed = false;
final SystemOutConsoleHandler systemOutConsoleHandler = new SystemOutConsoleHandler();
final FoxLoaderLogFormatter simpleFormatter = new FoxLoaderLogFormatter();
final Logger rootLogger = LogManager.getLogManager().getLogger("");
final DirectFileHandler directFileHandler;
try {
Expand All @@ -46,6 +50,8 @@ static boolean install(File logFile) {
} catch (Exception ignored) {
return false;
}
LoggerHelper.systemOutConsoleHandler = systemOutConsoleHandler;
LoggerHelper.directFileHandler = directFileHandler;
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
directFileHandler.flush();
systemOutConsoleHandler.flush();
Expand All @@ -57,7 +63,7 @@ static boolean install(File logFile) {
rootLogger.removeHandler(handler);
rootLogger.addHandler(systemOutConsoleHandler);
} else {
handler.setFormatter(simpleFormatter);
handler.setFormatter(LoggerHelper.simpleFormatter);
}
}
if (installed) {
Expand All @@ -69,6 +75,24 @@ static boolean install(File logFile) {
return installed;
}

static void installOn(Logger logger) {
Handler[] handlers = logger.getHandlers();
boolean hasDirectFileHandler = false;
for (Handler handler : handlers) {
if (handler instanceof ConsoleHandler) {
if (handler != systemOutConsoleHandler) {
logger.removeHandler(handler);
logger.addHandler(systemOutConsoleHandler);
}
} else if (handler == directFileHandler) {
hasDirectFileHandler = true;
}
}
if (!logger.getUseParentHandlers() && !hasDirectFileHandler) {
logger.addHandler(directFileHandler);
}
}

@SuppressWarnings({"UnnecessaryCallToStringValueOf", "StringOperationCanBeSimplified"})
private static final class FoxLoaderLogPrintStream extends PrintStream {
private final Logger rootLogger;
Expand Down Expand Up @@ -175,6 +199,12 @@ private static class DirectFileHandler extends StreamHandler {
setOutputStream(Files.newOutputStream(file.toPath()));
setLevel(Level.ALL);
}

@Override
public synchronized void publish(LogRecord record) {
super.publish(record);
flush();
}
}

private static class SystemOutConsoleHandler extends ConsoleHandler {
Expand Down
16 changes: 11 additions & 5 deletions common/src/main/java/com/fox2code/foxloader/loader/PreLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,25 @@ static void initializePrePatch(boolean client) {
prePatchInitialized = true;
preLoadMetaJarHash.freeze();
final String currentHash = preLoadMetaJarHash.getHash();
String previousHash = "";
String previousHashAndSize = "";
File configFolder = ModLoader.foxLoader.configFolder;
if (!configFolder.exists() && !configFolder.mkdirs()) {
ModLoader.foxLoader.logger.severe("Can't create FoxLoader config folder!");
return;
}
File jar = new File(configFolder, client ? "PatchedMinecraftClient.jar" : "PatchedMinecraftServer.jar");
File hash = new File(configFolder, client ? "PatchedMinecraftClient.hash" : "PatchedMinecraftServer.hash");
String jarSize = "";
if (jar.exists() && hash.exists()) {
try {
previousHash = new String(Files.readAllBytes(
previousHashAndSize = new String(Files.readAllBytes(
hash.toPath()), StandardCharsets.UTF_8);
jarSize = String.format("%08X", jar.length());
} catch (Exception ignored) {}
}
String expectedHashAndSize = currentHash + jarSize;
ModLoader.foxLoader.logger.info("PreLoader hash: " + currentHash);
if (currentHash.equals(previousHash) && !ignoreMinecraftCache) {
if (expectedHashAndSize.equals(previousHashAndSize) && !ignoreMinecraftCache) {
ModLoader.foxLoader.logger.info("Existing patched jar exists, using that!");
try {
FoxLauncher.getFoxClassLoader().setPatchedMinecraftURL(jar.toURI().toURL());
Expand All @@ -163,7 +166,8 @@ static void initializePrePatch(boolean client) {
.getMinecraftSource().toURI().getPath());
ModLoader.foxLoader.logger.info("Source jar file: " + sourceJar.getAbsolutePath());
patchJar(sourceJar, jar, false);
Files.write(hash.toPath(), currentHash.getBytes(StandardCharsets.UTF_8));
jarSize = String.format("%08X", jar.length());
Files.write(hash.toPath(), (currentHash + jarSize).getBytes(StandardCharsets.UTF_8));
ModLoader.foxLoader.logger.info("Jar patched successfully, using that!");
FoxLauncher.getFoxClassLoader().setPatchedMinecraftURL(jar.toURI().toURL());
if (!ModLoader.DEV_MODE) ignoreMinecraft = true;
Expand Down Expand Up @@ -193,6 +197,8 @@ static void loadPrePatches(boolean client) {
registerPrePatch(new FrustrumHelperTransformer());
registerPrePatch(new NetworkMappingTransformer());
registerPrePatch(new ClientOnlyInventoryTransformer());
} else {
registerPrePatch(new ConsoleLogManagerTransformer());
}
}

Expand Down Expand Up @@ -382,7 +388,7 @@ public String getHash() {
byte[] hash = makeHash();
StringBuilder builder = new StringBuilder();
for (byte b : hash) {
builder.append(String.format("%02X ", b));
builder.append(String.format("%02X", b));
}
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fox2code.foxloader.loader.transformer;

import org.objectweb.asm.tree.*;

public class ConsoleLogManagerTransformer implements PreClassTransformer {
@Override
public void transform(ClassNode classNode, String className) {
if (!"net.minecraft.src.server.ConsoleLogManager".equals(className)) return;
MethodNode methodNode = TransformerUtils.findMethod(classNode, "init");
if (methodNode == null) return;
for (AbstractInsnNode abstractInsnNode : methodNode.instructions) {
if (abstractInsnNode.getOpcode() == RETURN) {
InsnList insnList = new InsnList();
insnList.add(new FieldInsnNode(GETSTATIC,
"net/minecraft/src/server/ConsoleLogManager",
"logger", "Ljava/util/logging/Logger;"));
insnList.add(new MethodInsnNode(INVOKESTATIC,
"com/fox2code/foxloader/launcher/FoxLauncher",
"installLoggerHelperOn", "(Ljava/util/logging/Logger;)V", false));
methodNode.instructions.insertBefore(abstractInsnNode, insnList);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public CommandCompat(String name, boolean opOnly, boolean isHidden, String[] ali
this.name = name;
this.opOnly = opOnly;
this.isHidden = isHidden;
this.aliases = aliases;
this.aliases = aliases == null ?
NO_ALIASES : aliases;
}

public String getName() {
Expand Down
3 changes: 2 additions & 1 deletion final/src/main/java/net/minecraft/client/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fox2code.foxloader.launcher.ClientMain;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MinecraftApplet;

/**
* Should never be loaded in memory, if it is loaded, it means something wrong happened
Expand All @@ -10,6 +11,6 @@
*/
public class Main {
public static void main(String[] args) throws Exception {
Minecraft.main(args);
new MinecraftApplet(); // We need to remap args for it to work
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.parallel=true
org.gradle.jvmargs=-Xmx1024m -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8

# FoxLoader properties
foxloader.version=1.2.18
foxloader.lastReIndevTransformerChanges=1.2.17
foxloader.version=1.2.19
foxloader.lastReIndevTransformerChanges=1.2.19

# ReIndev properties
reindev.clientUrl=https://cdn.fox2code.com/files/reindev_2.8.1_04.jar
Expand Down
3 changes: 3 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ dependencies {

// Do no expose spark APIs to mods
implementation(project['spark.dependency'] as String)

// External mods APIs
implementation(project(":api"))
}
Loading

0 comments on commit 83e16fa

Please sign in to comment.