Ejemplo n.º 1
0
        public void ReadVectorFieldTest()
        {
            var reader = new NetBitReader(new byte[] { 0x01, 0x0B, 0xC7, 0x47, 0x8A, 0x26, 0xA7, 0xC7, 0x00, 0x80, 0x71, 0xC5 }, 96)
            {
                NetworkVersion       = NetworkVersionHistory.HISTORY_CHARACTER_MOVEMENT_NOINTERP,
                EngineNetworkVersion = EngineNetworkVersionHistory.HISTORY_CLASSNETCACHE_FULLNAME
            };

            var export = new NetFieldExport()
            {
                Handle = 0,
                Name   = "VectorField"
            };

            var group = new NetFieldExportGroup()
            {
                PathName = "group1",
                NetFieldExportsLength = 1,
                NetFieldExports       = new NetFieldExport[] { export },
                PathNameIndex         = 1
            };

            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            var data = parser.CreateType(group.PathName);

            parser.ReadField(data, export, export.Handle, group, reader);
            Assert.True(reader.AtEnd());
            Assert.False(reader.IsError);
            Assert.Equal(-3864, ((NetFieldGroup1)data).VectorField.Z);
        }
Ejemplo n.º 2
0
        public void ReadBooleanFieldTest()
        {
            var reader = new NetBitReader(new byte[] { 0x01 }, 1);
            var export = new NetFieldExport()
            {
                Handle = 0,
                Name   = "bField"
            };
            var group = new NetFieldExportGroup()
            {
                PathName = "group1",
                NetFieldExportsLength = 1,
                NetFieldExports       = new NetFieldExport[] { export },
                PathNameIndex         = 1
            };

            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            var data = parser.CreateType(group.PathName);

            parser.ReadField(data, export, export.Handle, group, reader);
            Assert.True(reader.AtEnd());
            Assert.False(reader.IsError);
            Assert.True(((NetFieldGroup1)data).bField);
        }
Ejemplo n.º 3
0
        public void ReadGuidFieldTest()
        {
            var reader = new NetBitReader(new byte[] { 0x87, 0x04 });
            var export = new NetFieldExport()
            {
                Handle = 0,
                Name   = "ItemDefinitionField"
            };

            var group = new NetFieldExportGroup()
            {
                PathName = "group1",
                NetFieldExportsLength = 1,
                NetFieldExports       = new NetFieldExport[] { export },
                PathNameIndex         = 1
            };

            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            var data = parser.CreateType(group.PathName);

            parser.ReadField(data, export, export.Handle, group, reader);
            Assert.True(reader.AtEnd());
            Assert.False(reader.IsError);
            Assert.True(((NetFieldGroup1)data).ItemDefinitionField.IsValid());
            Assert.Equal(323u, ((NetFieldGroup1)data).ItemDefinitionField.Value);
        }
 public void Resolve(NetGuidCache cache)
 {
     if (cache.TryGetPathName(Id, out var name))
     {
         Name = name;
     }
 }
Ejemplo n.º 5
0
        public void WillReadTypesOnFullTest()
        {
            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            Assert.True(parser.WillReadType("group1"));
            Assert.True(parser.WillReadType("group2"));
            Assert.False(parser.WillReadType("ignore"));
        }
Ejemplo n.º 6
0
        public void WillReadClassNetCacheOnFullTest()
        {
            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            Assert.True(parser.WillReadClassNetCache("classnetcache1"));
            Assert.True(parser.WillReadClassNetCache("classnetcache2"));
            Assert.False(parser.WillReadClassNetCache("classnetcacheignore"));
        }
        public BenchmarkNetGuidCache()
        {
            netGuidCache = new NetGuidCache();

            for (var i = 0; i < iterations; i++)
            {
                netGuidCache.AddToExportGroupMap(i.ToString(), new NetFieldExportGroup()
                {
                    PathNameIndex = (uint)i, PathName = i.ToString()
                });
            }
        }
Ejemplo n.º 8
0
        public void TryGetClassNetCachePropertyDoesNotThrowTest()
        {
            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            var result = parser.TryGetClassNetCacheProperty("doesnotexist", "classnetcache1", out var info);

            Assert.False(result);

            result = parser.TryGetClassNetCacheProperty("doesnotexist", "classnetcache3", out info);
            Assert.False(result);
        }
Ejemplo n.º 9
0
        public void TryGetClassNetCachePropertyTest()
        {
            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            var result = parser.TryGetClassNetCacheProperty("DefaultRPCProperty", "classnetcache1", out var info);

            Assert.True(result);
            Assert.Equal("DefaultRPCProperty", info.Name);
            Assert.Equal("path-DefaultRPCProperty", info.PathName);
            Assert.True(info.EnablePropertyChecksum);
            Assert.False(info.IsCustomStruct);
            Assert.False(info.IsFunction);

            result = parser.TryGetClassNetCacheProperty("RPCPropertyWithChecksum", "classnetcache1", out info);
            Assert.True(result);
            Assert.Equal("RPCPropertyWithChecksum", info.Name);
            Assert.Equal("path-RPCPropertyWithChecksum", info.PathName);
            Assert.False(info.EnablePropertyChecksum);
            Assert.False(info.IsCustomStruct);
            Assert.False(info.IsFunction);

            result = parser.TryGetClassNetCacheProperty("FunctionRPCProperty", "classnetcache1", out info);
            Assert.True(result);
            Assert.Equal("FunctionRPCProperty", info.Name);
            Assert.Equal("path-FunctionRPCProperty", info.PathName);
            Assert.True(info.EnablePropertyChecksum);
            Assert.False(info.IsCustomStruct);
            Assert.True(info.IsFunction);

            result = parser.TryGetClassNetCacheProperty("CustomRPCProperty", "classnetcache1", out info);
            Assert.True(result);
            Assert.Equal("CustomRPCProperty", info.Name);
            Assert.Equal("path-CustomRPCProperty", info.PathName);
            Assert.True(info.EnablePropertyChecksum);
            Assert.True(info.IsCustomStruct);
            Assert.False(info.IsFunction);
            Assert.True(typeof(int) == info.PropertyInfo.PropertyType);
        }
Ejemplo n.º 10
0
        public void ReadArrayFieldTest()
        {
            var reader = new NetBitReader(new byte[] {
                0x0C, 0x02, 0x6F, 0x02, 0x20, 0xD7, 0x08, 0x00, 0x04, 0x6F, 0x02, 0x20, 0xDF, 0x08, 0x00,
                0x06, 0x6F, 0x02, 0x20, 0xE7, 0x08, 0x00, 0x08, 0x6F, 0x02, 0x20, 0xEF, 0x08, 0x00, 0x0A,
                0x6F, 0x02, 0x20, 0x8F, 0x06, 0x00, 0x0C, 0x6F, 0x02, 0x20, 0xF7, 0x08, 0x00, 0x00
            }, 352)
            {
                NetworkVersion       = NetworkVersionHistory.HISTORY_CHARACTER_MOVEMENT_NOINTERP,
                EngineNetworkVersion = EngineNetworkVersionHistory.HISTORY_CLASSNETCACHE_FULLNAME
            };

            var export = new NetFieldExport()
            {
                Handle = 0,
                Name   = "ArrayField"
            };

            var group = new NetFieldExportGroup()
            {
                PathName = "group1",
                NetFieldExportsLength = 183,
                NetFieldExports       = new NetFieldExport[183],
                PathNameIndex         = 1
            };

            group.NetFieldExports[182] = export;

            var guidCache = new NetGuidCache();
            var parser    = new NetFieldParser(guidCache, ParseMode.Full, "Unreal.Core.Test");

            var data = parser.CreateType(group.PathName);

            parser.ReadField(data, export, export.Handle, group, reader);
            Assert.True(reader.AtEnd());
            Assert.False(reader.IsError);
            Assert.Equal(6, ((NetFieldGroup1)data).ArrayField.Length);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create a NetFieldParser, which will load all <see cref="NetFieldExportGroup"/> in the <see cref="AppDomain.CurrentDomain"/>.
        /// </summary>
        /// <param name="cache">Instance of NetGuidCache, used to resolve netguids to their string value.</param>
        /// <param name="mode"></param>
        /// <param name="assemblyNameFilter">Found assemblies should contain this string.</param>
        public NetFieldParser(NetGuidCache cache, ParseMode mode, string assemblyNameFilter = "ReplayReader")
        {
            GuidCache = cache;

            var types     = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.Contains(assemblyNameFilter) || a.FullName.Contains("Unreal.Core")).SelectMany(i => i.GetTypes());
            var netFields = types.Where(c => c.GetCustomAttribute <NetFieldExportGroupAttribute>() != null);

            foreach (var type in netFields)
            {
                var attribute = type.GetCustomAttribute <NetFieldExportGroupAttribute>();
                if (attribute.MinimalParseMode <= mode)
                {
                    var info = new NetFieldGroupInfo
                    {
                        Type = type
                    };

                    _netFieldGroups[attribute.Path] = info;
                    AddNetFieldInfo(type, info);
                }
            }

            // Allows deserializing type arrays
            var netSubFields = types.Where(c => c.GetCustomAttribute <NetFieldExportSubGroupAttribute>() != null);

            foreach (var type in netSubFields)
            {
                var attribute = type.GetCustomAttribute <NetFieldExportSubGroupAttribute>();
                if (attribute.MinimalParseMode <= mode)
                {
                    var info = _netFieldGroups[attribute.Path];
                    AddNetFieldInfo(type, info);
                }
            }

            // ClassNetCaches
            var classNetCaches = types.Where(c => c.GetCustomAttribute <NetFieldExportClassNetCacheAttribute>() != null);

            foreach (var type in classNetCaches)
            {
                var attribute = type.GetCustomAttribute <NetFieldExportClassNetCacheAttribute>();
                if (attribute.MinimalParseMode <= mode)
                {
                    var info = new ClassNetCacheInfo();
                    AddClassNetInfo(type, info);
                    _classNetCacheToNetFieldGroup[attribute.Path] = info;
                }
            }

            // PlayerControllers
            var controllers = types.Where(c => c.GetCustomAttribute <PlayerControllerAttribute>() != null);

            foreach (var type in controllers)
            {
                var attribute = type.GetCustomAttribute <PlayerControllerAttribute>();
                PlayerControllerGroups.Add(attribute.Path);
            }

            //Type layout for dynamic arrays
            _primitiveTypeLayout.Add(typeof(bool), RepLayoutCmdType.PropertyBool);
            _primitiveTypeLayout.Add(typeof(byte), RepLayoutCmdType.PropertyByte);
            _primitiveTypeLayout.Add(typeof(ushort), RepLayoutCmdType.PropertyUInt16);
            _primitiveTypeLayout.Add(typeof(int), RepLayoutCmdType.PropertyInt);
            _primitiveTypeLayout.Add(typeof(uint), RepLayoutCmdType.PropertyUInt32);
            _primitiveTypeLayout.Add(typeof(ulong), RepLayoutCmdType.PropertyUInt64);
            _primitiveTypeLayout.Add(typeof(float), RepLayoutCmdType.PropertyFloat);
            _primitiveTypeLayout.Add(typeof(string), RepLayoutCmdType.PropertyString);

            // Allows deserializing type arrays
            var iPropertyTypes = types.Where(x => typeof(IProperty).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);

            foreach (var iPropertyType in iPropertyTypes)
            {
                _primitiveTypeLayout.Add(iPropertyType, RepLayoutCmdType.Property);
            }

            _primitiveTypeLayout.Add(typeof(object), RepLayoutCmdType.Ignore);
        }
 public MockReplayReader(ILogger logger = null, ParseMode parseMode = ParseMode.Minimal) : base(logger, parseMode)
 {
     Replay        = new MockReplay();
     _netGuidCache = new NetGuidCache();
 }
 public MockReplayReader() : base()
 {
     _netGuidCache = new NetGuidCache();
 }