public override PKM convertToPKM(SaveFile SAV) { if (!IsPokémon) { return(null); } int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1); PK6 pk = new PK6 { Species = Species, HeldItem = HeldItem, TID = TID, SID = SID, Met_Level = currentLevel, 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(Level, 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); pk.MetDate = Date ?? DateTime.Now; if (SAV.Generation > 6) // Gen7 { pk.Version = (int)GameVersion.OR; } if (pk.CurrentHandler == 0) // OT { pk.OT_Memory = 3; pk.OT_TextVar = 9; pk.OT_Intensity = 1; pk.OT_Feeling = Util.rand.Next(0, 9); } else { pk.HT_Memory = 3; pk.HT_TextVar = 9; pk.HT_Intensity = 1; pk.HT_Feeling = Util.rand.Next(0, 9); pk.HT_Friendship = pk.OT_Friendship; } 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.AO.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 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 PK6 convertToPK6() { PK6 pk6 = new PK6 // Convert away! { EncryptionConstant = PID, Species = Species, TID = TID, SID = SID, EXP = EXP, PID = PID, Ability = Ability }; int[] abilities = PersonalInfo.Abilities; int abilval = Array.IndexOf(abilities, Ability); if (abilval >= 0 && abilities[abilval] == abilities[2] && HiddenAbility) { abilval = 2; // hidden ability shared with a regular ability } if (abilval >= 0) { pk6.AbilityNumber = 1 << abilval; } else // Fallback (shouldn't happen) { if (HiddenAbility) { pk6.AbilityNumber = 4; // Hidden, else G5 or G3/4 correlation. } else { pk6.AbilityNumber = Gen5 ? 1 << (int)(PID >> 16 & 1) : 1 << (int)(PID & 1); } } pk6.Markings = Markings; pk6.Language = Language; pk6.CNT_Cool = CNT_Cool; pk6.CNT_Beauty = CNT_Beauty; pk6.CNT_Cute = CNT_Cute; pk6.CNT_Smart = CNT_Smart; pk6.CNT_Tough = CNT_Tough; // Cap EVs pk6.EV_HP = EV_HP > 252 ? 252 : EV_HP; pk6.EV_ATK = EV_ATK > 252 ? 252 : EV_ATK; pk6.EV_DEF = EV_DEF > 252 ? 252 : EV_DEF; pk6.EV_SPA = EV_SPA > 252 ? 252 : EV_SPA; pk6.EV_SPD = EV_SPD > 252 ? 252 : EV_SPD; pk6.EV_SPE = EV_SPE > 252 ? 252 : EV_SPE; pk6.Move1 = Move1; pk6.Move2 = Move2; pk6.Move3 = Move3; pk6.Move4 = Move4; pk6.Move1_PPUps = Move1_PPUps; pk6.Move2_PPUps = Move2_PPUps; pk6.Move3_PPUps = Move3_PPUps; pk6.Move4_PPUps = Move4_PPUps; // Fix PP pk6.Move1_PP = pk6.getMovePP(pk6.Move1, pk6.Move1_PPUps); pk6.Move2_PP = pk6.getMovePP(pk6.Move2, pk6.Move2_PPUps); pk6.Move3_PP = pk6.getMovePP(pk6.Move3, pk6.Move3_PPUps); pk6.Move4_PP = pk6.getMovePP(pk6.Move4, pk6.Move4_PPUps); pk6.IV_HP = IV_HP; pk6.IV_ATK = IV_ATK; pk6.IV_DEF = IV_DEF; pk6.IV_SPA = IV_SPA; pk6.IV_SPD = IV_SPD; pk6.IV_SPE = IV_SPE; pk6.IsEgg = IsEgg; pk6.IsNicknamed = IsNicknamed; pk6.FatefulEncounter = FatefulEncounter; pk6.Gender = Gender; pk6.AltForm = AltForm; pk6.Nature = Nature; pk6.Nickname = Nickname.Length > 1 && !IsNicknamed ? Nickname[0] + Nickname.Substring(1).ToLower() // Decapitalize : Nickname; pk6.Version = Version; pk6.OT_Name = OT_Name; // Dates are kept upon transfer pk6.MetDate = MetDate; pk6.EggMetDate = EggMetDate; // Locations are kept upon transfer pk6.Met_Location = Met_Location; pk6.Egg_Location = Egg_Location; pk6.PKRS_Strain = PKRS_Strain; pk6.PKRS_Days = PKRS_Days; pk6.Ball = Ball; // OT Gender & Encounter Level pk6.Met_Level = Met_Level; pk6.OT_Gender = OT_Gender; pk6.EncounterType = EncounterType; // Ribbon Decomposer (Contest & Battle) byte contestribbons = 0; byte battleribbons = 0; // Contest Ribbon Counter for (int i = 0; i < 8; i++) // Sinnoh 3, Hoenn 1 { if ((Data[0x60] >> i & 1) == 1) { contestribbons++; } if (((Data[0x61] >> i) & 1) == 1) { contestribbons++; } if (((Data[0x3C] >> i) & 1) == 1) { contestribbons++; } if (((Data[0x3D] >> i) & 1) == 1) { contestribbons++; } } for (int i = 0; i < 4; i++) // Sinnoh 4, Hoenn 2 { if (((Data[0x62] >> i) & 1) == 1) { contestribbons++; } if (((Data[0x3E] >> i) & 1) == 1) { contestribbons++; } } // Battle Ribbon Counter // Winning Ribbon if ((Data[0x3E] & 0x20) >> 5 == 1) { battleribbons++; } // Victory Ribbon if ((Data[0x3E] & 0x40) >> 6 == 1) { battleribbons++; } for (int i = 1; i < 7; i++) // Sinnoh Battle Ribbons { if (((Data[0x24] >> i) & 1) == 1) { battleribbons++; } } // Fill the Ribbon Counter Bytes pk6.RibbonCountMemoryContest = contestribbons; pk6.RibbonCountMemoryBattle = battleribbons; // Copy Ribbons to their new locations. int bx30 = 0; // bx30 |= 0; // Kalos Champ - New Kalos Ribbon bx30 |= ((Data[0x3E] & 0x10) >> 4) << 1; // Hoenn Champion bx30 |= ((Data[0x24] & 0x01) >> 0) << 2; // Sinnoh Champ // bx30 |= 0; // Best Friend - New Kalos Ribbon // bx30 |= 0; // Training - New Kalos Ribbon // bx30 |= 0; // Skillful - New Kalos Ribbon // bx30 |= 0; // Expert - New Kalos Ribbon bx30 |= ((Data[0x3F] & 0x01) >> 0) << 7; // Effort Ribbon pk6.Data[0x30] = (byte)bx30; int bx31 = 0; bx31 |= ((Data[0x24] & 0x80) >> 7) << 0; // Alert bx31 |= ((Data[0x25] & 0x01) >> 0) << 1; // Shock bx31 |= ((Data[0x25] & 0x02) >> 1) << 2; // Downcast bx31 |= ((Data[0x25] & 0x04) >> 2) << 3; // Careless bx31 |= ((Data[0x25] & 0x08) >> 3) << 4; // Relax bx31 |= ((Data[0x25] & 0x10) >> 4) << 5; // Snooze bx31 |= ((Data[0x25] & 0x20) >> 5) << 6; // Smile bx31 |= ((Data[0x25] & 0x40) >> 6) << 7; // Gorgeous pk6.Data[0x31] = (byte)bx31; int bx32 = 0; bx32 |= ((Data[0x25] & 0x80) >> 7) << 0; // Royal bx32 |= ((Data[0x26] & 0x01) >> 0) << 1; // Gorgeous Royal bx32 |= ((Data[0x3E] & 0x80) >> 7) << 2; // Artist bx32 |= ((Data[0x26] & 0x02) >> 1) << 3; // Footprint bx32 |= ((Data[0x26] & 0x04) >> 2) << 4; // Record bx32 |= ((Data[0x26] & 0x10) >> 4) << 5; // Legend bx32 |= ((Data[0x3F] & 0x10) >> 4) << 6; // Country bx32 |= ((Data[0x3F] & 0x20) >> 5) << 7; // National pk6.Data[0x32] = (byte)bx32; int bx33 = 0; bx33 |= ((Data[0x3F] & 0x40) >> 6) << 0; // Earth bx33 |= ((Data[0x3F] & 0x80) >> 7) << 1; // World bx33 |= ((Data[0x27] & 0x04) >> 2) << 2; // Classic bx33 |= ((Data[0x27] & 0x08) >> 3) << 3; // Premier bx33 |= ((Data[0x26] & 0x08) >> 3) << 4; // Event bx33 |= ((Data[0x26] & 0x40) >> 6) << 5; // Birthday bx33 |= ((Data[0x26] & 0x80) >> 7) << 6; // Special bx33 |= ((Data[0x27] & 0x01) >> 0) << 7; // Souvenir pk6.Data[0x33] = (byte)bx33; int bx34 = 0; bx34 |= ((Data[0x27] & 0x02) >> 1) << 0; // Wishing Ribbon bx34 |= ((Data[0x3F] & 0x02) >> 1) << 1; // Battle Champion bx34 |= ((Data[0x3F] & 0x04) >> 2) << 2; // Regional Champion bx34 |= ((Data[0x3F] & 0x08) >> 3) << 3; // National Champion bx34 |= ((Data[0x26] & 0x20) >> 5) << 4; // World Champion pk6.Data[0x34] = (byte)bx34; // Write Transfer Location - location is dependent on 3DS system that transfers. pk6.Country = PKMConverter.Country; pk6.Region = PKMConverter.Region; pk6.ConsoleRegion = PKMConverter.ConsoleRegion; // Write the Memories, Friendship, and Origin! pk6.CurrentHandler = 1; pk6.HT_Name = PKMConverter.OT_Name; pk6.HT_Gender = PKMConverter.OT_Gender; pk6.Geo1_Region = PKMConverter.Region; pk6.Geo1_Country = PKMConverter.Country; pk6.HT_Intensity = 1; pk6.HT_Memory = 4; pk6.HT_Feeling = (int)(Util.rnd32() % 10); // When transferred, friendship gets reset. pk6.OT_Friendship = pk6.HT_Friendship = PersonalInfo.BaseFriendship; // Antishiny Mechanism ushort LID = (ushort)(PID & 0xFFFF); ushort HID = (ushort)(PID >> 0x10); int XOR = TID ^ SID ^ LID ^ HID; if (XOR >= 8 && XOR < 16) // If we get an illegal collision... { pk6.PID ^= 0x80000000; } // HMs are not deleted 5->6, transfer away (but fix if blank spots?) pk6.FixMoves(); // Decapitalize if (!pk6.IsNicknamed && pk6.Nickname.Length > 1) { pk6.Nickname = char.ToUpper(pk6.Nickname[0]) + pk6.Nickname.Substring(1).ToLower(); } // Fix Name Strings pk6.Nickname = pk6.Nickname .Replace('\u2467', '\u00d7') // × .Replace('\u2468', '\u00f7') // ÷ .Replace('\u246c', '\u2026') // … .Replace('\u246d', '\uE08E') // ♂ .Replace('\u246e', '\uE08F') // ♀ .Replace('\u246f', '\uE090') // ♠ .Replace('\u2470', '\uE091') // ♣ .Replace('\u2471', '\uE092') // ♥ .Replace('\u2472', '\uE093') // ♦ .Replace('\u2473', '\uE094') // ★ .Replace('\u2474', '\uE095') // ◎ .Replace('\u2475', '\uE096') // ○ .Replace('\u2476', '\uE097') // □ .Replace('\u2477', '\uE098') // △ .Replace('\u2478', '\uE099') // ◇ .Replace('\u2479', '\uE09A') // ♪ .Replace('\u247a', '\uE09B') // ☀ .Replace('\u247b', '\uE09C') // ☁ .Replace('\u247d', '\uE09D') // ☂ ; pk6.OT_Name = pk6.OT_Name .Replace('\u2467', '\u00d7') // × .Replace('\u2468', '\u00f7') // ÷ .Replace('\u246c', '\u2026') // … .Replace('\u246d', '\uE08E') // ♂ .Replace('\u246e', '\uE08F') // ♀ .Replace('\u246f', '\uE090') // ♠ .Replace('\u2470', '\uE091') // ♣ .Replace('\u2471', '\uE092') // ♥ .Replace('\u2472', '\uE093') // ♦ .Replace('\u2473', '\uE094') // ★ .Replace('\u2474', '\uE095') // ◎ .Replace('\u2475', '\uE096') // ○ .Replace('\u2476', '\uE097') // □ .Replace('\u2477', '\uE098') // △ .Replace('\u2478', '\uE099') // ◇ .Replace('\u2479', '\uE09A') // ♪ .Replace('\u247a', '\uE09B') // ☀ .Replace('\u247b', '\uE09C') // ☁ .Replace('\u247d', '\uE09D') // ☂ ; // Fix Checksum pk6.RefreshChecksum(); return(pk6); // Done! }