Last active
January 4, 2019 18:01
-
-
Save Frontear/1ea64972a4eb5d514d5b5b8e456ef83c to your computer and use it in GitHub Desktop.
A shell script dedicated to automatically downloading and setting up a ModCoderPack workspace. Now includes more functionality than ever!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # I highly recommend this video: https://www.youtube.com/watch?v=b2gJfKNSb1k | |
| # It can help troubleshoot, and is the sole reason I decided to even expand this script for such complex tasks in the first place | |
| # update these urls correctly for yourself | |
| MC_VERSION="1.8.8" # just the minecraft version you are planning to decompile | |
| MCP_ZIP="http://www.modcoderpack.com/files/mcp918.zip" # the modcoderpack zip. Download the one closest to your version | |
| SERVER_JAR="https://launcher.mojang.com/v1/objects/5fafba3f58c40dc51b5c3ca72a98f62dfdae1db7/server.jar" # the server jar. Download the exact one for your version | |
| MAPPINGS_ZIP="http://export.mcpbot.bspk.rs/mcp_stable/20-1.8.8/mcp_stable-20-1.8.8.zip" # the obfuscated mappings. Download the stable ones, if possible | |
| PATCHES_ZIP="https://bitbucket.org/ProfMobius/mcpbot/raw/f53f7839cb0524a918c1d772b495243f18c8f9b0/mcp-$MC_VERSION-srg.zip" # the patches for each version. Download for your exact version, however if not possible, do note that any close version may work | |
| # directory path. Be careful with this, and NEVER leave this as just $PWD, as it will overwrite itself and anything inside the folder due to the rm -rf instructions below | |
| MCP_DIR=$PWD/mcp | |
| OG_DIR=$PWD | |
| # only set these values if you are trying to decompile a custom jar file. WARNING, this will take a little bit longer, since it decompiles twice, once for vanilla, and once for custom. | |
| # additionally, decompiling a custom jar WILL cause errors. That is unavoidable. You will need to fix all of them yourself | |
| BACKUP_DIR=$MCP_DIR/backup | |
| function download() { | |
| # $1 = File to download | |
| # $2 = Directory to save in | |
| # $3 = Any custom names for the file | |
| # $4 = Is it a zip? Should it have 'unzip' run on it? | |
| cd $2 # the directory must have been created prior | |
| wget $1 -O $3 # download the file | |
| if [ $4 = "true" ]; then | |
| unzip -o $3 && rm $3 # unzip (-o means force overwrite anything that may be similar and collides) and remove | |
| fi | |
| } | |
| function replace() { | |
| # $1 = text to replace | |
| # $2 = replacement text | |
| # $3 = file path | |
| sed -i "s/$1/$2/" $3 | |
| } | |
| function decompile_custom() { | |
| echo "Setting up environment for custom jar..." | |
| rm -rf $BACKUP_DIR | |
| mkdir $BACKUP_DIR | |
| python2 runtime/cleanup.py "$@" --force # remove all decompiled code, leaving the libraries and other's for reuse | |
| mv $MCP_DIR/jars/versions/$MC_VERSION/$MC_VERSION.jar $BACKUP_DIR/$MC_VERSION.jar # copy the jar, do not remove it just yet | |
| echo "### Decompiling a custom jar ###" | |
| echo "Please download the jar file, and place it into the backup folder, name is custom.jar" | |
| echo "The script will extract and wrap it back into a decompilable jar merged with Minecraft's code" | |
| echo "Please make sure the jar file you are providing is actually a minecraft jar and not a mod" | |
| echo "You can tell if it has a.class aa.class or such within it, alongside assets, net or other folders" | |
| read -n1 -s -r -p "Press any key when you have completed and read the above steps..." | |
| cd $BACKUP_DIR | |
| mkdir tmp | |
| cp $MC_VERSION.jar tmp/$MC_VERSION.jar && cp custom.jar tmp/custom.jar # copy the jars into the temporary folder | |
| cd tmp | |
| jar xvf $MC_VERSION.jar && jar xvf custom.jar # extract both jars into the tmp directory. MC_VERSION must go first, so custom.jar, when extracting, will overwrite all same files | |
| rm $MC_VERSION.jar && rm custom.jar # remove both | |
| jar cvf $MC_VERSION-custom.jar * # create a jar file with all the extracted and replaced contents | |
| mv $MC_VERSION-custom.jar $MCP_DIR/backup/$MC_VERSION-custom.jar | |
| cd $MCP_DIR/backup | |
| rm -rf tmp | |
| mv $MC_VERSION-custom.jar $MCP_DIR/jars/versions/$MC_VERSION/$MC_VERSION.jar # represent the 'vanilla' jar, MCP will be tricked into decompiling this | |
| cd $MCP_DIR | |
| python2 runtime/decompile.py "$@" # call decompile again. This time, it will attempt to decompile the new jar instead. | |
| } | |
| clear # initial clear. | |
| echo "### Please Read ###" | |
| echo "Make sure you've run MC $MC_VERSION at least once on the official launcher" | |
| echo "Make sure that the directory $MCP_DIR contains no important files" | |
| echo "WARNING: Errors may be present in the code. They will not be large issues" | |
| echo "Please attempt to correct them manually. This script will not fix them for you" | |
| read -n1 -s -r -p "Press any key if you understand and wish to continue..." | |
| clear # final clear. Never clear again | |
| echo "Downloading various files..." | |
| rm -rf $MCP_DIR # if it already exists, remove it | |
| mkdir $MCP_DIR | |
| echo "Downloading MCP..." | |
| download $MCP_ZIP $MCP_DIR "mcp.zip" "true" | |
| echo "Downloading server jar..." | |
| download $SERVER_JAR $MCP_DIR/jars "minecraft_server.$MC_VERSION.jar" "false" | |
| echo "Downloading and applying specified mappings..." | |
| download $MAPPINGS_ZIP $MCP_DIR/conf "mappings.zip" "true" | |
| # note, it is usually not necessary to download the patches. Only uncomment the following if it fails to correctly decompile without them | |
| echo "Downloading and applying specified patches..." | |
| download $PATCHES_ZIP $MCP_DIR/conf "patches.zip" "true" | |
| echo "Updating version.cfg to accept configured version..." | |
| # the reason we can't wildcard anything before Version is that MCP will change, and I don't really want to do that. | |
| replace "ClientVersion =.*" "ClientVersion = $MC_VERSION" $MCP_DIR/conf/version.cfg | |
| replace "ServerVersion =.*" "ServerVersion = $MC_VERSION" $MCP_DIR/conf/version.cfg | |
| echo "Decompiling Minecraft" | |
| cd $MCP_DIR # return to the main directory | |
| python2 runtime/decompile.py "$@" | |
| # only uncomment below if decompiling a custom jar as well | |
| # decompile_custom | |
| zip -r $OG_DIR/mcp_workspace.zip $MCP_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment