mirror of
https://github.com/SourMesen/Mesen.git
synced 2025-04-02 10:52:48 -04:00
60 lines
No EOL
1.7 KiB
C++
60 lines
No EOL
1.7 KiB
C++
#pragma once
|
|
#include "stdafx.h"
|
|
#include "NetMessage.h"
|
|
#include "Console.h"
|
|
#include "../Utilities/CRC32.h"
|
|
#include "../Utilities/FolderUtilities.h"
|
|
|
|
class GameInformationMessage : public NetMessage
|
|
{
|
|
protected:
|
|
virtual uint32_t GetMessageLength()
|
|
{
|
|
return sizeof(ROMFilename) + sizeof(CRC32Hash) + sizeof(ControllerPort) + sizeof(Paused);
|
|
}
|
|
|
|
virtual void ProtectedSend(Socket &socket)
|
|
{
|
|
socket.BufferedSend((char*)&ROMFilename, sizeof(ROMFilename));
|
|
socket.BufferedSend((char*)&CRC32Hash, sizeof(CRC32Hash));
|
|
socket.BufferedSend((char*)&ControllerPort, sizeof(ControllerPort));
|
|
socket.BufferedSend((char*)&Paused, sizeof(Paused));
|
|
}
|
|
|
|
public:
|
|
wchar_t ROMFilename[255];
|
|
uint32_t CRC32Hash;
|
|
uint8_t ControllerPort;
|
|
bool Paused;
|
|
|
|
GameInformationMessage(char *readBuffer) : NetMessage(MessageType::GameInformation)
|
|
{
|
|
memcpy((char*)ROMFilename, readBuffer, sizeof(ROMFilename));
|
|
memcpy((char*)&CRC32Hash, readBuffer + sizeof(ROMFilename), sizeof(CRC32Hash));
|
|
ControllerPort = readBuffer[sizeof(ROMFilename) + sizeof(CRC32Hash)];
|
|
Paused = readBuffer[sizeof(ROMFilename) + sizeof(CRC32Hash) + sizeof(ControllerPort)] == 1;
|
|
}
|
|
|
|
GameInformationMessage(wstring filepath, uint8_t port, bool paused) : NetMessage(MessageType::GameInformation)
|
|
{
|
|
memset(ROMFilename, 0, sizeof(ROMFilename));
|
|
wcscpy_s(ROMFilename, FolderUtilities::GetFilename(filepath, true).c_str());
|
|
CRC32Hash = CRC32::GetCRC(filepath);
|
|
ControllerPort = port;
|
|
Paused = paused;
|
|
}
|
|
|
|
bool AttemptLoadGame()
|
|
{
|
|
wstring filename = ROMFilename;
|
|
if(filename.size() > 0) {
|
|
if(Console::AttemptLoadROM(filename, CRC32Hash)) {
|
|
return true;
|
|
} else {
|
|
Console::DisplayMessage(L"Could not find matching game ROM.");
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}; |