| 691 | } |
| 692 | |
| 693 | bool patch_engine::add_patch_data(YAML::Node node, patch_info& info, u32 modifier, const YAML::Node& root, std::string_view path, std::stringstream* log_messages) |
| 694 | { |
| 695 | if (!node || !node.IsSequence()) |
| 696 | { |
| 697 | append_log_message(log_messages, fmt::format("Skipping invalid patch node %s. (key: %s, location: %s, file: %s)", info.description, info.hash, get_yaml_node_location(node), path), &patch_log.error); |
| 698 | return false; |
| 699 | } |
| 700 | |
| 701 | const auto type_node = node[0]; |
| 702 | const auto addr_node = node[1]; |
| 703 | const auto value_node = node[2]; |
| 704 | |
| 705 | const auto type = get_patch_type(type_node); |
| 706 | |
| 707 | if (type == patch_type::invalid) |
| 708 | { |
| 709 | const auto type_str = type_node && type_node.IsScalar() ? type_node.Scalar() : ""; |
| 710 | append_log_message(log_messages, fmt::format("Skipping patch node %s: type '%s' is invalid. (key: %s, location: %s, file: %s)", info.description, type_str, info.hash, get_yaml_node_location(node), path), &patch_log.error); |
| 711 | return false; |
| 712 | } |
| 713 | |
| 714 | if (type == patch_type::load) |
| 715 | { |
| 716 | // Special syntax: anchors (named sequence) |
| 717 | |
| 718 | // Check if the anchor was resolved. |
| 719 | if (const auto yml_type = addr_node.Type(); yml_type != YAML::NodeType::Sequence) |
| 720 | { |
| 721 | append_log_message(log_messages, fmt::format("Skipping patch node %s: expected Sequence, found %s (key: %s, location: %s, file: %s)", info.description, yml_type, info.hash, get_yaml_node_location(node), path), &patch_log.error); |
| 722 | return false; |
| 723 | } |
| 724 | |
| 725 | // Address modifier (optional) |
| 726 | const u32 mod = value_node.as<u32>(0); |
| 727 | |
| 728 | bool is_valid = true; |
| 729 | |
| 730 | for (const auto& item : addr_node) |
| 731 | { |
| 732 | if (!add_patch_data(item, info, mod, root, path, log_messages)) |
| 733 | { |
| 734 | is_valid = false; |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | return is_valid; |
| 739 | } |
| 740 | |
| 741 | if (const auto yml_type = value_node.Type(); yml_type != YAML::NodeType::Scalar) |
| 742 | { |
| 743 | append_log_message(log_messages, fmt::format("Skipping patch node %s. Value element has wrong type %s. (key: %s, location: %s, file: %s)", info.description, yml_type, info.hash, get_yaml_node_location(node), path), &patch_log.error); |
| 744 | return false; |
| 745 | } |
| 746 | |
| 747 | if (patch_type_uses_hex_offset(type) && !addr_node.Scalar().starts_with("0x")) |
| 748 | { |
| 749 | append_log_message(log_messages, fmt::format("Skipping patch node %s. Address element has wrong format %s. (key: %s, location: %s, file: %s)", info.description, addr_node.Scalar(), info.hash, get_yaml_node_location(node), path), &patch_log.error); |
| 750 | return false; |
nothing calls this directly
no test coverage detected