diff --git a/BizHawk.MultiClient/Global.cs b/BizHawk.MultiClient/Global.cs index bd79a38c24..4ace8c05a9 100644 --- a/BizHawk.MultiClient/Global.cs +++ b/BizHawk.MultiClient/Global.cs @@ -23,6 +23,7 @@ namespace BizHawk.MultiClient public static CoreComm CoreComm; public static GameInfo Game; public static CheatList CheatList; + public static NewCheatList CheatList2; public static Controller NullControls; public static AutofireController AutofireNullControls; diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 9be3ff4a14..6fc9d8b7e5 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -172,6 +172,7 @@ namespace BizHawk.MultiClient FFMpeg.FFMpegPath = PathManager.MakeProgramRelativePath(Global.Config.FFMpegPath); Global.CheatList = new CheatList(); + Global.CheatList2 = new NewCheatList(); UpdateStatusSlots(); UpdateKeyPriorityIcon(); diff --git a/BizHawk.MultiClient/tools/Cheats/CheatList.cs b/BizHawk.MultiClient/tools/Cheats/CheatList.cs index 8d5b6a6cac..8f5faee6eb 100644 --- a/BizHawk.MultiClient/tools/Cheats/CheatList.cs +++ b/BizHawk.MultiClient/tools/Cheats/CheatList.cs @@ -2,11 +2,158 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; -namespace BizHawk.MultiClient.tools.Cheats +namespace BizHawk.MultiClient { - class CheatList + public class NewCheatList : IEnumerable { + private List _cheatList = new List(); + private string _currentFileName = String.Empty; + private bool _changes = false; + + public NewCheatList() { } + + public IEnumerator GetEnumerator() + { + return _cheatList.GetEnumerator(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public NewCheat this[int index] + { + get { return _cheatList[index]; } + } + + public int Count + { + get { return _cheatList.Count; } + } + + public void Update() + { + _cheatList.ForEach(x => x.Pulse()); + } + + public void Add(NewCheat c) + { + _changes = true; + _cheatList.Add(c); + } + + public void Remove(NewCheat c) + { + _changes = true; + _cheatList.Remove(c); + } + + public bool Changes + { + get { return _changes; } + } + + public void Clear() + { + _changes = true; + _cheatList.Clear(); + } + + public void DisableAll() + { + _changes = true; + _cheatList.ForEach(x => x.Enabled = false); + } + + public void EnableAll() + { + _changes = true; + _cheatList.ForEach(x => x.Enabled = true); + } + + public bool IsActive(MemoryDomain domain, int address) + { + foreach (var cheat in _cheatList) + { + if (cheat.IsSeparator) + { + continue; + } + else if (cheat.Domain == domain && cheat.Contains(address) && cheat.Enabled) + { + return true; + } + } + + return false; + } + + public void Freeze(MemoryDomain domain, int address, Watch.WatchSize size, int value, bool? bigendian = null) + { + var exists = _cheatList.Any(x => x.Domain == domain && x.Address == address && x.Size == size); + if (!exists) + { + bool endian = false; + if (bigendian.HasValue) + { + endian = bigendian.Value; + } + else + { + switch(domain.Endian) + { + default: + case Endian.Unknown: + case Endian.Little: + bigendian = false; + break; + case Endian.Big: + bigendian = true; + break; + } + } + + Watch w = Watch.GenerateWatch(domain, address, size, Watch.DisplayType.Unsigned, String.Empty, endian); + _cheatList.Add(new NewCheat(w, compare: null, enabled: true)); + } + } + + public bool Save() + { + if (!String.IsNullOrWhiteSpace(_currentFileName)) + { + return SaveFile(); + } + else + { + return SaveAs(); + } + } + + public void Load() + { + throw new NotImplementedException(); + } + + public string CurrentFileName + { + get { return _currentFileName; } + } + + #region privates + + private bool SaveFile() + { + throw new NotImplementedException(); + } + + private bool SaveAs() + { + throw new NotImplementedException(); + } + + #endregion } } diff --git a/BizHawk.MultiClient/tools/Cheats/NewCheat.cs b/BizHawk.MultiClient/tools/Cheats/NewCheat.cs index 0cdc21930a..1b66d437d7 100644 --- a/BizHawk.MultiClient/tools/Cheats/NewCheat.cs +++ b/BizHawk.MultiClient/tools/Cheats/NewCheat.cs @@ -5,7 +5,7 @@ using System.Text; namespace BizHawk.MultiClient { - class NewCheat + public class NewCheat { #region Constructors @@ -60,6 +60,8 @@ namespace BizHawk.MultiClient get { if (_compare.HasValue && !IsSeparator) return _compare; else return null; } } + public MemoryDomain Domain { get { return _watch.Domain; } } + public Watch.WatchSize Size { get { return _watch.Size; }