Merge branch 'master' of https://github.com/PatrickvL/Cxbx-Reloaded
This commit is contained in:
commit
f8fc7d09dc
|
@ -261,7 +261,7 @@ void CxbxKrnlMain(int argc, char* argv[])
|
||||||
NewDosHeader = (PIMAGE_DOS_HEADER)VirtualAlloc(nullptr, ExeHeaderSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
NewDosHeader = (PIMAGE_DOS_HEADER)VirtualAlloc(nullptr, ExeHeaderSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||||
memcpy(NewDosHeader, ExeDosHeader, ExeHeaderSize);
|
memcpy(NewDosHeader, ExeDosHeader, ExeHeaderSize);
|
||||||
|
|
||||||
// Determine NewNtHeader and NewOptionalHeader, both required by RestoreExeImageHeader
|
// Determine NewOptionalHeader, required by RestoreExeImageHeader
|
||||||
NewNtHeader = (PIMAGE_NT_HEADERS)((ULONG_PTR)NewDosHeader + ExeDosHeader->e_lfanew);
|
NewNtHeader = (PIMAGE_NT_HEADERS)((ULONG_PTR)NewDosHeader + ExeDosHeader->e_lfanew);
|
||||||
NewOptionalHeader = (PIMAGE_OPTIONAL_HEADER)&(NewNtHeader->OptionalHeader);
|
NewOptionalHeader = (PIMAGE_OPTIONAL_HEADER)&(NewNtHeader->OptionalHeader);
|
||||||
|
|
||||||
|
@ -576,7 +576,9 @@ void CxbxKrnlInit
|
||||||
// this will better aproximate the environment with regard to multi-threading) :
|
// this will better aproximate the environment with regard to multi-threading) :
|
||||||
DbgPrintf("EmuMain : Determining CPU affinity.\n");
|
DbgPrintf("EmuMain : Determining CPU affinity.\n");
|
||||||
{
|
{
|
||||||
GetProcessAffinityMask(g_CurrentProcessHandle, &g_CPUXbox, &g_CPUOthers);
|
if (!GetProcessAffinityMask(g_CurrentProcessHandle, &g_CPUXbox, &g_CPUOthers))
|
||||||
|
CxbxKrnlCleanup("EmuMain: GetProcessAffinityMask failed.");
|
||||||
|
|
||||||
// For the other threads, remove one bit from the processor mask:
|
// For the other threads, remove one bit from the processor mask:
|
||||||
g_CPUOthers = ((g_CPUXbox - 1) & g_CPUXbox);
|
g_CPUOthers = ((g_CPUXbox - 1) & g_CPUXbox);
|
||||||
|
|
||||||
|
|
|
@ -68,12 +68,6 @@ CRITICAL_SECTION dbgCritical;
|
||||||
// Global Variable(s)
|
// Global Variable(s)
|
||||||
HANDLE g_hCurDir = NULL;
|
HANDLE g_hCurDir = NULL;
|
||||||
CHAR *g_strCurDrive= NULL;
|
CHAR *g_strCurDrive= NULL;
|
||||||
HANDLE g_hTDrive = NULL;
|
|
||||||
CHAR *g_strTDrive = NULL;
|
|
||||||
HANDLE g_hUDrive = NULL;
|
|
||||||
CHAR *g_strUDrive = NULL;
|
|
||||||
HANDLE g_hZDrive = NULL;
|
|
||||||
CHAR *g_strZDrive = NULL;
|
|
||||||
volatile bool g_bEmuException = false;
|
volatile bool g_bEmuException = false;
|
||||||
volatile bool g_bEmuSuspended = false;
|
volatile bool g_bEmuSuspended = false;
|
||||||
volatile bool g_bPrintfOn = true;
|
volatile bool g_bPrintfOn = true;
|
||||||
|
|
|
@ -68,12 +68,6 @@ extern void * funcExclude[2048];
|
||||||
// partition emulation directory handles
|
// partition emulation directory handles
|
||||||
extern HANDLE g_hCurDir;
|
extern HANDLE g_hCurDir;
|
||||||
extern CHAR *g_strCurDrive;
|
extern CHAR *g_strCurDrive;
|
||||||
extern HANDLE g_hTDrive;
|
|
||||||
extern CHAR *g_strTDrive;
|
|
||||||
extern HANDLE g_hUDrive;
|
|
||||||
extern CHAR *g_strUDrive;
|
|
||||||
extern HANDLE g_hZDrive;
|
|
||||||
extern CHAR *g_strZDrive;
|
|
||||||
extern HWND g_hEmuWindow;
|
extern HWND g_hEmuWindow;
|
||||||
|
|
||||||
// thread notification routine
|
// thread notification routine
|
||||||
|
|
|
@ -43,12 +43,14 @@ namespace xboxkrnl
|
||||||
#include <xboxkrnl/xboxkrnl.h> // For HalReadSMCTrayState, etc.
|
#include <xboxkrnl/xboxkrnl.h> // For HalReadSMCTrayState, etc.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <Shlwapi.h> // For PathRemoveFileSpec()
|
||||||
#include "Logging.h" // For LOG_FUNC()
|
#include "Logging.h" // For LOG_FUNC()
|
||||||
#include "EmuKrnlLogging.h"
|
#include "EmuKrnlLogging.h"
|
||||||
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
|
||||||
#include "Emu.h" // For EmuWarning()
|
#include "Emu.h" // For EmuWarning()
|
||||||
#include "EmuX86.h" // HalReadWritePciSpace needs this
|
#include "EmuX86.h" // HalReadWritePciSpace needs this
|
||||||
#include "EmuKrnl.h" // For EEPROM
|
#include "EmuKrnl.h" // For EEPROM
|
||||||
|
#include "EmuFile.h" // For FindNtSymbolicLinkObjectByDriveLetter
|
||||||
|
|
||||||
// prevent name collisions
|
// prevent name collisions
|
||||||
namespace NtDll
|
namespace NtDll
|
||||||
|
@ -396,7 +398,49 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN xboxkrnl::HalReturnToFir
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
LOG_FUNC_ONE_ARG(Routine);
|
LOG_FUNC_ONE_ARG(Routine);
|
||||||
CxbxKrnlCleanup("Xbe has rebooted : HalReturnToFirmware(%d)", Routine);
|
|
||||||
|
char *lpTitlePath = xboxkrnl::LaunchDataPage->Header.szLaunchPath;
|
||||||
|
char szXbePath[MAX_PATH];
|
||||||
|
char szWorkingDirectoy[MAX_PATH];
|
||||||
|
|
||||||
|
// Convert Xbox XBE Path to Windows Path
|
||||||
|
{
|
||||||
|
EmuNtSymbolicLinkObject* symbolicLink = FindNtSymbolicLinkObjectByDriveLetter(lpTitlePath[0]);
|
||||||
|
snprintf(szXbePath, MAX_PATH, "%s%s", symbolicLink->HostSymbolicLinkPath.c_str(), &lpTitlePath[2]);
|
||||||
|
|
||||||
|
// Determine Working Directory
|
||||||
|
strncpy_s(szWorkingDirectoy, szXbePath, MAX_PATH);
|
||||||
|
PathRemoveFileSpec(szWorkingDirectoy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the launch data page to disk for later.
|
||||||
|
{
|
||||||
|
char szLaunchDataPagePath[MAX_PATH];
|
||||||
|
snprintf(szLaunchDataPagePath, MAX_PATH, "%s\\CxbxLaunchDataPage.bin", szWorkingDirectoy);
|
||||||
|
|
||||||
|
DbgPrintf("Saving launch data to %s\n", szLaunchDataPagePath);
|
||||||
|
// TODO : When reading Xbe files from read-only storage, we must use another location for "CxbxLaunchDataPage.bin" !
|
||||||
|
FILE* fp = fopen(szLaunchDataPagePath, "wb");
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
fwrite(xboxkrnl::LaunchDataPage, sizeof(xboxkrnl::LAUNCH_DATA_PAGE), 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Launch the new Xbe
|
||||||
|
{
|
||||||
|
char szExeFileName[MAX_PATH];
|
||||||
|
GetModuleFileName(GetModuleHandle(NULL), szExeFileName, MAX_PATH);
|
||||||
|
|
||||||
|
char szArgsBuffer[4096];
|
||||||
|
snprintf(szArgsBuffer, 4096, "/load \"%s\" %u %d \"%s\"", szXbePath, CxbxKrnl_hEmuParent, CxbxKrnl_DebugMode, CxbxKrnl_DebugFileName);
|
||||||
|
|
||||||
|
if ((int)ShellExecute(NULL, "open", szExeFileName, szArgsBuffer, szWorkingDirectoy, SW_SHOWDEFAULT) <= 32)
|
||||||
|
{
|
||||||
|
CxbxKrnlCleanup("Could not launch %s", lpTitlePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExitProcess(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ******************************************************************
|
// ******************************************************************
|
||||||
|
|
|
@ -959,47 +959,7 @@ DWORD WINAPI XTL::EMUPATCH(XLaunchNewImage)
|
||||||
strncpy(&(xboxkrnl::LaunchDataPage->Header.szLaunchPath[0]), lpTitlePath, 520);
|
strncpy(&(xboxkrnl::LaunchDataPage->Header.szLaunchPath[0]), lpTitlePath, 520);
|
||||||
}
|
}
|
||||||
|
|
||||||
char szXbePath[MAX_PATH];
|
xboxkrnl::HalReturnToFirmware(xboxkrnl::ReturnFirmwareQuickReboot);
|
||||||
char szWorkingDirectoy[MAX_PATH];
|
|
||||||
|
|
||||||
// Convert Xbox XBE Path to Windows Path
|
|
||||||
{
|
|
||||||
EmuNtSymbolicLinkObject* symbolicLink = FindNtSymbolicLinkObjectByDriveLetter(lpTitlePath[0]);
|
|
||||||
snprintf(szXbePath, MAX_PATH, "%s%s", symbolicLink->HostSymbolicLinkPath.c_str(), &lpTitlePath[2]);
|
|
||||||
|
|
||||||
// Determine Working Directory
|
|
||||||
strncpy_s(szWorkingDirectoy, szXbePath, MAX_PATH);
|
|
||||||
PathRemoveFileSpec(szWorkingDirectoy);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the launch data page to disk for later.
|
|
||||||
{
|
|
||||||
char szLaunchDataPagePath[MAX_PATH];
|
|
||||||
snprintf(szLaunchDataPagePath, MAX_PATH, "%s\\CxbxLaunchDataPage.bin", szWorkingDirectoy);
|
|
||||||
|
|
||||||
DbgPrintf("Saving launch data to %s\n", szLaunchDataPagePath);
|
|
||||||
// TODO : When reading Xbe files from read-only storage, we must use another location for "CxbxLaunchDataPage.bin" !
|
|
||||||
FILE* fp = fopen(szLaunchDataPagePath, "wb");
|
|
||||||
fseek(fp, 0, SEEK_SET);
|
|
||||||
fwrite(xboxkrnl::LaunchDataPage, sizeof(xboxkrnl::LAUNCH_DATA_PAGE), 1, fp);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the new Xbe
|
|
||||||
{
|
|
||||||
char szExeFileName[MAX_PATH];
|
|
||||||
GetModuleFileName(GetModuleHandle(NULL), szExeFileName, MAX_PATH);
|
|
||||||
|
|
||||||
char szArgsBuffer[4096];
|
|
||||||
snprintf(szArgsBuffer, 4096, "/load \"%s\" %u %d \"%s\"", szXbePath, CxbxKrnl_hEmuParent, CxbxKrnl_DebugMode, CxbxKrnl_DebugFileName);
|
|
||||||
|
|
||||||
if ((int)ShellExecute(NULL, "open", szExeFileName, szArgsBuffer, szWorkingDirectoy, SW_SHOWDEFAULT) <= 32)
|
|
||||||
{
|
|
||||||
CxbxKrnlCleanup("Could not launch %s", lpTitlePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExitProcess(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this function succeeds, it doesn't get a chance to return anything.
|
// If this function succeeds, it doesn't get a chance to return anything.
|
||||||
RETURN(ERROR_GEN_FAILURE);
|
RETURN(ERROR_GEN_FAILURE);
|
||||||
|
|
Loading…
Reference in New Issue