DriverVersionWarning.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // DriverVersionWarning.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "wwconfig.h"
  22. #include "videoconfigdialog.h"
  23. #include "DriverVersionWarning.h"
  24. #include "dx8caps.h"
  25. #include "cpudetect.h"
  26. #include "dx8wrapper.h"
  27. #include "registry.h"
  28. #include "formconv.h"
  29. #include "locale_api.h"
  30. #include "wwconfig_ids.h"
  31. extern int GlobalExitValue;
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. static StringClass VersionWarningString;
  38. /////////////////////////////////////////////////////////////////////////////
  39. // DriverVersionWarning dialog
  40. DriverVersionWarning::DriverVersionWarning(CWnd* pParent /*=NULL*/)
  41. : CDialog(DriverVersionWarning::IDD, pParent)
  42. {
  43. //{{AFX_DATA_INIT(DriverVersionWarning)
  44. // NOTE: the ClassWizard will add member initialization here
  45. //}}AFX_DATA_INIT
  46. }
  47. void DriverVersionWarning::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CDialog::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(DriverVersionWarning)
  51. // NOTE: the ClassWizard will add DDX and DDV calls here
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(DriverVersionWarning, CDialog)
  55. //{{AFX_MSG_MAP(DriverVersionWarning)
  56. ON_BN_CLICKED(IDC_DISABLE_DRIVER_VERSION_DIALOG_CHECKBOX, OnDisableDriverVersionDialogCheckbox)
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. //
  61. // DriverVersionWarning message handlers
  62. //
  63. // Modified: 12/06/2001 by MML - Retrieving strings from Locomoto file.
  64. //
  65. /////////////////////////////////////////////////////////////////////////////
  66. static void Get_Driver_Version_Warning_String(StringClass& str, DX8Caps& caps)
  67. {
  68. DX8Caps::DriverVersionStatusType status=caps.Get_Driver_Version_Status();
  69. if (status!=DX8Caps::DRIVER_STATUS_BAD) {
  70. // str="Driver version is GOOD";
  71. str = StringClass( Locale_GetString( IDS_GOOD_DRIVER ));
  72. return;
  73. }
  74. StringClass driver_name(0,true);
  75. driver_name=caps.Get_Driver_Name();
  76. // str.Format(
  77. // "Your current video card driver version is known to cause problems with Renegade. If you encounter problems while playing Renegade, please refer to the readme.txt for instructions on how to update your video card driver.\n"
  78. // "\n"
  79. // "Driver: %s\n"
  80. // "Driver version: %d.%d (Status: BAD)\n",
  81. // driver_name,
  82. // caps.Get_Driver_Build_Version()/100,
  83. // caps.Get_Driver_Build_Version()%100);
  84. StringClass format_string( Locale_GetString( IDS_KNOW_PROBLEMS ));
  85. format_string += "\n\n";
  86. format_string += StringClass( Locale_GetString( IDS_DRIVER_NAME ));
  87. format_string += "\n";
  88. format_string += StringClass( Locale_GetString( IDS_DRIVER_VERSION ));
  89. format_string += "\n";
  90. str.Format( format_string,
  91. driver_name,
  92. caps.Get_Driver_Build_Version()/100,
  93. caps.Get_Driver_Build_Version()%100 );
  94. switch (caps.Get_Vendor()) {
  95. default:
  96. break;
  97. case DX8Caps::VENDOR_NVIDIA:
  98. if (driver_name=="nv4_disp.dll" || driver_name=="nvdd32.dll") {
  99. // str += "Recommended version: 21.81 or higher\n";
  100. str += StringClass( Locale_GetString( IDS_VERSION_MIN1 ));
  101. }
  102. break;
  103. case DX8Caps::VENDOR_ATI:
  104. if (driver_name=="ati2dvag.dll") {
  105. // str += "Recommended version: 3281 or higher\n";
  106. str += StringClass( Locale_GetString( IDS_VERSION_MIN2 ));
  107. }
  108. break;
  109. case DX8Caps::VENDOR_3DFX:
  110. // str += "There is no driver support for 3Dfx. Website www.x3dfx.com has some unofficial drivers.\n";
  111. str += StringClass( Locale_GetString( IDS_NO_DRIVER_SUPPORT ));
  112. break;
  113. }
  114. }
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CheckDriverVersion
  117. void CheckDriverVersion()
  118. {
  119. //
  120. // Attempt to open the registry key
  121. //
  122. RegistryClass render_registry(RENEGADE_SUB_KEY_NAME_RENDER);
  123. if (!render_registry.Is_Valid()) return;
  124. int disabled=render_registry.Get_Int( "DriverVersionCheckDisabled" );
  125. if (disabled>=87) return;
  126. IDirect3D8* d3d=NULL;
  127. D3DCAPS8 tmp_caps;
  128. const D3DCAPS8* d3dcaps=NULL;
  129. D3DADAPTER_IDENTIFIER8 adapter_id;
  130. VideoConfigDialogClass* video=VideoConfigDialogClass::Get_Instance();
  131. if (video) {
  132. d3d=DX8Wrapper::_Get_D3D8();
  133. d3d->AddRef();
  134. d3dcaps=&video->Get_Current_Caps();
  135. adapter_id=video->Get_Current_Adapter_Identifier();
  136. }
  137. else {
  138. // Init D3D
  139. Init_D3D_To_WW3_Conversion();
  140. d3d=Direct3DCreate8(D3D_SDK_VERSION); // TODO: handle failure cases...
  141. if (!d3d) {
  142. return;
  143. }
  144. // Select device. If there is already a device selected in the registry, use it.
  145. int current_adapter_index=D3DADAPTER_DEFAULT;
  146. //
  147. // Load the render device settings from the registry
  148. //
  149. char device_name[256] = { 0 };
  150. render_registry.Get_String( VALUE_NAME_RENDER_DEVICE_NAME, device_name, sizeof(device_name));
  151. int adapter_count = d3d->GetAdapterCount();
  152. for (int adapter_index=0; adapter_index<adapter_count; adapter_index++) {
  153. D3DADAPTER_IDENTIFIER8 id;
  154. ::ZeroMemory(&id, sizeof(D3DADAPTER_IDENTIFIER8));
  155. HRESULT res = d3d->GetAdapterIdentifier(adapter_index,D3DENUM_NO_WHQL_LEVEL,&id);
  156. // If device ok, check if it matches the currently set adapter name
  157. if (res == D3D_OK) {
  158. StringClass name(id.Description,true);
  159. if (name==device_name) {
  160. current_adapter_index=adapter_index;
  161. break;
  162. }
  163. }
  164. }
  165. if (FAILED(d3d->GetDeviceCaps(
  166. current_adapter_index,
  167. D3DDEVTYPE_HAL,
  168. &tmp_caps))) {
  169. d3d->Release();
  170. return;
  171. }
  172. ::ZeroMemory(&adapter_id, sizeof(D3DADAPTER_IDENTIFIER8));
  173. if (FAILED( d3d->GetAdapterIdentifier(
  174. current_adapter_index,
  175. D3DENUM_NO_WHQL_LEVEL,
  176. &adapter_id))) {
  177. d3d->Release();
  178. return;
  179. }
  180. d3dcaps=&tmp_caps;
  181. }
  182. DX8Caps caps(d3d,*d3dcaps,WW3D_FORMAT_UNKNOWN,adapter_id);
  183. d3d->Release();
  184. d3d=NULL;
  185. // Beta message - remember to remove!
  186. /* bool unknown_device=false;
  187. switch (caps.Get_Vendor()) {
  188. default:
  189. case DX8Caps::VENDOR_UNKNOWN:
  190. unknown_device=true;
  191. break;
  192. case DX8Caps::VENDOR_NVIDIA:
  193. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_NVIDIA_UNKNOWN);
  194. break;
  195. case DX8Caps::VENDOR_ATI:
  196. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_ATI_UNKNOWN);
  197. break;
  198. case DX8Caps::VENDOR_INTEL:
  199. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_INTEL_UNKNOWN);
  200. break;
  201. case DX8Caps::VENDOR_S3:
  202. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_S3_UNKNOWN);
  203. break;
  204. case DX8Caps::VENDOR_POWERVR:
  205. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_POWERVR_UNKNOWN);
  206. break;
  207. case DX8Caps::VENDOR_MATROX:
  208. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_MATROX_UNKNOWN);
  209. break;
  210. case DX8Caps::VENDOR_3DFX:
  211. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_3DFX_UNKNOWN);
  212. break;
  213. case DX8Caps::VENDOR_3DLABS:
  214. unknown_device=(caps.Get_Device()==DX8Caps::DEVICE_3DLABS_UNKNOWN);
  215. break;
  216. }
  217. if (unknown_device) {
  218. VersionWarningString=
  219. "Renegade doesn't recognize your videocard.\n"
  220. "While you will most likely be able to play\n"
  221. "the game without problems, we would still\n"
  222. "like to add your video card in our datebase.\n"
  223. "Please send email to [email protected] and\n"
  224. "tell what your system configuration is. Please\n"
  225. "include a file called sysinfo.txt from Renegade\n"
  226. "folder (c:\\westwood\\renegade by default)\n"
  227. "\n"
  228. "Thanks!";
  229. DriverVersionWarning dlg;
  230. dlg.DoModal();
  231. }
  232. */
  233. render_registry.Set_Int( "DriverVersionCheckDisabled", 87 ); // Disable checking if driver version is good
  234. GlobalExitValue=0;
  235. // IML: Disable driver warning message.
  236. #if 0
  237. DX8Caps::DriverVersionStatusType status=caps.Get_Driver_Version_Status();
  238. switch (status) {
  239. default:
  240. case DX8Caps::DRIVER_STATUS_GOOD:
  241. case DX8Caps::DRIVER_STATUS_OK:
  242. case DX8Caps::DRIVER_STATUS_UNKNOWN:
  243. render_registry.Set_Int( "DriverVersionCheckDisabled", 87 ); // Disable checking if driver version is good
  244. break;
  245. case DX8Caps::DRIVER_STATUS_BAD:
  246. {
  247. Get_Driver_Version_Warning_String(VersionWarningString,caps);
  248. DriverVersionWarning dlg;
  249. dlg.DoModal();
  250. }
  251. break;
  252. }
  253. #endif
  254. }
  255. void DriverVersionWarning::OnDisableDriverVersionDialogCheckbox()
  256. {
  257. // TODO: Add your control notification handler code here
  258. int is_disabled = SendDlgItemMessage (IDC_DISABLE_DRIVER_VERSION_DIALOG_CHECKBOX, BM_GETCHECK);
  259. RegistryClass render_registry(RENEGADE_SUB_KEY_NAME_RENDER);
  260. if (!render_registry.Is_Valid()) return;
  261. render_registry.Set_Int( "DriverVersionCheckDisabled", is_disabled ? 87 : 0 );
  262. }
  263. int DriverVersionWarning::DoModal()
  264. {
  265. // TODO: Add your specialized code here and/or call the base class
  266. return CDialog::DoModal();
  267. }
  268. /////////////////////////////////////////////////////////////////////////////
  269. //
  270. // OnInitDialog
  271. //
  272. // Modified: 12/06/2001 by MML - Retrieving strings from Locomoto file.
  273. //
  274. /////////////////////////////////////////////////////////////////////////////
  275. BOOL DriverVersionWarning::OnInitDialog()
  276. {
  277. CDialog::OnInitDialog();
  278. //
  279. // Set all the static strings for this dialog.
  280. //
  281. char string[ _MAX_PATH ];
  282. // Message
  283. SetDlgItemText(IDC_DRIVER_VERSION_WARNING_TEXT,VersionWarningString);
  284. // Title
  285. Locale_GetString( IDS_WARNING, string );
  286. SetWindowText((LPCTSTR) string );
  287. // Checkbox
  288. Locale_GetString( IDS_DO_NOT_SHOW_MSG_AGAIN, string );
  289. SetDlgItemText( IDC_DISABLE_DRIVER_VERSION_DIALOG_CHECKBOX, string );
  290. // Buttons
  291. Locale_GetString( IDS_OK, string );
  292. SetDlgItemText( IDOK, string );
  293. Locale_GetString( IDS_CANCEL, string );
  294. SetDlgItemText( IDCANCEL, string );
  295. // TODO: Add extra initialization here
  296. return TRUE; // return TRUE unless you set the focus to a control
  297. // EXCEPTION: OCX Property Pages should return FALSE
  298. }
  299. void DriverVersionWarning::OnCancel()
  300. {
  301. // TODO: Add extra cleanup here
  302. GlobalExitValue=1;
  303. CDialog::OnCancel();
  304. }
  305. void DriverVersionWarning::OnOK()
  306. {
  307. // TODO: Add extra validation here
  308. GlobalExitValue=0;
  309. CDialog::OnOK();
  310. }