Esempio n. 1
0
        public static async Task <MixIndexEntry[]> GetIndex(this Stream stream, Memory <byte> buffer, MixHeader head)
        {
            if (buffer.Length < 12)
            {
                throw new Exception("Buffer Too Short");
            }

            var index = new MixIndexEntry[head.Files];

            for (int i = 0; i < head.Files; i++)
            {
                await stream.ReadAsync(buffer.Slice(0, 12)).ConfigureAwait(false);

                index[i] = buffer.Slice(0, 12).ToArray().ToStruct <MixIndexEntry>();
            }
            return(index);
        }
Esempio n. 2
0
 public static void Write(this BinaryWriter @this, MixIndexEntry head)
 {
     @this.Write(head.Id);
     @this.Write(head.Offset);
     @this.Write(head.Size);
 }
Esempio n. 3
0
        public static async Task <Dictionary <uint, string>?> LoadLocalXccDatabase(this Stream stream, MixIndexEntry lxd, int body_offset)
        {
            Dictionary <uint, string> fileNameMap;

            try
            {
                StringBuilder       sb = new();
                Func <string, uint> GetId;
                byte ch;
                stream.Seek(lxd.Offset + body_offset, SeekOrigin.Begin);
                await using MemoryStream ms = new(lxd.Size);
                await stream.CopyToAsync(ms, lxd.Size).ConfigureAwait(false);

                ms.Seek(48, SeekOrigin.Begin);
                using BinaryReader msbr = new(ms, Encoding.ASCII);
                var count = msbr.ReadInt32();
                fileNameMap = new(count);
                GetId       = lxd.Id is 0x366E051F
                    ? IdUtils.GetIdASCII
                    : IdUtils.GetIdTs;
                for (int i = 0; i < count; i++)
                {
                    sb.Clear();
                    while ((ch = msbr.ReadByte()) > 0)
                    {
                        sb.Append((char)ch);
                    }
                    var name = sb.ToString();
                    fileNameMap.Add(GetId(name), name);
                }
                return(fileNameMap);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return(null);
            }
        }