Example #1
0
        public string[] Import()
        {
            PackgetStatus Status = GetPackgetStatus(Script);

            switch (Status)
            {
            case PackgetStatus.Invalid:
                throw new Exception("Invalid Packget");

            case PackgetStatus.MDF:
                Script          = ExtractMDF(Script);
                CompressPackget = true;
                break;
            }

            MemoryStream In = new MemoryStream(Script);

            Header = new PSBHeader();
            StructReader Reader = new StructReader(In);

            Reader.ReadStruct(ref Header);

            Reader.BaseStream.Position = Header.StrOffPos;
            OffLength = ConvertSize(Reader.ReadByte());
            StrCount  = ReadOffset(Reader.ReadBytes(OffLength), 0, OffLength);
            OffLength = ConvertSize(Reader.ReadByte());

            int[] Offsets = new int[StrCount];
            for (int i = 0; i < StrCount; i++)
            {
                Offsets[i] = ReadOffset(Reader.ReadBytes(OffLength), 0, OffLength);
            }

            OldOffTblLen = (int)(Reader.BaseStream.Position - Header.StrOffPos);

            string[] Strings = new string[StrCount];
            for (int i = 0; i < StrCount; i++)
            {
                Reader.BaseStream.Position = Header.StrDataPos + Offsets[i];
                StrEntry Entry = new StrEntry();
                Reader.ReadStruct(ref Entry);
                Strings[i] = Entry.Content;
            }

            OldStrDatLen = (int)(Reader.BaseStream.Position - Header.StrDataPos);

            Reader.Close();
            return(Strings);
        }
Example #2
0
        private void BuildStringData(string[] Strings, out byte[] StringTable, out int[] Offsets)
        {
            Offsets = new int[StrCount];
            MemoryStream StrData = new MemoryStream();
            StructWriter Writer  = new StructWriter(StrData);

            for (int i = 0; i < StrCount; i++)
            {
                Offsets[i] = (int)Writer.BaseStream.Length;
                StrEntry Entry = new StrEntry();
                Entry.Content = Strings[i];
                Writer.WriteStruct(ref Entry);
            }
            StringTable = StrData.ToArray();
            Writer.Close();
            StrData?.Close();
        }