From 4b7548e99867d47a750c3916268d20050cde6067 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Thu, 11 Aug 2022 21:16:39 -0400 Subject: [PATCH] Throws exception if an invalid itemID is used Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r943694857 --- soh/soh/Enhancements/randomizer/randomizer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index baae0bca52..9a8cebae36 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -16,6 +16,7 @@ #include #include #include +#include using json = nlohmann::json; using namespace std::literals::string_literals; @@ -4580,6 +4581,18 @@ void Randomizer::CreateCustomMessages() { CreateScrubMessages(); } +class ExtendedVanillaTableInvalidItemIdException: public std::exception { + private: + s16 itemID; + + public: + ExtendedVanillaTableInvalidItemIdException(s16 itemID): itemID(itemID) {} + std::string what() { + return itemID + " is not a valid ItemID for the extendedVanillaGetItemTable. If you are adding a new" + "item, try adding it to randoGetItemTable instead."; + } +}; + void InitRandoItemTable() { // These entries have ItemIDs from vanilla, but not GetItemIDs or entries in the old sGetItemTable GetItemEntry extendedVanillaGetItemTable[] = { @@ -4702,8 +4715,7 @@ void InitRandoItemTable() { // We should never get here. If this branch of code executes, // then you've added an item to extendedVanillaGetItemTable that // should be in randoGetItemTable. - getItemID = RG_NONE; - break; + throw ExtendedVanillaTableInvalidItemIdException(extendedVanillaGetItemTable[i].itemId); } ItemTableManager::Instance->AddItemEntry(MOD_RANDOMIZER, getItemID, extendedVanillaGetItemTable[i]); }