public void DecompressGroupSeasons(int group, MapLoader mapLoader) { if (gb.Buffer.Length == 0x100000) { throw new Exception("ROM has not been expanded."); } if (group == 0) { for (int season = 0; season < 4; season++) { int address = 0x150000 + (season * 2) * 0x4000; //Bank 0x54 for (int i = 0; i < 256; i++) { mapLoader.loadMap(i, group, season, false, Program.GameTypes.Seasons); MapLoader.Room r = mapLoader.room; gb.BufferLocation = address; gb.WriteBytes(r.decompressed); int count = gb.BufferLocation - address; address = gb.BufferLocation; gb.BufferLocation = 0x42 * 0x4000 + season * 0x400 + i * 4; gb.WriteByte(1); gb.WriteByte((byte)((address - count) / 0x4000)); gb.WriteBytes(gb.Get2BytePointer(address - count)); //Write the new bank indexes /*group = season; //7 + season; * gb.BufferLocation = 0x5C * 0x4000 + group * 2; * gb.WriteBytes(gb.Get2BytePointer(group * 0x100 + 0x20)); * gb.BufferLocation = 0x5C * 0x4000 + group * 0x100 + 0x20 + i; * gb.WriteByte((byte)((address - count) / 0x4000)); * //Write the map-specific header * gb.BufferLocation = 0x40 * 0x4000 + 0x200 + (0x200 * group) + (i * 2); * byte[] b = gb.Get2BytePointer(address - count); * gb.WriteBytes(new byte[] { b[0], (byte)(b[1] - 0x40) }); * group = 0;*/ //gb.WriteBytes(new byte[] { (byte)(count + (address % 0x4000)), (byte)((count + (address % 0x4000)) >> 8) }); } } } else if (group > 0 && group < 4) //Subrosia { int address = 0x104000 + (group * 2) * 0x4000; //Bank 0x41 for (int i = 0; i < 256; i++) { mapLoader.loadMap(i, group, 0, false, Program.GameTypes.Seasons); MapLoader.Room r = mapLoader.room; gb.BufferLocation = address; gb.WriteBytes(r.decompressed); int count = gb.BufferLocation - address; address = gb.BufferLocation; gb.BufferLocation = 0x42 * 0x4000 + 4 * 0x400 + i * 4; gb.WriteByte(1); gb.WriteByte((byte)((address - count) / 0x4000)); gb.WriteBytes(gb.Get2BytePointer(address - count)); } } else { int address = 0x104000 + (group * 3) * 0x4000; //Bank 0x41 for (int i = 0; i < 256; i++) { mapLoader.loadMap(i, group, 0, false, Program.GameTypes.Seasons); MapLoader.Room r = mapLoader.room; gb.BufferLocation = address; gb.WriteBytes(r.decompressed); int count = gb.BufferLocation - address; address = gb.BufferLocation; gb.BufferLocation = 0x42 * 0x4000 + (group + 1) * 0x400 + i * 4; gb.WriteByte(0); gb.WriteByte((byte)((address - count) / 0x4000)); gb.WriteBytes(gb.Get2BytePointer(address - count)); } } //Write the new region header int indexBase = 0x10C4C; if (group == 0) { for (int season = 0; season < 4; season++) { byte a = (byte)(season * 8); gb.BufferLocation = indexBase + a; gb.WriteByte(1); //The map type gb.WriteByte(0x40); //The header pointers will always be in bank 0x40 gb.WriteBytes(new byte[] { 0, (byte)(0x42 + (0x4 * season)) }); // The pointer. 0x300 bytes per group //gb.WriteByte((byte)(0x41 + (season * 2))); //gb.WriteBytes(new byte[] { 0, 0x40 }); //Temporary!! } } else { byte a = 0x20; if (group > 3) { a += (byte)((group - 3) * 8); } gb.BufferLocation = indexBase + a; gb.WriteByte((byte)(group < 4 ? 1 : 0)); //The map type gb.WriteByte(0x40); //The header pointers will always be in bank 0x40 gb.WriteBytes(new byte[] { 0, (byte)(0x42 + (0x4 * (a / 8))) }); // The pointer. 0x400 bytes per group //else // gb.WriteBytes(new byte[] { 0, (byte)(0x32 + (0x3 * (a / 8))) }); //The relative minor pointer. Only 41 because the loading procedure address 0x1000 /*if (group < 4) * gb.WriteByte((byte)(0x41 + ((a / 8) * 2))); * else * gb.WriteByte((byte)(0x46 + (((a / 8) - 4) * 3)))*/ //gb.WriteBytes(new byte[] { 0, 0x40 }); //Temporary!! } }
private void button1_Click(object sender, EventArgs e) { bool dungeon = new MinimapCreator(gb).dungeon(cboArea.SelectedIndex, game); mapLoader.loadMap((int)nMap.Value, new MinimapCreator(gb).getRealMapGroup(cboArea.SelectedIndex, game), 0, true, game); bool sideMap = isSidemap(mapLoader.room); this.sideMap = sideMap; if (!sideMap) { groupBox3.Visible = false; int address = warpLoader.getWarpHeaderAddress(getRealMapGroup(cboArea.SelectedIndex), (int)nMap.Value, new MinimapCreator(gb).dungeon(cboArea.SelectedIndex, game), flag2, game); lastAddress = address; if (address == -1) { groupBox1.Visible = false; groupBox2.Visible = false; button5.Enabled = false; if (!dungeon) { MessageBox.Show("No warp for that map found. To add one, find\nan existing warp on the same group\nand change the index.", "No Warp Found"); } else { MessageBox.Show("No warp for that map found. Either find an\nexisting warp and replace it or have the warp\nlead directly to the underlying or above room.", "No Warp Found"); } return; } Warp w = warpLoader.loadWarp(address); w.srcGroup = (byte)cboArea.SelectedIndex; button5.Enabled = true; loadedWarp = w; if ((w.opcode & 0x40) != 0) { groupBox2.Text = "Warp Header - 0x" + address.ToString("X"); groupBox1.Visible = false; groupBox2.Visible = true; nFType.Value = w.opcode; nFMap.Value = w.map; nPointer.Value = 0x10000 + w.fpointer; } else { groupBox1.Text = "Warp Header - 0x" + address.ToString("X"); groupBox2.Visible = false; groupBox1.Visible = true; nType.Value = w.opcode; nSrcMap.Value = w.map; nWarp.Value = w.index; nDestGroup.Value = w.group; nEntrance.Value = w.entrance; } } else { int address = warpLoader.getSideWarpHeaderAddress((new MinimapCreator(gb).getRealMapGroup(cboArea.SelectedIndex, game) == 4 ? 6 : 7), (int)nMap.Value, game); lastAddress = address; groupBox1.Visible = false; groupBox2.Visible = false; if (address == -1) { groupBox3.Visible = false; MessageBox.Show("No warp for that map found. To add one, find\nan existing warp on the same group\nand change the values to match the format similar\nto a regular side-map warp.", "No Warp Found"); button5.Enabled = false; return; } button5.Enabled = true; groupBox3.Text = "Warp Header - 0x" + address.ToString("X"); groupBox3.Visible = true; Warp w = warpLoader.loadSideWarp(address); w.srcGroup = (byte)cboArea.SelectedIndex; nX.Value = w.x; nSMap.Value = w.map; nSIndex.Value = w.index; nSGroup.Value = w.group; nSEntrance.Value = w.entrance; loadedWarp = w; } }
public void decompressGroup(int group, MapLoader mapLoader, Program.GameTypes game) { if (gb.Buffer.Length == 0x100000) { throw new Exception("ROM has not been expanded."); } if (group < 4) { int address = 0x104000 + (group * 2) * 0x4000; //Bank 0x41 for (int i = 0; i < 256; i++) { /*int rg = group; * if (group == 1) * rg = 2; * else if (group == 2) * rg = 1;*/ mapLoader.loadMap(i, group, 0, false, game); MapLoader.Room r = mapLoader.room; gb.BufferLocation = address; gb.WriteBytes(r.decompressed); int count = gb.BufferLocation - address; address = gb.BufferLocation; //Write the new bank indexes gb.BufferLocation = 0x54 * 0x4000 + group * 2; gb.WriteBytes(gb.Get2BytePointer(group * 0x100 + 0x20)); gb.BufferLocation = 0x54 * 0x4000 + group * 0x100 + 0x20 + i; gb.WriteByte((byte)((address - count) / 0x4000)); //Write the map-specific header gb.BufferLocation = 0x40 * 0x4000 + 0x200 + (0x200 * group) + (i * 2); byte[] b = gb.Get2BytePointer(address - count); gb.WriteBytes(new byte[] { b[0], (byte)(b[1] - 0x40) }); //gb.WriteBytes(new byte[] { (byte)(count + (address % 0x4000)), (byte)((count + (address % 0x4000)) >> 8) }); } } else { int address = 0x104000 + (group * 3) * 0x4000; //Bank 0x41 for (int i = 0; i < 256; i++) { mapLoader.loadMap(i, group, 0, false, game); MapLoader.Room r = mapLoader.room; gb.BufferLocation = address; gb.WriteBytes(r.decompressed); int count = gb.BufferLocation - address; address = gb.BufferLocation; //Write the new bank indexes gb.BufferLocation = 0x54 * 0x4000 + group * 2; gb.WriteBytes(gb.Get2BytePointer(group * 0x100 + 0x20)); gb.BufferLocation = 0x54 * 0x4000 + group * 0x100 + 0x20 + i; gb.WriteByte((byte)((address - count) / 0x4000)); gb.BufferLocation = 0x40 * 0x4000 + 0x200 + (0x200 * group) + (i * 2); byte[] p = gb.Get2BytePointer(address - count); gb.WriteBytes(new byte[] { p[0], (byte)(p[1] + 2) }); //TEMPORARY! } } //Write the new region header int indexBase = 0x10000 + (game == Program.GameTypes.Ages ? 0x0F6C : 0x0C4C); byte a = (byte)(group * 8); gb.BufferLocation = indexBase + a; gb.WriteByte((byte)(group < 4 ? 1 : 0)); //The map type gb.WriteByte(0x40); //The header pointers will always be in bank 0x40 if (group < 4) { gb.WriteBytes(new byte[] { 0, (byte)(0x42 + (0x2 * group)) }); // The pointer. 0x200 bytes per group } else { gb.WriteBytes(new byte[] { 0, (byte)(0x32 + (0x2 * group)) }); //The relative minor pointer. Only 41 because the loading procedure address 0x1000 } if (group < 4) { gb.WriteByte((byte)(0x41 + (group * 2))); } else { gb.WriteByte((byte)(0x46 + ((group - 4) * 3))); } gb.WriteBytes(new byte[] { 0, 0x40 }); //Temporary!! }