public void LoadFromCpk(int index, VirtualCpk cpk)
        {
            var headerSize = sizeof(DwPackHeader) + (cpk.Entries.Count * sizeof(DwPackEntry));

            Native = new DwPackPtr((byte *)Marshal.AllocHGlobal(headerSize));
            Native.Header->Signature = DwPackHeader.SIGNATURE;
            Native.Header->Field08   = 0;
            Native.Header->FileCount = cpk.Entries.Count;
            Native.Header->Index     = index;

            for (int i = 0; i < cpk.Entries.Count; i++)
            {
                var entry = Native.Entries + i;
                entry->Field00   = 0;
                entry->Index     = (short)i;
                entry->PackIndex = (short)Native.Header->Index;
                entry->Path      = cpk.Entries[i].Path;
                entry->Field104  = 0;
                entry->Flags     = 0;

                // These will be filled in later
                entry->CompressedSize = entry->UncompressedSize = 1;
                entry->DataOffset     = 0;
            }

            LoadEntries();
        }
        public void AddNewFiles(VirtualCpk cpk)
        {
            var newFileCount = cpk.Entries.Where(x => x.PacIndex == Native.Header->Index)
                               .Max(x => x.FileIndex + 1);

            if (newFileCount > Entries.Count)
            {
                var oldHeaderSize = sizeof(DwPackHeader) + (Entries.Count * sizeof(DwPackEntry));
                var newHeaderSize = sizeof(DwPackHeader) + (newFileCount * sizeof(DwPackEntry));
                var oldNative     = Native;

                Native = new DwPackPtr((byte *)Marshal.AllocHGlobal(newHeaderSize));
                Unsafe.CopyBlock((void *)Native.Ptr, (void *)oldNative.Ptr, (uint)oldHeaderSize);
                Native.Header->FileCount = newFileCount;
                oldNative.Dispose();

                var dataOffset = Entries.Max(x => x.Native->DataOffset + x.Native->CompressedSize);
                for (int i = oldNative.Header->FileCount; i < Native.Header->FileCount; i++)
                {
                    var entry    = Native.Entries + i;
                    var cpkEntry = cpk.Entries.First(x => x.PacIndex == Native.Header->Index && x.FileIndex == i);

                    entry->Field00   = 0;
                    entry->Index     = (short)i;
                    entry->PackIndex = (short)Native.Header->Index;
                    entry->Path      = cpkEntry.Path;
                    entry->Field104  = 0;
                    entry->Flags     = 0;

                    // These will be filled in later
                    entry->CompressedSize = entry->UncompressedSize = 1;
                    entry->DataOffset     = dataOffset;
                    dataOffset           += entry->CompressedSize;
                }

                mMapper = new MemoryMapper();
                Entries.Clear();
                LoadEntries();
            }
        }
 private void OnCpkLoaded(object sender, VirtualCpk e)
 {
     mLoadedCpks.Add(e);
 }