Skip to content

Functions using mixed arg.argumentN and builtin.argumentN don't decompile correctly #21

@misternebula

Description

@misternebula

Incorrect output observed

function scr_limitval_lower(arg0, arg1, arg2)
{
    var ____limiter = instance_create(x, y, obj_limit_val);
    ____limiter.limittype = 0;
    ____limiter.target = arg0;
    ____limiter.variablename = arg1;
    ____limiter.vallimit = arg2;
    
    if (argument_count >= 4)
        ____limiter.lifetime = argument3;
}

Expected output

function scr_limitval_lower()
{
    var ____limiter = instance_create(x, y, obj_limit_val);
    ____limiter.limittype = 0;
    ____limiter.target = argument0;
    ____limiter.variablename = argument1;
    ____limiter.vallimit = argument2;
    
    if (argument_count >= 4)
        ____limiter.lifetime = argument3;
}

VM assembly

> gml_Script_scr_limitval_lower (locals=1, argc=3)
:[1]
pushi.e 1372
conv.i.v
push.v self.y
push.v self.x
call.i gml_Script_instance_create(argc=3)
pop.v.v local.____limiter
pushi.e 0
pushloc.v local.____limiter
pushi.e -9
pop.v.i [stacktop]self.limittype
push.v arg.argument0
pushloc.v local.____limiter
pushi.e -9
pop.v.v [stacktop]self.target
push.v arg.argument1
pushloc.v local.____limiter
pushi.e -9
pop.v.v [stacktop]self.variablename
push.v arg.argument2
pushloc.v local.____limiter
pushi.e -9
pop.v.v [stacktop]self.vallimit
pushbltn.v builtin.argument_count
pushi.e 4
cmp.i.v GTE
bf [3]

:[2]
pushbltn.v builtin.argument3
pushloc.v local.____limiter
pushi.e -9
pop.v.v [stacktop]self.lifetime

:[3]
exit.i

Additional context
From DELTARUNE Chapter 3 - happens in all the other scripts in scr_limitval, as well as scr_couchtalk and possibly more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdecompilerInvolves the decompiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions