MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / LoadPatchesFromString

Method LoadPatchesFromString

pcsx2/Patch.cpp:203–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203u32 Patch::LoadPatchesFromString(std::vector<PatchGroup>* patch_list, const std::string& patch_file)
204{
205 const size_t before = patch_list->size();
206
207 PatchGroup current_patch_group;
208 const auto add_current_patch = [patch_list, &current_patch_group]() {
209 if (!current_patch_group.patches.empty())
210 {
211 // Ungrouped/legacy patches should merge with other ungrouped patches.
212 if (current_patch_group.name.empty())
213 {
214 const std::vector<PatchGroup>::iterator ungrouped_patch = std::find_if(patch_list->begin(), patch_list->end(),
215 [](const PatchGroup& pg) { return pg.name.empty(); });
216 if (ungrouped_patch != patch_list->end())
217 {
218 Console.WriteLn(Color_Gray, fmt::format(
219 "Patch: Merging {} new patch commands into ungrouped list.", current_patch_group.patches.size()));
220
221 ungrouped_patch->patches.reserve(ungrouped_patch->patches.size() + current_patch_group.patches.size());
222 for (PatchCommand& cmd : current_patch_group.patches)
223 ungrouped_patch->patches.push_back(std::move(cmd));
224 }
225 else
226 {
227 // Always add ungrouped patches, no sense to compare empty names.
228 patch_list->push_back(std::move(current_patch_group));
229 }
230
231 return;
232 }
233 }
234
235 if (current_patch_group.patches.empty() && current_patch_group.dpatches.empty())
236 return;
237
238 // Don't show patches with duplicate names, prefer the first loaded.
239 if (!ContainsPatchName(*patch_list, current_patch_group.name))
240 {
241 patch_list->push_back(std::move(current_patch_group));
242 }
243 else
244 {
245 Console.WriteLn(Color_Gray, fmt::format(
246 "Patch: Skipped loading patch '{}' since a patch with a duplicate name was already loaded.",
247 current_patch_group.name));
248 }
249 };
250
251 std::istringstream ss(patch_file);
252 std::string line;
253 while (std::getline(ss, line))
254 {
255 TrimPatchLine(line);
256 if (line.empty())
257 continue;
258
259 if (line.front() == '[')
260 {

Callers

nothing calls this directly

Calls 14

substrMethod · 0.80
formatFunction · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
WriteLnMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
frontMethod · 0.45
lengthMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected