diff --git a/source/logger.c b/source/logger.c new file mode 100644 index 0000000..0411db7 --- /dev/null +++ b/source/logger.c @@ -0,0 +1,36 @@ +#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) { + WHBLogModuleDeinit(); + moduleLogInit = false; + } + if (cafeLogInit) { + WHBLogCafeDeinit(); + cafeLogInit = false; + } + if (udpLogInit) { + WHBLogUdpDeinit(); + udpLogInit = false; + } +#endif // DEBUG +} \ No newline at end of file diff --git a/source/logger.h b/source/logger.h index 94c763b..6ff5ae2 100644 --- a/source/logger.h +++ b/source/logger.h @@ -32,6 +32,10 @@ extern "C" { #endif +void initLogging(); + +void deinitLogging(); + #ifdef __cplusplus } #endif diff --git a/source/main.cpp b/source/main.cpp index 2b2da1a..f77d4d5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,46 +1,19 @@ #include -#ifdef DEBUG -#include -#include -#include -#endif // DEBUG +#include "logger.h" #include "function_patcher.h" WUMS_MODULE_EXPORT_NAME("homebrew_functionpatcher"); WUMS_MODULE_SKIP_INIT_FINI(); -#ifdef DEBUG -uint32_t moduleLogInit = false; -uint32_t cafeLogInit = false; -uint32_t udpLogInit = false; -#endif WUMS_APPLICATION_STARTS() { -#ifdef DEBUG - if (!(moduleLogInit = WHBLogModuleInit())) { - cafeLogInit = WHBLogCafeInit(); - udpLogInit = WHBLogUdpInit(); - } -#endif // DEBUG + initLogging(); FunctionPatcherResetLibHandles(); } WUMS_APPLICATION_REQUESTS_EXIT() { -#ifdef DEBUG - if (moduleLogInit) { - WHBLogModuleDeinit(); - moduleLogInit = false; - } - if (cafeLogInit) { - WHBLogCafeDeinit(); - cafeLogInit = false; - } - if (udpLogInit) { - WHBLogUdpDeinit(); - udpLogInit = false; - } -#endif // DEBUG + deinitLogging(); } WUMS_EXPORT_FUNCTION(FunctionPatcherPatchFunction);