From fa63bc3ae0abec298ce64e2b307d7b17cb1a26ce Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Fri, 3 Dec 2021 21:05:16 -0800 Subject: [PATCH] compiles --- Source/Core/Common/FileUtil.cpp | 21 +++++++++++-------- Source/Core/Core/GeckoCode.cpp | 2 -- Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp | 14 +++++++------ .../Core/Core/Slippi/SlippiGameReporter.cpp | 16 ++------------ Source/Core/Core/Slippi/SlippiGameReporter.h | 2 +- Source/Core/Core/Slippi/SlippiNetplay.cpp | 14 ++++++------- Source/Core/Core/Slippi/SlippiNetplay.h | 2 +- 7 files changed, 31 insertions(+), 40 deletions(-) diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 2c069dfca6..2e5e5dfb43 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -26,13 +26,13 @@ #ifdef _WIN32 #include +#include #include #include // for GetSaveFileName #include // getcwd #include #include // guid stuff #include -#include #include #else #include @@ -791,21 +791,22 @@ std::string GetExePath() return dolphin_path; } -// SLIPPITODO: refactor with c++17 std::filesystem? std::string GetHomeDirectory() { std::string homeDir; #ifdef _WIN32 wchar_t* path = nullptr; - if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &path))) { + if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &path))) + { char pathStr[MAX_PATH]; wcstombs(pathStr, path, MAX_PATH); homeDir = std::string(pathStr); CoTaskMemFree(path); } - else { + else + { const char* home = getenv("USERPROFILE"); homeDir = std::string(home) + "\\Documents"; } @@ -853,13 +854,15 @@ std::string GetSysDirectory() ASSERT_MSG(COMMON, !sysDir.empty(), "Sys directory has not been set"); #else const char* home = getenv("HOME"); - if (!home) home = getenv("PWD"); - if (!home) home = ""; + if (!home) + home = getenv("PWD"); + if (!home) + home = ""; std::string home_path = std::string(home) + DIR_SEP; const char* config_home = getenv("XDG_CONFIG_HOME"); - sysDir = std::string(config_home && config_home[0] == '/' - ? config_home : (home_path + ".config")) - + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP "Sys" DIR_SEP; + sysDir = + std::string(config_home && config_home[0] == '/' ? config_home : (home_path + ".config")) + + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP "Sys" DIR_SEP; #endif INFO_LOG_FMT(COMMON, "GetSysDirectory: Setting to {}:", sysDir); diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 8412137694..f9de54bb22 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -365,8 +365,6 @@ std::vector GenerateGct() std::lock_guard lk(s_active_codes_lock); - int i = 0; - // Write codes for (const GeckoCode& active_code : s_active_codes) { diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp index 9eb09ffc52..de4a85c033 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp @@ -99,9 +99,11 @@ void appendHalfToBuffer(std::vector* buf, u16 word) std::string ConvertConnectCodeForGame(const std::string& input) { - char fullWidthShiftJisHashtag[] = {(char)0x81, (char)0x94, (char)0x00}; + // Shift-Jis '#' symbol is two bytes (0x8194), followed by 0x00 null terminator + char fullWidthShiftJisHashtag[] = {-127, -108, 0}; // 0x81, 0x94, 0x00 std::string connectCode(input); - connectCode = ReplaceAll(connectCode, "#", fullWidthShiftJisHashtag); + // SLIPPITODO:Not the best use of ReplaceAll. potential bug if more than one '#' found. + connectCode = ReplaceAll(connectCode, "#", std::string(fullWidthShiftJisHashtag)); connectCode.resize(CONNECT_CODE_LENGTH + 2); // fixed length + full width (two byte) hashtag +1, null terminator +1 return connectCode; @@ -2144,7 +2146,7 @@ void CEXISlippi::prepareOnlineMatchState() onlineMatchBlock[0x84]); // Turn pause on in direct, off in everything else - u8* gameBitField3 = (u8*)&onlineMatchBlock[2]; + u8* gameBitField3 = static_cast(&onlineMatchBlock[2]); *gameBitField3 = lastSearch.mode >= directMode ? *gameBitField3 & 0xF7 : *gameBitField3 | 0x8; //*gameBitField3 = *gameBitField3 | 0x8; @@ -2157,8 +2159,8 @@ void CEXISlippi::prepareOnlineMatchState() else rightTeamPlayers.push_back(i); } - auto leftTeamSize = leftTeamPlayers.size(); - auto rightTeamSize = rightTeamPlayers.size(); + int leftTeamSize = static_cast(leftTeamPlayers.size()); + int rightTeamSize = static_cast(rightTeamPlayers.size()); leftTeamPlayers.resize(4, 0); rightTeamPlayers.resize(4, 0); leftTeamPlayers[3] = static_cast(leftTeamSize); @@ -2229,7 +2231,7 @@ void CEXISlippi::prepareOnlineMatchState() auto playerInfo = matchmaking->GetPlayerInfo(); for (int i = 0; i < 4; i++) { - std::string connectCode = i < playerInfo.size() ? playerInfo[i].connectCode : ""; + std::string connectCode = i < playerInfo.size() ? playerInfo[i].connect_code : ""; #ifdef LOCAL_TESTING connectCode = defaultConnectCodes[i]; #endif diff --git a/Source/Core/Core/Slippi/SlippiGameReporter.cpp b/Source/Core/Core/Slippi/SlippiGameReporter.cpp index 08b759d003..fcd2af3d21 100644 --- a/Source/Core/Core/Slippi/SlippiGameReporter.cpp +++ b/Source/Core/Core/Slippi/SlippiGameReporter.cpp @@ -16,18 +16,6 @@ #include using json = nlohmann::json; -inline size_t receive(char* ptr, size_t size, size_t nmemb, void* rcvBuf) -{ - size_t len = size * nmemb; - INFO_LOG(SLIPPI_ONLINE, "[User] Received data: %d", len); - - std::string* buf = (std::string*)rcvBuf; - - buf->insert(buf->end(), ptr, ptr + len); - - return len; -} - SlippiGameReporter::SlippiGameReporter(SlippiUser* user) { CURL* curl = curl_easy_init(); @@ -76,7 +64,7 @@ void SlippiGameReporter::StartReport(GameReport report) void SlippiGameReporter::StartNewSession(std::vector new_player_uids) { - this->player_uids = new_player_uids; + this->m_player_uids = new_player_uids; gameIndex = 1; } @@ -108,7 +96,7 @@ void SlippiGameReporter::ReportThreadHandler() for (int i = 0; i < report.players.size(); i++) { json p; - p["uid"] = player_uids[i]; + p["uid"] = m_player_uids[i]; p["damage_done"] = report.players[i].damage_done; p["stocks_remaining"] = report.players[i].stocks_remaining; diff --git a/Source/Core/Core/Slippi/SlippiGameReporter.h b/Source/Core/Core/Slippi/SlippiGameReporter.h index 1a0b825700..ea68933e23 100644 --- a/Source/Core/Core/Slippi/SlippiGameReporter.h +++ b/Source/Core/Core/Slippi/SlippiGameReporter.h @@ -38,7 +38,7 @@ protected: struct curl_slist* m_curl_header_list = nullptr; u32 gameIndex = 1; - std::vector player_uids; + std::vector m_player_uids; SlippiUser* m_user; std::queue game_report_queue; diff --git a/Source/Core/Core/Slippi/SlippiNetplay.cpp b/Source/Core/Core/Slippi/SlippiNetplay.cpp index 0fb0511703..81eb7e2f09 100644 --- a/Source/Core/Core/Slippi/SlippiNetplay.cpp +++ b/Source/Core/Core/Slippi/SlippiNetplay.cpp @@ -67,13 +67,13 @@ SlippiNetplayClient::SlippiNetplayClient(std::vector addrs, std::ve this->isDecider = isDecider; this->m_remotePlayerCount = remotePlayerCount; - this->playerIdx = playerIdx; + this->m_player_idx = playerIdx; // Set up remote player data structures. int j = 0; for (int i = 0; i < SLIPPI_REMOTE_PLAYER_MAX; i++, j++) { - if (j == playerIdx) + if (j == m_player_idx) j++; this->matchInfo.remotePlayerSelections[i] = SlippiPlayerSelections(); this->matchInfo.remotePlayerSelections[i].playerIdx = j; @@ -151,7 +151,7 @@ SlippiNetplayClient::SlippiNetplayClient(bool isDecider) u8 SlippiNetplayClient::PlayerIdxFromPort(u8 port) { u8 p = port; - if (port > playerIdx) + if (port > m_player_idx) { p--; } @@ -160,7 +160,7 @@ u8 SlippiNetplayClient::PlayerIdxFromPort(u8 port) u8 SlippiNetplayClient::LocalPlayerPort() { - return this->playerIdx; + return this->m_player_idx; } // called from ---NETPLAY--- thread @@ -267,7 +267,7 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet, ENetPeer* peer) sf::Packet spac; spac << (NetPlay::MessageId)NetPlay::NP_MSG_SLIPPI_PAD_ACK; spac << frame; - spac << playerIdx; + spac << m_player_idx; INFO_LOG(SLIPPI_ONLINE, "Sending ack packet for frame %d (player %d) to peer at %d:%d", frame, packetPlayerPort, peer->address.host, peer->address.port); @@ -835,7 +835,7 @@ void SlippiNetplayClient::SendSlippiPad(std::unique_ptr pad) auto spac = std::make_unique(); *spac << static_cast(NetPlay::NP_MSG_SLIPPI_PAD); *spac << frame; - *spac << this->playerIdx; + *spac << this->m_player_idx; // INFO_LOG(SLIPPI_ONLINE, "Sending a packet of inputs [%d]...", frame); for (auto it = localPadQueue.begin(); it != localPadQueue.end(); ++it) { @@ -869,7 +869,7 @@ void SlippiNetplayClient::SendSlippiPad(std::unique_ptr pad) void SlippiNetplayClient::SetMatchSelections(SlippiPlayerSelections& s) { matchInfo.localPlayerSelections.Merge(s); - matchInfo.localPlayerSelections.playerIdx = playerIdx; + matchInfo.localPlayerSelections.playerIdx = m_player_idx; // Send packet containing selections auto spac = std::make_unique(); diff --git a/Source/Core/Core/Slippi/SlippiNetplay.h b/Source/Core/Core/Slippi/SlippiNetplay.h index 90821f7a39..ffb5eeaad9 100644 --- a/Source/Core/Core/Slippi/SlippiNetplay.h +++ b/Source/Core/Core/Slippi/SlippiNetplay.h @@ -192,7 +192,7 @@ protected: bool isConnectionSelected = false; bool isDecider = false; bool hasGameStarted = false; - u8 playerIdx = 0; + u8 m_player_idx = 0; std::deque> localPadQueue; // most recent inputs at start of deque std::deque>