public void Write() { using (MemoryStream headerBuff = new MemoryStream(32768)) using (MemoryStream textBuff = new MemoryStream(32768)) { ArchiveListingBlockInfo[] blocksInfo; ArchiveListingEntryInfoV1[] entriesInfoV1; ArchiveListingTextWriter textWriter = new ArchiveListingTextWriter(textBuff); textWriter.Write(_listing, out blocksInfo, out entriesInfoV1); for (int i = 0; i < entriesInfoV1.Length; i++) { entriesInfoV1[i].UnknownNumber = _listing[i].UnknownNumber; entriesInfoV1[i].UnknownValue = _listing[i].UnknownValue; } byte[] buff = new byte[8192]; int blocksSize = (int)textBuff.Position; textBuff.Position = 0; ArchiveListingHeaderV1 header = new ArchiveListingHeaderV1 { EntriesCount = entriesInfoV1.Length, BlockOffset = entriesInfoV1.Length * 8 + 12 }; header.InfoOffset = header.BlockOffset + blocksInfo.Length * 12; headerBuff.WriteStruct(header); foreach (ArchiveListingEntryInfoV1 entry in entriesInfoV1) headerBuff.WriteStruct(entry); foreach (ArchiveListingBlockInfo block in blocksInfo) headerBuff.WriteStruct(block); int hederSize = (int)headerBuff.Length; headerBuff.Position = 0; using (Stream output = _accessor.RecreateListing(hederSize + blocksSize)) { headerBuff.CopyToStream(output, hederSize, buff); textBuff.CopyToStream(output, blocksSize, buff); } } }
public void Write() { using (MemoryStream headerBuff = new MemoryStream(32768)) using (MemoryStream textBuff = new MemoryStream(32768)) { ArchiveListingBlockInfo[] blocksInfo; ArchiveListingEntryInfoV2[] entriesInfoV2; ArchiveListingTextWriterV2 textWriter = new ArchiveListingTextWriterV2(textBuff); textWriter.Write(_listing, out blocksInfo, out entriesInfoV2); for (int i = 0; i < entriesInfoV2.Length; i++) { ArchiveListingEntryInfoV2 info = entriesInfoV2[i]; ArchiveEntry entry = _listing[i]; info.UnknownNumber = entry.UnknownNumber; info.UnknownValue = entry.UnknownValue; info.UnknownData = entry.UnknownData; } byte[] buff = new byte[8192]; int blocksSize = (int)textBuff.Position; textBuff.Position = 0; ArchiveListingHeaderV2 header = (ArchiveListingHeaderV2)_listing.Header; header.EntriesCount = entriesInfoV2.Length; header.RawBlockOffset = entriesInfoV2.Length * 8 + 12; header.RawInfoOffset = header.RawBlockOffset + blocksInfo.Length * 12; headerBuff.WriteContent(header); foreach (ArchiveListingEntryInfoV2 entry in entriesInfoV2) headerBuff.WriteContent(entry); foreach (ArchiveListingBlockInfo block in blocksInfo) headerBuff.WriteStruct(block); int hederSize = (int)headerBuff.Length; headerBuff.Position = 0; if (header.IsEncrypted) { RecreateEncryptedListing(headerBuff, hederSize, textBuff, blocksSize, buff); } else { using (Stream output = _accessor.RecreateListing(hederSize + blocksSize)) { headerBuff.CopyToStream(output, hederSize, buff); textBuff.CopyToStream(output, blocksSize, buff); } } } }
public void should_correctly_read_overlays() { var expectedOutput = new List<WEDOverlay>(); var overlay1 = new WEDOverlay(); overlay1.Width = 32; overlay1.Height = 32; overlay1.ResourceType = "example1".ToCharArray(); overlay1.UnknownData = 0x3D; overlay1.TileOffset = 5; overlay1.TileIndexOffset = 0x2D; var overlay2 = new WEDOverlay(); overlay2.Width = 32; overlay2.Height = 32; overlay2.ResourceType = "example2".ToCharArray(); overlay2.UnknownData = 0xC1; overlay2.TileOffset = 2; overlay2.TileIndexOffset = 0xFD; expectedOutput.Add(overlay1); expectedOutput.Add(overlay2); var plugin = new WEDPlugin(); var memoryStream = new MemoryStream(); memoryStream.WriteStruct(overlay1); memoryStream.WriteStruct(overlay2); memoryStream.Seek(0, SeekOrigin.Begin); var binaryReader = new BinaryReader(memoryStream); var descriptor = new WEDDescriptor(); descriptor.OverlayOffset = 0; descriptor.OverlayCount = 2; var createDescriptorMethod = plugin.GetType().GetMethod("ReadOverlays", BindingFlags.NonPublic | BindingFlags.Instance); var result = createDescriptorMethod.Invoke(plugin, new object[] { binaryReader, descriptor }); Assert.That(result, Is.EquivalentTo(expectedOutput)); }
public void should_create_descriptor() { var expectedOutput = new AREDescriptor(); expectedOutput.WedResource = "example ".ToCharArray(); expectedOutput.LastSaveTime = 0; expectedOutput.AreaFlags = 0x1; expectedOutput.NorthLinkResource = "nortreso".ToCharArray(); expectedOutput.EastLinkResource = "eastreso".ToCharArray(); expectedOutput.SouthLinkResource = "soutreso".ToCharArray(); expectedOutput.WestLinkResource = "westreso".ToCharArray(); expectedOutput.AreaType = 0x3; expectedOutput.RainProbability = 125; expectedOutput.SnowProbability = 25; expectedOutput.FogProbability = 742; expectedOutput.LightningProbability = 32; expectedOutput.ActorOffset = 0x1C; expectedOutput.ActorCount = 10; expectedOutput.RegionOffset = 0x25; expectedOutput.RegionCount = 5; expectedOutput.SpawnPointOffset = 0X3A; expectedOutput.SpawnPointCount = 2; expectedOutput.EntranceOffset = 0x40; expectedOutput.EntranceCount = 1; expectedOutput.ContainerOffset = 0x5A; expectedOutput.ContainerCount = 120; expectedOutput.ItemOffset = 0x6F; expectedOutput.ItemCount = 94; expectedOutput.VerticeOffset = 0x7F; expectedOutput.VerticeCount = 1000; expectedOutput.AmbientSoundOffset = 0x82; expectedOutput.AmbientSoundCount = 1; expectedOutput.VariableOffset = 0x91; expectedOutput.VariableCount = 12; expectedOutput.AreaScript = "areascri".ToCharArray(); expectedOutput.ExploredBitmapOffset = 0xAA; expectedOutput.ExploredBitmaskSize = 12; expectedOutput.DoorOffset = 0xBA; expectedOutput.DoorCount = 20; expectedOutput.AnimationOffset = 0xC1; expectedOutput.AnimationCount = 38; expectedOutput.TiledObjectOffset = 0xD0; expectedOutput.TiledObjectCount = 10; expectedOutput.SongEntryOffset = 0xED; expectedOutput.RestInterruptionOffset = 0xFF; expectedOutput.GeneralData1 = new char[8]; expectedOutput.GeneralData2 = new char[8]; expectedOutput.UnknownEndData = new byte[38]; var plugin = new AREPlugin(); var memoryStream = new MemoryStream(); memoryStream.WriteStruct(expectedOutput); memoryStream.Seek(0, SeekOrigin.Begin); var binaryReader = new BinaryReader(memoryStream); var createMethod = plugin.GetType().GetMethod("ReadDescriptor", BindingFlags.NonPublic | BindingFlags.Instance); var result = createMethod.Invoke(plugin, new object[] { binaryReader, 0 }); Assert.That(result, Is.EqualTo(expectedOutput)); }
public async Task<IEnumerable<BsonDocument>> SendCommand() { var NetworkStream = TcpClient.GetStream(); var WritePacket = new MemoryStream(); var BinaryWriter = new BinaryWriter(WritePacket); var PacketBsonWriter = BsonWriter.Create(WritePacket); var MsgHeader = default(MsgHeader); BsonSerializer.Serialize(PacketBsonWriter, "admin.$cmd"); BinaryWriter.Write((uint)0); BinaryWriter.Write((uint)100); BsonSerializer.Serialize(PacketBsonWriter, new[] { "test" }); var WritePacketHeader = new MemoryStream(); WritePacketHeader.WriteStruct(MsgHeader); await NetworkStream.WriteAsync(WritePacketHeader.GetBuffer(), 0, WritePacketHeader.GetBuffer().Length); await NetworkStream.WriteAsync(WritePacket.GetBuffer(), 0, WritePacket.GetBuffer().Length); return await ReadReplyFromMemory(new MemoryStream(await ReadPacketAsync(NetworkStream))); }