public void TestWrite() { var ms = new MapStart { MapSize = 1024 }; byte[] buffer = new byte[ms.Length]; ms.Write(buffer.AsSpan()); byte[] expected = new byte[] { 0x0, 0x4, 0x0, 0x0 }; Assert.Equal(expected, buffer); var cp = new CreatePlayer { Name = "Deuce", PlayerId = 0, Position = new Vector3(0f, 0f, 0f), Team = TeamType.Blue, Weapon = WeaponType.Rifle }; buffer = new byte[cp.Length]; cp.Write(buffer.AsSpan()); expected = new byte[] { // ID 0x0, // Weapon 0x0, // Team (byte)TeamType.Blue, // Position 0x0, 0x0, 0x0, 0x00, 0x0, 0x0, 0x0, 0x00, 0x0, 0x0, 0x0, 0x00, // Name 0x44, 0x65, 0x75, 0x63, 0x65 }; output.WriteLine("Expected:"); output.WriteLine(HexDump.Create(expected)); output.WriteLine("Actual:"); output.WriteLine(HexDump.Create(buffer)); Assert.Equal(expected, buffer); }
public void Test_Write() { var packet = new StateData { PlayerId = 1, FogColor = Color.Red, BlueColor = Color.Blue, GreenColor = Color.Green, BlueName = "AAAAAAAAAA", GreenName = "BBBBBBBBBB", State = new TcState() }; Span <byte> buffer = new byte[packet.Length]; buffer.Fill(0x1); packet.Write(buffer); byte[] expected = new byte[] { // Player ID 0x01, // Fog 0x00, 0x00, 0xFF, // Blue team 0xFF, 0x00, 0x00, // Green team 0x00, 0x80, 0x00, // Blue name 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // Green name 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, // Gamemode ID 0x01, 0x00 //#region CTF State //// Scores //0x00, 0x00, 0x00, //// Intel flags //0x00, //// Blue intel location //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //// Green intel location //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //// Blue base location //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //// Green base location //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //#endregion }; output.WriteLine("Expected:"); output.WriteLine(HexDump.Create(expected)); output.WriteLine("Actual:"); output.WriteLine(HexDump.Create(buffer)); Assert.Equal(expected, buffer.ToArray()); }
public void Test_Write() { var packet = new CtfState { BlueScore = 2, GreenScore = 3, CaptureLimit = 5, BlueHasIntel = true, GreenHasIntel = true, BlueIntel = new IntelLocation { Holder = 1, IsHeld = true }, GreenIntel = new IntelLocation { IsHeld = false, Position = new Vector3(1, 1, 1) }, BlueBasePosition = new Vector3(10, 10, 10), GreenBasePosition = new Vector3(20, 20, 20) }; Span <byte> buffer = new byte[packet.Length]; buffer.Fill(0x1); packet.WriteTo(buffer); byte[] expected = new byte[] { // Scores 0x02, 0x03, // Capture limit 0x05, // Intel flags 0x03, // Blue intel location // Holder 0x01, // Padding 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Green intel location // X 0x00, 0x00, 0x80, 0x3F, // Y 0x00, 0x00, 0x80, 0x3F, // Z 0x00, 0x00, 0x80, 0x3F, // Blue base location // X 0x00, 0x00, 0x20, 0x41, // Y 0x00, 0x00, 0x20, 0x41, // Z 0x00, 0x00, 0x20, 0x41, // Green base location // X 0x00, 0x00, 0xA0, 0x41, // Y 0x00, 0x00, 0xA0, 0x41, // Z 0x00, 0x00, 0xA0, 0x41 }; output.WriteLine("Expected:"); output.WriteLine(HexDump.Create(expected)); output.WriteLine("Actual:"); output.WriteLine(HexDump.Create(buffer)); Assert.Equal(expected, buffer.ToArray()); }