UnderminersTeam / UndertaleModTool

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

Possibly a bug with Code.ByName, or maybe I'm just stupid #1162

Closed DT-is-not-available closed 1 year ago

DT-is-not-available commented 1 year ago

Describe the bug

Using UndertaleModCLI to run scripts, using Data.Code.ByName(name).Replace(Assembler.Assemble()) to change the assembly of a script (specifically gml_GlobalScript_legui_create_settings_windows from circloO) throws the error

System.NullReferenceException: Object reference not set to an instance of an object.
   at UndertaleModLib.Decompiler.Assembler.Assemble(String source, IList`1 funcs, IList`1 vars, IList`1 strg, UndertaleData data) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Assembler.cs:line 268
   at Submission#0.<<Initialize>>d__0.MoveNext() in C:\Users\DT\Documents\cylindoO\main.csx:line 494
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.ScriptStateTaskExtensions.GetEvaluationResultAsync[T](Task`1 task)
   at UndertaleModCli.Program.RunCSharpCode(String code, String scriptFile) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModCli\Program.cs:line 724

When I try editing the file in the GUI however, it

  1. has no issue changing assembly code.
  2. hangs on the compiling window if I try to change any gml.
The file looks like this when decompiled ```gml function legui_create_settings_window() //gml_Script_legui_create_settings_window { if (windowRelatedTo == "settings") { legui_destroy_window() return; } legui_create_basic_window("Level settings") windowRelatedTo = "settings" var windowToolbar = legui_add_variable_update_to_window("Starting gravity: {}", function() //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_282_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { return obj_leveleditor.startingGravity; } , function(argument0) //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_338_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { obj_leveleditor.startingGravity = argument0 return; } , 2, 0, 2) legui_toolbar_add_button(windowToolbar, legui_create_button(16, function() //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_512_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { return obj_leveleditor.gravity_dir == 90; } , -1, function() //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_574_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { obj_leveleditor.gravity_dir = 90 return; } , -1, "")) legui_toolbar_add_button(windowToolbar, legui_create_button(118, function() //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_729_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { return obj_leveleditor.gravity_dir == 270; } , -1, function() //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_792_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { obj_leveleditor.gravity_dir = 270 return; } , -1, "")) legui_add_variable_update_to_window("COLOR{}", function() //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_903_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { return obj_leveleditor.levelColors; } , function(argument0) //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_955_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { obj_leveleditor.levelColors = argument0 return; } , 5, 0, 255) legui_add_variable_update_to_window("Level parts: {}", function() //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_1098_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { return obj_leveleditor.totalCircles; } , function(argument0) //gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_1151_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows { obj_leveleditor.totalCircles = argument0 return; } , 3, 3, 7) legui_finish_basic_window() return; } ```
and this when disassembled: ```asm .localvar 2 arguments .localvar 2157 windowToolbar 2044 :[0] b [29] > gml_Script_legui_create_settings_window (locals=1, argc=0) :[1] push.v self.windowRelatedTo push.s "settings"@2613 cmp.s.v EQ bf [3] :[2] call.i gml_Script_legui_destroy_window(argc=0) popz.v exit.i :[3] push.s "Level settings"@2614 conv.s.v call.i gml_Script_legui_create_basic_window(argc=1) popz.v push.s "settings"@2613 pop.v.s self.windowRelatedTo pushi.e 2 conv.i.v pushi.e 0 conv.i.v pushi.e 2 conv.i.v b [5] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_338_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=1) :[4] push.v arg.argument0 pop.v.v 85.startingGravity exit.i :[5] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_338_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) b [8] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_282_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=0) :[6] push.v 85.startingGravity ret.v :[7] exit.i :[8] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_282_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) push.s "Starting gravity: {}"@2617 conv.s.v call.i gml_Script_legui_add_variable_update_to_window(argc=6) pop.v.v local.windowToolbar push.s ""@172 conv.s.v pushi.e -1 conv.i.v b [10] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_574_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=0) :[9] pushi.e 90 pop.v.i 85.gravity_dir exit.i :[10] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_574_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) pushi.e -1 conv.i.v b [13] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_512_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=0) :[11] push.v 85.gravity_dir pushi.e 90 cmp.i.v EQ conv.b.v ret.v :[12] exit.i :[13] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_512_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) pushi.e 16 conv.i.v call.i gml_Script_legui_create_button(argc=6) pushloc.v local.windowToolbar call.i gml_Script_legui_toolbar_add_button(argc=2) popz.v push.s ""@172 conv.s.v pushi.e -1 conv.i.v b [15] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_792_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=0) :[14] pushi.e 270 pop.v.i 85.gravity_dir exit.i :[15] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_792_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) pushi.e -1 conv.i.v b [18] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_729_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=0) :[16] push.v 85.gravity_dir pushi.e 270 cmp.i.v EQ conv.b.v ret.v :[17] exit.i :[18] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_729_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) pushi.e 118 conv.i.v call.i gml_Script_legui_create_button(argc=6) pushloc.v local.windowToolbar call.i gml_Script_legui_toolbar_add_button(argc=2) popz.v pushi.e 255 conv.i.v pushi.e 0 conv.i.v pushi.e 5 conv.i.v b [20] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_955_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=1) :[19] push.v arg.argument0 pop.v.v 85.levelColors exit.i :[20] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_955_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) b [23] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_903_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=0) :[21] push.v 85.levelColors ret.v :[22] exit.i :[23] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_903_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) push.s "COLOR{}"@2624 conv.s.v call.i gml_Script_legui_add_variable_update_to_window(argc=6) popz.v pushi.e 7 conv.i.v pushi.e 3 conv.i.v pushi.e 3 conv.i.v b [25] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_1151_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=1) :[24] push.v arg.argument0 pop.v.v 85.totalCircles exit.i :[25] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_1151_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) b [28] > gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_1098_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows (locals=0, argc=0) :[26] push.v 85.totalCircles ret.v :[27] exit.i :[28] push.i gml_Script_anon_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows_1098_legui_create_settings_window_gml_GlobalScript_legui_create_settings_windows conv.i.v pushi.e -1 conv.i.v call.i method(argc=2) push.s "Level parts: {}"@2627 conv.s.v call.i gml_Script_legui_add_variable_update_to_window(argc=6) popz.v call.i gml_Script_legui_finish_basic_window(argc=0) popz.v exit.i :[29] push.i gml_Script_legui_create_settings_window 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.legui_create_settings_window popz.v :[end] ```

Am I missing something, or is this an issue with the CLI? Using the GUI isn't really an option for what I'm trying to do. Other global scripts and object scripts work just fine, so I'm not sure what is wrong with this one.

Reproducing steps

  1. Download circloO
  2. Using UndertaleModCLI, use a script containing a call to Data.Code.ByName("gml_GlobalScript_legui_create_settings_windows").Replace(Assembler.Assemble(any_valid_gml_ASM, Data.Functions, Data.Variables, Data.Strings))
  3. See the error

Setup Details

  1. UndertaleModCLI, previous bleeding edge
  2. Windows 10
  3. https://store.steampowered.com/app/2195630/circloO/
Dobby233Liu commented 1 year ago
UndertaleModLib.Decompiler.Assembler.Assemble(String source, IList funcs, IList vars, IList strg, *UndertaleData data*)
DT-is-not-available commented 1 year ago

Yup ok I'm just stupid. Thanks!