/[RomCheater]/trunk/RomCheater/Serialization/SearchResultReader.cs
ViewVC logotype

Diff of /trunk/RomCheater/Serialization/SearchResultReader.cs

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

--- trunk/RomCheater/Serialization/SearchResultReader.cs	2013/06/03 07:13:44	471
+++ trunk/RomCheater/Serialization/SearchResultReader.cs	2013/06/03 07:39:39	472
@@ -233,5 +233,42 @@
             update_progress.Invoke(0, string.Empty);
             return results;
         }
+
+        public ResultType<object> GetResultAtIndex(int index, bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
+        {
+            update_progress.Invoke(0, string.Empty);
+            int data_size = sizeof(uint); // address size ... should be 4 bytes (could be 8, if we have a 64-bit address)
+            ResultType<object> result = new ResultType<object>();
+            using (FileStream fs = CreateReader())
+            {
+                using (BinaryReader binReader = new BinaryReader(fs))
+                {
+                    binReader.BaseStream.Seek(ResultDataOffset, SeekOrigin.Begin); // seek to start of result data 
+                    data_size += (int)datatype / 8;
+                    long offset = data_size * index;
+                    binReader.BaseStream.Seek(offset, SeekOrigin.Current);
+                    uint Address = binReader.ReadUInt32();
+                    object Value = 0;
+                    switch (datatype)
+                    {
+                        case SearchDataTypes._8bits:
+                            if (unsigned) { Value = binReader.ReadByte(); } else { Value = binReader.ReadSByte(); }
+                            break;
+                        case SearchDataTypes._16bits:
+                            if (unsigned) { Value = binReader.ReadUInt16(); } else { Value = binReader.ReadInt16(); }
+                            break;
+                        case SearchDataTypes._32bits:
+                            if (unsigned) { Value = binReader.ReadUInt32(); } else { Value = binReader.ReadInt32(); }
+                            break;
+                        case SearchDataTypes._64bits:
+                            if (unsigned) { Value = binReader.ReadUInt64(); } else { Value = binReader.ReadInt64(); }
+                            break;
+                    }
+                    result = new ResultType<object>(Address, Value);
+                }
+            }
+            return result;
+        }
+
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22