Example #1
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.
        }
Example #2
0
        public int Read(Stream stream)
        {
            BinaryReader  br     = new BinaryReader(stream);
            HAMDataReader reader = new HAMDataReader();

            DataPointer = br.ReadInt32();

            numTextures = br.ReadInt32();
            for (int i = 0; i < 800; i++)
            {
                Textures[i] = br.ReadUInt16();
            }
            for (int i = 0; i < 800; i++)
            {
                TMapInfo[i] = reader.ReadTMAPInfoDescentPSX(br);
            }
            Sounds    = br.ReadBytes(250);
            AltSounds = br.ReadBytes(250);
            numVClips = br.ReadInt32(); //this value is bogus. rip
            for (int i = 0; i < 70; i++)
            {
                VClips[i] = reader.ReadVClipPSX(br);
            }
            numEClips = br.ReadInt32();
            for (int i = 0; i < 60; i++)
            {
                EClips[i] = reader.ReadEClipPSX(br);
            }
            numWClips = br.ReadInt32();
            for (int i = 0; i < 30; i++)
            {
                WClips[i] = reader.ReadWClipPSX(br);
            }
            numRobots = br.ReadInt32();
            for (int i = 0; i < 30; i++)
            {
                Robots[i] = reader.ReadRobotPSX(br);
            }
            numJoints = br.ReadInt32();
            for (int i = 0; i < 600; i++)
            {
                JointPos joint = new JointPos();
                joint.JointNum = br.ReadInt16();
                joint.Angles.P = br.ReadInt16();
                joint.Angles.B = br.ReadInt16();
                joint.Angles.H = br.ReadInt16();
                Joints[i]      = joint;
            }
            numWeapons = br.ReadInt32();
            for (int i = 0; i < 30; i++)
            {
                Weapons[i] = reader.ReadWeaponInfoPSX(br);
            }
            numPowerups = br.ReadInt32();
            for (int i = 0; i < 29; i++)
            {
                Powerup powerup = new Powerup();
                powerup.VClipNum = br.ReadInt32();
                powerup.HitSound = br.ReadInt32();
                powerup.Size     = new Fix(br.ReadInt32());
                powerup.Light    = new Fix(br.ReadInt32());
                Powerups[i]      = powerup;
            }
            numModels = br.ReadInt32();
            for (int i = 0; i < numModels; i++)
            {
                Models[i] = reader.ReadPolymodelInfoPSX(br);
            }
            for (int i = 0; i < numModels; i++)
            {
                Models[i].InterpreterData = br.ReadBytes(Models[i].ModelIDTASize);
            }
            for (int i = 0; i < Gauges.Length; i++)
            {
                Gauges[i] = br.ReadUInt16();
            }
            for (int i = 0; i < 85; i++)
            {
                int num = br.ReadInt32();
                if (i < numModels)
                {
                    Models[i].DyingModelnum = num;
                }
            }
            for (int i = 0; i < 85; i++)
            {
                int num = br.ReadInt32();
                if (i < numModels)
                {
                    Models[i].DeadModelnum = num;
                }
            }
            for (int i = 0; i < 210; i++)
            {
                ObjBitmaps[i] = br.ReadUInt16();
            }
            for (int i = 0; i < 210; i++)
            {
                ObjBitmapPointers[i] = br.ReadUInt16();
            }
            PlayerShip                   = new Ship();
            PlayerShip.ModelNum          = br.ReadInt32();
            PlayerShip.DeathVClipNum     = br.ReadInt32();
            PlayerShip.Mass              = new Fix(br.ReadInt32());
            PlayerShip.Drag              = new Fix(br.ReadInt32());
            PlayerShip.MaxThrust         = new Fix(br.ReadInt32());
            PlayerShip.ReverseThrust     = new Fix(br.ReadInt32());
            PlayerShip.Brakes            = new Fix(br.ReadInt32());
            PlayerShip.Wiggle            = new Fix(br.ReadInt32());
            PlayerShip.MaxRotationThrust = new Fix(br.ReadInt32());
            for (int x = 0; x < 8; x++)
            {
                PlayerShip.GunPoints[x] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
            }
            numCockpits = br.ReadInt32();
            for (int i = 0; i < 4; i++)
            {
                Cockpits[i] = br.ReadUInt16();
            }
            //heh
            Sounds    = br.ReadBytes(250);
            AltSounds = br.ReadBytes(250);

            numObjects = br.ReadInt32();
            for (int i = 0; i < 100; i++)
            {
                ObjectTypes[i].type = (EditorObjectType)(br.ReadSByte());
            }
            for (int i = 0; i < 100; i++)
            {
                ObjectTypes[i].id = br.ReadByte();
            }
            for (int i = 0; i < 100; i++)
            {
                ObjectTypes[i].strength = new Fix(br.ReadInt32());
                //Console.WriteLine("type: {0}({3})\nid: {1}\nstr: {2}", ObjectTypes[i].type, ObjectTypes[i].id, ObjectTypes[i].strength, (int)ObjectTypes[i].type);
            }
            FirstMultiBitmapNum = br.ReadInt32();
            reactor.NumGuns     = br.ReadInt32();
            for (int y = 0; y < 4; y++)
            {
                reactor.GunPoints[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
            }
            for (int y = 0; y < 4; y++)
            {
                reactor.GunDirs[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
            }
            exitModelnum          = br.ReadInt32();
            destroyedExitModelnum = br.ReadInt32();

            for (int i = 0; i < 1800; i++)
            {
                BitmapXLATData[i] = br.ReadUInt16();
            }
            br.Dispose();

            return(0);
        }
Example #3
0
        public void Read(Stream stream)
        {
            BinaryReader br;

            br = new BinaryReader(stream);
            HAMDataReader bm = new HAMDataReader();

            int sig = br.ReadInt32();

            if (sig != 0x214D4148)
            {
                br.Dispose();
                throw new InvalidDataException("HAMFile::Read: HAM file has bad header.");
            }
            Version = br.ReadInt32();
            if (Version < 2 || Version > 3)
            {
                br.Dispose();
                throw new InvalidDataException(string.Format("HAMFile::Read: HAM file has bad version. Got {0}, but expected \"2\" or \"3\"", Version));
            }
            int sndptr = 0;

            if (Version == 2)
            {
                sndptr = br.ReadInt32();
            }

            int NumBitmaps = br.ReadInt32();

            for (int x = 0; x < NumBitmaps; x++)
            {
                Textures.Add(br.ReadUInt16());
            }
            for (int x = 0; x < NumBitmaps; x++)
            {
                TMapInfo.Add(bm.ReadTMAPInfo(br));
                TMapInfo[x].ID = x;
            }

            int NumSounds = br.ReadInt32();

            if (NumSounds > 254)
            {
                throw new InvalidDataException("HAM file specifies more than 254 sounds.");
            }

            for (int x = 0; x < NumSounds; x++)
            {
                Sounds[x] = br.ReadByte();
            }
            for (int x = 0; x < NumSounds; x++)
            {
                AltSounds[x] = br.ReadByte();
            }

            int NumVClips = br.ReadInt32();

            for (int x = 0; x < NumVClips; x++)
            {
                VClips.Add(bm.ReadVClip(br));
                VClips[x].ID = x;
            }

            int NumEClips = br.ReadInt32();

            for (int x = 0; x < NumEClips; x++)
            {
                EClips.Add(bm.ReadEClip(br));
                EClips[x].ID = x;
            }

            int NumWallAnims = br.ReadInt32();

            for (int x = 0; x < NumWallAnims; x++)
            {
                WClips.Add(bm.ReadWClip(br));
            }

            int NumRobots = br.ReadInt32();

            for (int x = 0; x < NumRobots; x++)
            {
                Robots.Add(bm.ReadRobot(br));
                Robots[x].ID = x;
            }

            int NumLoadJoints = br.ReadInt32();

            for (int x = 0; x < NumLoadJoints; x++)
            {
                JointPos joint = new JointPos();
                joint.JointNum = br.ReadInt16();
                joint.Angles.P = br.ReadInt16();
                joint.Angles.B = br.ReadInt16();
                joint.Angles.H = br.ReadInt16();
                Joints.Add(joint);
            }

            int NumWeaponTypes = br.ReadInt32();

            for (int x = 0; x < NumWeaponTypes; x++)
            {
                if (Version >= 3)
                {
                    Weapons.Add(bm.ReadWeapon(br));
                }
                else
                {
                    Weapons.Add(bm.ReadWeaponInfoVersion2(br));
                }
                Weapons[x].ID = x;
            }

            int NumPowerups = br.ReadInt32();

            for (int x = 0; x < NumPowerups; x++)
            {
                Powerup powerup = new Powerup();
                powerup.VClipNum = br.ReadInt32();
                powerup.HitSound = br.ReadInt32();
                powerup.Size     = new Fix(br.ReadInt32());
                powerup.Light    = new Fix(br.ReadInt32());
                powerup.ID       = x;
                Powerups.Add(powerup);
            }

            int NumPolygonModels = br.ReadInt32();

            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models.Add(bm.ReadPolymodelInfo(br));
                Models[x].ID = x;
            }

            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models[x].InterpreterData = br.ReadBytes(Models[x].ModelIDTASize);
                //PolymodelData.Add(modeldata);
            }
            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models[x].DyingModelnum = br.ReadInt32();
            }
            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models[x].DeadModelnum = br.ReadInt32();
            }
            int gagueCount = br.ReadInt32();

            for (int x = 0; x < gagueCount; x++)
            {
                Gauges.Add(br.ReadUInt16());
            }
            for (int x = 0; x < gagueCount; x++)
            {
                GaugesHires.Add(br.ReadUInt16());
            }

            int bitmapCount = br.ReadInt32();

            for (int x = 0; x < bitmapCount; x++)
            {
                ObjBitmaps.Add(br.ReadUInt16());
            }
            ushort value;

            for (int x = 0; x < bitmapCount; x++)
            {
                value = br.ReadUInt16();
                if ((value + 1) > NumObjBitmaps)
                {
                    NumObjBitmaps = (value + 1);
                }
                ObjBitmapPointers.Add(value);
            }

            PlayerShip                   = new Ship();
            PlayerShip.ModelNum          = br.ReadInt32();
            PlayerShip.DeathVClipNum     = br.ReadInt32();
            PlayerShip.Mass              = new Fix(br.ReadInt32());
            PlayerShip.Drag              = new Fix(br.ReadInt32());
            PlayerShip.MaxThrust         = new Fix(br.ReadInt32());
            PlayerShip.ReverseThrust     = new Fix(br.ReadInt32());
            PlayerShip.Brakes            = new Fix(br.ReadInt32());
            PlayerShip.Wiggle            = new Fix(br.ReadInt32());
            PlayerShip.MaxRotationThrust = new Fix(br.ReadInt32());
            for (int x = 0; x < 8; x++)
            {
                PlayerShip.GunPoints[x] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
            }

            int NumCockpits = br.ReadInt32();

            for (int x = 0; x < NumCockpits; x++)
            {
                Cockpits.Add(br.ReadUInt16());
            }
            //Build a table of all multiplayer bitmaps, to inject into the object bitmap table
            FirstMultiBitmapNum = br.ReadInt32();

            int NumReactors = br.ReadInt32();

            for (int x = 0; x < NumReactors; x++)
            {
                Reactor reactor = new Reactor();
                reactor.ModelNum = br.ReadInt32();
                reactor.NumGuns  = br.ReadInt32();
                for (int y = 0; y < 8; y++)
                {
                    reactor.GunPoints[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                for (int y = 0; y < 8; y++)
                {
                    reactor.GunDirs[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                Reactors.Add(reactor);
            }
            PlayerShip.MarkerModel = br.ReadInt32();
            //2620
            if (Version < 3)
            {
                ExitModelnum          = br.ReadInt32();
                DestroyedExitModelnum = br.ReadInt32();
            }
            for (int x = 0; x < 2620; x++)
            {
                try
                {
                    BitmapXLATData[x] = br.ReadUInt16();
                }
                catch (EndOfStreamException) //Descent 2's official HAM files have only 2600 XLAT entries, but later versions of the game attempt to read 2620.
                {
                    break;
                }
            }

            if (Version < 3)
            {
                br.BaseStream.Seek(sndptr, SeekOrigin.Begin);
                int dataToRead = (int)(br.BaseStream.Length - br.BaseStream.Position);
                sounddata = br.ReadBytes(dataToRead);
            }

            hasRead = true;
            //br.Dispose();
        }
Example #4
0
        public void Read(Stream stream)
        {
            BinaryReader  br     = new BinaryReader(stream);
            HAMDataReader reader = new HAMDataReader();

            if (LoadData)
            {
                DataPointer = br.ReadInt32();
                //So there's no sig, so we're going to take a guess based on the pointer. If it's greater than max bitmaps, we'll assume it's a descent 1 1.4+ piggy file
                if (DataPointer <= 1800)
                {
                    throw new ArgumentException("Cannot read this .PIG file");
                }

                numTextures = br.ReadInt32();
                for (int i = 0; i < 800; i++)
                {
                    Textures[i] = br.ReadUInt16();
                }

                for (int i = 0; i < 800; i++)
                {
                    TMapInfo[i] = reader.ReadTMAPInfoDescent1(br);
                }

                SoundIDs  = br.ReadBytes(250);
                AltSounds = br.ReadBytes(250);

                numVClips = br.ReadInt32(); //this value is bogus. rip
                for (int i = 0; i < 70; i++)
                {
                    VClips[i] = reader.ReadVClip(br);
                }

                numEClips = br.ReadInt32();
                for (int i = 0; i < 60; i++)
                {
                    EClips[i] = reader.ReadEClip(br);
                }

                numWClips = br.ReadInt32();
                for (int i = 0; i < 30; i++)
                {
                    WClips[i] = reader.ReadWClipDescent1(br);
                }

                numRobots = br.ReadInt32();
                for (int i = 0; i < 30; i++)
                {
                    Robots[i] = reader.ReadRobotDescent1(br);
                }

                numJoints = br.ReadInt32();
                for (int i = 0; i < 600; i++)
                {
                    JointPos joint = new JointPos();
                    joint.JointNum = br.ReadInt16();
                    joint.Angles.P = br.ReadInt16();
                    joint.Angles.B = br.ReadInt16();
                    joint.Angles.H = br.ReadInt16();
                    Joints[i]      = joint;
                }

                numWeapons = br.ReadInt32();
                for (int i = 0; i < 30; i++)
                {
                    Weapons[i] = reader.ReadWeaponInfoDescent1(br);
                }

                numPowerups = br.ReadInt32();
                for (int i = 0; i < 29; i++)
                {
                    Powerup powerup = new Powerup();
                    powerup.VClipNum = br.ReadInt32();
                    powerup.HitSound = br.ReadInt32();
                    powerup.Size     = new Fix(br.ReadInt32());
                    powerup.Light    = new Fix(br.ReadInt32());
                    Powerups[i]      = powerup;
                }

                numModels = br.ReadInt32();
                for (int i = 0; i < numModels; i++)
                {
                    Models[i] = reader.ReadPolymodelInfo(br);
                }
                for (int i = 0; i < numModels; i++)
                {
                    Models[i].InterpreterData = br.ReadBytes(Models[i].ModelIDTASize);
                }
                for (int i = 0; i < Gauges.Length; i++)
                {
                    Gauges[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 85; i++)
                {
                    int num = br.ReadInt32();
                    if (i < numModels)
                    {
                        Models[i].DyingModelnum = num;
                    }
                    else
                    {
                        int wtfIsThis = num;
                    }
                }
                for (int i = 0; i < 85; i++)
                {
                    int num = br.ReadInt32();

                    if (i < numModels)
                    {
                        Models[i].DeadModelnum = num;
                    }
                    else
                    {
                        int wtfIsThis = num;
                    }
                }

                for (int i = 0; i < 210; i++)
                {
                    ObjBitmaps[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 210; i++)
                {
                    ObjBitmapPointers[i] = br.ReadUInt16();
                }

                PlayerShip                   = new Ship();
                PlayerShip.ModelNum          = br.ReadInt32();
                PlayerShip.DeathVClipNum     = br.ReadInt32();
                PlayerShip.Mass              = new Fix(br.ReadInt32());
                PlayerShip.Drag              = new Fix(br.ReadInt32());
                PlayerShip.MaxThrust         = new Fix(br.ReadInt32());
                PlayerShip.ReverseThrust     = new Fix(br.ReadInt32());
                PlayerShip.Brakes            = new Fix(br.ReadInt32());
                PlayerShip.Wiggle            = new Fix(br.ReadInt32());
                PlayerShip.MaxRotationThrust = new Fix(br.ReadInt32());
                for (int x = 0; x < 8; x++)
                {
                    PlayerShip.GunPoints[x] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                numCockpits = br.ReadInt32();
                for (int i = 0; i < 4; i++)
                {
                    Cockpits[i] = br.ReadUInt16();
                }

                //heh
                SoundIDs  = br.ReadBytes(250);
                AltSounds = br.ReadBytes(250);

                numObjects = br.ReadInt32();
                for (int i = 0; i < 100; i++)
                {
                    ObjectTypes[i].type = (EditorObjectType)(br.ReadSByte());
                }
                for (int i = 0; i < 100; i++)
                {
                    ObjectTypes[i].id = br.ReadByte();
                }
                for (int i = 0; i < 100; i++)
                {
                    ObjectTypes[i].strength = new Fix(br.ReadInt32());
                    //Console.WriteLine("type: {0}({3})\nid: {1}\nstr: {2}", ObjectTypes[i].type, ObjectTypes[i].id, ObjectTypes[i].strength, (int)ObjectTypes[i].type);
                }
                FirstMultiBitmapNum = br.ReadInt32();
                reactor.NumGuns     = br.ReadInt32();
                for (int y = 0; y < 4; y++)
                {
                    reactor.GunPoints[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                for (int y = 0; y < 4; y++)
                {
                    reactor.GunDirs[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }

                exitModelnum          = br.ReadInt32();
                destroyedExitModelnum = br.ReadInt32();

                for (int i = 0; i < 1800; i++)
                {
                    BitmapXLATData[i] = br.ReadUInt16();
                }
            }


            //Init a bogus texture for all piggyfiles
            PIGImage bogusTexture = new PIGImage(64, 64, 0, 0, 0, 0, "bogus", 0);

            bogusTexture.Data = new byte[64 * 64];
            //Create an X using descent 1 palette indicies. For accuracy. Heh
            for (int i = 0; i < 4096; i++)
            {
                bogusTexture.Data[i] = 85;
            }
            for (int i = 0; i < 64; i++)
            {
                bogusTexture.Data[i * 64 + i]        = 193;
                bogusTexture.Data[i * 64 + (63 - i)] = 193;
            }
            Bitmaps.Add(bogusTexture);

            if (LoadData)
            {
                br.BaseStream.Seek(DataPointer, SeekOrigin.Begin);
            }

            int numBitmaps = br.ReadInt32();
            int numSounds  = br.ReadInt32();

            for (int i = 0; i < numBitmaps; i++)
            {
                bool hashitnull = false;

                byte[] localNameBytes = br.ReadBytes(8);
                char[] localname      = new char[8];

                for (int j = 0; j < 8; j++)
                {
                    char c = (char)localNameBytes[j];

                    if (c == 0)
                    {
                        hashitnull = true;
                    }
                    if (!hashitnull)
                    {
                        localname[j] = c;
                    }
                }

                string imagename = new String(localname);
                imagename = imagename.Trim(' ', '\0');
                byte framedata = br.ReadByte();
                byte lx        = br.ReadByte();
                byte ly        = br.ReadByte();
                byte flags     = br.ReadByte();
                byte average   = br.ReadByte();
                int  offset    = br.ReadInt32();

                PIGImage image = new PIGImage(lx, ly, framedata, flags, average, offset, imagename, big);
                image.LocalName = localNameBytes;
                Bitmaps.Add(image);
            }

            for (int i = 0; i < numSounds; i++)
            {
                bool hashitnull = false;

                byte[] localNameBytes = br.ReadBytes(8);
                char[] localname      = new char[8];

                for (int j = 0; j < 8; j++)
                {
                    char c = (char)localNameBytes[j];

                    if (c == 0)
                    {
                        hashitnull = true;
                    }
                    if (!hashitnull)
                    {
                        localname[j] = c;
                    }
                }

                string soundname = new string(localname);
                soundname = soundname.Trim(' ', '\0');
                int num1   = br.ReadInt32();
                int num2   = br.ReadInt32();
                int offset = br.ReadInt32();

                SoundData sound = new SoundData {
                    Data = null
                };
                sound.Name      = soundname;
                sound.LocalName = localNameBytes;
                sound.Offset    = offset;
                sound.Length    = num1;
                Sounds.Add(sound);
            }

            int basePointer = (int)br.BaseStream.Position;

            for (int i = 1; i < Bitmaps.Count; i++)
            {
                br.BaseStream.Seek(basePointer + Bitmaps[i].Offset, SeekOrigin.Begin);
                if ((Bitmaps[i].Flags & PIGImage.BM_FLAG_RLE) != 0)
                {
                    int compressedSize = br.ReadInt32();
                    Bitmaps[i].Data = br.ReadBytes(compressedSize - 4);
                }
                else
                {
                    Bitmaps[i].Data = br.ReadBytes(Bitmaps[i].Width * Bitmaps[i].Height);
                }
            }

            for (int i = 0; i < Sounds.Count; i++)
            {
                br.BaseStream.Seek(basePointer + Sounds[i].Offset, SeekOrigin.Begin);

                var soundBytes = br.ReadBytes(Sounds[i].Length);

                var ps = Sounds[i];

                ps.Data = soundBytes;
            }

            br.Dispose();
        }