Skip to content

Commit

Permalink
More cleaning and variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightkingale committed Apr 11, 2024
1 parent 51a98ca commit 9744cff
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TARGET := Wii_U_Account_Swap
BUILD := build
SOURCES := source
DATA := data
INCLUDES := source
INCLUDES := include

#-------------------------------------------------------------------------------
# options for code generation
Expand Down
13 changes: 13 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef GLOBAL_H
#define GLOBAL_H

extern const char* NNID_BACKUP;
extern const char* PNID_BACKUP;
extern const char* ACCOUNT_FILE;
extern const char* INKAY_CONFIG;
extern const int BUFFER_SIZE;

void deinitialize();
void initialize();

#endif // GLOBAL_H
7 changes: 3 additions & 4 deletions source/screens.h → include/screen.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// screens.h
#ifndef SCREENS_H
#define SCREENS_H
#ifndef SCREEN_H
#define SCREEN_H

void printOnScreen(int line, const char* format, ...);
void printMainMenu();
void printWarningScreen();

#endif // SCREENS_H
#endif // SCREEN_H
1 change: 0 additions & 1 deletion source/switch.h → include/switch.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// switch.h
#ifndef SWITCH_H
#define SWITCH_H

Expand Down
1 change: 0 additions & 1 deletion source/unlink.h → include/unlink.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// unlink.h
#ifndef UNLINK_H
#define UNLINK_H

Expand Down
12 changes: 0 additions & 12 deletions source/globals.h

This file was deleted.

20 changes: 11 additions & 9 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
#include <whb/log.h>
#include <whb/proc.h>

#include "globals.h"
#include "screens.h"
#include "switch.h"
#include "unlink.h"
#include "../include/global.h"
#include "../include/screen.h"
#include "../include/switch.h"
#include "../include/unlink.h"


const char* accountFile = "storage_mlc:/usr/save/system/act/8000000e/account.dat";
const char* inkayConfig = "/vol/external01/wiiu/environments/aroma/plugins/config/inkay.json";\
const char* NNID_BACKUP = "/vol/external01/accounts/nnid_account.dat";
const char* PNID_BACKUP = "/vol/external01/accounts/pnid_account.dat";
const char* ACCOUNT_FILE = "storage_mlc:/usr/save/system/act/8000000e/account.dat";
const char* INKAY_CONFIG = "/vol/external01/wiiu/environments/aroma/plugins/config/inkay.json";\
const int BUFFER_SIZE = 0x2000;

void deinitialize()
Expand Down Expand Up @@ -46,7 +48,7 @@ void initialize()
int main()
{
initialize();

VPADStatus input;
VPADReadError error;

Expand All @@ -59,12 +61,12 @@ int main()
// If the A button is pressed, switch to the Nintendo Network ID account.dat.
if (input.trigger & VPAD_BUTTON_A)
{
switchAccount("/vol/external01/accounts/nnid_account.dat", "Nintendo Network ID");
switchAccount(NNID_BACKUP, "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("/vol/external01/accounts/pnid_account.dat", "Pretendo Network ID");
switchAccount(PNID_BACKUP, "Pretendo Network ID");
}
// If the X button is pressed, unlink the account locally.
else if (input.trigger & VPAD_BUTTON_X)
Expand Down
11 changes: 7 additions & 4 deletions source/screens.cpp → source/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <coreinit/screen.h>
#include <coreinit/time.h>
#include <coreinit/thread.h>
#include <nn/act.h>


void printOnScreen(int line, const char* format, ...)
Expand All @@ -26,12 +27,14 @@ void printMainMenu()

printOnScreen(0, "Wii U Account Swap (v1.0.0)");
printOnScreen(1, "Created by Nightkingale");
printOnScreen(2, "-----------------------------------------------------------");
printOnScreen(2, "----------------------------------------------------------");
printOnScreen(3, "Press A to switch to Nintendo Network ID.");
printOnScreen(4, "Press B to switch to Pretendo Network ID.");
printOnScreen(5, "Press X to unlink your account locally.");
printOnScreen(6, "Press HOME to exit.");
printOnScreen(7, "-----------------------------------------------------------");
printOnScreen(7, "----------------------------------------------------------");
nn::act::Initialize(); // Initialize the Nintendo Account library


OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
Expand All @@ -44,11 +47,11 @@ void printWarningScreen()

printOnScreen(0, "Warning: This will unlink your account locally!");
printOnScreen(1, "This will not unlink your account from the server!");
printOnScreen(2, "-----------------------------------------------------------");
printOnScreen(2, "----------------------------------------------------------");
printOnScreen(3, "Your user can have a new account reattached!");
printOnScreen(4, "You will be able to login again on this Wii U as normal.");
printOnScreen(5, "However, you will NOT be able to login to another Wii U!");
printOnScreen(6, "-----------------------------------------------------------");
printOnScreen(6, "----------------------------------------------------------");
printOnScreen(7, "Press A to confirm the unlink or B to cancel.");

OSScreenFlipBuffersEx(SCREEN_TV);
Expand Down
8 changes: 4 additions & 4 deletions source/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include <whb/log.h>
#include <whb/proc.h>

#include "globals.h"
#include "../include/global.h"


void switchAccount(const char* backupFile, const char* accountType)
{
WHBLogPrintf("Switching to %s...", accountType);
WHBLogPrintf("Source: %s", backupFile);
WHBLogPrintf("%s", accountFile);
WHBLogPrintf("%s", ACCOUNT_FILE);
WHBLogPrint("----------------------------------------");
WHBLogConsoleDraw();

Expand Down Expand Up @@ -49,7 +49,7 @@ void switchAccount(const char* backupFile, const char* accountType)
WHBLogPrint("Memory was allocated successfully!");
WHBLogConsoleDraw();

FILE *account = fopen(accountFile, "wb");
FILE *account = fopen(ACCOUNT_FILE, "wb");
if (account == NULL)
{
WHBLogConsoleSetColor(0x99000000);
Expand All @@ -69,7 +69,7 @@ void switchAccount(const char* backupFile, const char* accountType)
WHBLogConsoleSetColor(0x00990000);
WHBLogPrint("System account.dat file was saved!");
// We'll attempt to automatically swap the network using Inkay's configuration.
FILE *inkay = fopen(inkayConfig, "wb");
FILE *inkay = fopen(INKAY_CONFIG, "wb");
if (inkay == NULL)
{
// If we can't open the file, we will move on.
Expand Down
8 changes: 4 additions & 4 deletions source/unlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <whb/log.h>
#include <whb/proc.h>

#include "globals.h"
#include "../include/global.h"


void unlinkAccount() {
Expand Down Expand Up @@ -60,12 +60,12 @@ void unlinkAccount() {
};

WHBLogPrintf("Unlinking: Default settings will be applied.");
WHBLogPrintf("%s", accountFile);
WHBLogPrintf("%s", ACCOUNT_FILE);
WHBLogPrint("----------------------------------------");
WHBLogConsoleDraw();

// Read the entire file into a string.
std::ifstream inFile(accountFile);
std::ifstream inFile(ACCOUNT_FILE);
std::string fileContents((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
inFile.close();
WHBLogPrint("System account.dat file is in memory!");
Expand All @@ -88,7 +88,7 @@ void unlinkAccount() {
WHBLogConsoleDraw();

// Write the string back to the file.
std::ofstream outFile(accountFile);
std::ofstream outFile(ACCOUNT_FILE);
outFile << fileContents;
outFile.close();
WHBLogPrint("System account.dat file was saved!");
Expand Down

0 comments on commit 9744cff

Please sign in to comment.