Open-source multiplayer game server compatible with the RuneScape client https://www.openrs2.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
openrs2/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt

35 lines
1.1 KiB

package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.stmt.ForStmt
import dev.openrs2.deob.ast.util.hasSideEffects
import dev.openrs2.deob.ast.util.walk
class ForLoopConditionTransformer : Transformer() {
override fun transformUnit(
units: Map<String, CompilationUnit>,
unit: CompilationUnit
) {
unit.walk { stmt: ForStmt ->
stmt.compare.ifPresent { compare ->
if (!compare.isBinaryExpr) {
return@ifPresent
}
val expr = compare.asBinaryExpr()
if (expr.hasSideEffects()) {
return@ifPresent
}
val flipped = when (expr.operator) {
BinaryExpr.Operator.GREATER -> BinaryExpr.Operator.LESS
BinaryExpr.Operator.GREATER_EQUALS -> BinaryExpr.Operator.LESS_EQUALS
else -> return@ifPresent
}
stmt.setCompare(BinaryExpr(expr.right, expr.left, flipped))
}
}
}
}