Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
vars_access.c
Go to the documentation of this file.
1#include "common.h"
2#include "vars_access.h"
3#include "dx/versioning.h"
4
6 SaveData* saveFile = &gCurrentSaveFile;
7 s32 i;
8
9 for (i = 0; i < ARRAY_COUNT(saveFile->globalFlags); i++) {
10 saveFile->globalFlags[i] = 0;
11 }
12
13 for (i = 0; i < ARRAY_COUNT(saveFile->globalBytes); i++) {
14 saveFile->globalBytes[i] = 0;
15 }
16
17 for (i = 0; i < ARRAY_COUNT(saveFile->areaFlags); i++) {
18 saveFile->areaFlags[i] = 0;
19 }
20
21 for (i = 0; i < ARRAY_COUNT(saveFile->areaBytes); i++) {
22 saveFile->areaBytes[i] = 0;
23 }
24}
25
26void clear_area_flags(void) {
27 SaveData* saveFile = &gCurrentSaveFile;
28 s32 i;
29
31 for (i = 0; i < ARRAY_COUNT(saveFile->areaFlags); i++) {
32 saveFile->areaFlags[i] = 0;
33 }
34
35 for (i = 0; i < ARRAY_COUNT(saveFile->areaBytes); i++) {
36 saveFile->areaBytes[i] = 0;
37 }
38 }
39}
40
41s32 clear_global_flag(s32 index) {
42 s32 wordIdx;
43 s32 bitIdx;
44 SaveData* saveFile;
45 s32 flag;
46
47 if (index <= EVT_GAME_FLAG_CUTOFF) {
48 index = EVT_INDEX_OF_GAME_FLAG(index);
49 }
50
51 wordIdx = index / 32;
52 bitIdx = index % 32;
53
54 saveFile = &gCurrentSaveFile;
55 flag = saveFile->globalFlags[wordIdx] & (1 << bitIdx);
56
57 if (flag != 0) {
58 flag = 1;
59 }
60
61 saveFile->globalFlags[wordIdx] &= ~(1 << bitIdx);
62 return flag;
63}
64
65s32 set_global_flag(s32 index) {
66 SaveData* saveFile;
67 s32 wordIdx;
68 s32 bitIdx;
69 s32 flag;
70
71 if (index <= EVT_GAME_FLAG_CUTOFF) {
72 index = EVT_INDEX_OF_GAME_FLAG(index);
73 }
74
75 wordIdx = index / 32;
76 bitIdx = index % 32;
77
78 saveFile = &gCurrentSaveFile;
79 flag = saveFile->globalFlags[wordIdx] & (1 << bitIdx);
80
81 if (flag != 0) {
82 flag = 1;
83 }
84
85 saveFile->globalFlags[wordIdx] |= (1 << bitIdx);
86 return flag;
87}
88
89s32 get_global_flag(s32 index) {
90 s32 wordIdx;
91 s32 bitIdx;
92 s32 flag;
93
94 if (index <= EVT_GAME_FLAG_CUTOFF) {
95 index = EVT_INDEX_OF_GAME_FLAG(index);
96 }
97
98 wordIdx = index / 32;
99 bitIdx = index % 32;
100 flag = gCurrentSaveFile.globalFlags[wordIdx] & (1 << bitIdx);
101
102 if (flag != 0) {
103 flag = 1;
104 }
105 return flag;
106}
107
108s8 set_global_byte(s32 index, s32 value) {
109 if (index <= EVT_GAME_BYTE_CUTOFF) {
110 index = EVT_INDEX_OF_GAME_BYTE(index);
111 }
112
113 s32 ret = gCurrentSaveFile.globalBytes[index];
114 gCurrentSaveFile.globalBytes[index] = value;
115 return ret;
116}
117
118s32 get_global_byte(s32 index) {
119 if (index <= EVT_GAME_BYTE_CUTOFF) {
120 index = EVT_INDEX_OF_GAME_BYTE(index);
121 }
122
123 return gCurrentSaveFile.globalBytes[index];
124}
125
126s16 set_global_short(s32 index, s32 value) {
127 if (index <= EVT_GAME_BYTE_CUTOFF) {
128 index = EVT_INDEX_OF_GAME_BYTE(index);
129 }
130
131 s32 b1 = gCurrentSaveFile.globalBytes[index] & 0xFF;
132 s32 b2 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
133 s16 ret = (b2 << 8) | b1;
134
135 gCurrentSaveFile.globalBytes[index] = value & 0xFF;
136 gCurrentSaveFile.globalBytes[index + 1] = (value >> 8) & 0xFF;
137 return ret;
138}
139
140s16 get_global_short(s32 index) {
141 if (index <= EVT_GAME_BYTE_CUTOFF) {
142 index = EVT_INDEX_OF_GAME_BYTE(index);
143 }
144
145 s32 b1 = gCurrentSaveFile.globalBytes[index] & 0xFF;
146 s32 b2 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
147
148 return (b2 << 8) | b1;
149}
150
151s32 set_global_word(s32 index, s32 value) {
152 if (index <= EVT_GAME_BYTE_CUTOFF) {
153 index = EVT_INDEX_OF_GAME_BYTE(index);
154 }
155
156 s32 b1 = gCurrentSaveFile.globalBytes[index] & 0xFF;
157 s32 b2 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
158 s32 b3 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
159 s32 b4 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
160 s16 ret = (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
161
162 gCurrentSaveFile.globalBytes[index] = value & 0xFF;
163 gCurrentSaveFile.globalBytes[index + 1] = (value >> 8) & 0xFF;
164 gCurrentSaveFile.globalBytes[index + 2] = (value >> 16) & 0xFF;
165 gCurrentSaveFile.globalBytes[index + 3] = (value >> 24) & 0xFF;
166 return ret;
167}
168
169s32 get_global_word(s32 index) {
170 if (index <= EVT_GAME_BYTE_CUTOFF) {
171 index = EVT_INDEX_OF_GAME_BYTE(index);
172 }
173
174 s32 b1 = gCurrentSaveFile.globalBytes[index] & 0xFF;
175 s32 b2 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
176 s32 b3 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
177 s32 b4 = gCurrentSaveFile.globalBytes[index + 1] & 0xFF;
178
179 return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
180}
181
182s32 clear_area_flag(s32 index) {
183 s32 wordIdx = index / 32;
184 s32 bitIdx = index % 32;
185 SaveData* saveFile = &gCurrentSaveFile;
186 s32 flag = saveFile->areaFlags[wordIdx] & (1 << bitIdx);
187
188 if (flag != 0) {
189 flag = 1;
190 }
191
192 saveFile->areaFlags[wordIdx] &= ~(1 << bitIdx);
193 return flag;
194}
195
196s32 set_area_flag(s32 index) {
197 s32 wordIdx = index / 32;
198 s32 bitIdx = index % 32;
199 SaveData* saveFile = &gCurrentSaveFile;
200 s32 flag = saveFile->areaFlags[wordIdx] & (1 << bitIdx);
201
202 if (flag != 0) {
203 flag = 1;
204 }
205
206 saveFile->areaFlags[wordIdx] |= 1 << bitIdx;
207 return flag;
208}
209
210s32 get_area_flag(s32 index) {
211 s32 wordIdx = index / 32;
212 s32 bitIdx = index % 32;
213 s32 flag = gCurrentSaveFile.areaFlags[wordIdx] & (1 << bitIdx);
214
215 if (flag != 0) {
216 flag = 1;
217 }
218
219 return flag;
220}
221
222s8 set_area_byte(s32 index, s32 value) {
223 SaveData* saveFile = &gCurrentSaveFile;
224 s32 ret = saveFile->areaBytes[index];
225
226 saveFile->areaBytes[index] = value;
227 return ret;
228}
229
230s32 get_area_byte(s32 index) {
231 return gCurrentSaveFile.areaBytes[index];
232}
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define EVT_GAME_FLAG_CUTOFF
Definition macros.h:34
#define EVT_INDEX_OF_GAME_BYTE(v)
Definition macros.h:143
#define EVT_GAME_BYTE_CUTOFF
Definition macros.h:38
#define EVT_INDEX_OF_GAME_FLAG(v)
Definition macros.h:142
GameStatus * gGameStatusPtr
Definition main_loop.c:32
s16 set_global_short(s32 index, s32 value)
Store a short in two consecutive saved game bytes.
s32 set_global_flag(s32 index)
Definition vars_access.c:65
void clear_saved_variables(void)
Definition vars_access.c:5
s32 get_global_flag(s32 index)
Definition vars_access.c:89
s32 set_area_flag(s32 index)
s32 set_global_word(s32 index, s32 value)
Store a word in four consecutive saved game bytes.
s32 get_global_byte(s32 index)
Get value of saved game byte.
s32 clear_area_flag(s32 index)
s32 get_area_flag(s32 index)
void clear_area_flags(void)
Definition vars_access.c:26
s32 get_area_byte(s32 index)
s8 set_area_byte(s32 index, s32 value)
s16 get_global_short(s32 index)
Retrieve a short from two consecutive saved game bytes.
s32 clear_global_flag(s32 index)
Definition vars_access.c:41
s32 get_global_word(s32 index)
Retrieve a word from four consecutive saved game bytes.
s8 set_global_byte(s32 index, s32 value)
Set value of saved game byte.
s32 areaFlags[8]
Definition versioning.h:162
s32 globalFlags[64]
Definition versioning.h:160
s8 globalBytes[512]
Definition versioning.h:161
SaveData gCurrentSaveFile
Definition fio.c:21
s8 areaBytes[16]
Definition versioning.h:163