From 8cbf50300860a8079d454799480b95eb3945ba84 Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Sun, 20 Jul 2025 10:16:36 -0500 Subject: [PATCH] Correct inverted if blocks in scripts --- libs/UIX.DecompXml/Decompiler.Script.cs | 47 +++++++++++++++++++++++-- test/ABOUTDIALOG.31_48_decomp.uix | 6 ++-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/libs/UIX.DecompXml/Decompiler.Script.cs b/libs/UIX.DecompXml/Decompiler.Script.cs index 3ccd15d..d1670b9 100644 --- a/libs/UIX.DecompXml/Decompiler.Script.cs +++ b/libs/UIX.DecompXml/Decompiler.Script.cs @@ -149,11 +149,11 @@ partial class Decompiler var jumpCondition = opCode switch { OpCode.JumpIfFalse or - OpCode.JumpIfFalsePeek => PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, rawJumpCondition), + OpCode.JumpIfFalsePeek => rawJumpCondition, - OpCode.JumpIfTruePeek => rawJumpCondition, + OpCode.JumpIfTruePeek => LogicalNotOf(rawJumpCondition), - OpCode.JumpIfNullPeek => BinaryExpression(SyntaxKind.EqualsExpression, + OpCode.JumpIfNullPeek => BinaryExpression(SyntaxKind.ExclamationEqualsToken, rawJumpCondition, LiteralExpression(SyntaxKind.NullLiteralExpression)), @@ -164,6 +164,9 @@ partial class Decompiler blockStack.Push(ifBlock); break; + case OpCode.ReturnVoid: + break; + default: if (!TryDecompileExpression(instruction, stack, blockStack)) throw new NotImplementedException(); @@ -366,6 +369,44 @@ partial class Decompiler return operationExpr; } + private static ExpressionSyntax LogicalNotOf(ExpressionSyntax originalExpression) + { + if (originalExpression is not BinaryExpressionSyntax binaryExpression) + goto defaultCase; + + SyntaxKind notOperatorToken; + switch (binaryExpression.OperatorToken.Kind()) + { + case SyntaxKind.EqualsEqualsToken: + notOperatorToken = SyntaxKind.ExclamationEqualsToken; + break; + + case SyntaxKind.LessThanToken: + notOperatorToken = SyntaxKind.GreaterThanEqualsToken; + break; + + case SyntaxKind.GreaterThanToken: + notOperatorToken = SyntaxKind.LessThanEqualsToken; + break; + + case SyntaxKind.LessThanEqualsToken: + notOperatorToken = SyntaxKind.GreaterThanToken; + break; + + case SyntaxKind.GreaterThanEqualsToken: + notOperatorToken = SyntaxKind.LessThanToken; + break; + + default: + goto defaultCase; + } + + return binaryExpression.WithOperatorToken(Token(notOperatorToken)); + + defaultCase: + return PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, originalExpression); + } + private static SyntaxKind OperationToSyntaxKind(OperationType operation) { return operation switch diff --git a/test/ABOUTDIALOG.31_48_decomp.uix b/test/ABOUTDIALOG.31_48_decomp.uix index 1f69c63..82ca396 100644 --- a/test/ABOUTDIALOG.31_48_decomp.uix +++ b/test/ABOUTDIALOG.31_48_decomp.uix @@ -1,11 +1,11 @@ - + - + @@ -15,7 +15,7 @@ ButtonCommands.Add(Dialog.Cancel); DefaultButtonModel = Dialog.Cancel; ButtonModelToFocus = Dialog.Cancel; -