diff --git a/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp b/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp index 1c4b3cb23b..4c7de26d02 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp @@ -7,6 +7,22 @@ #include "cellSysutil.h" #include "cellNetCtl.h" +#ifdef _WIN32 +#include +#include + +#pragma comment(lib, "iphlpapi.lib") +#else +#include + +#include +#include +#include +#include +#include +#include +#endif + extern Module cellNetCtl; struct cellNetCtlInternal @@ -89,7 +105,128 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr info) if (code == CELL_NET_CTL_INFO_IP_ADDRESS) { - strcpy_trunc(info->ip_address, "192.168.1.1"); +#ifdef _WIN32 + PIP_ADAPTER_INFO pAdapterInfo; + pAdapterInfo = (IP_ADAPTER_INFO*) malloc(sizeof(IP_ADAPTER_INFO)); + ULONG buflen = sizeof(IP_ADAPTER_INFO); + + if (GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) + { + free(pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO*) malloc(buflen); + } + + if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) + { + PIP_ADAPTER_INFO pAdapter = pAdapterInfo; + + for (int c = 0; c < Ini.NETInterface.GetValue(); c++) + { + pAdapter = pAdapter->Next; + } + + strcpy_trunc(info->ip_address, pAdapter->IpAddressList.IpAddress.String); + } + else + { + cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): Call to GetAdaptersInfo failed."); + // 0.0.0.0 seems to be the default address when no ethernet cables are connected to the PS3 + strcpy_trunc(info->ip_address, "0.0.0.0"); + } +#else + struct ifaddrs *ifaddr, *ifa; + int family, s, n; + char host[NI_MAXHOST]; + + if (getifaddrs(&ifaddr) == -1) + { + LOG_ERROR(HLE, "Call to getifaddrs returned negative."); + } + + for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) + { + if (ifa->ifa_addr == NULL) + { + continue; + } + + if (n < Ini.NETInterface.GetValue()) + { + continue; + } + + family = ifa->ifa_addr->sa_family; + + if (family == AF_INET) + { + strcpy_trunc(info->ip_address, ifaddrs->ifa_addr->sa_data); + } + } + + freeifaddrs(ifaddr); +#endif + } + else if (code == CELL_NET_CTL_INFO_NETMASK) + { +#ifdef _WIN32 + PIP_ADAPTER_INFO pAdapterInfo; + pAdapterInfo = (IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO)); + ULONG buflen = sizeof(IP_ADAPTER_INFO); + + if (GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) + { + free(pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO*)malloc(buflen); + } + + if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) + { + PIP_ADAPTER_INFO pAdapter = pAdapterInfo; + + for (int c = 0; c < Ini.NETInterface.GetValue(); c++) + { + pAdapter = pAdapter->Next; + } + + strcpy_trunc(info->ip_address, pAdapter->IpAddressList.IpMask.String); + } + else + { + cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): Call to GetAdaptersInfo failed."); + // TODO: What would be the default netmask? 255.255.255.0? + } +#else + struct ifaddrs *ifaddr, *ifa; + int family, s, n; + char host[NI_MAXHOST]; + + if (getifaddrs(&ifaddr) == -1) + { + LOG_ERROR(HLE, "Call to getifaddrs returned negative."); + } + + for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) + { + if (ifa->ifa_addr == NULL) + { + continue; + } + + if (n < Ini.NETInterface.GetValue()) + { + continue; + } + + family = ifa->ifa_addr->sa_family; + + if (family == AF_INET) + { + strcpy_trunc(info->ip_address, ifaddrs->ifa_netmask->sa_data); + } + } + + freeifaddrs(ifaddr); +#endif } return CELL_OK; diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 1c1bb00ad9..5e4eacad73 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -5,8 +5,21 @@ #include "rpcs3.h" #include "MainFrame.h" -#ifndef _WIN32 +#ifdef _WIN32 +#include +#include + +#pragma comment(lib, "iphlpapi.lib") +#else #include "frame_icon.xpm" + +#include +#include +#include +#include +#include +#include +#include #endif #include "git-version.h" @@ -348,7 +361,7 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) } wxDialog diag(this, wxID_ANY, "Settings", wxDefaultPosition); - static const u32 width = 425; + static const u32 width = 452; static const u32 height = 460; // Settings panels @@ -357,25 +370,25 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) wxPanel* p_cpu = new wxPanel(nb_config, wxID_ANY); wxPanel* p_graphics = new wxPanel(nb_config, wxID_ANY); wxPanel* p_audio = new wxPanel(nb_config, wxID_ANY); - wxPanel* p_camera = new wxPanel(nb_config, wxID_ANY); wxPanel* p_io = new wxPanel(nb_config, wxID_ANY); wxPanel* p_hle = new wxPanel(nb_config, wxID_ANY); + wxPanel* p_networking = new wxPanel(nb_config, wxID_ANY); - nb_config->AddPage(p_cpu, wxT("Core")); - nb_config->AddPage(p_graphics, wxT("Graphics")); - nb_config->AddPage(p_audio, wxT("Audio")); - nb_config->AddPage(p_camera, wxT("Camera")); - nb_config->AddPage(p_io, wxT("Input / Output")); - nb_config->AddPage(p_hle, wxT("HLE / Misc.")); - nb_config->AddPage(p_system, wxT("System")); + nb_config->AddPage(p_cpu, wxT("Core")); + nb_config->AddPage(p_graphics, wxT("Graphics")); + nb_config->AddPage(p_audio, wxT("Audio")); + nb_config->AddPage(p_io, wxT("Input / Output")); + nb_config->AddPage(p_hle, wxT("HLE / Misc.")); + nb_config->AddPage(p_networking, wxT("Networking")); + nb_config->AddPage(p_system, wxT("System")); - wxBoxSizer* s_subpanel_system = new wxBoxSizer(wxVERTICAL); - wxBoxSizer* s_subpanel_cpu = new wxBoxSizer(wxVERTICAL); - wxBoxSizer* s_subpanel_graphics = new wxBoxSizer(wxVERTICAL); - wxBoxSizer* s_subpanel_audio = new wxBoxSizer(wxVERTICAL); - wxBoxSizer* s_subpanel_camera = new wxBoxSizer(wxVERTICAL); - wxBoxSizer* s_subpanel_io = new wxBoxSizer(wxVERTICAL); - wxBoxSizer* s_subpanel_hle = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* s_subpanel_system = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* s_subpanel_cpu = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* s_subpanel_graphics = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* s_subpanel_audio = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* s_subpanel_io = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* s_subpanel_hle = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* s_subpanel_networking = new wxBoxSizer(wxVERTICAL); // CPU/SPU settings wxStaticBoxSizer* s_round_cpu_decoder = new wxStaticBoxSizer(wxVERTICAL, p_cpu, _("CPU")); @@ -391,17 +404,18 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) wxStaticBoxSizer* s_round_io_pad_handler = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Pad Handler")); wxStaticBoxSizer* s_round_io_keyboard_handler = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Keyboard Handler")); wxStaticBoxSizer* s_round_io_mouse_handler = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Mouse Handler")); + wxStaticBoxSizer* s_round_io_camera = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Camera")); + wxStaticBoxSizer* s_round_io_camera_type = new wxStaticBoxSizer(wxVERTICAL, p_io, _("Camera type")); // Audio wxStaticBoxSizer* s_round_audio_out = new wxStaticBoxSizer(wxVERTICAL, p_audio, _("Audio Out")); - // Camera - wxStaticBoxSizer* s_round_camera = new wxStaticBoxSizer(wxVERTICAL, p_camera, _("Camera")); - wxStaticBoxSizer* s_round_camera_type = new wxStaticBoxSizer(wxVERTICAL, p_camera, _("Camera type")); - // HLE / Misc. wxStaticBoxSizer* s_round_hle_log_lvl = new wxStaticBoxSizer(wxVERTICAL, p_hle, _("Log Level")); - wxStaticBoxSizer* s_round_net_status = new wxStaticBoxSizer(wxVERTICAL, p_hle, _("Connection status")); + + // Networking + wxStaticBoxSizer* s_round_net_status = new wxStaticBoxSizer(wxVERTICAL, p_networking, _("Connection status")); + wxStaticBoxSizer* s_round_net_interface = new wxStaticBoxSizer(wxVERTICAL, p_networking, _("Network adapter")); // System wxStaticBoxSizer* s_round_sys_lang = new wxStaticBoxSizer(wxVERTICAL, p_system, _("Language")); @@ -415,11 +429,12 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) wxComboBox* cbox_pad_handler = new wxComboBox(p_io, wxID_ANY); wxComboBox* cbox_keyboard_handler = new wxComboBox(p_io, wxID_ANY); wxComboBox* cbox_mouse_handler = new wxComboBox(p_io, wxID_ANY); + wxComboBox* cbox_camera = new wxComboBox(p_io, wxID_ANY); + wxComboBox* cbox_camera_type = new wxComboBox(p_io, wxID_ANY); wxComboBox* cbox_audio_out = new wxComboBox(p_audio, wxID_ANY); - wxComboBox* cbox_camera = new wxComboBox(p_camera, wxID_ANY); - wxComboBox* cbox_camera_type = new wxComboBox(p_camera, wxID_ANY); wxComboBox* cbox_hle_loglvl = new wxComboBox(p_hle, wxID_ANY); - wxComboBox* cbox_net_status = new wxComboBox(p_hle, wxID_ANY); + wxComboBox* cbox_net_status = new wxComboBox(p_networking, wxID_ANY); + wxComboBox* cbox_net_interface = new wxComboBox(p_networking, wxID_ANY); wxComboBox* cbox_sys_lang = new wxComboBox(p_system, wxID_ANY); wxCheckBox* chbox_gs_log_prog = new wxCheckBox(p_graphics, wxID_ANY, "Log vertex/fragment programs"); @@ -508,6 +523,60 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) cbox_net_status->Append("Connecting"); cbox_net_status->Append("Disconnected"); +#ifdef _WIN32 + PIP_ADAPTER_INFO pAdapterInfo; + pAdapterInfo = (IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO)); + ULONG buflen = sizeof(IP_ADAPTER_INFO); + + if (GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) + { + free(pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO*)malloc(buflen); + } + + if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) + { + PIP_ADAPTER_INFO pAdapter = pAdapterInfo; + while (pAdapter) + { + std::string adapterName = fmt::Format("%s", pAdapter->Description); + cbox_net_interface->Append(adapterName); + pAdapter = pAdapter->Next; + } + } + else + { + LOG_ERROR(HLE, "Call to GetAdaptersInfo failed."); + } +#else + struct ifaddrs *ifaddr, *ifa; + int family, s, n; + char host[NI_MAXHOST]; + + if (getifaddrs(&ifaddr) == -1) + { + LOG_ERROR(HLE, "Call to getifaddrs returned negative."); + } + + for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) + { + if (ifa->ifa_addr == NULL) + { + continue; + } + + family = ifa->ifa_addr->sa_family; + + if (family == AF_INET || family == AF_INET6) + { + std::string adapterName = fmt::Format("%s", ifa->ifa_name); + cbox_net_interface->Append(adapterName); + } + } + + freeifaddrs(ifaddr); +#endif + cbox_sys_lang->Append("Japanese"); cbox_sys_lang->Append("English (US)"); cbox_sys_lang->Append("French"); @@ -565,27 +634,33 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) cbox_camera_type ->SetSelection(Ini.CameraType.GetValue()); cbox_hle_loglvl ->SetSelection(Ini.HLELogLvl.GetValue()); cbox_net_status ->SetSelection(Ini.NETStatus.GetValue()); + cbox_net_interface ->SetSelection(Ini.NETInterface.GetValue()); cbox_sys_lang ->SetSelection(Ini.SysLanguage.GetValue()); + // Core s_round_cpu_decoder->Add(cbox_cpu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_spu_decoder->Add(cbox_spu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); + // Rendering s_round_gs_render->Add(cbox_gs_render, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_gs_res->Add(cbox_gs_resolution, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_gs_aspect->Add(cbox_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_gs_frame_limit->Add(cbox_gs_frame_limit, wxSizerFlags().Border(wxALL, 5).Expand()); + // Input/Output s_round_io_pad_handler->Add(cbox_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_io_keyboard_handler->Add(cbox_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_io_mouse_handler->Add(cbox_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_io_camera->Add(cbox_camera, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_io_camera_type->Add(cbox_camera_type, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_audio_out->Add(cbox_audio_out, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_camera->Add(cbox_camera, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_camera_type->Add(cbox_camera_type, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_hle_log_lvl->Add(cbox_hle_loglvl, wxSizerFlags().Border(wxALL, 5).Expand()); + + // Networking s_round_net_status->Add(cbox_net_status, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_net_interface->Add(cbox_net_interface, wxSizerFlags().Border(wxALL, 5).Expand()); s_round_sys_lang->Add(cbox_sys_lang, wxSizerFlags().Border(wxALL, 5).Expand()); @@ -609,19 +684,16 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) s_subpanel_io->Add(s_round_io_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_io->Add(s_round_io_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_io->Add(s_round_io_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + s_subpanel_io->Add(s_round_io_camera, wxSizerFlags().Border(wxALL, 5).Expand()); + s_subpanel_io->Add(s_round_io_camera_type, wxSizerFlags().Border(wxALL, 5).Expand()); // Audio s_subpanel_audio->Add(s_round_audio_out, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_audio->Add(chbox_audio_dump, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_audio->Add(chbox_audio_conv, wxSizerFlags().Border(wxALL, 5).Expand()); - // Camera - s_subpanel_camera->Add(s_round_camera, wxSizerFlags().Border(wxALL, 5).Expand()); - s_subpanel_camera->Add(s_round_camera_type, wxSizerFlags().Border(wxALL, 5).Expand()); - // HLE / Misc. s_subpanel_hle->Add(s_round_hle_log_lvl, wxSizerFlags().Border(wxALL, 5).Expand()); - s_subpanel_hle->Add(s_round_net_status, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_hle->Add(chbox_hle_logging, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_hle->Add(chbox_rsx_logging, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_hle->Add(chbox_hle_hook_stfunc, wxSizerFlags().Border(wxALL, 5).Expand()); @@ -629,14 +701,18 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) s_subpanel_hle->Add(chbox_hle_exitonstop, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_hle->Add(chbox_hle_always_start, wxSizerFlags().Border(wxALL, 5).Expand()); - //Auto Pause + // Auto Pause s_subpanel_hle->Add(chbox_dbg_ap_systemcall, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_hle->Add(chbox_dbg_ap_functioncall, wxSizerFlags().Border(wxALL, 5).Expand()); + // Networking + s_subpanel_networking->Add(s_round_net_status, wxSizerFlags().Border(wxALL, 5).Expand()); + s_subpanel_networking->Add(s_round_net_interface, wxSizerFlags().Border(wxALL, 5).Expand()); + // System s_subpanel_system->Add(s_round_sys_lang, wxSizerFlags().Border(wxALL, 5).Expand()); - //Custom EmulationDir + // Custom EmulationDir s_subpanel_system->Add(chbox_emulationdir_enable, wxSizerFlags().Border(wxALL, 5).Expand()); s_subpanel_system->Add(txt_emulationdir_path, wxSizerFlags().Border(wxALL, 5).Expand()); @@ -650,12 +726,12 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) diag.SetSizerAndFit(s_subpanel_graphics, false); diag.SetSizerAndFit(s_subpanel_io, false); diag.SetSizerAndFit(s_subpanel_audio, false); - diag.SetSizerAndFit(s_subpanel_camera, false); diag.SetSizerAndFit(s_subpanel_hle, false); + diag.SetSizerAndFit(s_subpanel_networking, false); diag.SetSizerAndFit(s_subpanel_system, false); diag.SetSizerAndFit(s_b_panel, false); - diag.SetSize(width+26, height+80); + diag.SetSize(width + 26, height + 80); if(diag.ShowModal() == wxID_OK) { @@ -686,6 +762,7 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) Ini.HLEExitOnStop.SetValue(chbox_hle_exitonstop->GetValue()); Ini.HLELogLvl.SetValue(cbox_hle_loglvl->GetSelection()); Ini.NETStatus.SetValue(cbox_net_status->GetSelection()); + Ini.NETInterface.SetValue(cbox_net_interface->GetSelection()); Ini.SysLanguage.SetValue(cbox_sys_lang->GetSelection()); Ini.HLEAlwaysStart.SetValue(chbox_hle_always_start->GetValue()); diff --git a/rpcs3/Ini.h b/rpcs3/Ini.h index 2f8cb1b144..c3e9432d9a 100644 --- a/rpcs3/Ini.h +++ b/rpcs3/Ini.h @@ -147,6 +147,7 @@ public: // HLE/Miscs IniEntry HLELogLvl; IniEntry NETStatus; + IniEntry NETInterface; IniEntry HLELogging; IniEntry RSXLogging; IniEntry HLEHookStFunc; @@ -230,6 +231,7 @@ public: HLELogging.Init("HLE_HLELogging", path); RSXLogging.Init("RSX_Logging", path); NETStatus.Init("NET_Status", path); + NETInterface.Init("NET_Interface", path); HLEHookStFunc.Init("HLE_HLEHookStFunc", path); HLESaveTTY.Init("HLE_HLESaveTTY", path); HLEExitOnStop.Init("HLE_HLEExitOnStop", path); @@ -308,6 +310,7 @@ public: HLELogging.Load(false); RSXLogging.Load(false); NETStatus.Load(0); + NETInterface.Load(0); HLEHookStFunc.Load(false); HLESaveTTY.Load(false); HLEExitOnStop.Load(false); @@ -386,6 +389,7 @@ public: HLELogging.Save(); RSXLogging.Save(); NETStatus.Save(); + NETInterface.Save(); HLEHookStFunc.Save(); HLESaveTTY.Save(); HLEExitOnStop.Save();