/[RomCheater]/trunk/RomCheater.RVACalculator/RVACalculatorDockControl.cs
ViewVC logotype

Diff of /trunk/RomCheater.RVACalculator/RVACalculatorDockControl.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.RVACalculator/RVACalculatorDockControl.cs	2013/06/17 04:49:09	668
+++ trunk/RomCheater.RVACalculator/RVACalculatorDockControl.cs	2013/06/17 05:11:25	669
@@ -91,12 +91,12 @@
             if (result != DialogResult.OK) { return; }
 
             
-            ICheatList list = new ICheatList();
+            ICheatList2 list = new ICheatList2();
             list.RVA = txtRVA.ToUInt32();
-            List<ICheatEntry> cheats = new List<ICheatEntry>();
+            List<ICheatEntry2> cheats = new List<ICheatEntry2>();
             foreach (ListViewItem li in lstCheats.Items)
             {
-                cheats.Add(new ICheatEntry(li.Text, Convert.ToUInt32(li.SubItems[1].Text, 16)));
+                cheats.Add(new ICheatEntry2(li.Text, Convert.ToUInt32(li.SubItems[1].Text, 16), Convert.ToUInt32(li.SubItems[2].Text, 16)));
             }
 
             list.Cheats = cheats;
@@ -107,6 +107,7 @@
                 {
                     try
                     {
+                        fs.Seek(0, SeekOrigin.Begin);
                         BinaryFormatter bin = new BinaryFormatter();
                         bin.Serialize(fs, list);
                     }
@@ -115,6 +116,7 @@
                         logger.Error.WriteLine("Failed to save file: {0}", CheatSaver.FileName);
                         logger.VerboseError.WriteLine(ex.ToString());
                         MessageBox.Show(string.Format("Failed to save: '{0}'", new FileInfo(CheatSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                        return;
                     }
                 }
                 MessageBox.Show(string.Format("Successfully saved file: '{0}'", new FileInfo(CheatSaver.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -137,8 +139,20 @@
                 {
                     try
                     {
+                        ICheatList2 list = new ICheatList2();
                         BinaryFormatter bin = new BinaryFormatter();
-                        var list = (ICheatList)bin.Deserialize(fs);
+                        try
+                        {
+                            fs.Seek(0, SeekOrigin.Begin);
+                            var t_list = (ICheatList2)bin.Deserialize(fs);
+                            list = t_list;
+                        }
+                        catch (Exception)
+                        {
+                            fs.Seek(0, SeekOrigin.Begin);
+                            var t_list = (ICheatList)bin.Deserialize(fs);
+                            list = new ICheatList2(t_list);
+                        }
 
                         txtRVA.Value = list.RVA;
                         result = MessageBox.Show("Clear existing Cheats?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
@@ -168,6 +182,7 @@
                         logger.Error.WriteLine("Failed to load file: {0}", CheatLoader.FileName);
                         logger.VerboseError.WriteLine(ex.ToString());
                         MessageBox.Show(string.Format("Failed to open: '{0}'", new FileInfo(CheatLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                        return;
                     }
                 }
                 MessageBox.Show(string.Format("Successfully opened file: '{0}'", new FileInfo(CheatLoader.FileName).Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -193,7 +208,31 @@
                 index++;
             }
         }
+        private void btnCopyAll_Click(object sender, EventArgs e)
+        {
+            ICheatList2 list = new ICheatList2();
+            list.RVA = txtRVA.ToUInt32();
+            List<ICheatEntry2> cheats = new List<ICheatEntry2>();
+            foreach (ListViewItem li in lstCheats.Items)
+            {
+                cheats.Add(new ICheatEntry2(li.Text, Convert.ToUInt32(li.SubItems[1].Text, 16), Convert.ToUInt32(li.SubItems[2].Text, 16)));
+            }
+            StringBuilder builder = new StringBuilder();
+            builder.AppendFormat("RVA: 0x{0:x8}", list.RVA);
+            builder.AppendLine();
+            foreach (ColumnHeader t in lstCheats.Columns)
+            {
+                builder.AppendFormat("{0}:\t", t.Name);
+            }
+            builder.AppendLine();
+            foreach (var cheat in list.Cheats)
+            {
+                builder.AppendFormat("{0}\t{1}\t{2}", cheat.CheatName, cheat.CheatAddress, cheat.PhysicalAddress);
+                builder.AppendLine();
+            }
+            Clipboard.SetText(builder.ToString());
 
+        }
         private void RVACalculatorDockControl_Shown(object sender, EventArgs e)
         {
             //const int t = 100;
@@ -217,11 +256,55 @@
             public uint CheatAddress;
         }
         [Serializable]
+        private struct ICheatEntry2
+        {
+            public ICheatEntry2(string name, uint address, uint physical)
+            {
+                CheatName = name;
+                CheatAddress = address;
+                PhysicalAddress = physical;
+            }
+            public string CheatName;
+            public uint CheatAddress;
+            public uint PhysicalAddress;
+        }
+        [Serializable]
         private struct ICheatList
         {
+            public ICheatList(ICheatList2 t)
+            {
+                RVA = t.RVA;
+                List<ICheatEntry> cheats = new List<ICheatEntry>();
+                t.Cheats.ForEach(c => cheats.Add(new ICheatEntry(c.CheatName,c.CheatAddress)));
+                Cheats = cheats;
+            }
+            public ICheatList(uint rva, List<ICheatEntry> cheats)
+            {
+                RVA = rva;
+                Cheats = cheats;
+            }
             public uint RVA;
             public List<ICheatEntry> Cheats;
         }
+        [Serializable]
+        private struct ICheatList2
+        {
+            public ICheatList2(ICheatList t)
+            {
+                RVA = t.RVA;
+                List<ICheatEntry2> cheats = new List<ICheatEntry2>();
+                t.Cheats.ForEach(c => cheats.Add(new ICheatEntry2(c.CheatName, c.CheatAddress, c.CheatAddress)));
+                Cheats = cheats;
+            }
+            public ICheatList2(uint rva, List<ICheatEntry2> cheats)
+            {
+                RVA = rva;
+                Cheats = cheats;
+            }
+            public uint RVA;
+            public List<ICheatEntry2> Cheats;
+        }
+      
 
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22