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.

118 lines
4.9 KiB

  1. // The dtlibwrapper is an annoying workaround to make Sony's dtlib dll play
  2. // nicely with our exes (such as vxconsole).
  3. //
  4. // dtlib is Sony's library for bidirectional communication with the PS3 console.
  5. // (ie, it is the PC side of the DECI3 interface.)
  6. // dtlib.dllis linked against Microsoft�s dynamic C Runtime library.
  7. // VXConsole and all our libs are of course statically linked to the CRT so that
  8. // we can subvert malloc(). Ordinarily this wouldn�t really be a problem, except
  9. // that some functions in dtlib.dll pass and return STL strings by value:
  10. // HCONNECT dt_connect( std::string hostname, int portNo, std::string programName )
  11. // std::string dt_geterrormsg( int errorno )
  12. // This causes a crash because it guarantees that memory will be allocated on one
  13. // side of the DLL boundary and deallocated on the other (because of the pass-by-
  14. // value semantics).
  15. //
  16. // Therefore we construct this tiny DLL which links against the DLL version of
  17. // msft's runtime, and whose only purpose is to reexport functions which expect
  18. // a std::string parameter into ones that use char *s. By ensuring that
  19. // std::strings are only constructed or destructed on this side of the DLL boundary,
  20. // we avoid trouble with the free store.
  21. #ifndef DTLIBWRAPPER_H
  22. #define DTLIBWRAPPER_H
  23. #pragma once
  24. #ifdef DTLIBWRAPPER_DLL_EXPORT
  25. #define DTLIBWRAP_API __declspec(dllexport)
  26. #else
  27. #define DTLIBWRAP_API __declspec(dllimport)
  28. #endif
  29. #include "dtlib.h"
  30. // #include <string>
  31. // #include <vector>
  32. // This is the API for the dtlib; you get a pointer
  33. // to this class instance and then call its functions.
  34. // Call the static GetSingleton() to get the instance
  35. // of this.
  36. class DTLIBWRAP_API Idtwrap
  37. {
  38. public:
  39. /*
  40. // local typedefs to shadow (but be equal to) the global ones
  41. // copied from dtlib.h
  42. typedef HANDLE HCONNECT;
  43. typedef HANDLE HDECI;
  44. typedef HANDLE HSELECT;
  45. typedef HANDLE HDRIVER;
  46. typedef HANDLE HPROTO;
  47. typedef BOOL (CALLBACK DECIRECVPROC)(HDECI, BYTE*, int size, int status);
  48. typedef BOOL (CALLBACK DCMPRECVPROC)(HCONNECT, BYTE*, int size);
  49. typedef BOOL (CALLBACK DRIVERRECVPROC)(HDRIVER, BYTE*, int size);
  50. typedef enum DT_DESTINATION {
  51. HOST = 0, // Host Application
  52. MGR = 1, // Communication Processor
  53. TARGET = 2, // Protocol Driver
  54. };
  55. */
  56. virtual UINT32 dt_set_option(UINT32 value) = 0 ;
  57. virtual HCONNECT dt_connect(const char * hostname, int portNo,
  58. const char * programName) = 0;
  59. virtual void dt_disconnect(HCONNECT connect) = 0 ;
  60. virtual HDECI dt_register(HCONNECT connectH, int protocol, int port,
  61. deci3_lib::DT_DESTINATION dst, const char * lparName,
  62. int priority=128) = 0;
  63. virtual int dt_unregister(HDECI deciHandle) = 0 ;
  64. virtual int dt_send(HDECI deciHandle, BYTE* data, int length) = 0 ;
  65. virtual int dt_receive(HANDLE deciHandle, BYTE* data, int length) = 0 ;
  66. // error & error messages
  67. virtual int dt_getlasterror() = 0 ;
  68. // signature differs from dtlib:
  69. // you pass in a pointer to a (preallocated) buffer in which to store the error.
  70. // returns the length of the original string ( if it's greater than buflen, you
  71. // didn't get the whole string )
  72. virtual int dt_geterrormsg( char *pOutBuf, unsigned int bufLen, int error) = 0 ;
  73. virtual int dt_get_protocol(HANDLE handle, int &protocol, int &port) = 0 ; // deprecated
  74. // signatures on these change from dtlib:
  75. // instead of returning a std::vector, these
  76. // function accept a pointer to a (preallocated
  77. // by you) array of the underlying structs,
  78. // and the max length of that array.
  79. // It will copy the structs into the array and return
  80. // the number of structs it wanted to copy. If that
  81. // number is greater than the size of the buffer you fed
  82. // in, you didn't get the whole result.
  83. virtual int dt_get_registered_list( DtRegisteredInfo* pOutArray, unsigned int outLen, HCONNECT connectH) = 0 ;
  84. virtual int dt_get_protocol_list( DtProtocolInfo *pOutArray, unsigned int outLen, HCONNECT connectH, const char * lparName) = 0 ;
  85. enum { kLPAR_NAME_LENGTH = 64 };
  86. // as above, but note that you are passing in an array of
  87. // arrays: the inner dimension must be the constant kLPAR_NAME_LENGTH
  88. virtual int dt_get_lparlist( char pOutBufs[][kLPAR_NAME_LENGTH], unsigned int numBufs, HCONNECT connectH) = 0 ;
  89. virtual int dt_get_version( char *pOutBuf, unsigned int bufLen, HCONNECT connectH) = 0 ;
  90. virtual int dt_power_status(HCONNECT connH, int &status) = 0 ;
  91. virtual HANDLE dt_select(HCONNECT connH, int waitTime) = 0 ;
  92. virtual int dt_set_dcmp_status_function(HCONNECT connectH, DCMPRECVPROC* func) = 0 ;
  93. virtual int dt_add_recv_function(HDECI deciH, DECIRECVPROC* func) = 0 ;
  94. virtual int dt_delete_recv_function(HDECI deciH) = 0 ;
  95. virtual int dt_send_dcmp(HCONNECT connectH, const char * lparName, BYTE *data, int dataSize) = 0 ;
  96. virtual int dt_set_dcmp_echo_function(HCONNECT connectH, DCMPRECVPROC* func) = 0 ;
  97. static Idtwrap *GetSingleton();
  98. };
  99. #endif // DTLIBWRAPPER_H