Ejemplo n.º 1
0
        public void RemapVClip(int firstFrame, PIGFile piggyFile)
        {
            int      numFrames = 0;
            int      nextFrame = 0;
            PIGImage img       = piggyFile.Bitmaps[firstFrame];

            if (img.IsAnimated)
            {
                //Clear the old animation
                for (int i = 0; i < 30; i++)
                {
                    Frames[i] = 0;
                }

                Frames[numFrames] = (ushort)(firstFrame + numFrames);
                img = piggyFile.Bitmaps[firstFrame + numFrames + 1];
                numFrames++;
                while (img.Frame == numFrames)
                {
                    if (firstFrame + numFrames + 1 >= piggyFile.Bitmaps.Count)
                    {
                        break;
                    }
                    Frames[numFrames] = (ushort)(firstFrame + numFrames);
                    img = piggyFile.Bitmaps[firstFrame + numFrames + 1];
                    numFrames++;
                    nextFrame++;
                }
                this.NumFrames = numFrames;
            }
            FrameTime = PlayTime / NumFrames;
        }
Ejemplo n.º 2
0
        public byte[] GetBitmap(int id)
        {
            if (id >= Bitmaps.Count)
            {
                return(Bitmaps[0].GetData());
            }
            PIGImage image = Bitmaps[id];

            return(image.GetData());
        }
Ejemplo n.º 3
0
        public PIGFile()
        {
            Bitmaps = new List <PIGImage>(2620);
            //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);
        }
Ejemplo n.º 4
0
        public void Read(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);

            uint header  = br.ReadUInt32();
            int  version = br.ReadInt32();

            if (header != Util.MakeSig('D', 'P', 'O', 'G'))
            {
                br.Dispose();
                throw new InvalidDataException("POGFile::Read: POG file has bad header.");
            }
            if (version != 1)
            {
                br.Dispose();
                throw new InvalidDataException(string.Format("POGFile::Read: POG file has bad version. Got {0}, but expected 1", version));
            }

            int textureCount = br.ReadInt32();

            ushort[] replacements = new ushort[textureCount];
            for (int i = 0; i < textureCount; i++)
            {
                replacements[i] = br.ReadUInt16();
            }

            for (int i = 0; i < textureCount; i++)
            {
                bool   hashitnull = false;
                char[] localname  = new char[8];
                for (int j = 0; j < 8; j++)
                {
                    char c = (char)br.ReadByte();
                    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 extension = br.ReadByte();
                byte flag      = br.ReadByte();
                byte average   = br.ReadByte();
                int  offset    = br.ReadInt32();

                PIGImage image = new PIGImage(lx, ly, framedata, flag, average, offset, imagename, extension);
                image.ReplacementNum = replacements[i];
                Bitmaps.Add(image);
            }
            startptr = (int)br.BaseStream.Position;

            for (int i = 0; i < Bitmaps.Count; i++)
            {
                br.BaseStream.Seek(startptr + Bitmaps[i].Offset, SeekOrigin.Begin);
                if (Bitmaps[i].RLECompressed)
                {
                    int compressedSize = br.ReadInt32();
                    Bitmaps[i].Data = br.ReadBytes(compressedSize - 4);
                }
                else
                {
                    Bitmaps[i].Data = br.ReadBytes(Bitmaps[i].Width * Bitmaps[i].Height);
                }
            }
        }
Ejemplo n.º 5
0
        public void Read(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);

            int header  = br.ReadInt32();
            int version = br.ReadInt32();

            if (header != 1195987024)
            {
                br.Dispose();
                throw new InvalidDataException("PIGFile::Read: PIG file has bad header.");
            }
            if (version != 2)
            {
                br.Dispose();
                throw new InvalidDataException(string.Format("PIGFile::Read: PIG file has bad version. Got {0}, but expected 2", version));
            }

            int textureCount = br.ReadInt32();

            for (int x = 0; x < textureCount; x++)
            {
                bool   hashitnull = false;
                char[] localname  = new char[8];
                for (int i = 0; i < 8; i++)
                {
                    char c = (char)br.ReadByte();
                    if (c == 0)
                    {
                        hashitnull = true;
                    }
                    if (!hashitnull)
                    {
                        localname[i] = c;
                    }
                }
                string imagename = new String(localname);
                imagename = imagename.Trim(' ', '\0');
                byte framedata = br.ReadByte();
                byte lx        = br.ReadByte();
                byte ly        = br.ReadByte();
                byte extension = br.ReadByte();
                byte flag      = br.ReadByte();
                byte average   = br.ReadByte();
                int  offset    = br.ReadInt32();

                PIGImage image = new PIGImage(lx, ly, framedata, flag, average, offset, imagename, extension);
                Bitmaps.Add(image);
            }
            startptr = br.BaseStream.Position;

            for (int i = 1; i < Bitmaps.Count; i++)
            {
                br.BaseStream.Seek(startptr + Bitmaps[i].Offset, SeekOrigin.Begin);
                if (Bitmaps[i].RLECompressed)
                {
                    int compressedSize = br.ReadInt32();
                    Bitmaps[i].Data = br.ReadBytes(compressedSize - 4);
                }
                else
                {
                    Bitmaps[i].Data = br.ReadBytes(Bitmaps[i].Width * Bitmaps[i].Height);
                }
                //images[i].LoadData(br);
            }

            br.Dispose();
        }
Ejemplo n.º 6
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();
        }