Пример #1
0
        /// <summary>
        ///     Initialize with stream data
        /// </summary>
        /// <param name="buffer"></param>
        public RDBINFO(Span <byte> buffer)
        {
            //                                                         0      1     2      3      4    5
            var csv = ManagedFSHelper.GetFileList(buffer); // Format,Index,Offset,Length,Name,Path

            foreach (var line in csv)
            {
                var  encodedName = line[4];
                uint ktid;
                if (line.Length > 6) // .bin.info
                {
                    encodedName = line[2];
                    ktid        = uint.Parse(line[1], NumberStyles.HexNumber);
                }
                else // .info
                {
                    if (encodedName.Length == 0)
                    {
                        continue;
                    }
                    ktid = RDB.Hash(line[4]);
                }
                Entries.Add((ktid, line));

                var(name, _)  = RDB.StripName(encodedName);
                NameMap[ktid] = name;
                HashMap[ktid] = encodedName;
            }
        }
Пример #2
0
        /// <summary>
        ///     Initialize with stream data
        /// </summary>
        /// <param name="buffer"></param>
        public NDB(Span <byte> buffer)
        {
            Header  = MemoryMarshal.Read <NDBHeader>(buffer);
            Entries = new List <(KTIDReference reference, string[] strings)>(Header.Count);
            NameMap = new Dictionary <KTIDReference, string>(Header.Count);
            HashMap = new Dictionary <KTIDReference, string>(Header.Count);
            ExtMap  = new Dictionary <KTIDReference, string>(Header.Count);

            var offset    = Header.SectionHeader.Size;
            var entrySize = SizeHelper.SizeOf <NDBEntry>();

            for (var i = 0; i < Header.Count; ++i)
            {
                var entry   = MemoryMarshal.Read <NDBEntry>(buffer.Slice(offset));
                var strings = new string[entry.Count];
                Logger.Assert(entry.Count >= 2, "entry.Count >= 2");
                if (entry.Count > 0)
                {
                    var pointers = MemoryMarshal.Cast <byte, int>(buffer.Slice(offset + entrySize, entry.Count * 4));
                    for (var index = 0; index < pointers.Length; index++)
                    {
                        var pointer = pointers[index];
                        strings[index] = buffer.Slice(offset + pointer).ReadString() ?? string.Empty;
                    }
                }

                offset += entry.SectionHeader.Size;
                offset  = offset.Align(4);

                Entries.Add((entry.KTID, strings));

                var(name, ext)      = RDB.StripName(strings[0]);
                NameMap[entry.KTID] = name;
                HashMap[entry.KTID] = strings[0];

                if (strings[1].Length > 0)
                {
                    var hash = RDB.Hash(strings[1]);
                    if (ext != null)
                    {
                        ExtMap[hash] = ext.ToLower();
                    }
                }

                foreach (var str in strings.Where(x => x.Length > 0))
                {
                    HashMap[RDB.Hash(str)] = str;
                }
            }
        }