├── .gitignore ├── .gitmodules ├── ENet.ndoc ├── ENetCS ├── ENetCS.csproj ├── ENetException.cs ├── Event.cs ├── EventType.cs ├── Host.cs ├── Library.cs ├── Native │ ├── ENetApi.cs │ ├── ENetApiAny.cs │ └── Structs.cs ├── Packet.IList.cs ├── Packet.UserData.cs ├── Packet.cs ├── PacketFlags.cs ├── Peer.cs ├── PeerState.cs └── Properties │ └── AssemblyInfo.cs ├── ENetDLL ├── ENetDLL.vcxproj └── ENetDLL.vcxproj.filters ├── ENetDemo ├── ENetDemo.csproj ├── Program.cs └── Properties │ └── AssemblyInfo.cs ├── ENetUnityDemo ├── .gitignore ├── Assets │ ├── Plugins │ │ ├── ENetCS.dll │ │ ├── x86 │ │ │ └── ENet.dll │ │ └── x86_64 │ │ │ └── ENet.dll │ ├── Scenes │ │ └── Demo.unity │ └── Scripts │ │ └── Demo.cs ├── ProjectSettings │ ├── AudioManager.asset │ ├── ClusterInputManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── ProjectVersion.txt │ ├── QualitySettings.asset │ ├── TagManager.asset │ ├── TimeManager.asset │ └── UnityConnectSettings.asset └── UnityPackageManager │ └── manifest.json ├── LICENSE ├── License.txt ├── README.md └── enet-cs.sln /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # Build results 11 | [Dd]ebug/ 12 | [Dd]ebugPublic/ 13 | [Rr]elease/ 14 | [Rr]eleases/ 15 | build/ 16 | bld/ 17 | [Bb]in/ 18 | [Oo]bj/ 19 | 20 | # Roslyn cache directories 21 | *.ide/ 22 | 23 | # MSTest test Results 24 | [Tt]est[Rr]esult*/ 25 | [Bb]uild[Ll]og.* 26 | 27 | #NUNIT 28 | *.VisualState.xml 29 | TestResult.xml 30 | 31 | # Build Results of an ATL Project 32 | [Dd]ebugPS/ 33 | [Rr]eleasePS/ 34 | dlldata.c 35 | 36 | *_i.c 37 | *_p.c 38 | *_i.h 39 | *.ilk 40 | *.meta 41 | *.obj 42 | *.pch 43 | *.pdb 44 | *.pgc 45 | *.pgd 46 | *.rsp 47 | *.sbr 48 | *.tlb 49 | *.tli 50 | *.tlh 51 | *.tmp 52 | *.tmp_proj 53 | *.log 54 | *.vspscc 55 | *.vssscc 56 | .builds 57 | *.pidb 58 | *.svclog 59 | *.scc 60 | 61 | # Chutzpah Test files 62 | _Chutzpah* 63 | 64 | # Visual C++ cache files 65 | ipch/ 66 | *.aps 67 | *.ncb 68 | *.opensdf 69 | *.sdf 70 | *.cachefile 71 | 72 | # Visual Studio profiler 73 | *.psess 74 | *.vsp 75 | *.vspx 76 | 77 | # TFS 2012 Local Workspace 78 | $tf/ 79 | 80 | # Guidance Automation Toolkit 81 | *.gpState 82 | 83 | # ReSharper is a .NET coding add-in 84 | _ReSharper*/ 85 | *.[Rr]e[Ss]harper 86 | *.DotSettings.user 87 | 88 | # JustCode is a .NET coding addin-in 89 | .JustCode 90 | 91 | # TeamCity is a build add-in 92 | _TeamCity* 93 | 94 | # DotCover is a Code Coverage Tool 95 | *.dotCover 96 | 97 | # NCrunch 98 | _NCrunch_* 99 | .*crunch*.local.xml 100 | 101 | # MightyMoose 102 | *.mm.* 103 | AutoTest.Net/ 104 | 105 | # Web workbench (sass) 106 | .sass-cache/ 107 | 108 | # Installshield output folder 109 | [Ee]xpress/ 110 | 111 | # DocProject is a documentation generator add-in 112 | DocProject/buildhelp/ 113 | DocProject/Help/*.HxT 114 | DocProject/Help/*.HxC 115 | DocProject/Help/*.hhc 116 | DocProject/Help/*.hhk 117 | DocProject/Help/*.hhp 118 | DocProject/Help/Html2 119 | DocProject/Help/html 120 | 121 | # Click-Once directory 122 | publish/ 123 | 124 | # Publish Web Output 125 | *.[Pp]ublish.xml 126 | *.azurePubxml 127 | # TODO: Comment the next line if you want to checkin your web deploy settings 128 | # but database connection strings (with potential passwords) will be unencrypted 129 | *.pubxml 130 | *.publishproj 131 | 132 | # NuGet Packages 133 | *.nupkg 134 | # The packages folder can be ignored because of Package Restore 135 | **/packages/* 136 | # except build/, which is used as an MSBuild target. 137 | !**/packages/build/ 138 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 139 | #!**/packages/repositories.config 140 | 141 | # Windows Azure Build Output 142 | csx/ 143 | *.build.csdef 144 | 145 | # Windows Store app package directory 146 | AppPackages/ 147 | 148 | # Others 149 | sql/ 150 | *.Cache 151 | ClientBin/ 152 | [Ss]tyle[Cc]op.* 153 | ~$* 154 | *~ 155 | *.dbmdl 156 | *.dbproj.schemaview 157 | *.pfx 158 | *.publishsettings 159 | node_modules/ 160 | 161 | # RIA/Silverlight projects 162 | Generated_Code/ 163 | 164 | # Backup & report files from converting an old project file 165 | # to a newer Visual Studio version. Backup files are not needed, 166 | # because we have git ;-) 167 | _UpgradeReport_Files/ 168 | Backup*/ 169 | UpgradeLog*.XML 170 | UpgradeLog*.htm 171 | 172 | # SQL Server files 173 | *.mdf 174 | *.ldf 175 | 176 | # Business Intelligence projects 177 | *.rdl.data 178 | *.bim.layout 179 | *.bim_*.settings 180 | 181 | # Microsoft Fakes 182 | FakesAssemblies/ 183 | 184 | # ========================= 185 | # Operating System Files 186 | # ========================= 187 | 188 | # OSX 189 | # ========================= 190 | 191 | .DS_Store 192 | .AppleDouble 193 | .LSOverride 194 | 195 | # Thumbnails 196 | ._* 197 | 198 | # Files that might appear on external disk 199 | .Spotlight-V100 200 | .Trashes 201 | 202 | # Directories potentially created on remote AFP share 203 | .AppleDB 204 | .AppleDesktop 205 | Network Trash Folder 206 | Temporary Items 207 | .apdisk 208 | 209 | # Windows 210 | # ========================= 211 | 212 | # Windows image file caches 213 | Thumbs.db 214 | ehthumbs.db 215 | 216 | # Folder config file 217 | Desktop.ini 218 | 219 | # Recycle Bin used on file shares 220 | $RECYCLE.BIN/ 221 | 222 | # Windows Installer files 223 | *.cab 224 | *.msi 225 | *.msm 226 | *.msp 227 | 228 | # Windows shortcuts 229 | *.lnk 230 | 231 | # Visual Studio 2015 cache/options directory 232 | .vs/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ENet"] 2 | path = ENet 3 | url = https://github.com/lsalzman/enet 4 | -------------------------------------------------------------------------------- /ENet.ndoc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ENet is a UDP-based networking library for transmitting packets reliably and unreliably, sequenced and unsequenced, and with multiple channels per connection. 7 | 8 | In a game, for example, you can send chat and status updates reliably and positions unreliably, and in the event of packet loss the two will not interfere nor will there be lag on future position updates. Were you to use TCP, on the other hand, a "lag burst" would occur affecting all data, ending only on reception of the lost packet's retry. 9 | Access to the native C API is also available. 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ENetCS/ENetCS.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A} 9 | Library 10 | Properties 11 | ENetCS 12 | ENetCS 13 | v2.0 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | 23 | true 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | true 27 | ..\bin\ENetCS.xml 28 | full 29 | AnyCPU 30 | prompt 31 | MinimumRecommendedRules.ruleset 32 | 33 | 34 | bin\Release\ 35 | TRACE 36 | true 37 | ..\bin\ENetCS.xml 38 | true 39 | pdbonly 40 | AnyCPU 41 | prompt 42 | MinimumRecommendedRules.ruleset 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 72 | -------------------------------------------------------------------------------- /ENetCS/ENetException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2012 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using System.Runtime.Serialization; 22 | 23 | namespace ENet 24 | { 25 | /// 26 | /// This exception is thrown when ENet has an error. 27 | /// 28 | [Serializable] 29 | public class ENetException : Exception 30 | { 31 | /// 32 | /// Initializes an ENetException. 33 | /// 34 | public ENetException() 35 | : base("ENet error.") 36 | { 37 | 38 | } 39 | 40 | /// 41 | /// Initializes an ENetException with a given message. 42 | /// 43 | /// The error message. 44 | public ENetException(string message) 45 | : base(message) 46 | { 47 | 48 | } 49 | 50 | /// 51 | /// Initializes an ENetException with the given message and a reference to an inner exception. 52 | /// 53 | /// The error message. 54 | /// The inner exception. 55 | public ENetException(string message, Exception innerException) 56 | : base(message, innerException) 57 | { 58 | 59 | } 60 | 61 | /// 62 | /// Initializes an ENetException for serialization. 63 | /// 64 | /// The serialized data. 65 | /// The context for the serialization. 66 | protected ENetException(SerializationInfo info, StreamingContext context) 67 | : base(info, context) 68 | { 69 | 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ENetCS/Event.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2012 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using ENet.Native; 21 | 22 | namespace ENet 23 | { 24 | /// 25 | /// Represents an event from the method. 26 | /// 27 | public unsafe struct Event 28 | { 29 | ENetEvent _event; 30 | 31 | /// 32 | /// Initializes an event based on a native C event. 33 | /// 34 | /// The native C event. 35 | public Event(ENetEvent @event) 36 | { 37 | this = new Event() { NativeData = @event }; 38 | } 39 | 40 | /// 41 | /// Gets the channel ID. 42 | /// 43 | public byte ChannelID 44 | { 45 | get { return NativeData.channelID; } 46 | } 47 | 48 | /// 49 | /// Gets the data associated with the event. 50 | /// 51 | public int Data 52 | { 53 | get { return (int)NativeData.data; } 54 | } 55 | 56 | /// 57 | /// Gets or sets the native C event. 58 | /// 59 | public ENetEvent NativeData 60 | { 61 | get { return _event; } 62 | set { _event = value; } 63 | } 64 | 65 | /// 66 | /// Gets the packet associated with the event. 67 | /// 68 | public Packet Packet 69 | { 70 | get { return new Packet(NativeData.packet); } 71 | } 72 | 73 | /// 74 | /// Gets the peer associated with the event. 75 | /// 76 | public Peer Peer 77 | { 78 | get { return new Peer(NativeData.peer); } 79 | } 80 | 81 | /// 82 | /// Gets the event type. 83 | /// 84 | public EventType Type 85 | { 86 | get { return NativeData.type; } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /ENetCS/EventType.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | namespace ENet 21 | { 22 | /// 23 | /// Specifies types of events that can occur. 24 | /// 25 | public enum EventType 26 | { 27 | /// 28 | /// Nothing happened. 29 | /// 30 | None = 0, 31 | 32 | /// 33 | /// A peer has connected. 34 | /// 35 | Connect = 1, 36 | 37 | /// 38 | /// A peer has disconnected. 39 | /// 40 | Disconnect = 2, 41 | 42 | /// 43 | /// A packet has been received. 44 | /// 45 | Receive = 3 46 | } 47 | } -------------------------------------------------------------------------------- /ENetCS/Host.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2012 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using System.Net; 22 | using System.Net.Sockets; 23 | using ENet.Native; 24 | 25 | namespace ENet 26 | { 27 | /// 28 | /// Acts as either client or peer-to-peer/server. 29 | /// 30 | public unsafe struct Host : IDisposable, IEquatable 31 | { 32 | ENetHost* _host; 33 | 34 | /// 35 | /// Initializes a host based on a native C host. 36 | /// 37 | /// The native C peer. 38 | public Host(ENetHost* host) 39 | { 40 | this = new Host() { NativeData = host }; 41 | } 42 | 43 | public override bool Equals(object obj) 44 | { 45 | return obj is Host && Equals((Host)obj); 46 | } 47 | 48 | public bool Equals(Host other) 49 | { 50 | return NativeData == other.NativeData; 51 | } 52 | 53 | public override int GetHashCode() 54 | { 55 | return (int)(long)NativeData; // ENet types are malloc'ed. They do not move. 56 | } 57 | 58 | static void CheckBandwidthLimit(int incomingBandwidth, int outgoingBandwidth) 59 | { 60 | if (incomingBandwidth < 0) { throw new ArgumentOutOfRangeException("incomingBandwidth"); } 61 | if (outgoingBandwidth < 0) { throw new ArgumentOutOfRangeException("outgoingBandwidth"); } 62 | } 63 | 64 | static void CheckChannelLimit(int channelLimit) 65 | { 66 | if (channelLimit < 0 || channelLimit > ENetApi.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) 67 | { throw new ArgumentOutOfRangeException("channelLimit"); } 68 | } 69 | 70 | void CheckInitialized() 71 | { 72 | if (NativeData == null) { throw new InvalidOperationException("Not initialized."); } 73 | } 74 | 75 | /// 76 | /// Initialize a host that will not accept connections. 77 | /// 78 | /// 79 | /// The maximum number of peers for this host. 80 | /// If you are only connecting to one server, set this to 1. 81 | /// 82 | /// 83 | /// is less than 0 or greater than 4095. 84 | /// 85 | /// The host is already initialized. 86 | /// Failed to initialize the host. 87 | public void InitializeClient(int peerLimit) 88 | { 89 | Initialize(null, peerLimit); 90 | } 91 | 92 | /// 93 | /// Initialize a host that will accept connections on any IP address. 94 | /// 95 | /// The port to listen on. 96 | /// The maximum number of peers for this host. 97 | /// 98 | /// is less than 0 or greater than 65535, and/or 99 | /// is less than 0 or greater than 4095. 100 | /// 101 | /// The host is already initialized. 102 | /// Failed to initialize the host. 103 | public void InitializeServer(int port, int peerLimit) 104 | { 105 | Initialize(new IPEndPoint(IPAddress.Any, port), peerLimit); 106 | } 107 | 108 | /// 109 | /// Initialize a host that will accept connections on a particular address, or not accept connections. 110 | /// 111 | /// The address to listen on, or null to not accept connections. 112 | /// The maximum number of peers for this host. 113 | /// The maximum number of channels, or 0 to use the maximum possible (255). 114 | /// The maximum incoming rate of transfer, or 0 for no limit. 115 | /// The maximum outgoing rate of transfer, or 0 for no limit. 116 | /// 117 | /// is less than 0 or greater than 4095, 118 | /// is less than 0 or greater than 255, 119 | /// is less than 0, and/or 120 | /// is less than 0. 121 | /// 122 | /// The host is already initialized. 123 | /// Failed to initialize the host. 124 | public void Initialize(IPEndPoint address, int peerLimit, 125 | int channelLimit = 0, int incomingBandwidth = 0, int outgoingBandwidth = 0) 126 | { 127 | if (NativeData != null) { throw new InvalidOperationException("Already initialized."); } 128 | if (peerLimit < 0 || peerLimit > ENetApi.ENET_PROTOCOL_MAXIMUM_PEER_ID) 129 | { throw new ArgumentOutOfRangeException("peerLimit"); } 130 | CheckChannelLimit(channelLimit); 131 | CheckBandwidthLimit(incomingBandwidth, outgoingBandwidth); 132 | 133 | if (address != null) 134 | { 135 | ENetAddress nativeAddress = (ENetAddress)address; 136 | NativeData = ENetApi.enet_host_create(ref nativeAddress, (IntPtr)peerLimit, 137 | (IntPtr)channelLimit, (uint)incomingBandwidth, (uint)outgoingBandwidth); 138 | } 139 | else 140 | { 141 | NativeData = ENetApi.enet_host_create(null, (IntPtr)peerLimit, 142 | (IntPtr)channelLimit, (uint)incomingBandwidth, (uint)outgoingBandwidth); 143 | } 144 | if (NativeData == null) { throw new ENetException("Host creation call failed."); } 145 | } 146 | 147 | /// 148 | /// Destroys the host. 149 | /// 150 | public void Dispose() 151 | { 152 | if (NativeData != null) 153 | { 154 | ENetApi.enet_host_destroy(NativeData); 155 | NativeData = null; 156 | } 157 | } 158 | 159 | /// 160 | /// Broadcast a packet to all peers. 161 | /// 162 | /// The ID of the channel 163 | /// The packet to send. 164 | /// ENet takes ownership of the packet. Do not call methods on it afterwards. 165 | /// The host is not initialized. 166 | public void Broadcast(byte channelID, ref Packet packet) 167 | { 168 | CheckInitialized(); packet.CheckInitialized(); 169 | 170 | bool clear = packet.ReferenceCount == 0; 171 | ENetApi.enet_host_broadcast(NativeData, channelID, packet.NativeData); 172 | if (clear) { packet.NativeData = null; } // Broadcast may automatically free in this case. 173 | } 174 | 175 | /// 176 | /// Enables compression using the range encoder. 177 | /// 178 | /// The host is not initialized. 179 | /// Failed to create range encoder. This is likely due to low memory. 180 | public void CompressWithRangeEncoder() 181 | { 182 | CheckInitialized(); 183 | int ret = ENetApi.enet_host_compress_with_range_encoder(NativeData); 184 | if (ret < 0) { throw new ENetException("Failed to create range encoder."); } 185 | } 186 | 187 | /// 188 | /// Disables compression. 189 | /// 190 | /// The host is not initialized. 191 | public void DoNotCompress() 192 | { 193 | CheckInitialized(); 194 | ENetApi.enet_host_compress(NativeData, null); 195 | } 196 | 197 | /// 198 | /// Checks for queued events. 199 | /// 200 | /// The dequeued event. 201 | /// True if an event was dequeued, otherwise false. 202 | /// The host is not initialized. 203 | /// An error occured while checking events. 204 | public bool CheckEvents(out Event @event) 205 | { 206 | CheckInitialized(); ENetEvent nativeEvent; 207 | int ret = ENetApi.enet_host_check_events(NativeData, out nativeEvent); 208 | if (ret < 0) { throw new ENetException("Error while checking for events."); } 209 | if (ret == 0) { @event = new Event(); return false; } 210 | @event = new Event(nativeEvent); return true; 211 | } 212 | 213 | /// 214 | /// Connects to a remote computer at the given host and port. 215 | /// 216 | /// The IP address or host name to connect to. 217 | /// The port to connect to. 218 | /// Data to send along with the connect packet. 219 | /// The maximum number of channels, or 0 to use the maximum possible (255). 220 | /// 221 | /// The new peer. This method does not block: the connection will be established 222 | /// when you receive a event. 223 | /// 224 | /// is null. 225 | /// is invalid. 226 | /// 227 | /// is too long, 228 | /// is less than 0 or greater than 65535, and/or 229 | /// is less than 0 or greater than 255. 230 | /// 231 | /// The host is not initialized. 232 | /// Host name lookup failed, or no IPv4 hosts were available. 233 | /// An error occured. 234 | public Peer Connect(string hostName, int port, int data, int channelLimit = 0) 235 | { 236 | IPAddress[] addresses = Dns.GetHostAddresses(hostName); 237 | foreach (IPAddress address in addresses) 238 | { 239 | if (address.AddressFamily == AddressFamily.InterNetwork) 240 | { 241 | return Connect(new IPEndPoint(address, port), data, channelLimit); 242 | } 243 | } 244 | throw new SocketException(); 245 | } 246 | 247 | /// 248 | /// Connects to a remote computer at the given address. 249 | /// 250 | /// The address to connect to. 251 | /// Data to send along with the connect packet. 252 | /// The maximum number of channels, or 0 to use the maximum possible (255). 253 | /// 254 | /// The new peer. This method does not block: the connection will be established 255 | /// when you receive a event. 256 | /// 257 | /// is null. 258 | /// is not IPv4. 259 | /// 260 | /// 's port is less than 0 or greater than 65535, and/or 261 | /// is less than 0 or greater than 255. 262 | /// 263 | /// The host is not initialized. 264 | /// An error occured. 265 | public Peer Connect(IPEndPoint address, int data, int channelLimit = 0) 266 | { 267 | CheckInitialized(); ENetAddress nativeAddress = (ENetAddress)address; 268 | CheckChannelLimit(channelLimit); 269 | 270 | // For consistency with Connect() and SetChannelLimit(), 271 | if (channelLimit == 0) { channelLimit = (int)ENetApi.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT; } 272 | 273 | Peer peer = new Peer(ENetApi.enet_host_connect(NativeData, ref nativeAddress, (IntPtr)channelLimit, (uint)data)); 274 | if (peer.NativeData == null) { throw new ENetException("Host connect failed."); } 275 | return peer; 276 | } 277 | 278 | /// 279 | /// Sends queued packets immediately. Normally they are sent when you call . 280 | /// 281 | /// The host is not initialized. 282 | public void Flush() 283 | { 284 | CheckInitialized(); 285 | ENetApi.enet_host_flush(NativeData); 286 | } 287 | 288 | /// 289 | /// Sends queued outgoing packets, receives incoming packets, and handles connection events. 290 | /// 291 | /// Timeout in milliseconds to wait for an event. For polling, use 0. 292 | /// The event. 293 | /// True if an event occured, otherwise false. 294 | /// is negative. 295 | /// The host is not initialized. 296 | /// An error occured. 297 | public bool Service(int timeout, out Event @event) 298 | { 299 | if (timeout < 0) { throw new ArgumentOutOfRangeException("timeout"); } 300 | CheckInitialized(); ENetEvent nativeEvent = new ENetEvent(); 301 | 302 | // As of 1.3.6, ENet is not signal safe, and Mono uses signals for garbage collection. 303 | // 304 | // So, there's really nothing better we can do than retry. Luckily the cases that return -1 305 | // are cases that return immediately or this could cause lockups. 306 | // 307 | // The entire situation is still very dicey with MonoDevelop. 308 | // A proper fix really has to be done in the ENet native library. 309 | // If you want to eliminate this entirely and don't care about these spurious 310 | // failures of enet_host_service, try/catch the ENetException and just ignore it. 311 | // That's essentially what I am doing here, except with an upper limit so real errors 312 | // can get through... 313 | int ret = -1; 314 | for (int nretries = 0; nretries < 1000 && ret == -1; nretries++) 315 | { 316 | ret = ENetApi.enet_host_service(NativeData, out nativeEvent, (uint)timeout); 317 | } 318 | 319 | if (ret < 0) { throw new ENetException(string.Format("Service failed (native data {0}).", (IntPtr)NativeData)); } 320 | if (ret == 0) { @event = new Event(); return false; } 321 | @event = new Event(nativeEvent); return true; 322 | } 323 | 324 | /// 325 | /// Set the bandwidth limit. 326 | /// 327 | /// The maximum incoming rate of transfer, or 0 for no limit. 328 | /// The maximum outgoing rate of transfer, or 0 for no limit. 329 | /// 330 | /// is less than 0, and/or 331 | /// is less than 0. 332 | /// 333 | /// The host is not initialized. 334 | public void SetBandwidthLimit(int incomingBandwidth, int outgoingBandwidth) 335 | { 336 | CheckInitialized(); CheckBandwidthLimit(incomingBandwidth, outgoingBandwidth); 337 | ENetApi.enet_host_bandwidth_limit(NativeData, (uint)incomingBandwidth, (uint)outgoingBandwidth); 338 | } 339 | 340 | /// 341 | /// Set the channel limit. 342 | /// 343 | /// The maximum number of channels, or 0 to use the maximum possible (255). 344 | /// The host is not initialized. 345 | public void SetChannelLimit(int channelLimit) 346 | { 347 | CheckChannelLimit(channelLimit); CheckInitialized(); 348 | ENetApi.enet_host_channel_limit(NativeData, (IntPtr)channelLimit); 349 | } 350 | 351 | /// 352 | /// Gets or sets the native C host. 353 | /// 354 | public ENetHost* NativeData 355 | { 356 | get { return _host; } 357 | set { _host = value; } 358 | } 359 | 360 | /// 361 | /// Returns true if the host is initialized. 362 | /// 363 | public bool IsInitialized 364 | { 365 | get { return NativeData != null; } 366 | } 367 | 368 | public static bool operator ==(Host host1, Host host2) 369 | { 370 | return host1.Equals(host2); 371 | } 372 | 373 | public static bool operator !=(Host host1, Host host2) 374 | { 375 | return !host1.Equals(host2); 376 | } 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /ENetCS/Library.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2013 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using ENet.Native; 22 | 23 | namespace ENet 24 | { 25 | /// 26 | /// Provides initialization, deinitialization, and time-keeping methods. 27 | /// 28 | public unsafe static class Library 29 | { 30 | /// 31 | /// Throws an exception if the ENet native library cannot be loaded. 32 | /// ENet is now automatically initialized, so it is no longer strictly 33 | /// necessary to call this function. 34 | /// 35 | /// The native library cannot be loaded. 36 | public static void Initialize() 37 | { 38 | ENetApi.enet_time_get(); 39 | } 40 | 41 | /// 42 | /// This method is retained for backwards compatibility. It does nothing. 43 | /// 44 | public static void Deinitialize() 45 | { 46 | 47 | } 48 | 49 | /// 50 | /// Gets or set the time in milliseconds. 51 | /// 52 | public static int Time 53 | { 54 | get { return (int)ENetApi.enet_time_get(); } 55 | set { ENetApi.enet_time_set((uint)value); } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ENetCS/Native/ENetApi.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2013 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | #pragma warning disable 1591 21 | 22 | using System; 23 | 24 | namespace ENet.Native 25 | { 26 | public unsafe abstract class ENetApi 27 | { 28 | public const uint ENET_HOST_ANY = 0; 29 | public const uint ENET_HOST_BROADCAST = 0xffffffff; 30 | public const uint ENET_PEER_PACKET_THROTTLE_SCALE = 32; 31 | public const uint ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2; 32 | public const uint ENET_PEER_PACKET_THROTTLE_DECELERATION = 2; 33 | public const uint ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000; 34 | public const uint ENET_PEER_PING_INTERVAL = 500; 35 | public const uint ENET_PEER_TIMEOUT_LIMIT = 32; 36 | public const uint ENET_PEER_TIMEOUT_MINIMUM = 5000; 37 | public const uint ENET_PEER_TIMEOUT_MAXIMUM = 30000; 38 | public const uint ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 0x01; 39 | public const uint ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 0xff; 40 | public const uint ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT = 1024 * 1024; 41 | public const uint ENET_PROTOCOL_MAXIMUM_PACKET_SIZE = 1024 * 1024 * 1024; 42 | public const uint ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff; 43 | const uint ENET_VERSION = (1 << 16) | (3 << 8) | (6 << 0); 44 | 45 | #region Platform Detection 46 | internal static ENetApi _platform; 47 | internal static object _platformLock = new object(); 48 | 49 | internal ENetApi() 50 | { 51 | 52 | } 53 | 54 | internal static ENetApi Platform 55 | { 56 | get 57 | { 58 | if (_platform == null) 59 | { 60 | lock (_platformLock) 61 | { 62 | if (_platform == null) 63 | { 64 | foreach (ENetApi platform in new ENetApi[] 65 | { 66 | new ENetApiAny(), 67 | }) 68 | { 69 | try 70 | { 71 | ENetCallbacks inits = new ENetCallbacks(); 72 | if (platform.initialize_with_callbacks(ENET_VERSION, ref inits) >= 0) 73 | { 74 | _platform = platform; return platform; 75 | } 76 | } 77 | catch (BadImageFormatException) 78 | { 79 | continue; 80 | } 81 | catch (DllNotFoundException) 82 | { 83 | continue; 84 | } 85 | catch (EntryPointNotFoundException) 86 | { 87 | continue; 88 | } 89 | } 90 | 91 | throw new ENetException 92 | ("The ENet native library failed to initialize." + 93 | " Make sure ENetX86.dll and ENetX64.dll are in the program directory, and that" + 94 | " you are running on a x86 or x64-based computer." + 95 | " If you are running on Linux, make sure the libenet.so.1 is in your path." + 96 | " On Ubuntu Linux, install the libenet1a package (1.3.3 or newer) if you haven't already." + 97 | " If you are running on MacOS, make sure libenet.dylib is in your path or program directory."); 98 | } 99 | 100 | return _platform; 101 | } 102 | } 103 | 104 | return _platform; 105 | } 106 | } 107 | #endregion 108 | 109 | #region Address Functions 110 | public static int enet_address_set_host(ref ENetAddress address, byte* hostName) 111 | { 112 | return Platform.address_set_host(ref address, hostName); 113 | } 114 | 115 | public static int enet_address_set_host(ref ENetAddress address, byte[] hostName) 116 | { 117 | return Platform.address_set_host(ref address, hostName); 118 | } 119 | 120 | public static int enet_address_get_host(ref ENetAddress address, byte* hostName, IntPtr nameLength) 121 | { 122 | return Platform.address_get_host(ref address, hostName, nameLength); 123 | } 124 | 125 | public static int enet_address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength) 126 | { 127 | return Platform.address_get_host(ref address, hostName, nameLength); 128 | } 129 | 130 | public static int enet_address_get_host_ip(ref ENetAddress address, byte* hostIP, IntPtr ipLength) 131 | { 132 | return Platform.address_get_host_ip(ref address, hostIP, ipLength); 133 | } 134 | 135 | public static int enet_address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength) 136 | { 137 | return Platform.address_get_host_ip(ref address, hostIP, ipLength); 138 | } 139 | 140 | public abstract int address_set_host(ref ENetAddress address, byte* hostName); 141 | 142 | public abstract int address_set_host(ref ENetAddress address, byte[] hostName); 143 | 144 | public abstract int address_get_host(ref ENetAddress address, byte* hostName, IntPtr nameLength); 145 | 146 | public abstract int address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength); 147 | 148 | public abstract int address_get_host_ip(ref ENetAddress address, byte* hostIP, IntPtr ipLength); 149 | 150 | public abstract int address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength); 151 | #endregion 152 | 153 | #region Global Functions 154 | public abstract int initialize_with_callbacks(uint version, ref ENetCallbacks inits); 155 | #endregion 156 | 157 | #region Host Functions 158 | public static void enet_host_bandwidth_limit(ENetHost* host, uint incomingBandwidth, uint outgoingBandwidth) 159 | { 160 | Platform.host_bandwidth_limit(host, incomingBandwidth, outgoingBandwidth); 161 | } 162 | 163 | public static void enet_host_broadcast(ENetHost* host, byte channelID, ENetPacket* packet) 164 | { 165 | Platform.host_broadcast(host, channelID, packet); 166 | } 167 | 168 | public static void enet_host_channel_limit(ENetHost* host, IntPtr channelLimit) 169 | { 170 | Platform.host_channel_limit(host, channelLimit); 171 | } 172 | 173 | public static int enet_host_check_events(ENetHost* host, out ENetEvent @event) 174 | { 175 | return Platform.host_check_events(host, out @event); 176 | } 177 | 178 | public static ENetPeer* enet_host_connect(ENetHost* host, ref ENetAddress address, IntPtr channelCount, uint data) 179 | { 180 | return Platform.host_connect(host, ref address, channelCount, data); 181 | } 182 | 183 | public static void enet_host_compress(ENetHost* host, ENetCompressor* compressor) 184 | { 185 | Platform.host_compress(host, compressor); 186 | } 187 | 188 | public static int enet_host_compress_with_range_encoder(ENetHost* host) 189 | { 190 | return Platform.host_compress_with_range_encoder(host); 191 | } 192 | 193 | public static ENetHost* enet_host_create(ENetAddress* address, 194 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth) 195 | { 196 | return Platform.host_create(address, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth); 197 | } 198 | 199 | public static ENetHost* enet_host_create(ref ENetAddress address, 200 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth) 201 | { 202 | return Platform.host_create(ref address, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth); 203 | } 204 | 205 | public static void enet_host_destroy(ENetHost* host) 206 | { 207 | Platform.host_destroy(host); 208 | } 209 | 210 | public static void enet_host_flush(ENetHost* host) 211 | { 212 | Platform.host_flush(host); 213 | } 214 | 215 | public static int enet_host_service(ENetHost* host, ENetEvent* @event, uint timeout) 216 | { 217 | return Platform.host_service(host, @event, timeout); 218 | } 219 | 220 | public static int enet_host_service(ENetHost* host, out ENetEvent @event, uint timeout) 221 | { 222 | return Platform.host_service(host, out @event, timeout); 223 | } 224 | 225 | public abstract void host_bandwidth_limit(ENetHost* host, uint incomingBandwidth, uint outgoingBandwidth); 226 | 227 | public abstract void host_broadcast(ENetHost* host, byte channelID, ENetPacket* packet); 228 | 229 | public abstract void host_channel_limit(ENetHost* host, IntPtr channelLimit); 230 | 231 | public abstract int host_check_events(ENetHost* host, out ENetEvent @event); 232 | 233 | public abstract ENetPeer* host_connect(ENetHost* host, ref ENetAddress address, IntPtr channelCount, uint data); 234 | 235 | public abstract void host_compress(ENetHost* host, ENetCompressor* compressor); 236 | 237 | public abstract int host_compress_with_range_encoder(ENetHost* host); 238 | 239 | public abstract ENetHost* host_create(ENetAddress* address, 240 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth); 241 | 242 | public abstract ENetHost* host_create(ref ENetAddress address, 243 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth); 244 | 245 | public abstract void host_destroy(ENetHost* host); 246 | 247 | public abstract void host_flush(ENetHost* host); 248 | 249 | public abstract int host_service(ENetHost* host, ENetEvent* @event, uint timeout); 250 | 251 | public abstract int host_service(ENetHost* host, out ENetEvent @event, uint timeout); 252 | #endregion 253 | 254 | #region Miscellaneous Functions 255 | public static uint enet_time_get() 256 | { 257 | return Platform.time_get(); 258 | } 259 | 260 | public static void enet_time_set(uint newTimeBase) 261 | { 262 | Platform.time_set(newTimeBase); 263 | } 264 | 265 | public abstract uint time_get(); 266 | 267 | public abstract void time_set(uint newTimeBase); 268 | #endregion 269 | 270 | #region Packet Functions 271 | public static ENetPacket* enet_packet_create(IntPtr data, IntPtr dataLength, PacketFlags flags) 272 | { 273 | return Platform.packet_create(data, dataLength, flags); 274 | } 275 | 276 | public static void enet_packet_destroy(ENetPacket* packet) 277 | { 278 | Platform.packet_destroy(packet); 279 | } 280 | 281 | public static int enet_packet_resize(ENetPacket* packet, IntPtr dataLength) 282 | { 283 | return Platform.packet_resize(packet, dataLength); 284 | } 285 | 286 | public abstract ENetPacket* packet_create(IntPtr data, IntPtr dataLength, PacketFlags flags); 287 | 288 | public abstract void packet_destroy(ENetPacket* packet); 289 | 290 | public abstract int packet_resize(ENetPacket* packet, IntPtr dataLength); 291 | #endregion 292 | 293 | #region Peer Functions 294 | public static void enet_peer_disconnect(ENetPeer* peer, uint data) 295 | { 296 | Platform.peer_disconnect(peer, data); 297 | } 298 | 299 | public static void enet_peer_disconnect_now(ENetPeer* peer, uint data) 300 | { 301 | Platform.peer_disconnect_now(peer, data); 302 | } 303 | 304 | public static void enet_peer_disconnect_later(ENetPeer* peer, uint data) 305 | { 306 | Platform.peer_disconnect_later(peer, data); 307 | } 308 | 309 | public static void enet_peer_ping(ENetPeer* peer) 310 | { 311 | Platform.peer_ping(peer); 312 | } 313 | 314 | public static void enet_peer_ping_interval(ENetPeer* peer, uint pingInterval) 315 | { 316 | Platform.peer_ping_interval(peer, pingInterval); 317 | } 318 | 319 | public static ENetPacket* enet_peer_receive(ENetPeer* peer, out byte channelID) 320 | { 321 | return Platform.peer_receive(peer, out channelID); 322 | } 323 | 324 | public static void enet_peer_reset(ENetPeer* peer) 325 | { 326 | Platform.peer_reset(peer); 327 | } 328 | 329 | public static int enet_peer_send(ENetPeer* peer, byte channelID, ENetPacket* packet) 330 | { 331 | return Platform.peer_send(peer, channelID, packet); 332 | } 333 | 334 | public static void enet_peer_throttle_configure(ENetPeer* peer, uint interval, uint acceleration, uint deceleration) 335 | { 336 | Platform.peer_throttle_configure(peer, interval, acceleration, deceleration); 337 | } 338 | 339 | public static void enet_peer_timeout(ENetPeer* peer, uint timeoutLimit, uint timeoutMinimum, uint timeoutMaximum) 340 | { 341 | Platform.peer_timeout(peer, timeoutLimit, timeoutMinimum, timeoutMaximum); 342 | } 343 | 344 | public abstract void peer_disconnect(ENetPeer* peer, uint data); 345 | 346 | public abstract void peer_disconnect_now(ENetPeer* peer, uint data); 347 | 348 | public abstract void peer_disconnect_later(ENetPeer* peer, uint data); 349 | 350 | public abstract void peer_ping(ENetPeer* peer); 351 | 352 | public abstract void peer_ping_interval(ENetPeer* peer, uint pingInterval); 353 | 354 | public abstract ENetPacket* peer_receive(ENetPeer* peer, out byte channelID); 355 | 356 | public abstract void peer_reset(ENetPeer* peer); 357 | 358 | public abstract int peer_send(ENetPeer* peer, byte channelID, ENetPacket* packet); 359 | 360 | public abstract void peer_throttle_configure(ENetPeer* peer, uint interval, uint acceleration, uint deceleration); 361 | 362 | public abstract void peer_timeout(ENetPeer* peer, uint timeoutLimit, uint timeoutMinimum, uint timeoutMaximum); 363 | #endregion 364 | 365 | #region C# Utility 366 | public static bool memcmp(byte[] s1, byte[] s2) 367 | { 368 | if (s1 == null || s2 == null) { throw new ArgumentNullException(); } 369 | if (s1.Length != s2.Length) { return false; } 370 | 371 | for (int i = 0; i < s1.Length; i++) { if (s1[i] != s2[i]) { return false; } } 372 | return true; 373 | } 374 | 375 | public static int strlen(byte[] s) 376 | { 377 | if (s == null) { throw new ArgumentNullException(); } 378 | 379 | int i; 380 | for (i = 0; i < s.Length && s[i] != 0; i++) ; 381 | return i; 382 | } 383 | #endregion 384 | } 385 | } 386 | -------------------------------------------------------------------------------- /ENetCS/Native/ENetApiAny.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2013 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | #pragma warning disable 1591 21 | 22 | using System; 23 | using System.Runtime.InteropServices; 24 | 25 | namespace ENet.Native 26 | { 27 | unsafe sealed class ENetApiAny : ENetApi 28 | { 29 | const string LIB = "ENet"; 30 | 31 | #region Address Functions 32 | public override int address_set_host(ref ENetAddress address, byte* hostName) 33 | { 34 | return native_address_set_host(ref address, hostName); 35 | } 36 | 37 | public override int address_set_host(ref ENetAddress address, byte[] hostName) 38 | { 39 | return native_address_set_host(ref address, hostName); 40 | } 41 | 42 | public override int address_get_host(ref ENetAddress address, byte* hostName, IntPtr nameLength) 43 | { 44 | return native_address_get_host(ref address, hostName, nameLength); 45 | } 46 | 47 | public override int address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength) 48 | { 49 | return native_address_get_host(ref address, hostName, nameLength); 50 | } 51 | 52 | public override int address_get_host_ip(ref ENetAddress address, byte* hostIP, IntPtr ipLength) 53 | { 54 | return native_address_get_host_ip(ref address, hostIP, ipLength); 55 | } 56 | 57 | public override int address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength) 58 | { 59 | return native_address_get_host_ip(ref address, hostIP, ipLength); 60 | } 61 | 62 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_set_host")] 63 | static extern int native_address_set_host(ref ENetAddress address, byte* hostName); 64 | 65 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_set_host")] 66 | static extern int native_address_set_host(ref ENetAddress address, byte[] hostName); 67 | 68 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_get_host")] 69 | static extern int native_address_get_host(ref ENetAddress address, byte* hostName, IntPtr nameLength); 70 | 71 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_get_host")] 72 | static extern int native_address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength); 73 | 74 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_get_host_ip")] 75 | static extern int native_address_get_host_ip(ref ENetAddress address, byte* hostIP, IntPtr ipLength); 76 | 77 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_address_get_host_ip")] 78 | static extern int native_address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength); 79 | #endregion 80 | 81 | #region Global Functions 82 | public override int initialize_with_callbacks(uint version, ref ENetCallbacks inits) 83 | { 84 | return native_initialize_with_callbacks(version, ref inits); 85 | } 86 | 87 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_initialize_with_callbacks")] 88 | static extern int native_initialize_with_callbacks(uint version, ref ENetCallbacks inits); 89 | #endregion 90 | 91 | #region Host Functions 92 | public override void host_bandwidth_limit(ENetHost* host, uint incomingBandwidth, uint outgoingBandwidth) 93 | { 94 | native_host_bandwidth_limit(host, incomingBandwidth, outgoingBandwidth); 95 | } 96 | 97 | public override void host_broadcast(ENetHost* host, byte channelID, ENetPacket* packet) 98 | { 99 | native_host_broadcast(host, channelID, packet); 100 | } 101 | 102 | public override void host_channel_limit(ENetHost* host, IntPtr channelLimit) 103 | { 104 | native_host_channel_limit(host, channelLimit); 105 | } 106 | 107 | public override int host_check_events(ENetHost* host, out ENetEvent @event) 108 | { 109 | return native_host_check_events(host, out @event); 110 | } 111 | 112 | public override void host_compress(ENetHost* host, ENetCompressor* compressor) 113 | { 114 | native_host_compress(host, compressor); 115 | } 116 | 117 | public override int host_compress_with_range_encoder(ENetHost* host) 118 | { 119 | return native_host_compress_with_range_encoder(host); 120 | } 121 | 122 | public override ENetPeer* host_connect(ENetHost* host, ref ENetAddress address, IntPtr channelCount, uint data) 123 | { 124 | return native_host_connect(host, ref address, channelCount, data); 125 | } 126 | 127 | public override ENetHost* host_create(ENetAddress* address, 128 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth) 129 | { 130 | return native_host_create(address, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth); 131 | } 132 | 133 | public override ENetHost* host_create(ref ENetAddress address, 134 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth) 135 | { 136 | return native_host_create(ref address, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth); 137 | } 138 | 139 | public override void host_destroy(ENetHost* host) 140 | { 141 | native_host_destroy(host); 142 | } 143 | 144 | public override void host_flush(ENetHost* host) 145 | { 146 | native_host_flush(host); 147 | } 148 | 149 | public override int host_service(ENetHost* host, ENetEvent* @event, uint timeout) 150 | { 151 | return native_host_service(host, @event, timeout); 152 | } 153 | 154 | public override int host_service(ENetHost* host, out ENetEvent @event, uint timeout) 155 | { 156 | return native_host_service(host, out @event, timeout); 157 | } 158 | 159 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_bandwidth_limit")] 160 | static extern void native_host_bandwidth_limit(ENetHost* host, uint incomingBandwidth, uint outgoingBandwidth); 161 | 162 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_broadcast")] 163 | static extern void native_host_broadcast(ENetHost* host, byte channelID, ENetPacket* packet); 164 | 165 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_channel_limit")] 166 | static extern void native_host_channel_limit(ENetHost* host, IntPtr channelLimit); 167 | 168 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_check_events")] 169 | static extern int native_host_check_events(ENetHost* host, out ENetEvent @event); 170 | 171 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_compress")] 172 | static extern void native_host_compress(ENetHost* host, ENetCompressor* compressor); 173 | 174 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_compress_with_range_encoder")] 175 | static extern int native_host_compress_with_range_encoder(ENetHost* host); 176 | 177 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_connect")] 178 | static extern ENetPeer* native_host_connect(ENetHost* host, ref ENetAddress address, IntPtr channelCount, uint data); 179 | 180 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create")] 181 | static extern ENetHost* native_host_create(ENetAddress* address, 182 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth); 183 | 184 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_create")] 185 | static extern ENetHost* native_host_create(ref ENetAddress address, 186 | IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth); 187 | 188 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_destroy")] 189 | static extern void native_host_destroy(ENetHost* host); 190 | 191 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_flush")] 192 | static extern void native_host_flush(ENetHost* host); 193 | 194 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_service")] 195 | static extern int native_host_service(ENetHost* host, ENetEvent* @event, uint timeout); 196 | 197 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_host_service")] 198 | static extern int native_host_service(ENetHost* host, out ENetEvent @event, uint timeout); 199 | #endregion 200 | 201 | #region Miscellaneous Functions 202 | public override uint time_get() 203 | { 204 | return native_time_get(); 205 | } 206 | 207 | public override void time_set(uint newTimeBase) 208 | { 209 | native_time_set(newTimeBase); 210 | } 211 | 212 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_get")] 213 | static extern uint native_time_get(); 214 | 215 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_time_set")] 216 | static extern void native_time_set(uint newTimeBase); 217 | #endregion 218 | 219 | #region Packet Functions 220 | public override ENetPacket* packet_create(IntPtr data, IntPtr dataLength, PacketFlags flags) 221 | { 222 | return native_packet_create(data, dataLength, flags); 223 | } 224 | 225 | public override void packet_destroy(ENetPacket* packet) 226 | { 227 | native_packet_destroy(packet); 228 | } 229 | 230 | public override int packet_resize(ENetPacket* packet, IntPtr dataLength) 231 | { 232 | return native_packet_resize(packet, dataLength); 233 | } 234 | 235 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_create")] 236 | static extern ENetPacket* native_packet_create(IntPtr data, IntPtr dataLength, PacketFlags flags); 237 | 238 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_destroy")] 239 | static extern void native_packet_destroy(ENetPacket* packet); 240 | 241 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_packet_resize")] 242 | static extern int native_packet_resize(ENetPacket* packet, IntPtr dataLength); 243 | #endregion 244 | 245 | #region Peer Functions 246 | public override void peer_disconnect(ENetPeer* peer, uint data) 247 | { 248 | native_peer_disconnect(peer, data); 249 | } 250 | 251 | public override void peer_disconnect_now(ENetPeer* peer, uint data) 252 | { 253 | native_peer_disconnect_now(peer, data); 254 | } 255 | 256 | public override void peer_disconnect_later(ENetPeer* peer, uint data) 257 | { 258 | native_peer_disconnect_later(peer, data); 259 | } 260 | 261 | public override void peer_ping(ENetPeer* peer) 262 | { 263 | native_peer_ping(peer); 264 | } 265 | 266 | public override void peer_ping_interval(ENetPeer* peer, uint pingInterval) 267 | { 268 | native_peer_ping_interval(peer, pingInterval); 269 | } 270 | 271 | public override ENetPacket* peer_receive(ENetPeer* peer, out byte channelID) 272 | { 273 | return native_peer_receive(peer, out channelID); 274 | } 275 | 276 | public override void peer_reset(ENetPeer* peer) 277 | { 278 | native_peer_reset(peer); 279 | } 280 | 281 | public override int peer_send(ENetPeer* peer, byte channelID, ENetPacket* packet) 282 | { 283 | return native_peer_send(peer, channelID, packet); 284 | } 285 | 286 | public override void peer_throttle_configure(ENetPeer* peer, uint interval, uint acceleration, uint deceleration) 287 | { 288 | native_peer_throttle_configure(peer, interval, acceleration, deceleration); 289 | } 290 | 291 | public override void peer_timeout(ENetPeer* peer, uint timeoutLimit, uint timeoutMinimum, uint timeoutMaximum) 292 | { 293 | native_peer_timeout(peer, timeoutLimit, timeoutMinimum, timeoutMaximum); 294 | } 295 | 296 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_disconnect")] 297 | static extern void native_peer_disconnect(ENetPeer* peer, uint data); 298 | 299 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_disconnect_now")] 300 | static extern void native_peer_disconnect_now(ENetPeer* peer, uint data); 301 | 302 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_disconnect_later")] 303 | static extern void native_peer_disconnect_later(ENetPeer* peer, uint data); 304 | 305 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_ping")] 306 | static extern void native_peer_ping(ENetPeer* peer); 307 | 308 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_ping_interval")] 309 | static extern void native_peer_ping_interval(ENetPeer* peer, uint pingInterval); 310 | 311 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_receive")] 312 | static extern ENetPacket* native_peer_receive(ENetPeer* peer, out byte channelID); 313 | 314 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_reset")] 315 | static extern void native_peer_reset(ENetPeer* peer); 316 | 317 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_send")] 318 | static extern int native_peer_send(ENetPeer* peer, byte channelID, ENetPacket* packet); 319 | 320 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_throttle_configure")] 321 | static extern void native_peer_throttle_configure(ENetPeer* peer, uint interval, uint acceleration, uint deceleration); 322 | 323 | [DllImport(LIB, CallingConvention = CallingConvention.Cdecl, EntryPoint = "enet_peer_timeout")] 324 | static extern void native_peer_timeout(ENetPeer* peer, uint timeoutLimit, uint timeoutMinimum, uint timeoutMaximum); 325 | #endregion 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /ENetCS/Native/Structs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2012 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | #pragma warning disable 1591 21 | 22 | using System; 23 | using System.Net; 24 | using System.Net.Sockets; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace ENet.Native 28 | { 29 | [StructLayout(LayoutKind.Sequential)] 30 | public struct ENetAddress 31 | { 32 | public uint host; 33 | public ushort port; 34 | 35 | /// The address is null. 36 | /// The address is not IPv4. 37 | /// The port is less than 0 or greater than 65535. 38 | public static explicit operator ENetAddress(IPEndPoint endPoint) 39 | { 40 | if (endPoint == null) { throw new ArgumentNullException(); } 41 | if (endPoint.AddressFamily != AddressFamily.InterNetwork) { throw new ArgumentException(); } 42 | if (endPoint.Port < 0 || endPoint.Port > 65535) { throw new ArgumentOutOfRangeException(); } 43 | 44 | return new ENetAddress() 45 | { 46 | host = endPoint.Address == IPAddress.Any ? 0 : BitConverter.ToUInt32(endPoint.Address.GetAddressBytes(), 0), 47 | port = (ushort)endPoint.Port 48 | }; 49 | } 50 | 51 | public static implicit operator IPEndPoint(ENetAddress address) 52 | { 53 | return new IPEndPoint(address.host, address.port); 54 | } 55 | } 56 | 57 | [StructLayout(LayoutKind.Sequential)] 58 | public struct ENetCallbacks 59 | { 60 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 61 | public delegate IntPtr malloc_cb(IntPtr size); 62 | 63 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 64 | public delegate void free_cb(IntPtr memory); 65 | 66 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 67 | public delegate void no_memory_cb(); 68 | 69 | public IntPtr malloc, free, no_memory; 70 | } 71 | 72 | [StructLayout(LayoutKind.Sequential)] 73 | public struct ENetCompressor 74 | { 75 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 76 | public delegate IntPtr compress_cb(IntPtr context, IntPtr inBuffers, IntPtr inBufferCount, IntPtr inLimit, IntPtr outData, IntPtr outLimit); 77 | 78 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 79 | public delegate IntPtr decompress_cb(IntPtr context, IntPtr inData, IntPtr inLimit, IntPtr outData, IntPtr outLimit); 80 | 81 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 82 | public delegate void destroy_cb(IntPtr context); 83 | 84 | public IntPtr context; 85 | public IntPtr compress, decompress, destroy; 86 | } 87 | 88 | [StructLayout(LayoutKind.Sequential)] 89 | public unsafe struct ENetEvent 90 | { 91 | public EventType type; 92 | public ENetPeer* peer; 93 | public byte channelID; 94 | public uint data; 95 | public ENetPacket* packet; 96 | } 97 | 98 | [StructLayout(LayoutKind.Sequential)] 99 | public struct ENetHost 100 | { 101 | 102 | } 103 | 104 | [StructLayout(LayoutKind.Sequential)] 105 | public unsafe struct ENetListNode 106 | { 107 | public ENetListNode* next, previous; 108 | } 109 | 110 | [StructLayout(LayoutKind.Sequential)] 111 | public unsafe struct ENetPacket 112 | { 113 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 114 | public delegate void freeCallback_cb(ENetPacket* packet); 115 | 116 | public IntPtr referenceCount; 117 | public PacketFlags flags; 118 | public IntPtr data; 119 | public IntPtr dataLength; 120 | public IntPtr freeCallback; 121 | } 122 | 123 | [StructLayout(LayoutKind.Sequential)] 124 | public unsafe struct ENetPeer 125 | { 126 | public ENetListNode dispatchList; 127 | public ENetHost* host; 128 | public ushort outgoingPeerID; 129 | public ushort incomingPeerID; 130 | public uint connectID; 131 | public byte outgoingSessionID; 132 | public byte incomingSessionID; 133 | 134 | uint addressHost; // https://bugzilla.xamarin.com/show_bug.cgi?id=11899 135 | ushort addressPort; 136 | public ENetAddress address 137 | { 138 | get { return new ENetAddress() { host = addressHost, port = addressPort }; } 139 | set { addressHost = value.host; addressPort = value.port; } 140 | } 141 | 142 | public IntPtr data; 143 | public PeerState state; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /ENetCS/Packet.IList.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2013 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using System.Collections; 22 | using System.Collections.Generic; 23 | using System.Runtime.InteropServices; 24 | 25 | namespace ENet 26 | { 27 | partial struct Packet : IList 28 | { 29 | /// 30 | /// Adds a byte to the end of the packet. 31 | /// 32 | /// The value of the byte. 33 | /// The packet is not initialized. 34 | /// 35 | /// Packet resizing behavior is less than optimal. So, in performance-critical applications, it's 36 | /// presently a good idea to initialize the packet with a final byte array instead of using this method. 37 | /// 38 | public void Add(byte value) 39 | { 40 | Insert(Length, value); 41 | } 42 | 43 | /// 44 | /// Sets the packet length to zero. 45 | /// 46 | /// The packet is not initialized. 47 | public void Clear() 48 | { 49 | Resize(0); 50 | } 51 | 52 | /// 53 | /// Checks if the packet contains a particular byte. 54 | /// 55 | /// The value to look for. 56 | /// True if the packet contains the byte. 57 | /// The packet is not initialized. 58 | public bool Contains(byte value) 59 | { 60 | return IndexOf(value) != -1; 61 | } 62 | 63 | /// 64 | /// Copies part of the packet data into an array. 65 | /// 66 | /// The array to copy into. 67 | /// The target array index at which to begin copying. 68 | /// is null. 69 | /// is out of range. 70 | /// The packet is not initialized. 71 | public void CopyTo(byte[] array, int arrayIndex) 72 | { 73 | CopyTo(array, arrayIndex, Length, 0); 74 | } 75 | 76 | /// 77 | /// Returns an enumerator that iterates through the bytes of the packet. 78 | /// 79 | /// An enumerator. 80 | /// The packet is not initialized. 81 | public IEnumerator GetEnumerator() 82 | { 83 | CheckInitialized(); 84 | 85 | for (int i = 0; i < Length; i++) 86 | { 87 | yield return this[i]; 88 | } 89 | } 90 | 91 | IEnumerator IEnumerable.GetEnumerator() 92 | { 93 | return GetEnumerator(); 94 | } 95 | 96 | /// 97 | /// Checks if the packet contains a particular byte, and if so, returns the index. 98 | /// 99 | /// The value to look for. 100 | /// The index of the byte, or -1. 101 | /// The packet is not initialized. 102 | public int IndexOf(byte value) 103 | { 104 | for (int i = 0; i < Length; i++) 105 | { 106 | if (this[i] == value) { return i; } 107 | } 108 | 109 | return -1; 110 | } 111 | 112 | /// 113 | /// Inserts a byte in the packet. 114 | /// 115 | /// The index to insert at. 116 | /// The value of the byte. 117 | /// is out of range. 118 | /// The packet is not initialized. 119 | /// 120 | /// Packet resizing behavior is less than optimal. So, in performance-critical applications, it's 121 | /// presently a good idea to initialize the packet with a final byte array instead of using this method. 122 | /// 123 | public void Insert(int index, byte value) 124 | { 125 | if (index < 0 || index > Length) { throw new ArgumentOutOfRangeException("index"); } 126 | 127 | Resize(checked(Length + 1)); 128 | for (int i = Length - 1; i > index; i--) 129 | { 130 | this[i] = this[i - 1]; 131 | } 132 | this[index] = value; 133 | } 134 | 135 | /// 136 | /// Removes the first byte in the packet with the specified value. 137 | /// 138 | /// The value of the byte to remove. 139 | /// True if a byte was found and removed. 140 | /// The packet is not initialized. 141 | public bool Remove(byte value) 142 | { 143 | int index = IndexOf(value); 144 | if (index == -1) { return false; } 145 | RemoveAt(index); return true; 146 | } 147 | 148 | /// 149 | /// Removes the byte at the specified index from the packet. 150 | /// 151 | /// The index of the byte to remove. 152 | /// is out of range. 153 | /// The packet is not initialized. 154 | public void RemoveAt(int index) 155 | { 156 | if (index < 0 || index >= Length) { throw new ArgumentOutOfRangeException("index"); } 157 | 158 | for (int i = index; i < Length - 1; i++) 159 | { 160 | this[i] = this[i + 1]; 161 | } 162 | Resize(Length - 1); 163 | } 164 | 165 | /// 166 | /// Gets or sets the byte at the specified index. 167 | /// 168 | /// The index of the byte. 169 | /// The byte value. 170 | /// is out of range. 171 | /// The packet is not initialized. 172 | public byte this[int index] 173 | { 174 | get 175 | { 176 | if (index < 0 || index >= Length) { throw new ArgumentOutOfRangeException("index"); } 177 | return Marshal.ReadByte(Data, index); 178 | } 179 | 180 | set 181 | { 182 | if (index < 0 || index >= Length) { throw new ArgumentOutOfRangeException("index"); } 183 | Marshal.WriteByte(Data, index, value); 184 | } 185 | } 186 | 187 | int ICollection.Count 188 | { 189 | get { return Length; } 190 | } 191 | 192 | bool ICollection.IsReadOnly 193 | { 194 | get { return false; } 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /ENetCS/Packet.UserData.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2013 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using System.Collections.Generic; 22 | using System.Runtime.InteropServices; 23 | using System.Threading; 24 | 25 | namespace ENet 26 | { 27 | /// 28 | /// Called when ENet is finished with a packet and it is about to be freed from memory. 29 | /// 30 | /// The packet. 31 | public delegate void PacketFreeCallback(Packet packet); 32 | 33 | unsafe partial struct Packet 34 | { 35 | static Native.ENetPacket.freeCallback_cb _freeCallbackDelegate; 36 | static IntPtr _freeCallbackFunctionPointer; 37 | static object _freeCallbackKey; 38 | static Dictionary> _userData; 39 | static object _userDataDefaultKey; 40 | 41 | static void InitializeUserData() 42 | { 43 | _freeCallbackDelegate = FreeCallbackHandler; 44 | _freeCallbackFunctionPointer = Marshal.GetFunctionPointerForDelegate(_freeCallbackDelegate); 45 | _freeCallbackKey = new object(); 46 | _userData = new Dictionary>(); 47 | _userDataDefaultKey = new object(); 48 | } 49 | 50 | static void FreeCallbackHandler(Native.ENetPacket* native) 51 | { 52 | Packet packet = new Packet(native); 53 | 54 | lock (_userData) 55 | { 56 | try 57 | { 58 | PacketFreeCallback callback = (PacketFreeCallback)packet.GetUserData(_freeCallbackKey); 59 | 60 | if (callback != null) 61 | { 62 | try 63 | { 64 | Monitor.Exit(_userData); 65 | callback(packet); 66 | } 67 | finally 68 | { 69 | Monitor.Enter(_userData); 70 | } 71 | } 72 | } 73 | finally 74 | { 75 | _userData.Remove(packet); 76 | } 77 | } 78 | } 79 | 80 | /// 81 | /// Occurs when ENet is finished with a packet and it is about to be freed from memory. 82 | /// 83 | public event PacketFreeCallback Freed 84 | { 85 | add 86 | { 87 | lock (_userData) 88 | { 89 | SetUserData(_freeCallbackKey, (PacketFreeCallback)GetUserData(_freeCallbackKey) + value); 90 | } 91 | } 92 | 93 | remove 94 | { 95 | lock (_userData) 96 | { 97 | SetUserData(_freeCallbackKey, (PacketFreeCallback)GetUserData(_freeCallbackKey) - value); 98 | } 99 | } 100 | } 101 | 102 | /// 103 | /// Gets the user data associated with this packet. 104 | /// 105 | /// 106 | public object GetUserData() 107 | { 108 | return GetUserData(null); 109 | } 110 | 111 | /// 112 | /// Gets the user data associated with this packet and a particular key. 113 | /// 114 | /// The key to use. 115 | /// The user data. 116 | public object GetUserData(object key) 117 | { 118 | if (key == null) { key = _userDataDefaultKey; } 119 | 120 | lock (_userData) 121 | { 122 | Dictionary packetUserData; 123 | if (!_userData.TryGetValue(this, out packetUserData)) { return null; } 124 | 125 | object value; 126 | if (!packetUserData.TryGetValue(key, out value)) { return null; } 127 | return value; 128 | } 129 | } 130 | 131 | /// 132 | /// Associates user data with this packet. 133 | /// 134 | /// 135 | public void SetUserData(object value) 136 | { 137 | SetUserData(null, value); 138 | } 139 | 140 | /// 141 | /// Associates user data with this packet and a particular key. 142 | /// 143 | /// The key to use. 144 | /// The user data. 145 | public void SetUserData(object key, object value) 146 | { 147 | if (key == null) { key = _userDataDefaultKey; } 148 | 149 | lock (_userData) 150 | { 151 | CheckInitialized(); 152 | if (NativeData->freeCallback != _freeCallbackFunctionPointer) 153 | { 154 | if (NativeData->freeCallback != IntPtr.Zero) { throw new InvalidOperationException("An unknown free callback is set on this packet."); } 155 | NativeData->freeCallback = _freeCallbackFunctionPointer; 156 | } 157 | 158 | Dictionary packetUserData; 159 | if (!_userData.TryGetValue(this, out packetUserData)) 160 | { 161 | if (value == null) { return; } 162 | _userData[this] = packetUserData = new Dictionary(); 163 | } 164 | 165 | if (value == null) 166 | { 167 | packetUserData.Remove(key); 168 | } 169 | else 170 | { 171 | packetUserData[key] = value; 172 | } 173 | } 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /ENetCS/Packet.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2012 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using System.Runtime.InteropServices; 22 | using ENet.Native; 23 | 24 | namespace ENet 25 | { 26 | /// 27 | /// Contains data received or to be sent. 28 | /// 29 | public unsafe partial struct Packet : IDisposable, IEquatable 30 | { 31 | ENetPacket* _packet; 32 | 33 | static Packet() 34 | { 35 | InitializeUserData(); 36 | } 37 | 38 | /// 39 | /// Initializes a new packet based on a native C packet. 40 | /// 41 | /// The native C packet. 42 | public Packet(ENetPacket* packet) 43 | { 44 | _packet = packet; 45 | } 46 | 47 | internal void CheckInitialized() 48 | { 49 | if (NativeData == null) { throw new InvalidOperationException("Not initialized."); } 50 | } 51 | 52 | public override bool Equals(object obj) 53 | { 54 | return obj is Packet && Equals((Packet)obj); 55 | } 56 | 57 | public bool Equals(Packet other) 58 | { 59 | return NativeData == other.NativeData; 60 | } 61 | 62 | public override int GetHashCode() 63 | { 64 | return (int)(long)NativeData; // ENet types are malloc'ed. They do not move. 65 | } 66 | 67 | /// 68 | /// Initializes a new packet. 69 | /// 70 | /// The data the packet will contain. 71 | /// is null. 72 | /// The packet is already initialized. 73 | /// Packet creation failed. 74 | public void Initialize(byte[] data) 75 | { 76 | Initialize(data, PacketFlags.None); 77 | } 78 | 79 | /// 80 | /// Initializes a new packet, with the given flags. 81 | /// 82 | /// The data the packet will contain. 83 | /// The flags the packet will use. 84 | /// is null. 85 | /// The packet is already initialized. 86 | /// Packet creation failed. 87 | public void Initialize(byte[] data, PacketFlags flags) 88 | { 89 | if (data == null) { throw new ArgumentNullException("data"); } 90 | Initialize(data, 0, data.Length, flags); 91 | } 92 | 93 | /// 94 | /// Initializes a new packet from data, at the given offset, and of the given length. 95 | /// 96 | /// An array containing the data the packet will contain. 97 | /// The offset of the first byte of data. 98 | /// The length of the data. 99 | /// is null. 100 | /// and/or are out of range. 101 | /// The packet is already initialized. 102 | /// Packet creation failed. 103 | public void Initialize(byte[] data, int offset, int length) 104 | { 105 | Initialize(data, offset, length, PacketFlags.None); 106 | } 107 | 108 | /// 109 | /// Initializes a new packet from data at the given offset, of the given length, and with the given flags. 110 | /// 111 | /// An array containing the data the packet will contain. 112 | /// The offset of the first byte of data. 113 | /// The length of the data. 114 | /// The flags the packet will use. 115 | /// is null. 116 | /// and/or are out of range. 117 | /// The packet is already initialized. 118 | /// Packet creation failed. 119 | public void Initialize(byte[] data, int offset, int length, PacketFlags flags) 120 | { 121 | if (data == null) { throw new ArgumentNullException("data"); } 122 | if (offset < 0 || length < 0 || length > data.Length - offset) { throw new ArgumentOutOfRangeException(); } 123 | fixed (byte* bytes = data) { Initialize((IntPtr)(bytes + offset), length, flags); } 124 | } 125 | 126 | /// 127 | /// Initializes a new packet from data, of the given length. 128 | /// 129 | /// A pointer to the first byte of data. 130 | /// The length of the data. 131 | /// The packet is already initialized. 132 | /// Packet creation failed. 133 | public void Initialize(IntPtr data, int length) 134 | { 135 | Initialize(data, length, PacketFlags.None); 136 | } 137 | 138 | /// 139 | /// Initializes a new packet from data, of the given length, and with the given flags. 140 | /// 141 | /// A pointer to the first byte of data. 142 | /// The length of the data. 143 | /// The flags the packet will use. 144 | /// The packet is already initialized. 145 | /// Packet creation failed. 146 | public void Initialize(IntPtr data, int length, PacketFlags flags) 147 | { 148 | if (NativeData != null) { throw new InvalidOperationException("Already initialized."); } 149 | 150 | NativeData = ENetApi.enet_packet_create(data, (IntPtr)length, flags); 151 | if (NativeData == null) { throw new ENetException("Packet creation call failed."); } 152 | } 153 | 154 | /// 155 | /// Copies the packet data into an array. 156 | /// 157 | /// The array to copy into. 158 | /// is null. 159 | /// The packet is not initialized. 160 | public void CopyTo(byte[] array) 161 | { 162 | if (array == null) { throw new ArgumentNullException("array"); } 163 | CopyTo(array, 0, Length, 0); 164 | } 165 | 166 | /// 167 | /// Copies part of the packet data into an array. 168 | /// 169 | /// The array to copy into. 170 | /// The target array index at which to begin copying. 171 | /// The number of bytes to copy. 172 | /// is null. 173 | /// and/or are out of range. 174 | /// The packet is not initialized. 175 | public void CopyTo(byte[] array, int arrayIndex, int count) 176 | { 177 | CopyTo(array, arrayIndex, count, 0); 178 | } 179 | 180 | /// 181 | /// Copies part of the packet data into an array. 182 | /// 183 | /// The array to copy into. 184 | /// The target array index at which to begin copying. 185 | /// The number of bytes to copy. 186 | /// The index into the packet at which to begin copying. 187 | /// is null. 188 | /// , , and/or are out of range. 189 | /// The packet is not initialized. 190 | public void CopyTo(byte[] array, int arrayIndex, int count, int sourceIndex) 191 | { 192 | if (array == null) { throw new ArgumentNullException("array"); } 193 | if (sourceIndex < 0 || arrayIndex < 0 || count < 0 || count > array.Length - arrayIndex) { throw new ArgumentOutOfRangeException(); } 194 | 195 | CheckInitialized(); 196 | if (count > Length - sourceIndex) { throw new ArgumentOutOfRangeException(); } 197 | if (count > 0) 198 | { 199 | IntPtr srcPtr = (IntPtr)((byte*)Data + sourceIndex); 200 | Marshal.Copy(srcPtr, array, arrayIndex, count); 201 | } 202 | } 203 | 204 | /// 205 | /// Gets all bytes of the packet data. 206 | /// 207 | /// The packet data. 208 | /// The packet is not initialized. 209 | public byte[] GetBytes() 210 | { 211 | CheckInitialized(); 212 | byte[] array = new byte[Length]; CopyTo(array); return array; 213 | } 214 | 215 | /// 216 | /// Destroys the ENet packet. 217 | /// 218 | public void Dispose() 219 | { 220 | if (NativeData != null) 221 | { 222 | if (NativeData->referenceCount == IntPtr.Zero) { ENetApi.enet_packet_destroy(NativeData); } 223 | NativeData = null; 224 | } 225 | } 226 | 227 | /// 228 | /// Resizes the packet. 229 | /// 230 | /// The new packet length. 231 | /// is negative. 232 | /// The packet is not initialized. 233 | public void Resize(int length) 234 | { 235 | if (length < 0) { throw new ArgumentOutOfRangeException("length"); } 236 | CheckInitialized(); int ret = ENetApi.enet_packet_resize(NativeData, (IntPtr)length); 237 | if (ret < 0) { throw new OutOfMemoryException("Packet resizing failed."); } 238 | } 239 | 240 | /// 241 | /// Gets a pointer to the packet data. 242 | /// 243 | /// The packet is not initialized. 244 | public IntPtr Data 245 | { 246 | get { CheckInitialized(); return NativeData->data; } 247 | } 248 | 249 | /// 250 | /// Gets the packet flags. 251 | /// 252 | public PacketFlags Flags 253 | { 254 | get { CheckInitialized(); return NativeData->flags; } 255 | } 256 | 257 | /// 258 | /// Gets the length of the packet. 259 | /// 260 | /// The packet is not initialized, or is 2GB or larger. 261 | public int Length 262 | { 263 | get 264 | { 265 | CheckInitialized(); 266 | if ((ulong)NativeData->dataLength > (uint)int.MaxValue) { throw new InvalidOperationException("The packet is 2GB or larger."); } 267 | return (int)NativeData->dataLength; 268 | } 269 | } 270 | 271 | /// 272 | /// Gets or sets the native C packet. 273 | /// 274 | public ENetPacket* NativeData 275 | { 276 | get { return _packet; } 277 | set { _packet = value; } 278 | } 279 | 280 | /// 281 | /// Gets or sets the reference count. 282 | /// If you want to keep a packet around that you are giving to ENet, increment this. 283 | /// When you are finished with it, decrement this and call Dispose(). 284 | /// 285 | /// The value may not be negative. 286 | /// The packet is not initialized. 287 | public int ReferenceCount 288 | { 289 | get 290 | { 291 | CheckInitialized(); 292 | return NativeData->referenceCount.ToInt32(); 293 | } 294 | 295 | set 296 | { 297 | if (value < 0) { throw new ArgumentOutOfRangeException(); } 298 | CheckInitialized(); NativeData->referenceCount = (IntPtr)value; 299 | } 300 | } 301 | 302 | /// 303 | /// Returns true if the packet is initialized. 304 | /// 305 | public bool IsInitialized 306 | { 307 | get { return NativeData != null; } 308 | } 309 | 310 | public static bool operator ==(Packet packet1, Packet packet2) 311 | { 312 | return packet1.Equals(packet2); 313 | } 314 | 315 | public static bool operator !=(Packet packet1, Packet packet2) 316 | { 317 | return !packet1.Equals(packet2); 318 | } 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /ENetCS/PacketFlags.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2012 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | 22 | namespace ENet 23 | { 24 | /// 25 | /// Specifies outgoing packet transmittion behavior. 26 | /// 27 | [Flags] 28 | public enum PacketFlags 29 | { 30 | /// 31 | /// Sequence the packet, and unless it is larger than the MTU 32 | /// and requires fragmentation, send it unreliably. 33 | /// 34 | None = 0, 35 | 36 | /// 37 | /// Send the packet reliably. 38 | /// 39 | Reliable = 1 << 0, 40 | 41 | /// 42 | /// Allow the packet to arrive out-of-order. 43 | /// 44 | Unsequenced = 1 << 1, 45 | 46 | /// 47 | /// Let the application, not ENet, handle memory allocation for the packet. 48 | /// 49 | NoAllocate = 1 << 2, 50 | 51 | /// 52 | /// Even if an unreliable packet is larger than the MTU 53 | /// and requires fragmentation, send it unreliably. 54 | /// 55 | UnreliableFragment = 1 << 3 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ENetCS/Peer.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011-2013 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using System.Net; 22 | using System.Net.Sockets; 23 | using ENet.Native; 24 | 25 | namespace ENet 26 | { 27 | /// 28 | /// Represents a connection with another computer. 29 | /// 30 | public unsafe struct Peer : IEquatable 31 | { 32 | ENetPeer* _peer; 33 | 34 | /// 35 | /// Initializes a peer based on a native C peer. 36 | /// 37 | /// The native C peer. 38 | public Peer(ENetPeer* peer) 39 | { 40 | this = new Peer() { NativeData = peer }; 41 | } 42 | 43 | void CheckInitialized() 44 | { 45 | if (NativeData == null) { throw new InvalidOperationException("Not initialized."); } 46 | } 47 | 48 | public override bool Equals(object obj) 49 | { 50 | return obj is Peer && Equals((Peer)obj); 51 | } 52 | 53 | public bool Equals(Peer other) 54 | { 55 | return NativeData == other.NativeData; 56 | } 57 | 58 | public override int GetHashCode() 59 | { 60 | return (int)(long)NativeData; // ENet types are malloc'ed. They do not move. 61 | } 62 | 63 | /// 64 | /// Configures throttling. ENet measures lag over an interval, and alters its throttle parameter 65 | /// based on individual packet round-trip times versus the mean. This parameter controls the probability 66 | /// ENet will drop an unreliable packet. If a packet has a smaller round-trip time than average, the parameter 67 | /// is increased by the acceleration term, causing less packets to be dropped. If a packet has a larger 68 | /// round-trip time than average, the parameter is decreased by the deceleration term, causing more packets 69 | /// to be dropped. 70 | /// 71 | /// The interval in milliseconds over which to measure. The default is 5000. 72 | /// Acceleration rate. The default value is 2, and the limit is 32. 73 | /// Deceleration rate. The default value is 2, and the limit is 32. 74 | /// 75 | /// is negative, 76 | /// is less than 0 or greater than 32, and/or 77 | /// is less than 0 or greater than 32. 78 | /// 79 | /// The peer is not initialized. 80 | public void ConfigureThrottle(int interval, int acceleration, int deceleration) 81 | { 82 | CheckInitialized(); 83 | if (interval < 0) { throw new ArgumentOutOfRangeException("interval"); } 84 | if (acceleration < 0 || acceleration > 32) { throw new ArgumentOutOfRangeException("acceleration"); } 85 | if (deceleration < 0 || deceleration > 32) { throw new ArgumentOutOfRangeException("deceleration"); } 86 | ENetApi.enet_peer_throttle_configure(NativeData, (uint)interval, (uint)acceleration, (uint)deceleration); 87 | } 88 | 89 | /// 90 | /// Gracefully disconnects from the remote computer. 91 | /// A disconnect event occurs. 92 | /// 93 | /// Data to send along with the disconnect packet. 94 | /// The peer is not initialized. 95 | public void Disconnect(int data) 96 | { 97 | CheckInitialized(); ENetApi.enet_peer_disconnect(NativeData, (uint)data); 98 | } 99 | 100 | /// 101 | /// Gracefully disconnects from the remote computer after all outgoing data has been sent. 102 | /// A disconnect event occurs. 103 | /// 104 | /// Data to send along with the disconnect packet. 105 | /// The peer is not initialized. 106 | public void DisconnectLater(int data) 107 | { 108 | CheckInitialized(); ENetApi.enet_peer_disconnect_later(NativeData, (uint)data); 109 | } 110 | 111 | /// 112 | /// Immediately disconnects from the remote computer. 113 | /// A disconnect packet is sent unreliably. No event occurs. 114 | /// 115 | /// Data to send along with the disconnect packet. 116 | /// The peer is not initialized. 117 | public void DisconnectNow(int data) 118 | { 119 | CheckInitialized(); ENetApi.enet_peer_disconnect_now(NativeData, (uint)data); 120 | } 121 | 122 | /// 123 | /// Sends a ping to the remote computer. 124 | /// 125 | /// The peer is not initialized. 126 | public void Ping() 127 | { 128 | CheckInitialized(); ENetApi.enet_peer_ping(NativeData); 129 | } 130 | 131 | /// 132 | /// Resets the connection to the remote computer. 133 | /// No disconnect packets are sent, and no event occurs. 134 | /// 135 | /// The peer is not initialized. 136 | public void Reset() 137 | { 138 | CheckInitialized(); ENetApi.enet_peer_reset(NativeData); 139 | } 140 | 141 | /// 142 | /// Gets the remote address. 143 | /// 144 | /// The peer is not initialized. 145 | public IPEndPoint GetRemoteAddress() 146 | { 147 | CheckInitialized(); return NativeData->address; 148 | } 149 | 150 | /// 151 | /// Dequeue a received packet. 152 | /// 153 | /// The ID of the channel the packet was sent on. 154 | /// The received packet. 155 | /// True if a packet was dequeued, or false if there are no more packets. 156 | /// The peer is not initialized. 157 | public bool Receive(out byte channelID, out Packet packet) 158 | { 159 | CheckInitialized(); ENetPacket* nativePacket; 160 | nativePacket = ENetApi.enet_peer_receive(NativeData, out channelID); 161 | if (nativePacket == null) { packet = new Packet(); return false; } 162 | packet = new Packet(nativePacket); return true; 163 | } 164 | 165 | /// 166 | /// Enqueues a packet for sending using the given data and flags. 167 | /// 168 | /// The ID of the channel to send on. 169 | /// The data to send. 170 | /// The packet flags. 171 | /// is null. 172 | /// The peer is not initialized. 173 | /// An error occured. 174 | public void Send(byte channelID, byte[] data, PacketFlags flags) 175 | { 176 | if (data == null) { throw new ArgumentNullException("data"); } 177 | Send(channelID, data, 0, data.Length, flags); 178 | } 179 | 180 | /// 181 | /// Enqueues a packet for sending using the given data, offsets, length, and flags. 182 | /// 183 | /// The ID of the channel to send on. 184 | /// The array containing the data to send. 185 | /// The index of the first byte of data. 186 | /// The length of the data. 187 | /// The packet flags. 188 | /// is null. 189 | /// and/or are out of range. 190 | /// The peer is not initialized. 191 | /// An error occured. 192 | public void Send(byte channelID, byte[] data, int offset, int length, PacketFlags flags) 193 | { 194 | if (data == null) { throw new ArgumentNullException("data"); } 195 | using (Packet packet = new Packet()) 196 | { 197 | packet.Initialize(data, offset, length, flags); 198 | Send(channelID, packet); 199 | } 200 | } 201 | 202 | /// 203 | /// Enqueues a packet for sending. 204 | /// 205 | /// The ID of the channel to send on. 206 | /// The packet to send. 207 | /// True if the packet was enqueued successfully, or false if an error occured. 208 | /// The peer is not initialized. 209 | /// An error occured. 210 | public void Send(byte channelID, Packet packet) 211 | { 212 | CheckInitialized(); packet.CheckInitialized(); 213 | int ret = ENetApi.enet_peer_send(NativeData, channelID, packet.NativeData); 214 | if (ret < 0) { throw new ENetException("An error occured sending to the peer."); } 215 | } 216 | 217 | /// 218 | /// Sets the interval between pings. 219 | /// ENet will automatically send pings when it hasn't received anything from the remote computer. 220 | /// 221 | /// 222 | /// The interval in milliseconds between pings, or 0 to use the default (500). 223 | /// 224 | /// is negative. 225 | /// The peer is not initialized. 226 | /// This method requires ENet 1.3.4 or newer. 227 | public void SetPingInterval(int interval) 228 | { 229 | CheckInitialized(); 230 | if (interval < 0) { throw new ArgumentOutOfRangeException("interval"); } 231 | 232 | try 233 | { 234 | ENetApi.enet_peer_ping_interval(NativeData, (uint)interval); 235 | } 236 | catch (EntryPointNotFoundException e) 237 | { 238 | throw new NotSupportedException("This method requires ENet 1.3.4 or newer.", e); 239 | } 240 | } 241 | 242 | /// 243 | /// Sets timeouts for a response from the remote computer acknowledging its receipt of a reliable packet. 244 | /// When the timeouts are exceeded, a disconnect event occurs. 245 | /// 246 | /// 247 | /// The number of retries to make before considering the minimum timeout time. 248 | /// The default value is 5. 249 | /// 250 | /// 251 | /// The minimum time in milliseconds to allow for retrying, or 0 to use the default (5000). 252 | /// 253 | /// 254 | /// The maximum time in milliseconds to wait regardless of the number of retries, or 0 to use the default (30000). 255 | /// 256 | /// 257 | /// is negative or greater than 20, 258 | /// is negative, and/or 259 | /// is negative. 260 | /// 261 | /// The peer is not initialized. 262 | /// This method requires ENet 1.3.4 or newer. 263 | public void SetTimeouts(int retryLimit, int retryMinimumTime, int maximumTime) 264 | { 265 | CheckInitialized(); 266 | if (retryLimit < 0 || retryLimit > 20) { throw new ArgumentOutOfRangeException("retryLimit"); } 267 | if (retryMinimumTime < 0) { throw new ArgumentOutOfRangeException("retryMinimumTime"); } 268 | if (maximumTime < 0) { throw new ArgumentOutOfRangeException("maximumTime"); } 269 | 270 | try 271 | { 272 | ENetApi.enet_peer_timeout(NativeData, 1U << retryLimit, (uint)retryMinimumTime, (uint)maximumTime); 273 | } 274 | catch (EntryPointNotFoundException e) 275 | { 276 | throw new NotSupportedException("This method requires ENet 1.3.4 or newer.", e); 277 | } 278 | } 279 | 280 | /// 281 | /// Gets the host associated with this peer. 282 | /// 283 | public Host Host 284 | { 285 | get { CheckInitialized(); return new Host(NativeData->host); } 286 | } 287 | 288 | /// 289 | /// Gets or sets the native C peer. 290 | /// 291 | public ENetPeer* NativeData 292 | { 293 | get { return _peer; } 294 | set { _peer = value; } 295 | } 296 | 297 | /// 298 | /// Gets the peer state. 299 | /// 300 | public PeerState State 301 | { 302 | get { return IsInitialized ? NativeData->state : PeerState.Uninitialized; } 303 | } 304 | 305 | /// 306 | /// Gets or sets the user data associated with this peer. 307 | /// 308 | public IntPtr UserData 309 | { 310 | get { CheckInitialized(); return NativeData->data; } 311 | set { CheckInitialized(); NativeData->data = value; } 312 | } 313 | 314 | /// 315 | /// Returns true if the peer is initialized. 316 | /// 317 | public bool IsInitialized 318 | { 319 | get { return NativeData != null; } 320 | } 321 | 322 | public static bool operator ==(Peer peer1, Peer peer2) 323 | { 324 | return peer1.Equals(peer2); 325 | } 326 | 327 | public static bool operator !=(Peer peer1, Peer peer2) 328 | { 329 | return !peer1.Equals(peer2); 330 | } 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /ENetCS/PeerState.cs: -------------------------------------------------------------------------------- 1 | namespace ENet 2 | { 3 | /// 4 | /// Enumerates the possible peer states. 5 | /// 6 | public enum PeerState 7 | { 8 | /// 9 | /// The peer is uninitialized. 10 | /// 11 | Uninitialized = -1, 12 | 13 | /// 14 | /// The peer is disconnected. 15 | /// 16 | Disconnected = 0, 17 | 18 | /// 19 | /// Connecting to the peer. 20 | /// 21 | Connecting = 1, 22 | 23 | /// 24 | /// Connection is being acknowledged. 25 | /// 26 | AcknowledgingConnect = 2, 27 | 28 | /// 29 | /// A connection is pending. 30 | /// 31 | ConnectionPending = 3, 32 | 33 | /// 34 | /// A connection has been established. 35 | /// 36 | ConnectionSucceeded = 4, 37 | 38 | /// 39 | /// The peer is connected. 40 | /// 41 | Connected = 5, 42 | 43 | /// 44 | /// The peer will be disconnected once all packets are sent. 45 | /// 46 | DisconnectingLater = 6, 47 | 48 | /// 49 | /// The peer is disconnecting. 50 | /// 51 | Disconnecting = 7, 52 | 53 | /// 54 | /// Disconnection is being acknowledged. 55 | /// 56 | AcknowledgingDisconnect = 8, 57 | 58 | /// 59 | /// The peer is a zombie. 60 | /// 61 | Zombie = 9 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ENetCS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("ENet")] 6 | [assembly: AssemblyProduct("ENet for C#")] 7 | [assembly: AssemblyCopyright("Copyright © 2011-2013 James F. Bellinger ")] 8 | [assembly: AssemblyVersion("1.3.6.3")] 9 | [assembly: AssemblyFileVersion("1.3.6.3")] 10 | [assembly: ComVisible(false)] 11 | [assembly: CLSCompliant(false)] -------------------------------------------------------------------------------- /ENetDLL/ENetDLL.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31} 47 | 10.0.16299.0 48 | 49 | 50 | 51 | DynamicLibrary 52 | MultiByte 53 | v141 54 | 55 | 56 | DynamicLibrary 57 | MultiByte 58 | v141 59 | 60 | 61 | DynamicLibrary 62 | MultiByte 63 | v141 64 | 65 | 66 | DynamicLibrary 67 | MultiByte 68 | v141 69 | 70 | 71 | 72 | 73 | ..\bin\ 74 | 75 | 76 | ENet 77 | 78 | 79 | ENet 80 | 81 | 82 | ..\bin\ 83 | 84 | 85 | ENet 86 | 87 | 88 | ENet 89 | 90 | 91 | 92 | ../ENet/include 93 | MultiThreaded 94 | ENET_DLL;_WINDLL;WIN32;%(PreprocessorDefinitions) 95 | 96 | 97 | winmm.lib;ws2_32.lib;%(AdditionalDependencies) 98 | 99 | 100 | 101 | 102 | ../ENet/include 103 | MultiThreaded 104 | ENET_DLL;_WINDLL;WIN32;%(PreprocessorDefinitions) 105 | 106 | 107 | winmm.lib;ws2_32.lib;%(AdditionalDependencies) 108 | 109 | 110 | 111 | 112 | MultiThreadedDebug 113 | ENET_DLL;_WINDLL;WIN32;%(PreprocessorDefinitions) 114 | ../ENet/include 115 | 116 | 117 | winmm.lib;ws2_32.lib;%(AdditionalDependencies) 118 | 119 | 120 | 121 | 122 | MultiThreadedDebug 123 | ENET_DLL;_WINDLL;WIN32;%(PreprocessorDefinitions) 124 | ../ENet/include 125 | 126 | 127 | winmm.lib;ws2_32.lib;%(AdditionalDependencies) 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /ENetDLL/ENetDLL.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {97b24b6e-e0cd-4007-a52d-3b9f0d29556e} 6 | 7 | 8 | {b4684374-28b6-40a0-a447-39682ad2b7ca} 9 | 10 | 11 | 12 | 13 | include\enet 14 | 15 | 16 | include\enet 17 | 18 | 19 | include\enet 20 | 21 | 22 | include\enet 23 | 24 | 25 | include\enet 26 | 27 | 28 | include\enet 29 | 30 | 31 | include\enet 32 | 33 | 34 | include\enet 35 | 36 | 37 | include\enet 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /ENetDemo/ENetDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2} 9 | Exe 10 | Properties 11 | ENetDemo 12 | ENetDemo 13 | v2.0 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | 23 | true 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | full 27 | AnyCPU 28 | prompt 29 | MinimumRecommendedRules.ruleset 30 | 31 | 32 | bin\Release\ 33 | TRACE 34 | true 35 | pdbonly 36 | AnyCPU 37 | prompt 38 | MinimumRecommendedRules.ruleset 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A} 50 | ENetCS 51 | 52 | 53 | 54 | 61 | -------------------------------------------------------------------------------- /ENetDemo/Program.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | ENet for C# 4 | Copyright (c) 2011, 2013 James F. Bellinger 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #endregion 19 | 20 | using System; 21 | using System.Threading; 22 | 23 | namespace ENetDemo 24 | { 25 | // The general arrangement is as follows: 26 | // Create a Host. For a client, the peer count is 1. If it's a client, you don't 27 | // want someone to be able to connect to it, so the address parameter is null. 28 | // Connect if you're a client. 29 | // Service() checks for new notifications to read (Connect, Disconnect, Receive). 30 | // It returns true if there's something to read, and false if there isn't. 31 | // An exception is thrown if some error occured. 32 | // CheckEvents() pulls a notification from the queue. It returns true if an event 33 | // is dequeued, and false if there are no more. 34 | // An exception is thrown if some error occured. 35 | // Send and receive packets. One thing to keep in mind is, after reading a packet 36 | // from a Receive notification, you need to Dispose of it. Otherwise you'll get 37 | // a memory leak. Also, if on Peer.Send you give it a Packet instead of a byte 38 | // array, be sure to Dispose of the packet afterwards. Host.Broadcast does 39 | // disposal automatically. 40 | class Program 41 | { 42 | static void Server() 43 | { 44 | using (ENet.Host host = new ENet.Host()) 45 | { 46 | Console.WriteLine("Initializing server..."); 47 | 48 | host.InitializeServer(5000, 1); 49 | ENet.Peer peer = new ENet.Peer(); 50 | 51 | while (true) 52 | { 53 | ENet.Event @event; 54 | 55 | if (host.Service(15000, out @event)) 56 | { 57 | do 58 | { 59 | switch (@event.Type) 60 | { 61 | case ENet.EventType.Connect: 62 | peer = @event.Peer; 63 | // If you are using ENet 1.3.4 or newer, the following two methods will work: 64 | //peer.SetPingInterval(1000); 65 | //peer.SetTimeouts(8, 5000, 60000); 66 | Console.WriteLine("Connected to client at IP/port {0}.", peer.GetRemoteAddress()); 67 | for (int i = 0; i < 200; i++) 68 | { 69 | ENet.Packet packet = new ENet.Packet(); 70 | packet.Initialize(new byte[] { 0, 0 }, 0, 2, ENet.PacketFlags.Reliable); 71 | packet.SetUserData(i); 72 | packet.SetUserData("Test", i * i); 73 | packet.Freed += p => 74 | { 75 | Console.WriteLine("Initial packet freed (channel {0}, square of channel {1})", 76 | p.GetUserData(), 77 | p.GetUserData("Test")); 78 | }; 79 | peer.Send((byte)i, packet); 80 | } 81 | break; 82 | 83 | case ENet.EventType.Receive: 84 | byte[] data = @event.Packet.GetBytes(); 85 | ushort value = BitConverter.ToUInt16(data, 0); 86 | if (value % 1000 == 1) { Console.WriteLine(" Server: Ch={0} Recv={1}", @event.ChannelID, value); } 87 | value++; peer.Send(@event.ChannelID, BitConverter.GetBytes(value), ENet.PacketFlags.Reliable); 88 | @event.Packet.Dispose(); 89 | break; 90 | } 91 | } 92 | while (host.CheckEvents(out @event)); 93 | } 94 | } 95 | } 96 | } 97 | 98 | static void Client() 99 | { 100 | using (ENet.Host host = new ENet.Host()) 101 | { 102 | Console.WriteLine("Initializing client..."); 103 | host.Initialize(null, 1); 104 | 105 | ENet.Peer peer = host.Connect("127.0.0.1", 5000, 1234, 200); 106 | while (true) 107 | { 108 | ENet.Event @event; 109 | 110 | if (host.Service(15000, out @event)) 111 | { 112 | do 113 | { 114 | switch (@event.Type) 115 | { 116 | case ENet.EventType.Connect: 117 | Console.WriteLine("Connected to server at IP/port {0}.", peer.GetRemoteAddress()); 118 | break; 119 | 120 | case ENet.EventType.Receive: 121 | byte[] data = @event.Packet.GetBytes(); 122 | ushort value = BitConverter.ToUInt16(data, 0); 123 | if (value % 1000 == 0) { Console.WriteLine(" Client: Ch={0} Recv={1}", @event.ChannelID, value); } 124 | value++; peer.Send(@event.ChannelID, BitConverter.GetBytes(value), ENet.PacketFlags.Reliable); 125 | @event.Packet.Dispose(); 126 | break; 127 | 128 | default: 129 | Console.WriteLine(@event.Type); 130 | break; 131 | } 132 | } 133 | while (host.CheckEvents(out @event)); 134 | } 135 | } 136 | } 137 | } 138 | 139 | static void PacketManipulationDemo() 140 | { 141 | Console.WriteLine("Packet manipulation test/demo... should print 3 2 1..."); 142 | using (ENet.Packet packet = new ENet.Packet()) 143 | { 144 | packet.Initialize(new byte[0]); 145 | packet.Add((byte)1); 146 | packet.Insert(0, (byte)3); 147 | packet.Insert(1, (byte)2); 148 | packet.Insert(packet.IndexOf((byte)3), 4); 149 | packet.Remove(1); 150 | packet.RemoveAt(0); 151 | if (packet.Contains(3)) { packet.Add((byte)1); } 152 | if (packet.Contains(4)) { packet.Add((byte)5); } 153 | 154 | byte[] bytes = packet.GetBytes(); 155 | for (int i = 0; i < bytes.Length; i++) 156 | { 157 | Console.WriteLine(bytes[i]); 158 | } 159 | } 160 | } 161 | 162 | static void Main(string[] args) 163 | { 164 | Console.WriteLine("ENet demo"); 165 | ENet.Library.Initialize(); // Since 1.3.6.1, Initialize() is no longer required. 166 | 167 | Thread server = new Thread(Server); server.Start(); 168 | Thread.Sleep(250); 169 | Thread client = new Thread(Client); client.Start(); 170 | 171 | PacketManipulationDemo(); 172 | 173 | server.Join(); 174 | client.Join(); 175 | 176 | ENet.Library.Deinitialize(); // since 1.3.6.1, Deinitialize() does nothing. 177 | Console.WriteLine("Press Enter to exit"); 178 | Console.ReadLine(); 179 | } 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /ENetDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("ENet Demo")] 4 | [assembly: AssemblyProduct("ENet for C#")] 5 | [assembly: AssemblyCopyright("Copyright © 2011 James F. Bellinger ")] 6 | [assembly: AssemblyVersion("1.3.6.3")] 7 | [assembly: AssemblyFileVersion("1.3.6.3")] 8 | 9 | -------------------------------------------------------------------------------- /ENetUnityDemo/.gitignore: -------------------------------------------------------------------------------- 1 | # =============== # 2 | # Unity generated # 3 | # =============== # 4 | [Tt]emp/ 5 | [Oo]bj/ 6 | [Uu]nityGenerated/ 7 | [Ll]ibrary/ 8 | [Bb]uild/ 9 | 10 | # ===================================== # 11 | # Visual Studio / MonoDevelop generated # 12 | # ===================================== # 13 | ExportedObj/ 14 | *.svd 15 | *.userprefs 16 | *.csproj 17 | *.pidb 18 | *.suo 19 | *.sln 20 | *.user 21 | *.unityproj 22 | *.booproj 23 | *.DotSettings 24 | *.zip 25 | .vs/ 26 | 27 | #apk files 28 | *.apk 29 | 30 | # ============ # 31 | # OS generated # 32 | # ============ # 33 | .DS_Store 34 | .DS_Store? 35 | ._* 36 | .Spotlight-V100 37 | .Trashes 38 | ehthumbs.db 39 | Thumbs.db 40 | 41 | # Unity3D Generated File On Crash Reports 42 | sysinfo.txt -------------------------------------------------------------------------------- /ENetUnityDemo/Assets/Plugins/ENetCS.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insthync/ENetForUnity/bde64ed4128eec341a633e37c7bfc987a177249e/ENetUnityDemo/Assets/Plugins/ENetCS.dll -------------------------------------------------------------------------------- /ENetUnityDemo/Assets/Plugins/x86/ENet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insthync/ENetForUnity/bde64ed4128eec341a633e37c7bfc987a177249e/ENetUnityDemo/Assets/Plugins/x86/ENet.dll -------------------------------------------------------------------------------- /ENetUnityDemo/Assets/Plugins/x86_64/ENet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insthync/ENetForUnity/bde64ed4128eec341a633e37c7bfc987a177249e/ENetUnityDemo/Assets/Plugins/x86_64/ENet.dll -------------------------------------------------------------------------------- /ENetUnityDemo/Assets/Scenes/Demo.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 8 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481694, a: 1} 42 | --- !u!157 &3 43 | LightmapSettings: 44 | m_ObjectHideFlags: 0 45 | serializedVersion: 11 46 | m_GIWorkflowMode: 0 47 | m_GISettings: 48 | serializedVersion: 2 49 | m_BounceScale: 1 50 | m_IndirectOutputScale: 1 51 | m_AlbedoBoost: 1 52 | m_TemporalCoherenceThreshold: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 1 56 | m_LightmapEditorSettings: 57 | serializedVersion: 9 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_TextureWidth: 1024 61 | m_TextureHeight: 1024 62 | m_AO: 0 63 | m_AOMaxDistance: 1 64 | m_CompAOExponent: 1 65 | m_CompAOExponentDirect: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 0 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 500 79 | m_PVRBounces: 2 80 | m_PVRFilterTypeDirect: 0 81 | m_PVRFilterTypeIndirect: 0 82 | m_PVRFilterTypeAO: 0 83 | m_PVRFilteringMode: 1 84 | m_PVRCulling: 1 85 | m_PVRFilteringGaussRadiusDirect: 1 86 | m_PVRFilteringGaussRadiusIndirect: 5 87 | m_PVRFilteringGaussRadiusAO: 2 88 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 89 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 90 | m_PVRFilteringAtrousPositionSigmaAO: 1 91 | m_ShowResolutionOverlay: 1 92 | m_LightingDataAsset: {fileID: 0} 93 | m_UseShadowmask: 1 94 | --- !u!196 &4 95 | NavMeshSettings: 96 | serializedVersion: 2 97 | m_ObjectHideFlags: 0 98 | m_BuildSettings: 99 | serializedVersion: 2 100 | agentTypeID: 0 101 | agentRadius: 0.5 102 | agentHeight: 2 103 | agentSlope: 45 104 | agentClimb: 0.4 105 | ledgeDropHeight: 0 106 | maxJumpAcrossDistance: 0 107 | minRegionArea: 2 108 | manualCellSize: 0 109 | cellSize: 0.16666667 110 | manualTileSize: 0 111 | tileSize: 256 112 | accuratePlacement: 0 113 | debug: 114 | m_Flags: 0 115 | m_NavMeshData: {fileID: 0} 116 | --- !u!1 &664766254 117 | GameObject: 118 | m_ObjectHideFlags: 0 119 | m_PrefabParentObject: {fileID: 0} 120 | m_PrefabInternal: {fileID: 0} 121 | serializedVersion: 5 122 | m_Component: 123 | - component: {fileID: 664766258} 124 | - component: {fileID: 664766257} 125 | - component: {fileID: 664766256} 126 | - component: {fileID: 664766255} 127 | m_Layer: 0 128 | m_Name: Main Camera 129 | m_TagString: MainCamera 130 | m_Icon: {fileID: 0} 131 | m_NavMeshLayer: 0 132 | m_StaticEditorFlags: 0 133 | m_IsActive: 1 134 | --- !u!81 &664766255 135 | AudioListener: 136 | m_ObjectHideFlags: 0 137 | m_PrefabParentObject: {fileID: 0} 138 | m_PrefabInternal: {fileID: 0} 139 | m_GameObject: {fileID: 664766254} 140 | m_Enabled: 1 141 | --- !u!124 &664766256 142 | Behaviour: 143 | m_ObjectHideFlags: 0 144 | m_PrefabParentObject: {fileID: 0} 145 | m_PrefabInternal: {fileID: 0} 146 | m_GameObject: {fileID: 664766254} 147 | m_Enabled: 1 148 | --- !u!20 &664766257 149 | Camera: 150 | m_ObjectHideFlags: 0 151 | m_PrefabParentObject: {fileID: 0} 152 | m_PrefabInternal: {fileID: 0} 153 | m_GameObject: {fileID: 664766254} 154 | m_Enabled: 1 155 | serializedVersion: 2 156 | m_ClearFlags: 1 157 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 158 | m_NormalizedViewPortRect: 159 | serializedVersion: 2 160 | x: 0 161 | y: 0 162 | width: 1 163 | height: 1 164 | near clip plane: 0.3 165 | far clip plane: 1000 166 | field of view: 60 167 | orthographic: 0 168 | orthographic size: 5 169 | m_Depth: -1 170 | m_CullingMask: 171 | serializedVersion: 2 172 | m_Bits: 4294967295 173 | m_RenderingPath: -1 174 | m_TargetTexture: {fileID: 0} 175 | m_TargetDisplay: 0 176 | m_TargetEye: 3 177 | m_HDR: 1 178 | m_AllowMSAA: 1 179 | m_AllowDynamicResolution: 0 180 | m_ForceIntoRT: 0 181 | m_OcclusionCulling: 1 182 | m_StereoConvergence: 10 183 | m_StereoSeparation: 0.022 184 | --- !u!4 &664766258 185 | Transform: 186 | m_ObjectHideFlags: 0 187 | m_PrefabParentObject: {fileID: 0} 188 | m_PrefabInternal: {fileID: 0} 189 | m_GameObject: {fileID: 664766254} 190 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 191 | m_LocalPosition: {x: 0, y: 1, z: -10} 192 | m_LocalScale: {x: 1, y: 1, z: 1} 193 | m_Children: [] 194 | m_Father: {fileID: 0} 195 | m_RootOrder: 0 196 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 197 | --- !u!1 &676032182 198 | GameObject: 199 | m_ObjectHideFlags: 0 200 | m_PrefabParentObject: {fileID: 0} 201 | m_PrefabInternal: {fileID: 0} 202 | serializedVersion: 5 203 | m_Component: 204 | - component: {fileID: 676032184} 205 | - component: {fileID: 676032183} 206 | m_Layer: 0 207 | m_Name: Directional Light 208 | m_TagString: Untagged 209 | m_Icon: {fileID: 0} 210 | m_NavMeshLayer: 0 211 | m_StaticEditorFlags: 0 212 | m_IsActive: 1 213 | --- !u!108 &676032183 214 | Light: 215 | m_ObjectHideFlags: 0 216 | m_PrefabParentObject: {fileID: 0} 217 | m_PrefabInternal: {fileID: 0} 218 | m_GameObject: {fileID: 676032182} 219 | m_Enabled: 1 220 | serializedVersion: 8 221 | m_Type: 1 222 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 223 | m_Intensity: 1 224 | m_Range: 10 225 | m_SpotAngle: 30 226 | m_CookieSize: 10 227 | m_Shadows: 228 | m_Type: 2 229 | m_Resolution: -1 230 | m_CustomResolution: -1 231 | m_Strength: 1 232 | m_Bias: 0.05 233 | m_NormalBias: 0.4 234 | m_NearPlane: 0.2 235 | m_Cookie: {fileID: 0} 236 | m_DrawHalo: 0 237 | m_Flare: {fileID: 0} 238 | m_RenderMode: 0 239 | m_CullingMask: 240 | serializedVersion: 2 241 | m_Bits: 4294967295 242 | m_Lightmapping: 4 243 | m_AreaSize: {x: 1, y: 1} 244 | m_BounceIntensity: 1 245 | m_ColorTemperature: 6570 246 | m_UseColorTemperature: 0 247 | m_ShadowRadius: 0 248 | m_ShadowAngle: 0 249 | --- !u!4 &676032184 250 | Transform: 251 | m_ObjectHideFlags: 0 252 | m_PrefabParentObject: {fileID: 0} 253 | m_PrefabInternal: {fileID: 0} 254 | m_GameObject: {fileID: 676032182} 255 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 256 | m_LocalPosition: {x: 0, y: 3, z: 0} 257 | m_LocalScale: {x: 1, y: 1, z: 1} 258 | m_Children: [] 259 | m_Father: {fileID: 0} 260 | m_RootOrder: 1 261 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 262 | --- !u!1 &1539503798 263 | GameObject: 264 | m_ObjectHideFlags: 0 265 | m_PrefabParentObject: {fileID: 0} 266 | m_PrefabInternal: {fileID: 0} 267 | serializedVersion: 5 268 | m_Component: 269 | - component: {fileID: 1539503800} 270 | - component: {fileID: 1539503799} 271 | m_Layer: 0 272 | m_Name: TestDemo 273 | m_TagString: Untagged 274 | m_Icon: {fileID: 0} 275 | m_NavMeshLayer: 0 276 | m_StaticEditorFlags: 0 277 | m_IsActive: 1 278 | --- !u!114 &1539503799 279 | MonoBehaviour: 280 | m_ObjectHideFlags: 0 281 | m_PrefabParentObject: {fileID: 0} 282 | m_PrefabInternal: {fileID: 0} 283 | m_GameObject: {fileID: 1539503798} 284 | m_Enabled: 1 285 | m_EditorHideFlags: 0 286 | m_Script: {fileID: 11500000, guid: 38248f80ead75a442b3032045be5c6d8, type: 3} 287 | m_Name: 288 | m_EditorClassIdentifier: 289 | --- !u!4 &1539503800 290 | Transform: 291 | m_ObjectHideFlags: 0 292 | m_PrefabParentObject: {fileID: 0} 293 | m_PrefabInternal: {fileID: 0} 294 | m_GameObject: {fileID: 1539503798} 295 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 296 | m_LocalPosition: {x: 0, y: 0, z: 0} 297 | m_LocalScale: {x: 1, y: 1, z: 1} 298 | m_Children: [] 299 | m_Father: {fileID: 0} 300 | m_RootOrder: 2 301 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 302 | -------------------------------------------------------------------------------- /ENetUnityDemo/Assets/Scripts/Demo.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Threading; 3 | 4 | public class Demo : MonoBehaviour { 5 | Thread server; 6 | Thread client; 7 | 8 | private void Awake() 9 | { 10 | } 11 | 12 | private void Start() 13 | { 14 | Debug.Log("ENet demo"); 15 | 16 | server = new Thread(Server); 17 | server.Start(); 18 | Thread.Sleep(250); 19 | client = new Thread(Client); 20 | client.Start(); 21 | 22 | PacketManipulationDemo(); 23 | 24 | } 25 | 26 | private void OnDestroy() 27 | { 28 | server.Abort(); 29 | client.Abort(); 30 | } 31 | 32 | static void Server() 33 | { 34 | using (ENet.Host host = new ENet.Host()) 35 | { 36 | Debug.Log("Initializing server..."); 37 | 38 | host.InitializeServer(5000, 1); 39 | ENet.Peer peer = new ENet.Peer(); 40 | 41 | while (true) 42 | { 43 | ENet.Event @event; 44 | 45 | if (host.Service(15000, out @event)) 46 | { 47 | do 48 | { 49 | switch (@event.Type) 50 | { 51 | case ENet.EventType.Connect: 52 | peer = @event.Peer; 53 | // If you are using ENet 1.3.4 or newer, the following two methods will work: 54 | //peer.SetPingInterval(1000); 55 | //peer.SetTimeouts(8, 5000, 60000); 56 | Debug.LogFormat("Connected to client at IP/port {0}.", peer.GetRemoteAddress()); 57 | for (int i = 0; i < 200; i++) 58 | { 59 | ENet.Packet packet = new ENet.Packet(); 60 | packet.Initialize(new byte[] { 0, 0 }, 0, 2, ENet.PacketFlags.Reliable); 61 | packet.SetUserData(i); 62 | packet.SetUserData("Test", i * i); 63 | packet.Freed += p => 64 | { 65 | Debug.LogFormat("Initial packet freed (channel {0}, square of channel {1})", 66 | p.GetUserData(), 67 | p.GetUserData("Test")); 68 | }; 69 | peer.Send((byte)i, packet); 70 | } 71 | break; 72 | 73 | case ENet.EventType.Receive: 74 | byte[] data = @event.Packet.GetBytes(); 75 | ushort value = System.BitConverter.ToUInt16(data, 0); 76 | if (value % 1000 == 1) { Debug.LogFormat(" Server: Ch={0} Recv={1}", @event.ChannelID, value); } 77 | value++; peer.Send(@event.ChannelID, System.BitConverter.GetBytes(value), ENet.PacketFlags.Reliable); 78 | @event.Packet.Dispose(); 79 | break; 80 | } 81 | } 82 | while (host.CheckEvents(out @event)); 83 | } 84 | } 85 | } 86 | } 87 | 88 | static void Client() 89 | { 90 | using (ENet.Host host = new ENet.Host()) 91 | { 92 | Debug.Log("Initializing client..."); 93 | host.Initialize(null, 1); 94 | 95 | ENet.Peer peer = host.Connect("127.0.0.1", 5000, 1234, 200); 96 | while (true) 97 | { 98 | ENet.Event @event; 99 | 100 | if (host.Service(15000, out @event)) 101 | { 102 | do 103 | { 104 | switch (@event.Type) 105 | { 106 | case ENet.EventType.Connect: 107 | Debug.LogFormat("Connected to server at IP/port {0}.", peer.GetRemoteAddress()); 108 | break; 109 | 110 | case ENet.EventType.Receive: 111 | byte[] data = @event.Packet.GetBytes(); 112 | ushort value = System.BitConverter.ToUInt16(data, 0); 113 | if (value % 1000 == 0) { Debug.LogFormat(" Client: Ch={0} Recv={1}", @event.ChannelID, value); } 114 | value++; peer.Send(@event.ChannelID, System.BitConverter.GetBytes(value), ENet.PacketFlags.Reliable); 115 | @event.Packet.Dispose(); 116 | break; 117 | 118 | default: 119 | Debug.Log(@event.Type); 120 | break; 121 | } 122 | } 123 | while (host.CheckEvents(out @event)); 124 | } 125 | } 126 | } 127 | } 128 | 129 | static void PacketManipulationDemo() 130 | { 131 | Debug.Log("Packet manipulation test/demo... should print 3 2 1..."); 132 | using (ENet.Packet packet = new ENet.Packet()) 133 | { 134 | packet.Initialize(new byte[0]); 135 | packet.Add((byte)1); 136 | packet.Insert(0, (byte)3); 137 | packet.Insert(1, (byte)2); 138 | packet.Insert(packet.IndexOf((byte)3), 4); 139 | packet.Remove(1); 140 | packet.RemoveAt(0); 141 | if (packet.Contains(3)) { packet.Add((byte)1); } 142 | if (packet.Contains(4)) { packet.Add((byte)5); } 143 | 144 | byte[] bytes = packet.GetBytes(); 145 | for (int i = 0; i < bytes.Length; i++) 146 | { 147 | Debug.Log(bytes[i]); 148 | } 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 0 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_SpatializerPlugin: 15 | m_AmbisonicDecoderPlugin: 16 | m_DisableAudio: 0 17 | m_VirtualizeEffects: 1 18 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 1 23 | m_ClothInterCollisionSettingsToggle: 0 24 | m_ContactPairsMode: 0 25 | m_BroadphaseType: 0 26 | m_WorldBounds: 27 | m_Center: {x: 0, y: 0, z: 0} 28 | m_Extent: {x: 250, y: 250, z: 250} 29 | m_WorldSubdivisions: 8 30 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: 8 | - enabled: 1 9 | path: Assets/Scenes/Demo.unity 10 | guid: ec115d2aeddef9c408432e07a21cdf61 11 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_ExternalVersionControlSupport: Hidden Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_SpritePackerMode: 0 12 | m_SpritePackerPaddingPower: 1 13 | m_EtcTextureCompressorBehavior: 1 14 | m_EtcTextureFastCompressor: 1 15 | m_EtcTextureNormalCompressor: 2 16 | m_EtcTextureBestCompressor: 4 17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp 18 | m_ProjectGenerationRootNamespace: 19 | m_UserGeneratedProjectSuffix: 20 | m_CollabEditorSettings: 21 | inProgressEnabled: 1 22 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} 39 | - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} 40 | m_PreloadedShaders: [] 41 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 42 | type: 0} 43 | m_CustomRenderPipeline: {fileID: 0} 44 | m_TransparencySortMode: 0 45 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 46 | m_DefaultRenderingPath: 1 47 | m_DefaultMobileRenderingPath: 1 48 | m_TierSettings: [] 49 | m_LightmapStripping: 0 50 | m_FogStripping: 0 51 | m_InstancingStripping: 0 52 | m_LightmapKeepPlain: 1 53 | m_LightmapKeepDirCombined: 1 54 | m_LightmapKeepDynamicPlain: 1 55 | m_LightmapKeepDynamicDirCombined: 1 56 | m_LightmapKeepShadowMask: 1 57 | m_LightmapKeepSubtractive: 1 58 | m_FogKeepLinear: 1 59 | m_FogKeepExp: 1 60 | m_FogKeepExp2: 1 61 | m_AlbedoSwatchInfos: [] 62 | m_LightsUseLinearIntensity: 0 63 | m_LightsUseColorTemperature: 0 64 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!13 &1 4 | InputManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Axes: 8 | - serializedVersion: 3 9 | m_Name: Horizontal 10 | descriptiveName: 11 | descriptiveNegativeName: 12 | negativeButton: left 13 | positiveButton: right 14 | altNegativeButton: a 15 | altPositiveButton: d 16 | gravity: 3 17 | dead: 0.001 18 | sensitivity: 3 19 | snap: 1 20 | invert: 0 21 | type: 0 22 | axis: 0 23 | joyNum: 0 24 | - serializedVersion: 3 25 | m_Name: Vertical 26 | descriptiveName: 27 | descriptiveNegativeName: 28 | negativeButton: down 29 | positiveButton: up 30 | altNegativeButton: s 31 | altPositiveButton: w 32 | gravity: 3 33 | dead: 0.001 34 | sensitivity: 3 35 | snap: 1 36 | invert: 0 37 | type: 0 38 | axis: 0 39 | joyNum: 0 40 | - serializedVersion: 3 41 | m_Name: Fire1 42 | descriptiveName: 43 | descriptiveNegativeName: 44 | negativeButton: 45 | positiveButton: left ctrl 46 | altNegativeButton: 47 | altPositiveButton: mouse 0 48 | gravity: 1000 49 | dead: 0.001 50 | sensitivity: 1000 51 | snap: 0 52 | invert: 0 53 | type: 0 54 | axis: 0 55 | joyNum: 0 56 | - serializedVersion: 3 57 | m_Name: Fire2 58 | descriptiveName: 59 | descriptiveNegativeName: 60 | negativeButton: 61 | positiveButton: left alt 62 | altNegativeButton: 63 | altPositiveButton: mouse 1 64 | gravity: 1000 65 | dead: 0.001 66 | sensitivity: 1000 67 | snap: 0 68 | invert: 0 69 | type: 0 70 | axis: 0 71 | joyNum: 0 72 | - serializedVersion: 3 73 | m_Name: Fire3 74 | descriptiveName: 75 | descriptiveNegativeName: 76 | negativeButton: 77 | positiveButton: left shift 78 | altNegativeButton: 79 | altPositiveButton: mouse 2 80 | gravity: 1000 81 | dead: 0.001 82 | sensitivity: 1000 83 | snap: 0 84 | invert: 0 85 | type: 0 86 | axis: 0 87 | joyNum: 0 88 | - serializedVersion: 3 89 | m_Name: Jump 90 | descriptiveName: 91 | descriptiveNegativeName: 92 | negativeButton: 93 | positiveButton: space 94 | altNegativeButton: 95 | altPositiveButton: 96 | gravity: 1000 97 | dead: 0.001 98 | sensitivity: 1000 99 | snap: 0 100 | invert: 0 101 | type: 0 102 | axis: 0 103 | joyNum: 0 104 | - serializedVersion: 3 105 | m_Name: Mouse X 106 | descriptiveName: 107 | descriptiveNegativeName: 108 | negativeButton: 109 | positiveButton: 110 | altNegativeButton: 111 | altPositiveButton: 112 | gravity: 0 113 | dead: 0 114 | sensitivity: 0.1 115 | snap: 0 116 | invert: 0 117 | type: 1 118 | axis: 0 119 | joyNum: 0 120 | - serializedVersion: 3 121 | m_Name: Mouse Y 122 | descriptiveName: 123 | descriptiveNegativeName: 124 | negativeButton: 125 | positiveButton: 126 | altNegativeButton: 127 | altPositiveButton: 128 | gravity: 0 129 | dead: 0 130 | sensitivity: 0.1 131 | snap: 0 132 | invert: 0 133 | type: 1 134 | axis: 1 135 | joyNum: 0 136 | - serializedVersion: 3 137 | m_Name: Mouse ScrollWheel 138 | descriptiveName: 139 | descriptiveNegativeName: 140 | negativeButton: 141 | positiveButton: 142 | altNegativeButton: 143 | altPositiveButton: 144 | gravity: 0 145 | dead: 0 146 | sensitivity: 0.1 147 | snap: 0 148 | invert: 0 149 | type: 1 150 | axis: 2 151 | joyNum: 0 152 | - serializedVersion: 3 153 | m_Name: Horizontal 154 | descriptiveName: 155 | descriptiveNegativeName: 156 | negativeButton: 157 | positiveButton: 158 | altNegativeButton: 159 | altPositiveButton: 160 | gravity: 0 161 | dead: 0.19 162 | sensitivity: 1 163 | snap: 0 164 | invert: 0 165 | type: 2 166 | axis: 0 167 | joyNum: 0 168 | - serializedVersion: 3 169 | m_Name: Vertical 170 | descriptiveName: 171 | descriptiveNegativeName: 172 | negativeButton: 173 | positiveButton: 174 | altNegativeButton: 175 | altPositiveButton: 176 | gravity: 0 177 | dead: 0.19 178 | sensitivity: 1 179 | snap: 0 180 | invert: 1 181 | type: 2 182 | axis: 1 183 | joyNum: 0 184 | - serializedVersion: 3 185 | m_Name: Fire1 186 | descriptiveName: 187 | descriptiveNegativeName: 188 | negativeButton: 189 | positiveButton: joystick button 0 190 | altNegativeButton: 191 | altPositiveButton: 192 | gravity: 1000 193 | dead: 0.001 194 | sensitivity: 1000 195 | snap: 0 196 | invert: 0 197 | type: 0 198 | axis: 0 199 | joyNum: 0 200 | - serializedVersion: 3 201 | m_Name: Fire2 202 | descriptiveName: 203 | descriptiveNegativeName: 204 | negativeButton: 205 | positiveButton: joystick button 1 206 | altNegativeButton: 207 | altPositiveButton: 208 | gravity: 1000 209 | dead: 0.001 210 | sensitivity: 1000 211 | snap: 0 212 | invert: 0 213 | type: 0 214 | axis: 0 215 | joyNum: 0 216 | - serializedVersion: 3 217 | m_Name: Fire3 218 | descriptiveName: 219 | descriptiveNegativeName: 220 | negativeButton: 221 | positiveButton: joystick button 2 222 | altNegativeButton: 223 | altPositiveButton: 224 | gravity: 1000 225 | dead: 0.001 226 | sensitivity: 1000 227 | snap: 0 228 | invert: 0 229 | type: 0 230 | axis: 0 231 | joyNum: 0 232 | - serializedVersion: 3 233 | m_Name: Jump 234 | descriptiveName: 235 | descriptiveNegativeName: 236 | negativeButton: 237 | positiveButton: joystick button 3 238 | altNegativeButton: 239 | altPositiveButton: 240 | gravity: 1000 241 | dead: 0.001 242 | sensitivity: 1000 243 | snap: 0 244 | invert: 0 245 | type: 0 246 | axis: 0 247 | joyNum: 0 248 | - serializedVersion: 3 249 | m_Name: Submit 250 | descriptiveName: 251 | descriptiveNegativeName: 252 | negativeButton: 253 | positiveButton: return 254 | altNegativeButton: 255 | altPositiveButton: joystick button 0 256 | gravity: 1000 257 | dead: 0.001 258 | sensitivity: 1000 259 | snap: 0 260 | invert: 0 261 | type: 0 262 | axis: 0 263 | joyNum: 0 264 | - serializedVersion: 3 265 | m_Name: Submit 266 | descriptiveName: 267 | descriptiveNegativeName: 268 | negativeButton: 269 | positiveButton: enter 270 | altNegativeButton: 271 | altPositiveButton: space 272 | gravity: 1000 273 | dead: 0.001 274 | sensitivity: 1000 275 | snap: 0 276 | invert: 0 277 | type: 0 278 | axis: 0 279 | joyNum: 0 280 | - serializedVersion: 3 281 | m_Name: Cancel 282 | descriptiveName: 283 | descriptiveNegativeName: 284 | negativeButton: 285 | positiveButton: escape 286 | altNegativeButton: 287 | altPositiveButton: joystick button 1 288 | gravity: 1000 289 | dead: 0.001 290 | sensitivity: 1000 291 | snap: 0 292 | invert: 0 293 | type: 0 294 | axis: 0 295 | joyNum: 0 296 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_AutoSimulation: 1 23 | m_QueriesHitTriggers: 1 24 | m_QueriesStartInColliders: 1 25 | m_ChangeStopsCallbacks: 0 26 | m_CallbacksOnDisable: 1 27 | m_AutoSyncTransforms: 1 28 | m_AlwaysShowColliders: 0 29 | m_ShowColliderSleep: 1 30 | m_ShowColliderContacts: 0 31 | m_ShowColliderAABB: 0 32 | m_ContactArrowScale: 0.2 33 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 34 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 35 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 36 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 37 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 38 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!129 &1 4 | PlayerSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 14 7 | productGUID: 06257e212c0f15345ba43c46bf7d98e4 8 | AndroidProfiler: 0 9 | AndroidFilterTouchesWhenObscured: 0 10 | defaultScreenOrientation: 4 11 | targetDevice: 2 12 | useOnDemandResources: 0 13 | accelerometerFrequency: 60 14 | companyName: DefaultCompany 15 | productName: ENetUnityDemo 16 | defaultCursor: {fileID: 0} 17 | cursorHotspot: {x: 0, y: 0} 18 | m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1} 19 | m_ShowUnitySplashScreen: 1 20 | m_ShowUnitySplashLogo: 1 21 | m_SplashScreenOverlayOpacity: 1 22 | m_SplashScreenAnimation: 1 23 | m_SplashScreenLogoStyle: 1 24 | m_SplashScreenDrawMode: 0 25 | m_SplashScreenBackgroundAnimationZoom: 1 26 | m_SplashScreenLogoAnimationZoom: 1 27 | m_SplashScreenBackgroundLandscapeAspect: 1 28 | m_SplashScreenBackgroundPortraitAspect: 1 29 | m_SplashScreenBackgroundLandscapeUvs: 30 | serializedVersion: 2 31 | x: 0 32 | y: 0 33 | width: 1 34 | height: 1 35 | m_SplashScreenBackgroundPortraitUvs: 36 | serializedVersion: 2 37 | x: 0 38 | y: 0 39 | width: 1 40 | height: 1 41 | m_SplashScreenLogos: [] 42 | m_VirtualRealitySplashScreen: {fileID: 0} 43 | m_HolographicTrackingLossScreen: {fileID: 0} 44 | defaultScreenWidth: 1024 45 | defaultScreenHeight: 768 46 | defaultScreenWidthWeb: 960 47 | defaultScreenHeightWeb: 600 48 | m_StereoRenderingPath: 0 49 | m_ActiveColorSpace: 0 50 | m_MTRendering: 1 51 | m_StackTraceTypes: 010000000100000001000000010000000100000001000000 52 | iosShowActivityIndicatorOnLoading: -1 53 | androidShowActivityIndicatorOnLoading: -1 54 | tizenShowActivityIndicatorOnLoading: -1 55 | iosAppInBackgroundBehavior: 0 56 | displayResolutionDialog: 1 57 | iosAllowHTTPDownload: 1 58 | allowedAutorotateToPortrait: 1 59 | allowedAutorotateToPortraitUpsideDown: 1 60 | allowedAutorotateToLandscapeRight: 1 61 | allowedAutorotateToLandscapeLeft: 1 62 | useOSAutorotation: 1 63 | use32BitDisplayBuffer: 1 64 | preserveFramebufferAlpha: 0 65 | disableDepthAndStencilBuffers: 0 66 | androidBlitType: 0 67 | defaultIsFullScreen: 1 68 | defaultIsNativeResolution: 1 69 | macRetinaSupport: 1 70 | runInBackground: 0 71 | captureSingleScreen: 0 72 | muteOtherAudioSources: 0 73 | Prepare IOS For Recording: 0 74 | Force IOS Speakers When Recording: 0 75 | deferSystemGesturesMode: 0 76 | hideHomeButton: 0 77 | submitAnalytics: 1 78 | usePlayerLog: 1 79 | bakeCollisionMeshes: 0 80 | forceSingleInstance: 0 81 | resizableWindow: 0 82 | useMacAppStoreValidation: 0 83 | macAppStoreCategory: public.app-category.games 84 | gpuSkinning: 0 85 | graphicsJobs: 0 86 | xboxPIXTextureCapture: 0 87 | xboxEnableAvatar: 0 88 | xboxEnableKinect: 0 89 | xboxEnableKinectAutoTracking: 0 90 | xboxEnableFitness: 0 91 | visibleInBackground: 1 92 | allowFullscreenSwitch: 1 93 | graphicsJobMode: 0 94 | macFullscreenMode: 2 95 | d3d11FullscreenMode: 1 96 | xboxSpeechDB: 0 97 | xboxEnableHeadOrientation: 0 98 | xboxEnableGuest: 0 99 | xboxEnablePIXSampling: 0 100 | metalFramebufferOnly: 0 101 | n3dsDisableStereoscopicView: 0 102 | n3dsEnableSharedListOpt: 1 103 | n3dsEnableVSync: 0 104 | xboxOneResolution: 0 105 | xboxOneSResolution: 0 106 | xboxOneXResolution: 3 107 | xboxOneMonoLoggingLevel: 0 108 | xboxOneLoggingLevel: 1 109 | xboxOneDisableEsram: 0 110 | xboxOnePresentImmediateThreshold: 0 111 | videoMemoryForVertexBuffers: 0 112 | psp2PowerMode: 0 113 | psp2AcquireBGM: 1 114 | wiiUTVResolution: 0 115 | wiiUGamePadMSAA: 1 116 | wiiUSupportsNunchuk: 0 117 | wiiUSupportsClassicController: 0 118 | wiiUSupportsBalanceBoard: 0 119 | wiiUSupportsMotionPlus: 0 120 | wiiUSupportsProController: 0 121 | wiiUAllowScreenCapture: 1 122 | wiiUControllerCount: 0 123 | m_SupportedAspectRatios: 124 | 4:3: 1 125 | 5:4: 1 126 | 16:10: 1 127 | 16:9: 1 128 | Others: 1 129 | bundleVersion: 1.0 130 | preloadedAssets: [] 131 | metroInputSource: 0 132 | wsaTransparentSwapchain: 0 133 | m_HolographicPauseOnTrackingLoss: 1 134 | xboxOneDisableKinectGpuReservation: 0 135 | xboxOneEnable7thCore: 0 136 | vrSettings: 137 | cardboard: 138 | depthFormat: 0 139 | enableTransitionView: 0 140 | daydream: 141 | depthFormat: 0 142 | useSustainedPerformanceMode: 0 143 | enableVideoLayer: 0 144 | useProtectedVideoMemory: 0 145 | minimumSupportedHeadTracking: 0 146 | maximumSupportedHeadTracking: 1 147 | hololens: 148 | depthFormat: 1 149 | depthBufferSharingEnabled: 0 150 | oculus: 151 | sharedDepthBuffer: 0 152 | dashSupport: 0 153 | protectGraphicsMemory: 0 154 | useHDRDisplay: 0 155 | m_ColorGamuts: 00000000 156 | targetPixelDensity: 30 157 | resolutionScalingMode: 0 158 | androidSupportedAspectRatio: 1 159 | androidMaxAspectRatio: 2.1 160 | applicationIdentifier: {} 161 | buildNumber: {} 162 | AndroidBundleVersionCode: 1 163 | AndroidMinSdkVersion: 16 164 | AndroidTargetSdkVersion: 0 165 | AndroidPreferredInstallLocation: 1 166 | aotOptions: 167 | stripEngineCode: 1 168 | iPhoneStrippingLevel: 0 169 | iPhoneScriptCallOptimization: 0 170 | ForceInternetPermission: 0 171 | ForceSDCardPermission: 0 172 | CreateWallpaper: 0 173 | APKExpansionFiles: 0 174 | keepLoadedShadersAlive: 0 175 | StripUnusedMeshComponents: 0 176 | VertexChannelCompressionMask: 177 | serializedVersion: 2 178 | m_Bits: 238 179 | iPhoneSdkVersion: 988 180 | iOSTargetOSVersionString: 7.0 181 | tvOSSdkVersion: 0 182 | tvOSRequireExtendedGameController: 0 183 | tvOSTargetOSVersionString: 9.0 184 | uIPrerenderedIcon: 0 185 | uIRequiresPersistentWiFi: 0 186 | uIRequiresFullScreen: 1 187 | uIStatusBarHidden: 1 188 | uIExitOnSuspend: 0 189 | uIStatusBarStyle: 0 190 | iPhoneSplashScreen: {fileID: 0} 191 | iPhoneHighResSplashScreen: {fileID: 0} 192 | iPhoneTallHighResSplashScreen: {fileID: 0} 193 | iPhone47inSplashScreen: {fileID: 0} 194 | iPhone55inPortraitSplashScreen: {fileID: 0} 195 | iPhone55inLandscapeSplashScreen: {fileID: 0} 196 | iPhone58inPortraitSplashScreen: {fileID: 0} 197 | iPhone58inLandscapeSplashScreen: {fileID: 0} 198 | iPadPortraitSplashScreen: {fileID: 0} 199 | iPadHighResPortraitSplashScreen: {fileID: 0} 200 | iPadLandscapeSplashScreen: {fileID: 0} 201 | iPadHighResLandscapeSplashScreen: {fileID: 0} 202 | appleTVSplashScreen: {fileID: 0} 203 | appleTVSplashScreen2x: {fileID: 0} 204 | tvOSSmallIconLayers: [] 205 | tvOSSmallIconLayers2x: [] 206 | tvOSLargeIconLayers: [] 207 | tvOSTopShelfImageLayers: [] 208 | tvOSTopShelfImageLayers2x: [] 209 | tvOSTopShelfImageWideLayers: [] 210 | tvOSTopShelfImageWideLayers2x: [] 211 | iOSLaunchScreenType: 0 212 | iOSLaunchScreenPortrait: {fileID: 0} 213 | iOSLaunchScreenLandscape: {fileID: 0} 214 | iOSLaunchScreenBackgroundColor: 215 | serializedVersion: 2 216 | rgba: 0 217 | iOSLaunchScreenFillPct: 100 218 | iOSLaunchScreenSize: 100 219 | iOSLaunchScreenCustomXibPath: 220 | iOSLaunchScreeniPadType: 0 221 | iOSLaunchScreeniPadImage: {fileID: 0} 222 | iOSLaunchScreeniPadBackgroundColor: 223 | serializedVersion: 2 224 | rgba: 0 225 | iOSLaunchScreeniPadFillPct: 100 226 | iOSLaunchScreeniPadSize: 100 227 | iOSLaunchScreeniPadCustomXibPath: 228 | iOSUseLaunchScreenStoryboard: 0 229 | iOSLaunchScreenCustomStoryboardPath: 230 | iOSDeviceRequirements: [] 231 | iOSURLSchemes: [] 232 | iOSBackgroundModes: 0 233 | iOSMetalForceHardShadows: 0 234 | metalEditorSupport: 1 235 | metalAPIValidation: 1 236 | iOSRenderExtraFrameOnPause: 0 237 | appleDeveloperTeamID: 238 | iOSManualSigningProvisioningProfileID: 239 | tvOSManualSigningProvisioningProfileID: 240 | appleEnableAutomaticSigning: 0 241 | clonedFromGUID: 00000000000000000000000000000000 242 | AndroidTargetDevice: 0 243 | AndroidSplashScreenScale: 0 244 | androidSplashScreen: {fileID: 0} 245 | AndroidKeystoreName: 246 | AndroidKeyaliasName: 247 | AndroidTVCompatibility: 1 248 | AndroidIsGame: 1 249 | AndroidEnableTango: 0 250 | androidEnableBanner: 1 251 | androidUseLowAccuracyLocation: 0 252 | m_AndroidBanners: 253 | - width: 320 254 | height: 180 255 | banner: {fileID: 0} 256 | androidGamepadSupportLevel: 0 257 | resolutionDialogBanner: {fileID: 0} 258 | m_BuildTargetIcons: [] 259 | m_BuildTargetBatching: [] 260 | m_BuildTargetGraphicsAPIs: [] 261 | m_BuildTargetVRSettings: [] 262 | m_BuildTargetEnableVuforiaSettings: [] 263 | openGLRequireES31: 0 264 | openGLRequireES31AEP: 0 265 | m_TemplateCustomTags: {} 266 | mobileMTRendering: 267 | Android: 1 268 | iPhone: 1 269 | tvOS: 1 270 | m_BuildTargetGroupLightmapEncodingQuality: [] 271 | wiiUTitleID: 0005000011000000 272 | wiiUGroupID: 00010000 273 | wiiUCommonSaveSize: 4096 274 | wiiUAccountSaveSize: 2048 275 | wiiUOlvAccessKey: 0 276 | wiiUTinCode: 0 277 | wiiUJoinGameId: 0 278 | wiiUJoinGameModeMask: 0000000000000000 279 | wiiUCommonBossSize: 0 280 | wiiUAccountBossSize: 0 281 | wiiUAddOnUniqueIDs: [] 282 | wiiUMainThreadStackSize: 3072 283 | wiiULoaderThreadStackSize: 1024 284 | wiiUSystemHeapSize: 128 285 | wiiUTVStartupScreen: {fileID: 0} 286 | wiiUGamePadStartupScreen: {fileID: 0} 287 | wiiUDrcBufferDisabled: 0 288 | wiiUProfilerLibPath: 289 | playModeTestRunnerEnabled: 0 290 | actionOnDotNetUnhandledException: 1 291 | enableInternalProfiler: 0 292 | logObjCUncaughtExceptions: 1 293 | enableCrashReportAPI: 0 294 | cameraUsageDescription: 295 | locationUsageDescription: 296 | microphoneUsageDescription: 297 | switchNetLibKey: 298 | switchSocketMemoryPoolSize: 6144 299 | switchSocketAllocatorPoolSize: 128 300 | switchSocketConcurrencyLimit: 14 301 | switchScreenResolutionBehavior: 2 302 | switchUseCPUProfiler: 0 303 | switchApplicationID: 0x01004b9000490000 304 | switchNSODependencies: 305 | switchTitleNames_0: 306 | switchTitleNames_1: 307 | switchTitleNames_2: 308 | switchTitleNames_3: 309 | switchTitleNames_4: 310 | switchTitleNames_5: 311 | switchTitleNames_6: 312 | switchTitleNames_7: 313 | switchTitleNames_8: 314 | switchTitleNames_9: 315 | switchTitleNames_10: 316 | switchTitleNames_11: 317 | switchTitleNames_12: 318 | switchTitleNames_13: 319 | switchTitleNames_14: 320 | switchPublisherNames_0: 321 | switchPublisherNames_1: 322 | switchPublisherNames_2: 323 | switchPublisherNames_3: 324 | switchPublisherNames_4: 325 | switchPublisherNames_5: 326 | switchPublisherNames_6: 327 | switchPublisherNames_7: 328 | switchPublisherNames_8: 329 | switchPublisherNames_9: 330 | switchPublisherNames_10: 331 | switchPublisherNames_11: 332 | switchPublisherNames_12: 333 | switchPublisherNames_13: 334 | switchPublisherNames_14: 335 | switchIcons_0: {fileID: 0} 336 | switchIcons_1: {fileID: 0} 337 | switchIcons_2: {fileID: 0} 338 | switchIcons_3: {fileID: 0} 339 | switchIcons_4: {fileID: 0} 340 | switchIcons_5: {fileID: 0} 341 | switchIcons_6: {fileID: 0} 342 | switchIcons_7: {fileID: 0} 343 | switchIcons_8: {fileID: 0} 344 | switchIcons_9: {fileID: 0} 345 | switchIcons_10: {fileID: 0} 346 | switchIcons_11: {fileID: 0} 347 | switchIcons_12: {fileID: 0} 348 | switchIcons_13: {fileID: 0} 349 | switchIcons_14: {fileID: 0} 350 | switchSmallIcons_0: {fileID: 0} 351 | switchSmallIcons_1: {fileID: 0} 352 | switchSmallIcons_2: {fileID: 0} 353 | switchSmallIcons_3: {fileID: 0} 354 | switchSmallIcons_4: {fileID: 0} 355 | switchSmallIcons_5: {fileID: 0} 356 | switchSmallIcons_6: {fileID: 0} 357 | switchSmallIcons_7: {fileID: 0} 358 | switchSmallIcons_8: {fileID: 0} 359 | switchSmallIcons_9: {fileID: 0} 360 | switchSmallIcons_10: {fileID: 0} 361 | switchSmallIcons_11: {fileID: 0} 362 | switchSmallIcons_12: {fileID: 0} 363 | switchSmallIcons_13: {fileID: 0} 364 | switchSmallIcons_14: {fileID: 0} 365 | switchManualHTML: 366 | switchAccessibleURLs: 367 | switchLegalInformation: 368 | switchMainThreadStackSize: 1048576 369 | switchPresenceGroupId: 370 | switchLogoHandling: 0 371 | switchReleaseVersion: 0 372 | switchDisplayVersion: 1.0.0 373 | switchStartupUserAccount: 0 374 | switchTouchScreenUsage: 0 375 | switchSupportedLanguagesMask: 0 376 | switchLogoType: 0 377 | switchApplicationErrorCodeCategory: 378 | switchUserAccountSaveDataSize: 0 379 | switchUserAccountSaveDataJournalSize: 0 380 | switchApplicationAttribute: 0 381 | switchCardSpecSize: -1 382 | switchCardSpecClock: -1 383 | switchRatingsMask: 0 384 | switchRatingsInt_0: 0 385 | switchRatingsInt_1: 0 386 | switchRatingsInt_2: 0 387 | switchRatingsInt_3: 0 388 | switchRatingsInt_4: 0 389 | switchRatingsInt_5: 0 390 | switchRatingsInt_6: 0 391 | switchRatingsInt_7: 0 392 | switchRatingsInt_8: 0 393 | switchRatingsInt_9: 0 394 | switchRatingsInt_10: 0 395 | switchRatingsInt_11: 0 396 | switchLocalCommunicationIds_0: 397 | switchLocalCommunicationIds_1: 398 | switchLocalCommunicationIds_2: 399 | switchLocalCommunicationIds_3: 400 | switchLocalCommunicationIds_4: 401 | switchLocalCommunicationIds_5: 402 | switchLocalCommunicationIds_6: 403 | switchLocalCommunicationIds_7: 404 | switchParentalControl: 0 405 | switchAllowsScreenshot: 1 406 | switchAllowsVideoCapturing: 1 407 | switchAllowsRuntimeAddOnContentInstall: 0 408 | switchDataLossConfirmation: 0 409 | switchSupportedNpadStyles: 3 410 | switchSocketConfigEnabled: 0 411 | switchTcpInitialSendBufferSize: 32 412 | switchTcpInitialReceiveBufferSize: 64 413 | switchTcpAutoSendBufferSizeMax: 256 414 | switchTcpAutoReceiveBufferSizeMax: 256 415 | switchUdpSendBufferSize: 9 416 | switchUdpReceiveBufferSize: 42 417 | switchSocketBufferEfficiency: 4 418 | switchSocketInitializeEnabled: 1 419 | switchNetworkInterfaceManagerInitializeEnabled: 1 420 | switchPlayerConnectionEnabled: 1 421 | ps4NPAgeRating: 12 422 | ps4NPTitleSecret: 423 | ps4NPTrophyPackPath: 424 | ps4ParentalLevel: 11 425 | ps4ContentID: ED1633-NPXX51362_00-0000000000000000 426 | ps4Category: 0 427 | ps4MasterVersion: 01.00 428 | ps4AppVersion: 01.00 429 | ps4AppType: 0 430 | ps4ParamSfxPath: 431 | ps4VideoOutPixelFormat: 0 432 | ps4VideoOutInitialWidth: 1920 433 | ps4VideoOutBaseModeInitialWidth: 1920 434 | ps4VideoOutReprojectionRate: 60 435 | ps4PronunciationXMLPath: 436 | ps4PronunciationSIGPath: 437 | ps4BackgroundImagePath: 438 | ps4StartupImagePath: 439 | ps4StartupImagesFolder: 440 | ps4IconImagesFolder: 441 | ps4SaveDataImagePath: 442 | ps4SdkOverride: 443 | ps4BGMPath: 444 | ps4ShareFilePath: 445 | ps4ShareOverlayImagePath: 446 | ps4PrivacyGuardImagePath: 447 | ps4NPtitleDatPath: 448 | ps4RemotePlayKeyAssignment: -1 449 | ps4RemotePlayKeyMappingDir: 450 | ps4PlayTogetherPlayerCount: 0 451 | ps4EnterButtonAssignment: 1 452 | ps4ApplicationParam1: 0 453 | ps4ApplicationParam2: 0 454 | ps4ApplicationParam3: 0 455 | ps4ApplicationParam4: 0 456 | ps4DownloadDataSize: 0 457 | ps4GarlicHeapSize: 2048 458 | ps4ProGarlicHeapSize: 2560 459 | ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ 460 | ps4pnSessions: 1 461 | ps4pnPresence: 1 462 | ps4pnFriends: 1 463 | ps4pnGameCustomData: 1 464 | playerPrefsSupport: 0 465 | restrictedAudioUsageRights: 0 466 | ps4UseResolutionFallback: 0 467 | ps4ReprojectionSupport: 0 468 | ps4UseAudio3dBackend: 0 469 | ps4SocialScreenEnabled: 0 470 | ps4ScriptOptimizationLevel: 0 471 | ps4Audio3dVirtualSpeakerCount: 14 472 | ps4attribCpuUsage: 0 473 | ps4PatchPkgPath: 474 | ps4PatchLatestPkgPath: 475 | ps4PatchChangeinfoPath: 476 | ps4PatchDayOne: 0 477 | ps4attribUserManagement: 0 478 | ps4attribMoveSupport: 0 479 | ps4attrib3DSupport: 0 480 | ps4attribShareSupport: 0 481 | ps4attribExclusiveVR: 0 482 | ps4disableAutoHideSplash: 0 483 | ps4videoRecordingFeaturesUsed: 0 484 | ps4contentSearchFeaturesUsed: 0 485 | ps4attribEyeToEyeDistanceSettingVR: 0 486 | ps4IncludedModules: [] 487 | monoEnv: 488 | psp2Splashimage: {fileID: 0} 489 | psp2NPTrophyPackPath: 490 | psp2NPSupportGBMorGJP: 0 491 | psp2NPAgeRating: 12 492 | psp2NPTitleDatPath: 493 | psp2NPCommsID: 494 | psp2NPCommunicationsID: 495 | psp2NPCommsPassphrase: 496 | psp2NPCommsSig: 497 | psp2ParamSfxPath: 498 | psp2ManualPath: 499 | psp2LiveAreaGatePath: 500 | psp2LiveAreaBackroundPath: 501 | psp2LiveAreaPath: 502 | psp2LiveAreaTrialPath: 503 | psp2PatchChangeInfoPath: 504 | psp2PatchOriginalPackage: 505 | psp2PackagePassword: F69AzBlax3CF3EDNhm3soLBPh71Yexui 506 | psp2KeystoneFile: 507 | psp2MemoryExpansionMode: 0 508 | psp2DRMType: 0 509 | psp2StorageType: 0 510 | psp2MediaCapacity: 0 511 | psp2DLCConfigPath: 512 | psp2ThumbnailPath: 513 | psp2BackgroundPath: 514 | psp2SoundPath: 515 | psp2TrophyCommId: 516 | psp2TrophyPackagePath: 517 | psp2PackagedResourcesPath: 518 | psp2SaveDataQuota: 10240 519 | psp2ParentalLevel: 1 520 | psp2ShortTitle: Not Set 521 | psp2ContentID: IV0000-ABCD12345_00-0123456789ABCDEF 522 | psp2Category: 0 523 | psp2MasterVersion: 01.00 524 | psp2AppVersion: 01.00 525 | psp2TVBootMode: 0 526 | psp2EnterButtonAssignment: 2 527 | psp2TVDisableEmu: 0 528 | psp2AllowTwitterDialog: 1 529 | psp2Upgradable: 0 530 | psp2HealthWarning: 0 531 | psp2UseLibLocation: 0 532 | psp2InfoBarOnStartup: 0 533 | psp2InfoBarColor: 0 534 | psp2ScriptOptimizationLevel: 0 535 | psmSplashimage: {fileID: 0} 536 | splashScreenBackgroundSourceLandscape: {fileID: 0} 537 | splashScreenBackgroundSourcePortrait: {fileID: 0} 538 | spritePackerPolicy: 539 | webGLMemorySize: 256 540 | webGLExceptionSupport: 1 541 | webGLNameFilesAsHashes: 0 542 | webGLDataCaching: 0 543 | webGLDebugSymbols: 0 544 | webGLEmscriptenArgs: 545 | webGLModulesDirectory: 546 | webGLTemplate: APPLICATION:Default 547 | webGLAnalyzeBuildSize: 0 548 | webGLUseEmbeddedResources: 0 549 | webGLUseWasm: 0 550 | webGLCompressionFormat: 1 551 | scriptingDefineSymbols: {} 552 | platformArchitecture: {} 553 | scriptingBackend: {} 554 | incrementalIl2cppBuild: {} 555 | additionalIl2CppArgs: 556 | scriptingRuntimeVersion: 0 557 | apiCompatibilityLevelPerPlatform: {} 558 | m_RenderingPath: 1 559 | m_MobileRenderingPath: 1 560 | metroPackageName: ENetUnityDemo 561 | metroPackageVersion: 562 | metroCertificatePath: 563 | metroCertificatePassword: 564 | metroCertificateSubject: 565 | metroCertificateIssuer: 566 | metroCertificateNotAfter: 0000000000000000 567 | metroApplicationDescription: ENetUnityDemo 568 | wsaImages: {} 569 | metroTileShortName: 570 | metroCommandLineArgsFile: 571 | metroTileShowName: 0 572 | metroMediumTileShowName: 0 573 | metroLargeTileShowName: 0 574 | metroWideTileShowName: 0 575 | metroDefaultTileSize: 1 576 | metroTileForegroundText: 2 577 | metroTileBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21568628, a: 0} 578 | metroSplashScreenBackgroundColor: {r: 0.12941177, g: 0.17254902, b: 0.21568628, 579 | a: 1} 580 | metroSplashScreenUseBackgroundColor: 0 581 | platformCapabilities: {} 582 | metroFTAName: 583 | metroFTAFileTypes: [] 584 | metroProtocolName: 585 | metroCompilationOverrides: 1 586 | tizenProductDescription: 587 | tizenProductURL: 588 | tizenSigningProfileName: 589 | tizenGPSPermissions: 0 590 | tizenMicrophonePermissions: 0 591 | tizenDeploymentTarget: 592 | tizenDeploymentTargetType: -1 593 | tizenMinOSVersion: 1 594 | n3dsUseExtSaveData: 0 595 | n3dsCompressStaticMem: 1 596 | n3dsExtSaveDataNumber: 0x12345 597 | n3dsStackSize: 131072 598 | n3dsTargetPlatform: 2 599 | n3dsRegion: 7 600 | n3dsMediaSize: 0 601 | n3dsLogoStyle: 3 602 | n3dsTitle: GameName 603 | n3dsProductCode: 604 | n3dsApplicationId: 0xFF3FF 605 | XboxOneProductId: 606 | XboxOneUpdateKey: 607 | XboxOneSandboxId: 608 | XboxOneContentId: 609 | XboxOneTitleId: 610 | XboxOneSCId: 611 | XboxOneGameOsOverridePath: 612 | XboxOnePackagingOverridePath: 613 | XboxOneAppManifestOverridePath: 614 | XboxOnePackageEncryption: 0 615 | XboxOnePackageUpdateGranularity: 2 616 | XboxOneDescription: 617 | XboxOneLanguage: 618 | - enus 619 | XboxOneCapability: [] 620 | XboxOneGameRating: {} 621 | XboxOneIsContentPackage: 0 622 | XboxOneEnableGPUVariability: 0 623 | XboxOneSockets: {} 624 | XboxOneSplashScreen: {fileID: 0} 625 | XboxOneAllowedProductIds: [] 626 | XboxOnePersistentLocalStorageSize: 0 627 | xboxOneScriptCompiler: 0 628 | vrEditorSettings: 629 | daydream: 630 | daydreamIconForeground: {fileID: 0} 631 | daydreamIconBackground: {fileID: 0} 632 | cloudServicesEnabled: {} 633 | facebookSdkVersion: 7.9.4 634 | apiCompatibilityLevel: 2 635 | cloudProjectId: 636 | projectName: 637 | organizationId: 638 | cloudEnabled: 0 639 | enableNativePlatformBackendsForNewInputSystem: 0 640 | disableOldInputManagerSupport: 0 641 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2017.4.2f2 2 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 5 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | particleRaycastBudget: 4 33 | asyncUploadTimeSlice: 2 34 | asyncUploadBufferSize: 4 35 | resolutionScalingFixedDPIFactor: 1 36 | excludedTargetPlatforms: [] 37 | - serializedVersion: 2 38 | name: Low 39 | pixelLightCount: 0 40 | shadows: 0 41 | shadowResolution: 0 42 | shadowProjection: 1 43 | shadowCascades: 1 44 | shadowDistance: 20 45 | shadowNearPlaneOffset: 3 46 | shadowCascade2Split: 0.33333334 47 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 48 | shadowmaskMode: 0 49 | blendWeights: 2 50 | textureQuality: 0 51 | anisotropicTextures: 0 52 | antiAliasing: 0 53 | softParticles: 0 54 | softVegetation: 0 55 | realtimeReflectionProbes: 0 56 | billboardsFaceCameraPosition: 0 57 | vSyncCount: 0 58 | lodBias: 0.4 59 | maximumLODLevel: 0 60 | particleRaycastBudget: 16 61 | asyncUploadTimeSlice: 2 62 | asyncUploadBufferSize: 4 63 | resolutionScalingFixedDPIFactor: 1 64 | excludedTargetPlatforms: [] 65 | - serializedVersion: 2 66 | name: Medium 67 | pixelLightCount: 1 68 | shadows: 1 69 | shadowResolution: 0 70 | shadowProjection: 1 71 | shadowCascades: 1 72 | shadowDistance: 20 73 | shadowNearPlaneOffset: 3 74 | shadowCascade2Split: 0.33333334 75 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 76 | shadowmaskMode: 0 77 | blendWeights: 2 78 | textureQuality: 0 79 | anisotropicTextures: 1 80 | antiAliasing: 0 81 | softParticles: 0 82 | softVegetation: 0 83 | realtimeReflectionProbes: 0 84 | billboardsFaceCameraPosition: 0 85 | vSyncCount: 1 86 | lodBias: 0.7 87 | maximumLODLevel: 0 88 | particleRaycastBudget: 64 89 | asyncUploadTimeSlice: 2 90 | asyncUploadBufferSize: 4 91 | resolutionScalingFixedDPIFactor: 1 92 | excludedTargetPlatforms: [] 93 | - serializedVersion: 2 94 | name: High 95 | pixelLightCount: 2 96 | shadows: 2 97 | shadowResolution: 1 98 | shadowProjection: 1 99 | shadowCascades: 2 100 | shadowDistance: 40 101 | shadowNearPlaneOffset: 3 102 | shadowCascade2Split: 0.33333334 103 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 104 | shadowmaskMode: 1 105 | blendWeights: 2 106 | textureQuality: 0 107 | anisotropicTextures: 1 108 | antiAliasing: 0 109 | softParticles: 0 110 | softVegetation: 1 111 | realtimeReflectionProbes: 1 112 | billboardsFaceCameraPosition: 1 113 | vSyncCount: 1 114 | lodBias: 1 115 | maximumLODLevel: 0 116 | particleRaycastBudget: 256 117 | asyncUploadTimeSlice: 2 118 | asyncUploadBufferSize: 4 119 | resolutionScalingFixedDPIFactor: 1 120 | excludedTargetPlatforms: [] 121 | - serializedVersion: 2 122 | name: Very High 123 | pixelLightCount: 3 124 | shadows: 2 125 | shadowResolution: 2 126 | shadowProjection: 1 127 | shadowCascades: 2 128 | shadowDistance: 70 129 | shadowNearPlaneOffset: 3 130 | shadowCascade2Split: 0.33333334 131 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 132 | shadowmaskMode: 1 133 | blendWeights: 4 134 | textureQuality: 0 135 | anisotropicTextures: 2 136 | antiAliasing: 2 137 | softParticles: 1 138 | softVegetation: 1 139 | realtimeReflectionProbes: 1 140 | billboardsFaceCameraPosition: 1 141 | vSyncCount: 1 142 | lodBias: 1.5 143 | maximumLODLevel: 0 144 | particleRaycastBudget: 1024 145 | asyncUploadTimeSlice: 2 146 | asyncUploadBufferSize: 4 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Ultra 151 | pixelLightCount: 4 152 | shadows: 2 153 | shadowResolution: 2 154 | shadowProjection: 1 155 | shadowCascades: 4 156 | shadowDistance: 150 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 2 164 | antiAliasing: 2 165 | softParticles: 1 166 | softVegetation: 1 167 | realtimeReflectionProbes: 1 168 | billboardsFaceCameraPosition: 1 169 | vSyncCount: 1 170 | lodBias: 2 171 | maximumLODLevel: 0 172 | particleRaycastBudget: 4096 173 | asyncUploadTimeSlice: 2 174 | asyncUploadBufferSize: 4 175 | resolutionScalingFixedDPIFactor: 1 176 | excludedTargetPlatforms: [] 177 | m_PerPlatformDefaultQuality: 178 | Android: 2 179 | Nintendo 3DS: 5 180 | Nintendo Switch: 5 181 | PS4: 5 182 | PSM: 5 183 | PSP2: 2 184 | Standalone: 5 185 | Tizen: 2 186 | WebGL: 3 187 | WiiU: 5 188 | Windows Store Apps: 5 189 | XboxOne: 5 190 | iPhone: 2 191 | tvOS: 2 192 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.33333334 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /ENetUnityDemo/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | m_Enabled: 0 7 | m_TestMode: 0 8 | m_TestEventUrl: 9 | m_TestConfigUrl: 10 | m_TestInitMode: 0 11 | CrashReportingSettings: 12 | m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes 13 | m_NativeEventUrl: https://perf-events.cloud.unity3d.com/symbolicate 14 | m_Enabled: 0 15 | m_CaptureEditorExceptions: 1 16 | UnityPurchasingSettings: 17 | m_Enabled: 0 18 | m_TestMode: 0 19 | UnityAnalyticsSettings: 20 | m_Enabled: 0 21 | m_InitializeOnStartup: 1 22 | m_TestMode: 0 23 | m_TestEventUrl: 24 | m_TestConfigUrl: 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /ENetUnityDemo/UnityPackageManager/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | } 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ittipon Teerapruettikulchai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | ENet for C# 2 | Copyright (c) 2011-2013 James F. Bellinger 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ENetForUnity 2 | ENet C# wrapper forked from https://www.zer7.com/software/enetcs for Unity 3 | -------------------------------------------------------------------------------- /enet-cs.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27428.2005 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetCS", "ENetCS\ENetCS.csproj", "{D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetDemo", "ENetDemo\ENetDemo.csproj", "{E8F8C79F-557D-4454-A67B-996CF55F6BF2}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENetDLL", "ENetDLL\ENetDLL.vcxproj", "{11C051F5-67C7-E71E-9BE7-1AC69755EE31}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Release|Any CPU = Release|Any CPU 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Debug|x64.ActiveCfg = Debug|Any CPU 25 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Debug|x64.Build.0 = Debug|Any CPU 26 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Debug|x86.ActiveCfg = Debug|Any CPU 27 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Debug|x86.Build.0 = Debug|Any CPU 28 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Release|x64.ActiveCfg = Release|Any CPU 31 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Release|x64.Build.0 = Release|Any CPU 32 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Release|x86.ActiveCfg = Release|Any CPU 33 | {D3AFF7FA-96F6-42B8-B03C-E508DC80EC3A}.Release|x86.Build.0 = Release|Any CPU 34 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Debug|x64.ActiveCfg = Debug|Any CPU 37 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Debug|x64.Build.0 = Debug|Any CPU 38 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Debug|x86.ActiveCfg = Debug|Any CPU 39 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Debug|x86.Build.0 = Debug|Any CPU 40 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Release|x64.ActiveCfg = Release|Any CPU 43 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Release|x64.Build.0 = Release|Any CPU 44 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Release|x86.ActiveCfg = Release|Any CPU 45 | {E8F8C79F-557D-4454-A67B-996CF55F6BF2}.Release|x86.Build.0 = Release|Any CPU 46 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Debug|Any CPU.ActiveCfg = Debug|x64 47 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Debug|Any CPU.Build.0 = Debug|x64 48 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Debug|x64.ActiveCfg = Debug|x64 49 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Debug|x64.Build.0 = Debug|x64 50 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Debug|x86.ActiveCfg = Debug|Win32 51 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Debug|x86.Build.0 = Debug|Win32 52 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Release|Any CPU.ActiveCfg = Release|Win32 53 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Release|x64.ActiveCfg = Release|x64 54 | {11C051F5-67C7-E71E-9BE7-1AC69755EE31}.Release|x86.ActiveCfg = Release|Win32 55 | EndGlobalSection 56 | GlobalSection(SolutionProperties) = preSolution 57 | HideSolutionNode = FALSE 58 | EndGlobalSection 59 | GlobalSection(ExtensibilityGlobals) = postSolution 60 | SolutionGuid = {9AADF93F-C84B-40CD-B575-F1BD0EB8F931} 61 | EndGlobalSection 62 | EndGlobal 63 | --------------------------------------------------------------------------------