Convert names to snake case

This commit is contained in:
Nightkingale 2024-04-28 11:50:47 -06:00
parent 82e51b2f8a
commit 673f560e77
12 changed files with 128 additions and 131 deletions

View File

@ -2,9 +2,8 @@
#define BACKUP_HPP
void writeBackup(FILE* account, const std::string& backupPath, char* buffer);
void backupAccount();
void write_backup(FILE* account, const std::string& backup_path, char* buffer);
void backup_account();
#endif

View File

@ -5,19 +5,13 @@
extern const int BUFFER_SIZE;
extern unsigned int USER_ID;
extern std::string NNID_BACKUP;
extern std::string PNID_BACKUP;
extern std::string MII_NICKNAME;
extern std::string ACCOUNT_FILE;
extern std::string INKAY_CONFIG;
#endif

View File

@ -2,13 +2,10 @@
#define SCREEN_HPP
void printMainMenu();
void printUnlinkMenu();
void printBackupMenu();
void printOverwriteMenu(const char* backupPath);
void print_main_menu();
void print_unlink_menu();
void print_backup_menu();
void print_overwrite_menu(const char* backup_path);
#endif

View File

@ -2,9 +2,8 @@
#define SWITCH_HPP
void handleCleanup(FILE* account, FILE* backup, char* buffer, bool isError);
void switchAccount(const char* backupFile, const char* accountType);
void handle_cleanup(FILE* account, FILE* backup, char* buffer, bool is_error);
void switch_account(const char* backupFile, const char* accountType);
#endif

View File

@ -2,7 +2,7 @@
#define UNLINK_HPP
void unlinkAccount();
void unlink_account();
#endif

View File

@ -2,10 +2,8 @@
#define UTILS_HPP
void printOnScreen(int line, const char* format, ...);
void print_on_screen(int line, const char* format, ...);
void deinitialize();
void initialize();

View File

@ -20,9 +20,9 @@
#include "../include/screen.hpp"
bool backupConfirm = false;
bool backup_confirm = false;
void handleCleanup(FILE* account, FILE* backup, char* buffer, bool isError = false) {
void handle_cleanup(FILE* account, FILE* backup, char* buffer, bool is_error = false) {
// Wait 5 seconds.
OSSleepTicks(OSMillisecondsToTicks(5000));
@ -48,30 +48,31 @@ void handleCleanup(FILE* account, FILE* backup, char* buffer, bool isError = fal
}
// If there was an error, print the main menu.
if (isError) {
if (is_error) {
WHBLogPrint("---------------------------------------------------------");
printMainMenu();
print_main_menu();
}
}
void writeBackup(FILE* account, const std::string& backupPath, char* buffer) {
void write_backup(FILE* account, const std::string& backup_path, char* buffer) {
// Create the directories if they don't exist.
std::filesystem::path dirPath = std::filesystem::path(backupPath).remove_filename();
std::filesystem::path dirPath = std::filesystem::path(backup_path).remove_filename();
std::filesystem::create_directories(dirPath);
// Open the backup file for writing.
FILE *backup = fopen(backupPath.c_str(), "wb");
FILE *backup = fopen(backup_path.c_str(), "wb");
if (backup == NULL) {
WHBLogConsoleSetColor(0x99000000);
WHBLogPrintf("Error opening backup file.");
WHBLogPrintf("%s", backupPath.c_str());
WHBLogPrintf("%s", backup_path.c_str());
WHBLogConsoleDraw();
handleCleanup(account, backup, buffer, true);
handle_cleanup(account, backup, buffer, true);
return;
}
// Print the backup path to the screen.
WHBLogPrintf("%s", backupPath.c_str());
WHBLogPrintf("%s", backup_path.c_str());
WHBLogConsoleDraw();
// Open the backup file and write the account data to it.
@ -84,7 +85,7 @@ void writeBackup(FILE* account, const std::string& backupPath, char* buffer) {
// Close the backup file.
fclose(backup);
WHBLogPrintf("Backup account.dat written.", backupPath);
WHBLogPrintf("Backup account.dat written.", backup_path);
WHBLogConsoleDraw();
// Wait 5 seconds, then go back to the menu.
@ -97,7 +98,8 @@ void writeBackup(FILE* account, const std::string& backupPath, char* buffer) {
fclose(backup);
}
void backupAccount() {
void backup_account() {
// Inform the user that the backup process has started.
WHBLogConsoleSetColor(0x00009900);
WHBLogPrintf("Backup: A Network ID backup will be created.");
@ -105,13 +107,13 @@ void backupAccount() {
WHBLogConsoleDraw();
// Check if the account.dat file exists.
std::string backupPath;
std::string backup_path;
FILE *account = fopen(ACCOUNT_FILE.c_str(), "rb");
if (account == NULL) {
WHBLogConsoleSetColor(0x99000000);
WHBLogPrintf("Error opening system account.dat file!");
WHBLogConsoleDraw();
handleCleanup(account, NULL, NULL, true);
handle_cleanup(account, NULL, NULL, true);
return;
} else {
@ -124,7 +126,7 @@ void backupAccount() {
WHBLogConsoleSetColor(0x99000000);
WHBLogPrint("Error allocating memory!");
WHBLogConsoleDraw();
handleCleanup(account, NULL, buffer, true);
handle_cleanup(account, NULL, buffer, true);
return;
} else {
@ -139,45 +141,45 @@ void backupAccount() {
WHBLogPrint("account.dat file read in memory.");
WHBLogConsoleDraw();
bool networkAccountFound = false;
bool network_account_found = false;
if (content.find("account.nintendo.net") != std::string::npos) {
backupPath = NNID_BACKUP;
backup_path = NNID_BACKUP;
WHBLogPrint("Nintendo Network ID detected.");
WHBLogConsoleDraw();
networkAccountFound = true;
network_account_found = true;
} else if (content.find("pretendo-cdn.b-cdn.net") != std::string::npos) {
backupPath = PNID_BACKUP;
backup_path = PNID_BACKUP;
WHBLogPrint("Pretendo Network ID detected.");
WHBLogConsoleDraw();
networkAccountFound = true;
network_account_found = true;
} else {
WHBLogConsoleSetColor(0x99000000);
WHBLogPrint("Network ID detection failed!");
WHBLogPrint("Is this user a local-only account?");
WHBLogConsoleDraw();
handleCleanup(account, NULL, buffer, true);
handle_cleanup(account, NULL, buffer, true);
}
if (networkAccountFound) {
if (network_account_found) {
// Check if the backup file exists.
WHBLogPrintf("Opening backup account.dat for writing.", backupPath.c_str());
WHBLogPrintf("Opening backup account.dat for writing.", backup_path.c_str());
WHBLogConsoleDraw();
std::ifstream ifile(backupPath);
std::ifstream ifile(backup_path);
if (ifile) {
VPADStatus input;
VPADReadError error;
backupConfirm = false;
backup_confirm = false;
while (WHBProcIsRunning()) {
printOverwriteMenu(backupPath.c_str());
print_overwrite_menu(backup_path.c_str());
VPADRead(VPAD_CHAN_0, &input, 1, &error);
if (input.trigger == VPAD_BUTTON_A) {
backupConfirm = true;
backup_confirm = true;
break;
} else if (input.trigger == VPAD_BUTTON_B) {
break;
@ -185,16 +187,16 @@ void backupAccount() {
}
} else {
backupConfirm = true;
backup_confirm = true;
}
}
}
// Write the backup file.
if (backupConfirm) {
writeBackup(account, backupPath, buffer);
if (backup_confirm) {
write_backup(account, backup_path, buffer);
}
// Handle cleanup
handleCleanup(account, NULL, buffer, !backupConfirm);
handle_cleanup(account, NULL, buffer, !backup_confirm);
}
}

View File

@ -31,22 +31,22 @@ int main() {
VPADReadError error;
// Print the main menu to the screen.
printMainMenu();
print_main_menu();
while (WHBProcIsRunning()) {
printMainMenu();
print_main_menu();
// Watch the Wii U GamePad for button presses.
VPADRead(VPAD_CHAN_0, &input, 1, &error);
// If the A button is pressed, switch to the Nintendo Network ID account.dat.
if (input.trigger & VPAD_BUTTON_A) {
switchAccount(NNID_BACKUP.c_str(), "Nintendo Network ID");
switch_account(NNID_BACKUP.c_str(), "Nintendo Network ID");
}
// If the B button is pressed, switch to the Pretendo Network ID account.dat.
else if (input.trigger & VPAD_BUTTON_B) {
switchAccount(PNID_BACKUP.c_str(), "Pretendo Network ID");
switch_account(PNID_BACKUP.c_str(), "Pretendo Network ID");
}
// If the + button is pressed, backup the current account.dat.
@ -54,19 +54,19 @@ int main() {
while (WHBProcIsRunning()) {
// Disable the HOME Button temporarily.
OSEnableHomeButtonMenu(0);
printBackupMenu();
print_backup_menu();
VPADRead(VPAD_CHAN_0, &input, 1, &error);
if (input.trigger & VPAD_BUTTON_A) {
backupAccount();
backup_account();
break;
}
else if (input.trigger & VPAD_BUTTON_B) {
// Re-enable the HOME Button.
OSEnableHomeButtonMenu(1);
printMainMenu();
print_main_menu();
break;
}
}
@ -77,19 +77,19 @@ int main() {
while (WHBProcIsRunning()) {
// Disable the HOME Button temporarily.
OSEnableHomeButtonMenu(0);
printUnlinkMenu();
print_unlink_menu();
VPADRead(VPAD_CHAN_0, &input, 1, &error);
if (input.trigger & VPAD_BUTTON_A) {
unlinkAccount();
unlink_account();
break;
}
else if (input.trigger & VPAD_BUTTON_B) {
// Re-enable the HOME Button.
OSEnableHomeButtonMenu(1);
printMainMenu();
print_main_menu();
break;
}
}

View File

@ -11,7 +11,7 @@
#include "../include/utils.hpp"
void printMainMenu() {
void print_main_menu() {
OSScreenClearBufferEx(SCREEN_TV, 0x4A198500);
OSScreenClearBufferEx(SCREEN_DRC, 0x4A198500);
@ -24,89 +24,92 @@ void printMainMenu() {
}
versionLine << "Nightkingale";
printOnScreen(0, versionLine.str().c_str());
printOnScreen(1, "---------------------------------------------------------");
print_on_screen(0, versionLine.str().c_str());
print_on_screen(1, "---------------------------------------------------------");
printOnScreen(3, "Press (A) to switch to Nintendo Network ID.");
printOnScreen(4, "Press (B) to switch to Pretendo Network ID.");
printOnScreen(5, "Press (+) to backup your current account.");
printOnScreen(6, "Press (-) to unlink your account locally.");
print_on_screen(3, "Press (A) to switch to Nintendo Network ID.");
print_on_screen(4, "Press (B) to switch to Pretendo Network ID.");
print_on_screen(5, "Press (+) to backup your current account.");
print_on_screen(6, "Press (-) to unlink your account locally.");
printOnScreen(8, "Press (HOME) to exit.");
print_on_screen(8, "Press (HOME) to exit.");
printOnScreen(14, "---------------------------------------------------------");
printOnScreen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
printOnScreen(16, "%s", ACCOUNT_FILE.c_str());
print_on_screen(14, "---------------------------------------------------------");
print_on_screen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
print_on_screen(16, "%s", ACCOUNT_FILE.c_str());
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
}
void printUnlinkMenu() {
void print_unlink_menu() {
OSScreenClearBufferEx(SCREEN_TV, 0x4A198500);
OSScreenClearBufferEx(SCREEN_DRC, 0x4A198500);
printOnScreen(0, "Unlinking: Please read the following and confirm!");
printOnScreen(1, "---------------------------------------------------------");
print_on_screen(0, "Unlinking: Please read the following and confirm!");
print_on_screen(1, "---------------------------------------------------------");
printOnScreen(3, "This will unlink your Network ID from this user.");
printOnScreen(4, "You can reattach this account to any user on this Wii U,");
printOnScreen(5, "or attach a new account to this user.");
print_on_screen(3, "This will unlink your Network ID from this user.");
print_on_screen(4, "You can reattach this account to any user on this Wii U,");
print_on_screen(5, "or attach a new account to this user.");
printOnScreen(7, "However, this unlink will not take place on the server.");
printOnScreen(8, "You won't be able to use this account on any other Wii U.");
print_on_screen(7, "However, this unlink will not take place on the server.");
print_on_screen(8, "You won't be able to use this account on any other Wii U.");
printOnScreen(10, "Press (A) to confirm the unlink or (B) to cancel.");
print_on_screen(10, "Press (A) to confirm the unlink or (B) to cancel.");
printOnScreen(14, "---------------------------------------------------------");
printOnScreen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
printOnScreen(16, "%s", ACCOUNT_FILE.c_str());
print_on_screen(14, "---------------------------------------------------------");
print_on_screen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
print_on_screen(16, "%s", ACCOUNT_FILE.c_str());
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
}
void printBackupMenu() {
void print_backup_menu() {
OSScreenClearBufferEx(SCREEN_TV, 0x4A198500);
OSScreenClearBufferEx(SCREEN_DRC, 0x4A198500);
printOnScreen(0, "Backup: Please read the following and confirm!");
printOnScreen(1, "---------------------------------------------------------");
print_on_screen(0, "Backup: Please read the following and confirm!");
print_on_screen(1, "---------------------------------------------------------");
printOnScreen(3, "This will backup your current account.dat file.");
print_on_screen(3, "This will backup your current account.dat file.");
printOnScreen(5, "The account.dat may contain sensitive personal");
printOnScreen(6, "information, such as your e-mail address and encrypted");
printOnScreen(7, "cached password (if you have chosen to save it).");
print_on_screen(5, "The account.dat may contain sensitive personal");
print_on_screen(6, "information, such as your e-mail address and encrypted");
print_on_screen(7, "cached password (if you have chosen to save it).");
printOnScreen(9, "Please do not share these backups with anyone else!");
print_on_screen(9, "Please do not share these backups with anyone else!");
printOnScreen(11, "Press (A) to confirm the backup or (B) to cancel.");
print_on_screen(11, "Press (A) to confirm the backup or (B) to cancel.");
printOnScreen(14, "---------------------------------------------------------");
printOnScreen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
printOnScreen(16, "%s", ACCOUNT_FILE.c_str());
print_on_screen(14, "---------------------------------------------------------");
print_on_screen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
print_on_screen(16, "%s", ACCOUNT_FILE.c_str());
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
}
void printOverwriteMenu(const char* backupPath) {
void print_overwrite_menu(const char* backup_path) {
OSScreenClearBufferEx(SCREEN_TV, 0x4A198500);
OSScreenClearBufferEx(SCREEN_DRC, 0x4A198500);
printOnScreen(0, "Backup: A backup file already exists!");
printOnScreen(1, "---------------------------------------------------------");
print_on_screen(0, "Backup: A backup file already exists!");
print_on_screen(1, "---------------------------------------------------------");
printOnScreen(3, "The backup file already exists!");
printOnScreen(4, "%s", backupPath);
printOnScreen(5, "Would you like to overwrite it?");
print_on_screen(3, "The backup file already exists!");
print_on_screen(4, "%s", backup_path);
print_on_screen(5, "Would you like to overwrite it?");
printOnScreen(7, "Press (A) to overwrite the backup or (B) to cancel.");
print_on_screen(7, "Press (A) to overwrite the backup or (B) to cancel.");
printOnScreen(14, "---------------------------------------------------------");
printOnScreen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
printOnScreen(16, "%s", ACCOUNT_FILE.c_str());
print_on_screen(14, "---------------------------------------------------------");
print_on_screen(15, "Current User: %s (%x)", MII_NICKNAME.c_str(), USER_ID);
print_on_screen(16, "%s", ACCOUNT_FILE.c_str());
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);

View File

@ -17,7 +17,7 @@
#include "../include/utils.hpp"
void handleCleanup(FILE* backup, char* buffer, bool isError = false) {
void handle_cleanup(FILE* backup, char* buffer, bool is_error = false) {
// Wait 5 seconds.
OSSleepTicks(OSMillisecondsToTicks(5000));
@ -37,14 +37,15 @@ void handleCleanup(FILE* backup, char* buffer, bool isError = false) {
}
// If there was an error, return to the menu.
if (isError) {
if (is_error) {
// Print the main menu.
WHBLogPrint("---------------------------------------------------------");
printMainMenu();
print_main_menu();
}
}
void switchAccount(const char* backupFile, const char* accountType) {
void switch_account(const char* backupFile, const char* accountType) {
// Disable the HOME Button temporarily.
OSEnableHomeButtonMenu(0);
@ -64,7 +65,7 @@ void switchAccount(const char* backupFile, const char* accountType) {
WHBLogPrintf("Error opening %s account backup!", accountType);
WHBLogPrint("Have you made a backup of this account yet?");
WHBLogConsoleDraw();
handleCleanup(backup, NULL, true);
handle_cleanup(backup, NULL, true);
return;
}
else {
@ -77,7 +78,7 @@ void switchAccount(const char* backupFile, const char* accountType) {
WHBLogConsoleSetColor(0x99000000);
WHBLogPrint("Error allocating memory!");
WHBLogConsoleDraw();
handleCleanup(backup, buffer, true);
handle_cleanup(backup, buffer, true);
return;
} else {
@ -89,7 +90,7 @@ void switchAccount(const char* backupFile, const char* accountType) {
WHBLogConsoleSetColor(0x99000000);
WHBLogPrint("Error opening system account.dat file!");
WHBLogConsoleDraw();
handleCleanup(backup, buffer, true);
handle_cleanup(backup, buffer, true);
return;
} else {
@ -135,7 +136,7 @@ void switchAccount(const char* backupFile, const char* accountType) {
}
}
// Clean-up and exit.
handleCleanup(backup, buffer, false);
handle_cleanup(backup, buffer, false);
deinitialize();
OSForceFullRelaunch();

View File

@ -20,9 +20,10 @@
#include "../include/main.hpp"
#include "../include/utils.hpp"
void unlinkAccount() {
void unlink_account() {
// The default values to apply to the account.dat file.
std::map<std::string, std::string> defaultValues = {
std::map<std::string, std::string> default_values = {
{"IsMiiUpdated", "1"},
{"AccountId", ""},
{"BirthYear", "0"},
@ -67,33 +68,33 @@ void unlinkAccount() {
WHBLogConsoleDraw();
// Read the entire file into a string.
std::ifstream accountInput(ACCOUNT_FILE);
std::string fileContents((std::istreambuf_iterator<char>(accountInput)), std::istreambuf_iterator<char>());
accountInput.close();
std::ifstream account_input(ACCOUNT_FILE);
std::string file_contents((std::istreambuf_iterator<char>(account_input)), std::istreambuf_iterator<char>());
account_input.close();
WHBLogPrint("System account.dat file read in memory.");
WHBLogConsoleDraw();
// Process each line in the string.
std::istringstream fileContentStream(fileContents);
std::istringstream file_contentstream(file_contents);
std::string line;
while (std::getline(fileContentStream, line)) {
while (std::getline(file_contentstream, line)) {
size_t pos = line.find('=');
if (pos != std::string::npos) {
std::string key = line.substr(0, pos);
if (defaultValues.count(key) > 0) {
line = key + "=" + defaultValues[key];
if (default_values.count(key) > 0) {
line = key + "=" + default_values[key];
}
}
fileContents += line + "\n";
file_contents += line + "\n";
}
WHBLogPrint("Account file in memory patched.");
WHBLogConsoleDraw();
// Write the string back to the file.
std::ofstream accountOutput(ACCOUNT_FILE);
accountOutput << fileContents;
accountOutput.close();
std::ofstream account_output(ACCOUNT_FILE);
account_output << file_contents;
account_output.close();
WHBLogPrint("System account.dat file written.");
WHBLogConsoleDraw();

View File

@ -13,7 +13,8 @@
#include "../include/main.hpp"
void printOnScreen(int line, const char* format, ...) {
void print_on_screen(int line, const char* format, ...) {
char buffer[256];
va_list args;
@ -27,6 +28,7 @@ void printOnScreen(int line, const char* format, ...) {
OSScreenPutFontEx(SCREEN_DRC, 0, line, buffer);
}
void deinitialize() {
// This prevents hangs when called twice.
static bool isDeinitialized = false;
@ -40,6 +42,7 @@ void deinitialize() {
}
}
void initialize() {
OSScreenInit();
WHBProcInit();