/// <summary> /// Saves the HXM file to a given stream. /// </summary> /// <param name="stream">The stream to write to.</param> public void Write(Stream stream) { BinaryWriter bw = new BinaryWriter(stream); HAMDataWriter datawriter = new HAMDataWriter(); bw.Write(559435080); bw.Write(1); bw.Write(ReplacedRobots.Count); for (int x = 0; x < ReplacedRobots.Count; x++) { bw.Write(ReplacedRobots[x].replacementID); datawriter.WriteRobot(ReplacedRobots[x], bw); } bw.Write(ReplacedJoints.Count); for (int x = 0; x < ReplacedJoints.Count; x++) { bw.Write(ReplacedJoints[x].ReplacementID); bw.Write(ReplacedJoints[x].JointNum); bw.Write(ReplacedJoints[x].Angles.P); bw.Write(ReplacedJoints[x].Angles.B); bw.Write(ReplacedJoints[x].Angles.H); } bw.Write(ReplacedModels.Count); for (int x = 0; x < ReplacedModels.Count; x++) { bw.Write(ReplacedModels[x].ReplacementID); datawriter.WritePolymodel(ReplacedModels[x], bw); bw.Write(ReplacedModels[x].InterpreterData); bw.Write(ReplacedModels[x].DyingModelnum); bw.Write(ReplacedModels[x].DeadModelnum); } bw.Write(ReplacedObjBitmaps.Count); for (int x = 0; x < ReplacedObjBitmaps.Count; x++) { bw.Write(ReplacedObjBitmaps[x].ReplacementID); bw.Write(ReplacedObjBitmaps[x].Data); } bw.Write(ReplacedObjBitmapPtrs.Count); for (int x = 0; x < ReplacedObjBitmapPtrs.Count; x++) { bw.Write(ReplacedObjBitmapPtrs[x].ReplacementID); bw.Write(ReplacedObjBitmapPtrs[x].Data); } bw.Dispose(); }
public void Write(Stream stream) { HAMDataWriter writer = new HAMDataWriter(); BinaryWriter bw = new BinaryWriter(stream); bw.Write(558711112); bw.Write(Version); int returnPoint = (int)bw.BaseStream.Position; if (Version < 3) { bw.Write(0); } bw.Write(Textures.Count); for (int x = 0; x < Textures.Count; x++) { ushort texture = Textures[x]; bw.Write(texture); } for (int x = 0; x < TMapInfo.Count; x++) { TMAPInfo texture = TMapInfo[x]; writer.WriteTMAPInfo(texture, bw); } //Always write 254 sounds, for convenience. bw.Write(254); for (int x = 0; x < Sounds.Length; x++) { byte sound = Sounds[x]; bw.Write(sound); } for (int x = 0; x < Sounds.Length; x++) { byte sound = AltSounds[x]; bw.Write(sound); } bw.Write(VClips.Count); for (int x = 0; x < VClips.Count; x++) { writer.WriteVClip(VClips[x], bw); } bw.Write(EClips.Count); for (int x = 0; x < EClips.Count; x++) { writer.WriteEClip(EClips[x], bw); } bw.Write(WClips.Count); for (int x = 0; x < WClips.Count; x++) { writer.WriteWClip(WClips[x], bw); } bw.Write(Robots.Count); for (int x = 0; x < Robots.Count; x++) { writer.WriteRobot(Robots[x], bw); } bw.Write(Joints.Count); for (int x = 0; x < Joints.Count; x++) { JointPos joint = Joints[x]; bw.Write(joint.JointNum); bw.Write(joint.Angles.P); bw.Write(joint.Angles.B); bw.Write(joint.Angles.H); } bw.Write(Weapons.Count); if (Version < 3) { for (int x = 0; x < Weapons.Count; x++) { writer.WriteWeaponV2(Weapons[x], bw); } } else { for (int x = 0; x < Weapons.Count; x++) { writer.WriteWeapon(Weapons[x], bw); } } bw.Write(Powerups.Count); for (int x = 0; x < Powerups.Count; x++) { Powerup powerup = Powerups[x]; bw.Write(powerup.VClipNum); bw.Write(powerup.HitSound); bw.Write(powerup.Size.value); bw.Write(powerup.Light.value); } bw.Write(Models.Count); for (int x = 0; x < Models.Count; x++) { writer.WritePolymodel(Models[x], bw); } for (int x = 0; x < Models.Count; x++) { bw.Write(Models[x].InterpreterData); } for (int x = 0; x < Models.Count; x++) { int modelnum = Models[x].DyingModelnum; bw.Write(modelnum); } for (int x = 0; x < Models.Count; x++) { int modelnum = Models[x].DeadModelnum; bw.Write(modelnum); } bw.Write(Gauges.Count); for (int x = 0; x < Gauges.Count; x++) { ushort gague = Gauges[x]; bw.Write(gague); } for (int x = 0; x < Gauges.Count; x++) { ushort gague = GaugesHires[x]; bw.Write(gague); } //Always write exactly 600 ObjBitmaps, the limit in Descent 2, to conform to the original data files. //Can be optimized if you need to save a kb of data I guess bw.Write(600); for (int x = 0; x < 600; x++) { if (x < ObjBitmaps.Count) { bw.Write(ObjBitmaps[x]); } else { bw.Write((ushort)0); } } for (int x = 0; x < 600; x++) { if (x < ObjBitmapPointers.Count) { bw.Write(ObjBitmapPointers[x]); } else { bw.Write((ushort)0); } } writer.WritePlayerShip(PlayerShip, bw); bw.Write(Cockpits.Count); for (int x = 0; x < Cockpits.Count; x++) { ushort cockpit = Cockpits[x]; bw.Write(cockpit); } bw.Write(FirstMultiBitmapNum); bw.Write(Reactors.Count); for (int x = 0; x < Reactors.Count; x++) { Reactor reactor = Reactors[x]; bw.Write(reactor.ModelNum); bw.Write(reactor.NumGuns); for (int y = 0; y < 8; y++) { bw.Write(reactor.GunPoints[y].X.value); bw.Write(reactor.GunPoints[y].Y.value); bw.Write(reactor.GunPoints[y].Z.value); } for (int y = 0; y < 8; y++) { bw.Write(reactor.GunDirs[y].X.value); bw.Write(reactor.GunDirs[y].Y.value); bw.Write(reactor.GunDirs[y].Z.value); } } bw.Write(PlayerShip.MarkerModel); if (Version < 3) { bw.Write(ExitModelnum); bw.Write(DestroyedExitModelnum); } for (int x = 0; x < 2620; x++) { bw.Write(BitmapXLATData[x]); } int ptr = (int)bw.BaseStream.Position; if (Version < 3) { bw.BaseStream.Seek(returnPoint, SeekOrigin.Begin); bw.Write(ptr); bw.BaseStream.Seek(ptr, SeekOrigin.Begin); bw.Write(sounddata); } //bw.Dispose(); //[ISB] disposing a BinaryWriter seems to close the underlying stream. That's nice. }
public void Write(Stream stream) { BinaryWriter bw = new BinaryWriter(stream); HAMDataWriter writer = new HAMDataWriter(); bw.Write(Util.MakeSig('M', 'A', 'H', 'X')); //signature bw.Write(1); //version bw.Write(Weapons.Count); foreach (Weapon weapon in Weapons) { writer.WriteWeapon(weapon, bw); } bw.Write(Robots.Count); foreach (Robot robot in Robots) { writer.WriteRobot(robot, bw); } bw.Write(Joints.Count); foreach (JointPos joint in Joints) { bw.Write(joint.JointNum); bw.Write(joint.Angles.P); bw.Write(joint.Angles.B); bw.Write(joint.Angles.H); } bw.Write(Models.Count); //Copy and paste festival foreach (Polymodel model in Models) { writer.WritePolymodel(model, bw); } foreach (Polymodel model in Models) { bw.Write(model.InterpreterData); } foreach (Polymodel model in Models) { bw.Write(model.DyingModelnum); } foreach (Polymodel model in Models) { bw.Write(model.DeadModelnum); } bw.Write(ObjBitmaps.Count); foreach (ushort bitmap in ObjBitmaps) { bw.Write(bitmap); } bw.Write(ObjBitmapPointers.Count); foreach (ushort bitmap in ObjBitmapPointers) { bw.Write(bitmap); } bw.Flush(); bw.Dispose(); }