diff --git a/Makefile b/Makefile index 9c052c6..ec23c49 100644 --- a/Makefile +++ b/Makefile @@ -35,16 +35,21 @@ INCLUDES := source #------------------------------------------------------------------------------- # options for code generation #------------------------------------------------------------------------------- -CFLAGS := -g -Wall -O3 -ffunction-sections -fno-exceptions -fno-rtti\ +CFLAGS := -Wall -O2 -ffunction-sections\ $(MACHDEP) CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -CXXFLAGS := $(CFLAGS) -std=c++20 +CXXFLAGS := $(CFLAGS) -std=c++20 -fno-exceptions -fno-rtti ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libfunctionpatcher.ld -T$(WUMS_ROOT)/share/libmappedmemory.ld $(WUMSSPECS) +ifeq ($(DEBUG),1) +CXXFLAGS += -DDEBUG -g +CCFLAGS += -DDEBUG -g +endif + LIBS := -lwums -lwut -lwups -lfunctionpatcher -lmappedmemory -lfreetype -lbz2 -lpng -lz #------------------------------------------------------------------------------- diff --git a/source/main.cpp b/source/main.cpp index 0313200..037b8c6 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,6 +1,3 @@ -#include -#include -#include #include #include #include @@ -21,10 +18,7 @@ WUMS_MODULE_EXPORT_NAME("homebrew_wupsbackend"); WUMS_USE_WUT_DEVOPTAB(); WUMS_INITIALIZE(args) { - if (!WHBLogModuleInit()) { - WHBLogCafeInit(); - WHBLogUdpInit(); - } + initLogging(); gModuleData = args.module_information; if (gModuleData == nullptr) { @@ -33,11 +27,13 @@ WUMS_INITIALIZE(args) { if (gModuleData->version != MODULE_INFORMATION_VERSION) { OSFatal("WUPS-Backend: The module information struct version does not match."); } - WHBLogPrintf("Init successful"); + DEBUG_FUNCTION_LINE("Init successful"); + deinitLogging(); } WUMS_APPLICATION_REQUESTS_EXIT() { CallHook(gPluginInformation, WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT); + deinitLogging(); } WUMS_APPLICATION_ENDS() { @@ -57,15 +53,13 @@ WUMS_APPLICATION_ENDS() { void *allocOnCustomHeap(int alignment, int size); + WUMS_APPLICATION_STARTS() { - if (!WHBLogModuleInit()) { - WHBLogCafeInit(); - WHBLogUdpInit(); - } uint32_t upid = OSGetUPID(); if (upid != 2 && upid != 15) { return; } + initLogging(); bool initNeeded = false; if (gPluginDataHeap == nullptr) { DCFlushRange((void *) gModuleData, sizeof(module_information_t)); @@ -125,16 +119,19 @@ WUMS_APPLICATION_STARTS() { std::vector> pluginList = PluginDataFactory::loadDir("fs:/vol/external01/wiiu/plugins/", gPluginDataHeap); DEBUG_FUNCTION_LINE("Loaded data for %d plugins.", pluginList.size()); - auto plugins = PluginManagement::loadPlugins(pluginList, gPluginDataHeap, gTrampolineData, gTrampolineDataSize); + auto plugins = PluginManagement::loadPlugins(pluginList, gPluginDataHeap, gTrampolineData, gTrampolineDataSize); for (auto &pluginContainer: plugins) { +#ifdef DEBUG for (const auto &kv: pluginContainer->getPluginInformation()->getSectionInfoList()) { DEBUG_FUNCTION_LINE_VERBOSE("%s = %s %08X %d", kv.first.c_str(), kv.second->getName().c_str(), kv.second->getAddress(), kv.second->getSize()); } +#endif if (!PluginContainerPersistence::savePlugin(gPluginInformation, pluginContainer, gPluginDataHeap)) { DEBUG_FUNCTION_LINE("Failed to save plugin"); } } + initNeeded = true; } } diff --git a/source/utils/logger.c b/source/utils/logger.c new file mode 100644 index 0000000..4862f1d --- /dev/null +++ b/source/utils/logger.c @@ -0,0 +1,37 @@ +#ifdef DEBUG +#include +#include +#include +#include + + +uint32_t moduleLogInit = false; +uint32_t cafeLogInit = false; +uint32_t udpLogInit = false; +#endif // DEBUG + +void initLogging() { +#ifdef DEBUG + if (!(moduleLogInit = WHBLogModuleInit())) { + cafeLogInit = WHBLogCafeInit(); + udpLogInit = WHBLogUdpInit(); + } +#endif // DEBUG +} + +void deinitLogging() { +#ifdef DEBUG + if (moduleLogInit) { + WHBLogMffoduleDeinit(); + moduleLogInit = false; + } + if (cafeLogInit) { + WHBLogCafeDeinit(); + cafeLogInit = false; + } + if (udpLogInit) { + WHBLogUdpDeinit(); + udpLogInit = false; + } +#endif // DEBUG +} \ No newline at end of file diff --git a/source/utils/logger.h b/source/utils/logger.h index 03824ef..6ff5ae2 100644 --- a/source/utils/logger.h +++ b/source/utils/logger.h @@ -1,15 +1,18 @@ #pragma once + +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include +#ifdef DEBUG #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) -#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while(0) +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ @@ -19,6 +22,21 @@ extern "C" { WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ } while (0) +#else + +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) + +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) + +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) + +#endif + +void initLogging(); + +void deinitLogging(); + #ifdef __cplusplus } -#endif \ No newline at end of file +#endif +