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

"Index was out of range" in decompiled tab for"scr_monstersetup" #82

Closed warestarstuff closed 5 years ago

warestarstuff commented 5 years ago

Going into deltarune's "scr_monstersetup" file and looking at the decompiled tab will get this error:

EXCEPTION!
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at UndertaleModLib.Decompiler.Decompiler.HLDecompileBlocks(Block& block, Dictionary`2 blocks, Dictionary`2 loops, Dictionary`2 reverseDominators, List`1 alreadyVisited, Block currentLoop, Boolean decompileTheLoop, Block stopAt) in C:\Users\krzys\Documents\Visual Studio 2017\Projects\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1427
   at UndertaleModLib.Decompiler.Decompiler.HLDecompile(Dictionary`2 blocks, Block entryPoint, Block rootExitPoint) in C:\Users\krzys\Documents\Visual Studio 2017\Projects\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1525
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, UndertaleData data) in C:\Users\krzys\Documents\Visual Studio 2017\Projects\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1577
   at UndertaleModTool.UndertaleCodeEditor.<>c__DisplayClass11_0.<DecompileCode>b__0() in C:\Users\krzys\Documents\Visual Studio 2017\Projects\UndertaleModTool\UndertaleModTool\Editors\UndertaleCodeEditor.xaml.cs:line 251

Should possibly be noted I am running the program as an administrator.

colinator27 commented 5 years ago

That's strange. I do not get this error, and I can't see how it would occur in the code either...

krzys-h commented 5 years ago

Last time I checked there were no errors when decompiking Deltarune. Did you change anything in the script? What version are you on?

warestarstuff commented 5 years ago

alright, for some reason i didn't even mention this thanks to me just waking up, its a modified "scr_monstersetup" file. Not heavily modified mind you- the only things changed are some HP values and some ATK things. However, this doesn't mean there isn't an issue, as I remember it used to display stuff in the decompiler before. Also the file doesn't bring up any weird issues in the actual game, everything works as I intended it to work.

Heres the code in the disassembly, by the way: https://pastebin.com/4BzCdktj

Sorry for the initial confusion in the original post.

edit: using the latest version of the mod tool, it used to work before the big decompiler update i believe, but dont take my word on it

krzys-h commented 5 years ago

You probably made an error somewhere in your modified script then. It's possible that the game still works since the runner does not check for every possible error for performance reasons, or the code path the error is in just never got triggered.

krzys-h commented 5 years ago

Also, either you didn't copy the whole disassembly or the script is broken because it ends on some push instructions without matching pop

warestarstuff commented 5 years ago

a tad odd, i did copy the whole thing i believe, i checked. i loaded my data.win from an earlier version of the undertalemodtool, and it didnt generate an error however

https://i.imgur.com/UbmfC6T.png

also at the bottom of the script is some extra code https://i.imgur.com/pkQQMHG.png so i suppose you are correct about push not matching pop, but the fact is that this version of the mod tool still displays it, strangely enough... ill mess with it a bit and see what happens

warestarstuff commented 5 years ago

managed to fix the issue, the error is no longer showing up. turns out it wasnt the tool's fault, which is pretty cool. For some reason on lines 5490 and such, it had "bf 06077" instead of "bf func_end". Why? Who knows. Anyway, it works great now! Thanks for the help.

krzys-h commented 5 years ago

func_end is an alias for "last line + 1", where GMS always adds an implicit ret instruction. This means that these weird instructions at the end must have been added in some strange way that didn't update the jumps. No idea how that happened, but glad you got it sorted out.