RakNetCSharpTypeMaps.i 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. //------------------------------TypeMaps--------------------------
  2. //Swig typemaps help to either convert a C++ type into a C# type or tell it which types are the same
  3. //Swig typemaps also can modify the postprocessed C++ file as well as the postprocessed C# files
  4. //For example the cscode typemap is used extensively to write C# code into the postprocessed file
  5. //In the below section INOUT is used when the array needs to be passed in and results need copied out
  6. //INPUT is used for just a copy in
  7. //OUTPUT is used just for a copy out
  8. //Any pointers or references will need a typemap to be used in the original api form, otherwise it
  9. //Will show up as SWIGTYPE_p_int
  10. //NOTE: The typmaps are commented for the first class they are specifically made for, that doesn't mean other classes do not depend on the typemaps, once a typemap is defined it applies to all instances
  11. //Allow array of strings
  12. CSHARP_ARRAYS(char *,string)
  13. //INOUT char to byte array
  14. //This is used because RakNet uses char arrays as byte arrays, C# char arrays are unicode
  15. %apply unsigned char INOUT[] {unsigned char* inputByteArray};
  16. %apply unsigned char INOUT[] {unsigned char* inByteArray};
  17. %apply unsigned char INOUT[] {unsigned char* inByteArray2};
  18. %apply unsigned char INOUT[] {unsigned char* inOutByteArray};
  19. %apply unsigned char INOUT[] {unsigned char* _data};
  20. %apply unsigned char INOUT[] {unsigned char* inOutData};
  21. //TeamBalancer
  22. %apply unsigned short INOUT[] {unsigned short *values};
  23. //RakPeer
  24. %apply unsigned char INOUT[] {unsigned char* passwordDataByteArray};
  25. %typemap(ctype) unsigned char *inByteArrayArray "unsigned char*"
  26. %typemap(cstype) unsigned char *inByteArrayArray "byte[,]"
  27. %typemap(imtype, inattributes="[In, MarshalAs(UnmanagedType.LPArray)]") unsigned char *inByteArrayArray "byte[,]"
  28. %typemap(csin) unsigned char *inByteArrayArray "$csinput"
  29. %typemap(in) unsigned char *inByteArrayArray "$1 = $input;"
  30. %typemap(freearg) unsigned char *inByteArrayArray ""
  31. %typemap(argout) unsigned char *inByteArrayArray ""
  32. %apply int INOUT[] {int *lengths};
  33. //Other inout - RakPeer
  34. %apply unsigned int INOUT[] {unsigned int outputFrequencyTable[ 256 ]};
  35. %apply unsigned int INOUT[] {unsigned int inputFrequencyTable[ 256 ]};
  36. %apply unsigned short * INOUT {unsigned short *numberOfSystems };
  37. //For the read functions, out vars
  38. %apply long long &OUTPUT {long long &outTemplateVar};
  39. %apply long &OUTPUT {long &outTemplateVar};
  40. %apply short &OUTPUT {short &outTemplateVar};
  41. %apply bool &OUTPUT {bool &outTemplateVar};
  42. %apply float &OUTPUT {float &outTemplateVar};
  43. %apply float &OUTPUT {float &outFloat};
  44. %apply unsigned char &OUTPUT {unsigned char &outTemplateVar};
  45. //RakPeer inout
  46. %apply int *INOUT {int *passwordDataLength};
  47. //RakPeer out,ByteQueue out
  48. %apply unsigned int *OUTPUT {unsigned int *outLength};
  49. //RakNetStatistics
  50. %apply unsigned int OUTPUT[] {unsigned int *inUnsignedIntArray};
  51. %apply unsigned long long OUTPUT[] {unsigned long long *inUint64Array};
  52. //%apply ulong OUTPUT[] {uint64_t *inUint64Array};
  53. %apply double OUTPUT[] {double *inDoubleArray};
  54. //Inouts for serialize and such
  55. %apply long long &INOUT {long long &inOutTemplateVar};
  56. %apply long &INOUT {long &inOutTemplateVar};
  57. %apply short &INOUT {short &inOutTemplateVar};
  58. %apply unsigned short &INOUT {unsigned short &inOutTemplateVar};
  59. %apply bool &INOUT {bool &inOutTemplateVar};
  60. %apply float &INOUT {float &inOutTemplateVar};
  61. %apply float &INOUT {float &inOutFloat};
  62. %apply unsigned char &INOUT {unsigned char &inOutTemplateVar};
  63. %apply long long &INOUT {long long &inOutCurrentValue};
  64. %apply long &INOUT {long &inOutCurrentValue};
  65. %apply short &INOUT {short &inOutCurrentValue};
  66. %apply unsigned short &INOUT {unsigned short &inOutCurrentValue};
  67. %apply bool &INOUT {bool &inOutCurrentValue};
  68. %apply float &INOUT {float &inOutCurrentValue};
  69. %apply float &INOUT {float &inOutCurrentValue};
  70. %apply unsigned char &INOUT {unsigned char &inOutCurrentValue};
  71. //UDPForwarder
  72. %apply unsigned short *OUTPUT {unsigned short *forwardingPort}
  73. %apply __UDPSOCKET__ *OUTPUT {__UDPSOCKET__ *forwardingSocket}
  74. //CommandParserInterface
  75. %apply char * INPUT[] {char **parameterList}
  76. //DataStructures::Table
  77. %apply int *OUTPUT {int *output};
  78. %apply int *OUTPUT {int *outputLength};
  79. %apply int *INOUT {unsigned *key};
  80. %apply unsigned int INPUT[] {unsigned *columnIndicesSubset}
  81. %apply unsigned int INPUT[] {unsigned *rowIds}
  82. %apply double *OUTPUT {double *output}
  83. //UDPForwarder
  84. %apply unsigned short *OUTPUT {unsigned short *forwardingPort}
  85. %apply unsigned int *OUTPUT {SOCKET *forwardingSocket}
  86. //ConnectionGraph2
  87. %apply unsigned int *INOUT {unsigned int *inOutLength};
  88. %apply DataStructures::DefaultIndexType *OUTPUT {DataStructures::DefaultIndexType *participantListSize};
  89. //AWSSimpleDBInterface
  90. //Define RakString as a simple object situation Only needed once
  91. SIMPLE_OBJECT_OUTPUT_TYPEMAP(RakNet::RakString,RakString)
  92. //Apply to the specific function parameters, need for each parameter
  93. //out prefixed items like outItemCount help prevent mistakes
  94. %apply RakNet::RakString &OUTPUT {RakNet::RakString &itemCount};
  95. %apply RakNet::RakString &OUTPUT {RakNet::RakString &columnCount};
  96. %apply RakNet::RakString &OUTPUT {RakNet::RakString &rowCount};
  97. //Classless
  98. #ifdef SWIG_ADDITIONAL_AUTOPATCHER
  99. %apply unsigned int *OUTPUT {unsigned *outSize};//For CreatePatch function
  100. %apply bool *OUTPUT {bool *outBool};//For CreatePatch function
  101. #endif
  102. //The next few items are to convert members arrays into something nativly accessable in C#
  103. //For example struct a {unsigned char * array1;}; is not processed by Swig, there is no easy way to do it but these
  104. //Typemaps handle it so it is accessable as a byte[] array, this applies to other types of arrays as well.
  105. //----------------byte array out charmap for ByteQueue
  106. %typemap(cstype, out="byte[]") unsigned char* PeekContiguousBytesHelper "byte[]"
  107. %typemap(csout, excode=SWIGEXCODE2) unsigned char* PeekContiguousBytesHelper
  108. %{
  109. {
  110. IntPtr cPtr = RakNetPINVOKE.ByteQueue_PeekContiguousBytesHelper(swigCPtr, out outLength);
  111. int len = (int)outLength;
  112. if (len <= 0)
  113. {
  114. return null;
  115. }
  116. byte[] returnBytes = new byte[len];
  117. Marshal.Copy(cPtr, returnBytes, 0, len);
  118. return returnBytes;
  119. }
  120. %}
  121. //This is more efficient than the loop version but less compatible
  122. /*
  123. Vars:
  124. BOOLNAME- The name of the variable that keeps track of if it is cached, typically varIsCached
  125. CACHENAME- The name of the variable C# cache typically varCache
  126. CTYPE- The type in C of the var
  127. INCSTYPE- C# type
  128. INTERMEDIATETYPE- Type that is worked with in the function
  129. IN_DATA_CHANGE_FUNCTION- The name of the set function, Typically SetVar
  130. IN_DATA_GET_FUNCTION- The get function for that data in the pinvoke, typically Class_var_get
  131. IN_CLASS- The class we are working with
  132. IN_LEN_METHOD- Something to get the length of the C/C++ array for marshalling. This is called from C#, not C.
  133. */
  134. %define STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP(BOOLNAME,CACHENAME,CTYPE,INCSTYPE,INTERMEDIATETYPE,IN_DATA_CHANGE_FUNCTION,IN_DATA_GET_FUNCTION,IN_CLASS,IN_LEN_METHOD)
  135. %typemap(cstype, out="INCSTYPE[]") CTYPE "INCSTYPE[]"
  136. %typemap(csvarin, excode=SWIGEXCODE2) CTYPE
  137. %{
  138. set
  139. {
  140. CACHENAME=value;
  141. BOOLNAME = true;
  142. IN_DATA_CHANGE_FUNCTION (value, value.Length);
  143. }
  144. %}
  145. %typemap(csvarout, excode=SWIGEXCODE2) CTYPE
  146. %{
  147. get
  148. {
  149. INCSTYPE[] returnArray;
  150. if (!BOOLNAME)
  151. {
  152. IntPtr cPtr = RakNetPINVOKE.IN_DATA_GET_FUNCTION (swigCPtr);
  153. int len = (int) IN_LEN_METHOD;
  154. if (len<=0)
  155. {
  156. return null;
  157. }
  158. returnArray = new INCSTYPE[len];
  159. INTERMEDIATETYPE[] marshalArray = new INTERMEDIATETYPE[len];
  160. Marshal.Copy(cPtr, marshalArray, 0, len);
  161. marshalArray.CopyTo(returnArray, 0);
  162. CACHENAME = returnArray;
  163. BOOLNAME = true;
  164. }
  165. else
  166. {
  167. returnArray = CACHENAME;
  168. }
  169. return returnArray;
  170. }
  171. %}
  172. %enddef
  173. //More compatible version of the above macro
  174. //One new variable CONVERSION_MODIFIER that converts the type in the marshalarray to output array
  175. //this can be a function or a typecast if a function leave out the parentheses
  176. %define STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP_LOOP_COPY(BOOLNAME,CACHENAME,CTYPE,INCSTYPE,INTERMEDIATETYPE,IN_DATA_CHANGE_FUNCTION,IN_DATA_GET_FUNCTION,IN_CLASS,IN_LEN_METHOD,CONVERSION_MODIFIER)
  177. %typemap(cstype, out="INCSTYPE[]") CTYPE "INCSTYPE[]"
  178. %typemap(csvarin, excode=SWIGEXCODE2) CTYPE
  179. %{
  180. set
  181. {
  182. CACHENAME=value;
  183. BOOLNAME = true;
  184. IN_DATA_CHANGE_FUNCTION (value, value.Length);
  185. }
  186. %}
  187. %typemap(csvarout, excode=SWIGEXCODE2) CTYPE
  188. %{
  189. get
  190. {
  191. INCSTYPE[] returnArray;
  192. if (!BOOLNAME)
  193. {
  194. IntPtr cPtr = RakNetPINVOKE.IN_DATA_GET_FUNCTION (swigCPtr);
  195. int len = (int) IN_LEN_METHOD;
  196. if (len<=0)
  197. {
  198. return null;
  199. }
  200. returnArray = new INCSTYPE[len];
  201. INTERMEDIATETYPE[] marshalArray = new INTERMEDIATETYPE[len];
  202. Marshal.Copy(cPtr, marshalArray, 0, len);
  203. for (int i=0;i<len;i++)
  204. {
  205. returnArray[i]= CONVERSION_MODIFIER ( marshalArray[i] );
  206. }
  207. CACHENAME = returnArray;
  208. BOOLNAME = true;
  209. }
  210. else
  211. {
  212. returnArray = CACHENAME;
  213. }
  214. return returnArray;
  215. }
  216. %}
  217. %enddef
  218. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP_LOOP_COPY(bytesInSendBufferIsCached,bytesInSendBufferCache,double bytesInSendBuffer[ NUMBER_OF_PRIORITIES ],double,double,SetBytesInSendBuffer,RakNetStatistics_bytesInSendBuffer_get,RakNet::RakNetStatistics,PacketPriority.NUMBER_OF_PRIORITIES,(double));
  219. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP_LOOP_COPY(messageInSendBufferIsCached,messageInSendBufferCache,unsigned messageInSendBuffer[ NUMBER_OF_PRIORITIES ],uint,int,SetMessageInSendBuffer,RakNetStatistics_messageInSendBuffer_get,RakNet::RakNetStatistics,PacketPriority.NUMBER_OF_PRIORITIES,(uint));
  220. namespace RakNet
  221. {
  222. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP_LOOP_COPY(runningTotalIsCached,runningTotalCache,unsigned long long runningTotal [ RNS_PER_SECOND_METRICS_COUNT ],ulong,long,SetRunningTotal,RakNetStatistics_runningTotal_get,RakNet::RakNetStatistics,RNSPerSecondMetrics.RNS_PER_SECOND_METRICS_COUNT,(ulong));
  223. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP_LOOP_COPY(valueOverLastSecondIsCached,valueOverLastSecondCache,unsigned long long valueOverLastSecond [ RNS_PER_SECOND_METRICS_COUNT ],ulong,long,SetValueOverLastSecond,RakNetStatistics_valueOverLastSecond_get,RakNet::RakNetStatistics,RNSPerSecondMetrics.RNS_PER_SECOND_METRICS_COUNT,(ulong));
  224. }
  225. %typemap(imtype, out="IntPtr") char *firstDataChunk "IntPtr"
  226. %typemap(imtype, out="IntPtr") char *iriDataChunk "IntPtr"
  227. %typemap(imtype, out="IntPtr") char *fileData "IntPtr"
  228. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP(firstDataChunkIsCached,firstDataChunkCache,char *firstDataChunk,byte,byte,SetFirstDataChunk,FileProgressStruct_firstDataChunk_get,FileProgressStruct,dataChunkLength)
  229. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP(iriDataChunkIsCached,iriDataChunkCache,char *iriDataChunk,byte,byte,SetIriDataChunk,FileProgressStruct_iriDataChunk_get,FileProgressStruct,dataChunkLength)
  230. STRUCT_CUSTOM_GENERAL_ARRAY_TYPEMAP(fileDataIsCached,fileDataCache,char *fileData,byte,byte,SetFileData,OnFileStruct_fileData_get,OnFileStruct,byteLengthOfThisFile)
  231. //GetpntrTypemaps
  232. //Many of these typemaps are required to copy the
  233. //cached or changed data back into C++ when the pointer is passed into a C++ function
  234. //Think of it as a type of cache writeback
  235. %typemap(csbody) RakNet::OnFileStruct
  236. %{
  237. private HandleRef swigCPtr;
  238. protected bool swigCMemOwn;
  239. internal OnFileStruct(IntPtr cPtr, bool cMemoryOwn) {
  240. swigCMemOwn = cMemoryOwn;
  241. swigCPtr = new HandleRef(this, cPtr);
  242. }
  243. internal static HandleRef getCPtr(OnFileStruct obj) {
  244. if (obj != null)
  245. {
  246. if (obj.fileDataIsCached)
  247. {
  248. obj.SetFileData(obj.fileData, obj.fileData.Length); //If an individual index was modified we need to copy the data before passing to C++
  249. }
  250. obj.fileDataIsCached=false;
  251. }
  252. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  253. }
  254. %}
  255. %typemap(csbody) RakNet::Packet
  256. %{
  257. private HandleRef swigCPtr;
  258. protected bool swigCMemOwn;
  259. internal Packet(IntPtr cPtr, bool cMemoryOwn)
  260. {
  261. swigCMemOwn = cMemoryOwn;
  262. swigCPtr = new HandleRef(this, cPtr);
  263. }
  264. internal static HandleRef getCPtr(Packet obj)
  265. {
  266. if (obj != null)
  267. {
  268. if (obj.dataIsCached)
  269. {
  270. obj.SetPacketData(obj.data, obj.data.Length); //If an individual index was modified we need to copy the data before passing to C++
  271. }
  272. obj.dataIsCached=false;
  273. }
  274. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  275. }
  276. %}
  277. %typemap(csbody) FileProgressStruct
  278. %{
  279. private HandleRef swigCPtr;
  280. protected bool swigCMemOwn;
  281. internal FileProgressStruct(IntPtr cPtr, bool cMemoryOwn) {
  282. swigCMemOwn = cMemoryOwn;
  283. swigCPtr = new HandleRef(this, cPtr);
  284. }
  285. internal static HandleRef getCPtr(FileProgressStruct obj) {
  286. if (obj != null)
  287. {
  288. if (obj.firstDataChunkIsCached)
  289. {
  290. obj.SetFirstDataChunk(obj.firstDataChunk, obj.firstDataChunk.Length);
  291. }
  292. if (obj.iriDataChunkIsCached)
  293. {
  294. obj.SetIriDataChunk(obj.iriDataChunk, obj.iriDataChunk.Length);
  295. }
  296. obj.firstDataChunkIsCached=false;
  297. obj.iriDataChunkIsCached=false;
  298. }
  299. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  300. }
  301. %}
  302. %typemap(csbody) RakNet::RakNetStatistics
  303. %{
  304. private HandleRef swigCPtr;
  305. protected bool swigCMemOwn;
  306. internal RakNetStatistics(IntPtr cPtr, bool cMemoryOwn) {
  307. swigCMemOwn = cMemoryOwn;
  308. swigCPtr = new HandleRef(this, cPtr);
  309. }
  310. internal static HandleRef getCPtr(RakNetStatistics obj) {
  311. if (obj != null)
  312. {
  313. if (obj.bytesInSendBufferIsCached)
  314. {
  315. obj.SetBytesInSendBuffer(obj.bytesInSendBuffer, obj.bytesInSendBuffer.Length);
  316. }
  317. if (obj.messageInSendBufferIsCached)
  318. {
  319. obj.SetMessageInSendBuffer(obj.messageInSendBuffer, obj.messageInSendBuffer.Length);
  320. }
  321. if (obj.runningTotalIsCached)
  322. {
  323. obj.SetRunningTotal(obj.runningTotal, obj.runningTotal.Length);
  324. }
  325. if (obj.valueOverLastSecondIsCached)
  326. {
  327. obj.SetValueOverLastSecond(obj.valueOverLastSecond, obj.valueOverLastSecond.Length);
  328. }
  329. obj.bytesInSendBufferIsCached=false;
  330. obj.messageInSendBufferIsCached=false;
  331. obj.runningTotalIsCached=false;
  332. obj.valueOverLastSecondIsCached=false;
  333. }
  334. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  335. }
  336. %}
  337. //Removed from interface, commented rather than removed in case needed later
  338. /*
  339. %typemap(csbody) InternalPacket
  340. %{
  341. private HandleRef swigCPtr;
  342. internal InternalPacket(IntPtr cPtr, bool cMemoryOwn) : base(RakNetPINVOKE.InternalPacketUpcast(cPtr), cMemoryOwn)
  343. {
  344. swigCPtr = new HandleRef(this, cPtr);
  345. }
  346. internal static HandleRef getCPtr(InternalPacket obj)
  347. {
  348. if (obj != null)
  349. {
  350. if (obj.dataIsCached)
  351. {
  352. obj.SetInternalPacketData(obj.data, obj.data.Length); //If an individual index was modified we need to copy the data before passing to C++
  353. }
  354. }
  355. return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  356. }
  357. %}*/
  358. //Extra C# code
  359. //These typemaps add C# code to the postprocessed file, mostly to improve the user interface so it matches the original
  360. //API for things Swig doesn't support
  361. //This adds to the main RakNet class, generally used for globals
  362. #ifdef SWIG_ADDITIONAL_AUTOPATCHER
  363. %pragma(csharp) modulecode=
  364. %{
  365. public static readonly SystemAddress UNASSIGNED_SYSTEM_ADDRESS = new SystemAddress();
  366. public static readonly RakNetGUID UNASSIGNED_RAKNET_GUID = new RakNetGUID(ulong.MaxValue);
  367. public static void StatisticsToString(RakNetStatistics s, out string buffer, int verbosityLevel)
  368. {
  369. String tmp = new String('c', 9999);
  370. buffer=StatisticsToStringHelper(s,tmp,verbosityLevel);
  371. }
  372. /* public static bool CreatePatch(byte[] old, uint oldsize, byte[] _new, uint newsize, out byte[] outStore, out uint outSize)
  373. {
  374. bool returnVal;
  375. outStore=new byte[999999];
  376. return CreatePatchHelper(old,oldsize,_new,newsize,outStore,out outSize);
  377. Array.Resize<byte>(ref outStore, (int)outSize);
  378. return returnVal;
  379. }*/
  380. %}
  381. #else
  382. %pragma(csharp) modulecode=
  383. %{
  384. public static readonly SystemAddress UNASSIGNED_SYSTEM_ADDRESS = new SystemAddress();
  385. public static readonly RakNetGUID UNASSIGNED_RAKNET_GUID = new RakNetGUID(ulong.MaxValue);
  386. public static void StatisticsToString(RakNetStatistics s, out string buffer, int verbosityLevel)
  387. {
  388. String tmp = new String('c', 9999);
  389. buffer=StatisticsToStringHelper(s,tmp,verbosityLevel);
  390. }
  391. %}
  392. #endif
  393. //BitStream
  394. %typemap(cscode) RakNet::BitStream
  395. %{
  396. //String reading using original api, but converted to c# logic
  397. public bool Read(out string varString)
  398. {
  399. String tmp = new String('c', (int)GetNumberOfUnreadBits()/8);
  400. varString = CSharpStringReader(tmp);
  401. return varString!="";
  402. }
  403. //Byte read out
  404. public bool Read(byte[] inOutByteArray,uint numberOfBytes)
  405. {
  406. return CSharpByteReader(inOutByteArray,numberOfBytes);
  407. }
  408. public bool Read(out char outTemplateVar)
  409. {
  410. byte tmp;
  411. bool returnVal=Read(out tmp);
  412. outTemplateVar=(char)tmp;
  413. return returnVal;
  414. }
  415. public bool ReadCompressed(out char outTemplateVar)
  416. {
  417. byte tmp;
  418. bool returnVal=ReadCompressed(out tmp);
  419. outTemplateVar=(char)tmp;
  420. return returnVal;
  421. }
  422. public bool ReadCompressedDelta(out char outTemplateVar)
  423. {
  424. byte tmp;
  425. bool returnVal=ReadCompressedDelta(out tmp);
  426. outTemplateVar=(char)tmp;
  427. return returnVal;
  428. }
  429. public bool ReadDelta(out char outTemplateVar)
  430. {
  431. byte tmp;
  432. bool returnVal=ReadDelta(out tmp);;
  433. outTemplateVar=(char)tmp;
  434. return returnVal;
  435. }
  436. public bool ReadCompressed(out string var)
  437. {
  438. String tmp = new String('c', (int)GetNumberOfUnreadBits()/8);
  439. var = CSharpStringReaderCompressed(tmp);
  440. return var!="";
  441. }
  442. public bool ReadCompressedDelta(out string var)
  443. {
  444. String tmp = new String('c', (int)GetNumberOfUnreadBits()/8);
  445. var = CSharpStringReaderCompressedDelta(tmp);
  446. return var!="";
  447. }
  448. public bool ReadDelta(out string var)
  449. {
  450. String tmp = new String('c', (int)GetNumberOfUnreadBits()/8);
  451. var = CSharpStringReaderDelta(tmp);
  452. return var!="";
  453. }
  454. public uint CopyData(out byte[] outByteArray)
  455. {
  456. byte[] tmp= new byte[GetNumberOfBitsAllocated()/8];
  457. uint byteNum = CSharpCopyDataHelper(tmp);
  458. outByteArray=tmp;
  459. return byteNum;
  460. }
  461. public byte[] GetData()
  462. {
  463. byte[] tmp= new byte[GetNumberOfBitsAllocated()/8];
  464. CSharpCopyDataHelper(tmp);
  465. return tmp;
  466. }
  467. public void PrintBits(out string var)
  468. {
  469. String tmp = new String('c', (int)(GetNumberOfBitsAllocated()+GetNumberOfBitsAllocated()/8));
  470. var = CSharpPrintBitsHelper(tmp);
  471. }
  472. public void PrintHex(out string var)
  473. {
  474. String tmp = new String('c', (int)(GetNumberOfBitsAllocated()/4+GetNumberOfBitsAllocated()/8));
  475. var = CSharpPrintHexHelper(tmp);
  476. }
  477. public bool Serialize(bool WriteToBitstream,ref char inOutTemplateVar)
  478. {
  479. byte tmp = (byte)inOutTemplateVar;
  480. bool returnVal = Serialize(WriteToBitstream,ref tmp);
  481. inOutTemplateVar=(char)tmp;
  482. return returnVal;
  483. }
  484. public bool SerializeDelta(bool WriteToBitstream,ref char inOutTemplateVar)
  485. {
  486. byte tmp = (byte)inOutTemplateVar;
  487. bool returnVal = SerializeDelta(WriteToBitstream,ref tmp);
  488. inOutTemplateVar=(char)tmp;
  489. return returnVal;
  490. }
  491. public bool SerializeCompressed(bool WriteToBitstream,ref char inOutTemplateVar)
  492. {
  493. byte tmp = (byte)inOutTemplateVar;
  494. bool returnVal = SerializeCompressed(WriteToBitstream,ref tmp);
  495. inOutTemplateVar=(char)tmp;
  496. return returnVal;
  497. }
  498. public bool SerializeCompressedDelta(bool WriteToBitstream,ref char inOutTemplateVar)
  499. {
  500. byte tmp = (byte)inOutTemplateVar;
  501. bool returnVal = SerializeCompressedDelta(WriteToBitstream,ref tmp);
  502. inOutTemplateVar=(char)tmp;
  503. return returnVal;
  504. }
  505. public bool ReadAlignedBytesSafeAlloc( out byte[] outByteArray, int inputLength, int maxBytesToRead )
  506. {
  507. outByteArray= new byte[inputLength];
  508. return ReadAlignedBytesSafe(outByteArray,inputLength,maxBytesToRead);
  509. }
  510. public bool ReadAlignedBytesSafeAlloc( out byte[] outByteArray, uint inputLength, uint maxBytesToRead )
  511. {
  512. outByteArray= new byte[inputLength];
  513. return ReadAlignedBytesSafe(outByteArray,inputLength,maxBytesToRead);
  514. }
  515. %}
  516. %define RAKPEERANDINTERFACECSCODE(MACRO_FUNCTIONTYPE_MOD)
  517. %{
  518. public MACRO_FUNCTIONTYPE_MOD void GetIncomingPassword(ref string passwordData, ref int passwordDataLength )
  519. {
  520. passwordData=CSharpGetIncomingPasswordHelper(passwordData,ref passwordDataLength);
  521. }
  522. public MACRO_FUNCTIONTYPE_MOD void GetOfflinePingResponse( byte[] inOutByteArray, out uint length )
  523. {
  524. CSharpGetOfflinePingResponseHelper(inOutByteArray,out length);
  525. }
  526. public MACRO_FUNCTIONTYPE_MOD bool GetConnectionList(out SystemAddress[] remoteSystems, ref ushort numberOfSystems)
  527. {
  528. RakNetListSystemAddress passVal= new RakNetListSystemAddress();
  529. bool returnVal = GetConnectionList(passVal,ref numberOfSystems);
  530. SystemAddress[] outVal = new SystemAddress[numberOfSystems];
  531. for (int i=0; i<numberOfSystems;i++)
  532. {
  533. outVal[i]=passVal[i];
  534. }
  535. remoteSystems=outVal;
  536. return returnVal;
  537. }
  538. %}
  539. %enddef
  540. //Table
  541. %typemap(cscode) DataStructures::Table
  542. %{
  543. public RakNetPageRow GetListHead() {
  544. return GetListHeadHelper();
  545. }
  546. public void SortTable(SortQuery [] sortQueries, uint numSortQueries, out Row[] arg2)
  547. {
  548. RakNetListSortQuery sortQueriesList =null;
  549. if (sortQueries!=null)
  550. {
  551. sortQueriesList = new RakNetListSortQuery();
  552. int listLen = sortQueries.Length;
  553. for (int i = 0; i < listLen; i++)
  554. {
  555. sortQueriesList.Insert(sortQueries[i], "", 1);
  556. }
  557. }
  558. int rowCount= (int)GetRowCount();
  559. Row[] rowArray= new Row[rowCount];
  560. RakNetListTableRow passVal = new RakNetListTableRow();
  561. SortTableHelper(sortQueriesList,numSortQueries,passVal);
  562. for (int i=0; i<rowCount;i++)
  563. {
  564. rowArray[i]=passVal[i];
  565. }
  566. arg2=rowArray;
  567. }
  568. public void GetCellValueByIndex(uint rowIndex, uint columnIndex, out byte[] outByteArray, out int outputLength)
  569. {
  570. int returnInt=0;
  571. Row row = GetRowByIndex(rowIndex,ref returnInt);
  572. int arrayLen=0;
  573. if (row!=null)
  574. {
  575. arrayLen=(int)row.cells[(int)columnIndex].i;
  576. }
  577. byte[] inOutByteArray = new byte[arrayLen];
  578. GetCellValueByIndexHelper(rowIndex,columnIndex,inOutByteArray,out outputLength);
  579. outByteArray=inOutByteArray;
  580. }
  581. public void GetCellValueByIndex(uint rowIndex, uint columnIndex,out string output)
  582. {
  583. int returnInt=0;
  584. Row row = GetRowByIndex(rowIndex,ref returnInt);
  585. int arrayLen=0;
  586. if (row!=null)
  587. {
  588. arrayLen=(int)row.cells[(int)columnIndex].i;
  589. }
  590. String tmp = new String('c', arrayLen);
  591. output=GetCellValueByIndexHelper( rowIndex, columnIndex, tmp);
  592. }
  593. public void QueryTable(uint[] columnIndicesSubset, uint numColumnSubset, FilterQuery[] inclusionFilters, uint numInclusionFilters, uint[] rowIds, uint numRowIDs, Table result)
  594. {
  595. RakNetListFilterQuery inclusionFiltersList =null;
  596. if (inclusionFiltersList!=null)
  597. {
  598. inclusionFiltersList = new RakNetListFilterQuery();
  599. int listLen = inclusionFilters.Length;
  600. for (int i = 0; i < listLen; i++)
  601. {
  602. inclusionFiltersList.Insert(inclusionFilters[i], "", 1);
  603. }
  604. }
  605. QueryTableHelper(columnIndicesSubset, numColumnSubset, inclusionFiltersList, numInclusionFilters, rowIds, numRowIDs, result);
  606. }
  607. public uint ColumnIndex(string columnName) {
  608. return ColumnIndexHelper(columnName);
  609. }
  610. %}
  611. //Table Cell
  612. %typemap(cscode) Cell
  613. %{
  614. public void Get(out string output)
  615. {
  616. string temp=new String('c', (int) this.i);
  617. output=GetHelper(temp);
  618. }
  619. %}
  620. //RakPeer
  621. %typemap(cscode) RakNet::RakPeer
  622. RAKPEERANDINTERFACECSCODE(override)
  623. //RakPeerInterface
  624. %typemap(cscode) RakNet::RakPeerInterface
  625. RAKPEERANDINTERFACECSCODE(virtual)
  626. %typemap(cscode) RakNet::PacketLogger
  627. %{
  628. public virtual void FormatLine(ref string preInitializedStringBigEnoughToFitResult, string dir, string type, uint packet, uint frame, byte messageIdentifier, uint bitLen, ulong time, SystemAddress local, SystemAddress remote, uint splitPacketId, uint splitPacketIndex, uint splitPacketCount, uint orderingIndex) {
  629. preInitializedStringBigEnoughToFitResult=FormatLineHelper( preInitializedStringBigEnoughToFitResult, dir, type, packet, frame, messageIdentifier, bitLen, time, local, remote, splitPacketId, splitPacketIndex, splitPacketCount, orderingIndex);
  630. }
  631. public virtual void FormatLine(ref string preInitializedStringBigEnoughToFitResult, string dir, string type, uint packet, uint frame, string idToPrint, uint bitLen, ulong time, SystemAddress local, SystemAddress remote, uint splitPacketId, uint splitPacketIndex, uint splitPacketCount, uint orderingIndex) {
  632. preInitializedStringBigEnoughToFitResult=FormatLineHelper( preInitializedStringBigEnoughToFitResult, dir, type, packet, frame, idToPrint, bitLen, time, local, remote, splitPacketId, splitPacketIndex, splitPacketCount, orderingIndex);
  633. }
  634. %}
  635. %typemap(csimports) RakNet::SystemAddress
  636. %{
  637. using System;
  638. using System.Runtime.InteropServices;
  639. #pragma warning disable 0660
  640. %}
  641. %typemap(cscode) RakNet::SystemAddress
  642. %{
  643. public override int GetHashCode()
  644. {
  645. // return (int)((this.port+this.binaryAddress)% int.MaxValue);
  646. return (int) ToInteger(this);
  647. }
  648. public static bool operator ==(SystemAddress a, SystemAddress b)
  649. {
  650. // If both are null, or both are same instance, return true.
  651. if (System.Object.ReferenceEquals(a, b))
  652. {
  653. return true;
  654. }
  655. // If one is null, but not both, return false.
  656. if (((object)a == null) || ((object)b == null))
  657. {
  658. return false;
  659. }
  660. return a.Equals(b);//Equals should be overloaded as well
  661. }
  662. public static bool operator !=(SystemAddress a, SystemAddress b)
  663. {
  664. return a.OpNotEqual(b);
  665. }
  666. public static bool operator < (SystemAddress a, SystemAddress b)
  667. {
  668. return a.OpLess(b);
  669. }
  670. public static bool operator >(SystemAddress a, SystemAddress b)
  671. {
  672. return a.OpGreater(b);
  673. }
  674. public static bool operator <=(SystemAddress a, SystemAddress b)
  675. {
  676. return (a.OpLess(b) || a==b);
  677. }
  678. public static bool operator >=(SystemAddress a, SystemAddress b)
  679. {
  680. return (a.OpGreater(b) || a==b);
  681. }
  682. public override string ToString()
  683. {
  684. return ToString(true);
  685. }
  686. public void ToString(bool writePort,out string dest)
  687. {
  688. dest=ToString(writePort);
  689. }
  690. %}
  691. %typemap(csimports) RakNet::RakNetGUID
  692. %{
  693. using System;
  694. using System.Runtime.InteropServices;
  695. #pragma warning disable 0660
  696. %}
  697. %typemap(cscode) RakNet::RakNetGUID
  698. %{
  699. public override int GetHashCode()
  700. {
  701. // return (int)(this.g%int.MaxValue);
  702. return (int) ToUint32(this);
  703. }
  704. public static bool operator ==(RakNetGUID a, RakNetGUID b)
  705. {
  706. // If both are null, or both are same instance, return true.
  707. if (System.Object.ReferenceEquals(a, b))
  708. {
  709. return true;
  710. }
  711. // If one is null, but not both, return false.
  712. if (((object)a == null) || ((object)b == null))
  713. {
  714. return false;
  715. }
  716. return a.Equals(b);//Equals should be overloaded as well
  717. }
  718. public static bool operator !=(RakNetGUID a, RakNetGUID b)
  719. {
  720. return a.OpNotEqual(b);
  721. }
  722. public static bool operator < (RakNetGUID a, RakNetGUID b)
  723. {
  724. return a.OpLess(b);
  725. }
  726. public static bool operator >(RakNetGUID a, RakNetGUID b)
  727. {
  728. return a.OpGreater(b);
  729. }
  730. public static bool operator <=(RakNetGUID a, RakNetGUID b)
  731. {
  732. return (a.OpLess(b) || a==b);
  733. }
  734. public static bool operator >=(RakNetGUID a, RakNetGUID b)
  735. {
  736. return (a.OpGreater(b) || a==b);
  737. }
  738. public void ToString(out string dest)
  739. {
  740. dest = ToString();
  741. }
  742. %}
  743. %typemap(csimports) RakNet::RakString
  744. %{
  745. using System;
  746. using System.Runtime.InteropServices;
  747. #pragma warning disable 0660
  748. %}
  749. %typemap(cscode) RakNet::RakString
  750. %{
  751. public override int GetHashCode()
  752. {
  753. return this.C_String().GetHashCode();
  754. }
  755. public static bool operator ==(RakString a, RakString b)
  756. {
  757. // If both are null, or both are same instance, return true.
  758. if (System.Object.ReferenceEquals(a, b))
  759. {
  760. return true;
  761. }
  762. // If one is null, but not both, return false.
  763. if (((object)a == null) || ((object)b == null))
  764. {
  765. return false;
  766. }
  767. return a.Equals(b);//Equals should be overloaded as well
  768. }
  769. public static bool operator ==(RakString a, string b)
  770. {
  771. // If both are null, or both are same instance, return true.
  772. if (System.Object.ReferenceEquals(a, b))
  773. {
  774. return true;
  775. }
  776. // If one is null, but not both, return false.
  777. if (((object)a == null) || ((object)b == null))
  778. {
  779. return false;
  780. }
  781. return a.Equals(b);//Equals should be overloaded as well
  782. }
  783. public static bool operator ==(RakString a, char b)
  784. {
  785. // If both are null, or both are same instance, return true.
  786. if (System.Object.ReferenceEquals(a, b))
  787. {
  788. return true;
  789. }
  790. // If one is null, but not both, return false.
  791. if (((object)a == null) || ((object)b == null))
  792. {
  793. return false;
  794. }
  795. return a.Equals(b);//Equals should be overloaded as well
  796. }
  797. public static bool operator !=(RakString a, char b)
  798. {
  799. return !(a==b);
  800. }
  801. public static bool operator !=(RakString a, RakString b)
  802. {
  803. return a.OpNotEqual(b);
  804. }
  805. public static bool operator !=(RakString a, string b)
  806. {
  807. return a.OpNotEqual(b);
  808. }
  809. public static bool operator < (RakString a, RakString b)
  810. {
  811. return a.OpLess(b);
  812. }
  813. public static bool operator >(RakString a, RakString b)
  814. {
  815. return a.OpGreater(b);
  816. }
  817. public static bool operator <=(RakString a, RakString b)
  818. {
  819. return a.OpLessEquals(b);
  820. }
  821. public static bool operator >=(RakString a, RakString b)
  822. {
  823. return a.OpGreaterEquals(b);
  824. }
  825. public char this[int index]
  826. {
  827. get
  828. {
  829. return (char)OpArray((uint)index); // use indexto retrieve and return another value.
  830. }
  831. set
  832. {
  833. Replace((uint)index,1,(byte)value);// use index and value to set the value somewhere.
  834. }
  835. }
  836. public static RakString operator +(RakString a, RakString b)
  837. {
  838. return RakNet.OpPlus(a,b);
  839. }
  840. public static implicit operator RakString(String s)
  841. {
  842. return new RakString(s);
  843. }
  844. public static implicit operator RakString(char c)
  845. {
  846. return new RakString(c);
  847. }
  848. public static implicit operator RakString(byte c)
  849. {
  850. return new RakString(c);
  851. }
  852. public override string ToString()
  853. {
  854. return C_String();
  855. }
  856. public void SetChar(uint index, char inChar)
  857. {
  858. SetChar(index,(byte)inChar);
  859. }
  860. public void Replace(uint index, uint count, char inChar)
  861. {
  862. Replace(index,count,(byte)inChar);
  863. }
  864. %}
  865. %typemap(cscode) RakNet::AddressOrGUID
  866. %{
  867. public static implicit operator AddressOrGUID(SystemAddress systemAddress)
  868. {
  869. return new AddressOrGUID(systemAddress);
  870. }
  871. public static implicit operator AddressOrGUID(RakNetGUID guid)
  872. {
  873. return new AddressOrGUID(guid);
  874. }
  875. %}
  876. %typemap (cscode) DataStructures::ByteQueue
  877. %{
  878. public byte[] PeekContiguousBytes(out uint outLength)
  879. {
  880. return PeekContiguousBytesHelper(out outLength);
  881. }
  882. %}
  883. /*
  884. %typemap(cscode) RakNetSmartPtr<RakNetSocket>
  885. %{
  886. public static bool operator ==(RakNetSmartPtrRakNetSocket a, RakNetSmartPtrRakNetSocket b)
  887. {
  888. // If both are null, or both are same instance, return true.
  889. if (System.Object.ReferenceEquals(a, b))
  890. {
  891. return true;
  892. }
  893. // If one is null, but not both, return false.
  894. if (((object)a == null) || ((object)b == null))
  895. {
  896. return false;
  897. }
  898. return a.Equals(b);//Equals should be overloaded as well
  899. }
  900. public static bool operator !=(RakNetSmartPtrRakNetSocket a, RakNetSmartPtrRakNetSocket b)
  901. {
  902. return a.OpNotEqual(b);
  903. }
  904. public static bool operator < (RakNetSmartPtrRakNetSocket a, RakNetSmartPtrRakNetSocket b)
  905. {
  906. return a.OpLess(b);
  907. }
  908. public static bool operator >(RakNetSmartPtrRakNetSocket a, RakNetSmartPtrRakNetSocket b)
  909. {
  910. return a.OpGreater(b);
  911. }
  912. %}
  913. */
  914. %typemap(csimports) RakNet::uint24_t
  915. %{
  916. using System;
  917. using System.Runtime.InteropServices;
  918. #pragma warning disable 0660
  919. %}
  920. %typemap(cscode) RakNet::uint24_t
  921. %{
  922. public override int GetHashCode()
  923. {
  924. return (int)this.val;
  925. }
  926. public static implicit operator uint24_t(uint inUint)
  927. {
  928. return new uint24_t(inUint);
  929. }
  930. public static bool operator ==(uint24_t a, uint24_t b)
  931. {
  932. // If both are null, or both are same instance, return true.
  933. if (System.Object.ReferenceEquals(a, b))
  934. {
  935. return true;
  936. }
  937. // If one is null, but not both, return false.
  938. if (((object)a == null) || ((object)b == null))
  939. {
  940. return false;
  941. }
  942. return a.Equals(b);//Equals should be overloaded as well
  943. }
  944. public static bool operator !=(uint24_t a, uint24_t b)
  945. {
  946. return a.OpNotEqual(b);
  947. }
  948. public static bool operator < (uint24_t a, uint24_t b)
  949. {
  950. return a.OpLess(b);
  951. }
  952. public static bool operator >(uint24_t a, uint24_t b)
  953. {
  954. return a.OpGreater(b);
  955. }
  956. public static uint24_t operator +(uint24_t a, uint24_t b)
  957. {
  958. return a.OpPlus(b);
  959. }
  960. public static uint24_t operator ++(uint24_t a)
  961. {
  962. return a.OpPlusPlus();
  963. }
  964. public static uint24_t operator --(uint24_t a)
  965. {
  966. return a.OpMinusMinus();
  967. }
  968. public static uint24_t operator *(uint24_t a, uint24_t b)
  969. {
  970. return a.OpMultiply(b);
  971. }
  972. public static uint24_t operator /(uint24_t a, uint24_t b)
  973. {
  974. return a.OpDivide(b);
  975. }
  976. public static uint24_t operator -(uint24_t a, uint24_t b)
  977. {
  978. return a.OpMinus(b);
  979. }
  980. //------------
  981. public static bool operator ==(uint24_t a, uint b)
  982. {
  983. // If both are null, or both are same instance, return true.
  984. if (System.Object.ReferenceEquals(a, b))
  985. {
  986. return true;
  987. }
  988. // If one is null, but not both, return false.
  989. if (((object)a == null) || ((object)b == null))
  990. {
  991. return false;
  992. }
  993. return a.Equals(b);//Equals should be overloaded as well
  994. }
  995. public static bool operator !=(uint24_t a, uint b)
  996. {
  997. return a.OpNotEqual(b);
  998. }
  999. public static bool operator < (uint24_t a, uint b)
  1000. {
  1001. return a.OpLess(b);
  1002. }
  1003. public static bool operator >(uint24_t a, uint b)
  1004. {
  1005. return a.OpGreater(b);
  1006. }
  1007. public static uint24_t operator +(uint24_t a, uint b)
  1008. {
  1009. return a.OpPlus(b);
  1010. }
  1011. public static uint24_t operator *(uint24_t a, uint b)
  1012. {
  1013. return a.OpMultiply(b);
  1014. }
  1015. public static uint24_t operator /(uint24_t a, uint b)
  1016. {
  1017. return a.OpDivide(b);
  1018. }
  1019. public static uint24_t operator -(uint24_t a, uint b)
  1020. {
  1021. return a.OpMinus(b);
  1022. }
  1023. public override string ToString()
  1024. {
  1025. return val.ToString();
  1026. }
  1027. %}
  1028. %define STRUCT_UNSIGNED_CHAR_ARRAY_ONLY_CSCODE(BOOLNAME,CACHENAME)
  1029. %{
  1030. private bool BOOLNAME = false;
  1031. private byte[] CACHENAME;
  1032. %}
  1033. %enddef
  1034. %typemap(cscode) RakNet::FileListNode
  1035. %{
  1036. private bool dataIsCached = false;
  1037. private byte[] dataCache;
  1038. %}
  1039. %typemap(cscode) FileProgressStruct
  1040. %{
  1041. private bool firstDataChunkIsCached = false;
  1042. private byte[] firstDataChunkCache;
  1043. private bool iriDataChunkIsCached = false;
  1044. private byte[] iriDataChunkCache;
  1045. %}
  1046. %typemap(cscode) OnFileStruct
  1047. STRUCT_UNSIGNED_CHAR_ARRAY_ONLY_CSCODE(fileDataIsCached,fileDataCache)
  1048. //Packet->data related typemaps
  1049. %typemap(cscode) RakNet::Packet
  1050. STRUCT_UNSIGNED_CHAR_ARRAY_ONLY_CSCODE(dataIsCached,dataCache)
  1051. %typemap(cscode) RakNet::NetworkIDObject
  1052. %{
  1053. NetworkIDManager oldManager;
  1054. public virtual void SetNetworkIDManager(NetworkIDManager manager)
  1055. {
  1056. if (oldManager != null)
  1057. {
  1058. oldManager.pointerDictionary.Remove(GetIntPtr());
  1059. }
  1060. if (manager != null)
  1061. {
  1062. manager.pointerDictionary.Add(GetIntPtr(), this);
  1063. oldManager = manager;
  1064. }
  1065. SetNetworkIDManagerOrig(manager);
  1066. }
  1067. public IntPtr GetIntPtr()
  1068. {
  1069. return swigCPtr.Handle;
  1070. }
  1071. %}
  1072. %typemap(csimports) RakNet::NetworkIDManager
  1073. %{
  1074. using System;
  1075. using System.Runtime.InteropServices;
  1076. using System.Collections.Generic;
  1077. %}
  1078. %typemap(cscode) RakNet::NetworkIDManager
  1079. %{
  1080. public Dictionary<IntPtr, NetworkIDObject> pointerDictionary = new Dictionary<IntPtr, NetworkIDObject>();
  1081. public NetworkIDObject GET_BASE_OBJECT_FROM_ID(ulong x)
  1082. {
  1083. return pointerDictionary[GET_BASE_OBJECT_FROM_IDORIG(x).GetIntPtr()];
  1084. }
  1085. %}
  1086. %typemap(cscode) RakNet::ConnectionGraph2
  1087. %{
  1088. public bool GetConnectionListForRemoteSystem(RakNetGUID remoteSystemGuid, SystemAddress[] saOut, RakNetGUID[] guidOut, ref uint inOutLength)
  1089. {
  1090. uint minLength = inOutLength;
  1091. if (guidOut.Length < minLength)
  1092. { minLength = (uint)guidOut.Length; }
  1093. if (saOut.Length < minLength)
  1094. { minLength = (uint)saOut.Length; }
  1095. RakNetListRakNetGUID passListGUID = new RakNetListRakNetGUID();
  1096. RakNetListSystemAddress passListSystemAddress = new RakNetListSystemAddress();
  1097. bool returnVal = GetConnectionListForRemoteSystemHelper(remoteSystemGuid, passListSystemAddress, passListGUID, ref inOutLength);
  1098. if (inOutLength< minLength)
  1099. { minLength = (uint)inOutLength;}
  1100. for (int i = 0; i < minLength; i++)
  1101. {
  1102. guidOut[i] = passListGUID[i];
  1103. saOut[i] = passListSystemAddress[i];
  1104. }
  1105. return returnVal;
  1106. }
  1107. public void GetParticipantList(RakNetGUID[] participantList)
  1108. {
  1109. RakNetListRakNetGUID passListGUID = new RakNetListRakNetGUID();
  1110. GetParticipantListHelper(passListGUID);
  1111. for (int i = 0; i < participantList.Length && i < passListGUID.Size(); i++)
  1112. {
  1113. participantList[i] = passListGUID[i];
  1114. }
  1115. }
  1116. %}
  1117. //Removed from interface, commented rather than removed in case needed later
  1118. /*
  1119. %typemap(cscode) InternalPacket
  1120. STRUCT_UNSIGNED_CHAR_ARRAY_ONLY_CSCODE(dataIsCached,dataCache)*/
  1121. %typemap(cscode) RakNet::RakNetStatistics
  1122. %{
  1123. private bool bytesInSendBufferIsCached = false;
  1124. private bool messageInSendBufferIsCached = false;
  1125. private bool runningTotalIsCached = false;
  1126. private bool valueOverLastSecondIsCached = false;
  1127. private double[] bytesInSendBufferCache;
  1128. private uint[] messageInSendBufferCache;
  1129. private ulong[] runningTotalCache;
  1130. private ulong[] valueOverLastSecondCache;
  1131. %}
  1132. %define STRUCT_CUSTOM_UNSIGNED_CHAR_ARRAY_TYPEMAP(BOOLNAME,CACHENAME,CTYPE,IN_DATA_CHANGE_FUNCTION,IN_DATA_GET_FUNCTION,IN_CLASS,IN_LEN_METHOD)
  1133. %typemap(cstype, out="byte[]") CTYPE "byte[]"
  1134. %typemap(csvarin, excode=SWIGEXCODE2) CTYPE %{
  1135. set
  1136. {
  1137. CACHENAME=value;
  1138. BOOLNAME = true;
  1139. IN_DATA_CHANGE_FUNCTION (value, value.Length);
  1140. }
  1141. %}
  1142. %typemap(csvarout, excode=SWIGEXCODE2) CTYPE %{
  1143. get
  1144. {
  1145. byte[] returnBytes;
  1146. if (!BOOLNAME)
  1147. {
  1148. IntPtr cPtr = RakNetPINVOKE.IN_DATA_GET_FUNCTION (swigCPtr);
  1149. int len = (int)((IN_CLASS)swigCPtr.Wrapper).IN_LEN_METHOD;
  1150. if (len<=0)
  1151. {
  1152. return null;
  1153. }
  1154. returnBytes = new byte[len];
  1155. Marshal.Copy(cPtr, returnBytes, 0, len);
  1156. CACHENAME = returnBytes;
  1157. BOOLNAME = true;
  1158. }
  1159. else
  1160. {
  1161. returnBytes = CACHENAME;
  1162. }
  1163. return returnBytes;
  1164. }
  1165. %}
  1166. %enddef
  1167. #ifdef SWIG_ADDITIONAL_AUTOPATCHER
  1168. %typemap (cscode) RakNet::AutopatcherServer
  1169. %{
  1170. public void StartThreads(int numThreads, AutopatcherRepositoryInterface [] sqlConnectionPtrArray)
  1171. {
  1172. RakNetListAutopatcherRepositoryInterfacePointer inSqlConnect =null;
  1173. if (sqlConnectionPtrArray!=null)
  1174. {
  1175. inSqlConnect = new RakNetListAutopatcherRepositoryInterfacePointer();
  1176. int listLen = sqlConnectionPtrArray.Length;
  1177. for (int i = 0; i < listLen; i++)
  1178. {
  1179. inSqlConnect.Insert(sqlConnectionPtrArray[i], "", 1);
  1180. }
  1181. }
  1182. StartThreadsHelper(numThreads,inSqlConnect);
  1183. }
  1184. %}
  1185. %typemap (cscode) CompressorBase
  1186. %{
  1187. public byte[] GetOutput()
  1188. {
  1189. byte[] returnBytes= new byte[GetTotalOutputSize()];
  1190. GetOutputHelper(returnBytes);
  1191. return returnBytes;
  1192. }
  1193. %}
  1194. #endif
粤ICP备19079148号