This commit is contained in:
Nikhil Narayana 2021-12-01 20:30:09 -08:00
commit 2964a86b9b
8 changed files with 715 additions and 695 deletions

View file

@ -1620,6 +1620,17 @@ void CEXISlippi::handleSendInputs(u8* payload)
int32_t frame = payload[0] << 24 | payload[1] << 16 | payload[2] << 8 | payload[3];
u8 delay = payload[4];
// On the first frame sent, we need to queue up empty dummy pads for as many
// frames as we have delay
if (frame == 1)
{
for (int i = 1; i <= delay; i++)
{
auto empty = std::make_unique<SlippiPad>(i);
slippi_netplay->SendSlippiPad(std::move(empty));
}
}
auto pad = std::make_unique<SlippiPad>(frame + delay, &payload[5]);
slippi_netplay->SendSlippiPad(std::move(pad));
@ -1663,7 +1674,8 @@ void CEXISlippi::prepareOpponentInputs(u8* payload)
if (latestFrame > frame)
latestFrame = frame;
appendWordToBuffer(&m_read_queue, *(u32*)&latestFrame);
// INFO_LOG(SLIPPI_ONLINE, "Sending frame num %d for pIdx %d (offset: %d)", latestFrame, i, offset[i]);
// INFO_LOG(SLIPPI_ONLINE, "Sending frame num %d for pIdx %d (offset: %d)", latestFrame, i,
// offset[i]);
}
// Send the current frame for any unused player slots.
for (int i = remotePlayerCount; i < SLIPPI_REMOTE_PLAYER_MAX; i++)
@ -1821,27 +1833,30 @@ void CEXISlippi::startFindMatch(u8* payload)
void CEXISlippi::prepareOnlineMatchState()
{
// This match block is a VS match with P1 Red Falco vs P2 Red Bowser vs P3 Young Link vs P4 Young Link
// on Battlefield. The proper values will be overwritten
// This match block is a VS match with P1 Red Falco vs P2 Red Bowser vs P3 Young Link vs P4 Young
// Link on Battlefield. The proper values will be overwritten
static std::vector<u8> onlineMatchBlock = {
0x32, 0x01, 0x86, 0x4C, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x6E, 0x00, 0x1F, 0x00, 0x00,
0x01, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00,
0xC0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x05, 0x00, 0x04, 0x01, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00,
0xC0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x15, 0x03, 0x04, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00,
0xC0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x15, 0x03, 0x04, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00,
0xC0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x21, 0x03, 0x04, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00,
0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x21, 0x03, 0x04, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00,
0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x3F, 0x80, 0x00, 0x00,
0x32, 0x01, 0x86, 0x4C, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x6E, 0x00,
0x1F, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3F,
0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x09,
0x00, 0x78, 0x00, 0xC0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x05, 0x00, 0x04,
0x01, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00, 0xC0, 0x00, 0x04, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F,
0x80, 0x00, 0x00, 0x15, 0x03, 0x04, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00,
0xC0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x15, 0x03, 0x04, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x09, 0x00, 0x78, 0x00, 0xC0, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00,
0x21, 0x03, 0x04, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x09, 0x00, 0x78, 0x00, 0x40, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80,
0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x21, 0x03, 0x04, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x09,
0x00, 0x78, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00,
};
m_read_queue.clear();
@ -2115,7 +2130,8 @@ void CEXISlippi::prepareOnlineMatchState()
// Set rng offset
rngOffset = isDecider ? lps.rngOffset : rps[0].rngOffset;
WARN_LOG(SLIPPI_ONLINE, "Rng Offset: 0x%x", rngOffset);
WARN_LOG(SLIPPI_ONLINE, "P1 Char: 0x%X, P2 Char: 0x%X", onlineMatchBlock[0x60], onlineMatchBlock[0x84]);
WARN_LOG(SLIPPI_ONLINE, "P1 Char: 0x%X, P2 Char: 0x%X", onlineMatchBlock[0x60],
onlineMatchBlock[0x84]);
// Turn pause on in direct, off in everything else
u8* gameBitField3 = (u8*)&onlineMatchBlock[2];
@ -2251,8 +2267,8 @@ void CEXISlippi::setMatchSelections(u8* payload)
s.stageId = getRandomStage();
}
INFO_LOG(SLIPPI, "LPS set char: %d, iSS: %d, %d, stage: %d, team: %d", s.isCharacterSelected, stageSelectOption,
s.isStageSelected, s.stageId, s.teamId);
INFO_LOG(SLIPPI, "LPS set char: %d, iSS: %d, %d, stage: %d, team: %d", s.isCharacterSelected,
stageSelectOption, s.isStageSelected, s.stageId, s.teamId);
s.rngOffset = generator() % 0xFFFF;

View file

@ -1,15 +1,15 @@
#pragma once
#include "Common/CommonTypes.h"
#include "Core/Slippi/SlippiUser.h"
#include <atomic>
#include <condition_variable> // std::condition_variable
#include <curl/curl.h>
#include <mutex> // std::mutex, std::unique_lock
#include <queue>
#include <string>
#include <thread>
#include <vector>
#include <queue>
#include "Common/CommonTypes.h"
#include "Core/Slippi/SlippiUser.h"
class SlippiGameReporter
{

View file

@ -244,8 +244,9 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet, ENetPeer* peer)
// Check that the packet actually contains the data it claims to
if ((5 + inputsToCopy * SLIPPI_PAD_DATA_SIZE) > (int)packet.getDataSize())
{
ERROR_LOG(SLIPPI_ONLINE,
"Netplay packet too small to read pad buffer. Size: %d, Inputs: %d, MinSize: %d",
ERROR_LOG_FMT(
SLIPPI_ONLINE,
"Netplay packet too small to read pad buffer. Size: {}, Inputs: {}, MinSize: {}",
(int)packet.getDataSize(), inputsToCopy, 5 + inputsToCopy * SLIPPI_PAD_DATA_SIZE);
break;
}

View file

@ -1,9 +1,9 @@
#include "SlippiSpectate.h"
#include <Core/ConfigManager.h>
#include "Common/Base64.hpp"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/Version.h"
#include <Core/ConfigManager.h>
// Networking
#ifdef _WIN32
@ -26,7 +26,8 @@ SlippiSpectateServer& SlippiSpectateServer::getInstance()
void SlippiSpectateServer::write(u8* payload, u32 length)
{
if (isSpectatorEnabled()) {
if (isSpectatorEnabled())
{
std::string str_payload((char*)payload, length);
m_event_queue.Push(str_payload);
}
@ -56,7 +57,8 @@ void SlippiSpectateServer::writeEvents(u16 peer_id)
// Send menu events
if (!m_in_game && (m_sockets[peer_id]->m_menu_cursor != m_menu_cursor))
{
ENetPacket *packet = enet_packet_create(m_menu_event.data(), m_menu_event.length(), ENET_PACKET_FLAG_RELIABLE);
ENetPacket* packet =
enet_packet_create(m_menu_event.data(), m_menu_event.length(), ENET_PACKET_FLAG_RELIABLE);
// Batch for sending
enet_peer_send(m_sockets[peer_id]->m_peer, 0, packet);
// Record for the peer that it was sent
@ -76,8 +78,8 @@ void SlippiSpectateServer::writeEvents(u16 peer_id)
for (u64 i = m_sockets[peer_id]->m_cursor; i < m_event_buffer.size(); i++)
{
ENetPacket *packet =
enet_packet_create(m_event_buffer[i].data(), m_event_buffer[i].size(), ENET_PACKET_FLAG_RELIABLE);
ENetPacket* packet = enet_packet_create(m_event_buffer[i].data(), m_event_buffer[i].size(),
ENET_PACKET_FLAG_RELIABLE);
// Batch for sending
enet_peer_send(m_sockets[peer_id]->m_peer, 0, packet);
m_sockets[peer_id]->m_cursor++;
@ -215,7 +217,8 @@ void SlippiSpectateServer::handleMessage(u8 *buffer, u32 length, u16 peer_id)
// Set the user's cursor position
if (requested_cursor >= m_cursor_offset)
{
// If the requested cursor is past what events we even have, then just tell them to start over
// If the requested cursor is past what events we even have, then just tell them to start
// over
if (requested_cursor > m_event_buffer.size() + m_cursor_offset)
{
m_sockets[peer_id]->m_cursor = 0;
@ -249,8 +252,8 @@ void SlippiSpectateServer::handleMessage(u8 *buffer, u32 length, u16 peer_id)
std::string packet_buffer = reply.dump();
ENetPacket *packet =
enet_packet_create(packet_buffer.data(), (u32)packet_buffer.length(), ENET_PACKET_FLAG_RELIABLE);
ENetPacket* packet = enet_packet_create(packet_buffer.data(), (u32)packet_buffer.length(),
ENET_PACKET_FLAG_RELIABLE);
// Batch for sending
enet_peer_send(m_sockets[peer_id]->m_peer, 0, packet);
@ -323,7 +326,6 @@ void SlippiSpectateServer::SlippicommSocketThread(void)
{
case ENET_EVENT_TYPE_CONNECT:
{
INFO_LOG(SLIPPI, "A new spectator connected from %x:%u.\n", event.peer->address.host,
event.peer->address.port);
@ -334,7 +336,8 @@ void SlippiSpectateServer::SlippicommSocketThread(void)
}
case ENET_EVENT_TYPE_RECEIVE:
{
handleMessage(event.packet->data, (u32)event.packet->dataLength, event.peer->incomingPeerID);
handleMessage(event.packet->data, (u32)event.packet->dataLength,
event.peer->incomingPeerID);
/* Clean up the packet now that we're done using it. */
enet_packet_destroy(event.packet);

View file

@ -5,9 +5,9 @@
#include <map>
#include <thread>
#include <enet/enet.h>
#include "Common/SPSCQueue.h"
#include "nlohmann/json.hpp"
#include <enet/enet.h>
using json = nlohmann::json;
// Sockets in windows are unsigned