Beispiel #1
0
        public void UpdateEntries()
        {
            VoidPtr addr = _workingSource.Address;

            addr += 0x08;

            for (int i = 0; i < _entryCount; i++)
            {
                LSEntry lsobj = Entries.Values[i];
                if (Version == 1)
                {
                    _s_LSEntry_v1 *entry = (_s_LSEntry_v1 *)(addr + (i * 0x0C));
                    *entry = new _s_LSEntry_v1()
                    {
                        _crc   = lsobj.FileNameCRC,
                        _start = lsobj.DTOffset,
                        _size  = lsobj.Size
                    };
                    _s_LSEntry_v1 *entry2 = (_s_LSEntry_v1 *)(addr + (i * 0x0C));
                }
                else if (Version == 2)
                {
                    _s_LSEntry_v2 *entry = (_s_LSEntry_v2 *)(addr + (i * 0x10));
                    *entry = new _s_LSEntry_v2()
                    {
                        _crc     = lsobj.FileNameCRC,
                        _start   = lsobj.DTOffset,
                        _size    = lsobj.Size,
                        _dtIndex = lsobj.DTIndex,
                        _unk     = lsobj.PaddingLength
                    };
                }
            }
        }
Beispiel #2
0
        public LSEntry TryGetValue(string name)
        {
            uint    CRC = calc_crc(name);
            LSEntry tmp = null;

            Entries.TryGetValue(CRC, out tmp);
            return(tmp);
        }
Beispiel #3
0
        public bool InitializePartition(string partition)
        {
            Files.Clear();
            LSEntry resource = null;

            if ((resource = LS.TryGetValue(partition)) == null)
            {
                return(false);
            }

            File.WriteAllBytes(partition,
                               GetFile(resource.DTOffset, resource.Size, resource.DTIndex));

            RF = new RFFile(partition);
            if (partition.Contains("("))
            {
                RF.Locale = partition.Substring(partition.IndexOf("("));
            }
            RegionCode = RF.RegionCode;

            LSEntry     lsentry = null;
            IndexedPath path    = new IndexedPath($"data{RF.Locale}/");

            foreach (ResourceEntry rsobj in RF.ResourceEntries)
            {
                if (rsobj == null)
                {
                    continue;
                }

                path[rsobj.FolderDepth] = rsobj.EntryString;

                if (rsobj.Packed)
                {
                    lsentry = LS.TryGetValue(path.ToString() + "packed");
                }

                if (lsentry != null)
                {
                    var tpl = new Tuple <LSEntry, ResourceEntry>(lsentry, rsobj);
                    if (rsobj.Packed)
                    {
                        Files.Add(path.ToString() + "packed", tpl);
                    }
                    else
                    {
                        Files.Add(path.ToString(), tpl);
                    }
                }
            }
            return(true);
        }
Beispiel #4
0
        public bool InitializePartition(string partition)
        {
            LSEntry resource = null;

            if ((resource = LS.TryGetValue(partition)) == null)
            {
                return(false);
            }

            File.WriteAllBytes(partition,
                               GetFile(resource.DTOffset, resource.Size, resource.DTIndex));

            var rf = new RFFile(partition);

            if (partition.Contains("("))
            {
                rf.Locale = partition.Substring(partition.IndexOf("("));
            }

            return(InitializePartition(rf, partition));
        }
Beispiel #5
0
        public bool InitializePartition(RFFile rf, string partition)
        {
            Files.Clear();
            RegionCode = rf.RegionCode;
            LSEntry     lsentry = null;
            IndexedPath path    = new IndexedPath($"data{RF.Locale}/");

            foreach (ResourceEntry rsobj in RF.ResourceEntries)
            {
                if (rsobj == null)
                {
                    continue;
                }

                path[rsobj.FolderDepth] = rsobj.EntryString;

                if (rsobj.Packed)
                {
                    lsentry = LS.TryGetValue(path.ToString() + "packed");
                }

                if (lsentry != null)
                {
                    var tpl = new Tuple <LSEntry, ResourceEntry>(lsentry, rsobj);
                    if (rsobj.Packed)
                    {
                        Files.Add(path.ToString() + "packed", tpl);
                    }
                    else
                    {
                        Files.Add(path.ToString(), tpl);
                    }
                }
            }
            return(true);
        }
Beispiel #6
0
        public void Parse(string path)
        {
            _workingSource = new DataSource(FileMap.FromFile(path));

            short tag = *(short *)_workingSource.Address;

            if (tag != 0x666f)
            {
                return;
            }
            _version    = *(short *)(_workingSource.Address + 0x02);
            _entryCount = *(int *)(_workingSource.Address + 0x04);
            Entries     = new SortedList <uint, LSEntry>(_entryCount);

            for (int i = 0; i < _entryCount; i++)
            {
                LSEntry lsobj = new LSEntry();
                if (Version == 1)
                {
                    _s_LSEntry_v1 entry = *(_s_LSEntry_v1 *)(_workingSource.Address + 0x08 + (i * 0x0C));
                    lsobj.FileNameCRC = entry._crc;
                    lsobj.DTOffset    = entry._start;
                    lsobj.Size        = entry._size;
                }
                else if (Version == 2)
                {
                    _s_LSEntry_v2 entry = *(_s_LSEntry_v2 *)(_workingSource.Address + 0x08 + (i * 0x10));
                    lsobj.FileNameCRC   = entry._crc;
                    lsobj.DTOffset      = entry._start;
                    lsobj.Size          = entry._size;
                    lsobj.DTIndex       = entry._dtIndex;
                    lsobj.PaddingLength = entry._unk;
                }
                Entries.Add(lsobj.FileNameCRC, lsobj);
            }
        }
Beispiel #7
0
        public void BuildPartitions(string folder)
        {
            if (DTFiles == null)
            {
                return;
            }

            FileStream dtstrm   = File.Create("dt_rebuild");
            string     tmpfile  = Path.GetTempFileName();
            FileStream packstrm = File.Create(tmpfile);

            foreach (string str in Directory.EnumerateDirectories(folder))
            {
                if (!str.Contains("data"))
                {
                    return;
                }

                string partition = "resource";
                if (str.Contains("("))
                {
                    partition += str.Substring(str.IndexOf("("));
                }

                var rf = new RFFile();

                LSEntry curPacked = null;
                int     pad       = 0;
                string  packKey   = "";
                foreach (string key in Files.Keys)
                {
                    Console.WriteLine(key);
                    var tpl = Files[key];
                    if (tpl.Item2.Packed)
                    {
                        if (curPacked != null)
                        {
                            int aligned = (int)packstrm.Position.RoundUp(0x10) + 0x60;
                            while (packstrm.Position < aligned)
                            {
                                packstrm.WriteByte(0xBB);
                            }
                            curPacked.Size = (int)packstrm.Length;
                            LS.TrySetValue(packKey, curPacked);

                            packstrm.WriteTo(dtstrm);
                            packstrm.Close();
                            packstrm = File.Open(tmpfile, FileMode.Truncate);
                        }
                        curPacked          = tpl.Item1;
                        packKey            = key;
                        curPacked.DTOffset = (uint)dtstrm.Position;
                        var data = File.ReadAllBytes($"{folder}/{key}");
                        for (pad = 0; pad < data.Length && data[pad] == 0xCC; pad++)
                        {
                            packstrm.WriteByte(0xCC);
                        }
                    }
                    else if (!tpl.Item2.EntryString.EndsWith("/"))
                    {
                        var           filedata = File.ReadAllBytes($"{folder}/{key}");
                        var           cmp      = Util.Compress(filedata);
                        ResourceEntry rsobj    = tpl.Item2;
                        int           rIndex   = RF.ResourceEntries.IndexOf(rsobj);

                        rsobj.OffInPack = (uint)packstrm.Position;
                        rsobj.CmpSize   = cmp.Length;
                        rsobj.DecSize   = filedata.Length;
                        RF[rIndex]      = rsobj;
                        packstrm.Write(cmp, 0, cmp.Length);

                        int aligned = (int)packstrm.Position.RoundUp(0x10) + 0x20;
                        while (packstrm.Position % 0x10 > 0)
                        {
                            packstrm.WriteByte(0xCC);
                        }
                    }
                }
                if (curPacked != null)
                {
                    curPacked.Size = (int)packstrm.Length;
                    LS.TrySetValue(packKey, curPacked);
                    packstrm.WriteTo(dtstrm);
                }
                RF.UpdateEntries();


                byte[] full     = RF.GetBytes();
                var    resource = LS.TryGetValue(partition);
                resource.DTOffset = (uint)dtstrm.Position;
                dtstrm.Write(full, 0, full.Length);
                resource.Size = full.Length;
                LS.TrySetValue(partition, resource);
                LS.UpdateEntries();
                dtstrm.Close();
                packstrm.Close();
            }
        }
Beispiel #8
0
 public void TrySetValue(string key, LSEntry data)
 {
     Entries[calc_crc(key)] = data;
 }