yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
asm_patch.h
Go to the documentation of this file.
1#ifndef YAZE_CORE_PATCH_ASM_PATCH_H
2#define YAZE_CORE_PATCH_ASM_PATCH_H
3
4#include <string>
5#include <vector>
6
7#include "absl/status/status.h"
8
9namespace yaze::core {
10
17 kByte, // 8-bit value (0-255)
18 kWord, // 16-bit value (0-65535)
19 kLong, // 24-bit value (0-16777215)
20 kBool, // Boolean toggle with custom checked/unchecked values
21 kChoice, // Radio button selection from choice0-choice9
22 kBitfield, // Checkbox group for bit flags (bit0-bit7)
23 kItem // Game item selection dropdown
24};
25
34 std::string define_name; // Asar define name (e.g., "!MY_DEFINE")
35 std::string display_name; // User-friendly display name
37 int value = 0; // Current value
38 int min_value = 0; // Minimum allowed value
39 int max_value = 0xFF; // Maximum allowed value
40 int checked_value = 1; // Value when checkbox is checked (bool type)
41 int unchecked_value = 0; // Value when checkbox is unchecked (bool type)
42 bool use_decimal = false; // Display value as decimal instead of hex
43 std::vector<std::string> choices; // Choice labels (choice/bitfield types)
44};
45
74class AsmPatch {
75 public:
81 AsmPatch(const std::string& file_path, const std::string& folder);
82
83 // Metadata accessors
84 const std::string& name() const { return name_; }
85 const std::string& author() const { return author_; }
86 const std::string& version() const { return version_; }
87 const std::string& description() const { return description_; }
88 const std::string& folder() const { return folder_; }
89 const std::string& filename() const { return filename_; }
90 const std::string& file_path() const { return file_path_; }
91
92 // Enable/disable state
93 bool enabled() const { return enabled_; }
95
96 // Parameter access
97 const std::vector<PatchParameter>& parameters() const { return parameters_; }
98 std::vector<PatchParameter>& mutable_parameters() { return parameters_; }
99
106 bool SetParameterValue(const std::string& define_name, int value);
107
113 PatchParameter* GetParameter(const std::string& define_name);
114 const PatchParameter* GetParameter(const std::string& define_name) const;
115
120 std::string GenerateContent() const;
121
126 absl::Status Save();
127
133 absl::Status SaveToPath(const std::string& output_path);
134
138 bool is_valid() const { return is_valid_; }
139
140 private:
145 void ParseMetadata(const std::string& content);
146
152 static PatchParameterType ParseType(const std::string& type_str);
153
159 static int ParseValue(const std::string& value_str);
160
167 static void UpdateLine(std::string& content, const std::string& prefix,
168 const std::string& new_value);
169
176 static void UpdateDefineLine(std::string& content,
177 const std::string& define_name, int value);
178
179 // Patch metadata
180 std::string name_;
181 std::string author_;
182 std::string version_;
183 std::string description_;
184 std::string folder_;
185 std::string filename_;
186 std::string file_path_;
187 std::string original_content_;
188 bool enabled_ = true;
189 bool is_valid_ = false;
190
191 // Configurable parameters
192 std::vector<PatchParameter> parameters_;
193};
194
195} // namespace yaze::core
196
197#endif // YAZE_CORE_PATCH_ASM_PATCH_H
Represents a ZScream-compatible ASM patch file.
Definition asm_patch.h:74
absl::Status Save()
Save the patch to its original file location.
Definition asm_patch.cc:375
std::string description_
Definition asm_patch.h:183
AsmPatch(const std::string &file_path, const std::string &folder)
Construct a patch from a file path.
Definition asm_patch.cc:35
std::string name_
Definition asm_patch.h:180
static void UpdateLine(std::string &content, const std::string &prefix, const std::string &new_value)
Update a line in the content that starts with a prefix.
Definition asm_patch.cc:343
std::vector< PatchParameter > parameters_
Definition asm_patch.h:192
std::string filename_
Definition asm_patch.h:185
std::string file_path_
Definition asm_patch.h:186
const std::string & version() const
Definition asm_patch.h:86
const std::vector< PatchParameter > & parameters() const
Definition asm_patch.h:97
bool SetParameterValue(const std::string &define_name, int value)
Set the value of a parameter by its define name.
Definition asm_patch.cc:300
std::vector< PatchParameter > & mutable_parameters()
Definition asm_patch.h:98
const std::string & folder() const
Definition asm_patch.h:88
PatchParameter * GetParameter(const std::string &define_name)
Get a parameter by its define name.
Definition asm_patch.cc:310
bool enabled() const
Definition asm_patch.h:93
std::string folder_
Definition asm_patch.h:184
std::string original_content_
Definition asm_patch.h:187
static void UpdateDefineLine(std::string &content, const std::string &define_name, int value)
Update an Asar define line with a new value.
Definition asm_patch.cc:358
const std::string & author() const
Definition asm_patch.h:85
static PatchParameterType ParseType(const std::string &type_str)
Parse a parameter type from a string.
Definition asm_patch.cc:247
std::string GenerateContent() const
Generate the patch file content with current parameter values.
Definition asm_patch.cc:329
const std::string & filename() const
Definition asm_patch.h:89
const std::string & description() const
Definition asm_patch.h:87
std::string author_
Definition asm_patch.h:181
const std::string & name() const
Definition asm_patch.h:84
std::string version_
Definition asm_patch.h:182
void set_enabled(bool enabled)
Definition asm_patch.h:94
static int ParseValue(const std::string &value_str)
Parse an integer value from a string (handles $hex and decimal)
Definition asm_patch.cc:269
bool is_valid() const
Check if the patch was loaded successfully.
Definition asm_patch.h:138
const std::string & file_path() const
Definition asm_patch.h:90
absl::Status SaveToPath(const std::string &output_path)
Save the patch to a specific path.
Definition asm_patch.cc:379
void ParseMetadata(const std::string &content)
Parse metadata from the patch file content.
Definition asm_patch.cc:60
PatchParameterType
Parameter types supported by ZScream-compatible ASM patches.
Definition asm_patch.h:16
Represents a configurable parameter within an ASM patch.
Definition asm_patch.h:33
PatchParameterType type
Definition asm_patch.h:36
std::vector< std::string > choices
Definition asm_patch.h:43