Subversion Repositories eduke32

Rev

Rev 1677 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1677 Rev 1707
Line 66... Line 66...
66
        if (kdfread(&dummy,sizeof(dummy),1,fil) != 1)
66
        if (kdfread(&dummy,sizeof(dummy),1,fil) != 1)
67
        {
67
        {
68
            kclose(fil);
68
            kclose(fil);
69
            continue;
69
            continue;
70
        }
70
        }
71
        if (kdfread(&ud.savegame[i][0],19,1,fil) != 1)
71
        if (kdfread(&ud.savegame[i][0],21,1,fil) != 1)
72
        {
72
        {
73
            ud.savegame[i][0] = 0;
73
            ud.savegame[i][0] = 0;
74
        }
74
        }
-
 
75
        else ud.savegame[i][19] = 0;
-
 
76
75
        kclose(fil);
77
        kclose(fil);
76
    }
78
    }
77
}
79
}
78
80
79
int32_t G_LoadSaveHeader(char spot,struct savehead *saveh)
81
int32_t G_LoadSaveHeader(char spot,struct savehead *saveh)
Line 102... Line 104...
102
            return 1;
104
            return 1;
103
        }*/
105
        }*/
104
106
105
    if (kdfread(&saveh->numplr,sizeof(int32_t),1,fil) != 1) goto corrupt;
107
    if (kdfread(&saveh->numplr,sizeof(int32_t),1,fil) != 1) goto corrupt;
106
108
107
    if (kdfread(saveh->name,19,1,fil) != 1) goto corrupt;
109
    if (kdfread(saveh->name,21,1,fil) != 1) goto corrupt;
108
    if (kdfread(&saveh->volnum,sizeof(int32_t),1,fil) != 1) goto corrupt;
110
    if (kdfread(&saveh->volnum,sizeof(int32_t),1,fil) != 1) goto corrupt;
109
    if (kdfread(&saveh->levnum,sizeof(int32_t),1,fil) != 1) goto corrupt;
111
    if (kdfread(&saveh->levnum,sizeof(int32_t),1,fil) != 1) goto corrupt;
110
    if (kdfread(&saveh->plrskl,sizeof(int32_t),1,fil) != 1) goto corrupt;
112
    if (kdfread(&saveh->plrskl,sizeof(int32_t),1,fil) != 1) goto corrupt;
111
    if (kdfread(saveh->boardfn,BMAX_PATH,1,fil) != 1) goto corrupt;
113
    if (kdfread(saveh->boardfn,BMAX_PATH,1,fil) != 1) goto corrupt;
112
114
Line 185... Line 187...
185
    FX_StopAllSounds();
187
    FX_StopAllSounds();
186
    S_ClearSoundLocks();
188
    S_ClearSoundLocks();
187
189
188
    if (numplayers > 1)
190
    if (numplayers > 1)
189
    {
191
    {
190
        if (kdfread(&buf,19,1,fil) != 1) goto corrupt;
192
        if (kdfread(&buf,21,1,fil) != 1) goto corrupt;
191
    }
193
    }
192
    else
194
    else
193
    {
195
    {
194
        if (kdfread(&ud.savegame[spot][0],19,1,fil) != 1) goto corrupt;
196
        if (kdfread(&ud.savegame[spot][0],21,1,fil) != 1) goto corrupt;
-
 
197
        ud.savegame[spot][19] = 0;
195
    }
198
    }
196
199
197
200
198
    if (kdfread(&ud.volume_number,sizeof(ud.volume_number),1,fil) != 1) goto corrupt;
201
    if (kdfread(&ud.volume_number,sizeof(ud.volume_number),1,fil) != 1) goto corrupt;
199
    if (kdfread(&ud.level_number,sizeof(ud.level_number),1,fil) != 1) goto corrupt;
202
    if (kdfread(&ud.level_number,sizeof(ud.level_number),1,fil) != 1) goto corrupt;
Line 651... Line 654...
651
    dfwrite(g_szBuf,i,1,fil);
654
    dfwrite(g_szBuf,i,1,fil);
652
655
653
    dfwrite(&bv,sizeof(bv),1,fil);
656
    dfwrite(&bv,sizeof(bv),1,fil);
654
    dfwrite(&ud.multimode,sizeof(ud.multimode),1,fil);
657
    dfwrite(&ud.multimode,sizeof(ud.multimode),1,fil);
655
658
656
    dfwrite(&ud.savegame[spot][0],19,1,fil);
659
    dfwrite(&ud.savegame[spot][0],21,1,fil);
657
    dfwrite(&ud.volume_number,sizeof(ud.volume_number),1,fil);
660
    dfwrite(&ud.volume_number,sizeof(ud.volume_number),1,fil);
658
    dfwrite(&ud.level_number,sizeof(ud.level_number),1,fil);
661
    dfwrite(&ud.level_number,sizeof(ud.level_number),1,fil);
659
    dfwrite(&ud.player_skill,sizeof(ud.player_skill),1,fil);
662
    dfwrite(&ud.player_skill,sizeof(ud.player_skill),1,fil);
660
    dfwrite(&currentboardfilename[0],BMAX_PATH,1,fil);
663
    dfwrite(&currentboardfilename[0],BMAX_PATH,1,fil);
661
    if (!waloff[TILE_SAVESHOT])
664
    if (!waloff[TILE_SAVESHOT])
Line 2046... Line 2049...
2046
    mem=writespecdata(svgm_udnetw, fil, mem);  // user settings, players & net
2049
    mem=writespecdata(svgm_udnetw, fil, mem);  // user settings, players & net
2047
    PRINTSIZE(ud);
2050
    PRINTSIZE(ud);
2048
2051
2049
    if (spot>=0)
2052
    if (spot>=0)
2050
    {
2053
    {
2051
        SAVEWRU(&ud.savegame[spot][0], 19, 1);
2054
        SAVEWRU(&ud.savegame[spot][0], 21, 1);
2052
        SAVEWRU("1", 1, 1);
2055
        SAVEWRU("1", 1, 1);
2053
        if (!waloff[TILE_SAVESHOT])
2056
        if (!waloff[TILE_SAVESHOT])
2054
        {
2057
        {
2055
            walock[TILE_SAVESHOT] = 254;
2058
            walock[TILE_SAVESHOT] = 254;
2056
            allocache(&waloff[TILE_SAVESHOT],200*320,&walock[TILE_SAVESHOT]);
2059
            allocache(&waloff[TILE_SAVESHOT],200*320,&walock[TILE_SAVESHOT]);
Line 2059... Line 2062...
2059
        }
2062
        }
2060
        SAVEWR((char *)waloff[TILE_SAVESHOT], 320, 200);
2063
        SAVEWR((char *)waloff[TILE_SAVESHOT], 320, 200);
2061
    }
2064
    }
2062
    else
2065
    else
2063
    {
2066
    {
2064
        char buf[19];
2067
        char buf[21];
2065
        const time_t t=time(NULL);
2068
        const time_t t=time(NULL);
2066
        struct tm *st;
2069
        struct tm *st;
2067
        Bsprintf(buf, "Eduke32 demo");
2070
        Bsprintf(buf, "Eduke32 demo");
2068
        if (t>=0 && (st = localtime(&t)))
2071
        if (t>=0 && (st = localtime(&t)))
2069
            Bsprintf(buf, "Edemo32 %04d%02d%02d", st->tm_year+1900, st->tm_mon+1, st->tm_mday);
2072
            Bsprintf(buf, "Edemo32 %04d%02d%02d", st->tm_year+1900, st->tm_mon+1, st->tm_mday);
2070
        SAVEWRU(&buf, 19, 1);
2073
        SAVEWRU(&buf, 21, 1);
2071
        SAVEWRU("\0", 1, 1);  // demos don't save screenshot
2074
        SAVEWRU("\0", 1, 1);  // demos don't save screenshot
2072
    }
2075
    }
2073
2076
2074
    mem=writespecdata(svgm_secwsp, fil, mem);  // sector, wall, sprite
2077
    mem=writespecdata(svgm_secwsp, fil, mem);  // sector, wall, sprite
2075
    PRINTSIZE(sws);
2078
    PRINTSIZE(sws);
Line 2089... Line 2092...
2089
#define LOADRDU(ptr, sz, cnt) (kread(fil,ptr,(sz)*(cnt))!=(sz)*(cnt))
2092
#define LOADRDU(ptr, sz, cnt) (kread(fil,ptr,(sz)*(cnt))!=(sz)*(cnt))
2090
2093
2091
static int32_t doloadplayer2(int32_t spot, int32_t fil, uint8_t **memptr)
2094
static int32_t doloadplayer2(int32_t spot, int32_t fil, uint8_t **memptr)
2092
{
2095
{
2093
    uint8_t *mem = memptr ? *memptr : NULL, *tmem=mem;
2096
    uint8_t *mem = memptr ? *memptr : NULL, *tmem=mem;
2094
    char tbuf[19];
2097
    char tbuf[21];
2095
    int32_t i;
2098
    int32_t i;
2096
2099
2097
    if (readspecdata(svgm_udnetw, fil, &mem))
2100
    if (readspecdata(svgm_udnetw, fil, &mem))
2098
        return -2;
2101
        return -2;
2099
    PRINTSIZE(ud);
2102
    PRINTSIZE(ud);
2100
    if (spot >= 0 && ud.multimode!=numplayers)
2103
    if (spot >= 0 && ud.multimode!=numplayers)
2101
        return 2;
2104
        return 2;
2102
2105
2103
    if (spot<0 || numplayers > 1)
2106
    if (spot<0 || numplayers > 1)
2104
    {
2107
    {
2105
        if (LOADRDU(&tbuf, 19, 1)) return -3;
2108
        if (LOADRDU(&tbuf, 21, 1)) return -3;
2106
    }
2109
    }
2107
    else if (LOADRDU(&ud.savegame[spot][0], 19, 1)) return -3;
2110
    else if (LOADRDU(&ud.savegame[spot][0], 21, 1)) return -3;
-
 
2111
    else ud.savegame[spot][19] = 0;
2108
2112
2109
    if (LOADRDU(tbuf, 1, 1)) return -3;
2113
    if (LOADRDU(tbuf, 1, 1)) return -3;
2110
    if (tbuf[0])
2114
    if (tbuf[0])
2111
    {
2115
    {
2112
        //Fake read because lseek won't work with compression
2116
        //Fake read because lseek won't work with compression