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.

800 lines
23 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //
  9. // Half-Life Model Viewer (c) 1999 by Mete Ciragan
  10. //
  11. // file: ViewerSettings.cpp
  12. // last modified: May 29 1999, Mete Ciragan
  13. // copyright: The programs and associated files contained in this
  14. // distribution were developed by Mete Ciragan. The programs
  15. // are not in the public domain, but they are freely
  16. // distributable without licensing fees. These programs are
  17. // provided without guarantee or warrantee expressed or
  18. // implied.
  19. //
  20. // version: 1.2
  21. //
  22. // email: [email protected]
  23. // web: http://www.swissquake.ch/chumbalum-soft/
  24. //
  25. #include "ViewerSettings.h"
  26. #include "studiomodel.h"
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "windows.h"
  31. CUtlVector< qcpathrecord_t > g_QCPathRecords;
  32. ViewerSettings g_viewerSettings;
  33. ViewerSettings::ViewerSettings()
  34. {
  35. Q_memset( this, 0, sizeof( *this ) );
  36. }
  37. void InitViewerSettings ( const char *subkey )
  38. {
  39. ViewerSettings save = g_viewerSettings;
  40. memset (&g_viewerSettings, 0, sizeof (ViewerSettings));
  41. // Some values should survive. This is a crappy way to do settings in general. Sigh.
  42. {
  43. g_viewerSettings.faceposerToolsDriveMouth = save.faceposerToolsDriveMouth;
  44. g_viewerSettings.showHidden = save.showHidden;
  45. g_viewerSettings.showActivities = save.showActivities;
  46. g_viewerSettings.showSequenceIndices = save.showSequenceIndices;
  47. g_viewerSettings.sortSequences = save.sortSequences;
  48. g_viewerSettings.dotaMode = save.dotaMode;
  49. }
  50. g_viewerSettings.showOrbitCircle = false;
  51. g_viewerSettings.allowOrbitYaw = false;
  52. strcpy( g_viewerSettings.registrysubkey, subkey );
  53. g_pStudioModel->m_angles.Init( -90.0f, 0.0f, 0.0f );
  54. g_pStudioModel->m_origin.Init( 0.0f, 0.0f, 50.0f );
  55. g_viewerSettings.renderMode = RM_TEXTURED;
  56. g_viewerSettings.fov = 65.0f;
  57. g_viewerSettings.enableNormalMapping = false;
  58. g_viewerSettings.enableDisplacementMapping = true;
  59. g_viewerSettings.enableParallaxMapping = false;
  60. g_viewerSettings.showNormals = false;
  61. g_viewerSettings.showTangentFrame = false;
  62. g_viewerSettings.overlayWireframe = false;
  63. g_viewerSettings.enableSpecular = true;
  64. g_viewerSettings.playSounds = true;
  65. g_viewerSettings.bgColor[0] = 0.25f;
  66. g_viewerSettings.bgColor[1] = 0.25f;
  67. g_viewerSettings.bgColor[2] = 0.25f;
  68. g_viewerSettings.gColor[0] = 0.85f;
  69. g_viewerSettings.gColor[1] = 0.85f;
  70. g_viewerSettings.gColor[2] = 0.69f;
  71. g_viewerSettings.lColor[0] = 1.0f;
  72. g_viewerSettings.lColor[1] = 1.0f;
  73. g_viewerSettings.lColor[2] = 1.0f;
  74. g_viewerSettings.aColor[0] = 0.3f;
  75. g_viewerSettings.aColor[1] = 0.3f;
  76. g_viewerSettings.aColor[2] = 0.3f;
  77. g_viewerSettings.lightrot[0] = 0.0f;
  78. g_viewerSettings.lightrot[1] = 180.0f;
  79. g_viewerSettings.lightrot[2] = 0.0f;
  80. g_viewerSettings.speedScale = 1.0f;
  81. g_viewerSettings.application_mode = 0;
  82. g_viewerSettings.thumbnailsize = 128;
  83. g_viewerSettings.thumbnailsizeanim = 128;
  84. g_viewerSettings.m_iEditAttachment = -1;
  85. g_viewerSettings.highlightHitbox = -1;
  86. g_viewerSettings.highlightBone = -1;
  87. g_viewerSettings.speechapiindex = 0;
  88. g_viewerSettings.cclanguageid = 0;
  89. // default hlmv settings
  90. g_viewerSettings.xpos = 20;
  91. g_viewerSettings.ypos = 20;
  92. g_viewerSettings.width = 640;
  93. g_viewerSettings.height = 700;
  94. g_viewerSettings.originAxisLength = 10.0f;
  95. g_viewerSettings.hitboxEditMode = HITBOX_EDIT_ROTATION;
  96. g_viewerSettings.showBoneNames = false;
  97. }
  98. bool RegReadVector( HKEY hKey, const char *szSubKey, Vector& value )
  99. {
  100. LONG lResult; // Registry function result code
  101. char szBuff[128]; // Temp. buffer
  102. DWORD dwType; // Type of key
  103. DWORD dwSize; // Size of element data
  104. dwSize = sizeof( szBuff );
  105. lResult = RegQueryValueEx(
  106. hKey, // handle to key
  107. szSubKey, // value name
  108. 0, // reserved
  109. &dwType, // type buffer
  110. (LPBYTE)szBuff, // data buffer
  111. &dwSize ); // size of data buffer
  112. if (lResult != ERROR_SUCCESS) // Failure
  113. return false;
  114. if (sscanf( szBuff, "(%f %f %f)", &value[0], &value[1], &value[2] ) != 3)
  115. return false;
  116. return true;
  117. }
  118. bool RegReadQAngle( HKEY hKey, const char *szSubKey, QAngle& value )
  119. {
  120. Vector tmp;
  121. if (RegReadVector( hKey, szSubKey, tmp ))
  122. {
  123. value.Init( tmp.x, tmp.y, tmp.z );
  124. return true;
  125. }
  126. return false;
  127. }
  128. bool RegReadColor( HKEY hKey, const char *szSubKey, float value[4] )
  129. {
  130. LONG lResult; // Registry function result code
  131. char szBuff[128]; // Temp. buffer
  132. DWORD dwType; // Type of key
  133. DWORD dwSize; // Size of element data
  134. dwSize = sizeof( szBuff );
  135. lResult = RegQueryValueEx(
  136. hKey, // handle to key
  137. szSubKey, // value name
  138. 0, // reserved
  139. &dwType, // type buffer
  140. (LPBYTE)szBuff, // data buffer
  141. &dwSize ); // size of data buffer
  142. if (lResult != ERROR_SUCCESS) // Failure
  143. return false;
  144. if (sscanf( szBuff, "(%f %f %f %f)", &value[0], &value[1], &value[2], &value[3] ) != 4)
  145. return false;
  146. return true;
  147. }
  148. bool RegWriteVector( HKEY hKey, const char *szSubKey, Vector& value )
  149. {
  150. LONG lResult; // Registry function result code
  151. char szBuff[128]; // Temp. buffer
  152. DWORD dwSize; // Size of element data
  153. sprintf( szBuff, "(%f %f %f)", value[0], value[1], value[2] );
  154. dwSize = strlen( szBuff );
  155. lResult = RegSetValueEx(
  156. hKey, // handle to key
  157. szSubKey, // value name
  158. 0, // reserved
  159. REG_SZ, // type buffer
  160. (LPBYTE)szBuff, // data buffer
  161. dwSize ); // size of data buffer
  162. if (lResult != ERROR_SUCCESS) // Failure
  163. return false;
  164. return true;
  165. }
  166. bool RegWriteQAngle( HKEY hKey, const char *szSubKey, QAngle& value )
  167. {
  168. Vector tmp;
  169. tmp.Init( value.x, value.y, value.z );
  170. return RegWriteVector( hKey, szSubKey, tmp );
  171. }
  172. bool RegWriteColor( HKEY hKey, const char *szSubKey, float value[4] )
  173. {
  174. LONG lResult; // Registry function result code
  175. char szBuff[128]; // Temp. buffer
  176. DWORD dwSize; // Size of element data
  177. sprintf( szBuff, "(%f %f %f %f)", value[0], value[1], value[2], value[3] );
  178. dwSize = strlen( szBuff );
  179. lResult = RegSetValueEx(
  180. hKey, // handle to key
  181. szSubKey, // value name
  182. 0, // reserved
  183. REG_SZ, // type buffer
  184. (LPBYTE)szBuff, // data buffer
  185. dwSize ); // size of data buffer
  186. if (lResult != ERROR_SUCCESS) // Failure
  187. return false;
  188. return true;
  189. }
  190. bool RegReadBool( HKEY hKey, const char *szSubKey, bool *value )
  191. {
  192. LONG lResult; // Registry function result code
  193. DWORD dwType; // Type of key
  194. DWORD dwSize; // Size of element data
  195. DWORD dwTemp;
  196. dwSize = sizeof( dwTemp );
  197. lResult = RegQueryValueEx(
  198. hKey, // handle to key
  199. szSubKey, // value name
  200. 0, // reserved
  201. &dwType, // type buffer
  202. (LPBYTE)&dwTemp, // data buffer
  203. &dwSize ); // size of data buffer
  204. if (lResult != ERROR_SUCCESS) // Failure
  205. return false;
  206. if (dwType != REG_DWORD)
  207. return false;
  208. *value = (dwTemp != 0);
  209. return true;
  210. }
  211. bool RegReadInt( HKEY hKey, const char *szSubKey, int *value )
  212. {
  213. LONG lResult; // Registry function result code
  214. DWORD dwType; // Type of key
  215. DWORD dwSize; // Size of element data
  216. dwSize = sizeof( DWORD );
  217. lResult = RegQueryValueEx(
  218. hKey, // handle to key
  219. szSubKey, // value name
  220. 0, // reserved
  221. &dwType, // type buffer
  222. (LPBYTE)value, // data buffer
  223. &dwSize ); // size of data buffer
  224. if (lResult != ERROR_SUCCESS) // Failure
  225. return false;
  226. if (dwType != REG_DWORD)
  227. return false;
  228. return true;
  229. }
  230. bool RegWriteInt( HKEY hKey, const char *szSubKey, int value )
  231. {
  232. LONG lResult; // Registry function result code
  233. DWORD dwSize; // Size of element data
  234. dwSize = sizeof( DWORD );
  235. lResult = RegSetValueEx(
  236. hKey, // handle to key
  237. szSubKey, // value name
  238. 0, // reserved
  239. REG_DWORD, // type buffer
  240. (LPBYTE)&value, // data buffer
  241. dwSize ); // size of data buffer
  242. if (lResult != ERROR_SUCCESS) // Failure
  243. return false;
  244. return true;
  245. }
  246. bool RegReadFloat( HKEY hKey, const char *szSubKey, float *value )
  247. {
  248. LONG lResult; // Registry function result code
  249. char szBuff[128]; // Temp. buffer
  250. DWORD dwType; // Type of key
  251. DWORD dwSize; // Size of element data
  252. dwSize = sizeof( szBuff );
  253. lResult = RegQueryValueEx(
  254. hKey, // handle to key
  255. szSubKey, // value name
  256. 0, // reserved
  257. &dwType, // type buffer
  258. (LPBYTE)szBuff, // data buffer
  259. &dwSize ); // size of data buffer
  260. if (lResult != ERROR_SUCCESS) // Failure
  261. return false;
  262. *value = atof( szBuff );
  263. return true;
  264. }
  265. bool RegWriteFloat( HKEY hKey, const char *szSubKey, float value )
  266. {
  267. LONG lResult; // Registry function result code
  268. char szBuff[128]; // Temp. buffer
  269. DWORD dwSize; // Size of element data
  270. sprintf( szBuff, "%f", value );
  271. dwSize = strlen( szBuff );
  272. lResult = RegSetValueEx(
  273. hKey, // handle to key
  274. szSubKey, // value name
  275. 0, // reserved
  276. REG_SZ, // type buffer
  277. (LPBYTE)szBuff, // data buffer
  278. dwSize ); // size of data buffer
  279. if (lResult != ERROR_SUCCESS) // Failure
  280. return false;
  281. return true;
  282. }
  283. bool RegReadString( HKEY hKey, const char *szSubKey, char *string, int size )
  284. {
  285. LONG lResult; // Registry function result code
  286. DWORD dwType; // Type of key
  287. DWORD dwSize; // Size of element data
  288. dwSize = size;
  289. lResult = RegQueryValueEx(
  290. hKey, // handle to key
  291. szSubKey, // value name
  292. 0, // reserved
  293. &dwType, // type buffer
  294. (LPBYTE)string, // data buffer
  295. &dwSize ); // size of data buffer
  296. if (lResult != ERROR_SUCCESS) // Failure
  297. return false;
  298. if (dwType != REG_SZ)
  299. return false;
  300. return true;
  301. }
  302. bool RegWriteString( HKEY hKey, const char *szSubKey, char *string )
  303. {
  304. LONG lResult; // Registry function result code
  305. DWORD dwSize; // Size of element data
  306. dwSize = strlen( string );
  307. lResult = RegSetValueEx(
  308. hKey, // handle to key
  309. szSubKey, // value name
  310. 0, // reserved
  311. REG_SZ, // type buffer
  312. (LPBYTE)string, // data buffer
  313. dwSize ); // size of data buffer
  314. if (lResult != ERROR_SUCCESS) // Failure
  315. return false;
  316. return true;
  317. }
  318. LONG RegViewerSettingsKey( const char *filename, PHKEY phKey, LPDWORD lpdwDisposition )
  319. {
  320. if (strlen( filename ) == 0)
  321. return ERROR_KEY_DELETED;
  322. char szFileName[1024];
  323. strcpy( szFileName, filename );
  324. // strip out bogus characters
  325. for (char *cp = szFileName; *cp; cp++)
  326. {
  327. if (*cp == '\\' || *cp == '/' || *cp == ':')
  328. *cp = '.';
  329. }
  330. char szModelKey[1024];
  331. sprintf( szModelKey, "Software\\Valve\\%s\\%s", g_viewerSettings.registrysubkey, szFileName );
  332. return RegCreateKeyEx(
  333. HKEY_CURRENT_USER, // handle of open key
  334. szModelKey, // address of name of subkey to open
  335. 0, // DWORD ulOptions, // reserved
  336. NULL, // Type of value
  337. REG_OPTION_NON_VOLATILE, // Store permanently in reg.
  338. KEY_ALL_ACCESS, // REGSAM samDesired, // security access mask
  339. NULL,
  340. phKey, // Key we are creating
  341. lpdwDisposition); // Type of creation
  342. }
  343. LONG RegViewerRootKey( PHKEY phKey, LPDWORD lpdwDisposition )
  344. {
  345. char szRootKey[1024];
  346. sprintf( szRootKey, "Software\\Valve\\%s", g_viewerSettings.registrysubkey );
  347. return RegCreateKeyEx(
  348. HKEY_CURRENT_USER, // handle of open key
  349. szRootKey, // address of name of subkey to open
  350. 0, // DWORD ulOptions, // reserved
  351. NULL, // Type of value
  352. REG_OPTION_NON_VOLATILE, // Store permanently in reg.
  353. KEY_ALL_ACCESS, // REGSAM samDesired, // security access mask
  354. NULL,
  355. phKey, // Key we are creating
  356. lpdwDisposition); // Type of creation
  357. }
  358. bool LoadViewerSettingsInt( char const *keyname, int *value )
  359. {
  360. LONG lResult; // Registry function result code
  361. DWORD dwDisposition; // Type of key opening event
  362. HKEY hModelKey;
  363. lResult = RegViewerSettingsKey( "hlfaceposer", &hModelKey, &dwDisposition);
  364. if (lResult != ERROR_SUCCESS) // Failure
  365. return false;
  366. // First time, just set to Valve default
  367. if (dwDisposition == REG_CREATED_NEW_KEY)
  368. {
  369. return false;
  370. }
  371. *value = 0;
  372. RegReadInt( hModelKey, keyname, value );
  373. return true;
  374. }
  375. bool SaveViewerSettingsInt ( const char *keyname, int value )
  376. {
  377. LONG lResult; // Registry function result code
  378. DWORD dwDisposition; // Type of key opening event
  379. HKEY hModelKey;
  380. lResult = RegViewerSettingsKey( "hlfaceposer", &hModelKey, &dwDisposition);
  381. if (lResult != ERROR_SUCCESS) // Failure
  382. return false;
  383. RegWriteInt( hModelKey, keyname, value );
  384. return true;
  385. }
  386. bool LoadViewerSettings (const char *filename, StudioModel *pModel )
  387. {
  388. LONG lResult; // Registry function result code
  389. DWORD dwDisposition; // Type of key opening event
  390. HKEY hModelKey;
  391. if (filename == NULL || pModel == NULL)
  392. return false;
  393. lResult = RegViewerSettingsKey( filename, &hModelKey, &dwDisposition);
  394. if (lResult != ERROR_SUCCESS) // Failure
  395. return false;
  396. // First time, just set to Valve default
  397. if (dwDisposition == REG_CREATED_NEW_KEY)
  398. {
  399. return false;
  400. }
  401. RegReadQAngle( hModelKey, "Rot", pModel->m_angles );
  402. RegReadVector( hModelKey, "Trans", pModel->m_origin );
  403. RegReadColor( hModelKey, "bgColor", g_viewerSettings.bgColor );
  404. RegReadColor( hModelKey, "gColor", g_viewerSettings.gColor );
  405. RegReadColor( hModelKey, "lColor", g_viewerSettings.lColor );
  406. RegReadColor( hModelKey, "aColor", g_viewerSettings.aColor );
  407. RegReadQAngle( hModelKey, "lightrot", g_viewerSettings.lightrot );
  408. int iTemp;
  409. float flTemp;
  410. char szTemp[256];
  411. RegReadString( hModelKey, "sequence", szTemp, sizeof( szTemp ) );
  412. iTemp = pModel->LookupSequence( szTemp );
  413. pModel->SetSequence( iTemp );
  414. RegReadString( hModelKey, "overlaySequence0", szTemp, sizeof( szTemp ) );
  415. iTemp = pModel->LookupSequence( szTemp );
  416. RegReadFloat( hModelKey, "overlayWeight0", &flTemp );
  417. pModel->SetOverlaySequence( 0, iTemp, flTemp );
  418. RegReadString( hModelKey, "overlaySequence1", szTemp, sizeof( szTemp ) );
  419. iTemp = pModel->LookupSequence( szTemp );
  420. RegReadFloat( hModelKey, "overlayWeight1", &flTemp );
  421. pModel->SetOverlaySequence( 1, iTemp, flTemp );
  422. RegReadString( hModelKey, "overlaySequence2", szTemp, sizeof( szTemp ) );
  423. iTemp = pModel->LookupSequence( szTemp );
  424. RegReadFloat( hModelKey, "overlayWeight2", &flTemp );
  425. pModel->SetOverlaySequence( 2, iTemp, flTemp );
  426. RegReadString( hModelKey, "overlaySequence3", szTemp, sizeof( szTemp ) );
  427. iTemp = pModel->LookupSequence( szTemp );
  428. RegReadFloat( hModelKey, "overlayWeight3",&flTemp );
  429. pModel->SetOverlaySequence( 3, iTemp, flTemp );
  430. RegReadFloat( hModelKey, "speedscale", &g_viewerSettings.speedScale );
  431. if (g_viewerSettings.speedScale > 1.0)
  432. g_viewerSettings.speedScale = 1.0;
  433. RegReadInt( hModelKey, "viewermode", &g_viewerSettings.application_mode );
  434. RegReadInt( hModelKey, "thumbnailsize", &g_viewerSettings.thumbnailsize );
  435. RegReadInt( hModelKey, "thumbnailsizeanim", &g_viewerSettings.thumbnailsizeanim );
  436. if ( g_viewerSettings.thumbnailsize == 0 )
  437. {
  438. g_viewerSettings.thumbnailsize = 128;
  439. }
  440. if ( g_viewerSettings.thumbnailsizeanim == 0 )
  441. {
  442. g_viewerSettings.thumbnailsizeanim = 128;
  443. }
  444. RegReadInt( hModelKey, "speechapiindex", &g_viewerSettings.speechapiindex );
  445. RegReadInt( hModelKey, "cclanguageid", &g_viewerSettings.cclanguageid );
  446. RegReadBool( hModelKey, "showground", &g_viewerSettings.showGround );
  447. RegReadBool( hModelKey, "showbackground", &g_viewerSettings.showBackground );
  448. RegReadBool( hModelKey, "showshadow", &g_viewerSettings.showShadow );
  449. RegReadBool( hModelKey, "showillumpos", &g_viewerSettings.showIllumPosition );
  450. RegReadBool( hModelKey, "enablenormalmapping", &g_viewerSettings.enableNormalMapping );
  451. RegReadBool( hModelKey, "enabledisplacementmapping", &g_viewerSettings.enableDisplacementMapping );
  452. RegReadBool( hModelKey, "playsounds", &g_viewerSettings.playSounds );
  453. RegReadBool( hModelKey, "showoriginaxis", &g_viewerSettings.showOriginAxis );
  454. RegReadFloat( hModelKey, "originaxislength", &g_viewerSettings.originAxisLength );
  455. char merge_buffer[32];
  456. for ( int i = 0; i < HLMV_MAX_MERGED_MODELS; i++ )
  457. {
  458. Q_snprintf( merge_buffer, sizeof( merge_buffer ), "merge%d", i + 1 );
  459. RegReadString( hModelKey, merge_buffer, g_viewerSettings.mergeModelFile[i], sizeof( g_viewerSettings.mergeModelFile[i] ) );
  460. }
  461. return true;
  462. }
  463. bool LoadViewerRootSettings( void )
  464. {
  465. LONG lResult; // Registry function result code
  466. DWORD dwDisposition; // Type of key opening event
  467. HKEY hRootKey;
  468. lResult = RegViewerRootKey( &hRootKey, &dwDisposition);
  469. if (lResult != ERROR_SUCCESS) // Failure
  470. return false;
  471. RegReadInt( hRootKey, "renderxpos", &g_viewerSettings.xpos );
  472. RegReadInt( hRootKey, "renderypos", &g_viewerSettings.ypos );
  473. RegReadInt( hRootKey, "renderwidth", &g_viewerSettings.width );
  474. RegReadInt( hRootKey, "renderheight", &g_viewerSettings.height );
  475. RegReadBool( hRootKey, "faceposerToolsDriveMouth", &g_viewerSettings.faceposerToolsDriveMouth );
  476. RegReadBool( hRootKey, "showHidden", &g_viewerSettings.showHidden );
  477. RegReadBool( hRootKey, "showActivities", &g_viewerSettings.showActivities );
  478. RegReadBool( hRootKey, "showSequenceIndices", &g_viewerSettings.showSequenceIndices );
  479. RegReadBool( hRootKey, "sortSequences", &g_viewerSettings.sortSequences );
  480. RegReadBool( hRootKey, "dotaMode", &g_viewerSettings.dotaMode );
  481. return true;
  482. }
  483. bool SaveViewerSettings (const char *filename, StudioModel *pModel )
  484. {
  485. LONG lResult; // Registry function result code
  486. DWORD dwDisposition; // Type of key opening event
  487. if (filename == NULL || pModel == NULL)
  488. return false;
  489. HKEY hModelKey;
  490. lResult = RegViewerSettingsKey( filename, &hModelKey, &dwDisposition);
  491. if (lResult != ERROR_SUCCESS) // Failure
  492. return false;
  493. MDLCACHE_CRITICAL_SECTION_( g_pMDLCache );
  494. CStudioHdr *hdr = pModel->GetStudioHdr();
  495. if ( !hdr )
  496. return false;
  497. RegWriteQAngle( hModelKey, "Rot", pModel->m_angles );
  498. RegWriteVector( hModelKey, "Trans", pModel->m_origin );
  499. RegWriteColor( hModelKey, "bgColor", g_viewerSettings.bgColor );
  500. RegWriteColor( hModelKey, "gColor", g_viewerSettings.gColor );
  501. RegWriteColor( hModelKey, "lColor", g_viewerSettings.lColor );
  502. RegWriteColor( hModelKey, "aColor", g_viewerSettings.aColor );
  503. RegWriteQAngle( hModelKey, "lightrot", g_viewerSettings.lightrot );
  504. RegWriteString( hModelKey, "sequence", hdr->pSeqdesc( pModel->GetSequence() ).pszLabel() );
  505. RegWriteString( hModelKey, "overlaySequence0", hdr->pSeqdesc( pModel->GetOverlaySequence( 0 ) ).pszLabel() );
  506. RegWriteFloat( hModelKey, "overlayWeight0", pModel->GetOverlaySequenceWeight( 0 ) );
  507. RegWriteString( hModelKey, "overlaySequence1", hdr->pSeqdesc( pModel->GetOverlaySequence( 1 ) ).pszLabel() );
  508. RegWriteFloat( hModelKey, "overlayWeight1", pModel->GetOverlaySequenceWeight( 1 ) );
  509. RegWriteString( hModelKey, "overlaySequence2", hdr->pSeqdesc( pModel->GetOverlaySequence( 2 ) ).pszLabel() );
  510. RegWriteFloat( hModelKey, "overlayWeight2", pModel->GetOverlaySequenceWeight( 2 ) );
  511. RegWriteString( hModelKey, "overlaySequence3", hdr->pSeqdesc( pModel->GetOverlaySequence( 3 ) ).pszLabel() );
  512. RegWriteFloat( hModelKey, "overlayWeight3", pModel->GetOverlaySequenceWeight( 3 ) );
  513. RegWriteFloat( hModelKey, "speedscale", g_viewerSettings.speedScale );
  514. RegWriteInt( hModelKey, "viewermode", g_viewerSettings.application_mode );
  515. RegWriteInt( hModelKey, "thumbnailsize", g_viewerSettings.thumbnailsize );
  516. RegWriteInt( hModelKey, "thumbnailsizeanim", g_viewerSettings.thumbnailsizeanim );
  517. RegWriteInt( hModelKey, "speechapiindex", g_viewerSettings.speechapiindex );
  518. RegWriteInt( hModelKey, "cclanguageid", g_viewerSettings.cclanguageid );
  519. RegWriteInt( hModelKey, "showground", g_viewerSettings.showGround );
  520. RegWriteInt( hModelKey, "showbackground", g_viewerSettings.showBackground );
  521. RegWriteInt( hModelKey, "showshadow", g_viewerSettings.showShadow );
  522. RegWriteInt( hModelKey, "showillumpos", g_viewerSettings.showIllumPosition );
  523. RegWriteInt( hModelKey, "enablenormalmapping", g_viewerSettings.enableNormalMapping );
  524. RegWriteInt( hModelKey, "enabledisplacementmapping", g_viewerSettings.enableDisplacementMapping );
  525. RegWriteInt( hModelKey, "playsounds", g_viewerSettings.playSounds );
  526. RegWriteInt( hModelKey, "showoriginaxis", g_viewerSettings.showOriginAxis );
  527. RegWriteFloat( hModelKey, "originaxislength", g_viewerSettings.originAxisLength );
  528. char merge_buffer[32];
  529. for ( int i = 0; i < HLMV_MAX_MERGED_MODELS; i++ )
  530. {
  531. Q_snprintf( merge_buffer, sizeof( merge_buffer ), "merge%d", i + 1 );
  532. RegWriteString( hModelKey, merge_buffer, g_viewerSettings.mergeModelFile[i] );
  533. }
  534. return true;
  535. }
  536. bool SaveViewerRootSettings( void )
  537. {
  538. LONG lResult; // Registry function result code
  539. DWORD dwDisposition; // Type of key opening event
  540. HKEY hRootKey;
  541. lResult = RegViewerRootKey( &hRootKey, &dwDisposition);
  542. if (lResult != ERROR_SUCCESS) // Failure
  543. return false;
  544. RegWriteInt( hRootKey, "renderxpos", g_viewerSettings.xpos );
  545. RegWriteInt( hRootKey, "renderypos", g_viewerSettings.ypos );
  546. RegWriteInt( hRootKey, "renderwidth", g_viewerSettings.width );
  547. RegWriteInt( hRootKey, "renderheight", g_viewerSettings.height );
  548. RegWriteInt( hRootKey, "faceposerToolsDriveMouth", g_viewerSettings.faceposerToolsDriveMouth ? 1 : 0 );
  549. RegWriteInt( hRootKey, "showHidden", g_viewerSettings.showHidden ? 1 : 0 );
  550. RegWriteInt( hRootKey, "showActivities", g_viewerSettings.showActivities ? 1 : 0 );
  551. RegWriteInt( hRootKey, "showSequenceIndices", g_viewerSettings.showSequenceIndices ? 1 : 0 );
  552. RegWriteInt( hRootKey, "sortSequences", g_viewerSettings.sortSequences ? 1 : 0 );
  553. RegWriteInt( hRootKey, "dotaMode", g_viewerSettings.dotaMode ? 1 : 0 );
  554. return true;
  555. }
  556. bool SaveCompileQCPathSettings( void )
  557. {
  558. LONG lResult; // Registry function result code
  559. DWORD dwDisposition; // Type of key opening event
  560. HKEY hQCPathsKey;
  561. lResult = RegViewerSettingsKey( "qc_path_records", &hQCPathsKey, &dwDisposition);
  562. if (lResult != ERROR_SUCCESS) // Failure
  563. return false;
  564. char szKeyName[MAX_PATH];
  565. for ( int i=0; i<MAX_NUM_QCPATH_RECORDS; i++ )
  566. {
  567. V_sprintf_safe( szKeyName, "qcpath%i", i);
  568. if ( i < g_QCPathRecords.Count() )
  569. {
  570. RegWriteString( hQCPathsKey, szKeyName, g_QCPathRecords[i].szAbsPath );
  571. }
  572. else
  573. {
  574. RegDeleteValue( hQCPathsKey, szKeyName );
  575. }
  576. }
  577. return true;
  578. }
  579. bool LoadCompileQCPathSettings( void )
  580. {
  581. LONG lResult; // Registry function result code
  582. DWORD dwDisposition; // Type of key opening event
  583. HKEY hQCPathsKey;
  584. lResult = RegViewerSettingsKey( "qc_path_records", &hQCPathsKey, &dwDisposition);
  585. if (lResult != ERROR_SUCCESS) // Failure
  586. return false;
  587. // First time, just set to Valve default
  588. if (dwDisposition == REG_CREATED_NEW_KEY)
  589. {
  590. return false;
  591. }
  592. g_QCPathRecords.RemoveAll();
  593. char szKeyName[MAX_PATH];
  594. char szKeyValue[MAX_PATH];
  595. for ( int i=0; i<MAX_NUM_QCPATH_RECORDS; i++ )
  596. {
  597. V_sprintf_safe( szKeyName, "qcpath%i", i);
  598. if ( RegReadString( hQCPathsKey, szKeyName, szKeyValue, sizeof(szKeyValue) ) )
  599. {
  600. g_QCPathRecords[g_QCPathRecords.AddToTail()].InitFromAbsPath( szKeyValue );
  601. }
  602. }
  603. return true;
  604. }