pull in project-slippi/Ishiiruka/pull/275

This commit is contained in:
Nikhil Narayana 2021-12-17 21:38:57 -08:00
commit 1bc9f205f8
2 changed files with 33 additions and 11 deletions

View file

@ -2448,15 +2448,23 @@ std::vector<u8> CEXISlippi::loadPremadeText(u8* payload)
u8 paramId = payload[1]; 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(), " ", "<S>");
if (paramId == SlippiPremadeText::CHAT_MSG_CHAT_DISABLED) if (paramId == SlippiPremadeText::CHAT_MSG_CHAT_DISABLED)
{ {
return premadeTextData = return premadeTextData =
spt.GetPremadeTextData(SlippiPremadeText::SPT_CHAT_DISABLED, playerName.c_str()); spt.GetPremadeTextData(SlippiPremadeText::SPT_CHAT_DISABLED, playerName.c_str());
} }
auto chatMessage = spt.premadeTextsParams[paramId]; auto chatMessage = spt.premadeTextsParams[paramId];
std::string param = ReplaceAll(chatMessage.c_str(), " ", "<S>"); std::string param = ReplaceAll(chatMessage.c_str(), " ", "<S>");
playerName = ReplaceAll(playerName.c_str(), " ", "<S>");
premadeTextData = spt.GetPremadeTextData(textId, playerName.c_str(), param.c_str()); premadeTextData = spt.GetPremadeTextData(textId, playerName.c_str(), param.c_str());
} }
else else

View file

@ -74,15 +74,21 @@ public:
}; };
unordered_map<u8, string> premadeTexts = { unordered_map<u8, string> premadeTexts = {
{SPT_CHAT_P1, "<LEFT><KERN><COLOR, 229, 76, 76>%s-<S><COLOR, 255, 255, 255>%s<END>"}, {SPT_CHAT_P1, "<LEFT><KERN><COLOR, 229, 76, 76>%s:<S><COLOR, 255, 255, 255>%s<END>"},
{SPT_CHAT_P2, "<LEFT><KERN><COLOR, 59, 189, 255>%s-<S><COLOR, 255, 255, 255>%s<END>"}, {SPT_CHAT_P2, "<LEFT><KERN><COLOR, 59, 189, 255>%s:<S><COLOR, 255, 255, 255>%s<END>"},
{SPT_CHAT_P3, "<LEFT><KERN><COLOR, 255, 203, 4>%s-<S><COLOR, 255, 255, 255>%s<END>"}, {SPT_CHAT_P3, "<LEFT><KERN><COLOR, 255, 203, 4>%s:<S><COLOR, 255, 255, 255>%s<END>"},
{SPT_CHAT_P4, "<LEFT><KERN><COLOR, 0, 178, 2>%s-<S><COLOR, 255, 255, 255>%s<END>"}, {SPT_CHAT_P4, "<LEFT><KERN><COLOR, 0, 178, 2>%s:<S><COLOR, 255, 255, 255>%s<END>"},
{SPT_LOGOUT, "<FIT><COLOR, 243, 75, 75>Are<S>You<COLOR, 0, 175, 75><S>Sure?<END>"}, {SPT_LOGOUT, "<FIT><COLOR, 243, 75, 75>Are<S>You<COLOR, 0, 175, 75><S>Sure?<END>"},
{SPT_CHAT_DISABLED, {SPT_CHAT_DISABLED,
"<LEFT><KERN><COLOR, 0, 178, 2>%s<S><COLOR, 255, 255, 255>has<S>chat<S>disabled<S><END>"}, "<LEFT><KERN><COLOR, 0, 178, 2>%s<S><COLOR, 255, 255, 255>has<S>chat<S>disabled<S><END>"},
}; };
// 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<string, string> unsupportedStringMap = {
{"<", "\\"}, {">", "`"}, {",", ""}, // DELETE U+007F
};
// TODO: use va_list to handle any no. or args // TODO: use va_list to handle any no. or args
string GetPremadeTextString(u8 textId) { return premadeTexts[textId]; } string GetPremadeTextString(u8 textId) { return premadeTexts[textId]; }
@ -190,6 +196,16 @@ public:
{ {
int chr = utfMatch[c]; 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 // 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 // how to get Japanese characters properly working with a map, so I put everything on an
// int array in hex // int array in hex
@ -213,8 +229,7 @@ public:
data.push_back(r); data.push_back(r);
data.push_back(r2); data.push_back(r2);
} }
else // otherwise ignore
return empty;
} }
} }
} }
@ -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';', 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''};
};
}; };