forked from HarbourMasters/Ghostship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_file.h
More file actions
227 lines (186 loc) · 6.64 KB
/
Copy pathsave_file.h
File metadata and controls
227 lines (186 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#ifndef SAVE_FILE_H
#define SAVE_FILE_H
#include <libultra/types.h>
#include "port/Rando/Types.h"
#include "types.h"
#include "area.h"
#include "course_table.h"
#define EEPROM_SIZE 0x200
#define SAVE_FILE_SIZE 0x38
#define MENU_SAVE_DATA_SIZE 0x20
#define NUM_SAVE_FILES 4
struct SaveBlockSignature {
u16 magic;
u16 chksum;
};
struct RandoSaveCheck {
RandoItemId randoItemId;
RandoAct randoAct;
bool obtained;
bool skipped;
};
struct RandoSaveEntrance {
RandoEntranceId randoEntranceId;
int16_t destinationId;
};
struct RandoSaveOption {
const char* randoOptionName;
int32_t randoOptionValue;
};
typedef enum {
SAVETYPE_VANILLA,
SAVETYPE_RANDO,
} SaveType;
struct RandoSaveData {
struct RandoSaveCheck randoSaveChecks[RC_MAX];
struct RandoSaveEntrance randoSaveEntrances[RE_MAX];
u32 randoSaveOptions[RO_MAX];
u32 finalSeed;
};
struct ShipSaveData {
SaveType saveType;
struct RandoSaveData randoSaveData;
};
struct SaveFile {
// Location of lost cap.
// Note: the coordinates get set, but are never actually used, since the
// cap can always be found in a fixed spot within the course
u8 capLevel;
u8 capArea;
Vec3s capPos;
u32 flags;
// Star flags for each course.
// The most significant bit of the byte *following* each course is set if the
// cannon is open.
u8 courseStars[COURSE_COUNT];
u8 courseCoinScores[COURSE_STAGES_COUNT];
struct SaveBlockSignature signature;
// @port: Custom data needs to go after this point
struct ShipSaveData shipSaveData;
};
enum SaveFileIndex {
SAVE_FILE_A,
SAVE_FILE_B,
SAVE_FILE_C,
SAVE_FILE_D
};
struct MainMenuSaveData {
// 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.
u32 coinScoreAges[NUM_SAVE_FILES];
u16 soundMode;
#ifdef VERSION_EU
u16 language;
#define SUBTRAHEND 8
#else
#define SUBTRAHEND 6
#endif
// Pad to match the EEPROM size of 0x200 (10 bytes on JP/US, 8 bytes on EU)
u8 filler[EEPROM_SIZE / 2 - SUBTRAHEND - NUM_SAVE_FILES * (4 + SAVE_FILE_SIZE)];
struct SaveBlockSignature signature;
// @port: Custom data needs to go after this point
struct ShipSaveData shipSaveData;
};
struct SaveBuffer {
// Each of the four save files has two copies. If one is bad, the other is used as a backup.
struct SaveFile files[NUM_SAVE_FILES][2];
// The main menu data has two copies. If one is bad, the other is used as a backup.
struct MainMenuSaveData menuData[2];
};
extern u8 gLastCompletedCourseNum;
extern u8 gLastCompletedStarNum;
extern s8 sUnusedGotGlobalCoinHiScore;
extern u8 gGotFileCoinHiScore;
extern u8 gCurrCourseStarFlags;
extern u8 gSpecialTripleJump;
extern s8 gLevelToCourseNumTable[];
// game progress flags
#define SAVE_FLAG_FILE_EXISTS /* 0x00000001 */ (1 << 0)
#define SAVE_FLAG_HAVE_WING_CAP /* 0x00000002 */ (1 << 1)
#define SAVE_FLAG_HAVE_METAL_CAP /* 0x00000004 */ (1 << 2)
#define SAVE_FLAG_HAVE_VANISH_CAP /* 0x00000008 */ (1 << 3)
#define SAVE_FLAG_HAVE_KEY_1 /* 0x00000010 */ (1 << 4)
#define SAVE_FLAG_HAVE_KEY_2 /* 0x00000020 */ (1 << 5)
#define SAVE_FLAG_UNLOCKED_BASEMENT_DOOR /* 0x00000040 */ (1 << 6)
#define SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR /* 0x00000080 */ (1 << 7)
#define SAVE_FLAG_DDD_MOVED_BACK /* 0x00000100 */ (1 << 8)
#define SAVE_FLAG_MOAT_DRAINED /* 0x00000200 */ (1 << 9)
#define SAVE_FLAG_UNLOCKED_PSS_DOOR /* 0x00000400 */ (1 << 10)
#define SAVE_FLAG_UNLOCKED_WF_DOOR /* 0x00000800 */ (1 << 11)
#define SAVE_FLAG_UNLOCKED_CCM_DOOR /* 0x00001000 */ (1 << 12)
#define SAVE_FLAG_UNLOCKED_JRB_DOOR /* 0x00002000 */ (1 << 13)
#define SAVE_FLAG_UNLOCKED_BITDW_DOOR /* 0x00004000 */ (1 << 14)
#define SAVE_FLAG_UNLOCKED_BITFS_DOOR /* 0x00008000 */ (1 << 15)
#define SAVE_FLAG_CAP_ON_GROUND /* 0x00010000 */ (1 << 16)
#define SAVE_FLAG_CAP_ON_KLEPTO /* 0x00020000 */ (1 << 17)
#define SAVE_FLAG_CAP_ON_UKIKI /* 0x00040000 */ (1 << 18)
#define SAVE_FLAG_CAP_ON_MR_BLIZZARD /* 0x00080000 */ (1 << 19)
#define SAVE_FLAG_UNLOCKED_50_STAR_DOOR /* 0x00100000 */ (1 << 20)
#define SAVE_FLAG_COLLECTED_TOAD_STAR_1 /* 0x01000000 */ (1 << 24)
#define SAVE_FLAG_COLLECTED_TOAD_STAR_2 /* 0x02000000 */ (1 << 25)
#define SAVE_FLAG_COLLECTED_TOAD_STAR_3 /* 0x04000000 */ (1 << 26)
#define SAVE_FLAG_COLLECTED_MIPS_STAR_1 /* 0x08000000 */ (1 << 27)
#define SAVE_FLAG_COLLECTED_MIPS_STAR_2 /* 0x10000000 */ (1 << 28)
#define SAVE_FLAG_TO_STAR_FLAG(cmd) (((cmd) >> 24) & 0x7F)
#define STAR_FLAG_TO_SAVE_FLAG(cmd) ((cmd) << 24)
// Variable for setting a warp checkpoint.
// possibly a WarpDest struct where arg is a union. TODO: Check?
struct WarpCheckpoint {
/*0x00*/ u8 actNum;
/*0x01*/ u8 courseNum;
/*0x02*/ u8 levelID;
/*0x03*/ u8 areaNum;
/*0x04*/ u8 warpNode;
};
#ifdef __cplusplus
extern "C" {
#endif
extern struct WarpCheckpoint gWarpCheckpoint;
extern s8 gMainMenuDataModified;
extern s8 gSaveFileModified;
#ifdef __cplusplus
extern "C" {
#endif
void save_file_do_save(s32 fileIndex);
void save_file_erase(s32 fileIndex);
BAD_RETURN(s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex);
void save_file_load_all(void);
void save_file_reload(void);
void save_file_collect_star_or_key(s16 coinScore, s16 starIndex);
s32 save_file_exists(s32 fileIndex);
u32 save_file_get_max_coin_score(s32 courseIndex);
s32 save_file_get_course_star_count(s32 fileIndex, s32 courseIndex);
s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse);
void save_file_set_flags(u32 flags);
void save_file_clear_flags(u32 flags);
u32 save_file_get_flags(void);
u32 save_file_get_star_flags(s32 fileIndex, s32 courseIndex);
void save_file_set_star_flags(s32 fileIndex, s32 courseIndex, u32 starFlags);
s32 save_file_get_course_coin_score(s32 fileIndex, s32 courseIndex);
s32 save_file_is_cannon_unlocked(void);
void save_file_set_cannon_unlocked(void);
void save_file_set_cap_pos(s16 x, s16 y, s16 z);
s32 save_file_get_cap_pos(Vec3s capPos);
void save_file_set_sound_mode(u16 mode);
u16 save_file_get_sound_mode(void);
void save_file_move_cap_to_default_location(void);
void disable_warp_checkpoint(void);
void check_if_should_set_warp_checkpoint(struct WarpNode *warpNode);
s32 check_warp_checkpoint(struct WarpNode *warpNode);
#ifdef __cplusplus
}
#endif
#ifdef VERSION_EU
enum EuLanguages {
LANGUAGE_ENGLISH,
LANGUAGE_FRENCH,
LANGUAGE_GERMAN
};
void eu_set_language(u16 language);
u16 eu_get_language(void);
#endif
#ifdef __cplusplus
}
#endif
#endif // SAVE_FILE_H