2017-12-17 03:43:09 +00:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-07-07 14:30:37 +00:00
|
|
|
#include <functional>
|
2020-04-06 20:23:39 +00:00
|
|
|
#include <boost/serialization/vector.hpp>
|
2017-12-17 03:43:09 +00:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Service {
|
|
|
|
namespace HID {
|
|
|
|
struct AccelerometerDataEntry;
|
|
|
|
struct GyroscopeDataEntry;
|
|
|
|
struct PadState;
|
|
|
|
struct TouchDataEntry;
|
2018-03-09 17:54:43 +00:00
|
|
|
} // namespace HID
|
2017-12-17 03:43:09 +00:00
|
|
|
namespace IR {
|
|
|
|
struct ExtraHIDResponse;
|
|
|
|
union PadState;
|
2018-03-09 17:54:43 +00:00
|
|
|
} // namespace IR
|
|
|
|
} // namespace Service
|
2017-12-17 03:43:09 +00:00
|
|
|
|
2017-12-17 04:55:56 +00:00
|
|
|
namespace Core {
|
|
|
|
struct CTMHeader;
|
|
|
|
struct ControllerState;
|
|
|
|
enum class PlayMode;
|
|
|
|
|
|
|
|
class Movie {
|
|
|
|
public:
|
2018-07-07 14:30:37 +00:00
|
|
|
enum class ValidationResult {
|
|
|
|
OK,
|
|
|
|
RevisionDismatch,
|
|
|
|
GameDismatch,
|
|
|
|
Invalid,
|
|
|
|
};
|
2017-12-17 04:55:56 +00:00
|
|
|
/**
|
2018-03-09 17:54:43 +00:00
|
|
|
* Gets the instance of the Movie singleton class.
|
|
|
|
* @returns Reference to the instance of the Movie singleton class.
|
|
|
|
*/
|
2017-12-17 04:55:56 +00:00
|
|
|
static Movie& GetInstance() {
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2020-08-31 19:06:16 +00:00
|
|
|
void StartPlayback(
|
|
|
|
const std::string& movie_file, std::function<void()> completion_callback = [] {});
|
2018-07-07 14:30:37 +00:00
|
|
|
void StartRecording(const std::string& movie_file);
|
2018-09-26 12:38:57 +00:00
|
|
|
|
2020-06-29 14:32:24 +00:00
|
|
|
/**
|
|
|
|
* Sets the read-only status.
|
|
|
|
* When true, movies will be opened in read-only mode. Loading a state will resume playback
|
|
|
|
* from that state.
|
|
|
|
* When false, movies will be opened in read/write mode. Loading a state will start recording
|
|
|
|
* from that state (rerecording). To start rerecording without loading a state, one can save
|
|
|
|
* and then immediately load while in R/W.
|
|
|
|
*
|
|
|
|
* The default is true.
|
|
|
|
*/
|
|
|
|
void SetReadOnly(bool read_only);
|
|
|
|
|
2018-09-26 12:38:57 +00:00
|
|
|
/// Prepare to override the clock before playing back movies
|
|
|
|
void PrepareForPlayback(const std::string& movie_file);
|
|
|
|
|
|
|
|
/// Prepare to override the clock before recording movies
|
|
|
|
void PrepareForRecording();
|
|
|
|
|
2018-08-08 15:42:23 +00:00
|
|
|
ValidationResult ValidateMovie(const std::string& movie_file, u64 program_id = 0) const;
|
2018-09-26 12:38:57 +00:00
|
|
|
|
|
|
|
/// Get the init time that would override the one in the settings
|
|
|
|
u64 GetOverrideInitTime() const;
|
2018-08-08 15:42:23 +00:00
|
|
|
u64 GetMovieProgramID(const std::string& movie_file) const;
|
2017-12-17 04:55:56 +00:00
|
|
|
|
2020-06-29 14:32:24 +00:00
|
|
|
/// Get the current movie's unique ID. Used to provide separate savestate slots for movies.
|
|
|
|
u64 GetCurrentMovieID() const {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2017-12-17 04:55:56 +00:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When recording: Takes a copy of the given input states so they can be used for playback
|
|
|
|
* When playing: Replaces the given input states with the ones stored in the playback file
|
|
|
|
*/
|
|
|
|
void HandlePadAndCircleStatus(Service::HID::PadState& pad_state, s16& circle_pad_x,
|
|
|
|
s16& circle_pad_y);
|
|
|
|
|
|
|
|
/**
|
2018-03-09 17:54:43 +00:00
|
|
|
* When recording: Takes a copy of the given input states so they can be used for playback
|
|
|
|
* When playing: Replaces the given input states with the ones stored in the playback file
|
|
|
|
*/
|
2017-12-17 04:55:56 +00:00
|
|
|
void HandleTouchStatus(Service::HID::TouchDataEntry& touch_data);
|
|
|
|
|
|
|
|
/**
|
2018-03-09 17:54:43 +00:00
|
|
|
* When recording: Takes a copy of the given input states so they can be used for playback
|
|
|
|
* When playing: Replaces the given input states with the ones stored in the playback file
|
|
|
|
*/
|
2017-12-17 04:55:56 +00:00
|
|
|
void HandleAccelerometerStatus(Service::HID::AccelerometerDataEntry& accelerometer_data);
|
|
|
|
|
|
|
|
/**
|
2018-03-09 17:54:43 +00:00
|
|
|
* When recording: Takes a copy of the given input states so they can be used for playback
|
|
|
|
* When playing: Replaces the given input states with the ones stored in the playback file
|
|
|
|
*/
|
2017-12-17 04:55:56 +00:00
|
|
|
void HandleGyroscopeStatus(Service::HID::GyroscopeDataEntry& gyroscope_data);
|
|
|
|
|
|
|
|
/**
|
2018-03-09 17:54:43 +00:00
|
|
|
* When recording: Takes a copy of the given input states so they can be used for playback
|
|
|
|
* When playing: Replaces the given input states with the ones stored in the playback file
|
|
|
|
*/
|
2017-12-17 04:55:56 +00:00
|
|
|
void HandleIrRst(Service::IR::PadState& pad_state, s16& c_stick_x, s16& c_stick_y);
|
|
|
|
|
|
|
|
/**
|
2018-03-09 17:54:43 +00:00
|
|
|
* When recording: Takes a copy of the given input states so they can be used for playback
|
|
|
|
* When playing: Replaces the given input states with the ones stored in the playback file
|
|
|
|
*/
|
2017-12-17 04:55:56 +00:00
|
|
|
void HandleExtraHidResponse(Service::IR::ExtraHIDResponse& extra_hid_response);
|
2018-07-07 14:30:37 +00:00
|
|
|
bool IsPlayingInput() const;
|
|
|
|
bool IsRecordingInput() const;
|
2017-12-17 04:55:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static Movie s_instance;
|
|
|
|
|
|
|
|
void CheckInputEnd();
|
|
|
|
|
|
|
|
template <typename... Targs>
|
|
|
|
void Handle(Targs&... Fargs);
|
|
|
|
|
|
|
|
void Play(Service::HID::PadState& pad_state, s16& circle_pad_x, s16& circle_pad_y);
|
|
|
|
void Play(Service::HID::TouchDataEntry& touch_data);
|
|
|
|
void Play(Service::HID::AccelerometerDataEntry& accelerometer_data);
|
|
|
|
void Play(Service::HID::GyroscopeDataEntry& gyroscope_data);
|
|
|
|
void Play(Service::IR::PadState& pad_state, s16& c_stick_x, s16& c_stick_y);
|
|
|
|
void Play(Service::IR::ExtraHIDResponse& extra_hid_response);
|
|
|
|
|
|
|
|
void Record(const ControllerState& controller_state);
|
|
|
|
void Record(const Service::HID::PadState& pad_state, const s16& circle_pad_x,
|
|
|
|
const s16& circle_pad_y);
|
|
|
|
void Record(const Service::HID::TouchDataEntry& touch_data);
|
|
|
|
void Record(const Service::HID::AccelerometerDataEntry& accelerometer_data);
|
|
|
|
void Record(const Service::HID::GyroscopeDataEntry& gyroscope_data);
|
|
|
|
void Record(const Service::IR::PadState& pad_state, const s16& c_stick_x, const s16& c_stick_y);
|
|
|
|
void Record(const Service::IR::ExtraHIDResponse& extra_hid_response);
|
|
|
|
|
2018-08-08 15:42:23 +00:00
|
|
|
ValidationResult ValidateHeader(const CTMHeader& header, u64 program_id = 0) const;
|
2017-12-17 04:55:56 +00:00
|
|
|
|
|
|
|
void SaveMovie();
|
|
|
|
|
|
|
|
PlayMode play_mode;
|
2018-07-07 14:30:37 +00:00
|
|
|
std::string record_movie_file;
|
2017-12-17 04:55:56 +00:00
|
|
|
std::vector<u8> recorded_input;
|
2018-09-26 12:38:57 +00:00
|
|
|
u64 init_time;
|
2018-07-07 14:30:37 +00:00
|
|
|
std::function<void()> playback_completion_callback;
|
2018-09-06 20:03:28 +00:00
|
|
|
std::size_t current_byte = 0;
|
2020-06-29 14:32:24 +00:00
|
|
|
u64 id = 0; // ID of the current movie loaded
|
|
|
|
bool read_only = true;
|
2020-04-06 20:23:39 +00:00
|
|
|
|
|
|
|
template <class Archive>
|
2020-06-29 14:32:24 +00:00
|
|
|
void serialize(Archive& ar, const unsigned int file_version);
|
2020-04-06 20:23:39 +00:00
|
|
|
friend class boost::serialization::access;
|
2017-12-17 04:55:56 +00:00
|
|
|
};
|
2020-06-29 14:32:24 +00:00
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
BOOST_CLASS_VERSION(Core::Movie, 1)
|