Skip to content

Commit 5602dcd

Browse files
committed
Update 0.3.0
1 parent 641a142 commit 5602dcd

File tree

15 files changed

+1343
-74
lines changed

15 files changed

+1343
-74
lines changed

client/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ dependencies {
1111
//noinspection GradlePackageUpdate
1212
api("net.java.jinput:jinput:2.0.5")
1313
//noinspection GradlePackageUpdate
14-
api("org.lwjgl.lwjgl:lwjgl:2.9.1")
14+
api("org.lwjgl.lwjgl:lwjgl:2.9.3")
1515
//noinspection GradlePackageUpdate
16-
api("org.lwjgl.lwjgl:lwjgl_util:2.9.1")
16+
api("org.lwjgl.lwjgl:lwjgl_util:2.9.3")
1717
//noinspection GradlePackageUpdate
18-
api("org.lwjgl.lwjgl:lwjgl-platform:2.9.1")
18+
api("org.lwjgl.lwjgl:lwjgl-platform:2.9.3")
1919

2020
// Do no expose spark APIs to mods
2121
implementation(project['spark.dependency'] as String)

common/build.gradle

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,14 @@ dependencies {
1616
// Dev annotations
1717
api 'org.jetbrains:annotations:13.0'
1818

19-
// Do no expose spark APIs to mods
20-
implementation(project['spark.dependency'] as String)
21-
}
22-
23-
// Stuff for BuildConfig
24-
final File buildConfigSrc = new File(buildDir,
25-
"generated/sources/foxloader/com/fox2code/foxloader/launcher/BuildConfig.java")
26-
27-
static void generateBuildConfig0(File buildConfigSrc, Project project) {
28-
buildConfigSrc.getParentFile().mkdirs()
29-
final String FOXLOADER_TRANSFORMER_VERSION =
30-
project['foxloader.lastReIndevTransformerChanges']
31-
final String FOXLOADER_VERSION = project['foxloader.version']
32-
final String SPARK_DEPENDENCY = project['spark.dependency']
33-
final String SPARK_VERSION = project['spark.version']
34-
final String REINDEV_VERSION = project['reindev.version']
35-
final String CLIENT_URL = project['reindev.clientUrl']
36-
final String SERVER_URL = project['reindev.serverUrl']
37-
FileOutputStream fileOutputStream = new FileOutputStream(buildConfigSrc)
38-
try {
39-
PrintStream printStream = new PrintStream(fileOutputStream)
40-
printStream.println("// Auto generated class, do not modify.")
41-
printStream.println("package com.fox2code.foxloader.launcher;")
42-
printStream.println()
43-
printStream.println("public final class BuildConfig {")
44-
printStream.println(" private BuildConfig() {}")
45-
printStream.println( // We don't want devs to patch + decompile every update
46-
" public static final String FOXLOADER_TRANSFORMER_VERSION = \"" +
47-
FOXLOADER_TRANSFORMER_VERSION + "\";")
48-
printStream.println(" public static final String FOXLOADER_VERSION = \"" + FOXLOADER_VERSION + "\";")
49-
printStream.println(" public static final String SPARK_DEPENDENCY = \"" + SPARK_DEPENDENCY + "\";")
50-
printStream.println(" public static final String SPARK_VERSION = \"" + SPARK_VERSION + "\";")
51-
printStream.println(" public static final String REINDEV_VERSION = \"" + REINDEV_VERSION + "\";")
52-
printStream.println(" public static final String CLIENT_URL = \"" + CLIENT_URL + "\";")
53-
printStream.println(" public static final String SERVER_URL = \"" + SERVER_URL + "\";")
54-
printStream.println("}")
55-
} finally {
56-
fileOutputStream.close()
19+
// Unpick transformer helper
20+
compileOnly('org.lwjgl.lwjgl:lwjgl:2.9.3') {
21+
transitive = false
5722
}
58-
}
5923

60-
tasks.register('generateBuildConfig') {
61-
doLast {
62-
generateBuildConfig0(buildConfigSrc, project)
63-
}
64-
}
65-
66-
if (!buildConfigSrc.exists()) {
67-
generateBuildConfig0(buildConfigSrc, project)
24+
// Do no expose spark APIs to mods
25+
implementation(project['spark.dependency'] as String)
6826
}
6927

70-
compileJava.dependsOn('generateBuildConfig')
71-
72-
sourceSets {
73-
main {
74-
java {
75-
srcDir 'build/generated/sources/foxloader'
76-
}
77-
}
78-
}
28+
// Generated code is in another script to make code cleaner.
29+
apply from: "generate.gradle"

common/generate.gradle

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
import java.lang.reflect.Field
2+
import java.lang.reflect.Modifier
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
}
8+
dependencies {
9+
// Unpick transformer helper
10+
classpath('org.lwjgl.lwjgl:lwjgl:2.9.3') {
11+
transitive = false
12+
}
13+
}
14+
}
15+
16+
sourceSets {
17+
main {
18+
java {
19+
srcDir 'build/generated/sources/foxloader'
20+
}
21+
}
22+
}
23+
24+
// BuildConfig stuff
25+
final File buildConfigSrc = new File(buildDir,
26+
"generated/sources/foxloader/com/fox2code/foxloader/launcher/BuildConfig.java")
27+
28+
static void generateBuildConfig0(File buildConfigSrc, Project project) {
29+
buildConfigSrc.getParentFile().mkdirs()
30+
final String FOXLOADER_TRANSFORMER_VERSION =
31+
project['foxloader.lastReIndevTransformerChanges']
32+
final String FOXLOADER_VERSION = project['foxloader.version']
33+
final String SPARK_DEPENDENCY = project['spark.dependency']
34+
final String SPARK_VERSION = project['spark.version']
35+
final String REINDEV_VERSION = project['reindev.version']
36+
final String CLIENT_URL = project['reindev.clientUrl']
37+
final String SERVER_URL = project['reindev.serverUrl']
38+
FileOutputStream fileOutputStream = new FileOutputStream(buildConfigSrc)
39+
try {
40+
PrintStream printStream = new PrintStream(fileOutputStream)
41+
printStream.println("// Auto generated class, do not modify.")
42+
printStream.println("package com.fox2code.foxloader.launcher;")
43+
printStream.println()
44+
printStream.println("public final class BuildConfig {")
45+
printStream.println(" private BuildConfig() {}")
46+
printStream.println( // We don't want devs to patch + decompile every update
47+
" public static final String FOXLOADER_TRANSFORMER_VERSION = \"" +
48+
FOXLOADER_TRANSFORMER_VERSION + "\";")
49+
printStream.println(" public static final String FOXLOADER_VERSION = \"" + FOXLOADER_VERSION + "\";")
50+
printStream.println(" public static final String SPARK_DEPENDENCY = \"" + SPARK_DEPENDENCY + "\";")
51+
printStream.println(" public static final String SPARK_VERSION = \"" + SPARK_VERSION + "\";")
52+
printStream.println(" public static final String REINDEV_VERSION = \"" + REINDEV_VERSION + "\";")
53+
printStream.println(" public static final String CLIENT_URL = \"" + CLIENT_URL + "\";")
54+
printStream.println(" public static final String SERVER_URL = \"" + SERVER_URL + "\";")
55+
printStream.println("}")
56+
} finally {
57+
fileOutputStream.close()
58+
}
59+
}
60+
61+
tasks.register('generateBuildConfig') {
62+
doLast {
63+
generateBuildConfig0(buildConfigSrc, project)
64+
}
65+
}
66+
67+
if (!buildConfigSrc.exists()) {
68+
generateBuildConfig0(buildConfigSrc, project)
69+
}
70+
71+
compileJava.dependsOn('generateBuildConfig')
72+
73+
// GeneratedConstantUnpick stuff
74+
final File generatedConstantUnpicksSrc = new File(buildDir,
75+
"generated/sources/foxloader/com/fox2code/foxloader/loader/transformer/GeneratedConstantUnpicks.java")
76+
final String[] openGLSources = new String[]{"GL11", "GL12", "GL13", "GL14", "GL15", "GL20", "GL21"}
77+
final HashSet<String> explicitlyExcludedEntries = new HashSet<>(Arrays.asList(
78+
// Skip Generic entries
79+
"GL11#GL_ZERO", "GL11#GL_ONE", "GL11#GL_TRUE", "GL11#GL_FALSE", "GL11#GL_NONE", "GL11#GL_NO_ERROR",
80+
// Ignore duplicates
81+
"GL11#GL_LOGIC_OP", "GL11#GL_TEXTURE_COMPONENTS",
82+
"GL12#GL_SMOOTH_POINT_SIZE_RANGE", "GL12#GL_SMOOTH_POINT_SIZE_GRANULARITY",
83+
"GL12#GL_SMOOTH_LINE_WIDTH_RANGE", "GL12#GL_SMOOTH_LINE_WIDTH_GRANULARITY",
84+
"GL15#GL_FOG_COORD_SRC", "GL15#GL_FOG_COORD", "GL15#GL_CURRENT_FOG_COORD",
85+
"GL15#GL_FOG_COORD_ARRAY_TYPE", "GL15#GL_FOG_COORD_ARRAY_STRIDE",
86+
"GL15#GL_FOG_COORD_ARRAY_POINTER", "GL15#GL_FOG_COORD_ARRAY",
87+
"GL15#GL_FOG_COORD_ARRAY_BUFFER_BINDING",
88+
"GL15#GL_SRC0_RGB", "GL15#GL_SRC1_RGB", "GL15#GL_SRC2_RGB",
89+
"GL15#GL_SRC0_ALPHA", "GL15#GL_SRC1_ALPHA", "GL15#GL_SRC2_ALPHA",
90+
"GL20#GL_BLEND_EQUATION_RGB",
91+
))
92+
93+
void verifyConstantUnpickCollisions0(String[] openGLSources, HashSet<String> explicitlyExcludedEntries) {
94+
final String RESET = "\033[0m";
95+
final String RED = "\033[0;31m";
96+
final String GREEN = "\033[0;32m";
97+
final String YELLOW = "\033[0;33m";
98+
final String BLUE = "\033[0;34m";
99+
HashMap<Integer, String> integerHashSet = new HashMap<>()
100+
int entryCount = 0
101+
boolean configValid = true
102+
for (String openGLSource : openGLSources) {
103+
Class<?> aClass = Class.forName("org.lwjgl.opengl." + openGLSource)
104+
for (Field field : aClass.getDeclaredFields()) {
105+
if ((field.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC))
106+
!= (Modifier.PUBLIC | Modifier.STATIC)) continue
107+
if (field.getName().endsWith("_BIT")) continue
108+
if (field.getType() != int.class) continue
109+
Integer value = Integer.valueOf(field.getInt(null))
110+
final String entryName = openGLSource + "#" + field.getName()
111+
if (explicitlyExcludedEntries.contains(entryName)) continue
112+
String collision = integerHashSet.putIfAbsent(value, entryName)
113+
if (collision != null) {
114+
project.println(RED + "Collision detected: " + collision + " == " + entryName + RESET)
115+
configValid = false
116+
}
117+
entryCount++
118+
}
119+
}
120+
for (String exclusion : explicitlyExcludedEntries) {
121+
int i = exclusion.indexOf('#')
122+
if (i == -1) {
123+
project.println(YELLOW + "Exclusion does not contain class name: " + exclusion + RESET)
124+
continue
125+
}
126+
Class<?> aClass = Class.forName("org.lwjgl.opengl." + exclusion.substring(0, i))
127+
try {
128+
Field field = aClass.getDeclaredField(exclusion.substring(i + 1))
129+
String collision = integerHashSet.get(field.getInt(null))
130+
if (collision == null) {
131+
project.println(YELLOW + "No collision found fo exclusion: " + exclusion + RESET)
132+
} else {
133+
project.println(BLUE + "Exclusion " + exclusion + GREEN +
134+
" is good" + BLUE + " because of " + collision + RESET)
135+
}
136+
} catch (Exception e) {
137+
project.println(YELLOW + "Field no longer exists for exclusion: " + exclusion + RESET)
138+
}
139+
}
140+
if (!configValid) {
141+
project.println(RED + "Config is not valid because of collisions!" + RESET)
142+
} else {
143+
project.println(GREEN + "Config has " + entryCount + " entries!" + RESET)
144+
}
145+
}
146+
147+
static void generateUnpickStart(PrintStream printStream) {
148+
printStream.println(" @Override")
149+
printStream.println(" public FieldInsnNode unpick(int value) {")
150+
printStream.println(" //noinspection DanglingJavadoc")
151+
printStream.println(" switch(value) {")
152+
printStream.println(" default:")
153+
printStream.println(" return null;")
154+
}
155+
156+
static void generateUnpickEnd(PrintStream printStream) {
157+
printStream.println(" }")
158+
printStream.println(" }")
159+
}
160+
161+
static void generatedConstantUnpick0(File generatedConstantUnpicksSrc, String[] openGLSources,
162+
HashSet<String> explicitlyExcludedEntries) {
163+
generatedConstantUnpicksSrc.getParentFile().mkdirs()
164+
FileOutputStream fileOutputStream = new FileOutputStream(generatedConstantUnpicksSrc)
165+
try {
166+
PrintStream printStream = new PrintStream(fileOutputStream)
167+
printStream.println("// Auto generated class, do not modify.")
168+
printStream.println("package com.fox2code.foxloader.loader.transformer;")
169+
printStream.println()
170+
printStream.println("import static org.objectweb.asm.Opcodes.GETSTATIC;")
171+
printStream.println("import org.objectweb.asm.tree.FieldInsnNode;")
172+
printStream.println()
173+
for (String openGLSource : openGLSources) {
174+
printStream.println("import org.lwjgl.opengl." + openGLSource + ";")
175+
}
176+
printStream.println("import org.lwjgl.input.Keyboard;")
177+
printStream.println()
178+
printStream.println("public final class GeneratedConstantUnpicks {")
179+
printStream.println(" private GeneratedConstantUnpicks() {}")
180+
printStream.println()
181+
printStream.println(" public static final DevelopmentSourceTransformer.ConstantUnpick " +
182+
"openGLConstantUnpick = new OpenGLConstantUnpick();")
183+
printStream.println(" public static final DevelopmentSourceTransformer.ConstantUnpick " +
184+
"keyboardConstantUnpick = new KeyboardConstantUnpick();")
185+
// OpenGL
186+
printStream.println()
187+
printStream.println(" // Auto generated class, do not modify.")
188+
printStream.println(" private static final class OpenGLConstantUnpick")
189+
printStream.println(" extends DevelopmentSourceTransformer.GeneratedStaticConstantUnpick {")
190+
for (String openGLSource : openGLSources) {
191+
printStream.println(" private static final String " + openGLSource +
192+
" = \"org/lwjgl/opengl/" + openGLSource + "\";")
193+
}
194+
printStream.println()
195+
generateUnpickStart(printStream)
196+
for (String openGLSource : openGLSources) {
197+
Class<?> aClass = Class.forName("org.lwjgl.opengl." + openGLSource)
198+
for (Field field : aClass.getDeclaredFields()) {
199+
if ((field.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC))
200+
!= (Modifier.PUBLIC | Modifier.STATIC)) continue
201+
if (field.getName().endsWith("_BIT")) continue
202+
if (field.getType() != int.class) continue
203+
final String entryName = openGLSource + "#" + field.getName()
204+
if (explicitlyExcludedEntries.contains(entryName)) continue
205+
int value = field.getInt(null)
206+
printStream.println(" case " + value + ": /** {@link " + entryName + "} */")
207+
printStream.println(" return " +
208+
"new FieldInsnNode(GETSTATIC, " + openGLSource + ", \"" + field.getName() + "\", \"I\");")
209+
}
210+
}
211+
generateUnpickEnd(printStream)
212+
printStream.println(" }")
213+
// KeyBoard
214+
printStream.println()
215+
printStream.println(" // Auto generated class, do not modify.")
216+
printStream.println(" private static final class KeyboardConstantUnpick")
217+
printStream.println(" extends DevelopmentSourceTransformer.GeneratedStaticConstantUnpick {")
218+
Class<?> aClass = Class.forName("org.lwjgl.input.Keyboard")
219+
printStream.println(" private static final String KEYBOARD = \"org/lwjgl/input/Keyboard\";")
220+
printStream.println()
221+
generateUnpickStart(printStream)
222+
for (Field field : aClass.getDeclaredFields()) {
223+
if ((field.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC))
224+
!= (Modifier.PUBLIC | Modifier.STATIC)) continue
225+
if (!field.getName().startsWith("KEY_")) continue
226+
if (field.getName().endsWith("WIN")) continue
227+
if (field.getType() != int.class) continue
228+
int value = field.getInt(null)
229+
printStream.println(" case " + value + ": /** {@link Keyboard#" + field.getName() + "} */")
230+
printStream.println(" return " +
231+
"new FieldInsnNode(GETSTATIC, KEYBOARD, \"" + field.getName() + "\", \"I\");")
232+
}
233+
generateUnpickEnd(printStream)
234+
printStream.println(" }")
235+
// End
236+
printStream.println("}")
237+
} finally {
238+
fileOutputStream.close()
239+
}
240+
}
241+
242+
tasks.register('verifyConstantUnpickCollisions') {
243+
doLast {
244+
verifyConstantUnpickCollisions0(openGLSources, explicitlyExcludedEntries)
245+
}
246+
}
247+
248+
tasks.register('generateConstantUnpicksSrc') {
249+
doLast {
250+
generatedConstantUnpick0(generatedConstantUnpicksSrc, openGLSources, explicitlyExcludedEntries)
251+
}
252+
}
253+
254+
if (!generatedConstantUnpicksSrc.exists()) {
255+
generatedConstantUnpick0(generatedConstantUnpicksSrc, openGLSources, explicitlyExcludedEntries)
256+
}
257+
258+
compileJava.dependsOn('generateConstantUnpicksSrc')

0 commit comments

Comments
 (0)