public Write ( bool bit ) : void | ||
bit | bool |
/// A |
Результат | void |
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.SET_PLAYER_ID, 0, 16); packet.Write((byte)m_playerID); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)SGCommandID.SEND_DECK, 0, 16); packet.Write(m_deck); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)SGCommandID.PLAY_CARD_FROM_HAND, 0, 16); packet.Write((ushort)m_cardID, 0, 16); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.MOVE_CARD_TO_GRAVEYARD, 0, 16); packet.Write((byte)m_playerID); packet.Write((ushort)m_cardID, 0, 16); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.PHASE_TRANSITION, 0, 16); packet.Write(m_text.Length, 0, 8); packet.Write(m_text.ToCharArray(), 0, m_text.Length); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.CAST_SPELL, 0, 16); packet.Write((ushort)m_cardID, 0, 16); packet.Write((byte)m_casterID); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.OPPONENT_PLAY_CARD_FROM_HAND, 0, 16); packet.Write(m_cardData); packet.Write((ushort)m_cardID, 0, 16); packet.Write((ushort)m_channel, 0, 5); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.PLAYER_DRAW_CARD, 0, 16); packet.Write(m_cardData); packet.Write((ushort)m_cardID, 0, 16); Debug.Log("Sending card " + m_cardData.cardName + " with ID " + m_cardID); return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.WAIT_FOR_CAST_SELECTION, 0, 16); packet.Write((ushort)m_castableCards.Count, 0, 16); foreach (CastableCard card in m_castableCards) { packet.Write(card); } return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.WAIT_FOR_PLAY_FROM_HAND, 0, 16); packet.Write((byte)m_playerID); packet.Write((ushort)m_playableCards.Count, 0, 16); foreach (int card in m_playableCards) { packet.Write((ushort)card, 0, 16); } return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)SGCommandID.CAST_SPELL_FROM_0, 0, 16); packet.Write((ushort)m_cardID, 0, 16); packet.Write(m_targetID >= 0); if (m_targetID >= 0) { packet.Write((ushort)m_targetID, 0, 16); } return(packet); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.CHANNEL_SPELL, 0, 16); packet.Write(m_data.Count, 0, 16); foreach (SpellChannelData data in m_data) { packet.Write((ushort)data.cardID, 0, 16); packet.Write((byte)data.playerID); packet.Write((ushort)data.newChannel, 0, 5); } return(packet); }
public CGCommand ReceiveCommand() { NetworkStream stream = m_client.GetStream(); while (stream.DataAvailable) { //Debug.Log("Data available! Reading stream..."); // Decode the first 32 bits to find the length of the remaining data byte[] dataSizeBytes = new byte[4]; stream.Read(dataSizeBytes, 0, 4); int dataSize = BitConverter.ToInt32(dataSizeBytes, 0); dataSize = IPAddress.NetworkToHostOrder(dataSize); //Debug.Log("Received data of size " + dataSize + " bytes"); // Receive the data // Convert size to bytes byte[] data = new byte[dataSize]; stream.Read(data, 0, dataSize); // Put the data into a BitStream BKSystem.IO.BitStream serverStream = new BKSystem.IO.BitStream(dataSize * 8); serverStream.Write(data); if (serverStream.Length > 0) { return(CGCommand.CreateCommandFromPacket(serverStream)); } } return(null); }
public void TransmitStream(BKSystem.IO.BitStream data, int player) { if (m_clients[player] != null && m_clients[player].Connected) { // Pad the data by 1 bit ??? data.Write(0); // Send how large the data is in the first 32 bits byte[] sendData = data.ToByteArray(); int sendLength = IPAddress.HostToNetworkOrder(sendData.Length); byte[] lengthData = BitConverter.GetBytes(sendLength); // Choose the stream to use NetworkStream stream; stream = m_clients[player].GetStream(); stream.Flush(); stream.Write(lengthData, 0, lengthData.Length); //Debug.Log("Sending " + sendData.Length + " bytes to player " + player); // Then send the data stream.Write(sendData, 0, sendData.Length); } else { Debug.LogWarning("Attempting to transmit data while disconnected"); } }
public void TransmitStream(BKSystem.IO.BitStream data) { if (m_client.Connected) { // Pad the data by 1 bit ??? data.Write(0); // Send how large the data is in the first 32 bits byte[] sendData = data.ToByteArray(); int sendLength = IPAddress.HostToNetworkOrder(sendData.Length); byte[] lengthData = BitConverter.GetBytes(sendLength); m_client.GetStream().Flush(); m_client.GetStream().Write(lengthData, 0, lengthData.Length); Debug.Log("Sending " + sendData.Length + " bytes to server"); // Then send the data m_client.GetStream().Write(sendData, 0, sendData.Length); } }
public SGCommand ReceiveStream(int player) { NetworkStream stream; if (m_clients[player] != null && m_clients[player].Connected) { stream = m_clients[player].GetStream(); } else { Debug.LogWarning("Trying to receive stream from disconnected player " + player); return(null); } if (stream.DataAvailable) { // Decode the first 32 bits to find the length of the remaining data byte[] dataSizeBytes = new byte[4]; stream.Read(dataSizeBytes, 0, 4); int dataSize = BitConverter.ToInt32(dataSizeBytes, 0); dataSize = IPAddress.NetworkToHostOrder(dataSize); //Debug.Log("Received data of size " + dataSize + " bytes"); // Receive the data // Convert size to bytes byte[] data = new byte[dataSize]; stream.Read(data, 0, dataSize); // Put the data into a BitStream BKSystem.IO.BitStream clientStream = new BKSystem.IO.BitStream(dataSize * 8); clientStream.Write(data); if (clientStream.Length > 0) { return(SGCommand.CreateCommandFromPacket(clientStream, player)); } } return(null); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.OPPONENT_DRAW_CARD, 0, 16); return(packet); }
/// <summary> /// Function to pack an array of one-byte representations of a given gas's visibility. /// </summary> /// <param name="all">send em all anyway?</param> /// <returns></returns> /// public int PackDisplayBytes(BitStream bits, bool all = false) { int changedTypes = 0; //How many gas types we have! int typesCount = Enum.GetValues(typeof (GasType)).Length; var gasChanges = new byte[typesCount]; int bitCount = typesCount; for (int i = typesCount - 1; i >= 0; i--) { byte amount; var t = (GasType) i; switch (t) { case GasType.Toxin: if (gasMixture.gasses[(int)GasType.Toxin] > 0.00005f && (checkUpdateThreshold(GasType.Toxin) || all)) { amount = (byte)normalizeGasAmount(gasMixture.gasses[(int)GasType.Toxin]); gasChanges[i] = amount; changedTypes = (changedTypes | (1 << i)); lastSentGasses[GasType.Toxin] = gasMixture.gasses[(int)GasType.Toxin]; bitCount += 4; } else { lastSentGasses[GasType.Toxin] = 0; } break; case GasType.WVapor: //if (gasMixture.gasses[GasType.WVapor] > 0.005f && (checkUpdateThreshold(GasType.WVapor) || all)) if (gasMixture.Burning) { amount = 15; // normalizeGasAmount(gasMixture.gasses[GasType.WVapor]); gasChanges[i] = amount; changedTypes = (changedTypes | (1 << i)); lastSentGasses[GasType.WVapor] = gasMixture.gasses[(int)GasType.WVapor]; bitCount += 4; } else { amount = 0; // normalizeGasAmount(gasMixture.gasses[GasType.WVapor]); gasChanges[i] = amount; changedTypes = (changedTypes | (1 << i)); lastSentGasses[GasType.WVapor] = gasMixture.gasses[(int)GasType.WVapor]; bitCount += 4; //lastSentGasses[GasType.WVapor] = 0; } break; default: break; } } //Make a new bitstream with the number o bits we need. bits.Write(changedTypes, 0, typesCount); //write 8 bits for what gas types have changed... for (int i = typesCount - 1; i >= 0; i--) { int type = 1 << i; //Checks flags in the form of 00001011 -- each 1 is a gas type that needs sending... I know this is nuts but it works great! if ((changedTypes & type) == type) { bits.Write(gasChanges[i], 0, 4); } } return bitCount; }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)CGCommandID.REQUEST_DECK, 0, 16); return(packet); }
public Telemetry(byte[] raw) { this.originalpacketlength = raw.Length; if (Telemetry.logHeaderLine) { Console.WriteLine("UTCTime,"); } else if (this.originalpacketlength > 0) { Console.WriteLine(string.Format("{0} {1},", System.DateTime.UtcNow.ToShortDateString(), System.DateTime.UtcNow.ToLongTimeString())); } if (raw.Length == 0) { return; } BitStream bitStream = new BitStream(); bitStream.Write(raw); bitStream.Position = 0L; this.Set(Telemetry.DataIndex.SatelliteId, new SatelliteIdTelemetryValue(this.Get2bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.FrameId, new FrameIdTelemetryValue(this.Get6bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.PanelVoltX, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PanelVoltY, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PanelVoltZ, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PanelCurrentTotal, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.BattVolt0, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.BattCurrentBus, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.RebootCount, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.EpsErrorCount, new RawTelemetryValue(this.Get16bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.EpsTemp1, new RawTelemetryValue(this.Get8bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.EpsTemp2, new RawTelemetryValue(this.Get8bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.EpsTemp3, new RawTelemetryValue(this.Get8bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.BattTemp0, new RawTelemetryValue(this.Get8bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.LatchCount5_0, new RawTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.LatchCount3_3, new RawTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.ResetCause, new EPSResetcauseTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PptTrackingMode, new EPSPowerTrackingTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.AsibSunSensorX1, new SunSensorTelemetryValue(this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibSunSensorY1, new SunSensorTelemetryValue(this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibSunSensorZ1, new SunSensorTelemetryValue(this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibPanelTempX1, new MultiplierOffsetTelemetryValue(-0.2073, 158.239, this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibPanelTempX2, new MultiplierOffsetTelemetryValue(-0.2083, 159.227, this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibPanelTempY1, new MultiplierOffsetTelemetryValue(-0.2076, 158.656, this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibPanelTempY2, new MultiplierOffsetTelemetryValue(-0.2087, 159.045, this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibBusVolt3_3, new MultiplierTelemetryValue(4.0, this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibBusCurrent3_3, new MultiplierTelemetryValue(1.0, this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.AsibBusVolt5_0, new MultiplierTelemetryValue(6.0, this.Get10bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.RfReceiverDoppler, new RawTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.RfReceiverRSSI, new RawTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.RfTemp, new MultiplierOffsetTelemetryValue(-0.857, 193.672, this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.RfReceiveCurrent, new RawTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.RfTransmitCurrent3_3, new RawTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.RfTransmitCurrent5_0, new RawTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PaReversePower, new PaPowerTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PaForwardPower, new PaPowerTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PaTemperature, new PaTemperatureTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.PaCurrent, new PaCurrentTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.AntTempA, new AntsTemperatureTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.AntTempB, new AntsTemperatureTelemetryValue(this.Get8bitsAsUInt(bitStream))); this.Set(Telemetry.DataIndex.AntDeploy1, new AntsDeployTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.AntDeploy2, new AntsDeployTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.AntDeploy3, new AntsDeployTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.AntDeploy4, new AntsDeployTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.SequenceNumber, new RawTelemetryValue(this.Get24bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.DtmfCommandCount, new RawTelemetryValue(this.Get6bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.DtmfLastCommand, new RawTelemetryValue(this.Get5bitsAsInt(bitStream))); this.Set(Telemetry.DataIndex.DtmfCommandSuccess, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DataValidBob, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DataValidEps, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DataValidPa, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DataValidRf, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DataValidMse, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DataValidAnts2, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DataValidAnts1, new DeviceDataValidTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.InEclipse, new RawTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.InSafeMode, new RawTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.HardwareABF, new BoolOnOffTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.SoftwareABF, new SoftwareAbfTelemetryValue(this.Get1bitAsInt(bitStream))); this.Set(Telemetry.DataIndex.DeployWait, new BoolOnOffTelemetryValue(this.Get1bitAsInt(bitStream))); bitStream.Position = 448L; BitStream bitStream2 = new BitStream(1600L); for (int i = 0; i < 200; i++) { bitStream2.WriteByte((byte)bitStream.ReadByte()); } bitStream2.Position = 0L; this.Set(Telemetry.DataIndex.Payload, new PayloadTelemetryValue(bitStream2)); if (this.originalpacketlength > 0) { Console.WriteLine(string.Empty); } if (Settings.Default.LoggingEnabled) { Telemetry.logHeaderLine = false; } }
private static void getStreams(byte[][] celldata, byte[][] lastCellData, int frame, int width, uint[] palette, BitStream cellMatrix, BitStream cellDeltaEncoding, BitStream pixelData) { bool newLine = true; int x = 0; bool emptyCellSpan = true; byte cellSpanLength = 0; int cellMatrixEntryMaxSizeBits = 4; int cellMatrixEntryMaxSize = (int)Math.Pow(2, cellMatrixEntryMaxSizeBits) - 1; byte[] emptyCell = new byte[16]; for (int i = 0; i < celldata.Length; i++) { if (newLine) { newLine = false; x = 0; } bool writeCell; if (frame == 0) writeCell = !isCellEmpty(celldata[i]); else writeCell = isCellDifferent(celldata[i], lastCellData[i], palette); if (writeCell) { if (!emptyCellSpan) { cellSpanLength++; if (cellSpanLength == cellMatrixEntryMaxSize) { cellMatrix.Write(cellSpanLength, 0, cellMatrixEntryMaxSizeBits); cellSpanLength = 0; cellMatrix.Write(cellSpanLength, 0, cellMatrixEntryMaxSizeBits); bitswrittenCellMatrix += 8; } } else { cellMatrix.Write(cellSpanLength, 0, cellMatrixEntryMaxSizeBits); bitswrittenCellMatrix += 4; cellSpanLength = 1; emptyCellSpan = false; } byte[] lastframecell = (frame == 0) ? emptyCell : lastCellData[i]; writeCellData(celldata[i], lastframecell, palette, cellDeltaEncoding, pixelData); cellswritten++; } else { if (emptyCellSpan) { cellSpanLength++; if (cellSpanLength == cellMatrixEntryMaxSize) { cellMatrix.Write(cellSpanLength, 0, cellMatrixEntryMaxSizeBits); cellSpanLength = 0; cellMatrix.Write(cellSpanLength, 0, cellMatrixEntryMaxSizeBits); bitswrittenCellMatrix += 8; } } else { cellMatrix.Write(cellSpanLength, 0, cellMatrixEntryMaxSizeBits); bitswrittenCellMatrix += 4; cellSpanLength = 1; emptyCellSpan = true; } } x += 4; if (x >= width) newLine = true; } if (cellSpanLength > 0) { cellMatrix.Write(cellSpanLength, 0, cellMatrixEntryMaxSizeBits); } }
private static void writeCellData(byte[] cell, byte[] lastframecell, uint[] palette, BitStream cellDeltaEncoding, BitStream pixelData) { int count = 0; int numpixels = cell.Length; int delta = 0; byte[] pixels = new byte[16]; for (int i = 0; i < numpixels; i++) { if (isPixelDifferent(cell[i], lastframecell[i], palette, maxBitsDifferentForPalette)) { delta |= (1 << i); pixels[count] = cell[i]; count++; } } cellDeltaEncoding.Write(delta, 0, numpixels); bitswrittenCellDelta += numpixels; pixelData.Write(pixels, 0, count); bitswrittenCellData += count * 8; if (count == 0) emptycellswritten++; }
/// <summary> /// Converts specified item into item format for save file /// </summary> /// <returns>Byte representation of item for save file</returns> public byte[] GetItemBytes() { BitStream bs = new BitStream(); bs.WriteReversed('J', 8); bs.WriteReversed('M', 8); var ordered = dataEntries.OrderBy(n => n.Value.Index); foreach (var item in ordered) { if (item.Value.Value is string) { string value = item.Value.Value as string; if (item.Key == "ItemCode") { foreach (var ch in value) { bs.WriteReversed(ch, 8); } bs.WriteReversed(' ', 8); } else if (item.Key == "EarName" || item.Key == "PersonalizedName") { foreach (var ch in value) { bs.WriteReversed(ch, 7); } bs.WriteReversed(0, 7); } else { throw new Exception("Unknown string type in item data"); } } else if (item.Value.Value is ValueType) { // LAST key is the very last property added to the item data if (item.Key == "LAST") continue; TypeCode valueType = Type.GetTypeCode(item.Value.Value.GetType()); if (valueType == TypeCode.UInt32) { uint value = (uint)item.Value.Value; if (item.Key == "Defense") { value += (uint)ItemDefs.ItemStatCostsByName["armorclass"].SaveAdd; } else if (item.Key == "MaxDurability") { value += (uint)ItemDefs.ItemStatCostsByName["maxdurability"].SaveAdd; } else if (item.Key == "Durability") { value += (uint)ItemDefs.ItemStatCostsByName["durability"].SaveAdd; } bs.WriteReversed(value, item.Value.BitCount); } else if (valueType == TypeCode.Int32) { bs.WriteReversed((uint)((int)item.Value.Value), item.Value.BitCount); } else if (valueType == TypeCode.Boolean) { bs.Write((bool)item.Value.Value); } else { throw new Exception("Invalid ValueType!"); } } else { throw new Exception("Invalid data type in item dataEntries"); } } foreach (var item in properties) { WriteItemProperty(bs, item); } foreach (var item in propertiesSet) { WriteItemProperty(bs, item); } foreach (var item in propertiesRuneword) { WriteItemProperty(bs, item); } // Some simple items do have remaining data such as the soulstone if (IsSimpleItem) { //TODO: Enable renaming of ear and personlized names? if (remainingBytes != null) { bs.WriteReversed(remainingBytes); } if (dataEntries.ContainsKey("LAST")) { var lastEntry = dataEntries["LAST"]; bs.WriteReversed((uint)lastEntry.Value, lastEntry.BitCount); } } else { // Fill the last byte with 0 if it's not already full if ((bs.Position % 8) != 0) { int bitsToAdd = 8 - (int)(bs.Position % 8); if (bitsToAdd > 0) { bs.WriteReversed(0, bitsToAdd); } } } return bs.ToReversedByteArray(); }
public override BKSystem.IO.BitStream PackCommand() { BKSystem.IO.BitStream packet = new BKSystem.IO.BitStream(); packet.Write((ushort)SGCommandID.REFRESH_TIMEOUT, 0, 16); return(packet); }
public void HandleAtmosDisplayUpdate(NetIncomingMessage message) { if (!_loaded) return; //Length of records in bits int lengthBits = message.ReadInt32(); int lengthBytes = message.ReadInt32(); var records = new byte[lengthBytes]; message.ReadBytes(records, 0, lengthBytes); byte[] decompressed = Decompress(records); var recordStream = new BitStream(lengthBits); int bitsWritten = 0; for (int i = 0; i < decompressed.Length; i++) { int toWrite = 8; if (toWrite > lengthBits - bitsWritten) toWrite = lengthBits - bitsWritten; recordStream.Write(decompressed[i], 0, toWrite); bitsWritten += toWrite; } int typesCount = Enum.GetValues(typeof (GasType)).Length; recordStream.Position = 0; int types = 0; byte amount = 0; for (int x = 0; x < _mapWidth; x++) { for (int y = 0; y < _mapHeight; y++) { recordStream.Read(out types, 0, typesCount); for (int i = typesCount - 1; i >= 0; i--) { if ((types & (1 << i)) == (1 << i)) { recordStream.Read(out amount, 0, 4); Tile t = (Tile)GetFloorAt(new Vector2D(x * TileSpacing, y * TileSpacing)); if (t == null) continue; t.SetAtmosDisplay((GasType) i, amount); } } } } var gameScreen = IoCManager.Resolve<IStateManager>().CurrentState as GameScreen; gameScreen.RecalculateScene(); }