NativeMethods.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. namespace ENet
  5. {
  6. public static class NativeMethods
  7. {
  8. private const string LIB = "ENetCpp.dll";
  9. public const int ENET_PEER_PACKET_THROTTLE_SCALE = 32;
  10. public const int ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2;
  11. public const int ENET_PEER_PACKET_THROTTLE_DECELERATION = 2;
  12. public const int ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000;
  13. public const int ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1;
  14. public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
  15. public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
  16. public const uint ENET_VERSION = (1 << 16) | (3 << 8) | (10);
  17. public const uint ENET_HOST_ANY = 0;
  18. public const uint ENET_HOST_BROADCAST = 0xffffffff;
  19. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  20. EntryPoint = "enet_address_set_host")]
  21. internal static extern int EnetAddressSetHost(ref ENetAddress address, string hostName);
  22. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  23. EntryPoint = "enet_address_get_host")]
  24. internal static extern int EnetAddressGetHost(
  25. ref ENetAddress address, StringBuilder hostName, uint nameLength);
  26. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  27. EntryPoint = "enet_address_get_host_ip")]
  28. internal static extern int EnetAddressGetHostIp(
  29. ref ENetAddress address, StringBuilder hostIp, uint ipLength);
  30. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  31. EntryPoint = "enet_deinitialize")]
  32. internal static extern void EnetDeinitialize();
  33. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_initialize")
  34. ]
  35. internal static extern int EnetInitialize();
  36. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  37. EntryPoint = "enet_initialize_with_callbacks")]
  38. internal static extern int EnetInitializeWithCallbacks(
  39. uint version, ref ENetCallbacks inits);
  40. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_enable_crc")
  41. ]
  42. internal static extern void EnetEnableCrc(IntPtr host);
  43. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create"
  44. )]
  45. internal static extern IntPtr EnetHostCreate(
  46. ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  47. uint outgoingBandwidth);
  48. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create"
  49. )]
  50. internal static extern IntPtr EnetHostCreate(
  51. IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  52. uint outgoingBandwidth);
  53. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  54. EntryPoint = "enet_host_destroy")]
  55. internal static extern void EnetHostDestroy(IntPtr host);
  56. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  57. EntryPoint = "enet_host_connect")]
  58. internal static extern IntPtr EnetHostConnect(
  59. IntPtr host, ref ENetAddress address, uint channelCount, uint data);
  60. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  61. EntryPoint = "enet_host_broadcast")]
  62. internal static extern void EnetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
  63. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  64. EntryPoint = "enet_host_compress")]
  65. internal static extern void EnetHostCompress(IntPtr host, IntPtr compressor);
  66. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  67. EntryPoint = "enet_host_compress_with_range_coder")]
  68. internal static extern int EnetHostCompressWithRangeCoder(IntPtr host);
  69. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  70. EntryPoint = "enet_host_channel_limit")]
  71. internal static extern void EnetHostChannelLimit(IntPtr host, uint channelLimit);
  72. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  73. EntryPoint = "enet_host_bandwidth_limit")]
  74. internal static extern void EnetHostBandwidthLimit(
  75. IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  76. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_flush")
  77. ]
  78. internal static extern void EnetHostFlush(IntPtr host);
  79. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  80. EntryPoint = "enet_host_check_events")]
  81. internal static extern int EnetHostCheckEvents(IntPtr host, ENetEvent ev);
  82. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  83. EntryPoint = "enet_host_service")]
  84. internal static extern int EnetHostService(IntPtr host, ENetEvent ev, uint timeout);
  85. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_get")]
  86. internal static extern uint EnetTimeGet();
  87. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_set")]
  88. internal static extern void EnetTimeSet(uint newTimeBase);
  89. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  90. EntryPoint = "enet_packet_create")]
  91. internal static extern IntPtr EnetPacketCreate(
  92. byte[] data, uint dataLength, PacketFlags flags);
  93. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  94. EntryPoint = "enet_packet_destroy")]
  95. internal static extern void EnetPacketDestroy(IntPtr packet);
  96. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  97. EntryPoint = "enet_packet_resize")]
  98. internal static extern int EnetPacketResize(IntPtr packet, uint dataLength);
  99. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  100. EntryPoint = "enet_peer_throttle_configure")]
  101. internal static extern void EnetPeerThrottleConfigure(
  102. IntPtr peer, uint interval, uint acceleration, uint deceleration);
  103. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_send")]
  104. internal static extern int EnetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
  105. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  106. EntryPoint = "enet_peer_receive")]
  107. internal static extern IntPtr EnetPeerReceive(IntPtr peer, out byte channelID);
  108. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_reset")
  109. ]
  110. internal static extern void EnetPeerReset(IntPtr peer);
  111. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_ping")]
  112. internal static extern void EnetPeerPing(IntPtr peer);
  113. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  114. EntryPoint = "enet_peer_disconnect_now")]
  115. internal static extern void EnetPeerDisconnectNow(IntPtr peer, uint data);
  116. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  117. EntryPoint = "enet_peer_disconnect")]
  118. internal static extern void EnetPeerDisconnect(IntPtr peer, uint data);
  119. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  120. EntryPoint = "enet_peer_disconnect_later")]
  121. internal static extern void EnetPeerDisconnectLater(IntPtr peer, uint data);
  122. }
  123. }