NativeMethods.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. namespace Base
  5. {
  6. public static class NativeMethods
  7. {
  8. #if UNITY_IOS && !UNITY_EDITOR
  9. private const string LIB = "__Internal";
  10. #else
  11. private const string LIB = "ENet";
  12. #endif
  13. public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
  14. public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
  15. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  16. internal static extern int enet_address_set_host(ref ENetAddress address, string hostName);
  17. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  18. internal static extern int enet_address_get_host(ref ENetAddress address, StringBuilder hostName, uint nameLength);
  19. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  20. internal static extern int enet_address_get_host_ip(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
  21. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  22. internal static extern void enet_deinitialize();
  23. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  24. internal static extern int enet_initialize();
  25. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  26. internal static extern IntPtr enet_host_create(
  27. ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  28. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  29. internal static extern IntPtr enet_host_create(IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  30. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  31. internal static extern void enet_host_destroy(IntPtr host);
  32. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  33. internal static extern IntPtr enet_host_connect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
  34. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  35. internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
  36. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  37. internal static extern void enet_host_compress(IntPtr host, IntPtr compressor);
  38. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  39. internal static extern int enet_host_compress_with_range_coder(IntPtr host);
  40. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  41. internal static extern void enet_host_channel_limit(IntPtr host, uint channelLimit);
  42. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  43. internal static extern void enet_host_bandwidth_limit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  44. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  45. internal static extern void enet_host_flush(IntPtr host);
  46. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  47. internal static extern int enet_host_check_events(IntPtr host, ref ENetEvent ev);
  48. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  49. internal static extern int enet_host_service(IntPtr host, IntPtr ev, uint timeout);
  50. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  51. internal static extern uint enet_time_get();
  52. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  53. internal static extern void enet_time_set(uint newTimeBase);
  54. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  55. internal static extern IntPtr enet_packet_create(byte[] data, uint dataLength, PacketFlags flags);
  56. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  57. internal static extern void enet_packet_destroy(IntPtr packet);
  58. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  59. internal static extern int enet_packet_resize(IntPtr packet, uint dataLength);
  60. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  61. internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
  62. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  63. internal static extern int enet_peer_send(IntPtr peer, byte channelID, IntPtr packet);
  64. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  65. internal static extern IntPtr enet_peer_receive(IntPtr peer, out byte channelID);
  66. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  67. internal static extern void enet_peer_reset(IntPtr peer);
  68. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  69. internal static extern void enet_peer_ping(IntPtr peer);
  70. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  71. internal static extern void enet_peer_disconnect_now(IntPtr peer, uint data);
  72. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  73. internal static extern void enet_peer_disconnect(IntPtr peer, uint data);
  74. [DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
  75. internal static extern void enet_peer_disconnect_later(IntPtr peer, uint data);
  76. }
  77. }