Ejemplo n.º 1
0
        public static EventsSave Restore(TypeDesc typeDesc, SaveInfo info, ref ByteStreamReader bsr)
        {
            int count = bsr.ReadSInt();

            // inline version of reading embedded field of type CBaseEntityOutput (it only contains 1 field)

            if (bsr.ReadSShort() != 4)
            {
                throw new ConstraintException("first entry in data map should be 4");
            }
            string?mapSym = bsr.ReadSymbol(info);

            if (mapSym != "Value")
            {
                throw new ConstraintException($"bad symbol, expected \"Value\" but read \"{mapSym}\"");
            }
            int             fieldsSaved = bsr.ReadSInt();
            ParsedSaveField?psf         = null;

            if (fieldsSaved == 1)
            {
                bsr.StartBlock(info, out string?sym);
                if (sym != "m_Value")
                {
                    throw new ConstraintException($"bad symbol, expected \"m_Value\" but read \"{sym}\"");
                }
                FieldType type = (FieldType)bsr.ReadSInt();
                string?   s    = FieldNameFromType(type);
                if (s != null)
                {
                    TypeDesc t  = new TypeDesc(s, type);
                    DataMap  m  = new DataMap("m_Value", new [] { t });
                    var      pm = bsr.ReadDataMap(m, info);
                    if (pm.ParsedFields.Any())
                    {
                        psf = pm.ParsedFields.Single().Value;
                    }
                }
                bsr.EndBlock(info);
            }
            else if (fieldsSaved != 0)
            {
                throw new ConstraintException($"expected 0 fields, got {fieldsSaved}");
            }

            ParsedDataMap[] events = new ParsedDataMap[count];
            for (int i = 0; i < count; i++)
            {
                events[i] = bsr.ReadDataMap("EntityOutput", info);
            }

            return(new EventsSave(typeDesc, psf, events));
        }