--- trunk/RomCheater/Serialization/SearchResultReader.cs 2012/06/21 06:30:33 402 +++ trunk/RomCheater/Serialization/SearchResultReader.cs 2012/06/21 18:10:21 408 @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using RomCheater.Docking.MemorySearch; +using RomCheater.Logging; namespace RomCheater.Serialization { @@ -12,6 +13,10 @@ namespace RomCheater.Serialization uint CurrentAddress(); void CurrentResult<TValue>(out TValue Value); TValue CurrentResult<TValue>(); + + bool ReadCurrentAddess { get; } + bool ReadCurrentValue { get; } + } public class SearchResultReader : SerializationReader, ISearchResultReader { @@ -21,6 +26,7 @@ namespace RomCheater.Serialization { try { + //int ResultsRead = 0; // SRD (string) string magic = Encoding.UTF8.GetString(binReader.ReadBytes(3)); string SRD = "SRD"; @@ -41,10 +47,41 @@ namespace RomCheater.Serialization throw new InvalidOperationException(string.Format("Result Count is zero")); } ResultCount = resultcount; + + //for (int i = 0; i < ResultCount; i++) + //{ + // try + // { + // ResultsRead = i; + // uint address = 0; + // // assume uint for data type + // uint value = 0; + // address = binReader.ReadUInt32(); + // value = binReader.ReadUInt32(); + // //if (i % 100000 == 0) + // // logger.VerboseDebug.WriteLine("Result: @0x{0:x8}=0x{1:x8}", address, value); + // } + // catch (Exception ex) + // { + // logger.VerboseError.WriteLine("SearchResultReader.ReadHeader():Consistency Check"); + // //logger.VerboseError.WriteLine(ex.ToString()); + // logger.VerboseError.WriteLine("Faied entry: {0}", ResultsRead); + // break; + // } + // ResultsRead++; // add 1 + //} + ////throw new NotImplementedException("DEBUG: testing SearchResultReader consistency"); + //if (ResultCount != ResultsRead) + //{ + // throw new InvalidOperationException(string.Format("ResultCount does not match ResultsRead: 0x{0:x8} != 0x{1:x8}", ResultCount, ResultsRead)); + //} + } catch (System.IO.EndOfStreamException) { } } - #region ISearchResultReader members + #region ISearchResultReader members + public bool ReadCurrentAddess { get; private set; } + public bool ReadCurrentValue { get; private set; } public uint CurrentAddress() { uint Address = 0; @@ -56,7 +93,13 @@ namespace RomCheater.Serialization Address = 0; try { + if (ReadCurrentAddess && !ReadCurrentValue) + { + throw new InvalidOperationException("Cannot read Current Address because the current Value has not been read. Please call CurrentResult<TValue>() first."); + } Address = binReader.ReadUInt32(); + ReadCurrentAddess = true; + ReadCurrentValue = false; } catch (System.IO.EndOfStreamException) { } } @@ -69,6 +112,10 @@ namespace RomCheater.Serialization public void CurrentResult<TValue>(out TValue Value) { Value = default(TValue); + if (!ReadCurrentAddess) + { + throw new InvalidOperationException("Cannot read Current Value because the current Address has not been read. Please call CurrentAddress() first."); + } try { Type t = typeof(TValue); @@ -99,6 +146,8 @@ namespace RomCheater.Serialization Value = (TValue)Convert.ChangeType(binReader.ReadInt64(), typeof(TValue)); break; } + ReadCurrentValue = true; + ReadCurrentAddess = false; } catch (System.IO.EndOfStreamException) { } } |