Beispiel #1
0
        public string[] Import()
        {
            MemoryStream Script = new MemoryStream(Data);

            BlockPos = new List <long>();

            string[] Array = new string[0];
            using (StructReader Reader = new StructReader(Script, Encoding: Encoding)) {
                while (Reader.Peek() != -1)
                {
                    if (!IsValid(Reader))
                    {
                        Reader.ReadByte();
                        continue;
                    }
                    BINv2Struct Struct = new BINv2Struct();
                    long        Pos    = Reader.BaseStream.Position;
                    try {
                        Reader.ReadStruct(ref Struct);
                    } catch {
                        try {
                            Reader.Seek(Pos + 1, SeekOrigin.Begin);
                        } catch {
                            break;
                        }
                        continue;
                    }
                    BlockPos.Add(Pos);
                    AppendArray(ref Array, Struct.Strings);
                }

                return(Array);
            }
        }
Beispiel #2
0
        public byte[] Export(string[] Text)
        {
            MemoryStream Script   = new MemoryStream(Data);
            long         StrIndex = 0;
            long         LastPos  = 0;

            byte[] Buffer = new byte[0];
            using (MemoryStream Output = new MemoryStream())
                using (StructReader Reader = new StructReader(Script, Encoding: Encoding))
                    using (StructWriter Writer = new StructWriter(Output, Encoding: Encoding)) {
                        foreach (long BasePos in BlockPos)
                        {
                            Buffer = new byte[BasePos - LastPos];
                            Reader.Read(Buffer, 0, Buffer.Length);
                            Writer.Write(Buffer, 0, Buffer.Length);

                            BINv2Struct Struct = new BINv2Struct();
                            Reader.ReadStruct(ref Struct);
                            LastPos = Reader.BaseStream.Position;

                            for (uint i = 0; i < Struct.Strings.LongLength; i++)
                            {
                                Struct.Strings[i] = Text[i + StrIndex];
                            }

                            StrIndex += Struct.Strings.LongLength;
                            Writer.WriteStruct(ref Struct);
                        }

                        if (Reader.BaseStream.Position != Reader.BaseStream.Length)
                        {
                            Reader.BaseStream.CopyTo(Writer.BaseStream);
                        }

                        Writer.Flush();
                        return(Output.ToArray());
                    }
        }