Пример #1
0
TbBool load_ceiling_table(void)
{
    char *fname;
    TbFileHandle fh;
    unsigned short *value_array;
    char nchr;
    char numstr[8];
    TbBool do_next;
    long i,n;
    //_DK_load_ceiling_table(); return true;
    // Prepare filename and open the file
    wait_for_cd_to_be_available();
    fname = prepare_file_path(FGrp_StdData,"ceiling.txt");
    fh = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
    if (fh == -1) {
        return false;
    }

    value_array = &floor_to_ceiling_map[0];
    n = 0;
    do_next = 1;
    while (do_next == 1)
    {
        {
            do_next = LbFileRead(fh, &nchr, 1);
            if (do_next != 1)
                break;
            if ( (nchr == 10) || (nchr == 44) || (nchr == 32) || (nchr == 9) || (nchr == 13) )
                continue;
        }
        LbMemorySet(numstr, 0, sizeof(numstr));
        for (i=0; i < sizeof(numstr); i++)
        {
            numstr[i] = nchr;
            do_next = LbFileRead(fh, &nchr, 1);
            if (do_next != 1)
                break;
            if ( (nchr == 10) || (nchr == 44) || (nchr == 32) || (nchr == 9) || (nchr == 13) )
                break;
        }
        value_array[n] = atol(numstr);
        n++;
        if (n >= sizeof(floor_to_ceiling_map)/sizeof(floor_to_ceiling_map[0]))
        {
            do_next = 0;
        }
    }
    LbFileClose(fh);
    memcpy(_DK_floor_to_ceiling_map,floor_to_ceiling_map,sizeof(floor_to_ceiling_map));
    return true;
}
Пример #2
0
TbBool load_game_save_catalogue(void)
{
    long slot_num;
    char *fname;
    TbFileHandle fh;
    struct FileChunkHeader hdr;
    struct CatalogueEntry *centry;
    long saves_found;
    //return load_game_catalogue(save_game_catalogue);
    saves_found = 0;
    for (slot_num=0; slot_num < TOTAL_SAVE_SLOTS_COUNT; slot_num++)
    {
        centry = &save_game_catalogue[slot_num];
        LbMemorySet(centry, 0, sizeof(struct CatalogueEntry));
        fname = prepare_file_fmtpath(FGrp_Save, saved_game_filename, slot_num);
        fh = LbFileOpen(fname,Lb_FILE_MODE_READ_ONLY);
        if (fh == -1)
            continue;
        if (LbFileRead(fh, &hdr, sizeof(struct FileChunkHeader)) == sizeof(struct FileChunkHeader))
        {
            if (load_catalogue_entry(fh,&hdr,centry))
                saves_found++;
        }
        LbFileClose(fh);
    }
    return (saves_found > 0);
}
Пример #3
0
TbBool load_catalogue_entry(TbFileHandle fh,struct FileChunkHeader *hdr,struct CatalogueEntry *centry)
{
    set_flag_word(&centry->flags, CEF_InUse, false);
    if ((hdr->id == SGC_InfoBlock) && (hdr->len == sizeof(struct CatalogueEntry)))
    {
        if (LbFileRead(fh, centry, sizeof(struct CatalogueEntry))
          == sizeof(struct CatalogueEntry))
        {
            set_flag_word(&centry->flags, CEF_InUse, true);
        }
    }
    centry->textname[SAVE_TEXTNAME_LEN-1] = '\0';
    centry->campaign_name[LINEMSG_SIZE-1] = '\0';
    centry->campaign_fname[DISKPATH_SIZE-1] = '\0';
    centry->player_name[PLAYER_NAME_LENGTH-1] = '\0';
    return ((centry->flags & CEF_InUse) != 0);
}
Пример #4
0
TbBool is_save_game_loadable(long slot_num)
{
    char *fname;
    TbFileHandle fh;
    struct FileChunkHeader hdr;
    // Prepare filename and open the file
    fname = prepare_file_fmtpath(FGrp_Save,saved_game_filename,slot_num);
    fh = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
    if (fh != -1)
    {
        // Let's try to read the file, just to be sure
        if (LbFileRead(fh, &hdr, sizeof(struct FileChunkHeader)) == sizeof(struct FileChunkHeader))
        {
            LbFileClose(fh);
            return true;
        }
        LbFileClose(fh);
    }
    return false;
}
Пример #5
0
void net_load_config_file(void)
{
    TbFileHandle handle;
    char *fname;
    // Try to load the config file
    fname = prepare_file_path(FGrp_Save,keeper_netconf_file);
    handle = LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
    if (handle != -1)
    {
      if (LbFileRead(handle, &net_config_info, sizeof(net_config_info)) == sizeof(net_config_info))
      {
        LbFileClose(handle);
        return;
      }
      LbFileClose(handle);
    }
    // If can't load, then use default config
    LbMemoryCopy(&net_config_info, &default_net_config_info, sizeof(net_config_info));
    LbStringCopy(net_config_info.str_u2, get_string(GUIStr_MnuNoName), 20);
}
Пример #6
0
short read_continue_game_part(unsigned char *buf,long pos,long buf_len)
{
  TbFileHandle fh;
  short result;
  char *fname;
  fname = prepare_file_path(FGrp_Save,continue_game_filename);
  if (LbFileLength(fname) != sizeof(struct Game))
  {
    SYNCDBG(7,"No correct .SAV file; there's no continue");
    return false;
  }
  fh = LbFileOpen(fname,Lb_FILE_MODE_READ_ONLY);
  if (fh == -1)
  {
    SYNCDBG(7,"Can't open .SAV file; there's no continue");
    return false;
  }
  LbFileSeek(fh, pos, Lb_FILE_SEEK_BEGINNING);
  result = (LbFileRead(fh, buf, buf_len) == buf_len);
  LbFileClose(fh);
  return result;
}
Пример #7
0
int load_game_chunks(TbFileHandle fhandle,struct CatalogueEntry *centry)
{
    struct FileChunkHeader hdr;
    long chunks_done;
    chunks_done = 0;
    while (!LbFileEof(fhandle))
    {
        if (LbFileRead(fhandle, &hdr, sizeof(struct FileChunkHeader)) != sizeof(struct FileChunkHeader))
            break;
        switch(hdr.id)
        {
        case SGC_InfoBlock:
            if (load_catalogue_entry(fhandle,&hdr,centry))
            {
                chunks_done |= SGF_InfoBlock;
                if (!change_campaign(centry->campaign_fname)) {
                    ERRORLOG("Unable to load campaign");
                    return GLoad_Failed;
                }
                // Load configs which may have per-campaign part, and even be modified within a level
                load_computer_player_config(CnfLd_Standard);
                load_stats_files();
                check_and_auto_fix_stats();
                init_creature_scores();
                // Update interface items
                strncpy(high_score_entry,centry->player_name,PLAYER_NAME_LENGTH);
            }
            break;
        case SGC_GameAdd:
            if (hdr.len != sizeof(struct GameAdd))
            {
                if (LbFileSeek(fhandle, hdr.len, Lb_FILE_SEEK_CURRENT) < 0)
                    LbFileSeek(fhandle, 0, Lb_FILE_SEEK_END);
                WARNLOG("Incompatible GameAdd chunk");
                break;
            }
            if (LbFileRead(fhandle, &gameadd, sizeof(struct GameAdd)) == sizeof(struct GameAdd)) {
            //accept invalid saves -- if (LbFileRead(fhandle, &gameadd, hdr.len) == hdr.len) {
                chunks_done |= SGF_GameAdd;
            } else {
                WARNLOG("Could not read GameAdd chunk");
            }
            break;
        case SGC_GameOrig:
            if (hdr.len != sizeof(struct Game))
            {
                if (LbFileSeek(fhandle, hdr.len, Lb_FILE_SEEK_CURRENT) < 0)
                    LbFileSeek(fhandle, 0, Lb_FILE_SEEK_END);
                WARNLOG("Incompatible GameOrig chunk");
                break;
            }
            if (LbFileRead(fhandle, &game, sizeof(struct Game)) == sizeof(struct Game)) {
                chunks_done |= SGF_GameOrig;
            } else {
                WARNLOG("Could not read GameOrig chunk");
            }
            break;
        case SGC_PacketHeader:
            if (hdr.len != sizeof(struct PacketSaveHead))
            {
                if (LbFileSeek(fhandle, hdr.len, Lb_FILE_SEEK_CURRENT) < 0)
                    LbFileSeek(fhandle, 0, Lb_FILE_SEEK_END);
                WARNLOG("Incompatible PacketHeader chunk");
                break;
            }
            if (LbFileRead(fhandle, &game.packet_save_head, sizeof(struct PacketSaveHead))
                == sizeof(struct PacketSaveHead)) {
                chunks_done |= SGF_PacketHeader;
            } else {
                WARNLOG("Could not read GameOrig chunk");
            }
            break;
        case SGC_PacketData:
            if (hdr.len != 0)
            {
                if (LbFileSeek(fhandle, hdr.len, Lb_FILE_SEEK_CURRENT) < 0)
                    LbFileSeek(fhandle, 0, Lb_FILE_SEEK_END);
                WARNLOG("Incompatible PacketData chunk");
                break;
            }
            chunks_done |= SGF_PacketData;
            if ((chunks_done & SGF_PacketContinue) == SGF_PacketContinue)
                return GLoad_PacketContinue;
            if ((chunks_done & SGF_PacketStart) == SGF_PacketStart)
                return GLoad_PacketStart;
            return GLoad_Failed;
        default:
            WARNLOG("Unrecognized chunk, ID = %08lx",hdr.id);
            break;
        }
    }
    if ((chunks_done & SGF_SavedGame) == SGF_SavedGame)
        return GLoad_SavedGame;
    return GLoad_Failed;
}