diff --git a/pcsx2/Recording/InputRecording.cpp b/pcsx2/Recording/InputRecording.cpp index 1049ada063..c6ee3bb57b 100644 --- a/pcsx2/Recording/InputRecording.cpp +++ b/pcsx2/Recording/InputRecording.cpp @@ -47,7 +47,7 @@ InputRecording g_InputRecording; // Main func for handling controller input data // - Called by Sio.cpp::sioWriteController -void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 & bufCount, u8 buf[]) +void InputRecording::ControllerInterrupt(u8& data, u8& port, u16& bufCount, u8 buf[]) { // TODO - Multi-Tap Support // Only examine controllers 1 / 2 @@ -72,7 +72,7 @@ void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 & bufCount, u8 return; } } - else if ( bufCount == 2 ) + else if (bufCount == 2) { /* See - LilyPad.cpp::PADpoll - https://github.com/PCSX2/pcsx2/blob/v1.5.0-dev/plugins/LilyPad/LilyPad.cpp#L1194 @@ -87,8 +87,7 @@ void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 & bufCount, u8 } } - if (!fInterruptFrame - || state == INPUT_RECORDING_MODE_NONE + if (!fInterruptFrame || state == INPUT_RECORDING_MODE_NONE // We do not want to record or save the first two // bytes in the data returned from LilyPad || bufCount < 3) @@ -97,7 +96,7 @@ void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 & bufCount, u8 } // Read or Write - const u8 &nowBuf = buf[bufCount]; + const u8& nowBuf = buf[bufCount]; if (state == INPUT_RECORDING_MODE_RECORD) { InputRecordingData.UpdateFrameMax(g_FrameCount); @@ -141,29 +140,17 @@ void InputRecording::Create(wxString FileName, bool fromSaveState, wxString auth { return; } + // Set emulator version + InputRecordingData.GetHeader().SetEmulatorVersion(); + // Set author name if (!authorName.IsEmpty()) { InputRecordingData.GetHeader().SetAuthor(authorName); } // Set Game Name - // Code loosely taken from AppCoreThread.cpp to resolve the Game Name - // Fallback is ISO name - wxString gameName; - const wxString gameKey(SysGetDiscID()); - if (!gameKey.IsEmpty()) - { - if (IGameDatabase* GameDB = AppHost_GetGameDatabase()) - { - Game_Data game; - if (GameDB->findGame(game, gameKey)) - { - gameName = game.getString("Name"); - gameName += L" (" + game.getString("Region") + L")"; - } - } - } - InputRecordingData.GetHeader().SetGameName(!gameName.IsEmpty() ? gameName : Path::GetFilename(g_Conf->CurrentIso)); + InputRecordingData.GetHeader().SetGameName(resolveGameName()); + // Write header contents InputRecordingData.WriteHeader(); state = INPUT_RECORDING_MODE_RECORD; recordingConLog(wxString::Format(L"[REC]: Started new recording - [%s]\n", FileName)); @@ -191,20 +178,41 @@ void InputRecording::Play(wxString FileName, bool fromSaveState) // Check author name if (!g_Conf->CurrentIso.IsEmpty()) { - if (Path::GetFilename(g_Conf->CurrentIso) != InputRecordingData.GetHeader().gameName) + if (resolveGameName() != InputRecordingData.GetHeader().gameName) { - recordingConLog(L"[REC]: Information on CD in Movie file is Different.\n"); + recordingConLog(L"[REC]: Recording was possibly recorded on a different game.\n"); } } state = INPUT_RECORDING_MODE_REPLAY; recordingConLog(wxString::Format(L"[REC]: Replaying movie - [%s]\n", FileName)); + recordingConLog(wxString::Format(L"[REC]: PCSX2 Version Used: %s\n", InputRecordingData.GetHeader().emu)); recordingConLog(wxString::Format(L"[REC]: Recording File Version: %d\n", InputRecordingData.GetHeader().version)); - recordingConLog(wxString::Format(L"[REC]: Associated Game Name / ISO Filename: %s\n", InputRecordingData.GetHeader().gameName)); + recordingConLog(wxString::Format(L"[REC]: Associated Game Name or ISO Filename: %s\n", InputRecordingData.GetHeader().gameName)); recordingConLog(wxString::Format(L"[REC]: Author: %s\n", InputRecordingData.GetHeader().author)); recordingConLog(wxString::Format(L"[REC]: MaxFrame: %d\n", InputRecordingData.GetMaxFrame())); recordingConLog(wxString::Format(L"[REC]: UndoCount: %d\n", InputRecordingData.GetUndoCount())); } +wxString InputRecording::resolveGameName() +{ + // Code loosely taken from AppCoreThread::_ApplySettings to resolve the Game Name + wxString gameName; + const wxString gameKey(SysGetDiscID()); + if (!gameKey.IsEmpty()) + { + if (IGameDatabase* GameDB = AppHost_GetGameDatabase()) + { + Game_Data game; + if (GameDB->findGame(game, gameKey)) + { + gameName = game.getString("Name"); + gameName += L" (" + game.getString("Region") + L")"; + } + } + } + return !gameName.IsEmpty() ? gameName : Path::GetFilename(g_Conf->CurrentIso); +} + // Keybind Handler - Toggle between recording input and not void InputRecording::RecordModeToggle() { @@ -225,7 +233,7 @@ INPUT_RECORDING_MODE InputRecording::GetModeState() return state; } -InputRecordingFile & InputRecording::GetInputRecordingData() +InputRecordingFile& InputRecording::GetInputRecordingData() { return InputRecordingData; } diff --git a/pcsx2/Recording/InputRecording.h b/pcsx2/Recording/InputRecording.h index bc1cda0fa1..06a9e9ce06 100644 --- a/pcsx2/Recording/InputRecording.h +++ b/pcsx2/Recording/InputRecording.h @@ -30,14 +30,14 @@ class InputRecording { public: InputRecording() {} - ~InputRecording(){} + ~InputRecording() {} - void ControllerInterrupt(u8 &data, u8 &port, u16 & BufCount, u8 buf[]); + void ControllerInterrupt(u8& data, u8& port, u16& BufCount, u8 buf[]); void RecordModeToggle(); INPUT_RECORDING_MODE GetModeState(); - InputRecordingFile & GetInputRecordingData(); + InputRecordingFile& GetInputRecordingData(); bool IsInterruptFrame(); void Stop(); @@ -48,6 +48,9 @@ private: InputRecordingFile InputRecordingData; INPUT_RECORDING_MODE state = INPUT_RECORDING_MODE_NONE; bool fInterruptFrame = false; + // Resolve the name and region of the game currently loaded using the GameDB + // If the game cannot be found in the DB, the fallback is the ISO filename + wxString resolveGameName(); }; extern InputRecording g_InputRecording; diff --git a/pcsx2/Recording/InputRecordingFile.cpp b/pcsx2/Recording/InputRecordingFile.cpp index 482b04fa5f..464356f601 100644 --- a/pcsx2/Recording/InputRecordingFile.cpp +++ b/pcsx2/Recording/InputRecordingFile.cpp @@ -24,13 +24,11 @@ #include "InputRecordingFile.h" #ifndef DISABLE_RECORDING -long InputRecordingFile::GetBlockSeekPoint(const long & frame) +long InputRecordingFile::GetBlockSeekPoint(const long& frame) { if (savestate.fromSavestate) { - return RecordingHeaderSize - + RecordingSavestateHeaderSize - + frame * RecordingBlockSize; + return RecordingHeaderSize + RecordingSavestateHeaderSize + frame * RecordingBlockSize; } else { @@ -51,7 +49,7 @@ bool InputRecordingFile::Open(const wxString path, bool fNewOpen, bool fromSaveS header.Init(); } recordingFile = wxFopen(path, mode); - if ( recordingFile == NULL ) + if (recordingFile == NULL) { recordingConLog(wxString::Format("[REC]: Movie file opening failed. Error - %s\n", strerror(errno))); return false; @@ -95,7 +93,8 @@ bool InputRecordingFile::Close() } // Write savestate flag to file -bool InputRecordingFile::WriteSaveState() { +bool InputRecordingFile::WriteSaveState() +{ if (recordingFile == NULL) { return false; @@ -111,7 +110,7 @@ bool InputRecordingFile::WriteSaveState() { } // Write controller input buffer to file (per frame) -bool InputRecordingFile::WriteKeyBuf(const uint & frame, const uint port, const uint bufIndex, const u8 & buf) +bool InputRecordingFile::WriteKeyBuf(const uint& frame, const uint port, const uint bufIndex, const u8& buf) { if (recordingFile == NULL) { @@ -120,8 +119,7 @@ bool InputRecordingFile::WriteKeyBuf(const uint & frame, const uint port, const long seek = GetBlockSeekPoint(frame) + RecordingBlockHeaderSize + 18 * port + bufIndex; - if (fseek(recordingFile, seek, SEEK_SET) != 0 - || fwrite(&buf, 1, 1, recordingFile) != 1) + if (fseek(recordingFile, seek, SEEK_SET) != 0 || fwrite(&buf, 1, 1, recordingFile) != 1) { return false; } @@ -131,7 +129,7 @@ bool InputRecordingFile::WriteKeyBuf(const uint & frame, const uint port, const } // Read controller input buffer from file (per frame) -bool InputRecordingFile::ReadKeyBuf(u8 & result,const uint & frame, const uint port, const uint bufIndex) +bool InputRecordingFile::ReadKeyBuf(u8& result, const uint& frame, const uint port, const uint bufIndex) { if (recordingFile == NULL) { @@ -152,7 +150,7 @@ bool InputRecordingFile::ReadKeyBuf(u8 & result,const uint & frame, const uint p } -void InputRecordingFile::GetPadData(PadData & result, unsigned long frame) +void InputRecordingFile::GetPadData(PadData& result, unsigned long frame) { result.fExistKey = false; if (recordingFile == NULL) @@ -161,8 +159,7 @@ void InputRecordingFile::GetPadData(PadData & result, unsigned long frame) } long seek = GetBlockSeekPoint(frame) + RecordingBlockHeaderSize; - if (fseek(recordingFile, seek, SEEK_SET) != 0 - || fread(result.buf, 1, RecordingBlockDataSize, recordingFile) == 0) + if (fseek(recordingFile, seek, SEEK_SET) != 0 || fread(result.buf, 1, RecordingBlockDataSize, recordingFile) == 0) { return; } @@ -179,7 +176,7 @@ bool InputRecordingFile::DeletePadData(unsigned long frame) for (unsigned long i = frame; i < MaxFrame - 1; i++) { - long seek1 = GetBlockSeekPoint(i+1) + RecordingBlockHeaderSize; + long seek1 = GetBlockSeekPoint(i + 1) + RecordingBlockHeaderSize; long seek2 = GetBlockSeekPoint(i) + RecordingBlockHeaderSize; u8 buf[2][18]; @@ -215,7 +212,7 @@ bool InputRecordingFile::InsertPadData(unsigned long frame, const PadData& key) for (unsigned long i = MaxFrame - 1; i >= frame; i--) { long seek1 = GetBlockSeekPoint(i) + RecordingBlockHeaderSize; - long seek2 = GetBlockSeekPoint(i+1) + RecordingBlockHeaderSize; + long seek2 = GetBlockSeekPoint(i + 1) + RecordingBlockHeaderSize; u8 buf[2][18]; fseek(recordingFile, seek1, SEEK_SET); @@ -278,10 +275,7 @@ bool InputRecordingFile::ReadHeaderAndCheck() return false; } rewind(recordingFile); - if (fread(&header, sizeof(InputRecordingHeader), 1, recordingFile) != 1 - || fread(&MaxFrame, 4, 1, recordingFile) != 1 - || fread(&UndoCount, 4, 1, recordingFile) != 1 - || fread(&savestate.fromSavestate, sizeof(bool), 1, recordingFile) != 1) + if (fread(&header, sizeof(InputRecordingHeader), 1, recordingFile) != 1 || fread(&MaxFrame, 4, 1, recordingFile) != 1 || fread(&UndoCount, 4, 1, recordingFile) != 1 || fread(&savestate.fromSavestate, sizeof(bool), 1, recordingFile) != 1) { return false; } @@ -359,6 +353,14 @@ void InputRecordingFile::AddUndoCount() fwrite(&UndoCount, 4, 1, recordingFile); } +void InputRecordingHeader::SetEmulatorVersion() +{ + wxString emuVersion = wxString::Format("%s-%d.%d.%d", pxGetAppName().c_str(), PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo); + int max = ArraySize(emu) - 1; + strncpy(emu, emuVersion.c_str(), max); + emu[max] = 0; +} + void InputRecordingHeader::SetAuthor(wxString _author) { int max = ArraySize(author) - 1; @@ -381,7 +383,8 @@ void InputRecordingHeader::Init() InputRecordingHeader& InputRecordingFile::GetHeader() { - return header; } + return header; +} unsigned long& InputRecordingFile::GetMaxFrame() { @@ -393,7 +396,7 @@ unsigned long& InputRecordingFile::GetUndoCount() return UndoCount; } -const wxString & InputRecordingFile::GetFilename() +const wxString& InputRecordingFile::GetFilename() { return filename; } diff --git a/pcsx2/Recording/InputRecordingFile.h b/pcsx2/Recording/InputRecordingFile.h index 778e28f3bc..22d0e14f2d 100644 --- a/pcsx2/Recording/InputRecordingFile.h +++ b/pcsx2/Recording/InputRecordingFile.h @@ -23,11 +23,12 @@ struct InputRecordingHeader { u8 version = 1; - char emu[50] = "PCSX2-1.5.X"; + char emu[50] = ""; char author[255] = ""; char gameName[255] = ""; public: + void SetEmulatorVersion(); void SetAuthor(wxString author); void SetGameName(wxString cdrom); void Init(); @@ -51,11 +52,11 @@ public: // Movie File Manipulation bool Open(const wxString fn, bool fNewOpen, bool fromSaveState); bool Close(); - bool WriteKeyBuf(const uint & frame, const uint port, const uint bufIndex, const u8 & buf); - bool ReadKeyBuf(u8 & result, const uint & frame, const uint port, const uint bufIndex); + bool WriteKeyBuf(const uint& frame, const uint port, const uint bufIndex, const u8& buf); + bool ReadKeyBuf(u8& result, const uint& frame, const uint port, const uint bufIndex); // Controller Data - void GetPadData(PadData & result_pad, unsigned long frame); + void GetPadData(PadData& result_pad, unsigned long frame); bool DeletePadData(unsigned long frame); bool InsertPadData(unsigned long frame, const PadData& key); bool UpdatePadData(unsigned long frame, const PadData& key); @@ -64,7 +65,7 @@ public: InputRecordingHeader& GetHeader(); unsigned long& GetMaxFrame(); unsigned long& GetUndoCount(); - const wxString & GetFilename(); + const wxString& GetFilename(); bool WriteHeader(); bool WriteMaxFrame(); @@ -84,9 +85,9 @@ private: static const int RecordingSeekpointSaveState = RecordingSeekpointUndoCount + 4; // Movie File - FILE * recordingFile = NULL; + FILE* recordingFile = NULL; wxString filename = ""; - long GetBlockSeekPoint(const long & frame); + long GetBlockSeekPoint(const long& frame); // Header InputRecordingHeader header;