示例#1
0
void G_DoLoadGame(void)
{
    int i;
    int a, b, c;
    char savestr[SAVESTRINGSIZE];
    char vcheck[VERSIONSIZE], readversion[VERSIONSIZE];

    gameaction = ga_nothing;

    SV_OpenRead(savename);

    free(savename);
    savename = NULL;

    // Skip the description field
    SV_Read(savestr, SAVESTRINGSIZE);

    memset(vcheck, 0, sizeof(vcheck));
    DEH_snprintf(vcheck, VERSIONSIZE, "version %i", HERETIC_VERSION);
    SV_Read(readversion, VERSIONSIZE);

    if (strncmp(readversion, vcheck, VERSIONSIZE) != 0)
    {                           // Bad version
        return;
    }
    gameskill = SV_ReadByte();
    gameepisode = SV_ReadByte();
    gamemap = SV_ReadByte();
    for (i = 0; i < MAXPLAYERS; i++)
    {
        playeringame[i] = SV_ReadByte();
    }
    // Load a base level
    G_InitNew(gameskill, gameepisode, gamemap);

    // Create leveltime
    a = SV_ReadByte();
    b = SV_ReadByte();
    c = SV_ReadByte();
    leveltime = (a << 16) + (b << 8) + c;

    // De-archive all the modifications
    P_UnArchivePlayers();
    P_UnArchiveWorld();
    P_UnArchiveThinkers();
    P_UnArchiveSpecials();

    if (SV_ReadByte() != SAVE_GAME_TERMINATOR)
    {                           // Missing savegame termination marker
        I_Error("Bad savegame");
    }
}
示例#2
0
dboolean P_ReadSaveGame(char* name) {
    M_ReadFile(name, &savebuffer);
    save_offset = 0;

    saveg_read_header();

    // load a base level
    G_InitNew(gameskill, gamemap);
    G_DoLoadLevel();

    P_UnArchiveMobjs();
    P_UnArchivePlayers();
    P_UnArchiveWorld();
    P_UnArchiveSpecials();
    P_UnArchiveMacros();

    if(!saveg_read_marker(SAVEGAME_EOF)) {
        I_Error("Bad savegame");
    }

    Z_Free(savebuffer);

    return true;
}
示例#3
0
文件: g_save.c 项目: AlexMax/d2k
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;
}