|
|
@ -9,13 +9,17 @@ import com.github.javaparser.ast.body.Parameter |
|
|
|
import com.github.javaparser.ast.body.TypeDeclaration |
|
|
|
import com.github.javaparser.ast.body.TypeDeclaration |
|
|
|
import com.github.javaparser.ast.body.VariableDeclarator |
|
|
|
import com.github.javaparser.ast.body.VariableDeclarator |
|
|
|
import com.github.javaparser.ast.expr.BinaryExpr |
|
|
|
import com.github.javaparser.ast.expr.BinaryExpr |
|
|
|
|
|
|
|
import com.github.javaparser.ast.expr.ConditionalExpr |
|
|
|
import com.github.javaparser.ast.expr.Expression |
|
|
|
import com.github.javaparser.ast.expr.Expression |
|
|
|
import com.github.javaparser.ast.expr.FieldAccessExpr |
|
|
|
import com.github.javaparser.ast.expr.FieldAccessExpr |
|
|
|
|
|
|
|
import com.github.javaparser.ast.expr.IntegerLiteralExpr |
|
|
|
import com.github.javaparser.ast.expr.MethodCallExpr |
|
|
|
import com.github.javaparser.ast.expr.MethodCallExpr |
|
|
|
import com.github.javaparser.ast.expr.NameExpr |
|
|
|
import com.github.javaparser.ast.expr.NameExpr |
|
|
|
import com.github.javaparser.ast.expr.SimpleName |
|
|
|
import com.github.javaparser.ast.expr.SimpleName |
|
|
|
import com.github.javaparser.ast.type.PrimitiveType |
|
|
|
import com.github.javaparser.ast.type.PrimitiveType |
|
|
|
|
|
|
|
import com.github.javaparser.resolution.types.ResolvedArrayType |
|
|
|
import com.github.javaparser.resolution.types.ResolvedPrimitiveType |
|
|
|
import com.github.javaparser.resolution.types.ResolvedPrimitiveType |
|
|
|
|
|
|
|
import com.github.javaparser.resolution.types.ResolvedReferenceType |
|
|
|
import com.github.javaparser.resolution.types.ResolvedType |
|
|
|
import com.github.javaparser.resolution.types.ResolvedType |
|
|
|
import com.github.michaelbull.logging.InlineLogger |
|
|
|
import com.github.michaelbull.logging.InlineLogger |
|
|
|
import dev.openrs2.deob.ast.Library |
|
|
|
import dev.openrs2.deob.ast.Library |
|
|
@ -65,11 +69,11 @@ class GlTransformer @Inject constructor(private val registry: GlRegistry) : Tran |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun transformFramebufferStatus(unit: CompilationUnit, expr: Expression) { |
|
|
|
private fun transformFramebufferStatus(unit: CompilationUnit, expr: Expression) { |
|
|
|
if (!expr.isIntegerLiteralExpr) { |
|
|
|
if (expr !is IntegerLiteralExpr) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val value = expr.asIntegerLiteralExpr().checkedAsInt() |
|
|
|
val value = expr.checkedAsInt() |
|
|
|
if (value.toLong() != GL_FRAMEBUFFER_COMPLETE.value) { |
|
|
|
if (value.toLong() != GL_FRAMEBUFFER_COMPLETE.value) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -92,8 +96,8 @@ class GlTransformer @Inject constructor(private val registry: GlRegistry) : Tran |
|
|
|
|
|
|
|
|
|
|
|
private fun ResolvedType.isFollowedByOffset(): Boolean { |
|
|
|
private fun ResolvedType.isFollowedByOffset(): Boolean { |
|
|
|
return when { |
|
|
|
return when { |
|
|
|
isArray && asArrayType().componentType.isPrimitive -> true |
|
|
|
this is ResolvedArrayType && componentType.isPrimitive -> true |
|
|
|
isReferenceType && asReferenceType().qualifiedName == "java.lang.Object" -> true |
|
|
|
this is ResolvedReferenceType && qualifiedName == "java.lang.Object" -> true |
|
|
|
else -> false |
|
|
|
else -> false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -164,11 +168,11 @@ class GlTransformer @Inject constructor(private val registry: GlRegistry) : Tran |
|
|
|
|
|
|
|
|
|
|
|
expr.scope.ifPresent { scope -> |
|
|
|
expr.scope.ifPresent { scope -> |
|
|
|
val type = scope.calculateResolvedType() |
|
|
|
val type = scope.calculateResolvedType() |
|
|
|
if (!type.isReferenceType) { |
|
|
|
if (type !is ResolvedReferenceType) { |
|
|
|
return@ifPresent |
|
|
|
return@ifPresent |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val name = type.asReferenceType().qualifiedName |
|
|
|
val name = type.qualifiedName |
|
|
|
if (name in GL_CLASSES) { |
|
|
|
if (name in GL_CLASSES) { |
|
|
|
transformArguments(unit, expr) |
|
|
|
transformArguments(unit, expr) |
|
|
|
} |
|
|
|
} |
|
|
@ -235,16 +239,18 @@ class GlTransformer @Inject constructor(private val registry: GlRegistry) : Tran |
|
|
|
parameter: GlParameter, |
|
|
|
parameter: GlParameter, |
|
|
|
expr: Expression |
|
|
|
expr: Expression |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (expr.isBinaryExpr) { |
|
|
|
when (expr) { |
|
|
|
val binaryExpr = expr.asBinaryExpr() |
|
|
|
is BinaryExpr -> { |
|
|
|
transformExpr(unit, command, parameter, binaryExpr.left) |
|
|
|
transformExpr(unit, command, parameter, expr.left) |
|
|
|
transformExpr(unit, command, parameter, binaryExpr.right) |
|
|
|
transformExpr(unit, command, parameter, expr.right) |
|
|
|
} else if (expr.isConditionalExpr) { |
|
|
|
} |
|
|
|
val conditionalExpr = expr.asConditionalExpr() |
|
|
|
is ConditionalExpr -> { |
|
|
|
transformExpr(unit, command, parameter, conditionalExpr.thenExpr) |
|
|
|
transformExpr(unit, command, parameter, expr.thenExpr) |
|
|
|
transformExpr(unit, command, parameter, conditionalExpr.elseExpr) |
|
|
|
transformExpr(unit, command, parameter, expr.elseExpr) |
|
|
|
} else if (expr.isIntegerLiteralExpr) { |
|
|
|
} |
|
|
|
transformIntegerLiteralExpr(unit, command, parameter, expr) |
|
|
|
is IntegerLiteralExpr -> { |
|
|
|
|
|
|
|
transformIntegerLiteralExpr(unit, command, parameter, expr) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -252,9 +258,9 @@ class GlTransformer @Inject constructor(private val registry: GlRegistry) : Tran |
|
|
|
unit: CompilationUnit, |
|
|
|
unit: CompilationUnit, |
|
|
|
command: GlCommand, |
|
|
|
command: GlCommand, |
|
|
|
parameter: GlParameter, |
|
|
|
parameter: GlParameter, |
|
|
|
expr: Expression |
|
|
|
expr: IntegerLiteralExpr |
|
|
|
) { |
|
|
|
) { |
|
|
|
var value = expr.asIntegerLiteralExpr().checkedAsInt() |
|
|
|
var value = expr.checkedAsInt() |
|
|
|
val group = parameter.group ?: return |
|
|
|
val group = parameter.group ?: return |
|
|
|
|
|
|
|
|
|
|
|
if (parameter.bitfield) { |
|
|
|
if (parameter.bitfield) { |
|
|
@ -320,21 +326,21 @@ class GlTransformer @Inject constructor(private val registry: GlRegistry) : Tran |
|
|
|
|
|
|
|
|
|
|
|
private val FIELD_METHOD_COMPARATOR = Comparator<BodyDeclaration<*>> { a, b -> |
|
|
|
private val FIELD_METHOD_COMPARATOR = Comparator<BodyDeclaration<*>> { a, b -> |
|
|
|
when { |
|
|
|
when { |
|
|
|
a.isFieldDeclaration && !b.isFieldDeclaration -> -1 |
|
|
|
a is FieldDeclaration && b !is FieldDeclaration -> -1 |
|
|
|
!a.isFieldDeclaration && b.isFieldDeclaration -> 1 |
|
|
|
a !is FieldDeclaration && b is FieldDeclaration -> 1 |
|
|
|
else -> 0 |
|
|
|
else -> 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun BodyDeclaration<*>.getIntValue(): Int? { |
|
|
|
private fun BodyDeclaration<*>.getIntValue(): Int? { |
|
|
|
if (!isFieldDeclaration) { |
|
|
|
if (this !is FieldDeclaration) { |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val variable = asFieldDeclaration().variables.firstOrNull() ?: return null |
|
|
|
val variable = variables.firstOrNull() ?: return null |
|
|
|
return variable.initializer.map { |
|
|
|
return variable.initializer.map { |
|
|
|
if (it.isIntegerLiteralExpr) { |
|
|
|
if (it is IntegerLiteralExpr) { |
|
|
|
it.asIntegerLiteralExpr().checkedAsInt() |
|
|
|
it.checkedAsInt() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
null |
|
|
|
null |
|
|
|
} |
|
|
|
} |
|
|
|