diff --git a/src/core/kernel/init/CxbxKrnl.cpp b/src/core/kernel/init/CxbxKrnl.cpp index 834066917..22f222f95 100644 --- a/src/core/kernel/init/CxbxKrnl.cpp +++ b/src/core/kernel/init/CxbxKrnl.cpp @@ -872,6 +872,70 @@ void ImportLibraries(XbeImportEntry *pImportDirectory) } } +bool HandleFirstLaunch() +{ + bool bFirstLaunch; + g_EmuShared->GetIsFirstLaunch(&bFirstLaunch); + + /* check if process is launch with elevated access then prompt for continue on or not. */ + if (!bFirstLaunch) { + g_Settings = new Settings(); + if (g_Settings == nullptr) { + MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK); + return false; + } + + if (!g_Settings->Init()) { + return false; + } + + log_get_settings(); + + bool bElevated = CxbxIsElevated(); + if (bElevated && !g_Settings->m_core.allowAdminPrivilege) { + int ret = MessageBox(NULL, "Cxbx-Reloaded has detected that it has been launched with Administrator rights.\n" + "\nThis is dangerous, as a maliciously modified Xbox titles could take control of your system.\n" + "\nAre you sure you want to continue?", "Cxbx-Reloaded", MB_YESNO | MB_ICONWARNING); + if (ret != IDYES) { + return false; + } + } + + g_EmuShared->SetIsFirstLaunch(true); + } + + return true; +} + +void LaunchEmulation(int argc, char* argv[]) +{ + // NOTE: This is designated for standalone kernel mode launch without GUI + if (g_Settings != nullptr) { + + // Reset to default + g_EmuShared->Reset(); + + g_Settings->Verify(); + g_Settings->SyncToEmulator(); + + // We don't need to keep Settings open plus allow emulator to use unused memory. + delete g_Settings; + g_Settings = nullptr; + + // Perform identical to what GUI will do to certain EmuShared's variable before launch. + g_EmuShared->SetIsEmulating(true); + + // NOTE: This setting the ready status is optional. Internal kernel process is checking if GUI is running. + // Except if enforce check, then we need to re-set ready status every time for non-GUI. + //g_EmuShared->SetIsReady(true); + } + + /* Initialize Cxbx File Paths */ + CxbxInitFilePaths(); + + CxbxKrnlMain(argc, argv); +} + void CxbxKrnlMain(int argc, char* argv[]) { // Skip '/load' switch diff --git a/src/core/kernel/init/CxbxKrnl.h b/src/core/kernel/init/CxbxKrnl.h index 87c5c41ef..d49771f7a 100644 --- a/src/core/kernel/init/CxbxKrnl.h +++ b/src/core/kernel/init/CxbxKrnl.h @@ -224,8 +224,10 @@ bool CxbxKrnlVerifyVersion(const char *szVersion); extern bool g_bIsDebugKernel; +bool HandleFirstLaunch(); + /*! Cxbx Kernel Entry Point */ -void CxbxKrnlMain(int argc, char* argv[]); +void LaunchEmulation(int argc, char* argv[]); /*! initialize emulation */ __declspec(noreturn) void CxbxKrnlInit(void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32_t XbeHeaderSize, void (*Entry)(), int BootFlags); diff --git a/src/emulator/CxbxEmulator.cpp b/src/emulator/CxbxEmulator.cpp index da909eff2..18c2d201d 100644 --- a/src/emulator/CxbxEmulator.cpp +++ b/src/emulator/CxbxEmulator.cpp @@ -38,6 +38,7 @@ #include "VerifyAddressRanges.h" // For VerifyBaseAddr() and VerifyAddressRanges() //#include "CxbxKrnl/Emu.h" #include "EmuShared.h" +#include "core\kernel\init\CxbxKrnl.h" // For HandleFirstLaunch() and LaunchEmulation() //#include PCHAR* @@ -149,13 +150,13 @@ DWORD WINAPI Emulate(int system) return EXIT_FAILURE; } - // TODO : Call HandleFirstLaunch(); + HandleFirstLaunch(); LPSTR CommandLine = GetCommandLine(); int argc; PCHAR *argv = CommandLineToArgvA(CommandLine, &argc); - // TODO : Call LaunchEmulation(argc, argv); + LaunchEmulation(argc, argv); LocalFree(argv); diff --git a/src/gui/WinMain.cpp b/src/gui/WinMain.cpp index a794d4a96..f6424b48f 100644 --- a/src/gui/WinMain.cpp +++ b/src/gui/WinMain.cpp @@ -40,72 +40,6 @@ name = 'Microsoft.Windows.Common-Controls' version = '6.0.0.0' \ processorArchitecture = '*' publicKeyToken = '6595b64144ccf1df' language = '*'\"") -// TODO : Move HandleFirstLaunch() to a file shared with the CxbxEmulator project -bool HandleFirstLaunch() -{ - bool bFirstLaunch; - g_EmuShared->GetIsFirstLaunch(&bFirstLaunch); - - /* check if process is launch with elevated access then prompt for continue on or not. */ - if (!bFirstLaunch) { - g_Settings = new Settings(); - if (g_Settings == nullptr) { - MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK); - return false; - } - - if (!g_Settings->Init()) { - return false; - } - - log_get_settings(); - - bool bElevated = CxbxIsElevated(); - if (bElevated && !g_Settings->m_core.allowAdminPrivilege) { - int ret = MessageBox(NULL, "Cxbx-Reloaded has detected that it has been launched with Administrator rights.\n" - "\nThis is dangerous, as a maliciously modified Xbox titles could take control of your system.\n" - "\nAre you sure you want to continue?", "Cxbx-Reloaded", MB_YESNO | MB_ICONWARNING); - if (ret != IDYES) { - return false; - } - } - - g_EmuShared->SetIsFirstLaunch(true); - } - - return true; -} - -// TODO : Move LaunchEmulation() to a file shared with the CxbxEmulator project -void LaunchEmulation(int argc, char* argv[]) -{ - // NOTE: This is designated for standalone kernel mode launch without GUI - if (g_Settings != nullptr) { - - // Reset to default - g_EmuShared->Reset(); - - g_Settings->Verify(); - g_Settings->SyncToEmulator(); - - // We don't need to keep Settings open plus allow emulator to use unused memory. - delete g_Settings; - g_Settings = nullptr; - - // Perform identical to what GUI will do to certain EmuShared's variable before launch. - g_EmuShared->SetIsEmulating(true); - - // NOTE: This setting the ready status is optional. Internal kernel process is checking if GUI is running. - // Except if enforce check, then we need to re-set ready status every time for non-GUI. - //g_EmuShared->SetIsReady(true); - } - - /* Initialize Cxbx File Paths */ - CxbxInitFilePaths(); - - CxbxKrnlMain(argc, argv); -} - /*! program entry point */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {