even with 6e7b30d5d7d8b3a545dd412100401299ae8ada8d

This commit is contained in:
R2DLiu 2021-11-26 19:37:32 -05:00
commit 7665a31bb8
8 changed files with 106 additions and 91 deletions

View file

@ -19,9 +19,9 @@ namespace Common
#endif #endif
#ifndef IS_PLAYBACK #ifndef IS_PLAYBACK
#define SLIPPI_REV_STR "2.3.0" #define SLIPPI_REV_STR "2.3.2"
#else #else
#define SLIPPI_REV_STR "2.3.0" #define SLIPPI_REV_STR "2.3.2"
#endif #endif
const std::string scm_slippi_semver_str = SLIPPI_REV_STR; const std::string scm_slippi_semver_str = SLIPPI_REV_STR;

View file

@ -62,6 +62,7 @@
#include "Core/PatchEngine.h" #include "Core/PatchEngine.h"
#include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/Slippi/SlippiNetplay.h"
#include "Core/State.h" #include "Core/State.h"
#include "Core/WiiRoot.h" #include "Core/WiiRoot.h"
@ -642,6 +643,10 @@ void SetState(State state)
if (!IsRunningAndStarted()) if (!IsRunningAndStarted())
return; return;
// Do not allow any kind of cpu pause/resum if we are connected to someone on slippi
if (IsOnline())
return;
switch (state) switch (state)
{ {
case State::Paused: case State::Paused:
@ -720,6 +725,9 @@ static std::string GenerateScreenshotName()
void SaveScreenShot() void SaveScreenShot()
{ {
if (IsOnline())
return;
const bool bPaused = GetState() == State::Paused; const bool bPaused = GetState() == State::Paused;
SetState(State::Paused); SetState(State::Paused);

View file

@ -1667,10 +1667,8 @@ void CEXISlippi::prepareOpponentInputs(u8* payload)
void CEXISlippi::handleCaptureSavestate(u8* payload) void CEXISlippi::handleCaptureSavestate(u8* payload)
{ {
#ifndef IS_PLAYBACK
if (isDisconnected()) if (isDisconnected())
return; return;
#endif
s32 frame = payload[0] << 24 | payload[1] << 16 | payload[2] << 8 | payload[3]; s32 frame = payload[0] << 24 | payload[1] << 16 | payload[2] << 8 | payload[3];

View file

@ -3,39 +3,35 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/Slippi/SlippiNetplay.h" #include "Core/Slippi/SlippiNetplay.h"
#include "Common/Common.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Config/Config.h" #include "Common/Config/Config.h"
#include "Common/ENetUtil.h" #include "Common/ENetUtil.h"
#include "Common/MD5.h" #include "Common/Logging/Log.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/Timer.h" #include "Common/Timer.h"
#include "Core/Config/NetplaySettings.h" #include "Core/Config/NetplaySettings.h"
#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 "Core/HW/EXI_DeviceIPL.h"
//#include "Core/HW/SI.h"
//#include "Core/HW/SI_DeviceGCController.h"
#include "Core/HW/Sram.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
//#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_emu.h"
#include <SlippiGame.h>
#include <algorithm>
#include <fstream>
#include <mbedtls/md5.h>
#include <memory>
#include <thread>
#include "Core/Movie.h"
#include "InputCommon/GCAdapter.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
#include <SlippiGame.h>
#include <algorithm>
#include <fstream>
#include <memory>
#include <thread>
static std::mutex pad_mutex; static std::mutex pad_mutex;
static std::mutex ack_mutex; static std::mutex ack_mutex;
SlippiNetplayClient* SLIPPI_NETPLAY = nullptr;
static bool IsOnline()
{
return SLIPPI_NETPLAY != nullptr;
}
// called from ---GUI--- thread // called from ---GUI--- thread
SlippiNetplayClient::~SlippiNetplayClient() SlippiNetplayClient::~SlippiNetplayClient()
{ {
@ -58,6 +54,8 @@ SlippiNetplayClient::~SlippiNetplayClient()
m_client = nullptr; m_client = nullptr;
} }
SLIPPI_NETPLAY = nullptr;
WARN_LOG(SLIPPI_ONLINE, "Netplay client cleanup complete"); WARN_LOG(SLIPPI_ONLINE, "Netplay client cleanup complete");
} }
@ -68,11 +66,11 @@ SlippiNetplayClient::SlippiNetplayClient(const std::string& address, const u16 r
: m_qos_handle(nullptr), m_qos_flow_id(0) : m_qos_handle(nullptr), m_qos_flow_id(0)
#endif #endif
{ {
WARN_LOG(SLIPPI_ONLINE, "Initializing Slippi Netplay for port: %d, with host: %s", localPort, WARN_LOG_FMT(SLIPPI_ONLINE, "Initializing Slippi Netplay for port: %d, with host: %s", localPort,
isDecider ? "true" : "false"); isDecider ? "true" : "false");
this->isDecider = isDecider; this->isDecider = isDecider;
// this->playerIdx = isDecider ? 0 : 1; SLIPPI_NETPLAY = std::move(this);
// Local address // Local address
ENetAddress* localAddr = nullptr; ENetAddress* localAddr = nullptr;
@ -121,6 +119,7 @@ SlippiNetplayClient::SlippiNetplayClient(const std::string& address, const u16 r
SlippiNetplayClient::SlippiNetplayClient(bool isDecider) SlippiNetplayClient::SlippiNetplayClient(bool isDecider)
{ {
this->isDecider = isDecider; this->isDecider = isDecider;
SLIPPI_NETPLAY = std::move(this);
slippiConnectStatus = SlippiConnectStatus::NET_CONNECT_STATUS_FAILED; slippiConnectStatus = SlippiConnectStatus::NET_CONNECT_STATUS_FAILED;
} }
@ -292,7 +291,7 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet)
break; break;
default: default:
WARN_LOG(SLIPPI_ONLINE, "Unknown message received with id : %d", mid); WARN_LOG_FMT(SLIPPI_ONLINE, "Unknown message received with id : %d", mid);
break; break;
} }
@ -384,6 +383,7 @@ void SlippiNetplayClient::Disconnect()
// didn't disconnect gracefully force disconnect // didn't disconnect gracefully force disconnect
enet_peer_reset(m_server); enet_peer_reset(m_server);
m_server = nullptr; m_server = nullptr;
SLIPPI_NETPLAY = nullptr;
} }
void SlippiNetplayClient::SendAsync(std::unique_ptr<sf::Packet> packet) void SlippiNetplayClient::SendAsync(std::unique_ptr<sf::Packet> packet)
@ -422,7 +422,8 @@ void SlippiNetplayClient::ThreadFunc()
break; break;
} }
WARN_LOG(SLIPPI_ONLINE, "[Netplay] Not yet connected. Res: %d, Type: %d", net, netEvent.type); WARN_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Not yet connected. Res: %d, Type: %d", net,
netEvent.type);
// Time out after enough time has passed // Time out after enough time has passed
attemptCount++; attemptCount++;

View file

@ -130,8 +130,8 @@ public:
u8 GetSlippiRemoteSentChatMessage(); u8 GetSlippiRemoteSentChatMessage();
s32 CalcTimeOffsetUs(); s32 CalcTimeOffsetUs();
void WriteChatMessageToPacket(sf::Packet &packet, int messageId); void WriteChatMessageToPacket(sf::Packet& packet, int messageId);
std::unique_ptr<SlippiPlayerSelections> ReadChatMessageFromPacket(sf::Packet &packet); std::unique_ptr<SlippiPlayerSelections> ReadChatMessageFromPacket(sf::Packet& packet);
u8 remoteChatMessageId = 0; // most recent chat message id from opponent u8 remoteChatMessageId = 0; // most recent chat message id from opponent
u8 remoteSentChatMessageId = 0; // most recent chat message id that current player sent u8 remoteSentChatMessageId = 0; // most recent chat message id that current player sent
@ -204,3 +204,7 @@ private:
u32 m_timebase_frame = 0; u32 m_timebase_frame = 0;
}; };
extern SlippiNetplayClient* SLIPPI_NETPLAY; // singleton static pointer
static bool IsOnline();

View file

@ -23,8 +23,9 @@
#include "Core/HotkeyManager.h" #include "Core/HotkeyManager.h"
#include "Core/IOS/IOS.h" #include "Core/IOS/IOS.h"
#include "Core/IOS/USB/Bluetooth/BTBase.h" #include "Core/IOS/USB/Bluetooth/BTBase.h"
#include "Core/State.h" #include "Core/Slippi/SlippiNetplay.h"
#include "Core/Slippi/SlippiPlayback.h" #include "Core/Slippi/SlippiPlayback.h"
#include "Core/State.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
@ -454,6 +455,8 @@ void HotkeyScheduler::Run()
std::lround(SConfig::GetInstance().m_EmulationSpeed * 100.f))); std::lround(SConfig::GetInstance().m_EmulationSpeed * 100.f)));
}; };
if (!IsOnline())
{
if (IsHotkey(HK_DECREASE_EMULATION_SPEED)) if (IsHotkey(HK_DECREASE_EMULATION_SPEED))
{ {
auto speed = SConfig::GetInstance().m_EmulationSpeed - 0.1; auto speed = SConfig::GetInstance().m_EmulationSpeed - 0.1;
@ -469,6 +472,7 @@ void HotkeyScheduler::Run()
SConfig::GetInstance().m_EmulationSpeed = speed; SConfig::GetInstance().m_EmulationSpeed = speed;
ShowEmulationSpeed(); ShowEmulationSpeed();
} }
}
// Slot Saving / Loading // Slot Saving / Loading
if (IsHotkey(HK_SAVE_STATE_SLOT_SELECTED)) if (IsHotkey(HK_SAVE_STATE_SLOT_SELECTED))
@ -530,7 +534,8 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_SLIPPI_JUMP_BACK)) if (IsHotkey(HK_SLIPPI_JUMP_BACK))
{ {
INFO_LOG(SLIPPI, "jump back"); INFO_LOG(SLIPPI, "jump back");
if (g_playbackStatus->targetFrameNum == INT_MAX) { if (g_playbackStatus->targetFrameNum == INT_MAX)
{
g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame - 1200; g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame - 1200;
Host_PlaybackSeek(); Host_PlaybackSeek();
} }
@ -539,7 +544,8 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_SLIPPI_STEP_BACK)) if (IsHotkey(HK_SLIPPI_STEP_BACK))
{ {
INFO_LOG(SLIPPI, "step back"); INFO_LOG(SLIPPI, "step back");
if (g_playbackStatus->targetFrameNum == INT_MAX) { if (g_playbackStatus->targetFrameNum == INT_MAX)
{
g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame - 300; g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame - 300;
Host_PlaybackSeek(); Host_PlaybackSeek();
} }
@ -548,7 +554,8 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_SLIPPI_STEP_FORWARD)) if (IsHotkey(HK_SLIPPI_STEP_FORWARD))
{ {
INFO_LOG(SLIPPI, "step forward"); INFO_LOG(SLIPPI, "step forward");
if (g_playbackStatus->targetFrameNum == INT_MAX) { if (g_playbackStatus->targetFrameNum == INT_MAX)
{
g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame + 300; g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame + 300;
Host_PlaybackSeek(); Host_PlaybackSeek();
} }
@ -557,7 +564,8 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_SLIPPI_JUMP_FORWARD)) if (IsHotkey(HK_SLIPPI_JUMP_FORWARD))
{ {
INFO_LOG(SLIPPI, "jump forward"); INFO_LOG(SLIPPI, "jump forward");
if (g_playbackStatus->targetFrameNum == INT_MAX) { if (g_playbackStatus->targetFrameNum == INT_MAX)
{
g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame + 1200; g_playbackStatus->targetFrameNum = g_playbackStatus->currentPlaybackFrame + 1200;
Host_PlaybackSeek(); Host_PlaybackSeek();
} }

View file

@ -22,6 +22,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/Slippi/SlippiNetplay.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
@ -359,6 +360,7 @@ void GeneralPane::OnSaveConfig()
m_checkbox_override_region_settings->isChecked()); m_checkbox_override_region_settings->isChecked());
Config::SetBase(Config::MAIN_AUTO_DISC_CHANGE, m_checkbox_auto_disc_change->isChecked()); Config::SetBase(Config::MAIN_AUTO_DISC_CHANGE, m_checkbox_auto_disc_change->isChecked());
Config::SetBaseOrCurrent(Config::MAIN_ENABLE_CHEATS, m_checkbox_cheats->isChecked()); Config::SetBaseOrCurrent(Config::MAIN_ENABLE_CHEATS, m_checkbox_cheats->isChecked());
if (!IsOnline())
settings.m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f; settings.m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f;
Settings::Instance().SetFallbackRegion( Settings::Instance().SetFallbackRegion(
UpdateFallbackRegionFromIndex(m_combobox_fallback_region->currentIndex())); UpdateFallbackRegionFromIndex(m_combobox_fallback_region->currentIndex()));

View file

@ -14,9 +14,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <vector> #include <vector>
#include "Core/ConfigManager.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/Pipes/Pipes.h" #include "InputCommon/ControllerInterface/Pipes/Pipes.h"
@ -51,8 +51,7 @@ void PopulateDevices()
for (uint32_t i = 0; i < 4; i++) for (uint32_t i = 0; i < 4; i++)
{ {
std::string pipename = "\\\\.\\pipe\\slippibot" + std::to_string(i + 1); std::string pipename = "\\\\.\\pipe\\slippibot" + std::to_string(i + 1);
pipes[i] = CreateNamedPipeA( pipes[i] = CreateNamedPipeA(pipename.data(), // pipe name
pipename.data(), // pipe name
PIPE_ACCESS_INBOUND, // read access, inward only PIPE_ACCESS_INBOUND, // read access, inward only
PIPE_TYPE_BYTE | PIPE_NOWAIT, // byte mode, nonblocking PIPE_TYPE_BYTE | PIPE_NOWAIT, // byte mode, nonblocking
1, // number of clients 1, // number of clients
@ -124,14 +123,8 @@ s32 PipeDevice::readFromPipe(PIPE_FD file_descriptor, char* in_buffer, size_t si
u32 bytes_available = 0; u32 bytes_available = 0;
DWORD bytesread = 0; DWORD bytesread = 0;
bool peek_success = PeekNamedPipe( bool peek_success =
file_descriptor, PeekNamedPipe(file_descriptor, NULL, 0, NULL, (LPDWORD)&bytes_available, NULL);
NULL,
0,
NULL,
(LPDWORD)&bytes_available,
NULL
);
if (!peek_success && (GetLastError() == ERROR_BROKEN_PIPE)) if (!peek_success && (GetLastError() == ERROR_BROKEN_PIPE))
{ {
@ -142,8 +135,7 @@ s32 PipeDevice::readFromPipe(PIPE_FD file_descriptor, char* in_buffer, size_t si
if (peek_success && (bytes_available > 0)) if (peek_success && (bytes_available > 0))
{ {
bool success = ReadFile( bool success = ReadFile(file_descriptor, // pipe handle
file_descriptor, // pipe handle
in_buffer, // buffer to receive reply in_buffer, // buffer to receive reply
(DWORD)std::min(bytes_available, (u32)size), // size of buffer (DWORD)std::min(bytes_available, (u32)size), // size of buffer
&bytesread, // number of bytes read &bytesread, // number of bytes read
@ -173,12 +165,14 @@ s32 PipeDevice::readFromPipe(PIPE_FD file_descriptor, char* in_buffer, size_t si
void PipeDevice::UpdateInput() void PipeDevice::UpdateInput()
{ {
bool finished = false; bool finished = false;
do { do
{
// Read any pending characters off the pipe. If we hit a newline, // Read any pending characters off the pipe. If we hit a newline,
// then dequeue a command off the front of m_buf and parse it. // then dequeue a command off the front of m_buf and parse it.
char buf[32]; char buf[32];
s32 bytes_read = readFromPipe(m_fd, buf, sizeof buf); s32 bytes_read = readFromPipe(m_fd, buf, sizeof buf);
if (bytes_read == 0) { if (bytes_read == 0)
{
// Pipe died, so just quit out // Pipe died, so just quit out
return; return;
} }