diff --git a/src/main.cpp b/src/main.cpp index 4089dc9..2cfe38d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,6 @@ #include "patcher/function_patcher_gx2.h" #include "patcher/function_patcher_coreinit.h" #include "utils/sd_ip_reader.hpp" -#include "sd_cheats.h" bool isCodeHandlerInstalled; diff --git a/src/sd_cheats.cpp b/src/sd_cheats.cpp index 869dfd9..381c4bf 100644 --- a/src/sd_cheats.cpp +++ b/src/sd_cheats.cpp @@ -1,6 +1,5 @@ #include // snprintf #include // memcpy, memset -#include "sd_cheats.h" #include "utils/logger.h" #include "fs/sd_fat_devoptab.h" #include "fs/fs_utils.h" @@ -8,6 +7,9 @@ #include "tcp_gecko.h" #include "kernel/syscalls.h" +#define CODE_HANDLER_ENABLED_ADDRESS 0x10014CFC +#define CODE_LIST_START_ADDRESS 0x01133000 + #define EXTENSION_SIZE 6 #define SD_FILE_PATH_HEADER_LENGTH 10 #define TITLE_ID_LEADING_ZEROS 3 @@ -30,6 +32,12 @@ void kernelCopyData2(unsigned char *destinationBuffer, unsigned char *sourceBuff DCFlushRange(destinationBuffer, (u32) length); } +void setCodeHandlerEnabled(bool enabled) { + unsigned int *codeHandlerEnabled = (unsigned int *) CODE_HANDLER_ENABLED_ADDRESS; + *codeHandlerEnabled = (unsigned int) enabled; + log_printf("Code handler status: %i\n", enabled); +} + void considerApplyingSDCheats() { u64 currentTitleID = OSGetTitleID(); @@ -38,19 +46,23 @@ void considerApplyingSDCheats() { } else { log_print("Title ID changed\n"); cachedTitleID = currentTitleID; + log_print("Mounting...\n"); int result = mount_sd_fat("sd"); if (result < 0) { log_printf("Mounting error: %i\n", result); return; + } else { + log_print("Mounted!\n"); } + // Construct the file path unsigned char filePath[CODES_FILE_PATH_SIZE]; memset(filePath, '0', sizeof(filePath)); memcpy(filePath, "sd:/codes/", SD_FILE_PATH_HEADER_LENGTH); // File path header - log_printf("Title ID: %lu\n", currentTitleID); char asciiTitleID[TITLE_ID_LENGTH]; snprintf(asciiTitleID, TITLE_ID_LENGTH, "%llX", currentTitleID); + log_printf("Title ID: %s\n", asciiTitleID); memcpy(filePath + SD_FILE_PATH_HEADER_LENGTH + TITLE_ID_LEADING_ZEROS, asciiTitleID, TITLE_ID_LENGTH); // Title ID memcpy(filePath + SD_FILE_PATH_HEADER_LENGTH + TITLE_ID_LENGTH, ".gctu", EXTENSION_SIZE); // Extension @@ -62,21 +74,26 @@ void considerApplyingSDCheats() { result = LoadFileToMem((const char *) filePath, &codes, &codesSize); if (result < 0) { - log_printf("Reading error: %i\n", result); + log_printf("LoadFileToMem() error: %i\n", result); + setCodeHandlerEnabled(false); // Error, we won't write any codes goto CLEANUP; } log_print("Copying...\n"); - kernelCopyData2((unsigned char *) 0x01133000, codes, codesSize); + kernelCopyData2((unsigned char *) CODE_LIST_START_ADDRESS, codes, codesSize); log_print("Copied!\n"); + setCodeHandlerEnabled(true); CLEANUP: + log_print("Unmounting...\n"); result = unmount_sd_fat("sd"); if (result < 0) { log_printf("Unmounting error: %i\n", result); + } else { + log_print("Unmouted!\n"); } } } \ No newline at end of file diff --git a/src/tcp_gecko.cpp b/src/tcp_gecko.cpp index 15b2419..e63ae45 100644 --- a/src/tcp_gecko.cpp +++ b/src/tcp_gecko.cpp @@ -1513,6 +1513,7 @@ static int startTCPGeckoThread(int argc, void *argv) { // considerApplyingSDCheats(); // log_print("Running code handler...\n"); codeHandlerFunction(); + // log_print("Code handler done executing...\n"); if (assemblySize > 0) { executeAssembly(); diff --git a/tcpgecko.elf b/tcpgecko.elf index d1d6e70..6a79b43 100644 Binary files a/tcpgecko.elf and b/tcpgecko.elf differ