From 1bc9f205f828ceacffb3dcc42254b2e1f4a019e1 Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Fri, 17 Dec 2021 21:38:57 -0800 Subject: [PATCH] pull in project-slippi/Ishiiruka/pull/275 --- Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp | 12 ++++++-- Source/Core/Core/Slippi/SlippiPremadeText.h | 32 ++++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp index 6ae1194dcb..d9188acf1e 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp @@ -2448,15 +2448,23 @@ std::vector CEXISlippi::loadPremadeText(u8* payload) u8 paramId = payload[1]; + for (auto it = spt.unsupportedStringMap.begin(); it != spt.unsupportedStringMap.end(); it++) + { + playerName = ReplaceAll(playerName.c_str(), it->second, ""); // Remove unsupported chars + playerName = ReplaceAll(playerName.c_str(), it->first, + it->second); // Remap delimiters for premade text + } + + // Replaces spaces with premade text space + playerName = ReplaceAll(playerName.c_str(), " ", ""); + if (paramId == SlippiPremadeText::CHAT_MSG_CHAT_DISABLED) { return premadeTextData = spt.GetPremadeTextData(SlippiPremadeText::SPT_CHAT_DISABLED, playerName.c_str()); } - auto chatMessage = spt.premadeTextsParams[paramId]; std::string param = ReplaceAll(chatMessage.c_str(), " ", ""); - playerName = ReplaceAll(playerName.c_str(), " ", ""); premadeTextData = spt.GetPremadeTextData(textId, playerName.c_str(), param.c_str()); } else diff --git a/Source/Core/Core/Slippi/SlippiPremadeText.h b/Source/Core/Core/Slippi/SlippiPremadeText.h index 99ea438319..6e614181e4 100644 --- a/Source/Core/Core/Slippi/SlippiPremadeText.h +++ b/Source/Core/Core/Slippi/SlippiPremadeText.h @@ -74,15 +74,21 @@ public: }; unordered_map premadeTexts = { - {SPT_CHAT_P1, "%s-%s"}, - {SPT_CHAT_P2, "%s-%s"}, - {SPT_CHAT_P3, "%s-%s"}, - {SPT_CHAT_P4, "%s-%s"}, + {SPT_CHAT_P1, "%s:%s"}, + {SPT_CHAT_P2, "%s:%s"}, + {SPT_CHAT_P3, "%s:%s"}, + {SPT_CHAT_P4, "%s:%s"}, {SPT_LOGOUT, "AreYouSure?"}, {SPT_CHAT_DISABLED, "%shaschatdisabled"}, }; + // This is just a map of delimiters and temporary replacements to remap them before the name is + // converted to Slippi Premade Text format + unordered_map unsupportedStringMap = { + {"<", "\\"}, {">", "`"}, {",", ""}, // DELETE U+007F + }; + // TODO: use va_list to handle any no. or args string GetPremadeTextString(u8 textId) { return premadeTexts[textId]; } @@ -190,6 +196,16 @@ public: { int chr = utfMatch[c]; + // We are manually replacing "<" for "\" and ">" for "`" because I don't want to handle + // vargs and we need to prevent "format injection" lol... + for (auto it = unsupportedStringMap.begin(); it != unsupportedStringMap.end(); it++) + { + if (it->second.find(chr) != std::string::npos || (chr == U'Ç' && it->first[0] == ',')) + { // Need to figure out how to find extended ascii chars (Ç) + chr = it->first[0]; + } + } + // Yup, fuck strchr and cpp too, I'm not in the mood to spend 4 more hours researching // how to get Japanese characters properly working with a map, so I put everything on an // int array in hex @@ -213,8 +229,7 @@ public: data.push_back(r); data.push_back(r2); } - else - return empty; + // otherwise ignore } } } @@ -415,11 +430,10 @@ private: U'ト', U'ド', U'ナ', U'ニ', U'ヌ', U'ネ', U'ノ', U'ハ', U'バ', U'パ', U'ヒ', U'ビ', U'ピ', U'フ', U'ブ', U'プ', U'ヘ', U'ベ', U'ペ', U'ホ', U'ボ', U'ポ', U'マ', U'ミ', U'ム', U'メ', U'モ', U'ャ', U'ヤ', U'ュ', U'ユ', U'ョ', U'ヨ', U'ラ', U'リ', U'ル', U'レ', U'ロ', U'ヮ', - U'ワ', U'ヲ', U'ン', U'ヴ', U'ヵ', U'ヶ', U' ', U'、', U'。', U',', U'.', U'•', U',', + U'ワ', U'ヲ', U'ン', U'ヴ', U'ヵ', U'ヶ', U' ', U'、', U'。', U',', U'.', U'•', U':', U';', U'?', U'!', U'^', U'_', U'—', U'/', U'~', U'|', U'\'', U'"', U'(', U')', U'[', U']', U'{', U'}', U'+', '-', U'×', U'=', U'<', U'>', U'¥', U'$', U'%', U'#', U'&', U'*', U'@', U'扱', U'押', U'軍', U'源', U'個', U'込', U'指', U'示', U'取', U'書', U'詳', U'人', U'生', U'説', U'体', U'団', U'電', U'読', U'発', U'抜', U'閑', U'本', - U'明', - }; + U'明'}; };