diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp index 3a40dfd28f..d9450ea580 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp @@ -112,6 +112,7 @@ template std::shared_ptr AddDevice(const char* device_name) { auto device = std::make_shared(num_devices, device_name); + _assert_(device->GetDeviceType() == IWII_IPC_HLE_Device::DeviceType::Static); s_device_map[num_devices] = device; num_devices++; return device; @@ -172,7 +173,7 @@ void Reset(bool hard) for (auto& dev : s_fdmap) { - if (dev && !dev->IsHardware()) + if (dev && dev->GetDeviceType() != IWII_IPC_HLE_Device::DeviceType::Static) { // close all files and delete their resources dev->Close(0, true); @@ -285,12 +286,7 @@ void DoState(PointerWrap& p) } for (const auto& entry : s_device_map) - { - if (entry.second->IsHardware()) - { - entry.second->DoState(p); - } - } + entry.second->DoState(p); if (p.GetMode() == PointerWrap::MODE_READ) { @@ -300,18 +296,21 @@ void DoState(PointerWrap& p) p.Do(exists); if (exists) { - u32 isHw = 0; - p.Do(isHw); - if (isHw) + auto device_type = IWII_IPC_HLE_Device::DeviceType::Static; + p.Do(device_type); + switch (device_type) { - u32 hwId = 0; - p.Do(hwId); - s_fdmap[i] = AccessDeviceByID(hwId); + case IWII_IPC_HLE_Device::DeviceType::Static: + { + u32 device_id = 0; + p.Do(device_id); + s_fdmap[i] = AccessDeviceByID(device_id); + break; } - else - { + case IWII_IPC_HLE_Device::DeviceType::FileIO: s_fdmap[i] = std::make_shared(i, ""); s_fdmap[i]->DoState(p); + break; } } } @@ -331,9 +330,9 @@ void DoState(PointerWrap& p) p.Do(exists); if (exists) { - u32 isHw = descriptor->IsHardware() ? 1 : 0; - p.Do(isHw); - if (isHw) + auto device_type = descriptor->GetDeviceType(); + p.Do(device_type); + if (device_type == IWII_IPC_HLE_Device::DeviceType::Static) { u32 hwId = descriptor->GetDeviceID(); p.Do(hwId); diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.cpp index ef9ecd616c..0a3d9cf9a3 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.cpp @@ -47,8 +47,8 @@ SIOCtlVBuffer::SIOCtlVBuffer(const u32 address) : m_Address(address) } IWII_IPC_HLE_Device::IWII_IPC_HLE_Device(const u32 device_id, const std::string& device_name, - const bool hardware) - : m_name(device_name), m_device_id(device_id), m_is_hardware(hardware) + const DeviceType type) + : m_name(device_name), m_device_id(device_id), m_device_type(type) { } @@ -62,7 +62,7 @@ void IWII_IPC_HLE_Device::DoStateShared(PointerWrap& p) { p.Do(m_name); p.Do(m_device_id); - p.Do(m_is_hardware); + p.Do(m_device_type); p.Do(m_is_active); } diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.h b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.h index 90c848ea05..6f45c83f9f 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.h +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device.h @@ -62,7 +62,14 @@ struct SIOCtlVBuffer class IWII_IPC_HLE_Device { public: - IWII_IPC_HLE_Device(u32 device_id, const std::string& device_name, bool hardware = true); + enum class DeviceType : u32 + { + Static, // Devices which appear in s_device_map. + FileIO, // FileIO devices which are created dynamically. + }; + + IWII_IPC_HLE_Device(u32 device_id, const std::string& device_name, + DeviceType type = DeviceType::Static); virtual ~IWII_IPC_HLE_Device() = default; // Release any resources which might interfere with savestating. @@ -81,17 +88,16 @@ public: virtual IPCCommandResult IOCtlV(u32 command_address); virtual u32 Update() { return 0; } - virtual bool IsHardware() const { return m_is_hardware; } + virtual DeviceType GetDeviceType() const { return m_device_type; } virtual bool IsOpened() const { return m_is_active; } static IPCCommandResult GetDefaultReply(); static IPCCommandResult GetNoReply(); - std::string m_name; - protected: + std::string m_name; // STATE_TO_SAVE u32 m_device_id; - bool m_is_hardware; + DeviceType m_device_type; bool m_is_active = false; // Write out the IPC struct from command_address to number_of_commands numbers diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp index 8b60b7f128..8cd1f853a4 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp @@ -66,7 +66,7 @@ void HLE_IPC_CreateVirtualFATFilesystem() CWII_IPC_HLE_Device_FileIO::CWII_IPC_HLE_Device_FileIO(u32 device_id, const std::string& device_name) - : IWII_IPC_HLE_Device(device_id, device_name, false) // not a real hardware + : IWII_IPC_HLE_Device(device_id, device_name, DeviceType::FileIO) { } diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 36be7c6447..6d84534de5 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent; static std::thread g_save_thread; // Don't forget to increase this after doing changes on the savestate system -static const u32 STATE_VERSION = 67; // Last changed in PR 4634 +static const u32 STATE_VERSION = 68; // Last changed in PR 4638 // Maps savestate versions to Dolphin versions. // Versions after 42 don't need to be added to this list,