1#ifndef YAZE_CLI_COMMAND_HANDLER_H
2#define YAZE_CLI_COMMAND_HANDLER_H
9#include <unordered_map>
12#include "absl/status/status.h"
16#include "asar-dll-bindings/c/asar.h"
41 return os <<
"\033[" << mod.
code <<
"m";
49 virtual absl::Status
handle(
const std::vector<std::string>& arg_vec) = 0;
56 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override;
61 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override;
66 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override;
74 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override {
78 auto const& arg = arg_vec[0];
80 std::cout <<
"Title: " << green <<
rom_.
title() << std::endl;
81 std::cout << reset <<
"Size: " << blue <<
"0x" << std::hex <<
rom_.
size()
82 << reset << std::endl;
83 return absl::OkStatus();
92 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override {
94 if (arg_vec.size() == 2) {
100 return absl::OkStatus();
107 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override;
117 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override;
128 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override {
129 auto arg = arg_vec[0];
130 std::stringstream ss(arg.data());
131 uint32_t snes_address;
132 ss >> std::hex >> snes_address;
134 std::cout << std::hex << pc_address << std::endl;
135 return absl::OkStatus();
147 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override {
148 auto arg = arg_vec[0];
149 std::stringstream ss(arg.data());
151 ss >> std::hex >> pc_address;
154 std::cout <<
"SNES LoROM Address: ";
155 std::cout << blue <<
"$" << std::uppercase << std::hex << snes_address
157 return absl::OkStatus();
169 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override {
172 std::stringstream ss(arg_vec[1].data());
174 ss >> std::hex >> offset;
175 uint32_t length = 0x01;
176 if (!arg_vec[2].empty()) {
177 length = std::stoi(arg_vec[2]);
182 if (!returned_bytes_status.ok()) {
183 return returned_bytes_status.status();
185 auto returned_bytes = returned_bytes_status.value();
186 for (
const auto& each : returned_bytes) {
189 std::cout << std::endl;
192 std::cout << std::hex <<
byte.value() << std::endl;
195 return absl::OkStatus();
207 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override;
218 absl::Status
handle(
const std::vector<std::string>& arg_vec)
override {
221 std::stringstream ss(arg_vec[1].data());
223 ss >> std::hex >> size;
227 std::cout <<
"Successfully expanded ROM to " << std::hex << size
230 return absl::OkStatus();
238 std::unordered_map<std::string, std::shared_ptr<CommandHandler>>
handlers = {
239 {
"-a", std::make_shared<ApplyPatch>()},
240 {
"-asar", std::make_shared<AsarPatch>()},
241 {
"-c", std::make_shared<CreatePatch>()},
242 {
"-o", std::make_shared<Open>()},
243 {
"-b", std::make_shared<Backup>()},
244 {
"-x", std::make_shared<Expand>()},
245 {
"-i", std::make_shared<Compress>()},
246 {
"-e", std::make_shared<Decompress>()},
247 {
"-s", std::make_shared<SnesToPc>()},
248 {
"-p", std::make_shared<PcToSnes>()},
249 {
"-t", std::make_shared<Tile16Transfer>()},
250 {
"-r", std::make_shared<ReadFromRom>()}
The Rom class is used to load, save, and modify Rom data.
absl::Status SaveToFile(bool backup, bool save_new=false, std::string filename="")
Saves the Rom data to a file.
void Expand(int size)
Expand the Rom data to a specified size.
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
absl::StatusOr< uint8_t > ReadByte(int offset)
absl::StatusOr< std::vector< uint8_t > > ReadByteVector(uint32_t offset, uint32_t length)
absl::Status handle(const std::vector< std::string > &arg_vec) override
absl::Status handle(const std::vector< std::string > &arg_vec) override
absl::Status handle(const std::vector< std::string > &arg_vec) override
friend std::ostream & operator<<(std::ostream &os, const ColorModifier &mod)
ColorModifier(ColorCode pCode)
virtual ~CommandHandler()=default
virtual absl::Status handle(const std::vector< std::string > &arg_vec)=0
absl::Status handle(const std::vector< std::string > &arg_vec) override
absl::Status handle(const std::vector< std::string > &arg_vec) override
absl::Status handle(const std::vector< std::string > &arg_vec) override
absl::Status handle(const std::vector< std::string > &arg_vec) override
Open a Rom file and display information about it.
absl::Status handle(const std::vector< std::string > &arg_vec) override
Convert a PC address to a SNES address.
absl::Status handle(const std::vector< std::string > &arg_vec) override
absl::Status handle(const std::vector< std::string > &arg_vec) override
Convert a SNES address to a PC address.
absl::Status handle(const std::vector< std::string > &arg_vec) override
Transfer tile 16 data from one Rom to another.
absl::Status handle(const std::vector< std::string > &arg_vec) override
#define RETURN_IF_ERROR(expression)
uint32_t PcToSnes(uint32_t addr)
uint32_t SnesToPc(uint32_t addr) noexcept
Command handler for the CLI.
std::unordered_map< std::string, std::shared_ptr< CommandHandler > > handlers