System.IO.BinaryWriter.Write(int)

Here are the examples of the csharp api System.IO.BinaryWriter.Write(int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2220 Examples 7

19 View Source File : ExifWriter.cs
License : MIT License
Project Creator : 0xC0000054

private void WriteDirectory(BinaryWriter writer, Dictionary<ushort, MetadataEntry> tags, List<IFDEntry> entries, long ifdOffset)
        {
            writer.BaseStream.Position = ifdOffset;

            long nextIFDPointerOffset = ifdOffset + sizeof(ushort) + ((long)entries.Count * IFDEntry.SizeOf);

            writer.Write((ushort)entries.Count);

            foreach (IFDEntry entry in entries.OrderBy(e => e.Tag))
            {
                entry.Write(writer);

                if (!TagDataTypeUtil.ValueFitsInOffsetField(entry.Type, entry.Count))
                {
                    long oldPosition = writer.BaseStream.Position;

                    writer.BaseStream.Position = entry.Offset;

                    writer.Write(tags[entry.Tag].GetDataReadOnly());

                    writer.BaseStream.Position = oldPosition;
                }
            }

            writer.BaseStream.Position = nextIFDPointerOffset;
            // There is only one IFD in this directory.
            writer.Write(0);
        }

19 View Source File : ExifWriter.cs
License : MIT License
Project Creator : 0xC0000054

private void WriteDirectory(BinaryWriter writer, Dictionary<ushort, MetadataEntry> tags,  List<IFDEntry> entries, long ifdOffset)
        {
            writer.BaseStream.Position = ifdOffset;

            long nextIFDPointerOffset = ifdOffset + sizeof(ushort) + ((long)entries.Count * IFDEntry.SizeOf);

            writer.Write((ushort)entries.Count);

            foreach (IFDEntry entry in entries.OrderBy(e => e.Tag))
            {
                entry.Write(writer);

                if (!TagDataTypeUtil.ValueFitsInOffsetField(entry.Type, entry.Count))
                {
                    long oldPosition = writer.BaseStream.Position;

                    writer.BaseStream.Position = entry.Offset;

                    writer.Write(tags[entry.Tag].GetDataReadOnly());

                    writer.BaseStream.Position = oldPosition;
                }
            }

            writer.BaseStream.Position = nextIFDPointerOffset;
            // There is only one IFD in this directory.
            writer.Write(0);
        }

19 View Source File : UEStringProperty.cs
License : MIT License
Project Creator : 13xforever

public override void Serialize(BinaryWriter writer)
        {
            if (Value == null)
            {
                writer.Write(0L);
                writer.Write((byte)0);
            }
            else
            {
                var bytes = Utf8.GetBytes(Value);
                writer.Write(bytes.Length + 6L);
                writer.Write((byte)0);
                writer.Write(bytes.Length+1);
                if (bytes.Length > 0)
                    writer.Write(bytes);
                writer.Write((byte)0);
            }
        }

19 View Source File : BinaryReaderEx.cs
License : MIT License
Project Creator : 13xforever

public static void WriteUEString(this BinaryWriter writer, string value)
        {
            if (value == null)
            {
                writer.Write(0);
                return;
            }

            var valueBytes = Utf8.GetBytes(value);
            writer.Write(valueBytes.Length + 1);
            if (valueBytes.Length > 0)
                writer.Write(valueBytes);
            writer.Write((byte)0);
        }

19 View Source File : WaveFormat.cs
License : MIT License
Project Creator : 3wz

public virtual void Serialize(BinaryWriter writer)
        {
            writer.Write((int)(18 + extraSize)); // wave format length
            writer.Write((short)Encoding);
            writer.Write((short)Channels);
            writer.Write((int)SampleRate);
            writer.Write((int)AverageBytesPerSecond);
            writer.Write((short)BlockAlign);
            writer.Write((short)BitsPerSample);
            writer.Write((short)extraSize);
        }

19 View Source File : WaveFormatExtensible.cs
License : MIT License
Project Creator : 3wz

public override void Serialize(System.IO.BinaryWriter writer)
        {
            base.Serialize(writer);
            writer.Write(wValidBitsPerSample);
            writer.Write(dwChannelMask);
            byte[] guid = subFormat.ToByteArray();
            writer.Write(guid, 0, guid.Length);
        }

19 View Source File : EncodingUtil.cs
License : MIT License
Project Creator : 404Lcc

public static byte[] LengthEncode(byte[] bytes)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(bytes.Length);
                    writer.Write(bytes);
                    bytes = stream.ToArray();
                }
            }
            return bytes;
        }

19 View Source File : TLV_050C.cs
License : MIT License
Project Creator : 499116344

public byte[] Get_Tlv(QQUser user)
        {
            var buf = new BinaryWriter(new MemoryStream());
            var dataTime = DateTime.Now;
            buf.BeWrite(0);
            buf.BeWrite(user.QQ);
            buf.Write(new byte[] { 0x76, 0x71, 0x01, 0x9d });
            buf.BeWrite(Util.GetTimeMillis(dataTime));
            buf.BeWrite(user.TXProtocol.DwServiceId);
            buf.Write(new byte[]
                { 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x00, 0x04, 0x5f, 0x80, 0x33, 0x01, 0x01 });
            buf.BeWrite(user.TXProtocol.DwClientVer);
            buf.Write(new byte[]
                { 0x66, 0x35, 0x4d, 0xf1, 0xab, 0xdc, 0x98, 0xf0, 0x70, 0x69, 0xfc, 0x2a, 0x2b, 0x86, 0x06, 0x1b });
            buf.BeWrite(user.TXProtocol.SubVer);

            var data = new BinaryWriter(new MemoryStream());
            data.BeWrite(0);
            data.BeWrite(user.QQ);
            data.Write(new byte[] { 0x76, 0x71, 0x01, 0x9d });
            data.BeWrite(Util.GetTimeMillis(dataTime));
            data.Write(user.TXProtocol.DwPubNo);

            buf.Write((byte) data.BaseStream.Length * 3);
            buf.Write(data.BaseStream.ToBytesArray());
            buf.Write(data.BaseStream.ToBytesArray());
            buf.Write(data.BaseStream.ToBytesArray());


            FillHead(Command);
            FillBody(buf.BaseStream.ToBytesArray(), buf.BaseStream.Length);
            SetLength();
            return GetBuffer();
        }

19 View Source File : SimpleJSON.cs
License : MIT License
Project Creator : 734843327

public override void Serialize (System.IO.BinaryWriter aWriter)
		{
			aWriter.Write((byte)JSONBinaryTag.Array);
			aWriter.Write(m_List.Count);
			for(int i = 0; i < m_List.Count; i++)
			{
				m_List[i].Serialize(aWriter);
			}
		}

19 View Source File : SimpleJSON.cs
License : MIT License
Project Creator : 734843327

public override void Serialize (System.IO.BinaryWriter aWriter)
		{
			aWriter.Write((byte)JSONBinaryTag.Clreplaced);
			aWriter.Write(m_Dict.Count);
			foreach(string K in m_Dict.Keys)
			{
				aWriter.Write(K);
				m_Dict[K].Serialize(aWriter);
			}
		}

19 View Source File : SimpleJSON.cs
License : MIT License
Project Creator : 734843327

public override void Serialize (System.IO.BinaryWriter aWriter)
		{
			var tmp = new JSONData("");
			
			tmp.AsInt = AsInt;
			if (tmp.m_Data == this.m_Data)
			{
				aWriter.Write((byte)JSONBinaryTag.IntValue);
				aWriter.Write(AsInt);
				return;
			}
			tmp.AsFloat = AsFloat;
			if (tmp.m_Data == this.m_Data)
			{
				aWriter.Write((byte)JSONBinaryTag.FloatValue);
				aWriter.Write(AsFloat);
				return;
			}
			tmp.AsDouble = AsDouble;
			if (tmp.m_Data == this.m_Data)
			{
				aWriter.Write((byte)JSONBinaryTag.DoubleValue);
				aWriter.Write(AsDouble);
				return;
			}

			tmp.AsBool = AsBool;
			if (tmp.m_Data == this.m_Data)
			{
				aWriter.Write((byte)JSONBinaryTag.BoolValue);
				aWriter.Write(AsBool);
				return;
			}
			aWriter.Write((byte)JSONBinaryTag.Value);
			aWriter.Write(m_Data);
		}

19 View Source File : IPCSupport.cs
License : GNU General Public License v3.0
Project Creator : 9E4ECDDE

public void Send(Message messageType, string boneName, object data)
            {
                if (!IsConnected) throw new InvalidOperationException("Tried to send a message but the pipe is disconnected.");
                switch (messageType)
                {
                    case Message.SetBoneData:
                        {
                            if (!IsServer) throw new InvalidOperationException("GetBoneData can only be called from the server.");
                            pipeWriter.Write((int)Message.SetBoneData);
                            pipeWriter.Write((byte[])data);
                            break;
                        }
                    case Message.SetBoneDamping:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneDamping can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneDamping);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneElasticity:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneElasticity can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneElasticity);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneStiffness:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneStiffness can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneStiffness);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneInert:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneInert can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneInert);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneRadius:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneRadius can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneRadius);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneEndLength:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneEndLength can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneEndLength);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneEndOffset:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneEndOffset can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneEndOffset);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write(((float3)data).x);
                            pipeWriter.Write(((float3)data).y);
                            pipeWriter.Write(((float3)data).z);
                            break;
                        }
                    case Message.SetBoneGravity:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneGravity can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneGravity);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write(((float3)data).x);
                            pipeWriter.Write(((float3)data).y);
                            pipeWriter.Write(((float3)data).z);
                            break;
                        }
                    case Message.SetBoneForce:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneForce can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneForce);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write(((float3)data).x);
                            pipeWriter.Write(((float3)data).y);
                            pipeWriter.Write(((float3)data).z);
                            break;
                        }
                }
                pipe.WaitForPipeDrain();
            }

19 View Source File : IPCSupport.cs
License : GNU General Public License v3.0
Project Creator : 9E4ECDDE

public byte[] ToByteArray()
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (BinaryWriter binaryWriter = new BinaryWriter(ms))
                    {
                        binaryWriter.Write(name);
                        binaryWriter.Write(boneCount);
                        List<byte[]> bonesBytes = new List<byte[]>(bones.Select((b) => b.ToByteArray()));
                        foreach (byte[] boneByteData in bonesBytes)
                        {
                            binaryWriter.Write(boneByteData.Length);
                            binaryWriter.Write(boneByteData);
                        }
                        return ms.ToArray();
                    }
                }
            }

19 View Source File : IPCSupport.cs
License : GNU General Public License v3.0
Project Creator : 9E4ECDDE

public void Send(Message messageType, string boneName, object data)
            {
                if (!IsConnected) throw new InvalidOperationException("Tried to send a message but the pipe is disconnected.");
                switch (messageType)
                {
                    case Message.SetBoneData:
                        {
                            if (!IsServer) throw new InvalidOperationException("GetBoneData can only be called from the server.");
                            pipeWriter.Write((int)Message.SetBoneData);
                            pipeWriter.Write((byte[])data);
                            break;
                        }
                    case Message.SetBoneDamping:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneDamping can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneDamping);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneElasticity:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneElasticity can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneElasticity);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneStiffness:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneStiffness can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneStiffness);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneInert:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneInert can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneInert);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneRadius:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneRadius can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneRadius);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneEndLength:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneEndLength can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneEndLength);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write((float)data);
                            break;
                        }
                    case Message.SetBoneEndOffset:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneEndOffset can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneInert);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write(((float3)data).x);
                            pipeWriter.Write(((float3)data).y);
                            pipeWriter.Write(((float3)data).z);
                            break;
                        }
                    case Message.SetBoneGravity:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneGravity can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneGravity);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write(((float3)data).x);
                            pipeWriter.Write(((float3)data).y);
                            pipeWriter.Write(((float3)data).z);
                            break;
                        }
                    case Message.SetBoneForce:
                        {
                            if (IsServer) throw new InvalidOperationException("SetBoneForce can only be called from the client.");
                            pipeWriter.Write((int)Message.SetBoneInert);
                            pipeWriter.Write(boneName);
                            pipeWriter.Write(((float3)data).x);
                            pipeWriter.Write(((float3)data).y);
                            pipeWriter.Write(((float3)data).z);
                            break;
                        }
                }

            }

19 View Source File : UmaTPose.cs
License : Apache License 2.0
Project Creator : A7ocin

private void Serialize(BinaryWriter bn, SkeletonBone bone)
	    {
	        bn.Write(bone.name);
	        Serialize(bn, bone.position);
	        Serialize(bn, bone.rotation);
	        Serialize(bn, bone.scale);
	        bn.Write((int)1);
	    }

19 View Source File : UmaTPose.cs
License : Apache License 2.0
Project Creator : A7ocin

public void Serialize()
	    {
	        var ms = new MemoryStream();
	        var bn = new BinaryWriter(ms);
	        bn.Write(boneInfo.Length);
	        foreach(var bi in boneInfo)
	        {
	            Serialize(bn, bi);
	        }
	        bn.Write(humanInfo.Length);
	        foreach (var hi in humanInfo)
	        {
	            Serialize(bn, hi);
	        }
			if (extendedInfo)
			{
				bn.Write(armStretch);
				bn.Write(feetSpacing);
				bn.Write(legStretch);
				bn.Write(lowerArmTwist);
				bn.Write(lowerLegTwist);
				bn.Write(upperArmTwist);
				bn.Write(upperLegTwist);
			}
	        serializedChunk = ms.ToArray();
	    }

19 View Source File : InputAnimationSerializationUtils.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

public static void WriteHeader(BinaryWriter writer)
        {
            writer.Write(Magic);
            writer.Write(VersionMajor);
            writer.Write(VersionMinor);
        }

19 View Source File : InputAnimationSerializationUtils.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

public static void WriteFloatCurve(BinaryWriter writer, AnimationCurve curve, float startTime)
        {
            writer.Write((int)curve.preWrapMode);
            writer.Write((int)curve.postWrapMode);

            writer.Write(curve.length);
            for (int i = 0; i < curve.length; ++i)
            {
                var keyframe = curve.keys[i];
                writer.Write(keyframe.time - startTime);
                writer.Write(keyframe.value);
                writer.Write(keyframe.inTangent);
                writer.Write(keyframe.outTangent);
                writer.Write(keyframe.inWeight);
                writer.Write(keyframe.outWeight);
                writer.Write((int)keyframe.weightedMode);
            }
        }

19 View Source File : InputAnimationSerializationUtils.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

public static void WriteBoolCurve(BinaryWriter writer, AnimationCurve curve, float startTime)
        {
            writer.Write((int)curve.preWrapMode);
            writer.Write((int)curve.postWrapMode);

            writer.Write(curve.length);
            for (int i = 0; i < curve.length; ++i)
            {
                var keyframe = curve.keys[i];
                writer.Write(keyframe.time - startTime);
                writer.Write(keyframe.value);
            }
        }

19 View Source File : InputAnimationSerializationUtils.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

public static void WriteMarkerList(BinaryWriter writer, List<InputAnimationMarker> markers, float startTime)
        {
            writer.Write(markers.Count);
            foreach (var marker in markers)
            {
                writer.Write(marker.time - startTime);
                writer.Write(marker.name);
            }
        }

19 View Source File : RemoteLoopbackManager.cs
License : MIT License
Project Creator : absurd-joy

void OnLocalAvatarPacketRecorded(object sender, OvrAvatar.PacketEventArgs args)
    {
        using (MemoryStream outputStream = new MemoryStream())
        {
            BinaryWriter writer = new BinaryWriter(outputStream);

            if (LocalAvatar.UseSDKPackets)
            {
                var size = CAPI.ovrAvatarPacket_GetSize(args.Packet.ovrNativePacket);
                byte[] data = new byte[size];
                CAPI.ovrAvatarPacket_Write(args.Packet.ovrNativePacket, size, data);

                writer.Write(PacketSequence++);
                writer.Write(size);
                writer.Write(data);
            }
            else
            {
                writer.Write(PacketSequence++);
                args.Packet.Write(outputStream);
            }

            SendPacketData(outputStream.ToArray());
        }
    }

19 View Source File : OvrAvatarPacket.cs
License : MIT License
Project Creator : absurd-joy

public void Write(Stream stream)
    {
        BinaryWriter writer = new BinaryWriter(stream);

        // Write all of the frames
        int frameCount = frameTimes.Count;
        writer.Write(frameCount);
        for (int i = 0; i < frameCount; ++i)
        {
            writer.Write(frameTimes[i]);
        }
        for (int i = 0; i < frameCount; ++i)
        {
            OvrAvatarDriver.PoseFrame frame = frames[i];
            writer.Write(frame);
        }

        // Write all of the encoded audio packets
        int audioPacketCount = encodedAudioPackets.Count;
        writer.Write(audioPacketCount);
        for (int i = 0; i < audioPacketCount; ++i)
        {
            byte[] packet = encodedAudioPackets[i];
            writer.Write(packet.Length);
            writer.Write(packet);
        }
    }

19 View Source File : DataEntry.cs
License : MIT License
Project Creator : absurd-joy

public byte[] Serialize()
		{
			using (MemoryStream m = new MemoryStream())
			{
				using (BinaryWriter writer = new BinaryWriter(m))
				{
					// Limit our string to BUFFER_SIZE
					if (textString.Length > Constants.BUFFER_SIZE)
					{
						textString = textString.Substring(0, Constants.BUFFER_SIZE-1);
					}
					writer.Write(packetID);
					writer.Write(textString.ToCharArray());
					writer.Write('\0');
				}
				return m.ToArray();
			}
		}

19 View Source File : Wave.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void ReadData(Stream stream)
        {
            var binaryWriter = new BinaryWriter(stream);

            binaryWriter.Write(System.Text.Encoding.ASCII.GetBytes("RIFF"));

            uint filesize = (uint)(Data.Length + 36); // 36 is added for all the extra we're adding for the WAV header format
            binaryWriter.Write(filesize);

            binaryWriter.Write(System.Text.Encoding.ASCII.GetBytes("WAVE"));

            binaryWriter.Write(System.Text.Encoding.ASCII.GetBytes("fmt"));
            binaryWriter.Write((byte)0x20); // Null ending to the fmt

            binaryWriter.Write((int)0x10); // 16 ... length of all the above

            // AC audio headers start at Format Type,
            // and are usually 18 bytes, with some exceptions
            // notably objectID A000393 which is 30 bytes

            // WAV headers are always 16 bytes from Format Type to end of header,
            // so this extra data is truncated here.
            binaryWriter.Write(Header.Take(16).ToArray());

            binaryWriter.Write(System.Text.Encoding.ASCII.GetBytes("data"));
            binaryWriter.Write((uint)Data.Length);
            binaryWriter.Write(Data);
        }

19 View Source File : Position.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Serialize(BinaryWriter payload, PositionFlags positionFlags, int animationFrame, bool writeLandblock = true)
        {
            payload.Write((uint)positionFlags);

            if (writeLandblock)
                payload.Write(LandblockId.Raw);

            payload.Write(PositionX);
            payload.Write(PositionY);
            payload.Write(PositionZ);

            if ((positionFlags & PositionFlags.OrientationHasNoW) == 0)
                payload.Write(RotationW);

            if ((positionFlags & PositionFlags.OrientationHasNoX) == 0)
                payload.Write(RotationX);

            if ((positionFlags & PositionFlags.OrientationHasNoY) == 0)
                payload.Write(RotationY);

            if ((positionFlags & PositionFlags.OrientationHasNoZ) == 0)
                payload.Write(RotationZ);

            if ((positionFlags & PositionFlags.HasPlacementID) != 0)
                // TODO: this is current animationframe_id when we are animating (?) - when we are not, how are we setting on the ground Position_id.
                payload.Write(animationFrame);

            if ((positionFlags & PositionFlags.HasVelocity) != 0)
            {
                // velocity would go here
                payload.Write(0f);
                payload.Write(0f);
                payload.Write(0f);
            }
        }

19 View Source File : ChessPieceCoord.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, ChessPieceCoord coord)
        {
            writer.Write(coord.X);
            writer.Write(coord.Y);
        }

19 View Source File : Fellowship.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, Dictionary<uint, int> departedFellows)
        {
            PackableHashTable.WriteHeader(writer, departedFellows.Count, hashComparer.NumBuckets);

            var sorted = new SortedDictionary<uint, int>(departedFellows, hashComparer);

            foreach (var departed in sorted)
            {
                writer.Write(departed.Key);
                writer.Write(departed.Value);
            }
        }

19 View Source File : AppraiseInfo.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, Dictionary<PropertyInt, int> _properties)
        {
            PackableHashTable.WriteHeader(writer, _properties.Count, PropertyIntComparer.NumBuckets);

            var properties = new SortedDictionary<PropertyInt, int>(_properties, PropertyIntComparer);

            foreach (var kvp in properties)
            {
                writer.Write((uint)kvp.Key);
                writer.Write(kvp.Value);
            }
        }

19 View Source File : Shortcut.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, ICollection<Shortcut> shortcuts)
        {
            writer.Write(shortcuts.Count);
            foreach (var shortcut in shortcuts)
                writer.Write(shortcut);
        }

19 View Source File : SquelchInfo.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<SquelchMask> filters)
        {
            writer.Write(filters.Count);
            foreach (var filter in filters)
                writer.Write((uint)filter);
        }

19 View Source File : AllegianceHierarchy.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, AllegianceHierarchy hierarchy)
        {
            // ushort - recordCount - Number of character allegiance records
            // ushort - oldVersion = 0x000B - Defines which properties are available. 0x000B seems to be the latest version which includes all properties.
            // Dictionary<ObjectID, AllegianceOfficerLevel> - officers - Taking a guess on these values. Guessing they may only be valid for Monarchs
            //                                                           A list of officers and their officer levels?
            // List<string> - officerreplacedles - Believe these may preplaced in the current officer replacedle list. Guessing they may only be valid on Monarchs.
            // uint - monarchBroadcastTime - May only be valid for Monarchs/Speakers?
            // uint - monarchBroadcastsToday - May only be valid for Monarchs/Speakers?
            // uint - spokesBroadcastTime - May only be valid for Monarchs/Speakers?
            // uint - spokesBroadcastsToday - May only be valid for Monarchs/Speakers?
            // string - motd - Text for current Message of the Day. May only be valid for Monarchs/Speakers?
            // string - motdSetBy - Who set the current Message of the Day. May only be valid for Monarchs/Speakers?
            // uint - chatRoomID - allegiance chat channel number
            // Position - bindpoint - Location of monarchy bindpoint
            // string - allegianceName - The name of the allegiance.
            // uint - nameLastSetTime - Time name was last set. Seems to count upward for some reason.
            // bool - isLocked - Whether allegiance is locked.
            // int - approvedVreplacedal - ??
            // AllegianceData - monarchData - Monarch's data

            // records: vector of length recordCount - 1
            // ObjectID - treeParent - The ObjectID for the parent character to this character. Used by the client to decide how to build the display in the Allegiance tab. 1 is the monarch.
            // AllegianceData - allegianceData

            // recordCount = Monarch + Patron + Vreplacedals?
            // 2 in data for small allegiances?
            ushort recordCount = 0;
            ushort oldVersion = 0x000B;
            var officers = new Dictionary<ObjectGuid, AllegianceOfficerLevel>();
            var officerreplacedles = new List<string>();
            uint monarchBroadcastTime = 0;
            uint monarchBroadcastsToday = 0;
            uint spokesBroadcastTime = 0;
            uint spokesBroadcastsToday = 0;
            var motd = "";
            var motdSetBy = "";
            uint chatRoomID = 0;
            var bindPoint = new Position();
            var allegianceName = "";
            uint nameLastSetTime = 0;
            bool isLocked = false;
            int approvedVreplacedal = 0;
            AllegianceData monarchData = null;
            List<Tuple<ObjectGuid, AllegianceData>> records = null;

            var allegiance = hierarchy.Profile.Allegiance;
            var node = hierarchy.Profile.Node;

            if (allegiance != null && node != null)
            {
                // only send these to monarch?
                //foreach (var officer in allegiance.Officers)
                    //officers.Add(officer.Key, (AllegianceOfficerLevel)officer.Value.Player.AllegianceOfficerRank);

                // not in retail packets, breaks decal
                /*if (allegiance.HasCustomreplacedles)
                {
                    officerreplacedles.Add(allegiance.GetOfficerreplacedle(AllegianceOfficerLevel.Speaker));
                    officerreplacedles.Add(allegiance.GetOfficerreplacedle(AllegianceOfficerLevel.Seneschal));
                    officerreplacedles.Add(allegiance.GetOfficerreplacedle(AllegianceOfficerLevel.Castellan));
                }*/

                allegianceName = allegiance.AllegianceName ?? allegiance.Monarch.Player.Name;
                //motd = allegiance.AllegianceMotd ?? "";
                //motdSetBy = allegiance.AllegianceMotdSetBy ?? "";
                motd = "";          // fixes decal AllegianceUpdate parsing
                motdSetBy = "";
                chatRoomID = allegiance.Biota.Id;

                if (allegiance.Sanctuary != null)
                    bindPoint = allegiance.Sanctuary;

                // aclogview (verify):
                // i == 0 : monarch (no guid)
                // i == 1 : patron
                // i == 2 : peer?
                // i  > 2 : vreplacedals

                // peers = others with the same patron?

                recordCount = 1;    // monarch
                if (node.Patron != null && !node.Patron.IsMonarch)  // patron
                    recordCount++;
                if (!node.IsMonarch)    // self
                    recordCount++;
                if (node.TotalVreplacedals > 0)  // vreplacedals
                {
                    recordCount += (ushort)node.TotalVreplacedals;
                }
                //Console.WriteLine("Records: " + recordCount);

                // monarch
                monarchData = new AllegianceData(allegiance.Monarch);

                if (recordCount > 1)
                {
                    records = new List<Tuple<ObjectGuid, AllegianceData>>();

                    // patron
                    if (node.Patron != null && !node.Patron.IsMonarch)
                    {
                        records.Add(new Tuple<ObjectGuid, AllegianceData>(node.Monarch.PlayerGuid, new AllegianceData(node.Patron)));
                    }

                    // self
                    if (!node.IsMonarch)
                        records.Add(new Tuple<ObjectGuid, AllegianceData>(node.Patron.PlayerGuid, new AllegianceData(node)));

                    // vreplacedals
                    if (node.TotalVreplacedals > 0)
                    {
                        foreach (var vreplacedal in node.Vreplacedals.Values)
                            records.Add(new Tuple<ObjectGuid, AllegianceData>(node.PlayerGuid, new AllegianceData(vreplacedal)));
                    }
                }
            }

            writer.Write(recordCount);
            writer.Write(oldVersion);
            writer.Write(officers);
            writer.Write(officerreplacedles);
            writer.Write(monarchBroadcastTime);
            writer.Write(monarchBroadcastsToday);
            writer.Write(spokesBroadcastTime);
            writer.Write(spokesBroadcastsToday);
            writer.WriteString16L(motd);
            writer.WriteString16L(motdSetBy);
            writer.Write(chatRoomID);
            writer.Write(bindPoint);
            writer.WriteString16L(allegianceName);
            writer.Write(nameLastSetTime);
            writer.Write(Convert.ToUInt32(isLocked));
            writer.Write(approvedVreplacedal);

            if (monarchData != null)
                writer.Write(monarchData);

            if (records != null)
                writer.Write(records);
        }

19 View Source File : AllegianceHierarchy.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<string> strings)
        {
            writer.Write(strings.Count);
            foreach (var str in strings)
                writer.WriteString16L(str);
        }

19 View Source File : Enchantment.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<Enchantment> enchantments)
        {
            writer.Write(enchantments.Count);
            foreach (var enchantment in enchantments)
                writer.Write(enchantment);
        }

19 View Source File : ChessMoveData.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, ChessMoveData data)
        {
            writer.Write((int)data.Type);
            writer.Write(data.PlayerGuid.Full);
            //writer.Write((int)data.Color);

            // only ChessMoveType.FromTo used?
            switch (data.Type)
            {
                case ChessMoveType.Grid:
                    // xgrid / ygrid?
                    writer.Write(data.To);
                    break;

                case ChessMoveType.FromTo:
                    //writer.Write(data.PieceGuid.Full);
                    writer.Write(data.From);
                    writer.Write(data.To);
                    break;

                case ChessMoveType.SelectedPiece:
                    writer.Write(data.PieceGuid.Full);
                    break;
            }
        }

19 View Source File : HouseAccess.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<ObjectGuid> roommates)
        {
            // unused in client ui

            writer.Write(roommates.Count);

            foreach (var roommate in roommates)
                writer.Write(roommate.Full);
        }

19 View Source File : HousePayment.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, HousePayment payment)
        {
            writer.Write(payment.Num);
            writer.Write(payment.Paid);
            writer.Write(payment.WeenieID);
            writer.WriteString16L(payment.Name);
            writer.WriteString16L(payment.PluralName);
        }

19 View Source File : HousePayment.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<HousePayment> payments)
        {
            if (payments == null)
                payments = new List<HousePayment>();

            writer.Write(payments.Count);
            foreach (var payment in payments)
                writer.Write(payment);
        }

19 View Source File : HouseProfile.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, HouseProfile profile)
        {
            writer.Write(profile.DwellingID);
            writer.Write(profile.OwnerID.Full);
            writer.Write((uint)profile.Bitmask);
            writer.Write(profile.MinLevel);
            writer.Write(profile.MaxLevel);
            writer.Write(profile.MinAllegRank);
            writer.Write(profile.MaxAllegRank);
            writer.Write(Convert.ToUInt32(profile.MaintenanceFree));
            writer.Write((uint)profile.Type);
            writer.WriteString16L(profile.OwnerName);
            writer.Write(profile.Buy);
            writer.Write(profile.Rent);
        }

19 View Source File : LayeredSpell.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<LayeredSpell> spells)
        {
            writer.Write(spells.Count);
            foreach (var spell in spells)
                writer.Write(spell);
        }

19 View Source File : LayeredSpell.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<PropertiesEnchantmentRegistry> enchantments)
        {
            writer.Write(enchantments.Count);
            foreach (var enchantment in enchantments)
                writer.Write(enchantment);
        }

19 View Source File : PackableList.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static void Write(this BinaryWriter writer, List<uint> list)
        {
            writer.Write(list.Count);
            foreach (var item in list)
                writer.Write(item);
        }

19 View Source File : BasicBlockSerializer.cs
License : GNU General Public License v3.0
Project Creator : Aekras1a

public void WriteData(ILBlock block, BinaryWriter writer)
        {
            uint offset = 0;
            SequencePoint prevSeq = null;
            uint prevOffset = 0;
            foreach(var instr in block.Content)
            {
                if(rt.dbgWriter != null && instr.IR.ILAST is ILASTExpression)
                {
                    var expr = (ILASTExpression) instr.IR.ILAST;
                    var seq = expr.CILInstr == null ? null : expr.CILInstr.SequencePoint;

                    if(seq != null && seq.StartLine != 0xfeefee && (prevSeq == null || !Equals(seq, prevSeq)))
                    {
                        if(prevSeq != null)
                        {
                            uint len = offset - prevOffset, line = (uint) prevSeq.StartLine;
                            var doc = prevSeq.Doreplacedent.Url;

                            rt.dbgWriter.AddSequencePoint(block, prevOffset, len, doc, line);
                        }
                        prevSeq = seq;
                        prevOffset = offset;
                    }
                }

                writer.Write(rt.Descriptor.Architecture.OpCodes[instr.OpCode]);
                // Leave a padding to let BasicBlockChunk fixup block exit key
                writer.Write((byte) rt.Descriptor.Random.Next());
                offset += 2;

                if(instr.Operand != null)
                    if(instr.Operand is ILRegister)
                    {
                        writer.Write(rt.Descriptor.Architecture.Registers[((ILRegister) instr.Operand).Register]);
                        offset++;
                    }
                    else if(instr.Operand is ILImmediate)
                    {
                        var value = ((ILImmediate) instr.Operand).Value;
                        if(value is int)
                        {
                            writer.Write((int) value);
                            offset += 4;
                        }
                        else if(value is uint)
                        {
                            writer.Write((uint) value);
                            offset += 4;
                        }
                        else if(value is long)
                        {
                            writer.Write((long) value);
                            offset += 8;
                        }
                        else if(value is ulong)
                        {
                            writer.Write((ulong) value);
                            offset += 8;
                        }
                        else if(value is float)
                        {
                            writer.Write((float) value);
                            offset += 4;
                        }
                        else if(value is double)
                        {
                            writer.Write((double) value);
                            offset += 8;
                        }
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
            }

            if(prevSeq != null)
            {
                uint len = offset - prevOffset, line = (uint) prevSeq.StartLine;
                var doc = prevSeq.Doreplacedent.Url;

                rt.dbgWriter.AddSequencePoint(block, prevOffset, len, doc, line);
            }
        }

19 View Source File : DbgWriter.cs
License : GNU General Public License v3.0
Project Creator : Aekras1a

private void InitStream()
            {
                docMap = new Dictionary<string, uint>();
                writer.Write(dbg.doreplacedents.Count);
                uint docId = 0;
                foreach(var doc in dbg.doreplacedents)
                {
                    writer.Write(doc);
                    docMap[doc] = docId++;
                }
            }

19 View Source File : Pack.cs
License : Apache License 2.0
Project Creator : aequabit

public byte[] Serialize(params object[] data)
    {
        MemoryStream Stream = new MemoryStream();
        BinaryWriter Writer = new BinaryWriter(Stream, Encoding.UTF8);
        byte Current = 0;

        Writer.Write(Convert.ToByte(data.Length));

        for (int I = 0; I <= data.Length - 1; I++)
        {
            Current = Table[data[I].GetType()];
            Writer.Write(Current);

            switch (Current)
            {
                case 0:
                    Writer.Write((bool)data[I]);
                    break;
                case 1:
                    Writer.Write((byte)data[I]);
                    break;
                case 2:
                    Writer.Write(((byte[])data[I]).Length);
                    Writer.Write((byte[])data[I]);
                    break;
                case 3:
                    Writer.Write((char)data[I]);
                    break;
                case 4:
                    Writer.Write(((char[])data[I]).ToString());
                    break;
                case 5:
                    Writer.Write((decimal)data[I]);
                    break;
                case 6:
                    Writer.Write((double)data[I]);
                    break;
                case 7:
                    Writer.Write((int)data[I]);
                    break;
                case 8:
                    Writer.Write((long)data[I]);
                    break;
                case 9:
                    Writer.Write((sbyte)data[I]);
                    break;
                case 10:
                    Writer.Write((short)data[I]);
                    break;
                case 11:
                    Writer.Write((float)data[I]);
                    break;
                case 12:
                    Writer.Write((string)data[I]);
                    break;
                case 13:
                    Writer.Write((uint)data[I]);
                    break;
                case 14:
                    Writer.Write((ulong)data[I]);
                    break;
                case 15:
                    Writer.Write((ushort)data[I]);
                    break;
                case 16:
                    Writer.Write(((System.DateTime)data[I]).ToBinary());
                    break;
            }
        }

        Writer.Close();
        return Stream.ToArray();
    }

19 View Source File : ImageHelper.cs
License : GNU General Public License v3.0
Project Creator : affederaffe

internal static void WriteNullableSprite(this BinaryWriter binaryWriter, Sprite? sprite)
        {
            if (sprite is null)
            {
                binaryWriter.Write(false);
                return;
            }

            byte[] textureBytes = BytesFromTexture2D(sprite.texture);
            binaryWriter.Write(true);
            binaryWriter.Write(textureBytes.Length);
            binaryWriter.Write(textureBytes);
        }

19 View Source File : WaveHeader.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

public virtual void Write(BinaryWriter bw)
        {
            bw.Write(RiffChunkID);
            bw.Write(RiffChunkSize);
            bw.Write(Format);

            bw.Write(FmtChunkID);
            bw.Write(FmtChunkSize);
            bw.Write(AudioFormat);
            bw.Write(NumChannels);
            bw.Write(SampleRate);
            bw.Write(ByteRate);
            bw.Write(BlockAlign);
            bw.Write(BitsPerSample);

            if (ExtraDataSize > 0)
            {
                bw.Write(ExtraDataSize);
                bw.Write(ValidBitsPerSample);
                bw.Write((int) AvailableChannelMask);
                bw.Write(FormatGuid[0]);
                bw.Write(FormatGuid[1]);
                bw.Write(FormatGuid[2]);
                bw.Write(FormatGuid[3]);
            }

            bw.Write(DataChunkID);
            bw.Write(DataChunkSize);
        }

19 View Source File : TOCEntry.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

public void Write(BinaryWriter bw)
        {
            if (!IsResourceFile)
            {
                bw.Write( Size );
            }
            else
            {
                bw.Write( RSCFlags );
            }

            bw.Write( (int)ResourceType );
            bw.Write( OffsetBlock );
            bw.Write( UsedBlocks );
            bw.Write( Flags );
        }

19 View Source File : DirectoryEntry.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

public override void Write(BinaryWriter bw)
        {
            bw.Write(NameOffset);
            bw.Write(Flags);

            uint temp = (uint)ContentEntryIndex | 0x80000000;
            bw.Write(temp);
            bw.Write(ContentEntryCount);
        }

19 View Source File : Header.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

public void Write(BinaryWriter bw)
        {
            bw.Write((int)Identifier);
            bw.Write(TOCSize);
            bw.Write(EntryCount);
            bw.Write(Unknown1);
            bw.Write((int)0);           // not encrypted, we won't write encrypted archives :)
        }

19 View Source File : Header.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

public void Write(BinaryWriter bw)
        {
            bw.Write( Identifier );
            bw.Write( Version );
            bw.Write( EntryCount );
            bw.Write( TocSize );
            bw.Write( TocEntrySize );
            bw.Write( Unknown2 );
        }

See More Examples