Beispiel #1
0
        public static Gxt2File FromText(string text)
        {
            var gxt     = new Gxt2File();
            var lines   = text?.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0];
            var entries = new List <Gxt2Entry>();

            foreach (var line in lines)
            {
                var tline = line.Trim();
                if (tline.Length < 13)
                {
                    continue;
                }
                if (uint.TryParse(tline.Substring(2, 8), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint hash))
                {
                    var entry = new Gxt2Entry();
                    entry.Hash = hash;
                    entry.Text = (tline.Length > 13) ? tline.Substring(13) : "";
                    entries.Add(entry);
                }
                else
                {
                    //error parsing hash, probably should tell the user about this somehow
                }
            }
            entries.Sort((a, b) => a.Hash.CompareTo(b.Hash));
            gxt.TextEntries = entries.ToArray();
            gxt.EntryCount  = (uint)entries.Count;
            return(gxt);
        }
Beispiel #2
0
        //public Dictionary<uint, string> Dict { get; set; }


        public void Load(byte[] data, RpfFileEntry entry)
        {
            Name      = entry?.Name ?? "";
            FileEntry = entry;
            //Dict = new Dictionary<uint, string>();

            using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
            {
                uint gxt2 = br.ReadUInt32(); //"GXT2" - 1196971058
                if (gxt2 != 1196971058)
                {
                    return;
                }

                EntryCount  = br.ReadUInt32();
                TextEntries = new Gxt2Entry[EntryCount];
                for (uint i = 0; i < EntryCount; i++)
                {
                    var e = new Gxt2Entry();
                    e.Hash         = br.ReadUInt32();
                    e.Offset       = br.ReadUInt32();
                    TextEntries[i] = e;
                }

                gxt2 = br.ReadUInt32(); //another "GXT2"
                if (gxt2 != 1196971058)
                {
                    return;
                }

                uint endpos = br.ReadUInt32();

                List <byte> buf = new List <byte>();

                for (uint i = 0; i < EntryCount; i++)
                {
                    var e = TextEntries[i];
                    br.BaseStream.Position = e.Offset;

                    buf.Clear();
                    byte b = br.ReadByte();
                    while ((b != 0) && (br.BaseStream.Position < endpos))
                    {
                        buf.Add(b);
                        b = br.ReadByte();
                    }
                    e.Text = Encoding.UTF8.GetString(buf.ToArray());

                    //Dict[e.Hash] = e.Text;
                }
            }
        }