Exemple #1
0
        public static int Compress(ReadOnlySpan <byte> read, Span <byte> w, CompressTask task, int cur = 0)
        {
            DmadataRecord dmadataRec = GetDmadataRec(read, task.Dmadata);
            var           dmadata    = GetDmadataRecords(read, task.Dmadata);

            for (int i = 0; i < dmadata.Count; i++)
            {
                if (i % 50 == 0)
                {
                    Console.WriteLine($"File {i}");
                }
                var         dmarec = dmadata[i];
                FileAddress vrom   = dmarec.VRom;
                FileAddress rom    = dmarec.Rom;
                if (rom.Start < 0)
                {
                    continue;
                }

                ReadOnlySpan <byte> file = read.Slice(rom.Start, vrom.Size);

                //if file should be compressed
                if (!task.Exclusions.Contains(i))
                {
                    int size = Yaz.Encode(file.ToArray(), vrom.Size, out byte[] comp);
                    if (size > 0)
                    {
                        Span <byte> c = new Span <byte>(comp, 0, size);
                        c.CopyTo(w.Slice(cur, size));
                        dmarec.Rom = new FileAddress(cur, cur + size);
                        cur       += size;
                        continue;
                    }
                }

                file.CopyTo(w.Slice(cur, vrom.Size));
                dmarec.Rom = new FileAddress(cur, 0);
                cur       += vrom.Size;
            }
            WriteDmadataRecords(w.Slice(dmadataRec.Rom.Start, dmadataRec.VRom.Size), dmadata);

            return(cur);
        }
Exemple #2
0
        static List <DmadataRecord> GetDmadataRecords(ReadOnlySpan <byte> read)
        {
            List <DmadataRecord> result = new List <DmadataRecord>();
            DmadataRecord        record;

            for (int i = 0; i < read.Length; i += 0x10)
            {
                record = new DmadataRecord()
                {
                    VRom = new FileAddress(EndianX.ConvertInt32(read, i + 0x0), EndianX.ConvertInt32(read, i + 0x4)),
                    Rom  = new FileAddress(EndianX.ConvertInt32(read, i + 0x8), EndianX.ConvertInt32(read, i + 0xC))
                };
                if (record.VRom.End == 0)
                {
                    break;
                }
                result.Add(record);
            }
            return(result);
        }
Exemple #3
0
        public static string GetExclusions(ReadOnlySpan <byte> read, int dmadata)
        {
            DmadataRecord rec     = GetDmadataRec(read, dmadata);
            var           records = GetDmadataRecords(read.Slice(rec.Rom.Start, rec.VRom.Size));

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"{dmadata:X8}");

            for (int i = 0; i < records.Count; i++)
            {
                var record = records[i];

                if (record.VRom.End != 0 &&
                    record.Rom.End == 0)
                {
                    sb.AppendLine($"{i}");
                }
            }
            return(sb.ToString());
        }