Config: Add DEV9 options to global struct

Additionally switch to using std::string in various locations in DEV9
This commit is contained in:
TheLastRar 2022-02-07 23:38:50 +00:00 committed by lightningterror
parent 6df50992c4
commit 5ff49a78eb
27 changed files with 334 additions and 611 deletions

View File

@ -784,9 +784,6 @@ if(PCSX2_CORE)
list(APPEND pcsx2SPU2Headers
SPU2/WavFile.cpp
)
list(APPEND pcsx2DEV9Sources
DEV9/Linux/Config.cpp
)
endif()
elseif(WIN32)
list(APPEND pcsx2SPU2Sources
@ -807,7 +804,6 @@ elseif(WIN32)
)
list(APPEND pcsx2DEV9Sources
DEV9/Win32/DEV9WinConfig.cpp
DEV9/Win32/pcap_io_win32.cpp
DEV9/Win32/tap-win32.cpp
)
@ -878,10 +874,6 @@ else()
SPU2/wx/wxConfig.h
)
list(APPEND pcsx2DEV9Sources
DEV9/Linux/Config.cpp
)
list(APPEND pcsx2USBSources
USB/icon_buzz_24.cpp
USB/linux/config-gtk.cpp

View File

@ -633,6 +633,80 @@ struct Pcsx2Config
}
};
struct DEV9Options
{
enum struct NetApi : int
{
Unset = 0,
PCAP_Bridged = 1,
PCAP_Switched = 2,
TAP = 3,
};
static const char* NetApiNames[];
bool EthEnable{false};
NetApi EthApi{NetApi::Unset};
std::string EthDevice;
bool EthLogDNS{false};
bool InterceptDHCP{false};
u8 PS2IP[4]{};
u8 Mask[4]{};
u8 Gateway[4]{};
u8 DNS1[4]{};
u8 DNS2[4]{};
bool AutoMask{true};
bool AutoGateway{true};
bool AutoDNS1{true};
bool AutoDNS2{true};
bool HddEnable{false};
std::string HddFile;
/* The PS2's HDD max size is 2TB
* which is 2^32 * 512 byte sectors
* Note that we don't yet support
* 48bit LBA, so our limit is lower */
uint HddSizeSectors{0};
DEV9Options();
void LoadSave(SettingsWrapper& wrap);
bool operator==(const DEV9Options& right) const
{
return OpEqu(EthEnable) &&
OpEqu(EthApi) &&
OpEqu(EthDevice) &&
OpEqu(EthLogDNS) &&
OpEqu(InterceptDHCP) &&
(*(int*)PS2IP == *(int*)right.PS2IP) &&
(*(int*)Gateway == *(int*)right.Gateway) &&
(*(int*)DNS1 == *(int*)right.DNS1) &&
(*(int*)DNS2 == *(int*)right.DNS2) &&
OpEqu(AutoMask) &&
OpEqu(AutoGateway) &&
OpEqu(AutoDNS1) &&
OpEqu(AutoDNS2) &&
OpEqu(HddEnable) &&
OpEqu(HddFile) &&
OpEqu(HddSizeSectors);
}
bool operator!=(const DEV9Options& right) const
{
return !this->operator==(right);
}
protected:
static void LoadIPHelper(u8* field, const std::string& setting);
static std::string SaveIPHelper(u8* field);
};
// ------------------------------------------------------------------------
// NOTE: The GUI's GameFixes panel is dependent on the order of bits in this structure.
struct GamefixOptions
@ -833,6 +907,7 @@ struct Pcsx2Config
DebugOptions Debugger;
FramerateOptions Framerate;
SPU2Options SPU2;
DEV9Options DEV9;
TraceLogFilters Trace;

View File

@ -171,7 +171,7 @@ public:
private:
//Info
void CreateHDDinfo(int sizeMb);
void CreateHDDinfo(u64 sizeSectors);
void CreateHDDinfoCsum();
//State

View File

@ -44,11 +44,11 @@ void ATA::WritePaddedString(u8* data, int* index, std::string value, u32 len)
*index += len;
}
void ATA::CreateHDDinfo(int sizeMb)
void ATA::CreateHDDinfo(u64 sizeSectors)
{
const u16 sectorSize = 512;
DevCon.WriteLn("DEV9: HddSize : %i", config.HddSize);
const u64 nbSectors = ((u64)(sizeMb / sectorSize) * 1024 * 1024);
DevCon.WriteLn("DEV9: HddSize : %i", sizeSectors * sectorSize / (1024 * 1024));
const u64 nbSectors = sizeSectors;
DevCon.WriteLn("DEV9: nbSectors : %i", nbSectors);
memset(&identifyData, 0, sizeof(identifyData));

View File

@ -31,14 +31,14 @@ int ATA::Open(fs::path hddPath)
readBufferLen = 256 * 512;
readBuffer = new u8[readBufferLen];
CreateHDDinfo(config.HddSize);
CreateHDDinfo(EmuConfig.DEV9.HddSizeSectors);
//Open File
if (!fs::exists(hddPath))
{
HddCreate hddCreator;
hddCreator.filePath = hddPath;
hddCreator.neededSize = config.HddSize;
hddCreator.neededSize = ((u64)EmuConfig.DEV9.HddSizeSectors) * 512;
hddCreator.Start();
if (hddCreator.errored)
@ -396,7 +396,7 @@ bool ATA::HDD_CanAccess(int* sectors)
s64 posEnd;
s64 maxLBA;
maxLBA = std::min<s64>((s64)config.HddSize * 1024 * 1024 / 512, hddImageSize) - 1;
maxLBA = std::min<s64>(EmuConfig.DEV9.HddSizeSectors, hddImageSize / 512) - 1;
if ((regSelect & 0x40) == 0) //CHS mode
maxLBA = std::min<s64>(maxLBA, curCylinders * curHeads * curSectors);

View File

@ -73,7 +73,7 @@ void ATA::HDD_IdentifyDevice()
DevCon.WriteLn("DEV9: HddidentifyDevice");
//IDE transfer start
CreateHDDinfo(config.HddSize);
CreateHDDinfo(EmuConfig.DEV9.HddSizeSectors);
pioDRQEndTransferFunc = nullptr;
DRQCmdPIODataToHost(identifyData, 256 * 2, 0, 256 * 2, true);

View File

@ -32,8 +32,13 @@ void HddCreate::Start()
return;
}
#endif
int reqMiB = (neededSize + ((1024 * 1024) - 1)) / (1024 * 1024);
#ifndef PCSX2_CORE
//This creates a modeless dialog
progressDialog = new wxProgressDialog(_("Creating HDD file"), _("Creating HDD file"), neededSize, nullptr, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME);
progressDialog = new wxProgressDialog(_("Creating HDD file"), _("Creating HDD file"), reqMiB, nullptr, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME);
#endif
fileThread = std::thread(&HddCreate::WriteImage, this, filePath, neededSize);
@ -45,9 +50,9 @@ void HddCreate::Start()
//Instead, loop here to update UI
wxString msg;
int currentSize;
while ((currentSize = written.load()) != neededSize && !errored.load())
while ((currentSize = written.load()) != reqMiB && !errored.load())
{
msg.Printf(_("%i / %i MiB"), written.load(), neededSize);
msg.Printf(_("%i / %i MiB"), written.load(), reqMiB);
#ifndef PCSX2_CORE
if (!progressDialog->Update(currentSize, msg))
@ -78,7 +83,7 @@ void HddCreate::Start()
completedCV.notify_all();
}
void HddCreate::WriteImage(fs::path hddPath, int reqSizeMiB)
void HddCreate::WriteImage(fs::path hddPath, u64 reqSizeBytes)
{
constexpr int buffsize = 4 * 1024;
u8 buff[buffsize] = {0}; //4kb
@ -98,7 +103,7 @@ void HddCreate::WriteImage(fs::path hddPath, int reqSizeMiB)
}
//Size file
newImage.seekp(((u64)reqSizeMiB) * 1024 * 1024 - 1, std::ios::beg);
newImage.seekp(reqSizeBytes - 1, std::ios::beg);
const char zero = 0;
newImage.write(&zero, 1);
@ -114,9 +119,13 @@ void HddCreate::WriteImage(fs::path hddPath, int reqSizeMiB)
newImage.seekp(0, std::ios::beg);
for (int iMiB = 0; iMiB < reqSizeMiB; iMiB++)
//Round up
const s32 reqMiB = (reqSizeBytes + ((1024 * 1024) - 1)) / (1024 * 1024);
for (s32 iMiB = 0; iMiB < reqMiB; iMiB++)
{
for (int i4kb = 0; i4kb < 256; i4kb++)
//Round down
const s32 req4Kib = std::min<s32>(1024, (reqSizeBytes / 1024) - (u64)iMiB * 1024) / 4;
for (s32 i4kb = 0; i4kb < req4Kib; i4kb++)
{
newImage.write((char*)buff, buffsize);
if (newImage.fail())
@ -128,8 +137,21 @@ void HddCreate::WriteImage(fs::path hddPath, int reqSizeMiB)
}
}
if (req4Kib != 256)
{
const s32 remainingBytes = reqSizeBytes - (((u64)iMiB) * (1024 * 1024) + req4Kib * 4096);
newImage.write((char*)buff, remainingBytes);
if (newImage.fail())
{
newImage.close();
fs::remove(filePath);
SetError();
return;
}
}
const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastUpdate).count() >= 100 || (iMiB + 1) == neededSize)
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - lastUpdate).count() >= 100 || (iMiB + 1) == reqMiB)
{
lastUpdate = now;
SetFileProgress(iMiB + 1);

View File

@ -29,7 +29,7 @@ class HddCreate
{
public:
fs::path filePath;
int neededSize;
u64 neededSize;
std::atomic_bool errored{false};
@ -55,5 +55,5 @@ public:
private:
void SetFileProgress(int currentSize);
void SetError();
void WriteImage(fs::path hddPath, int reqSizeMB);
void WriteImage(fs::path hddPath, u64 reqSizeBytes);
};

View File

@ -28,7 +28,7 @@
#include "common/StringUtil.h"
#include "DEV9Config.h"
#include "Config.h"
#include "DEV9.h"
#include "pcap_io.h"
#include "net.h"
@ -81,7 +81,7 @@ class DEV9Dialog : public wxDialog
IPControl_SetValue(m_ip, ip);
m_auto->SetValue(is_auto);
}
void save(IP_Address& ip, int& is_auto)
void save(IP_Address& ip, bool& is_auto)
{
ip = IPControl_GetValue(m_ip);
is_auto = m_auto->GetValue();
@ -90,7 +90,7 @@ class DEV9Dialog : public wxDialog
wxCheckBox* m_eth_enable;
wxChoice* m_eth_adapter_api;
wxChoice* m_eth_adapter;
std::vector<NetApi> m_api_list;
std::vector<Pcsx2Config::DEV9Options::NetApi> m_api_list;
std::vector<std::vector<AdapterEntry>> m_adapter_list;
wxCheckBox* m_intercept_dhcp;
wxTextCtrl* m_ps2_address;
@ -143,8 +143,8 @@ public:
std::sort(list.begin(), list.end(), [](const AdapterEntry& a, AdapterEntry& b){ return a.name < b.name; });
wxArrayString adapter_api_name_list;
adapter_api_name_list.Add("");
for (const NetApi& type : m_api_list)
adapter_api_name_list.Add(NetApiToWxString(type));
for (const Pcsx2Config::DEV9Options::NetApi& type : m_api_list)
adapter_api_name_list.Add(Pcsx2Config::DEV9Options::NetApiNames[(int)type]);
auto* eth_adapter_api_label = new wxStaticText(this, wxID_ANY, _("Ethernet Device Type:"));
auto* eth_adapter_label = new wxStaticText(this, wxID_ANY, _("Ethernet Device:"));
@ -218,9 +218,9 @@ public:
Bind(wxEVT_BUTTON, &DEV9Dialog::OnOK, this, wxID_OK);
}
void Load(const ConfigDEV9& config)
void Load(const Pcsx2Config::DEV9Options& config)
{
m_eth_enable->SetValue(config.ethEnable);
m_eth_enable->SetValue(config.EthEnable);
m_eth_adapter_api->SetSelection(0);
for (size_t i = 0; i < m_api_list.size(); i++)
{
@ -234,7 +234,7 @@ public:
const auto& list = m_adapter_list[static_cast<u32>(config.EthApi)];
for (size_t i = 0; i < list.size(); i++)
{
if (list[i].guid == config.Eth)
if (list[i].guid == config.EthDevice)
{
m_eth_adapter->SetSelection(i + 1);
break;
@ -242,47 +242,48 @@ public:
}
}
m_intercept_dhcp->SetValue(config.InterceptDHCP);
IPControl_SetValue(m_ps2_address, config.PS2IP);
m_subnet_mask .load(config.Mask, config.AutoMask);
m_gateway_address.load(config.Gateway, config.AutoGateway);
m_dns1_address .load(config.DNS1, config.AutoDNS1);
m_dns2_address .load(config.DNS2, config.AutoDNS2);
IPControl_SetValue(m_ps2_address, *(IP_Address*)config.PS2IP);
m_subnet_mask .load(*(IP_Address*)config.Mask, config.AutoMask);
m_gateway_address.load(*(IP_Address*)config.Gateway, config.AutoGateway);
m_dns1_address .load(*(IP_Address*)config.DNS1, config.AutoDNS1);
m_dns2_address .load(*(IP_Address*)config.DNS2, config.AutoDNS2);
m_hdd_enable->SetValue(config.hddEnable);
m_hdd_file->SetInitialDirectory(config.Hdd);
m_hdd_file->SetPath(config.Hdd);
m_hdd_size_spin->SetValue(config.HddSize / 1024);
m_hdd_size_slider->SetValue(config.HddSize / 1024);
m_hdd_enable->SetValue(config.HddEnable);
wxString wxHddFile = StringUtil::UTF8StringToWxString(config.HddFile);
m_hdd_file->SetInitialDirectory(wxHddFile);
m_hdd_file->SetPath(wxHddFile);
m_hdd_size_spin->SetValue((u64)config.HddSizeSectors * 512 / (1024 * 1024 * 1024));
m_hdd_size_slider->SetValue((u64)config.HddSizeSectors * 512 / (1024 * 1024 * 1024));
UpdateEnable();
}
void Save(ConfigDEV9& config)
void Save(Pcsx2Config::DEV9Options& config)
{
config.ethEnable = m_eth_enable->GetValue();
config.EthEnable = m_eth_enable->GetValue();
int api = m_eth_adapter_api->GetSelection();
int eth = m_eth_adapter->GetSelection();
if (api && eth)
{
const AdapterEntry& adapter = m_adapter_list[static_cast<u32>(m_api_list[api - 1])][eth - 1];
wxStrncpy(config.Eth, adapter.guid, std::size(config.Eth) - 1);
config.EthDevice = adapter.guid;
config.EthApi = adapter.type;
}
else
{
config.Eth[0] = 0;
config.EthApi = NetApi::Unset;
config.EthDevice = "";
config.EthApi = Pcsx2Config::DEV9Options::NetApi::Unset;
}
config.InterceptDHCP = m_intercept_dhcp->GetValue();
config.PS2IP = IPControl_GetValue(m_ps2_address);
m_subnet_mask .save(config.Mask, config.AutoMask);
m_gateway_address.save(config.Gateway, config.AutoGateway);
m_dns1_address .save(config.DNS1, config.AutoDNS1);
m_dns2_address .save(config.DNS2, config.AutoDNS2);
*(IP_Address*)&config.PS2IP = IPControl_GetValue(m_ps2_address);
m_subnet_mask .save(*(IP_Address*)config.Mask, config.AutoMask);
m_gateway_address.save(*(IP_Address*)config.Gateway, config.AutoGateway);
m_dns1_address .save(*(IP_Address*)config.DNS1, config.AutoDNS1);
m_dns2_address .save(*(IP_Address*)config.DNS2, config.AutoDNS2);
config.hddEnable = m_hdd_enable->GetValue();
wxStrncpy(config.Hdd, m_hdd_file->GetPath(), std::size(config.Hdd) - 1);
config.HddSize = m_hdd_size_spin->GetValue() * 1024;
config.HddEnable = m_hdd_enable->GetValue();
config.HddFile = StringUtil::wxStringToUTF8String(m_hdd_file->GetPath());
config.HddSizeSectors = (u64)m_hdd_size_spin->GetValue() * 1024 * 1024 * 1024 / 512;
}
void UpdateEnable()
@ -317,7 +318,7 @@ public:
if (m_eth_adapter->GetCount())
current = m_eth_adapter->GetString(m_eth_adapter->GetSelection());
if (current.empty())
current = config.Eth;
current = StringUtil::UTF8StringToWxString(g_Conf->EmuOptions.DEV9.EthDevice);
for (size_t i = 0; i < list.size(); i++)
{
wxString wxAdapterName = StringUtil::UTF8StringToWxString(list[i].name);
@ -375,14 +376,12 @@ void DEV9configure()
ScopedCoreThreadPause paused_core;
DEV9Dialog dialog;
LoadConf();
dialog.Load(config);
dialog.Load(g_Conf->EmuOptions.DEV9);
if (dialog.ShowModal() == wxID_OK)
{
ConfigDEV9 oldConfig = config;
dialog.Save(config);
dialog.Save(g_Conf->EmuOptions.DEV9);
fs::path hddPath(config.Hdd);
fs::path hddPath(g_Conf->EmuOptions.DEV9.HddFile);
if (hddPath.is_relative())
{
@ -391,17 +390,15 @@ void DEV9configure()
hddPath = path / hddPath;
}
if (config.hddEnable && !fs::exists(hddPath))
if (g_Conf->EmuOptions.DEV9.HddEnable && !fs::exists(hddPath))
{
HddCreate hddCreator;
hddCreator.filePath = hddPath;
hddCreator.neededSize = config.HddSize;
hddCreator.neededSize = ((u64)g_Conf->EmuOptions.DEV9.HddSizeSectors) * 512;
hddCreator.Start();
}
SaveConf();
ApplyConfigIfRunning(oldConfig);
AppSaveSettings();
}
paused_core.AllowResume();

View File

@ -33,6 +33,7 @@
#define EXTERN
#include "DEV9.h"
#undef EXTERN
#include "Config.h"
#include "DEV9Config.h"
#include "smap.h"
@ -94,10 +95,10 @@ bool isRunning = false;
fs::path GetHDDPath()
{
//GHC uses UTF8 on all platforms
fs::path hddPath(config.Hdd);
fs::path hddPath(EmuConfig.DEV9.HddFile);
if (hddPath.empty())
config.hddEnable = false;
EmuConfig.DEV9.HddEnable = false;
if (hddPath.is_relative())
{
@ -198,25 +199,18 @@ void DEV9shutdown()
s32 DEV9open()
{
DevCon.WriteLn("DEV9: DEV9open");
LoadConf();
#ifdef _WIN32
//Convert to utf8
char mbHdd[sizeof(config.Hdd)] = {0};
WideCharToMultiByte(CP_UTF8, 0, config.Hdd, -1, mbHdd, sizeof(mbHdd) - 1, nullptr, nullptr);
DevCon.WriteLn("DEV9: open r+: %s", mbHdd);
#else
DevCon.WriteLn("DEV9: open r+: %s", config.Hdd);
#endif
LoadDnsHosts();
DevCon.WriteLn("DEV9: open r+: %s", EmuConfig.DEV9.HddFile.c_str());
fs::path hddPath = GetHDDPath();
if (config.hddEnable)
if (EmuConfig.DEV9.HddEnable)
{
if (dev9.ata->Open(hddPath) != 0)
config.hddEnable = false;
EmuConfig.DEV9.HddEnable = false;
}
if (config.ethEnable)
if (EmuConfig.DEV9.EthEnable)
InitNet();
isRunning = true;
@ -316,7 +310,7 @@ void FIFOIntr()
u8 DEV9read8(u32 addr)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return 0;
u8 hard;
@ -382,7 +376,7 @@ u8 DEV9read8(u32 addr)
u16 DEV9read16(u32 addr)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return 0;
u16 hard;
@ -458,9 +452,9 @@ u16 DEV9read16(u32 addr)
case SPD_R_REV_3:
hard = 0;
if (config.hddEnable)
if (EmuConfig.DEV9.HddEnable)
hard |= SPD_CAPS_ATA;
if (config.ethEnable)
if (EmuConfig.DEV9.EthEnable)
hard |= SPD_CAPS_SMAP;
hard |= SPD_CAPS_FLASH;
//DevCon.WriteLn("DEV9: SPD_R_REV_3 16bit read %x", hard);
@ -522,7 +516,7 @@ u16 DEV9read16(u32 addr)
u32 DEV9read32(u32 addr)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return 0;
u32 hard;
@ -548,7 +542,7 @@ u32 DEV9read32(u32 addr)
void DEV9write8(u32 addr, u8 value)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return;
if (addr >= ATA_DEV9_HDD_BASE && addr < ATA_DEV9_HDD_END)
@ -660,7 +654,7 @@ void DEV9write8(u32 addr, u8 value)
void DEV9write16(u32 addr, u16 value)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return;
if (addr >= ATA_DEV9_HDD_BASE && addr < ATA_DEV9_HDD_END)
@ -970,7 +964,7 @@ void DEV9write16(u32 addr, u16 value)
void DEV9write32(u32 addr, u32 value)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return;
if (addr >= ATA_DEV9_HDD_BASE && addr < ATA_DEV9_HDD_END)
@ -1006,7 +1000,7 @@ void DEV9write32(u32 addr, u32 value)
void DEV9readDMA8Mem(u32* pMem, int size)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return;
size >>= 1;
@ -1032,7 +1026,7 @@ void DEV9readDMA8Mem(u32* pMem, int size)
void DEV9writeDMA8Mem(u32* pMem, int size)
{
if (!config.ethEnable & !config.hddEnable)
if (!EmuConfig.DEV9.EthEnable && !EmuConfig.DEV9.HddEnable)
return;
size >>= 1;
@ -1062,44 +1056,36 @@ void DEV9async(u32 cycles)
dev9.ata->Async(cycles);
}
void ApplyConfigIfRunning(ConfigDEV9 oldConfig)
void DEV9CheckChanges(const Pcsx2Config& old_config)
{
if (!isRunning)
return;
//Eth
ReconfigureLiveNet(&oldConfig);
ReconfigureLiveNet(old_config);
//Hdd
//Hdd Validate Path
fs::path hddPath = GetHDDPath();
//Hdd Compare with old config
if (config.hddEnable)
if (EmuConfig.DEV9.HddEnable)
{
if (oldConfig.hddEnable)
if (old_config.DEV9.HddEnable)
{
//ATA::Open/Close dosn't set any regs
//So we can close/open to apply settings
#ifdef _WIN32
if (wcscmp(config.Hdd, oldConfig.Hdd))
#else
if (strcmp(config.Hdd, oldConfig.Hdd))
#endif
if (EmuConfig.DEV9.HddFile != old_config.DEV9.HddFile ||
EmuConfig.DEV9.HddSizeSectors != old_config.DEV9.HddSizeSectors)
{
dev9.ata->Close();
if (dev9.ata->Open(hddPath) != 0)
config.hddEnable = false;
}
if (config.HddSize != oldConfig.HddSize)
{
dev9.ata->Close();
if (dev9.ata->Open(hddPath) != 0)
config.hddEnable = false;
EmuConfig.DEV9.HddEnable = false;
}
}
else if (dev9.ata->Open(hddPath) != 0)
EmuConfig.DEV9.HddEnable = false;
}
else if (oldConfig.hddEnable)
else if (old_config.DEV9.HddEnable)
dev9.ata->Close();
}

View File

@ -65,29 +65,7 @@ struct ConfigHost
struct ConfigDEV9
{
char Eth[256];
NetApi EthApi;
bool InterceptDHCP;
PacketReader::IP::IP_Address PS2IP;
PacketReader::IP::IP_Address Mask;
PacketReader::IP::IP_Address Gateway;
PacketReader::IP::IP_Address DNS1;
PacketReader::IP::IP_Address DNS2;
int AutoMask;
int AutoGateway;
int AutoDNS1;
int AutoDNS2;
int EthLogDNS;
std::vector<ConfigHost> EthHosts;
#ifdef _WIN32
wchar_t Hdd[256];
#else
char Hdd[256];
#endif
int HddSize;
int hddEnable;
int ethEnable;
};
@ -738,7 +716,7 @@ u32 DEV9read32(u32 addr);
void DEV9write8(u32 addr, u8 value);
void DEV9write16(u32 addr, u16 value);
void DEV9write32(u32 addr, u32 value);
void ApplyConfigIfRunning(ConfigDEV9 oldConfig);
void DEV9CheckChanges(const Pcsx2Config& old_config);
#ifdef _WIN32
#pragma warning(error : 4013)

View File

@ -70,7 +70,7 @@ void LoadDnsHosts()
{
wxFileName iniPath = EmuFolders::Settings.Combine(wxString("DEV9Hosts.ini"));
config.EthHosts.clear();
//If no file exists, create one to provice an example config
//If no file exists, create one to provide an example config
if (!iniPath.FileExists())
{
//Load Default settings
@ -120,7 +120,7 @@ void LoadDnsHosts()
else
ini.Entry(L"Enabled", entry.Enabled, false);
if (config.EthLogDNS && entry.Enabled)
if (EmuConfig.DEV9.EthLogDNS && entry.Enabled)
Console.WriteLn("DEV9: Host entry %i: url %s mapped to %s", i, entry.Url.c_str(), tmp.ToStdString().c_str());
config.EthHosts.push_back(entry);

View File

@ -13,8 +13,5 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
void SaveConf();
void LoadConf();
void SaveDnsHosts();
void LoadDnsHosts();

View File

@ -52,30 +52,30 @@ namespace InternalServers
void DHCP_Server::Init(ifaddrs* adapter)
#endif
{
ps2IP = config.PS2IP;
ps2IP = *(IP_Address*)&EmuConfig.DEV9.PS2IP;
netmask = {0};
gateway = {0};
dns1 = {0};
dns2 = {0};
broadcastIP = {0};
if (config.AutoMask)
if (EmuConfig.DEV9.AutoMask)
AutoNetmask(adapter);
else
netmask = config.Mask;
netmask = *(IP_Address*)EmuConfig.DEV9.Mask;
if (config.AutoGateway)
if (EmuConfig.DEV9.AutoGateway)
AutoGateway(adapter);
else
gateway = config.Gateway;
gateway = *(IP_Address*)EmuConfig.DEV9.Gateway;
if (!config.AutoDNS1)
dns1 = config.DNS1;
if (!EmuConfig.DEV9.AutoDNS1)
dns1 = *(IP_Address*)EmuConfig.DEV9.DNS1;
if (!config.AutoDNS2)
dns2 = config.DNS2;
if (!EmuConfig.DEV9.AutoDNS2)
dns2 = *(IP_Address*)EmuConfig.DEV9.DNS2;
AutoDNS(adapter, config.AutoDNS1, config.AutoDNS2);
AutoDNS(adapter, EmuConfig.DEV9.AutoDNS1, EmuConfig.DEV9.AutoDNS2);
AutoBroadcast(ps2IP, netmask);
}

View File

@ -1,240 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2020 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include <stdlib.h>
#include <arpa/inet.h>
#include "DEV9/DEV9.h"
#include "DEV9/Config.h"
#include "Config.h"
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#if defined(__FreeBSD__)
#include <sys/socket.h>
#endif
void SaveConf()
{
xmlDocPtr doc = NULL; /* document pointer */
xmlNodePtr root_node = NULL;
char buff[256];
/*
* Creates a new document, a node and set it as a root node
*/
doc = xmlNewDoc(BAD_CAST "1.0");
root_node = xmlNewNode(NULL, BAD_CAST "dev9");
xmlDocSetRootElement(doc, root_node);
xmlNewChild(root_node, NULL, BAD_CAST "Eth",
BAD_CAST config.Eth);
sprintf(buff, "%d", (int)config.EthApi);
xmlNewChild(root_node, NULL, BAD_CAST "EthApi",
BAD_CAST buff);
sprintf(buff, "%d", config.InterceptDHCP);
xmlNewChild(root_node, NULL, BAD_CAST "InterceptDHCP",
BAD_CAST buff);
inet_ntop(AF_INET, &config.PS2IP, buff, 256);
xmlNewChild(root_node, NULL, BAD_CAST "PS2IP",
BAD_CAST buff);
inet_ntop(AF_INET, &config.Mask, buff, 256);
xmlNewChild(root_node, NULL, BAD_CAST "Subnet",
BAD_CAST buff);
sprintf(buff, "%d", config.AutoMask);
xmlNewChild(root_node, NULL, BAD_CAST "AutoSubnet",
BAD_CAST buff);
inet_ntop(AF_INET, &config.Gateway, buff, 256);
xmlNewChild(root_node, NULL, BAD_CAST "Gateway",
BAD_CAST buff);
sprintf(buff, "%d", config.AutoGateway);
xmlNewChild(root_node, NULL, BAD_CAST "AutoGateway",
BAD_CAST buff);
inet_ntop(AF_INET, &config.DNS1, buff, 256);
xmlNewChild(root_node, NULL, BAD_CAST "DNS1",
BAD_CAST buff);
sprintf(buff, "%d", config.AutoDNS1);
xmlNewChild(root_node, NULL, BAD_CAST "AutoDNS1",
BAD_CAST buff);
inet_ntop(AF_INET, &config.DNS2, buff, 256);
xmlNewChild(root_node, NULL, BAD_CAST "DNS2",
BAD_CAST buff);
sprintf(buff, "%d", config.AutoDNS2);
xmlNewChild(root_node, NULL, BAD_CAST "AutoDNS2",
BAD_CAST buff);
sprintf(buff, "%d", config.EthLogDNS);
xmlNewChild(root_node, NULL, BAD_CAST "EthLogDNS",
BAD_CAST buff);
xmlNewChild(root_node, NULL, BAD_CAST "Hdd",
BAD_CAST config.Hdd);
sprintf(buff, "%d", config.HddSize);
xmlNewChild(root_node, NULL, BAD_CAST "HddSize",
BAD_CAST buff);
sprintf(buff, "%d", config.ethEnable);
xmlNewChild(root_node, NULL, BAD_CAST "ethEnable",
BAD_CAST buff);
sprintf(buff, "%d", config.hddEnable);
xmlNewChild(root_node, NULL, BAD_CAST "hddEnable",
BAD_CAST buff);
/*
* Dumping document to stdio or file
*/
const std::string file(EmuFolders::Settings.Combine(wxString("DEV9.cfg")).GetFullPath());
Console.WriteLn("DEV9: CONF: %s", file.c_str());
xmlSaveFormatFileEnc(file.c_str(), doc, "UTF-8", 1);
// free(configFile);
/*free the document */
xmlFreeDoc(doc);
/*
*Free the global variables that may
*have been allocated by the parser.
*/
xmlCleanupParser();
SaveDnsHosts();
}
void LoadConf()
{
const std::string file(EmuFolders::Settings.Combine(wxString("DEV9.cfg")).GetFullPath());
if (-1 == access(file.c_str(), F_OK))
return;
memset(&config, 0, sizeof(config));
config.EthApi = NetApi::PCAP_Switched;
// Read the files
xmlDoc* doc = NULL;
xmlNode* cur_node = NULL;
doc = xmlReadFile(file.c_str(), NULL, 0);
if (doc == NULL)
{
Console.Error("Unable to parse configuration file! Suggest deleting it and starting over.");
}
for (cur_node = xmlDocGetRootElement(doc)->children; cur_node; cur_node = cur_node->next)
{
if (cur_node->type == XML_ELEMENT_NODE)
{
// printf("node type: Element, name: %s\n", cur_node->name);
if (0 == strcmp((const char*)cur_node->name, "Eth"))
{
strcpy(config.Eth, (const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "EthApi"))
{
config.EthApi = (NetApi)atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "InterceptDHCP"))
{
config.InterceptDHCP = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "PS2IP"))
{
inet_pton(AF_INET, (const char*)xmlNodeGetContent(cur_node), &config.PS2IP);
}
if (0 == strcmp((const char*)cur_node->name, "Subnet"))
{
inet_pton(AF_INET, (const char*)xmlNodeGetContent(cur_node), &config.Mask);
}
if (0 == strcmp((const char*)cur_node->name, "AutoSubnet"))
{
config.AutoMask = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "Gateway"))
{
inet_pton(AF_INET, (const char*)xmlNodeGetContent(cur_node), &config.Gateway);
}
if (0 == strcmp((const char*)cur_node->name, "AutoGateway"))
{
config.AutoGateway = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "DNS1"))
{
inet_pton(AF_INET, (const char*)xmlNodeGetContent(cur_node), &config.DNS1);
}
if (0 == strcmp((const char*)cur_node->name, "AutoDNS1"))
{
config.AutoDNS1 = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "DNS2"))
{
inet_pton(AF_INET, (const char*)xmlNodeGetContent(cur_node), &config.DNS2);
}
if (0 == strcmp((const char*)cur_node->name, "AutoDNS2"))
{
config.AutoDNS2 = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "EthLogDNS"))
{
config.EthLogDNS = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "Hdd"))
{
strcpy(config.Hdd, (const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "HddSize"))
{
config.HddSize = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "ethEnable"))
{
config.ethEnable = atoi((const char*)xmlNodeGetContent(cur_node));
}
if (0 == strcmp((const char*)cur_node->name, "hddEnable"))
{
config.hddEnable = atoi((const char*)xmlNodeGetContent(cur_node));
}
}
}
// free(configFile);
xmlFreeDoc(doc);
xmlCleanupParser();
LoadDnsHosts();
}

View File

@ -1,136 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2020 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include <stdlib.h>
#include <fstream>
#include "DEV9/DEV9.h"
#include "DEV9/DEV9Config.h"
#include "Config.h"
#include "ws2tcpip.h"
BOOL WritePrivateProfileInt(LPCWSTR lpAppName, LPCWSTR lpKeyName, int intvar, LPCWSTR lpFileName)
{
return WritePrivateProfileString(lpAppName, lpKeyName, std::to_wstring(intvar).c_str(), lpFileName);
}
bool FileExists(std::wstring szPath)
{
DWORD dwAttrib = GetFileAttributes(szPath.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
void SaveConf()
{
const std::wstring file(EmuFolders::Settings.Combine(wxString("DEV9.cfg")).GetFullPath());
DeleteFile(file.c_str());
//Create file with UT16 BOM to allow PrivateProfile to save unicode data
int bom = 0xFEFF;
std::fstream nfile = std::fstream(file, std::ios::out | std::ios::binary);
nfile.write((char*)&bom, 2);
//Write header to avoid empty line
nfile.write((char*)L"[DEV9]", 14);
nfile.close();
wchar_t addrBuff[INET_ADDRSTRLEN] = {0};
wchar_t wEth[sizeof(config.Eth)] = {0};
mbstowcs(wEth, config.Eth, sizeof(config.Eth) - 1);
WritePrivateProfileString(L"DEV9", L"Eth", wEth, file.c_str());
WritePrivateProfileInt(L"DEV9", L"EthApi", (int)config.EthApi, file.c_str());
WritePrivateProfileInt(L"DEV9", L"InterceptDHCP", config.InterceptDHCP, file.c_str());
InetNtop(AF_INET, &config.PS2IP, addrBuff, INET_ADDRSTRLEN);
WritePrivateProfileString(L"DEV9", L"PS2IP", addrBuff, file.c_str());
InetNtop(AF_INET, &config.Mask, addrBuff, INET_ADDRSTRLEN);
WritePrivateProfileString(L"DEV9", L"Subnet", addrBuff, file.c_str());
WritePrivateProfileInt(L"DEV9", L"AutoSubnet", config.AutoMask, file.c_str());
InetNtop(AF_INET, &config.Gateway, addrBuff, INET_ADDRSTRLEN);
WritePrivateProfileString(L"DEV9", L"Gateway", addrBuff, file.c_str());
WritePrivateProfileInt(L"DEV9", L"AutoGateway", config.AutoGateway, file.c_str());
InetNtop(AF_INET, &config.DNS1, addrBuff, INET_ADDRSTRLEN);
WritePrivateProfileString(L"DEV9", L"DNS1", addrBuff, file.c_str());
WritePrivateProfileInt(L"DEV9", L"AutoDNS1", config.AutoDNS1, file.c_str());
InetNtop(AF_INET, &config.DNS2, addrBuff, INET_ADDRSTRLEN);
WritePrivateProfileString(L"DEV9", L"DNS2", addrBuff, file.c_str());
WritePrivateProfileInt(L"DEV9", L"AutoDNS2", config.AutoDNS2, file.c_str());
WritePrivateProfileInt(L"DEV9", L"EthLogDNS", config.EthLogDNS, file.c_str());
WritePrivateProfileString(L"DEV9", L"Hdd", config.Hdd, file.c_str());
WritePrivateProfileInt(L"DEV9", L"HddSize", config.HddSize, file.c_str());
WritePrivateProfileInt(L"DEV9", L"ethEnable", config.ethEnable, file.c_str());
WritePrivateProfileInt(L"DEV9", L"hddEnable", config.hddEnable, file.c_str());
SaveDnsHosts();
}
void LoadConf()
{
const std::wstring file(EmuFolders::Settings.Combine(wxString("DEV9.cfg")).GetFullPath());
if (FileExists(file.c_str()) == false)
{
LoadDnsHosts();
return;
}
wchar_t addrBuff[INET_ADDRSTRLEN] = {0};
wchar_t wEth[sizeof(config.Eth)] = {0};
mbstowcs(wEth, ETH_DEF, sizeof(config.Eth) - 1);
GetPrivateProfileString(L"DEV9", L"Eth", wEth, wEth, sizeof(config.Eth), file.c_str());
wcstombs(config.Eth, wEth, sizeof(config.Eth) - 1);
config.EthApi = (NetApi)GetPrivateProfileInt(L"DEV9", L"EthApi", (int)NetApi::TAP, file.c_str());
config.InterceptDHCP = GetPrivateProfileInt(L"DEV9", L"InterceptDHCP", config.InterceptDHCP, file.c_str());
GetPrivateProfileString(L"DEV9", L"PS2IP", L"0.0.0.0", addrBuff, INET_ADDRSTRLEN, file.c_str());
InetPton(AF_INET, addrBuff, &config.PS2IP);
GetPrivateProfileString(L"DEV9", L"Subnet", L"0.0.0.0", addrBuff, INET_ADDRSTRLEN, file.c_str());
InetPton(AF_INET, addrBuff, &config.Mask);
config.AutoMask = GetPrivateProfileInt(L"DEV9", L"AutoSubnet", config.AutoMask, file.c_str());
GetPrivateProfileString(L"DEV9", L"Gateway", L"0.0.0.0", addrBuff, INET_ADDRSTRLEN, file.c_str());
InetPton(AF_INET, addrBuff, &config.Gateway);
config.AutoGateway = GetPrivateProfileInt(L"DEV9", L"AutoGateway", config.AutoGateway, file.c_str());
GetPrivateProfileString(L"DEV9", L"DNS1", L"0.0.0.0", addrBuff, INET_ADDRSTRLEN, file.c_str());
InetPton(AF_INET, addrBuff, &config.DNS1);
config.AutoDNS1 = GetPrivateProfileInt(L"DEV9", L"AutoDNS1", config.AutoDNS1, file.c_str());
GetPrivateProfileString(L"DEV9", L"DNS2", L"0.0.0.0", addrBuff, INET_ADDRSTRLEN, file.c_str());
InetPton(AF_INET, addrBuff, &config.DNS2);
config.AutoDNS2 = GetPrivateProfileInt(L"DEV9", L"AutoDNS2", config.AutoDNS2, file.c_str());
config.EthLogDNS = GetPrivateProfileInt(L"DEV9", L"EthLogDNS", config.EthLogDNS, file.c_str());
GetPrivateProfileString(L"DEV9", L"Hdd", HDD_DEF, config.Hdd, sizeof(config.Hdd), file.c_str());
config.HddSize = GetPrivateProfileInt(L"DEV9", L"HddSize", config.HddSize, file.c_str());
config.ethEnable = GetPrivateProfileInt(L"DEV9", L"ethEnable", config.ethEnable, file.c_str());
config.hddEnable = GetPrivateProfileInt(L"DEV9", L"hddEnable", config.hddEnable, file.c_str());
LoadDnsHosts();
}

View File

@ -218,10 +218,8 @@ static int TAPSetStatus(HANDLE handle, int status)
&status, sizeof(status), &len, NULL);
}
//Open the TAP adapter and set the connection to enabled :)
HANDLE TAPOpen(const char* device_guid)
HANDLE TAPOpen(const std::string& device_guid)
{
char device_path[256];
struct
{
unsigned long major;
@ -230,13 +228,10 @@ HANDLE TAPOpen(const char* device_guid)
} version;
LONG version_len;
sprintf_s(device_path, "%s%s%s",
USERMODEDEVICEDIR,
device_guid,
TAPSUFFIX);
std::string device_path = USERMODEDEVICEDIR + device_guid + TAPSUFFIX;
wil::unique_hfile handle(CreateFileA(
device_path,
device_path.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
0,
@ -282,7 +277,7 @@ PIP_ADAPTER_ADDRESSES FindAdapterViaIndex(PIP_ADAPTER_ADDRESSES adapterList, int
//IP_ADAPTER_ADDRESSES is a structure that contains ptrs to data in other regions
//of the buffer, se we need to return both so the caller can free the buffer
//after it's finished reading the needed data from IP_ADAPTER_ADDRESSES
bool TAPGetWin32Adapter(const char* name, PIP_ADAPTER_ADDRESSES adapter, std::unique_ptr<IP_ADAPTER_ADDRESSES[]>* buffer)
bool TAPGetWin32Adapter(const std::string& name, PIP_ADAPTER_ADDRESSES adapter, std::unique_ptr<IP_ADAPTER_ADDRESSES[]>* buffer)
{
int neededSize = 256;
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> AdapterInfo = std::make_unique<IP_ADAPTER_ADDRESSES[]>(neededSize);
@ -322,7 +317,7 @@ bool TAPGetWin32Adapter(const char* name, PIP_ADAPTER_ADDRESSES adapter, std::un
do
{
if (0 == strcmp(pAdapterInfo->AdapterName, name))
if (0 == strcmp(pAdapterInfo->AdapterName, name.c_str()))
break;
pAdapterInfo = pAdapterInfo->Next;
@ -535,9 +530,9 @@ bool TAPGetWin32Adapter(const char* name, PIP_ADAPTER_ADDRESSES adapter, std::un
TAPAdapter::TAPAdapter()
: NetAdapter()
{
if (config.ethEnable == 0)
if (!EmuConfig.DEV9.EthEnable)
return;
htap = TAPOpen(config.Eth);
htap = TAPOpen(EmuConfig.DEV9.EthDevice);
read.Offset = 0;
read.OffsetHigh = 0;
@ -563,7 +558,7 @@ TAPAdapter::TAPAdapter()
IP_ADAPTER_ADDRESSES adapter;
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> buffer;
if (TAPGetWin32Adapter(config.Eth, &adapter, &buffer))
if (TAPGetWin32Adapter(EmuConfig.DEV9.EthDevice, &adapter, &buffer))
InitInternalServer(&adapter);
else
{
@ -658,7 +653,7 @@ void TAPAdapter::reloadSettings()
{
IP_ADAPTER_ADDRESSES adapter;
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> buffer;
if (TAPGetWin32Adapter(config.Eth, &adapter, &buffer))
if (TAPGetWin32Adapter(EmuConfig.DEV9.EthDevice, &adapter, &buffer))
ReloadInternalServer(&adapter);
else
ReloadInternalServer(nullptr);

View File

@ -71,15 +71,15 @@ NetAdapter* GetNetAdapter()
{
NetAdapter* na = nullptr;
switch (config.EthApi)
switch (EmuConfig.DEV9.EthApi)
{
#ifdef _WIN32
case NetApi::TAP:
case Pcsx2Config::DEV9Options::NetApi::TAP:
na = static_cast<NetAdapter*>(new TAPAdapter());
break;
#endif
case NetApi::PCAP_Bridged:
case NetApi::PCAP_Switched:
case Pcsx2Config::DEV9Options::NetApi::PCAP_Bridged:
case Pcsx2Config::DEV9Options::NetApi::PCAP_Switched:
na = static_cast<NetAdapter*>(new PCAPAdapter());
break;
default:
@ -101,7 +101,7 @@ void InitNet()
if (!na)
{
Console.Error("DEV9: Failed to GetNetAdapter()");
config.ethEnable = false;
EmuConfig.DEV9.EthEnable = false;
return;
}
@ -123,16 +123,16 @@ void InitNet()
#endif
}
void ReconfigureLiveNet(ConfigDEV9* oldConfig)
void ReconfigureLiveNet(const Pcsx2Config& old_config)
{
//Eth
if (config.ethEnable)
if (EmuConfig.DEV9.EthEnable)
{
if (oldConfig->ethEnable)
if (old_config.DEV9.EthEnable)
{
//Reload Net if adapter changed
if (strcmp(oldConfig->Eth, config.Eth) != 0 ||
oldConfig->EthApi != config.EthApi)
if (EmuConfig.DEV9.EthDevice != old_config.DEV9.EthDevice ||
EmuConfig.DEV9.EthApi != old_config.DEV9.EthApi)
{
TermNet();
InitNet();
@ -144,7 +144,7 @@ void ReconfigureLiveNet(ConfigDEV9* oldConfig)
else
InitNet();
}
else if (oldConfig->ethEnable)
else if (old_config.DEV9.EthEnable)
TermNet();
}
@ -163,21 +163,6 @@ void TermNet()
}
}
const wxChar* NetApiToWxString(NetApi api)
{
switch (api)
{
case NetApi::PCAP_Bridged:
return _("PCAP Bridged");
case NetApi::PCAP_Switched:
return _("PCAP Switched");
case NetApi::TAP:
return _("TAP");
default:
return _("UNK");
}
}
using namespace PacketReader;
using namespace PacketReader::IP;
using namespace PacketReader::IP::UDP;
@ -224,7 +209,7 @@ NetAdapter::~NetAdapter()
void NetAdapter::InspectSend(NetPacket* pkt)
{
if (config.EthLogDNS)
if (EmuConfig.DEV9.EthLogDNS)
{
EthernetFrame frame(pkt);
if (frame.protocol == (u16)EtherType::IPv4)
@ -249,7 +234,7 @@ void NetAdapter::InspectSend(NetPacket* pkt)
}
void NetAdapter::InspectRecv(NetPacket* pkt)
{
if (config.EthLogDNS)
if (EmuConfig.DEV9.EthLogDNS)
{
EthernetFrame frame(pkt);
if (frame.protocol == (u16)EtherType::IPv4)
@ -313,7 +298,7 @@ void NetAdapter::InitInternalServer(ifaddrs* adapter)
if (adapter == nullptr)
Console.Error("DEV9: InitInternalServer() got nullptr for adapter");
if (config.InterceptDHCP)
if (EmuConfig.DEV9.InterceptDHCP)
dhcpServer.Init(adapter);
dnsServer.Init(adapter);
@ -334,7 +319,7 @@ void NetAdapter::ReloadInternalServer(ifaddrs* adapter)
if (adapter == nullptr)
Console.Error("DEV9: ReloadInternalServer() got nullptr for adapter");
if (config.InterceptDHCP)
if (EmuConfig.DEV9.InterceptDHCP)
dhcpServer.Init(adapter);
dnsServer.Init(adapter);
@ -391,7 +376,7 @@ bool NetAdapter::InternalServerSend(NetPacket* pkt)
if (udppkt.destinationPort == 67)
{
//Send DHCP
if (config.InterceptDHCP)
if (EmuConfig.DEV9.InterceptDHCP)
return dhcpServer.Send(&udppkt);
}
}

View File

@ -58,17 +58,9 @@ extern mtfifo<NetPacket*> rx_fifo;
extern mtfifo<NetPacket*> tx_fifo;
*/
enum struct NetApi : int
{
Unset = 0,
PCAP_Bridged = 1,
PCAP_Switched = 2,
TAP = 3,
};
struct AdapterEntry
{
NetApi type;
Pcsx2Config::DEV9Options::NetApi type;
//UTF8
std::string name;
std::string guid;
@ -133,7 +125,5 @@ private:
void tx_put(NetPacket* ptr);
void InitNet();
void ReconfigureLiveNet(ConfigDEV9* oldConfig);
void ReconfigureLiveNet(const Pcsx2Config& old_config);
void TermNet();
const wxChar* NetApiToWxString(NetApi api);

View File

@ -60,7 +60,7 @@ mac_address host_mac;
//IP_ADAPTER_ADDRESSES is a structure that contains ptrs to data in other regions
//of the buffer, se we need to return both so the caller can free the buffer
//after it's finished reading the needed data from IP_ADAPTER_ADDRESSES
bool PCAPGetWin32Adapter(const char* name, PIP_ADAPTER_ADDRESSES adapter, std::unique_ptr<IP_ADAPTER_ADDRESSES[]>* buffer)
bool PCAPGetWin32Adapter(const std::string& name, PIP_ADAPTER_ADDRESSES adapter, std::unique_ptr<IP_ADAPTER_ADDRESSES[]>* buffer)
{
const int guidindex = strlen("\\Device\\NPF_");
@ -99,7 +99,7 @@ bool PCAPGetWin32Adapter(const char* name, PIP_ADAPTER_ADDRESSES adapter, std::u
do
{
if (0 == strcmp(pAdapterInfo->AdapterName, &name[guidindex]))
if (0 == strcmp(pAdapterInfo->AdapterName, &name.c_str()[guidindex]))
{
*adapter = *pAdapterInfo;
buffer->swap(AdapterInfo);
@ -112,7 +112,7 @@ bool PCAPGetWin32Adapter(const char* name, PIP_ADAPTER_ADDRESSES adapter, std::u
}
#elif defined(__POSIX__)
//getifaddrs is not POSIX, but is supported on MAC & Linux
bool PCAPGetIfAdapter(char* name, ifaddrs* adapter, ifaddrs** buffer)
bool PCAPGetIfAdapter(const std::string& name, ifaddrs* adapter, ifaddrs** buffer)
{
//Note, we don't support "any" adapter, but that also fails in pcap_io_init()
ifaddrs* adapterInfo;
@ -126,7 +126,7 @@ bool PCAPGetIfAdapter(char* name, ifaddrs* adapter, ifaddrs** buffer)
do
{
if (pAdapter->ifa_addr != nullptr && pAdapter->ifa_addr->sa_family == AF_INET && strcmp(pAdapter->ifa_name, name) == 0)
if (pAdapter->ifa_addr != nullptr && pAdapter->ifa_addr->sa_family == AF_INET && strcmp(pAdapter->ifa_name, name.c_str()) == 0)
break;
pAdapter = pAdapter->ifa_next;
@ -145,7 +145,7 @@ bool PCAPGetIfAdapter(char* name, ifaddrs* adapter, ifaddrs** buffer)
#endif
// Fetches the MAC address and prints it
int GetMACAddress(char* adapter, mac_address* addr)
int GetMACAddress(const std::string& adapter, mac_address* addr)
{
int retval = 0;
#ifdef _WIN32
@ -161,7 +161,7 @@ int GetMACAddress(char* adapter, mac_address* addr)
#elif defined(__linux__)
struct ifreq ifr;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
strcpy(ifr.ifr_name, adapter);
strcpy(ifr.ifr_name, adapter.c_str());
if (0 == ioctl(fd, SIOCGIFHWADDR, &ifr))
{
retval = 1;
@ -169,7 +169,7 @@ int GetMACAddress(char* adapter, mac_address* addr)
}
else
{
Console.Error("Could not get MAC address for adapter: %s", adapter);
Console.Error("Could not get MAC address for adapter: %s", adapter.c_str());
}
close(fd);
#else
@ -178,18 +178,18 @@ int GetMACAddress(char* adapter, mac_address* addr)
return retval;
}
int pcap_io_init(char* adapter, bool switched, mac_address virtual_mac)
int pcap_io_init(const std::string& adapter, bool switched, mac_address virtual_mac)
{
struct bpf_program fp;
char filter[1024] = "ether broadcast or ether dst ";
int dlt;
char* dlt_name;
Console.WriteLn("DEV9: Opening adapter '%s'...", adapter);
Console.WriteLn("DEV9: Opening adapter '%s'...", adapter.c_str());
pcap_io_switched = switched;
/* Open the adapter */
if ((adhandle = pcap_open_live(adapter, // name of the device
if ((adhandle = pcap_open_live(adapter.c_str(), // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs.
switched ? 1 : 0,
@ -198,7 +198,7 @@ int pcap_io_init(char* adapter, bool switched, mac_address virtual_mac)
)) == NULL)
{
Console.Error("DEV9: %s", errbuf);
Console.Error("DEV9: Unable to open the adapter. %s is not supported by pcap", adapter);
Console.Error("DEV9: Unable to open the adapter. %s is not supported by pcap", adapter.c_str());
return -1;
}
if (switched)
@ -358,9 +358,8 @@ void pcap_io_close()
PCAPAdapter::PCAPAdapter()
: NetAdapter()
{
if (config.ethEnable == 0)
if (!EmuConfig.DEV9.EthEnable)
return;
#ifdef _WIN32
if (!load_pcap())
return;
@ -369,7 +368,7 @@ PCAPAdapter::PCAPAdapter()
mac_address hostMAC;
mac_address newMAC;
GetMACAddress(config.Eth, &hostMAC);
GetMACAddress(EmuConfig.DEV9.EthDevice, &hostMAC);
memcpy(&newMAC, ps2MAC, 6);
//Lets take the hosts last 2 bytes to make it unique on Xlink
@ -380,16 +379,16 @@ PCAPAdapter::PCAPAdapter()
host_mac = hostMAC;
ps2_mac = newMAC; //Needed outside of this class
if (pcap_io_init(config.Eth, config.EthApi == NetApi::PCAP_Switched, newMAC) == -1)
if (pcap_io_init(EmuConfig.DEV9.EthDevice, EmuConfig.DEV9.EthApi == Pcsx2Config::DEV9Options::NetApi::PCAP_Switched, newMAC) == -1)
{
Console.Error("DEV9: Can't open Device '%s'", config.Eth);
Console.Error("DEV9: Can't open Device '%s'", EmuConfig.DEV9.EthDevice.c_str());
return;
}
#ifdef _WIN32
IP_ADAPTER_ADDRESSES adapter;
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> buffer;
if (PCAPGetWin32Adapter(config.Eth, &adapter, &buffer))
if (PCAPGetWin32Adapter(EmuConfig.DEV9.EthDevice, &adapter, &buffer))
InitInternalServer(&adapter);
else
{
@ -399,7 +398,7 @@ PCAPAdapter::PCAPAdapter()
#elif defined(__POSIX__)
ifaddrs adapter;
ifaddrs* buffer;
if (PCAPGetIfAdapter(config.Eth, &adapter, &buffer))
if (PCAPGetIfAdapter(EmuConfig.DEV9.EthDevice, &adapter, &buffer))
{
InitInternalServer(&adapter);
freeifaddrs(buffer);
@ -457,14 +456,14 @@ void PCAPAdapter::reloadSettings()
#ifdef _WIN32
IP_ADAPTER_ADDRESSES adapter;
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> buffer;
if (PCAPGetWin32Adapter(config.Eth, &adapter, &buffer))
if (PCAPGetWin32Adapter(EmuConfig.DEV9.EthDevice, &adapter, &buffer))
ReloadInternalServer(&adapter);
else
ReloadInternalServer(nullptr);
#elif defined(__POSIX__)
ifaddrs adapter;
ifaddrs* buffer;
if (PCAPGetIfAdapter(config.Eth, &adapter, &buffer))
if (PCAPGetIfAdapter(EmuConfig.DEV9.EthDevice, &adapter, &buffer))
{
ReloadInternalServer(&adapter);
freeifaddrs(buffer);
@ -500,7 +499,7 @@ std::vector<AdapterEntry> PCAPAdapter::GetAdapters()
while (d != NULL)
{
AdapterEntry entry;
entry.type = NetApi::PCAP_Switched;
entry.type = Pcsx2Config::DEV9Options::NetApi::PCAP_Switched;
#ifdef _WIN32
//guid
entry.guid = std::string(d->name);
@ -531,7 +530,7 @@ std::vector<AdapterEntry> PCAPAdapter::GetAdapters()
#endif
nic.push_back(entry);
entry.type = NetApi::PCAP_Bridged;
entry.type = Pcsx2Config::DEV9Options::NetApi::PCAP_Bridged;
nic.push_back(entry);
d = d->next;
}

View File

@ -651,6 +651,78 @@ void Pcsx2Config::SPU2Options::LoadSave(SettingsWrapper& wrap)
}
}
const char* Pcsx2Config::DEV9Options::NetApiNames[] = {
"Unset",
"PCAP Bridged",
"PCAP Switched",
"TAP",
nullptr};
Pcsx2Config::DEV9Options::DEV9Options()
{
HddFile = "DEV9hdd.raw";
}
void Pcsx2Config::DEV9Options::LoadSave(SettingsWrapper& wrap)
{
{
SettingsWrapSection("DEV9/Eth");
SettingsWrapEntry(EthEnable);
SettingsWrapEnumEx(EthApi, "EthApi", NetApiNames);
SettingsWrapEntry(EthDevice);
SettingsWrapEntry(EthLogDNS);
SettingsWrapEntry(InterceptDHCP);
std::string ps2IPStr = "0.0.0.0";
std::string gatewayStr = "0.0.0.0";
std::string dns1Str = "0.0.0.0";
std::string dns2Str = "0.0.0.0";
if (wrap.IsSaving())
{
ps2IPStr = SaveIPHelper(PS2IP);
gatewayStr = SaveIPHelper(Gateway);
dns1Str = SaveIPHelper(DNS1);
dns2Str = SaveIPHelper(DNS2);
}
SettingsWrapEntryEx(ps2IPStr, "PS2IP");
SettingsWrapEntryEx(gatewayStr, "Gateway");
SettingsWrapEntryEx(dns1Str, "DNS1");
SettingsWrapEntryEx(dns2Str, "DNS2");
if (wrap.IsLoading())
{
LoadIPHelper(PS2IP, ps2IPStr);
LoadIPHelper(Gateway, gatewayStr);
LoadIPHelper(DNS1, dns1Str);
LoadIPHelper(DNS1, dns1Str);
}
SettingsWrapEntry(AutoMask);
SettingsWrapEntry(AutoGateway);
SettingsWrapEntry(AutoDNS1);
SettingsWrapEntry(AutoDNS2);
}
{
SettingsWrapSection("DEV9/Hdd");
SettingsWrapEntry(HddEnable);
SettingsWrapEntry(HddFile);
SettingsWrapEntry(HddSizeSectors);
}
}
void Pcsx2Config::DEV9Options::LoadIPHelper(u8* field, const std::string& setting)
{
if (4 == sscanf(setting.c_str(), "%hhu.%hhu.%hhu.%hhu", &field[0], &field[1], &field[2], &field[3]))
return;
Console.Error("Invalid IP address in settings file");
std::fill(field, field + 4, 0);
}
std::string Pcsx2Config::DEV9Options::SaveIPHelper(u8* field)
{
return StringUtil::StdStringFromFormat("%u.%u.%u.%u", field[0], field[1], field[2], field[3]);
}
static const char* const tbl_GamefixNames[] =
{
"FpuMul",
@ -947,6 +1019,7 @@ void Pcsx2Config::LoadSave(SettingsWrapper& wrap)
// SPU2 is in a separate ini in wx.
SPU2.LoadSave(wrap);
#endif
DEV9.LoadSave(wrap);
Gamefixes.LoadSave(wrap);
Profiler.LoadSave(wrap);
@ -1021,6 +1094,7 @@ bool Pcsx2Config::operator==(const Pcsx2Config& right) const
OpEqu(bitset) &&
OpEqu(Cpu) &&
OpEqu(GS) &&
OpEqu(DEV9) &&
OpEqu(Speedhacks) &&
OpEqu(Gamefixes) &&
OpEqu(Profiler) &&
@ -1042,6 +1116,7 @@ void Pcsx2Config::CopyConfig(const Pcsx2Config& cfg)
{
Cpu = cfg.Cpu;
GS = cfg.GS;
DEV9 = cfg.DEV9;
Speedhacks = cfg.Speedhacks;
Gamefixes = cfg.Gamefixes;
Profiler = cfg.Profiler;

View File

@ -187,8 +187,13 @@ void SysCoreThread::ApplySettings(const Pcsx2Config& src)
const bool gs_settings_changed = !src.GS.OptionsAreEqual(EmuConfig.GS);
Pcsx2Config old_config;
old_config.CopyConfig(EmuConfig);
EmuConfig.CopyConfig(src);
// handle DEV9 setting changes
DEV9CheckChanges(old_config);
// handle GS setting changes
if (GetMTGS().IsOpen() && gs_settings_changed)
{

View File

@ -44,6 +44,7 @@
#include "PerformanceMetrics.h"
#include "R5900.h"
#include "SPU2/spu2.h"
#include "DEV9/DEV9.h"
#include "System/SysThreads.h"
#include "USB/USB.h"
#include "PAD/Host/PAD.h"
@ -71,6 +72,7 @@ namespace VMManager
static void CheckForFramerateConfigChanges(const Pcsx2Config& old_config);
static void CheckForPatchConfigChanges(const Pcsx2Config& old_config);
static void CheckForSPU2ConfigChanges(const Pcsx2Config& old_config);
static void CheckForDEV9ConfigChanges(const Pcsx2Config& old_config);
static void CheckForMemoryCardConfigChanges(const Pcsx2Config& old_config);
static void UpdateRunningGame(bool force);
@ -1074,6 +1076,14 @@ void VMManager::CheckForSPU2ConfigChanges(const Pcsx2Config& old_config)
}
}
void VMManager::CheckForDEV9ConfigChanges(const Pcsx2Config& old_config)
{
if (EmuConfig.DEV9 == old_config.DEV9)
return;
DEV9CheckChanges(old_config);
}
void VMManager::CheckForMemoryCardConfigChanges(const Pcsx2Config& old_config)
{
bool changed = false;
@ -1118,6 +1128,7 @@ void VMManager::CheckForConfigChanges(const Pcsx2Config& old_config)
CheckForFramerateConfigChanges(old_config);
CheckForPatchConfigChanges(old_config);
CheckForSPU2ConfigChanges(old_config);
CheckForDEV9ConfigChanges(old_config);
CheckForMemoryCardConfigChanges(old_config);
if (EmuConfig.EnableCheats != old_config.EnableCheats || EmuConfig.EnableWideScreenPatches != old_config.EnableWideScreenPatches)

View File

@ -304,7 +304,6 @@
<ClCompile Include="DEV9\pcap_io.cpp" />
<ClCompile Include="DEV9\Win32\pcap_io_win32.cpp" />
<ClCompile Include="DEV9\smap.cpp" />
<ClCompile Include="DEV9\Win32\DEV9WinConfig.cpp" />
<ClCompile Include="DEV9\net.cpp" />
<ClCompile Include="DEV9\Win32\tap-win32.cpp" />
<ClCompile Include="Frontend\D3D11HostDisplay.cpp" />

View File

@ -1262,9 +1262,6 @@
<ClCompile Include="DEV9\Win32\tap-win32.cpp">
<Filter>System\Ps2\DEV9</Filter>
</ClCompile>
<ClCompile Include="DEV9\Win32\DEV9WinConfig.cpp">
<Filter>System\Ps2\DEV9</Filter>
</ClCompile>
<ClCompile Include="USB\configuration.cpp">
<Filter>System\Ps2\USB</Filter>
</ClCompile>

View File

@ -169,7 +169,6 @@
<ClCompile Include="DEV9\pcap_io.cpp" />
<ClCompile Include="DEV9\Win32\pcap_io_win32.cpp" />
<ClCompile Include="DEV9\smap.cpp" />
<ClCompile Include="DEV9\Win32\DEV9WinConfig.cpp" />
<ClCompile Include="DEV9\net.cpp" />
<ClCompile Include="DEV9\Win32\tap-win32.cpp" />
<ClCompile Include="Frontend\D3D11HostDisplay.cpp" />

View File

@ -923,9 +923,6 @@
<ClCompile Include="DEV9\Win32\tap-win32.cpp">
<Filter>System\Ps2\DEV9</Filter>
</ClCompile>
<ClCompile Include="DEV9\Win32\DEV9WinConfig.cpp">
<Filter>System\Ps2\DEV9</Filter>
</ClCompile>
<ClCompile Include="GS\GS.cpp">
<Filter>System\Ps2\GS</Filter>
</ClCompile>