public SAV_PokedexSM() { InitializeComponent(); CP = new[] { CHK_P1, CHK_P2, CHK_P3, CHK_P4, CHK_P5, CHK_P6, CHK_P7, CHK_P8, CHK_P9, }; CL = new[] { CHK_L1, CHK_L2, CHK_L3, CHK_L4, CHK_L5, CHK_L6, CHK_L7, CHK_L8, CHK_L9, }; Util.TranslateInterface(this, Main.curlanguage); editing = true; // Clear Listbox and ComboBox LB_Species.Items.Clear(); CB_Species.Items.Clear(); // Fill List CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource.Skip(1).ToList(), null); for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) { LB_Species.Items.Add($"{i:000} - {Main.GameStrings.specieslist[i]}"); } // Add Formes int ctr = SAV.MaxSpeciesID; for (int i = 0; i < SAV.MaxSpeciesID + 1; i++) { int c = SAV.Personal[i].FormeCount; for (int j = 0; j < c; j++) { int x = SaveUtil.getDexFormIndexSM(i, c, j); if (x == -1 || j == 0) { continue; } ctr++; LB_Species.Items.Add($"{ctr:000} - {Main.GameStrings.specieslist[i]}-{j}"); } } Dex = new PokeDex7(SAV); editing = false; LB_Species.SelectedIndex = 0; }
protected override void setDex(PKM pkm) { if (PokeDex < 0 || Version == GameVersion.Unknown) // sanity { return; } if (pkm.Species == 0 || pkm.Species > MaxSpeciesID) // out of range { return; } if (pkm.IsEgg) // do not add { return; } int bit = pkm.Species - 1; int bd = bit >> 3; // div8 int bm = bit & 7; // mod8 int gender = pkm.Gender % 2; // genderless -> male int shiny = pkm.IsShiny ? 1 : 0; if (pkm.Species == 351) // castform { shiny = 0; } int shift = gender | (shiny << 1); if (pkm.Species == 327) // Spinda { if ((Data[PokeDex + 0x84] & (1 << (shift + 4))) != 0) // Already 2 { BitConverter.GetBytes(pkm.EncryptionConstant).CopyTo(Data, PokeDex + 0x8E8 + shift * 4); // Data[PokeDex + 0x84] |= (byte)(1 << (shift + 4)); // 2 -- pointless Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1 } else if ((Data[PokeDex + 0x84] & (1 << shift)) == 0) // Not yet 1 { Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1 } } int ofs = PokeDex // Raw Offset + 0x08 // Magic + Flags + 0x80; // Misc Data (1024 bits) // Set the Owned Flag Data[ofs + bd] |= (byte)(1 << bm); // Starting with Gen7, form bits are stored in the same region as the species flags. int formstart = pkm.AltForm; int formend = pkm.AltForm; int fs, fe; bool reset = sanitizeFormsToIterate(pkm.Species, out fs, out fe, formstart); if (reset) { formstart = fs; formend = fe; } for (int form = formstart; form <= formend; form++) { int bitIndex = bit; if (form > 0) // Override the bit to overwrite { int fc = Personal[pkm.Species].FormeCount; if (fc > 1) // actually has forms { int f = SaveUtil.getDexFormIndexSM(pkm.Species, fc, MaxSpeciesID - 1); if (f >= 0) // bit index valid { bitIndex = f + form; } } } setDexFlags(bitIndex, gender, shiny, pkm.Species - 1); } // Set the Language int lang = pkm.Language; const int langCount = 9; if (lang <= 10 && lang != 6 && lang != 0) // valid language { if (lang >= 7) { lang--; } lang--; // 0-8 languages if (lang < 0) { lang = 1; } int lbit = bit * langCount + lang; if (lbit >> 3 < 920) // Sanity check for max length of region { Data[PokeDexLanguageFlags + (lbit >> 3)] |= (byte)(1 << (lbit & 7)); } } }
protected override void setDex(PKM pkm) { if (PokeDex < 0) return; if (pkm.Species == 0) return; if (pkm.Species > MaxSpeciesID) // Raw Max is 832 return; if (Version == GameVersion.Unknown) return; const int brSize = 0x68; // 832 bits, 32bit alignment is required (MaxSpeciesID > 800) int baseOfs = PokeDex + 0x08; int bit = pkm.Species - 1; int bd = bit >> 3; // div8 int bm = bit & 7; // mod8 int gender = pkm.Gender % 2; // genderless -> male int shiny = pkm.IsShiny ? 1 : 0; int shift = gender + shiny << 2; if (pkm.Species == 327) // Spinda { if ((Data[PokeDex + 0x84] & (1 << (shift + 4))) != 0) // Already 2 { BitConverter.GetBytes(pkm.EncryptionConstant).CopyTo(Data, PokeDex + 0x8E8 + shift * 4); // Data[PokeDex + 0x84] |= (byte)(1 << (shift + 4)); // 2 -- pointless Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1 } else if ((Data[PokeDex + 0x84] & (1 << shift)) == 0) // Not yet 1 { Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1 } } int ofs = PokeDex // Raw Offset + 0x08 // Magic + Flags + 0x80; // Misc Data (1024 bits) // Set the Owned Flag Data[ofs + bd] |= (byte)(1 << bm); // Set the [Species/Gender/Shiny] Seen Flag int brSeen = (shift + 1) * brSize; // offset by 1 for the "Owned" Region Data[ofs + brSeen + bd] |= (byte)(1 << bm); // Set the Display flag if none are set bool Displayed = false; for (int i = 0; i < 4; i++) { int brDisplayed = (5 + i) * brSize; // offset by 1 for the "Owned" Region, 4 for the Seen Regions Displayed |= (Data[ofs + brDisplayed + bd] & (byte)(1 << bm)) != 0; } if (!Displayed) Data[ofs + brSeen + brSize * 4 + bd] |= (byte)(1 << bm); // Adjust brSeen to the displayed flags. // Set the Language int lang = pkm.Language; const int langCount = 9; if (lang <= 10 && lang != 6 && lang != 0) // valid language { if (lang >= 7) lang--; lang--; // 0-8 languages if (lang < 0) lang = 1; int lbit = bit * langCount + lang; if (lbit >> 3 < 920) // Sanity check for max length of region Data[PokeDexLanguageFlags + (lbit >> 3)] |= (byte)(1 << (lbit & 7)); } return; // Set Form flags : TODO #pragma warning disable 162 int fc = Personal[pkm.Species].FormeCount; int f = SaveUtil.getDexFormIndexSM(pkm.Species, fc); if (f < 0) return; int FormLen = ORAS ? 0x26 : 0x18; int FormDex = PokeDex + 0x8 + brSize*9; int fbit = f + pkm.AltForm; int fbd = fbit>>3; int fbm = fbit&7; // Set Form Seen Flag Data[FormDex + FormLen*shiny + bit/8] |= (byte)(1 << (bit%8)); // Set Displayed Flag if necessary, check all flags for (int i = 0; i < fc; i++) { int dfbit = f + i; int dfbd = dfbit>>3; int dfbm = dfbit&7; if ((Data[FormDex + FormLen*2 + dfbd] & (byte) (1 << dfbm)) != 0) // Nonshiny return; // already set if ((Data[FormDex + FormLen*3 + dfbd] & (byte) (1 << dfbm)) != 0) // Shiny return; // already set } Data[FormDex + FormLen * (2 + shiny) + fbd] |= (byte)(1 << fbm); #pragma warning restore 162 }