From 3b05d0a9d50ec0b67e2acc743f5ffbe68e286281 Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Fri, 17 Dec 2021 21:24:48 -0800 Subject: [PATCH] pull in project-slippi/Ishiiruka/pull/256 --- Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp | 34 +- Source/Core/Core/Slippi/SlippiNetplay.cpp | 15 +- Source/Core/Core/Slippi/SlippiPremadeText.h | 326 ++----------------- 3 files changed, 76 insertions(+), 299 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp index 16f0deb4b7..0955517557 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp @@ -2039,19 +2039,33 @@ void CEXISlippi::prepareOnlineMatchState() // Set chat message if any if (slippi_netplay) { - auto remoteMessageSelection = slippi_netplay->GetSlippiRemoteChatMessage(); - chatMessageId = remoteMessageSelection.messageId; - chatMessagePlayerIdx = remoteMessageSelection.playerIdx; + auto isSingleMode = matchmaking && matchmaking->RemotePlayerCount() == 1; sentChatMessageId = slippi_netplay->GetSlippiRemoteSentChatMessage(); - // If connection is 1v1 set index 0 for local and 1 for remote - if ((matchmaking && matchmaking->RemotePlayerCount() == 1) || !matchmaking) + // Prevent processing a message in the same frame + if (sentChatMessageId <= 0) + { + auto remoteMessageSelection = slippi_netplay->GetSlippiRemoteChatMessage(); + chatMessageId = remoteMessageSelection.messageId; + chatMessagePlayerIdx = remoteMessageSelection.playerIdx; + if (chatMessageId == SlippiPremadeText::CHAT_MSG_CHAT_DISABLED && !isSingleMode) + { + // Clear remote chat messages if we are on teams and the player has chat disabled. + // Could also be handled on SlippiNetplay if the instance had acccess to the current + // connection mode + chatMessageId = chatMessagePlayerIdx = 0; + } + } + else + { + chatMessagePlayerIdx = localPlayerIndex; + } + + if (isSingleMode || !matchmaking) { chatMessagePlayerIdx = sentChatMessageId > 0 ? localPlayerIndex : remotePlayerIndex; } // in CSS p1 is always current player and p2 is opponent localPlayerName = p1Name = userInfo.display_name; - INFO_LOG_FMT(SLIPPI, "chatMessagePlayerIdx {} {}", chatMessagePlayerIdx, - matchmaking ? matchmaking->RemotePlayerCount() : 0); } std::vector leftTeamPlayers = {}; @@ -2436,6 +2450,12 @@ std::vector CEXISlippi::loadPremadeText(u8* payload) 0x88 : payload[1]; // TODO: Figure out what the hell is going on and fix this + 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(), " ", ""); diff --git a/Source/Core/Core/Slippi/SlippiNetplay.cpp b/Source/Core/Core/Slippi/SlippiNetplay.cpp index 81eb7e2f09..f88f770cc2 100644 --- a/Source/Core/Core/Slippi/SlippiNetplay.cpp +++ b/Source/Core/Core/Slippi/SlippiNetplay.cpp @@ -13,6 +13,7 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/NetPlayProto.h" +#include "SlippiPremadeText.h" #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/VideoConfig.h" @@ -358,8 +359,18 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet, ENetPeer* peer) case NetPlay::NP_MSG_SLIPPI_CHAT_MESSAGE: { auto playerSelection = ReadChatMessageFromPacket(packet); - INFO_LOG(SLIPPI_ONLINE, "[Netplay] Received chat message from opponent %d: %d", - playerSelection->playerIdx, playerSelection->messageId); + INFO_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Received chat message from opponent {}: {}", + playerSelection->playerIdx, playerSelection->messageId); + // if chat is not enabled, automatically send back a message saying so + if (!SConfig::GetInstance().m_slippiEnableQuickChat) + { + auto packet = std::make_unique(); + remoteSentChatMessageId = SlippiPremadeText::CHAT_MSG_CHAT_DISABLED; + WriteChatMessageToPacket(*packet, remoteSentChatMessageId, LocalPlayerPort()); + SendAsync(std::move(packet)); + remoteSentChatMessageId = 0; + break; + } // set message id to netplay instance remoteChatMessageSelection = std::move(playerSelection); } diff --git a/Source/Core/Core/Slippi/SlippiPremadeText.h b/Source/Core/Core/Slippi/SlippiPremadeText.h index c3908b9643..99ea438319 100644 --- a/Source/Core/Core/Slippi/SlippiPremadeText.h +++ b/Source/Core/Core/Slippi/SlippiPremadeText.h @@ -1,4 +1,5 @@ #pragma once +// This file must be encoded in UTF-8 with signatures on Windows #include #include @@ -8,6 +9,7 @@ #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" +#include "Common/StringUtil.h" using namespace std; @@ -21,6 +23,7 @@ public: SPT_CHAT_P3 = 0x3, SPT_CHAT_P4 = 0x4, SPT_LOGOUT = 0x5, + SPT_CHAT_DISABLED = 0x6, CHAT_MSG_U_PAD_LEFT = 0x81, CHAT_MSG_U_PAD_RIGHT = 0x82, @@ -41,6 +44,8 @@ public: CHAT_MSG_D_PAD_RIGHT = 0x42, CHAT_MSG_D_PAD_DOWN = 0x44, CHAT_MSG_D_PAD_UP = 0x48, + + CHAT_MSG_CHAT_DISABLED = 0x10, }; unordered_map premadeTextsParams = { @@ -64,6 +69,8 @@ public: {CHAT_MSG_D_PAD_LEFT, "thinking"}, {CHAT_MSG_D_PAD_RIGHT, "lets play again later"}, {CHAT_MSG_D_PAD_DOWN, "bad connection"}, + + {CHAT_MSG_CHAT_DISABLED, "player has chat disabled"}, }; unordered_map premadeTexts = { @@ -72,6 +79,8 @@ public: {SPT_CHAT_P3, "%s-%s"}, {SPT_CHAT_P4, "%s-%s"}, {SPT_LOGOUT, "AreYouSure?"}, + {SPT_CHAT_DISABLED, + "%shaschatdisabled"}, }; // TODO: use va_list to handle any no. or args @@ -115,6 +124,7 @@ public: if (splittedMatches.size() == 0) continue; string firstMatch = splittedMatches[0]; + auto utfMatch = UTF8ToUTF32(firstMatch); pair> key = findCodeKey(firstMatch); if (key.first != TEXT_OP_CODE::CUSTOM_NULL) @@ -176,9 +186,9 @@ public: } else { - for (int c = 0; c < strlen(firstMatch.c_str()); c++) + for (unsigned long c = 0; c < utfMatch.length(); c++) { - char chr = firstMatch[c]; + int chr = utfMatch[c]; // 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 @@ -186,7 +196,7 @@ public: int pos = -1; for (int ccc = 0; ccc < 287; ccc++) { - if ((char)CHAR_MAP[ccc] == chr) + if (static_cast(CHAR_MAP[ccc]) == chr) { pos = ccc; break; @@ -388,292 +398,28 @@ private: // region CharMAPS int CHAR_MAP[287] = { - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - 'A', - 'B', - 'C', - 'D', - 'E', - 'F', - 'G', - 'H', - 'I', - 'J', - 'K', - 'L', - 'M', - 'N', - 'O', - 'P', - 'Q', - 'R', - 'S', - 'T', - 'U', - 'V', - 'W', - 'X', - 'Y', - 'Z', - 'a', - 'b', - 'c', - 'd', - 'e', - 'f', - 'g', - 'h', - 'i', - 'j', - 'k', - 'l', - 'm', - 'n', - 'o', - 'p', - 'q', - 'r', - 's', - 't', - 'u', - 'v', - 'w', - 'x', - 0x0079 /*'y'*/, - 0x007a /*'z'*/, - 0x3041 /*'ぁ'*/, - 0x3042 /*'あ'*/, - 0x3043 /*'ぃ'*/, - 0x3044 /*'い'*/, - 0x3045 /*'ぅ'*/, - 0x3046 /*'う'*/, - 0x3047 /*'ぇ'*/, - 0x3048 /*'え'*/, - 0x3049 /*'ぉ'*/, - 0x304a /*'お'*/, - 0x304b /*'か'*/, - 0x304c /*'が'*/, - 0x304d /*'き'*/, - 0x304e /*'ぎ'*/, - 0x304f /*'く'*/, - 0x3050 /*'ぐ'*/, - 0x3051 /*'け'*/, - 0x3052 /*'げ'*/, - 0x3053 /*'こ'*/, - 0x3054 /*'ご'*/, - 0x3055 /*'さ'*/, - 0x3056 /*'ざ'*/, - 0x3057 /*'し'*/, - 0x3058 /*'じ'*/, - 0x3059 /*'す'*/, - 0x305a /*'ず'*/, - 0x305b /*'せ'*/, - 0x305c /*'ぜ'*/, - 0x305d /*'そ'*/, - 0x305e /*'ぞ'*/, - 0x305f /*'た'*/, - 0x3060 /*'だ'*/, - 0x3061 /*'ち'*/, - 0x3062 /*'ぢ'*/, - 0x3063 /*'っ'*/, - 0x3064 /*'つ'*/, - 0x3065 /*'づ'*/, - 0x3066 /*'て'*/, - 0x3067 /*'で'*/, - 0x3068 /*'と'*/, - 0x3069 /*'ど'*/, - 0x306a /*'な'*/, - 0x306b /*'に'*/, - 0x306c /*'ぬ'*/, - 0x306d /*'ね'*/, - 0x306e /*'の'*/, - 0x306f /*'は'*/, - 0x3070 /*'ば'*/, - 0x3071 /*'ぱ'*/, - 0x3072 /*'ひ'*/, - 0x3073 /*'び'*/, - 0x3074 /*'ぴ'*/, - 0x3075 /*'ふ'*/, - 0x3076 /*'ぶ'*/, - 0x3077 /*'ぷ'*/, - 0x3078 /*'へ'*/, - 0x3079 /*'べ'*/, - 0x307a /*'ぺ'*/, - 0x307b /*'ほ'*/, - 0x307c /*'ぼ'*/, - 0x307d /*'ぽ'*/, - 0x307e /*'ま'*/, - 0x307f /*'み'*/, - 0x3080 /*'む'*/, - 0x3081 /*'め'*/, - 0x3082 /*'も'*/, - 0x3083 /*'ゃ'*/, - 0x3084 /*'や'*/, - 0x3085 /*'ゅ'*/, - 0x3086 /*'ゆ'*/, - 0x3087 /*'ょ'*/, - 0x3088 /*'よ'*/, - 0x3089 /*'ら'*/, - 0x308a /*'り'*/, - 0x308b /*'る'*/, - 0x308c /*'れ'*/, - 0x308d /*'ろ'*/, - 0x308e /*'ゎ'*/, - 0x308f /*'わ'*/, - 0x3092 /*'を'*/, - 0x3093 /*'ん'*/, - 0x30a1 /*'ァ'*/, - 0x30a2 /*'ア'*/, - 0x30a3 /*'ィ'*/, - 0x30a4 /*'イ'*/, - 0x30a5 /*'ゥ'*/, - 0x30a6 /*'ウ'*/, - 0x30a7 /*'ェ'*/, - 0x30a8 /*'エ'*/, - 0x30a9 /*'ォ'*/, - 0x30aa /*'オ'*/, - 0x30ab /*'カ'*/, - 0x30ac /*'ガ'*/, - 0x30ad /*'キ'*/, - 0x30ae /*'ギ'*/, - 0x30af /*'ク'*/, - 0x30b0 /*'グ'*/, - 0x30b1 /*'ケ'*/, - 0x30b2 /*'ゲ'*/, - 0x30b3 /*'コ'*/, - 0x30b4 /*'ゴ'*/, - 0x30b5 /*'サ'*/, - 0x30b6 /*'ザ'*/, - 0x30b7 /*'シ'*/, - 0x30b8 /*'ジ'*/, - 0x30b9 /*'ス'*/, - 0x30ba /*'ズ'*/, - 0x30bb /*'セ'*/, - 0x30bc /*'ゼ'*/, - 0x30bd /*'ソ'*/, - 0x30be /*'ゾ'*/, - 0x30bf /*'タ'*/, - 0x30c0 /*'ダ'*/, - 0x30c1 /*'チ'*/, - 0x30c2 /*'ヂ'*/, - 0x30c3 /*'ッ'*/, - 0x30c4 /*'ツ'*/, - 0x30c5 /*'ヅ'*/, - 0x30c6 /*'テ'*/, - 0x30c7 /*'デ'*/, - 0x30c8 /*'ト'*/, - 0x30c9 /*'ド'*/, - 0x30ca /*'ナ'*/, - 0x30cb /*'ニ'*/, - 0x30cc /*'ヌ'*/, - 0x30cd /*'ネ'*/, - 0x30ce /*'ノ'*/, - 0x30cf /*'ハ'*/, - 0x30d0 /*'バ'*/, - 0x30d1 /*'パ'*/, - 0x30d2 /*'ヒ'*/, - 0x30d3 /*'ビ'*/, - 0x30d4 /*'ピ'*/, - 0x30d5 /*'フ'*/, - 0x30d6 /*'ブ'*/, - 0x30d7 /*'プ'*/, - 0x30d8 /*'ヘ'*/, - 0x30d9 /*'ベ'*/, - 0x30da /*'ペ'*/, - 0x30db /*'ホ'*/, - 0x30dc /*'ボ'*/, - 0x30dd /*'ポ'*/, - 0x30de /*'マ'*/, - 0x30df /*'ミ'*/, - 0x30e0 /*'ム'*/, - 0x30e1 /*'メ'*/, - 0x30e2 /*'モ'*/, - 0x30e3 /*'ャ'*/, - 0x30e4 /*'ヤ'*/, - 0x30e5 /*'ュ'*/, - 0x30e6 /*'ユ'*/, - 0x30e7 /*'ョ'*/, - 0x30e8 /*'ヨ'*/, - 0x30e9 /*'ラ'*/, - 0x30ea /*'リ'*/, - 0x30eb /*'ル'*/, - 0x30ec /*'レ'*/, - 0x30ed /*'ロ'*/, - 0x30ee /*'ヮ'*/, - 0x30ef /*'ワ'*/, - 0x30f2 /*'ヲ'*/, - 0x30f3 /*'ン'*/, - 0x30f4 /*'ヴ'*/, - 0x30f5 /*'ヵ'*/, - 0x30f6 /*'ヶ'*/, - 0x3000 /*' '*/, - 0x3001 /*'、'*/, - 0x3002 /*'。'*/, - 0x002c /*','*/, - 0x002e /*'.'*/, - 0x2022 /*'•'*/, - 0x002c /*','*/, - 0x003b /*';'*/, - 0x003f /*'?'*/, - 0x0021 /*'!'*/, - 0x005e /*'^'*/, - 0x005f /*'_'*/, - 0x2014 /*'—'*/, - 0x002f /*'/'*/, - 0x007e /*'~'*/, - 0x007c /*'|'*/, - 0x0027 /*'\''*/, - 0x0022 /*'"'*/, - 0x0028 /*'('*/, - 0x0029 /*')'*/, - 0x005b /*'['*/, - 0x005d /*']'*/, - 0x007b /*'{'*/, - 0x007d /*'}'*/, - 0x002b /*'+'*/, - '-', - 0x00d7 /*'×'*/, - 0x003d /*'='*/, - 0x003c /*'<'*/, - 0x003e /*'>'*/, - 0x00a5 /*'¥'*/, - 0x0024 /*'$'*/, - 0x0025 /*'%'*/, - 0x0023 /*'#'*/, - 0x0026 /*'&'*/, - 0x002a /*'*'*/, - 0x0040 /*'@'*/, - 0x6271 /*'扱'*/, - 0x62bc /*'押'*/, - 0x8ecd /*'軍'*/, - 0x6e90 /*'源'*/, - 0x500b /*'個'*/, - 0x8fbc /*'込'*/, - 0x6307 /*'指'*/, - 0x793a /*'示'*/, - 0x53d6 /*'取'*/, - 0x66f8 /*'書'*/, - 0x8a73 /*'詳'*/, - 0x4eba /*'人'*/, - 0x751f /*'生'*/, - 0x8aac /*'説'*/, - 0x4f53 /*'体'*/, - 0x56e3 /*'団'*/, - 0x96fb /*'電'*/, - 0x8aad /*'読'*/, - 0x767a /*'発'*/, - 0x629c /*'抜'*/, - 0x9591 /*'閑'*/, - 0x672c /*'本'*/, - 0x660e /*'明'*/, + 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', + 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'ぁ', U'あ', U'ぃ', + U'い', U'ぅ', U'う', U'ぇ', U'え', U'ぉ', U'お', U'か', U'が', U'き', U'ぎ', U'く', U'ぐ', + U'け', U'げ', U'こ', U'ご', U'さ', U'ざ', U'し', U'じ', U'す', U'ず', U'せ', U'ぜ', U'そ', + U'ぞ', U'た', U'だ', U'ち', U'ぢ', U'っ', U'つ', U'づ', U'て', U'で', U'と', U'ど', U'な', + U'に', U'ぬ', U'ね', U'の', U'は', U'ば', U'ぱ', U'ひ', U'び', U'ぴ', U'ふ', U'ぶ', U'ぷ', + U'へ', U'べ', U'ぺ', U'ほ', U'ぼ', U'ぽ', U'ま', U'み', U'む', U'め', U'も', U'ゃ', U'や', + U'ゅ', U'ゆ', U'ょ', U'よ', U'ら', U'り', U'る', U'れ', U'ろ', U'ゎ', U'わ', U'を', U'ん', + U'ァ', U'ア', U'ィ', U'イ', U'ゥ', U'ウ', U'ェ', U'エ', U'ォ', U'オ', U'カ', U'ガ', U'キ', + U'ギ', U'ク', U'グ', U'ケ', U'ゲ', U'コ', U'ゴ', U'サ', U'ザ', U'シ', U'ジ', U'ス', U'ズ', + U'セ', U'ゼ', U'ソ', U'ゾ', U'タ', U'ダ', U'チ', U'ヂ', U'ッ', U'ツ', U'ヅ', U'テ', U'デ', + U'ト', U'ド', U'ナ', U'ニ', U'ヌ', U'ネ', U'ノ', U'ハ', U'バ', U'パ', U'ヒ', U'ビ', U'ピ', + U'フ', U'ブ', U'プ', U'ヘ', U'ベ', U'ペ', U'ホ', U'ボ', U'ポ', U'マ', U'ミ', U'ム', U'メ', + U'モ', U'ャ', U'ヤ', U'ュ', U'ユ', U'ョ', U'ヨ', U'ラ', U'リ', U'ル', U'レ', U'ロ', U'ヮ', + U'ワ', U'ヲ', U'ン', U'ヴ', U'ヵ', U'ヶ', U' ', U'、', U'。', U',', U'.', U'•', U',', + U';', U'?', U'!', U'^', U'_', U'—', U'/', U'~', U'|', U'\'', U'"', U'(', U')', + U'[', U']', U'{', U'}', U'+', '-', U'×', U'=', U'<', U'>', U'¥', U'$', U'%', + U'#', U'&', U'*', U'@', U'扱', U'押', U'軍', U'源', U'個', U'込', U'指', U'示', U'取', + U'書', U'詳', U'人', U'生', U'説', U'体', U'団', U'電', U'読', U'発', U'抜', U'閑', U'本', + U'明', }; };