diff --git a/src/HexManiac.Core/Models/Code/tableReference.txt b/src/HexManiac.Core/Models/Code/tableReference.txt index 24ecfcb0..e0c8d1c3 100644 --- a/src/HexManiac.Core/Models/Code/tableReference.txt +++ b/src/HexManiac.Core/Models/Code/tableReference.txt @@ -43,12 +43,13 @@ battlescriptsource, , , , , , , , // sprites / palettes // bits x width x height. Width/Hegiht measured in tiles. -frontsprites, ,,,, 000128,,,, 000128, [sprite<`lzs4x8x8`> uncompressedLength: index:]440 -backsprites, ,,,, 00012C,,,, 00012C, [sprite<`lzs4x8x8`> uncompressedLength: index:]frontsprites -pokepalettes, ,,,, 000130,,,, 000130, [palette<`lzp4`> index: unused:]frontsprites -shinypalettes, ,,,, 000134,,,, 000134, [palette<`lzp4`> index: unused:]frontsprites -pokeicons, ,,,, 000138,,,, 000138, [icon<`ucs4x4x8|pokeiconpalindex`>]frontsprites -pokeiconpalindex, ,,,, 00013C,,,, 00013C, [index.pokeiconpalettes]frontsprites +// pakenames+28: egg, unown*27 (B-Z, !, ?), +frontsprites, ,,,, 000128,,,, 000128, [sprite<`lzs4x8x8`> uncompressedLength: index:]pokenames+28 +backsprites, ,,,, 00012C,,,, 00012C, [sprite<`lzs4x8x8`> uncompressedLength: index:]pokenames+28 +pokepalettes, ,,,, 000130,,,, 000130, [palette<`lzp4`> index: unused:]pokenames+28 +shinypalettes, ,,,, 000134,,,, 000134, [palette<`lzp4`> index: unused:]pokenames+28 +pokeicons, ,,,, 000138,,,, 000138, [icon<`ucs4x4x8|pokeiconpalindex`>]pokenames+28 +pokeiconpalindex, ,,,, 00013C,,,, 00013C, [index.pokeiconpalettes]pokenames+28 pokeiconpalettes, ,,,, 000140,,,, 000140, [palette<`ucp4`> id::]3 ballsprites, ,,,, 0001D0,,,, 0001D0, [sprite<`lzs4x2x6|ballpalettes`> uncompressedLength: a b]12 ballpalettes, ,,,, 0001D4,,,, 0001D4, [palette<`lzp4`> a b unused:]ballsprites diff --git a/src/HexManiac.Core/Models/Runs/ArrayRun.cs b/src/HexManiac.Core/Models/Runs/ArrayRun.cs index 6183ff9f..1dba5ffd 100644 --- a/src/HexManiac.Core/Models/Runs/ArrayRun.cs +++ b/src/HexManiac.Core/Models/Runs/ArrayRun.cs @@ -179,8 +179,10 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { } if (options.Count == ElementCount - ParentOffset && ParentOffset != 0) { + // if negative: pull values off the front if (ParentOffset < 0) options = options.Skip(-ParentOffset).ToList(); - else options = Enumerable.Repeat(string.Empty, ParentOffset).Concat(options).ToList(); + // if positive: add values onto the back + else options = options.Concat(Enumerable.Range(ElementCount, ParentOffset).Select(i => i.ToString())).ToList(); } return options; @@ -196,7 +198,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { if (!format.StartsWith(ArrayStart.ToString()) || closeArray == -1) throw new ArrayRunParseException($"Array Content must be wrapped in {ArrayStart}{ArrayEnd}."); var segments = format.Substring(1, closeArray - 1); var length = format.Substring(closeArray + 1); - if (!length.All(c => char.IsLetterOrDigit(c) || c == '-')) throw new ArrayRunParseException("Array length must be an anchor name or a number."); // the name might end with "-1" so also allow dashes + if (!length.All(c => char.IsLetterOrDigit(c) || c.IsAny('-', '+'))) throw new ArrayRunParseException("Array length must be an anchor name or a number."); // the name might end with "-1" so also allow +/- ElementContent = ParseSegments(segments, data); if (ElementContent.Count == 0) throw new ArrayRunParseException("Array Content must not be empty."); ElementLength = ElementContent.Sum(e => e.Length); @@ -257,7 +259,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { if (startArray == -1 || startArray > closeArray) return new ErrorInfo($"Array Content must be wrapped in {ArrayStart}{ArrayEnd}."); var length = format.Substring(closeArray + 1); - if (length.All(c => char.IsLetterOrDigit(c) || c == '-')) { + if (length.All(c => char.IsLetterOrDigit(c) || c.IsAny('-', '+'))) { // option 1: the length looks like a standard table length (or is empty, and thus dynamic). Parse as a table. try { using (ModelCacheScope.CreateScope(data)) { @@ -693,8 +695,9 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { private (string lengthFromAnchor, int parentOffset, int elementCount) ParseLengthFromAnchor(string length) { var parts = length.Split("-"); + if (parts.Length == 1) parts = length.Split("+"); if (parts.Length == 2 && int.TryParse(parts[1], out int parentOffset)) { - parentOffset = -parentOffset; + if (length.Contains("-")) parentOffset = -parentOffset; } else { parentOffset = 0; } diff --git a/src/HexManiac.Core/ViewModels/Tools/TableTool.cs b/src/HexManiac.Core/ViewModels/Tools/TableTool.cs index 858a20ba..cc0fc972 100644 --- a/src/HexManiac.Core/ViewModels/Tools/TableTool.cs +++ b/src/HexManiac.Core/ViewModels/Tools/TableTool.cs @@ -186,12 +186,13 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools { AddChildrenFromTable(array, index); if (array is ArrayRun arrayRun) { - index -= arrayRun.ParentOffset; + int negParentOffset = Math.Min(arrayRun.ParentOffset, 0); + index -= negParentOffset; if (!string.IsNullOrEmpty(arrayRun.LengthFromAnchor)) basename = arrayRun.LengthFromAnchor; // basename is now a 'parent table' name, if there is one foreach(var currentArray in model.GetRelatedArrays(arrayRun)) { var currentArrayName = model.GetAnchorFromAddress(-1, currentArray.Start); - var currentIndex = index + currentArray.ParentOffset; + var currentIndex = index + negParentOffset; if (currentIndex >= 0 && currentIndex < currentArray.ElementCount) { AddChild(new SplitterArrayElementViewModel(currentArrayName)); AddChildrenFromTable(currentArray, currentIndex);