diff --git a/bin/dev_usb000/.gitignore b/bin/dev_usb000/.gitignore new file mode 100644 index 0000000000..86d0cb2726 --- /dev/null +++ b/bin/dev_usb000/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/rpcs3/Emu/FS/VFS.cpp b/rpcs3/Emu/FS/VFS.cpp index 24141c5ff4..148a6b15eb 100644 --- a/rpcs3/Emu/FS/VFS.cpp +++ b/rpcs3/Emu/FS/VFS.cpp @@ -175,17 +175,16 @@ void VFS::SaveLoadDevices(Array& res, bool is_load) res[idx].path = "$(EmulatorDir)\\dev_hdd1\\"; res[idx].mount = "/dev_hdd1/"; res[idx].device = vfsDevice_LocalFile; - /* + idx = res.Move(new VFSManagerEntry()); - res[idx].path = "$(GameDir)"; - res[idx].mount = ""; + res[idx].path = "$(EmulatorDir)\\dev_usb000\\"; + res[idx].mount = "/dev_usb000/"; res[idx].device = vfsDevice_LocalFile; idx = res.Move(new VFSManagerEntry()); - res[idx].path = "$(GameDir)"; - res[idx].mount = "/"; + res[idx].path = "$(EmulatorDir)\\dev_usb000\\"; + res[idx].mount = "/dev_usb/"; res[idx].device = vfsDevice_LocalFile; - */ idx = res.Move(new VFSManagerEntry()); res[idx].path = "$(GameDir)"; @@ -196,6 +195,12 @@ void VFS::SaveLoadDevices(Array& res, bool is_load) res[idx].path = ""; res[idx].mount = "/host_root/"; res[idx].device = vfsDevice_LocalFile; + + idx = res.Move(new VFSManagerEntry()); + res[idx].path = "$(GameDir)"; + res[idx].mount = "/"; + res[idx].device = vfsDevice_LocalFile; + return; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp index 674b7a1d12..0eef3bd6c8 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp @@ -362,7 +362,7 @@ int cellGcmSetFlipCommandWithWaitLabel(u32 ctx, u32 id, u32 label_index, u32 lab int cellGcmSetFlip(mem_ptr_t ctxt, u32 id) { - cellGcmSys.Warning("cellGcmSetFlip(ctx=0x%x, id=0x%x)", ctxt.GetAddr(), id); + cellGcmSys.Log("cellGcmSetFlip(ctx=0x%x, id=0x%x)", ctxt.GetAddr(), id); int res = cellGcmSetPrepareFlip(ctxt, id); return res < 0 ? CELL_GCM_ERROR_FAILURE : CELL_OK; @@ -370,7 +370,7 @@ int cellGcmSetFlip(mem_ptr_t ctxt, u32 id) int cellGcmSetWaitFlip(mem_ptr_t ctxt) { - cellGcmSys.Warning("cellGcmSetWaitFlip(ctx=0x%x)", ctxt.GetAddr()); + cellGcmSys.Log("cellGcmSetWaitFlip(ctx=0x%x)", ctxt.GetAddr()); GSLockCurrent lock(GS_LOCK_WAIT_FLIP); return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp b/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp index 54f4878e00..7ff708405c 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp @@ -172,8 +172,8 @@ int cellPadGetInfo(u32 info_addr) if(i >= pads.GetCount()) break; info.status[i] = re(pads[i].m_port_status); - info.product_id[i] = 0xdead; //TODO - info.vendor_id[i] = 0xbeaf; //TODO + info.product_id[i] = const_se_t::value; + info.vendor_id[i] = const_se_t::value; } Memory.WriteData(info_addr, info); diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index d3b82b1fc5..f3903bcbea 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -6,6 +6,10 @@ #include "Emu/Cell/PPUThread.h" #include "Emu/Cell/SPUThread.h" #include "Emu/Cell/PPUInstrTable.h" + +#include "scetool/scetool.h" + +#include "Loader/SELF.h" #include #include using namespace PPU_instr; @@ -21,7 +25,7 @@ ModuleInitializer::ModuleInitializer() Emulator::Emulator() : m_status(Stopped) , m_mode(DisAsm) - , m_dbg_console(NULL) + , m_dbg_console(nullptr) , m_rsx_callback(0) { } @@ -85,16 +89,126 @@ void Emulator::CheckStatus() } } +bool Emulator::IsSelf(const std::string& path) +{ + vfsLocalFile f(path); + + if(!f.IsOpened()) + return false; + + SceHeader hdr; + hdr.Load(f); + + return hdr.CheckMagic(); +} + +bool Emulator::DecryptSelf(const std::string& elf, const std::string& self) +{ + // Check if the data really needs to be decrypted. + wxFile f(self.c_str()); + + if(!f.IsOpened()) + { + ConLog.Error("Could not open SELF file! (%s)", self.c_str()); + return false; + } + + // Get the key version. + f.Seek(0x08); + be_t key_version; + f.Read(&key_version, sizeof(key_version)); + + if(key_version.ToBE() == const_se_t::value) + { + ConLog.Warning("Debug SELF detected! Removing fake header..."); + + // Get the real elf offset. + f.Seek(0x10); + be_t elf_offset; + f.Read(&elf_offset, sizeof(elf_offset)); + + // Start at the real elf offset. + f.Seek(elf_offset); + + wxFile out(elf.c_str(), wxFile::write); + + if(!out.IsOpened()) + { + ConLog.Error("Could not create ELF file! (%s)", elf.c_str()); + return false; + } + + // Copy the data. + char buf[2048]; + while (ssize_t size = f.Read(buf, 2048)) + out.Write(buf, size); + } + else + { + if (!scetool_decrypt((scetool::s8 *)self.c_str(), (scetool::s8 *)elf.c_str())) + { + ConLog.Write("SELF: Could not decrypt file"); + return false; + } + } + + return true; +} + +bool Emulator::BootGame(const std::string& path) +{ + static const char* elf_path[6] = + { + "\\PS3_GAME\\USRDIR\\BOOT.BIN", + "\\USRDIR\\BOOT.BIN", + "\\BOOT.BIN", + "\\PS3_GAME\\USRDIR\\EBOOT.BIN", + "\\USRDIR\\EBOOT.BIN", + "\\EBOOT.BIN", + }; + + for(int i=0; i -#include "scetool/scetool.cpp" #include "unpkg/unpkg.c" BEGIN_EVENT_TABLE(MainFrame, FrameBase) @@ -22,9 +21,8 @@ END_EVENT_TABLE() enum IDs { id_boot_elf = 0x555, - id_boot_self, id_boot_game, - id_boot_pkg, + id_install_pkg, id_sys_pause, id_sys_stop, id_sys_send_open_menu, @@ -47,43 +45,43 @@ wxString GetPaneName() bool wxMoveDir(wxString sFrom, wxString sTo) { - if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/') sFrom += wxFILE_SEP_PATH; - if (sTo[sTo.Len() - 1] != '\\' && sTo[sTo.Len() - 1] != '/') sTo += wxFILE_SEP_PATH; + if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/') sFrom += wxFILE_SEP_PATH; + if (sTo[sTo.Len() - 1] != '\\' && sTo[sTo.Len() - 1] != '/') sTo += wxFILE_SEP_PATH; - if (!::wxDirExists(sFrom)) { - ::wxLogError(wxT("%s does not exist!\r\nCan not copy directory"), sFrom.c_str()); - return false; - } - if (!wxDirExists(sTo)) { - if (!wxFileName::Mkdir(sTo, 0777, wxPATH_MKDIR_FULL)) { - ::wxLogError(wxT("%s could not be created!"), sTo.c_str()); - return false; - } - } + if (!::wxDirExists(sFrom)) { + ::wxLogError(wxT("%s does not exist!\r\nCan not copy directory"), sFrom.c_str()); + return false; + } + if (!wxDirExists(sTo)) { + if (!wxFileName::Mkdir(sTo, 0777, wxPATH_MKDIR_FULL)) { + ::wxLogError(wxT("%s could not be created!"), sTo.c_str()); + return false; + } + } - wxDir fDir(sFrom); - wxString sNext = wxEmptyString; - bool bIsFile = fDir.GetFirst(&sNext); - while (bIsFile) { - const wxString sFileFrom = sFrom + sNext; - const wxString sFileTo = sTo + sNext; - if (::wxDirExists(sFileFrom)) { - wxMoveDir(sFileFrom, sFileTo); + wxDir fDir(sFrom); + wxString sNext = wxEmptyString; + bool bIsFile = fDir.GetFirst(&sNext); + while (bIsFile) { + const wxString sFileFrom = sFrom + sNext; + const wxString sFileTo = sTo + sNext; + if (::wxDirExists(sFileFrom)) { + wxMoveDir(sFileFrom, sFileTo); ::wxRmdir(sFileFrom); - } - else { - if (!::wxFileExists(sFileTo)) { - if (!::wxCopyFile(sFileFrom, sFileTo)) { - ::wxLogError(wxT("Could not copy %s to %s !"), sFileFrom.c_str(), sFileTo.c_str()); - return false; - } - } + } + else { + if (!::wxFileExists(sFileTo)) { + if (!::wxCopyFile(sFileFrom, sFileTo)) { + ::wxLogError(wxT("Could not copy %s to %s !"), sFileFrom.c_str(), sFileTo.c_str()); + return false; + } + } ::wxRemoveFile(sFileFrom); - } - bIsFile = fDir.GetNext(&sNext); - } + } + bIsFile = fDir.GetNext(&sNext); + } ::wxRmdir(sFrom); - return true; + return true; } MainFrame::MainFrame() @@ -113,10 +111,9 @@ MainFrame::MainFrame() menubar.Append(&menu_help, "Help"); menu_boot.Append(id_boot_game, "Boot game"); - menu_boot.Append(id_boot_pkg, "Install PKG"); + menu_boot.Append(id_install_pkg, "Install PKG"); menu_boot.AppendSeparator(); - menu_boot.Append(id_boot_elf, "Boot ELF"); - menu_boot.Append(id_boot_self, "Boot SELF"); + menu_boot.Append(id_boot_elf, "Boot (S)ELF"); menu_sys.Append(id_sys_pause, "Pause")->Enable(false); menu_sys.Append(id_sys_stop, "Stop\tCtrl + S")->Enable(false); @@ -140,9 +137,8 @@ MainFrame::MainFrame() AddPane(m_game_viewer, "Game List", wxAUI_DOCK_BOTTOM); Connect( id_boot_game, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootGame) ); - Connect( id_boot_pkg, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootPkg) ); + Connect( id_install_pkg, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::InstallPkg) ); Connect( id_boot_elf, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootElf) ); - Connect( id_boot_self, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootSelf) ); Connect( id_sys_pause, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Pause) ); Connect( id_sys_stop, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Stop) ); @@ -209,87 +205,20 @@ void MainFrame::BootGame(wxCommandEvent& WXUNUSED(event)) } Emu.Stop(); - - wxString elf[6] = { - "\\PS3_GAME\\USRDIR\\BOOT.BIN", - "\\USRDIR\\BOOT.BIN", - "\\BOOT.BIN", - "\\PS3_GAME\\USRDIR\\EBOOT.BIN", - "\\USRDIR\\EBOOT.BIN", - "\\EBOOT.BIN" - }; - - for(int i=0;i<6;i++) + + if(Emu.BootGame(ctrl.GetPath().c_str())) { - if(wxFile::Access(ctrl.GetPath() + elf[i], wxFile::read)) - { - ConLog.Write("SELF: booting..."); - - Emu.Stop(); - - wxString fileIn = ctrl.GetPath()+elf[i]; - wxString fileOut = (ctrl.GetPath()+elf[i])+".elf"; - - // Check if the data really needs to be decrypted. - if(!wxFileExists(fileIn)) - { - ConLog.Error("Could not open game boot file!"); - return; - } - - wxFile f(fileIn); - // Get the key version. - f.Seek(0x08); - be_t key_version; - f.Read(&key_version, sizeof(key_version)); - - if(key_version.ToBE() == const_se_t::value) - { - ConLog.Warning("Debug SELF detected! Removing fake header..."); - - // Get the real elf offset. - f.Seek(0x10); - be_t elf_offset; - f.Read(&elf_offset, sizeof(elf_offset)); - - // Start at the real elf offset. - f.Seek(elf_offset); - - wxFile out(fileOut, wxFile::write); - - // Copy the data. - char buf[2048]; - while (ssize_t size = f.Read(buf, 2048)) - out.Write(buf, size); - } - else - { - if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) - { - ConLog.Write("Could not decrypt game boot file"); - return; - } - } - - f.Close(); - - Emu.SetPath(fileOut); - Emu.Load(); - if (!wxRemoveFile(fileOut)) - ConLog.Warning("Could not delete the decrypted ELF file"); - - ConLog.Write("Game: boot done."); - return; - } + ConLog.Write("Game: boot done."); + } + else + { + ConLog.Error("Ps3 executable not found in selected folder (%s)", ctrl.GetPath().mb_str()); } - - ConLog.Error("Ps3 executable not found in selected folder (%s)", ctrl.GetPath().mb_str()); - return; } - -void MainFrame::BootPkg(wxCommandEvent& WXUNUSED(event)) +void MainFrame::InstallPkg(wxCommandEvent& WXUNUSED(event)) { + //TODO: progress bar bool stopped = false; if(Emu.IsRunning()) @@ -298,7 +227,7 @@ void MainFrame::BootPkg(wxCommandEvent& WXUNUSED(event)) stopped = true; } - wxFileDialog ctrl (this, L"Select PKG", wxEmptyString, wxEmptyString, "*.*", + wxFileDialog ctrl (this, L"Select PKG", wxEmptyString, wxEmptyString, "*.pkg", wxFD_OPEN | wxFD_FILE_MUST_EXIST); if(ctrl.ShowModal() == wxID_CANCEL) @@ -333,8 +262,8 @@ void MainFrame::BootPkg(wxCommandEvent& WXUNUSED(event)) wxString mainDir = wxGetCwd(); // Set PKG dir. - wxString oldPkgDir = wxT(wxGetCwd() + "\\" + titleID_full); - wxString newPkgDir = wxT(wxGetCwd() + gamePath + titleID); + wxString oldPkgDir = wxT(mainDir + "\\" + titleID_full); + wxString newPkgDir = wxT(mainDir + gamePath + titleID); // Move the final folder. wxMoveDir(oldPkgDir, newPkgDir); @@ -344,82 +273,10 @@ void MainFrame::BootPkg(wxCommandEvent& WXUNUSED(event)) ConLog.Write("PKG: extract done."); - // Travel to the installed PKG. - wxSetWorkingDirectory(newPkgDir); + // Travel to the main dir. + wxSetWorkingDirectory(mainDir); - wxString elf[6] = { - "\\PS3_GAME\\USRDIR\\BOOT.BIN", - "\\USRDIR\\BOOT.BIN", - "\\BOOT.BIN", - "\\PS3_GAME\\USRDIR\\EBOOT.BIN", - "\\USRDIR\\EBOOT.BIN", - "\\EBOOT.BIN" - }; - - for(int i=0;i<6;i++) - { - if(wxFile::Access(wxGetCwd() + elf[i], wxFile::read)) - { - ConLog.Write("SELF: booting..."); - - wxString fileIn = wxGetCwd()+elf[i]; - wxString fileOut = (wxGetCwd()+elf[i])+".elf"; - - // Check if the data really needs to be decrypted. - if(!wxFileExists(fileIn)) - { - ConLog.Error("Could not open game boot file!"); - return; - } - - wxFile f(fileIn); - // Get the key version. - f.Seek(0x08); - be_t key_version; - f.Read(&key_version, sizeof(key_version)); - - if(key_version.ToBE() == const_se_t::value) - { - ConLog.Warning("Debug SELF detected! Removing fake header..."); - - // Get the real elf offset. - f.Seek(0x10); - be_t elf_offset; - f.Read(&elf_offset, sizeof(elf_offset)); - - // Start at the real elf offset. - f.Seek(elf_offset); - - wxFile out(fileOut, wxFile::write); - - // Copy the data. - char buf[2048]; - while (ssize_t size = f.Read(buf, 2048)) - out.Write(buf, size); - } - else - { - if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) - { - ConLog.Write("Could not decrypt game boot file"); - return; - } - } - - f.Close(); - - // Set the working directory back. - wxSetWorkingDirectory(mainDir); - - Emu.SetPath(fileOut); - Emu.Load(); - if (!wxRemoveFile(fileOut)) - ConLog.Warning("Could not delete the decrypted ELF file"); - - ConLog.Write("Game: boot done."); - return; - } - } + Emu.BootGame(newPkgDir.c_str()); } void MainFrame::BootElf(wxCommandEvent& WXUNUSED(event)) @@ -432,7 +289,7 @@ void MainFrame::BootElf(wxCommandEvent& WXUNUSED(event)) stopped = true; } - wxFileDialog ctrl(this, L"Select ELF", wxEmptyString, wxEmptyString, "*.*", + wxFileDialog ctrl(this, L"Select (S)ELF", wxEmptyString, wxEmptyString, "*.*", wxFD_OPEN | wxFD_FILE_MUST_EXIST); if(ctrl.ShowModal() == wxID_CANCEL) @@ -441,91 +298,14 @@ void MainFrame::BootElf(wxCommandEvent& WXUNUSED(event)) return; } - ConLog.Write("ELF: booting..."); + ConLog.Write("(S)ELF: booting..."); Emu.Stop(); Emu.SetPath(ctrl.GetPath()); Emu.Load(); - ConLog.Write("ELF: boot done."); -} - -void MainFrame::BootSelf(wxCommandEvent& WXUNUSED(event)) -{ - bool stopped = false; - - if(Emu.IsRunning()) - { - Emu.Pause(); - stopped = true; - } - - wxFileDialog ctrl(this, L"Select SELF", wxEmptyString, wxEmptyString, "*.*", - wxFD_OPEN | wxFD_FILE_MUST_EXIST); - - if(ctrl.ShowModal() == wxID_CANCEL) - { - if(stopped) Emu.Resume(); - return; - } - - ConLog.Write("SELF: booting..."); - - Emu.Stop(); - - wxString fileIn = ctrl.GetPath(); - wxString fileOut = ctrl.GetPath()+".elf"; - - // Check if the data really needs to be decrypted. - if(!wxFileExists(fileIn)) - { - ConLog.Error("Could not open SELF file!"); - return; - } - - wxFile f(fileIn); - // Get the key version. - f.Seek(0x08); - be_t key_version; - f.Read(&key_version, sizeof(key_version)); - - if(key_version.ToBE() == const_se_t::value) - { - ConLog.Warning("Debug SELF detected! Removing fake header..."); - - // Get the real elf offset. - f.Seek(0x10); - be_t elf_offset; - f.Read(&elf_offset, sizeof(elf_offset)); - - // Start at the real elf offset. - f.Seek(elf_offset); - - wxFile out(fileOut, wxFile::write); - - // Copy the data. - char buf[2048]; - while (ssize_t size = f.Read(buf, 2048)) - out.Write(buf, size); - } - else - { - if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) - { - ConLog.Write("SELF: Could not decrypt file"); - return; - } - } - - f.Close(); - - Emu.SetPath(fileOut); - Emu.Load(); - //if (!wxRemoveFile(fileOut)) - // ConLog.Warning("Could not delete the decrypted ELF file"); - - ConLog.Write("SELF: boot done."); + ConLog.Write("(S)ELF: boot done."); } void MainFrame::Pause(wxCommandEvent& WXUNUSED(event)) diff --git a/rpcs3/Gui/MainFrame.h b/rpcs3/Gui/MainFrame.h index 27da011f28..bc90b3485b 100644 --- a/rpcs3/Gui/MainFrame.h +++ b/rpcs3/Gui/MainFrame.h @@ -20,9 +20,8 @@ private: void OnQuit(wxCloseEvent& event); void BootGame(wxCommandEvent& event); - void BootPkg(wxCommandEvent& event); + void InstallPkg(wxCommandEvent& event); void BootElf(wxCommandEvent& event); - void BootSelf(wxCommandEvent& event); void Pause(wxCommandEvent& event); void Stop(wxCommandEvent& event); void SendExit(wxCommandEvent& event); diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index b5c8620aab..f67f7f436d 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -199,6 +199,12 @@ + + NotUsing + NotUsing + NotUsing + NotUsing + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index 655f0f421a..feb18fc019 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -53,6 +53,9 @@ {bee6a4b4-6371-4c1b-8558-fc7888b1574e} + + {52b11fe8-a967-4d52-bf88-a3210d4ffb27} + @@ -343,6 +346,9 @@ Emu\SysCalls\lv2 + + Utilities\scetool + diff --git a/scetool/elf_inlines.h b/scetool/elf_inlines.h index ce36290552..79d9660099 100644 --- a/scetool/elf_inlines.h +++ b/scetool/elf_inlines.h @@ -8,6 +8,7 @@ #include +#define NOCOMPILE #include "types.h" #include "elf.h" diff --git a/scetool/scetool.cpp b/scetool/scetool.cpp index 57dbf40946..8f6df226c3 100644 --- a/scetool/scetool.cpp +++ b/scetool/scetool.cpp @@ -3,6 +3,8 @@ * This file is released under the GPLv2. */ +#include "stdafx.h" + #include #include diff --git a/scetool/scetool.h b/scetool/scetool.h new file mode 100644 index 0000000000..00ce0ea159 --- /dev/null +++ b/scetool/scetool.h @@ -0,0 +1,5 @@ +#pragma once + +#include "types.h" + +bool scetool_decrypt(scetool::s8 *_file_in, scetool::s8 *_file_out); \ No newline at end of file