Skip to content
This repository was archived by the owner on Jun 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 8 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

21 changes: 7 additions & 14 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 @@ -18,7 +18,7 @@ pipeline {
sh 'rm -rf ./Paper/Paper-API ./Paper/Paper-Server'

// sh 'mv ./Paper/work/Minecraft ./ || true'
sh 'rm -fr ./Paper/work/*'
// sh 'rm -fr ./Paper/work/*'
// sh 'mv ./Minecraft ./Paper/work/ || true'


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 @@ -70,20 +70,13 @@ pipeline {
) {
withCredentials([usernamePassword(credentialsId: 'jenkins-deploy', usernameVariable: 'ORG_GRADLE_PROJECT_mavenUsername', passwordVariable: 'ORG_GRADLE_PROJECT_mavenPassword')]) {
sh '''
./gradlew build publish
./gradlew build publish yatoclip
mkdir -p "./target"
basedir=$(pwd)
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"
vanillaJarPath="$paperworkdir/Minecraft/$mcver/$mcver.jar"

cd "$paperworkdir/Paperclip"
mvn -T 2C clean package -Dmcver="$mcver" -Dpaperjar="$patchedJarPath" -Dvanillajar="$vanillaJarPath" -Dstyle.color=never
cd "$basedir"

cp -v "$paperworkdir/Paperclip/assembly/target/paperclip-$mcver.jar" "./target/yatopia-$mcver-paperclip-b$BUILD_NUMBER.jar"
cp -v "./yatopia-$mcver-yatoclip.jar" "./target/yatopia-$mcver-yatoclip-b$BUILD_NUMBER.jar"
'''
}
}
Expand Down
6 changes: 6 additions & 0 deletions PATCHES.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ This is an overview over all patches that are currently used.
| server | Breedable parrots | BillyGalbreath | |
| api | Bring back server name | William Blake Galbreath | |
| server | Bring back server name | William Blake Galbreath | |
| server | C2ME Port | ishland | Simon Gardling |
| server | Cache climbing check for activation | Paul Sauve | |
| server | Cache coordinate key for micro opt | Paul Sauve | |
| server | Cache entityhuman display name | Paul Sauve | |
Expand Down Expand Up @@ -234,6 +235,7 @@ This is an overview over all patches that are currently used.
| server | Fix the dead lagging the server | William Blake Galbreath | |
| server | Fix vanilla command permission handler | William Blake Galbreath | |
| server | Flying squids! Oh my! | William Blake Galbreath | |
| server | Force world save | ishland | |
| api | Full netherite armor grants fire resistance | BillyGalbreath | |
| server | Full netherite armor grants fire resistance | BillyGalbreath | |
| server | Gamemode extra permissions | BillyGalbreath | |
Expand Down Expand Up @@ -302,6 +304,7 @@ This is an overview over all patches that are currently used.
| server | Movement options for armor stands | Mariell Hoversholm | |
| server | Multi-Threaded Server Ticking Vanilla | Spottedleaf | |
| server | Multi-Threaded ticking CraftBukkit | Spottedleaf | |
| server | Multi-threaded World Upgrade | ishland | |
| server | Name craft scheduler threads according to the plugin using | Spottedleaf | |
| server | New nbt cache | Hugo Planque | ishland |
| server | Nuke streams off BlockPosition | Ivan Pekov | |
Expand Down Expand Up @@ -453,10 +456,13 @@ This is an overview over all patches that are currently used.
| server | Zombie horse naturally spawn | William Blake Galbreath | |
| server | add config for logging login location | Simon Gardling | |
| server | dont load chunks for physics | Aikar | |
| api | java 11 | Simon Gardling | |
| server | java 11 | Simon Gardling | |
| server | lithium DataTrackerMixin | JellySquid | tr7zw |
| server | lithium HashedList | JellySquid | |
| server | lithium MixinBox | JellySquid | |
| server | lithium MixinDirection | JellySquid | |
| server | lithium MultiNoiseBiomeSourceMixin | ishland | |
| server | lithium NoiseChunkGeneratorMixin | JellySquid | |
| server | lithium PerlinNoiseSamplerMixin | JellySquid | Bud Gidiere |
| server | lithium VoronoiBiomeAccessTypeMixin | JellySquid | |
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