UnderminersTeam / UndertaleModTool

The most complete tool for modding, decompiling and unpacking Undertale (and other Game Maker: Studio games!)
GNU General Public License v3.0
1.07k stars 205 forks source link

Issues decompiling Antonblast scripts #1110

Open TrashBandatcoot opened 1 year ago

TrashBandatcoot commented 1 year ago

Describe the bug

Some Antonblast scripts fail to decompile properly. An earlier build of UndertaleModTool (v94ea048) decompiled them just fine, but some builds later, either one of four error codes appear.

/*
DECOMPILER FAILED!

System.InvalidOperationException: Stack empty.
   at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
   at System.Collections.Generic.Stack`1.Pop()
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block, List`1 tempvars, Stack`1 workQueue) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2120
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2618
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3769
   at Submission#0.DumpCode(UndertaleCode code) in C:\X\UndertaleModTool\UTMT-Workflow\Scripts\Resource Unpackers\ExportAllCode.csx:line 89
*/

/*
DECOMPILER FAILED!

System.NullReferenceException: Object reference not set to an instance of an object.
   at UndertaleModLib.Decompiler.Decompiler.FunctionDefinition.ToString(DecompileContext context) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1386
   at UndertaleModLib.Decompiler.Decompiler.AssignmentStatement.ToString(DecompileContext context) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1181
   at UndertaleModLib.Decompiler.Decompiler.BlockHLStatement.ToString(DecompileContext context, Boolean canSkipBrackets, Boolean forceSkipBrackets) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2771
   at UndertaleModLib.Decompiler.Decompiler.WithHLStatement.ToString(DecompileContext context) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3164
   at UndertaleModLib.Decompiler.Decompiler.BlockHLStatement.ToString(DecompileContext context, Boolean canSkipBrackets, Boolean forceSkipBrackets) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2786
   at UndertaleModLib.Decompiler.Decompiler.IfHLStatement.ToString(DecompileContext context) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2972
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3789
   at Submission#0.DumpCode(UndertaleCode code) in C:\X\UndertaleModTool\UTMT-Workflow\Scripts\Resource Unpackers\ExportAllCode.csx:line 89
*/

/*
DECOMPILER FAILED!

System.NullReferenceException: Object reference not set to an instance of an object.
   at UndertaleModLib.Decompiler.Decompiler.FunctionDefinition.ToString(DecompileContext context) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1386
   at UndertaleModLib.Decompiler.Decompiler.AssignmentStatement.ToString(DecompileContext context) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1181
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3789
   at Submission#0.DumpCode(UndertaleCode code) in C:\X\UndertaleModTool\UTMT-Workflow\Scripts\Resource Unpackers\ExportAllCode.csx:line 89
*/

/*
DECOMPILER FAILED!

System.Exception: Reentered block with different amount of vars on stack (Entry: 1, Actual Count: 0)
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block, List`1 tempvars, Stack`1 workQueue) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1943
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2618
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3769
   at Submission#0.DumpCode(UndertaleCode code) in C:\X\UndertaleModTool\UTMT-Workflow\Scripts\Resource Unpackers\ExportAllCode.csx:line 89
*/

Reproducing steps

  1. Open UndertaleModTool, and go to Resource Unpackers > ExportAllCode.csx.
  2. Wait for the process to complete.
  3. Various scripts fail to decompile with one of four error codes above.

Setup Details

  1. UndertaleModTool version used: v6501d9a
  2. OS used: Windows 10 (64-bit)
  3. Game Maker game used: https://summitsphere.itch.io/antonblast-kickstarter-demo
Jacky720 commented 4 months ago

Is an older version of the demo available? The current Steam download uses YYC, which produces no code UTMT can work with at all.

TrashBandatcoot commented 4 months ago

Mirrored them here if you want to check it out: https://archive.org/download/antonblastdemo/Kickstarter%20Demo/

Jacky720 commented 4 months ago

Hmm. I downloaded v1.1.6 from your link, and went and compiled the tool from around the time it supposedly worked (June 2022), but all the same scripts still fail to decompile-- 9 with stack empty, 1 with reentered block with different number of variables. Is it specific to a different version, or were there additional decompiler errors that have since been resolved?

I'm not saying I intend to close this issue, but resolving the last ten is going to be trickier without decompilation from any version.

Jacky720 commented 3 months ago

Seems like one of the stack empty problems is the use of static variables, which invoke the isstaticok.e instruction that UTMT currently ignores, meaning the stack is missing the variable to indicate whether static is, in fact, ok. Three of the scripts still don't decompile, and recompiling the other seven with proper static implementation hasn't been implemented in the compiler.