private const int SIZE_RESERVED = 0x8000; // unpacked box data public override byte[] Write(bool DSV) { for (int i = 0; i < BoxCount; i++) { PokemonList1 boxPL = new PokemonList1(Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese); int slot = 0; for (int j = 0; j < boxPL.Pokemon.Length; j++) { PK1 boxPK = (PK1)getPKM(getData(getBoxOffset(i) + j * SIZE_STORED, SIZE_STORED)); if (boxPK.Species > 0) { boxPL[slot++] = boxPK; } } if (i < BoxCount / 2) { boxPL.GetBytes().CopyTo(Data, 0x4000 + i * SIZE_STOREDBOX); } else { boxPL.GetBytes().CopyTo(Data, 0x6000 + (i - BoxCount / 2) * SIZE_STOREDBOX); } if (i == CurrentBox) { boxPL.GetBytes().CopyTo(Data, Japanese ? 0x302D : 0x30C0); } } PokemonList1 partyPL = new PokemonList1(PokemonList1.CapacityType.Party, Japanese); int pSlot = 0; for (int i = 0; i < 6; i++) { PK1 partyPK = (PK1)getPKM(getData(getPartyOffset(i), SIZE_STORED)); if (partyPK.Species > 0) { partyPL[pSlot++] = partyPK; } } partyPL.GetBytes().CopyTo(Data, Japanese ? 0x2ED5 : 0x2F2C); // Daycare is read-only, but in case it ever becomes editable, copy it back in. byte[] rawDC = getData(getDaycareSlotOffset(loc: 0, slot: 0), SIZE_STORED); byte[] dc = new byte[1 + 2 * StringLength + PKX.SIZE_1STORED]; dc[0] = rawDC[0]; Array.Copy(rawDC, 2 + 1 + PKX.SIZE_1PARTY + StringLength, dc, 1, StringLength); Array.Copy(rawDC, 2 + 1 + PKX.SIZE_1PARTY, dc, 1 + StringLength, StringLength); Array.Copy(rawDC, 2 + 1, dc, 1 + 2 * StringLength, PKX.SIZE_1STORED); dc.CopyTo(Data, Japanese ? 0x2CA7 : 0x2CF4); setChecksums(); byte[] outData = new byte[Data.Length - SIZE_RESERVED]; Array.Copy(Data, outData, outData.Length); return(outData); }
public SAV1(byte[] data = null) { Data = data == null ? new byte[SaveUtil.SIZE_G1RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); Version = data == null ? GameVersion.RBY : SaveUtil.getIsG1SAV(Data); if (Version == GameVersion.Invalid) return; Box = Data.Length; Array.Resize(ref Data, Data.Length + SIZE_RESERVED); Party = getPartyOffset(0); Japanese = SaveUtil.getIsG1SAVJ(data); Personal = PersonalTable.RBY; // Stash boxes after the save file's end. byte[] TempBox = new byte[SIZE_STOREDBOX]; for (int i = 0; i < BoxCount; i++) { if (i < BoxCount / 2) Array.Copy(Data, 0x4000 + i * TempBox.Length, TempBox, 0, TempBox.Length); else Array.Copy(Data, 0x6000 + (i - BoxCount / 2) * TempBox.Length, TempBox, 0, TempBox.Length); PokemonList1 PL1 = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese); for (int j = 0; j < PL1.Pokemon.Length; j++) { if (j < PL1.Count) { byte[] pkDat = new PokemonList1(PL1[j]).GetBytes(); pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED); } else { byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED); } } } Array.Copy(Data, Japanese ? 0x302D : 0x30C0, TempBox, 0, TempBox.Length); PokemonList1 curBoxPL = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese); for (int i = 0; i < curBoxPL.Pokemon.Length; i++) { if (i < curBoxPL.Count) { byte[] pkDat = new PokemonList1(curBoxPL[i]).GetBytes(); pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED); } else { byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED); } } byte[] TempParty = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Party, Japanese)]; Array.Copy(Data, Japanese ? 0x2ED5 : 0x2F2C, TempParty, 0, TempParty.Length); PokemonList1 partyList = new PokemonList1(TempParty, PokemonList1.CapacityType.Party, Japanese); for (int i = 0; i < partyList.Pokemon.Length; i++) { if (i < partyList.Count) { byte[] pkDat = new PokemonList1(partyList[i]).GetBytes(); pkDat.CopyTo(Data, getPartyOffset(i)); } else { byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; pkDat.CopyTo(Data, getPartyOffset(i)); } } byte[] rawDC = new byte[0x38]; Array.Copy(Data, Japanese ? 0x2CA7 : 0x2CF4, rawDC, 0, rawDC.Length); byte[] TempDaycare = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; TempDaycare[0] = rawDC[0]; Array.Copy(rawDC, 1, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY + StringLength, StringLength); Array.Copy(rawDC, 1 + StringLength, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY, StringLength); Array.Copy(rawDC, 1 + 2 * StringLength, TempDaycare, 2 + 1, PKX.SIZE_1STORED); PokemonList1 daycareList = new PokemonList1(TempDaycare, PokemonList1.CapacityType.Single, Japanese); daycareList.GetBytes().CopyTo(Data, getPartyOffset(7)); Daycare = getPartyOffset(7); // Enable Pokedex editing PokeDex = 0; if (!Exportable) resetBoxes(); }
public SAV1(byte[] data = null) { Data = data == null ? new byte[SaveUtil.SIZE_G1RAW] : (byte[])data.Clone(); BAK = (byte[])Data.Clone(); Exportable = !Data.SequenceEqual(new byte[Data.Length]); Version = data == null ? GameVersion.RBY : SaveUtil.getIsG1SAV(Data); if (Version == GameVersion.Invalid) { return; } Box = Data.Length; Array.Resize(ref Data, Data.Length + SIZE_RESERVED); Party = getPartyOffset(0); Japanese = SaveUtil.getIsG1SAVJ(data); Personal = PersonalTable.RBY; // Stash boxes after the save file's end. byte[] TempBox = new byte[SIZE_STOREDBOX]; for (int i = 0; i < BoxCount; i++) { if (i < BoxCount / 2) { Array.Copy(Data, 0x4000 + i * TempBox.Length, TempBox, 0, TempBox.Length); } else { Array.Copy(Data, 0x6000 + (i - BoxCount / 2) * TempBox.Length, TempBox, 0, TempBox.Length); } PokemonList1 PL1 = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese); for (int j = 0; j < PL1.Pokemon.Length; j++) { if (j < PL1.Count) { byte[] pkDat = new PokemonList1(PL1[j]).GetBytes(); pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED); } else { byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED); } } } Array.Copy(Data, Japanese ? 0x302D : 0x30C0, TempBox, 0, TempBox.Length); PokemonList1 curBoxPL = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese); for (int i = 0; i < curBoxPL.Pokemon.Length; i++) { if (i < curBoxPL.Count) { byte[] pkDat = new PokemonList1(curBoxPL[i]).GetBytes(); pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED); } else { byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED); } } byte[] TempParty = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Party, Japanese)]; Array.Copy(Data, Japanese ? 0x2ED5 : 0x2F2C, TempParty, 0, TempParty.Length); PokemonList1 partyList = new PokemonList1(TempParty, PokemonList1.CapacityType.Party, Japanese); for (int i = 0; i < partyList.Pokemon.Length; i++) { if (i < partyList.Count) { byte[] pkDat = new PokemonList1(partyList[i]).GetBytes(); pkDat.CopyTo(Data, getPartyOffset(i)); } else { byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; pkDat.CopyTo(Data, getPartyOffset(i)); } } byte[] rawDC = new byte[0x38]; Array.Copy(Data, Japanese ? 0x2CA7 : 0x2CF4, rawDC, 0, rawDC.Length); byte[] TempDaycare = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)]; TempDaycare[0] = rawDC[0]; Array.Copy(rawDC, 1, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY + StringLength, StringLength); Array.Copy(rawDC, 1 + StringLength, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY, StringLength); Array.Copy(rawDC, 1 + 2 * StringLength, TempDaycare, 2 + 1, PKX.SIZE_1STORED); PokemonList1 daycareList = new PokemonList1(TempDaycare, PokemonList1.CapacityType.Single, Japanese); daycareList.GetBytes().CopyTo(Data, getPartyOffset(7)); Daycare = getPartyOffset(7); // Enable Pokedex editing PokeDex = 0; if (!Exportable) { resetBoxes(); } }
public override byte[] Write(bool DSV) { for (int i = 0; i < BoxCount; i++) { PokemonList1 boxPL = new PokemonList1(Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese); int slot = 0; for (int j = 0; j < boxPL.Pokemon.Length; j++) { PK1 boxPK = (PK1) getPKM(getData(getBoxOffset(i) + j*SIZE_STORED, SIZE_STORED)); if (boxPK.Species > 0) boxPL[slot++] = boxPK; } if (i < BoxCount / 2) boxPL.GetBytes().CopyTo(Data, 0x4000 + i * SIZE_STOREDBOX); else boxPL.GetBytes().CopyTo(Data, 0x6000 + (i - BoxCount / 2) * SIZE_STOREDBOX); if (i == CurrentBox) boxPL.GetBytes().CopyTo(Data, Japanese ? 0x302D : 0x30C0); } PokemonList1 partyPL = new PokemonList1(PokemonList1.CapacityType.Party, Japanese); int pSlot = 0; for (int i = 0; i < 6; i++) { PK1 partyPK = (PK1)getPKM(getData(getPartyOffset(i), SIZE_STORED)); if (partyPK.Species > 0) partyPL[pSlot++] = partyPK; } partyPL.GetBytes().CopyTo(Data, Japanese ? 0x2ED5 : 0x2F2C); // Daycare is read-only, but in case it ever becomes editable, copy it back in. byte[] rawDC = getData(getDaycareSlotOffset(loc: 0, slot: 0), SIZE_STORED); byte[] dc = new byte[1 + 2*StringLength + PKX.SIZE_1STORED]; dc[0] = rawDC[0]; Array.Copy(rawDC, 2 + 1 + PKX.SIZE_1PARTY + StringLength, dc, 1, StringLength); Array.Copy(rawDC, 2 + 1 + PKX.SIZE_1PARTY, dc, 1 + StringLength, StringLength); Array.Copy(rawDC, 2 + 1, dc, 1 + 2*StringLength, PKX.SIZE_1STORED); dc.CopyTo(Data, Japanese ? 0x2CA7 : 0x2CF4); setChecksums(); byte[] outData = new byte[Data.Length - SIZE_RESERVED]; Array.Copy(Data, outData, outData.Length); return outData; }