diff --git a/Dockerfile b/Dockerfile index e89c2a7..7d3a364 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM wiiuenv/devkitppc:20220917 +FROM wiiuenv/devkitppc:20221228 -COPY --from=wiiuenv/libfunctionpatcher:20220904 /artifacts $DEVKITPRO -COPY --from=wiiuenv/wiiumodulesystem:20221005 /artifacts $DEVKITPRO +COPY --from=wiiuenv/libfunctionpatcher:20230106 /artifacts $DEVKITPRO +COPY --from=wiiuenv/wiiumodulesystem:20230106 /artifacts $DEVKITPRO WORKDIR project diff --git a/Makefile b/Makefile index 3b6c1bd..f6d8b5b 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ CXXFLAGS := $(CFLAGS) -std=c++20 ASFLAGS := -g $(ARCH) -LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libfunctionpatcher.ld $(WUMSSPECS) +LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -Tfunctionpatcher.ld $(WUMSSPECS) ifeq ($(DEBUG),1) CXXFLAGS += -DDEBUG -g @@ -79,6 +79,7 @@ export DEPSDIR := $(CURDIR)/$(BUILD) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +DEFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.def))) BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) #------------------------------------------------------------------------------- @@ -96,7 +97,7 @@ endif #------------------------------------------------------------------------------- export OFILES_BIN := $(addsuffix .o,$(BINFILES)) -export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES_SRC := $(DEFFILES:.def=.o) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) export OFILES := $(OFILES_BIN) $(OFILES_SRC) export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) @@ -145,6 +146,11 @@ $(OFILES_SRC) : $(HFILES_BIN) #------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) +#--------------------------------------------------------------------------------- +%.o: %.def + $(SILENTMSG) $(notdir $<) + $(SILENTCMD)rplimportgen $< $*.s $*.ld $(ERROR_FILTER) + $(SILENTCMD)$(CC) -x assembler-with-cpp $(ASFLAGS) -c $*.s -o $@ $(ERROR_FILTER) -include $(DEPENDS) diff --git a/source/applicationendshook/applicationendhook.cpp b/source/applicationendshook/applicationendhook.cpp index 8c9bf4c..1b0bd1c 100644 --- a/source/applicationendshook/applicationendhook.cpp +++ b/source/applicationendshook/applicationendhook.cpp @@ -6,7 +6,8 @@ void initApplicationEndsHook() { DEBUG_FUNCTION_LINE("Patch ApplicationEndsHook functions"); for (uint32_t i = 0; i < applicationendshook_function_replacements_size; i++) { - if (!FunctionPatcherPatchFunction(&applicationendshook_function_replacements[i], nullptr)) { + bool wasPatched = false; + if (FunctionPatcher_AddFunctionPatch(&applicationendshook_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) { OSFatal("AromaBaseModule: Failed to patch ApplicationEndsHook function"); } } diff --git a/source/dynload/dynload.cpp b/source/dynload/dynload.cpp index 0d3a2ed..f5b80a3 100644 --- a/source/dynload/dynload.cpp +++ b/source/dynload/dynload.cpp @@ -4,6 +4,8 @@ #include "logger.h" #include +extern "C" FunctionPatcherStatus FPAddFunctionPatch(function_replacement_data_t *function_data, PatchedFunctionHandle *outHandle, bool *outHasBeenPatched); + void initDynload() { gLoadedRPLData = (LOADED_RPL *) malloc(sizeof(LOADED_RPL) * gModuleData->number_modules); if (!gLoadedRPLData) { @@ -18,7 +20,9 @@ void initDynload() { DEBUG_FUNCTION_LINE("Patch functions for dynload patches"); for (uint32_t i = 0; i < dynload_function_replacements_size; i++) { - if (!FunctionPatcherPatchFunction(&dynload_function_replacements[i], nullptr)) { + bool wasPatched = false; + // We need to use FPAddFunctionPatch because we can't use libfunctionpatcher yet. This patch enables it though. + if (FPAddFunctionPatch(&dynload_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) { OSFatal("AromaBaseModule: Failed to patch function for dynload patches"); } } diff --git a/source/functionpatcher.def b/source/functionpatcher.def new file mode 100644 index 0000000..0c87cbc --- /dev/null +++ b/source/functionpatcher.def @@ -0,0 +1,4 @@ +:NAME homebrew_functionpatcher + +:TEXT +FPAddFunctionPatch \ No newline at end of file diff --git a/source/globals.h b/source/globals.h index 79e833d..562ef56 100644 --- a/source/globals.h +++ b/source/globals.h @@ -1,4 +1,5 @@ #include "dynload/loader_defines.h" +#include #include extern module_information_t *gModuleData; diff --git a/source/main.cpp b/source/main.cpp index b3d1197..98ae07e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -6,10 +6,12 @@ #include "sdrefcount/refcount.h" #include "symbolnamepatcher/symbolname.h" #include "version.h" +#include #include WUMS_MODULE_EXPORT_NAME("homebrew_basemodule"); WUMS_MODULE_SKIP_INIT_FINI(); +WUMS_DEPENDS_ON(homebrew_functionpatcher); #define VERSION "v0.2.0" @@ -23,10 +25,18 @@ WUMS_INITIALIZE(args) { OSFatal("AromaBaseModule: The module information struct version does not match."); } + // First init Dynload to have proper OSDynLoad support! + initDynload(); + + // Now init the library so we can use it for the other patches. + if (FunctionPatcher_InitLibrary() != FUNCTION_PATCHER_RESULT_SUCCESS) { + OSFatal("homebrew_basemodule: FunctionPatcher_InitLibrary failed"); + } + initApplicationEndsHook(); initSDRefCount(); initSymbolNamePatcher(); - initDynload(); + initCommonPatches(); deinitLogging(); diff --git a/source/patches/patches.cpp b/source/patches/patches.cpp index 384d762..68c0cfd 100644 --- a/source/patches/patches.cpp +++ b/source/patches/patches.cpp @@ -21,7 +21,8 @@ void initCommonPatches() { DEBUG_FUNCTION_LINE("Do common patches"); for (uint32_t i = 0; i < patches_function_replacements_size; i++) { - if (!FunctionPatcherPatchFunction(&patches_function_replacements[i], nullptr)) { + bool wasPatched = false; + if (FunctionPatcher_AddFunctionPatch(&patches_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) { OSFatal("AromaBaseModule: Failed apply common patches"); } } diff --git a/source/sdrefcount/refcount.cpp b/source/sdrefcount/refcount.cpp index 1d0ae11..00a1725 100644 --- a/source/sdrefcount/refcount.cpp +++ b/source/sdrefcount/refcount.cpp @@ -21,7 +21,8 @@ void initSDRefCount() { DEBUG_FUNCTION_LINE("Patch SDRefCount functions"); for (uint32_t i = 0; i < sdrefcount_function_replacements_size; i++) { - if (!FunctionPatcherPatchFunction(&sdrefcount_function_replacements[i], nullptr)) { + bool wasPatched = false; + if (FunctionPatcher_AddFunctionPatch(&sdrefcount_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) { OSFatal("AromaBaseModule: Failed to patch function for sd ref counting"); } } diff --git a/source/symbolnamepatcher/symbolname.cpp b/source/symbolnamepatcher/symbolname.cpp index a1a9399..2993d4c 100644 --- a/source/symbolnamepatcher/symbolname.cpp +++ b/source/symbolnamepatcher/symbolname.cpp @@ -5,7 +5,8 @@ void initSymbolNamePatcher() { DEBUG_FUNCTION_LINE("Patch SymbolNamePatcher functions"); for (uint32_t i = 0; i < symbolname_function_replacements_size; i++) { - if (!FunctionPatcherPatchFunction(&symbolname_function_replacements[i], nullptr)) { + bool wasPatched = false; + if (FunctionPatcher_AddFunctionPatch(&symbolname_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) { OSFatal("AromaBaseModule: Failed to patch SymbolNamePatcher function"); } }