Example #1
0
        public string Import()
        {
            if (Header.IsBinary || Header.Entries != 1)
            {
                throw new Exception("Not Suported.");
            }

            if (Header.IsEncrypted)
            {
                Decrypt();
            }
            if (Header.IsCompressed)
            {
                Decompress();
            }

            Content = new VLContent();
            StructReader Reader = new StructReader(new MemoryStream(Script), true, Encoding);

            Reader.Seek(0x50, 0);

            if (Reader.PeekUInt32() == 3557938853)  //English Script from KoiChoco
            {
                Reader.Seek(0x4C, 0);
                Header.Unk = 0;
                NoUnk14    = true;
            }

            Reader.ReadStruct(ref Content);

            return(Content.Content);
        }
Example #2
0
        public byte[] Export(string Content)
        {
            dynamic NewVLC = new VLContent()
            {
                Dummy   = this.Content.Dummy,
                Content = Content
            };

            if (NoUnk14 && (Encrypt || Compress))
            {
                //The English Script of koichoco have a part of the header cutted off, so...
                //if you ignore this he corrupt when you encrypt or compress the script
                throw new Exception("This Script is Corrupted, You can't Export it with Compression or Encryption.");
            }

            SL2Header Header = new SL2Header();

            Tools.CopyStruct(this.Header, ref Header);
            Header.IsCompressed = Header.IsEncrypted = false;
            Header.DecLen       = 0;


            byte[] Output = Tools.BuildStruct(ref NewVLC, true, Encoding);

            if (Compress)
            {
                Output = CompressData(Output);
                Header.IsCompressed = true;
                Header.DecLen       = (uint)Encoding.GetByteCount(Content) + 0x18;//???
            }

            if (Encrypt)
            {
                Output             = EncryptData(Output);
                Header.IsEncrypted = true;
            }


            Header.Length = (uint)(Output.LongLength + (NoUnk14 ? 0x4C : 0x50));

            if (UpdateModifyDate)
            {
                Header.Day   = (byte)DateTime.Now.Day;
                Header.Month = (byte)DateTime.Now.Month;
                Header.Year  = (ushort)DateTime.Now.Year;
            }

            MemoryStream Data   = new MemoryStream();
            StructWriter Result = new StructWriter(Data, true, Encoding);

            Result.WriteStruct(ref Header);

            if (NoUnk14)
            {
                Result.Seek(-4, SeekOrigin.Current);
            }

            Result.Write(Output, 0, Output.Length);
            Output = Data.ToArray();
            Result.Close();
            Data.Close();

            return(Output);
        }