void P_SerializeSubsectors(FArchive &arc) { int num_verts, num_subs, num_nodes; BYTE by; if (arc.IsStoring()) { if (hasglnodes) { arc << numvertexes << numsubsectors << numnodes; // These are only for verification for(int i=0;i<numsubsectors;i+=8) { by = 0; for(int j=0;j<8;j++) { if (i+j<numsubsectors && (subsectors[i+j].flags & SSECF_DRAWN)) { by |= (1<<j); } } arc << by; } } else { int v = 0; arc << v << v << v; } } else { arc << num_verts << num_subs << num_nodes; if (num_verts != numvertexes || num_subs != numsubsectors || num_nodes != numnodes) { // Nodes don't match - we can't use this info for(int i=0;i<num_subs;i+=8) { // Skip the subsector info. arc << by; } if (hasglnodes) { RecalculateDrawnSubsectors(); } return; } else { for(int i=0;i<numsubsectors;i+=8) { arc << by; for(int j=0;j<8;j++) { if ((by & (1<<j)) && i+j<numsubsectors) { subsectors[i+j].flags |= SSECF_DRAWN; } } } } } }
FSerializer &Serialize(FSerializer &arc, const char *key, subsector_t *&ss, subsector_t **) { BYTE by; const char *str; if (arc.isWriting()) { if (hasglnodes) { TArray<char> encoded(1 + (numsubsectors + 5) / 6); int p = 0; for (int i = 0; i < numsubsectors; i += 6) { by = 0; for (int j = 0; j < 6; j++) { if (i + j < numsubsectors && (subsectors[i + j].flags & SSECF_DRAWN)) { by |= (1 << j); } } if (by < 10) by += '0'; else if (by < 36) by += 'A' - 10; else if (by < 62) by += 'a' - 36; else if (by == 62) by = '-'; else if (by == 63) by = '+'; encoded[p++] = by; } encoded[p] = 0; str = &encoded[0]; if (arc.BeginArray(key)) { arc(nullptr, numvertexes) (nullptr, numsubsectors) .StringPtr(nullptr, str) .EndArray(); } } } else { int num_verts, num_subs; bool success = false; if (arc.BeginArray(key)) { arc(nullptr, num_verts) (nullptr, num_subs) .StringPtr(nullptr, str) .EndArray(); if (num_verts == numvertexes && num_subs == numsubsectors && hasglnodes) { success = true; int sub = 0; for (int i = 0; str[i] != 0; i++) { by = str[i]; if (by >= '0' && by <= '9') by -= '0'; else if (by >= 'A' && by <= 'Z') by -= 'A' - 10; else if (by >= 'a' && by <= 'z') by -= 'a' - 36; else if (by == '-') by = 62; else if (by == '+') by = 63; else { success = false; break; } for (int s = 0; s < 6; s++) { if (sub + s < numsubsectors && (by & (1 << s))) { subsectors[sub + s].flags |= SSECF_DRAWN; } } sub += 6; } } if (hasglnodes && !success) { RecalculateDrawnSubsectors(); } } } return arc; }
dboolean G_ReadSaveData(pbuf_t *savebuffer, dboolean bail_on_errors, dboolean init_new) { int i; int savegame_compatibility = -1; complevel_t m_compatibility_level; skill_t m_gameskill; int m_gameepisode; int m_gamemap; //e6y: numeric version number of package should be zero before initializing // from savegame unsigned int packageversion = 0; unsigned char description[SAVESTRINGSIZE]; unsigned char save_version[VERSIONSIZE]; byte game_options[GAME_OPTION_SIZE]; unsigned int game_option_count; unsigned char safety_byte; buf_t byte_buf; M_BufferInit(&byte_buf); memset(description, 0, SAVESTRINGSIZE); memset(save_version, 0, VERSIONSIZE); M_PBufReadBytes(savebuffer, &byte_buf); if (M_BufferGetSize(&byte_buf) != SAVESTRINGSIZE) { I_Error("G_ReadSaveData: save string size mismatch (%zu != %u)", M_BufferGetSize(&byte_buf), SAVESTRINGSIZE ); } memcpy(description, M_BufferGetData(&byte_buf), M_BufferGetSize(&byte_buf)); M_BufferClear(&byte_buf); M_PBufReadBytes(savebuffer, &byte_buf); if (M_BufferGetSize(&byte_buf) != VERSIONSIZE) { I_Error("G_ReadSaveData: version size mismatch (%zu != %u)", M_BufferGetSize(&byte_buf), VERSIONSIZE ); } memcpy(save_version, M_BufferGetData(&byte_buf), M_BufferGetSize(&byte_buf)); M_BufferFree(&byte_buf); // CPhipps - read the description field, compare with supported ones for (i = 0; i < num_version_headers; i++) { char vcheck[VERSIONSIZE]; // killough 2/22/98: "proprietary" version string :-) sprintf(vcheck, version_headers[i].ver_printf, version_headers[i].version); if (!strncmp((const char *)save_version, vcheck, VERSIONSIZE)) { savegame_compatibility = version_headers[i].comp_level; break; } } if (savegame_compatibility == -1) { fprintf(stderr, "savegame_compatibility == -1 (%s)\n", save_version); if (bail_on_errors) { return false; } else if (forced_loadgame) { savegame_compatibility = MAX_COMPATIBILITY_LEVEL - 1; } else { G_LoadGameErr("Unrecognized savegame version!\nAre you sure? (y/n) "); return false; } } // CPhipps - always check savegames even when forced, // only print a warning if forced { // killough 3/16/98: check lump name checksum (independent of order) uint_64_t checksum; uint_64_t save_checksum = 0; if (MULTINET) checksum = 1; else checksum = G_Signature(); M_PBufReadLong(savebuffer, (int_64_t *)&save_checksum); if (save_checksum != checksum) { fprintf(stderr, "bad checksum: %" PRIu64 " != %" PRIu64 "\n", checksum, save_checksum ); if (bail_on_errors) return false; if (!forced_loadgame) { G_LoadGameErr("Incompatible Savegame!!!\n\nAre you sure?"); return false; } else { lprintf(LO_WARN, "G_DoLoadGame: Incompatible savegame\n"); } } } /*-----------------*/ /* CG: TODO: PWADs */ /*-----------------*/ M_PBufReadUInt(savebuffer, &packageversion); M_PBufReadInt(savebuffer, &m_compatibility_level); M_PBufReadInt(savebuffer, &m_gameskill); M_PBufReadInt(savebuffer, &m_gameepisode); M_PBufReadInt(savebuffer, &m_gamemap); if (!init_new) { if (m_compatibility_level != compatibility_level) { if (bail_on_errors) return false; I_Error("G_ReadSaveData: Mismatched compatibility level"); } if (m_gameskill != gameskill) { if (bail_on_errors) return false; I_Error("G_ReadSaveData: Mismatched game skill"); } if (m_gameepisode != gameepisode) { if (bail_on_errors) return false; I_Error("G_ReadSaveData: Mismatched episode"); } if (m_gamemap != gamemap) { if (bail_on_errors) return false; I_Error("G_ReadSaveData: Mismatched map"); } } compatibility_level = m_compatibility_level; gameskill = m_gameskill; gameepisode = m_gameepisode; gamemap = m_gamemap; M_PBufReadInt(savebuffer, &gametic); M_PBufReadBool(savebuffer, &levelTimer); M_PBufReadInt(savebuffer, &levelTimeCount); M_PBufReadBool(savebuffer, &levelFragLimit); M_PBufReadInt(savebuffer, &levelFragLimitCount); for (i = 0; i < MAXPLAYERS; i++) M_PBufReadBool(savebuffer, &playeringame[i]); // killough 2/28/98 for (dboolean b = false, i = MAXPLAYERS; i < MIN_MAXPLAYERS; i++) M_PBufReadBool(savebuffer, &b); M_PBufReadInt(savebuffer, &idmusnum); // jff 3/17/98 restore idmus music /* killough 3/1/98: Read game options * killough 11/98: move down to here */ M_PBufReadArray(savebuffer, &game_option_count); if (mbf_features && (game_option_count > GAME_OPTION_SIZE)) { I_Error("G_ReadSaveData: too many options (%d > %d)", game_option_count, GAME_OPTION_SIZE ); } else if ((!mbf_features) && game_option_count > OLD_GAME_OPTION_SIZE) { I_Error("G_ReadSaveData: too many options (%d > %d)", game_option_count, OLD_GAME_OPTION_SIZE ); } for (i = 0; i < game_option_count; i++) M_PBufReadUChar(savebuffer, &game_options[i]); G_ReadOptions(game_options); // killough 3/1/98: Read game options // load a base level if (init_new) G_InitNew(gameskill, gameepisode, gamemap); P_IdentReset(); /* get the times - killough 11/98: save entire word */ M_PBufReadInt(savebuffer, &leveltime); /* cph - total episode time */ //e6y: total level times are always saved since 2.4.8.1 M_PBufReadInt(savebuffer, &totalleveltimes); // killough 11/98: load revenant tracer state M_PBufReadInt(savebuffer, &basetic); // dearchive all the modifications P_MapStart(); P_UnArchiveWorld(savebuffer); P_UnArchivePlayers(savebuffer); P_UnArchiveThinkers(savebuffer); P_UnArchiveSpecials(savebuffer); P_UnArchiveRNG(savebuffer); // killough 1/18/98: load RNG information P_UnArchiveMap(savebuffer); // killough 1/22/98: load automap information S_ReloadChannelOrigins(); P_MapEnd(); R_ActivateSectorInterpolations();//e6y R_SmoothPlaying_Reset(NULL); // e6y if (musinfo.current_item != -1) S_ChangeMusInfoMusic(musinfo.current_item, true); RecalculateDrawnSubsectors(); M_PBufReadUChar(savebuffer, &safety_byte); if (safety_byte != 0xe6) I_Error("G_ReadSaveData: Bad savegame"); G_UpdateAverageSaveSize(M_PBufGetCapacity(savebuffer)); return true; }