mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-08-27 05:14:43 -05:00
Coded Import Party button
This commit is contained in:
@@ -7210,10 +7210,13 @@ namespace DSPRE {
|
||||
private void partyMoveComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
if (!disableHandlers) {
|
||||
for (int i = 0; i < TrainerFile.POKE_IN_PARTY; i++) {
|
||||
currentTrainerFile.party[i].moves[0] = (ushort)partyFirstMoveComponentList[i].SelectedIndex;
|
||||
currentTrainerFile.party[i].moves[1] = (ushort)partySecondMoveComponentList[i].SelectedIndex;
|
||||
currentTrainerFile.party[i].moves[2] = (ushort)partyThirdMoveComponentList[i].SelectedIndex;
|
||||
currentTrainerFile.party[i].moves[3] = (ushort)partyFourthMoveComponentList[i].SelectedIndex;
|
||||
ushort[] moves = currentTrainerFile.party[i].moves;
|
||||
if (moves != null) {
|
||||
moves[0] = (ushort)partyFirstMoveComponentList[i].SelectedIndex;
|
||||
moves[1] = (ushort)partySecondMoveComponentList[i].SelectedIndex;
|
||||
moves[2] = (ushort)partyThirdMoveComponentList[i].SelectedIndex;
|
||||
moves[3] = (ushort)partyFourthMoveComponentList[i].SelectedIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7404,7 +7407,7 @@ namespace DSPRE {
|
||||
RefreshTrainerPropertiesGUI();
|
||||
|
||||
/* Display success message */
|
||||
MessageBox.Show("Events imported successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
MessageBox.Show("Trainer Properties imported successfully!\nRemember to save the current Trainer File.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void exportPartyButton_Click(object sender, EventArgs e) {
|
||||
@@ -7413,7 +7416,21 @@ namespace DSPRE {
|
||||
}
|
||||
|
||||
private void importReplacePartyButton_Click(object sender, EventArgs e) {
|
||||
/* Prompt user to select .evt file */
|
||||
OpenFileDialog of = new OpenFileDialog {
|
||||
Filter = "Gen IV Party File (*.pdat)|*.pdat"
|
||||
};
|
||||
if (of.ShowDialog(this) != DialogResult.OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Update trp object in memory */
|
||||
currentTrainerFile.party = new Party(readFirstByte: true, TrainerFile.POKE_IN_PARTY, new FileStream(of.FileName, FileMode.Open), currentTrainerFile.trp);
|
||||
RefreshTrainerPropertiesGUI();
|
||||
RefreshTrainerPartyGUI();
|
||||
|
||||
/* Display success message */
|
||||
MessageBox.Show("Trainer Party imported successfully!\nRemember to save the current Trainer File.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void saveTrainerClassButton_Click(object sender, EventArgs e) {
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace DSPRE.ROMFiles {
|
||||
using (BinaryWriter writer = new BinaryWriter(newData)) {
|
||||
writer.Write(unknown1_DATASTART);
|
||||
writer.Write(level);
|
||||
writer.Write((ushort)pokeID);
|
||||
writer.Write(pokeID ?? 0);
|
||||
|
||||
if (heldItem != null) {
|
||||
writer.Write((ushort)heldItem);
|
||||
@@ -150,6 +150,57 @@ namespace DSPRE.ROMFiles {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Party(bool readFirstByte, int maxPoke, Stream partyData, TrainerProperties traipr) {
|
||||
using (BinaryReader reader = new BinaryReader(partyData)) {
|
||||
this.trp = traipr;
|
||||
if (readFirstByte) {
|
||||
byte flags = reader.ReadByte();
|
||||
|
||||
trp.hasMoves = (flags & 1) != 0;
|
||||
trp.hasItems = (flags & 2) != 0;
|
||||
trp.partyCount = (byte)((flags & 28) >> 2);
|
||||
}
|
||||
|
||||
int dividend = 8;
|
||||
int nMoves = 4;
|
||||
|
||||
if (trp.hasMoves) {
|
||||
dividend += nMoves * sizeof(ushort);
|
||||
}
|
||||
if (trp.hasItems) {
|
||||
dividend += sizeof(ushort);
|
||||
}
|
||||
|
||||
int endval = Math.Min((int)(partyData.Length-1 / dividend), trp.partyCount);
|
||||
this.content = new PartyPokemon[maxPoke];
|
||||
for (int i = 0; i < endval; i++) {
|
||||
ushort unknown1 = reader.ReadUInt16();
|
||||
ushort level = reader.ReadUInt16();
|
||||
ushort pokemon = reader.ReadUInt16();
|
||||
|
||||
ushort? heldItem = null;
|
||||
ushort[] moves = null;
|
||||
|
||||
if (trp.hasItems) {
|
||||
heldItem = reader.ReadUInt16();
|
||||
}
|
||||
if (trp.hasMoves) {
|
||||
moves = new ushort[4];
|
||||
for (int m = 0; m < moves.Length; m++) {
|
||||
ushort val = reader.ReadUInt16();
|
||||
moves[m] = (ushort)(val == 0xFFFF ? 0 : val);
|
||||
}
|
||||
}
|
||||
|
||||
content[i] = new PartyPokemon(unknown1, level, pokemon, reader.ReadUInt16(), heldItem, moves);
|
||||
}
|
||||
for (int i = endval; i < maxPoke; i++) {
|
||||
content[i] = new PartyPokemon();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public PartyPokemon this[int index] {
|
||||
get {
|
||||
return content[index];
|
||||
@@ -197,44 +248,7 @@ namespace DSPRE.ROMFiles {
|
||||
public TrainerFile(TrainerProperties trp, Stream partyData, string name = "") {
|
||||
this.name = name;
|
||||
this.trp = trp;
|
||||
party = new Party(POKE_IN_PARTY, init: false, trp);
|
||||
using (BinaryReader reader = new BinaryReader(partyData)) {
|
||||
int dividend = 8;
|
||||
int nMoves = 4;
|
||||
|
||||
if (trp.hasMoves) {
|
||||
dividend += nMoves * sizeof(ushort);
|
||||
}
|
||||
if (trp.hasItems) {
|
||||
dividend += sizeof(ushort);
|
||||
}
|
||||
|
||||
int endval = Math.Min((int)(partyData.Length / dividend), trp.partyCount);
|
||||
for (int i = 0; i < endval; i++) {
|
||||
ushort unknown1 = reader.ReadUInt16();
|
||||
ushort level = reader.ReadUInt16();
|
||||
ushort pokemon = reader.ReadUInt16();
|
||||
|
||||
ushort? heldItem = null;
|
||||
ushort[] moves = null;
|
||||
|
||||
if (trp.hasItems) {
|
||||
heldItem = reader.ReadUInt16();
|
||||
}
|
||||
if (trp.hasMoves) {
|
||||
moves = new ushort[4];
|
||||
for (int m = 0; m < moves.Length; m++) {
|
||||
ushort val = reader.ReadUInt16();
|
||||
moves[m] = (ushort)(val == 0xFFFF ? 0 : val);
|
||||
}
|
||||
}
|
||||
|
||||
party[i] = new PartyPokemon(unknown1, level, pokemon, reader.ReadUInt16(), heldItem, moves);
|
||||
}
|
||||
for (int i = endval; i < POKE_IN_PARTY; i++) {
|
||||
party[i] = new PartyPokemon();
|
||||
}
|
||||
}
|
||||
party = new Party(readFirstByte: false, POKE_IN_PARTY, partyData, this.trp);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user