Skip to content

Commit

Permalink
fix protocol info generation
Browse files Browse the repository at this point in the history
  • Loading branch information
derklaro committed Mar 2, 2024
1 parent 1edf41d commit 34a71b8
Show file tree
Hide file tree
Showing 25 changed files with 785 additions and 369 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ atlassian-ide-plugin.xml
# delombok
*/src/main/lombok

# temp test files
# stuff for generation only
*.tmp
client_libs/

# final protocol output
*.md
Expand Down
35 changes: 12 additions & 23 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
plugins {
id("java")
id("application")
id("com.diffplug.spotless") version "6.23.3"
id("com.diffplug.spotless") version "6.25.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
}

Expand All @@ -34,7 +34,7 @@ version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
maven("https://maven.fabricmc.net/")
maven("https://maven.minecraftforge.net/")
}

dependencies {
Expand All @@ -44,38 +44,33 @@ dependencies {
val guava = "33.0.0-jre"
implementation("com.google.guava", "guava", guava)

val slf4j = "2.0.9"
val slf4j = "2.0.12"
implementation("org.slf4j", "slf4j-api", slf4j)

val logback = "1.4.14"
val logback = "1.5.0"
runtimeOnly("ch.qos.logback", "logback-classic", logback)

val jackson = "2.16.0"
val jackson = "2.16.1"
implementation("com.fasterxml.jackson.core", "jackson-databind", jackson)
implementation("com.fasterxml.jackson.datatype", "jackson-datatype-jsr310", jackson)

val enigma = "2.3.3"
implementation("cuchaz", "enigma", enigma)
// for updates check https://maven.minecraftforge.net/net/minecraftforge/ForgeAutoRenamingTool/maven-metadata.xml
val autoRenamingTool = "1.0.6"
implementation("net.minecraftforge", "ForgeAutoRenamingTool", autoRenamingTool)

val argparse4j = "0.9.0"
implementation("net.sourceforge.argparse4j", "argparse4j", argparse4j)

val reflexion = "1.8.0"
implementation("dev.derklaro.reflexion", "reflexion", reflexion)

val fastutil = "8.5.12" // needed internally for minecraft, do not remove
runtimeOnly("it.unimi.dsi", "fastutil", fastutil)

val joml = "1.10.5" // needed internally for minecraft, do not remove
runtimeOnly("org.joml", "joml", joml)

val netty = "4.1.104.Final" // needed internally for minecraft, do not remove
runtimeOnly("io.netty", "netty-buffer", netty)
runtimeOnly("io.netty", "netty-handler", netty)

val lombok = "1.18.30"
compileOnly("org.projectlombok", "lombok", lombok)
annotationProcessor("org.projectlombok", "lombok", lombok)

val asm = "9.6"
implementation("org.ow2.asm", "asm", asm)
implementation("org.ow2.asm", "asm-tree", asm)
}

tasks.withType<JavaCompile>().configureEach {
Expand All @@ -86,12 +81,6 @@ tasks.withType<JavaCompile>().configureEach {
options.isIncremental = true
}

java {
sourceSets["main"].java {
srcDir("src/bridge/java")
}
}

tasks.shadowJar {
archiveFileName.set("protocol-generator.jar")
}
Expand Down
29 changes: 0 additions & 29 deletions src/bridge/java/com/mojang/authlib/GameProfile.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/bridge/java/com/mojang/datafixers/util/Pair.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/bridge/java/com/mojang/serialization/DynamicOps.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/bridge/java/com/mojang/serialization/Keyable.java

This file was deleted.

2 changes: 0 additions & 2 deletions src/bridge/readme.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package dev.derklaro.protocolgenerator;

import dev.derklaro.protocolgenerator.cli.CliArgParser;
import dev.derklaro.protocolgenerator.manifest.McManifestVersion;
import dev.derklaro.protocolgenerator.manifest.McManifestVersionType;
import lombok.NonNull;
import net.sourceforge.argparse4j.impl.Arguments;

Expand All @@ -38,9 +38,9 @@ private GeneratorCLIArguments() {
public static void registerDefaultArguments(@NonNull CliArgParser argParser) {
// argument to set the version type to fetch
argParser.registerArgument("-vt", "--version-type")
.setDefault(McManifestVersion.VersionType.LATEST)
.setDefault(McManifestVersionType.LATEST)
.help("Sets the argument type to download and parse the protocol of")
.type(Arguments.caseInsensitiveEnumType(McManifestVersion.VersionType.class));
.type(Arguments.caseInsensitiveEnumType(McManifestVersionType.class));

// the final output file name
argParser.registerArgument("-of", "--output-file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
import dev.derklaro.protocolgenerator.cli.CliArgParser;
import dev.derklaro.protocolgenerator.gameversion.JarGameVersionParser;
import dev.derklaro.protocolgenerator.http.HttpFileDownloader;
import dev.derklaro.protocolgenerator.manifest.McManifestVersion;
import dev.derklaro.protocolgenerator.library.McLibraryLoader;
import dev.derklaro.protocolgenerator.manifest.McManifestVersionFetcher;
import dev.derklaro.protocolgenerator.manifest.McManifestVersionType;
import dev.derklaro.protocolgenerator.manifest.McVersionDumper;
import dev.derklaro.protocolgenerator.markdown.MarkdownFormatter;
import dev.derklaro.protocolgenerator.markdown.MarkdownGenerator;
Expand All @@ -38,12 +39,15 @@
import dev.derklaro.protocolgenerator.util.FileUtil;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import lombok.NonNull;

public final class GeneratorEntrypoint {

private static final Path LIB_DIR_PATH = Path.of("client_libs");
private static final Path MAPPING_PATH = Path.of("mappings.tmp");
private static final Path CLIENT_JAR_PATH = Path.of("client.tmp");
private static final Path REMAPPED_JAR_PATH = Path.of("client_remapped.tmp");
Expand All @@ -59,10 +63,10 @@ public static void main(@NonNull String[] args) throws IOException {
var clientVersions = versionFetcher.resolveMcVersions();

// search the requested version
McManifestVersion.VersionType versionType = cliNamespace.get("version_type");
McManifestVersionType versionType = cliNamespace.get("version_type");
var latestVersionOfType = clientVersions
.thenApply(versions -> versions.stream()
.filter(version -> versionType == McManifestVersion.VersionType.LATEST || version.type() == versionType)
.filter(version -> versionType == McManifestVersionType.LATEST || version.type() == versionType)
.sorted()
.findFirst())
.thenApply(optional -> {
Expand All @@ -71,26 +75,42 @@ public static void main(@NonNull String[] args) throws IOException {
return optional.orElseThrow(versionNotFoundExceptionSupplier);
});

// fetch the version data of the latest version
var versionTypeDownloads = latestVersionOfType
.thenCompose(versionFetcher::parseVersionData)
.thenApply(data -> data.get("downloads"))
.thenCompose(downloads -> {
// extract the client downloads
var clientUrl = downloads.get("client").get("url").asText();
var clientMappings = downloads.get("client_mappings").get("url").asText();

// download both files
var clientDownload = HttpFileDownloader.downloadFile(clientUrl, CLIENT_JAR_PATH);
var clientMappingsDownload = HttpFileDownloader.downloadFile(clientMappings, MAPPING_PATH);

// combine both futures
return CompletableFuture.allOf(clientDownload, clientMappingsDownload);
});
// deserialize version data
var versionData = latestVersionOfType.thenCompose(versionFetcher::parseVersionData);

// download the client and client mappings of the version
var versionTypeDownloads = versionData.thenCompose(data -> {
var clientDownloadInfo = data.fileDownloads().get("client");
var mappingsDownloadInfo = data.fileDownloads().get("client_mappings");

// no null check here as we just require the downloads to present
// in all other cases we cannot proceed anyway
var clientDownload = HttpFileDownloader.downloadFile(clientDownloadInfo.downloadUrl(), CLIENT_JAR_PATH);
var clientMappingsDownload = HttpFileDownloader.downloadFile(mappingsDownloadInfo.downloadUrl(), MAPPING_PATH);

// combine both futures
return CompletableFuture.allOf(clientDownload, clientMappingsDownload);
});

// download all required client libraries
var libraryLoader = new McLibraryLoader(LIB_DIR_PATH);
var libraryLoading = versionData.thenCompose(data -> {
List<CompletableFuture<Void>> libDownloadFutures = new ArrayList<>();
for (var library : data.libraries()) {
var downloadFuture = libraryLoader.loadLibrary(library);
libDownloadFutures.add(downloadFuture);
}

var futures = libDownloadFutures.toArray(CompletableFuture[]::new);
return CompletableFuture.allOf(futures);
});

// combine the loading of the client and the loading of the required libraries
var downloadFuture = CompletableFuture.allOf(versionTypeDownloads, libraryLoading);

// remap the client jar
var remapper = new JarRemapper(CLIENT_JAR_PATH, MAPPING_PATH);
var remapOutput = versionTypeDownloads.thenApply(CatchingFunction.asJavaUtil(ignored -> {
var remapOutput = downloadFuture.thenApply(CatchingFunction.asJavaUtil(ignored -> {
remapper.remap(REMAPPED_JAR_PATH);
return null;
}, "Unable to remap client"));
Expand All @@ -106,7 +126,7 @@ public static void main(@NonNull String[] args) throws IOException {
// collect the protocol information
var protocolInfos = remapOutput
.thenApply(CatchingFunction.asJavaUtil(ignored -> {
var protocolInfoGenerator = new ProtocolInfoCollector(REMAPPED_JAR_PATH);
var protocolInfoGenerator = new ProtocolInfoCollector(REMAPPED_JAR_PATH, libraryLoader.provideClassLoader());
return protocolInfoGenerator.collectAllPacketInfos();
}, "Unable to resolve packet information"))
.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ private HttpFileDownloader() {
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream())
.thenApply(BodyParser.bodyExtractorIfOk())
.thenApply(CatchingFunction.asJavaUtil(stream -> {
var parent = filePath.getParent();
if (parent != null) {
Files.createDirectories(parent);
}

try (stream) {
Files.copy(stream, filePath, StandardCopyOption.REPLACE_EXISTING);
return null;
Expand Down
Loading

0 comments on commit 34a71b8

Please sign in to comment.