From f6c6822f71e795563e5eacdb28c2a740ca79b520 Mon Sep 17 00:00:00 2001 From: comex Date: Mon, 17 Nov 2014 13:40:59 -0500 Subject: [PATCH] The old g_want_determinism check in WiiSockMan missed a few cases. Move to net.cpp. Specifically, things like GETHOSTBYNAME, GETHOSTID, etc. could be done without creating a socket, which is what the old check blocked. Now we check at the ioctl and ioctlv handlers. Might be possible to get a bit more realistic behavior in future by filtering individual ioctls, but it probably doesn't matter. --- .../Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp | 114 ++++++++++-------- Source/Core/Core/IPC_HLE/WII_Socket.cpp | 5 - 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index d52c4b7b9e..69cf92c1ed 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -644,6 +644,13 @@ static unsigned int opt_name_mapping[][2] = { IPCCommandResult CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) { + if (Core::g_want_determinism) + { + Memory::Write_U32(-1, _CommandAddress + 4); + return IPC_DEFAULT_REPLY; + } + + u32 Command = Memory::Read_U32(_CommandAddress + 0x0C); u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10); u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14); @@ -1222,65 +1229,68 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ip_top::IOCtlV(u32 CommandAddress) { u32 address = 0; #ifdef _WIN32 - PIP_ADAPTER_ADDRESSES AdapterAddresses = nullptr; - ULONG OutBufferLength = 0; - ULONG RetVal = 0, i; - for (i = 0; i < 5; ++i) + if (!Core::g_want_determinism) { - RetVal = GetAdaptersAddresses( - AF_INET, - 0, - nullptr, - AdapterAddresses, - &OutBufferLength); - - if (RetVal != ERROR_BUFFER_OVERFLOW) + PIP_ADAPTER_ADDRESSES AdapterAddresses = nullptr; + ULONG OutBufferLength = 0; + ULONG RetVal = 0, i; + for (i = 0; i < 5; ++i) { - break; - } + RetVal = GetAdaptersAddresses( + AF_INET, + 0, + nullptr, + AdapterAddresses, + &OutBufferLength); + if (RetVal != ERROR_BUFFER_OVERFLOW) + { + break; + } + + if (AdapterAddresses != nullptr) + { + FREE(AdapterAddresses); + } + + AdapterAddresses = (PIP_ADAPTER_ADDRESSES)MALLOC(OutBufferLength); + if (AdapterAddresses == nullptr) + { + RetVal = GetLastError(); + break; + } + } + if (RetVal == NO_ERROR) + { + unsigned long dwBestIfIndex = 0; + IPAddr dwDestAddr = (IPAddr)0x08080808; + // If successful, output some information from the data we received + PIP_ADAPTER_ADDRESSES AdapterList = AdapterAddresses; + if (GetBestInterface(dwDestAddr, &dwBestIfIndex) == NO_ERROR) + { + while (AdapterList) + { + if (AdapterList->IfIndex == dwBestIfIndex && + AdapterList->FirstDnsServerAddress && + AdapterList->OperStatus == IfOperStatusUp) + { + INFO_LOG(WII_IPC_NET, "Name of valid interface: %S", AdapterList->FriendlyName); + INFO_LOG(WII_IPC_NET, "DNS: %u.%u.%u.%u", + (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[2], + (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[3], + (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[4], + (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[5]); + address = Common::swap32(*(u32*)(&AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[2])); + break; + } + AdapterList = AdapterList->Next; + } + } + } if (AdapterAddresses != nullptr) { FREE(AdapterAddresses); } - - AdapterAddresses = (PIP_ADAPTER_ADDRESSES)MALLOC(OutBufferLength); - if (AdapterAddresses == nullptr) - { - RetVal = GetLastError(); - break; - } - } - if (RetVal == NO_ERROR) - { - unsigned long dwBestIfIndex = 0; - IPAddr dwDestAddr = (IPAddr)0x08080808; - // If successful, output some information from the data we received - PIP_ADAPTER_ADDRESSES AdapterList = AdapterAddresses; - if (GetBestInterface(dwDestAddr, &dwBestIfIndex) == NO_ERROR) - { - while (AdapterList) - { - if (AdapterList->IfIndex == dwBestIfIndex && - AdapterList->FirstDnsServerAddress && - AdapterList->OperStatus == IfOperStatusUp) - { - INFO_LOG(WII_IPC_NET, "Name of valid interface: %S", AdapterList->FriendlyName); - INFO_LOG(WII_IPC_NET, "DNS: %u.%u.%u.%u", - (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[2], - (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[3], - (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[4], - (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[5]); - address = Common::swap32(*(u32*)(&AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[2])); - break; - } - AdapterList = AdapterList->Next; - } - } - } - if (AdapterAddresses != nullptr) - { - FREE(AdapterAddresses); } #endif if (address == 0) diff --git a/Source/Core/Core/IPC_HLE/WII_Socket.cpp b/Source/Core/Core/IPC_HLE/WII_Socket.cpp index ca8f457738..8799c84d29 100644 --- a/Source/Core/Core/IPC_HLE/WII_Socket.cpp +++ b/Source/Core/Core/IPC_HLE/WII_Socket.cpp @@ -562,11 +562,6 @@ void WiiSockMan::AddSocket(s32 fd) s32 WiiSockMan::NewSocket(s32 af, s32 type, s32 protocol) { - if (Core::g_want_determinism) - { - return SO_ENOMEM; - } - s32 fd = (s32)socket(af, type, protocol); s32 ret = GetNetErrorCode(fd, "NewSocket", false); AddSocket(ret);