mirror of
https://github.com/kwsch/pk3DS.git
synced 2026-10-02 13:57:14 -05:00
Use objects in form
This commit is contained in:
@@ -433,7 +433,7 @@ public class Learnset
|
||||
public Learnset(byte[] data)
|
||||
{
|
||||
if (data.Length < 4 || data.Length % 4 != 0) return; // Detect invalid files, weakly.
|
||||
int Count = (data.Length / 4) - 1;
|
||||
Count = (data.Length / 4) - 1;
|
||||
Moves = new short[Count];
|
||||
Levels = new short[Count];
|
||||
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
|
||||
@@ -479,9 +479,11 @@ public EggMoves(byte[] data)
|
||||
public byte[] Write()
|
||||
{
|
||||
Count = (ushort)Moves.Length;
|
||||
if (Count == 0) return new byte[0];
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(Count);
|
||||
for (int i = 0; i < Count; i++)
|
||||
bw.Write(Moves[i]);
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ private void setupDGV()
|
||||
}
|
||||
dgv.Columns.Add(dgvMove);
|
||||
}
|
||||
|
||||
private EggMoves pkm = new EggMoves(new byte[0]);
|
||||
private void getList()
|
||||
{
|
||||
entry = Util.getIndex(CB_Species);
|
||||
@@ -63,13 +65,13 @@ private void getList()
|
||||
dgv.Rows.Clear();
|
||||
byte[] input = File.ReadAllBytes(files[entry]);
|
||||
if (input.Length == 0) return;
|
||||
int count = BitConverter.ToUInt16(input, 0);
|
||||
if (count < 1) { File.WriteAllBytes(files[entry], new byte[0]); return; }
|
||||
dgv.Rows.Add(count);
|
||||
pkm = new EggMoves(input);
|
||||
if (pkm.Count < 1) { File.WriteAllBytes(files[entry], new byte[0]); return; }
|
||||
dgv.Rows.Add(pkm.Count);
|
||||
|
||||
// Fill Entries
|
||||
for (int i = 0; i < count; i++)
|
||||
dgv.Rows[i].Cells[0].Value = movelist[BitConverter.ToUInt16(input, 2 + i * 2)];
|
||||
for (int i = 0; i < pkm.Count; i++)
|
||||
dgv.Rows[i].Cells[0].Value = movelist[pkm.Moves[i]];
|
||||
|
||||
dgv.CancelEdit();
|
||||
}
|
||||
@@ -82,13 +84,9 @@ private void setList()
|
||||
int move = Array.IndexOf(movelist, dgv.Rows[i].Cells[0].Value);
|
||||
if (move > 0) moves.Add((ushort)move);
|
||||
}
|
||||
ushort[] movevals = moves.ToArray(); if (movevals.Length == 0) { File.WriteAllBytes(files[entry], new byte[0]); return; }
|
||||
byte[] movedata = new byte[2 + movevals.Length * 2];
|
||||
Array.Copy(BitConverter.GetBytes((ushort)movevals.Length), movedata, 2);
|
||||
for (int i = 0; i < movevals.Length; i++)
|
||||
Array.Copy(BitConverter.GetBytes(movevals[i]), 0, movedata, 2 + 2 * i, 2);
|
||||
pkm.Moves = moves.ToArray();
|
||||
|
||||
File.WriteAllBytes(files[entry], movedata);
|
||||
File.WriteAllBytes(files[entry], pkm.Write());
|
||||
}
|
||||
|
||||
private void changeEntry(object sender, EventArgs e)
|
||||
|
||||
@@ -62,6 +62,8 @@ private void setupDGV()
|
||||
dgv.Columns.Add(dgvLevel);
|
||||
dgv.Columns.Add(dgvMove);
|
||||
}
|
||||
|
||||
private Learnset pkm;
|
||||
private void getList()
|
||||
{
|
||||
entry = Util.getIndex(CB_Species);
|
||||
@@ -73,27 +75,15 @@ private void getList()
|
||||
dgv.Rows.Clear();
|
||||
byte[] input = File.ReadAllBytes(files[entry]);
|
||||
if (input.Length <= 4) { File.WriteAllBytes(files[entry], BitConverter.GetBytes(-1)); return; }
|
||||
pkm = new Learnset(input);
|
||||
|
||||
List<short> moves = new List<short>();
|
||||
List<byte> levels = new List<byte>();
|
||||
for (int i = 0; i < (input.Length / 4) - 1; i++)
|
||||
{
|
||||
short move = BitConverter.ToInt16(input, i * 4);
|
||||
if (move < 0) continue;
|
||||
|
||||
moves.Add(move);
|
||||
levels.Add(input[i * 4 + 2]);
|
||||
}
|
||||
short[] moveList = moves.ToArray();
|
||||
byte[] levelList = levels.ToArray();
|
||||
|
||||
dgv.Rows.Add(moveList.Length);
|
||||
dgv.Rows.Add(pkm.Count);
|
||||
|
||||
// Fill Entries
|
||||
for (int i = 0; i < moveList.Length; i++)
|
||||
for (int i = 0; i < pkm.Count; i++)
|
||||
{
|
||||
dgv.Rows[i].Cells[0].Value = levelList[i];
|
||||
dgv.Rows[i].Cells[1].Value = movelist[moveList[i]];
|
||||
dgv.Rows[i].Cells[0].Value = pkm.Levels[i];
|
||||
dgv.Rows[i].Cells[1].Value = movelist[pkm.Moves[i]];
|
||||
}
|
||||
|
||||
dgv.CancelEdit();
|
||||
@@ -101,35 +91,24 @@ private void getList()
|
||||
private void setList()
|
||||
{
|
||||
if (entry < 1 || dumping) return;
|
||||
List<ushort> moves = new List<ushort>();
|
||||
List<ushort> levels = new List<ushort>();
|
||||
List<short> moves = new List<short>();
|
||||
List<short> levels = new List<short>();
|
||||
for (int i = 0; i < dgv.Rows.Count - 1; i++)
|
||||
{
|
||||
int move = Array.IndexOf(movelist, dgv.Rows[i].Cells[1].Value);
|
||||
if (move < 1) continue;
|
||||
|
||||
moves.Add((ushort)move);
|
||||
moves.Add((short)move);
|
||||
string level = (dgv.Rows[i].Cells[0].Value ?? 0).ToString();
|
||||
ushort lv;
|
||||
UInt16.TryParse(level, out lv);
|
||||
short lv;
|
||||
Int16.TryParse(level, out lv);
|
||||
if (lv > 100) lv = 100;
|
||||
else if (lv == 0) lv = 1;
|
||||
levels.Add(lv);
|
||||
}
|
||||
ushort[] movevals = moves.ToArray(); if (movevals.Length == 0) { File.WriteAllBytes(files[entry], BitConverter.GetBytes(-1)); return; }
|
||||
ushort[] levelvals = levels.ToArray();
|
||||
|
||||
byte[] data = new byte[4 + 4 * movevals.Length];
|
||||
for (int i = 0; i < movevals.Length; i++)
|
||||
{
|
||||
Array.Copy(BitConverter.GetBytes(movevals[i]), 0, data, 4 * i, 2);
|
||||
Array.Copy(BitConverter.GetBytes(levelvals[i]), 0, data, 2 + 4 * i, 2);
|
||||
}
|
||||
|
||||
// Cap data
|
||||
Array.Copy(BitConverter.GetBytes(-1), 0, data, data.Length - 4, 4);
|
||||
|
||||
File.WriteAllBytes(files[entry], data);
|
||||
pkm.Moves = moves.ToArray();
|
||||
pkm.Levels = levels.ToArray();
|
||||
File.WriteAllBytes(files[entry], pkm.Write());
|
||||
}
|
||||
|
||||
private void changeEntry(object sender, EventArgs e)
|
||||
|
||||
@@ -67,9 +67,7 @@
|
||||
<Compile Include="3DS\BCLIM.cs" />
|
||||
<Compile Include="Randomizer.cs" />
|
||||
<Compile Include="3DS\RomFS.cs" />
|
||||
<Compile Include="Structs.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Structs.cs" />
|
||||
<Compile Include="Subforms\Patch.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user