2019-11-14 20:07:43 +00:00
|
|
|
/*
|
|
|
|
** savegame.cpp
|
2019-11-26 23:41:26 +00:00
|
|
|
**
|
|
|
|
** common savegame utilities for all front ends.
|
2019-11-14 20:07:43 +00:00
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2019 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OFf
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
2019-11-26 23:41:26 +00:00
|
|
|
*/
|
2019-11-14 20:07:43 +00:00
|
|
|
|
|
|
|
#include "savegamehelp.h"
|
2019-11-26 23:41:26 +00:00
|
|
|
#include "gstrings.h"
|
|
|
|
#include "i_specialpaths.h"
|
|
|
|
#include "cmdlib.h"
|
2020-04-11 21:54:33 +00:00
|
|
|
#include "filesystem.h"
|
2019-11-26 23:41:26 +00:00
|
|
|
#include "statistics.h"
|
|
|
|
#include "secrets.h"
|
2019-12-03 23:28:28 +00:00
|
|
|
#include "quotemgr.h"
|
2019-12-10 21:22:59 +00:00
|
|
|
#include "mapinfo.h"
|
2020-01-12 22:16:21 +00:00
|
|
|
#include "v_video.h"
|
2020-02-05 11:56:54 +00:00
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "m_argv.h"
|
2020-02-23 08:41:12 +00:00
|
|
|
#include "serializer.h"
|
|
|
|
#include "version.h"
|
2020-04-12 06:07:48 +00:00
|
|
|
#include "raze_music.h"
|
2020-04-12 06:09:38 +00:00
|
|
|
#include "raze_sound.h"
|
2020-06-20 16:01:02 +00:00
|
|
|
#include "gamestruct.h"
|
2020-09-06 11:39:57 +00:00
|
|
|
#include "automap.h"
|
2020-09-08 16:28:41 +00:00
|
|
|
#include "statusbar.h"
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "gamestate.h"
|
|
|
|
#include "razemenu.h"
|
2020-11-25 22:22:13 +00:00
|
|
|
#include "interpolate.h"
|
2021-03-19 19:40:44 +00:00
|
|
|
#include "gamefuncs.h"
|
2021-03-24 17:42:00 +00:00
|
|
|
#include "render.h"
|
2021-05-02 22:04:36 +00:00
|
|
|
#include "hw_sections.h"
|
2021-05-03 15:48:35 +00:00
|
|
|
#include "sectorgeometry.h"
|
2021-05-03 17:01:00 +00:00
|
|
|
#include "d_net.h"
|
2021-11-20 16:01:59 +00:00
|
|
|
#include "ns.h"
|
2021-12-05 23:50:33 +00:00
|
|
|
#include "serialize_obj.h"
|
2021-11-20 16:01:59 +00:00
|
|
|
#include "games/blood/src/mapstructs.h"
|
2022-12-07 16:10:27 +00:00
|
|
|
#include "texinfo.h"
|
2023-10-02 19:38:58 +00:00
|
|
|
#include "coreplayer.h"
|
2023-09-23 07:56:27 +00:00
|
|
|
#include <miniz.h>
|
2019-11-14 20:07:43 +00:00
|
|
|
|
2022-12-07 16:10:27 +00:00
|
|
|
#include "buildtiles.h"
|
2023-08-19 16:08:27 +00:00
|
|
|
#include "fs_findfile.h"
|
2023-12-17 11:48:03 +00:00
|
|
|
#include "resourcefile.h"
|
2022-12-07 16:10:27 +00:00
|
|
|
|
|
|
|
|
2020-10-11 18:57:20 +00:00
|
|
|
|
2020-04-26 21:17:54 +00:00
|
|
|
void WriteSavePic(FileWriter* file, int width, int height);
|
2023-09-24 03:40:15 +00:00
|
|
|
extern bool crouch_toggle;
|
2021-05-11 22:31:49 +00:00
|
|
|
extern FString savename;
|
2020-10-07 16:32:57 +00:00
|
|
|
extern FString BackupSaveGame;
|
2021-05-13 11:44:58 +00:00
|
|
|
int SaveVersion;
|
2021-05-11 22:21:26 +00:00
|
|
|
|
2020-10-11 16:10:52 +00:00
|
|
|
void SerializeMap(FSerializer &arc);
|
2023-12-17 11:48:03 +00:00
|
|
|
bool WriteZip(const char* filename, const FileSys::FCompressedBuffer* content, size_t contentcount);
|
2019-11-14 20:07:43 +00:00
|
|
|
|
2021-11-20 16:01:59 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, XWALL& w, XWALL* def);
|
2021-11-20 16:35:41 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, XSECTOR& w, XSECTOR* def);
|
2021-11-20 16:01:59 +00:00
|
|
|
END_BLD_NS
|
2020-02-02 15:06:13 +00:00
|
|
|
|
2020-02-23 13:03:03 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2023-09-24 03:40:15 +00:00
|
|
|
static void SerializeGlobals(FSerializer& arc)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject("globals"))
|
|
|
|
{
|
|
|
|
arc("crouch_toggle", crouch_toggle)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2020-02-23 13:03:03 +00:00
|
|
|
static void SerializeSession(FSerializer& arc)
|
|
|
|
{
|
2023-05-26 21:27:46 +00:00
|
|
|
// Only Exhumed still depends in indexed sounds.
|
|
|
|
if (!isExhumed()) arc.SetUniqueSoundNames();
|
2022-11-24 15:49:38 +00:00
|
|
|
|
2021-12-07 23:14:10 +00:00
|
|
|
arc.ReadObjects(false);
|
2020-10-11 16:10:52 +00:00
|
|
|
SerializeMap(arc);
|
2020-02-23 13:03:03 +00:00
|
|
|
SerializeStatistics(arc);
|
|
|
|
SECRET_Serialize(arc);
|
|
|
|
Mus_Serialize(arc);
|
|
|
|
quoteMgr.Serialize(arc);
|
2020-02-29 11:33:35 +00:00
|
|
|
S_SerializeSounds(arc);
|
2020-09-06 11:39:57 +00:00
|
|
|
SerializeAutomap(arc);
|
2020-09-08 16:28:41 +00:00
|
|
|
SerializeHud(arc);
|
2023-09-24 03:40:15 +00:00
|
|
|
SerializeGlobals(arc);
|
2020-11-21 14:09:38 +00:00
|
|
|
gi->SerializeGameState(arc);
|
2020-02-23 13:03:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 23:41:26 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-04-18 22:00:09 +00:00
|
|
|
bool ReadSavegame(const char* name)
|
2019-11-14 20:07:43 +00:00
|
|
|
{
|
2023-12-17 11:48:03 +00:00
|
|
|
auto savereader = FileSys::FResourceFile::OpenResourceFile(name, true);
|
2019-11-26 23:41:26 +00:00
|
|
|
|
|
|
|
if (savereader != nullptr)
|
|
|
|
{
|
2023-12-10 12:30:50 +00:00
|
|
|
auto lump = savereader->FindEntry("info.json");
|
|
|
|
if (lump < 0)
|
2020-07-20 22:07:02 +00:00
|
|
|
{
|
|
|
|
delete savereader;
|
|
|
|
return false;
|
|
|
|
}
|
2023-12-10 12:30:50 +00:00
|
|
|
auto file = savereader->GetEntryReader(lump);
|
2020-07-20 22:07:02 +00:00
|
|
|
if (G_ValidateSavegame(file, nullptr, false) <= 0)
|
|
|
|
{
|
|
|
|
delete savereader;
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-10 18:02:16 +00:00
|
|
|
file.Close();
|
2020-07-20 22:07:02 +00:00
|
|
|
|
2023-12-10 12:30:50 +00:00
|
|
|
auto info = savereader->FindEntry("session.json");
|
|
|
|
if (info < 0)
|
2020-02-23 13:03:03 +00:00
|
|
|
{
|
2021-04-18 22:00:09 +00:00
|
|
|
delete savereader;
|
2020-02-23 13:03:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-10 12:30:50 +00:00
|
|
|
auto data = savereader->Read(info);
|
2023-05-27 08:10:42 +00:00
|
|
|
FRazeSerializer arc;
|
2023-12-10 12:30:50 +00:00
|
|
|
if (!arc.OpenReader(data.string(), data.size()))
|
2020-02-23 13:03:03 +00:00
|
|
|
{
|
2021-05-08 07:22:08 +00:00
|
|
|
delete savereader;
|
2020-02-23 13:03:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-23 08:41:12 +00:00
|
|
|
|
2021-04-18 22:00:09 +00:00
|
|
|
// Load the savegame.
|
2023-10-08 07:15:32 +00:00
|
|
|
loadMapBackup(currentLevel->fileName.GetChars());
|
2020-10-13 17:43:45 +00:00
|
|
|
SerializeSession(arc);
|
2021-11-18 09:06:33 +00:00
|
|
|
g_nextskill = gi->GetCurrentSkill();
|
2021-05-10 18:02:16 +00:00
|
|
|
arc.Close();
|
2021-04-18 22:00:09 +00:00
|
|
|
delete savereader;
|
2023-10-02 19:38:58 +00:00
|
|
|
|
|
|
|
// this can only be done after the load is complete
|
|
|
|
for (auto pl : PlayerArray)
|
|
|
|
{
|
2023-10-31 03:44:58 +00:00
|
|
|
pl->resetCameraAngles();
|
2023-10-02 19:38:58 +00:00
|
|
|
}
|
2021-05-16 18:25:56 +00:00
|
|
|
ResetStatusBar();
|
2021-04-18 22:00:09 +00:00
|
|
|
return true;
|
2019-12-10 21:22:59 +00:00
|
|
|
}
|
2021-04-18 22:00:09 +00:00
|
|
|
return false;
|
2019-11-14 20:07:43 +00:00
|
|
|
}
|
2019-11-26 23:41:26 +00:00
|
|
|
|
2020-07-21 19:32:38 +00:00
|
|
|
CVAR(Bool, save_formatted, false, 0) // should be set to false once the conversion is done
|
2020-02-23 08:41:12 +00:00
|
|
|
|
2019-11-26 23:41:26 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
2020-01-12 22:16:21 +00:00
|
|
|
// Creates the savegame and writes all cross-game content.
|
2019-11-26 23:41:26 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-04-18 21:55:33 +00:00
|
|
|
bool WriteSavegame(const char* filename, const char *name)
|
2019-11-26 23:41:26 +00:00
|
|
|
{
|
2021-04-18 22:00:09 +00:00
|
|
|
BufferWriter savepic;
|
2020-02-23 08:41:12 +00:00
|
|
|
FSerializer savegameinfo; // this is for displayable info about the savegame.
|
2023-05-27 08:10:42 +00:00
|
|
|
FRazeSerializer savegamesession; // saved game session settings.
|
2020-02-23 08:41:12 +00:00
|
|
|
|
|
|
|
char buf[100];
|
|
|
|
mysnprintf(buf, countof(buf), GAMENAME " %s", GetVersionString());
|
2019-11-26 23:41:26 +00:00
|
|
|
auto savesig = gi->GetSaveSig();
|
2023-10-01 09:48:32 +00:00
|
|
|
auto gs = PlayClock / 120;
|
|
|
|
FStringf timeStr("%02d:%02d", gs / 60, gs % 60);
|
2020-09-08 16:28:41 +00:00
|
|
|
auto lev = currentLevel;
|
2020-02-23 08:41:12 +00:00
|
|
|
|
2021-04-18 22:00:09 +00:00
|
|
|
savegameinfo.OpenWriter(true);
|
2020-02-23 08:41:12 +00:00
|
|
|
savegameinfo.AddString("Software", buf)
|
|
|
|
("Save Version", savesig.currentsavever)
|
|
|
|
.AddString("Engine", savesig.savesig)
|
|
|
|
.AddString("Game Resource", fileSystem.GetResourceFileName(1))
|
2020-09-08 16:28:41 +00:00
|
|
|
.AddString("Map Name", lev->DisplayName())
|
2020-02-23 08:41:12 +00:00
|
|
|
.AddString("Creation Time", myasctime())
|
|
|
|
.AddString("Title", name)
|
2023-10-08 07:15:32 +00:00
|
|
|
.AddString("Map File", lev->fileName.GetChars())
|
|
|
|
.AddString("Map Label", lev->labelName.GetChars())
|
|
|
|
.AddString("Map Time", timeStr.GetChars());
|
2020-02-23 08:41:12 +00:00
|
|
|
|
2023-09-30 21:06:27 +00:00
|
|
|
const char *fn = lev->fileName.GetChars();
|
2019-12-10 21:22:59 +00:00
|
|
|
if (*fn == '/') fn++;
|
2019-12-11 00:10:59 +00:00
|
|
|
if (strncmp(fn, "file://", 7) != 0) // this only has meaning for non-usermaps
|
2019-12-10 21:22:59 +00:00
|
|
|
{
|
|
|
|
auto fileno = fileSystem.FindFile(fn);
|
|
|
|
auto mapfile = fileSystem.GetFileContainer(fileno);
|
|
|
|
auto mapcname = fileSystem.GetResourceFileName(mapfile);
|
2020-02-23 08:41:12 +00:00
|
|
|
if (mapcname) savegameinfo.AddString("Map Resource", mapcname);
|
2020-01-12 22:16:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false; // this should never happen. Saving on a map that isn't present is impossible.
|
|
|
|
}
|
2019-12-10 21:22:59 +00:00
|
|
|
}
|
2019-11-26 23:41:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-18 22:00:09 +00:00
|
|
|
// Save the game state
|
2020-02-23 13:03:03 +00:00
|
|
|
savegamesession.OpenWriter(save_formatted);
|
|
|
|
SerializeSession(savegamesession);
|
|
|
|
|
2021-04-18 22:00:09 +00:00
|
|
|
WriteSavePic(&savepic, 240, 180);
|
2020-09-11 23:11:32 +00:00
|
|
|
mysnprintf(buf, countof(buf), GAMENAME " %s", GetVersionString());
|
|
|
|
// put some basic info into the PNG so that this isn't lost when the image gets extracted.
|
2021-04-18 22:00:09 +00:00
|
|
|
M_AppendPNGText(&savepic, "Software", buf);
|
|
|
|
M_AppendPNGText(&savepic, "Title", name);
|
2023-10-08 07:15:32 +00:00
|
|
|
M_AppendPNGText(&savepic, "Current Map", lev->labelName.GetChars());
|
2021-04-18 22:00:09 +00:00
|
|
|
M_FinishPNG(&savepic);
|
|
|
|
|
|
|
|
auto picdata = savepic.GetBuffer();
|
2023-12-17 11:48:03 +00:00
|
|
|
FileSys::FCompressedBuffer bufpng = { picdata->size(), picdata->size(), FileSys::METHOD_STORED, static_cast<unsigned int>(crc32(0, &(*picdata)[0], picdata->size())), (char*)&(*picdata)[0] };
|
2021-04-18 22:00:09 +00:00
|
|
|
|
2023-08-23 18:36:19 +00:00
|
|
|
TArray<FileSys::FCompressedBuffer> savegame_content;
|
2021-04-18 22:00:09 +00:00
|
|
|
TArray<FString> savegame_filenames;
|
2020-09-11 23:11:32 +00:00
|
|
|
|
2021-04-18 22:00:09 +00:00
|
|
|
savegame_content.Push(bufpng);
|
|
|
|
savegame_filenames.Push("savepic.png");
|
|
|
|
savegame_content.Push(savegameinfo.GetCompressedOutput());
|
|
|
|
savegame_filenames.Push("info.json");
|
|
|
|
savegame_content.Push(savegamesession.GetCompressedOutput());
|
|
|
|
savegame_filenames.Push("session.json");
|
2023-08-19 16:08:27 +00:00
|
|
|
for (unsigned i = 0; i < savegame_content.Size(); i++)
|
|
|
|
savegame_content[i].filename = savegame_filenames[i].GetChars();
|
2021-04-18 22:00:09 +00:00
|
|
|
|
2023-08-19 16:08:27 +00:00
|
|
|
if (WriteZip(filename, savegame_content.Data(), savegame_content.Size()))
|
2021-04-18 22:00:09 +00:00
|
|
|
{
|
|
|
|
// Check whether the file is ok by trying to open it.
|
|
|
|
FResourceFile* test = FResourceFile::OpenResourceFile(filename, true);
|
|
|
|
if (test != nullptr)
|
|
|
|
{
|
|
|
|
delete test;
|
2020-01-12 22:16:21 +00:00
|
|
|
return true;
|
2021-04-18 22:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2019-11-26 23:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
static bool CheckSingleFile (const char *name, bool &printRequires, bool printwarn)
|
|
|
|
{
|
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2019-12-11 00:10:59 +00:00
|
|
|
if (strncmp(name, "file://", 7) == 0)
|
2019-12-10 21:22:59 +00:00
|
|
|
{
|
|
|
|
return FileExists(name + 7); // User maps must be present to be validated.
|
|
|
|
}
|
2019-11-26 23:41:26 +00:00
|
|
|
if (fileSystem.CheckIfResourceFileLoaded(name) < 0)
|
|
|
|
{
|
|
|
|
if (printwarn)
|
|
|
|
{
|
|
|
|
if (!printRequires)
|
|
|
|
{
|
|
|
|
Printf ("%s:\n%s", GStrings("TXT_SAVEGAMENEEDS"), name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf (", %s", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printRequires = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Return false if not all the needed wads have been loaded.
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-11-30 21:46:00 +00:00
|
|
|
static bool G_CheckSaveGameWads (const char *gamegrp, const char *mapgrp, bool printwarn)
|
2019-11-26 23:41:26 +00:00
|
|
|
{
|
|
|
|
bool printRequires = false;
|
2019-11-30 21:46:00 +00:00
|
|
|
CheckSingleFile (gamegrp, printRequires, printwarn);
|
|
|
|
CheckSingleFile (mapgrp, printRequires, printwarn);
|
2019-11-26 23:41:26 +00:00
|
|
|
|
|
|
|
if (printRequires)
|
|
|
|
{
|
|
|
|
if (printwarn)
|
|
|
|
{
|
|
|
|
Printf ("\n");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Checks if the savegame is valid. Gets a reader to the included info.json
|
|
|
|
// Returns 1 if valid, 0 if invalid and -1 if old and -2 if content missing
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2019-12-10 21:22:59 +00:00
|
|
|
int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu)
|
2019-11-26 23:41:26 +00:00
|
|
|
{
|
2020-02-23 13:03:03 +00:00
|
|
|
auto data = fr.Read();
|
|
|
|
FSerializer arc;
|
2023-08-19 16:08:27 +00:00
|
|
|
if (!arc.OpenReader((const char*)data.data(), data.size()))
|
2020-02-23 08:41:12 +00:00
|
|
|
{
|
2020-02-23 13:03:03 +00:00
|
|
|
return -2;
|
2020-02-23 08:41:12 +00:00
|
|
|
}
|
|
|
|
|
2020-02-23 13:03:03 +00:00
|
|
|
int savever;
|
2020-07-07 18:27:21 +00:00
|
|
|
FString engine, gamegrp, mapgrp, title, filename, label;
|
2020-02-23 13:03:03 +00:00
|
|
|
|
|
|
|
arc("Save Version", savever)
|
|
|
|
("Engine", engine)
|
|
|
|
("Game Resource", gamegrp)
|
|
|
|
("Map Resource", mapgrp)
|
|
|
|
("Title", title)
|
2020-07-26 10:15:24 +00:00
|
|
|
("Map Label", label)
|
2020-02-23 13:03:03 +00:00
|
|
|
("Map File", filename);
|
|
|
|
|
|
|
|
auto savesig = gi->GetSaveSig();
|
|
|
|
|
|
|
|
if (savetitle) *savetitle = title;
|
|
|
|
if (engine.Compare(savesig.savesig) != 0 || savever > savesig.currentsavever)
|
2019-11-26 23:41:26 +00:00
|
|
|
{
|
2020-02-23 13:03:03 +00:00
|
|
|
// different engine or newer version:
|
|
|
|
// not our business. Leave it alone.
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-13 11:44:58 +00:00
|
|
|
SaveVersion = savesig.currentsavever;
|
2019-12-10 21:22:59 +00:00
|
|
|
|
2023-10-08 07:15:32 +00:00
|
|
|
MapRecord *curLevel = FindMapByName(label.GetChars());
|
2019-12-10 21:22:59 +00:00
|
|
|
|
2020-07-07 18:27:21 +00:00
|
|
|
// If the map does not exist, check if it's a user map.
|
|
|
|
if (!curLevel)
|
2020-02-23 13:03:03 +00:00
|
|
|
{
|
2020-07-07 18:27:21 +00:00
|
|
|
curLevel = AllocateMap();
|
2020-02-23 13:03:03 +00:00
|
|
|
if (!formenu)
|
2019-12-10 21:22:59 +00:00
|
|
|
{
|
2020-07-07 18:27:21 +00:00
|
|
|
curLevel->name = "";
|
2023-10-08 07:15:32 +00:00
|
|
|
curLevel->SetFileName(filename.GetChars());
|
2019-12-10 21:22:59 +00:00
|
|
|
}
|
2020-02-23 13:03:03 +00:00
|
|
|
}
|
|
|
|
if (!curLevel) return 0;
|
|
|
|
if (!formenu) currentLevel = curLevel;
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2019-11-30 21:46:00 +00:00
|
|
|
|
2020-02-23 13:03:03 +00:00
|
|
|
if (savever < savesig.minsavever)
|
|
|
|
{
|
|
|
|
// old, incompatible savegame. List as not usable.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ggfn = ExtractFileBase(fileSystem.GetResourceFileName(1), true);
|
|
|
|
if (gamegrp.CompareNoCase(ggfn) == 0)
|
2019-11-26 23:41:26 +00:00
|
|
|
{
|
2023-10-08 07:15:32 +00:00
|
|
|
return G_CheckSaveGameWads(gamegrp.GetChars(), mapgrp.GetChars(), false) ? 1 : -2;
|
2019-11-26 23:41:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-23 13:03:03 +00:00
|
|
|
// different game. Skip this.
|
|
|
|
return 0;
|
2019-11-26 23:41:26 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-30 21:46:00 +00:00
|
|
|
return 0;
|
2019-11-26 23:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-21 18:22:38 +00:00
|
|
|
#include "build.h"
|
2020-01-21 20:51:05 +00:00
|
|
|
|
2020-10-11 16:10:52 +00:00
|
|
|
#define V(x) x
|
|
|
|
static spritetype zsp;
|
2020-10-13 17:43:45 +00:00
|
|
|
static spriteext_t zspx;
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, spritetype &c, spritetype *def)
|
|
|
|
{
|
|
|
|
def = &zsp; // always delta against 0
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
2023-10-03 09:07:53 +00:00
|
|
|
arc("pos", c.pos, def->pos)
|
2020-10-13 17:43:45 +00:00
|
|
|
("cstat", c.cstat, def->cstat)
|
|
|
|
("picnum", c.picnum, def->picnum)
|
|
|
|
("shade", c.shade, def->shade)
|
|
|
|
("pal", c.pal, def->pal)
|
|
|
|
("clipdist", c.clipdist, def->clipdist)
|
|
|
|
("blend", c.blend, def->blend)
|
2023-10-03 09:07:53 +00:00
|
|
|
("repeat", c.scale, def->scale)
|
2020-10-13 17:43:45 +00:00
|
|
|
("xoffset", c.xoffset, def->xoffset)
|
|
|
|
("yoffset", c.yoffset, def->yoffset)
|
|
|
|
("statnum", c.statnum)
|
2021-12-06 16:40:33 +00:00
|
|
|
("sectnum", c.sectp)
|
2022-11-25 12:13:50 +00:00
|
|
|
("angles", c.Angles, def->Angles)
|
2022-08-16 21:29:54 +00:00
|
|
|
("ang", c.intangle, def->intangle)
|
2022-05-23 22:30:41 +00:00
|
|
|
("owner", c.intowner, def->intowner)
|
2022-09-01 15:17:06 +00:00
|
|
|
("xvel", c.xint, def->xint)
|
|
|
|
("yvel", c.yint, def->yint)
|
2022-08-31 22:45:45 +00:00
|
|
|
("zvel", c.inittype, def->inittype)
|
2020-10-13 17:43:45 +00:00
|
|
|
("lotag", c.lotag, def->lotag)
|
|
|
|
("hitag", c.hitag, def->hitag)
|
|
|
|
("extra", c.extra, def->extra)
|
|
|
|
("detail", c.detail, def->detail)
|
2021-09-05 10:25:52 +00:00
|
|
|
("cstat2", c.cstat2, def->cstat2)
|
2020-10-13 17:43:45 +00:00
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* key, spriteext_t& c, spriteext_t* def)
|
|
|
|
{
|
|
|
|
def = &zspx; // always delta against 0
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("mdanimtims", c.mdanimtims, def->mdanimtims)
|
|
|
|
("mdanimcur", c.mdanimcur, def->mdanimcur)
|
2022-09-25 10:47:07 +00:00
|
|
|
("rot", c.rot, def->rot)
|
2020-10-13 17:43:45 +00:00
|
|
|
("pivot_offset", c.pivot_offset, def->pivot_offset)
|
|
|
|
("position_offset", c.position_offset, def->position_offset)
|
2022-01-23 18:03:14 +00:00
|
|
|
("flags", c.renderflags, def->renderflags)
|
2020-10-13 17:43:45 +00:00
|
|
|
("alpha", c.alpha, def->alpha)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return arc;
|
|
|
|
}
|
2020-10-11 16:10:52 +00:00
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, sectortype &c, sectortype *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
2021-12-07 23:14:10 +00:00
|
|
|
arc("firstentry", c.firstEntry)
|
|
|
|
("lastentry", c.lastEntry)
|
2021-12-27 22:04:26 +00:00
|
|
|
#ifndef SECTOR_HACKJOB // can't save these in test mode...
|
2022-02-03 18:15:46 +00:00
|
|
|
("ceilingz", c.ceilingz, def->ceilingz)
|
|
|
|
("floorz", c.floorz, def->floorz)
|
2021-12-27 21:32:26 +00:00
|
|
|
#endif
|
2020-10-11 16:10:52 +00:00
|
|
|
("ceilingstat", c.ceilingstat, def->ceilingstat)
|
|
|
|
("floorstat", c.floorstat, def->floorstat)
|
2022-12-09 09:48:47 +00:00
|
|
|
("ceilingpicnum", c.ceilingtexture, def->ceilingtexture)
|
2020-10-11 16:10:52 +00:00
|
|
|
("ceilingheinum", c.ceilingheinum, def->ceilingheinum)
|
|
|
|
("ceilingshade", c.ceilingshade, def->ceilingshade)
|
|
|
|
("ceilingpal", c.ceilingpal, def->ceilingpal)
|
2020-11-25 19:52:06 +00:00
|
|
|
("ceilingxpanning", c.ceilingxpan_, def->ceilingxpan_)
|
|
|
|
("ceilingypanning", c.ceilingypan_, def->ceilingypan_)
|
2022-12-09 09:48:47 +00:00
|
|
|
("floorpicnum", c.floortexture, def->floortexture)
|
2020-10-11 16:10:52 +00:00
|
|
|
("floorheinum", c.floorheinum, def->floorheinum)
|
|
|
|
("floorshade", c.floorshade, def->floorshade)
|
|
|
|
("floorpal", c.floorpal, def->floorpal)
|
2020-11-25 19:52:06 +00:00
|
|
|
("floorxpanning", c.floorxpan_, def->floorxpan_)
|
|
|
|
("floorypanning", c.floorypan_, def->floorypan_)
|
2020-10-11 16:10:52 +00:00
|
|
|
("visibility", c.visibility, def->visibility)
|
|
|
|
("fogpal", c.fogpal, def->fogpal)
|
|
|
|
("lotag", c.lotag, def->lotag)
|
|
|
|
("hitag", c.hitag, def->hitag)
|
|
|
|
("extra", c.extra, def->extra)
|
2021-03-20 22:01:16 +00:00
|
|
|
("portalflags", c.portalflags, def->portalflags)
|
2022-06-26 07:36:01 +00:00
|
|
|
("portalnum", c.portalnum, def->portalnum)
|
|
|
|
("exflags", c.exflags, def->exflags);
|
2021-11-20 16:35:41 +00:00
|
|
|
|
2021-11-20 22:20:43 +00:00
|
|
|
// Save the extensions only when playing their respective games.
|
2022-11-25 07:59:16 +00:00
|
|
|
if (isDukeEngine())
|
2021-11-20 16:35:41 +00:00
|
|
|
{
|
2022-12-31 16:58:14 +00:00
|
|
|
arc("keyinfo", c.lockinfo, def->lockinfo)
|
2021-12-05 16:35:23 +00:00
|
|
|
("shadedsector", c.shadedsector, def->shadedsector)
|
|
|
|
("hitagactor", c.hitagactor, def->hitagactor);
|
|
|
|
|
2021-11-20 16:35:41 +00:00
|
|
|
}
|
|
|
|
else if (isBlood())
|
|
|
|
{
|
2021-11-20 17:42:19 +00:00
|
|
|
arc("upperlink", c.upperLink, def->upperLink)
|
2021-11-20 18:10:02 +00:00
|
|
|
("lowerlink", c.lowerLink, def->lowerLink)
|
|
|
|
("basefloor", c.baseFloor, def->baseFloor)
|
|
|
|
("baseCeil", c.baseCeil, def->baseCeil)
|
2022-09-03 22:28:30 +00:00
|
|
|
("velfloor", c.velFloor, def->velFloor)
|
|
|
|
("velCeil", c.velCeil, def->velCeil)
|
2021-11-20 18:10:02 +00:00
|
|
|
("slopwwallofs", c.slopewallofs, def->slopewallofs);
|
2021-11-20 17:42:19 +00:00
|
|
|
|
2021-11-20 16:35:41 +00:00
|
|
|
if (arc.isWriting())
|
|
|
|
{
|
|
|
|
if (c.hasX())
|
|
|
|
{
|
|
|
|
BLD_NS::Serialize(arc, "xsector", *c._xs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (arc.HasObject("xsector"))
|
|
|
|
{
|
|
|
|
c.allocX();
|
|
|
|
BLD_NS::Serialize(arc, "xsector", *c._xs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
2021-11-20 19:52:29 +00:00
|
|
|
}
|
|
|
|
else if (isExhumed())
|
|
|
|
{
|
2021-11-22 19:18:14 +00:00
|
|
|
arc("SoundSect", c.pSoundSect, def->pSoundSect)
|
2021-11-20 19:52:29 +00:00
|
|
|
("Depth", c.Depth, def->Depth)
|
2021-11-22 22:05:48 +00:00
|
|
|
("Above", c.pAbove, def->pAbove)
|
|
|
|
("Below", c.pBelow, def->pBelow)
|
2021-11-20 19:52:29 +00:00
|
|
|
("Sound", c.Sound, def->Sound)
|
|
|
|
("Flag", c.Flag, def->Flag)
|
|
|
|
("Damage", c.Damage, def->Damage)
|
|
|
|
("Speed", c.Speed, def->Speed);
|
|
|
|
|
2021-11-20 16:35:41 +00:00
|
|
|
}
|
2021-11-20 22:20:43 +00:00
|
|
|
else if (isSWALL())
|
|
|
|
{
|
|
|
|
arc("flags", c.flags, def->flags)
|
|
|
|
("depth_fixed", c.depth_fixed, def->depth_fixed)
|
|
|
|
("stag", c.stag, def->stag)
|
2022-08-30 22:46:45 +00:00
|
|
|
("ang", c.angle, def->angle)
|
2021-11-20 22:20:43 +00:00
|
|
|
("height", c.height, def->height)
|
|
|
|
("speed", c.speed, def->speed)
|
|
|
|
("damage", c.damage, def->damage)
|
|
|
|
("number", c.number, def->number)
|
|
|
|
("u_defined", c.u_defined, def->u_defined)
|
2023-01-05 18:26:42 +00:00
|
|
|
("flags2", c.flags2, def->flags2)
|
|
|
|
("interpolate", c.interpolate, def->interpolate);
|
2021-11-20 22:20:43 +00:00
|
|
|
}
|
2021-11-20 16:35:41 +00:00
|
|
|
|
2021-11-20 22:20:43 +00:00
|
|
|
arc.EndObject();
|
2020-10-11 16:10:52 +00:00
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, walltype &c, walltype *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
2023-10-03 09:07:53 +00:00
|
|
|
arc("pos", c.pos, def->pos)
|
2020-10-11 16:10:52 +00:00
|
|
|
("point2", c.point2, def->point2)
|
|
|
|
("nextwall", c.nextwall, def->nextwall)
|
|
|
|
("nextsector", c.nextsector, def->nextsector)
|
|
|
|
("cstat", c.cstat, def->cstat)
|
2022-12-31 14:14:29 +00:00
|
|
|
("texture", c.walltexture, def->walltexture)
|
|
|
|
("overtexture", c.overtexture, def->overtexture)
|
2020-10-11 16:10:52 +00:00
|
|
|
("shade", c.shade, def->shade)
|
|
|
|
("pal", c.pal, def->pal)
|
2022-10-07 22:02:10 +00:00
|
|
|
("xrepeat", c.xrepeat, def->xrepeat)
|
|
|
|
("yrepeat", c.yrepeat, def->yrepeat)
|
2020-11-26 07:38:59 +00:00
|
|
|
("xpanning", c.xpan_, def->xpan_)
|
|
|
|
("ypanning", c.ypan_, def->ypan_)
|
2020-10-11 16:10:52 +00:00
|
|
|
("lotag", c.lotag, def->lotag)
|
|
|
|
("hitag", c.hitag, def->hitag)
|
|
|
|
("extra", c.extra, def->extra)
|
2021-03-20 22:01:16 +00:00
|
|
|
("portalflags", c.portalflags, def->portalflags)
|
2021-11-20 16:01:59 +00:00
|
|
|
("portalnum", c.portalnum, def->portalnum);
|
|
|
|
|
|
|
|
// Save the blood-specific extensions only when playing Blood
|
|
|
|
if (isBlood())
|
|
|
|
{
|
|
|
|
arc("wallbase", c.baseWall, def->baseWall);
|
|
|
|
if (arc.isWriting())
|
|
|
|
{
|
|
|
|
if (c.hasX())
|
|
|
|
{
|
|
|
|
BLD_NS::Serialize(arc, "xwall", *c._xw, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (arc.HasObject("xwall"))
|
|
|
|
{
|
|
|
|
c.allocX();
|
|
|
|
BLD_NS::Serialize(arc, "xwall", *c._xw, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
arc.EndObject();
|
2020-10-11 16:10:52 +00:00
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2021-12-07 23:14:10 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* key, ActorStatList& c, ActorStatList* def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("firstentry", c.firstEntry)
|
|
|
|
("lastentry", c.lastEntry)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
2020-10-13 17:43:45 +00:00
|
|
|
|
2023-10-02 19:38:58 +00:00
|
|
|
void DCorePlayer::Serialize(FSerializer& arc)
|
|
|
|
{
|
|
|
|
Super::Serialize(arc);
|
|
|
|
arc("pnum", pnum)
|
|
|
|
("actor", actor)
|
2023-10-02 22:28:01 +00:00
|
|
|
("actions", cmd.ucmd.actions)
|
2023-10-31 03:44:58 +00:00
|
|
|
("viewangles", ViewAngles)
|
|
|
|
("yawspin", YawSpin)
|
2023-10-02 19:38:58 +00:00
|
|
|
//("cmd", cmd)
|
|
|
|
//("lastcmd", lastcmd)
|
|
|
|
;
|
2023-10-02 22:28:01 +00:00
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
cmd.ucmd.actions &= SB_CENTERVIEW|SB_CROUCH; // these are the only bits we need to preserve.
|
|
|
|
}
|
2023-10-02 19:38:58 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 08:20:41 +00:00
|
|
|
void DCoreActor::Serialize(FSerializer& arc)
|
2020-10-11 16:10:52 +00:00
|
|
|
{
|
2021-12-07 23:14:10 +00:00
|
|
|
Super::Serialize(arc);
|
|
|
|
arc("link_stat", link_stat)
|
|
|
|
("link_sector", link_sector)
|
|
|
|
("prevstat", prevStat)
|
|
|
|
("nextstat", nextStat)
|
|
|
|
("prevsect", prevSect)
|
|
|
|
("nextsect", nextSect)
|
|
|
|
("sprite", spr)
|
2022-10-04 17:06:49 +00:00
|
|
|
("clipdist", clipdist)
|
2022-01-08 20:18:18 +00:00
|
|
|
("time", time)
|
2022-02-13 10:38:21 +00:00
|
|
|
("spritesetindex", spritesetindex)
|
2022-09-01 18:33:22 +00:00
|
|
|
("spriteext", sprext)
|
2023-10-03 09:07:53 +00:00
|
|
|
("vel", vel)
|
2022-12-01 12:58:18 +00:00
|
|
|
("viewzoffset", viewzoffset)
|
2023-04-23 08:32:58 +00:00
|
|
|
("dispicnum", dispictex);
|
2021-12-05 08:34:30 +00:00
|
|
|
|
2022-11-21 03:53:52 +00:00
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
spsmooth = {};
|
2022-11-25 12:13:50 +00:00
|
|
|
backuploc();
|
2022-11-21 03:53:52 +00:00
|
|
|
}
|
2021-12-05 08:20:41 +00:00
|
|
|
}
|
2020-10-13 17:43:45 +00:00
|
|
|
|
2023-09-30 21:06:27 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* key, StatRecord& c, StatRecord* def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("max", c.max)
|
|
|
|
("got", c.got)
|
|
|
|
.Array("player", c.player, MAXPLAYERS)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* key, MapLocals& c, MapLocals* def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("kills", c.kills)
|
|
|
|
("secrets", c.secrets)
|
|
|
|
("superSecrets", c.superSecrets)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-05 08:20:41 +00:00
|
|
|
|
|
|
|
void SerializeMap(FSerializer& arc)
|
|
|
|
{
|
2020-10-11 16:10:52 +00:00
|
|
|
if (arc.BeginObject("engine"))
|
|
|
|
{
|
2023-09-30 21:06:27 +00:00
|
|
|
arc("maplocals", Level)
|
|
|
|
// everything here should move into MapLocals as well later.
|
|
|
|
.Array("statlist", statList, MAXSTATUS)
|
2023-10-02 19:38:58 +00:00
|
|
|
.Array("players",PlayerArray, MAXPLAYERS)
|
2021-11-20 22:20:43 +00:00
|
|
|
("sectors", sector, sectorbackup)
|
2021-11-20 22:42:01 +00:00
|
|
|
("walls", wall, wallbackup)
|
2020-11-30 22:45:21 +00:00
|
|
|
|
2020-10-13 17:43:45 +00:00
|
|
|
("myconnectindex", myconnectindex)
|
|
|
|
("connecthead", connecthead)
|
|
|
|
.Array("connectpoint2", connectpoint2, countof(connectpoint2))
|
|
|
|
("randomseed", randomseed)
|
|
|
|
("numshades", numshades) // is this really needed?
|
|
|
|
("visibility", g_visibility)
|
2022-01-08 11:23:05 +00:00
|
|
|
("relvisibility", g_relvisibility)
|
2020-11-30 22:45:21 +00:00
|
|
|
("numsprites", Numsprites)
|
2021-03-24 17:42:00 +00:00
|
|
|
("allportals", allPortals);
|
2020-10-13 17:43:45 +00:00
|
|
|
|
2020-11-25 22:22:13 +00:00
|
|
|
SerializeInterpolations(arc);
|
2020-10-13 17:43:45 +00:00
|
|
|
arc.EndObject();
|
2020-05-24 10:31:38 +00:00
|
|
|
}
|
2020-01-21 20:51:05 +00:00
|
|
|
|
2021-03-19 19:40:44 +00:00
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
setWallSectors();
|
2021-12-16 05:10:59 +00:00
|
|
|
hw_CreateSections();
|
2021-12-15 12:08:09 +00:00
|
|
|
sectionGeometry.SetSize(sections.Size());
|
2021-03-19 19:40:44 +00:00
|
|
|
}
|
2020-02-02 15:06:13 +00:00
|
|
|
}
|
2020-10-04 16:31:48 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
CVAR(Bool, saveloadconfirmation, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|
|
|
|
|
|
|
CVAR(Int, autosavenum, 0, CVAR_NOSET | CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|
|
|
static int nextautosave = -1;
|
|
|
|
CVAR(Int, disableautosave, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|
|
|
CUSTOM_CVAR(Int, autosavecount, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|
|
|
{
|
|
|
|
if (self < 1)
|
|
|
|
self = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVAR(Int, quicksavenum, 0, CVAR_NOSET | CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|
|
|
static int nextquicksave = -1;
|
2023-04-02 09:45:41 +00:00
|
|
|
CUSTOM_CVAR(Int, quicksavecount, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
2020-10-04 16:31:48 +00:00
|
|
|
{
|
|
|
|
if (self < 1)
|
|
|
|
self = 1;
|
|
|
|
}
|
|
|
|
|
2023-04-02 09:45:41 +00:00
|
|
|
void DoLoadGame(const char* name)
|
|
|
|
{
|
|
|
|
gi->FreeLevelData();
|
|
|
|
if (ReadSavegame(name))
|
|
|
|
{
|
|
|
|
gameaction = ga_level;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
I_Error("%s: Failed to open savegame", name);
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 22:21:26 +00:00
|
|
|
|
2023-04-02 09:45:41 +00:00
|
|
|
|
|
|
|
void G_LoadGame(const char* name, bool hidecon)
|
|
|
|
{
|
|
|
|
if (name != NULL)
|
|
|
|
{
|
|
|
|
savename = name;
|
|
|
|
gameaction = !hidecon ? ga_loadgame : ga_loadgamehidecon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void G_DoLoadGame()
|
|
|
|
{
|
|
|
|
if (gameaction == ga_loadgamehidecon && gamestate == GS_FULLCONSOLE)
|
|
|
|
{
|
|
|
|
// does this even do anything anymore?
|
|
|
|
gamestate = GS_HIDECONSOLE;
|
|
|
|
}
|
|
|
|
|
2023-10-08 07:15:32 +00:00
|
|
|
DoLoadGame(savename.GetChars());
|
2023-04-02 09:45:41 +00:00
|
|
|
BackupSaveGame = savename;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern bool sendsave;
|
|
|
|
extern FString savedescription;
|
|
|
|
extern FString savegamefile;
|
|
|
|
|
|
|
|
void G_SaveGame(const char* filename, const char* description)
|
|
|
|
{
|
|
|
|
if (sendsave || gameaction == ga_savegame)
|
|
|
|
{
|
|
|
|
Printf("%s\n", GStrings("TXT_SAVEPENDING"));
|
|
|
|
}
|
|
|
|
else if (gamestate != GS_LEVEL)
|
|
|
|
{
|
|
|
|
Printf("%s\n", GStrings("TXT_NOTINLEVEL"));
|
|
|
|
}
|
|
|
|
else if (!gi->CanSave())
|
|
|
|
{
|
|
|
|
Printf("%s\n", GStrings("TXT_SPPLAYERDEAD"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
savegamefile = filename;
|
|
|
|
savedescription = description;
|
|
|
|
sendsave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2021-05-11 22:21:26 +00:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-04-02 09:45:41 +00:00
|
|
|
void startSaveGame(int player, uint8_t** stream, bool skip)
|
|
|
|
{
|
|
|
|
auto s = ReadString(stream);
|
|
|
|
savegamefile = s;
|
|
|
|
delete[] s;
|
|
|
|
s = ReadString(stream);
|
|
|
|
savedescription = s;
|
|
|
|
if (!skip && gi->CanSave())
|
|
|
|
{
|
|
|
|
if (player != consoleplayer)
|
|
|
|
{
|
|
|
|
// Paths sent over the network will be valid for the system that sent
|
|
|
|
// the save command. For other systems, the path needs to be changed.
|
2023-10-08 07:15:32 +00:00
|
|
|
savegamefile = G_BuildSaveName(ExtractFileBase(savegamefile.GetChars(), true).GetChars());
|
2023-04-02 09:45:41 +00:00
|
|
|
}
|
|
|
|
gameaction = ga_savegame;
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 16:32:57 +00:00
|
|
|
|
2021-05-11 22:21:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2020-10-07 16:32:57 +00:00
|
|
|
|
2023-04-02 09:45:41 +00:00
|
|
|
void G_DoSaveGame(bool ok4q, bool forceq, const char* fn, const char* desc)
|
|
|
|
{
|
|
|
|
if (WriteSavegame(fn, desc))
|
|
|
|
{
|
|
|
|
savegameManager.NotifyNewSave(fn, desc, ok4q, forceq);
|
|
|
|
Printf(PRINT_NOTIFY, "%s\n", GStrings("GGSAVED"));
|
|
|
|
BackupSaveGame = fn;
|
|
|
|
}
|
|
|
|
}
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2021-05-11 22:21:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-04-02 09:45:41 +00:00
|
|
|
void M_Autosave()
|
2020-10-04 16:31:48 +00:00
|
|
|
{
|
|
|
|
if (disableautosave) return;
|
|
|
|
if (!gi->CanSave()) return;
|
|
|
|
FString description;
|
|
|
|
FString file;
|
|
|
|
// Keep a rotating sets of autosaves
|
|
|
|
UCVarValue num;
|
|
|
|
const char* readableTime;
|
|
|
|
int count = autosavecount != 0 ? autosavecount : 1;
|
|
|
|
|
|
|
|
if (nextautosave == -1)
|
|
|
|
{
|
|
|
|
nextautosave = (autosavenum + 1) % count;
|
|
|
|
}
|
|
|
|
|
|
|
|
num.Int = nextautosave;
|
2022-10-21 22:12:17 +00:00
|
|
|
autosavenum->ForceSet(num, CVAR_Int);
|
2020-10-04 16:31:48 +00:00
|
|
|
|
2023-10-08 07:15:32 +00:00
|
|
|
auto Filename = G_BuildSaveName(FStringf("auto%04d", nextautosave).GetChars());
|
2020-10-04 16:31:48 +00:00
|
|
|
readableTime = myasctime();
|
2020-10-07 16:32:57 +00:00
|
|
|
FStringf SaveTitle("Autosave %s", readableTime);
|
2020-10-04 16:31:48 +00:00
|
|
|
nextautosave = (nextautosave + 1) % count;
|
2023-10-08 07:15:32 +00:00
|
|
|
G_DoSaveGame(false, false, Filename.GetChars(), SaveTitle.GetChars());
|
2020-10-04 16:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(autosave)
|
|
|
|
{
|
|
|
|
gameaction = ga_autosave;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(rotatingquicksave)
|
|
|
|
{
|
|
|
|
if (!gi->CanSave()) return;
|
|
|
|
FString description;
|
|
|
|
FString file;
|
|
|
|
// Keep a rotating sets of quicksaves
|
|
|
|
UCVarValue num;
|
|
|
|
const char* readableTime;
|
|
|
|
int count = quicksavecount != 0 ? quicksavecount : 1;
|
|
|
|
|
|
|
|
if (nextquicksave == -1)
|
|
|
|
{
|
|
|
|
nextquicksave = (quicksavenum + 1) % count;
|
|
|
|
}
|
|
|
|
|
|
|
|
num.Int = nextquicksave;
|
2022-10-21 22:12:17 +00:00
|
|
|
quicksavenum->ForceSet(num, CVAR_Int);
|
2020-10-04 16:31:48 +00:00
|
|
|
|
|
|
|
FSaveGameNode sg;
|
2023-10-08 07:15:32 +00:00
|
|
|
auto Filename = G_BuildSaveName(FStringf("quick%04d", nextquicksave).GetChars());
|
2020-10-04 16:31:48 +00:00
|
|
|
readableTime = myasctime();
|
2020-10-07 16:32:57 +00:00
|
|
|
FStringf SaveTitle("Quicksave %s", readableTime);
|
2020-10-04 16:31:48 +00:00
|
|
|
nextquicksave = (nextquicksave + 1) % count;
|
2023-10-08 07:15:32 +00:00
|
|
|
G_SaveGame(Filename.GetChars(), SaveTitle.GetChars());
|
2020-10-04 16:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-16 09:24:08 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CCMD load
|
|
|
|
//
|
|
|
|
// Load a saved game.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
UNSAFE_CCMD(load)
|
|
|
|
{
|
|
|
|
if (argv.argc() != 2)
|
|
|
|
{
|
|
|
|
Printf("usage: load <filename>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (netgame)
|
|
|
|
{
|
|
|
|
Printf("cannot load during a network game\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FString fname = G_BuildSaveName(argv[1]);
|
2023-10-08 07:15:32 +00:00
|
|
|
G_LoadGame(fname.GetChars());
|
2021-05-16 09:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CCMD save
|
|
|
|
//
|
|
|
|
// Save the current game.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
UNSAFE_CCMD(save)
|
|
|
|
{
|
|
|
|
if (argv.argc() < 2 || argv.argc() > 3)
|
|
|
|
{
|
|
|
|
Printf("usage: save <filename> [description]\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FString fname = G_BuildSaveName(argv[1]);
|
2023-10-08 07:15:32 +00:00
|
|
|
G_SaveGame(fname.GetChars(), argv.argc() > 2 ? argv[2] : argv[1]);
|
2021-05-16 09:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|