diff --git a/CMakeLists.txt b/CMakeLists.txt index a06dc137f..53aa46c8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ file (GLOB CXBXR_HEADER_COMMON "${CXBXR_ROOT_DIR}/src/common/win32/EmuShared.h" "${CXBXR_ROOT_DIR}/src/common/win32/Mutex.h" "${CXBXR_ROOT_DIR}/src/common/win32/Threads.h" + "${CXBXR_ROOT_DIR}/src/common/win32/WineEnv.h" "${CXBXR_ROOT_DIR}/src/common/xbdm/CxbxXbdm.h" "${CXBXR_ROOT_DIR}/src/common/xbe/Xbe.h" "${CXBXR_ROOT_DIR}/src/common/xbe/XbePrinter.h" @@ -219,6 +220,7 @@ file (GLOB CXBXR_SOURCE_COMMON "${CXBXR_ROOT_DIR}/src/common/win32/IPCWindows.cpp" "${CXBXR_ROOT_DIR}/src/common/win32/Mutex.cpp" "${CXBXR_ROOT_DIR}/src/common/win32/Threads.cpp" + "${CXBXR_ROOT_DIR}/src/common/win32/WineEnv.cpp" "${CXBXR_ROOT_DIR}/src/common/xbdm/CxbxXbdm.cpp" "${CXBXR_ROOT_DIR}/src/common/xbe/Xbe.cpp" "${CXBXR_ROOT_DIR}/src/common/xbe/XbePrinter.cpp" diff --git a/src/common/win32/WineEnv.cpp b/src/common/win32/WineEnv.cpp new file mode 100644 index 000000000..accb415df --- /dev/null +++ b/src/common/win32/WineEnv.cpp @@ -0,0 +1,52 @@ +// ****************************************************************** +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2002-2003 Aaron Robinson +// * +// * All rights reserved +// * +// ****************************************************************** + +#include + +typedef const char* (CDECL* LPFN_WINEGETVERSION)(void); +LPFN_WINEGETVERSION wine_get_version; + +static bool CheckForWine() { + HMODULE hNtDll = GetModuleHandle("ntdll.dll"); + if (hNtDll != nullptr) { + wine_get_version = (LPFN_WINEGETVERSION)GetProcAddress(hNtDll, "wine_get_version"); + // If wine is found, store pointer to the function for later call. + if (wine_get_version) { + return true; + } + } + return false; +} + +bool isWineEnv() +{ + static bool bIsWine = CheckForWine(); + return bIsWine; +} + +const char* getWineVersion() +{ + return wine_get_version(); +} diff --git a/src/common/win32/WineEnv.h b/src/common/win32/WineEnv.h new file mode 100644 index 000000000..a2c2f4f79 --- /dev/null +++ b/src/common/win32/WineEnv.h @@ -0,0 +1,30 @@ +// ****************************************************************** +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2002-2003 Aaron Robinson +// * +// * All rights reserved +// * +// ****************************************************************** + +#pragma once + +bool isWineEnv(); + +const char* getWineVersion(); diff --git a/src/core/kernel/init/CxbxKrnl.cpp b/src/core/kernel/init/CxbxKrnl.cpp index d7370f79d..b859d744b 100644 --- a/src/core/kernel/init/CxbxKrnl.cpp +++ b/src/core/kernel/init/CxbxKrnl.cpp @@ -52,6 +52,7 @@ #include "xxhash.h" #include "common/ReserveAddressRanges.h" #include "common/xbox/Types.hpp" +#include "common/win32/WineEnv.h" #include #include @@ -106,7 +107,6 @@ std::atomic_bool g_bEnableAllInterrupts = true; size_t g_SystemMaxMemory = 0; HANDLE g_CurrentProcessHandle = 0; // Set in CxbxKrnlMain -bool g_bIsWine = false; bool g_CxbxPrintUEM = false; ULONG g_CxbxFatalErrorCode = FATAL_ERROR_NONE; @@ -220,9 +220,6 @@ void RestoreExeImageHeader() ExeOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] = NewOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS]; } -typedef const char* (CDECL *LPFN_WINEGETVERSION)(void); -LPFN_WINEGETVERSION wine_get_version; - // Forward declaration to avoid moving the definition of LoadXboxKeys void LoadXboxKeys(std::string path); @@ -267,8 +264,8 @@ std::string CxbxGetLastErrorString(char * lpszFunction) void PrintCurrentConfigurationLog() { - if (g_bIsWine) { - EmuLogInit(LOG_LEVEL::INFO, "Running under Wine Version %s", wine_get_version()); + if (isWineEnv()) { + EmuLogInit(LOG_LEVEL::INFO, "Running under Wine Version %s", getWineVersion()); } // HACK: For API TRace.. @@ -667,8 +664,10 @@ bool HandleFirstLaunch() return false; } + // Wine will always run programs as administrator by default, it can be safely disregard. + // Since Wine doesn't use root permission. Unless user is running Wine as root. bool bElevated = CxbxIsElevated(); - if (bElevated && !g_Settings->m_core.allowAdminPrivilege) { + if (bElevated && !isWineEnv() && !g_Settings->m_core.allowAdminPrivilege) { PopupReturn ret = PopupWarningEx(nullptr, PopupButtons::YesNo, PopupReturn::No, "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" @@ -882,17 +881,6 @@ void CxbxKrnlEmulate(unsigned int reserved_systems, blocks_reserved_t blocks_res log_generate_active_filter_output(CXBXR_MODULE::INIT); } - // Detect Wine - g_bIsWine = false; - HMODULE hNtDll = GetModuleHandle("ntdll.dll"); - - if (hNtDll != nullptr) { - wine_get_version = (LPFN_WINEGETVERSION)GetProcAddress(hNtDll, "wine_get_version"); - if (wine_get_version) { - g_bIsWine = true; - } - } - // Now we got the arguments, start by initializing the Xbox memory map : // PrepareXBoxMemoryMap() { diff --git a/src/core/kernel/init/CxbxKrnl.h b/src/core/kernel/init/CxbxKrnl.h index 490c9a95b..3c45d5f60 100644 --- a/src/core/kernel/init/CxbxKrnl.h +++ b/src/core/kernel/init/CxbxKrnl.h @@ -198,7 +198,6 @@ bool CxbxIsElevated(); /*! kernel thunk table */ extern uint32_t CxbxKrnl_KernelThunkTable[379]; -extern bool g_bIsWine; extern bool g_bClipCursor; extern bool g_CxbxPrintUEM; extern ULONG g_CxbxFatalErrorCode; diff --git a/src/gui/WndMain.cpp b/src/gui/WndMain.cpp index bb1044fcc..c38e7b056 100644 --- a/src/gui/WndMain.cpp +++ b/src/gui/WndMain.cpp @@ -44,6 +44,7 @@ #include "core\hle\D3D8\XbConvert.h" // For EmuPC2XB_D3DFormat #include "common\Settings.hpp" #include "common/util/cliConfig.hpp" +#include "common/win32/WineEnv.h" #include "core\kernel\init\CxbxKrnl.h" // For CxbxExec #include "resource/ResCxbx.h" @@ -273,6 +274,12 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP ReleaseDC(hwnd, hDC); } + // Check if running in Wine environment. If it is, then we don't need admin warning message popup on startup. + if (isWineEnv()) { + BOOL bAdminCheckRemoveRet = RemoveMenu(GetMenu(hwnd), ID_SETTINGS_ALLOWADMINPRIVILEGE, MF_GRAYED); + assert(bAdminCheckRemoveRet != -1); + } + SetClassLong(hwnd, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDI_CXBX))); DragAcceptFiles(hwnd, TRUE);