private void button3_Click(object sender, EventArgs e)
 {
     if (saveDir != null) {
         dataSet1.Tables["extensionTable"].Rows.Clear();
         dataSet1.ReadXml("extension.xml");
         BigEndianBinaryReader saveFileBinaryReader = new BigEndianBinaryReader(new FileStream(saveDir + @"\USR-DATA", FileMode.Open));
         foreach (DataRow dr in dataSet1.Tables["extensionTable"].Rows) {
             long pointer;
             if (!long.TryParse(dr["hackOffset"].ToString(), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat, out pointer)) {
                 MessageBox.Show("位置格式不正確");
                 dataSet1.Tables["extensionTable"].Rows.Clear();
                 return;
             }
             if (pointer > saveFileBinaryReader.BaseStream.Length) {
                 MessageBox.Show("超過存檔可以表示的範圍");
                 dataSet1.Tables["extensionTable"].Rows.Clear();
                 return;
             }
             saveFileBinaryReader.BaseStream.Position = pointer;
             if (dr["hackType"].Equals("int")) {
                 dr["hackValue"] = saveFileBinaryReader.ReadInt32();
             } else if (dr["hackType"].Equals("uint")) {
                 dr["hackValue"] = saveFileBinaryReader.ReadUInt32();
             } else if (dr["hackType"].Equals("short")) {
                 dr["hackValue"] = saveFileBinaryReader.ReadInt16();
             } else if (dr["hackType"].Equals("ushort")) {
                 dr["hackValue"] = saveFileBinaryReader.ReadUInt16();
             } else if (dr["hackType"].Equals("byte")) {
                 dr["hackValue"] = saveFileBinaryReader.ReadByte();
             } else {
                 MessageBox.Show("讀取失敗,不支援的數據格式");
                 return;
             }
         }
         saveFileBinaryReader.Close();
     } else {
         MessageBox.Show("無法讀取存檔");
     }
 }
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (saveDir != null) {
                long pointer;
                if (dataGridView1.Rows[e.RowIndex].Cells[1].Value == null) {
                    dataGridView1.Rows[e.RowIndex].Cells[1].Value = 0;
                }
                if (dataGridView1.Rows[e.RowIndex].Cells[2].Value == null) {
                    dataGridView1.Rows[e.RowIndex].Cells[2].Value = "int";
                }
                long.TryParse(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()
                    , System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat, out pointer);

                BigEndianBinaryReader saveFileBinaryReader = new BigEndianBinaryReader(new FileStream(saveDir + @"\USR-DATA", FileMode.Open));
                saveFileBinaryReader.BaseStream.Position = pointer;
                string type = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                if (type.Trim().Equals("int")) {
                    dataGridView1.Rows[e.RowIndex].Cells[3].Value =
                        saveFileBinaryReader.ReadInt32();
                } else if (type.Trim().Equals("uint")) {
                    dataGridView1.Rows[e.RowIndex].Cells[3].Value =
                        saveFileBinaryReader.ReadUInt32();
                } else if (type.Trim().Equals("short")) {
                    dataGridView1.Rows[e.RowIndex].Cells[3].Value =
                         saveFileBinaryReader.ReadInt16();
                } else if (type.Trim().Equals("ushort")) {
                    dataGridView1.Rows[e.RowIndex].Cells[3].Value =
                       saveFileBinaryReader.ReadUInt16();
                } else if (type.Trim().Equals("byte")) {
                    dataGridView1.Rows[e.RowIndex].Cells[3].Value =
                        saveFileBinaryReader.ReadByte();
                }
                saveFileBinaryReader.Close();
            } else {
                MessageBox.Show("無法讀取存檔");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // ofd.Filter = "Ps3 Save (USR-DATA)|USR-DATA|All files (*.*)|*.*";
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
                if (saveDir != null) {
                    /////////////////////////
                    // Encrypt
                    /////////////////////////
                    gameID = ((string)SFO.getValue("SAVEDATA_DIRECTORY")).Split('-')[0];
                    Utility.encryptSave(gameID, saveDir);
                    saveDir = null;
                }

                saveDir = folderBrowserDialog1.SelectedPath;
                if (!File.Exists(saveDir + @"\USR-DATA") || !File.Exists(saveDir + @"\ICON0.PNG") || !File.Exists(saveDir + @"\PARAM.SFO")
                    || !File.Exists(saveDir + @"\PIC1.PNG") || !File.Exists(saveDir + @"\PARAM.PFD")) {
                    saveDir = null;
                    MessageBox.Show("錯誤的存檔");
                    return;
                }

                /////////////////////////
                // SFO Block
                /////////////////////////
                SFO = new ParamSFOParser(saveDir + @"\PARAM.SFO");
                // tabPage4.BackgroundImage = Image.FromFile( saveDir + @"\PIC1.PNG" );

                imageLabel.Image = Image.FromFile(saveDir + @"\ICON0.PNG");
                TITLE.Text = (string)SFO.getValue("TITLE");
                SUB_TITLE.Text = (string)SFO.getValue("SUB_TITLE");
                DETAIL.Text = (string)SFO.getValue("DETAIL");

                /////////////////////////
                // Decrypt
                /////////////////////////
                gameID = ((string)SFO.getValue("SAVEDATA_DIRECTORY")).Split('-')[0];

                Utility.decryptSave(gameID, saveDir);
                // Get the output into a string
                // string result = proc.StandardOutput.ReadToEnd();

                // //////////////////////
                // SaveBlock
                /////////////////////////
                boxList_lv.Items.Clear();
                basketList_lv.Items.Clear();
                BigEndianBinaryReader SaveDataFile = new BigEndianBinaryReader(new FileStream(saveDir + @"\USR-DATA", FileMode.Open));
                SaveDataFile.BaseStream.Position = AtelierAyeshaDataType.CollectionBasketOffset;
                BasketItem basketTmp;
                for (int i = 0; i < 120; i++) {
                    basketTmp = new BasketItem(SaveDataFile);
                    if (basketTmp.ID == 0xFFFF) {
                        break;
                    }
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = i + "";
                    lvi.SubItems.Add(basketTmp.Name);
                    lvi.Tag = basketTmp;
                    basketList_lv.Items.Add(lvi);
                }

                BoxItem boxTemp;
                SaveDataFile.BaseStream.Position = AtelierAyeshaDataType.BoxOffset;
                boxList_lv.BeginUpdate();
                for (int i = 0; i < 10000; i++) {
                    boxTemp = new BoxItem(SaveDataFile);
                    if (boxTemp.ID == 0xFFFF || boxTemp.Count == 0) {
                        break;
                    }
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = i + "";
                    lvi.SubItems.Add(boxTemp.Name);
                    lvi.Tag = boxTemp;
                    boxList_lv.Items.Add(lvi);
                }
                boxList_lv.EndUpdate();

                // 錢
                SaveDataFile.BaseStream.Position = AtelierAyeshaDataType.money;
                money_nud.Value = Convert.ToDecimal(SaveDataFile.ReadUInt32());
                // pt1
                SaveDataFile.BaseStream.Position = AtelierAyeshaDataType.pt;
                pt1_nud.Value = Convert.ToDecimal(SaveDataFile.ReadUInt32());
                readExtensionFile(SaveDataFile.BaseStream);

                SaveDataFile.Close();
            }
        }