NativeMethods.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, EntryPoint = "enet_address_set_host")
  20. ]
  21. internal static extern int EnetAddressSetHost(ref ENetAddress address, string hostName);
  22. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_get_host")
  23. ]
  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, EntryPoint = "enet_deinitialize")]
  31. internal static extern void EnetDeinitialize();
  32. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_initialize")]
  33. internal static extern int EnetInitialize();
  34. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  35. EntryPoint = "enet_initialize_with_callbacks")]
  36. internal static extern int EnetInitializeWithCallbacks(uint version, ref ENetCallbacks inits);
  37. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_enable_crc")]
  38. internal static extern void EnetEnableCrc(IntPtr host);
  39. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create")]
  40. internal static extern IntPtr EnetHostCreate(
  41. ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  42. uint outgoingBandwidth);
  43. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create")]
  44. internal static extern IntPtr EnetHostCreate(
  45. IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
  46. uint outgoingBandwidth);
  47. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_destroy")]
  48. internal static extern void EnetHostDestroy(IntPtr host);
  49. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_connect")]
  50. internal static extern IntPtr EnetHostConnect(
  51. IntPtr host, ref ENetAddress address, uint channelCount, uint data);
  52. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_broadcast")]
  53. internal static extern void EnetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
  54. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_compress")]
  55. internal static extern void EnetHostCompress(IntPtr host, IntPtr compressor);
  56. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  57. EntryPoint = "enet_host_compress_with_range_coder")]
  58. internal static extern int EnetHostCompressWithRangeCoder(IntPtr host);
  59. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  60. EntryPoint = "enet_host_channel_limit")]
  61. internal static extern void EnetHostChannelLimit(IntPtr host, uint channelLimit);
  62. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  63. EntryPoint = "enet_host_bandwidth_limit")]
  64. internal static extern void EnetHostBandwidthLimit(
  65. IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  66. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_flush")]
  67. internal static extern void EnetHostFlush(IntPtr host);
  68. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_check_events"
  69. )]
  70. internal static extern int EnetHostCheckEvents(IntPtr host, ENetEvent ev);
  71. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_service")]
  72. internal static extern int EnetHostService(IntPtr host, ENetEvent ev, uint timeout);
  73. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_get")]
  74. internal static extern uint EnetTimeGet();
  75. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_set")]
  76. internal static extern void EnetTimeSet(uint newTimeBase);
  77. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_create")]
  78. internal static extern IntPtr EnetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
  79. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_destroy")]
  80. internal static extern void EnetPacketDestroy(IntPtr packet);
  81. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_resize")]
  82. internal static extern int EnetPacketResize(IntPtr packet, uint dataLength);
  83. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  84. EntryPoint = "enet_peer_throttle_configure")]
  85. internal static extern void EnetPeerThrottleConfigure(
  86. IntPtr peer, uint interval, uint acceleration, uint deceleration);
  87. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_send")]
  88. internal static extern int EnetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
  89. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_receive")]
  90. internal static extern IntPtr EnetPeerReceive(IntPtr peer, out byte channelID);
  91. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_reset")]
  92. internal static extern void EnetPeerReset(IntPtr peer);
  93. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_ping")]
  94. internal static extern void EnetPeerPing(IntPtr peer);
  95. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  96. EntryPoint = "enet_peer_disconnect_now")]
  97. internal static extern void EnetPeerDisconnectNow(IntPtr peer, uint data);
  98. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_disconnect")]
  99. internal static extern void EnetPeerDisconnect(IntPtr peer, uint data);
  100. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl,
  101. EntryPoint = "enet_peer_disconnect_later")]
  102. internal static extern void EnetPeerDisconnectLater(IntPtr peer, uint data);
  103. }
  104. }