diff --git a/UndertaleModLib/Decompiler/Assembler.cs b/UndertaleModLib/Decompiler/Assembler.cs index d936ca1f6..9c22dda6d 100644 --- a/UndertaleModLib/Decompiler/Assembler.cs +++ b/UndertaleModLib/Decompiler/Assembler.cs @@ -227,8 +227,19 @@ public static UndertaleInstruction AssembleOne(string source, IList(f); + } } } else diff --git a/UndertaleModLib/Decompiler/Decompiler.cs b/UndertaleModLib/Decompiler/Decompiler.cs index d5aa564b7..932d2cf1b 100644 --- a/UndertaleModLib/Decompiler/Decompiler.cs +++ b/UndertaleModLib/Decompiler/Decompiler.cs @@ -706,6 +706,11 @@ assign.Value is FunctionDefinition funcDef && // Note that this operator peeks from the stack, it does not pop directly. break; case -11: // GM 2023.8+, pushref + if (instr.Function != null) + { + stack.Push(new ExpressionConstant(UndertaleInstruction.DataType.Int32, instr.Function)); + break; + } stack.Push(new ExpressionAssetRef(instr.IntArgument)); break; } diff --git a/UndertaleModLib/Decompiler/Disassembler.cs b/UndertaleModLib/Decompiler/Disassembler.cs index 5017c6718..7d5d63c40 100644 --- a/UndertaleModLib/Decompiler/Disassembler.cs +++ b/UndertaleModLib/Decompiler/Disassembler.cs @@ -11,7 +11,7 @@ public static class Disassembler { private static void AppendLocalVarDefinitionsToStringBuilder(StringBuilder sb, UndertaleCode code, IList vars, UndertaleCodeLocals locals) { - if (code.WeirdLocalFlag) + if (code.WeirdLocalFlag && locals is null) { return; } diff --git a/UndertaleModLib/Models/UndertaleCode.cs b/UndertaleModLib/Models/UndertaleCode.cs index 0be02a78b..8b15b11ea 100644 --- a/UndertaleModLib/Models/UndertaleCode.cs +++ b/UndertaleModLib/Models/UndertaleCode.cs @@ -363,10 +363,18 @@ public static void ParseReferenceChain(UndertaleReader reader, T obj) public Reference GetReference(bool allowResolve = false) where T : class, UndertaleObject, ReferencedObject { Reference res = (Destination as Reference) ?? (Function as Reference) ?? (Value as Reference); - if (allowResolve && res == null && Value is int val) + if (allowResolve && res == null) { - Value = new Reference(val); - return (Reference)Value; + if (Kind == Opcode.Break && Value is short breakType && breakType == -11 /* pushref */) + { + Function = new Reference(IntArgument); + return Function as Reference; + } + if (Value is int val) + { + Value = new Reference(val); + return (Reference)Value; + } } return res; } @@ -563,7 +571,13 @@ public void Serialize(UndertaleWriter writer) writer.Write((short)Value); writer.Write((byte)Type1); writer.Write((byte)Kind); - if (Type1 == DataType.Int32) writer.Write(IntArgument); + if (Type1 == DataType.Int32) + { + if (Function != null) + writer.WriteUndertaleObject(Function); + else + writer.Write(IntArgument); + } } break; @@ -1008,7 +1022,10 @@ public void ToString(StringBuilder stringBuilder, UndertaleCode code, List if (Type1 == DataType.Int32) { sbh.Append(stringBuilder, ' '); - sbh.Append(stringBuilder, IntArgument); + if (Function != null) + sbh.Append(stringBuilder, Function); + else + sbh.Append(stringBuilder, IntArgument); } break; }