1 // Copyright (c) 2018- PPSSPP Project.
2 
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6 
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License 2.0 for more details.
11 
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14 
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17 
18 #pragma once
19 
20 #include <cstdint>
21 #include <string>
22 #include <vector>
23 
24 #include "Common/File/Path.h"
25 
26 // Be careful about changing these values (used in file data.)
27 enum class ReplayAction : uint8_t {
28 	BUTTONS = 0x00,
29 	ANALOG = 0x01,
30 
31 	// All of these are just save results of memory stick operations, e.g. if mkdir succeeded, etc.
32 	// We assume the game will generate the same data and syscalls.
33 	FILE_RENAME = 0x40,
34 	FILE_REMOVE = 0x41,
35 	// For FILE_READ, we do save the read data, in case it could change.
36 	FILE_READ = 0xC2,
37 	FILE_OPEN = 0x43,
38 	FILE_SEEK = 0x44,
39 	FILE_INFO = 0xC5,
40 	FILE_LISTING = 0xC6,
41 	MKDIR = 0x47,
42 	RMDIR = 0x48,
43 	FREESPACE = 0x49,
44 
45 	MASK_FILE = 0x40,
46 	MASK_SIDEDATA = 0x80,
47 };
48 
49 struct PSPFileInfo;
50 
51 // Replay from data in memory.  Does not manipulate base time / RNG state.
52 bool ReplayExecuteBlob(int version, const std::vector<uint8_t> &data);
53 // Replay from data in a file.  Returns false if invalid.
54 bool ReplayExecuteFile(const Path &filename);
55 // Returns whether there are unexecuted events to replay.
56 bool ReplayHasMoreEvents();
57 
58 // Begin recording.  If currently executing, discards unexecuted events.
59 void ReplayBeginSave();
60 // Flush buffered events to memory.  Continues recording (next call will receive new events only.)
61 // No header is flushed with this operation - don't mix with ReplayFlushFile().
62 void ReplayFlushBlob(std::vector<uint8_t> *data);
63 // Flush buffered events to file.  Continues recording (next call will receive new events only.)
64 // Do not call with a different filename before ReplayAbort().
65 bool ReplayFlushFile(const Path &filename);
66 // Get current replay data version.
67 int ReplayVersion();
68 
69 // Abort any execute or record operation in progress.
70 void ReplayAbort();
71 
72 // Check if replay data is being executed or saved.
73 bool ReplayIsExecuting();
74 bool ReplayIsSaving();
75 
76 void ReplayApplyCtrl(uint32_t &buttons, uint8_t analog[2][2], uint64_t t);
77 uint32_t ReplayApplyDisk(ReplayAction action, uint32_t result, uint64_t t);
78 uint64_t ReplayApplyDisk64(ReplayAction action, uint64_t result, uint64_t t);
79 uint32_t ReplayApplyDiskRead(void *data, uint32_t readSize, uint32_t dataSize, bool inGameDir, uint64_t t);
80 uint64_t ReplayApplyDiskWrite(const void *data, uint64_t writeSize, uint64_t dataSize, bool *diskFull, bool inGameDir, uint64_t t);
81 PSPFileInfo ReplayApplyDiskFileInfo(const PSPFileInfo &data, uint64_t t);
82 std::vector<PSPFileInfo> ReplayApplyDiskListing(const std::vector<PSPFileInfo> &data, uint64_t t);
83