From ace76fe9e4a7337f10ab61984b2b46313df2f3df Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 12 Mar 2020 19:59:32 +0000 Subject: [PATCH] Transform GL_FRAMEBUFFER_COMPLETE literals This is a special case, so I've just hard-coded the GlEnum name and value. Luckily its value is only used in the client in an OpenGL context. Signed-off-by: Graham --- .../ast/transform/GlConstantTransformer.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlConstantTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlConstantTransformer.kt index 0dac12379e..0d97362c64 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlConstantTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlConstantTransformer.kt @@ -47,6 +47,33 @@ class GlConstantTransformer : Transformer() { } else { transformArguments(unit) } + + transformFramebufferStatus(unit) + } + + private fun transformFramebufferStatus(unit: CompilationUnit) { + unit.walk { expr: BinaryExpr -> + if (expr.operator == BinaryExpr.Operator.EQUALS || expr.operator == BinaryExpr.Operator.NOT_EQUALS) { + transformFramebufferStatus(unit, expr.left) + transformFramebufferStatus(unit, expr.right) + } + } + } + + private fun transformFramebufferStatus(unit: CompilationUnit, expr: Expression) { + if (!expr.isIntegerLiteralExpr) { + return + } + + val value = expr.asIntegerLiteralExpr().checkedAsInt() + if (value.toLong() != GL_FRAMEBUFFER_COMPLETE.value) { + return + } + + unit.addImport(GL_CLASS) + enums += GL_FRAMEBUFFER_COMPLETE + + expr.replace(GL_FRAMEBUFFER_COMPLETE.toExpr()) } private fun transformParameterNames(type: TypeDeclaration<*>) { @@ -287,6 +314,7 @@ class GlConstantTransformer : Transformer() { private const val JAGGL_CLASS = "jaggl.opengl" private val GL_CLASSES = setOf(GL_CLASS, JAGGL_CLASS) private val REGISTRY = GlRegistry.parse() + private val GL_FRAMEBUFFER_COMPLETE = GlEnum("GL_FRAMEBUFFER_COMPLETE", 0x8CD5) private val FIELD_METHOD_COMPARATOR = Comparator> { a, b -> when {