X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=save.c;h=90e9c202cbab2732ce793d90e0ce7dca9603a3a3;hb=137d40d96fe923600d8378b8e138e3c276f27ff4;hp=ed869e67af7aa031f7b332fb063657a2cdd21171;hpb=c77e15a8dc7b976371a473bc8794cb55601d82f6;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/save.c b/save.c index ed869e6..90e9c20 100644 --- a/save.c +++ b/save.c @@ -65,22 +65,22 @@ static void skaterift_read_addon_alias( vg_msg *msg, const char *key, alias->workshop_id = 0; alias->type = type; - vg_msg_cmd kv = vg_msg_seekkv( msg, key, 0 ); - if( kv.code == k_vg_msg_kvstring ){ - vg_strncpy( kv.value, alias->foldername, sizeof(alias->foldername), - k_strncpy_allow_cutoff ); + vg_msg_cmd kv; + if( vg_msg_getkvcmd( msg, key, &kv ) ){ + if( kv.code == k_vg_msg_kvstring ){ + vg_strncpy( kv.value, alias->foldername, sizeof(alias->foldername), + k_strncpy_allow_cutoff ); + } + else + vg_msg_cast( kv.value, kv.code, &alias->workshop_id, k_vg_msg_u64 ); } - else - alias->workshop_id = vg_msg_read_as_u64( &kv ); } static void skaterift_populate_world_savedata( savedata_file *file, enum world_purpose which ){ file->path[0] = '\0'; file->len = 0; - addon_reg *reg = NULL; - if( which == k_world_purpose_hub ) reg = world_static.addon_hub; - else reg = world_static.addon_client; + addon_reg *reg = world_static.instance_addons[ which ]; if( !reg ){ vg_error( "Tried to save unspecified world (reg was null)\n" ); @@ -89,9 +89,8 @@ static void skaterift_populate_world_savedata( savedata_file *file, skaterift_world_get_save_path( which, file->path ); - vg_msg sav = {0}; - sav.buf = file->buf; - sav.max = sizeof(file->buf); + vg_msg sav; + vg_msg_init( &sav, file->buf, sizeof(file->buf) ); if( which == k_world_purpose_hub ){ if( world_static.instances[0].status == k_world_status_loaded ) @@ -106,15 +105,14 @@ static void skaterift_populate_world_savedata( savedata_file *file, } } - file->len = sav.len; + file->len = sav.cur.co; } static void skaterift_populate_main_savedata( savedata_file *file ){ strcpy( file->path, str_skaterift_main_save ); - vg_msg sav = {0}; - sav.buf = file->buf; - sav.max = sizeof(file->buf); + vg_msg sav; + vg_msg_init( &sav, file->buf, sizeof(file->buf) ); vg_msg_frame( &sav, "player" ); { @@ -127,17 +125,17 @@ static void skaterift_populate_main_savedata( savedata_file *file ){ vg_msg_frame( &sav, "world" ); { - addon_reg *reg = world_static.addon_client; + addon_reg *reg = world_static.instance_addons[ k_world_purpose_client ]; if( reg && (world_static.active_instance > 0) ){ skaterift_write_addon_alias( &sav, "alias", ®->alias ); - vg_msg_wkvu32( &sav, "index", world_static.active_instance ); - vg_msg_wkvnum( &sav, "position", k_vg_msg_float|k_vg_msg_32b, 3, - localplayer.rb.co ); } + vg_msg_wkvu32( &sav, "index", world_static.active_instance ); + vg_msg_wkvnum( &sav, "position", k_vg_msg_float|k_vg_msg_32b, 3, + localplayer.rb.co ); } vg_msg_end_frame( &sav ); - file->len = sav.len; + file->len = sav.cur.co; } static int skaterift_autosave( int async ){ @@ -145,7 +143,7 @@ static int skaterift_autosave( int async ){ if( !vg_loader_availible() ) return 0; u32 save_files = 2; - if( world_static.addon_client ) + if( world_static.instance_addons[ k_world_purpose_client ] ) save_files ++; vg_linear_clear( vg_async.buffer ); @@ -163,9 +161,10 @@ static int skaterift_autosave( int async ){ skaterift_populate_main_savedata( &group->files[0] ); skaterift_populate_world_savedata( &group->files[1], k_world_purpose_hub ); - if( world_static.addon_client ) + if( world_static.instance_addons[ k_world_purpose_client ] ){ skaterift_populate_world_savedata( &group->files[2], k_world_purpose_client ); + } if( async ) vg_loader_start( (void *)savedata_group_write, group );