diff --git a/Includes/Helpers/Chat.hpp b/Includes/Helpers/Chat.hpp index 5bac89e..fc3f30b 100644 --- a/Includes/Helpers/Chat.hpp +++ b/Includes/Helpers/Chat.hpp @@ -24,13 +24,19 @@ namespace CTRPluginFramework { protected: static void CommandCallback(void); - private: + private: void CommandLoop(void); void AnimationCommand(void); void EmotionCommand(void); void SnakeCommand(void); void MusicCommand(void); void ItemCommand(void); + bool AnimationContext(const std::string &ID_8Bit); + bool EmotionContext(const std::string &ID_8Bit); + bool SnakeContext(const std::string &ID_12Bit); + bool MusicContext(const std::string &ID_12Bit); + bool ItemContext(const std::string &ID_16Bit, const std::string &SPCommand, const std::string &SPID_16Bit); + bool NameContext(std::string &ItemName); u8 animID = 6; u8 emotionID = 1; @@ -38,4 +44,4 @@ namespace CTRPluginFramework { u16 musicID = 0x660; CTRPluginFramework::Item itemID = { 0x7FFE, 0 }; }; -} \ No newline at end of file +} diff --git a/Sources/Helpers/Chat.cpp b/Sources/Helpers/Chat.cpp index c386116..b52dccf 100644 --- a/Sources/Helpers/Chat.cpp +++ b/Sources/Helpers/Chat.cpp @@ -5,7 +5,7 @@ namespace CTRPluginFramework { u32 Chat::GetPlayerMessageData() { u8 _pID = Game::GetActualPlayerIndex(); - // swap your index with player 0 in order to get the correct pointer + //swap your index with player 0 in order to get the correct pointer if(_pID == Game::GetOnlinePlayerIndex()) { _pID = 0; } @@ -98,7 +98,78 @@ namespace CTRPluginFramework { } } + bool Chat::AnimationContext(const std::string &ID_8Bit) { + animID = StringToHex(ID_8Bit, 6); //sets animation + if(!IDList::AnimationValid(animID, GetPlayerIndex())) { + OSDExtras::Notify(TextID::CHAT_INVALID_ANIMATION, Color::Red); + return false; + } + AnimationCommand(); + return true; + } + + bool Chat::EmotionContext(const std::string &ID_8Bit) { + emotionID = StringToHex(ID_8Bit, 1); //sets emotion + if(!IDList::EmotionValid(emotionID)) { + OSDExtras::Notify(TextID::CHAT_INVALID_EMOTION, Color::Red); + return false; + } + EmotionCommand(); + return true; + } + + bool Chat::SnakeContext(const std::string &ID_12Bit) { + snakeID = StringToHex(ID_12Bit, 1); //sets snake + if(!IDList::SnakeValid(snakeID)) { + OSDExtras::Notify(TextID::CHAT_INVALID_SNAKE, Color::Red); + return false; + } + SnakeCommand(); + return true; + } + + bool Chat::MusicContext(const std::string &ID_12Bit) { + musicID = StringToHex(ID_12Bit, 0x660); //sets music + if(!IDList::MusicValid(musicID)) { + OSDExtras::Notify(TextID::CHAT_INVALID_MUSIC, Color::Red); + return false; + } + MusicCommand(); + return true; + } + + bool Chat::ItemContext(const std::string &ID_16Bit, const std::string &SPCommand, const std::string &SPID_16Bit) { + itemID.ID = StringToHex(ID_16Bit, 0x2001); //sets item + if(!itemID.isValid()) { + OSDExtras::Notify(TextID::INVALID_ITEM, Color::Red); + return false; + } + if(SPCommand == "f:") { + itemID.Flags = StringToHex(SPID_16Bit, 0); //sets flag + } + ItemCommand(); + return true; + } + + bool Chat::NameContext(std::string &ItemName) { + UtilsExtras::Trim(ItemName); + ItemNamePack match; + if (!Item::searchByKeyword(ItemName, match)) { + OSDExtras::Notify(TextID::CHAT_NO_ITEM_FOUND, Color::Red); + return false; + } + + itemID = Item(match.ID); //sets item + if(!itemID.isValid()) { //should always be true if orig file is used + OSDExtras::Notify(TextID::INVALID_ITEM, Color::Red); + return false; + } + ItemCommand(); + return true; + } + void Chat::CommandLoop() { + if(!IsPlayerMessageOnScreen()) { return; } @@ -127,83 +198,26 @@ namespace CTRPluginFramework { //Item Name std::string ItemName = PlayerText.substr(2, 23); - + if(Command == "a:") { - animID = StringToHex(ID_8Bit, 6); //sets animation - if(IDList::AnimationValid(animID, GetPlayerIndex())) { - AnimationCommand(); - } - else { - OSDExtras::Notify(TextID::CHAT_INVALID_ANIMATION, Color::Red); - return; - } + AnimationContext(ID_8Bit); } - else if(Command == "e:") { - emotionID = StringToHex(ID_8Bit, 1); //sets emotion - if(IDList::EmotionValid(emotionID)) { - EmotionCommand(); - } - else { - OSDExtras::Notify(TextID::CHAT_INVALID_EMOTION, Color::Red); - return; - } + EmotionContext(ID_8Bit); } - else if(Command == "s:") { - snakeID = StringToHex(ID_12Bit, 1); //sets snake - if(IDList::SnakeValid(snakeID)) { - SnakeCommand(); - } - else { - OSDExtras::Notify(TextID::CHAT_INVALID_SNAKE, Color::Red); - return; - } + SnakeContext(ID_12Bit); } - else if(Command == "m:") { - musicID = StringToHex(ID_12Bit, 0x660); //sets music - if(IDList::MusicValid(musicID)) { - MusicCommand(); - } - else { - OSDExtras::Notify(TextID::CHAT_INVALID_MUSIC, Color::Red); - return; - } + MusicContext(ID_12Bit); } - else if(Command == "i:") { - itemID.ID = StringToHex(ID_16Bit, 0x2001); //sets item - if(itemID.isValid()) { - if(SPCommand == "f:") { - itemID.Flags = StringToHex(SPID_16Bit, 0); //sets flag - } - ItemCommand(); - } - else { - OSDExtras::Notify(TextID::INVALID_ITEM, Color::Red); - return; - } + ItemContext(ID_16Bit, SPCommand, SPID_16Bit); } - else if(Command == "n:") { - UtilsExtras::Trim(ItemName); - ItemNamePack match; - if (!Item::searchByKeyword(ItemName, match)) { - OSDExtras::Notify(TextID::CHAT_NO_ITEM_FOUND, Color::Red); - return; - } - - itemID = Item(match.ID); //sets item - if(!itemID.isValid()) { //should always be true if orig file is used - OSDExtras::Notify(TextID::INVALID_ITEM, Color::Red); - return; - } - - ItemCommand(); + NameContext(ItemName); } - - else { // any other message + else { //any other message return; } ClearPlayerMessage();