2011-07-22 01:14:13 +00:00
using System ;
2014-06-14 02:23:13 +00:00
using System.Drawing ;
2011-07-22 01:14:13 +00:00
using System.IO ;
using System.Windows.Forms ;
2013-10-25 00:57:23 +00:00
using BizHawk.Client.Common ;
2014-04-22 01:16:11 +00:00
using BizHawk.Emulation.Common ;
2014-06-01 00:40:13 +00:00
using BizHawk.Emulation.Common.IEmulatorExtensions ;
2014-04-22 01:16:11 +00:00
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES ;
2014-05-18 16:28:56 +00:00
using BizHawk.Emulation.Cores.Nintendo.NES ;
2014-06-14 01:37:20 +00:00
using BizHawk.Emulation.Cores.Nintendo.SNES ;
2014-05-18 15:54:56 +00:00
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2011-07-22 01:14:13 +00:00
{
partial class MainForm
{
2013-12-14 06:58:09 +00:00
public void StartNewMovie ( IMovie movie , bool record , bool fromTastudio = false ) //TasStudio flag is a hack for now
2011-07-22 01:14:13 +00:00
{
2012-09-22 20:04:37 +00:00
//If a movie is already loaded, save it before starting a new movie
2013-12-14 06:58:09 +00:00
if ( ! fromTastudio & & Global . MovieSession . Movie . IsActive )
2012-09-22 20:04:37 +00:00
{
2013-11-23 18:18:58 +00:00
Global . MovieSession . Movie . Save ( ) ;
2012-09-22 20:04:37 +00:00
}
2012-10-13 21:30:19 +00:00
2013-11-01 18:52:26 +00:00
Global . MovieSession = new MovieSession
{
2013-12-04 15:17:02 +00:00
Movie = movie ,
2014-06-19 01:47:22 +00:00
MovieControllerAdapter = movie . LogGeneratorInstance ( ) . MovieControllerAdapter ,
2013-11-03 16:07:58 +00:00
MessageCallback = GlobalWin . OSD . AddMessage ,
2013-11-01 18:52:26 +00:00
AskYesNoCallback = StateErrorAskUser
} ;
2013-12-24 21:59:41 +00:00
InputManager . RewireInputChain ( ) ;
2011-07-22 01:14:13 +00:00
2011-09-04 19:04:00 +00:00
if ( ! record )
2012-09-03 19:42:53 +00:00
{
2013-11-23 18:18:58 +00:00
Global . MovieSession . Movie . Load ( ) ;
2012-09-03 19:42:53 +00:00
}
2013-12-24 23:32:43 +00:00
try
{
2014-05-18 16:28:56 +00:00
var quicknesName = ( ( CoreAttributes ) Attribute . GetCustomAttribute ( typeof ( QuickNES ) , typeof ( CoreAttributes ) ) ) . CoreName ;
2014-05-29 12:25:42 +00:00
var neshawkName = ( ( CoreAttributes ) Attribute . GetCustomAttribute ( typeof ( NES ) , typeof ( CoreAttributes ) ) ) . CoreName ;
2014-05-18 16:28:56 +00:00
if ( ! record & & Global . Emulator . SystemId = = "NES" ) // For NES we need special logic since the movie will drive which core to load
2013-12-24 23:32:43 +00:00
{
2014-05-29 12:25:42 +00:00
// If either is specified use that, else use whatever is currently set
2014-06-12 23:22:15 +00:00
if ( Global . MovieSession . Movie . Core = = quicknesName )
2014-04-22 01:16:11 +00:00
{
Global . Config . NES_InQuickNES = true ;
}
2014-06-12 23:22:15 +00:00
else if ( Global . MovieSession . Movie . Core = = neshawkName )
2014-04-22 01:16:11 +00:00
{
2014-05-18 16:28:56 +00:00
Global . Config . NES_InQuickNES = false ;
2014-04-22 01:16:11 +00:00
}
2014-01-01 03:03:10 +00:00
}
2014-06-01 00:40:13 +00:00
2014-06-08 22:12:15 +00:00
string s = Global . MovieSession . Movie . SyncSettingsJson ;
2014-05-18 17:15:51 +00:00
if ( ! string . IsNullOrWhiteSpace ( s ) )
{
2014-05-18 17:19:38 +00:00
_syncSettingsHack = ConfigService . LoadWithType ( s ) ;
2014-05-18 17:15:51 +00:00
}
2014-05-24 22:06:08 +00:00
if ( record ) // This is a hack really, the movie isn't active yet unless I do this, and LoadRom wants to know if it is
{
Global . MovieSession . Movie . SwitchToRecord ( ) ;
}
LoadRom ( GlobalWin . MainForm . CurrentlyOpenRom ) ;
2013-12-24 23:32:43 +00:00
}
finally
{
// ensure subsequent calls to LoadRom won't get the settings object created here
2013-12-29 23:35:42 +00:00
this . _syncSettingsHack = null ;
2013-12-24 23:32:43 +00:00
}
2012-11-22 03:47:18 +00:00
2013-12-14 06:58:09 +00:00
if ( ! fromTastudio )
{
Global . Config . RecentMovies . Add ( movie . Filename ) ;
}
2014-06-11 01:41:41 +00:00
if ( Global . MovieSession . Movie . StartsFromSavestate )
2011-07-30 20:49:36 +00:00
{
2014-06-11 00:41:20 +00:00
var state = Convert . FromBase64String ( Global . MovieSession . Movie . SavestateBinaryBase64Blob ) ;
2014-04-25 02:19:46 +00:00
Global . Emulator . LoadStateBinary ( new BinaryReader ( new MemoryStream ( state ) ) ) ;
2013-11-03 16:29:51 +00:00
Global . Emulator . ResetCounters ( ) ;
2011-07-30 20:49:36 +00:00
}
2013-12-03 18:08:45 +00:00
2013-12-14 14:40:33 +00:00
if ( ! fromTastudio )
2011-07-22 01:14:13 +00:00
{
2013-12-14 14:40:33 +00:00
if ( record )
{
Global . MovieSession . Movie . StartNewRecording ( ) ;
Global . MovieSession . ReadOnly = false ;
}
else
{
Global . MovieSession . Movie . StartNewPlayback ( ) ;
}
2011-07-22 01:14:13 +00:00
}
2013-12-03 18:08:45 +00:00
2011-07-22 01:14:13 +00:00
SetMainformMovieInfo ( ) ;
2013-12-14 06:58:09 +00:00
if ( ! fromTastudio )
{
GlobalWin . Tools . Restart < TAStudio > ( ) ;
}
2013-11-03 16:07:58 +00:00
GlobalWin . Tools . Restart < VirtualPadForm > ( ) ;
GlobalWin . DisplayManager . NeedsToPaint = true ;
2011-07-22 01:14:13 +00:00
}
public void SetMainformMovieInfo ( )
{
2013-10-24 22:26:28 +00:00
if ( Global . MovieSession . Movie . IsPlaying )
2011-07-22 01:14:13 +00:00
{
2014-05-23 16:22:24 +00:00
Text = DisplayNameForSystem ( Global . Game . System ) + " - " + Global . Game . Name + " - " + Path . GetFileName ( Global . MovieSession . Movie . Filename ) ;
2013-10-27 15:53:37 +00:00
PlayRecordStatusButton . Image = Properties . Resources . Play ;
PlayRecordStatusButton . ToolTipText = "Movie is in playback mode" ;
PlayRecordStatusButton . Visible = true ;
2011-07-22 01:14:13 +00:00
}
2013-10-24 22:26:28 +00:00
else if ( Global . MovieSession . Movie . IsRecording )
2011-07-22 01:14:13 +00:00
{
2014-05-23 16:22:24 +00:00
Text = DisplayNameForSystem ( Global . Game . System ) + " - " + Global . Game . Name + " - " + Path . GetFileName ( Global . MovieSession . Movie . Filename ) ;
2013-10-27 15:53:37 +00:00
PlayRecordStatusButton . Image = Properties . Resources . RecordHS ;
PlayRecordStatusButton . ToolTipText = "Movie is in record mode" ;
PlayRecordStatusButton . Visible = true ;
2011-07-22 01:14:13 +00:00
}
2013-10-24 22:26:28 +00:00
else if ( ! Global . MovieSession . Movie . IsActive )
2011-07-22 01:14:13 +00:00
{
2014-05-23 16:22:24 +00:00
Text = DisplayNameForSystem ( Global . Game . System ) + " - " + Global . Game . Name ;
2013-10-27 15:53:37 +00:00
PlayRecordStatusButton . Image = Properties . Resources . Blank ;
PlayRecordStatusButton . ToolTipText = "No movie is active" ;
PlayRecordStatusButton . Visible = false ;
2011-07-22 01:14:13 +00:00
}
}
2013-11-01 18:52:26 +00:00
public void LoadPlayMovieDialog ( )
2011-07-22 01:14:13 +00:00
{
2013-08-24 20:11:41 +00:00
new PlayMovie ( ) . ShowDialog ( ) ;
2011-07-22 01:14:13 +00:00
}
2013-11-01 18:52:26 +00:00
public void LoadRecordMovieDialog ( )
2011-07-22 01:14:13 +00:00
{
2014-06-01 00:40:13 +00:00
if ( ! Global . Emulator . Attributes ( ) . Released )
2012-11-24 22:14:05 +00:00
{
var result = MessageBox . Show
( this , "Thanks for using Bizhawk! The emulation core you have selected " +
"is currently BETA-status. We appreciate your help in testing Bizhawk. " +
"You can record a movie on this core if you'd like to, but expect to " +
"encounter bugs and sync problems. Continue?" , "BizHawk" , MessageBoxButtons . YesNo ) ;
2014-06-14 01:37:20 +00:00
if ( result ! = DialogResult . Yes )
{
return ;
}
}
else if ( Global . Emulator is LibsnesCore )
{
var ss = ( LibsnesCore . SnesSyncSettings ) Global . Emulator . GetSyncSettings ( ) ;
2014-06-14 02:23:13 +00:00
if ( ss . Profile = = "Performance" & & ! Global . Config . DontAskPerformanceCoreRecordingNag )
2014-06-14 01:37:20 +00:00
{
2014-06-14 02:23:13 +00:00
var box = new MsgBox (
"While the performance core is faster, it is recommended that you use the Compatibility profile when recording movies for better accuracy and stability\n\nSwitch to Compatibility?" ,
2014-06-14 01:37:20 +00:00
"Stability Warning" ,
MessageBoxIcon . Warning ) ;
2014-06-14 02:23:13 +00:00
box . SetButtons (
new [ ] { "Switch" , "Continue" , "Cancel" } ,
new DialogResult [ ] { DialogResult . Yes , DialogResult . No , DialogResult . Cancel } ) ;
box . SetCheckbox ( "Don't ask me again" ) ;
box . MaximumSize = new Size ( 450 , 350 ) ;
box . SetMessageToAutoSize ( ) ;
var result = box . ShowDialog ( ) ;
Global . Config . DontAskPerformanceCoreRecordingNag = box . CheckboxChecked ;
2014-06-14 01:37:20 +00:00
if ( result = = DialogResult . Yes )
{
ss . Profile = "Compatibility" ;
Global . Emulator . PutSyncSettings ( ss ) ;
}
else if ( result = = DialogResult . Cancel )
{
return ;
}
}
2012-11-24 22:14:05 +00:00
}
2014-06-14 01:37:20 +00:00
2013-08-24 20:11:41 +00:00
new RecordMovie ( ) . ShowDialog ( ) ;
2011-07-22 01:14:13 +00:00
}
2013-11-01 18:52:26 +00:00
public void RestartMovie ( )
2011-07-22 01:14:13 +00:00
{
2013-10-24 22:26:28 +00:00
if ( Global . MovieSession . Movie . IsActive )
2011-07-22 01:14:13 +00:00
{
2014-05-24 22:06:08 +00:00
LoadRom ( CurrentlyOpenRom ) ;
2014-06-11 01:41:41 +00:00
if ( Global . MovieSession . Movie . StartsFromSavestate )
2011-09-04 19:06:18 +00:00
{
2014-06-11 00:41:20 +00:00
var state = Convert . FromBase64String ( Global . MovieSession . Movie . SavestateBinaryBase64Blob ) ;
2014-04-25 21:43:29 +00:00
Global . Emulator . LoadStateBinary ( new BinaryReader ( new MemoryStream ( state ) ) ) ;
2013-11-03 16:29:51 +00:00
Global . Emulator . ResetCounters ( ) ;
2011-09-04 19:06:18 +00:00
}
2013-12-03 18:08:45 +00:00
2013-11-29 19:55:05 +00:00
Global . MovieSession . Movie . StartNewPlayback ( ) ;
2011-07-22 01:14:13 +00:00
SetMainformMovieInfo ( ) ;
2013-11-03 16:07:58 +00:00
GlobalWin . OSD . AddMessage ( "Replaying movie file in read-only mode" ) ;
2013-12-03 18:08:45 +00:00
Global . MovieSession . ReadOnly = true ;
2011-07-22 01:14:13 +00:00
}
}
2011-07-22 01:34:21 +00:00
2013-11-23 18:18:58 +00:00
public void StopMovie ( bool saveChanges = true )
2011-07-22 01:34:21 +00:00
{
2013-11-23 18:18:58 +00:00
Global . MovieSession . StopMovie ( saveChanges ) ;
2013-11-01 18:52:26 +00:00
SetMainformMovieInfo ( ) ;
2013-10-25 00:57:23 +00:00
}
2011-07-22 01:14:13 +00:00
}
}