mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 22:40:22 +00:00
Convert battle video interaction to class obj
Makes it easier for gen7 battle videos; none of this info is new (comes from pkBV).
This commit is contained in:
parent
bc9893415b
commit
283ee64e4f
3 changed files with 158 additions and 14 deletions
|
@ -23,7 +23,7 @@ namespace PKHeX
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
// Check for Updates
|
// Check for Updates
|
||||||
L_UpdateAvailable.Click += (sender, e) => { Process.Start(ThreadPath); };
|
L_UpdateAvailable.Click += (sender, e) => Process.Start(ThreadPath);
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
string data = Util.getStringFromURL(VersionPath);
|
string data = Util.getStringFromURL(VersionPath);
|
||||||
|
@ -476,7 +476,7 @@ namespace PKHeX
|
||||||
CHK_Nicknamed.Checked = Set.Nickname != null;
|
CHK_Nicknamed.Checked = Set.Nickname != null;
|
||||||
if (Set.Nickname != null)
|
if (Set.Nickname != null)
|
||||||
TB_Nickname.Text = Set.Nickname;
|
TB_Nickname.Text = Set.Nickname;
|
||||||
if (Set.Gender != null && PKX.getGender(Set.Gender) != 2 && PKX.getGender(Set.Gender) != 2)
|
if (Set.Gender != null)
|
||||||
{
|
{
|
||||||
int Gender = PKX.getGender(Set.Gender);
|
int Gender = PKX.getGender(Set.Gender);
|
||||||
Label_Gender.Text = gendersymbols[Gender];
|
Label_Gender.Text = gendersymbols[Gender];
|
||||||
|
@ -699,21 +699,20 @@ namespace PKHeX
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region Battle Video
|
#region Battle Video
|
||||||
else if (input.Length == 0x2E60 && BitConverter.ToUInt64(input, 0xE18) != 0 && BitConverter.ToUInt16(input, 0xE12) == 0)
|
else if (input.Length == BV6.SIZE && BV6.getIsValid(input))
|
||||||
{
|
{
|
||||||
if (SAV.Generation != 6)
|
if (SAV.Generation != 6)
|
||||||
{ Util.Alert("Cannot load a Gen6 Battle Video to a past generation save file."); return; }
|
{ Util.Alert("Cannot load a Gen6 Battle Video to a past generation save file."); return; }
|
||||||
|
|
||||||
if (Util.Prompt(MessageBoxButtons.YesNo, "Load Battle Video Pokémon data to " + CB_BoxSelect.Text + "?", "The box will be overwritten.") != DialogResult.Yes)
|
if (Util.Prompt(MessageBoxButtons.YesNo, $"Load Battle Video Pokémon data to {CB_BoxSelect.Text}?", "The box will be overwritten.") != DialogResult.Yes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool? noSetb = getPKMSetOverride();
|
bool? noSetb = getPKMSetOverride();
|
||||||
|
PKM[] data = new BV6(input).BattlePKMs;
|
||||||
int offset = SAV.getBoxOffset(CB_BoxSelect.SelectedIndex);
|
int offset = SAV.getBoxOffset(CB_BoxSelect.SelectedIndex);
|
||||||
for (int i = 0; i < 24; i++)
|
for (int i = 0; i < 24; i++)
|
||||||
{
|
SAV.setStoredSlot(data[i], offset + i*SAV.SIZE_STORED, noSetb);
|
||||||
byte[] data = input.Skip(0xE18 + PKX.SIZE_6PARTY * i + i / 6 * 8).Take(PKX.SIZE_6STORED).ToArray();
|
|
||||||
SAV.setStoredSlot(data, offset + i * SAV.SIZE_STORED, noSetb);
|
|
||||||
}
|
|
||||||
setPKXBoxes();
|
setPKXBoxes();
|
||||||
updateBoxViewers();
|
updateBoxViewers();
|
||||||
}
|
}
|
||||||
|
@ -3328,14 +3327,11 @@ namespace PKHeX
|
||||||
if (getSlot(sender) > 30) return; // only perform action if cloning to boxes
|
if (getSlot(sender) > 30) return; // only perform action if cloning to boxes
|
||||||
if (!verifiedPKM()) return; // don't copy garbage to the box
|
if (!verifiedPKM()) return; // don't copy garbage to the box
|
||||||
|
|
||||||
PKM pk;
|
if (Util.Prompt(MessageBoxButtons.YesNo, $"Clone Pokemon from Editing Tabs to all slots in {CB_BoxSelect.Text}?") != DialogResult.Yes)
|
||||||
if (Util.Prompt(MessageBoxButtons.YesNo, $"Clone Pokemon from Editing Tabs to all slots in {CB_BoxSelect.Text}?") == DialogResult.Yes)
|
|
||||||
pk = preparePKM();
|
|
||||||
else if (Util.Prompt(MessageBoxButtons.YesNo, $"Delete all Pokemon in {CB_BoxSelect.Text}?") == DialogResult.Yes)
|
|
||||||
pk = SAV.BlankPKM;
|
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
PKM pk = preparePKM();
|
||||||
|
|
||||||
for (int i = 0; i < 30; i++) // set to every slot in box
|
for (int i = 0; i < 30; i++) // set to every slot in box
|
||||||
{
|
{
|
||||||
SAV.setStoredSlot(pk, getPKXOffset(i));
|
SAV.setStoredSlot(pk, getPKXOffset(i));
|
||||||
|
|
|
@ -171,6 +171,7 @@
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Saves\Substructures\BlockInfo.cs" />
|
<Compile Include="Saves\Substructures\BlockInfo.cs" />
|
||||||
<Compile Include="Saves\Substructures\BoxWallpaper.cs" />
|
<Compile Include="Saves\Substructures\BoxWallpaper.cs" />
|
||||||
|
<Compile Include="Saves\Substructures\BV6.cs" />
|
||||||
<Compile Include="Saves\Substructures\Inventory.cs" />
|
<Compile Include="Saves\Substructures\Inventory.cs" />
|
||||||
<Compile Include="Saves\SAV2.cs" />
|
<Compile Include="Saves\SAV2.cs" />
|
||||||
<Compile Include="Saves\SAV1.cs" />
|
<Compile Include="Saves\SAV1.cs" />
|
||||||
|
|
147
PKHeX/Saves/Substructures/BV6.cs
Normal file
147
PKHeX/Saves/Substructures/BV6.cs
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PKHeX
|
||||||
|
{
|
||||||
|
public class BV6
|
||||||
|
{
|
||||||
|
internal const int SIZE = 0x2E60;
|
||||||
|
internal static bool getIsValid(byte[] data)
|
||||||
|
{
|
||||||
|
return BitConverter.ToUInt64(data, 0xE18) != 0 && BitConverter.ToUInt16(data, 0xE12) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BV6(byte[] data)
|
||||||
|
{
|
||||||
|
Data = (byte[])data.Clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly byte[] Data;
|
||||||
|
|
||||||
|
private int Mode { get { return Data[0x00]; } set { Data[0x00] = (byte)value; } }
|
||||||
|
private string[] BVmode =
|
||||||
|
{
|
||||||
|
"Link", "Maison", "Super Maison", "Battle Spot - Free", "Battle Spot - Rating",
|
||||||
|
"Battle Spot - Special", "UNUSED", "JP-1", "JP-2", "BROKEN",
|
||||||
|
};
|
||||||
|
private int Style { get { return Data[0x01]; } set { Data[0x01] = (byte)value; } }
|
||||||
|
private string[] BVstyle = { "Single", "Double", "Triple", "Rotation", "Multi", };
|
||||||
|
private string Debug1
|
||||||
|
{
|
||||||
|
get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x6, 24)); }
|
||||||
|
set { Encoding.Unicode.GetBytes(value.PadRight(12, '\0')).CopyTo(Data, 0x6); }
|
||||||
|
}
|
||||||
|
private string Debug2
|
||||||
|
{
|
||||||
|
get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x50, 24)); }
|
||||||
|
set { Encoding.Unicode.GetBytes(value.PadRight(12, '\0')).CopyTo(Data, 0x50); }
|
||||||
|
}
|
||||||
|
private ulong RNGConst1 { get { return BitConverter.ToUInt64(Data, 0x1A0); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1A0); } }
|
||||||
|
private ulong RNGConst2 { get { return BitConverter.ToUInt64(Data, 0x1A4); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1A4); } }
|
||||||
|
private ulong RNGSeed1 { get { return BitConverter.ToUInt64(Data, 0x1A8); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1A8); } }
|
||||||
|
private ulong RNGSeed2 { get { return BitConverter.ToUInt64(Data, 0x1B0); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1B0); } }
|
||||||
|
|
||||||
|
private int Background { get { return BitConverter.ToInt32(Data, 0x1BC); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x1BC); } }
|
||||||
|
private int _1CE { get { return BitConverter.ToUInt16(Data, 0x1CE); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1CE); } }
|
||||||
|
private int IntroID { get { return BitConverter.ToUInt16(Data, 0x1E4); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1E4); } }
|
||||||
|
private int MusicID { get { return BitConverter.ToUInt16(Data, 0x1F0); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1F0); } }
|
||||||
|
|
||||||
|
|
||||||
|
public PKM[] BattlePKMs => PlayerTeams.SelectMany(t => t).ToArray();
|
||||||
|
|
||||||
|
private const string NPC = "NPC";
|
||||||
|
private string[] PlayerNames
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string[] trainers = new string[4];
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
trainers[i] = Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0xEC + 0x1A*i, 0x1A));
|
||||||
|
if (string.IsNullOrWhiteSpace(trainers[i]))
|
||||||
|
trainers[i] = NPC;
|
||||||
|
}
|
||||||
|
return trainers;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value?.Length != 4)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
string tr = value[i] == NPC ? "" : value[i];
|
||||||
|
Encoding.Unicode.GetBytes(tr.PadRight(0x1A/2)).CopyTo(Data, 0xEC + 0x1A*i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private PKM[][] PlayerTeams
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var Teams = new PKM[4][];
|
||||||
|
const int start = 0xE18;
|
||||||
|
for (int t = 0; t < 4; t++)
|
||||||
|
{
|
||||||
|
Teams[t] = new PKM[6];
|
||||||
|
for (int p = 0; p < 6; p++)
|
||||||
|
{
|
||||||
|
int offset = start + PKX.SIZE_6PARTY*(t*6 + p);
|
||||||
|
offset += 8*((t*6 + p)/6); // 8 bytes padding between teams
|
||||||
|
Teams[t][p] = new PK6(Data.Skip(offset).Take(PKX.SIZE_6PARTY).ToArray(), $"Team {t}, Slot {p}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Teams;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
var Teams = value;
|
||||||
|
const int start = 0xE18;
|
||||||
|
for (int t = 0; t < 4; t++)
|
||||||
|
{
|
||||||
|
for (int p = 0; p < 6; p++)
|
||||||
|
{
|
||||||
|
int offset = start + PKX.SIZE_6PARTY*(t*6 + p);
|
||||||
|
offset += 8*((t*6 + p)/6); // 8 bytes padding between teams
|
||||||
|
Teams[t][p].EncryptedPartyData.CopyTo(Data, offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int MatchYear { get { return BitConverter.ToUInt16(Data, 0x2E50); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E50); } }
|
||||||
|
private int MatchDay { get { return Data[0x2E52]; } set { Data[0x2E52] = (byte)value; } }
|
||||||
|
private int MatchMonth { get { return Data[0x2E53]; } set { Data[0x2E53] = (byte)value; } }
|
||||||
|
private int MatchHour { get { return Data[0x2E54]; } set { Data[0x2E54] = (byte)value; } }
|
||||||
|
private int MatchMinute { get { return Data[0x2E55]; } set { Data[0x2E55] = (byte)value; } }
|
||||||
|
private int MatchSecond { get { return Data[0x2E56]; } set { Data[0x2E56] = (byte)value; } }
|
||||||
|
private int MatchFlags { get { return Data[0x2E57]; } set { Data[0x2E57] = (byte)value; } }
|
||||||
|
public DateTime MatchStamp
|
||||||
|
{
|
||||||
|
get { return new DateTime(MatchYear, MatchDay, MatchMonth, MatchHour, MatchMinute, MatchSecond); }
|
||||||
|
set { MatchYear = value.Year; MatchDay = value.Day; MatchMonth = value.Month; MatchHour = value.Hour; MatchMinute = value.Minute; MatchSecond = value.Second; }
|
||||||
|
}
|
||||||
|
private int UploadYear { get { return BitConverter.ToUInt16(Data, 0x2E58); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E58); } }
|
||||||
|
private int UploadDay { get { return Data[0x2E5A]; } set { Data[0x2E5A] = (byte)value; } }
|
||||||
|
private int UploadMonth { get { return Data[0x2E5B]; } set { Data[0x2E5B] = (byte)value; } }
|
||||||
|
private int UploadHour { get { return Data[0x2E5C]; } set { Data[0x2E5C] = (byte)value; } }
|
||||||
|
private int UploadMinute { get { return Data[0x2E5D]; } set { Data[0x2E5D] = (byte)value; } }
|
||||||
|
private int UploadSecond { get { return Data[0x2E5E]; } set { Data[0x2E5E] = (byte)value; } }
|
||||||
|
private int UploadFlags { get { return Data[0x2E5F]; } set { Data[0x2E5F] = (byte)value; } }
|
||||||
|
public DateTime UploadStamp
|
||||||
|
{
|
||||||
|
get { return new DateTime(UploadYear, UploadDay, UploadMonth, UploadHour, UploadMinute, UploadSecond); }
|
||||||
|
set { UploadYear = value.Year; UploadDay = value.Day; UploadMonth = value.Month; UploadHour = value.Hour; UploadMinute = value.Minute; UploadSecond = value.Second; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Battle Instruction Parsing
|
||||||
|
private string[] Action = { "0", "Fight", "2", "Switch", "Run", "5", "Rotate", "7", "MegaEvolve" };
|
||||||
|
private string[] Target =
|
||||||
|
{
|
||||||
|
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "Opposite Enemy", "B", "C", "D",
|
||||||
|
"All except User", "Everyone"
|
||||||
|
};
|
||||||
|
private string[] Rotate = { "0", "Right", "Left", "3" };
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue