diff --git a/CMakeLists.txt b/CMakeLists.txt index bbd5c966c..2829a071f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,7 @@ file (GLOB CXBXR_SOURCE_EMU "${CXBXR_KRNL_CPP}" "${CXBXR_ROOT_DIR}/HighPerformanceGraphicsEnabler.c" "${CXBXR_ROOT_DIR}/src/common/AddressRanges.cpp" + "${CXBXR_ROOT_DIR}/src/common/VerifyAddressRanges.cpp" "${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/glextensions.cpp" "${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen_common.cpp" "${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen_wgl.cpp" diff --git a/src/common/VerifyAddressRanges.cpp b/src/common/VerifyAddressRanges.cpp index 20bd93ced..9e77896a2 100644 --- a/src/common/VerifyAddressRanges.cpp +++ b/src/common/VerifyAddressRanges.cpp @@ -35,6 +35,15 @@ // ****************************************************************** #include "AddressRanges.h" +#include "core\kernel\init\CxbxKrnl.h" // For CXBX_BASE_ADDR + +bool VerifyBaseAddr() +{ + /*! CXBX_BASE_ADDR is defined as 0x00010000, which is the base address of + the CxbxLoader.exe host executable. + Set in CxbxLoader.exe Project options, Linker, Advanced, Base Address */ + return ((UINT_PTR)GetModuleHandle(nullptr) == CXBX_BASE_ADDR); +} // This array keeps track of which ranges have successfully been reserved. struct { diff --git a/src/common/VerifyAddressRanges.h b/src/common/VerifyAddressRanges.h index b6204e70d..67b73332f 100644 --- a/src/common/VerifyAddressRanges.h +++ b/src/common/VerifyAddressRanges.h @@ -35,6 +35,8 @@ // ****************************************************************** #pragma once +extern bool VerifyBaseAddr(); + // TODO : extern ReservedRanges[]; extern int ReservedRangeCount; diff --git a/src/emulator/CxbxEmulator.cpp b/src/emulator/CxbxEmulator.cpp index 7b2014be8..01f84229c 100644 --- a/src/emulator/CxbxEmulator.cpp +++ b/src/emulator/CxbxEmulator.cpp @@ -35,8 +35,7 @@ // CxbxEmulator.cpp : Defines the exported functions for the DLL application. #include "Cxbx.h" // For FUNC_EXPORTS -#include "VerifyAddressRanges.h" -#include "core\kernel\init\CxbxKrnl.h" // For CXBX_BASE_ADDR +#include "VerifyAddressRanges.h" // For VerifyBaseAddr() and VerifyAddressRanges() //#include "CxbxKrnl/Emu.h" #include "EmuShared.h" //#include @@ -132,10 +131,7 @@ DWORD WINAPI Emulate(int system) FUNC_EXPORTS /*! Verify our host executable, CxbxLoader.exe, is loaded to base address 0x00010000 */ - if ((UINT_PTR)GetModuleHandle(nullptr) != CXBX_BASE_ADDR) { - /*! CXBX_BASE_ADDR is defined as 0x00010000, which is the base address of - the CxbxLoader.exe host executable. - Set in CxbxLoader.exe Project options, Linker, Advanced, Base Address */ + if (!VerifyBaseAddr()) { MessageBox(NULL, "CxbxLoader.exe was not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", MB_OK); return EXIT_FAILURE; } diff --git a/src/gui/WinMain.cpp b/src/gui/WinMain.cpp index 3202423b5..0deeeba9f 100644 --- a/src/gui/WinMain.cpp +++ b/src/gui/WinMain.cpp @@ -28,6 +28,7 @@ #include "WndMain.h" #include "AddressRanges.h" // For VerifyWow64() +#include "VerifyAddressRanges.h" // For VerifyBaseAddr() #include "core\kernel\init\CxbxKrnl.h" #include "core\kernel\support\Emu.h" #include "EmuShared.h" @@ -52,18 +53,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine return EXIT_FAILURE; } -#ifndef CXBX_LOADER /*! verify Cxbx.exe is loaded to base address 0x00010000 */ - if ((UINT_PTR)GetModuleHandle(nullptr) != CXBX_BASE_ADDR) - { - /*! CXBX_BASE_ADDR is defined as 0x00010000, which is the base address of - the Cxbx.exe host executable. - Set in Cxbx Project options, Linker, Advanced, Base Address */ + if (!VerifyBaseAddr()) { MessageBox(NULL, "Cxbx.exe is not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", MB_OK | MB_ICONERROR); return EXIT_FAILURE; } -#endif bool bRet, bKernel; HWND hWnd = nullptr;