Skip to content
This repository has been archived by the owner on Jun 19, 2021. It is now read-only.

C2ME Port #471

Open
wants to merge 11 commits into
base: staging/1.16.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11', '15', '16' ]
java: [ '11', '15', '16' ]
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -65,8 +65,7 @@ jobs:

- name: Apply Patches
run: |
./gradlew setupUpstream
./gradlew applyPatches
./gradlew setupUpstream applyPatches

- name: Pull Maven Cache
uses: actions/cache@v2
Expand All @@ -77,11 +76,11 @@ jobs:

- name: Build Yatopia
run: |
./gradlew clean build paperclip
./gradlew clean build yatoclip

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: Yatopia-${{ matrix.java }}
path: yatopia-${{ steps.mcver.outputs.mcver }}-paperclip.jar
path: yatopia-${{ steps.mcver.outputs.mcver }}-yatoclip.jar

11 changes: 6 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipeline {
stages {
stage('Cleanup') {
tools {
jdk "OpenJDK 8"
jdk "OpenJDK 11"
}
steps {
scmSkip(deleteBuild: true, skipPattern:'.*\\[CI-SKIP\\].*')
Expand All @@ -29,7 +29,7 @@ pipeline {
}
stage('Init project & submodules') {
tools {
jdk "OpenJDK 8"
jdk "OpenJDK 11"
}
steps {
withMaven(
Expand All @@ -43,7 +43,7 @@ pipeline {
}
stage('Decompile & apply patches') {
tools {
jdk "OpenJDK 8"
jdk "OpenJDK 11"
}
steps {
withMaven(
Expand All @@ -60,7 +60,7 @@ pipeline {
}
stage('Build') {
tools {
jdk "OpenJDK 8"
jdk "OpenJDK 11"
}
steps {
withMaven(
Expand All @@ -76,7 +76,8 @@ pipeline {
paperworkdir="$basedir/Paper/work"
mcver=$(cat "$paperworkdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4)

patchedJarPath="$basedir/Yatopia-Server/build/libs/yatopia-server-$mcver-R0.1-SNAPSHOT.jar"
patchedJarPath=$(find "$basedir/Yatopia-Server/build/libs/" -type f -name "*.jar" | grep -v '\\-sources.jar$')

vanillaJarPath="$paperworkdir/Minecraft/$mcver/$mcver.jar"

cd "$paperworkdir/Paperclip"
Expand Down
1 change: 1 addition & 0 deletions Licensing/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All files in the buildSrc folder are licensed under MIT found [here](../buildSrc
All patches (.patch files) marked with "lithium" are licensed under LGPL3 found [here](https://github.com/CaffeineMC/lithium-fabric/blob/1.16.x/dev/LICENSE.txt).<br>
All patches (.patch files) marked with "hydrogen" are licensed under LGPL3 found [here](https://github.com/CaffeineMC/hydrogen-fabric/blob/1.16.x/LICENSE.txt).<br>
All patches (.patch files) marked with "krypton" are licensed under MIT found [here](https://github.com/astei/krypton/blob/master/LICENSE).<br>
All patches (.patch files) marked with "Cadmium" are licensed under MIT found [here](https://github.com/LucilleTea/cadmium-fabric/blob/1.16.x/dev-my-fork/LICENSE.txt).<br>
All patches (.patch files) marked with "Tic-Tacs" are licensed under LGPLv3 found [here](https://github.com/Gegy/tic-tacs/blob/1.16.4/LICENSE).<br>
All other patches (.patch files) included in this repo are licensed under the MIT license found [here](MIT.md).<br>
See [EMC](https://github.com/starlis/empirecraft/blob/master/README.md), [Akarin](https://github.com/Akarin-project/Akarin/blob/1.16.5/LICENSE.md), [Purpur](https://github.com/pl3xgaming/Purpur/blob/ver/1.16.5/LICENSE), [Airplane](https://github.com/Technove/Airplane/blob/master/PATCHES-LICENSE), [Origami](https://github.com/Minebench/Origami/blob/1.16/PATCHES-LICENSE), and [Tuinity](https://github.com/Spottedleaf/Tuinity/blob/master/PATCHES-LICENSE) for the license of patches automatically pulled during upstream updates.
72 changes: 39 additions & 33 deletions PATCHES.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Yatopia combines the code from many [Paper](https://github.com/PaperMC/Paper) fo
* [Origami](https://github.com/Minebench/Origami)
* [Purpur](https://github.com/pl3xgaming/Purpur)
* [Airplane](https://github.com/Technove/Airplane)
* [Cadmium](https://github.com/LucilleTea/cadmium-fabric)
* [Tic-Tacs](https://github.com/Gegy/tic-tacs)


Expand Down
36 changes: 13 additions & 23 deletions Yatoclip/src/main/java/org/yatopiamc/yatoclip/PatchesMetadata.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
package org.yatopiamc.yatoclip;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class PatchesMetadata {

public final Set<PatchMetadata> patches;
public final Set<Relocation> relocations;
public final Set<String> copyExcludes;
public final Map<String, String> relocationMapping;
public final Map<String, String> relocationInvertedMapping;

public PatchesMetadata(Set<PatchMetadata> patches, Set<Relocation> relocations, Set<String> copyExcludes) {
public PatchesMetadata(Set<PatchMetadata> patches, Set<String> copyExcludes, Map<String, String> relocationMapping, Map<String, String> relocationInvertedMapping) {
Objects.requireNonNull(copyExcludes);
this.copyExcludes = Collections.unmodifiableSet(copyExcludes);
Objects.requireNonNull(relocations);
this.relocations = Collections.unmodifiableSet(relocations);
Objects.requireNonNull(patches);
this.patches = Collections.unmodifiableSet(patches);
Objects.requireNonNull(relocationMapping);
this.relocationMapping = relocationMapping;
Objects.requireNonNull(relocationInvertedMapping);
this.relocationInvertedMapping = relocationInvertedMapping;
}

public static class PatchMetadata {
public final String name;
public final String originalName;
public final String targetName;
public final String originalHash;
public final String targetHash;
public final String patchHash;

public PatchMetadata(String name, String originalHash, String targetHash, String patchHash) {
this.name = name;
public PatchMetadata(String originalName, String targetName, String originalHash, String targetHash, String patchHash) {
this.originalName = originalName;
this.targetName = targetName;
this.originalHash = originalHash;
this.targetHash = targetHash;
this.patchHash = patchHash;
}
}

public static class Relocation implements Serializable {

public final String from;
public final String to;
public final boolean includeSubPackages;

public Relocation(String from, String to, boolean includeSubPackages) {
Objects.requireNonNull(from);
Objects.requireNonNull(to);
this.from = from.replaceAll("\\.", "/");
this.to = to.replaceAll("\\.", "/");
this.includeSubPackages = includeSubPackages;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ private static void applyMappingsAndPatches() throws IOException {
SpecialSourceLauncher.setSpecialSourceJar(buildData.resolve("bin").resolve("SpecialSource-2.jar").toFile());
System.err.println("Applying class mapping...");
SpecialSourceLauncher.runProcess(
"map", "--only", ".", "--only", "net/minecraft", "--auto-lvt", "BASIC", "--auto-member", "SYNTHETIC",
"map", "--only", ".", "--only", "net/minecraft", "--only", "com/mojang/math", "--auto-lvt", "BASIC", "--auto-member", "SYNTHETIC",
"-i", vanillaJar.toAbsolutePath().toString(),
"-m", buildData.resolve("mappings").resolve(buildDataInfo.classMappings).toAbsolutePath().toString(),
"-o", classMappedJar.toAbsolutePath().toString()
);
System.err.println("Applying member mapping...");
SpecialSourceLauncher.runProcess(
"map", "--only", ".", "--only", "net/minecraft", "--auto-member", "LOGGER", "--auto-member", "TOKENS",
"map", "--only", ".", "--only", "net/minecraft", "--only", "com/mojang/math", "--auto-member", "LOGGER", "--auto-member", "TOKENS",
"-i", classMappedJar.toAbsolutePath().toString(),
"-m", buildData.resolve("mappings").resolve(buildDataInfo.memberMappings).toAbsolutePath().toString(),
"-o", memberMappedJar.toAbsolutePath().toString()
Expand Down
65 changes: 22 additions & 43 deletions Yatoclip/src/main/java/org/yatopiamc/yatoclip/YatoclipPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static boolean isJarUpToDate(Path patchedJar) {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
try (ZipFile patchedZip = new ZipFile(patchedJar.toFile())) {
for (PatchesMetadata.PatchMetadata patchMetadata : patchesMetadata.patches) {
ZipEntry zipEntry = patchedZip.getEntry(patchMetadata.name);
ZipEntry zipEntry = patchedZip.getEntry(patchMetadata.targetName);
if (zipEntry == null || !patchMetadata.targetHash.equals(ServerSetup.toHex(digest.digest(IOUtils.toByteArray(patchedZip.getInputStream(zipEntry))))))
return false;
}
Expand All @@ -72,10 +72,10 @@ static boolean isJarUpToDate(Path patchedJar) {
static void patchJar(Path memberMappedJar, Path patchedJar) {
requireNonNull(memberMappedJar);
requireNonNull(patchedJar);
if(!memberMappedJar.toFile().isFile()) throw new IllegalArgumentException(new FileNotFoundException());
if(!memberMappedJar.toFile().isFile()) throw new IllegalArgumentException(new FileNotFoundException(memberMappedJar.toString()));
try {
patchedJar.toFile().getParentFile().mkdirs();
final ThreadLocal<ZipFile> classMappedZip = ThreadLocal.withInitial(() -> {
final ThreadLocal<ZipFile> memberMappedZip = ThreadLocal.withInitial(() -> {
try {
return new ZipFile(memberMappedJar.toFile());
} catch (IOException e) {
Expand All @@ -99,7 +99,7 @@ public Thread newThread(Runnable r) {
r.run();
} finally {
try {
classMappedZip.get().close();
memberMappedZip.get().close();
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -113,7 +113,7 @@ public Thread newThread(Runnable r) {
try {
final Set<PatchData> patchDataSet = patchesMetadata.patches.stream().map((PatchesMetadata.PatchMetadata metadata) -> new PatchData(CompletableFuture.supplyAsync(() -> {
try {
return getPatchedBytes(classMappedZip.get(), digest.get(), metadata);
return getPatchedBytes(memberMappedZip.get(), digest.get(), metadata);
} catch (IOException | CompressorException | InvalidHeaderException e) {
throw new RuntimeException(e);
}
Expand All @@ -123,19 +123,19 @@ public Thread newThread(Runnable r) {
patchedZip.setLevel(Deflater.BEST_SPEED);
Set<String> processed = new HashSet<>();
for (PatchData patchData : patchDataSet) {
putNextEntrySafe(patchedZip, patchData.metadata.name);
putNextEntrySafe(patchedZip, patchData.metadata.targetName);
final byte[] patchedBytes = patchData.patchedBytesFuture.join();
patchedZip.write(patchedBytes);
patchedZip.closeEntry();
processed.add(patchData.metadata.name);
processed.add(patchData.metadata.targetName);
}

((Iterator<ZipEntry>) classMappedZip.get().entries()).forEachRemaining(zipEntry -> {
if (zipEntry.isDirectory() || processed.contains(applyRelocations(zipEntry.getName())) || patchesMetadata.copyExcludes.contains(zipEntry.getName()))
((Iterator<ZipEntry>) memberMappedZip.get().entries()).forEachRemaining(zipEntry -> {
if (zipEntry.isDirectory() || processed.contains(patchesMetadata.relocationMapping.getOrDefault(zipEntry.getName(), zipEntry.getName())) || patchesMetadata.copyExcludes.contains(zipEntry.getName()))
return;
try {
InputStream in = classMappedZip.get().getInputStream(zipEntry);
putNextEntrySafe(patchedZip, zipEntry.getName());
InputStream in = memberMappedZip.get().getInputStream(zipEntry);
putNextEntrySafe(patchedZip, patchesMetadata.relocationMapping.getOrDefault(zipEntry.getName(), zipEntry.getName()));
patchedZip.write(IOUtils.toByteArray(in));
patchedZip.closeEntry();
} catch (Throwable t) {
Expand All @@ -152,28 +152,31 @@ public Thread newThread(Runnable r) {
}
}

private static byte[] getPatchedBytes(ZipFile classMappedZip, MessageDigest digest, PatchesMetadata.PatchMetadata patchMetadata) throws IOException, CompressorException, InvalidHeaderException {
private static byte[] getPatchedBytes(ZipFile memberMappedZip, MessageDigest digest, PatchesMetadata.PatchMetadata patchMetadata) throws IOException, CompressorException, InvalidHeaderException {
final byte[] originalBytes;
final ZipEntry originalEntry = classMappedZip.getEntry(applyRelocationsReverse(patchMetadata.name));
final ZipEntry originalEntry = memberMappedZip.getEntry(patchMetadata.originalName);
if (originalEntry != null)
try (final InputStream in = classMappedZip.getInputStream(originalEntry)) {
try (final InputStream in = memberMappedZip.getInputStream(originalEntry)) {
originalBytes = IOUtils.toByteArray(in);
}
else originalBytes = new byte[0];
final byte[] patchBytes;
try (final InputStream in = YatoclipPatcher.class.getClassLoader().getResourceAsStream("patches/" + patchMetadata.name + ".patch")) {
try (final InputStream in = YatoclipPatcher.class.getClassLoader().getResourceAsStream("patches/" + patchMetadata.targetName + ".patch")) {
if (in == null)
throw new FileNotFoundException();
throw new FileNotFoundException("patches/" + patchMetadata.targetName + ".patch");
patchBytes = IOUtils.toByteArray(in);
}
if (!patchMetadata.originalHash.equals(ServerSetup.toHex(digest.digest(originalBytes))) || !patchMetadata.patchHash.equals(ServerSetup.toHex(digest.digest(patchBytes))))
throw new FileNotFoundException("Hash do not match");
if (!patchMetadata.originalHash.equals(ServerSetup.toHex(digest.digest(originalBytes))))
throw new FileNotFoundException(String.format("Hash do not match: original file: %s: expected %s but got %s", patchMetadata.originalName, patchMetadata.originalHash, ServerSetup.toHex(digest.digest(originalBytes))));

if (!patchMetadata.patchHash.equals(ServerSetup.toHex(digest.digest(patchBytes))))
throw new FileNotFoundException(String.format("Hash do not match: patch file: %s: expected %s but got %s", patchMetadata.targetName + ".patch", patchMetadata.patchHash, ServerSetup.toHex(digest.digest(patchBytes))));

ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
Patch.patch(originalBytes, patchBytes, byteOut);
final byte[] patchedBytes = byteOut.toByteArray();
if (!patchMetadata.targetHash.equals(ServerSetup.toHex(digest.digest(patchedBytes))))
throw new FileNotFoundException("Hash do not match");
throw new FileNotFoundException(String.format("Hash do not match: target file: %s: expected %s but got %s", patchMetadata.targetName, patchMetadata.targetHash, ServerSetup.toHex(digest.digest(patchedBytes))));
return patchedBytes;
}

Expand All @@ -195,30 +198,6 @@ private static void putNextEntrySafe(ZipOutputStream patchedZip, String name) th
patchedZip.putNextEntry(entry);
}

private static String applyRelocations(String name) {
if (!name.endsWith(".class")) return name;
if (name.indexOf('/') == -1)
name = "/" + name;
for (PatchesMetadata.Relocation relocation : patchesMetadata.relocations) {
if (name.startsWith(relocation.from) && (relocation.includeSubPackages || name.split("/").length == name.split("/").length - 1)) {
return relocation.to + name.substring(relocation.from.length());
}
}
return name;
}

private static String applyRelocationsReverse(String name) {
if (!name.endsWith(".class")) return name;
if (name.indexOf('/') == -1)
name = "/" + name;
for (PatchesMetadata.Relocation relocation : patchesMetadata.relocations) {
if (name.startsWith(relocation.to) && (relocation.includeSubPackages || name.split("/").length == name.split("/").length - 1)) {
return relocation.from + name.substring(relocation.to.length());
}
}
return name;
}

private static class PatchData {

public final CompletableFuture<byte[]> patchedBytesFuture;
Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ subprojects {
}

java {
if(JavaVersion.VERSION_1_8 > JavaVersion.current()){
error("This build must be run with Java 8 or better")
if(JavaVersion.VERSION_11 > JavaVersion.current()){
error("This build must be run with Java 11 or later")
}
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.current()
withSourcesJar()
}
Expand Down
Loading