UnderminersTeam / UndertaleModTool

The most complete tool for modding, decompiling and unpacking Undertale (and other GameMaker games!)
GNU General Public License v3.0
1.13k stars 215 forks source link

Error recompiling modified code with Underanalyzer #1916

Open ChronoVortex opened 5 days ago

ChronoVortex commented 5 days ago

Describe the bug

Attempting to make changes to the decompiled gml_GlobalScript_scrScore code file in the latest Void War release throws the following error:

---------------------------
Compiler error
---------------------------
Errors parsing code when trying to compile modified "gml_GlobalScript_scrScore":

Expected local variable declaration, got nothing around line 334, column 5.

Unexpected token in expression around line 334, column 9.

Malformed assignment statement.

Unexpected token in expression around line 336, column 5.

Malformed assignment statement.

Unexpected token in expression around line 353, column 24.

Expected ',' or ')' after argument in function call around line 353, column 13 (array_push).

Expected toke...
---------------------------
OK   
---------------------------

The code referenced by the error:

332 function crew_to_struct(argument0)
333 {
334     var struct, i, itm, assetName;
335     
336     struct = 
337     {
338         obj: objGN(argument0.object_index),
339         crewName: argument0.crewName,
340         baseName: argument0.baseName,
341         crewItems: [],
342         crewDead: crew_is_dead(argument0)
343     };
344     i = 0;
345     
346     repeat (4)
347     {
348         itm = ds_list_find_value(argument0.setItem, i);
349         
350         if (object_exists(itm))
351         {
352             assetName = objGN(itm);
353             array_push(struct.crewItems, assetName);
354         }
355         
356         i++;
357     }
358     
359     return struct;
360 }

The disassembly associated with the decomp (I think, not super familiar with this format so I'm not 100% certain):

> gml_Script_crew_to_struct (locals=4, argc=1)
:[201]
push.v arg.argument0
call.i gml_Script_crew_is_dead(argc=1)
push.v arg.argument0
pushi.e -9
push.v [stacktop]self.baseName
push.v arg.argument0
pushi.e -9
push.v [stacktop]self.crewName
push.v arg.argument0
pushi.e -9
push.v [stacktop]self.object_index
call.i gml_Script_objGN(argc=1)
b [203]

> gml_Script____struct___39_crew_to_struct_gml_GlobalScript_scrScore (locals=0, argc=0)
:[202]
pushi.e -15
pushi.e 0
push.v [array]self.argument
pop.v.v self.obj
pushi.e -15
pushi.e 1
push.v [array]self.argument
pop.v.v self.crewName
pushi.e -15
pushi.e 2
push.v [array]self.argument
pop.v.v self.baseName
push.i 168558591
setowner.e
call.i @@NewGMLArray@@(argc=0)
pop.v.v self.crewItems
pushi.e -15
pushi.e 3
push.v [array]self.argument
pop.v.v self.crewDead
exit.i

:[203]
push.i [function]gml_Script____struct___39_crew_to_struct_gml_GlobalScript_scrScore
conv.i.v
call.i @@NullObject@@(argc=0)
call.i method(argc=2)
dup.v 0
pushi.e -16
pop.v.v [stacktop]static.___struct___39
call.i @@NewGMLObject@@(argc=5)
pop.v.v local.struct
pushi.e 0
pop.v.i local.i
pushi.e 4
dup.i 0
push.i 0
cmp.i.i LTE
bt [207]

:[204]
pushloc.v local.i
push.v arg.argument0
pushi.e -9
push.v [stacktop]self.setItem
call.i ds_list_find_value(argc=2)
pop.v.v local.itm
pushloc.v local.itm
call.i object_exists(argc=1)
conv.v.b
bf [206]

:[205]
pushloc.v local.itm
call.i gml_Script_objGN(argc=1)
pop.v.v local.assetName
pushloc.v local.assetName
pushloc.v local.struct
pushi.e -9
push.v [stacktop]self.crewItems
call.i array_push(argc=2)
popz.v

:[206]
push.v local.i
push.e 1
add.i.v
pop.v.v local.i
pushi.e 1
sub.i.i
dup.i 0
bt [204]

:[207]
popz.i
pushloc.v local.struct
ret.v

:[208]
exit.i

:[209]
push.i [function]gml_Script_crew_to_struct
conv.i.v
pushi.e -1
conv.i.v
call.i method(argc=2)
dup.v 0
pushi.e -6
pop.v.v [stacktop]self.crew_to_struct
popz.v
b [241]

Reproducing steps

Uncertain, haven't been able to replicate the issue starting from a blank GameMaker project.

Setup Details

  1. Latest from underanalyzer branch (8c5462c)
  2. Windows 10
  3. Void War Alpha Patch #​2 (https://tundra-interactive.itch.io/void-war)
Dobby233Liu commented 5 days ago

Note that the compiler is provided by UML instead of UA

Dobby233Liu commented 5 days ago

It seems like the compiler thinks struct is a reserved token, maybe change it to something else?

ChronoVortex commented 5 days ago

It seems like the compiler thinks struct is a reserved token, maybe change it to something else?

That does seem to fix it, though it's immediately replaced by a different error. If UA has a compiler that isn't set up to be used on the underanalyzer branch yet, then these issues that are cropping up will probably be resolved once that happens.

ChronoVortex commented 4 days ago

Just found this in the readme for UA

At the time of writing, there are no concrete plans for a GML VM compiler as part of this project

So much for that, sounds like the UML compiler needs to be brought in-line with UA instead. Will open another issue for the new error that came up.