diff options
-rw-r--r-- | release-notes.md | 1 | ||||
-rw-r--r-- | src/TrainerMod/TrainerMod.cs | 30 |
2 files changed, 24 insertions, 7 deletions
diff --git a/release-notes.md b/release-notes.md index 797da19d..3dfa42ad 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,6 +14,7 @@ For players: * Fixed installer errors for some players when deleting files. * Fixed installer not ignoring potential game folders that don't contain a Stardew Valley exe. * Fixed installer not recognising Linux/Mac paths starting with `~/` or containing an escaped space. +* Fixed TrainerMod letting you add invalid items which may crash the game. * Fixed rare issue where mod dependencies would override SMAPI dependencies and cause unpredictable bugs. * Fixed errors in console command handlers causing the game to crash. diff --git a/src/TrainerMod/TrainerMod.cs b/src/TrainerMod/TrainerMod.cs index 1e668b42..5cbd1ae6 100644 --- a/src/TrainerMod/TrainerMod.cs +++ b/src/TrainerMod/TrainerMod.cs @@ -583,8 +583,13 @@ namespace TrainerMod } var item = new Object(itemID, count) { quality = quality }; - Game1.player.addItemByMenuIfNecessary(item); - this.Monitor.Log($"OK, added {item.Name} to your inventory.", LogLevel.Info); + if (item.Name == "Error Item") + this.Monitor.Log("There is no such item ID.", LogLevel.Error); + else + { + Game1.player.addItemByMenuIfNecessary(item); + this.Monitor.Log($"OK, added {item.Name} to your inventory.", LogLevel.Info); + } } else this.LogUsageError("The item ID must be an integer.", command); @@ -599,8 +604,13 @@ namespace TrainerMod if (args[0].IsInt()) { MeleeWeapon weapon = new MeleeWeapon(args[0].ToInt()); - Game1.player.addItemByMenuIfNecessary(weapon); - this.Monitor.Log($"OK, added {weapon.Name} to your inventory.", LogLevel.Info); + if (weapon.Name == null) + this.Monitor.Log("There is no such weapon ID.", LogLevel.Error); + else + { + Game1.player.addItemByMenuIfNecessary(weapon); + this.Monitor.Log($"OK, added {weapon.Name} to your inventory.", LogLevel.Info); + } } else this.LogUsageError("The weapon ID must be an integer.", command); @@ -614,9 +624,15 @@ namespace TrainerMod { if (args[0].IsInt()) { - Ring ring = new Ring(args[0].ToInt()); - Game1.player.addItemByMenuIfNecessary(ring); - this.Monitor.Log($"OK, added {ring.Name} to your inventory.", LogLevel.Info); + int ringID = args[0].ToInt(); + if (ringID < Ring.ringLowerIndexRange || ringID > Ring.ringUpperIndexRange) + this.Monitor.Log($"There is no such ring ID (must be between {Ring.ringLowerIndexRange} and {Ring.ringUpperIndexRange}).", LogLevel.Error); + else + { + Ring ring = new Ring(ringID); + Game1.player.addItemByMenuIfNecessary(ring); + this.Monitor.Log($"OK, added {ring.Name} to your inventory.", LogLevel.Info); + } } else this.Monitor.Log("<item> is invalid", LogLevel.Error); |