diff --git a/source/main.cpp b/source/main.cpp index dee5b87..2fb9b1f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,15 +2,13 @@ #include "globals.h" #include "hooks.h" #include "patcher/hooks_patcher_static.h" -#include "plugin/PluginContainer.h" #include "plugin/PluginContainerPersistence.h" #include "plugin/PluginDataFactory.h" #include "plugin/PluginDataPersistence.h" +#include "utils/utils.h" #include #include #include -#include -#include #include #include @@ -54,22 +52,6 @@ WUMS_APPLICATION_ENDS() { void *allocOnCustomHeap(int alignment, int size); -std::string getPluginPath() { - char environmentPath[0x100]; - memset(environmentPath, 0, sizeof(environmentPath)); - - auto handle = IOS_Open("/dev/mcp", IOS_OPEN_READ); - if (handle >= 0) { - int in = 0xF9; // IPC_CUSTOM_COPY_ENVIRONMENT_PATH - if (IOS_Ioctl(handle, 100, &in, sizeof(in), environmentPath, sizeof(environmentPath)) != IOS_ERROR_OK) { - return "fs:/vol/external01/wiiu/plugins"; - } - - IOS_Close(handle); - } - return std::string(environmentPath) + "/plugins"; -} - WUMS_APPLICATION_STARTS() { uint32_t upid = OSGetUPID(); if (upid != 2 && upid != 15) { diff --git a/source/utils/StorageUtils.cpp b/source/utils/StorageUtils.cpp index f6fb2e4..015190f 100644 --- a/source/utils/StorageUtils.cpp +++ b/source/utils/StorageUtils.cpp @@ -54,7 +54,7 @@ int StorageUtils::OpenStorage(const char *plugin_id, wups_storage_item_t *items) return WUPS_STORAGE_ERROR_INVALID_BACKEND_PARAMS; } - std::string filePath = std::string("fs:/vol/external01/wiiu/plugins/config/") + plugin_id + ".json"; + std::string filePath = getPluginPath() + "/config/" + plugin_id + ".json"; nlohmann::json j; CFile file(filePath, CFile::ReadOnly); @@ -113,7 +113,7 @@ int StorageUtils::CloseStorage(const char *plugin_id, wups_storage_item_t *items return WUPS_STORAGE_ERROR_INVALID_BACKEND_PARAMS; } - std::string folderPath = "fs:/vol/external01/wiiu/plugins/config/"; + std::string folderPath = getPluginPath() + "/config/"; std::string filePath = folderPath + plugin_id + ".json"; FSUtils::CreateSubfolder(folderPath.c_str()); @@ -133,5 +133,6 @@ int StorageUtils::CloseStorage(const char *plugin_id, wups_storage_item_t *items memcpy(data, jsonString.c_str(), writeSize); file.write(data, writeSize); file.close(); + return WUPS_STORAGE_ERROR_SUCCESS; } diff --git a/source/utils/utils.c b/source/utils/utils.cpp similarity index 62% rename from source/utils/utils.c rename to source/utils/utils.cpp index 5c4e503..409d3e6 100644 --- a/source/utils/utils.c +++ b/source/utils/utils.cpp @@ -1,11 +1,24 @@ #include "utils/logger.h" +#include +#include #include -#include -#include -#include -#include -#include -#include +#include + +std::string getPluginPath() { + char environmentPath[0x100]; + memset(environmentPath, 0, sizeof(environmentPath)); + + auto handle = IOS_Open("/dev/mcp", IOS_OPEN_READ); + if (handle >= 0) { + int in = 0xF9; // IPC_CUSTOM_COPY_ENVIRONMENT_PATH + if (IOS_Ioctl(handle, 100, &in, sizeof(in), environmentPath, sizeof(environmentPath)) != IOS_ERROR_OK) { + return "fs:/vol/external01/wiiu/plugins"; + } + + IOS_Close(handle); + } + return std::string(environmentPath) + "/plugins"; +} // https://gist.github.com/ccbrown/9722406 void dumpHex(const void *data, size_t size) { @@ -25,7 +38,7 @@ void dumpHex(const void *data, size_t size) { if ((i + 1) % 16 == 0) { WHBLogPrintf("| %s ", ascii); if (i + 1 < size) { - DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1, i + 1); + DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", ((uint32_t) data) + i + 1, i + 1); } } else if (i + 1 == size) { ascii[(i + 1) % 16] = '\0'; diff --git a/source/utils/utils.h b/source/utils/utils.h index 201b575..1fab308 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -1,7 +1,7 @@ -#ifndef __UTILS_H_ -#define __UTILS_H_ +#pragma once #include +#include #ifdef __cplusplus extern "C" { @@ -41,4 +41,4 @@ void dumpHex(const void *data, size_t size); } #endif -#endif // __UTILS_H_ +std::string getPluginPath(); \ No newline at end of file