Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Includes/Helpers/Chat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ 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;
u16 snakeID = 1;
u16 musicID = 0x660;
CTRPluginFramework::Item itemID = { 0x7FFE, 0 };
};
}
}
146 changes: 80 additions & 66 deletions Sources/Helpers/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -98,7 +98,78 @@ namespace CTRPluginFramework {
}
}

bool Chat::AnimationContext(const std::string &ID_8Bit) {
animID = StringToHex<u8>(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<u8>(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<u16>(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<u16>(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<u16>(ID_16Bit, 0x2001); //sets item
if(!itemID.isValid()) {
OSDExtras::Notify(TextID::INVALID_ITEM, Color::Red);
return false;
}
if(SPCommand == "f:") {
itemID.Flags = StringToHex<u16>(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;
}
Expand Down Expand Up @@ -127,83 +198,26 @@ namespace CTRPluginFramework {

//Item Name
std::string ItemName = PlayerText.substr(2, 23);

if(Command == "a:") {
animID = StringToHex<u8>(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<u8>(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<u16>(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<u16>(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<u16>(ID_16Bit, 0x2001); //sets item
if(itemID.isValid()) {
if(SPCommand == "f:") {
itemID.Flags = StringToHex<u16>(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();
Expand Down