Example #1
0
        public static NPK3Entry[] CreateInitialEntries(string[] Files, Stream[] Streams)
        {
            Console.WriteLine("Loading Files...");

            List <NPK3Entry> Entries = new List <NPK3Entry>();

            for (int i = 0; i < Files.Length; i++)
            {
                NPK3Entry Entry = new NPK3Entry();
                Entry.FilePath = Files[i].Replace("\\", "/");
                Entry.FileSize = (uint)Streams[i].Length;
                Entry.SHA256   = Streams[i].SHA256Checksum();

                long Reaming = Entry.FileSize;
                if (EnableSegmentation || Reaming > uint.MaxValue)
                {
                    if (!EnableSegmentation)
                    {
                        var OriColor = Console.ForegroundColor;
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine($"Big File Detected: '{Entry.FilePath}', Enforcing Segmentation");
                        Console.ForegroundColor = OriColor;
                    }

                    Entry.SegmentsInfo     = new NPKSegmentInfo[1 + (Entry.FileSize / MaxSectionSize)];
                    Entry.SegmentationMode = (byte)(Entry.SegmentsInfo.Length > 1 ? 0 : 1);
                    for (int x = 0; x < Entry.SegmentsInfo.Length; x++)
                    {
                        uint MaxBytes = Reaming < MaxSectionSize ? (uint)Reaming : MaxSectionSize;
                        Entry.SegmentsInfo[x] = new NPKSegmentInfo()
                        {
                            Offset           = 0,
                            DecompressedSize = MaxBytes,
                            RealSize         = MaxBytes,
                            AlignedSize      = MaxBytes + (0x10 - (MaxBytes % 0x10))
                        };

                        Reaming -= MaxBytes;
                    }
                }
                else
                {
                    Entry.SegmentationMode = 1;
                    Entry.SegmentsInfo     = new NPKSegmentInfo[] {
                        new NPKSegmentInfo()
                        {
                            Offset           = 0,
                            DecompressedSize = (uint)Reaming,
                            RealSize         = (uint)Reaming,
                            AlignedSize      = (uint)Reaming + (0x10 - ((uint)Reaming % 0x10))
                        }
                    };
                }

                Entries.Add(Entry);
            }

            return(Entries.ToArray());
        }
Example #2
0
        public static NPK3Entry[] GetEntries(Stream EntryTable)
        {
            List <NPK3Entry> Entries = new List <NPK3Entry>();
            StructReader     Reader  = new StructReader(EntryTable, Encoding: Encoding);

            while (Reader.BaseStream.Position + 1 < Reader.BaseStream.Length)
            {
                var Entry = new NPK3Entry();
                Reader.ReadStruct(ref Entry);
                Entries.Add(Entry);
            }
            return(Entries.ToArray());
        }
Example #3
0
        public static NPK3Entry[] CreateInitialEntries(string[] Files, Stream[] Streams)
        {
            Console.WriteLine("Loading Files...");

            List <NPK3Entry> Entries = new List <NPK3Entry>();

            for (int i = 0; i < Files.Length; i++)
            {
                NPK3Entry Entry = new NPK3Entry();
                Entry.FilePath = Files[i].Replace("\\", "/");
                Entry.FileSize = (uint)Streams[i].Length;
                Entry.SHA256   = Streams[i].SHA256Checksum();

                long Reaming = Entry.FileSize;
                if (EnableSegmentation)
                {
                    Entry.SegmentsInfo = new NPKSegmentInfo[1 + (Entry.FileSize / MaxSectionSize)];
                    for (int x = 0; x < Entry.SegmentsInfo.Length; x++)
                    {
                        uint MaxBytes = Reaming < MaxSectionSize ? (uint)Reaming : MaxSectionSize;
                        Entry.SegmentsInfo[x] = new NPKSegmentInfo()
                        {
                            Offset           = 0,
                            DecompressedSize = MaxBytes,
                            RealSize         = MaxBytes,
                            AlignedSize      = MaxBytes + (0x10 - (MaxBytes % 0x10))
                        };

                        Reaming -= MaxBytes;
                    }
                }
                else
                {
                    Entry.SegmentationMode = 1;
                    Entry.SegmentsInfo     = new NPKSegmentInfo[] {
                        new NPKSegmentInfo()
                        {
                            Offset           = 0,
                            DecompressedSize = (uint)Reaming,
                            RealSize         = (uint)Reaming,
                            AlignedSize      = (uint)Reaming + (0x10 - ((uint)Reaming % 0x10))
                        }
                    };
                }

                Entries.Add(Entry);
            }

            return(Entries.ToArray());
        }