From 350aff3a60386ecebc2be42d1ff2e71ec0230adc Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 19 Jan 2024 15:56:14 -0500 Subject: Fix some bad memory access stuff --- src/game_data.cpp | 181 +++++++++++++++++++++++++++++------------------------- 1 file changed, 99 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/game_data.cpp b/src/game_data.cpp index 5204262..8f237b0 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp @@ -98,16 +98,14 @@ struct GameData { for (const auto &room_it : lingo_config) { int room_id = AddOrGetRoom(room_it.first.as()); - Room &room_obj = rooms_[room_id]; for (const auto &entrance_it : room_it.second["entrances"]) { int from_room_id = AddOrGetRoom(entrance_it.first.as()); - Room &from_room_obj = rooms_[from_room_id]; switch (entrance_it.second.Type()) { case YAML::NodeType::Scalar: { // This is just "true". - from_room_obj.exits.push_back({.destination_room = room_id}); + rooms_[from_room_id].exits.push_back({.destination_room = room_id}); break; } case YAML::NodeType::Map: { @@ -115,7 +113,7 @@ struct GameData { exit_obj.destination_room = room_id; if (entrance_it.second["door"]) { - std::string door_room = room_obj.name; + std::string door_room = rooms_[room_id].name; if (entrance_it.second["room"]) { door_room = entrance_it.second["room"].as(); } @@ -127,7 +125,7 @@ struct GameData { exit_obj.painting = entrance_it.second["painting"].as(); } - from_room_obj.exits.push_back(exit_obj); + rooms_[from_room_id].exits.push_back(exit_obj); break; } case YAML::NodeType::Sequence: { @@ -135,7 +133,7 @@ struct GameData { Exit exit_obj; exit_obj.destination_room = room_id; - std::string door_room = room_obj.name; + std::string door_room = rooms_[room_id].name; if (option["room"]) { door_room = option["room"].as(); } @@ -146,7 +144,7 @@ struct GameData { exit_obj.painting = option["painting"].as(); } - from_room_obj.exits.push_back(exit_obj); + rooms_[from_room_id].exits.push_back(exit_obj); } break; @@ -162,18 +160,17 @@ struct GameData { if (room_it.second["panels"]) { for (const auto &panel_it : room_it.second["panels"]) { - int panel_id = - AddOrGetPanel(room_obj.name, panel_it.first.as()); - Panel &panel_obj = panels_[panel_id]; - room_obj.panels.push_back(panel_id); + int panel_id = AddOrGetPanel(rooms_[room_id].name, + panel_it.first.as()); + rooms_[room_id].panels.push_back(panel_id); if (panel_it.second["colors"]) { if (panel_it.second["colors"].IsScalar()) { - panel_obj.colors.push_back(GetColorForString( + panels_[panel_id].colors.push_back(GetColorForString( panel_it.second["colors"].as())); } else { for (const auto &color_node : panel_it.second["colors"]) { - panel_obj.colors.push_back( + panels_[panel_id].colors.push_back( GetColorForString(color_node.as())); } } @@ -181,11 +178,11 @@ struct GameData { if (panel_it.second["required_room"]) { if (panel_it.second["required_room"].IsScalar()) { - panel_obj.required_rooms.push_back(AddOrGetRoom( + panels_[panel_id].required_rooms.push_back(AddOrGetRoom( panel_it.second["required_room"].as())); } else { for (const auto &rr_node : panel_it.second["required_room"]) { - panel_obj.required_rooms.push_back( + panels_[panel_id].required_rooms.push_back( AddOrGetRoom(rr_node.as())); } } @@ -193,23 +190,22 @@ struct GameData { if (panel_it.second["required_door"]) { if (panel_it.second["required_door"].IsMap()) { - std::string rd_room = room_obj.name; + std::string rd_room = rooms_[room_id].name; if (panel_it.second["required_door"]["room"]) { rd_room = panel_it.second["required_door"]["room"].as(); } - panel_obj.required_doors.push_back(AddOrGetDoor( + panels_[panel_id].required_doors.push_back(AddOrGetDoor( rd_room, panel_it.second["required_door"]["door"].as())); } else { for (const auto &rr_node : panel_it.second["required_door"]) { - std::string rd_room = room_obj.name; + std::string rd_room = rooms_[room_id].name; if (rr_node["room"]) { rd_room = rr_node["room"].as(); - } - - panel_obj.required_doors.push_back( + }; + panels_[panel_id].required_doors.push_back( AddOrGetDoor(rd_room, rr_node["door"].as())); } } @@ -217,61 +213,68 @@ struct GameData { if (panel_it.second["required_panel"]) { if (panel_it.second["required_panel"].IsMap()) { - std::string rp_room = room_obj.name; + std::string rp_room = rooms_[room_id].name; if (panel_it.second["required_panel"]["room"]) { rp_room = panel_it.second["required_panel"]["room"].as(); } - panel_obj.required_panels.push_back(AddOrGetPanel( - rp_room, panel_it.second["required_panel"]["panel"] - .as())); + int rp_id = AddOrGetPanel( + rp_room, + panel_it.second["required_panel"]["panel"].as()); + panels_[panel_id].required_panels.push_back(rp_id); } else { for (const auto &rp_node : panel_it.second["required_panel"]) { - std::string rp_room = room_obj.name; + std::string rp_room = rooms_[room_id].name; if (rp_node["room"]) { rp_room = rp_node["room"].as(); } - panel_obj.required_panels.push_back( - AddOrGetPanel(rp_room, rp_node["panel"].as())); + int rp_id = + AddOrGetPanel(rp_room, rp_node["panel"].as()); + panels_[panel_id].required_panels.push_back(rp_id); } } } if (panel_it.second["check"]) { - panel_obj.check = panel_it.second["check"].as(); + panels_[panel_id].check = panel_it.second["check"].as(); } if (panel_it.second["achievement"]) { - panel_obj.achievement = true; - panel_obj.achievement_name = + panels_[panel_id].achievement = true; + panels_[panel_id].achievement_name = panel_it.second["achievement"].as(); achievement_panels_.push_back(panel_id); } if (panel_it.second["hunt"]) { - panel_obj.hunt = panel_it.second["hunt"].as(); + panels_[panel_id].hunt = panel_it.second["hunt"].as(); } if (panel_it.second["exclude_reduce"]) { - panel_obj.exclude_reduce = + panels_[panel_id].exclude_reduce = panel_it.second["exclude_reduce"].as(); } if (panel_it.second["non_counting"]) { - panel_obj.non_counting = panel_it.second["non_counting"].as(); + panels_[panel_id].non_counting = + panel_it.second["non_counting"].as(); } - if (ids_config["panels"] && ids_config["panels"][room_obj.name] && - ids_config["panels"][room_obj.name][panel_obj.name]) { - panel_obj.ap_location_id = - ids_config["panels"][room_obj.name][panel_obj.name].as(); + if (ids_config["panels"] && + ids_config["panels"][rooms_[room_id].name] && + ids_config["panels"][rooms_[room_id].name] + [panels_[panel_id].name]) { + panels_[panel_id].ap_location_id = + ids_config["panels"][rooms_[room_id].name] + [panels_[panel_id].name] + .as(); } else { std::ostringstream errmsg; - errmsg << "Missing AP location ID for panel " << room_obj.name - << " - " << panel_obj.name; + errmsg << "Missing AP location ID for panel " + << rooms_[room_id].name << " - " << panels_[panel_id].name; TrackerLog(errmsg.str()); } } @@ -279,10 +282,9 @@ struct GameData { if (room_it.second["doors"]) { for (const auto &door_it : room_it.second["doors"]) { - int door_id = - AddOrGetDoor(room_obj.name, door_it.first.as()); + int door_id = AddOrGetDoor(rooms_[room_id].name, + door_it.first.as()); door_definition_order_.push_back(door_id); - Door &door_obj = doors_[door_id]; bool has_external_panels = false; std::vector panel_names; @@ -290,103 +292,117 @@ struct GameData { for (const auto &panel_node : door_it.second["panels"]) { if (panel_node.IsScalar()) { panel_names.push_back(panel_node.as()); - door_obj.panels.push_back( - AddOrGetPanel(room_obj.name, panel_node.as())); + doors_[door_id].panels.push_back(AddOrGetPanel( + rooms_[room_id].name, panel_node.as())); } else { has_external_panels = true; panel_names.push_back(panel_node["panel"].as()); - door_obj.panels.push_back( + doors_[door_id].panels.push_back( AddOrGetPanel(panel_node["room"].as(), panel_node["panel"].as())); } } if (door_it.second["skip_location"]) { - door_obj.skip_location = door_it.second["skip_location"].as(); + doors_[door_id].skip_location = + door_it.second["skip_location"].as(); } if (door_it.second["skip_item"]) { - door_obj.skip_item = door_it.second["skip_item"].as(); + doors_[door_id].skip_item = door_it.second["skip_item"].as(); } if (door_it.second["event"]) { - door_obj.skip_location = door_it.second["event"].as(); - door_obj.skip_item = door_it.second["event"].as(); - door_obj.is_event = door_it.second["event"].as(); + doors_[door_id].skip_location = door_it.second["event"].as(); + doors_[door_id].skip_item = door_it.second["event"].as(); + doors_[door_id].is_event = door_it.second["event"].as(); } if (door_it.second["item_name"]) { - door_obj.item_name = door_it.second["item_name"].as(); + doors_[door_id].item_name = + door_it.second["item_name"].as(); } else if (!door_it.second["skip_item"] && !door_it.second["event"]) { - door_obj.item_name = room_obj.name + " - " + door_obj.name; + doors_[door_id].item_name = + rooms_[room_id].name + " - " + doors_[door_id].name; } if (!door_it.second["skip_item"] && !door_it.second["event"]) { - if (ids_config["doors"] && ids_config["doors"][room_obj.name] && - ids_config["doors"][room_obj.name][door_obj.name] && - ids_config["doors"][room_obj.name][door_obj.name]["item"]) { - door_obj.ap_item_id = - ids_config["doors"][room_obj.name][door_obj.name]["item"] - .as(); + if (ids_config["doors"] && + ids_config["doors"][rooms_[room_id].name] && + ids_config["doors"][rooms_[room_id].name] + [doors_[door_id].name] && + ids_config["doors"][rooms_[room_id].name][doors_[door_id].name] + ["item"]) { + doors_[door_id].ap_item_id = + ids_config["doors"][rooms_[room_id].name] + [doors_[door_id].name]["item"] + .as(); } else { std::ostringstream errmsg; - errmsg << "Missing AP item ID for door " << room_obj.name << " - " - << door_obj.name; + errmsg << "Missing AP item ID for door " << rooms_[room_id].name + << " - " << doors_[door_id].name; TrackerLog(errmsg.str()); } } if (door_it.second["group"]) { - door_obj.group_name = door_it.second["group"].as(); + doors_[door_id].group_name = + door_it.second["group"].as(); if (ids_config["door_groups"] && - ids_config["door_groups"][door_obj.group_name]) { - door_obj.group_ap_item_id = - ids_config["door_groups"][door_obj.group_name].as(); + ids_config["door_groups"][doors_[door_id].group_name]) { + doors_[door_id].group_ap_item_id = + ids_config["door_groups"][doors_[door_id].group_name] + .as(); } else { std::ostringstream errmsg; errmsg << "Missing AP item ID for door group " - << door_obj.group_name; + << doors_[door_id].group_name; TrackerLog(errmsg.str()); } } if (door_it.second["location_name"]) { - door_obj.location_name = + doors_[door_id].location_name = door_it.second["location_name"].as(); } else if (!door_it.second["skip_location"] && !door_it.second["event"]) { if (has_external_panels) { std::ostringstream errmsg; errmsg - << room_obj.name << " - " << door_obj.name + << rooms_[room_id].name << " - " << doors_[door_id].name << " has panels from other rooms but does not have an " "explicit " "location name and is not marked skip_location or event"; TrackerLog(errmsg.str()); } - door_obj.location_name = - room_obj.name + " - " + hatkirby::implode(panel_names, ", "); + doors_[door_id].location_name = + rooms_[room_id].name + " - " + + hatkirby::implode(panel_names, ", "); } if (!door_it.second["skip_location"] && !door_it.second["event"]) { - if (ids_config["doors"] && ids_config["doors"][room_obj.name] && - ids_config["doors"][room_obj.name][door_obj.name] && - ids_config["doors"][room_obj.name][door_obj.name]["location"]) { - door_obj.ap_location_id = - ids_config["doors"][room_obj.name][door_obj.name]["location"] - .as(); + if (ids_config["doors"] && + ids_config["doors"][rooms_[room_id].name] && + ids_config["doors"][rooms_[room_id].name] + [doors_[door_id].name] && + ids_config["doors"][rooms_[room_id].name][doors_[door_id].name] + ["location"]) { + doors_[door_id].ap_location_id = + ids_config["doors"][rooms_[room_id].name] + [doors_[door_id].name]["location"] + .as(); } else { std::ostringstream errmsg; - errmsg << "Missing AP location ID for door " << room_obj.name - << " - " << door_obj.name; + errmsg << "Missing AP location ID for door " + << rooms_[room_id].name << " - " << doors_[door_id].name; TrackerLog(errmsg.str()); } } if (door_it.second["include_reduce"]) { - door_obj.exclude_reduce = + doors_[door_id].exclude_reduce = !door_it.second["include_reduce"].as(); } } @@ -402,7 +418,7 @@ struct GameData { painting_exit.id = painting_id; if (painting["required_door"]) { - std::string rd_room = room_obj.name; + std::string rd_room = rooms_[room_id].name; if (painting["required_door"]["room"]) { rd_room = painting["required_door"]["room"].as(); } @@ -411,7 +427,7 @@ struct GameData { rd_room, painting["required_door"]["door"].as()); } - room_obj.paintings.push_back(painting_exit); + rooms_[room_id].paintings.push_back(painting_exit); } } } @@ -438,7 +454,8 @@ struct GameData { int door_id = -1; if (stage.IsScalar()) { - door_id = AddOrGetDoor(room_obj.name, stage.as()); + door_id = + AddOrGetDoor(rooms_[room_id].name, stage.as()); } else { door_id = AddOrGetDoor(stage["room"].as(), stage["door"].as()); -- cgit 1.4.1