Exemplo n.º 1
0
 public override string getDaycareRNGSeed(int loc)
 {
     int ofs = loc == 0 ? Daycare : Daycare2;
     if (ofs <= 0)
         return null;
     
     var data = Data.Skip(Daycare + 0x1E8).Take(DaycareSeedSize/2).Reverse().ToArray();
     return BitConverter.ToString(data).Replace("-", "");
 }
Exemplo n.º 2
0
 public override void SetMessage(string line1, string line2)
 {
     if (US)
     {
         StringConverter12.SetString1(line2, 0x10, false, 0x10, 0x50).CopyTo(Data, 0x11);
         StringConverter12.SetString1(line1, 0x10, false, 0x10, Data.Skip(0x11).Take(0x10).All(v => v == 0x50) ? 0x50 : 0x7F).CopyTo(Data, 0);
         Data[0x10] = 0x4E;
     }
 }
Exemplo n.º 3
0
        public override string getBoxName(int box)
        {
            int offset = getBoxOffset(BoxCount);

            if (Version == GameVersion.HGSS)
            {
                offset += 0x8;
            }
            return(PKX.array2strG4(Data.Skip(offset + box * 0x28).Take(0x28).ToArray()));
        }
Exemplo n.º 4
0
        public override string GetDaycareRNGSeed(int loc)
        {
            if (Version != GameVersion.B2W2)
            {
                return(null);
            }
            var data = Data.Skip(Daycare + 0x1CC).Take(DaycareSeedSize / 2).Reverse().ToArray();

            return(BitConverter.ToString(data).Replace("-", ""));
        }
Exemplo n.º 5
0
 public WC7(byte[] data = null)
 {
     Data = (byte[])(data?.Clone() ?? new byte[Size]);
     if (Data.Length == SizeFull)
     {
         Data = Data.Skip(SizeFull - Size).ToArray();
         DateTime now = DateTime.Now;
         Year  = (uint)now.Year;
         Month = (uint)now.Month;
         Day   = (uint)now.Day;
     }
 }
Exemplo n.º 6
0
        private void InitializeData()
        {
            // Scan all 3 save slots for the highest counter
            for (int i = 0; i < SLOT_COUNT; i++)
            {
                int slotOffset  = SLOT_START + (i * SLOT_SIZE);
                int SaveCounter = BigEndian.ToInt32(Data, slotOffset + 4);
                if (SaveCounter <= SaveCount)
                {
                    continue;
                }

                SaveCount = SaveCounter;
                SaveIndex = i;
            }

            // Decrypt most recent save slot
            {
                byte[] slot       = new byte[SLOT_SIZE];
                int    slotOffset = SLOT_START + (SaveIndex * SLOT_SIZE);
                Array.Copy(Data, slotOffset, slot, 0, slot.Length);

                ushort[] keys = new ushort[4];
                for (int i = 0; i < keys.Length; i++)
                {
                    keys[i] = BigEndian.ToUInt16(slot, 8 + (i * 2));
                }

                // Decrypt Slot
                Data = GCSaveUtil.Decrypt(slot, 0x00010, 0x27FD8, keys);
            }

            // Get Offset Info
            ushort[] subLength = new ushort[16];
            for (int i = 0; i < 16; i++)
            {
                subLength[i]  = BigEndian.ToUInt16(Data, 0x20 + (2 * i));
                subOffsets[i] = BigEndian.ToUInt16(Data, 0x40 + (4 * i)) | BigEndian.ToUInt16(Data, 0x40 + (4 * i) + 2) << 16;
            }

            // Offsets are displaced by the 0xA8 savedata region
            Trainer1 = subOffsets[1] + 0xA8;
            Party    = Trainer1 + 0x30;
            Box      = subOffsets[2] + 0xA8;
            Daycare  = subOffsets[4] + 0xA8;
            Memo     = subOffsets[5] + 0xA8;
            Shadow   = subOffsets[7] + 0xA8;
            // Purifier = subOffsets[14] + 0xA8;

            StrategyMemo = new StrategyMemo(Data, Memo, xd: true);
            ShadowInfo   = new ShadowInfoTableXD(Data.Skip(Shadow).Take(subLength[7]).ToArray());
        }
Exemplo n.º 7
0
 public WC7(byte[] data = null)
 {
     Data = (byte[])(data?.Clone() ?? new byte[Size]);
     if (Data.Length == SizeFull)
     {
         FullDesc = Util.TrimFromZero(Encoding.Unicode.GetString(Data, 4, 0x1FC));
         Data     = Data.Skip(SizeFull - Size).ToArray();
         DateTime now = DateTime.Now;
         Year  = (uint)now.Year;
         Month = (uint)now.Month;
         Day   = (uint)now.Day;
     }
 }
Exemplo n.º 8
0
        private void ReloadBattleTeams()
        {
            var demo = this is SAV7SM && Data.Skip(PCLayout).Take(0x4C4).All(z => z == 0); // up to Battle Box values

            if (demo || !Exportable)
            {
                BoxLayout.ClearBattleTeams();
            }
            else // Valid slot locking info present
            {
                BoxLayout.LoadBattleTeams();
            }
        }
Exemplo n.º 9
0
        public override string GetDaycareRNGSeed(int loc)
        {
            int ofs = loc == 0 ? Daycare : Daycare2;

            if (ofs <= 0)
            {
                return(null);
            }

            var data = Data.Skip(ofs + 0x1E8).Take(DaycareSeedSize / 2).Reverse().ToArray();

            return(BitConverter.ToString(data).Replace("-", string.Empty));
        }
Exemplo n.º 10
0
        private MysteryGift getWC6(int index)
        {
            if (WondercardData < 0)
            {
                return(null);
            }
            if (index < 0 || index > GiftCountMax)
            {
                return(null);
            }

            return(new WC6(Data.Skip(WondercardData + index * WC6.Size).Take(WC6.Size).ToArray()));
        }
Exemplo n.º 11
0
        public override byte[] Write(bool DSV)
        {
            StrategyMemo.FinalData.CopyTo(Data, Memo);
            setChecksums();

            // Get updated save slot data
            byte[] digest = Data.Skip(Data.Length - 20).Take(20).ToArray();
            byte[] newSAV = EncryptColosseum(Data, digest);

            // Put save slot back in original save data
            byte[] newFile = (byte[])OriginalData.Clone();
            Array.Copy(newSAV, 0, newFile, SLOT_START + SaveIndex * SLOT_SIZE, newSAV.Length);
            return(Header.Concat(newFile).ToArray());
        }
Exemplo n.º 12
0
        private byte[] GetInnerData()
        {
            StrategyMemo.FinalData.CopyTo(Data, Memo);
            SetChecksums();

            // Get updated save slot data
            byte[] digest = Data.Skip(Data.Length - 20).Take(20).ToArray();
            byte[] newSAV = EncryptColosseum(Data, digest);

            // Put save slot back in original save data
            byte[] newFile = MC != null ? MC.SelectedSaveData : (byte[])BAK.Clone();
            Array.Copy(newSAV, 0, newFile, SLOT_START + (SaveIndex * SLOT_SIZE), newSAV.Length);
            return(newFile);
        }
Exemplo n.º 13
0
        // Checksums
        private ushort GetChecksum()
        {
            int end;

            switch (Version)
            {
            case GameVersion.C:
                end = Japanese ? 0x2AE2 : 0x2B82;
                break;

            default:     // GS
                end = Japanese ? 0x2C8B : 0x2D68;
                break;
            }
            return((ushort)Data.Skip(0x2009).Take(end - 0x2009 + 1).Sum(a => a));
        }
Exemplo n.º 14
0
 protected override void SetChecksums()
 {
     // Check for invalid block lengths
     if (Blocks.Length < 3) // arbitrary...
     {
         Debug.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length);
         return;
     }
     // Apply checksums
     foreach (BlockInfo b in Blocks)
     {
         byte[] array = Data.Skip(b.Offset).Take(b.Length).ToArray();
         ushort chk   = SaveUtil.CRC16_CCITT(array);
         BitConverter.GetBytes(chk).CopyTo(Data, b.ChecksumOffset);
         BitConverter.GetBytes(chk).CopyTo(Data, b.ChecksumMirror);
     }
 }
Exemplo n.º 15
0
        public override string getBoxName(int box)
        {
            // Tweaked for the 1-30/31-60 box showing
            string lo      = (30 * (box % 2) + 1).ToString("00");
            string hi      = (30 * (box % 2 + 1)).ToString("00");
            string boxName = $"[{lo}-{hi}] ";

            box = box / 2;

            int offset = Box + 0x1EC38 + 9 * box;

            if (Data[offset] == 0 || Data[offset] == 0xFF)
            {
                boxName += $"BOX {box + 1}";
            }
            boxName += PKX.getG3Str(Data.Skip(offset).Take(9).ToArray(), Japanese);

            return(boxName);
        }
Exemplo n.º 16
0
        public SAV3RSBox(byte[] data = null)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G3BOX] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            if (SaveUtil.getIsG3BOXSAV(Data) != GameVersion.RSBOX)
            {
                return;
            }

            Blocks = new RSBOX_Block[2 * BLOCK_COUNT];
            for (int i = 0; i < Blocks.Length; i++)
            {
                int offset = BLOCK_SIZE + i * BLOCK_SIZE;
                Blocks[i] = new RSBOX_Block(Data.Skip(offset).Take(BLOCK_SIZE).ToArray(), offset);
            }

            // Detect active save
            int[] SaveCounts = Blocks.Select(block => (int)block.SaveCount).ToArray();
            SaveCount = SaveCounts.Max();
            int ActiveSAV = Array.IndexOf(SaveCounts, SaveCount) / BLOCK_COUNT;

            Blocks = Blocks.Skip(ActiveSAV * BLOCK_COUNT).Take(BLOCK_COUNT).OrderBy(b => b.BlockNumber).ToArray();

            // Set up PC data buffer beyond end of save file.
            Box = Data.Length;
            Array.Resize(ref Data, Data.Length + SIZE_RESERVED); // More than enough empty space.

            // Copy block to the allocated location
            foreach (RSBOX_Block b in Blocks)
            {
                Array.Copy(b.Data, 0xC, Data, Box + b.BlockNumber * (BLOCK_SIZE - 0x10), b.Data.Length - 0x10);
            }

            Personal  = PersonalTable.RS;
            HeldItems = Legal.HeldItems_RS;

            if (!Exportable)
            {
                resetBoxes();
            }
        }
Exemplo n.º 17
0
 public WC6(byte[] data = null)
 {
     Data = (byte[])(data?.Clone() ?? new byte[Size]);
     if (Data.Length == SizeFull)
     {
         if (Data[0x205] == 0)
         {
             Data = new byte[Data.Length]; // Invalidate
         }
         Data = Data.Skip(SizeFull - Size).ToArray();
         DateTime now = DateTime.Now;
         Year  = (uint)now.Year;
         Month = (uint)now.Month;
         Day   = (uint)now.Day;
     }
     if (Year < 2000)
     {
         Data = new byte[Data.Length]; // Invalidate
     }
 }
Exemplo n.º 18
0
        // Writeback Validity
        public override string MiscSaveChecks()
        {
            string r = "";
            byte[] FFFF = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            for (int i = 0; i < Data.Length / 0x200; i++)
            {
                if (!FFFF.SequenceEqual(Data.Skip(i * 0x200).Take(0x200))) continue;
                r = $"0x200 chunk @ 0x{i*0x200:X5} is FF'd."
                    + Environment.NewLine + "Cyber will screw up (as of August 31st 2014)." + Environment.NewLine + Environment.NewLine;

                // Check to see if it is in the Pokedex
                if (i * 0x200 > PokeDex && i * 0x200 < PokeDex + 0x900)
                {
                    r += "Problem lies in the Pokedex. ";
                    if (i * 0x200 == PokeDex + 0x400)
                        r += "Remove a language flag for a species < 585, ie Petilil";
                }
                break;
            }
            return r;
        }
Exemplo n.º 19
0
        public override byte[] Write(bool DSV, bool GCI)
        {
            StrategyMemo.FinalData.CopyTo(Data, Memo);
            SetChecksums();

            // Get updated save slot data
            byte[] digest = Data.Skip(Data.Length - 20).Take(20).ToArray();
            byte[] newSAV = EncryptColosseum(Data, digest);

            // Put save slot back in original save data
            byte[] newFile = MC != null ? MC.SelectedSaveData : (byte[])BAK.Clone();
            Array.Copy(newSAV, 0, newFile, SLOT_START + (SaveIndex * SLOT_SIZE), newSAV.Length);

            // Return the gci if Memory Card is not being exported
            if (!IsMemoryCardSave || GCI)
            {
                return(Header.Concat(newFile).ToArray());
            }

            MC.SelectedSaveData = newFile.ToArray();
            return(MC.Data);
        }
Exemplo n.º 20
0
        public SAV3XD(byte[] data = null)
        {
            Data       = data ?? new byte[SaveUtil.SIZE_G3XD];
            BAK        = (byte[])Data.Clone();
            Exportable = !IsRangeEmpty(0, Data.Length);

            if (SaveUtil.GetIsG3XDSAV(Data) != GameVersion.XD)
            {
                return;
            }

            // Scan all 3 save slots for the highest counter
            for (int i = 0; i < SLOT_COUNT; i++)
            {
                int slotOffset  = SLOT_START + (i * SLOT_SIZE);
                int SaveCounter = BigEndian.ToInt32(Data, slotOffset + 4);
                if (SaveCounter <= SaveCount)
                {
                    continue;
                }

                SaveCount = SaveCounter;
                SaveIndex = i;
            }

            // Decrypt most recent save slot
            {
                byte[] slot       = new byte[SLOT_SIZE];
                int    slotOffset = SLOT_START + (SaveIndex * SLOT_SIZE);
                Array.Copy(Data, slotOffset, slot, 0, slot.Length);

                ushort[] keys = new ushort[4];
                for (int i = 0; i < keys.Length; i++)
                {
                    keys[i] = BigEndian.ToUInt16(slot, 8 + (i * 2));
                }

                // Decrypt Slot
                Data = SaveUtil.DecryptGC(slot, 0x00010, 0x27FD8, keys);
            }

            // Get Offset Info
            ushort[] subLength = new ushort[16];
            for (int i = 0; i < 16; i++)
            {
                subLength[i]  = BigEndian.ToUInt16(Data, 0x20 + (2 * i));
                subOffsets[i] = BigEndian.ToUInt16(Data, 0x40 + (4 * i)) | BigEndian.ToUInt16(Data, 0x40 + (4 * i) + 2) << 16;
            }
            // Offsets are displaced by the 0xA8 savedata region
            Trainer1 = subOffsets[1] + 0xA8;
            Party    = Trainer1 + 0x30;
            Box      = subOffsets[2] + 0xA8;
            Daycare  = subOffsets[4] + 0xA8;
            Memo     = subOffsets[5] + 0xA8;
            Shadow   = subOffsets[7] + 0xA8;
            // Purifier = subOffsets[14] + 0xA8;

            StrategyMemo = new StrategyMemo(Data, Memo, xd: true);
            ShadowInfo   = new ShadowInfoTableXD(Data.Skip(Shadow).Take(subLength[7]).ToArray());

            OFS_PouchHeldItem = Trainer1 + 0x4C8;
            OFS_PouchKeyItem  = Trainer1 + 0x540;
            OFS_PouchBalls    = Trainer1 + 0x5EC;
            OFS_PouchTMHM     = Trainer1 + 0x62C;
            OFS_PouchBerry    = Trainer1 + 0x72C;
            OFS_PouchCologne  = Trainer1 + 0x7E4;
            OFS_PouchDisc     = Trainer1 + 0x7F0;

            LegalItems    = Legal.Pouch_Items_XD;
            LegalKeyItems = Legal.Pouch_Key_XD;
            LegalBalls    = Legal.Pouch_Ball_RS;
            LegalTMHMs    = Legal.Pouch_TM_RS; // not HMs
            LegalBerries  = Legal.Pouch_Berries_RS;
            LegalCologne  = Legal.Pouch_Cologne_XD;
            LegalDisc     = Legal.Pouch_Disc_XD;

            Personal  = PersonalTable.RS;
            HeldItems = Legal.HeldItems_XD;

            if (!Exportable)
            {
                ClearBoxes();
            }

            // Since PartyCount is not stored in the save file,
            // Count up how many party slots are active.
            for (int i = 0; i < 6; i++)
            {
                if (GetPartySlot(GetPartyOffset(i)).Species != 0)
                {
                    PartyCount++;
                }
            }
        }
Exemplo n.º 21
0
 public override string getBoxName(int box)
 {
     return(PKX.getG1Str(Data.Skip(BoxNamesOffset + box * 9).Take(9).ToArray(), Japanese));
 }
Exemplo n.º 22
0
 // Checksums
 private ushort GetChecksum()
 {
     return((ushort)Data.Skip(Offsets.Trainer1).Take(Offsets.AccumulatedChecksumEnd - Offsets.Trainer1 + 1).Sum(a => a));
 }
Exemplo n.º 23
0
        public override string getBoxName(int box)
        {
            int offset = getBoxOffset(BoxCount);

            return(PKX.getG3Str(Data.Skip(offset + box * 9).Take(9).ToArray(), Japanese));
        }