coastline 0.0.4
Loading...
Searching...
No Matches
controllerpak.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <cstddef>
11#include <cstdint>
12#include <filesystem>
13#include <optional>
14#include <span>
15#include <string>
16#include <vector>
17
18#include "savefile.h"
19
20namespace coastline {
21
23inline constexpr std::size_t PAK_PAGE_BYTES = 0x100;
24
26inline constexpr std::size_t PAK_PAGES = 123;
27
29inline constexpr std::size_t PAK_NOTES = 16;
30
36
38inline constexpr std::string_view PAK_SETTINGS_NOTE = "TOP GEAR OPTIONS";
39
42public:
51 std::filesystem::path settingsDirectory = {});
52
61 ReadNote(const std::string &name, const SavePayloadValidator &validate = {}) const;
62
70 bool WriteNote(const std::string &name, std::span<const std::uint8_t> bytes) const;
71
76 bool DeleteNote(const std::string &name) const;
77
80
83
91
92private:
93 // The directory a note of the name is stored in.
94 const std::filesystem::path &DirectoryOf(const std::string &name) const;
95
96 std::filesystem::path m_directory;
97 std::filesystem::path m_settingsDirectory;
98};
99
101inline constexpr std::size_t PAK_IMAGE_BYTES = 0x8000;
102
104enum class PakRelease {
108};
109
122 const std::filesystem::path &file,
123 PakRelease release = PakRelease::Usa);
124
135 const std::filesystem::path &file);
136
137} // namespace coastline
The notes of a Controller Pak, stored in a directory, with the settings note in another.
Definition controllerpak.h:41
std::size_t FreeBytes() const
bool WriteNote(const std::string &name, std::span< const std::uint8_t > bytes) const
Atomically write a complete note with its integrity header and checksum.
std::optional< std::vector< std::uint8_t > > ReadNote(const std::string &name, const SavePayloadValidator &validate={}) const
Validate the note's integrity header and checksum, attempting to delete corrupt saves.
ControllerPak(std::filesystem::path directory, std::filesystem::path settingsDirectory={})
Select note directories without creating or reading them.
std::vector< PakNote > Notes() const
bool DeleteNote(const std::string &name) const
ControllerPak Subdirectory(const std::filesystem::path &directory) const
Store independent notes beneath the Controller Pak directory without using its capacity.
Definition assetimport.h:11
std::optional< std::string > ExportPakImage(const ControllerPak &pak, const std::filesystem::path &file, PakRelease release=PakRelease::Usa)
Write the notes of a pak as the image of a formatted Controller Pak, with the game code and the compa...
constexpr std::size_t PAK_PAGE_BYTES
The bytes of a page of a Controller Pak, the unit a note takes its room in.
Definition controllerpak.h:23
PakRelease
The release of the cartridge whose game code and company code the notes of an image take.
Definition controllerpak.h:104
@ Jpn
Definition controllerpak.h:107
@ Usa
Definition controllerpak.h:105
@ Eur
Definition controllerpak.h:106
std::optional< std::string > ImportPakImage(const ControllerPak &pak, const std::filesystem::path &file)
Copy the notes of any release of the game from the image of a Controller Pak, or from the first pak o...
constexpr std::size_t PAK_IMAGE_BYTES
The bytes of the image of a Controller Pak, as emulators and the tools of a pak store one.
Definition controllerpak.h:101
constexpr std::string_view PAK_SETTINGS_NOTE
The note of the settings of the options menu, stored with the settings of the game.
Definition controllerpak.h:38
std::function< bool(std::span< const std::uint8_t >)> SavePayloadValidator
Validate format-specific fields of an internal save's payload under its exclusive process lock.
Definition savefile.h:19
constexpr std::size_t PAK_PAGES
The pages of a Controller Pak free for notes.
Definition controllerpak.h:26
constexpr std::size_t PAK_NOTES
The notes a Controller Pak has room for.
Definition controllerpak.h:29
A note of a Controller Pak.
Definition controllerpak.h:32
std::string name
Definition controllerpak.h:33
std::size_t bytes
Definition controllerpak.h:34