Implement working SD card cheats (thanks Maschell)

This commit is contained in:
BullyWiiPlaza 2017-08-28 14:49:01 +02:00
parent caacafc25f
commit da0dc52a84
4 changed files with 22 additions and 5 deletions

View File

@ -20,7 +20,6 @@
#include "patcher/function_patcher_gx2.h" #include "patcher/function_patcher_gx2.h"
#include "patcher/function_patcher_coreinit.h" #include "patcher/function_patcher_coreinit.h"
#include "utils/sd_ip_reader.hpp" #include "utils/sd_ip_reader.hpp"
#include "sd_cheats.h"
bool isCodeHandlerInstalled; bool isCodeHandlerInstalled;

View File

@ -1,6 +1,5 @@
#include <stdio.h> // snprintf #include <stdio.h> // snprintf
#include <string.h> // memcpy, memset #include <string.h> // memcpy, memset
#include "sd_cheats.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "fs/sd_fat_devoptab.h" #include "fs/sd_fat_devoptab.h"
#include "fs/fs_utils.h" #include "fs/fs_utils.h"
@ -8,6 +7,9 @@
#include "tcp_gecko.h" #include "tcp_gecko.h"
#include "kernel/syscalls.h" #include "kernel/syscalls.h"
#define CODE_HANDLER_ENABLED_ADDRESS 0x10014CFC
#define CODE_LIST_START_ADDRESS 0x01133000
#define EXTENSION_SIZE 6 #define EXTENSION_SIZE 6
#define SD_FILE_PATH_HEADER_LENGTH 10 #define SD_FILE_PATH_HEADER_LENGTH 10
#define TITLE_ID_LEADING_ZEROS 3 #define TITLE_ID_LEADING_ZEROS 3
@ -30,6 +32,12 @@ void kernelCopyData2(unsigned char *destinationBuffer, unsigned char *sourceBuff
DCFlushRange(destinationBuffer, (u32) length); 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() { void considerApplyingSDCheats() {
u64 currentTitleID = OSGetTitleID(); u64 currentTitleID = OSGetTitleID();
@ -38,19 +46,23 @@ void considerApplyingSDCheats() {
} else { } else {
log_print("Title ID changed\n"); log_print("Title ID changed\n");
cachedTitleID = currentTitleID; cachedTitleID = currentTitleID;
log_print("Mounting...\n");
int result = mount_sd_fat("sd"); int result = mount_sd_fat("sd");
if (result < 0) { if (result < 0) {
log_printf("Mounting error: %i\n", result); log_printf("Mounting error: %i\n", result);
return; return;
} else {
log_print("Mounted!\n");
} }
// Construct the file path
unsigned char filePath[CODES_FILE_PATH_SIZE]; unsigned char filePath[CODES_FILE_PATH_SIZE];
memset(filePath, '0', sizeof(filePath)); memset(filePath, '0', sizeof(filePath));
memcpy(filePath, "sd:/codes/", SD_FILE_PATH_HEADER_LENGTH); // File path header memcpy(filePath, "sd:/codes/", SD_FILE_PATH_HEADER_LENGTH); // File path header
log_printf("Title ID: %lu\n", currentTitleID);
char asciiTitleID[TITLE_ID_LENGTH]; char asciiTitleID[TITLE_ID_LENGTH];
snprintf(asciiTitleID, TITLE_ID_LENGTH, "%llX", currentTitleID); 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, memcpy(filePath + SD_FILE_PATH_HEADER_LENGTH + TITLE_ID_LEADING_ZEROS, asciiTitleID,
TITLE_ID_LENGTH); // Title ID TITLE_ID_LENGTH); // Title ID
memcpy(filePath + SD_FILE_PATH_HEADER_LENGTH + TITLE_ID_LENGTH, ".gctu", EXTENSION_SIZE); // Extension 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); result = LoadFileToMem((const char *) filePath, &codes, &codesSize);
if (result < 0) { 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 // Error, we won't write any codes
goto CLEANUP; goto CLEANUP;
} }
log_print("Copying...\n"); log_print("Copying...\n");
kernelCopyData2((unsigned char *) 0x01133000, codes, codesSize); kernelCopyData2((unsigned char *) CODE_LIST_START_ADDRESS, codes, codesSize);
log_print("Copied!\n"); log_print("Copied!\n");
setCodeHandlerEnabled(true);
CLEANUP: CLEANUP:
log_print("Unmounting...\n");
result = unmount_sd_fat("sd"); result = unmount_sd_fat("sd");
if (result < 0) { if (result < 0) {
log_printf("Unmounting error: %i\n", result); log_printf("Unmounting error: %i\n", result);
} else {
log_print("Unmouted!\n");
} }
} }
} }

View File

@ -1513,6 +1513,7 @@ static int startTCPGeckoThread(int argc, void *argv) {
// considerApplyingSDCheats(); // considerApplyingSDCheats();
// log_print("Running code handler...\n"); // log_print("Running code handler...\n");
codeHandlerFunction(); codeHandlerFunction();
// log_print("Code handler done executing...\n");
if (assemblySize > 0) { if (assemblySize > 0) {
executeAssembly(); executeAssembly();

Binary file not shown.