Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
2.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Platform level security functions.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. // Uncomment the following line to require the prescence of a hardware key.
  8. //#define REQUIRE_HARDWARE_KEY
  9. // NOTE - this DOESN'T work under linux!!!!
  10. #include "tier0/platform.h"
  11. #include "tier0/memalloc.h"
  12. #ifdef REQUIRE_HARDWARE_KEY
  13. #define VALVE_DESKEY_ID "uW" // Uniquely identifies HL2 keys
  14. // Include the key's API:
  15. #include "deskey/algo.h"
  16. #include "deskey/dk2win32.h"
  17. // #pragma comment(lib, "DESKey/algo32.lib" )
  18. // #pragma comment(lib, "DESKey/dk2win32.lib" )
  19. #endif
  20. // NOTE: This has to be the last file included! (turned off below, since this is included like a header)
  21. #include "tier0/memdbgon.h"
  22. bool Plat_VerifyHardwareKey()
  23. {
  24. #ifdef REQUIRE_HARDWARE_KEY
  25. // Ensure that a key with our ID exists:
  26. if( FindDK2( VALVE_DESKEY_ID, NULL ) )
  27. return true;
  28. return false;
  29. #else
  30. return true;
  31. #endif
  32. }
  33. bool Plat_VerifyHardwareKeyDriver()
  34. {
  35. #ifdef REQUIRE_HARDWARE_KEY
  36. // Ensure that the driver is at least installed:
  37. return DK2DriverInstalled() != 0;
  38. #else
  39. return true;
  40. #endif
  41. }
  42. bool Plat_VerifyHardwareKeyPrompt()
  43. {
  44. #ifdef REQUIRE_HARDWARE_KEY
  45. if( !DK2DriverInstalled() )
  46. {
  47. if( IDCANCEL == MessageBox( NULL, "No drivers detected for the hardware key, please install them and re-run the application.\n", "No Driver Detected", MB_OKCANCEL ) )
  48. {
  49. return false;
  50. }
  51. }
  52. while( !Plat_VerifyHardwareKey() )
  53. {
  54. if( IDCANCEL == MessageBox( NULL, "Please insert the hardware key and hit 'ok'.\n", "Insert Hardware Key", MB_OKCANCEL ) )
  55. {
  56. return false;
  57. }
  58. for( int i=0; i < 2; i++ )
  59. {
  60. // Is the key in now?
  61. if( Plat_VerifyHardwareKey() )
  62. {
  63. return true;
  64. }
  65. // Sleep 2 / 3 of a second before trying again, in case the os recognizes the key slightly after it's being inserted:
  66. Sleep(666);
  67. }
  68. }
  69. return true;
  70. #else
  71. return true;
  72. #endif
  73. }
  74. bool Plat_FastVerifyHardwareKey()
  75. {
  76. #ifdef REQUIRE_HARDWARE_KEY
  77. static int nIterations = 0;
  78. nIterations++;
  79. if( nIterations > 100 )
  80. {
  81. nIterations = 0;
  82. return Plat_VerifyHardwareKey();
  83. }
  84. return true;
  85. #else
  86. return true;
  87. #endif
  88. }
  89. // Turn off memdbg macros (turned on up top) since this is included like a header
  90. #include "tier0/memdbgoff.h"