From 20b43ac1c58859e786caca1211ee59fc9f79f9b1 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Mon, 14 Jan 2013 00:16:10 +1300 Subject: [PATCH] Fix a bug introduced by me when I thought I was fixing something. Thanks skidau. Fixes Mario Kart Wii not being able to write. This was caused by reuse of a buffer containing an error code. --- .../Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp | 20 +++++++++---------- .../Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp | 15 ++++++++------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp index 044e2e821b..0572e01e4c 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp @@ -182,20 +182,20 @@ void CWII_IPC_HLE_Device_FileIO::CloseFile() bool CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress) { u32 ReturnValue = FS_RESULT_FATAL; - const u32 SeekPosition = Memory::Read_U32(_CommandAddress + 0xC); - const u32 Mode = Memory::Read_U32(_CommandAddress + 0x10); + const s32 SeekPosition = Memory::Read_U32(_CommandAddress + 0xC); + const s32 Mode = Memory::Read_U32(_CommandAddress + 0x10); if (OpenFile()) { ReturnValue = FS_RESULT_FATAL; - const u64 fileSize = m_pFileHandle.GetSize(); - INFO_LOG(WII_IPC_FILEIO, "FileIO: Seek Pos: 0x%08x, Mode: %i (%s, Length=0x%08llx)", SeekPosition, Mode, m_Name.c_str(), fileSize); + const s64 fileSize = m_pFileHandle.GetSize(); + INFO_LOG(WII_IPC_FILEIO, "FileIO: Seek Pos: 0x%08x, Mode: %i (%s, Length=0x%08llx) (%08X)", SeekPosition, Mode, m_Name.c_str(), fileSize, m_DeviceID); switch (Mode){ case 0: { - if (SeekPosition <= fileSize) + if ((SeekPosition >=0) && (SeekPosition <= fileSize)) { m_SeekPos = SeekPosition; ReturnValue = m_SeekPos; @@ -204,8 +204,8 @@ bool CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress) } case 1: { - u32 wantedPos = SeekPosition+m_SeekPos; - if (wantedPos <= fileSize) + s32 wantedPos = SeekPosition+m_SeekPos; + if (wantedPos >=0 && wantedPos <= fileSize) { m_SeekPos = wantedPos; ReturnValue = m_SeekPos; @@ -214,8 +214,8 @@ bool CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress) } case 2: { - u64 wantedPos = fileSize+m_SeekPos; - if (wantedPos <= fileSize) + s32 wantedPos = fileSize+m_SeekPos; + if (wantedPos >=0 && wantedPos <= fileSize) { m_SeekPos = wantedPos; ReturnValue = m_SeekPos; @@ -328,12 +328,12 @@ bool CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress) { case ISFS_IOCTL_GETFILESTATS: { + INFO_LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS"); if (OpenFile()) { u32 m_FileLength = (u32)m_pFileHandle.GetSize(); const u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18); - INFO_LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS"); INFO_LOG(WII_IPC_FILEIO, " File: %s, Length: %i, Pos: %i", m_Name.c_str(), m_FileLength, m_SeekPos); Memory::Write_U32(m_FileLength, BufferOut); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp index 3bdab17e2f..24f1d80bb7 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -133,6 +133,7 @@ bool CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress) case IOCTL_NWC24_SUSPEND_SCHEDULAR: // NWC24iResumeForCloseLib from NWC24SuspendScheduler (Input: none, Output: 32 bytes) WARN_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_SUSPEND_SCHEDULAR - NI"); + Memory::Write_U32(0, BufferOut); // no error break; case IOCTL_NWC24_EXEC_TRY_SUSPEND_SCHEDULAR: // NWC24iResumeForCloseLib @@ -141,6 +142,7 @@ bool CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress) case IOCTL_NWC24_EXEC_RESUME_SCHEDULAR : // NWC24iResumeForCloseLib WARN_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_EXEC_RESUME_SCHEDULAR - NI"); + Memory::Write_U32(0, BufferOut); // no error break; case IOCTL_NWC24_STARTUP_SOCKET: // NWC24iStartupSocket @@ -169,7 +171,6 @@ bool CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress) case IOCTL_NWC24_REQUEST_GENERATED_USER_ID: // (Input: none, Output: 32 bytes) WARN_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_GENERATED_USER_ID"); - if(config.CreationStage() == nwc24_config_t::NWC24_IDCS_INITIAL) { std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING); @@ -212,14 +213,16 @@ bool CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress) } else if(config.CreationStage() == nwc24_config_t::NWC24_IDCS_GENERATED) + { Memory::Write_U32(nwc24_err_t::WC24_ERR_ID_GENERATED, BufferOut); + } else if(config.CreationStage() == nwc24_config_t::NWC24_IDCS_REGISTERED) + { Memory::Write_U32(nwc24_err_t::WC24_ERR_ID_REGISTERED, BufferOut); - + } Memory::Write_U64(config.Id(), BufferOut + 4); Memory::Write_U32(config.CreationStage(), BufferOut + 0xC); break; - case IOCTL_NWC24_GET_SCHEDULAR_STAT: WARN_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_GET_SCHEDULAR_STAT - NI"); break; @@ -1656,9 +1659,9 @@ u32 CWII_IPC_HLE_Device_net_ip_top::ExecuteCommandV(SIOCtlVBuffer& CommandBuffer hints.ai_socktype = Memory::Read_U32(_BufferIn3 + 0x8); hints.ai_protocol = Memory::Read_U32(_BufferIn3 + 0xC); hints.ai_addrlen = Memory::Read_U32(_BufferIn3 + 0x10); - hints.ai_canonname = (char*)Memory::GetPointer(Memory::Read_U32(_BufferIn3 + 0x14)); - hints.ai_addr = (sockaddr *)Memory::GetPointer(Memory::Read_U32(_BufferIn3 + 0x18)); - hints.ai_next = (addrinfo *)Memory::GetPointer(Memory::Read_U32(_BufferIn3 + 0x1C)); + hints.ai_canonname = (char*)Memory::Read_U32(_BufferIn3 + 0x14); + hints.ai_addr = (sockaddr *)Memory::Read_U32(_BufferIn3 + 0x18); + hints.ai_next = (addrinfo *)Memory::Read_U32(_BufferIn3 + 0x1C); } char* pNodeName = NULL;