diff --git a/.gitignore b/.gitignore index 952f896..41c5b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ build/ bin/ dist/ manifest.mf +work/ # Mac filesystem dust .DS_Store/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4fbc64d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "Bukkit"] + path = Bukkit + url = https://hub.spigotmc.org/stash/scm/spigot/bukkit.git +[submodule "CraftBukkit"] + path = CraftBukkit + url = https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git +[submodule "BuildData"] + path = BuildData + url = https://hub.spigotmc.org/stash/scm/spigot/builddata.git diff --git a/BuildData b/BuildData new file mode 160000 index 0000000..838b405 --- /dev/null +++ b/BuildData @@ -0,0 +1 @@ +Subproject commit 838b40587fa7a68a130b75252959bc8a3481d94f diff --git a/Bukkit b/Bukkit new file mode 160000 index 0000000..f10a7a9 --- /dev/null +++ b/Bukkit @@ -0,0 +1 @@ +Subproject commit f10a7a92f33995b08f63633b23de6ec80b50a609 diff --git a/CraftBukkit b/CraftBukkit new file mode 160000 index 0000000..a66b965 --- /dev/null +++ b/CraftBukkit @@ -0,0 +1 @@ +Subproject commit a66b96584771093d7199eff150161b83384b7056 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..d138a58 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +git submodule update --init && ./remap.sh && ./decompile.sh && ./init.sh && ./newApplyPatches.sh && mvn clean install diff --git a/decompile.sh b/decompile.sh new file mode 100755 index 0000000..2489ddf --- /dev/null +++ b/decompile.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +PS1="$" +basedir=`pwd` +workdir=$basedir/work +minecraftversion=$(cat BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +decompiledir=$workdir/$minecraftversion +classdir=$decompiledir/classes + +echo "Extracting NMS classes..." +if [ ! -d "$classdir" ]; then + mkdir -p "$classdir" + cd "$classdir" + jar xf "$decompiledir/$minecraftversion-mapped.jar" net/minecraft/server + if [ "$?" != "0" ]; then + cd "$basedir" + echo "Failed to extract NMS classes." + exit 1 + fi +fi + +echo "Decompiling classes..." +if [ ! -d "$decompiledir/net/minecraft/server" ]; then + cd "$basedir" + java -jar BuildData/bin/fernflower.jar -dgs=1 -hdc=0 -rbr=0 -asc=1 -udv=0 "$classdir" "$decompiledir" + if [ "$?" != "0" ]; then + echo "Failed to decompile classes." + exit 1 + fi +fi diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..ee291e1 --- /dev/null +++ b/init.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +PS1="$" +basedir=`pwd` +workdir=$basedir/work +minecraftversion=$(cat BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +decompiledir=$workdir/$minecraftversion +nms=$decompiledir/net/minecraft/server +cb=src/main/java/net/minecraft/server + +patch=$(which patch 2>/dev/null) +if [ "x$patch" == "x" ]; then + patch=$basedir/hctap.exe +fi + +echo "Applying CraftBukkit patches to NMS..." +cd "$basedir/CraftBukkit" +git checkout -B patched HEAD >/dev/null 2>&1 +rm -rf $cb +mkdir -p $cb +for file in $(ls nms-patches) +do + patchFile="nms-patches/$file" + file="$(echo $file | cut -d. -f1).java" + + echo "Patching $file < $patchFile" + sed -i 's/\r//' "$nms/$file" > /dev/null + + cp "$nms/$file" "$cb/$file" + "$patch" -s -d src/main/java/ "net/minecraft/server/$file" < "$patchFile" +done + +git add src >/dev/null 2>&1 +git commit -m "CraftBukkit $ $(date)" >/dev/null 2>&1 +git checkout -f HEAD^ >/dev/null 2>&1 diff --git a/newApplyPatches.sh b/newApplyPatches.sh new file mode 100755 index 0000000..21a0eb6 --- /dev/null +++ b/newApplyPatches.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +PS1="$" +basedir=`pwd` +echo "Rebuilding Forked projects.... " + +function applyPatch { + what=$1 + target=$2 + branch=$3 + cd "$basedir/$what" + git fetch + git branch -f upstream "$branch" >/dev/null + + cd "$basedir" + if [ ! -d "$basedir/$target" ]; then + git clone "$what" "$target" + fi + cd "$basedir/$target" + echo "Resetting $target to $what..." + git remote add -f upstream ../$what >/dev/null 2>&1 + git checkout master >/dev/null 2>&1 + git fetch upstream >/dev/null 2>&1 + git reset --hard upstream/upstream + echo " Applying patches to $target..." + git am --abort >/dev/null 2>&1 + git am --3way --ignore-whitespace "$basedir/${what}-Patches/"*.patch + if [ "$?" != "0" ]; then + echo " Something did not apply cleanly to $target." + echo " Please review above details and finish the apply then" + echo " save the changes with rebuildPatches.sh" + exit 1 + else + echo " Patches applied cleanly to $target" + fi +} + +applyPatch Bukkit Spigot-API HEAD && applyPatch CraftBukkit Spigot-Server patched +applyPatch Spigot-API PaperSpigot-API HEAD && applyPatch Spigot-Server PaperSpigot-Server HEAD \ No newline at end of file diff --git a/newRebuildPatches.sh b/newRebuildPatches.sh new file mode 100755 index 0000000..f5b7f8b --- /dev/null +++ b/newRebuildPatches.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +PS1="$" +basedir=`pwd` +echo "Rebuilding patch files from current fork state..." +git config core.safecrlf false + +function cleanupPatches { + cd "$1" + for patch in *.patch; do + echo "$patch" + gitver=$(tail -n 2 $patch | grep -ve "^$" | tail -n 1) + diffs=$(git diff --staged $patch | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index)") + + testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver") + if [ "x$testver" != "x" ]; then + diffs=$(echo "$diffs" | sed 'N;$!P;$!D;$d') + fi + + if [ "x$diffs" == "x" ] ; then + git reset HEAD $patch >/dev/null + git checkout -- $patch >/dev/null + fi + done +} + +function savePatches { + what=$1 + target=$2 + echo "Formatting patches for $what..." + cd "$basedir/$target" + git format-patch --no-stat -N -o "$basedir/${what}-Patches/" upstream/upstream >/dev/null + cd "$basedir" + git add -A "$basedir/${what}-Patches" + cleanupPatches "$basedir/${what}-Patches" + echo " Patches saved for $what to $what-Patches/" +} +if [ "$1" == "clean" ]; then + rm -rf Spigot-*-Patches +fi +savePatches Spigot-API PaperSpigot-API +savePatches Spigot-Server PaperSpigot-Server diff --git a/remap.sh b/remap.sh new file mode 100755 index 0000000..3afed48 --- /dev/null +++ b/remap.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +PS1="$" +basedir=`pwd` +workdir=$basedir/work +minecraftversion=$(cat BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +minecrafthash=$(cat BuildData/info.json | grep minecraftHash | cut -d '"' -f 4) +accesstransforms=BuildData/mappings/$(cat BuildData/info.json | grep accessTransforms | cut -d '"' -f 4) +classmappings=BuildData/mappings/$(cat BuildData/info.json | grep classMappings | cut -d '"' -f 4) +membermappings=BuildData/mappings/$(cat BuildData/info.json | grep memberMappings | cut -d '"' -f 4) +packagemappings=BuildData/mappings/$(cat BuildData/info.json | grep packageMappings | cut -d '"' -f 4) +jarpath=$workdir/$minecraftversion/$minecraftversion + +echo "Downloading unmapped vanilla jar..." +if [ ! -f "$jarpath.jar" ]; then + mkdir -p "$workdir/$minecraftversion" + curl -s -o "$jarpath.jar" "https://s3.amazonaws.com/Minecraft.Download/versions/$minecraftversion/minecraft_server.$minecraftversion.jar" + if [ "$?" != "0" ]; then + echo "Failed to download the vanilla server jar. Check connectivity or try again later." + exit 1 + fi +fi + +checksum=$(md5sum "$jarpath.jar" | cut -d ' ' -f 1) +if [ "$checksum" != "$minecrafthash" ]; then + echo "The MD5 checksum of the downloaded server jar does not match the BuildData hash." + exit 1 +fi + +echo "Applying class mappings..." +if [ ! -f "$jarpath-cl.jar" ]; then + java -jar BuildData/bin/SpecialSource-2.jar map -i "$jarpath.jar" -m "$classmappings" -o "$jarpath-cl.jar" 1>/dev/null + if [ "$?" != "0" ]; then + echo "Failed to apply class mappings." + exit 1 + fi +fi + +echo "Applying member mappings..." +if [ ! -f "$jarpath-m.jar" ]; then + java -jar BuildData/bin/SpecialSource-2.jar map -i "$jarpath-cl.jar" -m "$membermappings" -o "$jarpath-m.jar" 1>/dev/null + if [ "$?" != "0" ]; then + echo "Failed to apply member mappings." + exit 1 + fi +fi + +echo "Creating remapped jar..." +if [ ! -f "$jarpath-mapped.jar" ]; then + java -jar BuildData/bin/SpecialSource.jar --kill-lvt -i "$jarpath-m.jar" --access-transformer "$accesstransforms" -m "$packagemappings" -o "$jarpath-mapped.jar" 1>/dev/null + if [ "$?" != "0" ]; then + echo "Failed to create remapped jar." + exit 1 + fi +fi + +echo "Installing remapped jar..." +cd CraftBukkit # Need to be in a directory with a valid POM at the time of install. +mvn install:install-file -q -Dfile="$jarpath-mapped.jar" -Dpackaging=jar -DgroupId=org.spigotmc -DartifactId=minecraft-server -Dversion="$minecraftversion-SNAPSHOT" +if [ "$?" != "0" ]; then + echo "Failed to install remapped jar." + exit 1 +fi