Skip to content

Commit

Permalink
Support WUPS 0.4, remove some unused code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Mar 16, 2021
1 parent 1491e22 commit f11649b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 294 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM wiiuenv/devkitppc:20210101

COPY --from=wiiuenv/wiiumodulesystem:20210219 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiupluginsystem:20210109 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiumodulesystem:20210313 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiupluginsystem:20210316 /artifacts $DEVKITPRO
COPY --from=wiiuenv/libfunctionpatcher:20210109 /artifacts $DEVKITPRO

WORKDIR project
33 changes: 11 additions & 22 deletions source/PluginManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,6 @@ void PluginManagement::memsetBSS(const std::vector<PluginContainer> &plugins) {
}
}

void PluginManagement::callDeinitHooks(plugin_information_t *pluginInformation) {
CallHook(pluginInformation, WUPS_LOADER_HOOK_RELEASE_FOREGROUND);
CallHook(pluginInformation, WUPS_LOADER_HOOK_APPLICATION_END);
CallHook(pluginInformation, WUPS_LOADER_HOOK_DEINIT_PLUGIN);

CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_STDCPP);
CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_NEWLIB);
CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_MALLOC);

DEBUG_FUNCTION_LINE_VERBOSE("Done calling deinit hooks");
}


void PluginManagement::RestorePatches(plugin_information_t *pluginInformation, BOOL pluginOnly) {
for (int32_t plugin_index = pluginInformation->number_used_plugins - 1; plugin_index >= 0; plugin_index--) {
FunctionPatcherRestoreFunctions(pluginInformation->plugin_data[plugin_index].info.functions, pluginInformation->plugin_data[plugin_index].info.number_used_functions);
Expand All @@ -112,6 +98,16 @@ void PluginManagement::RestorePatches(plugin_information_t *pluginInformation, B
}

void PluginManagement::unloadPlugins(plugin_information_t *gPluginInformation, MEMHeapHandle pluginHeap, BOOL freePluginData) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_MALLOC);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_NEWLIB);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_STDCPP);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_DEINIT_PLUGIN);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_STDCPP);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_NEWLIB);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_MALLOC);

RestorePatches(gPluginInformation, true);
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
plugin_information_single_t *plugin = &(gPluginInformation->plugin_data[plugin_index]);
Expand Down Expand Up @@ -155,13 +151,7 @@ void PluginManagement::unloadPlugins(plugin_information_t *gPluginInformation, M
}

void PluginManagement::callInitHooks(plugin_information_t *pluginInformation) {
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_VID_MEM);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_KERNEL);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_OVERLAY);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_PLUGIN);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_MALLOC);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_NEWLIB);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_STDCPP);
DEBUG_FUNCTION_LINE_VERBOSE("Done calling init hooks");
}

Expand All @@ -184,9 +174,8 @@ void PluginManagement::PatchFunctionsAndCallHooks(plugin_information_t *gPluginI
DCFlushRange((void *) 0x00800000, 0x00800000);
ICInvalidateRange((void *) 0x00800000, 0x00800000);

CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB);
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
CallHookEx(gPluginInformation, WUPS_LOADER_HOOK_APPLICATION_START, plugin_index);
CallHookEx(gPluginInformation, WUPS_LOADER_HOOK_APPLICATION_STARTS, plugin_index);
FunctionPatcherPatchFunction(gPluginInformation->plugin_data[plugin_index].info.functions, gPluginInformation->plugin_data[plugin_index].info.number_used_functions);
CallHookEx(gPluginInformation, WUPS_LOADER_HOOK_FUNCTIONS_PATCHED, plugin_index);
}
Expand Down
2 changes: 0 additions & 2 deletions source/PluginManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ class PluginManagement {
static std::vector<PluginContainer> loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle pHeader, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length);

static void RestorePatches(plugin_information_t *pluginInformation, BOOL pluginOnly);

static void callDeinitHooks(plugin_information_t *pluginInformation);
};
38 changes: 16 additions & 22 deletions source/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,24 @@ bool HasHookCallHook(plugin_information_t *pluginInformation, wups_loader_hook_t
}

static const char **hook_names = (const char *[]) {
"WUPS_LOADER_HOOK_INIT_OVERLAY",
"WUPS_LOADER_HOOK_INIT_KERNEL",
"WUPS_LOADER_HOOK_INIT_VID_MEM",
"WUPS_LOADER_HOOK_INIT_WUT_MALLOC",
"WUPS_LOADER_HOOK_FINI_WUT_MALLOC",
"WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB",
"WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB",
"WUPS_LOADER_HOOK_INIT_WUT_NEWLIB",
"WUPS_LOADER_HOOK_FINI_WUT_NEWLIB",
"WUPS_LOADER_HOOK_INIT_WUT_STDCPP",
"WUPS_LOADER_HOOK_FINI_WUT_STDCPP",
"WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB",
"WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB",

"WUPS_LOADER_HOOK_INIT_PLUGIN",
"WUPS_LOADER_HOOK_DEINIT_PLUGIN",
"WUPS_LOADER_HOOK_APPLICATION_START",
"WUPS_LOADER_HOOK_APPLICATION_STARTS",
"WUPS_LOADER_HOOK_FUNCTIONS_PATCHED",
"WUPS_LOADER_HOOK_RELEASE_FOREGROUND",
"WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND",
"WUPS_LOADER_HOOK_APPLICATION_END",
"WUPS_LOADER_HOOK_CONFIRM_RELEASE_FOREGROUND",
"WUPS_LOADER_HOOK_SAVES_DONE_READY_TO_RELEASE",
"WUPS_LOADER_HOOK_VSYNC",
"WUPS_LOADER_HOOK_GET_CONFIG",
"WUPS_LOADER_HOOK_VID_DRC_DRAW",
"WUPS_LOADER_HOOK_VID_TV_DRAW",
"WUPS_LOADER_HOOK_APPLET_START"};
"WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT",
"WUPS_LOADER_HOOK_APPLICATION_ENDS",
"WUPS_LOADER_HOOK_VSYNC"};

void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t hook_type, int32_t plugin_index_needed) {
if(hook_type != WUPS_LOADER_HOOK_VSYNC) {
Expand All @@ -71,21 +64,18 @@ void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_START) {
wups_loader_app_started_args_t args;
((void (*)(wups_loader_app_started_args_t)) ((uint32_t *) func_ptr))(args);
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_STARTS) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FUNCTIONS_PATCHED) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_END) {
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_ENDS) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_MALLOC) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_MALLOC) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_NEWLIB) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_NEWLIB) {
Expand All @@ -94,6 +84,10 @@ void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_STDCPP) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND) {
Expand Down
18 changes: 14 additions & 4 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ WUMS_INITIALIZE(args) {
WHBLogPrintf("Init successful");
}

WUMS_APPLICATION_REQUESTS_EXIT() {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT);
}

WUMS_APPLICATION_ENDS() {
DEBUG_FUNCTION_LINE("Reset alreadyPatched flags for dynamic functions");
CallHook(gPluginInformation, WUPS_LOADER_HOOK_APPLICATION_ENDS);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_STDCPP);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_NEWLIB);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_MALLOC);
auto pluginInformation = gPluginInformation;
for (int32_t plugin_index = pluginInformation->number_used_plugins - 1; plugin_index >= 0; plugin_index--) {
FunctionPatcherRestoreDynamicFunctions(pluginInformation->plugin_data[plugin_index].info.functions, pluginInformation->plugin_data[plugin_index].info.number_used_functions);
}
FunctionPatcherRestoreDynamicFunctions(method_hooks_hooks_static, method_hooks_size_hooks_static);
DEBUG_FUNCTION_LINE("Call hooks");
CallHook(gPluginInformation, WUPS_LOADER_HOOK_APPLICATION_END);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB);
}

WUMS_APPLICATION_STARTS() {
Expand Down Expand Up @@ -155,6 +160,11 @@ WUMS_APPLICATION_STARTS() {
DCFlushRange((void *) pluginDataHeap, gPluginDataHeapSize);
ICInvalidateRange((void *) pluginDataHeap, gPluginDataHeapSize);

CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_MALLOC);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_NEWLIB);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_STDCPP);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB);

if (initNeeded) {
PluginManagement::callInitHooks(gPluginInformation);
}
Expand Down
Loading

0 comments on commit f11649b

Please sign in to comment.