Team Fortress 2 Source Code as on 22/4/2020
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.

320 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Xbox Remote Commands
  4. //
  5. //=====================================================================================//
  6. #include "xbox/xbox_console.h"
  7. #include "xbox/xbox_vxconsole.h"
  8. #include "tier0/tslist.h"
  9. #include "tier0/memdbgon.h"
  10. CInterlockedInt g_xbx_numProfileCounters;
  11. unsigned int g_xbx_profileCounters[XBX_MAX_PROFILE_COUNTERS];
  12. char g_xbx_profileName[32];
  13. //-----------------------------------------------------------------------------
  14. // XBX_rSetProfileAttributes
  15. //
  16. // Expose profile counters attributes to the console.
  17. //-----------------------------------------------------------------------------
  18. int CXboxConsole::SetProfileAttributes( const char *pProfileName, int numCounters, const char *names[], unsigned int colors[] )
  19. {
  20. char dbgCommand[XBX_MAX_RCMDLENGTH];
  21. int retVal;
  22. xrProfile_t* profileList;
  23. if ( numCounters > XBX_MAX_PROFILE_COUNTERS )
  24. {
  25. numCounters = XBX_MAX_PROFILE_COUNTERS;
  26. }
  27. profileList = new xrProfile_t[numCounters];
  28. memset( profileList, 0, numCounters*sizeof( xrProfile_t ) );
  29. for ( int i=0; i<numCounters; i++ )
  30. {
  31. strncpy( profileList[i].labelString, names[i], sizeof( profileList[i].labelString ) );
  32. profileList[i].labelString[sizeof( profileList[i].labelString ) - 1] = '\0';
  33. profileList[i].color = colors[i];
  34. }
  35. _snprintf( dbgCommand, sizeof( dbgCommand ), "SetProfile() %s 0x%8.8x 0x%8.8x 0x%8.8x", pProfileName, numCounters, profileList, &retVal );
  36. XBX_SendRemoteCommand( dbgCommand, false );
  37. delete[] profileList;
  38. return ( retVal );
  39. }
  40. //-----------------------------------------------------------------------------
  41. // XBX_rSetProfileData
  42. //
  43. // Expose profile counters to the console. Expected to be called once per game frame.
  44. //-----------------------------------------------------------------------------
  45. void CXboxConsole::SetProfileData( const char *pProfileName, int numCounters, unsigned int *pCounters )
  46. {
  47. static unsigned int lastTime = 0;
  48. unsigned int time;
  49. // not faster than 10Hz
  50. time = GetTickCount();
  51. if ( time - lastTime < 100 )
  52. {
  53. return;
  54. }
  55. if ( g_xbx_numProfileCounters == 0 )
  56. {
  57. _snprintf( g_xbx_profileName, sizeof( g_xbx_profileName ), pProfileName );
  58. if ( numCounters > XBX_MAX_PROFILE_COUNTERS )
  59. {
  60. numCounters = XBX_MAX_PROFILE_COUNTERS;
  61. }
  62. memcpy( g_xbx_profileCounters, pCounters, numCounters * sizeof( unsigned int ) );
  63. // mark for sending
  64. g_xbx_numProfileCounters = numCounters;
  65. lastTime = time;
  66. }
  67. }
  68. //-----------------------------------------------------------------------------
  69. // XBX_rMemDump
  70. //
  71. // Send signal to remote console to read mempry dump in specified filename.
  72. //-----------------------------------------------------------------------------
  73. int CXboxConsole::MemDump( const char *pDumpFileName )
  74. {
  75. char dbgCommand[XBX_MAX_RCMDLENGTH];
  76. _snprintf( dbgCommand, sizeof( dbgCommand ), "MemDump() %s", pDumpFileName );
  77. XBX_SendRemoteCommand( dbgCommand, true );
  78. return 0;
  79. }
  80. //-----------------------------------------------------------------------------
  81. // XBX_rTimeStampLog
  82. //
  83. // Send time stamp to remote console
  84. //-----------------------------------------------------------------------------
  85. int CXboxConsole::TimeStampLog( float time, const char *pString )
  86. {
  87. char dbgCommand[XBX_MAX_RCMDLENGTH];
  88. int retVal;
  89. xrTimeStamp_t timeStamp;
  90. MEMORYSTATUS stat;
  91. static int lastMemoryStamp = 0;
  92. static float lastTimeStamp = 0;
  93. // get current available memory
  94. GlobalMemoryStatus( &stat );
  95. if ( !lastTimeStamp || time < lastTimeStamp )
  96. {
  97. // first entry or restart, reset stamps
  98. lastMemoryStamp = stat.dwAvailPhys;
  99. lastTimeStamp = time;
  100. }
  101. timeStamp.time = time;
  102. timeStamp.deltaTime = time - lastTimeStamp;
  103. timeStamp.memory = stat.dwAvailPhys;
  104. timeStamp.deltaMemory = stat.dwAvailPhys - lastMemoryStamp;
  105. strncpy( timeStamp.messageString, pString, sizeof( timeStamp.messageString ) );
  106. timeStamp.messageString[sizeof( timeStamp.messageString ) - 1] = '\0';
  107. _snprintf( dbgCommand, sizeof( dbgCommand ), "TimeStampLog() 0x%8.8x 0x%8.8x", &timeStamp, &retVal );
  108. XBX_SendRemoteCommand( dbgCommand, false );
  109. lastTimeStamp = time;
  110. lastMemoryStamp = stat.dwAvailPhys;
  111. return retVal;
  112. }
  113. //-----------------------------------------------------------------------------
  114. // XBX_rMaterialList
  115. //
  116. // Send material list to remote console
  117. //-----------------------------------------------------------------------------
  118. int CXboxConsole::MaterialList( int nMaterials, const xMaterialList_t* pXMaterialList )
  119. {
  120. char dbgCommand[XBX_MAX_RCMDLENGTH];
  121. int retVal;
  122. xrMaterial_t* pRemoteList;
  123. pRemoteList = new xrMaterial_t[nMaterials];
  124. memset( pRemoteList, 0, nMaterials*sizeof( xrMaterial_t ) );
  125. for ( int i=0; i<nMaterials; i++ )
  126. {
  127. strncpy( pRemoteList[i].nameString, pXMaterialList[i].pName, sizeof( pRemoteList[i].nameString ) );
  128. pRemoteList[i].nameString[sizeof( pRemoteList[i].nameString ) - 1] = '\0';
  129. strncpy( pRemoteList[i].shaderString, pXMaterialList[i].pShaderName, sizeof( pRemoteList[i].shaderString ) );
  130. pRemoteList[i].shaderString[sizeof( pRemoteList[i].shaderString ) - 1] = '\0';
  131. pRemoteList[i].refCount = pXMaterialList[i].refCount;
  132. }
  133. _snprintf( dbgCommand, sizeof( dbgCommand ), "MaterialList() 0x%8.8x 0x%8.8x 0x%8.8x", nMaterials, pRemoteList, &retVal );
  134. XBX_SendRemoteCommand( dbgCommand, false );
  135. delete [] pRemoteList;
  136. return retVal;
  137. }
  138. //-----------------------------------------------------------------------------
  139. // XBX_rTextureList
  140. //
  141. // Send texture list to remote console
  142. //-----------------------------------------------------------------------------
  143. int CXboxConsole::TextureList( int nTextures, const xTextureList_t* pXTextureList )
  144. {
  145. char dbgCommand[XBX_MAX_RCMDLENGTH];
  146. int retVal;
  147. xrTexture_t* pRemoteList;
  148. pRemoteList = new xrTexture_t[nTextures];
  149. memset( pRemoteList, 0, nTextures*sizeof( xrTexture_t ) );
  150. for ( int i=0; i<nTextures; i++ )
  151. {
  152. strncpy( pRemoteList[i].nameString, pXTextureList[i].pName, sizeof( pRemoteList[i].nameString ) );
  153. pRemoteList[i].nameString[sizeof( pRemoteList[i].nameString ) - 1] = '\0';
  154. strncpy( pRemoteList[i].groupString, pXTextureList[i].pGroupName, sizeof( pRemoteList[i].groupString ) );
  155. pRemoteList[i].groupString[sizeof( pRemoteList[i].groupString ) - 1] = '\0';
  156. strncpy( pRemoteList[i].formatString, pXTextureList[i].pFormatName, sizeof( pRemoteList[i].formatString ) );
  157. pRemoteList[i].formatString[sizeof( pRemoteList[i].formatString ) - 1] = '\0';
  158. pRemoteList[i].size = pXTextureList[i].size;
  159. pRemoteList[i].width = pXTextureList[i].width;
  160. pRemoteList[i].height = pXTextureList[i].height;
  161. pRemoteList[i].depth = pXTextureList[i].depth;
  162. pRemoteList[i].numLevels = pXTextureList[i].numLevels;
  163. pRemoteList[i].binds = pXTextureList[i].binds;
  164. pRemoteList[i].refCount = pXTextureList[i].refCount;
  165. pRemoteList[i].sRGB = pXTextureList[i].sRGB;
  166. pRemoteList[i].edram = pXTextureList[i].edram;
  167. pRemoteList[i].procedural = pXTextureList[i].procedural;
  168. pRemoteList[i].fallback = pXTextureList[i].fallback;
  169. pRemoteList[i].final = pXTextureList[i].final;
  170. pRemoteList[i].failed = pXTextureList[i].failed;
  171. }
  172. _snprintf( dbgCommand, sizeof( dbgCommand ), "TextureList() 0x%8.8x 0x%8.8x 0x%8.8x", nTextures, pRemoteList, &retVal );
  173. XBX_SendRemoteCommand( dbgCommand, false );
  174. delete [] pRemoteList;
  175. return ( retVal );
  176. }
  177. //-----------------------------------------------------------------------------
  178. // XBX_rSoundList
  179. //
  180. // Send sound list to remote console
  181. //-----------------------------------------------------------------------------
  182. int CXboxConsole::SoundList( int nSounds, const xSoundList_t* pXSoundList )
  183. {
  184. char dbgCommand[XBX_MAX_RCMDLENGTH];
  185. int retVal;
  186. xrSound_t* pRemoteList;
  187. pRemoteList = new xrSound_t[nSounds];
  188. memset( pRemoteList, 0, nSounds*sizeof( xrSound_t ) );
  189. for ( int i=0; i<nSounds; i++ )
  190. {
  191. strncpy( pRemoteList[i].nameString, pXSoundList[i].name, sizeof( pRemoteList[i].nameString ) );
  192. pRemoteList[i].nameString[sizeof( pRemoteList[i].nameString ) - 1] = '\0';
  193. strncpy( pRemoteList[i].formatString, pXSoundList[i].formatName, sizeof( pRemoteList[i].formatString ) );
  194. pRemoteList[i].formatString[sizeof( pRemoteList[i].formatString ) - 1] = '\0';
  195. pRemoteList[i].rate = pXSoundList[i].rate;
  196. pRemoteList[i].bits = pXSoundList[i].bits;
  197. pRemoteList[i].channels = pXSoundList[i].channels;
  198. pRemoteList[i].looped = pXSoundList[i].looped;
  199. pRemoteList[i].dataSize = pXSoundList[i].dataSize;
  200. pRemoteList[i].numSamples = pXSoundList[i].numSamples;
  201. pRemoteList[i].streamed = pXSoundList[i].streamed;
  202. }
  203. _snprintf( dbgCommand, sizeof( dbgCommand ), "SoundList() 0x%8.8x 0x%8.8x 0x%8.8x", nSounds, pRemoteList, &retVal );
  204. XBX_SendRemoteCommand( dbgCommand, false );
  205. delete [] pRemoteList;
  206. return ( retVal );
  207. }
  208. //-----------------------------------------------------------------------------
  209. // XBX_rMapInfo
  210. //
  211. // Send signal to remote console with various info
  212. //-----------------------------------------------------------------------------
  213. int CXboxConsole::MapInfo( const xMapInfo_t *pXMapInfo )
  214. {
  215. char dbgCommand[XBX_MAX_RCMDLENGTH];
  216. int retVal;
  217. xrMapInfo_t xrMapInfo;
  218. memcpy( xrMapInfo.position, pXMapInfo->position, 3 * sizeof( float ) );
  219. memcpy( xrMapInfo.angle, pXMapInfo->angle, 3 * sizeof( float ) );
  220. strncpy( xrMapInfo.mapPath, pXMapInfo->mapPath, sizeof( xrMapInfo.mapPath ) );
  221. xrMapInfo.mapPath[sizeof( xrMapInfo.mapPath ) - 1] = '\0';
  222. strncpy( xrMapInfo.savePath, pXMapInfo->savePath, sizeof( xrMapInfo.savePath ) );
  223. xrMapInfo.savePath[sizeof( xrMapInfo.savePath ) - 1] = '\0';
  224. xrMapInfo.build = pXMapInfo->build;
  225. xrMapInfo.skill = pXMapInfo->skill;
  226. _snprintf( dbgCommand, sizeof( dbgCommand ), "MapInfo() 0x%8.8x 0x%8.8x", &xrMapInfo, &retVal );
  227. XBX_SendRemoteCommand( dbgCommand, false );
  228. return retVal;
  229. }
  230. //-----------------------------------------------------------------------------
  231. // XBX_rAddCommands
  232. //
  233. // Expose commands to remote console
  234. //-----------------------------------------------------------------------------
  235. int CXboxConsole::AddCommands( int numCommands, const char* commands[], const char* help[] )
  236. {
  237. char dbgCommand[XBX_MAX_RCMDLENGTH];
  238. int retVal;
  239. xrCommand_t* cmdList;
  240. cmdList = new xrCommand_t[numCommands];
  241. memset( cmdList, 0, numCommands*sizeof( xrCommand_t ) );
  242. for ( int i=0; i<numCommands; i++ )
  243. {
  244. strncpy( cmdList[i].nameString, commands[i], sizeof( cmdList[i].nameString ) );
  245. cmdList[i].nameString[sizeof( cmdList[i].nameString ) - 1] = '\0';
  246. strncpy( cmdList[i].helpString, help[i], sizeof( cmdList[i].helpString ) );
  247. cmdList[i].helpString[sizeof( cmdList[i].helpString ) - 1] = '\0';
  248. }
  249. _snprintf( dbgCommand, sizeof( dbgCommand ), "AddCommands() 0x%8.8x 0x%8.8x 0x%8.8x", numCommands, cmdList, &retVal );
  250. XBX_SendRemoteCommand( dbgCommand, false );
  251. delete [] cmdList;
  252. return ( retVal );
  253. }