Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of the "GameObjectCopy.csx" script. #1282

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion UndertaleModCli/Program.UMTLibInherited.cs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,6 @@ void ImportCode(string codeName, string gmlCode, bool isGML = true, bool doParse
locals.Locals.Add(argsLocal);

code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.CodeLocals.Add(locals);
}
if (doParse)
Expand Down
1 change: 0 additions & 1 deletion UndertaleModTool/ImportCodeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ void ImportCode(string codeName, string gmlCode, bool IsGML = true, bool doParse
locals.Locals.Add(argsLocal);

code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.CodeLocals.Add(locals);
}
if (doParse)
Expand Down
4 changes: 1 addition & 3 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,6 @@ private void MenuItem_Add_Click(object sender, RoutedEventArgs e)
argsLocal.Index = 0;
locals.Locals.Add(argsLocal);
code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals);
Data.CodeLocals.Add(locals);
}
(obj as UndertaleScript).Code = code;
Expand All @@ -2070,7 +2069,6 @@ private void MenuItem_Add_Click(object sender, RoutedEventArgs e)
argsLocal.Index = 0;
locals.Locals.Add(argsLocal);
(obj as UndertaleCode).LocalsCount = 1;
(obj as UndertaleCode).GenerateLocalVarDefinitions((obj as UndertaleCode).FindReferencedLocalVars(), locals);
Data.CodeLocals.Add(locals);
}
}
Expand Down Expand Up @@ -2562,7 +2560,7 @@ private async Task RunScriptNow(string path)

ScriptPath = path;

string compatScriptText = Regex.Replace(scriptText, @"\bDecompileContext\b", "GlobalDecompileContext", RegexOptions.None);
string compatScriptText = Regex.Replace(scriptText, @"\bDecompileContext(?!\.)\b", "GlobalDecompileContext", RegexOptions.None);
object result = await CSharpScript.EvaluateAsync(compatScriptText, scriptOptions, this, typeof(IScriptInterface));

if (FinishedMessageEnabled)
Expand Down
1 change: 0 additions & 1 deletion UndertaleModTool/Scripts/Helper Scripts/15_To_16.csx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ if ((Data?.GeneralInfo.BytecodeVersion == 14) || (Data?.GeneralInfo.BytecodeVers
locals.Locals.Add(argsLocal);

code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.CodeLocals.Add(locals);
}
}
Expand Down
16 changes: 15 additions & 1 deletion UndertaleModTool/Scripts/Resource Repackers/GameObjectCopy.csx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ string DonorDataPath = PromptLoadFile(null, null);
if (DonorDataPath == null)
throw new ScriptException("The donor data path was not set.");

bool compContextState = CompileContext.GMS2_3;
bool decompContextState = DecompileContext.GMS2_3;

using (var stream = new FileStream(DonorDataPath, FileMode.Open, FileAccess.Read))
DonorData = UndertaleIO.Read(stream, warning => ScriptMessage("A warning occured while trying to load " + DonorDataPath + ":\n" + warning));
var DonorDataEmbeddedTexturesCount = DonorData.EmbeddedTextures.Count;
DonorData.BuiltinList = new BuiltinList(DonorData);
AssetTypeResolver.InitializeTypes(DonorData);


CompileContext.GMS2_3 = compContextState;
DecompileContext.GMS2_3 = decompContextState;

bool donorIs2_3 = DonorData.IsVersionAtLeast(2, 3);

int copiedGameObjectsCount = 0;
List<string> splitStringsList = GetSplitStringsList("game object");
for (var j = 0; j < splitStringsList.Count; j++)
Expand Down Expand Up @@ -129,7 +138,13 @@ for (var j = 0; j < splitStringsList.Count; j++)
string codeToCopy = "";
try
{
CompileContext.GMS2_3 = donorIs2_3;
DecompileContext.GMS2_3 = donorIs2_3;

codeToCopy = (donorACT.CodeId != null ? Decompiler.Decompile(donorACT.CodeId, DECOMPILE_CONTEXT.Value) : "");

CompileContext.GMS2_3 = compContextState;
DecompileContext.GMS2_3 = decompContextState;
}
catch (Exception e)
{
Expand Down Expand Up @@ -167,7 +182,6 @@ for (var j = 0; j < splitStringsList.Count; j++)
nativelocals.Locals.Add(argsLocal);
}
nativeACT.CodeId.LocalsCount = (uint)nativelocals.Locals.Count;
nativeACT.CodeId.GenerateLocalVarDefinitions(nativeACT.CodeId.FindReferencedLocalVars(), nativelocals); // Dunno if we actually need this line, but it seems to work?
}
}
nativeACT.ArgumentCount = donorACT.ArgumentCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ for (var j = 0; j < splitStringsList.Count; j++)
nativelocals.Locals.Add(argsLocal);
}
nativeACT.CodeId.LocalsCount = (uint)nativelocals.Locals.Count;
nativeACT.CodeId.GenerateLocalVarDefinitions(nativeACT.CodeId.FindReferencedLocalVars(), nativelocals); // Dunno if we actually need this line, but it seems to work?
}
}
nativeACT.ArgumentCount = donorACT.ArgumentCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ await Task.Run(() => {
argsLocal.Index = 0;
locals.Locals.Add(argsLocal);
code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.CodeLocals.Add(locals);
}
if (doParse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ await Task.Run(() => {
locals.Locals.Add(argsLocal);

code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.CodeLocals.Add(locals);
}
if (doParse)
Expand Down
1 change: 0 additions & 1 deletion UndertaleModTool/Scripts/Technical Scripts/14_To_16.csx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ for (var i = 0; i < Data.Code.Count; i++)
locals.Locals.Add(argsLocal);

Data.Code[i].LocalsCount = 1;
Data.Code[i].GenerateLocalVarDefinitions(Data.Code[i].FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.Code[i].WeirdLocalFlag = false;
Data.CodeLocals.Add(locals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ if ((Data?.GeneralInfo.BytecodeVersion == 14) || (Data?.GeneralInfo.BytecodeVers
locals.Locals.Add(argsLocal);

code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.CodeLocals.Add(locals);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void DumpCode()
codeLocalsCount += 1;
}
code_orig.LocalsCount = codeLocalsCount;
code_orig.GenerateLocalVarDefinitions(code_orig.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
code_orig.ParentEntry = null;
}
else
Expand All @@ -83,7 +82,6 @@ void DumpCode()
argsLocal.Index = 0;
locals.Locals.Add(argsLocal);
code_orig.LocalsCount = 1;
code_orig.GenerateLocalVarDefinitions(code_orig.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
}
Data.CodeLocals.Add(locals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ foreach (UndertaleCode code in Data.Code)
argsLocal.Index = 0;
locals.Locals.Add(argsLocal);
code.LocalsCount = 1;
code.GenerateLocalVarDefinitions(code.FindReferencedLocalVars(), locals); // Dunno if we actually need this line, but it seems to work?
Data.CodeLocals.Add(locals);
newCount += 1;
}
Expand Down