public static void WriteProperty(BinaryWriter bw, Property p) { bw.WriteCString(p.Key); bw.WriteCString(p.Value); }
public override bool Write(BinaryWriter bw) { base.Write(bw); bw.Write((int)version); bw.WriteCString(login, 24); bw.WriteCString(pw, 24); bw.Write((byte)type); bw.Flush(); return true; }
// Internal Methods internal void InternalWrite(BinaryWriter writer) { writer.Write(_unk0x00); writer.WriteCString(_comment, 16); writer.Write(_textureIndex); writer.Write(_unk0x18); writer.Write(_unk0x1C); writer.Write(_unk0x20); writer.Write(_unk0x24); writer.Write(_unk0x28); writer.Write(_unk0x2C); writer.Write(_unk0x30); writer.Write(_unk0x34); writer.Write(_unk0x38); writer.Write(_unk0x3C); writer.Write(_unk0x40); writer.Write(_unk0x44); writer.Write(_unk0x48); writer.Write(_unk0x4C); writer.Write(_unk0x50); writer.Write(_unk0x54); writer.Write(_unk0x58); writer.Write(_unk0x5C); writer.Write(_unk0x60); writer.Write(_unk0x64); writer.Write(_unk0x68); writer.Write(_unk0x6C); writer.Write(_unk0x70); writer.Write(_unk0x74); writer.Write(_unk0x78); writer.Write(_unk0x7C); }
/*****************/ /**** Methods ****/ /*****************/ internal void InternalWrite(BinaryWriter writer) { writer.WriteCString(_name, MAX_NAME_LENGTH); writer.Write(DataLength); writer.Write(Data); writer.AlignPosition(64); }
// Internal Methods internal void Write(BinaryWriter writer) { // Save start offset and seek past the header long startOffset = writer.BaseStream.Position; writer.BaseStream.Seek(0x08, SeekOrigin.Current); // Write entries for (int i = 0; i < _names.Length; i++) { writer.WriteCStringAligned(_names[i].Name); writer.Write(_names[i].ID); } // Save end offset and calculate the size of the section long endOffset = writer.BaseStream.Position; _length = (uint)(endOffset - startOffset); // Seek back to the start and write the header writer.BaseStream.Seek(startOffset, SeekOrigin.Begin); writer.WriteCString(TAG, 4); writer.Write(_length); // Seek to the end of the section to align the writer position writer.BaseStream.Seek(endOffset, SeekOrigin.Begin); }
private static IPacket GetUpdateAccountDataPkt(AccpuntData accpuntData) { IPacket packet = WorldPacketFactory.Create(WMSG.SMSG_UPDATE_ACCOUNT_DATA); BinaryWriter writer = packet.CreateWriter(); writer.Write(accpuntData.Guid); writer.Write((uint)accpuntData.Type); writer.Write(accpuntData.Time.ToUnixTimestamp()); writer = new BinaryWriter(new DeflaterOutputStream(writer.BaseStream)); writer.WriteCString(accpuntData.Data); writer.Flush(); return packet; }
protected void WriteStringSection(BinaryWriter writer, string[] array, int stringLength) { using (BinaryWriter sectionWriter = new BinaryWriter(new MemoryStream())) { // write the strings to the memory stream foreach (string item in array) { sectionWriter.WriteCString(item, stringLength); } // write the section to the file using the memory stream we just wrote to WriteSection(writer, sectionWriter.BaseStream); } }
internal override void InternalWrite(BinaryWriter writer, ref List<int> addressList, int fp) { // Write header fields writer.WriteCString(name, NAME_LENGTH); writer.Write(_field18); writer.Write((ushort)DialogCount); // unknown zero writer.Write(0); // Save the pointer table offset for writing later long pagePointerTableOffset = writer.BaseStream.Position; // dummy page pointer table for (int i = 0; i < DialogCount; i++) { addressList.Add((int)writer.BaseStream.Position - fp); writer.Write(0); } // dummy length writer.Write(0); int[] pagePointerTable = new int[DialogCount]; // Write the pages long pageDataStart = writer.BaseStream.Position; for (int i = 0; i < DialogCount; i++) { pagePointerTable[i] = (int)writer.BaseStream.Position - BMDFile.DATA_START_ADDRESS - fp; dialogs[i].InternalWrite(writer); } long dialogDataEnd = writer.BaseStream.Position; // Calculate the page data length int pageDataLength = (int)(dialogDataEnd - pageDataStart); // Seek to the pointer table and write it writer.BaseStream.Seek(pagePointerTableOffset, SeekOrigin.Begin); writer.Write(pagePointerTable); writer.Write(pageDataLength); // Seek back to the end of the data writer.BaseStream.Seek(dialogDataEnd, SeekOrigin.Begin); }
// Internal Methods internal override void InternalWrite(BinaryWriter writer) { int posFileStart = (int)writer.BaseStream.Position; // Seek past chunk header writer.BaseStream.Seek(HEADER_SIZE + 4, SeekOrigin.Current); // Seek past texture pack header writer.BaseStream.Seek(TextureCount * sizeof(int), SeekOrigin.Current); int[] texturePointerTable = new int[TextureCount]; // Write texture data for (int i = 0; i < TextureCount; i++) { writer.AlignPosition(64); texturePointerTable[i] = (int)(writer.BaseStream.Position - posFileStart); _textures[i].InternalWrite(writer); } // Calculate length long posFileEnd = writer.BaseStream.Position; int length = (int)(posFileEnd - posFileStart); // Write header writer.BaseStream.Seek(posFileStart, SeekOrigin.Begin); writer.Write(FLAG); writer.Write((short)0); // userID writer.Write(length); writer.WriteCString(TAG, 4); writer.Write(0); writer.Write(TextureCount); // Write pointer table writer.Write(texturePointerTable); // Seek to end writer.BaseStream.Seek(posFileEnd, SeekOrigin.Begin); }
private static void WriteMapGroup(BinaryWriter bw, Group g) { bw.WriteCString("CMapGroup"); WriteMapBase(bw, g); }
private static void WriteMapEntity(BinaryWriter bw, Entity ent) { bw.WriteCString("CMapEntity"); WriteMapBase(bw, ent); WriteEntityData(bw, ent.EntityData); bw.Write(new byte[2]); // Unused bw.WriteCoordinate(ent.Origin); bw.Write(new byte[4]); // Unused }
private static void WriteEntityData(BinaryWriter bw, EntityData data) { bw.WriteCString(data.Name); bw.Write(new byte[4]); // Unused bw.Write(data.Flags); bw.Write(data.Properties.Count); foreach (var property in data.Properties) { WriteProperty(bw, property); } bw.Write(new byte[12]); // Unused }
internal override void InternalWrite(BinaryWriter writer) { writer.WriteCString(m_tag, TAG_LENGTH); writer.Write(m_flags); writer.Write(Size); writer.Write(m_data); }
internal override void InternalWrite(BinaryWriter writer) { int posFileStart = (int)writer.BaseStream.Position; List<int> addressList = new List<int>(); // Seek past chunk and msg header for writing later writer.BaseStream.Seek(DATA_START_ADDRESS, SeekOrigin.Current); // Write a dummy message pointer table for (int i = 0; i < DialogCount; i++) { writer.Write(0); addressList.Add((int)writer.BaseStream.Position - posFileStart); writer.Write(0); } // Write a dummy offset for writing later addressList.Add((int)writer.BaseStream.Position - posFileStart); writer.Write(0); writer.Write(ActorCount); // These are always here for some reason writer.Write(0); writer.Write(0); writer.AlignPosition(4); BMDMessageTable[] messagePointerTable = new BMDMessageTable[DialogCount]; // Write the messages and fill in the message pointer table for (int i = 0; i < DialogCount; i++) { writer.AlignPosition(4); messagePointerTable[i].Offset = (int)writer.BaseStream.Position - DATA_START_ADDRESS - posFileStart; _messages[i].InternalWrite(writer, ref addressList, posFileStart); } writer.AlignPosition(4); int actorNamePointerTableOffset = (int)writer.BaseStream.Position - DATA_START_ADDRESS - posFileStart; // Write dummy actor name pointer table if there are actors present if (ActorCount > 0) { long actorNamePointerTablePosition = writer.BaseStream.Position; for (int i = 0; i < ActorCount; i++) { addressList.Add((int)writer.BaseStream.Position - posFileStart); writer.Write(0); } int[] actorNamePointerTable = new int[ActorCount]; for (int i = 0; i < actorNamePointerTable.Length; i++) { actorNamePointerTable[i] = (int)writer.BaseStream.Position - DATA_START_ADDRESS - posFileStart; writer.WriteCString(_actorNames[i]); } long addresRelocPosition = writer.BaseStream.Position; writer.BaseStream.Seek(actorNamePointerTablePosition, SeekOrigin.Begin); writer.Write(actorNamePointerTable); writer.BaseStream.Seek(addresRelocPosition, SeekOrigin.Begin); } // Compress and write the address relocationt able byte[] addressRelocTable = PointerRelocationTableCompression.Compress(addressList, DATA_START_ADDRESS); int addressRelocTableOffset = (int)writer.BaseStream.Position - posFileStart; int addressRelocTableSize = addressRelocTable.Length; writer.Write(addressRelocTable); // Save the end offset for calculating length and seeking later long posFileEnd = writer.BaseStream.Position; int length = (int)(posFileEnd - posFileStart); // Seek back to the start writer.BaseStream.Seek(posFileStart, SeekOrigin.Begin); // Write Chunk header writer.Write(FLAG); writer.Write((short)0); // userID writer.Write(length); writer.WriteCString(TAG, 4); writer.Write(0); // Write MSG header writer.Write(addressRelocTableOffset); writer.Write(addressRelocTableSize); writer.Write(DialogCount); writer.Write(UNK_CONSTANT); for (int i = 0; i < DialogCount; i++) { writer.Write((int)messagePointerTable[i].Type); writer.Write(messagePointerTable[i].Offset); } writer.Write(actorNamePointerTableOffset); writer.BaseStream.Seek(posFileEnd, SeekOrigin.Begin); }
// write the data using the binary writer internal override void InternalWrite(BinaryWriter writer) { // write magic writer.WriteCString(MAGIC, MAGIC_LENGTH); // write chunk list writer.Write(ChunkCount); foreach (AMDChunk chunk in Chunks) { chunk.InternalWrite(writer); } }
/// <summary> /// メッシュを書き出します。 /// </summary> public void Write(BinaryWriter bw) { bw.WriteCString(this.name); Matrix m = this.transform_matrix; bw.Write(ref m); bw.Write(this.unknown1); bw.Write(this.sub_meshes.Length); foreach (TSOSubMesh sub_mesh in this.sub_meshes) sub_mesh.Write(bw); }
// Methods internal void InternalWrite(BinaryWriter writer) { writer.WriteCString(_name, NAME_LENGTH); writer.Write(_data.Length); writer.Write(_data); }
internal override void InternalWrite(BinaryWriter writer) { int posFileStart = (int)writer.BaseStream.Position; // Seek past chunk header writer.BaseStream.Seek(HEADER_SIZE, SeekOrigin.Current); writer.Write(PaletteCount); writer.Write((byte)PaletteFormat); writer.Write(Width); writer.Write(Height); writer.Write((byte)PixelFormat); writer.Write(MipMapCount); writer.Write(_mipKL); writer.Write((byte)0); writer.Write(_wrapModes); writer.Write(UserTextureID); writer.Write(UserClutID); writer.WriteCString(_userComment, COMMENT_MAX_LENGTH); // Check if there's any palettes and write them if (UsesPalette) { WritePalette(writer); } // Write the pixels for the image and mipmaps WritePixels(writer); // Calculate the length int posFileEnd = (int)writer.BaseStream.Position; int length = posFileEnd - posFileStart; // Seek back to the chunk header and write it writer.BaseStream.Seek(posFileStart, SeekOrigin.Begin); writer.Write(FLAG); writer.Write((short)0); // userID writer.Write(length); writer.WriteCString(TAG, 4); // Seek back to the end of the data writer.BaseStream.Seek(posFileEnd, SeekOrigin.Begin); }
/// <summary> /// TMONodeを書き出します。 /// </summary> public void Write(BinaryWriter bw) { bw.WriteCString(this.Path); }
internal override void InternalWrite(BinaryWriter writer) { int posFileStart = (int)writer.BaseStream.Position; // seek past the header, type table and code labels writer.BaseStream.Seek(DATA_START + (_procedures.Length * BFCodeLabel.SIZE) + (_jumpLabels.Length * BFCodeLabel.SIZE), SeekOrigin.Current); // create code label type table entries int procsLength = _procedures.Length * BFCodeLabel.SIZE; int jumpsLength = _jumpLabels.Length * BFCodeLabel.SIZE; int opCodeDataStart = (int)(writer.BaseStream.Position - posFileStart); int numProcsSet = 0; int numJumpsSet = 0; for (int i = 0; i < _opcodes.Count; i++) { int procIdx = -1; // try to find a procedure with this index if (numProcsSet != _procedures.Length) { procIdx = Array.FindIndex(_procedures, p => p.OpcodeIndex == i); if (procIdx != -1) { _procedures[procIdx].Offset = (uint)(((writer.BaseStream.Position - posFileStart) - opCodeDataStart) / 4); numProcsSet++; } } // if we haven't found a procedure, try to find a jump label with this index if (procIdx == -1 && numJumpsSet != _jumpLabels.Length) { int jumpIdx = Array.FindIndex(_jumpLabels, j => j.OpcodeIndex == i); if (jumpIdx != -1) { _jumpLabels[jumpIdx].Offset = (uint)(((writer.BaseStream.Position - posFileStart) - opCodeDataStart) / 4); numJumpsSet++; } } // write the opcode data writer.Write((ushort)_opcodes[i].Instruction); if (_opcodes[i].Operand != null) { switch (_opcodes[i].Operand.Type) { case BFOperandType.Immediate: if (_opcodes[i].Instruction == BFInstruction.PushUInt32) { writer.Write((ushort)0); writer.Write((uint)_opcodes[i].Operand.ImmediateValue); } else { writer.Write((ushort)_opcodes[i].Operand.ImmediateValue); } break; case BFOperandType.FloatingPoint: writer.Write((ushort)0); writer.Write((float)_opcodes[i].Operand.FloatValue); break; } } else { writer.Write((ushort)0); } } int opCodeDataEnd = (int)(writer.BaseStream.Position - posFileStart); // set type table entries TypeTableEntry[] typeTableEntries = new TypeTableEntry[TYPE_TABLE_COUNT]; typeTableEntries[(int)TypeTableType.Procedures] = CreateTypeTableEntry(TypeTableType.Procedures, procsLength, DATA_START); typeTableEntries[(int)TypeTableType.JumpLabels] = CreateTypeTableEntry(TypeTableType.JumpLabels, jumpsLength, DATA_START + procsLength); typeTableEntries[(int)TypeTableType.Opcodes] = CreateTypeTableEntry(TypeTableType.Opcodes, opCodeDataEnd - opCodeDataStart, opCodeDataStart); typeTableEntries[(int)TypeTableType.Messages] = CreateTypeTableEntry(TypeTableType.Messages, 0, opCodeDataEnd); typeTableEntries[(int)TypeTableType.Strings] = CreateTypeTableEntry(TypeTableType.Strings, 0xF0, opCodeDataEnd); if (_messageFile != null) { _messageFile.InternalWrite(writer); int messageDataEnd = (int)writer.BaseStream.Position - posFileStart; int messageDataSize = messageDataEnd - opCodeDataEnd; typeTableEntries[(int)TypeTableType.Strings].dataOffset += messageDataSize; typeTableEntries[(int)TypeTableType.Messages] = CreateTypeTableEntry(TypeTableType.Messages, messageDataSize, opCodeDataEnd); } // TODO: add code for the 'string' table here? haven't really seen it being used though. // fixed size zero bytes for the strings table when unused writer.Write(0, 0xF0); long posFileEnd = writer.BaseStream.Position; int length = (int)posFileEnd - posFileStart; writer.BaseStream.Seek(posFileStart, SeekOrigin.Begin); // write standard header writer.Write(TYPE); writer.Write((short)0); // userID writer.Write(length); writer.WriteCString(TAG, 4); writer.Write(0); // unused // write bf header writer.Write(typeTableEntries.Length); writer.Write(0); // some unknown value here, not sure what its for writer.AlignPosition(16); // write type table entries foreach (TypeTableEntry entry in typeTableEntries) { entry.InternalWrite(writer); } // lastly, write the code labels foreach (BFCodeLabel label in _procedures) { label.InternalWrite(writer); } foreach (BFCodeLabel label in _jumpLabels) { label.InternalWrite(writer); } }
private static void WriteMapSolid(BinaryWriter bw, Solid s) { bw.WriteCString("CMapSolid"); WriteMapBase(bw, s); bw.Write(s.Faces.Count); foreach (var face in s.Faces) { WriteFace(bw, face); } }
/// <summary> /// テクスチャを書き出します。 /// </summary> public void Write(BinaryWriter bw) { bw.WriteCString(this.name); bw.WriteCString(this.file); bw.Write(this.width); bw.Write(this.height); bw.Write(this.depth); byte[] buf = new byte[this.data.Length]; Array.Copy(this.data, 0, buf, 0, buf.Length); for(int j = 0; j < buf.Length; j += 4) { byte tmp = buf[j+2]; buf[j+2] = buf[j+0]; buf[j+0] = tmp; } bw.Write(buf); }
private static void WriteMapWorld(BinaryWriter bw, World w) { bw.WriteCString("CMapWorld"); WriteMapBase(bw, w); WriteEntityData(bw, w.EntityData); bw.Write(w.Paths.Count); foreach (var path in w.Paths) { WritePath(bw, path); } }
/// <summary> /// Inherited from <see cref="RWNode"/>. Writes the data beyond the header. /// </summary> /// <param name="writer">The <see cref="BinaryWriter"/> to write the data with.</param> protected internal override void InternalWriteInnerData(BinaryWriter writer) { writer.WriteCString(Value); writer.AlignPosition(4); }
internal void InternalWrite(BinaryWriter writer) { writer.WriteCString(_name, 24); writer.Write(_offset); writer.Write(0); }
/// <summary> /// スクリプトを書き出します。 /// </summary> public void Write(BinaryWriter bw) { bw.WriteCString(this.name); bw.Write(this.lines.Length); foreach (string line in this.lines) bw.WriteCString(line); }