Refactor non-working SD cheats
This commit is contained in:
parent
738a750593
commit
caacafc25f
@ -20,6 +20,7 @@
|
||||
#include "patcher/function_patcher_gx2.h"
|
||||
#include "patcher/function_patcher_coreinit.h"
|
||||
#include "utils/sd_ip_reader.hpp"
|
||||
#include "sd_cheats.h"
|
||||
|
||||
bool isCodeHandlerInstalled;
|
||||
|
||||
|
82
src/sd_cheats.cpp
Normal file
82
src/sd_cheats.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include <stdio.h> // snprintf
|
||||
#include <string.h> // memcpy, memset
|
||||
#include "sd_cheats.h"
|
||||
#include "utils/logger.h"
|
||||
#include "fs/sd_fat_devoptab.h"
|
||||
#include "fs/fs_utils.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "tcp_gecko.h"
|
||||
#include "kernel/syscalls.h"
|
||||
|
||||
#define EXTENSION_SIZE 6
|
||||
#define SD_FILE_PATH_HEADER_LENGTH 10
|
||||
#define TITLE_ID_LEADING_ZEROS 3
|
||||
#define TITLE_ID_LENGTH 16
|
||||
#define CODES_FILE_PATH_SIZE (SD_FILE_PATH_HEADER_LENGTH + TITLE_ID_LENGTH + EXTENSION_SIZE)
|
||||
|
||||
u64 cachedTitleID;
|
||||
|
||||
unsigned char *kernelCopyBufferOld2[DATA_BUFFER_SIZE];
|
||||
|
||||
void kernelCopyData2(unsigned char *destinationBuffer, unsigned char *sourceBuffer, unsigned int length) {
|
||||
if (length > DATA_BUFFER_SIZE) {
|
||||
OSFatal("Kernel copy buffer size exceeded");
|
||||
}
|
||||
|
||||
memcpy(kernelCopyBufferOld2, sourceBuffer, length);
|
||||
SC0x25_KernelCopyData((unsigned int) OSEffectiveToPhysical(destinationBuffer),
|
||||
(unsigned int) &kernelCopyBufferOld2,
|
||||
length);
|
||||
DCFlushRange(destinationBuffer, (u32) length);
|
||||
}
|
||||
|
||||
void considerApplyingSDCheats() {
|
||||
u64 currentTitleID = OSGetTitleID();
|
||||
|
||||
if (cachedTitleID == currentTitleID) {
|
||||
// log_print("Title ID NOT changed\n");
|
||||
} else {
|
||||
log_print("Title ID changed\n");
|
||||
cachedTitleID = currentTitleID;
|
||||
int result = mount_sd_fat("sd");
|
||||
|
||||
if (result < 0) {
|
||||
log_printf("Mounting error: %i\n", result);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
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
|
||||
filePath[CODES_FILE_PATH_SIZE - 1] = '\0'; // Null-terminated
|
||||
log_printf("File Path: %s\n", filePath);
|
||||
|
||||
unsigned char *codes = NULL;
|
||||
unsigned int codesSize = 0;
|
||||
result = LoadFileToMem((const char *) filePath, &codes, &codesSize);
|
||||
|
||||
if (result < 0) {
|
||||
log_printf("Reading error: %i\n", result);
|
||||
// Error, we won't write any codes
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
log_print("Copying...\n");
|
||||
kernelCopyData2((unsigned char *) 0x01133000, codes, codesSize);
|
||||
log_print("Copied!\n");
|
||||
|
||||
CLEANUP:
|
||||
|
||||
result = unmount_sd_fat("sd");
|
||||
|
||||
if (result < 0) {
|
||||
log_printf("Unmounting error: %i\n", result);
|
||||
}
|
||||
}
|
||||
}
|
6
src/sd_cheats.h
Normal file
6
src/sd_cheats.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef TCPGECKO_SD_CHEATS_H
|
||||
#define TCPGECKO_SD_CHEATS_H
|
||||
|
||||
void considerApplyingSDCheats();
|
||||
|
||||
#endif
|
@ -6,8 +6,6 @@
|
||||
#include "../tcp_gecko.h"
|
||||
#include "../utils/logger.h"
|
||||
|
||||
unsigned char *kernelCopyBuffer[sizeof(int)];
|
||||
|
||||
// TODO Variable size, not hard-coded
|
||||
unsigned char *kernelCopyBufferOld[DATA_BUFFER_SIZE];
|
||||
|
||||
@ -22,6 +20,8 @@ void kernelCopyData(unsigned char *destinationBuffer, unsigned char *sourceBuffe
|
||||
DCFlushRange(destinationBuffer, (u32) length);
|
||||
}
|
||||
|
||||
unsigned char *kernelCopyBuffer[sizeof(int)];
|
||||
|
||||
void kernelCopyInt(unsigned char *destinationBuffer, unsigned char *sourceBuffer, unsigned int length) {
|
||||
memcpy(kernelCopyBuffer, sourceBuffer, length);
|
||||
unsigned int destinationAddress = (unsigned int) OSEffectiveToPhysical(destinationBuffer);
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
// #include <inttypes.h>
|
||||
#include "common/common.h"
|
||||
#include <zlib.h> // Actually must be included before os_functions
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
@ -22,8 +22,7 @@
|
||||
#include "utils/sd_ip_reader.hpp"
|
||||
#include "patcher/function_patcher_gx2.h"
|
||||
#include "system/raw_assembly_cheats.h"
|
||||
#include "fs/fs_utils.h"
|
||||
#include "fs/sd_fat_devoptab.h"
|
||||
#include "sd_cheats.h"
|
||||
|
||||
void *client;
|
||||
void *commandBlock;
|
||||
@ -1480,64 +1479,6 @@ static int runTCPGeckoServer(int argc, void *argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define EXTENSION_SIZE 6
|
||||
#define SD_FILE_PATH_HEADER_LENGTH 10
|
||||
#define TITLE_ID_LEADING_ZEROS 3
|
||||
#define TITLE_ID_LENGTH 16
|
||||
#define CODES_FILE_PATH_SIZE (SD_FILE_PATH_HEADER_LENGTH + TITLE_ID_LENGTH + EXTENSION_SIZE)
|
||||
|
||||
u64 cachedTitleID = 0;
|
||||
|
||||
void considerApplyingSDCheats() {
|
||||
u64 currentTitleID = OSGetTitleID();
|
||||
|
||||
if (cachedTitleID == currentTitleID) {
|
||||
// log_print("Title ID NOT changed\n");
|
||||
} else {
|
||||
log_print("Title ID changed\n");
|
||||
cachedTitleID = currentTitleID;
|
||||
int result = mount_sd_fat("sd");
|
||||
|
||||
if (result < 0) {
|
||||
log_printf("Mounting error: %i\n", result);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
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
|
||||
filePath[CODES_FILE_PATH_SIZE - 1] = '\0'; // Null-terminated
|
||||
log_printf("File Path: %s\n", filePath);
|
||||
|
||||
unsigned char *codes = NULL;
|
||||
unsigned int codesSize = 0;
|
||||
result = LoadFileToMem((const char *) filePath, &codes, &codesSize);
|
||||
|
||||
if (result < 0) {
|
||||
log_printf("Reading error: %i\n", result);
|
||||
// Error, we won't write any codes
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
||||
kernelCopyData((unsigned char *) 0x01133000, codes, codesSize);
|
||||
log_print("Copied!\n");
|
||||
|
||||
CLEANUP:
|
||||
|
||||
result = unmount_sd_fat("sd");
|
||||
|
||||
if (result < 0) {
|
||||
log_printf("Unmounting error: %i\n", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int startTCPGeckoThread(int argc, void *argv) {
|
||||
log_print("Starting TCP Gecko thread...\n");
|
||||
|
||||
@ -1562,13 +1503,14 @@ static int startTCPGeckoThread(int argc, void *argv) {
|
||||
|
||||
// Execute the code handler if it is installed
|
||||
if (isCodeHandlerInstalled) {
|
||||
considerApplyingSDCheats();
|
||||
log_print("Code handler installed...\n");
|
||||
void (*codeHandlerFunction)() = (void (*)()) CODE_HANDLER_INSTALL_ADDRESS;
|
||||
|
||||
while (true) {
|
||||
usleep(9000);
|
||||
|
||||
considerApplyingSDCheats();
|
||||
// considerApplyingSDCheats();
|
||||
// log_print("Running code handler...\n");
|
||||
codeHandlerFunction();
|
||||
|
||||
|
BIN
tcpgecko.elf
BIN
tcpgecko.elf
Binary file not shown.
Loading…
Reference in New Issue
Block a user