Skip to content

Commit

Permalink
properly convert object array to DynValue array for closure callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Sep 14, 2024
1 parent 1568df1 commit 61b31a1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions UniTAS/Patcher/Implementations/GUI/TerminalCommands/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,28 @@ private static bool PatchBody(int closureIndex, object __instance, object[] __ar
ref object __result)
{
var closure = PatchClosures[closureIndex];
var args = new List<object>();
var args = new List<DynValue>();
var script = closure.OwnerScript;
if (__instance != null)
{
args.Add(__instance);
args.Add(DynValue.FromObject(script, __instance));
}

if (__args != null)
{
args.Add(__args);
var argsDynValue = DynValue.NewTable(script);
for (var i = 0; i < __args.Length; i++)
{
var arg = __args[i];
argsDynValue.Table[i] = DynValue.FromObject(script, arg);
}

args.Add(argsDynValue);
}

if (PatchCanReturn[closureIndex])
{
args.Add(__result);
args.Add(DynValue.FromObject(script, __result));
}

var ret = closure.Call(args.ToArray());
Expand Down

0 comments on commit 61b31a1

Please sign in to comment.