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.06k stars 205 forks source link

`switch` expression value type error. #1374

Open VladiStep opened 1 year ago

VladiStep commented 1 year ago

Describe the bug

The decompiler doesn't parse all the case values type, only the first one. Here's an example: case fnt_main:, but case 2:

switch myfont
{
    case fnt_main:
        if (ascciChar < 1025 || myletter == "Ә" || myletter == "ә")
            letterx += spacing
        else
            letterx += (string_width(myletter) + 3)
        break
    case 2:
        if (ascciChar < 1025 || myletter == "Ә" || myletter == "ә")
            letterx += spacing
        else
            letterx += (string_width(myletter) + 1)
        break
    case 4:
        if (ascciChar < 1025 || myletter == "Ә" || myletter == "ә")
            letterx += spacing
        else
            letterx += string_width(myletter)
        break
...

Reproducing steps

  1. Use switch in code.

Setup Details

  1. UTMT version - https://github.com/krzys-h/UndertaleModTool/commit/a71280878faa0874bf2f25730b251733f447af8c
Jacky720 commented 3 months ago

It appears this is because switch blocks are processed in reverse order (at least for type propagation) such that every case except the first is being compared to an untyped tempvar instead of the actual switch comparison. My best ideas for first steps at a fix would be to somehow fast-track the tempvar parsing or to try a second pass of the type propagation after high-level decompilation.