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.

312 lines
9.3 KiB

  1. // ps_console.cpp - for communicating with vxconsole_ps3
  2. #include <string.h>
  3. #include <sys/event.h>
  4. #include <string.h>
  5. #include "ps3/ps3_console.h"
  6. #include "ps3/ps3_vxconsole.h"
  7. #include "ps3/ps3_win32stubs.h"
  8. #include "../utils/ps3/vpbdm/vpbdm_exports.h"
  9. #include "ps3/ps3_helpers.h"
  10. #include "ps3_pathinfo.h"
  11. // #include "cmd.h"
  12. #ifdef _RETAIL
  13. //Stubs for retail
  14. bool PS3_DebugString( unsigned int color, const char* format, ... )
  15. {
  16. return false;
  17. }
  18. bool PS3_IsConsoleConnected()
  19. {
  20. return false;
  21. }
  22. void PS3_InitConsoleMonitor( bool bWaitForConnect)
  23. {
  24. }
  25. void PS3_UpdateConsoleMonitor()
  26. {
  27. }
  28. int XBX_rAddCommands(int numCommands, const char* commands[], const char* help[])
  29. {
  30. return 0;
  31. }
  32. #else
  33. //Development
  34. static PS3_LoadAppSystemInterface_Parameters_t s_VXBDMPrxLoadParameters;
  35. IPS3Console *g_pValvePS3Console = NULL;
  36. // an empty implementation to use if the debug PRX isn't available
  37. class CPS3DummyDebugConsole : public IPS3Console
  38. {
  39. public:
  40. virtual void SendRemoteCommand( const char *dbgCommand, bool bAsync ) {}
  41. virtual void SendPrefixedDECIMessage( const char *prefix, const char *message, bool async ) {};
  42. virtual void DebugString( unsigned int color, const char *format, ... ) {}
  43. virtual bool IsConsoleConnected() {return false;}
  44. virtual void InitConsoleMonitor( bool bWaitForConnect = false ) {}
  45. virtual void DisconnectConsoleMonitor() {}
  46. virtual void FlushDebugOutput() {}
  47. virtual bool GetXboxName( char *, unsigned * ) { return false; }
  48. virtual void CrashDump( bool ) {}
  49. virtual void CrashDumpFullHeap( bool ) {}
  50. virtual void DumpDllInfo( const char *pBasePath ) {}
  51. // virtual void OutputDebugString( const char * ) = 0;
  52. virtual bool IsDebuggerPresent() { return false; }
  53. virtual int SetProfileAttributes( const char *pProfileName, int numCounters, const char *names[], COLORREF colors[] ) { return 0; }
  54. virtual void SetProfileData( const char *pProfileName, int numCounters, unsigned int *counters ) {}
  55. virtual int MemDump( const char *pDumpFileName ) { return -1; }
  56. virtual int TimeStampLog( float time, const char *pString ) { return -1; }
  57. virtual int MaterialList( int nMaterials, const xMaterialList_t *pXMaterialList ) { return -1; }
  58. virtual int TextureList( int nTextures, const xTextureList_t *pXTextureList ) { return -1; }
  59. virtual int SoundList( int nSounds, const xSoundList_t *pXSoundList ) { return -1; }
  60. virtual int MapInfo( const xMapInfo_t *pXMapInfo ) { return -1; }
  61. virtual int AddCommands( int numCommands, const char *commands[], const char* help[] ) { return -1; }
  62. virtual int ModelList( int nModels, const xModelList_t *pList ) { return -1; }
  63. virtual int DataCacheList( int nItems, const xDataCacheItem_t* pItems ) { return -1; }
  64. virtual int VProfNodeList( int nItems, const xVProfNodeItem_t *pItems ) { return -1; }
  65. virtual int TraceComplete( void ) { return -1; }
  66. virtual int BugReporter( void ) { return -1; }
  67. virtual bool SendBinaryData( const void *pData, int iDataSize, bool bAsync = true, DWORD dwSyncTimout = 15000 ) { return false; }
  68. virtual int SyncDvdDevCache() { return -1; }
  69. virtual int SyncShaderCache() { return -1; }
  70. virtual int Version( int nVersion ) { return -1; }
  71. virtual void TransmitScreenshot( char *pFrameBuffer, uint32 uWidth, uint32 uHeight, uint32 uPitch, uint32 uColorFmt ){ }
  72. virtual void PumpMessage( fRemoteCommandSink_t ) {}
  73. virtual int SendBinaryDECI( const uint8 *dbgCommand, uint length, bool ){return 0;}
  74. virtual void AddOnConnectDelegate( fOnConnectDelegate_t pOnConnectDelegate ) {};
  75. virtual void AddOnDisconnectDelegate( fOnDisconnectDelegate_t pOnDisconnectDelegate ) {};
  76. };
  77. CPS3DummyDebugConsole g_ValveDummyDebugConsoleForUseWhenThePRXContainingTheRealOneIsntAvailable;
  78. // try to load the debug library
  79. void ValvePS3ConsoleInit()
  80. {
  81. if ( g_pValvePS3Console != NULL )
  82. {
  83. AssertMsg(false,"Called ValvePS3ConsoleInit twice!\n");
  84. // emergency cleanup
  85. ValvePS3ConsoleShutdown();
  86. g_pValvePS3Console = NULL;
  87. }
  88. memset( &s_VXBDMPrxLoadParameters, 0, sizeof( s_VXBDMPrxLoadParameters ) );
  89. s_VXBDMPrxLoadParameters.cbSize = sizeof( s_VXBDMPrxLoadParameters );
  90. char szAbsoluteModuleName[1024];
  91. // getcwd not supported on ps3; use PRX path instead (TODO: fallback to DISK path too)
  92. snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s",
  93. g_pPS3PathInfo->PrxPath(), "vxbdm_ps3.sprx" );
  94. int loadresult = IsCert() ? ENOENT : PS3_PrxLoad( szAbsoluteModuleName, &s_VXBDMPrxLoadParameters );
  95. if ( loadresult < CELL_OK )
  96. {
  97. // we failed to load the module. This might be because we're a cert build, so it's fine.
  98. Msg("VXBDM: not loaded\n");
  99. g_pValvePS3Console = &g_ValveDummyDebugConsoleForUseWhenThePRXContainingTheRealOneIsntAvailable;
  100. }
  101. else // loaded successfully
  102. {
  103. g_pValvePS3Console = reinterpret_cast< IPS3Console *> ( (*s_VXBDMPrxLoadParameters.pfnCreateInterface)(NULL, NULL) );
  104. Msg("VXBDM: loaded %x!\n", loadresult);
  105. }
  106. }
  107. void ValvePS3ConsoleShutdown()
  108. {
  109. if ( !g_pValvePS3Console )
  110. return;
  111. g_pValvePS3Console = NULL;
  112. PS3_PrxUnload( s_VXBDMPrxLoadParameters.sysPrxId );
  113. };
  114. //defined in ps3_events.cpp, needed to process commands sent from the VXConsole
  115. extern void XBX_ProcessXCommand(const char* command);
  116. bool PS3_DebugString( unsigned int color, const char* format, ... )
  117. {
  118. return false;
  119. }
  120. bool PS3_IsConsoleConnected()
  121. {
  122. return false;
  123. }
  124. int XBX_rAddCommands(int numCommands, const char* commands[], const char* help[])
  125. {
  126. #if 0
  127. // PS3_UpdateConsoleMonitor();
  128. if(PS3_IsConsoleConnected())
  129. {
  130. /*
  131. for(int i=0;i<numCommands;i++)
  132. {
  133. sprintf(ps3ConsoleBuffer, "AddCommand() %s %s", commands[i], help[i]);
  134. sys_deci3_send(ps3ConsoleSessionId,(uint8_t*)ps3ConsoleBuffer,strlen(ps3ConsoleBuffer)+1);
  135. }
  136. return 1;
  137. */
  138. }
  139. #else
  140. Error("Deprecated function called.\n");
  141. #endif
  142. return 0;
  143. }
  144. void PS3_InitConsoleMonitor( bool bWaitForConnect )
  145. {
  146. Error("You didn't implement this you idiot\n");
  147. }
  148. //-----------------------------------------------------------------------------
  149. // XBX_ProcessXCommand
  150. //
  151. //-----------------------------------------------------------------------------
  152. void XBX_ProcessXCommand(const char* command)
  153. {
  154. #if 0 // This is the Windows way of doing things. We are not Windows.
  155. // if we WERE Windows, we would do this, which would call a function
  156. // which found a function pointer which called a function which
  157. // dispatched a switch which etc. etc....
  158. // by the way, function call overhead is at least 21 cycles on PS3.
  159. // remote command
  160. // pass it game via windows message
  161. HWND hWnd = GetFocus();
  162. WNDPROC windowProc = ( WNDPROC)GetWindowLong(hWnd, GWL_WNDPROC );
  163. if ( windowProc )
  164. {
  165. windowProc( hWnd, WM_XREMOTECOMMAND, 0, (LPARAM)command );
  166. }
  167. #elif 0 // until finally just doing this:
  168. ECommandTarget_t t = Cbuf_GetCurrentPlayer();
  169. Cbuf_AddText( t, command );
  170. Cbuf_AddText( t, "\n" );
  171. #else
  172. #pragma message("You must implement XBX_ProcessXCommand")
  173. #endif
  174. }
  175. void PS3_ReceiveCommand(const char *strCommand)
  176. {
  177. #if 0
  178. // skip over the command prefix and the exclamation mark
  179. strCommand += strlen( XBX_DBGCOMMANDPREFIX ) + 1;
  180. if ( strCommand[0] == '\0' )
  181. {
  182. // just a ping
  183. char tmp[1]={'\0'};
  184. sys_deci3_send(ps3ConsoleSessionId,(uint8_t*)tmp,1);
  185. goto cleanUp;
  186. }
  187. if ( strncmp( strCommand, "__connect__", 11 ) ==0)
  188. {
  189. //respond that we're connected
  190. sys_deci3_send(ps3ConsoleSessionId,(uint8_t*)strCommand,strlen(strCommand)+1);
  191. if(!isConsoleConnected)
  192. {
  193. //initial connect - get the console variables (used for autocomplete on the vxconsole)
  194. XBX_ProcessXCommand("getcvars");
  195. }
  196. isConsoleConnected=true;
  197. goto cleanUp;
  198. }
  199. if ( strncmp( strCommand, "__disconnect__", 14 ) ==0)
  200. {
  201. isConsoleConnected=false;
  202. goto cleanUp;
  203. }
  204. if ( strncmp( strCommand, "__complete__", 12 ) ==0)
  205. {
  206. //isn't used for ps3 vxconsole
  207. goto cleanUp;
  208. }
  209. if ( strncmp( strCommand, "__memory__", 10 ) ==0)
  210. {
  211. //...
  212. goto cleanUp;
  213. }
  214. XBX_ProcessXCommand(strCommand);
  215. cleanUp:
  216. return;
  217. #else
  218. Warning("PS3_ReceiveCommand() is not implemented.\n");
  219. #endif
  220. }
  221. void PS3_UpdateConsoleMonitor()
  222. {
  223. #if 0
  224. if(ps3ConsoleSessionId==-1)
  225. return;
  226. const int MAX_EVENTS=32;
  227. int numEvents;
  228. sys_event_t events[MAX_EVENTS];
  229. int ret = sys_event_queue_tryreceive(ps3ConsoleEventQueue, events,MAX_EVENTS, &numEvents);
  230. if(ret!=CELL_OK)
  231. {
  232. //fprintf(stderr, "sys_event_queue_tryreceive() failed: %d\n", ret);
  233. return;
  234. }
  235. for(int i=0;i<numEvents;i++)
  236. {
  237. sys_event &event=events[i];
  238. switch(event.data1)
  239. {
  240. case SYS_DECI3_EVENT_COMM_ENABLED:
  241. //(wait for a "__connect__" packet instead of assuming an enabled connection means its working)
  242. //isConsoleConnected=true;
  243. break;
  244. case SYS_DECI3_EVENT_COMM_DISABLED:
  245. isConsoleConnected=false;
  246. break;
  247. case SYS_DECI3_EVENT_DATA_READY:
  248. ret = sys_deci3_receive(ps3ConsoleSessionId,(uint8_t*)ps3ConsoleBuffer,event.data2);
  249. if(ret==CELL_OK)
  250. {
  251. PS3_ReceiveCommand(ps3ConsoleBuffer);
  252. }
  253. break;
  254. }
  255. }
  256. #endif
  257. }
  258. int XBX_rSetProfileAttributes(const char *pProfileName, int numCounters, const char *names[], COLORREF colors[])
  259. {
  260. return ( !g_pValvePS3Console ) ? 0 : g_pValvePS3Console->SetProfileAttributes( pProfileName, numCounters, names, colors );
  261. }
  262. void XBX_rSetProfileData( const char *pProfileName, int numCounters, unsigned int *counters )
  263. {
  264. g_pValvePS3Console->SetProfileData( pProfileName, numCounters, counters );
  265. }
  266. void XBX_rVProfNodeList( int nItems, const xVProfNodeItem_t *pItems )
  267. {
  268. g_pValvePS3Console->VProfNodeList( nItems, pItems );
  269. }
  270. #endif//!_RETAIL