Esempio 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        /// <summary>
        /// Tries to read the property and update the value accordingly.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="export"></param>
        /// <param name="handle"></param>
        /// <param name="exportGroup"></param>
        /// <param name="netBitReader"></param>
        public void ReadField(object obj, NetFieldExport export, uint handle, NetFieldExportGroup exportGroup, NetBitReader netBitReader)
        {
            if (!_netFieldGroups.TryGetValue(exportGroup.PathName, out var netGroupInfo))
            {
                return;
            }

            NetFieldInfo netFieldInfo;

            if (netGroupInfo.UsesHandles)
            {
                if (!netGroupInfo.Handles.TryGetValue(handle, out netFieldInfo))
                {
                    return;
                }
            }
            else
            {
                if (!netGroupInfo.Properties.TryGetValue(export.Name, out netFieldInfo))
                {
                    return;
                }
            }

            SetType(obj, exportGroup, netFieldInfo, netBitReader);
        }
Esempio n. 5
0
        public static void ReadField(object obj, NetFieldExport export, NetFieldExportGroup exportGroup, uint handle, NetBitReader netBitReader)
        {
            string group = exportGroup.PathName;

            string fixedExportName = FixInvalidNames(export.Name);

            if (!_netFieldGroups.ContainsKey(group))
            {
                AddUnknownField(fixedExportName, export?.Type, group, handle, netBitReader);

                return;
            }

            Type netType = _netFieldGroups[group];
            NetFieldGroupInfo netGroupInfo = _netFieldGroupInfo[netType];

            if (!netGroupInfo.Properties.ContainsKey(fixedExportName))
            {
                AddUnknownField(fixedExportName, export?.Type, group, handle, netBitReader);

                return;
            }

            NetFieldInfo netFieldInfo = netGroupInfo.Properties[fixedExportName];

            //Update if it finds a higher bit count or an actual type
            if (!String.IsNullOrEmpty(export.Type))
            {
                if (String.IsNullOrEmpty(netFieldInfo.Attribute.Info.Type))
                {
                    AddUnknownField(fixedExportName, export?.Type, group, handle, netBitReader);
                }
            }

            /*else if(netFieldInfo.Attribute.Info.BitCount < netBitReader.GetBitsLeft())
             * {
             *  if(String.IsNullOrEmpty(netFieldInfo.Attribute.Info.Type))
             *  {
             *      AddUnknownField(fixedExportName, export?.Type, group, handle, netBitReader);
             *  }
             * }*/

            SetType(obj, netType, netFieldInfo, exportGroup, netBitReader);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        private static Array ReadArrayField(object obj, NetFieldExportGroup netfieldExportGroup, NetFieldInfo fieldInfo, NetBitReader netBitReader)
        {
            uint arrayIndexes = netBitReader.ReadIntPacked();

            Type             elementType = fieldInfo.PropertyInfo.PropertyType.GetElementType();
            RepLayoutCmdType replayout   = RepLayoutCmdType.Ignore;

            NetFieldGroupInfo groupInfo = null;

            if (_netFieldGroupInfo.ContainsKey(elementType))
            {
                groupInfo = _netFieldGroupInfo[elementType];
            }
            else
            {
                if (!_primitiveTypeLayout.TryGetValue(elementType, out replayout))
                {
                    replayout = RepLayoutCmdType.Ignore;
                }
                else
                {
                    if (elementType == typeof(DebuggingObject))
                    {
                    }
                }
            }


            Array arr = Array.CreateInstance(elementType, arrayIndexes);

            while (true)
            {
                uint index = netBitReader.ReadIntPacked();

                if (index == 0)
                {
                    if (netBitReader.GetBitsLeft() == 8)
                    {
                        uint terminator = netBitReader.ReadIntPacked();

                        if (terminator != 0x00)
                        {
                            //Log error

                            return(arr);
                        }
                    }

                    return(arr);
                }

                --index;

                if (index >= arrayIndexes)
                {
                    //Log error

                    return(arr);
                }

                object data = null;

                if (groupInfo != null)
                {
                    data = Activator.CreateInstance(elementType);
                }

                while (true)
                {
                    uint handle = netBitReader.ReadIntPacked();

                    if (handle == 0)
                    {
                        break;
                    }

                    handle--;

                    if (netfieldExportGroup.NetFieldExports.Length < handle)
                    {
                        return(arr);
                    }

                    NetFieldExport export  = netfieldExportGroup.NetFieldExports[handle];
                    uint           numBits = netBitReader.ReadIntPacked();

                    if (numBits == 0)
                    {
                        continue;
                    }

                    if (export == null)
                    {
                        netBitReader.SkipBits((int)numBits);

                        continue;
                    }

                    NetBitReader cmdReader = new NetBitReader(netBitReader.ReadBits(numBits))
                    {
                        EngineNetworkVersion = netBitReader.EngineNetworkVersion,
                        NetworkVersion       = netBitReader.NetworkVersion
                    };

                    //Uses the same type for the array
                    if (groupInfo != null)
                    {
                        ReadField(data, export, netfieldExportGroup, handle, cmdReader);
                    }
                    else //Probably primitive values
                    {
                        data = ReadDataType(replayout, cmdReader, elementType);
                    }
                }

                arr.SetValue(data, index);
            }
        }