70 if (
len >
sizeof(header->
name)) {
90 cgi->Com_DPrintf(
DEBUG_CLIENT,
"Savefile has incompatible amount of subsystems\n");
94 if (header->
xmlSize > 15 * 1024 * 1024) {
95 cgi->Com_Printf(
"Save size seems to be to large (over 15 MB) %i.\n", header->
xmlSize);
99 cgi->Com_Printf(
"Version is invalid - must be greater than zero\n");
103 cgi->Com_Printf(
"Savefile is newer than the game!\n");
120 cgi->GetRelativeSavePath(path,
sizeof(path));
125 cgi->Com_Printf(
"Couldn't open file '%s'\n",
filename);
161 cgi->Com_Printf(
"Couldn't open file '%s'\n",
filename);
162 *error =
"File not found";
167 if (
cgi->FS_Read(cbuf, clen, &
f) != clen)
168 cgi->Com_Printf(
"Warning: Could not read %i bytes from savefile\n", clen);
169 cgi->Com_Printf(
"Loading savegame xml (size %d)\n", clen);
172 memcpy(&header, cbuf,
sizeof(header));
182 *error =
"Corrupted header";
186 cgi->Com_Printf(
"Loading savegame\n"
188 "...game version: %s\n"
189 "...xml Size: %i, compressed? %c\n",
197 const int res = uncompress(
buf, &
len, cbuf +
sizeof(header), clen -
sizeof(header));
203 *error =
_(
"Error decompressing data");
204 cgi->Com_Printf(
"Error decompressing data in '%s'.\n",
filename);
207 topNode =
cgi->XML_Parse((
const char*)
buf);
210 cgi->Com_Printf(
"Error: Failure in loading the xml data!\n");
211 *error =
"Corrupted xml data";
216 topNode =
cgi->XML_Parse((
const char*)(cbuf +
sizeof(header)));
219 cgi->Com_Printf(
"Error: Failure in loading the xml data!\n");
220 *error =
"Corrupted xml data";
226 cgi->GAME_ReloadMode();
229 cgi->Com_Printf(
"Error: Failure in loading the xml data! (savegame node not found)\n");
231 *error =
"Invalid xml data";
241 cgi->Com_Printf(
"...subsystem '%s' returned false - savegame could not be loaded\n",
252 cgi->Com_Printf(
"Savegame postprocessing returned false - savegame could not be loaded\n");
253 *error =
"Postprocessing failed";
257 cgi->Com_Printf(
"File '%s' successfully loaded from %s xml savegame.\n",
260 cgi->UI_InitStack(
"geoscape",
"campaign_main");
271 *error =
_(
"Saving is not possible: Campaign is not active.");
274 if (
cgi->CL_OnBattlescape()) {
276 *error =
_(
"Saving is not possible: Cannot save the Battlescape.");
281 *error =
_(
"Saving is not possible: No base is built.");
296 cgi->Com_Printf(
"%s", *error);
304 char timeStampBuffer[32];
307 cgi->GetRelativeSavePath(savegame,
sizeof(savegame));
321 cgi->Com_Printf(
"Calling subsystems\n");
344 buf = mxmlSaveAllocString(topNode,
nullptr);
347 *error =
_(
"Could not allocate enough memory to save this game");
348 cgi->Com_Printf(
"Error: Could not allocate enough memory to save this game\n");
351 int requiredBufferLength = strlen(
buf) + 1;
353 cgi->Com_Printf(
"XML Written to buffer (%d Bytes)\n", requiredBufferLength);
357 bufLen = compressBound(requiredBufferLength);
359 bufLen = requiredBufferLength;
362 memcpy(fbuf, &header,
sizeof(header));
365 int res = compress(fbuf +
sizeof(header), &bufLen, (
byte*)
buf, requiredBufferLength);
370 *error =
_(
"Memory error compressing save-game data - set save_compressed cvar to 0");
371 cgi->Com_Printf(
"Memory error compressing save-game data (%s) (Error: %i)!\n", comment, res);
375 memcpy(fbuf +
sizeof(header),
buf, requiredBufferLength);
380 cgi->FS_WriteFile(fbuf, bufLen +
sizeof(header), savegame);
401 cgi->Com_Printf(
"added %s subsystem\n", subsystem->
name);
437 cgi->Com_Printf(
"\n--- save subsystem initialization --\n");
Shared game type headers.
Share stuff between the different cgame implementations.
bool AIR_LoadXML(xmlNode_t *parent)
bool AIR_SaveXML(xmlNode_t *parent)
Save callback for savegames in xml format.
bool AIR_PostLoadInit(void)
Actions needs to be done after loading the savegame.
bool INT_LoadXML(xmlNode_t *parent)
Load callback for savegames in XML Format.
bool INT_SaveXML(xmlNode_t *parent)
Save callback for savegames in XML Format.
bool AB_SaveXML(xmlNode_t *p)
Save callback for alien base data.
bool AB_LoadXML(xmlNode_t *p)
Load callback for alien base data.
bool AC_LoadXML(xmlNode_t *parent)
Load callback for savin in XML Format.
bool B_LoadXML(xmlNode_t *parent)
Loads base data.
bool B_PostLoadInit(void)
Set the capacity stuff for all the bases after loading a savegame.
bool B_SaveXML(xmlNode_t *parent)
Save callback for saving in xml format.
#define B_AtLeastOneExists()
memPool_t * cp_campaignPool
bool CP_IsRunning(void)
Checks whether a campaign mode game is running.
bool CP_SaveXML(xmlNode_t *parent)
Save callback for savegames in XML Format.
bool CP_LoadXML(xmlNode_t *parent)
Load callback for savegames in XML Format.
Header file for single player campaign control.
const cgame_import_t * cgi
bool E_LoadXML(xmlNode_t *p)
Load callback for savegames in XML Format.
bool E_SaveXML(xmlNode_t *p)
Save callback for savegames in XML Format.
bool CP_TriggerEventLoadXML(xmlNode_t *p)
bool CP_TriggerEventSaveXML(xmlNode_t *p)
bool HOS_SaveXML(xmlNode_t *p)
Saving function for hospital related data.
bool HOS_LoadXML(xmlNode_t *p)
Saving function for hospital related data.
bool INS_SaveXML(xmlNode_t *p)
Save callback for savegames in xml.
bool INS_LoadXML(xmlNode_t *p)
Load callback for savegames.
bool BS_LoadXML(xmlNode_t *parent)
Load callback for savegames.
bool BS_SaveXML(xmlNode_t *parent)
Save callback for savegames.
bool MSO_SaveXML(xmlNode_t *p)
saves current notification and pause settings
bool MSO_LoadXML(xmlNode_t *p)
Restores the notification and pause settings from savegame.
bool MS_LoadXML(xmlNode_t *p)
Load callback for messages.
bool MS_SaveXML(xmlNode_t *p)
Save callback for messages.
bool MIS_SaveXML(xmlNode_t *parent)
Save callback for savegames in XML Format.
bool MIS_LoadXML(xmlNode_t *parent)
Load callback for savegames in XML Format.
bool NAT_SaveXML(xmlNode_t *p)
Nation saving callback.
bool NAT_LoadXML(xmlNode_t *p)
Nation loading xml callback.
bool PR_LoadXML(xmlNode_t *p)
Load callback for xml savegames.
bool PR_SaveXML(xmlNode_t *p)
Save callback for savegames in XML Format.
bool PR_PostLoadInit(void)
actions to do with productions after loading a savegame
void RADAR_SetRadarAfterLoading(void)
Set radar to proper values after loading.
bool RS_SaveXML(xmlNode_t *parent)
Save callback for research and technologies.
bool RS_LoadXML(xmlNode_t *parent)
Load callback for research and technologies.
static cvar_t * save_compressed
bool SAV_AddSubsystem(saveSubsystems_t *subsystem)
Adds a subsystem to the saveSubsystems array.
static saveSubsystems_t saveSubsystems[MAX_SAVESUBSYSTEMS]
bool SAV_GameLoad(const char *file, const char **error)
Loads the given savegame from an xml File.
static int saveSubsystemsAmount
bool SAV_LoadHeader(const char *filename, saveFileHeader_t *header)
Loads and verifies a savegame header.
static bool SAV_VerifyHeader(saveFileHeader_t const *const header)
Tries to verify the Header of the savegame.
void SAV_Init(void)
Register all save-subsystems and init some cvars and commands.
bool SAV_GameSaveAllowed(char **error=nullptr)
Determines if saving is allowed.
static bool SAV_GameActionsAfterLoad(void)
Perform actions after loading a game for single player campaign.
bool SAV_GameSave(const char *filename, const char *comment, char **error)
This is a savegame function which stores the game in xml-Format.
Defines some savefile structures.
bool US_LoadXML(xmlNode_t *parent)
Load callback for xml savegames.
bool STATS_LoadXML(xmlNode_t *parent)
Load callback for savegames in XML Format.
bool US_SaveXML(xmlNode_t *parent)
Save callback for savegames in XML Format.
bool XVI_LoadXML(xmlNode_t *parent)
Load the XVI map from the savegame.
bool TR_SaveXML(xmlNode_t *parent)
Save callback for xml savegames.
bool TR_LoadXML(xmlNode_t *parent)
Load callback for xml savegames.
bool STATS_SaveXML(xmlNode_t *parent)
Save callback for savegames in XML Format.
#define SAVE_FILE_VERSION
#define MAX_SAVESUBSYSTEMS
bool XVI_SaveXML(xmlNode_t *parent)
XVI map saving callback.
#define SAVEGAME_EXTENSION
void CP_UpdateTime(void)
Updates date/time and timescale (=timelapse) on the geoscape menu.
void CP_DateConvertLong(const DateTime &date, dateLong_t *dateLong)
Converts a date from the engine in a (longer) human-readable format.
const char * Date_GetMonthName(int month)
Returns the short monthame to the given month index.
Campaign geoscape time header.
void CP_UpdateXVIMapButton(void)
This will hide or show the geoscape button for handling the xvi overlay map.
#define Mem_PoolAllocTypeN(type, n, pool)
QGL_EXTERN GLuint GLchar GLuint * len
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
XML tag constants for savegame.
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
void Com_MakeTimestamp(char *ts, const size_t tslen)
Creates a timestamp with date and time at the specified location.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Human readable time information in the game.
bool(* load)(xmlNode_t *parent)
bool(* save)(xmlNode_t *parent)