mirror of
https://github.com/kwsch/pk3DS.git
synced 2026-10-02 13:57:14 -05:00
Refactoring
This commit is contained in:
@@ -387,7 +387,7 @@ private void B_Maison_Click(object sender, EventArgs e)
|
||||
bool super = (dr == DialogResult.Yes);
|
||||
string[] files = { (super) ? "maisontrS" : "maisontrN", (super) ? "maisonpkS" : "maisonpkN" };
|
||||
fileGet(files);
|
||||
Invoke((Action)(() => new Maison(super).ShowDialog()));
|
||||
Invoke((Action)(() => new MaisonEditor(super).ShowDialog()));
|
||||
fileSet(files);
|
||||
}).Start();
|
||||
}
|
||||
|
||||
428
pk3DS/Structs.cs
Normal file
428
pk3DS/Structs.cs
Normal file
@@ -0,0 +1,428 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace pk3DS
|
||||
{
|
||||
public class PersonalInfo
|
||||
{
|
||||
public byte HP, ATK, DEF, SPE, SPA, SPD;
|
||||
public int BST;
|
||||
private ushort EVs;
|
||||
public int EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD;
|
||||
public byte[] Types = new byte[2];
|
||||
public byte CatchRate, EvoStage;
|
||||
public ushort[] Items = new ushort[3];
|
||||
public byte Gender, HatchCycles, BaseFriendship, EXPGrowth;
|
||||
public byte[] EggGroups = new byte[2];
|
||||
public byte[] Abilities = new byte[3];
|
||||
public ushort FormeSprite, BaseEXP;
|
||||
public byte FormeCount, Color;
|
||||
public float Height, Weight;
|
||||
public bool[] TMHM;
|
||||
public bool[] Tutors;
|
||||
public bool[][] ORASTutors = new bool[4][];
|
||||
public byte _1B;
|
||||
public ushort _1C;
|
||||
public PersonalInfo(byte[] data)
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
|
||||
{
|
||||
HP = br.ReadByte(); ATK = br.ReadByte(); DEF = br.ReadByte();
|
||||
SPE = br.ReadByte(); SPA = br.ReadByte(); SPD = br.ReadByte();
|
||||
BST = HP + ATK + DEF + SPE + SPA + SPD;
|
||||
|
||||
Types = new[] { br.ReadByte(), br.ReadByte() };
|
||||
CatchRate = br.ReadByte();
|
||||
EvoStage = br.ReadByte();
|
||||
|
||||
EVs = br.ReadUInt16();
|
||||
EV_HP = ((EVs >> 0) & 0x3);
|
||||
EV_ATK = ((EVs >> 2) & 0x3);
|
||||
EV_DEF = ((EVs >> 4) & 0x3);
|
||||
EV_SPE = ((EVs >> 6) & 0x3);
|
||||
EV_SPA = ((EVs >> 8) & 0x3);
|
||||
EV_SPD = ((EVs >> 10) & 0x3);
|
||||
|
||||
Items = new[] { br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16() };
|
||||
Gender = br.ReadByte();
|
||||
HatchCycles = br.ReadByte();
|
||||
BaseFriendship = br.ReadByte();
|
||||
|
||||
EXPGrowth = br.ReadByte();
|
||||
EggGroups = new[] { br.ReadByte(), br.ReadByte() };
|
||||
Abilities = new[] { br.ReadByte(), br.ReadByte(), br.ReadByte() };
|
||||
_1B = br.ReadByte();
|
||||
_1C = br.ReadUInt16();
|
||||
|
||||
FormeSprite = br.ReadUInt16();
|
||||
FormeCount = br.ReadByte();
|
||||
Color = br.ReadByte();
|
||||
BaseEXP = br.ReadUInt16();
|
||||
|
||||
Height = br.ReadUInt16();
|
||||
Weight = br.ReadUInt16();
|
||||
|
||||
byte[] TMHMData = br.ReadBytes(0x10);
|
||||
TMHM = new bool[8 * TMHMData.Length];
|
||||
for (int j = 0; j < TMHM.Length; j++)
|
||||
TMHM[j / 8 + j % 8] = ((TMHMData[j / 8] >> j % 8) & 0x1) == 1; //Bitflags for TMHM
|
||||
|
||||
byte[] TutorData = br.ReadBytes(8);
|
||||
Tutors = new bool[8 * TutorData.Length];
|
||||
for (int j = 0; j < Tutors.Length; j++)
|
||||
Tutors[j / 8 + j % 8] = ((TutorData[j / 8] >> j % 8) & 0x1) == 1; //Bitflags for Tutors
|
||||
|
||||
if (br.BaseStream.Length - br.BaseStream.Position == 0x10) // ORAS
|
||||
{
|
||||
byte[][] ORASTutorData =
|
||||
{
|
||||
br.ReadBytes(2), // 15
|
||||
br.ReadBytes(3), // 17
|
||||
br.ReadBytes(2), // 16
|
||||
br.ReadBytes(2), // 15
|
||||
};
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ORASTutors[i] = new bool[8 * ORASTutorData[i].Length];
|
||||
for (int b = 0; b < 8 * ORASTutorData[i].Length; b++)
|
||||
ORASTutors[i][b] = ((ORASTutorData[i][b / 8] >> b % 8) & 0x1) == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(HP);
|
||||
bw.Write(ATK);
|
||||
bw.Write(DEF);
|
||||
bw.Write(SPE);
|
||||
bw.Write(SPD);
|
||||
bw.Write(SPE);
|
||||
foreach (byte Type in Types) bw.Write(Type);
|
||||
bw.Write(CatchRate);
|
||||
bw.Write(EvoStage);
|
||||
EVs = (ushort)(EVs & 0x80 | (HP >> 0 & 3) | (ATK >> 2 & 3) | (DEF >> 4 & 3) | (SPE >> 6 & 3) | (SPA >> 8 & 3) | (SPD >> 10 & 3));
|
||||
bw.Write(EVs);
|
||||
foreach (ushort Item in Items) bw.Write(Item);
|
||||
bw.Write(Gender);
|
||||
bw.Write(HatchCycles);
|
||||
bw.Write(BaseFriendship);
|
||||
bw.Write(EXPGrowth);
|
||||
foreach (byte EggGroup in EggGroups) bw.Write(EggGroup);
|
||||
foreach (byte Ability in Abilities) bw.Write(Ability);
|
||||
bw.Write(_1B);
|
||||
bw.Write(_1C);
|
||||
bw.Write(FormeSprite);
|
||||
bw.Write(FormeCount);
|
||||
bw.Write(Color);
|
||||
bw.Write(BaseEXP);
|
||||
bw.Write(BitConverter.GetBytes(Convert.ToUInt16(Height)));
|
||||
bw.Write(BitConverter.GetBytes(Convert.ToUInt16(Weight)));
|
||||
|
||||
byte[] TMHMData = new byte[0x10];
|
||||
for (int i = 0; i < TMHM.Length; i++)
|
||||
TMHMData[i % 8] |= (byte)(TMHM[i] ? (1 << i % 8) : 0);
|
||||
bw.Write(TMHMData);
|
||||
|
||||
byte[] TutorData = new byte[8];
|
||||
for (int i = 0; i < Tutors.Length; i++)
|
||||
TutorData[i % 8] |= (byte)(Tutors[i] ? (1 << i % 8) : 0);
|
||||
bw.Write(TutorData);
|
||||
|
||||
while (bw.BaseStream.Length != 0x40) bw.Write((byte)0);
|
||||
|
||||
if (ORASTutors[0] != null) // ORAS Data
|
||||
{
|
||||
byte[][] ORASTutorData =
|
||||
{
|
||||
new byte[2], // 15
|
||||
new byte[3], // 17
|
||||
new byte[2], // 16
|
||||
new byte[2], // 15
|
||||
};
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int b = 0; b < ORASTutors[i].Length; b++)
|
||||
ORASTutorData[i][b / 8] = (byte)(ORASTutors[i][b] ? (1 << b % 8) : 0);
|
||||
|
||||
foreach (byte[] ORASTutor in ORASTutorData) bw.Write(ORASTutor);
|
||||
|
||||
while (bw.BaseStream.Length != 0x50) bw.Write((byte)0);
|
||||
}
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class Trainer
|
||||
{
|
||||
public bool isORAS;
|
||||
public int Format, Class;
|
||||
public bool Item, Moves;
|
||||
public byte BattleType, NumPokemon, AI;
|
||||
public ushort[] Items = new ushort[4];
|
||||
public byte u1, u2, u3;
|
||||
public ushort uORAS;
|
||||
public bool Healer;
|
||||
public byte Money;
|
||||
public ushort Prize;
|
||||
public Pokemon[] Team;
|
||||
public Trainer(byte[] trData, byte[] trPoke, bool ORAS)
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(new MemoryStream(trData)))
|
||||
{
|
||||
isORAS = ORAS;
|
||||
Format = ORAS ? br.ReadUInt16() : br.ReadByte();
|
||||
Class = ORAS ? br.ReadUInt16() : br.ReadByte();
|
||||
if (ORAS) uORAS = br.ReadUInt16();
|
||||
Item = ((Format >> 1) & 1) == 1;
|
||||
Moves = (Format & 1) == 1;
|
||||
BattleType = br.ReadByte();
|
||||
NumPokemon = br.ReadByte();
|
||||
for (int i = 0; i < 4; i++)
|
||||
Items[i] = br.ReadUInt16();
|
||||
AI = br.ReadByte();
|
||||
u1 = br.ReadByte();
|
||||
u2 = br.ReadByte();
|
||||
u3 = br.ReadByte();
|
||||
Healer = br.ReadByte() != 0;
|
||||
Money = br.ReadByte();
|
||||
Prize = br.ReadUInt16();
|
||||
|
||||
// Fetch Team
|
||||
Team = new Pokemon[NumPokemon];
|
||||
byte[][] TeamData = new byte[NumPokemon][];
|
||||
int dataLen = trPoke.Length / NumPokemon;
|
||||
for (int i = 0; i < TeamData.Length; i++)
|
||||
TeamData[i] = trPoke.Skip(i * dataLen).Take(dataLen).ToArray();
|
||||
for (int i = 0; i < NumPokemon; i++)
|
||||
Team[i] = new Pokemon(TeamData[i], Item, Moves);
|
||||
}
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter bw = new BinaryWriter(ms))
|
||||
{
|
||||
Format = Convert.ToByte(Moves) + (Convert.ToByte(Item) << 1);
|
||||
if (isORAS)
|
||||
{ bw.Write((ushort)Format); bw.Write((ushort)Class); bw.Write((ushort)0); }
|
||||
else
|
||||
{ bw.Write((byte)Format); bw.Write((byte)Class); }
|
||||
|
||||
bw.Write(BattleType);
|
||||
bw.Write(NumPokemon);
|
||||
bw.Write(Items[0]);
|
||||
bw.Write(Items[1]);
|
||||
bw.Write(Items[2]);
|
||||
bw.Write(Items[3]);
|
||||
|
||||
bw.Write(AI);
|
||||
bw.Write(u1);
|
||||
bw.Write(u2);
|
||||
bw.Write(u3);
|
||||
bw.Write(Convert.ToByte(Healer));
|
||||
bw.Write(Money);
|
||||
bw.Write(Prize);
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
public byte[] WriteTeam()
|
||||
{
|
||||
return Team.Aggregate(new byte[0], (i, pkm) => i.Concat(pkm.Write(Item, Moves)).ToArray());
|
||||
}
|
||||
|
||||
public class Pokemon
|
||||
{
|
||||
public byte IVs;
|
||||
public byte PID;
|
||||
public ushort Level;
|
||||
public ushort Species;
|
||||
public ushort Form;
|
||||
public int Ability;
|
||||
public int Gender;
|
||||
public int uBit;
|
||||
public ushort Item;
|
||||
public ushort[] Moves = new ushort[4];
|
||||
|
||||
public Pokemon(byte[] data, bool HasItem, bool HasMoves)
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
|
||||
{
|
||||
IVs = br.ReadByte();
|
||||
PID = br.ReadByte();
|
||||
Level = br.ReadUInt16();
|
||||
Species = br.ReadUInt16();
|
||||
Form = br.ReadUInt16();
|
||||
|
||||
Ability = PID >> 4;
|
||||
Gender = PID & 3;
|
||||
uBit = (PID >> 3) & 1;
|
||||
|
||||
if (HasItem)
|
||||
Item = br.ReadUInt16();
|
||||
if (HasMoves)
|
||||
for (int i = 0; i < 4; i++)
|
||||
Moves[i] = br.ReadUInt16();
|
||||
}
|
||||
}
|
||||
public byte[] Write(bool HasItem, bool HasMoves)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(IVs);
|
||||
PID = (byte)(((Ability & 0xF) << 4) | ((uBit & 1) << 3) | (Gender & 0x7));
|
||||
bw.Write(PID);
|
||||
bw.Write(Level);
|
||||
bw.Write(Species);
|
||||
bw.Write(Form);
|
||||
|
||||
if (HasItem)
|
||||
bw.Write(Item);
|
||||
if (HasMoves)
|
||||
foreach (ushort Move in Moves)
|
||||
bw.Write(Move);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class Move
|
||||
{
|
||||
public byte Type, Quality, Category, Power, Accuracy, PP, Priority, InflictPercent,
|
||||
HitMin, HitMax, TurnMin, TurnMax, CritStage, Flinch, Recoil, Heal, Targeting,
|
||||
Stat1, Stat2, Stat3,
|
||||
Stat1Stage, Stat2Stage, Stat3Stage,
|
||||
Stat1Percent, Stat2Percent, Stat3Percent;
|
||||
public ushort Inflict, Effect;
|
||||
public byte _0xB, _0x1E, _0x1F, _0x20, _0x21;
|
||||
public Move(byte[] data)
|
||||
{
|
||||
Type = data[0];
|
||||
Quality = data[1];
|
||||
Category = data[2];
|
||||
Power = data[3];
|
||||
Accuracy = data[4];
|
||||
PP = data[5];
|
||||
Priority = data[6];
|
||||
HitMin = (byte)(data[7] & 0xF);
|
||||
HitMax = (byte)(data[7] >> 4);
|
||||
Inflict = BitConverter.ToUInt16(data, 0x8);
|
||||
InflictPercent = data[0xA];
|
||||
_0xB = data[0xB];
|
||||
TurnMin = data[0xC];
|
||||
TurnMax = data[0xD];
|
||||
CritStage = data[0xE];
|
||||
Flinch = data[0xF];
|
||||
Effect = BitConverter.ToUInt16(data, 0x10);
|
||||
Recoil = data[0x12];
|
||||
Heal = data[0x13];
|
||||
Targeting = data[0x14];
|
||||
Stat1 = data[0x15];
|
||||
Stat2 = data[0x16];
|
||||
Stat3 = data[0x17];
|
||||
Stat1Stage = data[0x18];
|
||||
Stat2Stage = data[0x19];
|
||||
Stat3Stage = data[0x1A];
|
||||
Stat1Percent = data[0x1B];
|
||||
Stat2Percent = data[0x1C];
|
||||
Stat3Percent = data[0x1D];
|
||||
_0x1E = data[0x1E];
|
||||
_0x1F = data[0x1F];
|
||||
_0x20 = data[0x20];
|
||||
_0x21 = data[0x21];
|
||||
}
|
||||
}
|
||||
public class Maison
|
||||
{
|
||||
public class Trainer
|
||||
{
|
||||
public ushort Class;
|
||||
public ushort Count;
|
||||
public ushort[] Choices;
|
||||
|
||||
public Trainer() { }
|
||||
public Trainer(byte[] data)
|
||||
{
|
||||
Class = BitConverter.ToUInt16(data, 0);
|
||||
Count = BitConverter.ToUInt16(data, 0);
|
||||
Choices = new ushort[Count];
|
||||
for (int i = 0; i < Count; i++)
|
||||
Choices[i] = BitConverter.ToUInt16(data, 4 + 2 * i);
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
using (var bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(Class);
|
||||
bw.Write(Count);
|
||||
foreach (ushort Choice in Choices)
|
||||
bw.Write(Choice);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class Pokemon
|
||||
{
|
||||
public ushort Species, Item;
|
||||
public byte EVs, Nature;
|
||||
public ushort[] Moves;
|
||||
public bool HP, ATK, DEF, SPE, SPA, SPD;
|
||||
|
||||
private byte _u1, _u2;
|
||||
|
||||
public Pokemon(byte[] data)
|
||||
{
|
||||
Species = BitConverter.ToUInt16(data, 0);
|
||||
Moves = new[]
|
||||
{
|
||||
BitConverter.ToUInt16(data, 2),
|
||||
BitConverter.ToUInt16(data, 4),
|
||||
BitConverter.ToUInt16(data, 6),
|
||||
BitConverter.ToUInt16(data, 8)
|
||||
};
|
||||
EVs = data[0xA];
|
||||
HP = (EVs >> 0 & 1) == 1;
|
||||
ATK = (EVs >> 1 & 1) == 1;
|
||||
DEF = (EVs >> 2 & 1) == 1;
|
||||
SPE = (EVs >> 3 & 1) == 1;
|
||||
SPA = (EVs >> 4 & 1) == 1;
|
||||
SPD = (EVs >> 5 & 1) == 1;
|
||||
Nature = data[0xB];
|
||||
Item = BitConverter.ToUInt16(data, 0xC);
|
||||
_u1 = data[0xE];
|
||||
_u2 = data[0xF];
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
using (var bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(Species);
|
||||
foreach (ushort Move in Moves)
|
||||
bw.Write(Move);
|
||||
|
||||
EVs &= 0xC0;
|
||||
EVs |= (byte)(HP ? 1 << 0 : 0);
|
||||
EVs |= (byte)(ATK ? 1 << 1 : 0);
|
||||
EVs |= (byte)(DEF ? 1 << 1 : 0);
|
||||
EVs |= (byte)(SPE ? 1 << 1 : 0);
|
||||
EVs |= (byte)(SPA ? 1 << 1 : 0);
|
||||
EVs |= (byte)(SPD ? 1 << 1 : 0);
|
||||
bw.Write(EVs);
|
||||
|
||||
bw.Write(Nature);
|
||||
bw.Write(Item);
|
||||
bw.Write(_u1);
|
||||
bw.Write(_u2);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,9 +168,9 @@ private void B_RandAll_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Get a new random species
|
||||
int oldSpecies = rb[j].SelectedIndex;
|
||||
Personal.Info oldpkm = new Personal.Info(personal[oldSpecies]);
|
||||
PersonalInfo oldpkm = new PersonalInfo(personal[oldSpecies]);
|
||||
int currentSpecies = Array.IndexOf(specieslist, CB_Species.Text);
|
||||
Personal.Info pkm = new Personal.Info(personal[currentSpecies]);
|
||||
PersonalInfo pkm = new PersonalInfo(personal[currentSpecies]);
|
||||
int loopctr = 0; // altering calculatiosn to prevent infinite loops
|
||||
defspecies:
|
||||
int newSpecies = Randomizer.getRandomSpecies(ref sL, ref ctr);
|
||||
|
||||
2
pk3DS/Subforms/Maison.Designer.cs
generated
2
pk3DS/Subforms/Maison.Designer.cs
generated
@@ -1,6 +1,6 @@
|
||||
namespace pk3DS
|
||||
{
|
||||
partial class Maison
|
||||
partial class MaisonEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
namespace pk3DS
|
||||
{
|
||||
public partial class Maison : Form
|
||||
public partial class MaisonEditor : Form
|
||||
{
|
||||
public Maison(bool super)
|
||||
public MaisonEditor(bool super)
|
||||
{
|
||||
Array.Resize(ref specieslist, 722);
|
||||
movelist[0] = specieslist[0] = itemlist[0] = "";
|
||||
@@ -69,7 +69,7 @@ private void getTrainer()
|
||||
|
||||
// Get
|
||||
LB_Choices.Items.Clear();
|
||||
Trainer tr = new Trainer(File.ReadAllBytes(trFiles[trEntry]));
|
||||
Maison.Trainer tr = new Maison.Trainer(File.ReadAllBytes(trFiles[trEntry]));
|
||||
|
||||
CB_Class.SelectedIndex = tr.Class;
|
||||
GB_Trainer.Enabled = tr.Count > 0;
|
||||
@@ -81,9 +81,11 @@ private void setTrainer()
|
||||
{
|
||||
if (trEntry < 0 || !GB_Trainer.Enabled || dumping) return;
|
||||
// Gather
|
||||
Trainer tr = new Trainer();
|
||||
tr.Class = (ushort)CB_Class.SelectedIndex;
|
||||
tr.Count = (ushort)LB_Choices.Items.Count;
|
||||
Maison.Trainer tr = new Maison.Trainer
|
||||
{
|
||||
Class = (ushort) CB_Class.SelectedIndex,
|
||||
Count = (ushort) LB_Choices.Items.Count
|
||||
};
|
||||
tr.Choices = new ushort[tr.Count];
|
||||
for (int i = 0; i < tr.Count; i++)
|
||||
tr.Choices[i] = Convert.ToUInt16(LB_Choices.Items[i].ToString());
|
||||
@@ -93,7 +95,7 @@ private void setTrainer()
|
||||
private void getPokemon()
|
||||
{
|
||||
if (pkEntry < 0 || dumping) return;
|
||||
Pokemon pkm = new Pokemon(File.ReadAllBytes(pkFiles[pkEntry]));
|
||||
Maison.Pokemon pkm = new Maison.Pokemon(File.ReadAllBytes(pkFiles[pkEntry]));
|
||||
|
||||
// Get
|
||||
CB_Move1.SelectedIndex = pkm.Moves[0];
|
||||
@@ -117,20 +119,22 @@ private void setPokemon()
|
||||
if (pkEntry < 0 || dumping) return;
|
||||
|
||||
// Each File is 16 Bytes.
|
||||
Pokemon pkm = new Pokemon(File.ReadAllBytes(pkFiles[pkEntry]));
|
||||
pkm.Species = (ushort) CB_Species.SelectedIndex;
|
||||
Maison.Pokemon pkm = new Maison.Pokemon(File.ReadAllBytes(pkFiles[pkEntry]))
|
||||
{
|
||||
Species = (ushort) CB_Species.SelectedIndex,
|
||||
HP = CHK_HP.Checked,
|
||||
ATK = CHK_ATK.Checked,
|
||||
DEF = CHK_DEF.Checked,
|
||||
SPE = CHK_Spe.Checked,
|
||||
SPA = CHK_SpA.Checked,
|
||||
SPD = CHK_SpD.Checked,
|
||||
Nature = (byte) CB_Nature.SelectedIndex,
|
||||
Item = (ushort) CB_Item.SelectedIndex
|
||||
};
|
||||
pkm.Moves[0] = (ushort)CB_Move1.SelectedIndex;
|
||||
pkm.Moves[1] = (ushort)CB_Move2.SelectedIndex;
|
||||
pkm.Moves[2] = (ushort)CB_Move3.SelectedIndex;
|
||||
pkm.Moves[3] = (ushort)CB_Move4.SelectedIndex;
|
||||
pkm.HP = CHK_HP.Checked;
|
||||
pkm.ATK = CHK_ATK.Checked;
|
||||
pkm.DEF = CHK_DEF.Checked;
|
||||
pkm.SPE = CHK_Spe.Checked;
|
||||
pkm.SPA = CHK_SpA.Checked;
|
||||
pkm.SPD = CHK_SpD.Checked;
|
||||
pkm.Nature = (byte)CB_Nature.SelectedIndex;
|
||||
pkm.Item = (ushort)CB_Item.SelectedIndex;
|
||||
|
||||
byte[] data = pkm.Write();
|
||||
File.WriteAllBytes(pkFiles[pkEntry], data);
|
||||
@@ -211,7 +215,6 @@ private void DumpTRs_Click(object sender, EventArgs e)
|
||||
dumping = false;
|
||||
CB_Trainer.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private void B_DumpPKs_Click(object sender, EventArgs e)
|
||||
{
|
||||
dumping = true;
|
||||
@@ -252,91 +255,5 @@ private void B_DumpPKs_Click(object sender, EventArgs e)
|
||||
dumping = false;
|
||||
CB_Trainer.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
public class Trainer
|
||||
{
|
||||
public ushort Class;
|
||||
public ushort Count;
|
||||
public ushort[] Choices;
|
||||
|
||||
public Trainer(){}
|
||||
public Trainer(byte[] data)
|
||||
{
|
||||
Class = BitConverter.ToUInt16(data, 0);
|
||||
Count = BitConverter.ToUInt16(data, 0);
|
||||
Choices = new ushort[Count];
|
||||
for (int i = 0; i < Count; i++)
|
||||
Choices[i] = BitConverter.ToUInt16(data, 4 + 2*i);
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
using (var bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(Class);
|
||||
bw.Write(Count);
|
||||
foreach (ushort Choice in Choices)
|
||||
bw.Write(Choice);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class Pokemon
|
||||
{
|
||||
public ushort Species, Item;
|
||||
public byte EVs, Nature;
|
||||
public ushort[] Moves;
|
||||
public bool HP, ATK, DEF, SPE, SPA, SPD;
|
||||
|
||||
private byte _u1, _u2;
|
||||
|
||||
public Pokemon(byte[] data)
|
||||
{
|
||||
Species = BitConverter.ToUInt16(data, 0);
|
||||
Moves = new[]
|
||||
{
|
||||
BitConverter.ToUInt16(data, 2),
|
||||
BitConverter.ToUInt16(data, 4),
|
||||
BitConverter.ToUInt16(data, 6),
|
||||
BitConverter.ToUInt16(data, 8)
|
||||
};
|
||||
EVs = data[0xA];
|
||||
HP = (EVs >> 0 & 1) == 1;
|
||||
ATK = (EVs >> 1 & 1) == 1;
|
||||
DEF = (EVs >> 2 & 1) == 1;
|
||||
SPE = (EVs >> 3 & 1) == 1;
|
||||
SPA = (EVs >> 4 & 1) == 1;
|
||||
SPD = (EVs >> 5 & 1) == 1;
|
||||
Nature = data[0xB];
|
||||
Item = BitConverter.ToUInt16(data, 0xC);
|
||||
_u1 = data[0xE];
|
||||
_u2 = data[0xF];
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
using (var bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(Species);
|
||||
foreach (ushort Move in Moves)
|
||||
bw.Write(Move);
|
||||
|
||||
EVs &= 0xC0;
|
||||
EVs |= (byte)(HP ? 1 << 0 : 0);
|
||||
EVs |= (byte)(ATK ? 1 << 1 : 0);
|
||||
EVs |= (byte)(DEF ? 1 << 1 : 0);
|
||||
EVs |= (byte)(SPE ? 1 << 1 : 0);
|
||||
EVs |= (byte)(SPA ? 1 << 1 : 0);
|
||||
EVs |= (byte)(SPD ? 1 << 1 : 0);
|
||||
bw.Write(EVs);
|
||||
|
||||
bw.Write(Nature);
|
||||
bw.Write(Item);
|
||||
bw.Write(_u1);
|
||||
bw.Write(_u2);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,50 +203,4 @@ internal static Move[] getMoves()
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
public class Move
|
||||
{
|
||||
public byte Type, Quality, Category, Power, Accuracy, PP, Priority, InflictPercent,
|
||||
HitMin, HitMax, TurnMin, TurnMax, CritStage, Flinch, Recoil, Heal, Targeting,
|
||||
Stat1, Stat2, Stat3,
|
||||
Stat1Stage, Stat2Stage, Stat3Stage,
|
||||
Stat1Percent, Stat2Percent, Stat3Percent;
|
||||
public ushort Inflict, Effect;
|
||||
public byte _0xB, _0x1E, _0x1F, _0x20, _0x21;
|
||||
public Move(byte[] data)
|
||||
{
|
||||
Type = data[0];
|
||||
Quality = data[1];
|
||||
Category = data[2];
|
||||
Power = data[3];
|
||||
Accuracy = data[4];
|
||||
PP = data[5];
|
||||
Priority = data[6];
|
||||
HitMin = (byte)(data[7] & 0xF);
|
||||
HitMax = (byte)(data[7] >> 4);
|
||||
Inflict = BitConverter.ToUInt16(data, 0x8);
|
||||
InflictPercent = data[0xA];
|
||||
_0xB = data[0xB];
|
||||
TurnMin = data[0xC];
|
||||
TurnMax = data[0xD];
|
||||
CritStage = data[0xE];
|
||||
Flinch = data[0xF];
|
||||
Effect = BitConverter.ToUInt16(data, 0x10);
|
||||
Recoil = data[0x12];
|
||||
Heal = data[0x13];
|
||||
Targeting = data[0x14];
|
||||
Stat1 = data[0x15];
|
||||
Stat2 = data[0x16];
|
||||
Stat3 = data[0x17];
|
||||
Stat1Stage = data[0x18];
|
||||
Stat2Stage = data[0x19];
|
||||
Stat3Stage = data[0x1A];
|
||||
Stat1Percent = data[0x1B];
|
||||
Stat2Percent = data[0x1C];
|
||||
Stat3Percent = data[0x1D];
|
||||
_0x1E = data[0x1E];
|
||||
_0x1F = data[0x1F];
|
||||
_0x20 = data[0x20];
|
||||
_0x21 = data[0x21];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,14 +182,13 @@ private void ByteLimiter(object sender, EventArgs e)
|
||||
else if (Array.IndexOf(ev_boxes, mtb) > -1 && val > 3)
|
||||
mtb.Text = "3";
|
||||
}
|
||||
int bst;
|
||||
|
||||
private Info pkm;
|
||||
private PersonalInfo pkm;
|
||||
private void readInfo()
|
||||
{
|
||||
byte[] array = new byte[Main.oras ? 0x50 : 0x40];
|
||||
Array.Copy(data, array.Length * entry, array, 0, array.Length);
|
||||
pkm = new Info(array);
|
||||
pkm = new PersonalInfo(array);
|
||||
|
||||
TB_BaseHP.Text = pkm.HP.ToString("000");
|
||||
TB_BaseATK.Text = pkm.ATK.ToString("000");
|
||||
@@ -197,7 +196,6 @@ private void readInfo()
|
||||
TB_BaseSPE.Text = pkm.SPE.ToString("000");
|
||||
TB_BaseSPA.Text = pkm.SPA.ToString("000");
|
||||
TB_BaseSPD.Text = pkm.SPD.ToString("000");
|
||||
bst = pkm.BST;
|
||||
TB_HPEVs.Text = pkm.EV_HP.ToString("0");
|
||||
TB_ATKEVs.Text = pkm.EV_ATK.ToString("0");
|
||||
TB_DEFEVs.Text = pkm.EV_DEF.ToString("0");
|
||||
@@ -477,7 +475,7 @@ private void B_Dump_Click(object sender, EventArgs e)
|
||||
CB_Species.SelectedIndex = i; // Get new Species
|
||||
result += "======" + Environment.NewLine + entry + " " + CB_Species.Text + Environment.NewLine + "======" + Environment.NewLine;
|
||||
|
||||
result += String.Format("Base Stats: {0}.{1}.{2}.{3}.{4}.{5} (BST: {6})", TB_BaseHP.Text, TB_BaseATK.Text, TB_BaseDEF.Text, TB_BaseSPA.Text, TB_BaseSPD.Text, TB_BaseSPE.Text, bst) + Environment.NewLine;
|
||||
result += String.Format("Base Stats: {0}.{1}.{2}.{3}.{4}.{5} (BST: {6})", TB_BaseHP.Text, TB_BaseATK.Text, TB_BaseDEF.Text, TB_BaseSPA.Text, TB_BaseSPD.Text, TB_BaseSPE.Text, pkm.BST) + Environment.NewLine;
|
||||
result += String.Format("EV Yield: {0}.{1}.{2}.{3}.{4}.{5}", TB_HPEVs.Text, TB_ATKEVs.Text, TB_DEFEVs.Text, TB_SPAEVs.Text, TB_SPDEVs.Text, TB_SPEEVs.Text) + Environment.NewLine;
|
||||
result += String.Format("Abilities: {0} (1) | {1} (2) | {2} (H)", CB_Ability1.Text, CB_Ability2.Text, CB_Ability3.Text) + Environment.NewLine;
|
||||
|
||||
@@ -622,158 +620,5 @@ internal static string[] getSpeciesIndexStrings(bool oras)
|
||||
Array.Resize(ref species, oras ? species.Length : 799);
|
||||
return species;
|
||||
}
|
||||
|
||||
public class Info
|
||||
{
|
||||
public byte HP, ATK, DEF, SPE, SPA, SPD;
|
||||
public int BST;
|
||||
private ushort EVs;
|
||||
public int EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD;
|
||||
public byte[] Types = new byte[2];
|
||||
public byte CatchRate, EvoStage;
|
||||
public ushort[] Items = new ushort[3];
|
||||
public byte Gender, HatchCycles, BaseFriendship, EXPGrowth;
|
||||
public byte[] EggGroups = new byte[2];
|
||||
public byte[] Abilities = new byte[3];
|
||||
public ushort FormeSprite, BaseEXP;
|
||||
public byte FormeCount, Color;
|
||||
public float Height, Weight;
|
||||
public bool[] TMHM;
|
||||
public bool[] Tutors;
|
||||
public bool[][] ORASTutors = new bool[4][];
|
||||
public byte _1B;
|
||||
public ushort _1C;
|
||||
public Info(byte[] data)
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
|
||||
{
|
||||
HP = br.ReadByte(); ATK = br.ReadByte(); DEF = br.ReadByte();
|
||||
SPE = br.ReadByte(); SPA = br.ReadByte(); SPD = br.ReadByte();
|
||||
BST = HP + ATK + DEF + SPE + SPA + SPD;
|
||||
|
||||
Types = new[] {br.ReadByte(), br.ReadByte()};
|
||||
CatchRate = br.ReadByte();
|
||||
EvoStage = br.ReadByte();
|
||||
|
||||
EVs = br.ReadUInt16();
|
||||
EV_HP = ((EVs >> 0) & 0x3);
|
||||
EV_ATK = ((EVs >> 2) & 0x3);
|
||||
EV_DEF = ((EVs >> 4) & 0x3);
|
||||
EV_SPE = ((EVs >> 6) & 0x3);
|
||||
EV_SPA = ((EVs >> 8) & 0x3);
|
||||
EV_SPD = ((EVs >> 10) & 0x3);
|
||||
|
||||
Items = new[] {br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16()};
|
||||
Gender = br.ReadByte();
|
||||
HatchCycles = br.ReadByte();
|
||||
BaseFriendship = br.ReadByte();
|
||||
|
||||
EXPGrowth = br.ReadByte();
|
||||
EggGroups = new[] {br.ReadByte(), br.ReadByte()};
|
||||
Abilities = new[] {br.ReadByte(), br.ReadByte(), br.ReadByte()};
|
||||
_1B = br.ReadByte();
|
||||
_1C = br.ReadUInt16();
|
||||
|
||||
FormeSprite = br.ReadUInt16();
|
||||
FormeCount = br.ReadByte();
|
||||
Color = br.ReadByte();
|
||||
BaseEXP = br.ReadUInt16();
|
||||
|
||||
Height = br.ReadUInt16();
|
||||
Weight = br.ReadUInt16();
|
||||
|
||||
byte[] TMHMData = br.ReadBytes(0x10);
|
||||
TMHM = new bool[8 * TMHMData.Length];
|
||||
for (int j = 0; j < TMHM.Length; j++)
|
||||
TMHM[j/8 + j%8] = ((TMHMData[j/8] >> j%8) & 0x1) == 1; //Bitflags for TMHM
|
||||
|
||||
byte[] TutorData = br.ReadBytes(8);
|
||||
Tutors = new bool[8 * TutorData.Length];
|
||||
for (int j = 0; j < Tutors.Length; j++)
|
||||
Tutors[j/8 + j%8] = ((TutorData[j/8] >> j%8) & 0x1) == 1; //Bitflags for Tutors
|
||||
|
||||
if (br.BaseStream.Length - br.BaseStream.Position == 0x10) // ORAS
|
||||
{
|
||||
byte[][] ORASTutorData =
|
||||
{
|
||||
br.ReadBytes(2), // 15
|
||||
br.ReadBytes(3), // 17
|
||||
br.ReadBytes(2), // 16
|
||||
br.ReadBytes(2), // 15
|
||||
};
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ORASTutors[i] = new bool[8*ORASTutorData[i].Length];
|
||||
for (int b = 0; b < 8*ORASTutorData[i].Length; b++)
|
||||
ORASTutors[i][b] = ((ORASTutorData[i][b/8] >> b%8) & 0x1) == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(HP);
|
||||
bw.Write(ATK);
|
||||
bw.Write(DEF);
|
||||
bw.Write(SPE);
|
||||
bw.Write(SPD);
|
||||
bw.Write(SPE);
|
||||
foreach (byte Type in Types) bw.Write(Type);
|
||||
bw.Write(CatchRate);
|
||||
bw.Write(EvoStage);
|
||||
EVs = (ushort)(EVs & 0x80 | (HP >> 0 & 3) | (ATK >> 2 & 3) | (DEF >> 4 & 3) | (SPE >> 6 & 3) | (SPA >> 8 & 3) | (SPD >> 10 & 3));
|
||||
bw.Write(EVs);
|
||||
foreach (ushort Item in Items) bw.Write(Item);
|
||||
bw.Write(Gender);
|
||||
bw.Write(HatchCycles);
|
||||
bw.Write(BaseFriendship);
|
||||
bw.Write(EXPGrowth);
|
||||
foreach (byte EggGroup in EggGroups) bw.Write(EggGroup);
|
||||
foreach (byte Ability in Abilities) bw.Write(Ability);
|
||||
bw.Write(_1B);
|
||||
bw.Write(_1C);
|
||||
bw.Write(FormeSprite);
|
||||
bw.Write(FormeCount);
|
||||
bw.Write(Color);
|
||||
bw.Write(BaseEXP);
|
||||
bw.Write(BitConverter.GetBytes(Convert.ToUInt16(Height)));
|
||||
bw.Write(BitConverter.GetBytes(Convert.ToUInt16(Weight)));
|
||||
|
||||
byte[] TMHMData = new byte[0x10];
|
||||
for (int i = 0; i < TMHM.Length; i++)
|
||||
TMHMData[i % 8] |= (byte)(TMHM[i] ? (1 << i % 8) : 0);
|
||||
bw.Write(TMHMData);
|
||||
|
||||
byte[] TutorData = new byte[8];
|
||||
for (int i = 0; i < Tutors.Length; i++)
|
||||
TutorData[i % 8] |= (byte)(Tutors[i] ? (1 << i % 8) : 0);
|
||||
bw.Write(TutorData);
|
||||
|
||||
while (bw.BaseStream.Length != 0x40) bw.Write((byte)0);
|
||||
|
||||
if (ORASTutors[0] != null) // ORAS Data
|
||||
{
|
||||
byte[][] ORASTutorData =
|
||||
{
|
||||
new byte[2], // 15
|
||||
new byte[3], // 17
|
||||
new byte[2], // 16
|
||||
new byte[2], // 15
|
||||
};
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int b = 0; b < ORASTutors[i].Length; b++)
|
||||
ORASTutorData[i][b / 8] = (byte)(ORASTutors[i][b] ? (1 << b % 8) : 0);
|
||||
|
||||
foreach (byte[] ORASTutor in ORASTutorData) bw.Write(ORASTutor);
|
||||
|
||||
while (bw.BaseStream.Length != 0x50) bw.Write((byte)0);
|
||||
}
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -695,13 +695,13 @@ private void Randomize()
|
||||
// Randomize Pokemon
|
||||
for (int p = 0; p < CB_numPokemon.SelectedIndex; p++)
|
||||
{
|
||||
Personal.Info oldpkm = new Personal.Info(personal[trpk_pkm[p].SelectedIndex]);
|
||||
Personal.Info pkm = null;
|
||||
PersonalInfo oldpkm = new PersonalInfo(personal[trpk_pkm[p].SelectedIndex]);
|
||||
PersonalInfo pkm = null;
|
||||
if (rPKM)
|
||||
{
|
||||
// randomize pokemon
|
||||
int species = Randomizer.getRandomSpecies(ref sL, ref ctr);
|
||||
pkm = new Personal.Info(personal[species]);
|
||||
pkm = new PersonalInfo(personal[species]);
|
||||
if (rTypeTheme)
|
||||
{
|
||||
while (pkm.Types[0] != type && pkm.Types[1] != type || (mevo && p == CB_numPokemon.SelectedIndex - 1 && !megaEvos.Contains(species)))
|
||||
@@ -713,7 +713,7 @@ private void Randomize()
|
||||
else if (rSmart) // Get a new Pokemon with a close BST
|
||||
{
|
||||
while (!(pkm.BST * 5 / 6 < oldpkm.BST && pkm.BST * 6 / 5 > oldpkm.BST))
|
||||
{ species = sL[rand.Next(1, sL.Length)]; pkm = new Personal.Info(personal[species]); }
|
||||
{ species = sL[rand.Next(1, sL.Length)]; pkm = new PersonalInfo(personal[species]); }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -728,7 +728,7 @@ private void Randomize()
|
||||
else if (rSmart) // Get a new Pokemon with a close BST
|
||||
{
|
||||
while (!(pkm.BST * 5 / 6 < oldpkm.BST && pkm.BST * 6 / 5 > oldpkm.BST))
|
||||
{ species = sL[rand.Next(1, sL.Length)]; pkm = new Personal.Info(personal[species]); }
|
||||
{ species = sL[rand.Next(1, sL.Length)]; pkm = new PersonalInfo(personal[species]); }
|
||||
}
|
||||
|
||||
trpk_pkm[p].SelectedIndex = species;
|
||||
@@ -759,7 +759,7 @@ private void Randomize()
|
||||
|
||||
if (rMove)
|
||||
{
|
||||
pkm = pkm ?? new Personal.Info(personal[trpk_pkm[p].SelectedIndex]);
|
||||
pkm = pkm ?? new PersonalInfo(personal[trpk_pkm[p].SelectedIndex]);
|
||||
int[] pkMoves = new int[4];
|
||||
var moves = new[] {trpk_m1[p], trpk_m2[p], trpk_m3[p], trpk_m4[p]};
|
||||
|
||||
@@ -1055,140 +1055,5 @@ private void formClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
writeFile();
|
||||
}
|
||||
|
||||
public class Trainer
|
||||
{
|
||||
public bool isORAS;
|
||||
public int Format, Class;
|
||||
public bool Item, Moves;
|
||||
public byte BattleType, NumPokemon, AI;
|
||||
public ushort[] Items = new ushort[4];
|
||||
public byte u1, u2, u3;
|
||||
public ushort uORAS;
|
||||
public bool Healer;
|
||||
public byte Money;
|
||||
public ushort Prize;
|
||||
public Pokemon[] Team;
|
||||
public Trainer(byte[] trData, byte[] trPoke, bool ORAS)
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(new MemoryStream(trData)))
|
||||
{
|
||||
isORAS = ORAS;
|
||||
Format = ORAS ? br.ReadUInt16() : br.ReadByte();
|
||||
Class = ORAS ? br.ReadUInt16() : br.ReadByte();
|
||||
if (ORAS) uORAS = br.ReadUInt16();
|
||||
Item = ((Format >> 1) & 1) == 1;
|
||||
Moves = (Format & 1) == 1;
|
||||
BattleType = br.ReadByte();
|
||||
NumPokemon = br.ReadByte();
|
||||
for (int i = 0; i < 4; i++)
|
||||
Items[i] = br.ReadUInt16();
|
||||
AI = br.ReadByte();
|
||||
u1 = br.ReadByte();
|
||||
u2 = br.ReadByte();
|
||||
u3 = br.ReadByte();
|
||||
Healer = br.ReadByte() != 0;
|
||||
Money = br.ReadByte();
|
||||
Prize = br.ReadUInt16();
|
||||
|
||||
// Fetch Team
|
||||
Team = new Pokemon[NumPokemon];
|
||||
byte[][] TeamData = new byte[NumPokemon][];
|
||||
int dataLen = trPoke.Length/NumPokemon;
|
||||
for (int i = 0; i < TeamData.Length; i++)
|
||||
TeamData[i] = trPoke.Skip(i*dataLen).Take(dataLen).ToArray();
|
||||
for (int i = 0; i < NumPokemon; i++)
|
||||
Team[i] = new Pokemon(TeamData[i], Item, Moves);
|
||||
}
|
||||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter bw = new BinaryWriter(ms))
|
||||
{
|
||||
Format = Convert.ToByte(Moves) + (Convert.ToByte(Item) << 1);
|
||||
if (isORAS)
|
||||
{ bw.Write((ushort)Format); bw.Write((ushort)Class); bw.Write((ushort)0); }
|
||||
else
|
||||
{ bw.Write((byte)Format); bw.Write((byte)Class); }
|
||||
|
||||
bw.Write(BattleType);
|
||||
bw.Write(NumPokemon);
|
||||
bw.Write(Items[0]);
|
||||
bw.Write(Items[1]);
|
||||
bw.Write(Items[2]);
|
||||
bw.Write(Items[3]);
|
||||
|
||||
bw.Write(AI);
|
||||
bw.Write(u1);
|
||||
bw.Write(u2);
|
||||
bw.Write(u3);
|
||||
bw.Write(Convert.ToByte(Healer));
|
||||
bw.Write(Money);
|
||||
bw.Write(Prize);
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
public byte[] WriteTeam()
|
||||
{
|
||||
return Team.Aggregate(new byte[0], (i, pkm) => i.Concat(pkm.Write(Item, Moves)).ToArray());
|
||||
}
|
||||
}
|
||||
public class Pokemon
|
||||
{
|
||||
public byte IVs;
|
||||
public byte PID;
|
||||
public ushort Level;
|
||||
public ushort Species;
|
||||
public ushort Form;
|
||||
public int Ability;
|
||||
public int Gender;
|
||||
public int uBit;
|
||||
public ushort Item;
|
||||
public ushort[] Moves = new ushort[4];
|
||||
|
||||
public Pokemon(byte[] data, bool HasItem, bool HasMoves)
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
|
||||
{
|
||||
IVs = br.ReadByte();
|
||||
PID = br.ReadByte();
|
||||
Level = br.ReadUInt16();
|
||||
Species = br.ReadUInt16();
|
||||
Form = br.ReadUInt16();
|
||||
|
||||
Ability = PID >> 4;
|
||||
Gender = PID & 3;
|
||||
uBit = (PID >> 3) & 1;
|
||||
|
||||
if (HasItem)
|
||||
Item = br.ReadUInt16();
|
||||
if (HasMoves)
|
||||
for (int i = 0; i < 4; i++)
|
||||
Moves[i] = br.ReadUInt16();
|
||||
}
|
||||
}
|
||||
public byte[] Write(bool HasItem, bool HasMoves)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (BinaryWriter bw = new BinaryWriter(ms))
|
||||
{
|
||||
bw.Write(IVs);
|
||||
PID = (byte)(((Ability & 0xF) << 4) | ((uBit & 1) << 3) | (Gender & 0x7));
|
||||
bw.Write(PID);
|
||||
bw.Write(Level);
|
||||
bw.Write(Species);
|
||||
bw.Write(Form);
|
||||
|
||||
if (HasItem)
|
||||
bw.Write(Item);
|
||||
if (HasMoves)
|
||||
foreach (ushort Move in Moves)
|
||||
bw.Write(Move);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,9 @@
|
||||
<Compile Include="3DS\BCLIM.cs" />
|
||||
<Compile Include="Randomizer.cs" />
|
||||
<Compile Include="3DS\RomFS.cs" />
|
||||
<Compile Include="Structs.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Subforms\Patch.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user