public void Test_Patching_Payload_Deserializes_To_Correct_Values()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadClient, PSOBBPatchPacketPayloadClient_AutoGeneratedTemplateSerializerStrategy>();
            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadServer, PSOBBPatchPacketPayloadServer_AutoGeneratedTemplateSerializerStrategy>();
            Span <byte> buffer = new Span <byte>(new byte[500]);

            PatchingWelcomePayload payload = new PatchingWelcomePayload("Patch Server. Copyright SonicTeam, LTD. 2001", 506953426, 214005626);

            //assert
            int offset = 0;

            serializer.Write(payload, buffer, ref offset);
            int size = offset;

            offset = 0;
            PatchingWelcomePayload deserializedPayload = (PatchingWelcomePayload)serializer.Read <PSOBBPatchPacketPayloadServer>(buffer.Slice(0, size), ref offset);

            //assert
            Assert.AreEqual(payload.PatchCopyrightMessage, deserializedPayload.PatchCopyrightMessage);
            Assert.AreEqual(payload.ClientVector, deserializedPayload.ClientVector);
            Assert.AreEqual(payload.ServerVector, deserializedPayload.ServerVector);
            Assert.AreEqual(0x99, deserializedPayload.OperationCode);
        }
        public void Test_Can_Register_Payload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadClient, PSOBBPatchPacketPayloadClient_AutoGeneratedTemplateSerializerStrategy>();
            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadServer, PSOBBPatchPacketPayloadServer_AutoGeneratedTemplateSerializerStrategy>();
        }
        public void Test_Can_Register_Payload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadClient, PSOBBPatchPacketPayloadClient_Serializer>();
            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadServer, PSOBBPatchPacketPayloadServer_Serializer>();
        }
        public void Test_No_Stack_Overflow_On_Deserializing_PacketHeader()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadClient, PSOBBPatchPacketPayloadClient_AutoGeneratedTemplateSerializerStrategy>();
            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadServer, PSOBBPatchPacketPayloadServer_AutoGeneratedTemplateSerializerStrategy>();

            byte[] bytes = new byte[] { 55, 78 };

            serializer.Read <PSOBBPacketHeader>(new Span <byte>(bytes), 0);
        }
예제 #5
0
        public IReadOnlyCollection <PacketCaptureTestEntry> BuildCaptureEntries(Expansions expacType, SerializerService serializer, IEnumerable <Type> typesToRegister)
        {
            List <PacketCaptureTestEntry> testSource = new List <PacketCaptureTestEntry>(500);

            //Do file loading first because it could fail
            //Then we need to populate the input source for the tests.
            string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "PacketCaptures", expacType.ToString());

            //Get every folder
            foreach (string dir in Directory.GetDirectories(testPath))
            {
                //Each directory should fit the form of OpCode name
                //Even though the below is a Path with the directory if we pretend it's a file we can easily get the last part of the path
                //which represents the opcode
                NetworkOperationCode code  = (NetworkOperationCode)Enum.Parse(typeof(NetworkOperationCode), Path.GetFileNameWithoutExtension(dir));
                string[]             files = null;

                try
                {
                    files = Directory.GetFiles(Path.Combine(testPath, dir));
                }
                catch (Exception ee)
                {
                    throw new InvalidOperationException($"Failed to load File: {Path.Combine(testPath, dir)} Exception: {ee.Message} Stack: {ee.StackTrace}");
                }

                //Now we want to load each capture.
                foreach (var cap in files)
                {
                    string filePath = Path.Combine(testPath, dir, cap);
                    //Captures should have a guid on the end of them
                    Guid guid = Guid.Parse(cap.Split('_').Last());

                    try
                    {
                        byte[] bytes = File.ReadAllBytes(filePath);

                        testSource.Add(new PacketCaptureTestEntry(code, bytes, Path.GetFileName(cap)));
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException($"Failed to open File: {filePath} Exception: {e.Message}", e);
                    }
                }
            }

            serializer.RegisterPolymorphicSerializer <AuthenticationClientPayload, AuthenticationClientPayload_Serializer>();
            serializer.RegisterPolymorphicSerializer <AuthenticationServerPayload, AuthenticationServerPayload_Serializer>();
            serializer.RegisterPolymorphicSerializer <GamePacketPayload, GamePacketPayload_Serializer>();

            return(testSource);
        }
        public void Test_Can_Serialize_Payload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadClient, PSOBBPatchPacketPayloadClient_AutoGeneratedTemplateSerializerStrategy>();
            serializer.RegisterPolymorphicSerializer <PSOBBPatchPacketPayloadServer, PSOBBPatchPacketPayloadServer_AutoGeneratedTemplateSerializerStrategy>();
            byte[] bytes = Enumerable.Repeat((byte)55, 200).ToArray();

            //act
            int offset = 0;
            UnknownPatchPacket payload = serializer.Read <PSOBBPatchPacketPayloadServer>(new Span <byte>(bytes), ref offset)
                                         as UnknownPatchPacket;

            Assert.True(payload.UnknownBytes.Length == (200 - 2));

            for (int i = 0; i < bytes.Length - 2; i++)
            {
                Assert.AreEqual(bytes[i], payload.UnknownBytes[i]);
            }
        }
예제 #7
0
        public void Test_Can_Serialize_Subcommand60Payload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <BaseSubCommand60, BaseSubCommand60_Serializer>();
            Span <byte> buffer = new Span <byte>(new byte[1000]);
            int         offset = 0;

            //act
            serializer.Write(new Sub60MovingFastPositionSetCommand(5, new Vector2 <float>(2, 5)), buffer, ref offset);

            //assert
            Assert.True(offset != 0);
        }
예제 #8
0
        public void Test_Can_Serialize_Then_Deserialize_Subcommand60Payload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <BaseSubCommand60, BaseSubCommand60_Serializer>();
            Span <byte> buffer = new Span <byte>(new byte[1000]);
            int         offset = 0;

            //act
            serializer.Write(new Sub60MovingFastPositionSetCommand(5, new Vector2 <float>(2, 5)), buffer, ref offset);
            Sub60MovingFastPositionSetCommand desserialized = serializer.Read <BaseSubCommand60>(buffer.Slice(0, offset), 0)
                                                              as Sub60MovingFastPositionSetCommand;

            //assert
            Assert.NotNull(desserialized, "Object was null.");
            Assert.NotNull(desserialized.Position);
            Assert.AreEqual(5, desserialized.Identifier);
            Assert.True(Math.Abs(desserialized.Position.X - 2) < float.Epsilon);
        }
예제 #9
0
        static void Main(string[] args)
        {
            realWorldBytes = realWorldBytes
                             .Take(1)
                             .Concat(new byte[5000])
                             .Concat(realWorldBytes.Skip(1))
                             .ToArray();

            Span <byte> buffer = new Span <byte>(new byte[10000]);
            int         offset = 0;

            SerializerService serializer = new SerializerService();

            serializer.RegisterPolymorphicSerializer <AuthPacketBaseTest, AuthPacketBaseTest_AutoGeneratedTemplateSerializerStrategy>();

            //JIT
            AuthPacketBaseTest packet = serializer.Read <AuthPacketBaseTest>(realWorldBytes, 0);

            serializer.Write(packet, buffer, ref offset);

            BenchMarkMethod(serializer);
            Console.ReadKey();
        }