Skip to content

Instantly share code, notes, and snippets.

@Caellian
Last active August 29, 2015 14:26
Show Gist options
  • Save Caellian/e1b65f566e95af330d7a to your computer and use it in GitHub Desktop.
Save Caellian/e1b65f566e95af330d7a to your computer and use it in GitHub Desktop.
Cuchaz m3l build script
import groovy.json.JsonSlurper
import java.nio.file.Files
//Project data
String minecraftVersion = "1.8.3",
dirLib = "lib",
dirNatives = "natives/${minecraftVersion}"
//Minecraft data
String minecraftRepo = "https://s3.amazonaws.com/Minecraft.Download/",
versionURL = "${minecraftRepo}versions/${minecraftVersion}/${minecraftVersion}",
versionJSON = "${versionURL}.json",
versionJAR = "${versionURL}.jar"
//Mapping data
String mappingsCommit = "88962d643ca3912333ede2da1b25d9a1092d5781",
mappingsFile = "../Enigma Mappings/${minecraftVersion}.mappings",
pathMappings = "conf/${minecraftVersion}.client.mappings"
//Forge data
String forgeVersion = "1.8-11.14.1.1334",
forgeJar = "forge-${forgeVersion}-universal.jar",
pathForgeUniversal = "${dirLib}/${forgeJar}"
//Enigma data
String enigmaVer = "0.10.4b",
dirEnigma = "enigma",
pathEnigma = "${dirEnigma}/enigma-lib-${enigmaVer}.jar"
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
jcenter()
maven {
url "http://maven.cuchazinteractive.com"
}
maven {
url "https://libraries.minecraft.net"
}
}
version = minecraftVersion + "-0.3b"
group = "cuchaz.m3l"
dependencies {
compile 'net.minecraft:launchwrapper:1.8'
compile 'com.google.guava:guava:18.0'
compile 'org.javassist:javassist:3.19.0-GA'
compile 'ch.qos.logback:logback-classic:1.1.2'
compile 'org.slf4j:slf4j-api:1.7.10'
download(pathForgeUniversal, "http://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeVersion}/${forgeJar}")
compile fileTree(dir: dirLib, include: '*.jar')
compile fileTree(dir: dirNatives, include: '*.jar')
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
}
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'resources'
}
}
test {
java {
srcDir 'test'
}
resources {
srcDir 'testResources'
}
}
}
def parseRules = { lib ->
if (lib.rules)
{
def download = false
lib.rules.each { rule ->
if (rule.os)
{
if (rule.os.name == getOs())
{
download = rule.action == "allow"
}
}
else
{
download = rule.action == "allow"
}
}
download
}
else
{
true
}
}
def parseNatives = { lib ->
if (lib.natives && getOs() != "unknown")
{
assert lib.natives instanceof Map
lib.natives.get(getOs())
}
else
{
"?"
}
}
task downloadLibraries << {
println "Downloading libraries from ${versionJSON}..."
download("${project.tasks['downloadLibraries'].temporaryDir}/version.json", "${versionJSON}")
def jsonSlurper = new JsonSlurper()
def root = jsonSlurper.parse(new File("${project.tasks['downloadLibraries'].temporaryDir}/version.json"))
assert root instanceof Map
assert root.libraries instanceof List
root.libraries.each {
assert it.name instanceof String
println "Handling library ${it.name}..."
assert it.rules instanceof List || it.rules == null
assert it.natives instanceof Map || it.natives == null
String location = it.name
String natives = parseNatives it
if (parseRules(it))
{
String packagePath = location.split(":")[0]
String name = location.split(":")[1]
String version = location.split(":")[2]
String arch = System.getProperty("os.arch")
String downloadURL = "https://libraries.minecraft.net/${packagePath.replace(".", "/")}/${name}/${version}/${name}-${version}"
if (natives == "?")
{
downloadURL += ".jar"
download("${dirNatives}/${name}-${version}.jar", downloadURL)
}
else
{
downloadURL += "-${it.natives}-${arch}.jar"
download("${dirNatives}/${name}-${version}-${natives}-${arch}.jar", downloadURL)
}
}
}
}
task getMappings << {
if (mappingsFile != null && new File(mappingsFile).isFile())
{
Files.copy(new File(mappingsFile).toPath(), new File(pathMappings).newOutputStream())
println "Read mappings from ${mappingsFile}."
}
else
{
download(pathMappings, "https://bitbucket.org/cuchaz/minecraft-mappings/raw/${mappingsCommit}/${minecraftVersion}.mappings")
println "Wrote mappings to ${pathMappings}"
}
}
task deobfMinecraftClient << {
new File(dirEnigma).mkdir()
download(pathEnigma, "http://maven.cuchazinteractive.com/cuchaz/enigma-lib/${enigmaVer}/enigma-lib-${enigmaVer}.jar")
download("${dirEnigma}/guava-18.0.jar", "https://repo1.maven.org/maven2/com/google/guava/guava/18.0/guava-18.0.jar")
download("${dirEnigma}/javassist-3.19.0-GA.jar", "https://repo1.maven.org/maven2/org/javassist/javassist/3.19.0-GA/javassist-3.19.0-GA.jar")
download("${dirEnigma}/procyon-fat-0.5.29.jar", "https://bitbucket.org/caellian/procyon/downloads/procyon-fat-0.5.29.jar")
new File(dirLib).mkdir()
String pathCleanJar = "${dirLib}/minecraft-${minecraftVersion}-clean.jar",
pathTempJar = "${dirLib}/minecraft-${minecraftVersion}-temp.jar",
pathDeobfJar = "${dirLib}/minecraft-${minecraftVersion}-client-deobf.jar",
pathSrcJar = "${dirLib}/minecraft-${minecraftVersion}-client-deobf-src.jar"
download(pathCleanJar, versionJAR)
println "Deobfuscating ${pathTempJar}..."
exec {
executable = "java";
args = ["-cp", pathEnigma + File.pathSeparator + "${dirEnigma}/*", "cuchaz.enigma.CommandMain", "deobfuscate", pathCleanJar, pathTempJar, pathMappings]
}
println "Wrote ${pathTempJar}."
println "Publifying ${pathTempJar}..."
exec {
executable = "java";
args = ["-cp", pathEnigma + File.pathSeparator + "${dirEnigma}/*", "cuchaz.enigma.CommandMain", "publify", pathTempJar, pathDeobfJar]
}
println "Wrote ${pathDeobfJar}."
println "Decompiling ${pathDeobfJar}..."
File tmp = tasks['deobfMinecraftClient'].temporaryDir
tmp.mkdir()
String tmpPath = tmp.getPath()
exec {
executable = "java";
args = ["-cp", pathEnigma + File.pathSeparator + "${dirEnigma}/*", "cuchaz.enigma.CommandMain", "decompile", pathTempJar, tmpPath]
}
exec {
executable = "jar";
args = ["cf", pathSrcJar, tmpPath]
}
tmp.delete()
println "Wrote ${pathSrcJar}."
}
// Helper methods
def static String getOs()
{
String osName = System.getProperty("os.name").toLowerCase()
String normalizedName
if (osName.contains("linux") || osName.contains("unix"))
{
normalizedName = "linux"
}
else if (osName.contains("win"))
{
normalizedName = "windows"
}
else if (osName.contains("mac"))
{
normalizedName = "osx"
}
else
{
normalizedName = "unknown"
}
return normalizedName
}
def static download(String filePath, String dependencyURL)
{
try
{
File file = new File(filePath)
file.getParentFile().mkdirs();
if (!file.exists())
{
println "Downloading ${dependencyURL}..."
new URL(dependencyURL).withInputStream { i -> file.withOutputStream { it << i } }
}
}
catch (Exception e)
{
println "Unable to download from ${dependencyURL}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment