Wii IOS FileIO: Fixed bug "NewSeekPosition = 0" to "NewSeekPosition = SeekPosition", now Zelda TP savegames should work as well as other games
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1981 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
e332e18ce6
commit
d7fe42d069
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "FileUtil.h"
|
#include "FileUtil.h"
|
||||||
|
#include "StringUtil.h"
|
||||||
|
|
||||||
#include "WII_IPC_HLE_Device_FileIO.h"
|
#include "WII_IPC_HLE_Device_FileIO.h"
|
||||||
|
|
||||||
|
@ -39,9 +40,9 @@ std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size)
|
||||||
}
|
}
|
||||||
|
|
||||||
CWII_IPC_HLE_Device_FileIO::CWII_IPC_HLE_Device_FileIO(u32 _DeviceID, const std::string& _rDeviceName )
|
CWII_IPC_HLE_Device_FileIO::CWII_IPC_HLE_Device_FileIO(u32 _DeviceID, const std::string& _rDeviceName )
|
||||||
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
|
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
|
||||||
, m_pFileHandle(NULL)
|
, m_pFileHandle(NULL)
|
||||||
, m_FileLength(0)
|
, m_FileLength(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,14 +124,35 @@ CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress)
|
||||||
u32 SeekPosition = Memory::Read_U32(_CommandAddress + 0xC);
|
u32 SeekPosition = Memory::Read_U32(_CommandAddress + 0xC);
|
||||||
u32 Mode = Memory::Read_U32(_CommandAddress +0x10);
|
u32 Mode = Memory::Read_U32(_CommandAddress +0x10);
|
||||||
|
|
||||||
LOG(WII_IPC_FILEIO, "FileIO: Seek Pos: %i, Mode: %i (Device=%s)", SeekPosition, Mode, GetDeviceName().c_str());
|
LOG(WII_IPC_FILEIO, "FileIO: Old Seek Pos: %s, Mode: %i (Device=%s, FileSize=%s)", ThS(SeekPosition).c_str(), Mode, GetDeviceName().c_str(), ThS(m_FileLength).c_str());
|
||||||
|
|
||||||
|
/* Zelda - TP Fix: It doesn't make much sense but it works in Zelda - TP and
|
||||||
|
it's probably better than trying to read outside the file (it seeks to 0x6000 instead
|
||||||
|
of the correct 0x2000 for the second half of the file). Could this be right
|
||||||
|
or has it misunderstood the filesize somehow? My guess is that the filesize is
|
||||||
|
hardcoded in to the game, and it never checks the filesize, so I don't know.
|
||||||
|
Maybe it's wrong to return the seekposition when it's zero? Perhaps it wants
|
||||||
|
the filesize then? - No, that didn't work either, it seeks to 0x6000 even if I return
|
||||||
|
0x4000 from the first seek. */
|
||||||
|
u32 NewSeekPosition = SeekPosition;
|
||||||
|
if (m_FileLength > 0 && SeekPosition > m_FileLength && Mode == 0)
|
||||||
|
{
|
||||||
|
NewSeekPosition = SeekPosition % m_FileLength;
|
||||||
|
LOG(WII_IPC_FILEIO, "***********************************:");
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(WII_IPC_FILEIO, "FileIO: New Seek Pos: %s, Mode: %i (Device=%s)", ThS(NewSeekPosition).c_str(), Mode, GetDeviceName().c_str());
|
||||||
|
|
||||||
|
// Set seek mode
|
||||||
int seek_mode[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
|
int seek_mode[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
|
||||||
|
|
||||||
if (Mode >= 0 && Mode <= 2) {
|
if (Mode >= 0 && Mode <= 2)
|
||||||
if (fseek(m_pFileHandle, SeekPosition, seek_mode[Mode]) == 0) {
|
{
|
||||||
|
if (fseek(m_pFileHandle, NewSeekPosition, seek_mode[Mode]) == 0)
|
||||||
|
{
|
||||||
// Seek always return the seek position for success
|
// Seek always return the seek position for success
|
||||||
// Not sure if it's right in all modes though.
|
// Not sure if it's right in all modes though.
|
||||||
|
// What should we return for Zelda, the new correct or old incorrect seek position?
|
||||||
ReturnValue = SeekPosition;
|
ReturnValue = SeekPosition;
|
||||||
} else {
|
} else {
|
||||||
LOG(WII_IPC_FILEIO, "FILEIO: Seek failed");
|
LOG(WII_IPC_FILEIO, "FILEIO: Seek failed");
|
||||||
|
@ -148,14 +170,14 @@ bool
|
||||||
CWII_IPC_HLE_Device_FileIO::Read(u32 _CommandAddress)
|
CWII_IPC_HLE_Device_FileIO::Read(u32 _CommandAddress)
|
||||||
{
|
{
|
||||||
u32 ReturnValue = 0;
|
u32 ReturnValue = 0;
|
||||||
u32 Address = Memory::Read_U32(_CommandAddress +0xC);
|
u32 Address = Memory::Read_U32(_CommandAddress +0xC); // Read to this memory address
|
||||||
u32 Size = Memory::Read_U32(_CommandAddress +0x10);
|
u32 Size = Memory::Read_U32(_CommandAddress +0x10);
|
||||||
|
|
||||||
if (m_pFileHandle != NULL)
|
if (m_pFileHandle != NULL)
|
||||||
{
|
{
|
||||||
|
LOG(WII_IPC_FILEIO, "FileIO: Read 0x%x bytes to 0x%08x from %s", Size, Address, GetDeviceName().c_str());
|
||||||
size_t readItems = fread(Memory::GetPointer(Address), 1, Size, m_pFileHandle);
|
size_t readItems = fread(Memory::GetPointer(Address), 1, Size, m_pFileHandle);
|
||||||
ReturnValue = (u32)readItems;
|
ReturnValue = (u32)readItems;
|
||||||
LOG(WII_IPC_FILEIO, "FileIO reads from %s (Addr=0x%08x Size=0x%x)", GetDeviceName().c_str(), Address, Size);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -171,10 +193,10 @@ bool
|
||||||
CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
|
CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
|
||||||
{
|
{
|
||||||
u32 ReturnValue = 0;
|
u32 ReturnValue = 0;
|
||||||
u32 Address = Memory::Read_U32(_CommandAddress +0xC);
|
u32 Address = Memory::Read_U32(_CommandAddress +0xC); // Write data from this memory address
|
||||||
u32 Size = Memory::Read_U32(_CommandAddress +0x10);
|
u32 Size = Memory::Read_U32(_CommandAddress +0x10);
|
||||||
|
|
||||||
LOG(WII_IPC_FILEIO, "FileIO: Write Addr: 0x%08x Size: %i (Device=%s)", Address, Size, GetDeviceName().c_str());
|
LOG(WII_IPC_FILEIO, "FileIO: Write 0x%04x bytes to 0x%08x from %s", Size, Address, GetDeviceName().c_str());
|
||||||
|
|
||||||
if (m_pFileHandle)
|
if (m_pFileHandle)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue