/// <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();
        }
Exemple #2
0
        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.
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        public void Write(Stream stream)
        {
            DescentWriter descentWriter = new DescentWriter(stream);
            HAMDataWriter writer        = new HAMDataWriter();

            Int32 DataPointer = 0;            // update this later on

            descentWriter.Write(DataPointer); // update this later on

            descentWriter.Write((Int32)numTextures);

            for (int i = 0; i < 800; i++)
            {
                descentWriter.Write((UInt16)Textures[i]);
            }

            for (int i = 0; i < 800; i++)
            {
                this.WriteTMAPInfoDescent1(descentWriter, TMapInfo[i]);
            }

            descentWriter.Write(SoundIDs);

            descentWriter.Write(AltSounds);

            descentWriter.Write((Int32)numVClips); //this value is bogus. rip

            for (int i = 0; i < 70; i++)
            {
                writer.WriteVClip(VClips[i], descentWriter);
            }

            descentWriter.Write((Int32)numEClips);

            for (int i = 0; i < 60; i++)
            {
                writer.WriteEClip(EClips[i], descentWriter);
            }

            descentWriter.Write((Int32)numWClips);
            for (int i = 0; i < 30; i++)
            {
                this.WriteWClipDescent1(WClips[i], descentWriter);
            }

            descentWriter.Write((Int32)numRobots);
            for (int i = 0; i < 30; i++)
            {
                this.WriteRobotDescent1(Robots[i], descentWriter);
            }

            descentWriter.Write((Int32)numJoints);
            for (int i = 0; i < 600; i++)
            {
                JointPos joint = Joints[i];

                descentWriter.WriteInt16(joint.JointNum);
                descentWriter.WriteInt16(joint.Angles.P);
                descentWriter.WriteInt16(joint.Angles.B);
                descentWriter.WriteInt16(joint.Angles.H);
            }

            descentWriter.WriteInt32(numWeapons);
            for (int i = 0; i < 30; i++)
            {
                this.WriteWeaponInfoDescent1(descentWriter, Weapons[i]);
            }

            descentWriter.WriteInt32(numPowerups);
            for (int i = 0; i < 29; i++)
            {
                var powerup = this.Powerups[i];

                descentWriter.WriteInt32(powerup.VClipNum);
                descentWriter.WriteInt32(powerup.HitSound);
                descentWriter.WriteFix(powerup.Size);
                descentWriter.WriteFix(powerup.Light);
            }

            descentWriter.WriteInt32(numModels);
            for (int i = 0; i < numModels; i++)
            {
                writer.WritePolymodel(Models[i], descentWriter);
            }

            for (int i = 0; i < numModels; i++)
            {
                descentWriter.Write(Models[i].InterpreterData, 0, Models[i].ModelIDTASize);
            }

            for (int i = 0; i < Gauges.Length; i++)
            {
                descentWriter.WriteUInt16(Gauges[i]);
            }

            for (int i = 0; i < 85; i++)
            {
                if (Models[i] == null)
                {
                    descentWriter.WriteInt32(-1);
                }
                else
                {
                    descentWriter.WriteInt32(Models[i].DyingModelnum);
                }
            }

            for (int i = 0; i < 85; i++)
            {
                if (Models[i] == null)
                {
                    descentWriter.WriteInt32(-1);
                }
                else
                {
                    descentWriter.WriteInt32(Models[i].DeadModelnum);
                }
            }

            for (int i = 0; i < 210; i++)
            {
                descentWriter.WriteUInt16(ObjBitmaps[i]);
            }

            for (int i = 0; i < 210; i++)
            {
                descentWriter.WriteUInt16(ObjBitmapPointers[i]);
            }

            descentWriter.WriteInt32(PlayerShip.ModelNum);
            descentWriter.WriteInt32(PlayerShip.DeathVClipNum);
            descentWriter.WriteFix(PlayerShip.Mass);
            descentWriter.WriteFix(PlayerShip.Drag);
            descentWriter.WriteFix(PlayerShip.MaxThrust);
            descentWriter.WriteFix(PlayerShip.ReverseThrust);
            descentWriter.WriteFix(PlayerShip.Brakes);
            descentWriter.WriteFix(PlayerShip.Wiggle);
            descentWriter.WriteFix(PlayerShip.MaxRotationThrust);

            for (int x = 0; x < 8; x++)
            {
                descentWriter.WriteFixVector(PlayerShip.GunPoints[x]);
            }

            descentWriter.WriteInt32(numCockpits);
            for (int i = 0; i < 4; i++)
            {
                descentWriter.WriteInt16((Int16)Cockpits[i]);
            }

            //heh
            descentWriter.Write(SoundIDs, 0, 250);
            descentWriter.Write(AltSounds, 0, 250);

            descentWriter.WriteInt32(numObjects);
            for (int i = 0; i < 100; i++)
            {
                descentWriter.Write((sbyte)ObjectTypes[i].type);
            }
            for (int i = 0; i < 100; i++)
            {
                descentWriter.Write((byte)ObjectTypes[i].id);
            }
            for (int i = 0; i < 100; i++)
            {
                descentWriter.WriteFix(ObjectTypes[i].strength);
            }

            descentWriter.WriteInt32(FirstMultiBitmapNum);
            descentWriter.WriteInt32(reactor.NumGuns);

            for (int y = 0; y < 4; y++)
            {
                descentWriter.WriteFixVector(reactor.GunPoints[y]);
            }
            for (int y = 0; y < 4; y++)
            {
                descentWriter.WriteFixVector(reactor.GunDirs[y]);
            }

            descentWriter.WriteInt32(exitModelnum);
            descentWriter.WriteInt32(destroyedExitModelnum);

            for (int i = 0; i < 1800; i++)
            {
                descentWriter.WriteInt16((Int16)BitmapXLATData[i]);
            }

            //
            // Go back to the start and update the DataPointer
            //
            DataPointer = (int)descentWriter.BaseStream.Position;

            descentWriter.BaseStream.Seek(0, SeekOrigin.Begin);
            descentWriter.Write((Int32)DataPointer); // update the data pointer

            // Return to where we were
            descentWriter.BaseStream.Seek(DataPointer, SeekOrigin.Begin);

            descentWriter.WriteInt32(Bitmaps.Count - 1); // Ignore the bogus one
            descentWriter.WriteInt32(Sounds.Count);

            int dynamicOffset = 0;

            for (int i = 1; i < Bitmaps.Count; i++) // Skip the bogus one
            {
                var bitmap = Bitmaps[i];

                descentWriter.Write(bitmap.LocalName, 0, 8);

                descentWriter.WriteByte((byte)bitmap.DFlags);
                descentWriter.WriteByte((byte)bitmap.Width);
                descentWriter.WriteByte((byte)bitmap.Height);
                descentWriter.WriteByte((byte)bitmap.Flags);
                descentWriter.WriteByte((byte)bitmap.AverageIndex);

                descentWriter.WriteInt32(dynamicOffset);
                dynamicOffset += bitmap.GetSize();
            }

            for (int i = 0; i < Sounds.Count; i++)
            {
                var sound = Sounds[i];

                //var nameBytes = NameHelper.GetNameBytes(sound.name, 8);
                descentWriter.Write(sound.LocalName, 0, 8);

                descentWriter.WriteInt32(sound.Length);
                descentWriter.WriteInt32(sound.Length);

                descentWriter.WriteInt32(dynamicOffset);
                dynamicOffset += sound.Length;
            }

            for (int i = 1; i < Bitmaps.Count; i++)
            {
                Bitmaps[i].WriteImage(descentWriter);
            }

            for (int i = 0; i < Sounds.Count; i++)
            {
                descentWriter.Write(Sounds[i].Data);
            }
        }