MPMGRW.CPP 7.6 KB

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