コード例 #1
0
    ///////////////////////////////////////////////////////////
    // Function type:  I/O
    // Contributors:   Pokedude
    // Last edit by:   Pokedude
    // Date of edit:   6/4/2016
    //
    ///////////////////////////////////////////////////////////
    bool WildPokemonArea::read(const qboy::Rom &rom, UInt32 offset, UInt32 amount)
    {
        rom.seek(offset); // exception-safe this time

        // Reads the probability and the pointer to the encounter array
        m_Probability = rom.readByte();
        rom.readBytes(3); // padding
        m_Offset =  rom.readPointer();


        // Determines whether the encounter array offset is valid
        if (!rom.seek(m_Offset))
            AME_THROW(WPST_ERROR_DATA, offset + 4);


        // Reads the encounter array
        for (UInt32 i = 0; i < amount; i++)
        {
            WildPokemonEncounter *entry = new WildPokemonEncounter;
            entry->min = rom.readByte();
            entry->max = rom.readByte();
            entry->id = rom.readHWord();
            m_Entries.push_back(entry);
        }


        // Loading successful
        return true;
    }
コード例 #2
0
    ///////////////////////////////////////////////////////////
    // Function type:  I/O
    // Contributors:   Pokedude
    // Last edit by:   Pokedude
    // Date of edit:   6/11/2016
    //
    ///////////////////////////////////////////////////////////
    bool MapHeader::read(const qboy::Rom &rom, UInt32 offset)
    {
        if (!rom.seek(offset))
            AME_THROW(HDR_ERROR_OFFSET, rom.redirected());


        // Reads the map's dimensions
        m_Width = rom.readWord();
        m_Height = rom.readWord();

        // Reads all the pointers within the structure
        m_PtrBorder = rom.readPointerRef();
        m_PtrBlocks = rom.readPointer();
        m_PtrPrimary = rom.readPointerRef();
        m_PtrSecondary = rom.readPointerRef();

        // Determines whether these pointers are valid
        if (!rom.checkOffset(m_PtrBorder))
            AME_THROW(HDR_ERROR_BORDER, offset + 8);
        if (!rom.checkOffset(m_PtrBlocks))
            AME_THROW(HDR_ERROR_BLOCKS, offset + 12);
        if (!rom.checkOffset(m_PtrPrimary))
            AME_THROW(HDR_ERROR_PRIMARY, offset + 16);
        if (!rom.checkOffset(m_PtrSecondary))
            AME_THROW(HDR_ERROR_SECONDARY, offset + 20);


        // Retrieves the border (different between games!)
        if (rom.info().isFRLG())
        {
            QSize borderSize(rom.readByte(), rom.readByte());
            m_Border.read(rom, m_PtrBorder, borderSize);
        }
        else
        {
            m_Border.read(rom, m_PtrBorder, QSize(2, 2));
        }

        // Retrieves the map block data
        rom.seek(m_PtrBlocks);
        for (unsigned i = 0; i < m_Width * m_Height; i++)
        {
            MapBlock *block = new MapBlock;
            UInt16 data = rom.readHWord();

            block->block = (data & 0x3FF);
            block->permission = (data >> 0xA);
            m_Blocks.push_back(block);
        }

        // Loads the tilesets, if necessary
        if ((m_Primary = TilesetManager::get(m_PtrPrimary)) == NULL)
        {
            m_Primary = new Tileset;
            m_Primary->read(rom, m_PtrPrimary);
            TilesetManager::add(m_Primary);
        }
        if ((m_Secondary = TilesetManager::get(m_PtrSecondary)) == NULL)
        {
            m_Secondary = new Tileset;
            m_Secondary->read(rom, m_PtrSecondary);
            TilesetManager::add(m_Secondary);
        }


        // Loading successful
        return true;
    }
コード例 #3
0
ファイル: Tileset.cpp プロジェクト: Tobber98/AwesomeMapEditor
    ///////////////////////////////////////////////////////////
    // Function type:  I/O
    // Contributers:   Pokedude
    // Last edit by:   Pokedude
    // Date of edit:   6/5/2016
    //
    ///////////////////////////////////////////////////////////
    bool Tileset::read(const qboy::Rom &rom, UInt32 offset)
    {
        if (!rom.seek(offset))
            AME_THROW(SET_ERROR_OFFSET, rom.redirected());


        // Reads the first two properties for the following determination
        m_IsCompressed = rom.readByte();
        m_IsPrimary = rom.readByte();
        rom.readHWord(); // padding


        // Determines all differences between FRLG and RSE
        int countPal;
        int countBlock;
        int palAdjustment;
        int uncompSize;
        if (rom.info().isFRLG())
        {
            if (!m_IsPrimary) // = 0 in the games -.-
            {
                countPal = 7;
                countBlock = 640;
                palAdjustment = 0;
                uncompSize = 40960;
            }
            else
            {
                countPal = 6;
                countBlock = 384;
                palAdjustment = 224;
                uncompSize = 24576;
            }
        }
        else
        {
            if (!m_IsPrimary) // = 0 in the games -.-
            {
                countPal = 6;
                countBlock = 512;
                palAdjustment = 0;
                uncompSize = 32768;
            }
            else
            {
                countPal = 7;
                countBlock = 512;
                palAdjustment = 192;
                uncompSize = 32768;
            }
        }


        // Reads all pointers within the tileset structure
        m_PtrImage = rom.readPointer();
        m_PtrPalette = rom.readPointer();
        m_PtrBlocks = rom.readPointer();

        if (rom.info().isFRLG()) // pointers reversed
        {
            m_PtrAnimations = rom.readPointer();
            m_PtrBehaviour = rom.readPointer();
        }
        else
        {
            m_PtrBehaviour = rom.readPointer();
            m_PtrAnimations = rom.readPointer();
        }


        // Determines whether all read pointers are valid
        if (!rom.checkOffset(m_PtrImage))
            AME_THROW(SET_ERROR_IMAGE, offset + 4);
        if (!rom.checkOffset(m_PtrPalette))
            AME_THROW(SET_ERROR_PALETTE, offset + 8);
        if (!rom.checkOffset(m_PtrBlocks))
            AME_THROW(SET_ERROR_BLOCKS, offset + 12);
        if (!rom.checkOffset(m_PtrAnimations))
            AME_THROW(SET_ERROR_ANIM, offset + 16);
        if (!rom.checkOffset(m_PtrBehaviour))
            AME_THROW(SET_ERROR_PROP, offset + 20);


        // Attempts to load the image
        if (m_IsCompressed)
        {
            if (!m_Image->readCompressed(rom, m_PtrImage, 128, true))
                AME_THROW(SET_ERROR_IMGDATA, m_PtrImage);
        }
        else
        {
            if (!m_Image->readUncompressed(rom, m_PtrImage, uncompSize, 128, true))
                AME_THROW(SET_ERROR_IMGDATA, m_PtrImage);
        }

        // Attempts to load the palettes
        for (int i = 0; i < countPal; i++)
        {
            qboy::Palette *pal = new qboy::Palette;
            pal->readUncompressed(rom, m_PtrPalette + palAdjustment + i * 32, 16);
            m_Pals.push_back(pal);
        }

        // Attempts to load the blocks
        rom.seek(m_PtrBlocks);
        for (int i = 0; i < countBlock; i++)
        {
            Block *block = new Block;
            m_Blocks.push_back(block);

            // Each block has 2 layers á 4 tiles
            for (int j = 0; j < 8; j++)
            {
                Tile tile;
                UInt16 data = rom.readHWord();

                // Extracts information from the hword
                tile.tile = (data & 0x3FF);
                tile.palette = ((data & 0xF800) >> 0xC);
                tile.flipX = ((data & 0x400) == 0x400);
                tile.flipY = ((data & 0x800) == 0x800);
                block->tiles[j] = tile;
            }
        }


        // Attempts to load the block properties
        m_Properties->read(rom, m_PtrBehaviour, countBlock);


        // Loading successful
        m_Offset = offset;
        return true;
    }