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

UndertaleModCLI not compiling correctly after script modification #1146

Open DT-is-not-available opened 1 year ago

DT-is-not-available commented 1 year ago

Describe the bug

using UndertaleModCLI with the arguments UndertaleModCLI.exe load "data.win" -s "main.csx" -o "mod.win", and running a script that only uses AppendGML to add code to the game, running the modded game will either completely refuse to launch, or display this error message:

___________________________________________
ERROR in
action number 1
of Create Event
for object <undefined>:

Error attempting to load wad file with unexpected size 23870566 szFORM 23870302

running the script through the GUI works just fine, and it modifies and saves the game correctly, and you should get the error described above. i am trying to make a mod loader GUI for a gamemaker game that downloads and installs mods, and it uses this as the compiler/backend, so the CLI is really necessary.

Reproducing steps

  1. Install circloO on steam.
  2. create a batch file containing the text
    
    @echo off

echo Patching data.win path/to/UndertaleModCLI.exe load "data.win" -s "main.csx" -o "mod.win" echo Launching game... circloo2.exe -game "%cd%\cylindoO\mod.win"

pause

and place it in the directory `C:\Program Files (x86)\Steam\steamapps\common\circloO`
3. create the file `main.csx`
```c#
using System.Text;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

EnsureDataLoaded();

Data.GeneralInfo.DisplayName.Content += " (modded)";

UndertaleCode code = Data.Code.ByName("gml_Object_obj_renderer_Draw_75");

code.AppendGML(@"draw_sest_color(c_white)
drawplus_set_font(fnt_small)
draw_text(0, 0, "+'"cylindoO"'+")", Data);

ChangeSelection(code);

ScriptMessage("Scripts patched!");

and place it in the same directory

  1. run the batch file, which will automatically run the script and launch the game accordingly

Setup Details

  1. I am using the bleeding edge version of UndertaleModCLI produced 2 weeks ago.
  2. I am using Windows 10.
  3. I am attempting to mod the game circloO: https://store.steampowered.com/app/2195630/circloO/
Jacky720 commented 1 year ago

I don't have a fix yet for the bug you're encountering, but a piece of advice: you can use Data.Code.ByName("gml_Object_obj_renderer_Draw_75") rather than a separate for loop over every entry.

DT-is-not-available commented 1 year ago

Alright, thank you for the advice and for responding quickly. Is there any other workaround I can use until this is fixed without having the UndertaleModTool GUI visible?

Jacky720 commented 1 year ago

Well, looking at the error now, it seems like the script increased the size of the data file, but the CLI didn't remember to apply that change to the FORM header. I suppose the GUI version handles it automatically, but if you can find the exact value and change it manually, it might work. I'll trace the save process on both versions later.

DT-is-not-available commented 1 year ago

Alright, thanks for helping. A few more things and then I will leave you alone. Any idea if it's possible to do that within the script, and if so what value would I need to change? Or would I need to edit the file directly after it saves (at which point is there a specific location I should search for, or just find the bytes containing the value of the old filesize)

Jacky720 commented 1 year ago

It's probably possible to do within the script, but I don't know where the structure of Data.FORM is defined. Editing the file in post is also probably possible; I would guess that it's the second four bytes after "FORM", but you should check yourself. There can only be so many "23870302" uint32 values in a file.

DT-is-not-available commented 1 year ago

Alrighty, thanks for all the help!

DT-is-not-available commented 1 year ago

I did some more experimenting, and it appears that this error does not occur if you delete the output file before saving, and replacing the uint32 that contains the file size does not fix the runtime error originally provided. Not sure what is going on here, but removing the old output file before writing to it seems to work.

Jacky720 commented 1 year ago

It could be that the prompt to launch the game is running asynchronously with UndertaleModCLI, such that the file it starts loading is different to the one it finishes? Glad you found something that works.

Dobby233Liu commented 1 year ago

It could be that the prompt to launch the game is running asynchronously with UndertaleModCLI

If it is that case, OP, I suggest to do start /wait UndertaleModCLI (note that this may open a new window, but that should be avoidable with extra command switches)

DT-is-not-available commented 1 year ago

I am running UndertaleModCLI synchronously (which causes the window to display not responding while its running but thats an unrelated issue in the fact that it's running synchronously). I will try adding a delay between UntertaleModCLI closing and starting the game to see if that changes anything. (Forgot to mention an external program is controlling this now, I'm no longer using the batch file provided.)

Miepee commented 1 month ago

I did some more experimenting, and it appears that this error does not occur if you delete the output file before saving,

I thought i was the only one having that weird bug. It seems like the lib has some edge case where overwriting the original file doesnt work - something the gui also works around by just saving to a temp file first and then copying the temp file to the original.