Update to work with UTMT 0.8.x

This commit is contained in:
OleSTEEP 2025-05-14 02:53:05 +03:00
parent 6ec4691448
commit 81e89b84fc
2 changed files with 25 additions and 15 deletions

View file

@ -10,12 +10,13 @@ using System.Reflection;
using UndertaleModLib.Models;
using UndertaleModLib.Util;
using UndertaleModLib.Decompiler;
using Underanalyzer.Decompiler;
string GameName = Data.GeneralInfo.Name.ToString().Replace(@"""",""); //Name == "Project" -> Project
int progress = 0;
string projFolder = GetFolder(FilePath) + GameName + ".gmx" + Path.DirectorySeparatorChar;
TextureWorker worker = new TextureWorker();
ThreadLocal<DecompileContext> DECOMPILE_CONTEXT = new ThreadLocal<DecompileContext>(() => new DecompileContext(Data, false));
TextureWorker worker = new();
GlobalDecompileContext decompileContext = new(Data);
string gmxDeclaration = "This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!";
string eol = "\n"; // Linux: "\n", Windows: "\r\n"
@ -70,7 +71,7 @@ await ExportTimelines();
GenerateProjectFile();
// --------------- Export completed ---------------
worker.Cleanup();
worker.Dispose(); // worker.Cleanup()?
HideProgressBar();
ScriptMessage("Export Complete.\n\nLocation: " + projFolder);
@ -269,6 +270,13 @@ void ExportGameObject(UndertaleGameObject gameObject)
// Traversing the action list
foreach (var k in j.Actions)
{
DecompileContext dec_context = new(decompileContext, k.CodeId, Data.ToolInfo.DecompilerSettings);
XElement act_string = null;
try {
act_string = new XElement("string", (k.CodeId != null && dec_context != null) ? dec_context.DecompileToString() : "");
} catch (DecompilerException) {
act_string = new XElement("string", "");
}
actionNode.Add(
new XElement("libid", k.LibID.ToString()),
new XElement("id", k.ID.ToString()),
@ -277,7 +285,7 @@ void ExportGameObject(UndertaleGameObject gameObject)
new XElement("isquestion", BoolToString(k.IsQuestion)),
new XElement("useapplyto", BoolToString(k.UseApplyTo)),
new XElement("exetype", k.ExeType.ToString()),
new XElement("functionname", k.ActionName.Content),
new XElement("functionname", k.ActionName != null ? k.ActionName.Content : ""),
new XElement("codestring", ""),
new XElement("whoName", "self"),
new XElement("relative", BoolToString(k.Relative)),
@ -285,7 +293,7 @@ void ExportGameObject(UndertaleGameObject gameObject)
new XElement("arguments",
new XElement("argument",
new XElement("kind", "1"),
new XElement("string", k.CodeId != null ? Decompiler.Decompile(k.CodeId, DECOMPILE_CONTEXT.Value) : "")
act_string
)
)
);
@ -324,10 +332,10 @@ void ExportRoom(UndertaleRoom room)
new XElement("persistent", BoolToString(room.Persistent)),
new XElement("colour", room.BackgroundColor.ToString()),
new XElement("showcolour", BoolToString(room.DrawBackgroundColor)),
new XElement("code", room.CreationCodeId != null ? Decompiler.Decompile(room.CreationCodeId, DECOMPILE_CONTEXT.Value) : ""),
new XElement("code", room.CreationCodeId != null ? new DecompileContext(decompileContext, room.CreationCodeId).DecompileToString() : ""),
new XElement("enableViews", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.EnableViews))),
new XElement("clearViewBackground", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ShowColor))),
new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer))),
//new XElement("clearDisplayBuffer", BoolToString(room.Flags.HasFlag(UndertaleRoom.RoomEntryFlags.ClearDisplayBuffer))),
new XElement("makerSettings",
new XElement("isSet", 0),
new XElement("w", 0),
@ -357,8 +365,8 @@ void ExportRoom(UndertaleRoom room)
new XAttribute("name", i.BackgroundDefinition is null ? "" : i.BackgroundDefinition.Name.Content),
new XAttribute("x", i.X.ToString()),
new XAttribute("y", i.Y.ToString()),
new XAttribute("htiled", i.TileX.ToString()),
new XAttribute("vtiled", i.TileY.ToString()),
new XAttribute("htiled", i.X.ToString()),
new XAttribute("vtiled", i.Y.ToString()),
new XAttribute("hspeed", i.SpeedX.ToString()),
new XAttribute("vspeed", i.SpeedY.ToString()),
new XAttribute("stretch", "0")
@ -401,7 +409,7 @@ void ExportRoom(UndertaleRoom room)
new XAttribute("y", i.Y.ToString()),
new XAttribute("name", "inst_" + i.InstanceID.ToString("X")),
new XAttribute("locked", "0"),
new XAttribute("code", i.CreationCode != null ? Decompiler.Decompile(i.CreationCode, DECOMPILE_CONTEXT.Value) : ""),
new XAttribute("code", i.CreationCode != null ? new DecompileContext(decompileContext, i.CreationCode).DecompileToString() : ""),
new XAttribute("scaleX", i.ScaleX.ToString()),
new XAttribute("scaleY", i.ScaleY.ToString()),
new XAttribute("colour", i.Color.ToString()),
@ -512,7 +520,7 @@ void ExportScript(UndertaleScript script)
UpdateProgressBar(null, $"Exporting script: {script.Name.Content}", progress++, resourceNum);
// Save GML files
File.WriteAllText(projFolder + "/scripts/" + script.Name.Content + ".gml", (script.Code != null ? Decompiler.Decompile(script.Code, DECOMPILE_CONTEXT.Value) : ""));
File.WriteAllText(projFolder + "/scripts/" + script.Name.Content + ".gml", script.Code != null ? new DecompileContext(decompileContext, script.Code).DecompileToString() : "");
}
// --------------- Export Font ---------------
@ -622,9 +630,9 @@ void ExportTimeline(UndertaleTimeline timeline)
foreach (var i in timeline.Moments)
{
var entryNode = new XElement("entry");
entryNode.Add(new XElement("step", i.Item1));
entryNode.Add(new XElement("step", i.Step));
entryNode.Add(new XElement("event"));
foreach (var j in i.Item2)
foreach (var j in i.Event)
{
entryNode.Element("event").Add(
new XElement("action",
@ -643,7 +651,7 @@ void ExportTimeline(UndertaleTimeline timeline)
new XElement("arguments",
new XElement("argument",
new XElement("kind", "1"),
new XElement("string", j.CodeId != null ? Decompiler.Decompile(j.CodeId, DECOMPILE_CONTEXT.Value) : "")
new XElement("string", j.CodeId != null ? new DecompileContext(decompileContext, j.CodeId).DecompileToString() : "")
)
)
)

View file

@ -2,4 +2,6 @@
This is a script for UndertaleModTool, which can export game files as project files of GameMaker Studio.
Currently compatible with gms1.4, will support gms2 in the future.
Currently compatible with gms1.4, will support gms2 in the future.
Original repo: https://github.com/cubeww/UndertaleModTool-ExportToProjectScript