| 202 | } |
| 203 | |
| 204 | std::vector<N64Recomp::FunctionTextHook> get_function_hooks(const toml::table* patches_data) { |
| 205 | std::vector<N64Recomp::FunctionTextHook> ret; |
| 206 | |
| 207 | // Check if the function hook array exists. |
| 208 | const toml::node_view func_hook_data = (*patches_data)["hook"]; |
| 209 | |
| 210 | if (func_hook_data.is_array()) { |
| 211 | const toml::array* func_hook_array = func_hook_data.as_array(); |
| 212 | ret.reserve(func_hook_array->size()); |
| 213 | |
| 214 | // Copy all the hooks into the output vector. |
| 215 | func_hook_array->for_each([&ret](auto&& el) { |
| 216 | if constexpr (toml::is_table<decltype(el)>) { |
| 217 | const toml::table& cur_hook = *el.as_table(); |
| 218 | |
| 219 | // Get the vram and make sure it's 4-byte aligned. |
| 220 | std::optional<uint32_t> before_vram = cur_hook["before_vram"].value<uint32_t>(); |
| 221 | std::optional<std::string> func_name = cur_hook["func"].value<std::string>(); |
| 222 | std::optional<std::string> text = cur_hook["text"].value<std::string>(); |
| 223 | |
| 224 | if (!func_name.has_value() || !text.has_value()) { |
| 225 | throw toml::parse_error("Function hook is missing required value(s)", el.source()); |
| 226 | } |
| 227 | |
| 228 | if (before_vram.has_value() && before_vram.value() & 0b11) { |
| 229 | // Not properly aligned, so throw an error (and make it look like a normal toml one). |
| 230 | throw toml::parse_error("before_vram is not word-aligned", el.source()); |
| 231 | } |
| 232 | |
| 233 | ret.push_back(N64Recomp::FunctionTextHook{ |
| 234 | .func_name = func_name.value(), |
| 235 | .before_vram = before_vram.has_value() ? (int32_t)before_vram.value() : 0, |
| 236 | .text = text.value(), |
| 237 | }); |
| 238 | } |
| 239 | else { |
| 240 | throw toml::parse_error("Invalid function hook entry", el.source()); |
| 241 | } |
| 242 | }); |
| 243 | } |
| 244 | |
| 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | void get_mdebug_mappings(const toml::array* mdebug_mappings_array, |
| 249 | std::unordered_map<std::string, std::string>& mdebug_text_map, |