4
4
5
5
#include < gc/card.h>
6
6
#include < ttyd/string.h>
7
- #include < ttyd/__mem.h>
8
7
9
8
#include < cstdio>
10
9
@@ -173,8 +172,11 @@ int32_t writeSettings(char *description, char *fileName,
173
172
return ReturnCode;
174
173
}
175
174
176
- uint32_t SettingsStructSize;
177
- uint32_t SettingsStructSizeAdjusted;
175
+ // Get the size thats going to be written
176
+ uint32_t FileSize = sizeof (struct SettingsStruct ) + 0x200 ;
177
+
178
+ // Adjust the file size to be in multiples of 0x2000, rounding up
179
+ uint32_t FileSizeAdjusted = (FileSize + 0x2000 - 1 ) & ~(0x2000 - 1 );
178
180
179
181
// Open the settings file if it exists
180
182
ReturnCode = gc::card::CARDOpen (CARD_SLOTA, fileName, fileInfo);
@@ -197,22 +199,16 @@ int32_t writeSettings(char *description, char *fileName,
197
199
}
198
200
199
201
// Get the size of the file
200
- uint32_t CurrentFileSize = *reinterpret_cast <uint32_t *>(&tempFileData[0x40 ]);
202
+ uint32_t StoredFileSize = *reinterpret_cast <uint32_t *>(&tempFileData[0x40 ]);
201
203
202
204
// Delete the data that holds the size, as it's not needed anymore
203
205
delete[] (tempFileData);
204
206
205
207
// Adjust the file size to be in multiples of 0x2000, rounding up
206
- uint32_t CurrentFileSizeAdjusted = (CurrentFileSize + 0x2000 - 1 ) & ~(0x2000 - 1 );
207
-
208
- // Get the size thats going to be written
209
- SettingsStructSize = sizeof (struct SettingsStruct );
210
-
211
- // Adjust the file size to be in multiples of 0x2000, rounding up
212
- SettingsStructSizeAdjusted = (SettingsStructSize + 0x2000 - 1 ) & ~(0x2000 - 1 );
208
+ uint32_t StoredFileSizeAdjusted = (StoredFileSize + 0x2000 - 1 ) & ~(0x2000 - 1 );
213
209
214
210
// Make sure the size being written does not exceed the current size
215
- if (SettingsStructSizeAdjusted > CurrentFileSizeAdjusted )
211
+ if (FileSizeAdjusted > StoredFileSizeAdjusted )
216
212
{
217
213
// The new size exceeds the current size, so a new file must be made created
218
214
// Close the file
@@ -250,12 +246,6 @@ int32_t writeSettings(char *description, char *fileName,
250
246
{
251
247
return ReturnCode;
252
248
}
253
-
254
- // Get the size thats going to be written
255
- SettingsStructSize = sizeof (struct SettingsStruct );
256
-
257
- // Adjust the file size to be in multiples of 0x2000, rounding up
258
- SettingsStructSizeAdjusted = (SettingsStructSize + 0x2000 - 1 ) & ~(0x2000 - 1 );
259
249
break ;
260
250
}
261
251
default :
@@ -265,13 +255,13 @@ int32_t writeSettings(char *description, char *fileName,
265
255
}
266
256
267
257
// Set up the memory to be written to the file
268
- char *MiscData = new char [SettingsStructSizeAdjusted ];
269
- clearMemory (MiscData, SettingsStructSizeAdjusted );
258
+ char *MiscData = new char [FileSizeAdjusted ];
259
+ clearMemory (MiscData, FileSizeAdjusted );
270
260
271
261
// Copy the name, description, and file size into the memory
272
262
ttyd::string::strcpy (MiscData, " Paper Mario" );
273
263
ttyd::string::strcpy (&MiscData[0x20 ], description);
274
- *reinterpret_cast <uint32_t *>(&MiscData[0x40 ]) = SettingsStructSize + 0x200 ;
264
+ *reinterpret_cast <uint32_t *>(&MiscData[0x40 ]) = FileSize ;
275
265
276
266
// Set up the struct to hold the variables to store
277
267
SettingsStruct *Settings = reinterpret_cast <SettingsStruct *>(&MiscData[0x200 ]);
@@ -296,7 +286,7 @@ int32_t writeSettings(char *description, char *fileName,
296
286
Settings->DisplaysButtonCombos [ONSCREEN_TIMER + 1 ] = OnScreenTimer.ButtonCombo [1 ];
297
287
298
288
// Write the data to the file
299
- ReturnCode = writeToCard (fileInfo, MiscData, SettingsStructSizeAdjusted , 0x2000 , nullptr );
289
+ ReturnCode = writeToCard (fileInfo, MiscData, FileSizeAdjusted , 0x2000 , nullptr );
300
290
301
291
delete[] (MiscData);
302
292
gc::card::CARDClose (fileInfo);
0 commit comments