public void Bytes(byte[] data, int bytes) { IsTrue(data != null); IsTrue(bytes >= 0); w.Align(); w.Bytes(data, bytes); }
public static byte[] Write(WaypointsDifficulty waypointsDifficulty) { using (BitWriter writer = new BitWriter()) { writer.WriteUInt16(waypointsDifficulty.Header ?? (UInt16)0x102); var skippedProperties = new string[] { "Header" }; Type waypointsDifficultyType = typeof(WaypointsDifficulty); foreach (var waypointsDifficultyProperty in waypointsDifficultyType.GetProperties()) { if (skippedProperties.Contains(waypointsDifficultyProperty.Name)) { continue; } Type type = waypointsDifficultyProperty.PropertyType; var waypoints = waypointsDifficultyProperty.GetValue(waypointsDifficulty); foreach (var property in type.GetProperties()) { writer.WriteBit((bool)property.GetValue(waypoints)); } } writer.Align(); writer.WriteBytes(new byte[17]); return(writer.ToArray()); } }
public static byte[] Write(Attributes attributes) { using (BitWriter writer = new BitWriter()) { ItemStatCostTXT itemStatCost = Core.TXT.ItemStatCostTXT; writer.WriteUInt16(attributes.Header ?? (UInt16)0x6667); foreach (var entry in attributes.Stats) { var property = itemStatCost[entry.Key]; writer.WriteUInt16(property["ID"].ToUInt16(), 9); long attribute = entry.Value; if (property["ValShift"].ToInt32() > 0) { attribute <<= property["ValShift"].ToInt32(); } if (attribute > int.MaxValue) { writer.WriteUInt32((uint)attribute, property["CSvBits"].ToInt32()); } else { writer.WriteInt32((int)attribute, property["CSvBits"].ToInt32()); } } writer.WriteUInt16(0x1ff, 9); writer.Align(); return(writer.ToArray()); } }
public void Align() { int[] codes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var ms = new MemoryStream(); var writer = new BitWriter(ms); foreach (int code in codes) { writer.WriteCode(code, 4); writer.Align(); } ms.Flush(); ms.Close(); byte[] data = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90 }; var actual = ms.ToArray(); Assert.AreEqual(data, actual); }
protected override void SerializeStart(BitWriter writer, BasicAttackBehaviorExecutionParameters parameters) { parameters.ServerSide = true; //TODO: when pathfinding gets added, remove this //makes enemies turn toward players when attacking if (parameters.Context.Associate.TryGetComponent <DestroyableComponent>(out var destroyableComponent) && destroyableComponent.Factions.First() == 4) { parameters.NpcContext.Associate.Transform.LookAt(parameters.BranchContext.Target.Transform.Position); } writer.Align(); // Three unknowns writer.Write <byte>(0); writer.Write <byte>(0); writer.Write <byte>(0); writer.WriteBit(false); writer.WriteBit(false); writer.WriteBit(true); // flag 2 == true so this should be set writer.Write <uint>(0); var damage = (uint)new Random().Next((int)MinDamage, (int)MaxDamage); writer.Write(damage); writer.WriteBit(!parameters.NpcContext.Alive); var success = parameters.NpcContext.IsValidTarget(parameters.BranchContext.Target) && parameters.NpcContext.Alive; parameters.SuccessState = (byte)(success ? 1 : 0); writer.Write(parameters.SuccessState); if (success) { parameters.OnSuccessBehaviorExecutionParameters = OnSuccess.SerializeStart(writer, parameters.NpcContext, parameters.BranchContext); } }
public static byte[] Write(Item item, UInt32 version) { using (BitWriter writer = new BitWriter()) { if (version <= 0x60) { writer.WriteUInt16(item.Header ?? (UInt16)0x4D4A); } WriteCompact(writer, item, version); if (!item.IsCompact) { WriteComplete(writer, item, version); } writer.Align(); for (int i = 0; i < item.NumberOfSocketedItems; i++) { writer.WriteBytes(Item.Write(item.SocketedItems[i], version)); } return(writer.ToArray()); } }
/// <summary> /// Adds padding bits to align byte boundary. /// </summary> public void Align() { _writer.Align(); }