From 4a5f351d6fbd99942da9bd2cff9a44ef1339c6c5 Mon Sep 17 00:00:00 2001 From: haven1433 Date: Sat, 3 Dec 2022 22:50:33 -0600 Subject: [PATCH] final fixes for 0.5 givePokemon, use item constants fix crashes/errors in hover-tip logic for trainerbattle commands * tested that macros and array args still work right --- src/HexManiac.Core/Models/Code/ScriptParser.cs | 12 +++++++----- src/HexManiac.Core/Models/Code/scriptReference.txt | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/HexManiac.Core/Models/Code/ScriptParser.cs b/src/HexManiac.Core/Models/Code/ScriptParser.cs index 7195e5677..75a37276d 100644 --- a/src/HexManiac.Core/Models/Code/ScriptParser.cs +++ b/src/HexManiac.Core/Models/Code/ScriptParser.cs @@ -261,12 +261,11 @@ public byte[] Compile(ModelDelta token, IDataModel model, int start, ref string var streamStart = i + 1; var indentCount = 1; i += 1; - while (indentCount > 0) { + while (indentCount > 0 && lines.Length > i) { line = lines[i].Trim(); if (line == "{") indentCount += 1; if (line == "}") indentCount -= 1; i += 1; - if (i == lines.Length) break; } i -= 1; var streamEnd = i; @@ -413,13 +412,16 @@ public string GetHelp(IDataModel model, HelpContext context) { var checkToken = 1; while (candidates.Count > 1 && checkToken < tokens.Length) { if (!tokens[checkToken].TryParseHex(out var codeValue)) break; - candidates = candidates.Where(line => line.LineCode[checkToken] == codeValue).ToList(); + candidates = candidates.Where(line => line.LineCode.Count <= checkToken || line.LineCode[checkToken] == codeValue).ToList(); + checkToken++; } var syntax = candidates.FirstOrDefault(); if (syntax != null) { var args = syntax.Args.Where(arg => arg is ScriptArg).ToList(); - if (args.Count + 1 > tokens.Length) { - var arg = args[tokens.Length - 2]; + var skipCount = syntax.LineCode.Count; + if (skipCount == 0) skipCount = 1; // macros + if (args.Count + skipCount > tokens.Length && tokens.Length >= skipCount + 1) { + var arg = args[tokens.Length - 1 - skipCount]; if (!string.IsNullOrEmpty(arg.EnumTableName)) { var options = model.GetOptions(arg.EnumTableName).Where(option => option.MatchesPartial(tokens[tokens.Length - 1])).ToList(); if (options.Count > 10) { diff --git a/src/HexManiac.Core/Models/Code/scriptReference.txt b/src/HexManiac.Core/Models/Code/scriptReference.txt index d777b35d2..a0745cfc2 100644 --- a/src/HexManiac.Core/Models/Code/scriptReference.txt +++ b/src/HexManiac.Core/Models/Code/scriptReference.txt @@ -182,7 +182,7 @@ msgbox.item 0F 00 msg<""> 1A 00 80 item:data.items.stats 1A 01 80 count: 1A 76 hidepokepic # hides all shown pokepics 77 showcontestwinner contest. # nop in FireRed. Shows the painting of a wenner of the given contest. 78 braille text<> # displays a message in braille. The text must be formatted to use braille. -79 givePokemon species:data.pokemon.names level. item: filler. filler:: filler:: +79 givePokemon species:data.pokemon.names level. item:data.items.stats filler. filler:: filler:: # gives the player one of that pokemon. the last 9 bytes are all 00. # 800D=0 if it was added to the party # 800D=1 if it was put in the PC