MPMGRW.CPP 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. #if (0)//PG
  15. #ifndef MP_LOAD_DLL_DYNAMICALLY
  16. #define MP_LOAD_DLL_DYNAMICALLY
  17. #endif
  18. #include "mpmgrw.h"
  19. extern "C" {
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. }
  25. #include <windows.h>
  26. #define STATUS_OK 1
  27. #define STATUS_BAD 0
  28. #define BROADCAST_ADDR 0
  29. #define PRIVATE 0
  30. #define PUBLIC 1
  31. #define min(a,b) (((a) < (b)) ? (a) : (b))
  32. typedef void __cdecl (*MPlayerInit_Type)(void);
  33. typedef void __cdecl (*MPlayerDestroy_Type)(void);
  34. typedef int __cdecl (*Send_Private_Message_Type)(void *buf,
  35. int buflen,
  36. int ack_req,
  37. int conn_id);
  38. typedef int __cdecl (*Get_Private_Message_Type)(void *buf, int *buflen,
  39. int *conn_id);
  40. typedef int __cdecl (*Send_Global_Message_Type)(void *buf, int buflen, int ack_req,
  41. int addr);
  42. typedef int __cdecl (*Get_Global_Message_Type)(void *buf, int *buflen, int *address);
  43. typedef int __cdecl (*Create_Connection_Type)(int id, char *name, int address);
  44. typedef int __cdecl (*Delete_Connection_Type)(int id);
  45. typedef char * __cdecl (*Connection_Name_Type)(int id);
  46. typedef int __cdecl (*Connection_Address_Type)(int id);
  47. typedef int __cdecl (*Num_Connections_Type)(void);
  48. typedef int __cdecl (*Connection_ID_Type)(int id);
  49. typedef int __cdecl (*Connection_Index_Type)(int id);
  50. typedef int __cdecl (*Init_Type)(void);
  51. typedef int __cdecl (*Find_Num_Connections_Type)(void);
  52. MPlayerInit_Type MPlayerManCreate;
  53. MPlayerDestroy_Type MPlayerManDestroy;
  54. Send_Private_Message_Type Send_Private_Message_DLL;
  55. Get_Private_Message_Type Get_Private_Message_DLL;
  56. Send_Global_Message_Type Send_Global_Message_DLL;
  57. Get_Global_Message_Type Get_Global_Message_DLL;
  58. Create_Connection_Type Create_Connection_DLL;
  59. Delete_Connection_Type Delete_Connection_DLL;
  60. Connection_Name_Type Connection_Name_DLL;
  61. Connection_Address_Type Connection_Address_DLL;
  62. Num_Connections_Type Num_Connections_DLL;
  63. Connection_ID_Type Connection_ID_DLL;
  64. Connection_Index_Type Connection_Index_DLL;
  65. Init_Type Init_DLL;
  66. Find_Num_Connections_Type Find_Num_Connections_DLL;
  67. FARPROC MPGetProcAddress(HMODULE hModule, LPCSTR lpProcName) {
  68. FARPROC ret=GetProcAddress(hModule, lpProcName);
  69. if (!ret) {
  70. char msg[255];
  71. sprintf(msg, "Unable to load function %s from %s",
  72. lpProcName, "RA95MP.DLL");
  73. MessageBox(0, msg, "Warning", MB_OK);
  74. }
  75. return ret;
  76. }
  77. MPlayerManClass::MPlayerManClass(void) : ConnManClass()
  78. {
  79. HMODULE lib;
  80. lib = LoadLibrary("ra95mp.dll");
  81. if (lib != 0) {
  82. MPlayerManCreate = (MPlayerInit_Type) MPGetProcAddress(lib,
  83. "MPlayerManCreate");
  84. MPlayerManDestroy = (MPlayerDestroy_Type) MPGetProcAddress(lib,
  85. "MPlayerManDestroy");
  86. Send_Private_Message_DLL = (Send_Private_Message_Type) MPGetProcAddress(lib,
  87. "Send_Private_Message");
  88. Get_Private_Message_DLL = (Get_Private_Message_Type) MPGetProcAddress(lib,
  89. "Get_Private_Message");
  90. Send_Global_Message_DLL = (Send_Global_Message_Type) MPGetProcAddress(lib,
  91. "Send_Global_Message");
  92. Get_Global_Message_DLL = (Get_Global_Message_Type) MPGetProcAddress(lib,
  93. "Get_Global_Message");
  94. Create_Connection_DLL = (Create_Connection_Type) MPGetProcAddress(lib,
  95. "Create_Connection");
  96. Delete_Connection_DLL = (Delete_Connection_Type) MPGetProcAddress(lib,
  97. "Delete_Connection");
  98. Connection_Name_DLL = (Connection_Name_Type) MPGetProcAddress(lib,
  99. "Connection_Name");
  100. Connection_Address_DLL = (Connection_Address_Type) MPGetProcAddress(lib,
  101. "Connection_Address");
  102. Num_Connections_DLL = (Num_Connections_Type) MPGetProcAddress(lib,
  103. "Num_Connections");
  104. Connection_ID_DLL = (Connection_ID_Type) MPGetProcAddress(lib,
  105. "Connection_ID");
  106. Connection_Index_DLL = (Connection_Index_Type) MPGetProcAddress(lib,
  107. "Connection_Index");
  108. Init_DLL = (Init_Type) MPGetProcAddress(lib,
  109. "Init");
  110. Find_Num_Connections_DLL = (Find_Num_Connections_Type) MPGetProcAddress(lib,
  111. "Find_Num_Connections");
  112. } else {
  113. MessageBox(0, "RA95MP.DLL not found!", "Warning", MB_OK);
  114. exit(0);
  115. }
  116. if (MPlayerManCreate != 0) {
  117. MPlayerManCreate();
  118. }
  119. }
  120. MPlayerManClass::~MPlayerManClass()
  121. {
  122. MPlayerManDestroy();
  123. }
  124. // here's what we do to get private & broadcasts over the same chunnel
  125. // we package up an extra dword at the beginning to indicate the address
  126. int
  127. MPlayerManClass::Send_Private_Message(void *buf,
  128. int buflen,
  129. int ack_req,
  130. int conn_id)
  131. {
  132. return Send_Private_Message_DLL(buf, buflen, ack_req, conn_id);
  133. }
  134. int
  135. MPlayerManClass::Get_Private_Message(void *buf, int *buflen,
  136. int *conn_id)
  137. {
  138. return Get_Private_Message_DLL(buf, buflen, conn_id);
  139. }
  140. int
  141. MPlayerManClass::Send_Global_Message(void *buf, int buflen, int ack_req,
  142. int addr)
  143. {
  144. return Send_Global_Message_DLL(buf, buflen, ack_req, addr);
  145. }
  146. int
  147. MPlayerManClass::Get_Global_Message(void *buf, int *buflen, int *address)
  148. {
  149. return Get_Global_Message_DLL(buf, buflen, address);
  150. }
  151. int
  152. MPlayerManClass::Service(void)
  153. {
  154. return STATUS_OK;
  155. }
  156. int
  157. MPlayerManClass::Create_Connection(int id, char *name, int address)
  158. {
  159. return Create_Connection_DLL(id, name, address);
  160. }
  161. int
  162. MPlayerManClass::Delete_Connection(int id)
  163. {
  164. return Delete_Connection_DLL(id);
  165. }
  166. char *
  167. MPlayerManClass::Connection_Name(int id)
  168. {
  169. return Connection_Name_DLL(id);
  170. }
  171. int
  172. MPlayerManClass::Connection_Address(int id)
  173. {
  174. return Connection_Address_DLL(id);
  175. }
  176. int
  177. MPlayerManClass::Num_Connections(void)
  178. {
  179. return Num_Connections_DLL();
  180. }
  181. int
  182. MPlayerManClass::Connection_ID(int index)
  183. {
  184. return Connection_ID_DLL(index);
  185. }
  186. int
  187. MPlayerManClass::Connection_Index(int id)
  188. {
  189. return Connection_Index_DLL(id);
  190. }
  191. int
  192. MPlayerManClass::Global_Num_Send(void)
  193. {
  194. return 0;
  195. }
  196. int
  197. MPlayerManClass::Global_Num_Receive(void)
  198. {
  199. return 0;
  200. // return MGenGetQueueCtr(GDOSPENDINGQUEUE);
  201. }
  202. int
  203. MPlayerManClass::Private_Num_Send(int /*id*/)
  204. {
  205. return 0;
  206. }
  207. int
  208. MPlayerManClass::Private_Num_Receive(int /*id*/)
  209. {
  210. return 0;
  211. }
  212. void
  213. MPlayerManClass::Reset_Response_Time(void)
  214. {
  215. // unsupported
  216. }
  217. unsigned long
  218. MPlayerManClass::Response_Time(void)
  219. {
  220. return (160 * 60) / 1000; // 160 microseconds one way (9 ticks)
  221. }
  222. void
  223. MPlayerManClass::Set_Timing(unsigned long /*retrydelta*/,
  224. unsigned long /*maxretries*/,
  225. unsigned long /*timeout*/)
  226. {
  227. // unsupported
  228. }
  229. void
  230. MPlayerManClass::Configure_Debug(int /*index*/, int /*type_offset*/,
  231. int /*type_size*/, char ** /*names*/,
  232. int /*namestart*/, int /*namecount*/)
  233. {
  234. // unsupported
  235. }
  236. void
  237. MPlayerManClass::Mono_Debug_Print(int /*index*/, int /*refresh*/)
  238. {
  239. // unsupported
  240. }
  241. int
  242. MPlayerManClass::Init(void)
  243. {
  244. return Init_DLL();
  245. }
  246. int MPlayerManClass::Find_Num_Connections(void)
  247. {
  248. return Find_Num_Connections_DLL();
  249. }
  250. void MPlayerManClass::Flush_All(void)
  251. {
  252. }
  253. #endif