GetValue() public method

public GetValue ( int i ) : string
i int
return string
Example #1
0
        internal Area(Project p, int i) : base(p, i)
        {
            areaFile = Project.GetFileWithLabel("areaData");

            areaData = areaFile.GetData("areaData", Index * 8);


            // If this is Seasons, it's possible that areaData does not point to 8 bytes as
            // expected, but instead to an "m_SeasonalData" macro.
            if (areaData.CommandLowerCase == "m_seasonalarea")
            {
                int season = 0;
                areaData = Project.GetData(areaData.GetValue(0), season * 8);
            }

            // Initialize graphics state
            graphicsState = new GraphicsState();
            // Global palettes
            PaletteHeaderGroup globalPaletteHeaderGroup =
                Project.GetIndexedDataType <PaletteHeaderGroup>(0xf);

            graphicsState.AddPaletteHeaderGroup(globalPaletteHeaderGroup, PaletteGroupType.Common);

            Data data = areaData;

            flags1 = p.EvalToInt(data.GetValue(0));

            data   = data.NextData;
            flags2 = p.EvalToInt(data.GetValue(0));

            data = data.NextData;
            SetUniqueGfx(Project.EvalToInt(data.GetValue(0)));

            data = data.NextData;
            SetMainGfx(Project.EvalToInt(data.GetValue(0)));

            data = data.NextData;
            SetPaletteHeader(Project.EvalToInt(data.GetValue(0)));

            data = data.NextData;
            SetTileset(Project.EvalToInt(data.GetValue(0)));

            data        = data.NextData;
            layoutGroup = Project.EvalToInt(data.GetValue(0));

            data = data.NextData;
            SetAnimation((byte)Project.EvalToInt(data.GetValue(0)));
        }
Example #2
0
        internal AnimationGroup(Project p, int i) : base(p, i)
        {
            FileParser parser  = Project.GetFileWithLabel("animationGroupTable");
            Data       pointer = parser.GetData("animationGroupTable", 2 * Index);
            string     label   = pointer.GetValue(0);

            Data data = parser.GetData(label);
            int  b1   = Project.EvalToInt(data.GetValue(0));

            data = data.NextData;
            int bits = b1 & 0xf;

            if (bits >= 0xf)
            {
                _numAnimations = 4;
            }
            else if (bits >= 0x7)
            {
                _numAnimations = 3;
            }
            else if (bits >= 0x3)
            {
                _numAnimations = 2;
            }
            else if (bits >= 0x1)
            {
                _numAnimations = 1;
            }
            else
            {
                _numAnimations = 0;
            }

            for (int j = 0; j < NumAnimations; j++)
            {
                if (data.CommandLowerCase != ".dw")
                {
                    throw new Exception("Malformatted animation group data (index 0x" +
                                        Index.ToString("x") + "\n");
                }
                animations[j] = Project.GetDataType <Animation>(data.GetValue(0));
                data          = data.NextData;
            }
        }
Example #3
0
        void UpdateRoomData()
        {
            // Get the tileDataFile
            int        layoutGroup = area.LayoutGroup;
            string     label       = "room" + ((layoutGroup << 8) + (Index & 0xff)).ToString("X4").ToLower();
            FileParser parserFile  = Project.GetFileWithLabel(label);
            Data       data        = parserFile.GetData(label);

            if (data.CommandLowerCase != "m_roomlayoutdata")
            {
                throw new Exception("Expected label \"" + label + "\" to be followed by the m_RoomLayoutData macro.");
            }
            string roomString = data.GetValue(0) + ".bin";

            try {
                tileDataFile = Project.GetBinaryFile(
                    "rooms/" + Project.GameString + "/small/" + roomString);
            }
            catch (FileNotFoundException) {
                try {
                    tileDataFile = Project.GetBinaryFile(
                        "rooms/" + Project.GameString + "/large/" + roomString);
                }
                catch (FileNotFoundException) {
                    throw new FileNotFoundException("Couldn't find \"" + roomString + "\" in \"rooms/small\" or \"rooms/large\".");
                }
            }

            if (tileDataFile.Length == 80)   // Small map
            {
                width  = fileWidth = 10;
                height = 8;
            }
            else if (tileDataFile.Length == 176)   // Large map
            {
                width     = 0xf;
                fileWidth = 0x10;
                height    = 0xb;
            }
            else
            {
                throw new Exception("Size of file \"" + tileDataFile.Name + "\" was invalid!");
            }
        }
Example #4
0
        internal TilesetHeaderGroup(Project p, int i) : base(p, i)
        {
            FileParser tableFile   = Project.GetFileWithLabel("tilesetHeaderGroupTable");
            Data       pointerData = tableFile.GetData("tilesetHeaderGroupTable", Index * 2);
            string     labelName   = pointerData.GetValue(0);

            FileParser        headerFile = Project.GetFileWithLabel(labelName);
            TilesetHeaderData headerData = headerFile.GetData(labelName) as TilesetHeaderData;
            bool next = true;

            while (next)
            {
                if (headerData == null)
                {
                    throw new Exception("Expected tileset header group " + Index.ToString("X") + " to reference tileset header data (m_TilesetHeader)");
                }

                Stream dataFile = headerData.ReferencedData;
                dataFile.Position = 0;
                if (headerData.DestAddress == Project.EvalToInt("w3TileMappingIndices"))
                {
                    // Mappings
                    mappingsDataFile = dataFile;
                }
                else if (headerData.DestAddress == Project.EvalToInt("w3TileCollisions"))
                {
                    // Collisions
                    collisionsDataFile = dataFile;
                }

                if (headerData.ShouldHaveNext())
                {
                    headerData = headerData.NextData as TilesetHeaderData;
                    if (headerData != null)
                    {
                        next = true;
                    }
                }
                else
                {
                    next = false;
                }
            }
        }
Example #5
0
        internal WarpSourceGroup(Project p, int id) : base(p, id)
        {
            fileParser = Project.GetFileWithLabel("warpSourcesTable");
            Data   d     = fileParser.GetData("warpSourcesTable", id * 2);
            string label = d.GetValue(0);

            warpSourceDataList = new List <WarpSourceData>();
            WarpSourceData warpData = fileParser.GetData(label) as WarpSourceData;

            while (warpData != null && warpData.WarpSourceType != WarpSourceType.WarpSourcesEnd)
            {
                warpSourceDataList.Add(warpData);
                warpData = warpData.NextData as WarpSourceData;
            }
            if (warpData != null)
            {
                warpSourceDataList.Add(warpData); // WarpSourcesEnd
            }
        }
Example #6
0
        internal EnemyObject(Project p, int i) : base(p, i)
        {
            try {
                objectData = p.GetData("enemyData", ID * 4);

                _objectGfxHeaderIndex = (byte)objectData.GetIntValue(0);
                _collisionReactionSet = (byte)objectData.GetIntValue(1);

                byte lookupIndex; // TODO: use this
                byte b3;

                if (objectData.GetNumValues() == 4)
                {
                    lookupIndex = (byte)objectData.GetIntValue(2);
                    b3          = (byte)(objectData.GetIntValue(3));
                }
                else
                {
                    Data subidData = Project.GetData(objectData.GetValue(2));
                    int  count     = SubID;
                    while (count > 0 && (subidData.GetIntValue(0) & 0x80) == 0x80)
                    {
                        subidData = subidData.NextData;
                        subidData = subidData.NextData;
                        count--;
                    }
                    lookupIndex = (byte)subidData.GetIntValue(0);
                    b3          = (byte)(subidData.NextData.GetIntValue(0));
                }

                _tileIndexBase = (byte)((b3 & 0xf) * 2);
                _oamFlagsBase  = (byte)(b3 >> 4);
            }
            catch (InvalidLookupException e) {
                Console.WriteLine(e.ToString());
                objectData = null;
            }
            catch (FormatException e) {
                Console.WriteLine(e.ToString());
                objectData = null;
            }
        }
Example #7
0
 public virtual string GetStringValue()
 {
     return(data.GetValue(valueIndex));
 }
        public ObjectAnimationFrame(ObjectAnimation anim, Data animData)
        {
            _animation = anim;
            _animData  = animData;

            Color[][] palettes = anim.GetPalettes();

            try {
                // Note: this "index" is more like index*2, since it's added directly to the offset
                // without being multiplied first
                int oamIndex = (byte)_animData.NextData.GetIntValue(0);

                // Get entry in oam table for this object
                Data oamPtr = Project.GetData(_animation.OamTableName, oamIndex);
                _oamData = Project.GetData(oamPtr.GetValue(0));

                // Load sprite images
                int  _numSprites = _oamData.GetIntValue(0);
                Data data        = _oamData.NextData;

                for (int i = 0; i < _numSprites; i++)
                {
                    int y = (sbyte)data.GetIntValue(0) - 16;
                    data = data.NextData;
                    int x = (sbyte)data.GetIntValue(0) - 8;
                    data = data.NextData;
                    int tileIndex = data.GetIntValue(0) + _animation.TileIndexBase;
                    data = data.NextData;
                    byte flags = (byte)(data.GetIntValue(0) | _animation.OamFlagsBase);
                    data = data.NextData;

                    ObjectGfxHeaderData gfxHeader = _animation.ObjectGfxHeaderData;
                    int origTileIndex             = tileIndex;

                    while (tileIndex >= 0x20)
                    {
                        if (gfxHeader.ShouldHaveNext)
                        {
                            gfxHeader  = gfxHeader.NextGfxHeader;
                            tileIndex -= 0x20;
                        }
                        else
                        {
                            throw new InvalidAnimationException("Tileindex out of range (" + tileIndex + ")");
                        }
                    }

                    int    tileOffset = (tileIndex & 0xfe) * 16;
                    Stream gfxStream  = gfxHeader.GfxStream;

                    if (gfxStream.Length - tileOffset < 0x20)
                    {
                        throw new InvalidAnimationException("Sprite not defined in gfx data");
                    }

                    gfxStream.Seek(tileOffset, SeekOrigin.Begin);
                    byte[] gfxData = new byte[0x20];
                    gfxStream.Read(gfxData, 0, 0x20);

                    Bitmap bitmap = GbGraphics.TileToBitmap(gfxData, palettes[flags & 7], flags);
                    bitmaps.Add(new Tuple <Bitmap, int, int>(bitmap, x, y));
                }
            }
            catch (InvalidLookupException e) {
                bitmaps = null;
                throw new InvalidAnimationException(e);
            }
            catch (FormatException e) {
                bitmaps = null;
                throw new InvalidAnimationException(e);
            }
        }