2010-06-09 01:37:08 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "OnFrame.h"
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Thread.h"
|
|
|
|
#include "FileUtil.h"
|
|
|
|
#include "PowerPC/PowerPC.h"
|
2010-09-06 21:41:01 +00:00
|
|
|
#include "HW/SI.h"
|
2011-02-11 19:09:46 +00:00
|
|
|
#include "HW/Wiimote.h"
|
|
|
|
#include "IPC_HLE/WII_IPC_HLE_Device_usb.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "VideoBackendBase.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2011-02-12 02:14:20 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <io.h> //_chsize_s
|
2011-02-12 03:01:54 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <share.h>
|
|
|
|
#include <sys/stat.h>
|
2011-02-12 02:14:20 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h> //truncate
|
|
|
|
#endif
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
Common::CriticalSection cs_frameSkip;
|
|
|
|
|
|
|
|
namespace Frame {
|
|
|
|
|
|
|
|
bool g_bFrameStep = false;
|
|
|
|
bool g_bFrameStop = false;
|
2011-02-12 02:14:20 +00:00
|
|
|
bool g_bReadOnly = true;
|
2010-08-30 07:05:47 +00:00
|
|
|
u32 g_rerecords = 0;
|
2010-06-09 01:37:08 +00:00
|
|
|
PlayMode g_playMode = MODE_NONE;
|
|
|
|
|
|
|
|
unsigned int g_framesToSkip = 0, g_frameSkipCounter = 0;
|
|
|
|
|
|
|
|
int g_numPads = 0;
|
2010-08-30 07:05:47 +00:00
|
|
|
ControllerState g_padState;
|
2011-02-12 02:14:20 +00:00
|
|
|
char g_playingFile[256] = "\0";
|
2010-06-09 01:37:08 +00:00
|
|
|
FILE *g_recordfd = NULL;
|
|
|
|
|
|
|
|
u64 g_frameCounter = 0, g_lagCounter = 0;
|
|
|
|
bool g_bPolled = false;
|
|
|
|
|
|
|
|
int g_numRerecords = 0;
|
2010-08-30 07:05:47 +00:00
|
|
|
std::string g_recordFile = "0.dtm";
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
void FrameUpdate()
|
|
|
|
{
|
|
|
|
g_frameCounter++;
|
|
|
|
|
|
|
|
if(!g_bPolled)
|
|
|
|
g_lagCounter++;
|
|
|
|
|
|
|
|
if (g_bFrameStep)
|
|
|
|
Core::SetState(Core::CORE_PAUSE);
|
|
|
|
|
|
|
|
// ("framestop") the only purpose of this is to cause interpreter/jit Run() to return temporarily.
|
|
|
|
// after that we set it back to CPU_RUNNING and continue as normal.
|
|
|
|
if (g_bFrameStop)
|
|
|
|
*PowerPC::GetStatePtr() = PowerPC::CPU_STEPPING;
|
|
|
|
|
|
|
|
if(g_framesToSkip)
|
|
|
|
FrameSkipping();
|
|
|
|
|
|
|
|
g_bPolled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFrameSkipping(unsigned int framesToSkip)
|
|
|
|
{
|
|
|
|
cs_frameSkip.Enter();
|
|
|
|
|
|
|
|
g_framesToSkip = framesToSkip;
|
|
|
|
g_frameSkipCounter = 0;
|
|
|
|
|
|
|
|
// Don't forget to re-enable rendering in case it wasn't...
|
|
|
|
// as this won't be changed anymore when frameskip is turned off
|
|
|
|
if (framesToSkip == 0)
|
2011-01-31 01:28:32 +00:00
|
|
|
g_video_backend->Video_SetRendering(true);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
cs_frameSkip.Leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
int FrameSkippingFactor()
|
|
|
|
{
|
|
|
|
return g_framesToSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPolledDevice()
|
|
|
|
{
|
|
|
|
g_bPolled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFrameStepping(bool bEnabled)
|
|
|
|
{
|
|
|
|
g_bFrameStep = bEnabled;
|
|
|
|
}
|
|
|
|
|
2011-01-17 01:47:27 +00:00
|
|
|
void SetFrameStopping(bool bEnabled)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-01-17 01:47:27 +00:00
|
|
|
g_bFrameStop = bEnabled;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-12 02:14:20 +00:00
|
|
|
void SetReadOnly(bool bEnabled)
|
|
|
|
{
|
|
|
|
g_bReadOnly = bEnabled;
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
void FrameSkipping()
|
|
|
|
{
|
2011-02-11 12:26:15 +00:00
|
|
|
// Frameskipping will desync movie playback
|
|
|
|
if (!IsPlayingInput() && !IsRecordingInput())
|
|
|
|
{
|
|
|
|
cs_frameSkip.Enter();
|
|
|
|
|
|
|
|
g_frameSkipCounter++;
|
|
|
|
if (g_frameSkipCounter > g_framesToSkip || Core::report_slow(g_frameSkipCounter) == false)
|
|
|
|
g_frameSkipCounter = 0;
|
|
|
|
|
|
|
|
g_video_backend->Video_SetRendering(!g_frameSkipCounter);
|
|
|
|
|
|
|
|
cs_frameSkip.Leave();
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsRecordingInput()
|
|
|
|
{
|
|
|
|
return (g_playMode == MODE_RECORDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPlayingInput()
|
|
|
|
{
|
|
|
|
return (g_playMode == MODE_PLAYING);
|
|
|
|
}
|
|
|
|
|
2010-09-06 21:41:01 +00:00
|
|
|
bool IsUsingPad(int controller)
|
|
|
|
{
|
2011-02-12 00:06:58 +00:00
|
|
|
return ((g_numPads & (1 << controller)) != 0);
|
2011-02-11 19:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsUsingWiimote(int wiimote)
|
|
|
|
{
|
2011-02-12 00:06:58 +00:00
|
|
|
return ((g_numPads & (1 << (wiimote + 4))) != 0);
|
2010-09-06 21:41:01 +00:00
|
|
|
}
|
|
|
|
|
2011-02-12 00:06:58 +00:00
|
|
|
void ChangePads(bool instantly)
|
2010-09-06 21:41:01 +00:00
|
|
|
{
|
2011-02-11 19:09:46 +00:00
|
|
|
if (Core::GetState() != Core::CORE_UNINITIALIZED)
|
2011-02-12 00:06:58 +00:00
|
|
|
{
|
2011-02-11 19:09:46 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
2011-02-12 00:06:58 +00:00
|
|
|
if (instantly) // Changes from savestates need to be instantaneous
|
|
|
|
SerialInterface::AddDevice(IsUsingPad(i) ? SI_GC_CONTROLLER : SI_NONE, i);
|
|
|
|
else
|
|
|
|
SerialInterface::ChangeDevice(IsUsingPad(i) ? SI_GC_CONTROLLER : SI_NONE, i);
|
|
|
|
}
|
2011-02-11 19:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChangeWiiPads()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
g_wiimote_sources[i] = IsUsingWiimote(i) ? WIIMOTE_SRC_EMU : WIIMOTE_SRC_NONE;
|
|
|
|
GetUsbPointer()->AccessWiiMote(i | 0x100)->Activate(IsUsingWiimote(i));
|
2010-09-06 21:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
// TODO: Add BeginRecordingFromSavestate
|
2010-08-30 07:05:47 +00:00
|
|
|
bool BeginRecordingInput(int controllers)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2010-09-06 21:41:01 +00:00
|
|
|
if(g_playMode != MODE_NONE || controllers == 0 || g_recordfd != NULL)
|
2010-06-09 01:37:08 +00:00
|
|
|
return false;
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
const char *filename = g_recordFile.c_str();
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
if(File::Exists(filename))
|
|
|
|
File::Delete(filename);
|
|
|
|
|
|
|
|
g_recordfd = fopen(filename, "wb");
|
|
|
|
if(!g_recordfd) {
|
2011-01-13 02:05:58 +00:00
|
|
|
PanicAlertT("Error opening file %s for recording", filename);
|
2010-06-09 01:37:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write initial empty header
|
|
|
|
DTMHeader dummy;
|
|
|
|
fwrite(&dummy, sizeof(DTMHeader), 1, g_recordfd);
|
|
|
|
|
|
|
|
g_numPads = controllers;
|
|
|
|
|
|
|
|
g_frameCounter = 0;
|
|
|
|
g_lagCounter = 0;
|
|
|
|
|
|
|
|
g_playMode = MODE_RECORDING;
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
Core::DisplayMessage("Starting movie recording", 2000);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordInput(SPADStatus *PadStatus, int controllerID)
|
|
|
|
{
|
2010-09-06 21:41:01 +00:00
|
|
|
if(!IsRecordingInput() || !IsUsingPad(controllerID))
|
2010-06-09 01:37:08 +00:00
|
|
|
return;
|
2010-08-30 07:05:47 +00:00
|
|
|
|
|
|
|
g_padState.A = ((PadStatus->button & PAD_BUTTON_A) != 0);
|
|
|
|
g_padState.B = ((PadStatus->button & PAD_BUTTON_B) != 0);
|
|
|
|
g_padState.X = ((PadStatus->button & PAD_BUTTON_X) != 0);
|
|
|
|
g_padState.Y = ((PadStatus->button & PAD_BUTTON_Y) != 0);
|
|
|
|
g_padState.Z = ((PadStatus->button & PAD_TRIGGER_Z) != 0);
|
|
|
|
g_padState.Start = ((PadStatus->button & PAD_BUTTON_START) != 0);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
g_padState.DPadUp = ((PadStatus->button & PAD_BUTTON_UP) != 0);
|
|
|
|
g_padState.DPadDown = ((PadStatus->button & PAD_BUTTON_DOWN) != 0);
|
|
|
|
g_padState.DPadLeft = ((PadStatus->button & PAD_BUTTON_LEFT) != 0);
|
|
|
|
g_padState.DPadRight = ((PadStatus->button & PAD_BUTTON_RIGHT) != 0);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
g_padState.L = PadStatus->triggerLeft;
|
|
|
|
g_padState.R = PadStatus->triggerRight;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
g_padState.AnalogStickX = PadStatus->stickX;
|
|
|
|
g_padState.AnalogStickY = PadStatus->stickY;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
g_padState.CStickX = PadStatus->substickX;
|
|
|
|
g_padState.CStickY = PadStatus->substickY;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
fwrite(&g_padState, sizeof(ControllerState), 1, g_recordfd);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 18:53:51 +00:00
|
|
|
void RecordWiimote(u8 *data, s8 size)
|
|
|
|
{
|
|
|
|
if(!IsRecordingInput())
|
|
|
|
return;
|
|
|
|
|
|
|
|
fwrite(&size, 1, 1, g_recordfd);
|
|
|
|
fwrite(data, 1, size, g_recordfd);
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
bool PlayInput(const char *filename)
|
|
|
|
{
|
|
|
|
if(!filename || g_playMode != MODE_NONE || g_recordfd)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!File::Exists(filename))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DTMHeader header;
|
|
|
|
|
2011-02-12 02:14:20 +00:00
|
|
|
File::Delete(g_recordFile.c_str());
|
|
|
|
File::Copy(filename, g_recordFile.c_str());
|
|
|
|
|
|
|
|
g_recordfd = fopen(g_recordFile.c_str(), "r+b");
|
2010-06-09 01:37:08 +00:00
|
|
|
if(!g_recordfd)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fread(&header, sizeof(DTMHeader), 1, g_recordfd);
|
|
|
|
|
|
|
|
if(header.filetype[0] != 'D' || header.filetype[1] != 'T' || header.filetype[2] != 'M' || header.filetype[3] != 0x1A) {
|
2011-01-13 02:05:58 +00:00
|
|
|
PanicAlertT("Invalid recording file");
|
2010-06-09 01:37:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load savestate (and skip to frame data)
|
|
|
|
if(header.bFromSaveState) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Put this verification somewhere we have the gameID of the played game
|
|
|
|
// TODO: Replace with Unique ID
|
|
|
|
if(header.uniqueID != 0) {
|
|
|
|
PanicAlert("Recording Unique ID Verification Failed");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strncmp((char *)header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str(), 6)) {
|
|
|
|
PanicAlert("The recorded game (%s) is not the same as the selected game (%s)", header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str());
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_numPads = header.numControllers;
|
|
|
|
g_numRerecords = header.numRerecords;
|
|
|
|
|
2010-09-06 21:41:01 +00:00
|
|
|
ChangePads();
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
g_playMode = MODE_PLAYING;
|
2011-02-12 02:14:20 +00:00
|
|
|
|
|
|
|
strncpy(g_playingFile, filename, 256);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
fclose(g_recordfd);
|
|
|
|
g_recordfd = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
void LoadInput(const char *filename)
|
|
|
|
{
|
|
|
|
FILE *t_record = fopen(filename, "rb");
|
|
|
|
|
|
|
|
DTMHeader header;
|
|
|
|
|
|
|
|
fread(&header, sizeof(DTMHeader), 1, t_record);
|
2010-09-06 21:41:01 +00:00
|
|
|
fclose(t_record);
|
2010-08-30 07:05:47 +00:00
|
|
|
|
|
|
|
if(header.filetype[0] != 'D' || header.filetype[1] != 'T' || header.filetype[2] != 'M' || header.filetype[3] != 0x1A) {
|
2011-01-13 02:05:58 +00:00
|
|
|
PanicAlertT("Savestate movie %s is corrupted, movie recording stopping...", filename);
|
2011-02-12 02:14:20 +00:00
|
|
|
strncpy(g_playingFile, "\0", 256);
|
2010-08-30 07:05:47 +00:00
|
|
|
EndPlayInput();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_rerecords == 0)
|
|
|
|
g_rerecords = header.numRerecords;
|
|
|
|
|
2011-02-12 02:14:20 +00:00
|
|
|
g_frameCounter = header.frameCount;
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
g_numPads = header.numControllers;
|
|
|
|
|
2011-02-12 00:06:58 +00:00
|
|
|
ChangePads(true);
|
|
|
|
|
|
|
|
if (Core::g_CoreStartupParameter.bWii)
|
|
|
|
ChangeWiiPads();
|
2010-08-30 07:05:47 +00:00
|
|
|
|
|
|
|
if (g_recordfd)
|
|
|
|
fclose(g_recordfd);
|
|
|
|
|
|
|
|
File::Delete(g_recordFile.c_str());
|
|
|
|
File::Copy(filename, g_recordFile.c_str());
|
|
|
|
|
|
|
|
g_recordfd = fopen(g_recordFile.c_str(), "r+b");
|
2010-12-04 03:50:55 +00:00
|
|
|
fseeko(g_recordfd, 0, SEEK_END);
|
2010-08-30 07:05:47 +00:00
|
|
|
|
|
|
|
g_rerecords++;
|
|
|
|
|
|
|
|
Core::DisplayMessage("Resuming movie recording", 2000);
|
|
|
|
|
|
|
|
g_playMode = MODE_RECORDING;
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
void PlayController(SPADStatus *PadStatus, int controllerID)
|
|
|
|
{
|
2010-08-30 07:05:47 +00:00
|
|
|
// Correct playback is entirely dependent on the emulator polling the controllers
|
|
|
|
// in the same order done during recording
|
2010-09-06 21:41:01 +00:00
|
|
|
if(!IsPlayingInput() || !IsUsingPad(controllerID))
|
2010-06-09 01:37:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
memset(PadStatus, 0, sizeof(SPADStatus));
|
2010-08-30 07:05:47 +00:00
|
|
|
fread(&g_padState, sizeof(ControllerState), 1, g_recordfd);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
PadStatus->button |= PAD_USE_ORIGIN;
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.A) {
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_A;
|
|
|
|
PadStatus->analogA = 0xFF;
|
|
|
|
}
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.B) {
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_B;
|
|
|
|
PadStatus->analogB = 0xFF;
|
|
|
|
}
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.X)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_X;
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.Y)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_Y;
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.Z)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_TRIGGER_Z;
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.Start)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_START;
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.DPadUp)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_UP;
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.DPadDown)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_DOWN;
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.DPadLeft)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_LEFT;
|
2010-08-30 07:05:47 +00:00
|
|
|
if(g_padState.DPadRight)
|
2010-06-09 01:37:08 +00:00
|
|
|
PadStatus->button |= PAD_BUTTON_RIGHT;
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
PadStatus->triggerLeft = g_padState.L;
|
2010-06-09 01:37:08 +00:00
|
|
|
if(PadStatus->triggerLeft > 230)
|
|
|
|
PadStatus->button |= PAD_TRIGGER_L;
|
2010-08-30 07:05:47 +00:00
|
|
|
PadStatus->triggerRight = g_padState.R;
|
2010-06-09 01:37:08 +00:00
|
|
|
if(PadStatus->triggerRight > 230)
|
|
|
|
PadStatus->button |= PAD_TRIGGER_R;
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
PadStatus->stickX = g_padState.AnalogStickX;
|
|
|
|
PadStatus->stickY = g_padState.AnalogStickY;
|
|
|
|
|
|
|
|
PadStatus->substickX = g_padState.CStickX;
|
|
|
|
PadStatus->substickY = g_padState.CStickY;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
if(feof(g_recordfd))
|
|
|
|
{
|
|
|
|
Core::DisplayMessage("Movie End", 2000);
|
2011-02-12 02:14:20 +00:00
|
|
|
EndPlayInput();
|
2010-08-30 07:05:47 +00:00
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 18:53:51 +00:00
|
|
|
void PlayWiimote(u8 *data, s8 &size)
|
|
|
|
{
|
|
|
|
s8 count = 0;
|
|
|
|
if(!IsPlayingInput())
|
|
|
|
return;
|
|
|
|
|
|
|
|
fread(&count, 1, 1, g_recordfd);
|
|
|
|
size = (count > size) ? size : count;
|
|
|
|
fread(data, 1, size, g_recordfd);
|
|
|
|
|
|
|
|
// TODO: merge this with the above so that there's no duplicate code
|
|
|
|
if(feof(g_recordfd))
|
|
|
|
{
|
|
|
|
Core::DisplayMessage("Movie End", 2000);
|
2011-02-12 02:14:20 +00:00
|
|
|
EndPlayInput();
|
2011-02-11 18:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
void EndPlayInput() {
|
2010-08-30 07:05:47 +00:00
|
|
|
if (g_recordfd)
|
|
|
|
fclose(g_recordfd);
|
2011-02-12 02:14:20 +00:00
|
|
|
|
|
|
|
if (!g_bReadOnly && strncmp(g_playingFile, "\0", 1))
|
|
|
|
{
|
|
|
|
File::Delete(g_recordFile.c_str());
|
|
|
|
File::Copy(g_playingFile, g_recordFile.c_str());
|
|
|
|
g_recordfd = fopen(g_recordFile.c_str(), "r+b");
|
|
|
|
fseeko(g_recordfd, 0, SEEK_END);
|
|
|
|
g_playMode = MODE_RECORDING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_recordfd = NULL;
|
|
|
|
g_numPads = g_rerecords = 0;
|
|
|
|
g_frameCounter = g_lagCounter = 0;
|
|
|
|
g_playMode = MODE_NONE;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-30 07:05:47 +00:00
|
|
|
void SaveRecording(const char *filename)
|
|
|
|
{
|
2011-02-12 02:14:20 +00:00
|
|
|
off_t size = ftello(g_recordfd);
|
2010-08-30 07:05:47 +00:00
|
|
|
|
2011-02-12 02:14:20 +00:00
|
|
|
// NOTE: Eventually this will not happen in
|
|
|
|
// read-only mode, but we need a way for the save state to
|
|
|
|
// store the current point in the file first.
|
|
|
|
// if (!g_bReadOnly)
|
|
|
|
{
|
|
|
|
rewind(g_recordfd);
|
2010-08-30 07:05:47 +00:00
|
|
|
|
2011-02-12 02:14:20 +00:00
|
|
|
// Create the real header now and write it
|
|
|
|
DTMHeader header;
|
|
|
|
memset(&header, 0, sizeof(DTMHeader));
|
|
|
|
|
|
|
|
header.filetype[0] = 'D'; header.filetype[1] = 'T'; header.filetype[2] = 'M'; header.filetype[3] = 0x1A;
|
|
|
|
strncpy((char *)header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str(), 6);
|
|
|
|
header.bWii = Core::g_CoreStartupParameter.bWii;
|
|
|
|
header.numControllers = g_numPads & (Core::g_CoreStartupParameter.bWii ? 0xFF : 0x0F);
|
|
|
|
|
|
|
|
header.bFromSaveState = false; // TODO: add the case where it's true
|
|
|
|
header.frameCount = g_frameCounter;
|
|
|
|
header.lagCount = g_lagCounter;
|
|
|
|
header.numRerecords = g_rerecords;
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
header.uniqueID = 0;
|
|
|
|
// header.author;
|
|
|
|
// header.videoPlugin;
|
|
|
|
// header.audioPlugin;
|
|
|
|
|
|
|
|
fwrite(&header, sizeof(DTMHeader), 1, g_recordfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool success = false;
|
2010-08-30 07:05:47 +00:00
|
|
|
fclose(g_recordfd);
|
2011-02-12 02:14:20 +00:00
|
|
|
File::Delete(filename);
|
|
|
|
success = File::Copy(g_recordFile.c_str(), filename);
|
|
|
|
|
|
|
|
if (success /* && !g_bReadOnly*/)
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
2011-02-12 02:40:31 +00:00
|
|
|
int fd;
|
2011-02-12 03:01:54 +00:00
|
|
|
if (!_sopen_s(&fd, filename, _O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE))
|
2011-02-12 02:40:31 +00:00
|
|
|
{
|
|
|
|
success = (_chsize_s(fd, size) == 0);
|
|
|
|
_close(fd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
2011-02-12 02:14:20 +00:00
|
|
|
#else
|
2011-02-12 02:40:31 +00:00
|
|
|
success = !truncate(filename, size);
|
2011-02-12 02:14:20 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-08-30 07:05:47 +00:00
|
|
|
|
2011-02-12 02:14:20 +00:00
|
|
|
if (success)
|
2010-08-30 07:05:47 +00:00
|
|
|
Core::DisplayMessage(StringFromFormat("DTM %s saved", filename).c_str(), 2000);
|
|
|
|
else
|
|
|
|
Core::DisplayMessage(StringFromFormat("Failed to save %s", filename).c_str(), 2000);
|
|
|
|
|
|
|
|
g_recordfd = fopen(g_recordFile.c_str(), "r+b");
|
2011-02-12 02:14:20 +00:00
|
|
|
fseeko(g_recordfd, size, SEEK_SET);
|
2010-08-30 07:05:47 +00:00
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|