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