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.

1512 lines
35 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: LCD support
  4. //
  5. //=====================================================================================//
  6. #if defined( WIN32 ) && !defined( _GAMECONSOLE )
  7. #include <windows.h>
  8. #endif
  9. #include "cbase.h"
  10. #ifdef POSIX
  11. #define HICON int
  12. const int DT_LEFT = 1;
  13. const int DT_CENTER = 2;
  14. const int DT_RIGHT = 3;
  15. #endif
  16. #include "hud_lcd.h"
  17. #include "vgui_controls/Controls.h"
  18. #include "vgui_controls/SectionedListPanel.h"
  19. #include "vgui/ISurface.h"
  20. #include "vgui/IScheme.h"
  21. #include "vgui/IVGui.h"
  22. #include "vgui/ILocalize.h"
  23. #include "vgui/IPanel.h"
  24. #include "c_team.h"
  25. #include "c_playerresource.h"
  26. #include "filesystem.h"
  27. #include "g15/ig15.h"
  28. #include "tier0/icommandline.h"
  29. #if defined( _X360 )
  30. #include "xbox/xbox_win32stubs.h"
  31. #endif
  32. // memdbgon must be the last include file in a .cpp file!!!
  33. #include "tier0/memdbgon.h"
  34. #define G15_RESOURCE_FILE "resource/g15.res"
  35. #define G15_MODULE_NAME "bin/g15.dll"
  36. #define SMALL_ITEM_HEIGHT 10
  37. #define G15_DEFAULT_MAX_CHAT_HISTORY 4
  38. CLCD gLCD;
  39. IHudLCD *hudlcd = IsGameConsole() ? NULL : &gLCD;
  40. CON_COMMAND( g15_reload, "Reloads the Logitech G-15 Keyboard configs." )
  41. {
  42. if ( !CommandLine()->FindParm( "-g15" ) )
  43. {
  44. Msg( "Must run with -g15 to enable support for the LCD Keyboard\n" );
  45. return;
  46. }
  47. gLCD.Reload();
  48. }
  49. CON_COMMAND( g15_dumpplayer, "Spew player data." )
  50. {
  51. if ( !CommandLine()->FindParm( "-g15" ) )
  52. {
  53. Msg( "Must run with -g15 to enable support for the LCD Keyboard\n" );
  54. return;
  55. }
  56. gLCD.DumpPlayer();
  57. }
  58. static ConVar g15_update_msec( "g15_update_msec", "250", FCVAR_ARCHIVE, "Logitech G-15 Keyboard update interval." );
  59. void CLCDItem::Wipe( IG15 *lcd )
  60. {
  61. for ( int i = 0; i < m_Children.Count(); ++i )
  62. {
  63. if ( m_Children[ i ]->m_Handle )
  64. {
  65. lcd->RemoveAndDestroyObject( m_Children[ i ]->m_Handle );
  66. }
  67. m_Children[ i ]->Wipe( lcd );
  68. delete m_Children[ i ];
  69. }
  70. m_Children.Purge();
  71. }
  72. void CLCDItemAggregate::Create( IG15 *lcd )
  73. {
  74. // Nothing
  75. }
  76. void CLCDItemAggregate::Wipe( IG15 *lcd )
  77. {
  78. BaseClass::Wipe( lcd );
  79. for ( int i = 0; i < m_Definition.Count(); ++i )
  80. {
  81. m_Definition[ i ]->Wipe( lcd );
  82. delete m_Definition[ i ];
  83. }
  84. m_Definition.Purge();
  85. }
  86. void CLCDItemAggregate::WipeChildrenOnly( IG15 *lcd )
  87. {
  88. BaseClass::Wipe( lcd );
  89. }
  90. void CLCDItemIcon::Create( IG15 *lcd )
  91. {
  92. #ifdef WIN32
  93. m_Handle = lcd->AddIcon( (HICON)m_icon, w, h );
  94. #else
  95. m_Handle = lcd->AddIcon( (void *)m_icon, w, h );
  96. #endif
  97. lcd->SetOrigin( m_Handle, x, y );
  98. lcd->SetVisible( m_Handle, false );
  99. }
  100. void CLCDItemText::Create( IG15 *lcd )
  101. {
  102. m_Handle = lcd->AddText( G15_STATIC_TEXT, (G15TextSize)m_iSize, m_iAlign, w );
  103. lcd->SetOrigin( m_Handle, x, y );
  104. lcd->SetText( m_Handle, m_OriginalText );
  105. lcd->SetVisible( m_Handle, false );
  106. }
  107. ///-----------------------------------------------------------------------------
  108. /// Constructor
  109. ///-----------------------------------------------------------------------------
  110. CLCD::CLCD( void )
  111. : m_lcd( NULL ),
  112. m_nCurrentPage( 0 ),
  113. m_nSubPage( 0 ),
  114. m_bHadPlayer( false ),
  115. m_dwNextUpdateTime( 0u ),
  116. m_nMaxChatHistory( G15_DEFAULT_MAX_CHAT_HISTORY ),
  117. m_pG15Module( 0 ),
  118. m_G15Factory( 0 )
  119. {
  120. m_Size[ 0 ] = m_Size[ 1 ] = 0;
  121. }
  122. ///-----------------------------------------------------------------------------
  123. /// Destructor
  124. ///-----------------------------------------------------------------------------
  125. CLCD::~CLCD( void )
  126. {
  127. }
  128. void CLCD::Reload()
  129. {
  130. Shutdown();
  131. Msg( "Reloading G15 config\n" );
  132. Init();
  133. }
  134. ///------------------------------------------------------------------------------
  135. /// Initializes the LCD device, and sets up the text handles
  136. ///------------------------------------------------------------------------------
  137. void CLCD::Init( void )
  138. {
  139. if ( !CommandLine()->FindParm( "-g15" ) )
  140. return;
  141. if ( m_lcd )
  142. return;
  143. m_pG15Module = Sys_LoadModule( G15_MODULE_NAME );
  144. if ( !m_pG15Module )
  145. {
  146. return;
  147. }
  148. m_G15Factory = Sys_GetFactory( m_pG15Module );
  149. if ( !m_G15Factory )
  150. {
  151. Shutdown();
  152. return;
  153. }
  154. m_lcd = reinterpret_cast< IG15 * >( m_G15Factory( G15_INTERFACE_VERSION, NULL ) );
  155. if ( !m_lcd )
  156. {
  157. Shutdown();
  158. return;
  159. }
  160. m_lcd->GetLCDSize( m_Size[ 0 ], m_Size[ 1 ] );
  161. m_nCurrentPage = 0;
  162. m_nSubPage = 0;
  163. m_TextSizes.Insert( "small", G15_SMALL );
  164. m_TextSizes.Insert( "medium", G15_MEDIUM );
  165. m_TextSizes.Insert( "big", G15_BIG );
  166. m_TextAlignments.Insert( "left", DT_LEFT );
  167. m_TextAlignments.Insert( "center", DT_CENTER );
  168. m_TextAlignments.Insert( "right", DT_RIGHT );
  169. KeyValues *kv = new KeyValues( "G15" );
  170. if ( kv->LoadFromFile( filesystem, G15_RESOURCE_FILE, "MOD" ) )
  171. {
  172. char const *title = kv->GetString( "game", "Source Engine" );
  173. m_nMaxChatHistory = clamp( 1, kv->GetInt( "chatlines", m_nMaxChatHistory ), 64 );
  174. Assert( title );
  175. m_Title = title;
  176. m_lcd->Init( m_Title.String() );
  177. for ( KeyValues *sub = kv->GetFirstSubKey(); sub; sub = sub->GetNextKey() )
  178. {
  179. char const *keyName = sub->GetName();
  180. if ( !Q_stricmp( keyName, "game" ) )
  181. {
  182. // Handled above!!!
  183. }
  184. else if ( !Q_stricmp( keyName, "icons" ) )
  185. {
  186. ParseIconMappings( sub );
  187. }
  188. else if ( !Q_stricmp( keyName, "replace" ) )
  189. {
  190. ParseReplacements( sub );
  191. }
  192. else if ( !Q_stricmp( keyName, "page" ) )
  193. {
  194. ParsePage( sub );
  195. }
  196. }
  197. }
  198. kv->deleteThis();
  199. UpdateChat();
  200. Msg( "Logitech LCD Keyboard initialized\n" );
  201. }
  202. ///--------------------------------------------------------------------------
  203. /// Destroys the local EZ LCD Object
  204. ///--------------------------------------------------------------------------
  205. void CLCD::Shutdown( void )
  206. {
  207. for ( int i = 0; i < m_Pages.Count(); ++i )
  208. {
  209. CLCDPage *page = m_Pages[ i ];
  210. page->Wipe( m_lcd );
  211. delete page;
  212. }
  213. m_Pages.Purge();
  214. if ( m_lcd )
  215. {
  216. m_lcd->Shutdown();
  217. m_lcd = NULL;
  218. }
  219. m_TextSizes.Purge();
  220. m_TextAlignments.Purge();
  221. m_GlobalStats.Purge();
  222. m_G15Factory = 0;
  223. if ( m_pG15Module )
  224. {
  225. Sys_UnloadModule( m_pG15Module );
  226. m_pG15Module = 0;
  227. }
  228. }
  229. int CLCD::FindTitlePage()
  230. {
  231. for ( int i = 0; i < m_Pages.Count(); ++i )
  232. {
  233. if ( m_Pages[ i ]->m_bTitlePage )
  234. return i;
  235. }
  236. return -1;
  237. }
  238. bool CLCD::IsPageValid( int currentPage, C_BasePlayer *player )
  239. {
  240. if ( m_Pages[ currentPage ]->m_bTitlePage && player )
  241. return false;
  242. if ( m_Pages[ currentPage ]->m_bRequiresPlayer && !player )
  243. return false;
  244. return true;
  245. }
  246. ///---------------------------------------------------------------------
  247. /// Update routine
  248. ///---------------------------------------------------------------------
  249. void CLCD::Update( void )
  250. {
  251. if ( !m_lcd )
  252. return ;
  253. C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
  254. bool hasplayer = player ? true : false;
  255. bool changed = hasplayer != m_bHadPlayer;
  256. m_bHadPlayer = hasplayer;
  257. int pageCount = m_Pages.Count();
  258. int prevPage = m_nCurrentPage;
  259. if ( pageCount > 0 )
  260. {
  261. bool force = false;
  262. if ( changed && hasplayer )
  263. {
  264. force = true;
  265. m_nCurrentPage = 0;
  266. m_nSubPage = 0;
  267. }
  268. if ( !IsPageValid( m_nCurrentPage, player ) )
  269. {
  270. force = true;
  271. }
  272. if ( m_lcd->ButtonTriggered( G15_BUTTON_1 ) || force )
  273. {
  274. m_nSubPage = 0;
  275. for ( int i = 0; i < pageCount; ++i )
  276. {
  277. m_nCurrentPage = ( m_nCurrentPage + 1 ) % pageCount;
  278. if ( !IsPageValid( m_nCurrentPage, player ) )
  279. continue;
  280. break;
  281. }
  282. }
  283. if ( m_lcd->ButtonTriggered( G15_BUTTON_2 ) )
  284. {
  285. int pc = m_Pages[ m_nCurrentPage ]->m_nSubPageCount;
  286. m_nSubPage = ( m_nSubPage + 1 ) % pc;
  287. }
  288. }
  289. else
  290. {
  291. m_nCurrentPage = -1;
  292. m_nSubPage = 0;
  293. }
  294. bool pageChanged = prevPage != m_nCurrentPage;
  295. unsigned int dwCurTime = (unsigned int)( 1000.0 * gpGlobals->realtime );
  296. if ( m_lcd->IsConnected() )
  297. {
  298. if ( dwCurTime >= m_dwNextUpdateTime || pageChanged )
  299. {
  300. m_dwNextUpdateTime = dwCurTime + g15_update_msec.GetInt();
  301. DisplayCurrentPage( dwCurTime );
  302. }
  303. }
  304. m_lcd->UpdateLCD( dwCurTime );
  305. }
  306. ///--------------------------------------------------------------------------
  307. ///
  308. ///--------------------------------------------------------------------------
  309. bool CLCD::IsConnected( void ) const
  310. {
  311. return m_lcd ? m_lcd->IsConnected() : false;
  312. }
  313. void CLCD::ShowItems_R( CLCDPage *page, unsigned int dwCurTime, CUtlVector< CLCDItem * >& list, bool bShowItems )
  314. {
  315. int itemCount = list.Count();
  316. for ( int j = 0; j < itemCount; ++j )
  317. {
  318. CLCDItem *item = list[ j ];
  319. if ( !item->m_bActive )
  320. continue;
  321. if ( bShowItems )
  322. {
  323. switch ( item->m_Type )
  324. {
  325. default:
  326. break;
  327. case LCDITEM_TEXT:
  328. {
  329. CLCDItemText *txt = static_cast< CLCDItemText * >( item );
  330. if ( txt )
  331. {
  332. // Need to build updated text
  333. CUtlString updated;
  334. CUtlString str = txt->m_OriginalText;
  335. BuildUpdatedText( str.String(), updated );
  336. DoGlobalReplacements( updated );
  337. ReduceParentheses( updated );
  338. m_lcd->SetText( item->m_Handle, updated.String() );
  339. }
  340. }
  341. break;
  342. case LCDITEM_ICON:
  343. {
  344. CLCDItemIcon *icon = static_cast< CLCDItemIcon * >( item );
  345. if ( icon )
  346. {
  347. // Need to build updated text
  348. CUtlString updated;
  349. CUtlString str = icon->m_IconName;
  350. BuildUpdatedText( str.String(), updated );
  351. DoGlobalReplacements( updated );
  352. ReduceParentheses( updated );
  353. int idx = m_Icons.Find( updated.String() );
  354. if ( idx != m_Icons.InvalidIndex() )
  355. {
  356. icon->m_icon = (void *)m_Icons[ idx ].m_handle;
  357. }
  358. // Recreate
  359. if ( icon->m_Handle )
  360. {
  361. m_lcd->RemoveAndDestroyObject( icon->m_Handle );
  362. icon->m_Handle = 0;
  363. }
  364. icon->Create( m_lcd );
  365. }
  366. }
  367. break;
  368. case LCDITEM_AGGREGATE:
  369. {
  370. CLCDItemAggregate *ag = static_cast< CLCDItemAggregate * >( item );
  371. if ( ag->m_dwNextUpdateTime > dwCurTime )
  372. break;
  373. // FIXME: encode update interval in text file
  374. ag->m_dwNextUpdateTime = dwCurTime + 1000;
  375. // Blow away current data
  376. ag->WipeChildrenOnly( m_lcd );
  377. CUtlVector< int > validIndices;
  378. char prefix[ 256 ];
  379. char altprefix[ 256 ];
  380. prefix[ 0 ] = 0;
  381. altprefix[ 0 ] = 0;
  382. int curx = ag->x;
  383. int cury = ag->y;
  384. switch ( ag->m_AggType )
  385. {
  386. default:
  387. Assert( 0 );
  388. break;
  389. case AGGTYPE_PERPLAYER:
  390. // Add all players into list
  391. {
  392. for ( int pl = 1; pl <= gpGlobals->maxClients; ++pl )
  393. {
  394. if ( g_PR && g_PR->IsConnected( pl ) )
  395. {
  396. validIndices.AddToTail( pl );
  397. }
  398. }
  399. Q_strncpy( prefix, "(playerindex)", sizeof( prefix ) );
  400. Q_strncpy( altprefix, "(playerindexplusone)", sizeof( altprefix ) );
  401. }
  402. break;
  403. case AGGTYPE_PERTEAM:
  404. {
  405. C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
  406. if ( local )
  407. {
  408. for ( int pl = 1; pl <= gpGlobals->maxClients; ++pl )
  409. {
  410. if ( g_PR && g_PR->IsConnected( pl ) && local->GetTeamNumber() == g_PR->GetTeam( pl ) )
  411. {
  412. validIndices.AddToTail( pl );
  413. }
  414. }
  415. }
  416. Q_strncpy( prefix, "(playerindex)", sizeof( prefix ) );
  417. Q_strncpy( altprefix, "(playerindexplusone)", sizeof( altprefix ) );
  418. }
  419. break;
  420. }
  421. int subPage = 0;
  422. int spItems = 0;
  423. int ecount = validIndices.Count();
  424. for ( int e = 0; e < ecount; ++e )
  425. {
  426. // Now fixup any strings
  427. int index = validIndices[ e ];
  428. char s1[ 512 ], s2[ 512 ];
  429. Q_snprintf( s1, sizeof( s1 ), "%d", index );
  430. Q_snprintf( s2, sizeof( s2 ), "%d", index + 1 );
  431. // Now replace "playerindex" with the index as needed
  432. for( int r = 0; r < ag->m_Definition.Count(); ++r )
  433. {
  434. CLCDItem *newItem = NULL;
  435. CLCDItem *item = ag->m_Definition[ r ];
  436. switch ( item->m_Type )
  437. {
  438. default:
  439. break;
  440. case LCDITEM_TEXT:
  441. {
  442. CLCDItemText *text = static_cast< CLCDItemText * >( item );
  443. CUtlString s;
  444. s = text->m_OriginalText;
  445. Replace( s, prefix, s1 );
  446. Replace( s, altprefix, s2 );
  447. char itemNumber[ 32 ];
  448. Q_snprintf( itemNumber, sizeof( itemNumber ), "%d", e +1 );
  449. Replace( s, "(itemnumber)", itemNumber );
  450. DoGlobalReplacements( s );
  451. // ReduceParentheses( s );
  452. // text->m_OriginalText = s;
  453. CLCDItemText *copy = static_cast< CLCDItemText * >( page->Alloc( item->m_Type ) );
  454. *copy = *text;
  455. copy->m_bActive = true;
  456. copy->m_OriginalText = s;
  457. copy->Create( m_lcd );
  458. m_lcd->SetOrigin( copy->m_Handle, curx + copy->x, cury + copy->y );
  459. newItem = copy;
  460. }
  461. break;
  462. case LCDITEM_ICON:
  463. {
  464. CLCDItemIcon *icon = static_cast< CLCDItemIcon * >( item );
  465. CLCDItemIcon *copy = static_cast< CLCDItemIcon * >( page->Alloc( item->m_Type ) );
  466. *copy = *icon;
  467. copy->m_bActive = true;
  468. copy->Create( m_lcd );
  469. m_lcd->SetOrigin( copy->m_Handle, curx + copy->x, cury + copy->y );
  470. newItem = copy;
  471. }
  472. break;
  473. }
  474. if ( newItem )
  475. {
  476. ++spItems;
  477. newItem->m_nSubPage = subPage;
  478. ag->m_Children.AddToTail( newItem );
  479. }
  480. }
  481. cury += ag->m_yincrement;
  482. if ( cury + SMALL_ITEM_HEIGHT > m_Size[ 1 ] )
  483. {
  484. spItems = 0;
  485. ++subPage;
  486. cury = ag->y;
  487. }
  488. }
  489. if ( spItems > 0 )
  490. {
  491. page->m_nSubPageCount = subPage + 1;
  492. }
  493. else
  494. {
  495. // We thought we needed a new page, but didn't actually use it
  496. page->m_nSubPageCount = subPage;
  497. }
  498. }
  499. }
  500. }
  501. m_lcd->SetVisible( item->m_Handle, bShowItems && ( ( item->m_nSubPage == -1 ) || item->m_nSubPage == m_nSubPage ) );
  502. ShowItems_R( page, dwCurTime, item->m_Children, bShowItems );
  503. }
  504. }
  505. void CLCD::DisplayCurrentPage( unsigned int dwCurTime )
  506. {
  507. int pageCount = m_Pages.Count();
  508. for ( int i = 0; i < pageCount; ++i )
  509. {
  510. bool bShowItems = ( i == m_nCurrentPage ) ? true : false;
  511. CLCDPage* page = m_Pages[ i ];
  512. ShowItems_R( page, dwCurTime, page->m_Children, bShowItems );
  513. }
  514. }
  515. CLCDItemIcon *CLCD::ParseItemIcon( CLCDPage *page, bool bCreateHandles, KeyValues *sub )
  516. {
  517. CLCDItemIcon *item = static_cast< CLCDItemIcon * >( page->Alloc( LCDITEM_ICON ) );
  518. item->m_IconName = sub->GetString( "name", "" );
  519. item->m_nSubPage = sub->GetInt( "header", 0 ) ? -1 : page->m_nSubPageCount - 1;
  520. item->w = sub->GetInt( "w", 24 );
  521. item->h = sub->GetInt( "h", 24 );
  522. item->x = sub->GetInt( "x", 0 );
  523. item->y = sub->GetInt( "y", 0 );
  524. int idx = m_Icons.Find( item->m_IconName.String() );
  525. item->m_icon = 0;
  526. if ( idx != m_Icons.InvalidIndex() )
  527. {
  528. item->m_icon = (void *)m_Icons[ idx ].m_handle;
  529. }
  530. if ( bCreateHandles )
  531. {
  532. item->Create( m_lcd );
  533. }
  534. return item;
  535. }
  536. CLCDItemText *CLCD::ParseItemText( CLCDPage *page, bool bCreateHandles, KeyValues *sub )
  537. {
  538. CLCDItemText *item = static_cast< CLCDItemText * >( page->Alloc( LCDITEM_TEXT ) );
  539. const char *initialText = sub->GetString( "text", "" );
  540. item->m_bHasWildcard = Q_strstr( initialText, "%" ) ? true : false;
  541. item->m_nSubPage = sub->GetInt( "header", 0 ) ? -1 : page->m_nSubPageCount - 1;
  542. item->w = sub->GetInt( "w", 150 );
  543. item->x = sub->GetInt( "x", 0 );
  544. item->y = sub->GetInt( "y", 0 );
  545. const char *sizeStr = sub->GetString( "size", "small" );
  546. item->m_iSize = G15_SMALL;
  547. int iFound = m_TextSizes.Find( sizeStr );
  548. if ( iFound != m_TextSizes.InvalidIndex() )
  549. {
  550. item->m_iSize = m_TextSizes[ iFound ];
  551. }
  552. const char *alignStr = sub->GetString( "align", "left" );
  553. item->m_iAlign = DT_LEFT;
  554. iFound = m_TextAlignments.Find( alignStr );
  555. if ( iFound != m_TextAlignments.InvalidIndex() )
  556. {
  557. item->m_iAlign = m_TextAlignments[ iFound ];
  558. }
  559. item->m_OriginalText = initialText;
  560. if ( bCreateHandles )
  561. {
  562. item->Create( m_lcd );
  563. }
  564. return item;
  565. }
  566. void CLCD::ParseItems_R( CLCDPage *page, bool bCreateHandles, KeyValues *kv, CUtlVector< CLCDItem * >& list )
  567. {
  568. for ( KeyValues *sub = kv->GetFirstSubKey(); sub; sub = sub->GetNextKey() )
  569. {
  570. char const *keyName = sub->GetName();
  571. if ( !Q_stricmp( keyName, "iterate_players" ) ||
  572. !Q_stricmp( keyName, "iterate_team" ) )
  573. {
  574. int aggType = AGGTYPE_UNKNOWN;
  575. if ( !Q_stricmp( keyName, "iterate_players" ) )
  576. {
  577. aggType = AGGTYPE_PERPLAYER;
  578. }
  579. else if ( !Q_stricmp( keyName, "iterate_team" ) )
  580. {
  581. aggType = AGGTYPE_PERTEAM;
  582. }
  583. // Now we parse the items out as we generally would
  584. CLCDItemAggregate *item = static_cast< CLCDItemAggregate * >( page->Alloc( LCDITEM_AGGREGATE ) );
  585. item->m_AggType = aggType;
  586. item->x = sub->GetInt( "x", 0 );
  587. item->y = sub->GetInt( "y", 0 );
  588. item->m_yincrement = sub->GetInt( "y_increment", 10 );
  589. // Parse the definition
  590. ParseItems_R( page, false, sub, item->m_Definition );
  591. // Add the definition items as "inactive" items to the scene (so they get destroyed)
  592. for ( int i = 0; i < item->m_Definition.Count(); ++i )
  593. {
  594. CLCDItem *pItem = item->m_Definition[ i ];
  595. pItem->m_bActive = false;
  596. }
  597. list.AddToTail( item );
  598. }
  599. else if ( !Q_stricmp( keyName, "static_icon" ) )
  600. {
  601. CLCDItemIcon *item = ParseItemIcon( page, true, sub );
  602. Assert( item );
  603. list.AddToTail(item );
  604. }
  605. else if ( !Q_stricmp( keyName, "static_text" ) )
  606. {
  607. CLCDItemText *item = ParseItemText( page, true, sub );
  608. Assert( item );
  609. list.AddToTail( item );
  610. }
  611. else if ( !Q_stricmp( keyName, "newsubpage" ) )
  612. {
  613. // Add to new subpage
  614. ++page->m_nSubPageCount;
  615. }
  616. else
  617. {
  618. // Skip unknown stuff
  619. continue;
  620. }
  621. }
  622. }
  623. void CLCD::ParsePage( KeyValues *kv )
  624. {
  625. CLCDPage *newPage = new CLCDPage();
  626. m_Pages.AddToTail( newPage );
  627. newPage->m_bTitlePage = kv->GetBool( "titlepage", false );
  628. newPage->m_bRequiresPlayer = kv->GetBool( "requiresplayer", false );
  629. ParseItems_R( newPage, true, kv, newPage->m_Children );
  630. }
  631. void CLCD::ParseIconMappings( KeyValues *kv )
  632. {
  633. for ( KeyValues *icon = kv->GetFirstSubKey(); icon; icon = icon->GetNextKey() )
  634. {
  635. IconInfo_t info;
  636. HICON hIcon = 0;
  637. char const *name = icon->GetName();
  638. char fullpath[ 512 ];
  639. filesystem->RelativePathToFullPath( icon->GetString(), "GAME", fullpath, sizeof( fullpath ) );
  640. #ifdef WIN32
  641. hIcon = (HICON)::LoadImageA( NULL, fullpath, IMAGE_ICON, 32, 32, LR_LOADFROMFILE );
  642. #else
  643. hIcon = 0;
  644. #endif
  645. info.m_handle = (void *)hIcon;
  646. m_Icons.Insert( name, info );
  647. }
  648. }
  649. //-----------------------------------------------------------------------------
  650. // Purpose: Simply dumps all data fields in object
  651. //-----------------------------------------------------------------------------
  652. class CDescribeData
  653. {
  654. public:
  655. explicit CDescribeData( const byte *src );
  656. void DescribeShort( const datamap_t *dmap, const typedescription_t *pField, const short *invalue, int count );
  657. void DescribeInt( const datamap_t *dmap, const typedescription_t *pField, const int *invalue, int count );
  658. void DescribeBool( const datamap_t *dmap, const typedescription_t *pField, const bool *invalue, int count );
  659. void DescribeFloat( const datamap_t *dmap, const typedescription_t *pField, const float *invalue, int count );
  660. void DescribeSimpleString( const datamap_t *dmap, const typedescription_t *pField, const char *indata, int length );
  661. void DescribeString( const datamap_t *dmap, const typedescription_t *pField, const string_t *instring, int count );
  662. void DescribeVector( const datamap_t *dmap, const typedescription_t *pField, const Vector *inValue, int count );
  663. void DescribeColor( const datamap_t *dmap, const typedescription_t *pField, const Color *invalue, int count );
  664. void DumpDescription( datamap_t *pMap );
  665. private:
  666. void DescribeFields( const datamap_t *pMap, int nPredictionCopyType );
  667. const byte *m_pSrc;
  668. int m_nSrcOffsetIndex;
  669. void Describe( const datamap_t *dmap, const typedescription_t *pField, const char *fmt, ... );
  670. };
  671. CDescribeData::CDescribeData( const byte *src )
  672. {
  673. m_pSrc = src;
  674. m_nSrcOffsetIndex = TD_OFFSET_NORMAL;
  675. }
  676. static typedescription_t *FindByName( datamap_t *pMap, char const *fn )
  677. {
  678. while ( pMap )
  679. {
  680. for ( int i = 0; i < pMap->dataNumFields; i++ )
  681. {
  682. typedescription_t *current = &pMap->dataDesc[ i ];
  683. if ( !current->fieldName )
  684. continue;
  685. if ( !Q_stricmp( current->fieldName, fn ) )
  686. return current;
  687. }
  688. pMap = pMap->baseMap;
  689. }
  690. return NULL;
  691. }
  692. static typedescription_t *FindField( datamap_t *pMap, char const *relativePath )
  693. {
  694. if ( !Q_strstr( relativePath, "." ) )
  695. {
  696. // Simple case, just look up field name
  697. return FindByName( pMap, relativePath );
  698. }
  699. // Complex case
  700. Assert( 0 );
  701. return NULL;
  702. }
  703. //-----------------------------------------------------------------------------
  704. // Purpose:
  705. // Input : *fmt -
  706. // ... -
  707. //-----------------------------------------------------------------------------
  708. void CDescribeData::Describe( const datamap_t *dmap, const typedescription_t *pField, const char *fmt, ... )
  709. {
  710. const char *fieldname;
  711. fieldname = pField->fieldName ? pField->fieldName : "null";
  712. va_list argptr;
  713. char data[ 4096 ];
  714. int len;
  715. va_start(argptr, fmt);
  716. len = Q_vsnprintf(data, sizeof( data ), fmt, argptr);
  717. va_end(argptr);
  718. Msg( "%s::%s%s",
  719. dmap->dataClassName,
  720. fieldname,
  721. data );
  722. }
  723. //-----------------------------------------------------------------------------
  724. // Purpose:
  725. // Input : size -
  726. // *outdata -
  727. // *indata -
  728. //-----------------------------------------------------------------------------
  729. void CDescribeData::DescribeSimpleString( const datamap_t *dmap, const typedescription_t *pField, char const *invalue, int count )
  730. {
  731. Describe( dmap, pField, "%s\n", invalue ? invalue : "" );
  732. }
  733. void CDescribeData::DescribeShort( const datamap_t *dmap, const typedescription_t *pField, const short *invalue, int count )
  734. {
  735. for ( int i = 0; i < count; ++i )
  736. {
  737. if ( count == 1 )
  738. {
  739. Describe( dmap, pField, " short (%i)\n", (int)(invalue[i]) );
  740. }
  741. else
  742. {
  743. Describe( dmap, pField, "[%i] short (%i)\n", i, (int)(invalue[i]) );
  744. }
  745. }
  746. }
  747. void CDescribeData::DescribeInt( const datamap_t *dmap, const typedescription_t *pField, const int *invalue, int count )
  748. {
  749. for ( int i = 0; i < count; ++i )
  750. {
  751. if ( count == 1 )
  752. {
  753. Describe( dmap, pField, " integer (%i)\n", invalue[i] );
  754. }
  755. else
  756. {
  757. Describe( dmap, pField, "[%i] integer (%i)\n", i, invalue[i] );
  758. }
  759. }
  760. }
  761. void CDescribeData::DescribeBool( const datamap_t *dmap, const typedescription_t *pField, const bool *invalue, int count )
  762. {
  763. for ( int i = 0; i < count; ++i )
  764. {
  765. if ( count == 1 )
  766. {
  767. Describe( dmap, pField, " bool (%s)\n", (invalue[i]) ? "true" : "false" );
  768. }
  769. else
  770. {
  771. Describe( dmap, pField, "[%i] bool (%s)\n", i, (invalue[i]) ? "true" : "false" );
  772. }
  773. }
  774. }
  775. void CDescribeData::DescribeFloat( const datamap_t *dmap, const typedescription_t *pField, const float *invalue, int count )
  776. {
  777. for ( int i = 0; i < count; ++i )
  778. {
  779. if ( count == 1 )
  780. {
  781. Describe( dmap, pField, " float (%f)\n", invalue[ i ] );
  782. }
  783. else
  784. {
  785. Describe( dmap, pField, "[%i] float (%f)\n", i, invalue[ i ] );
  786. }
  787. }
  788. }
  789. void CDescribeData::DescribeString( const datamap_t *dmap, const typedescription_t *pField, const string_t *instring, int count )
  790. {
  791. for ( int i = 0; i < count; ++i )
  792. {
  793. if ( count == 1 )
  794. {
  795. Describe( dmap, pField, " string (%s)\n", instring[ i ] ? instring[ i ] : "" );
  796. }
  797. else
  798. {
  799. Describe( dmap, pField, "[%i] string (%s)\n", i, instring[ i ] ? instring[ i ] : "" );
  800. }
  801. }
  802. }
  803. void CDescribeData::DescribeColor( const datamap_t *dmap, const typedescription_t *pField, const Color *invalue, int count )
  804. {
  805. for ( int i = 0; i < count; ++i )
  806. {
  807. if ( count == 1 )
  808. {
  809. Describe( dmap, pField, " color (%i %i %i %i)\n", invalue[ i ].r(), invalue[ i ].g(), invalue[ i ].b(), invalue[ i ].a() );
  810. }
  811. else
  812. {
  813. Describe( dmap, pField, "[%i] color (%i %i %i %i)\n", i, invalue[ i ].r(), invalue[ i ].g(), invalue[ i ].b(), invalue[ i ].a() );
  814. }
  815. }
  816. }
  817. void CDescribeData::DescribeVector( const datamap_t *dmap, const typedescription_t *pField, const Vector *inValue, int count )
  818. {
  819. for ( int i = 0; i < count; ++i )
  820. {
  821. if ( count == 1 )
  822. {
  823. Describe( dmap, pField, " vector (%f %f %f)\n",
  824. inValue[i].x, inValue[i].y, inValue[i].z );
  825. }
  826. else
  827. {
  828. Describe( dmap, pField, "[%i] vector (%f %f %f)\n",
  829. i,
  830. inValue[i].x, inValue[i].y, inValue[i].z );
  831. }
  832. }
  833. }
  834. void CDescribeData::DescribeFields( const datamap_t *pRootMap, int nPredictionCopyType )
  835. {
  836. int i;
  837. int flags;
  838. int fieldOffsetSrc;
  839. int fieldSize;
  840. const flattenedoffsets_t &flat = pRootMap->m_pOptimizedDataMap->m_Info[ nPredictionCopyType ].m_Flat;
  841. int fieldCount = flat.m_Flattened.Count();
  842. for ( i = 0; i < fieldCount; i++ )
  843. {
  844. const typedescription_t *pField = &flat.m_Flattened[ i ];
  845. flags = pField->flags;
  846. // Skip this field
  847. if ( flags & FTYPEDESC_VIEW_NEVER )
  848. continue;
  849. fieldSize = pField->fieldSize;
  850. fieldOffsetSrc = pField->flatOffset[ TD_OFFSET_NORMAL ];
  851. const byte *pInputData = m_pSrc + fieldOffsetSrc;
  852. switch( pField->fieldType )
  853. {
  854. default:
  855. break;
  856. case FIELD_EMBEDDED:
  857. {
  858. Error( "FIELD_EMBEDDED in flattened field list!" );
  859. }
  860. break;
  861. case FIELD_FLOAT:
  862. DescribeFloat( pRootMap, pField, (float const *)pInputData, fieldSize );
  863. break;
  864. case FIELD_STRING:
  865. DescribeString( pRootMap, pField, (const string_t*)pInputData, fieldSize );
  866. break;
  867. case FIELD_VECTOR:
  868. DescribeVector( pRootMap, pField, (const Vector *)pInputData, fieldSize );
  869. break;
  870. case FIELD_COLOR32:
  871. DescribeColor( pRootMap, pField, (const Color *)pInputData, fieldSize );
  872. break;
  873. case FIELD_BOOLEAN:
  874. DescribeBool( pRootMap, pField, (bool const *)pInputData, fieldSize );
  875. break;
  876. case FIELD_INTEGER:
  877. DescribeInt( pRootMap, pField, (int const *)pInputData, fieldSize );
  878. break;
  879. case FIELD_SHORT:
  880. DescribeShort( pRootMap, pField, (short const *)pInputData, fieldSize );
  881. break;
  882. case FIELD_CHARACTER:
  883. DescribeSimpleString( pRootMap, pField, (const char *)pInputData, fieldSize );
  884. break;
  885. }
  886. }
  887. }
  888. void CDescribeData::DumpDescription( datamap_t *pMap )
  889. {
  890. CPredictionCopy::PrepareDataMap( pMap );
  891. for ( int pc = 0; pc < PC_COPYTYPE_COUNT; ++pc )
  892. {
  893. DescribeFields( pMap, pc );
  894. }
  895. }
  896. void CLCD::DumpPlayer()
  897. {
  898. C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
  899. if ( !player )
  900. return;
  901. Msg( "(localplayer)\n\n" );
  902. CDescribeData helper( (const byte *)player );
  903. helper.DumpDescription( player->GetPredDescMap() );
  904. Msg( "(localteam)\n\n" );
  905. C_Team *team = player->GetTeam();
  906. if ( team )
  907. {
  908. CDescribeData helper( (const byte *)team );
  909. helper.DumpDescription( team->GetPredDescMap() );
  910. }
  911. Msg( "(playerresource)\n\n" );
  912. if ( g_PR )
  913. {
  914. CDescribeData helper( (const byte *)g_PR );
  915. helper.DumpDescription( g_PR->GetPredDescMap() );
  916. }
  917. Msg( "(localplayerweapon)\n\n" );
  918. // Get the player's weapons, too
  919. C_BaseCombatWeapon *active = player->GetActiveWeapon();
  920. if ( active )
  921. {
  922. CDescribeData helper( (const byte *)active );
  923. helper.DumpDescription( active->GetPredDescMap() );
  924. }
  925. Msg( "Other replacements:\n\n" );
  926. // Global replacements
  927. for( int i = m_GlobalStats.First() ; i != m_GlobalStats.InvalidIndex(); i = m_GlobalStats.Next( i ) )
  928. {
  929. CUtlString& r = m_GlobalStats[ i ];
  930. char const *pReplace = r.String();
  931. char ansi[ 512 ];
  932. ansi[ 0 ] = 0;
  933. if ( pReplace[ 0 ] == '#' )
  934. {
  935. const wchar_t *pWString = g_pVGuiLocalize->Find( pReplace );
  936. if ( pWString )
  937. {
  938. g_pVGuiLocalize->ConvertUnicodeToANSI( pWString, ansi, sizeof( ansi ) );
  939. pReplace = ansi;
  940. }
  941. }
  942. Msg( "'%s' = '%s'\n", m_GlobalStats.GetElementName( i ), pReplace );
  943. }
  944. }
  945. bool CLCD::ExtractArrayIndex( char *str, size_t bufsize, int *index )
  946. {
  947. Assert( index );
  948. *index = 0;
  949. char s[ 2048 ];
  950. Q_strncpy( s, str, sizeof( s ) );
  951. char *pos = Q_strstr( s, "[" );
  952. if ( !pos )
  953. return false;
  954. char *pos2 = Q_strstr( s, "]" );
  955. if ( !pos2 )
  956. return false;
  957. char num[ 32 ];
  958. Q_strncpy( num, pos + 1, pos2 - pos );
  959. *index = Q_atoi( num );
  960. int left = pos - s + 1;
  961. char o[ 2048 ];
  962. Q_strncpy( o, s, left );
  963. Q_strncat( o, pos2 + 1, sizeof( o ), COPY_ALL_CHARACTERS );
  964. Q_strncpy( str, o, bufsize );
  965. return true;
  966. }
  967. void CLCD::LookupToken( char const *in, CUtlString& value )
  968. {
  969. value = "";
  970. C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
  971. if ( !player )
  972. {
  973. return;
  974. }
  975. C_BaseEntity *ref = NULL;
  976. char outbuf[ 1024 ];
  977. char *o = outbuf;
  978. char const *i = in;
  979. while ( *i )
  980. {
  981. if ( *i == '(' )
  982. {
  983. char token[ 512 ];
  984. char *to = token;
  985. // swallow everything until matching '%' character
  986. ++i;
  987. while ( *i && *i != ')' )
  988. {
  989. *to++ = *i++;
  990. }
  991. if ( *i )
  992. ++i;
  993. *to = 0;
  994. if ( !Q_stricmp( token, "localplayer" ) )
  995. {
  996. ref = player;
  997. }
  998. else if ( !Q_stricmp( token, "localteam" ) )
  999. {
  1000. ref = player->GetTeam();
  1001. }
  1002. else if ( !Q_stricmp( token, "localplayerweapon" ) )
  1003. {
  1004. ref = player->GetActiveWeapon();
  1005. }
  1006. else if ( !Q_stricmp( token, "playerresource" ) )
  1007. {
  1008. ref = g_PR;
  1009. }
  1010. }
  1011. else
  1012. {
  1013. *o++ = *i++;
  1014. }
  1015. }
  1016. *o = '\0';
  1017. // Fixme, also need to get array reference removed from end and do the . field searching stuff
  1018. // Outbuf now has the actual field
  1019. if ( !ref )
  1020. {
  1021. return;
  1022. }
  1023. int iIndex = 0;
  1024. ExtractArrayIndex( outbuf, sizeof( outbuf ), &iIndex );
  1025. typedescription_t *td = FindField( ref->GetPredDescMap(), outbuf );
  1026. if ( !td )
  1027. {
  1028. return;
  1029. }
  1030. // Not allowed to see this one
  1031. if ( td->flags & FTYPEDESC_VIEW_NEVER )
  1032. {
  1033. return;
  1034. }
  1035. int fieldOffsetSrc = td->fieldOffset;
  1036. // int fieldSize = td->fieldSize;
  1037. void const *pInputData = (void const *)((char *)ref + fieldOffsetSrc );
  1038. char sz[ 256 ];
  1039. sz[ 0 ] = 0;
  1040. // Found it, now get the value
  1041. switch ( td->fieldType )
  1042. {
  1043. case FIELD_FLOAT:
  1044. Q_snprintf( sz, sizeof( sz ), "%.2f", *((float *)pInputData + iIndex ) );
  1045. break;
  1046. case FIELD_STRING:
  1047. {
  1048. string_t *pString = (string_t *)((string_t *)pInputData + iIndex );
  1049. Q_snprintf( sz, sizeof( sz ), "%s", pString ? STRING( *pString ) : "" );
  1050. }
  1051. break;
  1052. case FIELD_VECTOR:
  1053. {
  1054. Vector v = *((Vector *)pInputData + iIndex );
  1055. Q_snprintf( sz, sizeof( sz ), "%.2f %.2f %.2f", v.x, v.y, v.z );
  1056. }
  1057. break;
  1058. case FIELD_COLOR32:
  1059. {
  1060. Color c = *(( Color * )pInputData + iIndex );
  1061. Q_snprintf( sz, sizeof( sz ), "%d %d %d %d", c.r(), c.g(), c.b(), c.a() );
  1062. }
  1063. break;
  1064. case FIELD_BOOLEAN:
  1065. Q_snprintf( sz, sizeof( sz ), "%s", *( ( bool *)pInputData + iIndex ) ? "true" : "false" );
  1066. break;
  1067. case FIELD_INTEGER:
  1068. Q_snprintf( sz, sizeof( sz ), "%i", *( (int *)pInputData + iIndex ));
  1069. break;
  1070. case FIELD_SHORT:
  1071. Q_snprintf( sz, sizeof( sz ), "%i", *( (short *)pInputData + iIndex ) );
  1072. break;
  1073. case FIELD_CHARACTER:
  1074. Q_snprintf( sz, sizeof( sz ), "%s", ((const char *)pInputData + iIndex ) );
  1075. break;
  1076. }
  1077. value = sz;
  1078. }
  1079. void CLCD::BuildUpdatedText( char const *in, CUtlString& out )
  1080. {
  1081. char outbuf[ 1024 ];
  1082. char *o = outbuf;
  1083. char const *i = in;
  1084. while ( *i )
  1085. {
  1086. if ( *i == '%' )
  1087. {
  1088. char token[ 512 ];
  1089. char *to = token;
  1090. // swallow everything until matching '%' character
  1091. ++i;
  1092. while ( *i && *i != '%' )
  1093. {
  1094. *to++ = *i++;
  1095. }
  1096. if ( *i )
  1097. ++i;
  1098. *to = 0;
  1099. // Now we have the token, do the lookup
  1100. CUtlString value;
  1101. LookupToken( token, value );
  1102. to = (char *)value.String();
  1103. while ( *to )
  1104. {
  1105. *o++ = *to++;
  1106. }
  1107. }
  1108. else
  1109. {
  1110. *o++ = *i++;
  1111. }
  1112. }
  1113. *o = '\0';
  1114. out = outbuf;
  1115. }
  1116. bool CLCD::Replace( CUtlString& str, char const *search, char const *replace )
  1117. {
  1118. // If search string is part of replacement, this is a bad thing!!!
  1119. Assert( !*replace || !Q_strstr( replace, search ) );
  1120. bool changed = false;
  1121. if ( !Q_strstr( str.String(), search ) )
  1122. return false;
  1123. char s[ 2048 ];
  1124. Q_strncpy( s, str.String(), sizeof( s ) );
  1125. int searchlen = Q_strlen( search );
  1126. while ( true )
  1127. {
  1128. char *pos = Q_strstr( s, search );
  1129. if ( !pos )
  1130. break;
  1131. char temp[ 4096 ];
  1132. // Found an instance
  1133. int left = pos - s + 1;
  1134. Assert( left < sizeof( temp ) );
  1135. Q_strncpy( temp, s, left );
  1136. Q_strncat( temp, replace, sizeof( temp ), COPY_ALL_CHARACTERS );
  1137. int rightofs = left + searchlen - 1;
  1138. Q_strncat( temp, &s[ rightofs ], sizeof( temp ), COPY_ALL_CHARACTERS );
  1139. // Replace entire string
  1140. Q_strncpy( s, temp, sizeof( s ) );
  1141. changed = true;
  1142. }
  1143. str = s;
  1144. return changed;
  1145. }
  1146. void CLCD::SetGlobalStat( char const *name, char const *value )
  1147. {
  1148. if ( !m_lcd )
  1149. return;
  1150. int idx = m_GlobalStats.Find( name );
  1151. if ( idx == m_GlobalStats.InvalidIndex() )
  1152. {
  1153. idx = m_GlobalStats.Insert( name );
  1154. }
  1155. m_GlobalStats[ idx ] = value;
  1156. }
  1157. void CLCD::AddChatLine( char const *txt )
  1158. {
  1159. if ( !m_lcd )
  1160. return;
  1161. while ( m_ChatHistory.Count() >= m_nMaxChatHistory )
  1162. {
  1163. m_ChatHistory.Remove( 0 );
  1164. }
  1165. m_ChatHistory.AddToTail( CUtlString( txt ) );
  1166. UpdateChat();
  1167. }
  1168. void CLCD::UpdateChat()
  1169. {
  1170. for ( int i = 0; i < m_nMaxChatHistory; ++i )
  1171. {
  1172. char name[ 32 ];
  1173. Q_snprintf( name, sizeof( name ), "chat_%d", i + 1 );
  1174. SetGlobalStat( name, i < m_ChatHistory.Count() ? m_ChatHistory[ i ].String() : " " );
  1175. }
  1176. }
  1177. void CLCD::DoGlobalReplacements( CUtlString& str )
  1178. {
  1179. // Put some limit to avoid infinite recursion
  1180. int maxChanges = 16;
  1181. bool changed = false;
  1182. do
  1183. {
  1184. changed = false;
  1185. for ( int i = m_GlobalStats.First(); i != m_GlobalStats.InvalidIndex(); i = m_GlobalStats.Next( i ) )
  1186. {
  1187. CUtlString &r = m_GlobalStats[ i ];
  1188. char const *pReplace = r.String();
  1189. char ansi[ 512 ];
  1190. ansi[ 0 ] = 0;
  1191. if ( pReplace[ 0 ] == '#' )
  1192. {
  1193. const wchar_t *pWString = g_pVGuiLocalize->Find( pReplace );
  1194. if ( pWString )
  1195. {
  1196. g_pVGuiLocalize->ConvertUnicodeToANSI( pWString, ansi, sizeof( ansi ) );
  1197. pReplace = ansi;
  1198. }
  1199. }
  1200. if ( Replace( str, m_GlobalStats.GetElementName( i ), pReplace ) )
  1201. {
  1202. changed = true;
  1203. }
  1204. }
  1205. } while ( changed && --maxChanges >= 0 );
  1206. }
  1207. void CLCD::ReduceParentheses( CUtlString& str )
  1208. {
  1209. char s[ 2048 ];
  1210. Q_strncpy( s, str.String(), sizeof( s ) );
  1211. while ( true )
  1212. {
  1213. char *pos = Q_strstr( s, "(" );
  1214. if ( !pos )
  1215. break;
  1216. char *end = Q_strstr( pos, ")" );
  1217. if ( !end )
  1218. break;
  1219. char temp[ 4096 ];
  1220. // Found an instance
  1221. int left = pos - s + 1;
  1222. Assert( left < sizeof( temp ) );
  1223. Q_strncpy( temp, s, left );
  1224. int rightofs = end - s + 1;
  1225. Q_strncat( temp, &s[ rightofs ], sizeof( temp ), COPY_ALL_CHARACTERS );
  1226. // Replace entire string
  1227. Q_strncpy( s, temp, sizeof( s ) );
  1228. }
  1229. str = s;
  1230. }
  1231. void CLCD::ParseReplacements( KeyValues *kv )
  1232. {
  1233. for ( KeyValues *sub = kv->GetFirstSubKey(); sub; sub = sub->GetNextKey() )
  1234. {
  1235. char const *key = sub->GetName();
  1236. char const *value = sub->GetString();
  1237. SetGlobalStat( key, value );
  1238. }
  1239. }
  1240. CON_COMMAND_F( cl_dumpplayer, "Dumps info about a player", FCVAR_CHEAT )
  1241. {
  1242. if ( args.ArgC() != 2 )
  1243. return;
  1244. int n = Q_atoi( args[1] );
  1245. C_BasePlayer *pPlayer = ToBasePlayer( C_BaseEntity::Instance( n ) );
  1246. if ( !pPlayer )
  1247. return;
  1248. Vector absMins, absMaxs;
  1249. pPlayer->GetRenderBoundsWorldspace( absMins, absMaxs );
  1250. Msg( "Effects: %x\n", pPlayer->GetEffects() );
  1251. Msg( "Dormant: %d\n", pPlayer->IsDormant() );
  1252. Msg( "Worldspace Render Bounds: [%.2f %.2f %.2f] -> [%.2f %.2f %.2f]\n",
  1253. absMins.x, absMins.y, absMins.z,
  1254. absMaxs.x, absMaxs.y, absMaxs.z );
  1255. CDescribeData helper( (const byte *)pPlayer );
  1256. helper.DumpDescription( pPlayer->GetPredDescMap() );
  1257. }