Add battle video 7 importing

Thanks JohnTravolski!
This commit is contained in:
Kurt 2016-11-10 08:14:54 -08:00
parent cf74c7c209
commit c1b05e9331
6 changed files with 94 additions and 8 deletions

View file

@ -898,7 +898,7 @@ namespace PKHeX
} }
else // Is Traded else // Is Traded
{ {
if (pkm.HT_Memory == 0) if (pkm.HT_Memory == 0 && pkm.Format == 6)
return new CheckResult(Severity.Invalid, "Memory -- missing Handling Trainer Memory.", CheckIdentifier.History); return new CheckResult(Severity.Invalid, "Memory -- missing Handling Trainer Memory.", CheckIdentifier.History);
} }

View file

@ -691,16 +691,17 @@ namespace PKHeX
} }
#endregion #endregion
#region Battle Video #region Battle Video
else if (input.Length == BV6.SIZE && BV6.getIsValid(input)) else if (BattleVideo.getIsValid(input))
{ {
if (SAV.Generation != 6) BattleVideo b = BattleVideo.getVariantBattleVideo(input);
{ Util.Alert("Cannot load a Gen6 Battle Video to a past generation save file."); return; } if (SAV.Generation != b.Generation)
{ Util.Alert($"Cannot load a Gen{b.Generation} Battle Video to a different 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; PKM[] data = b.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); SAV.setStoredSlot(data[i], offset + i*SAV.SIZE_STORED, noSetb);

View file

@ -193,9 +193,11 @@
<DependentUpon>QR.cs</DependentUpon> <DependentUpon>QR.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Saves\SAV7.cs" /> <Compile Include="Saves\SAV7.cs" />
<Compile Include="Saves\Substructures\BattleVideo.cs" />
<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\BV6.cs" />
<Compile Include="Saves\Substructures\BV7.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" />

View file

@ -4,11 +4,13 @@ using System.Text;
namespace PKHeX namespace PKHeX
{ {
public class BV6 public class BV6 : BattleVideo
{ {
internal const int SIZE = 0x2E60; internal const int SIZE = 0x2E60;
internal static bool getIsValid(byte[] data) internal new static bool getIsValid(byte[] data)
{ {
if (data.Length != SIZE)
return false;
return BitConverter.ToUInt64(data, 0xE18) != 0 && BitConverter.ToUInt16(data, 0xE12) == 0; return BitConverter.ToUInt64(data, 0xE18) != 0 && BitConverter.ToUInt16(data, 0xE12) == 0;
} }
@ -48,7 +50,8 @@ namespace PKHeX
private int MusicID { get { return BitConverter.ToUInt16(Data, 0x1F0); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1F0); } } 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(); public override PKM[] BattlePKMs => PlayerTeams.SelectMany(t => t).ToArray();
public override int Generation => 6;
private const string NPC = "NPC"; private const string NPC = "NPC";
private string[] PlayerNames private string[] PlayerNames

View file

@ -0,0 +1,54 @@
using System.Linq;
namespace PKHeX
{
public class BV7 : BattleVideo
{
internal const int SIZE = 0x2BC0;
internal new static bool getIsValid(byte[] data)
{
return data.Length == SIZE;
}
public BV7(byte[] data)
{
Data = (byte[])data.Clone();
}
private readonly byte[] Data;
public override PKM[] BattlePKMs => PlayerTeams.SelectMany(t => t).ToArray();
public override int Generation => 7;
private PKM[][] PlayerTeams
{
get
{
var Teams = new PKM[4][];
int[] offsets = {0xE41, 0x145E, 0x1A7B, 0x2098};
for (int t = 0; t < 4; t++)
{
Teams[t] = new PKM[6];
for (int p = 0; p < 6; p++)
{
int offset = offsets[t] + PKX.SIZE_6PARTY * p;
Teams[t][p] = new PK7(Data.Skip(offset).Take(PKX.SIZE_6STORED).ToArray(), $"Team {t}, Slot {p}");
}
}
return Teams;
}
set
{
var Teams = value;
int[] offsets = { 0xE41, 0x145E, 0x1A7B, 0x2098 };
for (int t = 0; t < 4; t++)
{
for (int p = 0; p < 6; p++)
{
int offset = offsets[t] + PKX.SIZE_6PARTY * p;
Teams[t][p].EncryptedPartyData.CopyTo(Data, offset);
}
}
}
}
}
}

View file

@ -0,0 +1,26 @@
namespace PKHeX
{
public abstract class BattleVideo
{
public abstract PKM[] BattlePKMs { get; }
public abstract int Generation { get; }
public static BattleVideo getVariantBattleVideo(byte[] data)
{
if (BV6.getIsValid(data))
return new BV6(data);
if (BV7.getIsValid(data))
return new BV7(data);
return null;
}
public static bool getIsValid(byte[] data)
{
if (BV6.getIsValid(data))
return true;
if (BV7.getIsValid(data))
return true;
return false;
}
}
}