Exemple #1
0
 public static Bitmap getWallpaper(SaveFile SAV, int index)
 {
     index++;
     string s = "box_wp" + index.ToString("00");
     switch (SAV.Generation)
     {
         case 6: s += SAV.ORAS && index > 16 ? "ao" : "xy";
             break;
         case 5: s += SAV.B2W2 && index > 16 ? "b2w2" : "bw";
             break;
         case 4:
             if (SAV.Pt && index > 16)
                 s += "pt";
             else if (SAV.HGSS && index > 16)
                 s += "hgss";
             else
                 s += "dp";
             break;
         case 3:
             if (SAV.E)
                 s += "e";
             else if (SAV.FRLG && index > 12)
                 s += "frlg";
             else
                 s += "rs";
             break;
     }
     return (Bitmap)(Properties.Resources.ResourceManager.GetObject(s) ?? Properties.Resources.box_wp16xy);
 }
Exemple #2
0
        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,
            };
            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 (Date.HasValue)
            {
                pk.MetDate = Date.Value;
            }
            else
            {
                // No datetime set, typical for wc6full
                // Set it to now, instead of zeroing it out.
                pk.MetDate = DateTime.Now;
            }

            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;
        }
Exemple #3
0
 public override PKM convertToPKM(SaveFile SAV)
 {
     return Gift.convertToPKM(SAV);
 }
Exemple #4
0
        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 abstract PKM convertToPKM(SaveFile SAV);
Exemple #6
0
        private void openSAV(SaveFile sav, string path)
        {
            if (sav == null || sav.Version == GameVersion.Invalid)
            { Util.Error("Invalid save file loaded. Aborting.", path); return; }

            // Finish setting up the save file.
            if (sav.IndeterminateGame && sav.Generation == 3)
            {
                // Hacky cheats invalidated the Game Code value.
                var drGame = Util.Prompt(MessageBoxButtons.YesNoCancel,
                    "Unknown Gen3 Game Detected. Select Origins:",
                    "Yes: Ruby / Sapphire" + Environment.NewLine +
                    "No: Emerald" + Environment.NewLine +
                    "Cancel: FireRed / LeafGreen");

                switch (drGame) // Reset save file info
                {
                    case DialogResult.Yes: sav = new SAV3(sav.BAK, GameVersion.RS); break;
                    case DialogResult.No: sav = new SAV3(sav.BAK, GameVersion.E); break;
                    case DialogResult.Cancel: sav = new SAV3(sav.BAK, GameVersion.FRLG); break;
                    default: return;
                }
            }
            if (sav.IndeterminateLanguage)
            {
                // Japanese Save files are different. Get isJapanese
                var drJP = Util.Prompt(MessageBoxButtons.YesNoCancel, $"{sav.Version} Save File detected. Select language...",
                    "Yes: International" + Environment.NewLine + "No: Japanese");
                if (drJP == DialogResult.Cancel)
                    return;

                sav.Japanese = drJP == DialogResult.No;
            }
            if (sav.IndeterminateSubVersion && sav.Version == GameVersion.FRLG)
            {
                var drFRLG = Util.Prompt(MessageBoxButtons.YesNoCancel, $"{sav.Version} detected. Select version...",
                    "Yes: FireRed" + Environment.NewLine + "No: LeafGreen");
                if (drFRLG == DialogResult.Cancel)
                    return;

                sav.Personal = drFRLG == DialogResult.Yes ? PersonalTable.FR : PersonalTable.LG;
            }

            // clean fields
            PKM pk = preparePKM();
            populateFields(SAV.BlankPKM);
            SAV = sav;

            if (path != null) // Actual save file
            {
                SAV.FilePath = Path.GetDirectoryName(path);
                SAV.FileName = Path.GetExtension(path) == ".bak"
                    ? Path.GetFileName(path).Split(new[] { " [" }, StringSplitOptions.None)[0]
                    : Path.GetFileName(path);
                Text = $"PKH{(HaX ? "a" : "e")}X - " + $"SAV{SAV.Generation}: {Path.GetFileNameWithoutExtension(Util.CleanFileName(SAV.BAKName))}"; // more descriptive

                // If backup folder exists, save a backup.
                string backupName = Path.Combine(BackupPath, Util.CleanFileName(SAV.BAKName));
                if (SAV.Exportable && Directory.Exists(BackupPath) && !File.Exists(backupName))
                    File.WriteAllBytes(backupName, SAV.BAK);

                GB_SAVtools.Visible = true;
            }
            else // Blank save file
            {
                SAV.FilePath = null;
                SAV.FileName = "Blank Save File";
                Text = $"PKH{(HaX ? "a" : "e")}X - " + $"SAV{SAV.Generation}: {SAV.FileName} [{SAV.OT} ({SAV.Version})]";

                GB_SAVtools.Visible = false;
            }
            Menu_ExportSAV.Enabled = B_VerifyCHK.Enabled = SAV.Exportable;

            // Close subforms that are save dependent
            Type[] f = { typeof(SAV_BoxViewer), typeof(f2_Text) };
            foreach (var form in Application.OpenForms.Cast<Form>().Where(form => f.Contains(form.GetType())).ToArray())
                form.Close();

            setBoxNames();   // Display the Box Names
            if (SAV.HasBox)
            {
                int startBox = path == null ? 0 : SAV.CurrentBox; // FF if BattleBox
                if (startBox > SAV.BoxCount - 1) { tabBoxMulti.SelectedIndex = 1; CB_BoxSelect.SelectedIndex = 0; }
                else { tabBoxMulti.SelectedIndex = 0; CB_BoxSelect.SelectedIndex = startBox; }
            }
            setPKXBoxes();   // Reload all of the PKX Windows

            bool WindowTranslationRequired = false;

            // Hide content if not present in game.
            GB_SUBE.Visible = SAV.HasSUBE;
            PB_Locked.Visible = SAV.HasBattleBox && SAV.BattleBoxLocked;

            if (!SAV.HasBox && tabBoxMulti.TabPages.Contains(Tab_Box))
                tabBoxMulti.TabPages.Remove(Tab_Box);
            else if (SAV.HasBox && !tabBoxMulti.TabPages.Contains(Tab_Box))
            {
                tabBoxMulti.TabPages.Insert(0, Tab_Box);
                WindowTranslationRequired = true;
            }
            Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_Report.Enabled = Menu_Modify.Enabled = B_SaveBoxBin.Enabled = SAV.HasBox;

            int BoxTab = tabBoxMulti.TabPages.IndexOf(Tab_Box);
            int PartyTab = tabBoxMulti.TabPages.IndexOf(Tab_PartyBattle);

            if (!SAV.HasParty && tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
                tabBoxMulti.TabPages.Remove(Tab_PartyBattle);
            else if (SAV.HasParty && !tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
            {
                int index = BoxTab;
                if (index < 0)
                    index = -1;
                tabBoxMulti.TabPages.Insert(index + 1, Tab_PartyBattle);
                WindowTranslationRequired = true;
            }

            if (!SAV.HasDaycare && tabBoxMulti.TabPages.Contains(Tab_Other))
                tabBoxMulti.TabPages.Remove(Tab_Other);
            else if (SAV.HasDaycare && !tabBoxMulti.TabPages.Contains(Tab_Other))
            {
                int index = PartyTab;
                if (index < 0)
                    index = BoxTab;
                if (index < 0)
                    index = -1;
                tabBoxMulti.TabPages.Insert(index + 1, Tab_Other);
                WindowTranslationRequired = true;
            }

            if (path != null) // Actual save file
            {
                PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = SAV.HasBattleBox;
                GB_Daycare.Visible = SAV.HasDaycare;
                GB_Fused.Visible = SAV.HasFused;
                GB_GTS.Visible = SAV.HasGTS;
                B_OpenSecretBase.Enabled = SAV.HasSecretBase;
                B_OpenPokepuffs.Enabled = SAV.HasPuff;
                B_OUTPasserby.Enabled = SAV.HasPSS;
                B_OpenBoxLayout.Enabled = SAV.HasBoxWallpapers;
                B_OpenWondercards.Enabled = SAV.HasWondercards;
                B_OpenSuperTraining.Enabled = SAV.HasSuperTrain;
                B_OpenHallofFame.Enabled = SAV.HasHoF;
                B_OpenOPowers.Enabled = SAV.HasOPower;
                B_OpenPokedex.Enabled = SAV.HasPokeDex;
                B_OpenBerryField.Enabled = SAV.HasBerryField && SAV.XY;
                B_OpenPokeblocks.Enabled = SAV.HasPokeBlock;
                B_JPEG.Enabled = SAV.HasJPEG;
                B_OpenEventFlags.Enabled = SAV.HasEvents;
                B_OpenLinkInfo.Enabled = SAV.HasLink;
                B_CGearSkin.Enabled = SAV.Generation == 5;

                B_OpenTrainerInfo.Visible = B_OpenItemPouch.Visible = SAV.HasParty; // Box RS
            }
            GB_SAVtools.Visible = FLP_SAVtools.Controls.Cast<Control>().Any(c => c.Enabled);
            foreach (Control c in FLP_SAVtools.Controls.Cast<Control>())
                c.Visible = c.Enabled;

            // Generational Interface
            byte[] extraBytes = new byte[1];
            Tip1.RemoveAll(); Tip2.RemoveAll(); Tip3.RemoveAll(); // TSV/PSV

            FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = SAV.Generation >= 6;
            Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = SAV.Generation >= 6;
            GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_Medals.Visible = BTN_History.Visible = SAV.Generation >= 6;
            PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = SAV.Generation >= 6;

            PB_MarkPentagon.Visible = SAV.Generation >= 6;
            PB_MarkAlola.Visible = SAV.Generation >= 7;
            TB_Secure1.Visible = TB_Secure2.Visible = L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = SAV.Exportable && SAV.Generation >= 6;
            TB_GameSync.Visible = SAV.Exportable && SAV.Generation == 6;

            FLP_NSparkle.Visible = L_NSparkle.Visible = CHK_NSparkle.Visible = SAV.Generation == 5;

            CB_Form.Visible = Label_Form.Visible = CHK_AsEgg.Visible = GB_EggConditions.Visible = PB_Mark5.Visible = PB_Mark6.Visible = SAV.Generation >= 4;

            DEV_Ability.Enabled = DEV_Ability.Visible = SAV.Generation > 3 && HaX;
            CB_Ability.Visible = !DEV_Ability.Enabled && SAV.Generation >= 3;
            FLP_Nature.Visible = SAV.Generation >= 3;
            FLP_Ability.Visible = SAV.Generation >= 3;
            FLP_Language.Visible = SAV.Generation >= 3;
            GB_ExtraBytes.Visible = GB_ExtraBytes.Enabled = SAV.Generation >= 3;
            GB_Markings.Visible = SAV.Generation >= 3;
            BTN_Ribbons.Visible = SAV.Generation >= 3;
            CB_HPType.Enabled = CB_Form.Enabled = SAV.Generation >= 3;
            BTN_RerollPID.Visible = Label_PID.Visible = TB_PID.Visible = Label_SID.Visible = TB_SID.Visible = SAV.Generation >= 3;

            FLP_FriendshipForm.Visible = SAV.Generation >= 2;
            FLP_HeldItem.Visible = SAV.Generation >= 2;
            CHK_IsEgg.Visible = Label_Gender.Visible = SAV.Generation >= 2;
            FLP_PKRS.Visible = FLP_EggPKRSRight.Visible = SAV.Generation >= 2;
            Label_OTGender.Visible = SAV.Generation >= 2;

            if (SAV.Generation == 1)
                Label_IsShiny.Visible = false;

            if (SAV.Version == GameVersion.BATREV)
            {
                L_SaveSlot.Visible = CB_SaveSlot.Visible = true;
                CB_SaveSlot.Items.Clear();
                CB_SaveSlot.DisplayMember = "Text"; CB_SaveSlot.ValueMember = "Value";
                CB_SaveSlot.DataSource = new BindingSource(((SAV4BR) SAV).SaveSlots.Select(i => new ComboItem
                {
                    Text = ((SAV4BR) SAV).SaveNames[i],
                    Value = i
                }).ToList(), null);
                CB_SaveSlot.SelectedValue = ((SAV4BR)SAV).CurrentSlot;
            }
            else
                L_SaveSlot.Visible = CB_SaveSlot.Visible = false;

            FLP_Purification.Visible = FLP_ShadowID.Visible = SAV.Version == GameVersion.COLO || SAV.Version == GameVersion.XD;
            NUD_ShadowID.Maximum = SAV.MaxShadowID;

            // HaX override, needs to be after DEV_Ability enabled assignment.
            TB_AbilityNumber.Visible = SAV.Generation >= 6 && DEV_Ability.Enabled;

            // Met Tab
            FLP_MetDate.Visible = SAV.Generation >= 4;
            FLP_Fateful.Visible = FLP_Ball.Visible = FLP_OriginGame.Visible = SAV.Generation >= 3;
            FLP_MetLocation.Visible = FLP_MetLevel.Visible = SAV.Generation >= 2;
            FLP_TimeOfDay.Visible = SAV.Generation == 2;

            // Stats
            FLP_StatsTotal.Visible = SAV.Generation >= 3;
            FLP_Characteristic.Visible = SAV.Generation >= 3;
            FLP_HPType.Visible = SAV.Generation >= 2;

            PAN_Contest.Visible = SAV.Generation >= 3;

            // Second daycare slot
            SlotPictureBoxes[43].Visible = SAV.Generation >= 2;

            if (sav.Generation == 1)
            {
                FLP_SpD.Visible = false;
                Label_SPA.Visible = false;
                Label_SPC.Visible = true;
                TB_HPIV.Enabled = false;
                MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV };
                foreach (var ctrl in evControls)
                {
                    ctrl.Mask = "00000";
                    ctrl.Size = Stat_HP.Size;
                }
            }
            else if (sav.Generation == 2)
            {
                FLP_SpD.Visible = true;
                Label_SPA.Visible = true;
                Label_SPC.Visible = false;
                TB_SPDEV.Enabled = TB_SPDIV.Enabled = false;
                TB_HPIV.Enabled = false;
                MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV };
                foreach (var ctrl in evControls)
                {
                    ctrl.Mask = "00000";
                    ctrl.Size = Stat_HP.Size;
                }
            }
            else
            {
                FLP_SpD.Visible = true;
                Label_SPA.Visible = true;
                Label_SPC.Visible = false;
                TB_SPDEV.Enabled = TB_SPDIV.Enabled = true;
                TB_HPIV.Enabled = true;
                MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV };
                foreach (var ctrl in evControls)
                {
                    ctrl.Mask = "000";
                    ctrl.Size = TB_ExtraByte.Size;
                }
            }

            // Recenter PKM SubEditors
            FLP_PKMEditors.Location = new Point((Tab_OTMisc.Width - FLP_PKMEditors.Width) / 2, FLP_PKMEditors.Location.Y);

            switch (SAV.Generation)
            {
                case 1:
                    getFieldsfromPKM = populateFieldsPK1;
                    getPKMfromFields = preparePK1;
                    extraBytes = new byte[] {};
                    break;
                case 2:
                    getFieldsfromPKM = populateFieldsPK2;
                    getPKMfromFields = preparePK2;
                    extraBytes = new byte[] { };
                    break;
                case 3:
                    if (SAV.Version == GameVersion.COLO)
                    {
                        getFieldsfromPKM = populateFieldsCK3;
                        getPKMfromFields = prepareCK3;
                        extraBytes = CK3.ExtraBytes;
                        break;
                    }
                    if (SAV.Version == GameVersion.XD)
                    {
                        getFieldsfromPKM = populateFieldsXK3;
                        getPKMfromFields = prepareXK3;
                        extraBytes = XK3.ExtraBytes;
                        break;
                    }
                    getFieldsfromPKM = populateFieldsPK3;
                    getPKMfromFields = preparePK3;
                    extraBytes = PK3.ExtraBytes;
                    break;
                case 4:
                    if (SAV.Version == GameVersion.BATREV)
                    {
                        getFieldsfromPKM = populateFieldsBK4;
                        getPKMfromFields = prepareBK4;
                    }
                    else
                    {
                        getFieldsfromPKM = populateFieldsPK4;
                        getPKMfromFields = preparePK4;
                    }
                    extraBytes = PK4.ExtraBytes;
                    break;
                case 5:
                    getFieldsfromPKM = populateFieldsPK5;
                    getPKMfromFields = preparePK5;
                    extraBytes = PK5.ExtraBytes;
                    break;
                case 6:
                    getFieldsfromPKM = populateFieldsPK6;
                    getPKMfromFields = preparePK6;
                    extraBytes = PK6.ExtraBytes;
                    TB_GameSync.Enabled = (SAV.GameSyncID ?? 0) != 0;
                    TB_GameSync.Text = SAV.GameSyncID?.ToString("X16");
                    TB_Secure1.Text = SAV.Secure1?.ToString("X16");
                    TB_Secure2.Text = SAV.Secure2?.ToString("X16");
                    break;
                case 7:
                    getFieldsfromPKM = populateFieldsPK7;
                    getPKMfromFields = preparePK7;
                    extraBytes = PK7.ExtraBytes;
                    TB_GameSync.Enabled = (SAV.GameSyncID ?? 0) != 0;
                    TB_GameSync.Text = SAV.GameSyncID?.ToString("X16");
                    TB_Secure1.Text = SAV.Secure1?.ToString("X16");
                    TB_Secure2.Text = SAV.Secure2?.ToString("X16");
                    break;
            }
            bool init = fieldsInitialized;
            fieldsInitialized = fieldsLoaded = false;
            pkm = pkm.GetType() != SAV.PKMType ? SAV.BlankPKM : pk;
            if (pkm.Format < 3)
                pkm = SAV.BlankPKM;
            populateFilteredDataSources();
            populateFields(pkm);
            fieldsInitialized |= init;

            // SAV Specific Limits
            TB_OT.MaxLength = SAV.OTLength;
            TB_OTt2.MaxLength = SAV.OTLength;
            TB_Nickname.MaxLength = SAV.NickLength;

            // Hide Unused Tabs
            if (SAV.Generation == 1 && tabMain.TabPages.Contains(Tab_Met))
                tabMain.TabPages.Remove(Tab_Met);
            else if (SAV.Generation != 1 && !tabMain.TabPages.Contains(Tab_Met))
            {
                tabMain.TabPages.Insert(1, Tab_Met);
                WindowTranslationRequired = true;
            }

            // Common HaX Interface
            CHK_HackedStats.Enabled = CHK_HackedStats.Visible = MT_Level.Enabled = MT_Level.Visible = MT_Form.Enabled = MT_Form.Visible = HaX;
            TB_Level.Visible = !HaX;

            // Load Extra Byte List
            if (GB_ExtraBytes.Enabled)
            {
                CB_ExtraBytes.Items.Clear();
                foreach (byte b in extraBytes)
                    CB_ExtraBytes.Items.Add("0x" + b.ToString("X2"));
                CB_ExtraBytes.SelectedIndex = 0;
            }

            // pk2 save files do not have an Origin Game stored. Prompt the met location list to update.
            if (SAV.Generation == 2)
                updateOriginGame(null, null);

            // Refresh PK* conversion info
            PKMConverter.updateConfig(SAV.SubRegion, SAV.Country, SAV.ConsoleRegion, SAV.OT, SAV.Gender);

            if (WindowTranslationRequired) // force update -- re-added controls may be untranslated
                Util.TranslateInterface(this, curlanguage);

            // No changes made yet
            UndoStack.Clear(); Menu_Undo.Enabled = false;
            RedoStack.Clear(); Menu_Redo.Enabled = false;

            // Indicate audibly the save is loaded
            SystemSounds.Beep.Play();
        }
Exemple #7
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            DateTime dt = DateTime.Now;

            if (Day == 0)
            {
                Day   = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year  = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk           = new PK5
            {
                Species      = Species,
                HeldItem     = HeldItem,
                Met_Level    = currentLevel,
                Nature       = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender       = PersonalTable.B2W2[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PersonalTable.B2W2[Species].RandomGender),
                AltForm      = Form,
                Version      = OriginGame == 0 ? new[] { 20, 21, 22, 23 }[Util.rnd32() & 0x3] : OriginGame,
                Language     = Language == 0 ? SAV.Language : Language,
                Ball         = Ball,
                Move1        = Move1,
                Move2        = Move2,
                Move3        = Move3,
                Move4        = Move4,
                Met_Location = MetLocation,
                MetDate      = Date,
                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,

                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.B2W2[Species].BaseFriendship,
                FatefulEncounter = true,
            };

            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) // User's
            {
                pk.TID       = SAV.TID;
                pk.SID       = SAV.SID;
                pk.OT_Name   = SAV.OT;
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID       = IsEgg ? SAV.TID : TID;
                pk.SID       = IsEgg ? SAV.SID : SID;
                pk.OT_Name   = OT.Length > 0 ? OT : SAV.OT;
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            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];
            for (int i = 0; i < IVs.Length; i++)
            {
                finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            }
            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.HiddenAbility = av == 2;
            pk.Ability       = PersonalTable.B2W2.getAbilities(Species, pk.AltForm)[av];

            if (PID != 0)
            {
                pk.PID = PID;
            }
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0)
                {
                    pk.PID &= 0xFFFEFFFF;
                }
                else
                {
                    pk.PID |= 0x10000;
                }
                // Force Gender
                do
                {
                    pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF;
                } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0)
                    {
                        pk.PID &= 0xFFFEFFFE;
                    }
                    else
                    {
                        pk.PID |= 0x10001;
                    }
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                    {
                        pk.PID ^= 0x80000000;
                    }
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.EggMetDate = Date;
                // Force hatch
                pk.IsEgg        = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return(pk);
        }
Exemple #8
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
                return null;

            DateTime dt = DateTime.Now;
            if (Day == 0)
            {
                Day = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk = new PK5
            {
                Species = Species,
                HeldItem = HeldItem,
                Met_Level = currentLevel,
                Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender = PersonalTable.B2W2[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PersonalTable.B2W2[Species].RandomGender),
                AltForm = Form,
                Version = OriginGame == 0 ? new[] {20, 21, 22, 23}[Util.rnd32() & 0x3] : OriginGame,
                Language = Language == 0 ? SAV.Language : Language,
                Ball = Ball,
                Move1 = Move1,
                Move2 = Move2,
                Move3 = Move3,
                Move4 = Move4,
                Met_Location = MetLocation,
                MetDate = Date,
                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,

                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.B2W2[Species].BaseFriendship,
                FatefulEncounter = true,
            };
            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) // User's
            {
                pk.TID = SAV.TID;
                pk.SID = SAV.SID;
                pk.OT_Name = SAV.OT;
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID = IsEgg ? SAV.TID : TID;
                pk.SID = IsEgg ? SAV.SID : SID;
                pk.OT_Name = OT.Length > 0 ? OT : SAV.OT;
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            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];
            for (int i = 0; i < IVs.Length; i++)
                finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            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.HiddenAbility = av == 2;
            pk.Ability = PersonalTable.B2W2.getAbilities(Species, pk.AltForm)[av];

            if (PID != 0)
                pk.PID = PID;
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0) pk.PID &= 0xFFFEFFFF; else pk.PID |= 0x10000;
                // Force Gender
                do { pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF; } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0) pk.PID &= 0xFFFEFFFE; else pk.PID |= 0x10001;
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                        pk.PID ^= 0x80000000;
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.EggMetDate = Date;
                // Force hatch
                pk.IsEgg = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return pk;
        }
Exemple #9
0
        private void diffSaves()
        {
            if (!File.Exists(TB_OldSAV.Text))
            {
                Util.Alert("Save 1 path invalid."); return;
            }
            if (!File.Exists(TB_NewSAV.Text))
            {
                Util.Alert("Save 2 path invalid."); return;
            }
            if (new FileInfo(TB_OldSAV.Text).Length > 0x100000)
            {
                Util.Alert("Save 1 file invalid."); return;
            }
            if (new FileInfo(TB_NewSAV.Text).Length > 0x100000)
            {
                Util.Alert("Save 2 file invalid."); return;
            }

            SaveFile s1 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_OldSAV.Text));
            SaveFile s2 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_NewSAV.Text));

            if (s1.GetType() != s2.GetType())
            {
                Util.Alert("Save types are different.", $"S1: {s1.GetType().Name}", $"S2: {s2.GetType().Name}"); return;
            }
            if (s1.Version != s2.Version)
            {
                Util.Alert("Save versions are different.", $"S1: {s1.Version}", $"S2: {s2.Version}"); return;
            }

            string tbIsSet = "";
            string tbUnSet = "";

            try
            {
                bool[] oldBits = s1.EventFlags;
                bool[] newBits = s2.EventFlags;
                if (oldBits.Length != newBits.Length)
                {
                    Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < oldBits.Length; i++)
                {
                    if (oldBits[i] == newBits[i])
                    {
                        continue;
                    }
                    if (newBits[i])
                    {
                        tbIsSet += i.ToString("0000") + ",";
                    }
                    else
                    {
                        tbUnSet += i.ToString("0000") + ",";
                    }
                }
            }
            catch (Exception e)
            {
                Util.Error("An unexpected error has occurred.", e);
                Console.Write(e);
            }
            TB_IsSet.Text = tbIsSet;
            TB_UnSet.Text = tbUnSet;

            string r = "";

            try
            {
                ushort[] oldConst = s1.EventConsts;
                ushort[] newConst = s2.EventConsts;
                if (oldConst.Length != newConst.Length)
                {
                    Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < newConst.Length; i++)
                {
                    if (oldConst[i] != newConst[i])
                    {
                        r += $"{i}: {oldConst[i]}->{newConst[i]}{Environment.NewLine}";
                    }
                }
            }
            catch (Exception e)
            {
                Util.Error("An unexpected error has occurred.", e);
                Console.Write(e);
            }

            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?"))
            {
                return;
            }
            Clipboard.SetText(r);
        }
Exemple #10
0
        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,
            };

            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);
        }
Exemple #11
0
 public override PKM convertToPKM(SaveFile SAV)
 {
     return(Gift.convertToPKM(SAV));
 }
Exemple #12
0
        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
            DateTime dt = DateTime.Now;

            if (IsPokémon)
            {
                pk4.Met_Location = pk4.Egg_Location + 3000;
                pk4.Egg_Location = 0;
                pk4.Met_Day      = dt.Day;
                pk4.Met_Month    = dt.Month;
                pk4.Met_Year     = dt.Year - 2000;
                pk4.IsEgg        = false;
            }
            else
            {
                pk4.Egg_Location = pk4.Egg_Location + 3000;
                pk4.Egg_Day      = dt.Day;
                pk4.Egg_Month    = dt.Month;
                pk4.Egg_Year     = dt.Year - 2000;
                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);
        }
Exemple #13
0
 public abstract PKM convertToPKM(SaveFile SAV);