1
0

irctell.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include <windows.h>
  2. #include "irctell.h"
  3. #include <api/syscb/api_syscb.h>
  4. #include <api/core/api_core.h>
  5. #include "api__irctell.h"
  6. #include <api/service/waservicefactory.h>
  7. #include "dde.h"
  8. #include <strsafe.h>
  9. static WACIrctell Irctell;
  10. extern "C" __declspec(dllexport) ifc_wa5component *GetWinamp5SystemComponent()
  11. {
  12. return &Irctell;
  13. }
  14. bool dotell=true;
  15. api_syscb *sysCallbackApi=0;
  16. api_core *core=0;
  17. api_service *WASABI_API_SVC = 0;
  18. void WACIrctell::RegisterServices(api_service *service)
  19. {
  20. WASABI_API_SVC = service;
  21. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(syscbApiServiceGuid);
  22. if (sf) sysCallbackApi = reinterpret_cast<api_syscb *>(sf->getInterface());
  23. sysCallbackApi->syscb_registerCallback(static_cast<SysCallback *>(this));
  24. sf = WASABI_API_SVC->service_getServiceByGuid(coreApiServiceGuid);
  25. if (sf) core = reinterpret_cast<api_core *>(sf->getInterface());
  26. if (core)
  27. core->core_addCallback(0, this);
  28. }
  29. void WACIrctell::DeregisterServices(api_service *service)
  30. {
  31. // be sure to delete all your windows etc HERE, not in the destructor
  32. // because the API pointer might be invalid in the destructor
  33. // if (core)
  34. // core->core_delCallback(0, this);
  35. }
  36. /*
  37. void WACIrctell::onRegisterServices() {
  38. dotell.setName("Enabled");
  39. dotell=0;
  40. registerAttribute(&dotell);
  41. appstr.setName("DDE Target");
  42. appstr="mIRC";
  43. registerAttribute(&appstr);
  44. cmdstr.setName("DDE Command");
  45. cmdstr="/me is listening to %s";
  46. registerAttribute(&cmdstr);
  47. }
  48. */
  49. int WACIrctell::ccb_notify(int msg, int param1, int param2)
  50. {
  51. if (msg==TITLECHANGE && dotell)
  52. {
  53. const wchar_t *title = (const wchar_t *)param1;
  54. const wchar_t *cur=core->core_getCurrent(0);
  55. wchar_t msg[256];
  56. StringCchPrintfW(msg, 256, L"/describe #winamp is now listening to \"%s\"", title);
  57. DdeCom::sendCommand(L"mIRC", msg, 1000);
  58. }
  59. return 0;
  60. }
  61. FOURCC WACIrctell::getEventType()
  62. {
  63. return SysCallback::SERVICE;
  64. }
  65. int WACIrctell::notify(int msg, int param1, int param2)
  66. {
  67. switch(msg)
  68. {
  69. case SvcCallback::ONREGISTER:
  70. {
  71. waServiceFactory *sf = (waServiceFactory *)param2;
  72. if (sf->getGuid() == coreApiServiceGuid)
  73. {
  74. core = reinterpret_cast<api_core *>(sf->getInterface());
  75. core->core_addCallback(0, this);
  76. }
  77. }
  78. break;
  79. case SvcNotify::ONDEREGISTERED:
  80. {
  81. waServiceFactory *sf = (waServiceFactory *)param2;
  82. if (sf->getGuid() == coreApiServiceGuid)
  83. {
  84. if (core)
  85. core->core_delCallback(0, this);
  86. core = 0;
  87. }
  88. }
  89. break;
  90. }
  91. return 0;
  92. }
  93. #define CBCLASS WACIrctell
  94. START_MULTIPATCH;
  95. START_PATCH(patch_wa5)
  96. M_VCB(patch_wa5, ifc_wa5component, API_WA5COMPONENT_REGISTERSERVICES, RegisterServices);
  97. M_VCB(patch_wa5, ifc_wa5component, API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices);
  98. NEXT_PATCH(patch_core)
  99. M_CB(patch_core, CoreCallback, CCB_NOTIFY, ccb_notify);
  100. NEXT_PATCH(patch_svc)
  101. M_CB(patch_svc, SysCallback, SYSCALLBACK_GETEVENTTYPE, getEventType);
  102. M_CB(patch_svc, SysCallback, SYSCALLBACK_NOTIFY, notify);
  103. END_PATCH
  104. END_MULTIPATCH;
  105. #undef CBCLASS