Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
vars_access.c File Reference

Go to the source code of this file.

Functions

void clear_saved_variables (void)
 
void clear_area_flags (void)
 
s32 clear_global_flag (s32 index)
 
s32 set_global_flag (s32 index)
 
s32 get_global_flag (s32 index)
 
s8 set_global_byte (s32 index, s32 value)
 Set value of saved game byte.
 
s32 get_global_byte (s32 index)
 Get value of saved game byte.
 
s16 set_global_short (s32 index, s32 value)
 Store a short in two consecutive saved game bytes.
 
s16 get_global_short (s32 index)
 Retrieve a short from two consecutive saved game bytes.
 
s32 set_global_word (s32 index, s32 value)
 Store a word in four consecutive saved game bytes.
 
s32 get_global_word (s32 index)
 Retrieve a word from four consecutive saved game bytes.
 
s32 clear_area_flag (s32 index)
 
s32 set_area_flag (s32 index)
 
s32 get_area_flag (s32 index)
 
s8 set_area_byte (s32 index, s32 value)
 
s32 get_area_byte (s32 index)
 

Function Documentation

◆ clear_saved_variables()

void clear_saved_variables ( void )

Definition at line 5 of file vars_access.c.

5 {
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}
#define ARRAY_COUNT(arr)
Definition macros.h:40
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

Referenced by filemenu_yesno_handle_input(), load_engine_data(), state_init_demo(), state_step_demo(), state_step_intro(), and state_step_startup().

◆ clear_area_flags()

void clear_area_flags ( void )

Definition at line 26 of file vars_access.c.

26 {
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}
GameStatus * gGameStatusPtr
Definition main_loop.c:32

Referenced by load_map_by_IDs().

◆ clear_global_flag()

s32 clear_global_flag ( s32 index)

Definition at line 41 of file vars_access.c.

41 {
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}
#define EVT_GAME_FLAG_CUTOFF
Definition macros.h:34
#define EVT_INDEX_OF_GAME_FLAG(v)
Definition macros.h:142

Referenced by evt_set_variable().

◆ set_global_flag()

s32 set_global_flag ( s32 index)

Definition at line 65 of file vars_access.c.

65 {
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}

Referenced by entity_GiantChest_give_equipment(), entity_HeartBlock_show_tutorial_message(), entity_SaveBlock_show_tutorial_message(), evt_set_variable(), spawn_drops(), update_item_entity_collectable(), and update_item_entity_pickup().

◆ get_global_flag()

◆ set_global_byte()

s8 set_global_byte ( s32 index,
s32 value )

Set value of saved game byte.

Parameters
indexcan be either a global byte reference (GB_*) or index
valuenew value for the saved byte
Returns
previous value of the saved byte

Definition at line 108 of file vars_access.c.

108 {
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}
#define EVT_INDEX_OF_GAME_BYTE(v)
Definition macros.h:143
#define EVT_GAME_BYTE_CUTOFF
Definition macros.h:38

Referenced by evt_set_variable(), and save_tattle_flags().

◆ get_global_byte()

s32 get_global_byte ( s32 index)

Get value of saved game byte.

Parameters
indexcan be either a global byte reference (GB_*) or index
Returns
value of the saved byte

Definition at line 118 of file vars_access.c.

118 {
119 if (index <= EVT_GAME_BYTE_CUTOFF) {
120 index = EVT_INDEX_OF_GAME_BYTE(index);
121 }
122
123 return gCurrentSaveFile.globalBytes[index];
124}

Referenced by evt_get_float_variable(), evt_get_variable(), evt_handle_print_debug_var(), evt_set_variable(), is_actor_health_bar_visible(), is_actortype_health_bar_visible(), load_tattle_flags(), and save_tattle_flags().

◆ set_global_short()

s16 set_global_short ( s32 index,
s32 value )

Store a short in two consecutive saved game bytes.

Parameters
indexcan be either a global byte reference (GB_*) or index to the lowest byte
valuenew value for the saved short
Returns
previous value of the saved short

Definition at line 126 of file vars_access.c.

126 {
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}

◆ get_global_short()

s16 get_global_short ( s32 index)

Retrieve a short from two consecutive saved game bytes.

Parameters
indexcan be either a global byte reference (GB_*) or index to the lowest byte
Returns
value of the saved short

Definition at line 140 of file vars_access.c.

140 {
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}

◆ set_global_word()

s32 set_global_word ( s32 index,
s32 value )

Store a word in four consecutive saved game bytes.

Parameters
indexcan be either a global byte reference (GB_*) or index to the lowest byte
valuenew value for the saved word
Returns
previous value of the saved word

Definition at line 151 of file vars_access.c.

151 {
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}

◆ get_global_word()

s32 get_global_word ( s32 index)

Retrieve a word from four consecutive saved game bytes.

Parameters
indexcan be either a global byte reference (GB_*) or index to the lowest byte
Returns
value of the saved word

Definition at line 169 of file vars_access.c.

169 {
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}

◆ clear_area_flag()

s32 clear_area_flag ( s32 index)

Definition at line 182 of file vars_access.c.

182 {
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}

Referenced by evt_set_variable().

◆ set_area_flag()

s32 set_area_flag ( s32 index)

Definition at line 196 of file vars_access.c.

196 {
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}

Referenced by entity_base_switch_start_bound_script(), and evt_set_variable().

◆ get_area_flag()

s32 get_area_flag ( s32 index)

Definition at line 210 of file vars_access.c.

210 {
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}

Referenced by evt_get_variable(), evt_handle_print_debug_var(), evt_set_variable(), and update_triggers().

◆ set_area_byte()

s8 set_area_byte ( s32 index,
s32 value )

Definition at line 222 of file vars_access.c.

222 {
223 SaveData* saveFile = &gCurrentSaveFile;
224 s32 ret = saveFile->areaBytes[index];
225
226 saveFile->areaBytes[index] = value;
227 return ret;
228}

Referenced by evt_set_variable().

◆ get_area_byte()

s32 get_area_byte ( s32 index)

Definition at line 230 of file vars_access.c.

230 {
231 return gCurrentSaveFile.areaBytes[index];
232}

Referenced by evt_get_float_variable(), evt_get_variable(), evt_handle_print_debug_var(), and evt_set_variable().