Beispiel #1
0
        public SPR(IFFChunk BaseChunk)
            : base(BaseChunk)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Version1 = Reader.ReadUShort();
            Version2 = Reader.ReadUShort();

            if(Version1 == 0)
            {
                Version = Version2;
                Reader = new FileReader(new MemoryStream(Reader.ReadToEnd()), true);
            }
            else
                Version = Version1;

            uint SpriteCount = Reader.ReadUInt32();
            m_PaletteID = Reader.ReadUInt32();

            if (Version >= 502 && Version <= 505)
            {
                //TODO: Should this be stored?
                for (int i = 0; i < SpriteCount; i++)
                    m_OffsetTable.Add(Reader.ReadUInt32());
            }
            else
                m_OffsetTable.Add((uint)Reader.Position);

            Reader.Close();
            //m_Data = null; //DON'T DO THIS!
        }
Beispiel #2
0
        public DGRP(IFFChunk BaseChunk)
            : base(BaseChunk)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            m_Version = Reader.ReadUShort();

            switch(m_Version)
            {
                case 20000:
                    ImageCount = Reader.ReadUShort();
                    break;
                case 20001:
                    ImageCount = Reader.ReadUShort();
                    break;
                case 20003:
                    ImageCount = Reader.ReadUInt32();
                    break;
                case 20004:
                    ImageCount = Reader.ReadUInt32();
                    break;
            }

            for(int i = 0; i < ImageCount; i++)
            {
                Images.Add(new DGRPImg(Reader, m_Version));
            }

            Reader.Close();
            m_Data = null;
        }
Beispiel #3
0
        public OBJf(IFFChunk BaseChunk)
            : base(BaseChunk)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Reader.ReadBytes(4); //Zero
            Reader.ReadBytes(4); //Version
            Reader.ReadBytes(4); //Magic

            uint Count = Reader.ReadUInt32();

            for (int i = 0; i < Count; i++)
            {
                OBJfFunctionPair FuncPair = new OBJfFunctionPair();
                FuncPair.ConditionFunction = Reader.ReadUShort();
                FuncPair.ActionFunction = Reader.ReadUShort();
                FunctionTable.Add(i, FuncPair);
            }

            Reader.Close();
            m_Data = null;
        }
Beispiel #4
0
        public Anim(Stream Data)
        {
            m_Reader = new FileReader(Data, true);

            m_Reader.ReadUInt32(); //Version

            ASCIIEncoding Enc = new ASCIIEncoding();
            Name = Enc.GetString(m_Reader.ReadBytes(m_Reader.ReadUShort()));
            Duration = m_Reader.ReadFloat();
            Distance = m_Reader.ReadFloat();
            IsMoving = (m_Reader.ReadByte() != 0) ? true : false;
            TranslationsCount = m_Reader.ReadUInt32();

            Translations = new float[TranslationsCount, 3];

            for(int i = 0; i < TranslationsCount; i++)
            {
                Translations[i, 0] = m_Reader.ReadFloat();
                Translations[i, 1] = m_Reader.ReadFloat();
                Translations[i, 2] = m_Reader.ReadFloat();
            }

            RotationsCount = m_Reader.ReadUInt32();

            Rotations = new float[RotationsCount, 4];

            for (int i = 0; i < RotationsCount; i++)
            {
                Rotations[i, 0] = m_Reader.ReadFloat();
                Rotations[i, 1] = m_Reader.ReadFloat();
                Rotations[i, 2] = m_Reader.ReadFloat();
                Rotations[i, 3] = m_Reader.ReadFloat();
            }

            MotionCount = m_Reader.ReadUInt32();

            for(int i = 0; i < MotionCount; i++)
                Motions.Add(new Motion(m_Reader));

            m_Reader.Close();
        }
        public Skeleton(Stream Data)
        {
            m_Reader = new FileReader(Data, true);

            m_Reader.ReadUInt32(); //Version
            Name = m_Reader.ReadPascalString();
            BoneCount = m_Reader.ReadUShort();

            for(int i = 0; i < BoneCount; i++)
            {
                Bones.Add(new Bone(m_Reader, i));
            }

            /** Construct tree **/
            foreach (Bone bone in Bones)
                bone.Children = Bones.Where(x => x.ParentName == bone.Name).ToArray();

            RootBone = Bones.FirstOrDefault(x => x.ParentName == "NULL");

            m_Reader.Close();
        }
Beispiel #6
0
        public CST(IFFChunk BaseChunk)
            : base(BaseChunk)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Version = Reader.ReadInt16();
            ushort NumStrings = 0;

            if ((Reader.StreamLength - Reader.Position) > 2)
            {
                switch (Version)
                {
                    case 0:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = LanguageCodes.unused;
                            Str.TranslatedStr = Reader.ReadPascalString();

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -1:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = LanguageCodes.unused;
                            Str.TranslatedStr = Reader.ReadCString();

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -2:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = LanguageCodes.unused;
                            Str.TranslatedStr = Reader.ReadCString();
                            Reader.ReadCString(); //Comment

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -3:
                        NumStrings = Reader.ReadUShort();

                        for (int i = 0; i < NumStrings; i++)
                        {
                            TranslatedString Str = new TranslatedString();
                            Str.LangCode = (LanguageCodes)Reader.ReadByte();
                            Str.TranslatedStr = Reader.ReadCString();
                            Reader.ReadCString(); //Comment

                            if (Strings.ContainsKey(Str.LangCode))
                                Strings[Str.LangCode].Add(Str);
                            else
                            {
                                List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                LanguageSet.Add(Str);
                                Strings.Add(Str.LangCode, LanguageSet);
                            }
                        }

                        break;
                    case -4:
                        byte LanguageSets = Reader.ReadByte();
                        for (int i = 0; i < LanguageSets; i++)
                        {
                            NumStrings = Reader.ReadUShort();

                            for (int j = 0; j < NumStrings; j++)
                            {
                                TranslatedString Str = new TranslatedString();
                                Str.LangCode = (LanguageCodes)(Reader.ReadByte() + 1);
                                Str.TranslatedStr = Reader.ReadString();
                                Reader.ReadString(); //Comment

                                if (Strings.ContainsKey(Str.LangCode))
                                    Strings[Str.LangCode].Add(Str);
                                else
                                {
                                    List<TranslatedString> LanguageSet = new List<TranslatedString>();
                                    LanguageSet.Add(Str);
                                    Strings.Add(Str.LangCode, LanguageSet);
                                }
                            }
                        }

                        break;
                }
            }

            Reader.Close();
            m_Data = null;
        }
Beispiel #7
0
        public SPR2Frame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SpriteVersion)
        {
            if(SpriteVersion == 1001)
            {
                Reader.ReadUInt32(); //Version
                Reader.ReadUInt32(); //Size
            }

            Width = Reader.ReadUShort();
            Height = Reader.ReadUShort();
            Texture = new Texture2D(Device, Width, Height);
            ZBuffer = new byte[Width * Height];

            uint Flags = Reader.ReadUInt32();
            Reader.ReadUShort(); //Palette.

            TransparentColor = Palette[Reader.ReadUShort()];

            HasZBuffer = (Flags & 0x02) == 0x02;
            HasAlphaChannel = (Flags & 0x04) == 0x04;

            XLocation = Reader.ReadUShort();
            YLocation = Reader.ReadUShort();

            bool EndMarker = false;

            while(!EndMarker)
            {
                ushort Marker = Reader.ReadUShort();
                var Command = Marker >> 13;
                var Count = Marker & 0x1FFF;

                switch(Command)
                {
                    //Fill this row with pixel data that directly follows; the count byte of the row command denotes
                    //the size in bytes of the row's command/count bytes together with the supplied pixel data. In
                    //the pixel data, each pixel command consists of a 3-bit/13-bit command/count header followed by a
                    //block of pixel data padded to a multiple of 2 bytes. If the row is not filled completely, the
                    //remainder is transparent. The pixel commands are:
                    case 0x00:
                        for(int i = 0; i < Count; i++)
                        {
                            ushort PxMarker = Reader.ReadUShort();
                            var PxCommand = PxMarker >> 13;
                            var PxCount = PxMarker & 0x1FFF;

                            Color[] Colors;

                            switch(PxCommand)
                            {
                                //Set the next pixel count pixels in the z-buffer and color channels to the values defined
                                //by the pixel data provided directly after this command. Every group of 2 bytes in the pixel
                                //data provides a luminosity (z-buffer) or color index (color) value to be copied to the row
                                //for the z-buffer channel and color channel, respectively, in that order, using the full
                                //opacity value of 255 for each pixel that is not the transparent color.
                                case 0x01:
                                    Colors = new Color[PxCount];

                                    for(int j = 0; j < PxCount; j++)
                                    {
                                        byte Luminosity = Reader.ReadByte();
                                        byte ColorIndex = Reader.ReadByte();
                                        Colors[j] = Palette[ColorIndex];
                                        ZBuffer[j] = Luminosity;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                                    //Set the next pixel count pixels in the z-buffer, color, and alpha channels to the values
                                    //defined by the pixel data provided directly after this command. Every group of 3 bytes in
                                    //the pixel data, minus the padding byte at the very end (if it exists), provides a luminosity
                                    //(z-buffer and alpha) or color index (color) value to be copied to the row for the z-buffer,
                                    //color, and alpha channels, respectively, in that order. The alpha channel data is grayscale
                                    //in the range 0-31, and the z buffer is in range 0-255.
                                case 0x02:
                                    Colors = new Color[PxCount];

                                    for (int j = 0; j < PxCount; j++)
                                    {
                                        byte Luminosity = Reader.ReadByte();
                                        byte ColorIndex = Reader.ReadByte();
                                        byte Alpha = (byte)(Reader.ReadByte() * 8.2258064516129032258064516129032);
                                        Colors[j] = Palette[ColorIndex];
                                        Colors[j].A = Alpha;
                                        ZBuffer[j] = Luminosity;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                                //Leave the next pixel count pixels in the color channel filled with the transparent color,
                                //in the z-buffer channel filled with 255, and in the alpha channel filled with 0. This pixel
                                //command has no pixel data.
                                case 0x03:
                                    Colors = new Color[PxCount];

                                    for (int j = 0; j < PxCount; j++)
                                    {
                                        Colors[j] = Color.Transparent;
                                        Colors[j].A = 0;
                                        ZBuffer[j] = 255;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                                //Set the next pixel count pixels in the color channel to the palette color indices defined by
                                //the pixel data provided directly after this command.Every byte in the pixel data, minus the
                                //padding byte at the very end(if it exists), provides a color index value to be copied to the
                                //row for the color channel using the full opacity value of 255 and the closest z-buffer value
                                //of 0 if the pixel is not the transparent color, or otherwise the no opacity value of 0 and the
                                //farthest z-buffer value of 255.
                                case 0x06:
                                    Colors = new Color[PxCount];

                                    for (int j = 0; j < PxCount; j++)
                                    {
                                        byte ColorIndex = Reader.ReadByte();
                                        Colors[j] = Palette[ColorIndex];

                                        Colors[j].A = (Palette[ColorIndex] != Color.Transparent) ? (byte)255 : (byte)0;
                                        ZBuffer[j] = (Palette[ColorIndex] != Color.Transparent) ? (byte)0 : (byte)255;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                            }
                        }
                        break;
                    //Leave the next count rows in the color channel filled with the transparent color,
                    //in the z-buffer channel filled with 255, and in the alpha channel filled with 0.
                    case 0x04:
                        for (int j = 0; j < Count; j++)
                        {
                            Color[] Colors = new Color[Width];

                            for (int k = 0; k < Width; k++)
                            {
                                Colors[k] = Color.Transparent;
                                Colors[k].A = 0;
                                ZBuffer[k] = 255;
                            }

                            Texture.SetData<Color>(Colors, 0, Colors.Length);
                        }
                        break;
                    case 0x05:
                        EndMarker = true;
                        break;
                }
            }
        }
Beispiel #8
0
        public DGRPImg(FileReader Reader, uint Version)
        {
            if (Version == 20000 || Version == 20001)
            {
                SpriteCount = Reader.ReadUShort();
                DirectionFlags = Reader.ReadByte();
                ZoomLevel = Reader.ReadByte();

                for (int i = 0; i < SpriteCount; i++)
                    Info.Add(new SpriteInfo(Reader, Version));
            }
            else
            {
                DirectionFlags = Reader.ReadUInt32();
                ZoomLevel = Reader.ReadUInt32();
                SpriteCount = Reader.ReadUInt32();

                for (int i = 0; i < SpriteCount; i++)
                    Info.Add(new SpriteInfo(Reader, Version));
            }
        }
Beispiel #9
0
        /// <summary>
        /// Loads an *.xa file, setting things up for decompression.
        /// Should always be called before DecompressFile().
        /// </summary>
        /// <param name="Data">The data of the *.xa file to process.</param>
        public void LoadFile(byte[] Data)
        {
            m_Reader = new FileReader(new MemoryStream(Data), false);

            m_ID = Convert.ToString(m_Reader.ReadBytes(4));
            m_DecompressedSize = m_Reader.ReadUInt32();
            m_Tag = m_Reader.ReadUShort();
            m_Channels = m_Reader.ReadUShort();
            m_SampleRate = m_Reader.ReadUInt32();
            m_AvgByteRate = m_Reader.ReadUInt32();
            m_Align = m_Reader.ReadUShort();
            m_Bits = m_Reader.ReadUShort();

            m_DecompressedStream = new MemoryStream((int)m_DecompressedSize);
            m_Writer = new BinaryWriter(m_DecompressedStream);
        }
Beispiel #10
0
        /// <summary>
        /// Loads a *.xa file, setting things up for decompression.
        /// Should always be called before DecompressFile().
        /// </summary>
        /// <param name="Path">The path to the *.xa file to load.</param>
        public void LoadFile(string Path)
        {
            m_Reader = new FileReader(File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read), false);

            m_ID = Convert.ToString(m_Reader.ReadBytes(4));
            m_DecompressedSize = m_Reader.ReadUInt32();
            m_Tag = m_Reader.ReadUShort();
            m_Channels = m_Reader.ReadUShort();
            m_SampleRate = m_Reader.ReadUInt32();
            m_AvgByteRate = m_Reader.ReadUInt32();
            m_Align = m_Reader.ReadUShort();
            m_Bits = m_Reader.ReadUShort();

            m_DecompressedStream = new MemoryStream((int)m_DecompressedSize);
            m_Writer = new BinaryWriter(m_DecompressedStream);
        }
Beispiel #11
0
        public OBJD(IFFChunk BaseChunk)
            : base(BaseChunk)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Version = Reader.ReadUInt32();

            switch(Version)
            {
                case 136:
                    m_NumFields = 80;
                    break;
                case 138:
                    m_NumFields = 95;
                    break;
                case 139:
                    m_NumFields = 96;
                    break;
                case 140:
                    m_NumFields = 97;
                    break;
                case 141:
                    m_NumFields = 97;
                    break;
                case 142:
                    m_NumFields = 105;
                    break;
            }

            InitialStackSize = Reader.ReadUShort();
            BaseGraphicID = Reader.ReadUShort();
            NumGraphics = Reader.ReadUShort();
            MainID = Reader.ReadUShort();
            GardeningID = Reader.ReadUShort();
            TTABID = Reader.ReadUShort();
            InteractionGroup = Reader.ReadUShort();
            ObjectType = (OBJDType)Reader.ReadUShort();
            MasterID = Reader.ReadUShort();
            SubIndex = Reader.ReadInt16();
            WashHandsID = Reader.ReadUShort();
            AnimTableID = Reader.ReadUShort();
            GUID = Reader.ReadUInt32();
            Disabled = Reader.ReadUShort();
            Portal = Reader.ReadUShort();
            Price = Reader.ReadUShort();
            BodyStringsID = Reader.ReadUShort();
            SLOTID = Reader.ReadUShort();
            AllowIntersection = Reader.ReadUShort();
            UsesFnTable = Reader.ReadUShort();
            Bitfield1 = Reader.ReadUShort();
            PrepareFoodID = Reader.ReadUShort();
            CookFoodID = Reader.ReadUShort();
            PlaceOnSurfaceID = Reader.ReadUShort();
            DisposeID = Reader.ReadUShort();
            EatFoodID = Reader.ReadUShort();
            PickupFromSLOTID = Reader.ReadUShort();
            WashDishID = Reader.ReadUShort();
            EatingSurfaceID = Reader.ReadUShort();
            Sit = Reader.ReadUShort();
            Stand = Reader.ReadUShort();
            SalePrice = Reader.ReadUShort();
            InitialDepreciation = Reader.ReadUShort();
            DailyDepreciation = Reader.ReadUShort();
            SelfDepreciating = Reader.ReadUShort();
            DepreciationLimit = Reader.ReadUShort();
            RoomFlags = Reader.ReadUShort();
            FunctionFlags = Reader.ReadUShort();
            CatalogStringsID = Reader.ReadUShort();

            Global = Reader.ReadUShort();
            BHAV_Init = Reader.ReadUShort();
            BHAV_Place = Reader.ReadUShort();
            BHAV_UserPickup = Reader.ReadUShort();
            WallStyle = Reader.ReadUShort();
            BHAV_Load = Reader.ReadUShort();
            BHAV_UserPlace = Reader.ReadUShort();
            ObjectVersion = Reader.ReadUShort();
            BHAV_RoomChange = Reader.ReadUShort();
            MotiveEffectsID = Reader.ReadUShort();
            BHAV_Cleanup = Reader.ReadUShort();
            BHAV_LevelInfo = Reader.ReadUShort();
            CatalogID = Reader.ReadUShort();
            BHAV_ServingSurface = Reader.ReadUShort();
            LevelOffset = Reader.ReadUShort();
            Shadow = Reader.ReadUShort();
            NumAttributes = Reader.ReadUShort();

            BHAV_Clean = Reader.ReadUShort();
            BHAV_QueueSkipped = Reader.ReadUShort();
            FrontDirection = Reader.ReadUShort();
            BHAV_WallAdjacencyChanged = Reader.ReadUShort();
            MyLeadObject = Reader.ReadUShort();
            DynamicSpriteBaseId = Reader.ReadUShort();
            NumDynamicSprites = Reader.ReadUShort();

            ChairEntryFlags = Reader.ReadUShort();
            TileWidth = Reader.ReadUShort();
            InhibitSuitCopying = Reader.ReadUShort();
            BuildModeType = Reader.ReadUShort();
            OriginalGUID1 = Reader.ReadUShort();
            OriginalGUID2 = Reader.ReadUShort();
            SuitGUID1 = Reader.ReadUShort();
            SuitGUID2 = Reader.ReadUShort();
            BHAV_Pickup = Reader.ReadUShort();
            ThumbnailGraphic = Reader.ReadUShort();
            ShadowFlags = Reader.ReadUShort();
            FootprintMask = Reader.ReadUShort();
            BHAV_DynamicMultiTileUpdate = Reader.ReadUShort();
            ShadowBrightness = Reader.ReadUShort();
            BHAV_Repair = Reader.ReadUShort();

            if (m_NumFields > 80)
            {
                WallStyleSpriteID = Reader.ReadUShort();
                RatingHunger = Reader.ReadUShort();
                RatingComfort = Reader.ReadUShort();
                RatingHygiene = Reader.ReadUShort();
                RatingBladder = Reader.ReadUShort();
                RatingEnergy = Reader.ReadUShort();
                RatingFun = Reader.ReadUShort();
                RatingRoom = Reader.ReadUShort();
                RatingSkillFlags = Reader.ReadUShort();
            }

            m_Data = null;
        }
Beispiel #12
0
        public SPRFrame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SPRVersion)
        {
            if (Version == 1001)
            {
                Version = Reader.ReadUInt32();
                Size = Reader.ReadUInt32();
            }

            Reader.ReadUInt32(); //Reserved
            Height = Reader.ReadUShort();
            Width = Reader.ReadUShort();

            Texture = new Texture2D(Device, Width, Height);

            for(ushort i = 0; i < Height; i++)
            {
                byte Cmd = Reader.ReadByte();
                byte Count = Reader.ReadByte();

                switch(Cmd)
                {
                    case 0x04:
                        for(byte j = 0; j < Count; j++)
                        {
                            byte PxCmd = Reader.ReadByte();
                            byte PxCount = Reader.ReadByte();
                            Color[] Pixels;

                            switch(PxCmd)
                            {
                                case 0x01:
                                    //Leave the next pixel count pixels as transparent. This pixel command has no pixel data.
                                    Pixels = new Color[Count];
                                    for (int k = 0; k < Count; k++)
                                        Pixels[k] = Color.Transparent;

                                    Texture.SetData<Color>(Pixels, 0, Count);
                                    break;
                                case 0x02:
                                    //Fill the next pixel count pixels with a single palette color.
                                    //The pixel data is two bytes: the first byte denotes the palette color
                                    //index, and the second byte is padding (which is always equal to the
                                    //first byte but is ignored).
                                    Pixels = new Color[Count];
                                    byte ColorIndex = Reader.ReadByte();

                                    for (int k = 0; k < Count; k++)
                                        Pixels[k] = Palette[ColorIndex];

                                    Texture.SetData<Color>(Pixels, 0, Count);
                                    break;
                                case 0x03:
                                    //Set the next pixel count pixels to the palette color indices defined by
                                    //the pixel data provided directly after this command. Each byte in the pixel data,
                                    //minus the padding byte at the very end (if it exists), is a color index value to
                                    //be copied to the row.
                                    Pixels = new Color[Count];

                                    for (int k = 0; k < Count; k++)
                                        Pixels[k] = Palette[Reader.ReadByte()];

                                    Texture.SetData<Color>(Pixels, 0, Count);
                                    break;
                                case 0x09:
                                    //Leave the next count rows as transparent.
                                    for (int k = 0; k < Count; k++)
                                    {
                                        Pixels = new Color[Width];
                                        for (int l = 0; l < Width; l++)
                                            Pixels[l] = Color.Transparent;

                                        Texture.SetData<Color>(Pixels, 0, Width);
                                    }
                                    break;
                            }
                        }
                        break;
                }
            }
        }