diff --git a/Plague.g1a b/Plague.g1a index 12fbb36..7ffa8c6 100644 Binary files a/Plague.g1a and b/Plague.g1a differ diff --git a/src/save.c b/src/save.c index 01e4070..77d4363 100644 --- a/src/save.c +++ b/src/save.c @@ -15,7 +15,7 @@ void read_save(struct game *current_game) // Sizes of data const int planes_size = sizeof(*current_game->planes); - struct plane *planes = current_game->planes; + struct plane *planes[NB_PLANES + 1]; const int data_size = current_game->grid.width * current_game->grid.height; uint8_t *data = current_game->grid.data; @@ -37,12 +37,15 @@ void read_save(struct game *current_game) fd = BFile_Open(filename, BFile_ReadOnly); BFile_Read(fd, current_game, sizeof(*current_game), 0); - Bfile_Read(fd, planes, planes_size, -1); + BFile_Read(fd, planes, planes_size, -1); BFile_Read(fd, data, data_size, -1); BFile_Close(fd); - current_game->planes = planes; + for (int i = 0; planes[i]; i ++) + { + current_game->planes[i] = planes[i]; + } current_game->grid.data = data; } } @@ -55,7 +58,7 @@ void write_save(const struct game *current_game) // Create a new savefile const int data_size = current_game->grid.width * current_game->grid.height; - const int planes_size = sizeof(*current_game->planes); + const int planes_size = NB_PLANES * sizeof(struct plane); int size = sizeof(*current_game) + planes_size + data_size; BFile_Remove(filename); @@ -63,7 +66,10 @@ void write_save(const struct game *current_game) // Write data BFile_Write(fd, current_game, sizeof(*current_game)); - BFile_Write(fd, current_game->planes, planes_size); + for (int i = 0; current_game->planes[i] ; i ++) + { + BFile_Write(fd, current_game->planes[i], sizeof(struct plane)); + } BFile_Write(fd, current_game->grid.data, data_size); // Close file