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.

155 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // ASSERT_DIALOG.CPP
  4. //
  5. // Handle Remote Assert().
  6. //=====================================================================================//
  7. #include "vxconsole.h"
  8. AssertAction_t g_AssertAction = ASSERT_ACTION_BREAK;
  9. static const char * g_AssertInfo = "Assert Info Not Available.";
  10. bool g_AssertDialogActive = false;
  11. //-----------------------------------------------------------------------------
  12. // AssertDialogProc
  13. //
  14. //-----------------------------------------------------------------------------
  15. int CALLBACK AssertDialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  16. {
  17. switch( uMsg )
  18. {
  19. case WM_INITDIALOG:
  20. {
  21. SetWindowText( hDlg, "Xbox 360 Assert!" );
  22. SetDlgItemText( hDlg, IDC_FILENAME_CONTROL, g_AssertInfo );
  23. // Center the dialog.
  24. RECT rcDlg, rcDesktop;
  25. GetWindowRect( hDlg, &rcDlg );
  26. GetWindowRect( GetDesktopWindow(), &rcDesktop );
  27. SetWindowPos(
  28. hDlg,
  29. HWND_TOP,
  30. ((rcDesktop.right-rcDesktop.left) - (rcDlg.right-rcDlg.left)) / 2,
  31. ((rcDesktop.bottom-rcDesktop.top) - (rcDlg.bottom-rcDlg.top)) / 2,
  32. 0,
  33. 0,
  34. SWP_NOSIZE );
  35. }
  36. return true;
  37. case WM_COMMAND:
  38. {
  39. switch( LOWORD( wParam ) )
  40. {
  41. // Ignore Asserts in this file from now on.
  42. case IDC_IGNORE_FILE:
  43. {
  44. g_AssertAction = ASSERT_ACTION_IGNORE_FILE;
  45. EndDialog( hDlg, 0 );
  46. return true;
  47. }
  48. // Ignore this Assert once.
  49. case IDC_IGNORE_THIS:
  50. {
  51. g_AssertAction = ASSERT_ACTION_IGNORE_THIS;
  52. EndDialog( hDlg, 0 );
  53. return true;
  54. }
  55. // Always ignore this Assert.
  56. case IDC_IGNORE_ALWAYS:
  57. {
  58. g_AssertAction = ASSERT_ACTION_IGNORE_ALWAYS;
  59. EndDialog( hDlg, 0 );
  60. return true;
  61. }
  62. // Ignore all Asserts from now on.
  63. case IDC_IGNORE_ALL:
  64. {
  65. g_AssertAction = ASSERT_ACTION_IGNORE_ALL;
  66. EndDialog( hDlg, 0 );
  67. return true;
  68. }
  69. case IDC_BREAK:
  70. {
  71. g_AssertAction = ASSERT_ACTION_BREAK;
  72. EndDialog( hDlg, 0 );
  73. return true;
  74. }
  75. }
  76. case WM_KEYDOWN:
  77. {
  78. // Escape?
  79. if ( wParam == 2 )
  80. {
  81. // Ignore this Assert.
  82. g_AssertAction = ASSERT_ACTION_IGNORE_THIS;
  83. EndDialog( hDlg, 0 );
  84. return true;
  85. }
  86. }
  87. }
  88. return true;
  89. }
  90. return FALSE;
  91. }
  92. //-----------------------------------------------------------------------------
  93. // rc_Assert
  94. //
  95. // Sent from application on hitting an Assert
  96. //-----------------------------------------------------------------------------
  97. int rc_Assert( char* commandPtr )
  98. {
  99. char* cmdToken;
  100. int retAddr;
  101. int errCode = -1;
  102. // Flash the taskbar icon (otherwise users may not realise the app has stalled on an Assert, esp. during loading)
  103. FLASHWINFO flashWInfo = { sizeof(FLASHWINFO), g_hDlgMain, FLASHW_ALL|FLASHW_TIMERNOFG, 0, 1000 };
  104. FlashWindowEx( &flashWInfo );
  105. // get retAddr
  106. cmdToken = GetToken( &commandPtr );
  107. if ( !cmdToken[0] )
  108. goto cleanUp;
  109. if (1 != sscanf( cmdToken, "%x", &retAddr ))
  110. goto cleanUp;
  111. // skip whitespace
  112. while ( commandPtr[0] == ' ' )
  113. {
  114. commandPtr++;
  115. }
  116. // Display file/line/expression info from the message in the Assert dialog
  117. // (convert '\t' to '\n'; way simpler than tokenizing a general assert expression)
  118. g_AssertInfo = commandPtr;
  119. char *tab = commandPtr;
  120. while( ( tab = strchr( tab, '\t' ) ) != NULL )
  121. {
  122. tab[0] = '\n';
  123. }
  124. // Open the Assert dialog, to determine the desired action
  125. g_AssertAction = ASSERT_ACTION_BREAK;
  126. g_AssertDialogActive = true;
  127. DialogBox( g_hInstance, MAKEINTRESOURCE( IDD_ASSERT_DIALOG ), g_hDlgMain, ( DLGPROC )AssertDialogProc );
  128. g_AssertDialogActive = false;
  129. // Write the (endian-converted) result directly back into the application's memory:
  130. int xboxRetVal = BigDWord( g_AssertAction );
  131. DmSetMemory( ( void* )retAddr, sizeof( int ), &xboxRetVal, NULL );
  132. // success
  133. errCode = 0;
  134. cleanUp:
  135. return errCode;
  136. }