| 112 | //=========================================================================== |
| 113 | |
| 114 | MapData *P_OpenMapData(const char * mapname, bool justcheck) |
| 115 | { |
| 116 | MapData * map = new MapData; |
| 117 | FileReader * wadReader = nullptr; |
| 118 | bool externalfile = !strnicmp(mapname, "file:", 5); |
| 119 | |
| 120 | if (externalfile) |
| 121 | { |
| 122 | mapname += 5; |
| 123 | if (!FileExists(mapname)) |
| 124 | { |
| 125 | delete map; |
| 126 | return NULL; |
| 127 | } |
| 128 | map->resource = FResourceFile::OpenResourceFile(mapname); |
| 129 | wadReader = map->resource->GetContainerReader(); |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | FString fmt; |
| 134 | int lump_wad; |
| 135 | int lump_map; |
| 136 | int lump_name = -1; |
| 137 | |
| 138 | // Check for both *.wad and *.map in order to load Build maps |
| 139 | // as well. The higher one will take precedence. |
| 140 | // Names with more than 8 characters will only be checked as .wad and .map. |
| 141 | if (strlen(mapname) <= 8) lump_name = fileSystem.CheckNumForName(mapname); |
| 142 | fmt.Format("maps/%s.wad", mapname); |
| 143 | lump_wad = fileSystem.CheckNumForFullName(fmt.GetChars()); |
| 144 | fmt.Format("maps/%s.map", mapname); |
| 145 | lump_map = fileSystem.CheckNumForFullName(fmt.GetChars()); |
| 146 | |
| 147 | if (lump_name > lump_wad && lump_name > lump_map && lump_name != -1) |
| 148 | { |
| 149 | int lumpfile = fileSystem.GetFileContainer(lump_name); |
| 150 | int nextfile = fileSystem.GetFileContainer(lump_name+1); |
| 151 | |
| 152 | map->lumpnum = lump_name; |
| 153 | |
| 154 | if (lumpfile != nextfile) |
| 155 | { |
| 156 | // The following lump is from a different file so whatever this is, |
| 157 | // it is not a multi-lump Doom level so let's assume it is a Build map. |
| 158 | map->MapLumps[0].Reader = fileSystem.ReopenFileReader(lump_name); |
| 159 | if (!P_IsBuildMap(map)) |
| 160 | { |
| 161 | delete map; |
| 162 | return NULL; |
| 163 | } |
| 164 | return map; |
| 165 | } |
| 166 | |
| 167 | // This case can only happen if the lump is inside a real WAD file. |
| 168 | // As such any special handling for other types of lumps is skipped. |
| 169 | map->MapLumps[0].Reader = fileSystem.ReopenFileReader(lump_name); |
| 170 | strncpy(map->MapLumps[0].Name, fileSystem.GetFileFullName(lump_name), 8); |
| 171 | map->InWad = true; |
no test coverage detected