Skip to content

Commit

Permalink
fix Boolean casting on temp vars
Browse files Browse the repository at this point in the history
  • Loading branch information
CST1229 committed Mar 30, 2024
1 parent 725aced commit 88b1fc3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions UndertaleModLib/Decompiler/Decompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ internal static void DecompileFromBlock(DecompileContext context, Dictionary<uin
{
Expression val = stack.Pop();
if (context.BooleanTypeEnabled && instr.Type1 == UndertaleInstruction.DataType.Boolean) {
val.CastToBoolean();
val.CastToBoolean(context);
}
stack.Push(new ExpressionCast(instr.Type2, val));
}
Expand All @@ -296,11 +296,11 @@ internal static void DecompileFromBlock(DecompileContext context, Dictionary<uin
case UndertaleInstruction.Opcode.Cmp:
Expression aa2 = stack.Pop();
if (context.BooleanTypeEnabled && instr.Type1 == UndertaleInstruction.DataType.Boolean) {
aa2.CastToBoolean();
aa2.CastToBoolean(context);
}
Expression aa1 = stack.Pop();
if (context.BooleanTypeEnabled && instr.Type2 == UndertaleInstruction.DataType.Boolean) {
aa1.CastToBoolean();
aa1.CastToBoolean(context);
}
stack.Push(new ExpressionCompare(instr.ComparisonKind, aa1, aa2));
break;
Expand Down Expand Up @@ -402,7 +402,7 @@ internal static void DecompileFromBlock(DecompileContext context, Dictionary<uin
if (val != null)
{
if (context.BooleanTypeEnabled && instr.Type2 == UndertaleInstruction.DataType.Boolean) {
val.CastToBoolean();
val.CastToBoolean(context);
}
if ((target.VarType == UndertaleInstruction.VariableType.StackTop || target.VarType == UndertaleInstruction.VariableType.Array) && target.InstType.WasDuplicated)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal virtual bool IsDuplicationSafe()
}

// Used for converting int constants to bool constants for 2.3.7+ code
internal virtual void CastToBoolean() {
internal virtual void CastToBoolean(DecompileContext context) {
Type = UndertaleInstruction.DataType.Boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal override bool IsDuplicationSafe()
return true;
}

internal override void CastToBoolean() {
internal override void CastToBoolean(DecompileContext context) {
Type = UndertaleInstruction.DataType.Boolean;
Value = Convert.ToBoolean(Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public override Statement CleanStatement(DecompileContext context, BlockHLStatem
return this;
}

internal override void CastToBoolean(DecompileContext context) {
Type = UndertaleInstruction.DataType.Boolean;
if (context.TempVarMap.ContainsKey(Var.Var.Name))
{
context.TempVarMap[Var.Var.Name].Value.CastToBoolean(context);
}
}

internal override AssetIDType DoTypePropagation(DecompileContext context, AssetIDType suggestedType)
{
if (Var.Var.AssetType == AssetIDType.Other)
Expand Down

0 comments on commit 88b1fc3

Please sign in to comment.