private static readonly HashSet<string> Searched = new HashSet<string>(); // for debugging
		
		
		protected override void Parse(ref ByteStreamReader bsr) {
			EntData = new ParsedEntData[DataHeader.EntHeaders.Length];
			for (int i = 0; i < DataHeader.EntHeaders.Length; i++) {
				ParsedDataMap entHeader = DataHeader.EntHeaders[i];
				var edictIndex = entHeader.GetFieldOrDefault<int>("edictindex");
				bsr.CurrentByteIndex = entHeader.GetFieldOrDefault<int>("location");
				string? className = entHeader.GetFieldOrDefault<string>("classname");
				if (className == null) // todo
					continue;
				if (!SaveInfo.SDataMapLookup.TryGetValue(className, out DataMap? entMap)) {
					string s = $"{nameof(EntitySaveStateBlock)}.{nameof(Parse)} - datamap for \"{className}\" not found";
					if (bsr.ReadSShort() == 4 && Searched.Add(s)) {
						bsr.DetermineDataMapHierarchy(SaveInfo,
							$"{nameof(EntitySaveStateBlock)}.{nameof(Parse)} - datamap for \"{className}\" not found",
							bsr.AbsoluteByteIndex - 2);
					}
					SaveInfo.AddError(s
#if DEBUG
						,false
#endif
						);
					continue;
				}
				EntData[i] = EntDataFactory.CreateFromName(SaveRef!, entHeader, entMap);
				SaveInfo.ParseContext.CurrentEntity = EntData[i];
				EntData[i]!.ParseStream(ref bsr);
			}
		}
Exemplo n.º 2
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));
        }
 protected override void Parse(ref ByteStreamReader bsr)
 {
     Version = bsr.ReadSShort();
 }