Fixed Netplay issue introduced with ZIP support

This commit is contained in:
Souryo 2014-07-10 20:24:28 -04:00
parent 3cc3bf6cbd
commit 82006c057b
4 changed files with 23 additions and 7 deletions

View file

@ -4,7 +4,6 @@
#include "../Utilities/Timer.h"
#include "../Utilities/FolderUtilities.h"
#include "../Utilities/ConfigManager.h"
#include "../Utilities/CRC32.h"
Console* Console::Instance = nullptr;
IMessageManager* Console::MessageManager = nullptr;
@ -77,17 +76,20 @@ void Console::LoadROM(wstring filename)
bool Console::AttemptLoadROM(wstring filename, uint32_t crc32Hash)
{
if(Instance) {
if(CRC32::GetCRC(Instance->_romFilepath) == crc32Hash) {
if(ROMLoader::GetCRC32(Instance->_romFilepath) == crc32Hash) {
//Current game matches, no need to do anything
return true;
}
}
vector<wstring> romFiles = FolderUtilities::GetFilesInFolder(ConfigManager::GetValue<wstring>(Config::LastGameFolder), L"*.nes", true);
for(wstring zipFile : FolderUtilities::GetFilesInFolder(ConfigManager::GetValue<wstring>(Config::LastGameFolder), L"*.zip", true)) {
romFiles.push_back(zipFile);
}
for(wstring romFile : romFiles) {
//Quick search by filename
if(FolderUtilities::GetFilename(romFile, true).compare(filename) == 0) {
if(CRC32::GetCRC(romFile) == crc32Hash) {
if(ROMLoader::GetCRC32(romFile) == crc32Hash) {
//Matching ROM found
Console::LoadROM(romFile);
return true;
@ -97,7 +99,7 @@ bool Console::AttemptLoadROM(wstring filename, uint32_t crc32Hash)
for(wstring romFile : romFiles) {
//Slower search by CRC value
if(CRC32::GetCRC(romFile) == crc32Hash) {
if(ROMLoader::GetCRC32(romFile) == crc32Hash) {
//Matching ROM found
Console::LoadROM(romFile);
return true;

View file

@ -2,7 +2,7 @@
#include "stdafx.h"
#include "NetMessage.h"
#include "Console.h"
#include "../Utilities/CRC32.h"
#include "ROMLoader.h"
#include "../Utilities/FolderUtilities.h"
class GameInformationMessage : public NetMessage
@ -39,7 +39,7 @@ public:
{
memset(ROMFilename, 0, sizeof(ROMFilename));
wcscpy_s(ROMFilename, FolderUtilities::GetFilename(filepath, true).c_str());
CRC32Hash = CRC32::GetCRC(filepath);
CRC32Hash = ROMLoader::GetCRC32(filepath);
ControllerPort = port;
Paused = paused;
}

View file

@ -3,6 +3,7 @@
#include "stdafx.h"
#include "../Utilities/FolderUtilities.h"
#include "../Utilities/ZIPReader.h"
#include "../Utilities/CRC32.h"
enum class MirroringType
{
@ -56,6 +57,7 @@ class ROMLoader
wstring _filename;
uint8_t* _prgRAM = nullptr;
uint8_t* _chrRAM = nullptr;
uint32_t _crc32;
bool LoadFromZIP(ifstream &zipFile)
{
@ -119,6 +121,7 @@ class ROMLoader
bool LoadFromMemory(uint8_t* buffer, uint32_t length)
{
_crc32 = CRC32::GetCRC(buffer, length);
if(memcmp(buffer, "NES", 3) == 0) {
memcpy((char*)&_header, buffer, sizeof(NESHeader));
@ -216,5 +219,16 @@ class ROMLoader
{
return _filename;
}
static uint32_t GetCRC32(wstring filename)
{
ROMLoader loader;
uint32_t crc = 0;
if(loader.LoadFile(filename)) {
crc = loader._crc32;
loader.FreeMemory();
}
return crc;
}
};

View file

@ -1,6 +1,6 @@
//From: http://tdistler.com/2011/06/22/crc32-a-simple-c-class
//"You are free to use and adapt this code however you like<6B>c that goes for anyone."
#pragma once
#include "stdafx.h"
static const uint32_t kCrc32Table[256] = {