Merge pull request #3 from kwsch/master

Update from upstream repo kwsch/PKHeX
This commit is contained in:
ReignOfComputer 2017-01-31 07:00:29 +08:00 committed by GitHub
commit 2c8dec7f83
16 changed files with 151 additions and 80 deletions

View File

@ -2281,6 +2281,9 @@ private void updateForm(object sender, EventArgs e)
changingFields = true;
MT_Form.Text = CB_Form.SelectedIndex.ToString();
changingFields = false;
if (fieldsLoaded)
getQuickFiller(dragout);
}
private void updateHaXForm(object sender, EventArgs e)
{
@ -2290,6 +2293,9 @@ private void updateHaXForm(object sender, EventArgs e)
int form = pkm.AltForm = Util.ToInt32(MT_Form.Text);
CB_Form.SelectedIndex = CB_Form.Items.Count > form ? form : -1;
changingFields = false;
if (fieldsLoaded)
getQuickFiller(dragout);
}
private void updatePP(object sender, EventArgs e)
{
@ -3500,7 +3506,7 @@ private void clickClone(object sender, EventArgs e)
PKM pk = preparePKM();
int slotSkipped = 0;
for (int i = 0; i < 30; i++) // set to every slot in box
for (int i = 0; i < SAV.BoxSlotCount; i++) // set to every slot in box
{
if (SAV.getIsSlotLocked(CB_BoxSelect.SelectedIndex, i))
{ slotSkipped++; continue; }

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
@ -30,7 +31,8 @@ public SAV_PokedexSM()
// Add Formes
int ctr = SAV.MaxSpeciesID;
for (int i = 0; i < SAV.MaxSpeciesID + 1; i++)
baseSpecies = new List<int>();
for (int i = 1; i < SAV.MaxSpeciesID + 1; i++)
{
int c = SAV.Personal[i].FormeCount;
for (int j = 0; j < c; j++)
@ -38,6 +40,7 @@ public SAV_PokedexSM()
int x = SaveUtil.getDexFormIndexSM(i, c, j);
if (x == -1 || j == 0)
continue;
baseSpecies.Add(i);
ctr++;
LB_Species.Items.Add($"{ctr:000} - {GameInfo.Strings.specieslist[i]}-{j}");
}
@ -54,6 +57,16 @@ public SAV_PokedexSM()
private int species = -1;
private readonly CheckBox[] CP, CL;
private readonly List<int> baseSpecies;
private int getBaseSpeciesGender(int index)
{
if (index <= SAV.MaxSpeciesID)
return SAV.Personal[index + 1].Gender;
index -= SAV.MaxSpeciesID;
return SAV.Personal[baseSpecies[index]].Gender;
}
private void changeCBSpecies(object sender, EventArgs e)
{
if (editing) return;
@ -120,6 +133,11 @@ private void getEntry()
CHK_P1.Enabled = species <= SAV.MaxSpeciesID;
CHK_P1.Checked = CHK_P1.Enabled && Dex.Owned[pk];
int gt = getBaseSpeciesGender(LB_Species.SelectedIndex);
CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = gt != 254; // Not Female-Only
CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = gt != 0 && gt != 255; // Not Male-Only and Not Genderless
for (int i = 0; i < 4; i++)
CP[i + 1].Checked = Dex.Seen[i][pk];
@ -260,8 +278,7 @@ private void B_GiveAll_Click(object sender, EventArgs e)
{
CHK_P1.Checked = ModifierKeys != Keys.Control;
}
int index = LB_Species.SelectedIndex+1;
int gt = SAV.Personal[index].Gender;
int gt = getBaseSpeciesGender(LB_Species.SelectedIndex);
CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;
@ -282,18 +299,21 @@ private void modifyAll(object sender, EventArgs e)
int lang = SAV.Language;
if (lang > 5) lang -= 1;
lang -= 1;
int[] totem = { 811, 1018, 1019, 1024, 1025, 1026, 1058, 1059, 1060 };
if (sender == mnuSeenNone || sender == mnuSeenAll || sender == mnuComplete)
for (int i = 0; i < CB_Species.Items.Count; i++)
for (int i = 0; i < LB_Species.Items.Count; i++)
{
int gt = SAV.Personal[i + 1].Gender;
LB_Species.SelectedIndex = i;
int gt = getBaseSpeciesGender(LB_Species.SelectedIndex);
foreach (CheckBox t in new[] { CHK_P2, CHK_P3, CHK_P4, CHK_P5 })
t.Checked = mnuSeenNone != sender && t.Enabled;
if (mnuSeenNone != sender)
if (mnuSeenNone != sender && !totem.Contains(i+1))
{
// if seen ensure at least one Displayed
// ensure at least one Displayed except for formes
if (i >= CB_Species.Items.Count)
continue;
if (!(CHK_P6.Checked || CHK_P7.Checked || CHK_P8.Checked || CHK_P9.Checked))
(gt != 254 ? CHK_P6 : CHK_P7).Checked = true;
}
@ -309,41 +329,51 @@ private void modifyAll(object sender, EventArgs e)
}
if (sender == mnuCaughtNone || sender == mnuCaughtAll || sender == mnuComplete)
{
for (int i = 0; i < LB_Species.Items.Count; i++)
{
int gt = SAV.Personal[i + 1].Gender;
int gt = getBaseSpeciesGender(LB_Species.SelectedIndex);
LB_Species.SelectedIndex = i;
foreach (CheckBox t in new[] { CHK_P1 })
t.Checked = mnuCaughtNone != sender;
for (int j = 0; j < CL.Length; j++)
CL[j].Checked = CL[j].Enabled && (sender == mnuComplete || (mnuCaughtNone != sender && j == lang));
// Don't modify totem entries
if (totem.Contains(i+1))
continue;
if (mnuCaughtNone == sender)
{
if (i >= CB_Species.Items.Count)
continue;
if (!(CHK_P2.Checked || CHK_P3.Checked || CHK_P4.Checked || CHK_P5.Checked)) // if seen
if (!(CHK_P6.Checked || CHK_P7.Checked || CHK_P8.Checked || CHK_P9.Checked)) // not displayed
(gt != 254 ? CHK_P6 : CHK_P7).Checked = true; // check one
}
if (mnuCaughtNone != sender)
{
if (mnuComplete == sender)
{
// Seen All
foreach (var chk in new[] { CHK_P2, CHK_P3, CHK_P4, CHK_P5 })
chk.Checked = true;
}
else
{
// ensure at least one SEEN
if (!(CHK_P2.Checked || CHK_P3.Checked || CHK_P4.Checked || CHK_P5.Checked))
(gt != 254 ? CHK_P2 : CHK_P3).Checked = true;
}
// ensure at least one Displayed
if (!(CHK_P6.Checked || CHK_P7.Checked || CHK_P8.Checked || CHK_P9.Checked))
(gt != 254 ? CHK_P6 : CHK_P7).Checked = CHK_P1.Enabled; // except for formes -- base species is set as default seen
continue;
}
if (mnuComplete == sender)
{
// Seen All
foreach (var chk in new[] { CHK_P2, CHK_P3, CHK_P4, CHK_P5 })
chk.Checked = chk.Enabled;
}
else
{
// ensure at least one SEEN
if (!(CHK_P2.Checked || CHK_P3.Checked || CHK_P4.Checked || CHK_P5.Checked))
(gt != 254 ? CHK_P2 : CHK_P3).Checked = true;
}
// ensure at least one Displayed except for formes
if (i >= CB_Species.Items.Count)
continue;
if (!(CHK_P6.Checked || CHK_P7.Checked || CHK_P8.Checked || CHK_P9.Checked))
(gt != 254 ? CHK_P6 : CHK_P7).Checked = CHK_P1.Enabled;
}
}
setEntry();
// Turn off zh2 Petilil

View File

@ -51,7 +51,7 @@ private void B_Save_Click(object sender, EventArgs e)
private void initBags()
{
tabControl1.SizeMode = TabSizeMode.Fixed;
tabControl1.ItemSize = new Size(IL_Pouch.Images[0].Width + 4, 0);
tabControl1.ItemSize = new Size(IL_Pouch.Images[0].Width + 4, IL_Pouch.Images[0].Height + 4);
for (int i = 0; i < Pouches.Length; i++)
{
// Add Tab

View File

@ -176,7 +176,7 @@ private void B_Save_Click(object sender, EventArgs e)
if (SAV is SAV1)
{
SAV1 sav1 = (SAV1) SAV;
sav1.Coin = (ushort) Util.ToUInt32(MT_Coins.Text);
sav1.Coin = (ushort)Math.Max(Util.ToUInt32(MT_Coins.Text), 9999);
sav1.Badges = badgeval & 0xFF;
var pf = Util.ToUInt32(MT_PikaFriend.Text);
@ -193,7 +193,7 @@ private void B_Save_Click(object sender, EventArgs e)
if (SAV is SAV2)
{
SAV2 sav2 = (SAV2)SAV;
sav2.Coin = (ushort)Util.ToUInt32(MT_Coins.Text);
sav2.Coin = (ushort)Math.Max(Util.ToUInt32(MT_Coins.Text), 9999);
sav2.Badges = badgeval & 0xFFFF;
sav2.BattleEffects = CHK_BattleEffects.Checked;

View File

@ -369,7 +369,7 @@ private CheckResult verifyEncounter()
if (pkm.VC)
{
int baseSpecies = Legal.getEvolutionChain(pkm, null).Min(entry => entry.Species);
int baseSpecies = Legal.getBaseSpecies(pkm);
if ((pkm.VC1 && baseSpecies > Legal.MaxSpeciesID_1) ||
(pkm.VC2 && baseSpecies > Legal.MaxSpeciesID_2))
return new CheckResult(Severity.Invalid, "VC: Unobtainable species.", CheckIdentifier.Encounter);
@ -991,7 +991,7 @@ private void verifyEggBallGen6()
}
if (0x0D <= pkm.Ball && pkm.Ball <= 0x0F)
{
if (Legal.Ban_Gen4Ball.Contains(pkm.Species))
if (Legal.Ban_Gen4Ball_6.Contains(pkm.Species))
AddLine(Severity.Invalid, "Unobtainable capture for Gen4 Ball.", CheckIdentifier.Ball);
else
AddLine(Severity.Valid, "Obtainable capture for Gen4 Ball.", CheckIdentifier.Ball);
@ -1087,15 +1087,10 @@ private void verifyEggBallGen7()
return;
}
if (0x0D <= pkm.Ball && pkm.Ball <= 0x0F)
if (0x0D <= pkm.Ball && pkm.Ball <= 0x0F) // Dusk Heal Quick
{
if (Legal.Ban_Gen4Ball.Contains(pkm.Species))
{
if (!Legal.Ban_Gen4Ball_AllowG7.Contains(pkm.Species))
AddLine(Severity.Invalid, "Unobtainable capture for Gen4 Ball.", CheckIdentifier.Ball);
else
AddLine(Severity.Valid, "Obtainable capture for Gen4 Ball.", CheckIdentifier.Ball);
}
if (Legal.Ban_Gen4Ball_7.Contains(pkm.Species))
AddLine(Severity.Invalid, "Unobtainable capture for Gen4 Ball.", CheckIdentifier.Ball);
else
AddLine(Severity.Valid, "Obtainable capture for Gen4 Ball.", CheckIdentifier.Ball);

View File

@ -365,6 +365,40 @@ private static EvolutionTree getEvolutionTable(PKM pkm)
return Evolves6;
}
}
private static int getMaxSpeciesOrigin(int generation)
{
switch (generation)
{
case 1:
return Legal.MaxSpeciesID_1;
case 2:
return Legal.MaxSpeciesID_2;
case 3:
return Legal.MaxSpeciesID_3;
case 4:
return Legal.MaxSpeciesID_4;
case 5:
return Legal.MaxSpeciesID_5;
case 6:
return Legal.MaxSpeciesID_6;
case 7:
return Legal.MaxSpeciesID_7;
default:
return Legal.MaxSpeciesID_7;
}
}
internal static int getMaxSpeciesOrigin(PKM pkm)
{
if (pkm.Format == 1 || pkm.VC1) //Gen1 VC could not trade with gen 2 yet
return getMaxSpeciesOrigin(1);
else if (pkm.Format == 2 || pkm.VC2)
return getMaxSpeciesOrigin(2);
else
return getMaxSpeciesOrigin(pkm.GenNumber);
}
internal static IEnumerable<MysteryGift> getValidGifts(PKM pkm)
{
switch (pkm.GenNumber)
@ -953,11 +987,9 @@ private static IEnumerable<int> getEggMoves(PKM pkm, int species, int formnum)
case 6: // entries per species
return EggMovesAO[species].Moves.Concat(EggMovesXY[species].Moves);
case 7: // entries per form
if (species == 678)
{ species = 677; formnum = 0; }
case 7: // entries per form if required
var entry = EggMovesSM[species];
if (formnum > 0)
if (formnum > 0 && ((PersonalInfoSM)PersonalTable.SM[species]).FormVariantEggMoves)
entry = EggMovesSM[entry.FormTableIndex + formnum - 1];
return entry.Moves;

View File

@ -10,13 +10,13 @@ public class EvolutionTree
private readonly EvolutionLineage[] Lineage;
private readonly GameVersion Game;
private readonly PersonalTable Personal;
private readonly int MaxSpecies;
private readonly int MaxSpeciesTree;
public EvolutionTree(byte[][] data, GameVersion game, PersonalTable personal, int maxSpecies)
public EvolutionTree(byte[][] data, GameVersion game, PersonalTable personal, int maxSpeciesTree)
{
Game = game;
Personal = personal;
MaxSpecies = maxSpecies;
MaxSpeciesTree = maxSpeciesTree;
switch (game)
{
case GameVersion.SM:
@ -32,7 +32,7 @@ public EvolutionTree(byte[][] data, GameVersion game, PersonalTable personal, in
for (int i = 0; i < Entries.Count; i++)
Lineage[i] = new EvolutionLineage();
if (Game == GameVersion.ORAS)
Array.Resize(ref Lineage, maxSpecies + 1);
Array.Resize(ref Lineage, maxSpeciesTree + 1);
// Populate Lineages
for (int i = 1; i < Lineage.Length; i++)
@ -149,7 +149,8 @@ private int getIndex(EvolutionMethod evo)
public IEnumerable<DexLevel> getValidPreEvolutions(PKM pkm, int lvl, bool skipChecks = false)
{
int index = getIndex(pkm);
return Lineage[index].getExplicitLineage(pkm, lvl, skipChecks, MaxSpecies);
int maxSpeciesOrigin = Legal.getMaxSpeciesOrigin(pkm);
return Lineage[index].getExplicitLineage(pkm, lvl, skipChecks, MaxSpeciesTree, maxSpeciesOrigin);
}
}
@ -293,16 +294,6 @@ public bool Valid(PKM pkm, int lvl, bool skipChecks)
}
}
public DexLevel GetDexLevel(int lvl)
{
return new DexLevel
{
Species = Species,
Level = lvl,
Form = Form,
Flag = Method,
};
}
public DexLevel GetDexLevel(int species, int lvl)
{
@ -352,7 +343,7 @@ public void Insert(EvolutionStage evo)
Chain.Insert(0, evo);
}
public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, bool skipChecks, int maxSpecies)
public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin)
{
List<DexLevel> dl = new List<DexLevel> { new DexLevel { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } };
for (int i = Chain.Count-1; i >= 0; i--) // reverse evolution!
@ -364,11 +355,14 @@ public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, bool skipCheck
continue;
oneValid = true;
if (evo.Species > maxSpecies) // Gen7 Personal Formes -- unmap the forme personal entry to the actual species ID since species are consecutive
dl.Add(evo.GetDexLevel(pkm.Species - Chain.Count + i, lvl));
else
dl.Add(evo.GetDexLevel(lvl));
int species = evo.Species;
// Gen7 Personal Formes -- unmap the forme personal entry ID to the actual species ID since species are consecutive
if (evo.Species > maxSpeciesTree)
species = pkm.Species - Chain.Count + i;
dl.Add(evo.GetDexLevel(species, lvl));
if (evo.RequiresLevelUp)
lvl--;
break;
@ -376,6 +370,11 @@ public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, bool skipCheck
if (!oneValid)
break;
}
// Remove future gen preevolutions, no munchlax in a gen3 snorlax, no pichu in a gen1 vc raichu, etc
if (dl.Any(d => d.Species <= maxSpeciesOrigin) && dl.Last().Species > maxSpeciesOrigin)
dl.RemoveAt(dl.Count - 1);
return dl;
}
}

View File

@ -682,7 +682,7 @@ public static partial class Legal
497, 500, 503, //3
566, 567, 696, 697, 698, 699 // Fossil Only obtain
};
internal static readonly int[] Ban_Gen4Ball =
internal static readonly int[] Ban_Gen4Ball_6 =
{
152, 155, 158, //1 - Chikorita, Cyndaquil, Totodile
153, 156, 159, //2

View File

@ -434,14 +434,9 @@ public static partial class Legal
496, 499, 502, //2
497, 500, 503, //3
};
internal static readonly int[] Ban_Gen4Ball_AllowG7 =
internal static readonly int[] Ban_Gen4Ball_7 =
{
152, 155, 158, //1 - Chikorita, Cyndaquil, Totodile
153, 156, 159, //2
154, 157, 160, //3
495, 498, 501, //1 - Snivy, Tepig, Oshawott
496, 499, 502, //2
497, 500, 503, //3
566, 567, 696, 697, 698, 699 // Fossil Only obtain
};
internal static readonly int[] ZygardeMoves =

View File

@ -627,6 +627,8 @@ public PK7 convertToPK7()
pk7.Data[0xDE] = 0; /* Gen IV encounter type. */
pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm
pk7.Geo1_Country = PKMConverter.Country;
pk7.Geo1_Region = PKMConverter.Region;
// Fix Checksum
pk7.RefreshChecksum();

View File

@ -374,7 +374,7 @@ public virtual int[] Markings
return;
byte b = 0;
for (int i = 0; i < value.Length; i++)
b |= (byte)((value[i] & 1) << i);
b |= (byte)(Math.Max(value[i], 1) << i);
MarkValue = b;
}
}
@ -386,7 +386,7 @@ public int[] CNTs
}
public virtual int HPType
{
get { return 15 * ((IV_HP & 1) + 2 * (IV_ATK & 1) + 4 * (IV_DEF & 1) + 8 * (IV_SPE & 1) + 16 * (IV_SPA & 1) + 32 * (IV_SPD & 1)) / 63; }
get { return 0xF * ((IV_HP & 1) << 0 | (IV_ATK & 1) << 1 | (IV_DEF & 1) << 2 | (IV_SPE & 1) << 3 | (IV_SPA & 1) << 4 | (IV_SPD & 1) << 5) / 0x3F; }
set
{
IV_HP = (IV_HP & ~1) + PKX.hpivs[value, 0];

View File

@ -636,7 +636,7 @@ public static string[] getFormList(int species, string[] t, string[] f, string[]
{
f[412], // Plant
f[905], // Sandy
f[904], // Trash
f[906], // Trash
};
case 421:
@ -841,7 +841,7 @@ public static string[] getFormList(int species, string[] t, string[] f, string[]
f[976], // Savannah
f[977], // Sun
f[978], // Ocean
f[989], // Jungle
f[979], // Jungle
f[980], // Fancy
f[981], // Poké Ball
};
@ -871,7 +871,7 @@ public static string[] getFormList(int species, string[] t, string[] f, string[]
case 676:
return new[]
{
f[994], // Natural
f[676], // Natural
f[995], // Heart
f[996], // Star
f[997], // Diamond

View File

@ -25,6 +25,6 @@ public override byte[] Write()
public int SpecialZ_Item { get { return BitConverter.ToUInt16(Data, 0x4C); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4C); } }
public int SpecialZ_BaseMove { get { return BitConverter.ToUInt16(Data, 0x4E); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4E); } }
public int SpecialZ_ZMove { get { return BitConverter.ToUInt16(Data, 0x50); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x50); } }
public bool LocalVariant { get { return Data[0x52] == 1; } set { Data[0x52] = (byte)(value ? 1 : 0); } }
public bool FormVariantEggMoves { get { return Data[0x52] == 1; } set { Data[0x52] = (byte)(value ? 1 : 0); } }
}
}

Binary file not shown.

View File

@ -1,7 +1,19 @@
PKHeX - By Kaphotics
http://projectpokemon.org/pkhex
17/01/28 - New Update:
17/01/30 - New Update:
- Added: Control right-clicking a PKM slot (box, party, etc) now allows direct legality checking.
- Added: 6/7 detection preferential treatment & other detection methods. Thanks sora10pls!
- Added: Remove All medals button now clears Unlocked/Complete flags even if not visible.
- Fixed: Badly constructed ShowdownSets throw less exceptions (hopefully none). Thanks Sonic Blader!
- Fixed: Cloning to all slots in a Gen1/2 english save no longer overflows. Thanks Wanderer1391!
- Fixed: Forme list for Burmy/Vivillon/Furfrou now displays correct formes. Thanks sora10pls!
- Fixed: Gen4/5 PID no longer automatically rerolls when changing ability lists. Thanks RoC!
- Fixed: Multiple legality edge cases. Thanks everyone who reported!
- Fixed: 1/6->7 transfer not applying geolocation data. Thanks RoC!
- Fixed: English Demo Greninja now is recognized correctly.
17/01/28 - New Update: (23464) [241859]
- Added: Gen6->Gen7 transfer logic and Gen1->Gen7 transfer logic.
- - Note: Bank adds memories and geolocation data to all pk7 files it touches.
- Legality:

View File

@ -1 +1 @@
20170128
20170130