コード例 #1
0
ファイル: NetUtil.cs プロジェクト: wfraser/FooSync
        /// <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;
            }
        }
コード例 #2
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();
        }
コード例 #3
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteUInt16(m_offset);
     bw.WriteUInt16(m_numKeys);
 }
コード例 #4
0
ファイル: PosAng.cs プロジェクト: ctr-branch/CTR-tools-1
 public void Write(BinaryWriterEx bw)
 {
     Position.Write(bw);
     Angle.Write(bw);
 }
コード例 #5
0
ファイル: LabelFeatureData.cs プロジェクト: zbxzc35/BoostTree
        //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);
            }
        }  
コード例 #6
0
ファイル: LabelFeatureData.cs プロジェクト: zbxzc35/BoostTree
 //seralize the Object
 override public void Serialize(BinaryWriterEx binWriterEx)        
 {
     //first serialize the base class
     base.Serialize(binWriterEx);
                     
     ((IBinaryWritable)this.feature).Serialize(binWriterEx);                                   
 }  
コード例 #7
0
ファイル: BemaniLZSS2.cs プロジェクト: NoOnes2/scharfrichter
        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--;
                }
            }
        }
コード例 #8
0
ファイル: K054539.cs プロジェクト: NoOnes2/scharfrichter
 public static int WriteRaw(byte[] source, Stream target, Properties prop)
 {
     BinaryWriterEx writer = new BinaryWriterEx(target);
     return 0;
 }
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteByte(0);
 }
コード例 #10
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     s.WriteClassArray <hknpMotionProperties>(bw, m_elements);
     bw.WriteInt32(m_firstFree);
     bw.WriteUInt32(0);
 }
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteSingle(m_restLengths_0);
     bw.WriteSingle(m_restLengths_1);
     bw.WriteSingle(m_restLengths_2);
     bw.WriteSingle(m_restLengths_3);
     bw.WriteSingle(m_restLengths_4);
     bw.WriteSingle(m_restLengths_5);
     bw.WriteSingle(m_restLengths_6);
     bw.WriteSingle(m_restLengths_7);
     bw.WriteSingle(m_restLengths_8);
     bw.WriteSingle(m_restLengths_9);
     bw.WriteSingle(m_restLengths_10);
     bw.WriteSingle(m_restLengths_11);
     bw.WriteSingle(m_restLengths_12);
     bw.WriteSingle(m_restLengths_13);
     bw.WriteSingle(m_restLengths_14);
     bw.WriteSingle(m_restLengths_15);
     bw.WriteSingle(m_stiffnessesA_0);
     bw.WriteSingle(m_stiffnessesA_1);
     bw.WriteSingle(m_stiffnessesA_2);
     bw.WriteSingle(m_stiffnessesA_3);
     bw.WriteSingle(m_stiffnessesA_4);
     bw.WriteSingle(m_stiffnessesA_5);
     bw.WriteSingle(m_stiffnessesA_6);
     bw.WriteSingle(m_stiffnessesA_7);
     bw.WriteSingle(m_stiffnessesA_8);
     bw.WriteSingle(m_stiffnessesA_9);
     bw.WriteSingle(m_stiffnessesA_10);
     bw.WriteSingle(m_stiffnessesA_11);
     bw.WriteSingle(m_stiffnessesA_12);
     bw.WriteSingle(m_stiffnessesA_13);
     bw.WriteSingle(m_stiffnessesA_14);
     bw.WriteSingle(m_stiffnessesA_15);
     bw.WriteSingle(m_stiffnessesB_0);
     bw.WriteSingle(m_stiffnessesB_1);
     bw.WriteSingle(m_stiffnessesB_2);
     bw.WriteSingle(m_stiffnessesB_3);
     bw.WriteSingle(m_stiffnessesB_4);
     bw.WriteSingle(m_stiffnessesB_5);
     bw.WriteSingle(m_stiffnessesB_6);
     bw.WriteSingle(m_stiffnessesB_7);
     bw.WriteSingle(m_stiffnessesB_8);
     bw.WriteSingle(m_stiffnessesB_9);
     bw.WriteSingle(m_stiffnessesB_10);
     bw.WriteSingle(m_stiffnessesB_11);
     bw.WriteSingle(m_stiffnessesB_12);
     bw.WriteSingle(m_stiffnessesB_13);
     bw.WriteSingle(m_stiffnessesB_14);
     bw.WriteSingle(m_stiffnessesB_15);
     bw.WriteUInt16(m_particlesA_0);
     bw.WriteUInt16(m_particlesA_1);
     bw.WriteUInt16(m_particlesA_2);
     bw.WriteUInt16(m_particlesA_3);
     bw.WriteUInt16(m_particlesA_4);
     bw.WriteUInt16(m_particlesA_5);
     bw.WriteUInt16(m_particlesA_6);
     bw.WriteUInt16(m_particlesA_7);
     bw.WriteUInt16(m_particlesA_8);
     bw.WriteUInt16(m_particlesA_9);
     bw.WriteUInt16(m_particlesA_10);
     bw.WriteUInt16(m_particlesA_11);
     bw.WriteUInt16(m_particlesA_12);
     bw.WriteUInt16(m_particlesA_13);
     bw.WriteUInt16(m_particlesA_14);
     bw.WriteUInt16(m_particlesA_15);
     bw.WriteUInt16(m_particlesB_0);
     bw.WriteUInt16(m_particlesB_1);
     bw.WriteUInt16(m_particlesB_2);
     bw.WriteUInt16(m_particlesB_3);
     bw.WriteUInt16(m_particlesB_4);
     bw.WriteUInt16(m_particlesB_5);
     bw.WriteUInt16(m_particlesB_6);
     bw.WriteUInt16(m_particlesB_7);
     bw.WriteUInt16(m_particlesB_8);
     bw.WriteUInt16(m_particlesB_9);
     bw.WriteUInt16(m_particlesB_10);
     bw.WriteUInt16(m_particlesB_11);
     bw.WriteUInt16(m_particlesB_12);
     bw.WriteUInt16(m_particlesB_13);
     bw.WriteUInt16(m_particlesB_14);
     bw.WriteUInt16(m_particlesB_15);
 }
 public override void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     base.Write(s, bw);
     s.WriteClassArray <hclObjectSpaceDeformerLocalBlockPNT>(bw, m_localPNTs);
     s.WriteClassArray <hclObjectSpaceDeformerLocalBlockUnpackedPNT>(bw, m_localUnpackedPNTs);
 }
コード例 #13
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     s.WriteClassArray <hkRefCountedPropertiesEntry>(bw, m_entries);
 }
コード例 #14
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteSByte((sbyte)m_type);
 }
コード例 #15
0
 public override void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     base.Write(s, bw);
     s.WriteClassPointer <hkpEntity>(bw, m_bodyA);
     s.WriteClassPointer <hkpEntity>(bw, m_bodyB);
     bw.WriteUInt64(m_bodyAId);
     bw.WriteUInt64(m_bodyBId);
     bw.WriteBoolean(m_useEntityIds);
     bw.WriteSByte((sbyte)m_agentType);
     bw.WriteUInt64(0);
     bw.WriteUInt32(0);
     bw.WriteUInt16(0);
     m_atom.Write(s, bw);
     s.WriteByteArray(bw, m_propertiesStream);
     s.WriteClassArray <hkContactPoint>(bw, m_contactPoints);
     s.WriteByteArray(bw, m_cpIdMgr);
     bw.WriteByte(m_nnEntryData_0);
     bw.WriteByte(m_nnEntryData_1);
     bw.WriteByte(m_nnEntryData_2);
     bw.WriteByte(m_nnEntryData_3);
     bw.WriteByte(m_nnEntryData_4);
     bw.WriteByte(m_nnEntryData_5);
     bw.WriteByte(m_nnEntryData_6);
     bw.WriteByte(m_nnEntryData_7);
     bw.WriteByte(m_nnEntryData_8);
     bw.WriteByte(m_nnEntryData_9);
     bw.WriteByte(m_nnEntryData_10);
     bw.WriteByte(m_nnEntryData_11);
     bw.WriteByte(m_nnEntryData_12);
     bw.WriteByte(m_nnEntryData_13);
     bw.WriteByte(m_nnEntryData_14);
     bw.WriteByte(m_nnEntryData_15);
     bw.WriteByte(m_nnEntryData_16);
     bw.WriteByte(m_nnEntryData_17);
     bw.WriteByte(m_nnEntryData_18);
     bw.WriteByte(m_nnEntryData_19);
     bw.WriteByte(m_nnEntryData_20);
     bw.WriteByte(m_nnEntryData_21);
     bw.WriteByte(m_nnEntryData_22);
     bw.WriteByte(m_nnEntryData_23);
     bw.WriteByte(m_nnEntryData_24);
     bw.WriteByte(m_nnEntryData_25);
     bw.WriteByte(m_nnEntryData_26);
     bw.WriteByte(m_nnEntryData_27);
     bw.WriteByte(m_nnEntryData_28);
     bw.WriteByte(m_nnEntryData_29);
     bw.WriteByte(m_nnEntryData_30);
     bw.WriteByte(m_nnEntryData_31);
     bw.WriteByte(m_nnEntryData_32);
     bw.WriteByte(m_nnEntryData_33);
     bw.WriteByte(m_nnEntryData_34);
     bw.WriteByte(m_nnEntryData_35);
     bw.WriteByte(m_nnEntryData_36);
     bw.WriteByte(m_nnEntryData_37);
     bw.WriteByte(m_nnEntryData_38);
     bw.WriteByte(m_nnEntryData_39);
     bw.WriteByte(m_nnEntryData_40);
     bw.WriteByte(m_nnEntryData_41);
     bw.WriteByte(m_nnEntryData_42);
     bw.WriteByte(m_nnEntryData_43);
     bw.WriteByte(m_nnEntryData_44);
     bw.WriteByte(m_nnEntryData_45);
     bw.WriteByte(m_nnEntryData_46);
     bw.WriteByte(m_nnEntryData_47);
     bw.WriteByte(m_nnEntryData_48);
     bw.WriteByte(m_nnEntryData_49);
     bw.WriteByte(m_nnEntryData_50);
     bw.WriteByte(m_nnEntryData_51);
     bw.WriteByte(m_nnEntryData_52);
     bw.WriteByte(m_nnEntryData_53);
     bw.WriteByte(m_nnEntryData_54);
     bw.WriteByte(m_nnEntryData_55);
     bw.WriteByte(m_nnEntryData_56);
     bw.WriteByte(m_nnEntryData_57);
     bw.WriteByte(m_nnEntryData_58);
     bw.WriteByte(m_nnEntryData_59);
     bw.WriteByte(m_nnEntryData_60);
     bw.WriteByte(m_nnEntryData_61);
     bw.WriteByte(m_nnEntryData_62);
     bw.WriteByte(m_nnEntryData_63);
     bw.WriteByte(m_nnEntryData_64);
     bw.WriteByte(m_nnEntryData_65);
     bw.WriteByte(m_nnEntryData_66);
     bw.WriteByte(m_nnEntryData_67);
     bw.WriteByte(m_nnEntryData_68);
     bw.WriteByte(m_nnEntryData_69);
     bw.WriteByte(m_nnEntryData_70);
     bw.WriteByte(m_nnEntryData_71);
     bw.WriteByte(m_nnEntryData_72);
     bw.WriteByte(m_nnEntryData_73);
     bw.WriteByte(m_nnEntryData_74);
     bw.WriteByte(m_nnEntryData_75);
     bw.WriteByte(m_nnEntryData_76);
     bw.WriteByte(m_nnEntryData_77);
     bw.WriteByte(m_nnEntryData_78);
     bw.WriteByte(m_nnEntryData_79);
     bw.WriteByte(m_nnEntryData_80);
     bw.WriteByte(m_nnEntryData_81);
     bw.WriteByte(m_nnEntryData_82);
     bw.WriteByte(m_nnEntryData_83);
     bw.WriteByte(m_nnEntryData_84);
     bw.WriteByte(m_nnEntryData_85);
     bw.WriteByte(m_nnEntryData_86);
     bw.WriteByte(m_nnEntryData_87);
     bw.WriteByte(m_nnEntryData_88);
     bw.WriteByte(m_nnEntryData_89);
     bw.WriteByte(m_nnEntryData_90);
     bw.WriteByte(m_nnEntryData_91);
     bw.WriteByte(m_nnEntryData_92);
     bw.WriteByte(m_nnEntryData_93);
     bw.WriteByte(m_nnEntryData_94);
     bw.WriteByte(m_nnEntryData_95);
     bw.WriteByte(m_nnEntryData_96);
     bw.WriteByte(m_nnEntryData_97);
     bw.WriteByte(m_nnEntryData_98);
     bw.WriteByte(m_nnEntryData_99);
     bw.WriteByte(m_nnEntryData_100);
     bw.WriteByte(m_nnEntryData_101);
     bw.WriteByte(m_nnEntryData_102);
     bw.WriteByte(m_nnEntryData_103);
     bw.WriteByte(m_nnEntryData_104);
     bw.WriteByte(m_nnEntryData_105);
     bw.WriteByte(m_nnEntryData_106);
     bw.WriteByte(m_nnEntryData_107);
     bw.WriteByte(m_nnEntryData_108);
     bw.WriteByte(m_nnEntryData_109);
     bw.WriteByte(m_nnEntryData_110);
     bw.WriteByte(m_nnEntryData_111);
     bw.WriteByte(m_nnEntryData_112);
     bw.WriteByte(m_nnEntryData_113);
     bw.WriteByte(m_nnEntryData_114);
     bw.WriteByte(m_nnEntryData_115);
     bw.WriteByte(m_nnEntryData_116);
     bw.WriteByte(m_nnEntryData_117);
     bw.WriteByte(m_nnEntryData_118);
     bw.WriteByte(m_nnEntryData_119);
     bw.WriteByte(m_nnEntryData_120);
     bw.WriteByte(m_nnEntryData_121);
     bw.WriteByte(m_nnEntryData_122);
     bw.WriteByte(m_nnEntryData_123);
     bw.WriteByte(m_nnEntryData_124);
     bw.WriteByte(m_nnEntryData_125);
     bw.WriteByte(m_nnEntryData_126);
     bw.WriteByte(m_nnEntryData_127);
     bw.WriteByte(m_nnEntryData_128);
     bw.WriteByte(m_nnEntryData_129);
     bw.WriteByte(m_nnEntryData_130);
     bw.WriteByte(m_nnEntryData_131);
     bw.WriteByte(m_nnEntryData_132);
     bw.WriteByte(m_nnEntryData_133);
     bw.WriteByte(m_nnEntryData_134);
     bw.WriteByte(m_nnEntryData_135);
     bw.WriteByte(m_nnEntryData_136);
     bw.WriteByte(m_nnEntryData_137);
     bw.WriteByte(m_nnEntryData_138);
     bw.WriteByte(m_nnEntryData_139);
     bw.WriteByte(m_nnEntryData_140);
     bw.WriteByte(m_nnEntryData_141);
     bw.WriteByte(m_nnEntryData_142);
     bw.WriteByte(m_nnEntryData_143);
     bw.WriteByte(m_nnEntryData_144);
     bw.WriteByte(m_nnEntryData_145);
     bw.WriteByte(m_nnEntryData_146);
     bw.WriteByte(m_nnEntryData_147);
     bw.WriteByte(m_nnEntryData_148);
     bw.WriteByte(m_nnEntryData_149);
     bw.WriteByte(m_nnEntryData_150);
     bw.WriteByte(m_nnEntryData_151);
     bw.WriteByte(m_nnEntryData_152);
     bw.WriteByte(m_nnEntryData_153);
     bw.WriteByte(m_nnEntryData_154);
     bw.WriteByte(m_nnEntryData_155);
     bw.WriteByte(m_nnEntryData_156);
     bw.WriteByte(m_nnEntryData_157);
     bw.WriteByte(m_nnEntryData_158);
     bw.WriteByte(m_nnEntryData_159);
     bw.WriteByte(m_nnEntryData_160);
     bw.WriteByte(m_nnEntryData_161);
     bw.WriteByte(m_nnEntryData_162);
     bw.WriteByte(m_nnEntryData_163);
     bw.WriteByte(m_nnEntryData_164);
     bw.WriteByte(m_nnEntryData_165);
     bw.WriteByte(m_nnEntryData_166);
     bw.WriteByte(m_nnEntryData_167);
     bw.WriteByte(m_nnEntryData_168);
     bw.WriteByte(m_nnEntryData_169);
     bw.WriteByte(m_nnEntryData_170);
     bw.WriteByte(m_nnEntryData_171);
     bw.WriteByte(m_nnEntryData_172);
     bw.WriteByte(m_nnEntryData_173);
     bw.WriteByte(m_nnEntryData_174);
     bw.WriteByte(m_nnEntryData_175);
     bw.WriteByte(m_nnEntryData_176);
     bw.WriteByte(m_nnEntryData_177);
     bw.WriteByte(m_nnEntryData_178);
     bw.WriteByte(m_nnEntryData_179);
     bw.WriteByte(m_nnEntryData_180);
     bw.WriteByte(m_nnEntryData_181);
     bw.WriteByte(m_nnEntryData_182);
     bw.WriteByte(m_nnEntryData_183);
     bw.WriteByte(m_nnEntryData_184);
     bw.WriteByte(m_nnEntryData_185);
     bw.WriteByte(m_nnEntryData_186);
     bw.WriteByte(m_nnEntryData_187);
     bw.WriteByte(m_nnEntryData_188);
     bw.WriteByte(m_nnEntryData_189);
     bw.WriteByte(m_nnEntryData_190);
     bw.WriteByte(m_nnEntryData_191);
     m_trackInfo.Write(s, bw);
     bw.WriteByte(m_endianCheckBuffer_0);
     bw.WriteByte(m_endianCheckBuffer_1);
     bw.WriteByte(m_endianCheckBuffer_2);
     bw.WriteByte(m_endianCheckBuffer_3);
     bw.WriteUInt32(m_version);
     bw.WriteUInt64(0);
 }
コード例 #16
0
 public override void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     base.Write(s, bw);
     s.WriteClassPointer <hkbModifier>(bw, m_modifier);
     s.WriteClassPointer <hkbGenerator>(bw, m_generator);
 }
コード例 #17
0
ファイル: BemaniSSQ.cs プロジェクト: NoOnes2/scharfrichter
            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);
            }
コード例 #18
0
        private static void WriteCullingInfo(BinaryWriterEx bw, MESH_CULLING culling)
        {
            void WriteVector3(Vector3 v)
            {
                bw.WriteSingle(v.X);
                bw.WriteSingle(v.Y);
                bw.WriteSingle(v.Z);
            }

            void WriteVector2(Vector2 v)
            {
                bw.WriteSingle(v.X);
                bw.WriteSingle(v.Y);
            }

            long startPos = bw.BaseStream.Position;

            WriteSizedBlock(bw, () =>
            {
                bw.WriteInt32(culling.Type);
                bw.WriteInt32(culling.FromVertex);
                bw.WriteInt32(culling.VertexCount);
                bw.WriteInt32(culling.FromIndex);
                bw.WriteInt32(culling.IndexCount);

                long vertexOffsetPos = bw.BaseStream.Position;
                bw.Write(0);//dummy offset;

                int extraDataVal = 0;

                if (culling.AdjacentStuds != null && culling.AdjacentStuds.Length > 0)
                {
                    extraDataVal = 2;
                }
                else if (culling.Studs != null && culling.Studs.Length > 0)
                {
                    extraDataVal = 1;
                }

                bw.Write(extraDataVal);

                if (extraDataVal > 0)
                {
                    WriteSizedBlock(bw, () =>
                    {
                        int itemCount = culling.Studs?.Length ?? 0;
                        bw.Write(itemCount);
                        for (int i = 0; i < itemCount; i++)
                        {
                            WriteSizedBlock(bw, () =>
                            {
                                bw.Write(culling.Studs[i].ConnectorIndex);
                                bw.Write(culling.Studs[i].Indices.Length);
                                for (int j = 0; j < culling.Studs[i].Indices.Length; j++)
                                {
                                    bw.Write(culling.Studs[i].Indices[j].ArrayIndex);
                                    bw.Write(culling.Studs[i].Indices[j].Value2);
                                    bw.Write(culling.Studs[i].Indices[j].Value3);
                                    bw.Write(culling.Studs[i].Indices[j].Value4);
                                }
                            });
                        }
                    });
                }

                if (extraDataVal > 1)
                {
                    WriteSizedBlock(bw, () =>
                    {
                        int itemCount = culling.AdjacentStuds?.Length ?? 0;
                        bw.Write(itemCount);
                        for (int i = 0; i < itemCount; i++)
                        {
                            WriteSizedBlock(bw, () =>
                            {
                                bw.Write(culling.AdjacentStuds[i].ConnectorIndex);
                                bw.Write(culling.AdjacentStuds[i].Indices.Length);
                                for (int j = 0; j < culling.AdjacentStuds[i].Indices.Length; j++)
                                {
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].ArrayIndex);
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].Value2);
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].Value3);
                                    bw.Write(culling.AdjacentStuds[i].Indices[j].Value4);
                                }
                            });
                        }
                    });
                }

                if (culling.AlternateMesh != null)
                {
                    var cullingGeom        = culling.AlternateMesh.Value;
                    long currentPos        = bw.BaseStream.Position;
                    bw.BaseStream.Position = vertexOffsetPos;
                    bw.Write((int)(currentPos - startPos));
                    bw.BaseStream.Position = currentPos;

                    bw.WriteInt32(cullingGeom.Positions.Length);
                    bw.WriteInt32(cullingGeom.Indices.Length);

                    foreach (var pos in cullingGeom.Positions)
                    {
                        WriteVector3(pos);
                    }

                    foreach (var norm in cullingGeom.Normals)
                    {
                        WriteVector3(norm);
                    }

                    if (cullingGeom.UVs != null && cullingGeom.UVs.Length > 0)
                    {
                        foreach (var uv in cullingGeom.UVs)
                        {
                            WriteVector2(uv);
                        }
                    }

                    foreach (var index in cullingGeom.Indices)
                    {
                        bw.WriteInt32(index.VertexIndex);
                    }

                    foreach (var index in cullingGeom.Indices)
                    {
                        bw.WriteInt32(index.AverageNormalIndex);
                    }

                    foreach (var index in cullingGeom.Indices)
                    {
                        bw.WriteInt32(index.REShaderOffset);
                    }
                }
            });
        }
コード例 #19
0
ファイル: K054539.cs プロジェクト: NoOnes2/scharfrichter
 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);
 }
コード例 #20
0
        public static void WriteMeshFile(Stream stream, MESH_FILE meshFile)
        {
            using (var bw = new BinaryWriterEx(stream, Encoding.UTF8, true))
            {
                bw.WriteStruct(meshFile.Header);
                void WriteVector3(Vector3 v)
                {
                    bw.WriteSingle(v.X);
                    bw.WriteSingle(v.Y);
                    bw.WriteSingle(v.Z);
                }

                void WriteVector2(Vector2 v)
                {
                    bw.WriteSingle(v.X);
                    bw.WriteSingle(v.Y);
                }

                foreach (var pos in meshFile.Geometry.Positions)
                {
                    WriteVector3(pos);
                }

                foreach (var norm in meshFile.Geometry.Normals)
                {
                    WriteVector3(norm);
                }

                if (meshFile.Geometry.UVs != null && meshFile.Geometry.UVs.Length > 0)
                {
                    foreach (var uv in meshFile.Geometry.UVs)
                    {
                        WriteVector2(uv);
                    }
                }

                for (int i = 0; i < meshFile.Header.IndexCount; i++)
                {
                    bw.WriteInt32(meshFile.Geometry.Indices[i].VertexIndex);
                }


                //Round Edge Shader Data
                {
                    var allShaderData = meshFile.RoundEdgeShaderData.SelectMany(x => x.Coords).ToList();

                    bw.WriteInt32(allShaderData.Count * 2);
                    foreach (var shaderCoord in allShaderData)
                    {
                        WriteVector2(shaderCoord);
                    }

                    for (int i = 0; i < meshFile.Header.IndexCount; i++)
                    {
                        bw.WriteInt32(meshFile.Geometry.Indices[i].REShaderOffset);
                    }
                }

                //Average Normals
                {
                    bw.WriteInt32(meshFile.AverageNormals.Length + 1);
                    WriteVector3(new Vector3(83, 0, 0));

                    foreach (var avgNorm in meshFile.AverageNormals)
                    {
                        WriteVector3(avgNorm);
                    }

                    for (int i = 0; i < meshFile.Header.IndexCount; i++)
                    {
                        bw.WriteInt32(meshFile.Geometry.Indices[i].AverageNormalIndex);
                    }
                }

                if (meshFile.Geometry.Bones != null && meshFile.Geometry.Bones.Length > 0)
                {
                    //TODO: If flexible alternate meshes are supported, improve this code to include alternate meshes bones
                    //      and a way to retrieve the correct offsets in WriteCullingInfo

                    var allBones     = meshFile.Geometry.Bones.SelectMany(x => x.BoneWeights).ToList();
                    int boneDataSize = (allBones.Count * 8) + (meshFile.Header.VertexCount * 4);
                    bw.WriteInt32(boneDataSize);

                    var dataOffsets = new List <int>();
                    int totalOffset = 0;

                    for (int i = 0; i < meshFile.Header.VertexCount; i++)
                    {
                        var vertexBones = meshFile.Geometry.Bones[i];
                        bw.WriteInt32(vertexBones.BoneWeights.Length);
                        for (int j = 0; j < vertexBones.BoneWeights.Length; j++)
                        {
                            bw.WriteInt32(vertexBones.BoneWeights[j].BoneID);
                            bw.WriteSingle(vertexBones.BoneWeights[j].Weight);
                        }
                        //bone count (4 bytes) + bones data (id + weight = 8 bytes)
                        dataOffsets.Add(totalOffset);
                        totalOffset += 4 + (vertexBones.BoneWeights.Length * 8);
                    }

                    for (int i = 0; i < meshFile.Header.VertexCount; i++)
                    {
                        bw.WriteInt32(dataOffsets[i]);
                    }
                }

                //Mesh Culling Info
                {
                    bw.WriteInt32(meshFile.Cullings.Length);
                    WriteSizedBlock(bw, () =>
                    {
                        for (int i = 0; i < meshFile.Cullings.Length; i++)
                        {
                            WriteCullingInfo(bw, meshFile.Cullings[i]);
                        }
                    }, false);
                }
            }
        }
コード例 #21
0
ファイル: LabelFeatureData.cs プロジェクト: zbxzc35/BoostTree
        //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);
            }
        }
コード例 #22
0
ファイル: Vertex.cs プロジェクト: rjayhub/CTR-tools
 public void Write(BinaryWriterEx bw)
 {
     coord.Write(bw);
     color.Write(bw);
     color_morph.Write(bw);
 }
コード例 #23
0
ファイル: LabelFeatureData.cs プロジェクト: zbxzc35/BoostTree
        //seralize the Object
        override public void Save(string binFileName)
        {
#if FORMATTER
            FileStream fileStream = new FileStream(binFileName, FileMode.Create);
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(fileStream, this);
            fileStream.Close();
#else //FORMATTER
            BinaryWriterEx binWriterEx = new BinaryWriterEx(binFileName);
            this.Serialize(binWriterEx);
            binWriterEx.Close();
#endif //FORMATTER
        }
コード例 #24
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     m_aabb.Write(s, bw);
 }
コード例 #25
0
 public virtual void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     bw.WriteInt32(m_firstTargetIdx);
     bw.WriteInt32(m_numTargets);
     s.WriteClassPointer <hkpConstraintInstance>(bw, m_limitConstraint);
 }
コード例 #26
0
 public override void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     base.Write(s, bw);
 }
コード例 #27
0
ファイル: CDNClient.cs プロジェクト: Top-Cat/SteamBot
        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);
        }
コード例 #28
0
 public override void Write(PackFileSerializer s, BinaryWriterEx bw)
 {
     base.Write(s, bw);
     bw.WriteUInt64(0);
     m_motionState.Write(s, bw);
 }