Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dummy file creating, lock supportedLang to 0x3F if region changing #42

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 1 addition & 57 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ int main( int argc, char **argv) {
iprintf("\n");
if ((cursorPosition == 0) && (optionCount > 2)) {
iprintf(" Change the SDNAND region.\n");
if (regionChar == 'J') {
iprintf(" System settings will be reset.\n");
}
iprintf(" \n");
iprintf(" Original region: ");
if (regionChar == 'J') {
Expand Down Expand Up @@ -461,71 +458,18 @@ int main( int argc, char **argv) {
if (newRegion != oldRegion) {
FILE* f_hwinfoS = fopen("sd:/sys/HWINFO_S.dat", "rb+");
if (f_hwinfoS) {
u32 supportedLangBitmask = 0x01; // JPN: Japanese
u32 supportedLangBitmask = 0x3F; // Japanese, English, French, German, Italian, Spanish
if (newRegion == 5) { // KOR
supportedLangBitmask = 0x80; // Korean
} else if (newRegion == 4) { // CHN
supportedLangBitmask = 0x40; // Chinese
} else if (newRegion == 3) { // AUS
supportedLangBitmask = 0x02; // English
} else if (newRegion == 2) { // EUR
supportedLangBitmask = 0x3E; // English, French, German, Italian, Spanish
} else if (newRegion == 1) { // USA
supportedLangBitmask = 0x26; // English, French, Spanish
}
fseek(f_hwinfoS, 0x88, SEEK_SET);
fwrite(&supportedLangBitmask, sizeof(u32), 1, f_hwinfoS);
fseek(f_hwinfoS, 0x90, SEEK_SET);
fwrite(&newRegion, 1, 1, f_hwinfoS);
fclose(f_hwinfoS);
}
if (regionChar == 'J') {
// Reset system settings to work around touch inputs not working
remove("sd:/shared1/TWLCFG0.dat");
remove("sd:/shared1/TWLCFG1.dat");
}
}

// Create dummy file
// Check the free space
struct statvfs st;
statvfs("sd:/", &st);
u32 freeSpace = st.f_bsize * st.f_bfree;
u64 realFreeSpace = st.f_bsize * st.f_bfree;

// If the free space is bigger than 2GiB (using a u32 so always 0 - 4GiB)
// or the free space is less than 20MiB (and the actual free space is over 4GiB)
if(freeSpace > (2u << 30) || (freeSpace < (20u << 20) && realFreeSpace > (4u << 30))) {
consoleDemoInit();
size_t oldSize = 0;
// Check old dummy file size to see if it can just be removed
FILE *file = fopen("sd:/hiya/dummy.bin", "rb");
if(file) {
fseek(file, 0, SEEK_END);
oldSize = ftell(file);
fclose(file);
}

// Check that dummy file is still needed
if((freeSpace + oldSize) > (2u << 30) || (freeSpace + oldSize) < (20u << 20)) {
// Make sure hiya directory exists and make the file
mkdir("sd:/hiya", 0777);
iprintf("Making new dummy file... ");

// Make sure the file exists
file = fopen("sd:/hiya/dummy.bin", "wb");
if(file)
fclose(file);

// If free space is less than 20MiB, add free space + 2GiB + 10MiB
// otherwise add free space - 2GiB + 10MiB
truncate("sd:/hiya/dummy.bin", (freeSpace < (20u << 20) ? (freeSpace + (2 << 30)) : (freeSpace - (2 << 30))) + (10 << 20));
iprintf("Done!\n");
} else {
iprintf("Removing old dummy file... ");
remove("sd:/hiya/dummy.bin");
iprintf("Done!\n");
}
}

if (!gotoSettings && (*(u32*)0x02000300 == 0x434E4C54)) {
Expand Down
Binary file modified template.7z
Binary file not shown.