From 4be71c5e2c20b257aaebc1f5a9a6eb553fa86db6 Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Sun, 19 Dec 2021 10:47:50 -0800 Subject: [PATCH] refactor: make premade text maps const --- Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp | 2 +- Source/Core/Core/Slippi/SlippiPremadeText.h | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp index 6daded12c6..005036381c 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp @@ -2463,7 +2463,7 @@ std::vector CEXISlippi::loadPremadeText(u8* payload) return premadeTextData = spt.GetPremadeTextData(SlippiPremadeText::SPT_CHAT_DISABLED, playerName.c_str()); } - auto chatMessage = spt.premadeTextsParams[paramId]; + auto chatMessage = spt.premadeTextsParams.at(paramId); std::string param = ReplaceAll(chatMessage.c_str(), " ", ""); premadeTextData = spt.GetPremadeTextData(textId, playerName.c_str(), param.c_str()); } diff --git a/Source/Core/Core/Slippi/SlippiPremadeText.h b/Source/Core/Core/Slippi/SlippiPremadeText.h index 5f43cba06a..b8d4f991a6 100644 --- a/Source/Core/Core/Slippi/SlippiPremadeText.h +++ b/Source/Core/Core/Slippi/SlippiPremadeText.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once // This file must be encoded in UTF-8 with signatures on Windows #include @@ -46,7 +46,7 @@ public: CHAT_MSG_CHAT_DISABLED = 0x10, }; - std::unordered_map premadeTextsParams = { + const std::unordered_map premadeTextsParams = { {CHAT_MSG_U_PAD_UP, "ggs"}, {CHAT_MSG_U_PAD_LEFT, "one more"}, @@ -71,7 +71,7 @@ public: {CHAT_MSG_CHAT_DISABLED, "player has chat disabled"}, }; - std::unordered_map premadeTexts = { + const std::unordered_map premadeTexts = { {SPT_CHAT_P1, "%s:%s"}, {SPT_CHAT_P2, "%s:%s"}, {SPT_CHAT_P3, "%s:%s"}, @@ -83,12 +83,12 @@ public: // This is just a map of delimiters and temporary replacements to remap them before the name is // converted to Slippi Premade Text format - std::unordered_map unsupportedStringMap = { + const std::unordered_map unsupportedStringMap = { {"<", "\\"}, {">", "`"}, {",", ""}, // DELETE U+007F }; // TODO: use va_list to handle any no. or args - std::string GetPremadeTextString(u8 textId) { return premadeTexts[textId]; } + std::string GetPremadeTextString(u8 textId) { return premadeTexts.at(textId); } std::vector GetPremadeTextData(u8 textId, ...) { @@ -278,7 +278,7 @@ private: }; std::vector>> OPCODES; - std::unordered_map> CODES = { + const std::unordered_map> CODES = { {TEXT_OP_CODE::CENTERED, std::pair("CENTER", "")}, {TEXT_OP_CODE::RESET_CENTERED, std::pair("/CENTER", "")}, {TEXT_OP_CODE::CLEAR_COLOR, std::pair("/COLOR", "")}, @@ -310,9 +310,7 @@ private: std::pair> findCodeKey(std::string p) { - std::unordered_map>::iterator it; - - for (it = CODES.begin(); it != CODES.end(); it++) + for (auto it = CODES.begin(); it != CODES.end(); it++) { if (it->second.first == p) { @@ -345,7 +343,7 @@ private: } else { - std::pair code = CODES[opcode]; + std::pair code = CODES.at(opcode); auto p = code.second.c_str(); param = std::vector(strlen(p)); for (int j = 0; j < param.size(); j++) @@ -412,7 +410,7 @@ private: } // region CharMAPS - int CHAR_MAP[287] = { + const int CHAR_MAP[287] = { U'0', U'1', U'2', U'3', U'4', U'5', U'6', U'7', U'8', U'9', U'A', U'B', U'C', U'D', U'E', U'F', U'G', U'H', U'I', U'J', U'K', U'L', U'M', U'N', U'O', U'P', U'Q', U'R', U'S', U'T', U'U', U'V', U'W', U'X', U'Y', U'Z', U'a', U'b', U'c',