Skip to content

Instantly share code, notes, and snippets.

@Caellian
Created August 7, 2015 21:30
Show Gist options
  • Save Caellian/d0045ed187fe7d0b6bb7 to your computer and use it in GitHub Desktop.
Save Caellian/d0045ed187fe7d0b6bb7 to your computer and use it in GitHub Desktop.
Finished?
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}/"
//Mapping data
String mappingsCommit = "88962d643ca3912333ede2da1b25d9a1092d5781",
mappingsFile = "../Enigma Mappings/${minecraftVersion}.mappings",
pathMappings = "conf/${minecraftVersion}.client.mappings"
//Versions
String forgeVersion = "1.8-11.14.1.1334"
String enigmaVersion = "0.10.4b"
//Client files
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"
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
jcenter()
maven {
name "Cuchaz Custom Repository"
url "http://maven.cuchazinteractive.com"
}
maven {
name "Minecraft Library Repository"
url "https://libraries.minecraft.net"
}
maven {
name "Minecraft Forge Repository"
url "http://files.minecraftforge.net/maven"
}
}
configurations {
procyon
enigma
}
//M3L information
version = minecraftVersion + "-0.3b"
group = "cuchaz.m3l"
dependencies {
procyon 'org.bitbucket.mstrobel:procyon-core:0.5.29',
'org.bitbucket.mstrobel:procyon-reflection:0.5.29',
'org.bitbucket.mstrobel:procyon-compilertools:0.5.29',
'org.bitbucket.mstrobel:procyon-expressions:0.5.29'
enigma module("cuchaz:enigma-lib:${enigmaVersion}") {
dependency('com.google.guava:guava:18.0')
dependency('org.javassist:javassist:3.19.0-GA')
}
enigma configurations.procyon
compile configurations.enigma
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'
compile "net.minecraftforge.forge:forge:${forgeVersion}:universal"
compile fileTree(dir: dirLib, include: 'forge*.jar')
compile fileTree(dir: dirLib, include: '*deobf.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'
}
}
}
task downloadNatives() << {
println "Downloading libraries from ${versionURL}${minecraftVersion}.json..."
download("${project.tasks['downloadLibraries'].temporaryDir}/version.json", "${versionURL}${minecraftVersion}.json")
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
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 == "?") {
download("${dirNatives}/${name}-${version}.jar", downloadURL + ".jar")
} else {
if (!download("${dirNatives}/${name}-${version}-${natives}-${arch}.jar", downloadURL + "-${natives}-${arch}.jar")) {
download("${dirNatives}/${name}-${version}-${natives}.jar", downloadURL + "-${natives}.jar")
}
}
}
}
}
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(dependsOn: tasks['getMappings'], type: Jar) << {
download(pathCleanJar, "${versionURL}${minecraftVersion}.jar")
println "Deobfuscating ${pathTempJar}..."
javaexec {
classpath = configurations.enigma
main = "cuchaz.enigma.CommandMain"
args = ['deobfuscate', pathCleanJar, pathTempJar, pathMappings]
}
println "Wrote ${pathTempJar}."
println "Publifying ${pathTempJar}..."
javaexec {
classpath = configurations.enigma
main = 'cuchaz.enigma.CommandMain'
args = ['publify', pathTempJar, pathDeobfJar]
}
println "Wrote ${pathDeobfJar}."
println "Decompiling ${pathDeobfJar}..."
File tmp = tasks['deobfMinecraftClient'].temporaryDir
tmp.mkdir()
String tmpPath = tmp.getPath()
javaexec {
classpath = configurations.enigma
main = 'cuchaz.enigma.CommandMain'
args = ['decompile', pathTempJar, tmpPath]
}
//TODO: Turn "jar cf dirLib/pathSrcJar tasks['deobfMinecraftClient'].temporaryDir" into Jar task
println "Wrote ${pathSrcJar}."
}
// Helper methods
static 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
}
}
static parseNatives(lib) {
if (lib.natives && getOs() != "unknown") {
assert lib.natives instanceof Map
lib.natives.get(getOs())
} else {
"?"
}
}
static String getOs() {
switch (System.getProperty("os.name").toLowerCase()) {
case ~/.*(linux|unix|bsd).*/:
return "linux"
case ~/.*win.*/:
return "windows"
case ~/.*(osx|mac).*/:
return "osx"
default:
return "unknown"
}
}
static boolean 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}}
}
return true
}
catch (Exception ignored) {
println "Unable to download ${dependencyURL}"
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment