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(); }
public byte AddAbility(ItemType item) { byte animGfxNum = (byte)(Rom.NumOfAnimGfx + item - ItemType.Long); // find empty spot in palette int palRow = 15; for (int r = 1; r < 14; r++) { ushort color = palette.GetColor(r, 1); bool blank = true; for (int c = 2; c < 16; c++) { if (palette.GetColor(r, c) != color) { blank = false; break; } } if (blank) { Palette itemPal = item.AbilityPalette(); palette.CopyRows(itemPal, 0, r, 1); palRow = r + 2; break; } } // find empty spot in animGfx int animGfxSlot = 0; for (int i = 0; i < 0x10; i++) { if (animTileset[i * 3] == 0) { animTileset[i * 3] = animGfxNum; animGfxSlot = i; break; } } // find empty spot in tile table int blockNum = 0x4C; int tileVal = 0x40; for (int i = 0x4C; i < 0x50; i++) { int offset = i * 4 + 1; if (tilemap[offset] == 0x40 && tilemap[offset + 1] == 0x40 && tilemap[offset + 2] == 0x40 && tilemap[offset + 3] == 0x40) { tileVal = (palRow << 12) | (animGfxSlot * 4); tilemap[offset] = (ushort)tileVal; tilemap[offset + 1] = (ushort)(tileVal + 1); tilemap[offset + 2] = (ushort)(tileVal + 2); tilemap[offset + 3] = (ushort)(tileVal + 3); blockNum = i; break; } } // fix Tilemap400 int tm400Offset = rom.Tilemap400Offset + (0xD0 + item - ItemType.Long) * 8; rom.Write16(tm400Offset, (ushort)tileVal); rom.Write16(tm400Offset + 2, (ushort)(tileVal + 1)); rom.Write16(tm400Offset + 4, (ushort)(tileVal + 2)); rom.Write16(tm400Offset + 6, (ushort)(tileVal + 3)); return((byte)blockNum); }