Exemple #1
0
 public void Write(BinaryWriterEx bw)
 {
     bw.Write((int)size);
     bw.Write((byte)longCnt);
     bw.Write((byte)shortCnt);
     bw.Write((short)seqCnt);
 }
Exemple #2
0
        /// <summary>
        /// Writes VAG data to stream using binary writer.
        /// </summary>
        /// <param name="bw">BinaryWriterEx object.</param>
        public void Write(BinaryWriterEx bw)
        {
            //make sure magic string and version are correct
            magic   = "VAGp";
            version = 3;

            bw.Write(magic.ToCharArray());
            bw.WriteBig(version);
            bw.WriteBig(reserved);
            bw.WriteBig(dataSize);
            bw.WriteBig(sampleFreq);
            bw.WriteBig(unk1);
            bw.WriteBig(unk2);
            bw.WriteBig(unk3);

            int pos = (int)bw.BaseStream.Position;

            bw.Write(SampleName.ToCharArray());
            bw.Jump(pos + 16);

            foreach (var frame in Frames)
            {
                frame.Write(bw);
            }
        }
Exemple #3
0
 public void Write(BinaryWriterEx bw, List <UIntPtr> patchTable = null)
 {
     bw.Write(ptrVertex);
     bw.Write(unk1);
     bw.Write(unk2);
     color.Write(bw);
 }
Exemple #4
0
 public void Write(BinaryWriterEx output)
 {
     output.Write(Red);
     output.Write(Green);
     output.Write(Blue);
     output.Write(Alpha);
 }
Exemple #5
0
        private void Write(BinaryWriterEx output)
        {
            output.WriteAscii("RTM_0101", 8);
            Displacement.Write(output);

            var nFrames = FrameTimes.Length;
            var nBones  = BoneNames.Length;

            output.Write(nFrames);
            output.Write(nBones);

            for (int i = 0; i < nBones; i++)
            {
                output.WriteAscii(BoneNames[i], 32);
            }

            for (int frame = 0; frame < nFrames; frame++)
            {
                output.Write(FrameTimes[frame]);
                for (int b = 0; b < nBones; b++)
                {
                    output.WriteAscii(BoneNames[b], 32);
                    FrameTransforms[frame, b].Write(output);
                }
            }
        }
Exemple #6
0
 public void Write(BinaryWriterEx bw)
 {
     bw.Write(ptrVertex);
     bw.Write(unk1);
     bw.Write(unk2);
     color.Write(bw);
 }
Exemple #7
0
 public void Write(BinaryWriterEx writer)
 {
     writer.Write(Vertices[0]);
     writer.Write(Vertices[1]);
     writer.Write(Vertices[2]);
     writer.Write(Texture);
 }
Exemple #8
0
 public void Write(BinaryWriterEx writer)
 {
     writer.Write(Index0);
     writer.Write(Index1);
     writer.Write(Index2);
     writer.Write(Texture);
 }
Exemple #9
0
 public void Write(BinaryWriterEx bw)
 {
     bw.WriteStringFixed(Name);
     bw.Write(GameEvent);
     bw.Write(numEntries);
     bw.Write(ptrHeaders);
 }
Exemple #10
0
        /*
         * /// <summary>Exports every instrument to a SFZ text file.</summary>
         * /// <param name="fileName">Target file name.</param>
         * public void ToSFZ(string fileName)
         * {
         *  StringBuilder sb = new StringBuilder();
         *
         *  foreach (Instrument ss in longSamples)
         *      sb.Append(ss.ToSFZ(name));
         *
         *  foreach (Instrument ss in shortSamples)
         *      sb.Append(ss.ToSFZ(name));
         *
         *  File.WriteAllText(fileName, sb.ToString());
         * }
         *
         */

        /// <summary>Saves CSEQ file.</summary>
        /// <param name="fileName">Target file name.</param>
        public void Export(string fileName)
        {
            Helpers.CheckFolder(fileName);

            using (BinaryWriterEx bw = new BinaryWriterEx(File.Create(fileName)))
            {
                header.Write(bw);

                foreach (Instrument ls in longSamples)
                {
                    ls.Write(bw);
                }

                foreach (Instrument ss in shortSamples)
                {
                    ss.Write(bw);
                }


                long offsetsarraypos = bw.BaseStream.Position;

                foreach (Sequence seq in sequences)
                {
                    bw.Write((short)0);
                }

                int p = 3;
                if (USdemo)
                {
                    p = 1;
                }

                for (int i = 0; i < p; i++)
                {
                    bw.Write((byte)0);
                }

                List <long> offsets     = new List <long>();
                long        offsetstart = bw.BaseStream.Position;

                foreach (Sequence seq in sequences)
                {
                    offsets.Add(bw.BaseStream.Position - offsetstart);
                    seq.WriteBytes(bw);
                }

                bw.BaseStream.Position = offsetsarraypos;

                foreach (long off in offsets)
                {
                    bw.Write((short)off);
                }

                bw.BaseStream.Position = 0;
                bw.Write((int)bw.BaseStream.Length);

                bw.Close();
            }
        }
Exemple #11
0
 private void WriteShort(BinaryWriterEx bw)
 {
     bw.Write((byte)magic1);
     bw.Write((byte)velocity);
     bw.Write((short)basepitch);
     bw.Write((short)sampleID);
     bw.Write((short)always0);
 }
Exemple #12
0
 public virtual void Write(BinaryWriterEx bw)
 {
     bw.Write((byte)magic1);
     bw.Write((byte)volume);
     bw.Write((ushort)pitch);
     bw.Write((ushort)sampleID);
     bw.Write((short)always0);
 }
Exemple #13
0
 public void Write(BinaryWriterEx bw)
 {
     uv[0].Write(bw);
     bw.Write((ushort)0);
     uv[1].Write(bw);
     bw.Write((ushort)0);
     uv[2].Write(bw);
     uv[3].Write(bw);
 }
Exemple #14
0
 public void Write(BinaryWriterEx output)
 {
     output.WriteAsciiz(FileName);
     output.Write(CompressedMagic);
     output.Write(UncompressedSize);
     output.Write(StartOffset);
     output.Write(TimeStamp);
     output.Write(DataSize);
 }
Exemple #15
0
        public void WriteBytes(BinaryWriterEx bw)
        {
            int value = wait;

            int buffer = value & 0x7F;

            while (value != (value >> 7))
            {
                value    = value >> 7;
                buffer <<= 8;
                buffer  |= ((value & 0x7F) | 0x80);
            }

            while (true)
            {
                bw.Write((byte)buffer);
                if ((buffer & 0x80) > 0)
                {
                    buffer >>= 8;
                }
                else
                {
                    break;
                }
            }


            bw.Write((byte)evt);

            switch (evt)
            {
            case CSEQEvent.Unknown4:
            case CSEQEvent.Unknown8:
            case CSEQEvent.EndTrack2:
            case CSEQEvent.ChangePatch:
            case CSEQEvent.BendAssume:
            case CSEQEvent.VelAssume:
            case CSEQEvent.PanAssume:
            case CSEQEvent.NoteOff:
            {
                bw.Write((byte)pitch);
                break;
            }

            case CSEQEvent.NoteOn:
            {
                bw.Write((byte)pitch);
                bw.Write((byte)velocity);
                break;
            }

            case CSEQEvent.EndTrack:
            {
                break;
            }
            }
        }
Exemple #16
0
        public void Build(string basePath, string txt)
        {
            string path = Path.GetFileNameWithoutExtension(txt);

            string[] files = File.ReadAllLines(txt);


            Console.WriteLine(path);

            for (int i = 0; i < files.Length; i++)
            {
                files[i] = ".\\temp\\" + path + "\\" + files[i];
                ctrfiles.Add(new CTRFile(files[i]));
            }

            Console.WriteLine("we'll need " + TotalSize() + " Bytes for " + ctrfiles.Count + " files:");

            byte[]         final_big = new byte[TotalSize()];
            MemoryStream   ms        = new MemoryStream(final_big);
            BinaryWriterEx bw        = new BinaryWriterEx(ms);

            bw.BaseStream.Position = 4;
            bw.Write(ctrfiles.Count);

            bw.BaseStream.Position = 3 * 2048;

            foreach (CTRFile c in ctrfiles)
            {
                Console.Write(".");

                uint pos = (uint)bw.BaseStream.Position;
                c.offset = pos / 2048;


                bw.Write(c.data);

                bw.BaseStream.Position = pos + c.padded_size;
            }

            Console.WriteLine();

            bw.BaseStream.Position = 8;

            foreach (CTRFile c in ctrfiles)
            {
                bw.Write(c.offset);
                bw.Write(c.size);
            }

            //Console.WriteLine(p.disk_dump);

            //File.WriteAllBytes(path + ".BIG", final_big);
            File.WriteAllBytes(basePath + path + ".BIG", final_big);

            //Console.WriteLine(p.big_created);
        }
Exemple #17
0
 private void Write(BinaryWriterEx output)
 {
     output.WriteAscii("MLOD", 4);
     output.Write(Version);
     output.Write(Lods.Length);
     for (int index = 0; index < Lods.Length; ++index)
     {
         Lods[index].Write(output);
     }
 }
Exemple #18
0
 public void Write(BinaryWriterEx bw)
 {
     bw.Write(Data.Length);
     bw.Write(Data);
     bw.Write(PatchTable.Count * 4);
     foreach (var ptr in PatchTable)
     {
         bw.Write(ptr.ToUInt32());
     }
 }
Exemple #19
0
            public void Write(Stream target)
            {
                BinaryWriterEx writer = new BinaryWriterEx(target);
                Int32          length = Data.Length + 8;

                writer.Write(length);
                writer.Write(Type);
                writer.Write(Parameter);
                writer.Write(Data);
            }
Exemple #20
0
 public void Write(BinaryWriterEx bw)
 {
     //filler, add valid value
     uv[0].Write(bw);
     bw.Write((ushort)0);
     uv[1].Write(bw);
     bw.Write((ushort)0);
     uv[2].Write(bw);
     uv[3].Write(bw);
 }
Exemple #21
0
        public void Write(BinaryWriterEx bw)
        {
            bw.Write(System.Text.Encoding.ASCII.GetBytes(name));
            for (int i = 0; i < 16 - name.Length; i++)
            {
                bw.Write((byte)0);
            }
            bw.Write(modelOffset);

            scale.Write(bw);

            bw.Write(null1);
            bw.Write(unk1);

            bw.Write((int)0);
            bw.Write((int)0);
            bw.Write((int)0);

            position.Write(bw);
            angle.Write(bw);

            bw.Write(evt);

            bw.Seek((int)modelOffset + 4, SeekOrigin.Begin);
            bw.WriteStringFixed(ModelName);
        }
Exemple #22
0
        /// <summary>
        /// Writes the type and pointer for this material to a file.
        /// </summary>
        /// <param name="writer">The binary writer for this SegaNN file.</param>
        /// <param name="index">The number of this material in a linear list.</param>
        /// <param name="ObjectOffsets">The list of offsets this Object chunk uses.</param>
        public void WritePointer(BinaryWriterEx writer, int index, Dictionary <string, uint> ObjectOffsets)
        {
            // Write this material's type.
            writer.Write((uint)Type);

            // Add an offset to the BinaryWriter so we can fill it in in the NOF0 chunk.
            writer.AddOffset($"Material{index}", 0);

            // Write the value in ObjectOffsets of the main data for this material.
            writer.Write(ObjectOffsets[$"Material{index}"] - writer.Offset);
        }
        /// <summary>
        /// Gets the full packet data with a big-endian length prepended onto the payload.
        /// </summary>
        /// <returns>The full packet data.</returns>
        public byte[] GetData()
        {
            BinaryWriterEx bb = new BinaryWriterEx( true );

            byte[] payload = this.GetPayload();

            bb.Write( ( uint )payload.Length );
            bb.Write( payload );

            return bb.ToArray();
        }
Exemple #24
0
        /// <summary>
        /// Gets the full packet data with a big-endian length prepended onto the payload.
        /// </summary>
        /// <returns>The full packet data.</returns>
        public byte[] GetData()
        {
            BinaryWriterEx bb = new BinaryWriterEx(true);

            byte[] payload = this.GetPayload();

            bb.Write(( uint )payload.Length);
            bb.Write(payload);

            return(bb.ToArray());
        }
Exemple #25
0
        public override void Write(BinaryWriterEx output)
        {
            WriteHeader(output);
            var num = DataSize / 8;

            for (int index = 0; index < num; ++index)
            {
                output.Write(PointIndices[index, 0]);
                output.Write(PointIndices[index, 1]);
            }
        }
Exemple #26
0
        /// <summary>
        /// Writes VAG frame data to stream using binary writer.
        /// </summary>
        /// <param name="bw">Binary writer object.</param>
        public void Write(BinaryWriterEx bw)
        {
            if (data.Length != 14)
            {
                throw new Exception("Wrong VAG frame data length.");
            }

            bw.Write((byte)((predict_nr << 4) | shift_factor));
            bw.Write(flags);
            bw.Write(data);
        }
Exemple #27
0
        public void Write(BinaryWriterEx bw)
        {
            bw.Write(cnt);

            for (int i = 0; i < cnt; i++)
            {
                bw.Write(ptrs[i]);
            }


            bw.Seek(6, SeekOrigin.Current);
        }
Exemple #28
0
 public void Write(BinaryWriterEx bw)
 {
     bw.Write(magic.ToCharArray());
     WriteBig(bw, version);
     WriteBig(bw, reserved1);
     WriteBig(bw, datasize);
     WriteBig(bw, frequency);
     bw.Write(reserved10bytes);
     bw.Write(numChannels);
     bw.Write(reserved2);
     bw.Write(System.Text.Encoding.ASCII.GetBytes("testtesttesttest")); //name should go here
 }
Exemple #29
0
 public override void Write(BinaryWriterEx output)
 {
     WriteHeader(output);
     for (int index = 0; index < WeightedPoints.Length; ++index)
     {
         output.Write(WeightedPoints[index]);
     }
     for (int index = 0; index < Faces.Length; ++index)
     {
         output.Write(Faces[index]);
     }
 }
Exemple #30
0
        public void Write(BinaryWriterEx bw, List <UIntPtr> patchTable = null)
        {
            bw.Write(version);
            bw.Write(numFrames);
            bw.Write(data);
            start.Write(bw);

            foreach (NavFrame f in frames)
            {
                f.Write(bw);
            }
        }
Exemple #31
0
        public void Write(BinaryWriterEx bw)
        {
            bw.Write(unk1);
            bw.Write(numFrames);
            bw.Write(data);
            start.Write(bw);

            foreach (NavFrame f in frames)
            {
                f.Write(bw);
            }
        }
Exemple #32
0
        /// <summary>
        /// Note: this doesn't keep the SecureString secure.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="secure"></param>
        public static void Write(this BinaryWriter writer, SecureString secure)
        {
            var bwx = new BinaryWriterEx(writer.BaseStream);

            byte[] utf16 = new byte[secure.Length * 2];

            var ptr = Marshal.SecureStringToBSTR(secure);
            var len = Marshal.ReadInt32(ptr, -4);

            for (int i = 0; i < len; i += 2)
            {
                utf16[i] = Marshal.ReadByte(ptr, i);
            }

            Marshal.ZeroFreeBSTR(ptr);

            byte[] utf8 = UTF8Encoding.Convert(Encoding.Unicode, Encoding.UTF8, utf16);

            for (int i = 0; i < utf16.Length; i++)
            {
                utf16[i] = 0; // clear memory
            }

            bwx.Write7BitEncodedInt(utf8.Length);
            for (int i = 0; i < utf8.Length; i++)
            {
                bwx.Write(utf8[i]);
                utf8[i] = 0;
            }
        }
Exemple #33
0
        private void PrepareAuthHeader(ref WebClient client, Uri uri)
        {
            reqcounter++;

            byte[] sha_hash;

            BinaryWriterEx bb = new BinaryWriterEx();

            bb.Write( sessionID );
            bb.Write( reqcounter );
            bb.Write( sessionKey );
            bb.Write( Encoding.ASCII.GetBytes( uri.AbsolutePath ) );

            sha_hash = CryptoHelper.SHAHash(bb.ToArray());

            string hex_hash = Utils.EncodeHexString(sha_hash);

            string authheader = String.Format("sessionid={0};req-counter={1};hash={2};", sessionID, reqcounter, hex_hash);

            webClient.Headers.Clear();
            webClient.Headers.Add("x-steam-auth", authheader);
        }
Exemple #34
0
            public void Write(Stream target)
            {
                BinaryWriterEx writer = new BinaryWriterEx(target);
                Int32 length = Data.Length + 8;

                writer.Write(length);
                writer.Write(Type);
                writer.Write(Parameter);
                writer.Write(Data);
            }
Exemple #35
0
 public void Write(Stream target)
 {
     BinaryWriterEx writer = new BinaryWriterEx(target);
     writer.Write(Channel);
     writer.Write(Frequency);
     writer.Write(ReverbVolume);
     writer.Write(Volume);
     writer.Write(Panning);
     writer.Write24(Offset);
     writer.Write(SampleType);
     writer.Write(Flags);
 }
Exemple #36
0
        public static void Decompress(Stream source, Stream target, int length, int decompLength, BemaniLZSS2Properties props)
        {
            byte[] ring = new byte[props.ringBufferSize];
            int ring_pos = props.ringBufferOffset;
            int chunk_offset;
            int chunk_length;
            int control_word = 1;
            int controlBitsLeft = 0;
            int controlBitMask = 0x1;
            byte cmd1;
            byte cmd2;
            byte data;

            if (decompLength <= 0)
                decompLength = int.MaxValue;

            BinaryReaderEx sourceReader = new BinaryReaderEx(source);
            BinaryWriterEx writer = new BinaryWriterEx(target);

            using (MemoryStream mem = new MemoryStream(sourceReader.ReadBytes(length)))
            {
                BinaryReaderEx reader = new BinaryReaderEx(mem);

                while (decompLength > 0 && length > 0)
                {
                    if (controlBitsLeft == 0)
                    {
                        /* Read a control byte */
                        control_word = reader.ReadByte();
                        length--;
                        controlBitsLeft = 8;
                    }

                    /* Decode a byte according to the current control byte bit */
                    if ((control_word & controlBitMask) != 0)
                    {
                        /* Straight copy, store into history ring */
                        data = reader.ReadByte();
                        length--;

                        writer.Write(data);
                        ring[ring_pos] = data;

                        ring_pos = (ring_pos + 1) % props.ringBufferSize;
                        decompLength--;
                    }
                    else
                    {
                        /* Reference to data in ring buffer */

                        switch (props.type)
                        {
                            case BemaniLZSS2Type.Firebeat:
                                cmd1 = reader.ReadByte();
                                cmd2 = reader.ReadByte();
                                length -= 2;
                                chunk_length = (cmd1 & 0x0F) + 3;
                                chunk_offset = (((int)cmd1 & 0xF0) << 4) + (int)cmd2;
                                chunk_offset = ring_pos - chunk_offset;
                                while (chunk_offset < 0)
                                    chunk_offset += props.ringBufferSize;
                                break;
                            case BemaniLZSS2Type.GCZ:
                                cmd1 = reader.ReadByte();
                                cmd2 = reader.ReadByte();
                                length -= 2;
                                chunk_length = (cmd2 & 0x0F) + 3;
                                chunk_offset = (((int)cmd2 & 0xF0) << 4) | cmd1;
                                break;
                            default:
                                return;
                        }

                        for ( ; chunk_length > 0 && length > 0 ; chunk_length--)
                        {
                            /* Copy historical data to output AND current ring pos */
                            writer.Write(ring[chunk_offset]);
                            ring[ring_pos] = ring[chunk_offset];

                            /* Update counters */
                            chunk_offset = (chunk_offset + 1) % props.ringBufferSize;
                            ring_pos = (ring_pos + 1) % props.ringBufferSize;
                            decompLength--;
                        }
                    }

                    /* Get next control bit */
                    control_word >>= 1;
                    controlBitsLeft--;
                }
            }
        }
Exemple #37
0
        //seralize the Object
        virtual public void Serialize(BinaryWriterEx binWriterEx)
        {
            binWriterEx.Write(this.GetType());

            binWriterEx.Write(this.labels);           
            binWriterEx.Write(this.groupId);       
            binWriterEx.Write(this.featureNames);

            binWriterEx.Write((this.activeFeatureNames != null));
            if (this.activeFeatureNames != null)
            {
                binWriterEx.Write(this.activeFeatureNames);
            }
            binWriterEx.Write((this.activeFeatureIdx != null));
            if (this.activeFeatureIdx != null)
            {
                binWriterEx.Write(this.activeFeatureIdx);
            }
        }
Exemple #38
0
        //seralize the Object
        override public void Serialize(BinaryWriterEx binWriterEx)
        {
            //first serialize the base class
            base.Serialize(binWriterEx);

            binWriterEx.Write(this.codeBook);

            binWriterEx.Write((this.featureCoded != null));
            if (this.featureCoded != null)
            {                
                ((IBinaryWritable)this.featureCoded).Serialize(binWriterEx);
            }
        }