2022-09-10 21:24:58 +02:00
|
|
|
#include "FSAReplacements.h"
|
|
|
|
#include "FSReplacements.h"
|
2022-04-14 22:41:41 +02:00
|
|
|
#include "FileUtils.h"
|
2022-09-10 21:24:58 +02:00
|
|
|
#include "utils/StringTools.h"
|
2022-04-14 22:41:41 +02:00
|
|
|
#include "utils/logger.h"
|
2022-09-19 13:15:39 +02:00
|
|
|
#include "version.h"
|
2022-04-14 22:41:41 +02:00
|
|
|
#include <wums.h>
|
|
|
|
|
|
|
|
WUMS_MODULE_EXPORT_NAME("homebrew_content_redirection");
|
|
|
|
WUMS_USE_WUT_DEVOPTAB();
|
2023-01-07 10:20:21 +01:00
|
|
|
WUMS_DEPENDS_ON(homebrew_functionpatcher);
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2023-01-10 18:10:14 +01:00
|
|
|
#define VERSION "v0.2.4"
|
2022-09-19 13:15:39 +02:00
|
|
|
|
2022-10-04 18:40:26 +02:00
|
|
|
DECL_FUNCTION(void, OSCancelThread, OSThread *thread) {
|
|
|
|
if (thread == gThreadData[0].thread || thread == gThreadData[1].thread || thread == gThreadData[2].thread) {
|
|
|
|
DEBUG_FUNCTION_LINE_INFO("Prevent calling OSCancelThread for ContentRedirection IO Threads");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
real_OSCancelThread(thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
function_replacement_data_t OSCancelThreadReplacement = REPLACE_FUNCTION(OSCancelThread, LIBRARY_COREINIT, OSCancelThread);
|
|
|
|
|
2022-04-14 22:41:41 +02:00
|
|
|
WUMS_INITIALIZE() {
|
|
|
|
initLogging();
|
|
|
|
DEBUG_FUNCTION_LINE("Patch functions");
|
2023-01-07 10:27:11 +01:00
|
|
|
if (FunctionPatcher_InitLibrary() != FUNCTION_PATCHER_RESULT_SUCCESS) {
|
|
|
|
OSFatal("homebrew_content_redirection: FunctionPatcher_InitLibrary failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasPatched;
|
2022-05-08 19:37:46 +02:00
|
|
|
for (uint32_t i = 0; i < fs_file_function_replacements_size; i++) {
|
2023-01-07 10:27:11 +01:00
|
|
|
wasPatched = false;
|
|
|
|
if (FunctionPatcher_AddFunctionPatch(&fs_file_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
|
2022-05-08 19:37:46 +02:00
|
|
|
OSFatal("homebrew_content_redirection: Failed to patch function");
|
|
|
|
}
|
|
|
|
}
|
2022-08-09 00:28:29 +02:00
|
|
|
for (uint32_t i = 0; i < fsa_file_function_replacements_size; i++) {
|
2023-01-07 10:27:11 +01:00
|
|
|
wasPatched = false;
|
|
|
|
if (FunctionPatcher_AddFunctionPatch(&fsa_file_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
|
2022-08-09 00:28:29 +02:00
|
|
|
OSFatal("homebrew_content_redirection: Failed to patch function");
|
|
|
|
}
|
|
|
|
}
|
2023-01-07 10:27:11 +01:00
|
|
|
wasPatched = false;
|
|
|
|
if (FunctionPatcher_AddFunctionPatch(&OSCancelThreadReplacement, nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
|
2022-10-04 18:40:26 +02:00
|
|
|
OSFatal("homebrew_content_redirection: Failed to patch OSCancelThreadReplacement");
|
|
|
|
}
|
2022-04-14 22:41:41 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Patch functions finished");
|
|
|
|
deinitLogging();
|
|
|
|
}
|
|
|
|
|
|
|
|
WUMS_APPLICATION_STARTS() {
|
2022-09-19 13:15:39 +02:00
|
|
|
OSReport("Running ContentRedirectionModule " VERSION VERSION_EXTRA "\n");
|
2022-04-14 22:41:41 +02:00
|
|
|
initLogging();
|
2022-09-10 21:24:58 +02:00
|
|
|
startFSIOThreads();
|
2022-04-14 22:41:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WUMS_APPLICATION_ENDS() {
|
|
|
|
clearFSLayer();
|
2022-09-10 21:24:58 +02:00
|
|
|
|
|
|
|
stopFSIOThreads();
|
|
|
|
|
2022-04-14 22:41:41 +02:00
|
|
|
deinitLogging();
|
2022-10-11 15:09:47 +02:00
|
|
|
}
|