diff --git a/pcsx2/IopBios.cpp b/pcsx2/IopBios.cpp index fd2d51b052..14c12cc525 100644 --- a/pcsx2/IopBios.cpp +++ b/pcsx2/IopBios.cpp @@ -25,6 +25,51 @@ #define O_BINARY 0 #endif +// set this to 0 to disable rewriting 'host:' paths! +#define USE_HOST_REWRITE 1 + +#if USE_HOST_REWRITE +static char HostRoot[1024]; +#endif + +void Hle_SetElfPath(const char* elfFileName) +{ +#if USE_HOST_REWRITE + DevCon.WriteLn("HLE Host: Will load ELF: %s\n", elfFileName); + + const char* pos1 = strrchr(elfFileName,'/'); + const char* pos2 = strrchr(elfFileName,'\\'); + + if(pos2 > pos1) // we want the LAST path separator + pos1=pos2; + + if(!pos1) // if pos1 is NULL, then pos2 was not > pos1, so it must also be NULL + { + Console.Warning("HLE Warning: ELF does not have a path!!\n"); + + // use %CD%/host/ + getcwd(HostRoot,1000); // save the other 23 chars to append /host/ :P + HostRoot[1000]=0; // Be Safe. + + char* last = HostRoot + strlen(HostRoot) - 1; + + if((*last!='/') && (*last!='\\')) // PathAppend()-ish + last++; + + strcpy(last,"/host/"); + + return; + } + + int len = pos1-elfFileName+1; + memcpy(HostRoot,elfFileName,len); // include the / (or \\) + HostRoot[len] = 0; + + Console.WriteLn("HLE Host: Set 'host:' root path to: %s\n", HostRoot); + +#endif +} + namespace R3000A { #define v0 (psxRegs.GPR.n.v0) @@ -107,11 +152,7 @@ public: } else // relative paths { - // this assumes the PWD/CWD points to pcsx2's data folder, - // that is, eitehr the same folder as pcsx2.exe or somethign like - // c:\users\appdata\roaming\pcsx2, documents\pcsx2, $HOME\pcsx2, or similar - - strcpy(pathMod,"host/"); + strcpy(pathMod,HostRoot); strcat(pathMod,path); } #else diff --git a/pcsx2/IopBios.h b/pcsx2/IopBios.h index 83d4b77e2a..b8d3dece5e 100644 --- a/pcsx2/IopBios.h +++ b/pcsx2/IopBios.h @@ -72,4 +72,6 @@ namespace R3000A } } +extern void Hle_SetElfPath(const char* elfFileName); + #endif /* __PSXBIOS_H__ */ diff --git a/pcsx2/System/SysCoreThread.cpp b/pcsx2/System/SysCoreThread.cpp index f514537dbc..a295c7ed7c 100644 --- a/pcsx2/System/SysCoreThread.cpp +++ b/pcsx2/System/SysCoreThread.cpp @@ -16,6 +16,8 @@ #include "PrecompiledHeader.h" #include "Common.h" +#include "IopBios.h" + #include "Counters.h" #include "GS.h" #include "Elfheader.h" @@ -104,6 +106,9 @@ void SysCoreThread::SetElfOverride( const wxString& elf ) { //pxAssertDev( !m_hasValidMachine, "Thread synchronization error while assigning ELF override." ); m_elf_override = elf; + + + Hle_SetElfPath(elf.ToUTF8()); } void SysCoreThread::Reset()