pull in project-slippi/Ishiiruka/pull/256

This commit is contained in:
Nikhil Narayana 2021-12-17 21:24:48 -08:00
commit 3b05d0a9d5
3 changed files with 76 additions and 299 deletions

View file

@ -2038,20 +2038,34 @@ void CEXISlippi::prepareOnlineMatchState()
// Set chat message if any // Set chat message if any
if (slippi_netplay) if (slippi_netplay)
{
auto isSingleMode = matchmaking && matchmaking->RemotePlayerCount() == 1;
sentChatMessageId = slippi_netplay->GetSlippiRemoteSentChatMessage();
// Prevent processing a message in the same frame
if (sentChatMessageId <= 0)
{ {
auto remoteMessageSelection = slippi_netplay->GetSlippiRemoteChatMessage(); auto remoteMessageSelection = slippi_netplay->GetSlippiRemoteChatMessage();
chatMessageId = remoteMessageSelection.messageId; chatMessageId = remoteMessageSelection.messageId;
chatMessagePlayerIdx = remoteMessageSelection.playerIdx; chatMessagePlayerIdx = remoteMessageSelection.playerIdx;
sentChatMessageId = slippi_netplay->GetSlippiRemoteSentChatMessage(); if (chatMessageId == SlippiPremadeText::CHAT_MSG_CHAT_DISABLED && !isSingleMode)
// If connection is 1v1 set index 0 for local and 1 for remote {
if ((matchmaking && matchmaking->RemotePlayerCount() == 1) || !matchmaking) // 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; chatMessagePlayerIdx = sentChatMessageId > 0 ? localPlayerIndex : remotePlayerIndex;
} }
// in CSS p1 is always current player and p2 is opponent // in CSS p1 is always current player and p2 is opponent
localPlayerName = p1Name = userInfo.display_name; localPlayerName = p1Name = userInfo.display_name;
INFO_LOG_FMT(SLIPPI, "chatMessagePlayerIdx {} {}", chatMessagePlayerIdx,
matchmaking ? matchmaking->RemotePlayerCount() : 0);
} }
std::vector<u8> leftTeamPlayers = {}; std::vector<u8> leftTeamPlayers = {};
@ -2436,6 +2450,12 @@ std::vector<u8> CEXISlippi::loadPremadeText(u8* payload)
0x88 : 0x88 :
payload[1]; // TODO: Figure out what the hell is going on and fix this 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]; 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>"); playerName = ReplaceAll(playerName.c_str(), " ", "<S>");

View file

@ -13,6 +13,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
#include "SlippiPremadeText.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoConfig.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: case NetPlay::NP_MSG_SLIPPI_CHAT_MESSAGE:
{ {
auto playerSelection = ReadChatMessageFromPacket(packet); auto playerSelection = ReadChatMessageFromPacket(packet);
INFO_LOG(SLIPPI_ONLINE, "[Netplay] Received chat message from opponent %d: %d", INFO_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Received chat message from opponent {}: {}",
playerSelection->playerIdx, playerSelection->messageId); 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<sf::Packet>();
remoteSentChatMessageId = SlippiPremadeText::CHAT_MSG_CHAT_DISABLED;
WriteChatMessageToPacket(*packet, remoteSentChatMessageId, LocalPlayerPort());
SendAsync(std::move(packet));
remoteSentChatMessageId = 0;
break;
}
// set message id to netplay instance // set message id to netplay instance
remoteChatMessageSelection = std::move(playerSelection); remoteChatMessageSelection = std::move(playerSelection);
} }

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
// This file must be encoded in UTF-8 with signatures on Windows
#include <regex> #include <regex>
#include <stdarg.h> #include <stdarg.h>
@ -8,6 +9,7 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
using namespace std; using namespace std;
@ -21,6 +23,7 @@ public:
SPT_CHAT_P3 = 0x3, SPT_CHAT_P3 = 0x3,
SPT_CHAT_P4 = 0x4, SPT_CHAT_P4 = 0x4,
SPT_LOGOUT = 0x5, SPT_LOGOUT = 0x5,
SPT_CHAT_DISABLED = 0x6,
CHAT_MSG_U_PAD_LEFT = 0x81, CHAT_MSG_U_PAD_LEFT = 0x81,
CHAT_MSG_U_PAD_RIGHT = 0x82, CHAT_MSG_U_PAD_RIGHT = 0x82,
@ -41,6 +44,8 @@ public:
CHAT_MSG_D_PAD_RIGHT = 0x42, CHAT_MSG_D_PAD_RIGHT = 0x42,
CHAT_MSG_D_PAD_DOWN = 0x44, CHAT_MSG_D_PAD_DOWN = 0x44,
CHAT_MSG_D_PAD_UP = 0x48, CHAT_MSG_D_PAD_UP = 0x48,
CHAT_MSG_CHAT_DISABLED = 0x10,
}; };
unordered_map<u8, string> premadeTextsParams = { unordered_map<u8, string> premadeTextsParams = {
@ -64,6 +69,8 @@ public:
{CHAT_MSG_D_PAD_LEFT, "thinking"}, {CHAT_MSG_D_PAD_LEFT, "thinking"},
{CHAT_MSG_D_PAD_RIGHT, "lets play again later"}, {CHAT_MSG_D_PAD_RIGHT, "lets play again later"},
{CHAT_MSG_D_PAD_DOWN, "bad connection"}, {CHAT_MSG_D_PAD_DOWN, "bad connection"},
{CHAT_MSG_CHAT_DISABLED, "player has chat disabled"},
}; };
unordered_map<u8, string> premadeTexts = { unordered_map<u8, string> premadeTexts = {
@ -72,6 +79,8 @@ public:
{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,
"<LEFT><KERN><COLOR, 0, 178, 2>%s<S><COLOR, 255, 255, 255>has<S>chat<S>disabled<S><END>"},
}; };
// TODO: use va_list to handle any no. or args // TODO: use va_list to handle any no. or args
@ -115,6 +124,7 @@ public:
if (splittedMatches.size() == 0) if (splittedMatches.size() == 0)
continue; continue;
string firstMatch = splittedMatches[0]; string firstMatch = splittedMatches[0];
auto utfMatch = UTF8ToUTF32(firstMatch);
pair<TEXT_OP_CODE, pair<string, string>> key = findCodeKey(firstMatch); pair<TEXT_OP_CODE, pair<string, string>> key = findCodeKey(firstMatch);
if (key.first != TEXT_OP_CODE::CUSTOM_NULL) if (key.first != TEXT_OP_CODE::CUSTOM_NULL)
@ -176,9 +186,9 @@ public:
} }
else 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 // 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
@ -186,7 +196,7 @@ public:
int pos = -1; int pos = -1;
for (int ccc = 0; ccc < 287; ccc++) for (int ccc = 0; ccc < 287; ccc++)
{ {
if ((char)CHAR_MAP[ccc] == chr) if (static_cast<int>(CHAR_MAP[ccc]) == chr)
{ {
pos = ccc; pos = ccc;
break; break;
@ -388,292 +398,28 @@ private:
// region CharMAPS // region CharMAPS
int CHAR_MAP[287] = { int CHAR_MAP[287] = {
'0', 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',
'1', 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',
'2', 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',
'3', 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',
'4', U'q', U'r', U's', U't', U'u', U'v', U'w', U'x', U'y', U'z', U'', U'', U'',
'5', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'6', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'7', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'8', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'9', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'A', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'B', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'C', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'D', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'E', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'F', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'G', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'H', U'', U'', U'', U'', U'', U'', U' ', U'', U'', U',', U'.', U'', U',',
'I', U';', U'?', U'!', U'^', U'_', U'', U'/', U'~', U'|', U'\'', U'"', U'(', U')',
'J', U'[', U']', U'{', U'}', U'+', '-', U'×', U'=', U'<', U'>', U'¥', U'$', U'%',
'K', U'#', U'&', U'*', U'@', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'L', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'', U'',
'M', U'',
'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 /*'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6 /*'ヶ'*/,
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 /*'明'*/,
}; };
}; };