-
Notifications
You must be signed in to change notification settings - Fork 1
/
zomboid.gradle
118 lines (98 loc) · 4.01 KB
/
zomboid.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.nio.file.Paths
// directory containing Project Zomboid classes
project.ext.zomboidClassesDir = file("$buildDir/classes/zomboid").absoluteFile
// directory containing Project Zomboid sources
project.ext.zomboidSourcesDir = file("$buildDir/generated/sources/zomboid").absoluteFile
/**
* This task will sync zomboidClassesDir with classes found in game install directory.
* Note that it needs to run before dependencies are declared so that
* the assembled classes can be included onto the classpath
*/
def zomboidClasses = tasks.register('zomboidClasses', Sync.class) {
it.description 'Assembles Project Zomboid classes.'
it.group 'zomboid'
it.includeEmptyDirs false
it.from project.ext.gameDir
it.include '**/*.class', 'stdlib.lbc'
it.into zomboidClassesDir
}
classes.dependsOn(zomboidClasses)
configurations {
runtimeOnly.extendsFrom zomboidRuntimeOnly
implementation.extendsFrom zomboidImplementation
}
dependencies {
// Project Zomboid libraries
zomboidRuntimeOnly fileTree(dir: gameDir, include: ['*.jar'])
// Project Zomboid assets
def gameDirPath = gameDir as java.nio.file.Path
zomboidImplementation files(gameDirPath.resolve('media'))
// Project Zomboid classes
if (project.ext.has('mod.pzversion')) {
zomboidImplementation files("lib/zomboid-${project.ext.get('mod.pzversion')}.jar")
}
}
/**
* Decompile game classes with FernFlower using default IDEA settings.
* Default task behaviour is to decompile all class files found in game root directory.
*
* This can be changed by defining specific files to decompile with project property 'decompileFiles'.
* Each specified file path has to be a package path relative to destination root directory.
* When specifying multiple file paths remember to separate them with comma delimiter.
* example: gradle decompileZomboid -PdecompileFiles=zombie/FileGuidPair.class,zombie/GameTime.class
*/
tasks.register('decompileZomboid', JavaExec.class) {
it.description 'Decompile Project Zomboid classes.'
it.group 'zomboid'
if (project.ext.ideaHome == null) {
throw new InvalidUserDataException('Local property \"ideaHome\" is not defined')
}
it.onlyIf {
def files = zomboidClassesDir.exists() ? zomboidClassesDir.listFiles() : null
return files != null && files.size() > 0
}
//noinspection GroovyAssignabilityCheck,GroovyAccessibility
it.javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
it.classpath files("$ideaHome/plugins/java-decompiler/lib/java-decompiler.jar")
it.main 'org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler'
// default parameters used by IDEA compiler
def params = ['-hdc=0', '-dgs=1', '-rsy=1', '-rbr=1', '-lit=1', '-nls=1', '-mpm=60']
// decompiler will throw error if destination dir doesn't exist
zomboidSourcesDir.mkdirs()
String zomboidClassesDirPath = zomboidClassesDir.path;
List<String> decompileTargets = new ArrayList<>()
// handle compiling specified individual classes
if (project.ext.has('decompileFiles')) {
(project.ext.get('decompileFiles') as String).split(',').each {
decompileTargets.add(Paths.get(zomboidClassesDirPath, it).toString())
}
}
else decompileTargets.add(zomboidClassesDirPath)
it.args params + decompileTargets + zomboidSourcesDir.path
it.dependsOn(zomboidClasses)
}
tasks.register('zomboidJar', ZDocJar.class) {
it.description 'Assembles a jar archive containing game classes.'
it.includeEmptyDirs = false
it.archiveBaseName.set('zomboid')
it.from zomboidClassesDir
it.destinationDir file('lib')
it.onlyIf {
def files = zomboidClassesDir.exists() ? zomboidClassesDir.listFiles() : null
return files != null && files.size() > 0
}
it.dependsOn(zomboidClasses)
}
tasks.register("zomboidSourcesJar", ZDocJar.class) {
it.description 'Assembles a jar containing decompiled game sources.'
it.archiveBaseName.set('zomboid')
it.classifier 'sources'
it.from zomboidSourcesDir
it.destinationDir file('lib')
it.onlyIf {
def files = zomboidSourcesDir.exists() ? zomboidSourcesDir.listFiles() : null
return files != null && files.size() > 0
}
}