DiosConsoleScript.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #pragma once
  2. // 下列 ifdef 块是创建使从 DLL 导出更简单的
  3. // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 CCOSCONSOLESCRIPT_EXPORTS
  4. // 符号编译的。在使用此 DLL 的
  5. // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
  6. // CCOSCONSOLESCRIPT_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
  7. // 符号视为是被导出的。
  8. #ifndef CCOSCONSOLESCRIPT_EXPORTS
  9. #ifdef _WIN64
  10. #ifdef _DEBUG
  11. #define DCSBASE "CcosConsoleScriptX64D"
  12. #pragma comment(lib, "CcosConsoleScriptX64D.lib")
  13. #else
  14. #define DCSBASE "CcosConsoleScriptX64"
  15. #pragma comment(lib, "CcosConsoleScriptX64.lib")
  16. #endif
  17. #else
  18. #ifdef _DEBUG
  19. #define DCSBASE "CcosConsoleScriptD"
  20. #pragma comment(lib, "CcosConsoleScriptD.lib")
  21. #else
  22. #define DCSBASE "CcosConsoleScript"
  23. #pragma comment(lib, "CcosConsoleScript.lib")
  24. #endif
  25. #endif
  26. #endif
  27. #ifdef CCOSCONSOLESCRIPT_EXPORTS
  28. #define CCOSCONSOLESCRIPT_API __declspec(dllexport)
  29. #define CCOSCONSOLESCRIPT_CAPI extern "C" __declspec(dllexport)
  30. #else
  31. #define CCOSCONSOLESCRIPT_API __declspec(dllimport)
  32. #define CCOSCONSOLESCRIPT_CAPI extern "C" __declspec(dllimport)
  33. #endif
  34. typedef enum _DCS_RET {
  35. DCS_NOT_SUPPORT = -1,
  36. DCS_FAILED = 0,
  37. DCS_SUCCEED = 1,
  38. DCS_MAX
  39. }DCS_RET;
  40. #include <map>
  41. #include <string>
  42. #include "ResDataObject.h"
  43. #pragma warning( push )
  44. #pragma warning( disable : 4311 )
  45. #pragma warning( disable : 4312 )
  46. #pragma warning( disable : 4302 )
  47. template <class T1>
  48. DCS_RET TempRunClassFunc(T1 *p, ResDataObject &Req)
  49. {
  50. DCS_RET ret = DCS_NOT_SUPPORT;
  51. typedef DCS_RET (T1::*classMember) (ResDataObject &Req);
  52. typedef union _funcContext {
  53. classMember func;
  54. UINT32 Addr32;
  55. UINT64 Addr64;
  56. }FUNCCONTEXT;
  57. FUNCCONTEXT fc;
  58. memset(&fc, 0, sizeof(fc));
  59. const char *pFunc = p->GetFunc((const char*)Req[0]);
  60. if (pFunc)
  61. {
  62. if (sizeof(char*) == 4)
  63. {
  64. //RegistIF((char*)(fc.Addr32));
  65. fc.Addr32 = (UINT32)pFunc;
  66. }
  67. else if (sizeof(char*) == 8)
  68. {
  69. //RegistIF((char*)(fc.Addr64));
  70. fc.Addr64 = (UINT64)pFunc;
  71. }
  72. classMember Func = fc.func;
  73. if (Func)
  74. {
  75. return (p->*Func)(Req);
  76. }
  77. }
  78. return ret;
  79. }
  80. #define MacroRun(Req) TempRunClassFunc(this,Req)
  81. template <class T1, class T2>
  82. bool TempRegistClassFunc(T1 *p, T2 Addr, const char *pCmd)
  83. {
  84. typedef DCS_RET (T1::*classMember) (ResDataObject &Req);
  85. classMember func = (classMember)Addr;
  86. typedef union _funcContext {
  87. classMember func;
  88. UINT32 Addr32;
  89. UINT64 Addr64;
  90. }FUNCCONTEXT;
  91. FUNCCONTEXT fc;
  92. memset(&fc, 0, sizeof(fc));
  93. fc.func = func;
  94. if (sizeof(char*) == 4)
  95. {
  96. return p->MakeCmd(pCmd,(char*)(fc.Addr32));
  97. //RegistIF((char*)(fc.Addr32));
  98. }
  99. else if (sizeof(char*) == 8)
  100. {
  101. //RegistIF((char*)(fc.Addr64));
  102. return p->MakeCmd(pCmd, (char*)(fc.Addr64));
  103. }
  104. assert(0);
  105. return false;
  106. }
  107. #pragma warning( pop )
  108. #define MacroRegist(ClassType,Addr) TempRegistClassFunc<ClassType>(this,&ClassType::Addr,#Addr)
  109. //#define RUNCMD(CLASSTYPE,Req) { \
  110. // DCS_RET ret = DCS_NOT_SUPPORT; \
  111. // PVOID Addr = GetCmd((const char *)#Req[0]); \
  112. // if (Addr) { \
  113. // typedef DCS_RET(#CLASSTYPE"::"*ClassFunc)(ResDataObject &Req); \
  114. // ClassFunc Func = (ClassFunc)Addr; \
  115. // ret = ((*this).*ClassFunc)(Req); \
  116. // } \
  117. // return ret; \
  118. //} \
  119. // 此类是从 CcosConsoleScript.dll 导出的
  120. class CCOSCONSOLESCRIPT_API CcosConsoleScript {
  121. map<string, const char*> *m_pCommandMap;
  122. public:
  123. CcosConsoleScript(void);
  124. virtual ~CcosConsoleScript();
  125. bool MakeCmd(const char *pCmd, const char* pClassFunc);
  126. const char* GetFunc(const char *pCmd);
  127. virtual void Help();
  128. //inputcmd : helloworld 2020 Joy_Derk
  129. //[0]:helloworld
  130. //[1]:2020
  131. //[2]:Joy_Derk
  132. //[0]:command,[1]:P1,[2]:P2...
  133. static ResDataObject SeperateCommand(const char *pReq);
  134. virtual DCS_RET Command(ResDataObject &Req);
  135. };
  136. //CCOSCONSOLESCRIPT_CAPI CcosConsoleScript* LoadDCS();//user要集成此功能
  137. typedef CcosConsoleScript* (*LOADDCS)();
  138. typedef void(*UNLOADDCS)(CcosConsoleScript *p);