Simplify IMovie and refactor some code to allow that, this also disables more functionality in TAStudio but it is disabled in trunk currently anyway (pending a rewrite). Also a bunch of pedantic code cleanup in tool dialogs

This commit is contained in:
adelikat 2013-11-29 19:55:05 +00:00
parent 0ed9d832c7
commit 29a0fa49f8
17 changed files with 1568 additions and 1578 deletions

View File

@ -3,12 +3,11 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
// TODO: message callback / event handler
// TODO: consider other event handlers, switching modes?
public interface IMovie
{
int Rerecords { get; set; }
string Filename { get; set; }
#region Status
bool IsCountingRerecords { get; set; }
bool IsActive { get; }
@ -17,12 +16,57 @@ namespace BizHawk.Client.Common
bool IsFinished { get; }
bool Changes { get; }
bool Loaded { get; }
bool StartsFromSavestate { get; }
int Rerecords { get; set; }
#endregion
#region File Handling API
string Filename { get; set; }
bool Load();
void Save();
void SaveAs();
#endregion
#region Mode Handling API
/// <summary>
/// Tells the movie to start recording from the beginning.
/// This will clear sram, and the movie log
/// </summary>
/// <param name="truncate"></param>
void StartNewRecording();
/// <summary>
/// Tells the movie to start playback from the beginning
/// This will clear sram
/// </summary>
void StartNewPlayback();
/// <summary>
/// Sets the movie to inactive (note that it will still be in memory)
/// The saveChanges flag will tell the movie to save its contents to disk
/// </summary>
/// <param name="saveChanges"></param>
void Stop(bool saveChanges = true);
/// <summary>
/// Switches to record mode
/// Does not change the movie log or clear sram
/// </summary>
void SwitchToRecord();
/// <summary>
/// Switches to playback mode
/// Does not change the movie log or clear sram
/// </summary>
void SwitchToPlay();
#endregion
#region Editing API
void ClearFrame(int frame);
@ -36,39 +80,24 @@ namespace BizHawk.Client.Common
#endregion
#region Dubious, should reconsider
void CommitFrame(int frameNum, IController source); //why pass in frameNum? Calling api
void PokeFrame(int frameNum, string input); //Why does this exist as something different than Commit Frame?
void CaptureState(); //Movie code should manage wheter it needs to capture a state
LoadStateResult CheckTimeLines(TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage); //No need to return a status, no reason to have hacky flags, no need to pass a textreader
string GetTime(bool preLoad); //Rename to simply: Time, and make it a DateTime
void DumpLogIntoSavestateText(TextWriter writer); //Why pass a Textwriter, just make a string property that is the inputlog as text
void LoadLogFromSavestateText(TextReader reader, bool isMultitracking); //Pass in the text? do we need to care if it is multitracking, and can't hte movie already know that?
int? Frames { get; } //Nullable is a hack, also why does calling code need to know the number of frames, can that be minimized?
int RawFrames { get; } //Hacky to need two different frame properties
void CommitFrame(int frameNum, IController source); // Why pass in frameNum? Calling api
void PokeFrame(int frameNum, string input); // Why does this exist as something different than Commit Frame?
LoadStateResult CheckTimeLines(TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage); // No need to return a status, no reason to have hacky flags, no need to pass a textreader
string GetTime(bool preLoad); // Rename to simply: Time, and make it a Timespan
void DumpLogIntoSavestateText(TextWriter writer); // Why pass a Textwriter, just make a string property that is the inputlog as text
void LoadLogFromSavestateText(TextReader reader, bool isMultitracking); // Pass in the text? do we need to care if it is multitracking, and can't hte movie already know that?
int? Frames { get; } // Nullable is a hack, also why does calling code need to know the number of frames, can that be minimized?
int RawFrames { get; } // Hacky to need two different frame properties
void Finish(); //Why isn't the movie in charge of this?
void StartRecording(bool truncate = true); //Why do we need to truncate or not truncate? Why isn't the object in charge of this decision?
string GetInput(int frame); // Should be a property of a Record object
void StartPlayback(); //Poorly named for what it does, SetToPlay() perhaps? Also, this seems like too much power to give the calling code
void SwitchToRecord(); //Ditto
void SwitchToPlay(); //Dubious that it is needed
MovieHeader Header { get; } // Don't expose this!!!
MovieLog LogDump { get; } // Don't expose this!!!
SubtitleList Subtitles { get; } // Don't expose this!!!
bool FrameLagged(int frame); //SHould be a property of a Record object
byte[] GetState(int frame); //Should be a property of a Record object
string GetInput(int frame); //Should be a property of a Record object
byte[] InitState { get; } //Should be a record object?
bool StartsFromSavestate { get; set; } //Why is this settable!!!
MovieHeader Header { get; } //Don't expose this!!!
MovieLog LogDump { get; } //Don't expose this!!!
SubtitleList Subtitles { get; } //Don't expose this!!!
int StateFirstIndex { get; } //What do these do?
int StateLastIndex { get; }
#endregion
}
}
//TODO: delete this and refactor code that uses it!
// TODO: delete this and refactor code that uses it!
public enum LoadStateResult { Pass, GuidMismatch, TimeLineError, FutureEventError, NotInRecording, EmptyLog, MissingFrameNumber }

View File

@ -11,21 +11,21 @@ namespace BizHawk.Client.Common
{
#region Constructors
public Movie(string filename)
: this()
public Movie(string filename, bool startsFromSavestate = false)
: this(startsFromSavestate)
{
Rerecords = 0;
Filename = filename;
Loaded = !String.IsNullOrWhiteSpace(filename);
}
public Movie()
public Movie(bool startsFromSavestate = false)
{
Header = new MovieHeader();
Subtitles = new SubtitleList();
Filename = String.Empty;
_preloadFramecount = 0;
StartsFromSavestate = false;
StartsFromSavestate = startsFromSavestate;
IsCountingRerecords = true;
_mode = Moviemode.Inactive;
IsText = true;
@ -95,7 +95,7 @@ namespace BizHawk.Client.Common
public bool StartsFromSavestate
{
get { return _startsfromsavestate; }
set
private set
{
_startsfromsavestate = value;
if (value)
@ -109,17 +109,6 @@ namespace BizHawk.Client.Common
}
}
//TODO: these are getting too lengthy perhaps the log should just be exposed?
public int StateFirstIndex
{
get { return _log.StateFirstIndex; }
}
public int StateLastIndex
{
get { return _log.StateLastIndex; }
}
public bool StateCapturing
{
get { return _statecapturing; }
@ -133,16 +122,6 @@ namespace BizHawk.Client.Common
}
}
public byte[] GetState(int frame)
{
return _log.GetState(frame);
}
public byte[] InitState
{
get { return _log.InitState; }
}
#endregion
#region Mode API
@ -172,11 +151,7 @@ namespace BizHawk.Client.Common
get { return _changes; }
}
/// <summary>
/// Tells the movie to start recording from the beginning, this will clear sram, and the movie log
/// </summary>
/// <param name="truncate"></param>
public void StartRecording(bool truncate = true)
public void StartNewRecording()
{
_mode = Moviemode.Record;
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0)
@ -184,28 +159,20 @@ namespace BizHawk.Client.Common
SaveAs();
MakeBackup = false;
}
if (truncate)
{
_log.Clear();
}
_log.Clear();
}
public void StartPlayback()
public void StartNewPlayback()
{
_mode = Moviemode.Play;
Global.Emulator.ClearSaveRam();
}
/// <summary>
/// Tells the movie to recording mode
/// </summary>
public void SwitchToRecord()
{
_mode = Moviemode.Record;
}
/// <summary>
/// Tells the movie to go into playback mode
/// </summary>
public void SwitchToPlay()
{
_mode = Moviemode.Play;
@ -228,7 +195,7 @@ namespace BizHawk.Client.Common
/// <summary>
/// If a movie is in playback mode, this will set it to movie finished
/// </summary>
public void Finish()
private void Finish()
{
if (_mode == Moviemode.Play)
{
@ -372,30 +339,38 @@ namespace BizHawk.Client.Common
public string GetInput(int frame)
{
if (frame >= 0)
if (frame < _log.Length)
{
int getframe;
if (_loopOffset.HasValue)
if (frame >= 0)
{
if (frame < _log.Length)
int getframe;
if (_loopOffset.HasValue)
{
getframe = frame;
if (frame < _log.Length)
{
getframe = frame;
}
else
{
getframe = ((frame - _loopOffset.Value) % (_log.Length - _loopOffset.Value)) + _loopOffset.Value;
}
}
else
{
getframe = ((frame - _loopOffset.Value) % (_log.Length - _loopOffset.Value)) + _loopOffset.Value;
getframe = frame;
}
return _log[getframe];
}
else
{
getframe = frame;
return String.Empty;
}
return _log[getframe];
}
else
{
Finish();
return String.Empty;
}
}
@ -452,20 +427,6 @@ namespace BizHawk.Client.Common
get { return _log; }
}
public bool FrameLagged(int frame)
{
return _log.FrameLagged(frame);
}
public void CaptureState()
{
if (StateCapturing)
{
_log.AddState(Global.Emulator.SaveStateBinary());
GC.Collect();
}
}
public void PokeFrame(int frameNum, string input)
{
_changes = true;

View File

@ -4,7 +4,7 @@ using System.Linq;
namespace BizHawk.Client.Common
{
//TODO: what is this object really trying to accomplish? COnsider making it a collection (ICollection, IEnumerable perhaps)
// TODO: what is this object really trying to accomplish? COnsider making it a collection (ICollection, IEnumerable perhaps)
/// <summary>
/// Represents the controller key presses of a movie

View File

@ -10,7 +10,6 @@ namespace BizHawk.Client.Common
public MultitrackRecording MultiTrack = new MultitrackRecording();
public IMovie Movie;
public MovieControllerAdapter MovieControllerAdapter = new MovieControllerAdapter();
public bool EditorMode { get; set; }
public Action<string> MessageCallback; //Not Required
public Func<string, string, bool> AskYesNoCallback; //Not Required
@ -65,9 +64,15 @@ namespace BizHawk.Client.Common
/// </summary>
public void LatchInputFromLog()
{
MovieControllerAdapter.SetControllersAsMnemonic(
Movie.GetInput(Global.Emulator.Frame)
);
var input = Movie.GetInput(Global.Emulator.Frame);
// Attempting to get a frame past the end of a movie changes the mode to finished
if (!Movie.IsFinished)
{
MovieControllerAdapter.SetControllersAsMnemonic(
Movie.GetInput(Global.Emulator.Frame)
);
}
}
public void StopMovie(bool saveChanges = true)
@ -136,29 +141,18 @@ namespace BizHawk.Client.Common
else if (Movie.IsPlaying)
{
if (Global.Emulator.Frame >= Movie.Frames)
LatchInputFromLog();
//Movie may go into finished mode as a result from latching
if (!Movie.IsFinished)
{
if (EditorMode)
{
Movie.CaptureState();
LatchInputFromLog();
Movie.CommitFrame(Global.Emulator.Frame, Global.MovieOutputHardpoint);
}
else
{
Movie.Finish();
}
}
else
{
Movie.CaptureState();
LatchInputFromLog();
if (Global.ClientControls["Scrub Input"])
{
LatchInputFromPlayer(Global.MovieInputSourceAdapter);
ClearFrame();
}
else if (EditorMode || Global.Config.MoviePlaybackPokeMode)
else if (Global.Config.MoviePlaybackPokeMode)
{
LatchInputFromPlayer(Global.MovieInputSourceAdapter);
var mg = new MnemonicsGenerator();
@ -178,7 +172,6 @@ namespace BizHawk.Client.Common
else if (Movie.IsRecording)
{
Movie.CaptureState();
if (MultiTrack.IsActive)
{
LatchMultitrackPlayerInput(Global.MovieInputSourceAdapter, Global.MultitrackRewiringControllerAdapter);
@ -430,7 +423,7 @@ namespace BizHawk.Client.Common
if (result == LoadStateResult.Pass)
{
Global.Emulator.ClearSaveRam();
Movie.StartRecording();
Movie.StartNewRecording();
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.LoadLogFromSavestateText(reader, MultiTrack.IsActive);
@ -446,7 +439,7 @@ namespace BizHawk.Client.Common
if (newresult == LoadStateResult.Pass)
{
Global.Emulator.ClearSaveRam();
Movie.StartRecording();
Movie.StartNewRecording();
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.LoadLogFromSavestateText(reader, MultiTrack.IsActive);

View File

@ -34,12 +34,12 @@ namespace BizHawk.Client.Common
public override string ToString()
{
StringBuilder sb = new StringBuilder("subtitle ");
var sb = new StringBuilder("subtitle ");
sb
.Append(Frame.ToString()).Append(" ")
.Append(X.ToString()).Append(" ")
.Append(Y.ToString()).Append(" ")
.Append(Duration.ToString()).Append(" ")
.Append(Frame).Append(" ")
.Append(X).Append(" ")
.Append(Y).Append(" ")
.Append(Duration).Append(" ")
.Append(String.Format("{0:X8}", Color)).Append(" ")
.Append(Message);

View File

@ -1,10 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Drawing;
using System.IO;
namespace BizHawk.Client.Common
{
@ -23,14 +20,14 @@ namespace BizHawk.Client.Common
{
var subparts = subtitleStr.Split(' ');
//Unfortunately I made the file format space delminated so this hack is necessary to get the message
string message = String.Empty;
for (int i = 6; i < subparts.Length; i++)
// Unfortunately I made the file format space delminated so this hack is necessary to get the message
var message = String.Empty;
for (var i = 6; i < subparts.Length; i++)
{
message += subparts[i] + ' ';
}
Add(new Subtitle()
Add(new Subtitle
{
Frame = int.Parse(subparts[1]),
X = int.Parse(subparts[2]),

View File

@ -46,13 +46,12 @@ namespace BizHawk.Client.EmuHawk
if (record)
{
Global.Emulator.ClearSaveRam();
Global.MovieSession.Movie.StartRecording();
Global.MovieSession.Movie.StartNewRecording();
Global.ReadOnly = false;
}
else
{
Global.Emulator.ClearSaveRam();
Global.MovieSession.Movie.StartPlayback();
Global.MovieSession.Movie.StartNewPlayback();
}
SetMainformMovieInfo();
GlobalWin.Tools.Restart<TAStudio>();
@ -118,8 +117,7 @@ namespace BizHawk.Client.EmuHawk
LoadStateFile(Global.MovieSession.Movie.Filename, Path.GetFileName(Global.MovieSession.Movie.Filename));
Global.Emulator.ResetCounters();
}
Global.Emulator.ClearSaveRam();
Global.MovieSession.Movie.StartPlayback();
Global.MovieSession.Movie.StartNewPlayback();
SetMainformMovieInfo();
GlobalWin.OSD.AddMessage("Replaying movie file in read-only mode");
Global.ReadOnly = true;

View File

@ -731,7 +731,7 @@ namespace BizHawk.Client.EmuHawk
public void LoadTAStudio()
{
Global.MovieSession.EditorMode = true;
//Global.MovieSession.EditorMode = true;
GlobalWin.Tools.Load<TAStudio>();
}

View File

@ -18,8 +18,6 @@ namespace BizHawk.Client.EmuHawk
//TODO
//Allow relative paths in record textbox
private Movie _movieToRecord;
public RecordMovie()
{
InitializeComponent();
@ -55,7 +53,6 @@ namespace BizHawk.Client.EmuHawk
private void OK_Click(object sender, EventArgs e)
{
var path = MakePath();
if (!String.IsNullOrWhiteSpace(path))
{
var test = new FileInfo(path);
@ -68,7 +65,33 @@ namespace BizHawk.Client.EmuHawk
}
}
_movieToRecord = new Movie(path);
Movie _movieToRecord;
if (StartFromCombo.SelectedItem.ToString() == "Now")
{
_movieToRecord = new Movie(path, startsFromSavestate: true);
var temppath = path;
var writer = new StreamWriter(temppath);
Global.Emulator.SaveStateText(writer);
writer.Close();
var file = new FileInfo(temppath);
using (var sr = file.OpenText())
{
string str;
while ((str = sr.ReadLine()) != null)
{
if (!String.IsNullOrWhiteSpace(str))
{
_movieToRecord.Header.Comments.Add(str);
}
}
}
}
else
{
_movieToRecord = new Movie(path);
}
//Header
_movieToRecord.Header.SetHeaderLine(MovieHeader.AUTHOR, AuthorBox.Text);
@ -155,27 +178,6 @@ namespace BizHawk.Client.EmuHawk
}
}
if (StartFromCombo.SelectedItem.ToString() == "Now")
{
_movieToRecord.StartsFromSavestate = true;
var temppath = path;
var writer = new StreamWriter(temppath);
Global.Emulator.SaveStateText(writer);
writer.Close();
var file = new FileInfo(temppath);
using (var sr = file.OpenText())
{
string str;
while ((str = sr.ReadLine()) != null)
{
if (!String.IsNullOrWhiteSpace(str))
{
_movieToRecord.Header.Comments.Add(str);
}
}
}
}
GlobalWin.MainForm.StartNewMovie(_movieToRecord, true);
Global.Config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked;

View File

@ -90,27 +90,27 @@ namespace BizHawk.Client.EmuHawk
private void TASView_QueryItemBkColor(int index, int column, ref Color color)
{
if (index == 0 && Global.MovieSession.Movie.StateFirstIndex == 0)
{
if (color != Color.LightGreen)
{
color = Color.LightGreen; //special case for frame 0. Normally we need to go back an extra frame, but for frame 0 we can reload the rom.
}
}
else if (Global.MovieSession.Movie.FrameLagged(index))
{
if (color != Color.Pink)
{
color = Color.Pink;
}
}
else if (index > Global.MovieSession.Movie.StateFirstIndex && index <= Global.MovieSession.Movie.StateLastIndex)
{
if (color != Color.LightGreen)
{
color = Color.LightGreen;
}
}
//if (index == 0 && Global.MovieSession.Movie.StateFirstIndex == 0)
//{
// if (color != Color.LightGreen)
// {
// color = Color.LightGreen; //special case for frame 0. Normally we need to go back an extra frame, but for frame 0 we can reload the rom.
// }
//}
//else if (Global.MovieSession.Movie.FrameLagged(index))
//{
// if (color != Color.Pink)
// {
// color = Color.Pink;
// }
//}
//else if (index > Global.MovieSession.Movie.StateFirstIndex && index <= Global.MovieSession.Movie.StateLastIndex)
//{
// if (color != Color.LightGreen)
// {
// color = Color.LightGreen;
// }
//}
if (index == Global.Emulator.Frame)
{
if (color != Color.LightBlue)
@ -137,11 +137,11 @@ namespace BizHawk.Client.EmuHawk
private void DisplayList()
{
TASView.ItemCount = Global.MovieSession.Movie.RawFrames;
if (Global.MovieSession.Movie.Frames == Global.Emulator.Frame && Global.MovieSession.Movie.StateLastIndex == Global.Emulator.Frame - 1)
{
//If we're at the end of the movie add one to show the cursor as a blank frame
TASView.ItemCount++;
}
//if (Global.MovieSession.Movie.Frames == Global.Emulator.Frame && Global.MovieSession.Movie.StateLastIndex == Global.Emulator.Frame - 1)
//{
// //If we're at the end of the movie add one to show the cursor as a blank frame
// TASView.ItemCount++;
//}
TASView.ensureVisible(Global.Emulator.Frame - 1);
}
@ -415,17 +415,17 @@ namespace BizHawk.Client.EmuHawk
private void TASView_DoubleClick(object sender, EventArgs e)
{
if (TASView.selectedItem <= Global.MovieSession.Movie.StateLastIndex)
{
stopOnFrame = 0;
RewindToFrame(TASView.selectedItem);
}
else
{
RewindToFrame(Global.MovieSession.Movie.StateLastIndex);
stopOnFrame = TASView.selectedItem;
GlobalWin.MainForm.PressFrameAdvance = true;
}
//if (TASView.selectedItem <= Global.MovieSession.Movie.StateLastIndex)
//{
// stopOnFrame = 0;
// RewindToFrame(TASView.selectedItem);
//}
//else
//{
// RewindToFrame(Global.MovieSession.Movie.StateLastIndex);
// stopOnFrame = TASView.selectedItem;
// GlobalWin.MainForm.PressFrameAdvance = true;
//}
UpdateValues();
}
@ -540,54 +540,54 @@ namespace BizHawk.Client.EmuHawk
}
else if (frame <= Global.Emulator.Frame)
{
if (frame <= Global.MovieSession.Movie.StateFirstIndex)
{
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.InitState)));
if (Global.MovieSession.Movie.IsRecording)
{
Global.MovieSession.Movie.StartPlayback();
GlobalWin.MainForm.RestoreReadWriteOnStop = true;
}
}
else
{
if (frame == 0)
{
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.InitState)));
}
else
{
//frame-1 because we need to go back an extra frame and then run a frame, otherwise the display doesn't get updated.
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.GetState(frame - 1))));
GlobalWin.MainForm.UpdateFrame = true;
}
}
}
else if (frame <= Global.MovieSession.Movie.StateLastIndex)
{
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.GetState(frame - 1))));
GlobalWin.MainForm.UpdateFrame = true;
}
else
{
GlobalWin.MainForm.UnpauseEmulator();
//if (frame <= Global.MovieSession.Movie.StateFirstIndex)
//{
// Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.InitState)));
// if (Global.MovieSession.Movie.IsRecording)
// {
// Global.MovieSession.Movie.StartPlayback();
// GlobalWin.MainForm.RestoreReadWriteOnStop = true;
// }
//}
//else
//{
// if (frame == 0)
// {
// Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.InitState)));
// }
// else
// {
// //frame-1 because we need to go back an extra frame and then run a frame, otherwise the display doesn't get updated.
// Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.GetState(frame - 1))));
// GlobalWin.MainForm.UpdateFrame = true;
// }
//}
}
//else if (frame <= Global.MovieSession.Movie.StateLastIndex)
//{
// Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Global.MovieSession.Movie.GetState(frame - 1))));
// GlobalWin.MainForm.UpdateFrame = true;
//}
//else
//{
// GlobalWin.MainForm.UnpauseEmulator();
//}
}
public void DeleteFrame(int frame)
{
if (frame <= Global.MovieSession.Movie.StateLastIndex)
{
if (frame <= Global.MovieSession.Movie.StateFirstIndex)
{
RewindToFrame(0);
}
else
{
RewindToFrame(frame);
}
}
Global.MovieSession.Movie.DeleteFrame(frame);
//if (frame <= Global.MovieSession.Movie.StateLastIndex)
//{
// if (frame <= Global.MovieSession.Movie.StateFirstIndex)
// {
// RewindToFrame(0);
// }
// else
// {
// RewindToFrame(frame);
// }
//}
//Global.MovieSession.Movie.DeleteFrame(frame);
}
private void DeleteFrames()

View File

@ -65,7 +65,7 @@
this.OK.TabIndex = 35;
this.OK.Text = "&Poke";
this.OK.UseVisualStyleBackColor = true;
this.OK.Click += new System.EventHandler(this.OK_Click);
this.OK.Click += new System.EventHandler(this.Ok_Click);
//
// Cancel
//

View File

@ -10,8 +10,7 @@ namespace BizHawk.Client.EmuHawk
{
public partial class RamPoke : Form
{
//TODO: don't use textboxes as labels
// TODO: don't use textboxes as labels
private List<Watch> _watchList = new List<Watch>();
public Point InitialLocation = new Point(0, 0);
@ -34,7 +33,7 @@ namespace BizHawk.Client.EmuHawk
private void RamPoke_Load(object sender, EventArgs e)
{
_watchList = _watchList.Where(x => !x.IsSeparator).ToList(); //Weed out separators just in case
_watchList = _watchList.Where(x => !x.IsSeparator).ToList(); // Weed out separators just in case
if (_watchList.Count == 0)
{
@ -58,10 +57,11 @@ namespace BizHawk.Client.EmuHawk
UnSupportedConfiguration();
}
}
AddressBox.SetHexProperties(_watchList[0].Domain.Size);
AddressBox.Text = _watchList.Select(a => a.AddressString).Distinct().Aggregate((addrStr, nextStr) => addrStr + ("," + nextStr));
ValueHexLabel.Text = _watchList[0].Type == Watch.DisplayType.Hex ? "0x" : String.Empty;
ValueBox.Text = _watchList[0].ValueString.Replace(" ", "");
ValueBox.Text = _watchList[0].ValueString.Replace(" ", String.Empty);
DomainLabel.Text = _watchList[0].Domain.Name;
SizeLabel.Text = _watchList[0].Size.ToString();
DisplayTypeLabel.Text = Watch.DisplayTypeToString(_watchList[0].Type);
@ -83,14 +83,9 @@ namespace BizHawk.Client.EmuHawk
Close();
}
private void OK_Click(object sender, EventArgs e)
private void Ok_Click(object sender, EventArgs e)
{
var success = true;
foreach (var watch in _watchList.Where(watch => !watch.Poke(ValueBox.Text)))
{
success = false;
}
var success = _watchList.All(watch => watch.Poke(ValueBox.Text));
OutputLabel.Text = success ? "Value successfully written."
: "An error occured when writing Value.";
}

File diff suppressed because it is too large Load Diff

View File

@ -2,24 +2,23 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Globalization;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// A winform designed to search through ram values
/// A form designed to search through ram values
/// </summary>
public partial class RamSearch : Form, IToolForm
{
//TODO: DoSearch grabs the state of widgets and passes it to the engine before running, so rip out code that is attempting to keep the state up to date through change events
// TODO: DoSearch grabs the state of widgets and passes it to the engine before running, so rip out code that is attempting to keep the state up to date through change events
private readonly Dictionary<string, int> _defaultColumnWidths = new Dictionary<string, int>
{
{ WatchList.ADDRESS, 60 },
@ -34,20 +33,27 @@ namespace BizHawk.Client.EmuHawk
private RamSearchEngine _searches;
private RamSearchEngine.Settings _settings;
private int _defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
private int _defaultWidth;
private int _defaultHeight;
private string _sortedColumn = String.Empty;
private bool _sortReverse;
private bool _forcePreviewClear;
private bool _autoSearch;
private bool _dropdownDontfire; //Used as a hack to get around lame .net dropdowns, there's no way to set their index without firing the selectedindexchanged event!
private bool _dropdownDontfire; // Used as a hack to get around lame .net dropdowns, there's no way to set their index without firing the selectedindexchanged event!
public const int MaxDetailedSize = (1024 * 1024); //1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user
public const int MaxSupportedSize = (1024 * 1024 * 64); //64mb, semi-arbituary decision, sets the maximum size ram search will support (as it will crash beyond this)
public const int MaxDetailedSize = 1024 * 1024; // 1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user
public const int MaxSupportedSize = 1024 * 1024 * 64; // 64mb, semi-arbituary decision, sets the maximum size ram search will support (as it will crash beyond this)
public bool AskSave() { return true; }
public bool UpdateBefore { get { return false; } }
public bool AskSave()
{
return true;
}
public bool UpdateBefore
{
get { return false; }
}
#region Initialize, Load, and Save
@ -187,8 +193,7 @@ namespace BizHawk.Client.EmuHawk
private void LoadConfigSettings()
{
//Size and Positioning
_defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Global.Config.RamSearchSaveWindowPosition && Global.Config.RamSearchWndx >= 0 && Global.Config.RamSearchWndy >= 0)
@ -228,7 +233,10 @@ namespace BizHawk.Client.EmuHawk
public void Restart()
{
if (!IsHandleCreated || IsDisposed) return;
if (!IsHandleCreated || IsDisposed)
{
return;
}
_settings.Domain = Global.Emulator.MemoryDomains.MainMemory;
MessageLabel.Text = "Search restarted";
@ -515,13 +523,13 @@ namespace BizHawk.Client.EmuHawk
private void ColumnPositions()
{
var Columns = Global.Config.RamSearchColumnIndexes
var columns = Global.Config.RamSearchColumnIndexes
.Where(x => WatchListView.Columns.ContainsKey(x.Key))
.OrderBy(x => x.Value).ToList();
for (var i = 0; i < Columns.Count; i++)
for (var i = 0; i < columns.Count; i++)
{
WatchListView.Columns[Columns[i].Key].DisplayIndex = i;
WatchListView.Columns[columns[i].Key].DisplayIndex = i;
}
}
@ -575,6 +583,7 @@ namespace BizHawk.Client.EmuHawk
{
SpecificValueBox.Text = "0";
}
SpecificValueBox.Type = _settings.Type = type;
_searches.SetType(type);
@ -610,7 +619,7 @@ namespace BizHawk.Client.EmuHawk
}
_dropdownDontfire = true;
switch(size)
switch (size)
{
case Watch.WatchSize.Byte:
SizeDropdown.SelectedIndex = 0;
@ -622,6 +631,7 @@ namespace BizHawk.Client.EmuHawk
SizeDropdown.SelectedIndex = 2;
break;
}
PopulateTypeDropDown();
_dropdownDontfire = false;
SpecificValueBox.Type = _settings.Type;
@ -770,14 +780,11 @@ namespace BizHawk.Client.EmuHawk
private void AddToRamWatch()
{
if (SelectedIndices.Count > 0)
var watches = SelectedWatches.ToList();
if (watches.Any())
{
GlobalWin.Tools.LoadRamWatch(true);
foreach(var watch in SelectedWatches)
{
GlobalWin.Tools.RamWatch.AddWatch(watch);
}
watches.ForEach(GlobalWin.Tools.RamWatch.AddWatch);
if (Global.Config.RamSearchAlwaysExcludeRamWatch)
{
RemoveRamWatchesFromList();
@ -850,7 +857,7 @@ namespace BizHawk.Client.EmuHawk
private void GoToSpecifiedAddress()
{
WatchListView.SelectedIndices.Clear();
var prompt = new InputPrompt {Text = "Go to Address", _Location = GetPromptPoint()};
var prompt = new InputPrompt { Text = "Go to Address", _Location = GetPromptPoint() };
prompt.SetMessage("Enter a hexadecimal value");
prompt.ShowHawkDialog();
@ -897,7 +904,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!String.IsNullOrWhiteSpace(_currentFileName))
{
var watches = new WatchList(_settings.Domain) {CurrentFileName = _currentFileName};
var watches = new WatchList(_settings.Domain) { CurrentFileName = _currentFileName };
for (var i = 0; i < _searches.Count; i++)
{
watches.Add(_searches[i]);
@ -925,7 +932,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveAsMenuItem_Click(object sender, EventArgs e)
{
var watches = new WatchList(_settings.Domain) {CurrentFileName = _currentFileName};
var watches = new WatchList(_settings.Domain) { CurrentFileName = _currentFileName };
for (var i = 0; i < _searches.Count; i++)
{
watches.Add(_searches[i]);
@ -968,9 +975,9 @@ namespace BizHawk.Client.EmuHawk
private void SizeSubMenu_DropDownOpened(object sender, EventArgs e)
{
_1ByteMenuItem.Checked = _settings.Size == Watch.WatchSize.Byte;
_2ByteMenuItem.Checked = _settings.Size == Watch.WatchSize.Word;
_4ByteMenuItem.Checked = _settings.Size == Watch.WatchSize.DWord;
ByteMenuItem.Checked = _settings.Size == Watch.WatchSize.Byte;
WordMenuItem.Checked = _settings.Size == Watch.WatchSize.Word;
DWordMenuItem.Checked = _settings.Size == Watch.WatchSize.DWord;
}
private void DisplayTypeSubMenu_DropDownOpened(object sender, EventArgs e)
@ -1025,17 +1032,17 @@ namespace BizHawk.Client.EmuHawk
SetToFastMode();
}
private void _1ByteMenuItem_Click(object sender, EventArgs e)
private void ByteMenuItem_Click(object sender, EventArgs e)
{
SetSize(Watch.WatchSize.Byte);
}
private void _2ByteMenuItem_Click(object sender, EventArgs e)
private void WordMenuItem_Click(object sender, EventArgs e)
{
SetSize(Watch.WatchSize.Word);
}
private void _4ByteMenuItem_Click(object sender, EventArgs e)
private void DWordMenuItem_Click_Click(object sender, EventArgs e)
{
SetSize(Watch.WatchSize.DWord);
}
@ -1314,7 +1321,7 @@ namespace BizHawk.Client.EmuHawk
#region ContextMenu and Toolbar
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
private void ListViewContextMenu_Opening(object sender, CancelEventArgs e)
{
DoSearchContextMenuItem.Enabled = _searches.Count > 0;
@ -1329,7 +1336,7 @@ namespace BizHawk.Client.EmuHawk
UnfreezeAllContextMenuItem.Visible = Global.CheatList.ActiveCount > 0;
ContextMenuSeparator3.Visible = (SelectedIndices.Count > 0) || (Global.CheatList.ActiveCount > 0);
ContextMenuSeparator3.Visible = (SelectedIndices.Any()) || (Global.CheatList.ActiveCount > 0);
var allCheats = true;
foreach (var index in SelectedIndices)

View File

@ -120,7 +120,7 @@
<metadata name="SearchMenuItem.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="ListViewContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>457, 17</value>
</metadata>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

View File

@ -89,7 +89,7 @@
this.OK.TabIndex = 30;
this.OK.Text = "Ok";
this.OK.UseVisualStyleBackColor = true;
this.OK.Click += new System.EventHandler(this.OK_Click);
this.OK.Click += new System.EventHandler(this.Ok_Click);
//
// Cancel
//

View File

@ -59,6 +59,7 @@ namespace BizHawk.Client.EmuHawk
SizeDropDown.SelectedItem = SizeDropDown.Items[2];
break;
}
var index = DisplayTypeDropDown.Items.IndexOf(Watch.DisplayTypeToString(_watchList[0].Type));
DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[index];
@ -95,6 +96,7 @@ namespace BizHawk.Client.EmuHawk
{
_watchList.AddRange(watches);
}
_mode = mode;
ToolHelpers.PopulateMemoryDomainDropdown(ref DomainDropDown, domain ?? Global.Emulator.MemoryDomains.MainMemory);
SetTitle();
@ -145,6 +147,7 @@ namespace BizHawk.Client.EmuHawk
DisplayTypeDropDown.Items.AddRange(DWordWatch.ValidTypes.ConvertAll(e => Watch.DisplayTypeToString(e)).ToArray());
break;
}
DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[0];
}
@ -154,7 +157,7 @@ namespace BizHawk.Client.EmuHawk
{
if (_watchList.Count > 1)
{
//Aggregate state
// Aggregate state
var hasBig = _watchList.Any(x => x.BigEndian);
var hasLittle = _watchList.Any(x => x.BigEndian == false);
@ -192,7 +195,7 @@ namespace BizHawk.Client.EmuHawk
Close();
}
private void OK_Click(object sender, EventArgs e)
private void Ok_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
@ -217,6 +220,7 @@ namespace BizHawk.Client.EmuHawk
_watchList.Add(new DWordWatch(domain, address, type, bigendian, notes));
break;
}
break;
case Mode.Edit:
DoEdit();
@ -235,6 +239,7 @@ namespace BizHawk.Client.EmuHawk
watch.Notes,
watch.BigEndian));
}
DoEdit();
break;
}
@ -251,10 +256,10 @@ namespace BizHawk.Client.EmuHawk
if (_changedSize)
{
for(var i = 0; i < _watchList.Count; i++)
for (var i = 0; i < _watchList.Count; i++)
{
var size = Watch.WatchSize.Byte;
switch(SizeDropDown.SelectedIndex)
switch (SizeDropDown.SelectedIndex)
{
case 0:
size = Watch.WatchSize.Byte;
@ -266,6 +271,7 @@ namespace BizHawk.Client.EmuHawk
size = Watch.WatchSize.DWord;
break;
}
_watchList[i] = Watch.GenerateWatch(
_watchList[i].Domain,
_watchList.Count == 1 ? AddressBox.ToRawInt() ?? 0 : _watchList[i].Address ?? 0,
@ -276,10 +282,12 @@ namespace BizHawk.Client.EmuHawk
);
}
}
if (_changedDisplayType)
{
_watchList.ForEach(x => x.Type = Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()));
}
if (BigEndianCheckBox.CheckState != CheckState.Indeterminate)
{
_watchList.ForEach(x => x.BigEndian = BigEndianCheckBox.Checked);