From bab9ff3586fb5005fb4e625dc7f7867847881a06 Mon Sep 17 00:00:00 2001 From: haven1433 Date: Mon, 1 Dec 2025 06:55:08 -0600 Subject: [PATCH] fix crashes with curly braces --- src/HexManiac.Core/Models/Code/ScriptParser.cs | 4 ++-- src/HexManiac.Core/ViewModels/Tools/CodeBody.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HexManiac.Core/Models/Code/ScriptParser.cs b/src/HexManiac.Core/Models/Code/ScriptParser.cs index 74a376b1..c307e6b8 100644 --- a/src/HexManiac.Core/Models/Code/ScriptParser.cs +++ b/src/HexManiac.Core/Models/Code/ScriptParser.cs @@ -448,7 +448,7 @@ namespace HavenSoft.HexManiac.Core.Models.Code { break; } if (close == -1) { - if (i == caret) { + if (i == caret || (i == caret - 1 && caret == text.Count)) { text.Insert(i + 1, '\r'); text.Insert(i + 2, '\n'); } @@ -827,7 +827,7 @@ namespace HavenSoft.HexManiac.Core.Models.Code { partialDocumentation = candidates[0].Usage + Environment.NewLine + string.Join(Environment.NewLine, candidates[0].Documentation); } - if (context.Index > 0 && context.Line[context.Index - 1] == ' ' && tokens.Length > 0) { + if (context.Index > 0 && context.Index < context.Line.Length && context.Line[context.Index - 1] == ' ' && tokens.Length > 0) { // I'm directly after a space, I'm at the start of a new token, there is no existing documentation var skipCount = candidates[0].LineCode.Count; if (skipCount == 0) skipCount = 1; diff --git a/src/HexManiac.Core/ViewModels/Tools/CodeBody.cs b/src/HexManiac.Core/ViewModels/Tools/CodeBody.cs index bc1a46ce..9a7275e5 100644 --- a/src/HexManiac.Core/ViewModels/Tools/CodeBody.cs +++ b/src/HexManiac.Core/ViewModels/Tools/CodeBody.cs @@ -463,7 +463,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools { if (lines[i].Trim() == "{") { var type = queue.Count == 0 ? ExpectedPointerType.Unknown : queue.Dequeue(); i += 1; - while (lines[i].Trim() != "}") { + while (i < lines.Length && lines[i].Trim() != "}") { results.Add(new(i, type, lines[i])); i += 1; if (lines.Length <= i) break;