public byte[] Write() { byte[] data = (byte[])Data.Clone(); PKX.CryptArray(data, EncryptionSeed, 0, EncryptionSeedOffset); return(data); }
/// <summary> /// Gets the generation of the Pokemon data. /// </summary> /// <param name="data">Raw data representing a Pokemon.</param> /// <returns>An integer indicating the generation of the PKM file, or -1 if the data is invalid.</returns> public static int GetPKMDataFormat(byte[] data) { if (!PKX.IsPKM(data.Length)) { return(-1); } switch (data.Length) { case PokeCrypto.SIZE_1JLIST: case PokeCrypto.SIZE_1ULIST: return(1); case PokeCrypto.SIZE_2ULIST: case PokeCrypto.SIZE_2JLIST: return(2); case PokeCrypto.SIZE_3PARTY: case PokeCrypto.SIZE_3STORED: case PokeCrypto.SIZE_3CSTORED: case PokeCrypto.SIZE_3XSTORED: return(3); case PokeCrypto.SIZE_4PARTY: case PokeCrypto.SIZE_4STORED: case PokeCrypto.SIZE_5PARTY: if ((BitConverter.ToUInt16(data, 0x4) == 0) && (BitConverter.ToUInt16(data, 0x80) >= 0x3333 || data[0x5F] >= 0x10) && BitConverter.ToUInt16(data, 0x46) == 0) // PK5 { return(5); } return(4); case PokeCrypto.SIZE_6STORED: return(6); case PokeCrypto.SIZE_6PARTY: // collision with PGT, same size. if (BitConverter.ToUInt16(data, 0x4) != 0) // Bad Sanity? { return(-1); } if (BitConverter.ToUInt32(data, 0x06) == PokeCrypto.GetCHK(data)) { return(6); } if (BitConverter.ToUInt16(data, 0x58) != 0) // Encrypted? { for (int i = data.Length - 0x10; i < data.Length; i++) // 0x10 of 00's at the end != PK6 { if (data[i] != 0) { return(6); } } return(-1); } return(6); case PokeCrypto.SIZE_8PARTY: case PokeCrypto.SIZE_8STORED: return(8); default: return(-1); } }
public override bool IsPKMPresent(byte[] data, int offset) => PKX.IsPKMPresentGB(data, offset);
public override byte[] SetString(string value, int maxLength) => PKX.SetString1(value, maxLength, Japanese);
public override bool IsPKMPresent(int offset) => PKX.IsPKMPresentGBA(Data, offset);
public override string GetString(int Offset, int Count) => PKX.GetBEString3(Data, Offset, Count);
public override byte[] Encrypt() { RefreshChecksum(); return(PKX.shuffleArray45(Data, PKX.blockPositionInvert[((PID & 0x3E000) >> 0xD) % 24])); }
public override string getBoxName(int box) { return(PKX.getColoStr(Data, Box + (30 * SIZE_STORED + 0x14) * box, 8)); }
public PKM ConvertToPKM(ITrainerInfo SAV) { int gen = Version.GetGeneration(); if (gen < 2) { gen = 2; Version = GameVersion.C; } var pk = PKMConverter.GetBlank(gen); SAV.ApplyToPKM(pk); pk.Species = Species; pk.Nickname = PKX.GetSpeciesNameGeneration(Species, SAV.Language, gen); pk.CurrentLevel = Level; pk.Version = (int)Version; int[] moves = GetCurrentEggMoves(pk); pk.Moves = moves; pk.SetMaximumPPCurrent(moves); pk.OT_Friendship = pk.PersonalInfo.BaseFriendship; pk.SetRandomIVs(flawless: 3); if (pk.Format <= 2 && Version != GameVersion.C) { return(pk); } pk.Met_Level = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk); pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk)); if (pk.Format < 3) { return(pk); } pk.Ball = 4; int gender = pk.PersonalInfo.RandomGender; int nature = Util.Rand.Next(25); if (pk.Format <= 5) { pk.SetPIDGender(gender); pk.Gender = gender; pk.SetPIDNature(nature); pk.Nature = nature; pk.RefreshAbility(pk.PIDAbility); } else { pk.PID = Util.Rand32(); pk.Nature = nature; pk.Gender = gender; pk.RefreshAbility(Util.Rand.Next(2)); } bool traded = (int)Version == SAV.Game; var today = pk.MetDate = DateTime.Today; if (pk.GenNumber >= 4) { pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded); pk.EggMetDate = today; } if (pk.Format < 6) { return(pk); } if (pk.Gen6) { pk.SetHatchMemory6(); } switch (Species) { case 774: // Minior pk.AltForm = Util.Rand.Next(7, 14); break; case 664: // Scatterbug pk.AltForm = Legal.GetVivillonPattern(SAV.Country, SAV.SubRegion); break; } pk.SetRandomEC(); pk.RelearnMoves = moves; return(pk); }
private static PKM ConvertPKM(PKM pk, Type PKMType, Type fromType, int toFormat, ref string comment) { PKM pkm = pk.Clone(); if (pkm.IsEgg) { ForceHatchPKM(pkm); } switch (fromType.Name) { case nameof(PK1): if (toFormat == 7) // VC->Bank { pkm = ((PK1)pk).ConvertToPK7(); } else if (toFormat == 2) // GB<->GB { pkm = ((PK1)pk).ConvertToPK2(); } break; case nameof(PK2): if (toFormat == 7) // VC->Bank { pkm = ((PK2)pk).ConvertToPK7(); } else if (toFormat == 1) // GB<->GB { if (pk.Species > 151) { comment = $"Cannot convert a {PKX.GetSpeciesName(pkm.Species, pkm.Japanese ? 1 : 2)} to {PKMType.Name}"; return(pkm); } pkm = ((PK2)pk).ConvertToPK1(); pkm.ClearInvalidMoves(); } break; case nameof(CK3): pkm = ((CK3)pkm).ConvertToPK3(); goto case nameof(PK3); // fall through case nameof(XK3): pkm = ((XK3)pkm).ConvertToPK3(); goto case nameof(PK3); // fall through case nameof(PK3): if (toFormat == 3) { if (PKMType == typeof(CK3)) { pkm = ((PK3)pkm).ConvertToCK3(); } else if (PKMType == typeof(XK3)) { pkm = ((PK3)pkm).ConvertToXK3(); } break; } pkm = ((PK3)pkm).ConvertToPK4(); if (toFormat == 4) { break; } goto case nameof(PK4); case nameof(BK4): pkm = ((BK4)pkm).ConvertToPK4(); if (toFormat == 4) { break; } goto case nameof(PK4); case nameof(PK4): if (PKMType == typeof(BK4)) { pkm = ((PK4)pkm).ConvertToBK4(); break; } pkm = ((PK4)pkm).ConvertToPK5(); if (toFormat == 5) { break; } goto case nameof(PK5); case nameof(PK5): pkm = ((PK5)pkm).ConvertToPK6(); if (toFormat == 6) { break; } goto case nameof(PK6); case nameof(PK6): if (pkm.Species == 25 && pkm.AltForm != 0) // cosplay pikachu { comment = "Cannot transfer Cosplay Pikachu forward."; return(pkm); } pkm = ((PK6)pkm).ConvertToPK7(); if (toFormat == 7) { break; } goto case nameof(PK7); case nameof(PK7): break; } return(pkm); }
public override void Verify(LegalityAnalysis data) { var pkm = data.pkm; if (pkm is IAwakened a) { VerifyAwakenedValues(data, a); return; } var EncounterMatch = data.EncounterMatch; var evs = pkm.EVs; int sum = pkm.EVTotal; if (sum > 0 && pkm.IsEgg) { data.AddLine(GetInvalid(LEffortEgg)); } if (pkm.Format >= 3 && sum > 510) { data.AddLine(GetInvalid(LEffortAbove510)); } if (pkm.Format >= 6 && evs.Any(ev => ev > 252)) { data.AddLine(GetInvalid(LEffortAbove252)); } if (pkm.Format == 4 && pkm.Gen4 && EncounterMatch.LevelMin == 100) { // Cannot EV train at level 100 -- Certain events are distributed at level 100. if (evs.Any(ev => ev > 100)) // EVs can only be increased by vitamins to a max of 100. { data.AddLine(GetInvalid(LEffortCap100)); } } else if (pkm.Format < 5) { // In Generations I and II, when a Pokémon is taken out of the Day Care, its experience will lower to the minimum value for its current level. if (pkm.Format < 3) // can abuse daycare for EV training without EXP gain { return; } const int maxEV = 100; // Vitamin Max if (PKX.GetEXP(EncounterMatch.LevelMin, pkm.Species) == pkm.EXP && evs.Any(ev => ev > maxEV)) { data.AddLine(GetInvalid(string.Format(LEffortUntrainedCap, maxEV))); } } // Only one of the following can be true: 0, 508, and x%6!=0 if (sum == 0 && !EncounterMatch.IsWithinRange(pkm)) { data.AddLine(Get(LEffortEXPIncreased, Severity.Fishy)); } else if (sum == 508) { data.AddLine(Get(LEffort2Remaining, Severity.Fishy)); } else if (evs[0] != 0 && evs.All(ev => evs[0] == ev)) { data.AddLine(Get(LEffortAllEqual, Severity.Fishy)); } }
public override byte[] decryptPKM(byte[] data) { return(PKX.decryptArray(data)); }
public override byte[] setString(string value, int maxLength) => PKX.setString7(value, maxLength, Language);
public PK7 convertToPK7() { var pk7 = new PK7 { EncryptionConstant = Util.rnd32(), Species = Species, TID = TID, CurrentLevel = CurrentLevel, EXP = EXP, Met_Level = CurrentLevel, Nature = (int)(EXP % 25), PID = Util.rnd32(), Ball = 4, MetDate = DateTime.Now, Version = (int)GameVersion.RD, // Default to red, for now? Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4, Move1_PPUps = Move1_PPUps, Move2_PPUps = Move2_PPUps, Move3_PPUps = Move3_PPUps, Move4_PPUps = Move4_PPUps, Move1_PP = Move1_PP, Move2_PP = Move2_PP, Move3_PP = Move3_PP, Move4_PP = Move4_PP, Met_Location = 30013, // "Kanto region", hardcoded. Gender = PersonalTable.SM[Species].RandomGender, OT_Name = PKX.getG1ConvertedString(otname, Japanese), IsNicknamed = false, Country = PKMConverter.Country, Region = PKMConverter.Region, ConsoleRegion = PKMConverter.ConsoleRegion, CurrentHandler = 1, HT_Name = PKMConverter.OT_Name, HT_Gender = PKMConverter.OT_Gender, Language = PKMConverter.Language, Geo1_Country = PKMConverter.Country, Geo1_Region = PKMConverter.Region }; pk7.Nickname = PKX.getSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format); if (otname[0] == 0x5D) // Ingame Trade { var s = PKX.getG1Char(0x5D, Japanese); pk7.OT_Name = s.Substring(0, 1) + s.Substring(1).ToLower(); } pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship; // IVs var new_ivs = new int[6]; int flawless = Species == 151 ? 5 : 3; for (var i = 0; i < new_ivs.Length; i++) { new_ivs[i] = (int)(Util.rnd32() & 31); } for (var i = 0; i < flawless; i++) { new_ivs[i] = 31; } Util.Shuffle(new_ivs); pk7.IVs = new_ivs; // Really? :( if (IsShiny) { pk7.setShinyPID(); } int abil = 2; // Hidden if (Legal.TransferSpeciesDefaultAbility_1.Contains(Species)) { abil = 0; // Reset } pk7.RefreshAbility(abil); // 0/1/2 (not 1/2/4) if (Species == 151) // Mew gets special treatment. { pk7.FatefulEncounter = true; } else if (IsNicknamedBank) { pk7.IsNicknamed = true; pk7.Nickname = PKX.getG1ConvertedString(nick, Japanese); } pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm if (pk7.Species == 150) // Pay Day Mewtwo { var moves = pk7.Moves; var index = Array.IndexOf(moves, 6); if (index != -1) { moves[index] = 0; pk7.Moves = moves; pk7.FixMoves(); } } pk7.RefreshChecksum(); return(pk7); }
public override string getString(int Offset, int Count) => PKX.getBEString4(Data, Offset, Count);
public override bool IsPKMPresent(int Offset) => PKX.IsPKMPresentGB(Data, Offset);
public override byte[] setString(string value, int maxLength) => PKX.setBEString4(value, maxLength);
private PersonalTable(byte[] data, GameVersion format) { int size = 0; switch (format) { case GameVersion.RBY: size = PersonalInfoG1.SIZE; break; case GameVersion.GS: case GameVersion.C: size = PersonalInfoG2.SIZE; break; case GameVersion.RS: case GameVersion.E: case GameVersion.FR: case GameVersion.LG: size = PersonalInfoG3.SIZE; break; case GameVersion.DP: case GameVersion.Pt: case GameVersion.HGSS: size = PersonalInfoG4.SIZE; break; case GameVersion.BW: size = PersonalInfoBW.SIZE; break; case GameVersion.B2W2: size = PersonalInfoB2W2.SIZE; break; case GameVersion.XY: size = PersonalInfoXY.SIZE; break; case GameVersion.ORAS: size = PersonalInfoORAS.SIZE; break; case GameVersion.SM: size = PersonalInfoSM.SIZE; break; } if (size == 0) { Table = null; return; } byte[][] entries = splitBytes(data, size); PersonalInfo[] d = new PersonalInfo[data.Length / size]; switch (format) { case GameVersion.RBY: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoG1(entries[i]); } break; case GameVersion.GS: case GameVersion.C: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoG2(entries[i]); } break; case GameVersion.RS: case GameVersion.E: case GameVersion.FR: case GameVersion.LG: Array.Resize(ref d, 387); for (int i = 0; i < d.Length; i++) // entries are not in order of natdexID { d[i] = new PersonalInfoG3(entries[PKX.getG3Species(i)]); } break; case GameVersion.DP: case GameVersion.Pt: case GameVersion.HGSS: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoG4(entries[i]); } break; case GameVersion.BW: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoBW(entries[i]); } break; case GameVersion.B2W2: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoB2W2(entries[i]); } break; case GameVersion.XY: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoXY(entries[i]); } break; case GameVersion.ORAS: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoORAS(entries[i]); } break; case GameVersion.SM: for (int i = 0; i < d.Length; i++) { d[i] = new PersonalInfoSM(entries[i]); } break; } Table = d; }
public override byte[] SetString(string value, int maxLength) => PKX.SetBEString3(value, maxLength);
public override string getBoxName(int box) { return(PKX.getG1Str(getData(BoxNamesOffset + box * 9, 9), Japanese)); }
public override string GetString(int Offset, int Count) => PKX.GetString1(Data, Offset, Count, Japanese);
// Parsing Utility public ShowdownSet(string input = null) { if (input == null) { return; } string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].Replace("'", "’").Trim(); // Sanitize apostrophes } lines = lines.Where(line => line.Length > 2).ToArray(); if (lines.Length < 3) { return; } // Seek for start of set int start = Array.FindIndex(lines, line => line.Contains(" @ ")); if (start != -1) // Has Item -- skip to start. { lines = lines.Skip(start).Take(lines.Length - start).ToArray(); } else // Has no Item -- try parsing the first line anyway. { ParseFirstLine(lines[0]); if (Species < -1) { return; // Abort if no text is found } lines = lines.Skip(1).Take(lines.Length - 1).ToArray(); } int movectr = 0; // Detect relevant data foreach (string line in lines) { if (line.StartsWith("-")) { string moveString = ParseLineMove(line); int move = Array.IndexOf(moves, moveString); if (move < 0) { InvalidLines.Add($"Unknown Move: {moveString}"); } else { Moves[movectr++] = move; } if (movectr == 4) { break; // End of moves } continue; } string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None); if (brokenline.Length == 1) { brokenline = new[] { brokenline[0], string.Empty } } ; switch (brokenline[0]) { case "Trait": case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1].Trim()); break; } case "Level": { if (int.TryParse(brokenline[1].Trim(), out int val)) { Level = val; } else { InvalidLines.Add(line); } break; } case "Shiny": { Shiny = brokenline[1].Trim() == "Yes"; break; } case "Happiness": { if (int.TryParse(brokenline[1].Trim(), out int val)) { Friendship = val; } else { InvalidLines.Add(line); } break; } case "Nature": { Nature = Array.IndexOf(natures, brokenline[1].Trim()); break; } case "EV": case "EVs": { ParseLineEVs(brokenline[1].Trim()); break; } case "IV": case "IVs": { ParseLineIVs(brokenline[1].Trim()); break; } case "Type": { brokenline = new[] { line }; goto default; } // Type: Null edge case default: { // Either Nature or Gender ItemSpecies if (brokenline[0].Contains(" @ ")) { string[] pieces = line.Split(new[] { " @ " }, StringSplitOptions.None); string itemstr = pieces.Last().Trim(); int item = Array.IndexOf(items, itemstr); if (item < 0) { InvalidLines.Add($"Unknown Item: {itemstr}"); } else { HeldItem = item; } ParseFirstLine(pieces[0]); } else if (brokenline[0].Contains("Nature")) { string naturestr = line.Split(' ')[0].Trim(); int nature = Array.IndexOf(natures, naturestr); if (nature < 0) { InvalidLines.Add($"Unknown Nature: {naturestr}"); } else { Nature = nature; } } else // Fallback { string speciesstr = line.Split('(')[0].Trim(); int spec = Array.IndexOf(species, speciesstr); if (spec < 1) { InvalidLines.Add(speciesstr); } else { Species = spec; } } break; } } } IVs = IVsSpeedFirst; EVs = EVsSpeedFirst; // Showdown Quirks Form = ConvertFormFromShowdown(Form, Species, Ability); // Set Form string[] formStrings = PKX.GetFormList(Species, types, forms, genderForms); FormIndex = Math.Max(0, Array.FindIndex(formStrings, z => z.Contains(Form ?? ""))); }
public override byte[] decryptPKM(byte[] data) { return(PKX.decryptArray3(data.Take(PKX.SIZE_3STORED).ToArray())); }
public override void Verify(LegalityAnalysis data) { var pkm = data.pkm; var EncounterMatch = data.EncounterOriginal; if (EncounterMatch is MysteryGift gift) { if (gift.Level != pkm.Met_Level && pkm.HasOriginalMetLocation) { switch (gift) { case WC3 wc3 when wc3.Met_Level == pkm.Met_Level || wc3.IsEgg: break; case WC7 wc7 when wc7.MetLevel == pkm.Met_Level: break; default: data.AddLine(GetInvalid(V83)); return; } } if (gift.Level > pkm.CurrentLevel) { data.AddLine(GetInvalid(V84)); return; } } if (pkm.IsEgg) { int elvl = Legal.GetEggHatchLevel(pkm); if (elvl != pkm.CurrentLevel) { data.AddLine(GetInvalid(string.Format(V52, elvl))); return; } var reqEXP = EncounterMatch is EncounterStatic s && s.Version == GameVersion.C ? 125 // Gen2 Dizzy Punch gifts always have 125 EXP, even if it's more than the Lv5 exp required. : PKX.GetEXP(elvl, pkm.Species); if (reqEXP != pkm.EXP) { data.AddLine(GetInvalid(V613)); } return; } int lvl = pkm.CurrentLevel; if (lvl < pkm.Met_Level) { data.AddLine(GetInvalid(V85)); } else if (!EncounterMatch.IsWithinRange(pkm) && lvl != 100 && pkm.EXP == PKX.GetEXP(lvl, pkm.Species)) { data.AddLine(Get(V87, Severity.Fishy)); } else { data.AddLine(GetValid(V88)); } }
public static PKM convertToFormat(PKM pk, Type PKMType, out string comment) { if (pk == null || pk.Species == 0) { comment = "Null input. Aborting."; return(null); } Type fromType = pk.GetType(); int fromFormat = int.Parse(fromType.Name.Last().ToString()); int toFormat = int.Parse(PKMType.Name.Last().ToString()); Console.WriteLine($"Trying to convert {fromType.Name} to {PKMType.Name}."); PKM pkm = null; if (fromType == PKMType) { comment = "No need to convert, current format matches requested format."; return(pk); } if (fromFormat <= toFormat || fromFormat == 2) { pkm = pk.Clone(); if (pkm.IsEgg) // force hatch { pkm.IsEgg = false; if (pkm.AO) { pkm.Met_Location = 318; // Battle Resort } else if (pkm.XY) { pkm.Met_Location = 38; // Route 7 } else if (pkm.Gen5) { pkm.Met_Location = 16; // Route 16 } else { pkm.Met_Location = 30001; // Pokétransfer } } switch (fromType.Name) { case nameof(PK1): if (toFormat == 2) { pkm = PKMType == typeof(PK2) ? ((PK1)pk).convertToPK2() : null; break; } if (toFormat == 7) { pkm = null; // pkm.convertPK1toPK7(); } break; case nameof(PK2): if (PKMType == typeof(PK1)) { if (pk.Species > 151) { comment = $"Cannot convert a {PKX.getSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}"; return(null); } pkm = ((PK2)pk).convertToPK1(); } else { pkm = null; } break; case nameof(CK3): case nameof(XK3): // interconverting C/XD needs to visit main series format // ends up stripping purification/shadow etc stats pkm = pkm.convertToPK3(); goto case nameof(PK3); // fall through case nameof(PK3): if (toFormat == 3) // Gen3 Inter-trading { switch (PKMType.Name) { case nameof(CK3): pkm = pkm.convertToCK3(); break; case nameof(XK3): pkm = pkm.convertToXK3(); break; case nameof(PK3): pkm = pkm.convertToPK3(); break; // already converted, instantly returns default: throw new FormatException(); } break; } if (fromType.Name != nameof(PK3)) { pkm = pkm.convertToPK3(); } pkm = ((PK3)pkm).convertToPK4(); if (toFormat == 4) { break; } goto case nameof(PK4); case nameof(BK4): pkm = ((BK4)pkm).convertToPK4(); if (toFormat == 4) { break; } goto case nameof(PK4); case nameof(PK4): if (PKMType == typeof(BK4)) { pkm = ((PK4)pkm).convertToBK4(); break; } pkm = ((PK4)pkm).convertToPK5(); if (toFormat == 5) { break; } goto case nameof(PK5); case nameof(PK5): pkm = ((PK5)pkm).convertToPK6(); if (toFormat == 6) { break; } goto case nameof(PK6); case nameof(PK6): pkm = new PK7(pkm.Data, pkm.Identifier); if (toFormat == 7) { break; } goto case nameof(PK7); case nameof(PK7): break; } } comment = pkm == null ? $"Cannot convert a {fromType.Name} to a {PKMType.Name}." : $"Converted from {fromType.Name} to {PKMType.Name}."; return(pkm); }
public override PKM convertToPKM(SaveFile SAV) { if (!IsPokémon) { return(null); } int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1); int metLevel = MetLevel > 0 ? MetLevel : currentLevel; PK7 pk = new PK7 { Species = Species, HeldItem = HeldItem, TID = TID, SID = SID, Met_Level = metLevel, Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25), Gender = PersonalTable.AO[Species].Gender == 255 ? 2 : (Gender != 3 ? Gender : PersonalTable.AO[Species].RandomGender), AltForm = Form, EncryptionConstant = EncryptionConstant == 0 ? Util.rnd32() : EncryptionConstant, Version = OriginGame == 0 ? SAV.Game : OriginGame, Language = Language == 0 ? SAV.Language : Language, Ball = Ball, Country = SAV.Country, Region = SAV.SubRegion, ConsoleRegion = SAV.ConsoleRegion, Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4, RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2, RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4, Met_Location = MetLocation, Egg_Location = EggLocation, CNT_Cool = CNT_Cool, CNT_Beauty = CNT_Beauty, CNT_Cute = CNT_Cute, CNT_Smart = CNT_Smart, CNT_Tough = CNT_Tough, CNT_Sheen = CNT_Sheen, OT_Name = OT.Length > 0 ? OT : SAV.OT, OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender, HT_Name = OT.Length > 0 ? SAV.OT : "", HT_Gender = OT.Length > 0 ? SAV.Gender : 0, CurrentHandler = OT.Length > 0 ? 1 : 0, EXP = PKX.getEXP(currentLevel, Species), // Ribbons RibbonCountry = RibbonCountry, RibbonNational = RibbonNational, RibbonEarth = RibbonEarth, RibbonWorld = RibbonWorld, RibbonClassic = RibbonClassic, RibbonPremier = RibbonPremier, RibbonEvent = RibbonEvent, RibbonBirthday = RibbonBirthday, RibbonSpecial = RibbonSpecial, RibbonSouvenir = RibbonSouvenir, RibbonWishing = RibbonWishing, RibbonChampionBattle = RibbonChampionBattle, RibbonChampionRegional = RibbonChampionRegional, RibbonChampionNational = RibbonChampionNational, RibbonChampionWorld = RibbonChampionWorld, OT_Friendship = PersonalTable.AO[Species].BaseFriendship, OT_Intensity = OT_Intensity, OT_Memory = OT_Memory, OT_TextVar = OT_TextVar, OT_Feeling = OT_Feeling, FatefulEncounter = true, EVs = EVs, }; pk.Move1_PP = pk.getMovePP(Move1, 0); pk.Move2_PP = pk.getMovePP(Move2, 0); pk.Move3_PP = pk.getMovePP(Move3, 0); pk.Move4_PP = pk.getMovePP(Move4, 0); if (OTGender == 3) { pk.TID = SAV.TID; pk.SID = SAV.SID; } pk.MetDate = Date ?? DateTime.Now; pk.IsNicknamed = IsNicknamed; pk.Nickname = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language); // More 'complex' logic to determine final values // Dumb way to generate random IVs. int[] finalIVs = new int[6]; switch (IVs[0]) { case 0xFE: finalIVs[0] = 31; do // 31 HP IV, 2 other 31s { for (int i = 1; i < 6; i++) { finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i]; } } while (finalIVs.Count(r => r == 31) < 3); // 31 + 2*31 break; case 0xFD: do // 2 other 31s { for (int i = 0; i < 6; i++) { finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i]; } } while (finalIVs.Count(r => r == 31) < 2); // 2*31 break; default: // Random IVs for (int i = 0; i < 6; i++) { finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i]; } break; } pk.IVs = finalIVs; int av = 0; switch (AbilityType) { case 00: // 0 - 0 case 01: // 1 - 1 case 02: // 2 - H av = AbilityType; break; case 03: // 0/1 case 04: // 0/1/H av = (int)(Util.rnd32() % (AbilityType - 1)); break; } pk.Ability = PersonalTable.SM.getAbilities(Species, pk.AltForm)[av]; pk.AbilityNumber = 1 << av; switch (PIDType) { case 00: // Specified pk.PID = PID; break; case 01: // Random pk.PID = Util.rnd32(); break; case 02: // Random Shiny pk.PID = Util.rnd32(); pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)); break; case 03: // Random Nonshiny do { pk.PID = Util.rnd32(); } while ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)) < 16); break; } if (IsEgg) { pk.IsEgg = true; pk.EggMetDate = Date; } pk.RefreshChecksum(); return(pk); }
public override PKM convertToPKM(SaveFile SAV) { if (!IsPokémon) { return(null); } PK4 pk4 = new PK4(PK.Data); if (!IsHatched && Detail == 0) { pk4.OT_Name = SAV.OT; pk4.TID = SAV.TID; pk4.SID = SAV.SID; pk4.OT_Gender = SAV.Gender; } if (IsManaphyEgg) { // Since none of this data is populated, fill in default info. pk4.Species = 490; // Level 1 Moves pk4.Move1 = 294; pk4.Move2 = 145; pk4.Move3 = 346; pk4.FatefulEncounter = true; pk4.Ball = 4; pk4.Version = 10; // Diamond pk4.Language = 2; // English pk4.Nickname = "MANAPHY"; pk4.Egg_Location = 1; // Ranger (will be +3000 later) } // Generate IV uint seed = Util.rnd32(); if (pk4.PID == 1 || IsManaphyEgg) // Create Nonshiny { uint pid1 = PKX.LCRNG(ref seed) >> 16; uint pid2 = PKX.LCRNG(ref seed) >> 16; while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8) { uint testPID = pid1 | pid2 << 16; // Call the ARNG to change the PID testPID = testPID * 0x6c078965 + 1; pid1 = testPID & 0xFFFF; pid2 = testPID >> 16; } pk4.PID = pid1 | (pid2 << 16); } // Generate IVs if (pk4.IV32 == 0) { uint iv1 = PKX.LCRNG(ref seed) >> 16; uint iv2 = PKX.LCRNG(ref seed) >> 16; pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF; } // Generate Met Info if (IsPokémon) { pk4.Met_Location = pk4.Egg_Location + 3000; pk4.Egg_Location = 0; pk4.MetDate = DateTime.Now; pk4.IsEgg = false; } else { pk4.Egg_Location = pk4.Egg_Location + 3000; pk4.MetDate = DateTime.Now; pk4.IsEgg = false; // Met Location is modified when transferred to pk5; don't worry about it. } if (pk4.Species == 201) // Never will be true; Unown was never distributed. { pk4.AltForm = PKX.getUnownForm(pk4.PID); } if (IsEgg || IsManaphyEgg) { pk4.IsEgg = true; } pk4.RefreshChecksum(); return(pk4); }
public override string getBoxName(int box) { return(PKX.getG1Str(Data.Skip(BoxNamesOffset + box * 9).Take(9).ToArray(), Japanese)); }
protected override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray(data);
public EntreeForest(byte[] data) { Data = data; PKX.CryptArray(data, EncryptionSeed, 0, EncryptionSeedOffset); }