savedata start
[carveJwlIkooP6JGAAIwe30JlM.git] / save.c
1 #ifndef SAVE_C
2 #define SAVE_C
3
4 struct {
5 u8 buf[ 1024 ];
6 u32 len;
7 }
8 static savedata;
9
10 static void skaterift_write_savedata(void){
11 vg_msg sav = {0};
12 sav.buf = savedata.buf;
13 sav.max = sizeof(savedata.buf);
14
15 vg_msg_frame( &sav, "player" );
16
17 if( localplayer.board_view_slot ){
18 struct cache_board *cache_ptr = localplayer.board_view_slot;
19 if( cache_ptr->reg_ptr ){
20 if( cache_ptr->reg_ptr->workshop_id )
21 vg_msg_wkvu64( &sav, "board", cache_ptr->reg_ptr->workshop_id );
22 else
23 vg_msg_wkvstr( &sav, "board", cache_ptr->reg_ptr->foldername );
24 }
25 }
26
27 vg_msg_end_frame( &sav );
28 savedata.len = sav.len;
29
30 FILE *fp = fopen( "save.bkv", "wb" );
31 if( fp ){
32 fwrite( savedata.buf, sav.len, 1, fp );
33 fclose( fp );
34 }
35 }
36
37 static void skaterift_read_savedata(void){
38 FILE *fp = fopen( "save.bkv", "rb" );
39 if( fp ){
40 savedata.len = fread( savedata.buf, 1, sizeof(savedata.buf), fp );
41 fclose( fp );
42 }
43 }
44
45 #endif /* SAVE_C */