public FormKey Parse(
            ReadOnlySpan <byte> span,
            IMasterReferenceReader masterReferences)
        {
            var id = BinaryPrimitives.ReadUInt32LittleEndian(span);

            return(FormKey.Factory(masterReferences, id));
        }
Beispiel #2
0
        /// <summary>
        /// Constructs a FormKey from a list of masters and the raw uint
        /// </summary>
        /// <param name="masterReferences">Master reference list to refer to</param>
        /// <param name="idWithModID">Mod index and Record ID to use</param>
        /// <returns>Converted FormID</returns>
        public static FormKey Factory(IMasterReferenceReader masterReferences, uint idWithModID)
        {
            var modID = ModIndex.GetModIndexByteFromUInt(idWithModID);

            if (modID >= masterReferences.Masters.Count)
            {
                return(new FormKey(
                           masterReferences.CurrentMod,
                           idWithModID));
            }

            var justId = idWithModID & 0xFFFFFF;

            if (modID == 0 && justId == 0)
            {
                return(FormKey.Null);
            }

            var master = masterReferences.Masters[modID];

            return(new FormKey(
                       master.Master,
                       idWithModID));
        }
Beispiel #3
0
            public static OwnerTarget GetBinaryOwner(ReadOnlySpan <byte> span, RecordTypeInfoCacheReader cache, IMasterReferenceReader masters)
            {
                FormID  form    = new FormID(BinaryPrimitives.ReadUInt32LittleEndian(span));
                FormKey formKey = FormKey.Factory(masters, form.Raw);

                if (cache.IsOfRecordType <Npc>(formKey))
                {
                    return(new NpcOwner()
                    {
                        Npc = new FormLink <INpcGetter>(FormKeyBinaryTranslation.Instance.Parse(span, masters)),
                        Global = new FormLink <IGlobalGetter>(FormKeyBinaryTranslation.Instance.Parse(span.Slice(4), masters))
                    });
                }
                else if (cache.IsOfRecordType <Faction>(formKey))
                {
                    return(new FactionOwner()
                    {
                        Faction = new FormLink <IFactionGetter>(FormKeyBinaryTranslation.Instance.Parse(span, masters)),
                        RequiredRank = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(4))
                    });
                }
                else
                {
                    return(new NoOwner()
                    {
                        RawOwnerData = BinaryPrimitives.ReadUInt32LittleEndian(span),
                        RawVariableData = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(4))
                    });
                }
            }
 public static AMastersListOrderingOption ByMasters(IMasterReferenceReader reader)
 {
     return(new MastersListOrderingByLoadOrder(reader.Masters.Select(m => m.Master)));
 }