NativeMethods.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. namespace Base
  5. {
  6. public static class NativeMethods
  7. {
  8. private const string LIB = "ENet";
  9. public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
  10. public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
  11. [DllImport(LIB, EntryPoint = "enet_address_set_host")]
  12. internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);
  13. [DllImport(LIB, EntryPoint = "enet_address_get_host")]
  14. internal static extern int ENetAddressGetHost(ref ENetAddress address, StringBuilder hostName, uint nameLength);
  15. [DllImport(LIB, EntryPoint = "enet_address_get_host_ip")]
  16. internal static extern int ENetAddressGetHostIp(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
  17. [DllImport(LIB, EntryPoint = "enet_deinitialize")]
  18. internal static extern void ENetDeinitialize();
  19. [DllImport(LIB, EntryPoint = "enet_initialize")]
  20. internal static extern int ENetInitialize();
  21. [DllImport(LIB, EntryPoint = "enet_host_create")]
  22. internal static extern IntPtr ENetHostCreate(
  23. ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  24. [DllImport(LIB, EntryPoint = "enet_host_create")]
  25. internal static extern IntPtr ENetHostCreate(IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  26. [DllImport(LIB, EntryPoint = "enet_host_destroy")]
  27. internal static extern void ENetHostDestroy(IntPtr host);
  28. [DllImport(LIB, EntryPoint = "enet_host_connect")]
  29. internal static extern IntPtr ENetHostConnect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
  30. [DllImport(LIB, EntryPoint = "enet_host_broadcast")]
  31. internal static extern void ENetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
  32. [DllImport(LIB, EntryPoint = "enet_host_compress")]
  33. internal static extern void ENetHostCompress(IntPtr host, IntPtr compressor);
  34. [DllImport(LIB, EntryPoint = "enet_host_compress_with_range_coder")]
  35. internal static extern int ENetHostCompressWithRangeCoder(IntPtr host);
  36. [DllImport(LIB, EntryPoint = "enet_host_channel_limit")]
  37. internal static extern void ENetHostChannelLimit(IntPtr host, uint channelLimit);
  38. [DllImport(LIB, EntryPoint = "enet_host_bandwidth_limit")]
  39. internal static extern void ENetHostBandwidthLimit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  40. [DllImport(LIB, EntryPoint = "enet_host_flush")]
  41. internal static extern void ENetHostFlush(IntPtr host);
  42. [DllImport(LIB, EntryPoint = "enet_host_check_events")]
  43. internal static extern int ENetHostCheckEvents(IntPtr host, ENetEvent ev);
  44. [DllImport(LIB, EntryPoint = "enet_host_service")]
  45. internal static extern int ENetHostService(IntPtr host, ENetEvent ev, uint timeout);
  46. [DllImport(LIB, EntryPoint = "enet_time_get")]
  47. internal static extern uint ENetTimeGet();
  48. [DllImport(LIB, EntryPoint = "enet_time_set")]
  49. internal static extern void ENetTimeSet(uint newTimeBase);
  50. [DllImport(LIB, EntryPoint = "enet_packet_create")]
  51. internal static extern IntPtr ENetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
  52. [DllImport(LIB, EntryPoint = "enet_packet_destroy")]
  53. internal static extern void ENetPacketDestroy(IntPtr packet);
  54. [DllImport(LIB, EntryPoint = "enet_packet_resize")]
  55. internal static extern int ENetPacketResize(IntPtr packet, uint dataLength);
  56. [DllImport(LIB, EntryPoint = "enet_peer_throttle_configure")]
  57. internal static extern void ENetPeerThrottleConfigure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
  58. [DllImport(LIB, EntryPoint = "enet_peer_send")]
  59. internal static extern int ENetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
  60. [DllImport(LIB, EntryPoint = "enet_peer_receive")]
  61. internal static extern IntPtr ENetPeerReceive(IntPtr peer, out byte channelID);
  62. [DllImport(LIB, EntryPoint = "enet_peer_reset")]
  63. internal static extern void ENetPeerReset(IntPtr peer);
  64. [DllImport(LIB, EntryPoint = "enet_peer_ping")]
  65. internal static extern void ENetPeerPing(IntPtr peer);
  66. [DllImport(LIB, EntryPoint = "enet_peer_disconnect_now")]
  67. internal static extern void ENetPeerDisconnectNow(IntPtr peer, uint data);
  68. [DllImport(LIB, EntryPoint = "enet_peer_disconnect")]
  69. internal static extern void ENetPeerDisconnect(IntPtr peer, uint data);
  70. [DllImport(LIB, EntryPoint = "enet_peer_disconnect_later")]
  71. internal static extern void ENetPeerDisconnectLater(IntPtr peer, uint data);
  72. }
  73. }