Esempio n. 1
0
        public byte[] Export(string[] Strings)
        {
            if (Strings.Length != StrCount)
            {
                throw new Exception("You can't add or remove a string entry");
            }

            int[]  Offsets;
            byte[] StringData, OffsetData;
            BuildStringData(Strings, out StringData, out Offsets);
            BuildOffsetTable(Offsets, out OffsetData);

            int       OffTblDiff = OffsetData.Length - OldOffTblLen;
            int       StrDatDiff = StringData.Length - OldStrDatLen;
            PSBHeader Header     = new PSBHeader();

            AdvancedBinary.Tools.CopyStruct(this.Header, ref Header);

            UpdateOffsets(ref Header, OffTblDiff, StrDatDiff);

            byte[] OutScript = new byte[Script.Length];
            Script.CopyTo(OutScript, 0);

            OverwriteRange(ref OutScript, this.Header.StrOffPos, OldOffTblLen, OffsetData);
            OverwriteRange(ref OutScript, Header.StrDataPos, OldStrDatLen, StringData);

            AdvancedBinary.Tools.BuildStruct(ref Header).CopyTo(OutScript, 0);

            return(CompressPackget ? CompressMDF(OutScript) : OutScript);
        }
Esempio n. 2
0
        private void UpdateOffsets(ref PSBHeader Header, int OffTblDiff, int StrDatDiff)
        {
            UpdateOffset(ref Header.ResOffPos, Header.StrOffPos, OffTblDiff);
            UpdateOffset(ref Header.ResDataPos, Header.StrOffPos, OffTblDiff);
            UpdateOffset(ref Header.ResLenPos, Header.StrOffPos, OffTblDiff);
            UpdateOffset(ref Header.ResIndexTree, Header.StrOffPos, OffTblDiff);
            UpdateOffset(ref Header.StrDataPos, Header.StrOffPos, OffTblDiff);

            UpdateOffset(ref Header.ResOffPos, Header.StrDataPos, StrDatDiff);
            UpdateOffset(ref Header.ResDataPos, Header.StrDataPos, StrDatDiff);
            UpdateOffset(ref Header.ResLenPos, Header.StrDataPos, StrDatDiff);
            UpdateOffset(ref Header.ResIndexTree, Header.StrDataPos, StrDatDiff);
        }
Esempio n. 3
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);
        }