2013-10-01 13:02:19 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Drawing ;
2013-10-02 15:09:49 +00:00
using System.IO ;
2013-10-01 13:02:19 +00:00
using System.Linq ;
using System.Windows.Forms ;
2014-09-01 18:43:41 +00:00
using BizHawk.Emulation.Common ;
using BizHawk.Emulation.Common.IEmulatorExtensions ;
2013-11-13 23:36:21 +00:00
using BizHawk.Emulation.Cores.Nintendo.SNES ;
using BizHawk.Emulation.Cores.Sega.Genesis ;
2014-07-28 02:10:31 +00:00
2014-09-01 18:43:41 +00:00
using BizHawk.Client.Common ;
2014-07-28 01:51:11 +00:00
using BizHawk.Client.EmuHawk.ToolExtensions ;
2014-07-28 02:10:31 +00:00
using BizHawk.Client.EmuHawk.WinFormExtensions ;
2013-10-05 00:38:46 +00:00
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2013-10-01 13:02:19 +00:00
{
2013-11-02 20:48:24 +00:00
public partial class Cheats : Form , IToolForm
2013-10-01 13:02:19 +00:00
{
2014-12-31 23:28:50 +00:00
private const string NAME = "NamesColumn" ;
private const string ADDRESS = "AddressColumn" ;
private const string VALUE = "ValueColumn" ;
private const string COMPARE = "CompareColumn" ;
private const string ON = "OnColumn" ;
private const string DOMAIN = "DomainColumn" ;
private const string SIZE = "SizeColumn" ;
private const string ENDIAN = "EndianColumn" ;
private const string TYPE = "DisplayTypeColumn" ;
2013-10-04 16:06:08 +00:00
2013-11-25 00:55:56 +00:00
private int _defaultWidth ;
private int _defaultHeight ;
2014-01-30 15:51:07 +00:00
private string _sortedColumn = string . Empty ;
2013-11-25 00:55:56 +00:00
private bool _sortReverse ;
2013-10-04 16:06:08 +00:00
2013-10-06 20:02:34 +00:00
public Cheats ( )
2013-10-01 13:02:19 +00:00
{
InitializeComponent ( ) ;
2014-12-31 22:16:22 +00:00
Settings = new CheatsSettings ( ) ;
2014-09-01 18:43:41 +00:00
2013-11-05 16:37:05 +00:00
Closing + = ( o , e ) = >
{
2014-08-19 19:24:17 +00:00
if ( AskSaveChanges ( ) )
2013-11-05 16:37:05 +00:00
{
SaveConfigSettings ( ) ;
}
else
{
e . Cancel = true ;
}
} ;
2013-10-04 01:35:58 +00:00
CheatListView . QueryItemText + = CheatListView_QueryItemText ;
CheatListView . QueryItemBkColor + = CheatListView_QueryItemBkColor ;
CheatListView . VirtualMode = true ;
2013-10-04 16:06:08 +00:00
2014-01-30 15:51:07 +00:00
_sortedColumn = string . Empty ;
2013-10-04 16:06:08 +00:00
_sortReverse = false ;
2013-10-01 13:02:19 +00:00
}
2015-01-01 00:11:39 +00:00
[RequiredService]
private IMemoryDomains Core { get ; set ; }
[ConfigPersist]
public CheatsSettings Settings { get ; set ; }
public bool UpdateBefore { get { return false ; } }
2013-10-06 16:40:51 +00:00
public void UpdateValues ( )
{
2014-07-25 01:55:21 +00:00
// Do nothing
}
public void FastUpdate ( )
{
// Do nothing
2013-10-06 16:40:51 +00:00
}
public void Restart ( )
{
2015-01-14 21:55:48 +00:00
CheatEditor . MemoryDomains = Core ;
2013-10-06 16:40:51 +00:00
}
2013-11-07 20:33:29 +00:00
/// <summary>
/// Tools that want to refresh the cheats list should call this, not UpdateValues
/// </summary>
public void UpdateDialog ( )
2013-10-02 15:09:49 +00:00
{
2013-10-20 18:02:43 +00:00
CheatListView . ItemCount = Global . CheatList . Count ;
2013-11-25 02:08:45 +00:00
TotalLabel . Text = Global . CheatList . CheatCount
2013-10-20 18:02:43 +00:00
+ ( Global . CheatList . CheatCount = = 1 ? " cheat " : " cheats " )
2013-11-25 02:08:45 +00:00
+ Global . CheatList . ActiveCount + " active" ;
2013-10-02 15:09:49 +00:00
}
public void LoadFileFromRecent ( string path )
{
2014-08-19 19:24:17 +00:00
var askResult = ! Global . CheatList . Changes | | AskSaveChanges ( ) ;
2014-01-01 02:02:23 +00:00
if ( askResult )
2013-10-02 15:09:49 +00:00
{
2014-01-01 02:02:23 +00:00
var loadResult = Global . CheatList . Load ( path , append : false ) ;
if ( ! loadResult )
2013-10-02 15:09:49 +00:00
{
2014-07-28 01:51:11 +00:00
Global . Config . RecentWatches . HandleLoadError ( path ) ;
2013-10-02 15:09:49 +00:00
}
else
{
Global . Config . RecentWatches . Add ( path ) ;
2013-11-07 20:33:29 +00:00
UpdateDialog ( ) ;
2013-10-04 23:50:26 +00:00
UpdateMessageLabel ( ) ;
2013-10-02 15:09:49 +00:00
}
}
}
2013-10-04 23:50:26 +00:00
private void UpdateMessageLabel ( bool saved = false )
2013-10-04 22:21:09 +00:00
{
2014-01-01 02:02:23 +00:00
MessageLabel . Text = saved
? Path . GetFileName ( Global . CheatList . CurrentFileName ) + " saved."
2014-01-30 15:51:07 +00:00
: Path . GetFileName ( Global . CheatList . CurrentFileName ) + ( Global . CheatList . Changes ? " *" : string . Empty ) ;
2013-10-04 22:21:09 +00:00
}
2014-08-19 19:24:17 +00:00
public bool AskSaveChanges ( )
2013-10-02 15:09:49 +00:00
{
2013-10-20 18:02:43 +00:00
if ( Global . CheatList . Changes )
2013-10-02 15:09:49 +00:00
{
2013-11-03 16:07:58 +00:00
GlobalWin . Sound . StopSound ( ) ;
2013-11-25 02:08:45 +00:00
var result = MessageBox . Show ( "Save Changes?" , "Cheats" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question , MessageBoxDefaultButton . Button3 ) ;
2013-11-03 16:07:58 +00:00
GlobalWin . Sound . StartSound ( ) ;
2013-10-02 15:09:49 +00:00
if ( result = = DialogResult . Yes )
{
2013-10-20 18:02:43 +00:00
Global . CheatList . Save ( ) ;
2013-10-02 15:09:49 +00:00
}
else if ( result = = DialogResult . No )
{
2013-11-05 16:37:05 +00:00
Global . CheatList . Changes = false ;
2013-10-02 15:09:49 +00:00
return true ;
}
else if ( result = = DialogResult . Cancel )
{
return false ;
}
}
return true ;
}
2013-11-25 02:08:45 +00:00
private void LoadFile ( FileSystemInfo file , bool append )
2013-10-03 15:27:51 +00:00
{
if ( file ! = null )
{
2013-11-25 02:08:45 +00:00
var result = true ;
2013-10-20 18:02:43 +00:00
if ( Global . CheatList . Changes )
2013-10-03 15:27:51 +00:00
{
2014-08-19 19:24:17 +00:00
result = AskSaveChanges ( ) ;
2013-10-03 15:27:51 +00:00
}
if ( result )
{
2013-10-20 18:02:43 +00:00
Global . CheatList . Load ( file . FullName , append ) ;
2013-11-07 20:33:29 +00:00
UpdateDialog ( ) ;
2013-10-05 01:30:59 +00:00
UpdateMessageLabel ( ) ;
2013-10-20 18:02:43 +00:00
Global . Config . RecentCheats . Add ( Global . CheatList . CurrentFileName ) ;
2013-10-03 15:27:51 +00:00
}
}
}
2013-11-25 02:08:45 +00:00
private static bool SaveAs ( )
2013-10-25 00:57:23 +00:00
{
var file = ToolHelpers . GetCheatSaveFileFromUser ( Global . CheatList . CurrentFileName ) ;
2013-11-25 02:08:45 +00:00
return file ! = null & & Global . CheatList . SaveFile ( file . FullName ) ;
2013-10-25 00:57:23 +00:00
}
2014-12-13 22:57:51 +00:00
private void Cheats_Load ( object sender , EventArgs e )
2013-10-01 13:02:19 +00:00
{
2014-12-31 22:16:22 +00:00
TopMost = Settings . TopMost ;
2015-01-14 21:55:48 +00:00
CheatEditor . MemoryDomains = Core ;
2013-10-04 16:06:08 +00:00
LoadConfigSettings ( ) ;
2013-10-06 16:40:51 +00:00
ToggleGameGenieButton ( ) ;
2013-10-05 20:22:55 +00:00
CheatEditor . SetAddEvent ( AddCheat ) ;
2014-01-01 15:50:33 +00:00
CheatEditor . SetEditEvent ( EditCheat ) ;
2013-11-19 19:28:37 +00:00
UpdateDialog ( ) ;
2014-12-31 23:48:39 +00:00
2015-01-01 01:21:06 +00:00
CheatsMenu . Items . Add ( Settings . Columns . GenerateColumnsMenu ( ColumnToggleCallback ) ) ;
}
private void ColumnToggleCallback ( )
{
SaveColumnInfo ( ) ;
LoadColumnInfo ( ) ;
2013-10-05 20:22:55 +00:00
}
2013-10-06 16:40:51 +00:00
private void ToggleGameGenieButton ( )
{
GameGenieToolbarSeparator . Visible =
LoadGameGenieToolbarItem . Visible =
2015-01-01 00:11:39 +00:00
GlobalWin . Tools . GameGenieAvailable ;
2013-10-06 16:40:51 +00:00
}
2013-10-05 20:22:55 +00:00
private void AddCheat ( )
{
2013-11-05 23:14:22 +00:00
Global . CheatList . Add ( CheatEditor . Cheat ) ;
2013-11-07 20:33:29 +00:00
UpdateDialog ( ) ;
2013-11-05 19:33:06 +00:00
UpdateMessageLabel ( ) ;
2013-10-02 15:09:49 +00:00
}
2014-01-01 15:50:33 +00:00
private void EditCheat ( )
{
Global . CheatList . Remove ( CheatEditor . OriginalCheat ) ;
AddCheat ( ) ;
}
2013-10-04 01:35:58 +00:00
public void SaveConfigSettings ( )
{
2013-10-05 20:22:55 +00:00
SaveColumnInfo ( ) ;
2014-12-31 22:16:22 +00:00
Settings . Wndx = Location . X ;
Settings . Wndy = Location . Y ;
Settings . Width = Right - Left ;
Settings . Height = Bottom - Top ;
2013-10-04 01:35:58 +00:00
}
2013-10-04 16:06:08 +00:00
private void LoadConfigSettings ( )
{
2013-12-22 20:25:43 +00:00
_defaultWidth = Size . Width ;
2013-11-25 00:55:56 +00:00
_defaultHeight = Size . Height ;
2013-10-04 16:06:08 +00:00
2014-12-31 22:16:22 +00:00
if ( Settings . UseWindowPosition )
2013-10-04 16:06:08 +00:00
{
2014-12-31 22:16:22 +00:00
Location = Settings . WindowPosition ;
2013-10-04 16:06:08 +00:00
}
2014-12-31 22:16:22 +00:00
if ( Settings . UseWindowSize )
2013-10-04 16:06:08 +00:00
{
2014-12-31 22:16:22 +00:00
Size = Settings . WindowSize ;
2013-10-04 16:06:08 +00:00
}
LoadColumnInfo ( ) ;
}
private void LoadColumnInfo ( )
{
CheatListView . Columns . Clear ( ) ;
2014-12-31 23:28:50 +00:00
2015-01-01 01:21:06 +00:00
var columns = Settings . Columns
. Where ( c = > c . Visible )
. OrderBy ( c = > c . Index ) ;
2014-06-20 17:41:40 +00:00
2015-01-01 01:21:06 +00:00
foreach ( var column in columns )
2014-06-20 17:41:40 +00:00
{
2015-01-01 01:21:06 +00:00
CheatListView . AddColumn ( column ) ;
2014-06-20 17:41:40 +00:00
}
2013-10-04 16:06:08 +00:00
}
2014-01-01 02:02:23 +00:00
private void SaveColumnInfo ( )
{
2014-12-31 23:28:50 +00:00
foreach ( ColumnHeader column in CheatListView . Columns )
2014-01-01 02:02:23 +00:00
{
2014-12-31 23:28:50 +00:00
Settings . Columns [ column . Name ] . Index = column . DisplayIndex ;
Settings . Columns [ column . Name ] . Width = column . Width ;
2014-01-01 02:02:23 +00:00
}
}
private void DoColumnToggle ( string column )
{
2014-12-31 23:28:50 +00:00
Settings . Columns [ column ] . Visible ^ = true ;
2014-01-01 02:02:23 +00:00
SaveColumnInfo ( ) ;
LoadColumnInfo ( ) ;
}
2013-10-04 01:35:58 +00:00
private void CheatListView_QueryItemText ( int index , int column , out string text )
{
2014-01-30 15:51:07 +00:00
text = string . Empty ;
2013-10-20 18:02:43 +00:00
if ( index > = Global . CheatList . Count | | Global . CheatList [ index ] . IsSeparator )
2013-10-04 01:35:58 +00:00
{
return ;
}
2013-10-04 16:06:08 +00:00
2013-11-25 02:08:45 +00:00
var columnName = CheatListView . Columns [ column ] . Name ;
2013-10-04 16:06:08 +00:00
switch ( columnName )
{
case NAME :
2013-10-20 18:02:43 +00:00
text = Global . CheatList [ index ] . Name ;
2013-10-04 16:06:08 +00:00
break ;
case ADDRESS :
2013-10-20 18:02:43 +00:00
text = Global . CheatList [ index ] . AddressStr ;
2013-10-04 16:06:08 +00:00
break ;
case VALUE :
2013-10-20 18:02:43 +00:00
text = Global . CheatList [ index ] . ValueStr ;
2013-10-04 16:06:08 +00:00
break ;
case COMPARE :
2013-10-20 18:02:43 +00:00
text = Global . CheatList [ index ] . CompareStr ;
2013-10-04 16:06:08 +00:00
break ;
case ON :
2014-01-30 15:51:07 +00:00
text = Global . CheatList [ index ] . Enabled ? "*" : string . Empty ;
2013-10-04 16:06:08 +00:00
break ;
case DOMAIN :
2013-10-20 18:02:43 +00:00
text = Global . CheatList [ index ] . Domain . Name ;
2013-10-04 16:06:08 +00:00
break ;
2013-10-05 03:40:36 +00:00
case SIZE :
2013-10-20 18:02:43 +00:00
text = Global . CheatList [ index ] . Size . ToString ( ) ;
2013-10-05 03:40:36 +00:00
break ;
case ENDIAN :
2013-11-25 00:55:56 +00:00
text = ( Global . CheatList [ index ] . BigEndian ? ? false ) ? "Big" : "Little" ;
2013-10-05 03:40:36 +00:00
break ;
case TYPE :
2013-10-20 18:02:43 +00:00
text = Watch . DisplayTypeToString ( Global . CheatList [ index ] . Type ) ;
2013-10-05 03:40:36 +00:00
break ;
2013-10-04 16:06:08 +00:00
}
2013-10-04 01:35:58 +00:00
}
private void CheatListView_QueryItemBkColor ( int index , int column , ref Color color )
{
2013-10-20 18:02:43 +00:00
if ( index < Global . CheatList . Count )
2013-10-04 01:35:58 +00:00
{
2013-10-20 18:02:43 +00:00
if ( Global . CheatList [ index ] . IsSeparator )
2013-10-04 01:35:58 +00:00
{
2013-10-04 16:06:08 +00:00
color = BackColor ;
2013-10-04 01:35:58 +00:00
}
2013-10-20 18:02:43 +00:00
else if ( Global . CheatList [ index ] . Enabled )
2013-10-04 01:35:58 +00:00
{
color = Color . LightCyan ;
}
2013-10-04 16:06:08 +00:00
}
}
2013-11-25 00:55:56 +00:00
private IEnumerable < int > SelectedIndices
2013-10-04 16:06:08 +00:00
{
2013-11-25 02:08:45 +00:00
get { return CheatListView . SelectedIndices . Cast < int > ( ) ; }
2013-10-04 16:06:08 +00:00
}
2013-10-05 03:40:36 +00:00
2013-11-25 00:55:56 +00:00
private IEnumerable < Cheat > SelectedItems
2013-10-04 16:06:08 +00:00
{
2013-11-25 00:55:56 +00:00
get { return SelectedIndices . Select ( index = > Global . CheatList [ index ] ) ; }
2013-10-04 16:06:08 +00:00
}
2013-11-25 00:55:56 +00:00
private IEnumerable < Cheat > SelectedCheats
2013-10-04 16:06:08 +00:00
{
2013-11-25 02:08:45 +00:00
get { return SelectedItems . Where ( x = > ! x . IsSeparator ) ; }
2013-10-04 01:35:58 +00:00
}
2013-10-05 20:22:55 +00:00
private void DoSelectedIndexChange ( )
{
2014-03-23 14:10:35 +00:00
if ( ! CheatListView . SelectAllInProgress )
2013-10-05 20:22:55 +00:00
{
2014-03-23 14:10:35 +00:00
if ( SelectedCheats . Any ( ) )
{
var cheat = SelectedCheats . First ( ) ;
CheatEditor . SetCheat ( cheat ) ;
CheatGroupBox . Text = "Editing Cheat " + cheat . Name + " - " + cheat . AddressStr ;
}
else
{
CheatEditor . ClearForm ( ) ;
CheatGroupBox . Text = "New Cheat" ;
}
2013-10-05 20:22:55 +00:00
}
}
2013-11-05 16:37:05 +00:00
private void StartNewList ( )
{
2014-08-19 19:24:17 +00:00
var result = ! Global . CheatList . Changes | | AskSaveChanges ( ) ;
2014-01-01 15:56:47 +00:00
if ( result )
{
Global . CheatList . NewList ( ToolManager . GenerateDefaultCheatFilename ( ) ) ;
UpdateDialog ( ) ;
UpdateMessageLabel ( ) ;
ToggleGameGenieButton ( ) ;
}
2013-11-05 16:37:05 +00:00
}
2013-10-06 16:40:51 +00:00
private void NewList ( )
{
2014-08-19 19:24:17 +00:00
var result = ! Global . CheatList . Changes | | AskSaveChanges ( ) ;
2013-10-06 16:40:51 +00:00
if ( result )
{
2013-11-05 16:37:05 +00:00
StartNewList ( ) ;
2013-10-06 16:40:51 +00:00
}
}
2014-01-30 15:51:07 +00:00
private void RefreshFloatingWindowControl ( )
{
2014-12-31 22:16:22 +00:00
Owner = Settings . FloatingWindow ? null : GlobalWin . MainForm ;
2014-01-30 15:51:07 +00:00
}
2013-10-02 15:09:49 +00:00
#region Events
#region File
private void FileSubMenu_DropDownOpened ( object sender , EventArgs e )
{
2013-10-20 18:02:43 +00:00
SaveMenuItem . Enabled = Global . CheatList . Changes ;
2013-10-02 15:09:49 +00:00
}
2013-10-05 03:40:36 +00:00
private void RecentSubMenu_DropDownOpened ( object sender , EventArgs e )
{
RecentSubMenu . DropDownItems . Clear ( ) ;
2013-10-17 00:21:45 +00:00
RecentSubMenu . DropDownItems . AddRange (
2014-07-28 01:51:11 +00:00
Global . Config . RecentCheats . RecentMenu ( LoadFileFromRecent ) ) ;
2013-10-05 03:40:36 +00:00
}
private void NewMenuItem_Click ( object sender , EventArgs e )
{
2013-10-06 16:40:51 +00:00
NewList ( ) ;
2013-10-05 03:40:36 +00:00
}
private void OpenMenuItem_Click ( object sender , EventArgs e )
{
2013-11-25 02:08:45 +00:00
var append = sender = = AppendMenuItem ;
2013-10-25 00:57:23 +00:00
LoadFile ( ToolHelpers . GetCheatFileFromUser ( Global . CheatList . CurrentFileName ) , append ) ;
2013-10-05 03:40:36 +00:00
}
2013-10-05 01:30:59 +00:00
private void SaveMenuItem_Click ( object sender , EventArgs e )
{
2013-10-20 18:02:43 +00:00
if ( Global . CheatList . Changes )
2013-10-05 01:30:59 +00:00
{
2013-10-20 18:02:43 +00:00
if ( Global . CheatList . Save ( ) )
2013-10-05 01:30:59 +00:00
{
UpdateMessageLabel ( saved : true ) ;
}
}
else
{
SaveAsMenuItem_Click ( sender , e ) ;
}
}
private void SaveAsMenuItem_Click ( object sender , EventArgs e )
{
2013-10-25 00:57:23 +00:00
if ( SaveAs ( ) )
2013-10-05 01:30:59 +00:00
{
UpdateMessageLabel ( saved : true ) ;
}
}
2013-10-02 15:09:49 +00:00
private void ExitMenuItem_Click ( object sender , EventArgs e )
{
Close ( ) ;
}
#endregion
#region Cheats
private void CheatsSubMenu_DropDownOpened ( object sender , EventArgs e )
{
2013-10-04 23:50:26 +00:00
RemoveCheatMenuItem . Enabled =
MoveUpMenuItem . Enabled =
MoveDownMenuItem . Enabled =
2013-10-05 00:38:46 +00:00
ToggleMenuItem . Enabled =
2013-10-04 23:50:26 +00:00
SelectedIndices . Any ( ) ;
2013-10-01 13:02:19 +00:00
2013-10-20 18:02:43 +00:00
DisableAllCheatsMenuItem . Enabled = Global . CheatList . ActiveCount > 0 ;
2013-10-05 00:38:46 +00:00
GameGenieSeparator . Visible =
2015-01-01 00:11:39 +00:00
OpenGameGenieEncoderDecoderMenuItem . Visible =
GlobalWin . Tools . GameGenieAvailable ;
2013-10-04 23:50:26 +00:00
}
private void RemoveCheatMenuItem_Click ( object sender , EventArgs e )
{
2014-01-01 02:02:23 +00:00
var items = SelectedItems . ToList ( ) ;
if ( items . Any ( ) )
{
foreach ( var item in items )
{
Global . CheatList . Remove ( item ) ;
}
CheatListView . SelectedIndices . Clear ( ) ;
UpdateDialog ( ) ;
}
2013-10-01 13:02:19 +00:00
}
2013-10-02 15:09:49 +00:00
2013-10-04 16:06:08 +00:00
private void InsertSeparatorMenuItem_Click ( object sender , EventArgs e )
{
if ( SelectedIndices . Any ( ) )
{
2013-10-20 18:02:43 +00:00
Global . CheatList . Insert ( SelectedIndices . Max ( ) , Cheat . Separator ) ;
2013-10-04 16:06:08 +00:00
}
else
{
2013-10-20 18:02:43 +00:00
Global . CheatList . Add ( Cheat . Separator ) ;
2013-10-04 16:06:08 +00:00
}
2013-10-05 01:30:59 +00:00
2013-11-07 20:33:29 +00:00
UpdateDialog ( ) ;
2013-10-05 01:30:59 +00:00
UpdateMessageLabel ( ) ;
2013-10-04 16:06:08 +00:00
}
2013-10-04 23:50:26 +00:00
private void MoveUpMenuItem_Click ( object sender , EventArgs e )
{
2014-01-01 02:02:23 +00:00
var indices = SelectedIndices . ToList ( ) ;
if ( indices . Count = = 0 | | indices [ 0 ] = = 0 )
{
return ;
}
foreach ( var index in indices )
{
var cheat = Global . CheatList [ index ] ;
Global . CheatList . Remove ( cheat ) ;
Global . CheatList . Insert ( index - 1 , cheat ) ;
}
var newindices = indices . Select ( t = > t - 1 ) . ToList ( ) ;
CheatListView . SelectedIndices . Clear ( ) ;
foreach ( var newi in newindices )
{
CheatListView . SelectItem ( newi , true ) ;
}
UpdateMessageLabel ( ) ;
UpdateDialog ( ) ;
2013-10-04 23:50:26 +00:00
}
private void MoveDownMenuItem_Click ( object sender , EventArgs e )
{
2014-01-01 02:02:23 +00:00
var indices = SelectedIndices . ToList ( ) ;
if ( indices . Count = = 0 | | indices . Last ( ) = = Global . CheatList . Count - 1 )
{
return ;
}
for ( var i = indices . Count - 1 ; i > = 0 ; i - - )
{
var cheat = Global . CheatList [ indices [ i ] ] ;
Global . CheatList . Remove ( cheat ) ;
Global . CheatList . Insert ( indices [ i ] + 1 , cheat ) ;
}
UpdateMessageLabel ( ) ;
var newindices = indices . Select ( t = > t + 1 ) . ToList ( ) ;
CheatListView . SelectedIndices . Clear ( ) ;
foreach ( var newi in newindices )
{
CheatListView . SelectItem ( newi , true ) ;
}
UpdateDialog ( ) ;
2013-10-04 23:50:26 +00:00
}
private void SelectAllMenuItem_Click ( object sender , EventArgs e )
{
2014-02-15 19:15:04 +00:00
CheatListView . SelectAll ( ) ;
2013-10-04 23:50:26 +00:00
}
2013-10-05 00:38:46 +00:00
private void ToggleMenuItem_Click ( object sender , EventArgs e )
{
2014-01-01 02:02:23 +00:00
SelectedCheats . ToList ( ) . ForEach ( x = > x . Toggle ( ) ) ;
2013-10-05 00:38:46 +00:00
}
2013-10-04 23:50:26 +00:00
private void DisableAllCheatsMenuItem_Click ( object sender , EventArgs e )
{
2013-10-20 18:02:43 +00:00
Global . CheatList . DisableAll ( ) ;
2013-10-04 23:50:26 +00:00
}
2013-10-05 00:38:46 +00:00
private void OpenGameGenieEncoderDecoderMenuItem_Click ( object sender , EventArgs e )
{
2013-12-22 23:34:22 +00:00
GlobalWin . Tools . LoadGameGenieEc ( ) ;
2013-10-05 00:38:46 +00:00
}
2013-10-02 15:09:49 +00:00
#endregion
#region Options
private void OptionsSubMenu_DropDownOpened ( object sender , EventArgs e )
{
2013-10-05 23:16:35 +00:00
AlwaysLoadCheatsMenuItem . Checked = Global . Config . LoadCheatFileByGame ;
AutoSaveCheatsMenuItem . Checked = Global . Config . CheatsAutoSaveOnClose ;
2013-10-05 03:40:36 +00:00
DisableCheatsOnLoadMenuItem . Checked = Global . Config . DisableCheatsOnLoad ;
AutoloadMenuItem . Checked = Global . Config . RecentCheats . AutoLoad ;
2014-12-31 22:16:22 +00:00
SaveWindowPositionMenuItem . Checked = Settings . SaveWindowPosition ;
AlwaysOnTopMenuItem . Checked = Settings . TopMost ;
FloatingWindowMenuItem . Checked = Settings . FloatingWindow ;
2013-10-05 03:40:36 +00:00
}
2013-10-05 23:16:35 +00:00
private void AlwaysLoadCheatsMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . LoadCheatFileByGame ^ = true ;
}
private void AutoSaveCheatsMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . CheatsAutoSaveOnClose ^ = true ;
}
2013-10-05 03:40:36 +00:00
private void CheatsOnOffLoadMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . DisableCheatsOnLoad ^ = true ;
}
2014-01-01 00:07:24 +00:00
2013-10-05 03:40:36 +00:00
private void AutoloadMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . RecentCheats . AutoLoad ^ = true ;
2013-10-04 16:06:08 +00:00
}
2013-10-02 15:09:49 +00:00
2013-10-04 16:06:08 +00:00
private void SaveWindowPositionMenuItem_Click ( object sender , EventArgs e )
{
2014-12-31 22:16:22 +00:00
Settings . SaveWindowPosition ^ = true ;
2013-10-04 16:06:08 +00:00
}
private void AlwaysOnTopMenuItem_Click ( object sender , EventArgs e )
{
2014-12-31 22:16:22 +00:00
Settings . TopMost ^ = true ;
2014-01-30 15:51:07 +00:00
}
private void FloatingWindowMenuItem_Click ( object sender , EventArgs e )
{
2014-12-31 22:16:22 +00:00
Settings . FloatingWindow ^ = true ;
2014-01-30 15:51:07 +00:00
RefreshFloatingWindowControl ( ) ;
2013-10-02 15:09:49 +00:00
}
2015-01-01 01:21:06 +00:00
private void RestoreDefaultsMenuItem_Click ( object sender , EventArgs e )
2013-10-05 03:40:36 +00:00
{
2013-11-25 00:55:56 +00:00
Size = new Size ( _defaultWidth , _defaultHeight ) ;
2014-12-31 22:16:22 +00:00
Settings = new CheatsSettings ( ) ;
2015-01-01 01:21:06 +00:00
CheatsMenu . Items . Remove (
CheatsMenu . Items
. OfType < ToolStripMenuItem > ( )
. First ( x = > x . Name = = "GeneratedColumnsSubMenu" )
) ;
CheatsMenu . Items . Add ( Settings . Columns . GenerateColumnsMenu ( ColumnToggleCallback ) ) ;
2013-10-05 03:40:36 +00:00
Global . Config . DisableCheatsOnLoad = false ;
2013-10-06 22:16:12 +00:00
Global . Config . LoadCheatFileByGame = true ;
Global . Config . CheatsAutoSaveOnClose = true ;
2013-10-05 03:40:36 +00:00
2014-01-30 15:51:07 +00:00
RefreshFloatingWindowControl ( ) ;
2014-06-20 18:09:53 +00:00
LoadColumnInfo ( ) ;
2013-10-05 03:40:36 +00:00
}
2013-10-02 15:09:49 +00:00
#endregion
2013-10-05 21:37:01 +00:00
#region ListView and Dialog Events
2013-10-05 20:22:55 +00:00
private void CheatListView_Click ( object sender , EventArgs e )
{
DoSelectedIndexChange ( ) ;
}
private void CheatListView_DoubleClick ( object sender , EventArgs e )
{
2014-01-01 02:02:23 +00:00
ToggleMenuItem_Click ( sender , e ) ;
2013-10-05 20:22:55 +00:00
}
private void CheatListView_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . KeyCode = = Keys . Delete & & ! e . Control & & ! e . Alt & & ! e . Shift )
{
2014-01-01 02:02:23 +00:00
RemoveCheatMenuItem_Click ( sender , e ) ;
2013-10-05 20:22:55 +00:00
}
2014-01-01 00:07:24 +00:00
else if ( e . KeyCode = = Keys . A & & e . Control & & ! e . Alt & & ! e . Shift )
2013-10-05 20:22:55 +00:00
{
SelectAllMenuItem_Click ( null , null ) ;
}
}
private void CheatListView_SelectedIndexChanged ( object sender , EventArgs e )
{
DoSelectedIndexChange ( ) ;
}
2013-10-05 21:37:01 +00:00
private void CheatListView_ColumnClick ( object sender , ColumnClickEventArgs e )
{
var column = CheatListView . Columns [ e . Column ] ;
if ( column . Name ! = _sortedColumn )
{
_sortReverse = false ;
}
2013-10-20 18:02:43 +00:00
Global . CheatList . Sort ( column . Name , _sortReverse ) ;
2013-10-05 21:37:01 +00:00
_sortedColumn = column . Name ;
_sortReverse ^ = true ;
2013-11-07 20:33:29 +00:00
UpdateDialog ( ) ;
2013-10-05 21:37:01 +00:00
}
2013-10-05 20:22:55 +00:00
private void NewCheatForm_DragDrop ( object sender , DragEventArgs e )
{
2013-11-25 02:08:45 +00:00
var filePaths = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
2014-01-01 00:07:24 +00:00
if ( Path . GetExtension ( filePaths [ 0 ] ) = = ".cht" )
2013-10-05 20:22:55 +00:00
{
LoadFile ( new FileInfo ( filePaths [ 0 ] ) , append : false ) ;
2013-11-07 20:33:29 +00:00
UpdateDialog ( ) ;
2013-10-05 20:22:55 +00:00
UpdateMessageLabel ( ) ;
}
}
private void NewCheatForm_DragEnter ( object sender , DragEventArgs e )
{
e . Effect = e . Data . GetDataPresent ( DataFormats . FileDrop ) ? DragDropEffects . Copy : DragDropEffects . None ;
}
2014-01-01 00:07:24 +00:00
private void CheatsContextMenu_Opening ( object sender , CancelEventArgs e )
2013-10-14 01:37:09 +00:00
{
ToggleContextMenuItem . Enabled =
RemoveContextMenuItem . Enabled =
SelectedCheats . Any ( ) ;
2013-10-20 18:02:43 +00:00
DisableAllContextMenuItem . Enabled = Global . CheatList . ActiveCount > 0 ;
2013-10-14 01:37:09 +00:00
}
2013-12-21 15:01:12 +00:00
private void ViewInHexEditorContextMenuItem_Click ( object sender , EventArgs e )
{
var selected = SelectedCheats . ToList ( ) ;
if ( selected . Any ( ) )
{
GlobalWin . Tools . Load < HexEditor > ( ) ;
if ( selected . Select ( x = > x . Domain ) . Distinct ( ) . Count ( ) > 1 )
{
2015-01-18 18:01:27 +00:00
ToolHelpers . ViewInHexEditor ( selected [ 0 ] . Domain , new List < long > { ( long ) ( selected . First ( ) . Address ? ? 0 ) } , selected . First ( ) . Size ) ; // int to long TODO: cheat address should be long
2013-12-21 15:01:12 +00:00
}
else
{
2015-01-18 18:01:27 +00:00
ToolHelpers . ViewInHexEditor ( selected . First ( ) . Domain , selected . Select ( x = > x . Address ? ? 0 ) . Cast < long > ( ) , selected . First ( ) . Size ) ; // int to long TODO: cheat address should be long
2013-12-21 15:01:12 +00:00
}
}
}
2014-01-30 15:51:07 +00:00
protected override void OnShown ( EventArgs e )
{
RefreshFloatingWindowControl ( ) ;
base . OnShown ( e ) ;
}
2013-10-05 20:22:55 +00:00
#endregion
2013-10-02 15:09:49 +00:00
#endregion
2015-01-01 00:11:39 +00:00
public class CheatsSettings : ToolDialogSettings
{
public CheatsSettings ( )
{
Columns = new ColumnList
{
new Column { Name = NAME , Visible = true , Index = 0 , Width = 128 } ,
new Column { Name = ADDRESS , Visible = true , Index = 1 , Width = 60 } ,
new Column { Name = VALUE , Visible = true , Index = 2 , Width = 59 } ,
new Column { Name = COMPARE , Visible = true , Index = 3 , Width = 59 } ,
new Column { Name = ON , Visible = false , Index = 4 , Width = 28 } ,
new Column { Name = DOMAIN , Visible = true , Index = 5 , Width = 55 } ,
new Column { Name = SIZE , Visible = true , Index = 6 , Width = 55 } ,
new Column { Name = ENDIAN , Visible = false , Index = 7 , Width = 55 } ,
new Column { Name = TYPE , Visible = false , Index = 8 , Width = 55 }
} ;
}
public ColumnList Columns { get ; set ; }
}
2013-10-01 13:02:19 +00:00
}
}