Esempio n. 1
0
        private void DrawFileSelectHash()
        {
            // apply tweak for hash icons
            Patch.Apply(rom, Resources.ZM_U_hashIcons);

            // compute the hash based on settings and seed
            string s = settings.GetString() + seed;

            byte[] bytes = Encoding.ASCII.GetBytes(s);
            int    hash  = 5381;

            foreach (byte b in bytes)
            {
                hash = (hash << 5) + hash + b;
            }

            const int palPtr = 0x7C7CC;
            const int gfxPtr = 0x7C7E0;
            const int tmPtr  = 0x7C80C;

            // get palette, graphics, and tile table
            int     palOffset = rom.ReadPtr(palPtr);
            Palette filePal   = new Palette(rom, palOffset, 7, palPtr);
            Gfx     fileGfx   = new Gfx(rom, gfxPtr, 32);
            Tilemap fileTm    = new Tilemap(rom, tmPtr, true);

            for (int i = 0; i < 4; i++)
            {
                int index = hash & 15;
                hash >>= 4;
                ItemType item = (index + ItemType.Super);

                // modify palette
                filePal.AppendPalette(item.AbilityPalette());

                // modify graphics
                Gfx       itemGfx = item.AbilityGraphics();
                Rectangle rect    = new Rectangle(0, 0, 2, 2);
                fileGfx.AddGfx(itemGfx, rect, i * 3, 17);

                // modify tile table
                int x   = 9 + i * 3;
                int pal = i + 7;
                fileTm.SetPalette(pal, x, 1);
                fileTm.SetPalette(pal, x, 2);
                fileTm.SetPalette(pal, x + 1, 1);
                fileTm.SetPalette(pal, x + 1, 2);
                fileTm.SetTileNumber(0, x + 2, 1);
                fileTm.SetTileNumber(0, x + 2, 2);
            }

            // write palette, graphics, and tile table
            filePal.Write();
            fileGfx.Write();
            fileTm.Write();
        }