From 53b4ed35e0cb8a7e17d3ec2d4d12e47da74b1d0e Mon Sep 17 00:00:00 2001 From: haven1433 Date: Sun, 1 Oct 2023 12:50:07 -0500 Subject: [PATCH] allow scripts to see scripts before they start --- src/HexManiac.Core/Models/Code/ScriptParser.cs | 2 +- src/HexManiac.Tests/CodeToolTests.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/HexManiac.Core/Models/Code/ScriptParser.cs b/src/HexManiac.Core/Models/Code/ScriptParser.cs index 025fa1ce..2338d692 100644 --- a/src/HexManiac.Core/Models/Code/ScriptParser.cs +++ b/src/HexManiac.Core/Models/Code/ScriptParser.cs @@ -879,7 +879,7 @@ namespace HavenSoft.HexManiac.Core.Models.Code { // (1) the run has no name // (2) the run has only one source (the script) if (run is NoInfoRun || run.PointerSources == null) return -1; - if (run is IScriptStartRun) return -1; // this script has a length, but don't track it (prevent recursion loop) + if (run is IScriptStartRun) return 1; // this script has a length, but don't calculate it (prevent recursion loop) if (run.PointerSources.Count == 1 && string.IsNullOrEmpty(model.GetAnchorFromAddress(-1, destination))) { return run.Length; } diff --git a/src/HexManiac.Tests/CodeToolTests.cs b/src/HexManiac.Tests/CodeToolTests.cs index faf8fa0d..a8bb9d59 100644 --- a/src/HexManiac.Tests/CodeToolTests.cs +++ b/src/HexManiac.Tests/CodeToolTests.cs @@ -873,5 +873,15 @@ label2:;goto <000050>;end"; Assert.Equal(8, run.Start); Assert.IsType(run); } + + [Fact] + public void ScriptGotoBeforeScriptStarts_Reload_IncludesSubScript() { + EventScript = "end"; + ViewPort.Goto.Execute(0x10); + + EventScript = "if.yes.goto ;end;section1:;if.yes.goto <000000>;end"; + + Assert.Equal(2, Tool.Contents.Count); + } } }