PKHeX/SAV/SAV_PokedexORAS.cs

486 lines
19 KiB
C#
Raw Normal View History

2014-07-28 01:30:54 +00:00
using System;
using System.Collections;
using System.Windows.Forms;
namespace PKHeX
{
2014-11-26 03:55:46 +00:00
public partial class SAV_PokedexORAS : Form
2014-07-28 01:30:54 +00:00
{
public SAV_PokedexORAS()
2014-07-28 01:30:54 +00:00
{
InitializeComponent();
Util.TranslateInterface(this, Main.curlanguage);
sav = (byte[])Main.savefile.Clone();
2014-07-28 01:30:54 +00:00
Setup();
editing = false;
2014-08-10 03:56:03 +00:00
LB_Species.SelectedIndex = 0;
TB_Spinda.Text = BitConverter.ToUInt32(sav, Main.SaveGame.Spinda).ToString("X8");
2014-07-28 01:30:54 +00:00
}
public byte[] sav;
2014-11-29 07:46:36 +00:00
public bool[,] specbools = new bool[9, 0x60 * 8];
2014-07-28 01:30:54 +00:00
public bool[,] langbools = new bool[7, 0x60 * 8];
2014-08-12 23:37:41 +00:00
bool editing = true;
2014-07-28 01:30:54 +00:00
private void Setup()
{
// Clear Listbox and ComboBox
LB_Species.Items.Clear();
CB_Species.Items.Clear();
2014-07-28 01:30:54 +00:00
// Fill List
2014-08-10 03:56:03 +00:00
#region Species
{
var species_list = Util.getCBList(Main.specieslist, null);
2014-08-10 03:56:03 +00:00
species_list.RemoveAt(0); // Remove 0th Entry
CB_Species.DisplayMember = "Text";
CB_Species.ValueMember = "Value";
CB_Species.DataSource = species_list;
}
#endregion
2014-07-28 01:30:54 +00:00
for (int i = 1; i < Main.specieslist.Length; i++)
LB_Species.Items.Add(i.ToString("000") + " - " + Main.specieslist[i]);
2014-07-28 01:30:54 +00:00
getBools();
2014-07-28 01:30:54 +00:00
}
private void changeCBSpecies(object sender, EventArgs e)
{
if (editing) return;
editing = true;
int index = (int)CB_Species.SelectedValue;
LB_Species.SelectedIndex = index - 1; // Since we don't allow index0 in combobox, everything is shifted by 1
LB_Species.TopIndex = LB_Species.SelectedIndex;
loadchks();
editing = false;
2014-07-28 01:30:54 +00:00
}
private void changeLBSpecies(object sender, EventArgs e)
{
if (editing) return;
editing = true;
int index = LB_Species.SelectedIndex + 1;
CB_Species.SelectedValue = index;
loadchks();
editing = false;
2014-07-28 01:30:54 +00:00
}
private void loadchks()
{
// Load Bools for the data
int pk;
2014-08-10 03:56:03 +00:00
try
2014-12-14 18:31:53 +00:00
{ pk = Util.getIndex(CB_Species); }
catch { pk = LB_Species.SelectedIndex + 1; }
2014-08-10 03:56:03 +00:00
CheckBox[] CP =
{
2014-11-29 07:46:36 +00:00
CHK_P1,CHK_P2,CHK_P3,CHK_P4,CHK_P5,CHK_P6,CHK_P7,CHK_P8,CHK_P9,
2014-07-28 01:30:54 +00:00
};
CheckBox[] CL =
{
2014-07-28 01:30:54 +00:00
CHK_L1,CHK_L2,CHK_L3,CHK_L4,CHK_L5,CHK_L6,CHK_L7,
};
// Load Partitions
2014-11-29 07:46:36 +00:00
for (int i = 0; i < 9; i++)
2014-07-28 01:30:54 +00:00
CP[i].Checked = specbools[i, pk-1];
for (int i = 0; i < 7; i++)
CL[i].Checked = langbools[i, pk-1];
2014-08-17 22:39:27 +00:00
{
CHK_P1.Enabled = true;
int index = LB_Species.SelectedIndex + 1;
2014-12-12 06:36:39 +00:00
PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(index);
int gt = MonData.GenderRatio;
2014-12-12 06:36:39 +00:00
CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = (gt != 254); // Not Female-Only
CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = (gt != 0) && (gt != 255); // Not Male-Only and Not Genderless
2014-08-17 22:39:27 +00:00
for (int i = 0; i < 7; i++)
CL[i].Enabled = true;
}
2014-11-26 03:55:46 +00:00
// Load Encountered Count
editing = true;
MT_Count.Text = BitConverter.ToUInt16(sav, Main.SaveGame.EncounterCount + (pk - 1) * 2).ToString();
2014-11-26 03:55:46 +00:00
editing = false;
2014-07-28 01:30:54 +00:00
}
private void removedropCB(object sender, KeyEventArgs e)
{
((ComboBox)sender).DroppedDown = false;
}
2014-08-10 03:56:03 +00:00
private void changeLanguageBool(object sender, EventArgs e)
{
int species = LB_Species.SelectedIndex + 1;
langbools[0, (species - 1)] = CHK_L1.Checked;
langbools[1, (species - 1)] = CHK_L2.Checked;
langbools[2, (species - 1)] = CHK_L3.Checked;
langbools[3, (species - 1)] = CHK_L4.Checked;
langbools[4, (species - 1)] = CHK_L5.Checked;
langbools[5, (species - 1)] = CHK_L6.Checked;
langbools[6, (species - 1)] = CHK_L7.Checked;
}
private void changePartitionBool(object sender, EventArgs e)
{
int species = LB_Species.SelectedIndex + 1;
specbools[0, (species - 1)] = CHK_P1.Checked;
specbools[1, (species - 1)] = CHK_P2.Checked;
specbools[2, (species - 1)] = CHK_P3.Checked;
specbools[3, (species - 1)] = CHK_P4.Checked;
specbools[4, (species - 1)] = CHK_P5.Checked;
specbools[5, (species - 1)] = CHK_P6.Checked;
specbools[6, (species - 1)] = CHK_P7.Checked;
specbools[7, (species - 1)] = CHK_P8.Checked;
specbools[8, (species - 1)] = CHK_P9.Checked;
}
2014-08-12 23:37:41 +00:00
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
2014-08-12 23:37:41 +00:00
}
2014-08-10 03:56:03 +00:00
private void B_Save_Click(object sender, EventArgs e)
2014-09-05 05:58:49 +00:00
{
saveChanges();
// Return back to the parent savefile
Array.Copy(sav, Main.savefile, sav.Length);
Close();
2014-09-05 05:58:49 +00:00
}
private void saveChanges()
2014-08-10 03:56:03 +00:00
{
// Save back the Species Bools
// Return to Byte Array
2014-11-29 07:46:36 +00:00
for (int p = 0; p < 9; p++)
2014-08-10 03:56:03 +00:00
{
byte[] sdata = new byte[0x60];
for (int i = 0; i < 0x60 * 8; i++)
if (specbools[p, i])
sdata[i / 8] |= (byte)(1 << i % 8);
Array.Copy(sdata, 0, sav, Main.SaveGame.PokeDex + 0x8 + 0x60 * p, 0x60);
2014-08-10 03:56:03 +00:00
}
// Build new bool array for the Languages
{
2014-11-26 03:55:46 +00:00
bool[] languagedata = new bool[0x27C * 8];
for (int i = 0; i < 722; i++)
2014-08-10 03:56:03 +00:00
for (int l = 0; l < 7; l++)
languagedata[i * 7 + l] = langbools[l, i];
// Return to Byte Array
byte[] ldata = new byte[languagedata.Length / 8];
for (int i = 0; i < languagedata.Length; i++)
if (languagedata[i])
ldata[i / 8] |= (byte)(1 << i % 8);
Array.Copy(ldata, 0, sav, Main.SaveGame.PokeDexLanguageFlags, 0x27C);
2014-08-10 03:56:03 +00:00
}
2014-11-30 04:12:37 +00:00
2014-08-31 21:10:06 +00:00
// Store Spinda Spot
uint PID = Util.getHEXval(TB_Spinda);
Array.Copy(BitConverter.GetBytes(PID), 0, sav, Main.SaveGame.Spinda, 4);
2014-08-10 03:56:03 +00:00
}
2014-08-17 18:30:46 +00:00
private void getBools()
{
// Fill Bit arrays
for (int i = 0; i < 9; i++)
{
byte[] data = new byte[0x60];
int offset = Main.SaveGame.PokeDex + 0x8 + 0x60 * i;
Array.Copy(sav, offset, data, 0, 0x60);
BitArray BitRegion = new BitArray(data);
for (int b = 0; b < (0x60 * 8); b++)
specbools[i, b] = BitRegion[b];
}
// Fill Language arrays
byte[] langdata = new byte[0x280];
Array.Copy(sav, Main.SaveGame.PokeDexLanguageFlags, langdata, 0, 0x280);
BitArray LangRegion = new BitArray(langdata);
for (int b = 0; b < (721); b++) // 721 Species
for (int i = 0; i < 7; i++) // 7 Languages
langbools[i, b] = LangRegion[7 * b + i];
}
2014-08-17 18:30:46 +00:00
private void B_GiveAll_Click(object sender, EventArgs e)
{
2014-08-31 21:10:06 +00:00
if (LB_Species.SelectedIndex > 0x2D0) return;
2014-08-17 22:39:27 +00:00
if (CHK_L1.Enabled)
{
CHK_L1.Checked =
CHK_L2.Checked =
CHK_L3.Checked =
CHK_L4.Checked =
CHK_L5.Checked =
CHK_L6.Checked =
CHK_L7.Checked = ModifierKeys != Keys.Control;
2014-08-17 22:39:27 +00:00
}
if (CHK_P1.Enabled)
{
CHK_P1.Checked = ModifierKeys != Keys.Control;
2014-08-17 22:39:27 +00:00
}
int index = LB_Species.SelectedIndex+1;
2014-12-12 06:36:39 +00:00
PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(index);
int gt = MonData.GenderRatio;
CHK_P2.Checked = CHK_P4.Checked = CHK_P6.Checked = CHK_P8.Checked = ((gt != 254)) && ModifierKeys != Keys.Control;
CHK_P3.Checked = CHK_P5.Checked = CHK_P7.Checked = CHK_P9.Checked = (gt != 0) && (gt != 255) && ModifierKeys != Keys.Control;
2014-12-12 06:36:39 +00:00
2014-08-17 18:30:46 +00:00
changePartitionBool(null, null);
changeLanguageBool(null, null);
2014-08-31 21:10:06 +00:00
LB_Species.SelectedIndex++;
2014-08-17 18:30:46 +00:00
}
private void B_FillDex_Click(object sender, EventArgs e)
{
2014-09-05 05:58:49 +00:00
saveChanges();
// Copy Full Dex Byte Array
2014-11-29 07:46:36 +00:00
// Native Byte Writing
for (int i = 0; i < 0x5A; i++)
sav[Main.SaveGame.PokeDex + 8 + i] = 0xFF;
// Write remainder
sav[Main.SaveGame.PokeDex + 8 + 0x5A] = 0x01;
2014-11-29 07:46:36 +00:00
// Midsection Writing
2014-09-05 05:58:49 +00:00
{
2014-11-29 07:46:36 +00:00
#region Payload
uint[] payload =
{
0x8FFFFFFF, // 20015068
0xFFFFFFFF, // 2001506C
0xFFFFFFFF, // 20015070
0xF7FAFFFF, // 20015074
0xFFFFFFFF, // 20015078
0xFFFFFFFF, // 2001507C
0xFFFFFFFF, // 20015080
0xFFFCDFFF, // 20015084
0xFFFFFFFF, // 20015088
0xFDFFFFFF, // 2001508C
0xFFFFFFFF, // 20015090
0xF7FFFFFF, // 20015094
0x6FFFFFFF, // 20015098
0xFF7FFFFF, // 2001509C
0xDFFFFFFF, // 200150A0
0xFFFFFF7F, // 200150A4
0xFFFFFFFF, // 200150A8
0xFFFFFFE7, // 200150AC
0xFFFFFFFF, // 200150B0
0xFFCFFFFF, // 200150B4
0x8FFFFFFF, // 200150B8
0xFFFFFFFF, // 200150BC
0x0001FFFF, // 200150C0
0x00000000, //
2014-11-29 07:46:36 +00:00
0x7FFFFFFF, // 200150C8
0xFFFFFFFC, // 200150CC
0xFFFCFFFF, // 200150D0
0x7E7FF9E7, // 200150D4
0xFF9C7EF7, // 200150D8
0xFFFFFFFF, // 200150DC
0xFFFFFEFF, // 200150E0
0xF8E3E6FF, // 200150E4
0xFFFFFFFF, // 200150E8
0xFEFFFFF7, // 200150EC
0xFF3CFFFF, // 200150F0
0x081FFFFF, // 200150F4
0xDFFFFFFC, // 200150F8
0xFFE7FFFF, // 200150FC
0x39FFDFFF, // 20015100
0xFFFFC090, // 20015104
0xF9FFFFFF, // 20015108
0xFFFFFFFF, // 2001510C
0xFE3FFFFF, // 20015110
0x1FF39FBF, // 20015114
0xFFFFFE00, // 20015118
0xBFFFFFFF, // 2001511C
0x000007FF, // 10015120
0x00000000, //
2014-11-29 07:46:36 +00:00
0x8FFFFFFF, // 20015128
0xFFFFFFFF, // 2001512C
0xFFFFFFFF, // 20015130
0xF7FAFFFF, // 20015134
0xFFFFFFFF, // 20015138
0xFFFFFFFF, // 2001513C
0xFFFFFFFF, // 20015140
0xFFFCDFFF, // 20015144
0xFFFFFFFF, // 20015148
0xFDFFFFFF, // 2001514C
0xFFFFFFFF, // 20015150
0xF7FFFFFF, // 20015154
0x6FFFFFFF, // 20015158
0xFF7FFFFF, // 2001515C
0xDFFFFFFF, // 20015160
0xFFFFFF7F, // 20015164
0xFFFFFFFF, // 20015168
0xFFFFFFE7, // 2001516C
0xFFFFFFFF, // 20015170
0xFFCFFFFF, // 20015174
0x8FFFFFFF, // 20015178
0xFFFFFFFF, // 2001517C
0x0001FFFF, // 20015180
0x00000000, //
2014-11-29 07:46:36 +00:00
0x7FFFFFFF, // 20015188
0xFFFFFFFC, // 2001518C
0xFFFCFFFF, // 20015190
0x7E7FF9E7, // 20015194
0xFF9C7EF7, // 20015198
0xFFFFFFFF, // 2001519C
0xFFFFFEFF, // 200151A0
0xF8E3E6FF, // 200151A4
0xFFFFFFFF, // 200151A8
0xFEFFFFF7, // 200151AC
0xFF3CFFFF, // 200151B0
0x081FFFFF, // 200151B4
0xDFFFFFFC, // 200151B8
0xFFE7FFFF, // 200151BC
0x39FFDFFF, // 200151C0
0xFFFFC090, // 200151C4
0xF9FFFFFF, // 200151C8
0xFFFFFFFF, // 200151CC
0xFE3FFFFF, // 200151D0
0x1FF39FBF, // 200151D4
0xFFFFFE00, // 200151D8
0xBFFFFFFF, // 200151DC
0x000007FF, // 100151E0
0x00000000, //
2014-11-29 07:46:36 +00:00
0x8FFFFFFF, // 200151E8
0xFFFFFFFF, // 200151EC
0xFFFFFFFF, // 200151F0
0xF7FAFFFF, // 200151F4
0xFFFFFFFF, // 200151F8
0xFFFFFFFF, // 200151FC
0xFFFFFFFF, // 20015200
0xFFFCDFFF, // 20015204
0xFFFFFFFF, // 20015208
0xFDFFFFFF, // 2001520C
0xFFFFFFFF, // 20015210
0xF7FFFFFF, // 20015214
0x6FFFFFFF, // 20015218
0xFF7FFFFF, // 2001521C
0xDFFFFFFF, // 20015220
0xFFFFFF7F, // 20015224
0xFFFFFFFF, // 20015228
0xFFFFFFE7, // 2001522C
0xFFFFFFFF, // 20015230
0xFFCFFFFF, // 20015234
0x8FFFFFFF, // 20015238
0xFFFFFFFF, // 2001523C
0x0001FFFF, // 20015240
0x00000000, //
2014-11-29 07:46:36 +00:00
0x7FFFFFFF, // 20015248
0xFFFFFFFC, // 2001524C
0xFFFCFFFF, // 20015250
0x7E7FF9E7, // 20015254
0xFF9C7EF7, // 20015258
0xFFFFFFFF, // 2001525C
0xFFFFFEFF, // 20015260
0xF8E3E6FF, // 20015264
0xFFFFFFFF, // 20015268
0xFEFFFFF7, // 2001526C
0xFF3CFFFF, // 20015270
0x081FFFFF, // 20015274
0xDFFFFFFC, // 20015278
0xFFE7FFFF, // 2001527C
0x39FFDFFF, // 20015280
0xFFFFC090, // 20015284
0xF9FFFFFF, // 20015288
0xFFFFFFFF, // 2001528C
0xFE3FFFFF, // 20015290
0x1FF39FBF, // 20015294
0xFFFFFE00, // 20015298
0xBFFFFFFF, // 2001529C
0x000007FF, // 100152A0
0x00000000, //
2014-11-29 07:46:36 +00:00
0x8FFFFFFF, // 200152A8
0xFFFFFFFF, // 200152AC
0xFFFFFFFF, // 200152B0
0xF7FAFFFF, // 200152B4
0xFFFFFFFF, // 200152B8
0xFFFFFFFF, // 200152BC
0xFFFFFFFF, // 200152C0
0xFFFCDFFF, // 200152C4
0xFFFFFFFF, // 200152C8
0xFDFFFFFF, // 200152CC
0xFFFFFFFF, // 200152D0
0xF7FFFFFF, // 200152D4
0x6FFFFFFF, // 200152D8
0xFF7FFFFF, // 200152DC
0xDFFFFFFF, // 200152E0
0xFFFFFF7F, // 200152E4
0xFFFFFFFF, // 200152E8
0xFFFFFFE7, // 200152EC
0xFFFFFFFF, // 200152F0
0xFFCFFFFF, // 200152F4
0x8FFFFFFF, // 200152F8
0xFFFFFFFF, // 200152FC
0x0001FFFF, // 20015300
0x00000000, //
2014-11-29 07:46:36 +00:00
0x7FFFFFFF, // 20015308
0xFFFFFFFC, // 2001530C
0xFFFCFFFF, // 20015310
0x7E7FF9E7, // 20015314
0xFF9C7EF7, // 20015318
0xFFFFFFFF, // 2001531C
0xFFFFFEFF, // 20015320
0xF8E3E6FF, // 20015324
0xFFFFFFFF, // 20015328
0xFEFFFFF7, // 2001532C
0xFF3CFFFF, // 20015330
0x081FFFFF, // 20015334
0xDFFFFFFC, // 20015338
0xFFE7FFFF, // 2001533C
0x39FFDFFF, // 20015340
0xFFFFC090, // 20015344
0xF9FFFFFF, // 20015348
0xFFFFFFFF, // 2001534C
0xFE3FFFFF, // 20015350
0x1FF39FBF, // 20015354
0xFFFFFE00, // 20015358
0xBFFFFFFF, // 2001535C
0x000007FF, // 10015360
0x00000000, //
};
2014-11-29 07:46:36 +00:00
#endregion
for (int i = 0; i < payload.Length; i++)
Array.Copy(BitConverter.GetBytes(payload[i]), 0, sav, Main.SaveGame.PokeDex + 68 + 4 * i, 4);
2014-09-05 05:58:49 +00:00
}
2014-11-29 07:46:36 +00:00
// Language Writing
for (int i = 0; i < 0x9D; i++)
Array.Copy(BitConverter.GetBytes(0xFFFFFFFF), 0, sav, Main.SaveGame.PokeDexLanguageFlags + 4 * i, 4);
Array.Copy(BitConverter.GetBytes(0x007FFFFF), 0, sav, Main.SaveGame.PokeDexLanguageFlags + 4 * 0x9D, 4);
2014-11-29 07:46:36 +00:00
// Encounter Count Writing (999*all species)
for (int i = 0; i < 0x2D1; i++)
Array.Copy(BitConverter.GetBytes(999), 0, sav, Main.SaveGame.EncounterCount + i * 2, 2);
// Turn off Italian Petlil
sav[Main.SaveGame.PokeDexLanguageFlags + 0x1DF] &= 0xFE;
2014-11-29 07:46:36 +00:00
// Forms Bool Writing
for (int i = 0; i < 0x9C; i++)
sav[Main.SaveGame.PokeDex + 0x364 + i] = 0xFF;
sav[Main.SaveGame.PokeDex + 0x3FF] = 0x8F; // make sure we don't have FF because CGSE may screw up.
// Fetch the dex bools
getBools();
2014-08-17 18:30:46 +00:00
// Reload the current entry
loadchks();
2014-08-17 18:30:46 +00:00
}
2014-11-26 03:55:46 +00:00
private void changeEncounteredCount(object sender, EventArgs e)
{
if (!editing)
Array.Copy(BitConverter.GetBytes(Math.Min(0xFFFF, Util.ToUInt32(MT_Count))), 0, sav, Main.SaveGame.EncounterCount + (Util.getIndex(CB_Species) - 1) * 2, 2);
2014-11-26 03:55:46 +00:00
}
2014-07-28 01:30:54 +00:00
}
}