Deserialize() public static method

public static Deserialize ( IClassNetCache classMap, string typeName, string objectIndexToName, UInt32 versionMajor, UInt32 versionMinor, BitReader br ) : ActorStateProperty
classMap IClassNetCache
typeName string
objectIndexToName string
versionMajor System.UInt32
versionMinor System.UInt32
br BitReader
return ActorStateProperty
Example #1
0
        public static ActorState Deserialize(int maxChannels, List <ActorState> existingActorStates, List <ActorState> frameActorStates, string[] objectIndexToName, IDictionary <string, ClassNetCache> classNetCacheByName, UInt32 engineVersion, UInt32 licenseeVersion, UInt32 netVersion, BitReader br)
        {
            var        startPosition = br.Position;
            ActorState a             = new ActorState();

            try
            {
                var actorId = br.ReadUInt32Max(maxChannels);

                a.Id = actorId;

                if (br.ReadBit())
                {
                    if (br.ReadBit())
                    {
                        a.State = ActorStateState.New;

                        if (engineVersion > 868 || (engineVersion == 868 && licenseeVersion >= 14))
                        {
                            a.NameId = br.ReadUInt32();
                        }

                        a.Unknown1 = br.ReadBit();
                        a.TypeId   = br.ReadUInt32();

                        a.TypeName       = objectIndexToName[(int)a.TypeId.Value];
                        a._classNetCache = ObjectNameToClassNetCache(a.TypeName, classNetCacheByName);
                        a.ClassName      = objectIndexToName[a._classNetCache.ObjectIndex];

                        if (!ClassHasInitialPosition(a.ClassName))
                        {
#if DEBUG
                            a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
                            a.Complete  = true;
#endif
                            return(a);
                        }

                        a.Position = Vector3D.Deserialize(br);

                        if (ClassHasRotation(a.ClassName))
                        {
                            a.Rotation = Rotator.Deserialize(br);
                        }
#if DEBUG
                        a.Complete = true;
#endif
                    }
                    else
                    {
                        a.State = ActorStateState.Existing;
                        var oldState = existingActorStates.Where(x => x.Id == a.Id).Single();

                        a.TypeId = oldState.TypeId;

                        a.Properties = new List <ActorStateProperty>();
                        ActorStateProperty lastProp = null;
                        while (br.ReadBit())
                        {
                            lastProp = ActorStateProperty.Deserialize(oldState._classNetCache, oldState.TypeName, objectIndexToName, engineVersion, licenseeVersion, netVersion, br);
                            a.Properties.Add(lastProp);

#if DEBUG
                            if (!lastProp.IsComplete)
                            {
                                break;
                            }
#endif
                        }

#if DEBUG
                        a.Complete = lastProp.IsComplete;
                        if (lastProp.Data.Count > 0 && lastProp.Data.Last().ToString() == "FAILED")
                        {
                            a.Failed = true;
                        }
#endif
                        var endPosition = br.Position;
                    }
                }
                else
                {
                    a.State = ActorStateState.Deleted;

                    var actor = existingActorStates.Where(x => x.Id == a.Id).SingleOrDefault();
#if DEBUG
                    a.Complete = true;
#endif
                    var endPosition = br.Position;
                }
#if DEBUG
                if (!a.Complete)
                {
                    // Read a bunch of data so we have something to look at in the logs
                    // Otherwise the logs may not show any data bits for whatever is broken, which is hard to interpret
                    br.ReadBytes(16);
                }

                a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
#endif
                return(a);
            }
            catch (Exception e)
            {
#if DEBUG
                a.KnownBits   = br.GetBits(startPosition, br.Position - startPosition);
                a.UnknownBits = br.GetBits(br.Position, 100);
                Console.WriteLine(e.ToString());
                a.Failed   = true;
                a.Complete = false;
                return(a);
#else
                throw;
#endif
            }
        }
Example #2
0
        public static ActorState Deserialize(int maxChannels, IDictionary <UInt32, ActorState> existingActorStates, List <ActorState> frameActorStates, string[] objectIndexToName, IDictionary <string, ClassNetCache> classNetCacheByName, UInt32 engineVersion, UInt32 licenseeVersion, UInt32 netVersion, BitReader br)
        {
            var        startPosition = br.Position;
            ActorState a             = new ActorState();

            try
            {
                var actorId = br.ReadUInt32Max(maxChannels);

                a.Id = actorId;

                if (br.ReadBit())
                {
                    if (br.ReadBit())
                    {
                        a.State = ActorStateState.New;

                        if (engineVersion > 868 || (engineVersion == 868 && licenseeVersion >= 14))
                        {
                            a.NameId = br.ReadUInt32();
                        }

                        a.Unknown1 = br.ReadBit();
                        a.TypeId   = br.ReadUInt32();

                        var typeName = objectIndexToName[(int)a.TypeId.Value];
                        a._classNetCache = ObjectNameToClassNetCache(typeName, classNetCacheByName);
                        a.ClassId        = a._classNetCache.ObjectIndex;

                        if (!ClassHasInitialPosition(objectIndexToName[a.ClassId.Value]))
                        {
#if DEBUG
                            a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
                            a.Complete  = true;
#endif
                            return(a);
                        }

                        a.Position = Vector3D.Deserialize(br, netVersion);

                        if (ClassHasRotation(objectIndexToName[a.ClassId.Value]))
                        {
                            a.Rotation = Rotator.Deserialize(br);
                        }
#if DEBUG
                        a.Complete = true;
#endif
                    }
                    else
                    {
                        a.State = ActorStateState.Existing;
                        var oldState = existingActorStates[a.Id];

                        ActorStateProperty lastProp = null;
                        while (br.ReadBit())
                        {
                            lastProp = ActorStateProperty.Deserialize(oldState._classNetCache, objectIndexToName, engineVersion, licenseeVersion, netVersion, br);

                            ActorStateProperty existingProperty = null;
                            if (!a.Properties.TryGetValue(lastProp.PropertyId, out existingProperty))
                            {
                                a.Properties.Add(lastProp.PropertyId, lastProp);
                            }
                            else
                            {
                                // Combine this property's data into the existing property's data.
                                // TODO: If/When concrete property types are created, we should convert to an array type

                                // The "pretty" json serializer methods try hard to avoid serializing extra data.
                                // But, it gets confused by these cases where we have multiple properties with the same name on a single ActorState.
                                // The serializer could consider them all as a single array of values,
                                // but I think it makes more sense to treat them as an array in the parser.
                                // It probably more closely reflects the object in Rocket League that way.

                                // This implementation is a bit of a hack though. But the whole property class is a little hacky...

                                var listProperty = existingProperty as ActorStateListProperty;
                                if (listProperty == null)
                                {
                                    listProperty = new ActorStateListProperty(existingProperty);
                                    a.Properties[listProperty.PropertyId] = listProperty;
                                }

                                listProperty.Add(lastProp);
                            }
                        }

#if DEBUG
                        a.Complete = true;
#endif
                    }
                }
                else
                {
                    a.State = ActorStateState.Deleted;
#if DEBUG
                    a.Complete = true;
#endif
                    var endPosition = br.Position;
                }
#if DEBUG
                if (!a.Complete)
                {
                    // Read a bunch of data so we have something to look at in the logs
                    // Otherwise the logs may not show any data bits for whatever is broken, which is hard to interpret
                    br.ReadBytes(16);
                }

                a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
#endif
                return(a);
            }
            catch (Exception e)
            {
#if DEBUG
                a.KnownBits   = br.GetBits(startPosition, br.Position - startPosition);
                a.UnknownBits = br.GetBits(br.Position, 100);
                Console.WriteLine(e.ToString());
                a.Failed   = true;
                a.Complete = false;
                return(a);
#else
                throw;
#endif
            }
        }
Example #3
0
        public static ActorState Deserialize(int maxChannels, List <ActorState> existingActorStates, List <ActorState> frameActorStates, string[] objectIndexToName, IEnumerable <ClassNetCache> classNetCache, BitReader br)
        {
            var        startPosition = br.Position;
            ActorState a             = new ActorState();

            try
            {
                var actorId = br.ReadInt32Max(maxChannels);

                a.Id = actorId;

                if (br.ReadBit())
                {
                    if (br.ReadBit())
                    {
                        a.State    = ActorStateState.New;
                        a.Unknown1 = br.ReadBit();

                        a.TypeId = br.ReadInt32();

                        a.TypeName = objectIndexToName[(int)a.TypeId.Value];
                        var classMap = ObjectNameToClassNetCache(a.TypeName, objectIndexToName, classNetCache);
                        a.ClassName = objectIndexToName[classMap.ObjectIndex];

                        if (a.ClassName == "TAGame.CrowdActor_TA" ||
                            a.ClassName == "TAGame.CrowdManager_TA" ||
                            a.ClassName == "TAGame.VehiclePickup_Boost_TA" ||
                            a.ClassName == "Core.Object")
                        {
#if DEBUG
                            a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
                            a.Complete  = true;
#endif
                            return(a);
                        }

                        a.Position = Vector3D.Deserialize(br);

                        if (a.ClassName == "Engine.GameReplicationInfo" ||
                            a.ClassName == "TAGame.GameEvent_SoccarSplitscreen_TA" ||
                            a.ClassName == "TAGame.CarComponent_Boost_TA" ||
                            a.ClassName == "TAGame.CarComponent_Jump_TA" ||
                            a.ClassName == "TAGame.CarComponent_DoubleJump_TA" ||
                            a.ClassName == "TAGame.CarComponent_Dodge_TA" ||
                            a.ClassName == "TAGame.CarComponent_FlipCar_TA" ||
                            a.ClassName == "TAGame.Team_TA" ||                             // Team1 = Orange, Team0 = Blue (probably different for season mode)
                            a.ClassName == "TAGame.PRI_TA" ||
                            a.ClassName == "TAGame.GameEvent_Soccar_TA" ||
                            a.ClassName == "TAGame.GRI_TA" ||
                            a.ClassName == "TAGame.GameEvent_SoccarPrivate_TA" ||
                            a.ClassName == "TAGame.GameEvent_Season_TA")
                        {
#if DEBUG
                            a.Complete = true;
#endif
                        }
                        else if (a.ClassName == "TAGame.Ball_TA" ||
                                 a.ClassName == "TAGame.Car_TA" ||
                                 a.ClassName == "TAGame.Car_Season_TA")
                        {
                            if (br.ReadBit())
                            {
                                br.ReadByte();
                            }
                            if (br.ReadBit())
                            {
                                br.ReadByte();
                            }
                            if (br.ReadBit())
                            {
                                br.ReadByte();
                            }
#if DEBUG
                            a.Complete = true;
#endif
                        }
                    }
                    else
                    {
                        a.State    = ActorStateState.Existing;
                        a.TypeId   = existingActorStates.Where(x => x.Id == a.Id).Single().TypeId;
                        a.TypeName = objectIndexToName[(int)a.TypeId.Value];
                        var classMap = ObjectNameToClassNetCache(a.TypeName, objectIndexToName, classNetCache);
                        a.ClassName = objectIndexToName[classMap.ObjectIndex];

                        a.Properties = new List <ActorStateProperty>();
                        ActorStateProperty lastProp = null;
                        while (br.ReadBit())
                        {
                            lastProp = ActorStateProperty.Deserialize(classMap, objectIndexToName, br);
                            a.Properties.Add(lastProp);

#if DEBUG
                            if (!lastProp.IsComplete)
                            {
                                break;
                            }
#endif
                        }

#if DEBUG
                        a.Complete = lastProp.IsComplete;
                        if (lastProp.Data.Count > 0 && lastProp.Data.Last().ToString() == "FAILED")
                        {
                            a.Failed = true;
                        }
#endif
                        var endPosition = br.Position;
                    }
                }
                else
                {
                    a.State = ActorStateState.Deleted;

                    var actor = existingActorStates.Where(x => x.Id == a.Id).SingleOrDefault();
                    if (actor != null)                     // TODO remove this someday. Only here because we might be deleting objects we havent figured out how to parse yet
                    {
                        a.TypeId   = actor.TypeId;
                        a.TypeName = objectIndexToName[(int)a.TypeId.Value];
                        var classMap = ObjectNameToClassNetCache(a.TypeName, objectIndexToName, classNetCache);
                        a.ClassName = objectIndexToName[classMap.ObjectIndex];
                    }
#if DEBUG
                    a.Complete = true;
#endif
                    var endPosition = br.Position;
                }
#if DEBUG
                if (!a.Complete)
                {
                    // Read a bunch of data so we have something to look at in the logs
                    // Otherwise the logs may not show any data bits for whatever is broken, which is hard to interpret
                    br.ReadBytes(16);
                }

                a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
#endif
                return(a);
            }
            catch (Exception e)
            {
#if DEBUG
                a.KnownBits   = br.GetBits(startPosition, br.Position - startPosition);
                a.UnknownBits = br.GetBits(br.Position, 100);
                Console.WriteLine(e.ToString());
                a.Failed   = true;
                a.Complete = false;
                return(a);
#else
                throw;
#endif
            }
        }