Skip to content

Commit

Permalink
RE 2, room 301, fix random event crash
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Dec 8, 2023
1 parent 8ba57fd commit 90d9408
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion IntelOrca.Biohazard.BioRand/Rdt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ public void AddCustomScript()
if (insertIndex == -1)
throw new Exception("Unable to insert custom script");

insertIndex = FindNextLine(disassembly, insertIndex);
var nextProc = disassembly.IndexOf(".proc", insertIndex + 1);
var endOfFirstProc = disassembly.LastIndexOf("evt_end", nextProc);

insertIndex = FindStartOfLine(disassembly, endOfFirstProc);
disassembly = disassembly.Insert(insertIndex, " gosub biorand_custom\n");

var scdAssembler = new ScdAssembler();
Expand All @@ -430,6 +433,16 @@ public void AddCustomScript()
RdtFile = RdtFile.WithScd(BioScriptKind.Main, newScd);
}

private static int FindStartOfLine(string s, int startIndex)
{
var index = startIndex;
while (index < s.Length && s[index] != '\n' && s[index] != '\r')
{
index--;
}
return index + 1;
}

private static int FindNextLine(string s, int startIndex)
{
var index = startIndex;
Expand Down

0 comments on commit 90d9408

Please sign in to comment.