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.

479 lines
17 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // VXCONSOLE.H
  4. //
  5. // Master Header.
  6. //=====================================================================================//
  7. #pragma once
  8. #include "tier0/platform.h"
  9. #include <winsock2.h>
  10. #include <windows.h>
  11. #include <windowsx.h>
  12. #include <commctrl.h>
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. #include <io.h>
  16. #include <fcntl.h>
  17. #include <string.h>
  18. #include <share.h>
  19. #include <richedit.h>
  20. #include <assert.h>
  21. #include <xbdm.h>
  22. #include <time.h>
  23. #include <sys/stat.h>
  24. #include "resource.h"
  25. #include "assert_resource.h"
  26. #include "sys_utils.h"
  27. #include "sys_scriptlib.h"
  28. #include "bugreporter/bugreporter.h"
  29. #include "jpeglib/jpeglib.h"
  30. #include "UtlBuffer.h"
  31. #include "strtools.h"
  32. #include "xbox/xbox_vxconsole.h"
  33. #include "UtlRBTree.h"
  34. #include "UtlSymbol.h"
  35. #include "UtlVector.h"
  36. #include "UtlString.h"
  37. #define VXCONSOLE_VERSION "1.2"
  38. #define VXCONSOLE_CLASSNAME "VXConsole"
  39. #define VXCONSOLE_TITLE "VXConsole"
  40. #define VXCONSOLE_FONT "Courier"
  41. #define VXCONSOLE_FONTSIZE 10
  42. #define VXCONSOLE_MAGIC "3\\"
  43. #define VXCONSOLE_REGISTRY "HKEY_CURRENT_USER\\Software\\VXConsole\\" VXCONSOLE_MAGIC
  44. #ifdef _DEBUG
  45. #define VXCONSOLE_BUILDTYPE "Debug"
  46. #else
  47. #define VXCONSOLE_BUILDTYPE "Release"
  48. #endif
  49. #define VXCONSOLE_WINDOWBYTES ( DLGWINDOWEXTRA + 4 )
  50. #define VXCONSOLE_CONFIGID ( VXCONSOLE_WINDOWBYTES - 4 )
  51. #define MAX_QUEUEDSTRINGS 4096
  52. #define MAX_QUEUEDSTRINGLEN 512
  53. #define MAX_RCMDNAMELEN 32
  54. #define MAX_RCMDS 4096
  55. #define MAX_TOKENCHARS 256
  56. #define MAX_XBOXNAMELEN 64
  57. #define MAX_ARGVELEMS 20
  58. #define MAX_COMMANDHISTORY 25
  59. #define TIMERID_AUTOCONNECT 0x1000
  60. #define TIMERID_MEMPROFILE 0x1001
  61. #define IDC_COMMANDHINT 666
  62. #define XBX_CLR_RED ( RGB( 255,0,0 ) )
  63. #define XBX_CLR_GREEN ( RGB( 0,255,0 ) )
  64. #define XBX_CLR_WHITE ( RGB( 255,255,255 ) )
  65. #define XBX_CLR_BLACK ( RGB( 0,0,0 ) )
  66. #define XBX_CLR_BLUE ( RGB( 0,0,255 ) )
  67. #define XBX_CLR_YELLOW ( RGB( 255,255,0 ) )
  68. #define XBX_CLR_LTGREY ( RGB( 180,180,180 ) )
  69. #define XBX_CLR_DEFAULT XBX_CLR_BLACK
  70. // The command prefix that is prepended to all communication between the Xbox
  71. // app and the debug console app
  72. #define VXCONSOLE_PRINT_PREFIX "XPRT"
  73. #define VXCONSOLE_COMMAND_PREFIX "XCMD"
  74. #define VXCONSOLE_COMMAND_ACK "XACK"
  75. #define VXCONSOLE_COLOR_PREFIX "XCLR"
  76. #define ICON_APPLICATION 0
  77. #define ICON_DISCONNECTED 1
  78. #define ICON_CONNECTED_XBOX 2
  79. #define ICON_CONNECTED_APP0 3
  80. #define ICON_CONNECTED_APP1 4
  81. #define MAX_ICONS 5
  82. typedef BOOL ( *cmdHandler_t )( int argc, char* argv[] );
  83. #define IDM_BINDINGS 50000
  84. #define IDM_BINDINGS_EDIT ( IDM_BINDINGS+1 )
  85. #define IDM_BINDINGS_BIND1 ( IDM_BINDINGS+2 )
  86. #define IDM_BINDINGS_BIND2 ( IDM_BINDINGS+3 )
  87. #define IDM_BINDINGS_BIND3 ( IDM_BINDINGS+4 )
  88. #define IDM_BINDINGS_BIND4 ( IDM_BINDINGS+5 )
  89. #define IDM_BINDINGS_BIND5 ( IDM_BINDINGS+6 )
  90. #define IDM_BINDINGS_BIND6 ( IDM_BINDINGS+7 )
  91. #define IDM_BINDINGS_BIND7 ( IDM_BINDINGS+8 )
  92. #define IDM_BINDINGS_BIND8 ( IDM_BINDINGS+9 )
  93. #define IDM_BINDINGS_BIND9 ( IDM_BINDINGS+10 )
  94. #define IDM_BINDINGS_BIND10 ( IDM_BINDINGS+11 )
  95. #define IDM_BINDINGS_BIND11 ( IDM_BINDINGS+12 )
  96. #define IDM_BINDINGS_BIND12 ( IDM_BINDINGS+13 )
  97. #define MAX_BINDINGS ( VK_F12-VK_F1+1 )
  98. // file serving
  99. #define FSERVE_LOCALONLY 0
  100. #define FSERVE_REMOTEONLY 1
  101. #define FSERVE_LOCALFIRST 2
  102. // file sync
  103. #define FSYNC_OFF 0x00000000
  104. #define FSYNC_ALWAYS 0x00000001
  105. #define FSYNC_IFNEWER 0x00000002
  106. #define FSYNC_TYPEMASK 0x0000000F
  107. #define FSYNC_ANDEXISTSONTARGET 0x80000000
  108. // track function invocations
  109. typedef enum
  110. {
  111. FL_INVALID,
  112. FL_STAT,
  113. FL_FOPEN,
  114. FL_FSEEK,
  115. FL_FTELL,
  116. FL_FREAD,
  117. FL_FWRITE,
  118. FL_FCLOSE,
  119. FL_FEOF,
  120. FL_FERROR,
  121. FL_FFLUSH,
  122. FL_FGETS,
  123. FL_MAXFUNCTIONCOUNTS,
  124. } fileLogFunctions_e;
  125. typedef enum
  126. {
  127. VPROF_OFF = 0,
  128. VPROF_CPU,
  129. VPROF_TEXTURE,
  130. VPROF_TEXTUREFRAME,
  131. } vprofState_e;
  132. // funtion command types
  133. #define FN_CONSOLE 0x00 // command runs at console
  134. #define FN_XBOX 0x01 // command requires xbox
  135. #define FN_APP 0x02 // command requires application
  136. // shorthand
  137. #define FA_NORMAL FILE_ATTRIBUTE_NORMAL
  138. #define FA_DIRECTORY FILE_ATTRIBUTE_DIRECTORY
  139. #define FA_READONLY FILE_ATTRIBUTE_READONLY
  140. typedef struct
  141. {
  142. const CHAR* strCommand;
  143. int flags;
  144. cmdHandler_t pfnHandler;
  145. const CHAR* strHelp;
  146. } localCommand_t;
  147. typedef struct
  148. {
  149. char* strCommand;
  150. char* strHelp;
  151. } remoteCommand_t;
  152. typedef struct
  153. {
  154. CRITICAL_SECTION CriticalSection;
  155. int numMessages;
  156. bool bInit;
  157. COLORREF aColors[MAX_QUEUEDSTRINGS];
  158. CHAR *pMessages[MAX_QUEUEDSTRINGS];
  159. } printQueue_t;
  160. class CProgress
  161. {
  162. public:
  163. CProgress();
  164. ~CProgress();
  165. void Open( const char* title, bool canCancel, bool bHasMeter );
  166. void SetStatus( const char *line1, const char *line2, const char *line3 );
  167. void SetMeter( int currentPos, int range );
  168. bool IsCancel();
  169. HWND m_hWnd;
  170. HWND m_hWndStatus1;
  171. HWND m_hWndStatus2;
  172. HWND m_hWndStatus3;
  173. HWND m_hWndPercent;
  174. HWND m_hWndMeter;
  175. HWND m_hWndCancel;
  176. bool m_bCancelPressed;
  177. int m_range;
  178. private:
  179. void Update();
  180. };
  181. typedef struct fileNode_s
  182. {
  183. char *filename;
  184. FILETIME creationTime;
  185. FILETIME changeTime;
  186. DWORD sizeHigh;
  187. DWORD sizeLow;
  188. DWORD attributes;
  189. int level;
  190. struct fileNode_s *nextPtr;
  191. bool needsUpdate;
  192. }
  193. fileNode_t;
  194. //-----------------------------------------------------------------------------
  195. // FILEIO.CPP
  196. //-----------------------------------------------------------------------------
  197. extern void RemoteToLocalFilename( const char* inFilename, char* outFilename, int outSize );
  198. extern void RemoteToTargetFilename( const char* inFilename, char* outFilename, int outSize );
  199. extern void FreeTargetFileList( fileNode_t* pFileList );
  200. extern bool GetTargetFileList_r( char* targetPath, bool recurse, int attributes, int level, fileNode_t** pFileList );
  201. extern char *SystemTimeToString( SYSTEMTIME *systemTime, char *buffer, int bufferSize );
  202. extern bool CreateTargetPath( const char *pTargetFilename );
  203. //-----------------------------------------------------------------------------
  204. // BINDINGS.CPP
  205. //-----------------------------------------------------------------------------
  206. extern bool Bindings_TranslateKey( int vkKeyCode );
  207. extern bool Bindings_MenuSelection( int wID );
  208. extern void Bindings_LoadConfig();
  209. extern void Bindings_SaveConfig();
  210. extern void Bindings_Open();
  211. extern bool Bindings_Init();
  212. //-----------------------------------------------------------------------------
  213. // COMMON.CPP
  214. //-----------------------------------------------------------------------------
  215. //-----------------------------------------------------------------------------
  216. // VXCONSOLE.CPP
  217. //-----------------------------------------------------------------------------
  218. extern void SetConnectionIcon( int icon );
  219. extern void PrintToQueue( COLORREF color, const CHAR* strFormat, ... );
  220. extern void ProcessPrintQueue();
  221. extern void DmAPI_DisplayError( const char* strApiName, HRESULT hr );
  222. extern int ConsoleWindowPrintf( COLORREF rgb, LPCTSTR lpFmt, ... );
  223. extern int CmdToArgv( char* str, char* argv[], int maxargs );
  224. extern char* GetToken( char** tokenStreamPtr );
  225. extern void DebugCommand( const char* strFormat, ... );
  226. extern bool ProcessCommand( const char* strCmd );
  227. extern HRESULT DmAPI_SendCommand( const char* strCommand, bool wait );
  228. extern void NotImplementedYet();
  229. extern void SetMainWindowTitle();
  230. extern HWND g_hDlgMain;
  231. extern HWND g_hwndOutputWindow;
  232. extern UINT_PTR g_autoConnectTimer;
  233. extern BOOL g_autoConnect;
  234. extern CHAR g_xboxName[];
  235. extern DWORD g_xboxAddress;
  236. extern CHAR g_remotePath[];
  237. extern CHAR g_localPath[];
  238. extern CHAR g_targetPath[];
  239. extern CHAR g_installPath[];
  240. extern CHAR g_xboxTargetName[];
  241. extern BOOL g_connectedToApp;
  242. extern BOOL g_connectedToXBox;
  243. extern PDMN_SESSION g_pdmnSession;
  244. extern PDM_CONNECTION g_pdmConnection;
  245. extern BOOL g_debugCommands;
  246. extern BOOL g_captureDebugSpew;
  247. extern HINSTANCE g_hInstance;
  248. extern HICON g_hIcons[];
  249. extern BOOL g_reboot;
  250. extern int g_rebootArgc;
  251. extern char* g_rebootArgv[];
  252. extern int g_connectCount;
  253. extern int g_currentIcon;
  254. extern BOOL g_clsOnConnect;
  255. extern DWORD g_connectedTime;
  256. extern HBRUSH g_hBackgroundBrush;
  257. extern COLORREF g_backgroundColor;
  258. extern HFONT g_hFixedFont;
  259. extern HFONT g_hProportionalFont;
  260. extern HANDLE g_hCommandReadyEvent;
  261. extern BOOL g_loadSymbolsOnConnect;
  262. extern HACCEL g_hAccel;
  263. extern BOOL g_alwaysAutoConnect;
  264. extern BOOL g_startMinimized;
  265. extern int g_connectFailure;
  266. extern BOOL g_captureDebugSpew_StartupState;
  267. extern bool g_bSuppressBlink;
  268. extern BOOL g_bPlayTestMode;
  269. //-----------------------------------------------------------------------------
  270. // LOCAL_CMDS.CPP
  271. //-----------------------------------------------------------------------------
  272. extern BOOL lc_bug( int argc, char* argv[] );
  273. extern BOOL lc_dir( int argc, char* argv[] );
  274. extern BOOL lc_del( int argc, char* argv[] );
  275. extern BOOL lc_memory( int argc, char* argv[] );
  276. extern BOOL lc_screenshot( int argc, char* argv[] );
  277. extern BOOL lc_help( int argc, char* argv[] );
  278. extern BOOL lc_cls( int argc, char* argv[] );
  279. extern BOOL lc_connect( int argc, char* argv[] );
  280. extern BOOL lc_autoConnect( int argc, char* argv[] );
  281. extern BOOL lc_disconnect( int argc, char* argv[] );
  282. extern BOOL lc_quit( int argc, char* argv[] );
  283. extern BOOL lc_crashdump( int argc, char* argv[] );
  284. extern BOOL lc_listen( int argc, char* argv[] );
  285. extern BOOL lc_run( int argc, char* argv[] );
  286. extern BOOL lc_reset( int argc, char* argv[] );
  287. extern BOOL lc_modules( int argc, char* argv[] );
  288. extern BOOL lc_sections( int argc, char* argv[] );
  289. extern BOOL lc_threads( int argc, char* argv[] );
  290. extern BOOL lc_ClearConfigs( int argc, char* argv[] );
  291. extern void AutoConnectTimerProc( HWND hwnd, UINT_PTR idEvent );
  292. extern int MatchLocalCommands( char* cmdStr, const char* cmdList[], int maxCmds );
  293. extern void DoDisconnect( BOOL bKeepConnection, int waitTime = 15 );
  294. extern localCommand_t g_localCommands[];
  295. extern const int g_numLocalCommands;
  296. //-----------------------------------------------------------------------------
  297. // REMOTE_CMDS.CPP
  298. //-----------------------------------------------------------------------------
  299. extern int rc_AddCommands( char* commandPtr );
  300. extern void Remote_DeleteCommands();
  301. extern DWORD __stdcall Remote_NotifyDebugString( ULONG dwNotification, DWORD dwParam );
  302. extern DWORD __stdcall Remote_NotifyPrintFunc( const CHAR* strNotification );
  303. extern DWORD __stdcall Remote_NotifyCommandFunc( const CHAR* strNotification );
  304. extern int MatchRemoteCommands( char* cmdStr, const char* cmdList[], int maxCmds );
  305. extern remoteCommand_t* g_remoteCommands[];
  306. extern int g_numRemoteCommands;
  307. //-----------------------------------------------------------------------------
  308. // BUG.CPP
  309. //-----------------------------------------------------------------------------
  310. extern bool BugDlg_Init( void );
  311. extern void BugDlg_Open( void );
  312. extern void BugReporter_FreeInterfaces();
  313. extern int rc_MapInfo( char* commandPtr );
  314. //-----------------------------------------------------------------------------
  315. // CONFIG.CPP
  316. //-----------------------------------------------------------------------------
  317. extern void ConfigDlg_Open( void );
  318. extern void ConfigDlg_LoadConfig();
  319. //-----------------------------------------------------------------------------
  320. // FILELOG.CPP
  321. //-----------------------------------------------------------------------------
  322. extern void FileLog_Open();
  323. extern bool FileLog_Init();
  324. extern void FileLog_Clear();
  325. extern unsigned int FileLog_AddItem( const char* filename, unsigned int fp );
  326. extern void FileLog_UpdateItem( unsigned int log, unsigned int fp, fileLogFunctions_e functionId, int value );
  327. extern void FileLog_SaveConfig();
  328. extern void FileLog_LoadConfig();
  329. extern bool g_fileLogEnable;
  330. //-----------------------------------------------------------------------------
  331. // CPU_PROFILE.CPP
  332. //-----------------------------------------------------------------------------
  333. extern void CpuProfileSamples_Open();
  334. extern void CpuProfileHistory_Open();
  335. extern void CpuProfile_SetTitle();
  336. extern bool CpuProfile_Init();
  337. extern void CpuProfile_Clear();
  338. extern int rc_SetCpuProfile( char* commandPtr );
  339. extern int rc_SetCpuProfileData( char* commandPtr );
  340. //-----------------------------------------------------------------------------
  341. // TEX_PROFILE.CPP
  342. //-----------------------------------------------------------------------------
  343. extern void TexProfile_SetTitle();
  344. extern void TexProfileSamples_Open();
  345. extern void TexProfileHistory_Open();
  346. extern bool TexProfile_Init();
  347. extern int rc_SetTexProfile( char* commandPtr );
  348. extern int rc_SetTexProfileData( char* commandPtr );
  349. //-----------------------------------------------------------------------------
  350. // MEM_PROFILE.CPP
  351. //-----------------------------------------------------------------------------
  352. extern void MemProfile_Open();
  353. extern void MemProfile_SetTitle();
  354. extern bool MemProfile_Init();
  355. extern void MemProfile_Clear();
  356. extern int rc_FreeMemory( char* commandPtr );
  357. //-----------------------------------------------------------------------------
  358. // MEMLOG.CPP
  359. //-----------------------------------------------------------------------------
  360. extern void MemoryLog_Open();
  361. extern bool MemoryLog_Init();
  362. extern void MemoryLog_Clear();
  363. extern void MemoryLog_SaveConfig();
  364. extern void MemoryLog_LoadConfig();
  365. extern void MemoryLog_TreeView( bool enable );
  366. extern void MemoryLog_RefreshItems();
  367. extern int rc_MemoryLog( char* commandPtr );
  368. extern bool g_memoryLog_enable;
  369. //-----------------------------------------------------------------------------
  370. // SYNC_FILES.CPP
  371. //-----------------------------------------------------------------------------
  372. extern int FileSyncEx( const char* localFilename, const char* remoteFilename, int fileSyncMode, bool bVerbose, bool bNoWrite );
  373. extern bool SyncFilesDlg_Init( void );
  374. extern void SyncFilesDlg_Open( void );
  375. extern void InstallDlg_Open( void );
  376. //-----------------------------------------------------------------------------
  377. // FILEIO.CPP
  378. //-----------------------------------------------------------------------------
  379. extern int CompareFileTimes_NTFStoFATX( FILETIME* ntfsFileTime, char *ntfsTimeString, int ntfsStringSize, FILETIME* fatxFileTime, char *fatxTimeString, int fatxStringSize );
  380. extern bool LoadTargetFile( const char *pTargetPath, int *pFileSize, void **pData );
  381. //-----------------------------------------------------------------------------
  382. // PROGRESS.CPP
  383. //-----------------------------------------------------------------------------
  384. extern bool Progress_Init();
  385. //-----------------------------------------------------------------------------
  386. // SHOW_TEXTURES.CPP
  387. //-----------------------------------------------------------------------------
  388. extern void ShowTextures_Open();
  389. extern bool ShowTextures_Init();
  390. extern int rc_TextureList( char* commandPtr );
  391. //-----------------------------------------------------------------------------
  392. // TIMESTAMP_LOG.CPP
  393. //-----------------------------------------------------------------------------
  394. extern void TimeStampLog_Open();
  395. extern bool TimeStampLog_Init();
  396. extern void TimeStampLog_Clear();
  397. extern int rc_TimeStampLog( char* commandPtr );
  398. //-----------------------------------------------------------------------------
  399. // COMMON.CPP
  400. //-----------------------------------------------------------------------------
  401. extern vprofState_e VProf_GetState();
  402. extern void VProf_Enable( vprofState_e state );
  403. //-----------------------------------------------------------------------------
  404. // SHOW_MATERIALS.CPP
  405. //-----------------------------------------------------------------------------
  406. extern void ShowMaterials_Open();
  407. extern bool ShowMaterials_Init();
  408. extern int rc_MaterialList( char* commandPtr );
  409. //-----------------------------------------------------------------------------
  410. // SHOW_SOUNDS.CPP
  411. //-----------------------------------------------------------------------------
  412. extern void ShowSounds_Open();
  413. extern bool ShowSounds_Init();
  414. extern int rc_SoundList( char* commandPtr );
  415. //-----------------------------------------------------------------------------
  416. // SHOW_MEMDUMP.CPP
  417. //-----------------------------------------------------------------------------
  418. extern void ShowMemDump_Open();
  419. extern bool ShowMemDump_Init();
  420. extern int rc_MemDump( char* commandPtr );
  421. //-----------------------------------------------------------------------------
  422. // EXCLUDE_PATHS.CPP
  423. //-----------------------------------------------------------------------------
  424. extern bool ExcludePathsDlg_Init( void );
  425. extern void ExcludePathsDlg_Open( void );
  426. //-----------------------------------------------------------------------------
  427. // ASSERT_DIALOG.CPP
  428. //-----------------------------------------------------------------------------
  429. extern bool g_AssertDialogActive;
  430. int rc_Assert( char *commandPtr );