Skip to content

Commit

Permalink
Added appropriate flags for sound mode and cap level. Documentation h…
Browse files Browse the repository at this point in the history
…as been updated.
  • Loading branch information
zrckr committed May 20, 2020
1 parent c540712 commit 89bab59
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 25 deletions.
20 changes: 10 additions & 10 deletions SAVE_FORMAT.MD
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ This section contains two flags for menu.

| Flag | Value | Description |
|---|---|---|
| coin_score_age | ?? | Each save file has a 2 bit "age" for each course. The higher this value, the older the high score is. This is used for tie-breaking when displaying on the high score screen
| sound_mode | ?? | Sound mode for the game: stereo, mono, or headset
| coin_score_age | 0, 1, 2, 3 | Each save file has a 2 bit "age" for each course. The higher this value, the older the high score is. This is used for tie-breaking when displaying on the high score screen
| sound_mode | stereo, mono, headset | Sound mode for the game

Example:
```
[menu]
coin_score_age = ??
sound_mode = ??
coin_score_age = 0
sound_mode = stereo
```
___
## Flags Section - [flags]
Expand Down Expand Up @@ -145,14 +145,14 @@ ___
This section contains information about where Mario lost his cap and who take it.
| Flag | Value | Description |
|---|---|---|
| type | ground, klepto, ukiki, mrblizzard | The one who or what took the cap from Mario.
| level | ?? | Specifies the course where the cap is located.
| area | ?? | Specifies the area in the course.
| type | ground, klepto, ukiki, mrblizzard | The one who or what took the cap from Mario. Default flag is **"ground"**
| level | ssl, sl, ttm, none | Specifies the course where the cap is located. Default flag is **"none"**.
| area | 1, 2 | Specifies the area in the course.

Example:
```
[cap]
type = onground
level = 5
area = 0
type = ground
level = ssl
area = 1
```
2 changes: 0 additions & 2 deletions src/game/save_file.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <ultra64.h>
#include <stdio.h>
#include "sm64.h"
#include "game_init.h"
#include "main.h"
Expand All @@ -11,7 +10,6 @@
#include "level_table.h"
#include "course_table.h"
#include "thread6.h"
#include "pc/ini.h"

#define MENU_DATA_MAGIC 0x4849
#define SAVE_FILE_MAGIC 0x4441
Expand Down
104 changes: 91 additions & 13 deletions src/game/text_save.inc.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include <string.h>
#include <stdio.h>
#include <time.h>
#include "course_table.h"
#include "pc/ini.h"

#define FILENAME_FORMAT "save_file_%d.sav"
#define NUM_COURSES 15
#define NUM_BONUS_COURSES 10
#define NUM_FLAGS 21
#define NUM_CAP_ON 4

/* Flag key */
/* Flag keys */
const char *sav_flags[NUM_FLAGS] = {
"file_exists", "wing_cap", "metal_cap", "vanish_cap", "key_1", "key_2",
"basement_door", "upstairs_door", "ddd_moved_back", "moat_drained",
Expand All @@ -31,6 +35,11 @@ const char *cap_on_types[NUM_CAP_ON] = {
"ground", "klepto", "ukiki", "mrblizzard"
};

/* Sound modes */
const char *sound_modes[3] = {
"stereo", "mono", "headset"
};

/* Get current timestamp */
static void get_timestamp(char* buffer) {
time_t timer;
Expand Down Expand Up @@ -75,7 +84,7 @@ static s32 write_text_save(s32 fileIndex) {
struct MainMenuSaveData *menudata;
char filename[32] = { 0 };
char value[32] = { 0 };
u32 i, flags, coins, stars, starFlags;
u32 i, bit, flags, coins, stars, starFlags;

/* Define savefile's name */
if (sprintf(filename, FILENAME_FORMAT, fileIndex) < 0)
Expand All @@ -84,6 +93,8 @@ static s32 write_text_save(s32 fileIndex) {
file = fopen(filename, "wt");
if (file == NULL)
return -1;
else
printf("Updating savefile in '%s'\n", filename);

/* Write header */
fprintf(file, "# Super Mario 64 save file\n");
Expand All @@ -98,8 +109,22 @@ static s32 write_text_save(s32 fileIndex) {
menudata = &gSaveBuffer.menuData[0];
fprintf(file, "\n[menu]\n");
fprintf(file, "coin_score_age = %d\n", menudata->coinScoreAges[fileIndex]);
fprintf(file, "sound_mode = %u\n", menudata->soundMode);


/* Sound mode */
if (menudata->soundMode == 0) {
fprintf(file, "sound_mode = %s\n", sound_modes[0]); // stereo
}
else if (menudata->soundMode == 3) {
fprintf(file, "sound_mode = %s\n", sound_modes[1]); // mono
}
else if (menudata->soundMode == 1) {
fprintf(file, "sound_mode = %s\n", sound_modes[2]); // headset
}
else {
printf("Undefined sound mode!");
return -1;
}

/* Write all flags */
fprintf(file, "\n[flags]\n");
for (i = 1; i < NUM_FLAGS; i++) {
Expand Down Expand Up @@ -139,7 +164,8 @@ static s32 write_text_save(s32 fileIndex) {
fprintf(file, "\n[cap]\n");
for (i = 0; i < NUM_CAP_ON; i++) {
flags = save_file_get_flags(); // Read all flags
flags = (flags & (1 << (i+16))); // Get `cap` flags
bit = (1 << (i+16)); // Determine current flag
flags = (flags & bit); // Get `cap` flag
flags = (flags) ? 1 : 0; // Determine if bit is set or not
if (flags) {
fprintf(file, "type = %s\n", cap_on_types[i]);
Expand All @@ -149,7 +175,20 @@ static s32 write_text_save(s32 fileIndex) {

/* Write in what course and area Mario losted its cap, and cap's position */
savedata = &gSaveBuffer.files[fileIndex][0];
fprintf(file, "level = %d\n", savedata->capLevel);
switch(savedata->capLevel) {
case COURSE_SSL:
fprintf(file, "level = %s\n", "ssl");
break;
case COURSE_SL:
fprintf(file, "level = %s\n", "sl");
break;
case COURSE_TTM:
fprintf(file, "level = %s\n", "ttm");
break;
default:
fprintf(file, "level = %s\n", "none");
break;
}
fprintf(file, "area = %d\n", savedata->capArea);

fclose(file);
Expand Down Expand Up @@ -178,15 +217,32 @@ static s32 read_text_save(s32 fileIndex) {
if (savedata == NULL) {
return -1;
} else {
printf("Loading savefile from '%s'\n", filename);
/* Good, file exists for gSaveBuffer */
gSaveBuffer.files[fileIndex][0].flags |= SAVE_FLAG_FILE_EXISTS;
}

/* Read coin score age for selected file and sound mode */
ini_sget(savedata, "menu", "coin_score_age", "%d",
&gSaveBuffer.menuData[0].coinScoreAges[fileIndex]);
ini_sget(savedata, "menu", "sound_mode", "%u",
&gSaveBuffer.menuData[0].soundMode); // Can override 4 times!

value = ini_get(savedata, "menu", "sound_mode");
if (value) {
if (strcmp(value, sound_modes[0]) == 0) {
gSaveBuffer.menuData[0].soundMode = 0; // stereo
}
else if (strcmp(value, sound_modes[1]) == 0) {
gSaveBuffer.menuData[0].soundMode = 3; // mono
}
else if (strcmp(value, sound_modes[2]) == 0) {
gSaveBuffer.menuData[0].soundMode = 1; // headset
}
}
else {
printf("Invalid 'menu:sound_mode' flag!\n");
return -1;
}


/* Parse main flags */
for (i = 1; i < NUM_FLAGS; i++) {
Expand Down Expand Up @@ -245,13 +301,35 @@ static s32 read_text_save(s32 fileIndex) {
}
}

/* ... also it's position, area and level */
sscanf(ini_get(savedata, "cap", "level"), "%d", &capLevel);
/* ... it's level ... */
value = ini_get(savedata, "cap", "level");
if (strcmp(value, "ssl") == 0) {
gSaveBuffer.files[fileIndex][0].capLevel = 8; // ssl
}
else if (strcmp(value, "sl") == 0) {
gSaveBuffer.files[fileIndex][0].capLevel = 10; // sl
}
else if (strcmp(value, "ttm") == 0) {
gSaveBuffer.files[fileIndex][0].capLevel = 12; // ttm
}
else if (strcmp(value, "none") == 0) {
gSaveBuffer.files[fileIndex][0].capLevel = 0;
}
else {
printf("Invalid 'cap:level' flag!\n");
return -1;
}

/* ... and it's area */
sscanf(ini_get(savedata, "cap", "area"), "%d", &capArea);
if (capArea > 1 && capArea < 2) {
printf("Invalid 'cap:area' flag: %d!\n", capArea);
return -1;
}
else {
gSaveBuffer.files[fileIndex][0].capArea = capArea;
}

gSaveBuffer.files[fileIndex][0].capLevel = capLevel;
gSaveBuffer.files[fileIndex][0].capArea = capArea;

/* Cleaning up after ourselves */
ini_free(savedata);
return 1;
Expand Down

0 comments on commit 89bab59

Please sign in to comment.