public override byte[] GetChunkBytes() { using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { writer.Write((uint)Flags); writer.WriteVector2UInt(Index); writer.Write(Layers); writer.Write(NumberDoodadRefs); var positionOffsetMCVT = BaseStream.Position; writer.Write(0); var positionOffsetMCNR = BaseStream.Position; writer.Write(0); var positionOffsetMCLY = BaseStream.Position; writer.Write(0); var positionOffsetMCRF = BaseStream.Position; writer.Write(0); var positionOffsetMCAL = BaseStream.Position; writer.Write(0); writer.Write(SizeShadow); var positionOffsetMCSH = BaseStream.Position; writer.Write(0); writer.Write(SizeShadow); writer.Write(AreaId); writer.Write(NumberMapObjectRefs); writer.Write(Holes); writer.Write(HolesPadding); for (int i = 0; i < 16; i++) { writer.Write(ReallyLowQualityTextureingMap[i]); } writer.Write(PredTex); writer.Write(NumberEffectDoodads); var positionOffsetMCSE = BaseStream.Position; writer.Write(0); writer.Write(NumberSoundEmitters); var positionOffsetMCLQ = BaseStream.Position; writer.Write(0); writer.Write(SizeLiquid); writer.WriteVector3Float(Position); var positionOffsetMCCV = BaseStream.Position; writer.Write(0); writer.Write(Unused1); writer.Write(Unused2); // Subchunks var positionMCVT = BaseStream.Position; BaseStream.Position = positionOffsetMCVT; writer.Write(positionMCVT); BaseStream.Position = positionMCVT; writer.Write(MCVT.GetChunkHeaderBytes()); writer.Write(MCVT.GetChunkBytes()); var positionMCNR = BaseStream.Position; BaseStream.Position = positionOffsetMCNR; writer.Write(positionMCNR); BaseStream.Position = positionMCNR; writer.Write(MCNR.GetChunkHeaderBytes()); writer.Write(MCNR.GetChunkBytes()); var positionMCLY = BaseStream.Position; BaseStream.Position = positionOffsetMCLY; writer.Write(positionMCLY); BaseStream.Position = positionMCLY; writer.Write(MCLY.GetChunkHeaderBytes()); writer.Write(MCLY.GetChunkBytes()); var positionMCRF = BaseStream.Position; BaseStream.Position = positionOffsetMCRF; writer.Write(positionMCRF); BaseStream.Position = positionMCRF; writer.Write(MCRF.GetChunkHeaderBytes()); writer.Write(MCRF.GetChunkBytes()); // if WDT var positionMCAL = BaseStream.Position; BaseStream.Position = positionOffsetMCAL; writer.Write(positionMCAL); BaseStream.Position = positionMCAL; writer.Write(MCAL.GetChunkHeaderBytes()); writer.Write(MCAL.GetChunkBytes()); if (SizeShadow > 8 && Flags.HasFlag(MCNKFlags.HasMCSH)) { var positionMCSH = BaseStream.Position; BaseStream.Position = positionOffsetMCSH; writer.Write(positionMCSH); BaseStream.Position = positionMCSH; writer.Write(MCSH.GetChunkHeaderBytes()); writer.Write(MCSH.GetChunkBytes()); } if (NumberSoundEmitters > 0) { var positionMCSE = BaseStream.Position; BaseStream.Position = positionOffsetMCSE; writer.Write(positionMCSE); BaseStream.Position = positionMCSE; writer.Write(MCSE.GetChunkHeaderBytes()); writer.Write(MCSE.GetChunkBytes()); } if (SizeLiquid > 0) { var positionMCLQ = BaseStream.Position; BaseStream.Position = positionOffsetMCLQ; writer.Write(positionMCLQ); BaseStream.Position = positionMCLQ; writer.Write(MCLQ.GetChunkHeaderBytes()); writer.Write(MCLQ.GetChunkBytes()); } var positionMCCV = BaseStream.Position; BaseStream.Position = positionOffsetMCCV; writer.Write(positionMCCV); BaseStream.Position = positionMCCV; writer.Write(MCCV.GetChunkHeaderBytes()); writer.Write(MCCV.GetChunkBytes()); } return(stream.ToArray()); } }
public MCNK(char[] magic, byte[] size, byte[] content) : base(magic, size) { using (BinaryReader reader = new BinaryReader(new MemoryStream(content))) { #region read MCNKhead mcHeader.Flags = reader.ReadUInt32(); mcHeader.IndexX = reader.ReadUInt32(); mcHeader.IndexY = reader.ReadUInt32(); mcHeader.NLayers = reader.ReadUInt32(); mcHeader.NDoodadRefs = reader.ReadUInt32(); offset offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCVT = offset; offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCNR = offset; offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCLY = offset; offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCRF = offset; offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCAL = offset; mcHeader.SizeAlpha = reader.ReadUInt32(); offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCSH = offset; mcHeader.SizeShadow = reader.ReadUInt32(); mcHeader.Areaid = reader.ReadUInt32(); mcHeader.NMapObjRefs = reader.ReadUInt32(); mcHeader.Holes = reader.ReadUInt32(); mcHeader.GroundEffectsMap = new byte[16]; for (int x = 0; x < 16; x++) { mcHeader.GroundEffectsMap[x] = reader.ReadByte(); } mcHeader.PredTex = reader.ReadUInt32(); mcHeader.NoEffectDoodad = reader.ReadUInt32(); offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCSE = offset; mcHeader.NSndEmitters = reader.ReadUInt32(); offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCLQ = offset; mcHeader.SizeLiquid = reader.ReadUInt32(); mcHeader.Pos = new float[3]; mcHeader.Pos[0] = reader.ReadSingle(); mcHeader.Pos[1] = reader.ReadSingle(); mcHeader.Pos[2] = reader.ReadSingle(); offset = new offset(); offset.address = reader.ReadUInt32(); mcHeader.OfsMCCV = offset; mcHeader.Props = reader.ReadUInt32(); mcHeader.EffectId = reader.ReadUInt32(); #endregion while (reader.BaseStream.Position < reader.BaseStream.Length) { byte[] ChunkMagic = reader.ReadBytes(4); byte[] ChunkSize = reader.ReadBytes(4); byte[] ChunkContent = reader.ReadBytes(BitConverter.ToInt32(ChunkSize, 0)); string ChunkMagicString = ADT.MagicBytesToString(ChunkMagic); switch (ChunkMagicString) { case "MCVT": mcvt = new MCVT(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; case "MCCV": mccv = new MCCV(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; case "MCNR": mcnr = new MCNR(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent, reader.ReadBytes(13)); break; case "MCLY": mcly = new MCLY(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; case "MCRF": mcrf = new MCRF(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; case "MCAL": mcal = new MCAL(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; case "MCSE": mcse = new MCSE(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; case "MCSH": mcsh = new MCSH(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; case "MCLQ": mclq = new MCLQ(ADT.MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent); break; } //Logger.log(ChunkMagicString, Logger.Direction.LEVEL2, ChunkContent.Length.ToString() + " byte"); } } //Logger.log("---", Logger.Direction.LEVEL2); }
public MCNK(byte[] chunkBytes, WDT.WDT wdt) : base(chunkBytes) { Flags = (MCNKFlags)ReadUInt32(); Index = this.ReadVector2UInt(); Layers = ReadUInt32(); NumberDoodadRefs = ReadUInt32(); OffsetMCVT = ReadUInt32(); OffsetMCNR = ReadUInt32(); OffsetMCLY = ReadUInt32(); OffsetMCRF = ReadUInt32(); OffsetMCAL = ReadUInt32(); SizeAlpha = ReadUInt32(); OffsetMCSH = ReadUInt32(); SizeShadow = ReadUInt32(); AreaId = ReadUInt32(); NumberMapObjectRefs = ReadUInt32(); Holes = ReadUInt16(); HolesPadding = ReadUInt16(); // Maybe change this to two longs like in https://bitbucket.org/mugadr_m/kotlin-wow/src/378f3fdec7fff325f52560fc2cce64c946cf57ab/editor/src/main/kotlin/ch/cromon/wow/io/files/map/wotlk/MapChunk.kt?at=master&fileviewer=file-view-default#MapChunk.kt-37 for (int i = 0; i < 16; i++) { ReallyLowQualityTextureingMap[i] = ReadByte(); } PredTex = ReadUInt32(); NumberEffectDoodads = ReadUInt32(); OffsetMCSE = ReadUInt32(); NumberSoundEmitters = ReadUInt32(); OffsetMCLQ = ReadUInt32(); SizeLiquid = ReadUInt32(); Position = this.ReadVector3Float(); OffsetMCCV = ReadUInt32(); Unused1 = ReadUInt32(); Unused2 = ReadUInt32(); if (OffsetMCVT > 0) { BaseStream.Position = OffsetMCVT; MCVT = new MCVT(ReadBytes((int)MCVT.ChunkSize)); } if (OffsetMCNR > 0) { BaseStream.Position = OffsetMCNR; MCNR = new MCNR(ReadBytes((int)MCNR.ChunkSize)); } if (OffsetMCLY > 0) { BaseStream.Position = OffsetMCLY; MCLY = new MCLY(ReadBytes((int)MCLY.ChunkSize)); } if (OffsetMCRF > 0) { BaseStream.Position = OffsetMCRF; MCRF = new MCRF(ReadBytes((int)MCRF.ChunkSize), this); } // TODO: && No WDT file? if (OffsetMCAL > 0 && wdt != null) { BaseStream.Position = OffsetMCAL; MCAL = new MCAL(ReadBytes((int)MCAL.ChunkSize), this, wdt); } if (OffsetMCSH > 0 && SizeShadow > 8 && Flags.HasFlag(MCNKFlags.HasMCSH)) { BaseStream.Position = OffsetMCSH; MCSH = new MCSH(ReadBytes((int)MCSH.ChunkSize)); } if (OffsetMCSE > 0 && NumberSoundEmitters > 0) { BaseStream.Position = OffsetMCSE; MCSE = new MCSE(ReadBytes((int)MCSE.ChunkSize), this); } if (OffsetMCLQ > 0 && SizeLiquid > 0) { BaseStream.Position = OffsetMCLQ; MCLQ = new MCLQ(ReadBytes((int)MCLQ.ChunkSize), this); } if (OffsetMCCV > 0) { BaseStream.Position = OffsetMCCV; MCCV = new MCCV(ReadBytes((int)MCCV.ChunkSize)); } Close(); }