Protect.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. /******************************************************************************
  19. *
  20. * FILE
  21. * $Archive: /Commando/Code/launcher/Protect.cpp $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * Denzil E. Long, Jr.
  27. * $Author: Tom_s $
  28. *
  29. * VERSION INFO
  30. * $Modtime: 3/04/02 5:55p $
  31. * $Revision: 3 $
  32. *
  33. ******************************************************************************/
  34. #include "Protect.h"
  35. #ifdef COPY_PROTECT
  36. #include "BFish.h"
  37. #include <Support\UString.h>
  38. #include <Support\RefPtr.h>
  39. #include <Storage\File.h>
  40. #include <windows.h>
  41. #include <memory>
  42. #include <assert.h>
  43. #include <Debug\DebugPrint.h>
  44. #include "SafeDisk\CdaPfn.h"
  45. #include "..\combat\specialbuilds.h"
  46. // This GUID should be unique for each product. (CHANGE IT WHEN DOING THE
  47. // NEXT PRODUCT) Note that the game will need to agree on this GUID also, so
  48. // the game will have to be modified also.
  49. const char* const LAUNCHER_GUID = "48BC11BD-C4D7-466b-8A31-C6ABBAD47B3E";
  50. #ifdef OLDWAY
  51. /******************************************************************************
  52. *
  53. * NAME
  54. *
  55. * DESCRIPTION
  56. *
  57. * INPUTS
  58. *
  59. * RESULT
  60. *
  61. ******************************************************************************/
  62. Protect::Protect()
  63. : mLauncherMutex(NULL),
  64. mMappedFile(NULL)
  65. {
  66. // Secure launcher mutex
  67. mLauncherMutex = CreateMutex(NULL, FALSE, LAUNCHER_GUID);
  68. if ((mLauncherMutex == NULL) ||
  69. ((mLauncherMutex != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS)))
  70. {
  71. return;
  72. }
  73. // Create memory mapped file to mirror protected file
  74. File file("Conquer.dat", Rights_ReadOnly);
  75. if (!file.IsAvailable())
  76. {
  77. return;
  78. }
  79. UInt32 fileSize = file.GetLength();
  80. SECURITY_ATTRIBUTES security;
  81. security.nLength = sizeof(security);
  82. security.lpSecurityDescriptor = NULL;
  83. security.bInheritHandle = TRUE;
  84. mMappedFile = CreateFileMapping(INVALID_HANDLE_VALUE, &security,
  85. PAGE_READWRITE, 0, fileSize, NULL);
  86. if ((mMappedFile == NULL) ||
  87. ((mMappedFile != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS)))
  88. {
  89. PrintWin32Error("***** CreateFileMapping() Failed!");
  90. CloseHandle(mMappedFile);
  91. mMappedFile = NULL;
  92. return;
  93. }
  94. // Map file to programs address space
  95. LPVOID mapAddress = MapViewOfFileEx(mMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
  96. if (mapAddress == NULL)
  97. {
  98. PrintWin32Error("***** MapViewOfFileEx() Failed!");
  99. return;
  100. }
  101. // Decrypt protected file contents to mapping file
  102. void* buffer = NULL;
  103. UInt32 bufferSize = 0;
  104. file.Load(buffer, bufferSize);
  105. if ((buffer != NULL) && (bufferSize > 0))
  106. {
  107. // Retrieve protection key
  108. RefPtr<UString> passKey = GetPassKey();
  109. Char key[64];
  110. passKey->ConvertToANSI(key, sizeof(key));
  111. DebugPrint("Retrieved PassKey: %s\n", key);
  112. // Decrypt data
  113. BlowfishEngine blowfish;
  114. blowfish.Submit_Key(key, strlen(key));
  115. blowfish.Decrypt(buffer, bufferSize, mapAddress);
  116. DebugPrint("Decrypted data: %s\n", mapAddress);
  117. free(buffer);
  118. }
  119. UnmapViewOfFile(mapAddress);
  120. }
  121. /******************************************************************************
  122. *
  123. * NAME
  124. *
  125. * DESCRIPTION
  126. *
  127. * INPUTS
  128. *
  129. * RESULT
  130. *
  131. ******************************************************************************/
  132. Protect::~Protect()
  133. {
  134. if (mMappedFile != NULL)
  135. {
  136. CloseHandle(mMappedFile);
  137. mMappedFile = NULL;
  138. }
  139. if (mLauncherMutex != NULL)
  140. {
  141. CloseHandle(mLauncherMutex);
  142. mLauncherMutex = NULL;
  143. }
  144. }
  145. /******************************************************************************
  146. *
  147. * NAME
  148. * Protect::SendMappedFileHandle()
  149. *
  150. * DESCRIPTION
  151. * Send the handle to the memory mapped file to the application.
  152. *
  153. * INPUTS
  154. * Process - Process of the application to send handle to.
  155. * ThreadID - Thread of the applicatin to send handle to.
  156. *
  157. * RESULT
  158. * NONE
  159. *
  160. ******************************************************************************/
  161. void Protect::SendMappedFileHandle(HANDLE process, DWORD threadID) const
  162. {
  163. DebugPrint("SendMappedFileHandle()\n");
  164. DebugPrint("Creating running notification event.\n");
  165. const char* const protectGUID = "D6E7FC97-64F9-4d28-B52C-754EDF721C6F";
  166. HANDLE event = CreateEvent(NULL, FALSE, FALSE, protectGUID);
  167. if ((event == NULL) || ((event != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS)))
  168. {
  169. PrintWin32Error("CreateEvent() Failed!");
  170. return;
  171. }
  172. DebugPrint("Waiting for game (timeout in %.02f seconds)...\n", ((float)((5 * 60) * 1000) * 0.001));
  173. #ifdef _DEBUG
  174. unsigned long start = timeGetTime();
  175. #endif
  176. HANDLE handles[2];
  177. handles[0] = event;
  178. handles[1] = process;
  179. DWORD waitResult = WaitForMultipleObjects(2, &handles[0], FALSE, ((5 * 60) * 1000));
  180. #ifdef _DEBUG
  181. unsigned long stop = timeGetTime();
  182. #endif
  183. DebugPrint("WaitResult = %ld (WAIT_OBJECT_0 = %ld)\n", waitResult, WAIT_OBJECT_0);
  184. if (waitResult == WAIT_OBJECT_0)
  185. {
  186. if (mMappedFile != NULL)
  187. {
  188. DebugPrint("Sending game the beef. (%lx)\n", mMappedFile);
  189. BOOL sent = PostThreadMessage(threadID, 0xBEEF, 0, (LPARAM)mMappedFile);
  190. assert(sent == TRUE);
  191. }
  192. }
  193. else
  194. {
  195. DebugPrint("***** Timeout!\n");
  196. }
  197. #ifdef _DEBUG
  198. DebugPrint("Waited %.02f seconds\n", ((float)(stop - start) * 0.001));
  199. #endif
  200. CloseHandle(event);
  201. }
  202. /******************************************************************************
  203. *
  204. * NAME
  205. *
  206. * DESCRIPTION
  207. *
  208. * INPUTS
  209. *
  210. * RESULT
  211. *
  212. ******************************************************************************/
  213. RefPtr<UString> Protect::GetPassKey(void) const
  214. {
  215. RefPtr<UString> passKey = new UString;
  216. if (passKey.IsValid())
  217. {
  218. unsigned char installPath[MAX_PATH];
  219. installPath[0] = '\0';
  220. // Get game information
  221. HKEY hKey;
  222. /*
  223. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  224. "Software\\Westwood\\Red Alert 2", 0, KEY_READ, &hKey);
  225. */
  226. #if defined(FREEDEDICATEDSERVER)
  227. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\RenegadeFDS", 0, KEY_READ, &hKey);
  228. #elif defined(MULTIPLAYERDEMO)
  229. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\RenegadeMPDemo", 0, KEY_READ, &hKey);
  230. #elif defined(BETACLIENT)
  231. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\RenegadeBeta", 0, KEY_READ, &hKey);
  232. #else
  233. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\Renegade", 0, KEY_READ, &hKey);
  234. #endif
  235. if (result != ERROR_SUCCESS)
  236. {
  237. DebugPrint("***** Failed to open game registry key\n");
  238. assert(result == ERROR_SUCCESS);
  239. }
  240. if (result == ERROR_SUCCESS)
  241. {
  242. // Retrieve install path
  243. DWORD type;
  244. DWORD sizeOfBuffer = sizeof(installPath);
  245. result = RegQueryValueEx(hKey, "InstallPath", NULL, &type, installPath, &sizeOfBuffer);
  246. if (result != ERROR_SUCCESS)
  247. {
  248. DebugPrint("***** Failed to obtain game install path!\n");
  249. assert(result == ERROR_SUCCESS);
  250. }
  251. DebugPrint("Game install path: %s\n", installPath);
  252. if (strlen((const char*)installPath) == 0)
  253. {
  254. DebugPrint("***** Game install path invalid!\n");
  255. }
  256. // Retrieve Hard drive S/N
  257. char drive[8];
  258. _splitpath((const char*)installPath, drive, NULL, NULL, NULL);
  259. strcat(drive, "\\");
  260. DWORD volumeSerialNumber = 0;
  261. DWORD maxComponentLength;
  262. DWORD fileSystemFlags;
  263. BOOL volInfoSuccess = GetVolumeInformation((const char*)drive, NULL, 0,
  264. &volumeSerialNumber, &maxComponentLength, &fileSystemFlags, NULL, 0);
  265. if (volInfoSuccess == FALSE)
  266. {
  267. PrintWin32Error("GetVolumeInformation() Failed!");
  268. }
  269. DebugPrint("Drive Serial Number: %lx\n", volumeSerialNumber);
  270. // Add hard drive serial number portion
  271. char volumeSN[16];
  272. sprintf(volumeSN, "%lx-", volumeSerialNumber);
  273. *passKey += volumeSN;
  274. // Retrieve game serial #
  275. unsigned char gameSerialNumber[64];
  276. gameSerialNumber[0] = '\0';
  277. sizeOfBuffer = sizeof(gameSerialNumber);
  278. result = RegQueryValueEx(hKey, "Serial", NULL, &type, gameSerialNumber, &sizeOfBuffer);
  279. if (result != ERROR_SUCCESS)
  280. {
  281. DebugPrint("***** Failed to obtain windows serial number!\n");
  282. assert(result == ERROR_SUCCESS);
  283. }
  284. DebugPrint("Game serial number: %s\n", gameSerialNumber);
  285. if (strlen((const char*)gameSerialNumber) == 0)
  286. {
  287. DebugPrint("***** Game serial number invalid!\n");
  288. }
  289. RegCloseKey(hKey);
  290. // Add game serial number portion
  291. *passKey += (char*)gameSerialNumber;
  292. }
  293. // Obtain windows product ID
  294. result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  295. "Software\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &hKey);
  296. if (result != ERROR_SUCCESS)
  297. {
  298. DebugPrint("***** Failed to open windows registry key!\n");
  299. assert(result == ERROR_SUCCESS);
  300. }
  301. if (result == ERROR_SUCCESS)
  302. {
  303. // Retrieve Windows Product ID
  304. unsigned char winProductID[64];
  305. winProductID[0] = '\0';
  306. DWORD type;
  307. DWORD sizeOfBuffer = sizeof(winProductID);
  308. result = RegQueryValueEx(hKey, "ProductID", NULL, &type, winProductID, &sizeOfBuffer);
  309. if (result != ERROR_SUCCESS)
  310. {
  311. DebugPrint("***** Failed to obtain windows product ID!\n");
  312. assert(result == ERROR_SUCCESS);
  313. }
  314. DebugPrint("Windows Product ID: %s\n", winProductID);
  315. if (strlen((const char*)winProductID) == 0)
  316. {
  317. DebugPrint("***** Invalid windows product ID\n");
  318. }
  319. RegCloseKey(hKey);
  320. // Add windows product ID portion
  321. *passKey += "-";
  322. *passKey += (char*)winProductID;
  323. }
  324. }
  325. return passKey;
  326. }
  327. #else
  328. HANDLE mLauncherMutex = NULL;
  329. HANDLE mMappedFile = NULL;
  330. void InitializeProtect(void)
  331. {
  332. ShutdownProtect();
  333. DebugPrint("Initializing protection\n");
  334. mLauncherMutex = NULL;
  335. mMappedFile = NULL;
  336. // Secure launcher mutex
  337. mLauncherMutex = CreateMutex(NULL, FALSE, LAUNCHER_GUID);
  338. if ((mLauncherMutex == NULL) || (mLauncherMutex && (GetLastError() == ERROR_ALREADY_EXISTS)))
  339. {
  340. DebugPrint("***** Failed to create launcher mutex\n");
  341. return;
  342. }
  343. // Create memory mapped file to mirror protected file
  344. File file("Conquer.dat", Rights_ReadOnly);
  345. if (!file.IsAvailable())
  346. {
  347. DebugPrint("***** Unable to find Conquer.dat\n");
  348. return;
  349. }
  350. UInt32 fileSize = file.GetLength();
  351. SECURITY_ATTRIBUTES security;
  352. security.nLength = sizeof(security);
  353. security.lpSecurityDescriptor = NULL;
  354. security.bInheritHandle = TRUE;
  355. mMappedFile = CreateFileMapping(INVALID_HANDLE_VALUE, &security, PAGE_READWRITE, 0, fileSize, NULL);
  356. if ((mMappedFile == NULL) || (mMappedFile && (GetLastError() == ERROR_ALREADY_EXISTS)))
  357. {
  358. PrintWin32Error("***** CreateFileMapping() Failed!");
  359. CloseHandle(mMappedFile);
  360. mMappedFile = NULL;
  361. return;
  362. }
  363. }
  364. CDAPFN_DECLARE_GLOBAL(SendProtectMessage, CDAPFN_OVERHEAD_L5, CDAPFN_CONSTRAINT_NONE);
  365. void SendProtectMessage(HANDLE process, DWORD threadID)
  366. {
  367. // Decrypt protected file contents to mapping file
  368. File file("Conquer.dat", Rights_ReadOnly);
  369. if (!file.IsAvailable())
  370. {
  371. DebugPrint("***** Unable to find Conquer.dat\n");
  372. return;
  373. }
  374. // Map file to programs address space
  375. LPVOID mapAddress = MapViewOfFileEx(mMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
  376. if (mapAddress == NULL)
  377. {
  378. PrintWin32Error("***** MapViewOfFileEx() Failed!");
  379. return;
  380. }
  381. void* buffer = NULL;
  382. UInt32 bufferSize = 0;
  383. file.Load(buffer, bufferSize);
  384. if (buffer && (bufferSize > 0))
  385. {
  386. DebugPrint("Generating PassKey\n");
  387. // Generate passkey
  388. char passKey[64];
  389. passKey[0] = '\0';
  390. // Get game information
  391. HKEY hKey;
  392. /*
  393. #ifdef FREEDEDICATEDSERVER
  394. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\RenegadeFDS", 0, KEY_READ, &hKey);
  395. #else //FREEDEDICATEDSERVER
  396. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\Renegade", 0, KEY_READ, &hKey);
  397. #endif //FREEDEDICATEDSERVER
  398. */
  399. #if defined(FREEDEDICATEDSERVER)
  400. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\RenegadeFDS", 0, KEY_READ, &hKey);
  401. #elif defined(MULTIPLAYERDEMO)
  402. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\RenegadeMPDemo", 0, KEY_READ, &hKey);
  403. #elif defined(BETACLIENT)
  404. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\RenegadeBeta", 0, KEY_READ, &hKey);
  405. #else
  406. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Westwood\\Renegade", 0, KEY_READ, &hKey);
  407. #endif
  408. assert((result == ERROR_SUCCESS) && "Failed to open game registry key");
  409. if (result == ERROR_SUCCESS)
  410. {
  411. // Retrieve install path
  412. unsigned char installPath[MAX_PATH];
  413. DWORD type;
  414. DWORD sizeOfBuffer = sizeof(installPath);
  415. result = RegQueryValueEx(hKey, "InstallPath", NULL, &type, installPath, &sizeOfBuffer);
  416. assert((result == ERROR_SUCCESS) && "Failed to obtain game install path!");
  417. assert((strlen((const char*)installPath) > 0) && "Game install path invalid!");
  418. DebugPrint("Game install path: %s\n", installPath);
  419. // Retrieve Hard drive S/N
  420. char drive[8];
  421. _splitpath((const char*)installPath, drive, NULL, NULL, NULL);
  422. strcat(drive, "\\");
  423. DWORD volumeSerialNumber = 0;
  424. DWORD maxComponentLength;
  425. DWORD fileSystemFlags;
  426. BOOL volInfoSuccess = GetVolumeInformation((const char*)drive, NULL, 0,
  427. &volumeSerialNumber, &maxComponentLength, &fileSystemFlags, NULL, 0);
  428. if (volInfoSuccess == FALSE)
  429. {
  430. PrintWin32Error("***** GetVolumeInformation() Failed!");
  431. }
  432. DebugPrint("Drive Serial Number: %lx\n", volumeSerialNumber);
  433. // Add hard drive serial number portion
  434. char volumeSN[16];
  435. sprintf(volumeSN, "%lx-", volumeSerialNumber);
  436. strcat(passKey, volumeSN);
  437. // Retrieve game serial #
  438. unsigned char gameSerialNumber[64];
  439. gameSerialNumber[0] = '\0';
  440. sizeOfBuffer = sizeof(gameSerialNumber);
  441. result = RegQueryValueEx(hKey, "Serial", NULL, &type, gameSerialNumber, &sizeOfBuffer);
  442. assert((result == ERROR_SUCCESS) && "Failed to obtain windows serial number!");
  443. assert((strlen((const char*)gameSerialNumber) > 0) && "Game serial number invalid!");
  444. DebugPrint("Game serial number: %s\n", gameSerialNumber);
  445. RegCloseKey(hKey);
  446. // Add game serial number portion
  447. strcat(passKey, (char*)gameSerialNumber);
  448. }
  449. // Obtain windows product ID
  450. result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &hKey);
  451. assert((result == ERROR_SUCCESS) && "Failed to open windows registry key!");
  452. if (result == ERROR_SUCCESS)
  453. {
  454. // Retrieve Windows Product ID
  455. unsigned char winProductID[64];
  456. winProductID[0] = '\0';
  457. DWORD type;
  458. DWORD sizeOfBuffer = sizeof(winProductID);
  459. result = RegQueryValueEx(hKey, "ProductID", NULL, &type, winProductID, &sizeOfBuffer);
  460. assert((result == ERROR_SUCCESS) && "Failed to obtain windows product ID!");
  461. assert((strlen((const char*)winProductID) > 0) && "Invalid windows product ID");
  462. DebugPrint("Windows Product ID: %s\n", winProductID);
  463. RegCloseKey(hKey);
  464. // Add windows product ID portion
  465. strcat(passKey, "-");
  466. strcat(passKey, (char*)winProductID);
  467. }
  468. DebugPrint("Retrieved PassKey: %s\n", passKey);
  469. // Decrypt protected data into the memory mapped file
  470. BlowfishEngine blowfish;
  471. blowfish.Submit_Key(passKey, strlen(passKey));
  472. blowfish.Decrypt(buffer, bufferSize, mapAddress);
  473. DebugPrint("Decrypted data: %s\n", mapAddress);
  474. free(buffer);
  475. }
  476. UnmapViewOfFile(mapAddress);
  477. //---------------------------------------------------------------------------
  478. // Send protection message
  479. //---------------------------------------------------------------------------
  480. DebugPrint("Sending protect message\n");
  481. DebugPrint("Creating running notification event.\n");
  482. const char* const protectGUID = "D6E7FC97-64F9-4d28-B52C-754EDF721C6F";
  483. HANDLE event = CreateEvent(NULL, FALSE, FALSE, protectGUID);
  484. if ((event == NULL) || (event && (GetLastError() == ERROR_ALREADY_EXISTS)))
  485. {
  486. PrintWin32Error("***** CreateEvent() Failed!");
  487. return;
  488. }
  489. DebugPrint("Waiting for game (timeout in %.02f seconds)...\n", ((float)((5 * 60) * 1000) * 0.001));
  490. #ifdef _DEBUG
  491. unsigned long start = timeGetTime();
  492. #endif
  493. HANDLE handles[2];
  494. handles[0] = event;
  495. handles[1] = process;
  496. DWORD waitResult = WaitForMultipleObjects(2, &handles[0], FALSE, ((5 * 60) * 1000));
  497. #ifdef _DEBUG
  498. unsigned long stop = timeGetTime();
  499. #endif
  500. DebugPrint("WaitResult = %ld (WAIT_OBJECT_0 = %ld)\n", waitResult, WAIT_OBJECT_0);
  501. if (waitResult == WAIT_OBJECT_0)
  502. {
  503. if (mMappedFile != NULL)
  504. {
  505. DebugPrint("Sending game the beef. (%lx)\n", mMappedFile);
  506. BOOL sent = PostThreadMessage(threadID, 0xBEEF, 0, (LPARAM)mMappedFile);
  507. assert(sent == TRUE);
  508. }
  509. }
  510. else
  511. {
  512. DebugPrint("***** Timeout!\n");
  513. }
  514. #ifdef _DEBUG
  515. DebugPrint("Waited %.02f seconds\n", ((float)(stop - start) * 0.001));
  516. #endif
  517. CloseHandle(event);
  518. CDAPFN_ENDMARK(SendProtectMessage);
  519. }
  520. void ShutdownProtect(void)
  521. {
  522. if (mMappedFile)
  523. {
  524. CloseHandle(mMappedFile);
  525. mMappedFile = NULL;
  526. }
  527. if (mLauncherMutex)
  528. {
  529. CloseHandle(mLauncherMutex);
  530. mLauncherMutex = NULL;
  531. }
  532. }
  533. #endif
  534. #endif // COPY_PROTECT