MCPcopy Create free account
hub / github.com/ZDoom/Raze / G_ValidateSavegame

Function G_ValidateSavegame

source/core/savegamehelp.cpp:338–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336//=============================================================================
337
338int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu)
339{
340 auto data = fr.Read();
341 FSerializer arc;
342 if (!arc.OpenReader((const char*)data.data(), data.size()))
343 {
344 return -2;
345 }
346
347 int savever;
348 FString engine, gamegrp, mapgrp, title, filename, label;
349
350 arc("Save Version", savever)
351 ("Engine", engine)
352 ("Game Resource", gamegrp)
353 ("Map Resource", mapgrp)
354 ("Title", title)
355 ("Map Label", label)
356 ("Map File", filename);
357
358 auto savesig = gi->GetSaveSig();
359
360 if (savetitle) *savetitle = title;
361 if (engine.Compare(savesig.savesig) != 0 || savever > savesig.currentsavever)
362 {
363 // different engine or newer version:
364 // not our business. Leave it alone.
365 return 0;
366 }
367 SaveVersion = savesig.currentsavever;
368
369 MapRecord *curLevel = FindMapByName(label.GetChars());
370
371 // If the map does not exist, check if it's a user map.
372 if (!curLevel)
373 {
374 curLevel = AllocateMap();
375 if (!formenu)
376 {
377 curLevel->name = "";
378 curLevel->SetFileName(filename.GetChars());
379 }
380 }
381 if (!curLevel) return 0;
382 if (!formenu) currentLevel = curLevel;
383
384
385 if (savever < savesig.minsavever)
386 {
387 // old, incompatible savegame. List as not usable.
388 return -1;
389 }
390 else
391 {
392 auto ggfn = ExtractFileBase(fileSystem.GetResourceFileName(1), true);
393 if (gamegrp.CompareNoCase(ggfn) == 0)
394 {
395 return G_CheckSaveGameWads(gamegrp.GetChars(), mapgrp.GetChars(), false) ? 1 : -2;

Callers 2

ReadSavegameFunction · 0.85
ReadSaveStringsMethod · 0.85

Calls 14

FindMapByNameFunction · 0.85
AllocateMapFunction · 0.85
ExtractFileBaseFunction · 0.85
G_CheckSaveGameWadsFunction · 0.85
OpenReaderMethod · 0.80
SetFileNameMethod · 0.80
GetResourceFileNameMethod · 0.80
CompareNoCaseMethod · 0.80
ReadMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
GetSaveSigMethod · 0.45

Tested by

no test coverage detected