Lerning to use datagrid

setblock will now check if checksumtable needs to be updated even if the imported block has a correct checksum.
This commit is contained in:
suloku
2016-03-07 19:38:42 +01:00
parent c8962d24d7
commit 93bbbc0bd6
4 changed files with 1353 additions and 223 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -55,6 +55,8 @@ namespace BW_tool
checkboxlist.Add(check8c);
checkboxlist.Add(check8l);
checkboxlist.Add(check8r);
dataGridView1.Rows.Add(19);
forest = new FOREST(MainForm.save.B2W2? MainForm.save.getBlockDec(60) : MainForm.save.getBlockDec(61));
unlock8box.SelectedIndex = forest.Unlock8;
@@ -156,6 +158,7 @@ namespace BW_tool
forest.Indexpkm = 0;
slot.Value = forest.Indexpkm;
updateGrid();
}
@@ -191,6 +194,49 @@ namespace BW_tool
updatearea();
updateslot();
}
void updateGrid()
{
int n;
int i;
int temp = forest.Indexpkm;
for (i=0;i<20;i++)
{
if (forest.Area > 0 && forest.Area < 3 && i > 9)
{
dataGridView1.Rows[i].Cells[0].Value = " ";
dataGridView1.Rows[i].Cells[1].Value = " ";
dataGridView1.Rows[i].Cells[2].Value = " ";
dataGridView1.Rows[i].Cells[3].Value = " ";
dataGridView1.Rows[i].Cells[4].Value = " ";
}else
{
forest.Indexpkm = i;
if (forest.Species == 0)
{
dataGridView1.Rows[i].Cells[0].Value = " ";
dataGridView1.Rows[i].Cells[1].Value = " ";
dataGridView1.Rows[i].Cells[2].Value = " ";
dataGridView1.Rows[i].Cells[3].Value = " ";
dataGridView1.Rows[i].Cells[4].Value = " ";
}
else
{
dataGridView1.Rows[i].Cells[0].Value = TEXT.pkmlist[forest.Species];
dataGridView1.Rows[i].Cells[1].Value = TEXT.movelist[forest.Move];
dataGridView1.Rows[i].Cells[2].Value = forest.Gender;
dataGridView1.Rows[i].Cells[3].Value = forest.Form;
dataGridView1.Rows[i].Cells[4].Value = forest.Animation;
}
}
}
forest.Indexpkm = temp;
}
void DataGridView1CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//if (!(forest.Area >0 && forest.Area > 4 && dataGridView1.CurrentRow.Index > 9))
slot.Value = (int)dataGridView1.CurrentRow.Index;
}
public class FOREST
{

View File

@@ -117,4 +117,19 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Species.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Move.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Gender.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Form.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Anim.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@@ -338,7 +338,8 @@ namespace BW_tool
{
//Recalculate checksum before applying to savedata
ushort crc = ccitt16(input.Take(blocks[index].Length).ToArray());
if (crc != BitConverter.ToUInt16(input, blocks[index].Checksum - blocks[index].Offset)) {
ushort crcintable = BitConverter.ToUInt16(Data, ((blocks[blocksnum].Offset) + (index * 2)));
if (crc != BitConverter.ToUInt16(input, blocks[index].Checksum - blocks[index].Offset) || crc!=crcintable) {
Array.Copy(BitConverter.GetBytes(crc), 0, input, blocks[index].Checksum - blocks[index].Offset, 2);
//Update CRC tables
Array.Copy(BitConverter.GetBytes(crc), 0, Data, ((blocks[blocksnum].Offset) + (index * 2)), 2);
@@ -409,6 +410,12 @@ namespace BW_tool
if (crc != BitConverter.ToUInt16(Data, blocks[i].Checksum)) {
if (correct) {
Array.Copy(BitConverter.GetBytes(crc), 0, Data, blocks[i].Checksum, 2);
//Update CRC tables
Array.Copy(BitConverter.GetBytes(crc), 0, Data, ((blocks[blocksnum].Offset) + (i * 2)), 2);
//recalculate crc table's checksum
ushort crctable = ccitt16(Data.Skip(blocks[blocksnum].Offset).Take(((blocksnum + 1) * 2)).ToArray());
Array.Copy(BitConverter.GetBytes(crctable), 0, Data, blocks[blocksnum].Checksum, 2);
if (!firstcorrect) {
firstcorrect = true;
correctedblocks = correctedblocks + i.ToString();
@@ -447,6 +454,12 @@ namespace BW_tool
if (crc != BitConverter.ToUInt16(Data, blocks[i].Checksum + backupoffset)) {
if (correct) {
Array.Copy(BitConverter.GetBytes(crc), 0, Data, blocks[i].Checksum + backupoffset, 2);
//Update CRC tables
Array.Copy(BitConverter.GetBytes(crc), 0, Data, ((blocks[blocksnum].Offset) + (i * 2) + backupoffset), 2);
//recalculate crc table's checksum
ushort crctable = ccitt16(Data.Skip(blocks[blocksnum].Offset + backupoffset).Take(((blocksnum + 1) * 2)).ToArray());
Array.Copy(BitConverter.GetBytes(crctable), 0, Data, blocks[blocksnum].Checksum + backupoffset, 2);
if (!firstcorrect) {
firstcorrect = true;
correctedblocks = correctedblocks + i.ToString();