Formatting and cleanup

This commit is contained in:
Maschell 2021-09-25 14:26:18 +02:00
parent 13ed348f43
commit aa90e2478b
38 changed files with 367 additions and 395 deletions

View File

@ -7,7 +7,6 @@
#include "plugin/PluginMetaInformationFactory.h"
#include "plugin/PluginInformationFactory.h"
#include "utils/logger.h"
#include "utils/ElfUtils.h"
#include "PluginManagement.h"
#include "hooks.h"
@ -15,7 +14,7 @@
bool PluginManagement::doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolinID) {
std::map<std::string, OSDynLoad_Module> moduleHandleCache;
for (auto const &cur : relocData) {
for (auto const &cur: relocData) {
uint32_t functionAddress = 0;
const std::string &functionName = cur.getName();
@ -65,7 +64,7 @@ bool PluginManagement::doRelocation(const std::vector<RelocationData> &relocData
void PluginManagement::doRelocations(const std::vector<PluginContainer> &plugins, relocation_trampolin_entry_t *trampData, uint32_t tramp_size) {
for (auto &pluginContainer : plugins) {
for (auto &pluginContainer: plugins) {
DEBUG_FUNCTION_LINE_VERBOSE("Doing relocations for plugin: %s", pluginContainer.getMetaInformation().getName().c_str());
if (!PluginManagement::doRelocation(pluginContainer.getPluginInformation().getRelocationDataList(), trampData, tramp_size, pluginContainer.getPluginInformation().getTrampolinId())) {
@ -75,7 +74,7 @@ void PluginManagement::doRelocations(const std::vector<PluginContainer> &plugins
}
void PluginManagement::memsetBSS(const std::vector<PluginContainer> &plugins) {
for (auto &pluginContainer : plugins) {
for (auto &pluginContainer: plugins) {
auto sbssSection = pluginContainer.getPluginInformation().getSectionInfo(".sbss");
if (sbssSection) {
DEBUG_FUNCTION_LINE_VERBOSE("memset .sbss %08X (%d)", sbssSection->getAddress(), sbssSection->getSize());
@ -98,22 +97,22 @@ 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_INIT_WUT_SOCKETS);
CallHook(gPluginInformation, WUPS_LOADER_HOOK_DEINIT_PLUGIN);
// CallHook(gPluginInformation, WUPS_LOADER_HOOK_FINI_WUT_SOCKETS); To keep network alive we skip this.
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);
void PluginManagement::unloadPlugins(plugin_information_t *pluginInformation, MEMHeapHandle pluginHeap, BOOL freePluginData) {
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_MALLOC);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_NEWLIB);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_STDCPP);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB);
CallHook(pluginInformation, WUPS_LOADER_HOOK_INIT_WUT_SOCKETS);
CallHook(pluginInformation, WUPS_LOADER_HOOK_DEINIT_PLUGIN);
// CallHook(pluginInformation, WUPS_LOADER_HOOK_FINI_WUT_SOCKETS); To keep network alive we skip this.
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);
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]);
RestorePatches(pluginInformation, true);
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
plugin_information_single_t *plugin = &(pluginInformation->plugin_data[plugin_index]);
if (freePluginData) {
if (plugin->data.buffer != nullptr) {
if (plugin->data.memoryType == eMemTypeMEM2) {
@ -151,7 +150,7 @@ void PluginManagement::unloadPlugins(plugin_information_t *gPluginInformation, M
}
}
memset((void *) gPluginInformation, 0, sizeof(plugin_information_t));
memset((void *) pluginInformation, 0, sizeof(plugin_information_t));
}
void PluginManagement::callInitHooks(plugin_information_t *pluginInformation) {
@ -165,32 +164,33 @@ void module_callback(OSDynLoad_Module module,
OSDynLoad_NotifyReason reason,
OSDynLoad_NotifyData *infos) {
if (reason == OS_DYNLOAD_NOTIFY_LOADED) {
auto *gPluginInformation = (plugin_information_t *) userContext;
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
FunctionPatcherPatchFunction(gPluginInformation->plugin_data[plugin_index].info.functions, gPluginInformation->plugin_data[plugin_index].info.number_used_functions);
auto *pluginInformation = (plugin_information_t *) userContext;
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
FunctionPatcherPatchFunction(pluginInformation->plugin_data[plugin_index].info.functions, pluginInformation->plugin_data[plugin_index].info.number_used_functions);
}
}
}
void PluginManagement::PatchFunctionsAndCallHooks(plugin_information_t *gPluginInformation) {
void PluginManagement::PatchFunctionsAndCallHooks(plugin_information_t *pluginInformation) {
DEBUG_FUNCTION_LINE_VERBOSE("Patching functions");
FunctionPatcherPatchFunction(method_hooks_hooks_static, method_hooks_size_hooks_static);
DCFlushRange((void *) 0x00800000, 0x00800000);
ICInvalidateRange((void *) 0x00800000, 0x00800000);
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; 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);
for (int32_t plugin_index = 0; plugin_index < pluginInformation->number_used_plugins; plugin_index++) {
CallHookEx(pluginInformation, WUPS_LOADER_HOOK_APPLICATION_STARTS, plugin_index);
FunctionPatcherPatchFunction(pluginInformation->plugin_data[plugin_index].info.functions, pluginInformation->plugin_data[plugin_index].info.number_used_functions);
CallHookEx(pluginInformation, WUPS_LOADER_HOOK_FUNCTIONS_PATCHED, plugin_index);
}
OSDynLoad_AddNotifyCallback(module_callback, gPluginInformation);
OSDynLoad_AddNotifyCallback(module_callback, pluginInformation);
}
std::vector<PluginContainer> PluginManagement::loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) {
std::vector<PluginContainer>
PluginManagement::loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) {
std::vector<PluginContainer> plugins;
for (auto &pluginData : pluginList) {
for (auto &pluginData: pluginList) {
DEBUG_FUNCTION_LINE_VERBOSE("Load meta information");
auto metaInfo = PluginMetaInformationFactory::loadPlugin(pluginData);
if (metaInfo) {
@ -203,7 +203,7 @@ std::vector<PluginContainer> PluginManagement::loadPlugins(const std::vector<Plu
}
}
uint32_t trampolineID = 0;
for (auto &pluginContainer : plugins) {
for (auto &pluginContainer: plugins) {
std::optional<PluginInformation> info = PluginInformationFactory::load(pluginContainer.getPluginData(), heapHandle, trampolin_data, trampolin_data_length, trampolineID++);
if (!info) {
DEBUG_FUNCTION_LINE("Failed to load Plugin %s", pluginContainer.getMetaInformation().getName().c_str());

View File

@ -1,6 +1,5 @@
#pragma once
#include <common/plugin_defines.h>
#include <vector>

View File

@ -17,8 +17,8 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <cstdint>
#include <cstddef>
#include <wums/defines/dynamic_linking_defines.h>
#include <wums/defines/export_defines.h>
#include <wums/defines/relocation_defines.h>
@ -45,8 +45,8 @@ extern "C" {
struct plugin_section_info_t {
char name[MAXIMUM_PLUGIN_SECTION_NAME_LENGTH] = "";
uint32_t addr;
uint32_t size;
uint32_t addr{};
uint32_t size{};
};
struct plugin_meta_info_t {
@ -57,28 +57,28 @@ struct plugin_meta_info_t {
char buildTimestamp[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
char descripion[MAXIMUM_PLUGIN_DESCRIPTION_LENGTH] = "";
char id[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = "";
uint32_t size;
uint32_t size{};
};
struct replacement_data_hook_t {
void * func_pointer = NULL; /* [will be filled] */
wups_loader_hook_type_t type; /* [will be filled] */
void * func_pointer = nullptr; /* [will be filled] */
wups_loader_hook_type_t type{}; /* [will be filled] */
};
struct plugin_info_t {
dyn_linking_relocation_entry_t linking_entries[PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH];
dyn_linking_relocation_entry_t linking_entries[PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH]{};
plugin_section_info_t sectionInfos[MAXIMUM_PLUGIN_SECTION_LENGTH];
uint32_t number_used_functions; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN
function_replacement_data_t functions[MAXIMUM_FUNCTION_PER_PLUGIN]; // Replacement information for each function.
uint32_t number_used_hooks; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN
uint32_t number_used_functions{}; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN
function_replacement_data_t functions[MAXIMUM_FUNCTION_PER_PLUGIN]{}; // Replacement information for each function.
uint32_t number_used_hooks{}; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN
replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_PLUGIN]; // Replacement information for each function.
uint8_t trampolinId;
uint8_t trampolinId{};
void * allocatedTextMemoryAddress = nullptr;
void * allocatedDataMemoryAddress = nullptr;
};
struct plugin_data_t {
char * buffer = NULL;
char * buffer = nullptr;
size_t bufferLength = 0;
int memoryType = 0;
int heapHandle = 0;
@ -88,7 +88,7 @@ struct plugin_information_single_t {
plugin_meta_info_t meta;
plugin_info_t info;
plugin_data_t data;
int32_t priority; // Priority of this plugin
int32_t priority{}; // Priority of this plugin
};
#define MAXIMUM_PLUGINS 32
@ -96,7 +96,7 @@ struct plugin_information_single_t {
struct plugin_information_t {
int32_t number_used_plugins = 0; // Number of used plugins. Maximum is MAXIMUM_PLUGINS
plugin_information_single_t plugin_data[MAXIMUM_PLUGINS];
dyn_linking_relocation_data_t linking_data; // RPL and function name list
dyn_linking_relocation_data_t linking_data{}; // RPL and function name list
};
struct plugin_information_on_reload_t {

View File

@ -31,7 +31,7 @@ public:
}
~WUPSConfig() {
for (auto &element : categories) {
for (auto &element: categories) {
delete element;
}
}
@ -69,7 +69,7 @@ public:
\param category: The category that will be added to this config.
\return On success, the inserted category will be returned.
On error NULL will be returned. In this case the caller still has the responsibility
On error nullptr will be returned. In this case the caller still has the responsibility
for deleting the WUPSConfigCategory instance.
**/
WUPSConfigCategory *addCategory(WUPSConfigCategory *category) {

View File

@ -29,7 +29,7 @@ public:
}
~WUPSConfigCategory() {
for (auto &element : items) {
for (auto &element: items) {
delete element;
}
}
@ -53,7 +53,7 @@ public:
for deleting the WUPSConfigItem instance.
**/
[[nodiscard]] bool addItem(WUPSConfigItem *item) {
if(item != nullptr){
if (item != nullptr) {
items.push_back(item);
return true;
}

View File

@ -44,7 +44,7 @@ int32_t WUPSConfig_AddCategoryByName(WUPSConfigHandle handle, const char *catego
if (res.has_value()) {
if (out != nullptr) {
*out = reinterpret_cast<WUPSConfigCategoryHandle>(res.value());
}else{
} else {
return -3;
}
return 0;

View File

@ -140,7 +140,7 @@ public:
This function will be called whenever this item should call it's (optional) given
callback with the current value.
Returns true if a valid callback could be called
Returns false if no callback was called (e.g. callback was NULL)
Returns false if no callback was called (e.g. callback was nullptr)
**/
bool callCallback() {
if (this->callbacks.callCallback != nullptr) {

View File

@ -4,7 +4,7 @@
typedef uint32_t WUPSConfigItemHandle;
int32_t WUPSConfigItem_Create(WUPSConfigItemHandle *out, const char *configID, const char *displayName, WUPSConfigCallbacks_t callbacks, void* context) {
int32_t WUPSConfigItem_Create(WUPSConfigItemHandle *out, const char *configID, const char *displayName, WUPSConfigCallbacks_t callbacks, void *context) {
if (configID == nullptr || displayName == nullptr) {
return -1;
}
@ -14,7 +14,7 @@ int32_t WUPSConfigItem_Create(WUPSConfigItemHandle *out, const char *configID, c
return 0;
}
return -2;
};
}
int32_t WUPSConfigItem_Destroy(WUPSConfigItemHandle handle) {
if (handle == 0) {
@ -24,7 +24,7 @@ int32_t WUPSConfigItem_Destroy(WUPSConfigItemHandle handle) {
auto *config = reinterpret_cast<WUPSConfigItem *>(handle);
delete config;
return 0;
};
}
int32_t WUPSConfigItem_SetDisplayName(WUPSConfigItemHandle handle, const char *displayName) {
if (displayName == nullptr) {
@ -34,7 +34,7 @@ int32_t WUPSConfigItem_SetDisplayName(WUPSConfigItemHandle handle, const char *d
auto *config = reinterpret_cast<WUPSConfigItem *>(handle);
config->setDisplayName(displayName);
return 0;
};
}
int32_t WUPSConfigItem_GetDisplayName(WUPSConfigItemHandle handle, char *out_buf, int32_t out_len) {
if (out_buf == nullptr) {
@ -53,7 +53,7 @@ int32_t WUPSConfigItem_SetConfigID(WUPSConfigItemHandle handle, const char *conf
auto *config = reinterpret_cast<WUPSConfigItem *>(handle);
config->setConfigID(configID);
return 0;
};
}
int32_t WUPSConfigItem_GetConfigID(WUPSConfigItemHandle handle, char *out_buf, int32_t out_len) {
if (out_buf == nullptr) {

View File

@ -1,13 +1,12 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstdarg>
#include <cstdio>
#include <strings.h>
#include <fs/CFile.hpp>
CFile::CFile() {
iFd = -1;
mem_file = NULL;
mem_file = nullptr;
filesize = 0;
pos = 0;
}
@ -78,7 +77,7 @@ void CFile::close() {
::close(iFd);
iFd = -1;
mem_file = NULL;
mem_file = nullptr;
filesize = 0;
pos = 0;
}
@ -99,7 +98,7 @@ int32_t CFile::read(uint8_t *ptr, size_t size) {
if (readsize <= 0)
return readsize;
if (mem_file != NULL) {
if (mem_file != nullptr) {
memcpy(ptr, mem_file + pos, readsize);
pos += readsize;
return readsize;
@ -147,7 +146,7 @@ int32_t CFile::seek(long int offset, int32_t origin) {
if (iFd >= 0)
ret = ::lseek(iFd, pos, SEEK_SET);
if (mem_file != NULL) {
if (mem_file != nullptr) {
if (pos > filesize) {
pos = filesize;
}

View File

@ -1,9 +1,8 @@
#ifndef CFILE_HPP_
#define CFILE_HPP_
#pragma once
#include <stdio.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include <wut_types.h>
@ -29,7 +28,7 @@ public:
int32_t open(const uint8_t *memory, int32_t memsize);
BOOL isOpen() const {
[[nodiscard]] BOOL isOpen() const {
if (iFd >= 0)
return true;
@ -49,11 +48,11 @@ public:
int32_t seek(long int offset, int32_t origin);
uint64_t tell() {
[[nodiscard]] uint64_t tell() const {
return pos;
};
uint64_t size() {
[[nodiscard]] uint64_t size() const {
return filesize;
};
@ -63,9 +62,7 @@ public:
protected:
int32_t iFd;
const uint8_t *mem_file;
uint64_t filesize;
uint64_t pos;
const uint8_t *mem_file{};
uint64_t filesize{};
uint64_t pos{};
};
#endif

View File

@ -81,11 +81,11 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
if (folderpath.size() < 3)
return false;
struct dirent *dirent = NULL;
DIR *dir = NULL;
struct dirent *dirent = nullptr;
DIR *dir = nullptr;
dir = opendir(folderpath.c_str());
if (dir == NULL)
if (dir == nullptr)
return false;
while ((dirent = readdir(dir)) != 0) {
@ -153,7 +153,7 @@ void DirList::ClearList() {
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
if (FileInfo[i].FilePath) {
free(FileInfo[i].FilePath);
FileInfo[i].FilePath = NULL;
FileInfo[i].FilePath = nullptr;
}
}

View File

@ -44,13 +44,13 @@ public:
//!\param path Path from where to load the filelist of all files
//!\param filter A fileext that needs to be filtered
//!\param flags search/filter flags from the enum
DirList(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
DirList(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//!Destructor
virtual ~DirList();
//! Load all the files from a directory
BOOL LoadPath(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
BOOL LoadPath(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//! Get a filename of the list
//!\param list index

View File

@ -9,7 +9,7 @@
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input
*inbuffer = NULL;
*inbuffer = nullptr;
if (size)
*size = 0;
@ -21,7 +21,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
lseek(iFd, 0, SEEK_SET);
uint8_t *buffer = (uint8_t *) malloc(filesize);
if (buffer == NULL) {
if (buffer == nullptr) {
close(iFd);
return -2;
}
@ -44,7 +44,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
if (done != filesize) {
free(buffer);
buffer = NULL;
buffer = nullptr;
return -3;
}

View File

@ -83,7 +83,7 @@ void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t
hook_type == WUPS_LOADER_HOOK_CONFIG_CLOSED ||
hook_type == WUPS_LOADER_HOOK_RELEASE_FOREGROUND ||
hook_type == WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND
){
) {
((void (*)()) ((uint32_t *) func_ptr))();
} else if (hook_type == WUPS_LOADER_HOOK_INIT_STORAGE) {
wups_loader_init_storage_args_t args;

View File

@ -117,8 +117,8 @@ WUMS_APPLICATION_STARTS() {
std::vector<PluginContainer> plugins = PluginManagement::loadPlugins(pluginList, gPluginDataHeap, gTrampolineData, gTrampolineDataSize);
for (auto &pluginContainer : plugins) {
for (const auto &kv : pluginContainer.getPluginInformation().getSectionInfoList()) {
for (auto &pluginContainer: plugins) {
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());
}
if (!PluginContainerPersistence::savePlugin(gPluginInformation, pluginContainer)) {
@ -171,7 +171,7 @@ WUMS_APPLICATION_STARTS() {
std::vector<PluginContainer> plugins = PluginManagement::loadPlugins(pluginDataList, gPluginDataHeap, gTrampolineData, gTrampolineDataSize);
for (auto &pluginContainer : plugins) {
for (auto &pluginContainer: plugins) {
DEBUG_FUNCTION_LINE("Stored information for plugin %s ; %s", pluginContainer.getMetaInformation().getName().c_str(), pluginContainer.getMetaInformation().getAuthor().c_str());
if (!PluginContainerPersistence::savePlugin(gPluginInformation, pluginContainer)) {
DEBUG_FUNCTION_LINE("Failed to save plugin");
@ -213,7 +213,7 @@ void *allocOnCustomHeap(int alignment, int size) {
}
uint32_t *custom_memalign;
dyn_res = OSDynLoad_FindExport(module, true, "MEMAllocFromMappedMemoryEx", reinterpret_cast<void **>(&custom_memalign));
void *(*customMEMAllocFromDefaultHeapEx)(uint32_t size, int align) = (void *(*)(uint32_t, int)) *custom_memalign;
auto * customMEMAllocFromDefaultHeapEx = (void *(*)(uint32_t, int)) *custom_memalign;
if (dyn_res != OS_DYNLOAD_OK) {
return nullptr;

View File

@ -31,7 +31,7 @@ DECL_FUNCTION(void, GX2SetTVBuffer, void *buffer, uint32_t buffer_size, int32_t
storedTVBuffer.surface_format = format;
storedTVBuffer.buffering_mode = buffering_mode;
return real_GX2SetTVBuffer(buffer,buffer_size,tv_render_mode,format,buffering_mode);
return real_GX2SetTVBuffer(buffer, buffer_size, tv_render_mode, format, buffering_mode);
}
DECL_FUNCTION(void, GX2SetDRCBuffer, void *buffer, uint32_t buffer_size, uint32_t drc_mode, GX2SurfaceFormat surface_format, GX2BufferingMode buffering_mode) {
@ -41,19 +41,20 @@ DECL_FUNCTION(void, GX2SetDRCBuffer, void *buffer, uint32_t buffer_size, uint32_
storedDRCBuffer.surface_format = surface_format;
storedDRCBuffer.buffering_mode = buffering_mode;
return real_GX2SetDRCBuffer(buffer,buffer_size,drc_mode,surface_format,buffering_mode);
return real_GX2SetDRCBuffer(buffer, buffer_size, drc_mode, surface_format, buffering_mode);
}
static uint32_t lastData0 = 0;
DECL_FUNCTION(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint32_t flags) {
int32_t res = real_OSReceiveMessage(queue, message, flags);
uint32_t res = real_OSReceiveMessage(queue, message, flags);
if (queue == OSGetSystemMessageQueue()) {
if (message != nullptr && res) {
if (lastData0 != message->args[0]) {
if (message->args[0] == 0xFACEF000) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND);
} else if (message->args[0] == 0xD1E0D1E0) {
// Implemented via WUMS Hook
// Implemented via WUMS Hook
}
}
lastData0 = message->args[0];
@ -89,7 +90,7 @@ DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) {
if (!configMenuOpened && data[0].err == 0) {
if (data[0].extensionType == WPAD_EXT_CORE || data[0].extensionType == WPAD_EXT_NUNCHUK) {
// button data is in the first 2 bytes for wiimotes
if (((uint16_t*)data)[0] == (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_MINUS)) {
if (((uint16_t *) data)[0] == (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_MINUS)) {
wantsToOpenConfigMenu = true;
}
} else {
@ -102,13 +103,13 @@ DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) {
}
function_replacement_data_t method_hooks_hooks_static[] __attribute__((section(".data"))) = {
REPLACE_FUNCTION(GX2SwapScanBuffers, LIBRARY_GX2, GX2SwapScanBuffers),
REPLACE_FUNCTION(GX2SetTVBuffer, LIBRARY_GX2, GX2SetTVBuffer),
REPLACE_FUNCTION(GX2SetDRCBuffer, LIBRARY_GX2, GX2SetDRCBuffer),
REPLACE_FUNCTION(OSReceiveMessage, LIBRARY_COREINIT, OSReceiveMessage),
REPLACE_FUNCTION(OSReleaseForeground, LIBRARY_COREINIT, OSReleaseForeground),
REPLACE_FUNCTION(VPADRead, LIBRARY_VPAD, VPADRead),
REPLACE_FUNCTION(WPADRead, LIBRARY_PADSCORE, WPADRead),
REPLACE_FUNCTION(GX2SwapScanBuffers, LIBRARY_GX2, GX2SwapScanBuffers),
REPLACE_FUNCTION(GX2SetTVBuffer, LIBRARY_GX2, GX2SetTVBuffer),
REPLACE_FUNCTION(GX2SetDRCBuffer, LIBRARY_GX2, GX2SetDRCBuffer),
REPLACE_FUNCTION(OSReceiveMessage, LIBRARY_COREINIT, OSReceiveMessage),
REPLACE_FUNCTION(OSReleaseForeground, LIBRARY_COREINIT, OSReleaseForeground),
REPLACE_FUNCTION(VPADRead, LIBRARY_VPAD, VPADRead),
REPLACE_FUNCTION(WPADRead, LIBRARY_PADSCORE, WPADRead),
};
uint32_t method_hooks_size_hooks_static __attribute__((section(".data"))) = sizeof(method_hooks_hooks_static) / sizeof(function_replacement_data_t);

View File

@ -1,6 +1,5 @@
#include "DynamicLinkingHelper.h"
#include <cstring>
#include "../utils/logger.h"
dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t *data, const char *functionName) {
if (data == nullptr) {
@ -10,19 +9,18 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
return nullptr;
}
dyn_linking_function_t *result = nullptr;
for (int32_t i = 0; i < DYN_LINK_FUNCTION_LIST_LENGTH; i++) {
dyn_linking_function_t *curEntry = &(data->functions[i]);
if (strlen(curEntry->functionName) == 0) {
for (auto & curEntry : data->functions) {
if (strlen(curEntry.functionName) == 0) {
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.");
return nullptr;
}
strncpy(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
result = curEntry;
strncpy(curEntry.functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH);
result = &curEntry;
break;
}
if (strncmp(curEntry->functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
result = curEntry;
if (strncmp(curEntry.functionName, functionName, DYN_LINK_FUNCTION_NAME_LENGTH) == 0) {
result = &curEntry;
break;
}
}
@ -42,31 +40,33 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return nullptr;
}
dyn_linking_import_t *result = nullptr;
for (int32_t i = 0; i < DYN_LINK_IMPORT_LIST_LENGTH; i++) {
dyn_linking_import_t *curEntry = &(data->imports[i]);
if (strlen(curEntry->importName) == 0) {
for (auto & curEntry : data->imports) {
if (strlen(curEntry.importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.");
return nullptr;
}
strncpy(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
curEntry->isData = isData;
result = curEntry;
strncpy(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH);
curEntry.isData = isData;
result = &curEntry;
break;
}
if (strncmp(curEntry->importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry->isData == isData)) {
return curEntry;
if (strncmp(curEntry.importName, importName, DYN_LINK_IMPORT_NAME_LENGTH) == 0 && (curEntry.isData == isData)) {
return &curEntry;
}
}
return result;
}
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData) {
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(), relocationData.getName(),
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length,
const RelocationData &relocationData) {
return addReloationEntry(linking_data, linking_entries, linking_entry_length, relocationData.getType(), relocationData.getOffset(), relocationData.getAddend(), relocationData.getDestination(),
relocationData.getName(),
relocationData.getImportRPLInformation());
}
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset,
int32_t addend, const void *destination,
const std::string &name, const ImportRPLInformation &rplInfo) {
dyn_linking_import_t *importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo.getName().c_str(), rplInfo.isData());
if (importInfoGbl == nullptr) {
@ -83,7 +83,8 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t *link
return addReloationEntry(linking_entries, linking_entry_length, type, offset, addend, destination, functionInfo, importInfoGbl);
}
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
dyn_linking_function_t *functionName,
dyn_linking_import_t *importInfo) {
for (uint32_t i = 0; i < linking_entry_length; i++) {
dyn_linking_relocation_entry_t *curEntry = &(linking_entries[i]);

View File

@ -49,10 +49,12 @@ public:
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const RelocationData &relocationData);
static bool
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, const std::string &name,
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend,
const void *destination, const std::string &name,
const ImportRPLInformation &rplInfo);
static bool addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination, dyn_linking_function_t *functionName,
static bool addReloationEntry(dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, const void *destination,
dyn_linking_function_t *functionName,
dyn_linking_import_t *importInfo);
private:

View File

@ -23,7 +23,8 @@
class FunctionData {
public:
FunctionData(void *paddress, void *vaddress, const std::string &name, function_replacement_library_type_t library, void *replaceAddr, void *replaceCall, FunctionPatcherTargetProcess targetProcess) {
FunctionData(void *paddress, void *vaddress, const std::string &name, function_replacement_library_type_t library, void *replaceAddr, void *replaceCall,
FunctionPatcherTargetProcess targetProcess) {
this->paddress = paddress;
this->vaddress = vaddress;
this->name = name;

View File

@ -6,9 +6,6 @@
#include "PluginContainerPersistence.h"
#include "PluginDataPersistence.h"
#include "DynamicLinkingHelper.h"
#include "../common/plugin_defines.h"
#include "PluginInformation.h"
#include "RelocationData.h"
bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformation, PluginContainer &plugin) {
int32_t plugin_count = pluginInformation->number_used_plugins;
@ -69,7 +66,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
// Relocation
std::vector<RelocationData> relocationData = pluginInfo.getRelocationDataList();
for (auto &reloc : relocationData) {
for (auto &reloc: relocationData) {
if (!DynamicLinkingHelper::addReloationEntry(&(pluginInformation->linking_data), plugin_data->info.linking_entries, PLUGIN_DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) {
DEBUG_FUNCTION_LINE("Failed to add a relocation entry");
return false;
@ -95,7 +92,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
/* Store function replacement information */
uint32_t i = 0;
for (auto &curFunction : pluginInfo.getFunctionDataList()) {
for (auto &curFunction: pluginInfo.getFunctionDataList()) {
function_replacement_data_t *function_data = &plugin_data->info.functions[i];
if (strlen(curFunction.getName().c_str()) > MAXIMUM_FUNCTION_NAME_LENGTH - 1) {
DEBUG_FUNCTION_LINE("Could not add function \"%s\" for plugin \"%s\" function name is too long.", curFunction.getName().c_str(), pluginName.c_str());
@ -119,7 +116,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
}
i = 0;
for (auto &curHook : pluginInfo.getHookDataList()) {
for (auto &curHook: pluginInfo.getHookDataList()) {
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[i];
DEBUG_FUNCTION_LINE_VERBOSE("Set hook for plugin \"%s\" of type %08X to target %08X", plugin_data->meta.name, curHook.getType(), (void *) curHook.getFunctionPointer());
@ -132,20 +129,20 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
}
/* Saving SectionInfos */
for (auto &curSection : pluginInfo.getSectionInfoList()) {
for (auto &curSection: pluginInfo.getSectionInfoList()) {
bool foundFreeSlot = false;
uint32_t slot = 0;
for (uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[i]);
for (uint32_t j = 0; j < MAXIMUM_PLUGIN_SECTION_LENGTH; j++) {
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[j]);
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
foundFreeSlot = true;
slot = i;
slot = j;
break;
}
}
if (foundFreeSlot) {
plugin_section_info_t *sectionInfo = &(plugin_data->info.sectionInfos[slot]);
if (strlen(curSection.first.c_str()) > MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1) {
if (curSection.first.length() > MAXIMUM_PLUGIN_SECTION_NAME_LENGTH - 1) {
DEBUG_FUNCTION_LINE("Could not add section info \"%s\" for plugin \"%s\" section name is too long.", curSection.first.c_str(), pluginName.c_str());
break;
}
@ -180,7 +177,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_information_t *pluginInformation) {
std::vector<PluginContainer> result;
if (pluginInformation == nullptr) {
DEBUG_FUNCTION_LINE("pluginInformation == NULL");
DEBUG_FUNCTION_LINE("pluginInformation == nullptr");
return result;
}
DCFlushRange((void *) pluginInformation, sizeof(plugin_information_t));
@ -216,7 +213,7 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
curPluginInformation.allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress;
curPluginInformation.allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress;
for (auto & curItem : plugin_data->info.sectionInfos) {
for (auto &curItem: plugin_data->info.sectionInfos) {
plugin_section_info_t *sectionInfo = &curItem;
if (sectionInfo->addr == 0 && sectionInfo->size == 0) {
continue;
@ -250,38 +247,30 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
for (uint32_t j = 0; j < functionReplaceCount; j++) {
function_replacement_data_t *entry = &(plugin_data->info.functions[j]);
FunctionData func((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library, (void *) entry->replaceAddr, (void *) entry->replaceCall, entry->targetProcess);
FunctionData func((void *) entry->physicalAddr, (void *) entry->virtualAddr, entry->function_name, (function_replacement_library_type_t) entry->library, (void *) entry->replaceAddr,
(void *) entry->replaceCall, entry->targetProcess);
curPluginInformation.addFunctionData(func);
}
/* load relocation data */
for (auto & linking_entrie : plugin_data->info.linking_entries) {
dyn_linking_relocation_entry_t *linking_entry = &linking_entrie;
if (linking_entry->destination == nullptr) {
for (auto &linking_entry: plugin_data->info.linking_entries) {
if (linking_entry.destination == nullptr) {
break;
}
dyn_linking_import_t *importEntry = linking_entry->importEntry;
dyn_linking_import_t *importEntry = linking_entry.importEntry;
if (importEntry == nullptr) {
DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry");
DEBUG_FUNCTION_LINE("importEntry was nullptr, skipping relocation entry");
continue;
}
if (importEntry->importName == nullptr) {
DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry");
continue;
}
dyn_linking_function_t *functionEntry = linking_entry->functionEntry;
dyn_linking_function_t *functionEntry = linking_entry.functionEntry;
if (functionEntry == nullptr) {
DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry");
continue;
}
if (functionEntry->functionName == nullptr) {
DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry");
DEBUG_FUNCTION_LINE("functionEntry was nullptr, skipping relocation entry");
continue;
}
ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData);
std::string functionName(functionEntry->functionName);
RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionName, rplInfo);
RelocationData reloc(linking_entry.type, linking_entry.offset, linking_entry.addend, linking_entry.destination, functionName, rplInfo);
curPluginInformation.addRelocationData(reloc);
}

View File

@ -31,10 +31,10 @@ void PluginData::freeMemory() {
}
}
PluginData::PluginData(const std::vector<uint8_t>& buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
PluginData::PluginData(const std::vector<uint8_t> &buffer) : PluginData(buffer, nullptr, eMemTypeMEM2) {
}
PluginData::PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
PluginData::PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType) :
heapHandle(heapHandle),
memoryType(memoryType),
length(input.size()) {

View File

@ -33,7 +33,7 @@ enum eMemoryTypes {
class PluginData {
public:
~PluginData()= default;
~PluginData() = default;
void freeMemory();
@ -49,7 +49,7 @@ public:
private:
explicit PluginData(const std::vector<uint8_t> &buffer);
PluginData(const std::vector<uint8_t>& input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
PluginData(const std::vector<uint8_t> &input, MEMHeapHandle heapHandle, eMemoryTypes memoryType);
friend class PluginDataFactory;

View File

@ -1,13 +1,13 @@
#include "PluginInformation.h"
PluginInformation::PluginInformation(const PluginInformation &other) {
for (const auto &i : other.hook_data_list) {
for (const auto &i: other.hook_data_list) {
hook_data_list.push_back(i);
}
for (const auto &i : other.function_data_list) {
for (const auto &i: other.function_data_list) {
function_data_list.push_back(i);
}
for (const auto &i : other.relocation_data_list) {
for (const auto &i: other.relocation_data_list) {
relocation_data_list.push_back(i);
}
section_info_list = other.section_info_list;

View File

@ -21,21 +21,17 @@
#include <coreinit/cache.h>
#include <coreinit/memexpheap.h>
#include <wups.h>
#include <whb/file.h>
#include "PluginData.h"
#include "PluginInformationFactory.h"
#include "HookData.h"
#include "SectionInfo.h"
#include "../elfio/elfio.hpp"
#include "../utils/utils.h"
#include "../utils/ElfUtils.h"
#include "../utils/StringTools.h"
using namespace ELFIO;
std::optional<PluginInformation> PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
std::optional<PluginInformation>
PluginInformationFactory::load(const PluginData &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId) {
if (pluginData.buffer == nullptr) {
DEBUG_FUNCTION_LINE("Buffer was NULL");
DEBUG_FUNCTION_LINE("Buffer was nullptr");
return std::nullopt;
}
elfio reader;
@ -62,7 +58,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
uint32_t address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
if ((address >= 0x02000000) && address < 0x10000000) {
text_size += sectionSize;
} else if ((address >= 0x10000000) && address < 0xC0000000) {
@ -89,8 +85,6 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
}
DEBUG_FUNCTION_LINE_VERBOSE("Allocated %d kb from ExpHeap", data_size / 1024);
uint32_t entrypoint = (uint32_t) text_data + (uint32_t) reader.get_entry() - 0x02000000;
for (uint32_t i = 0; i < sec_num; ++i) {
section *psec = reader.sections[i];
if (psec->get_type() == 0x80000002) {
@ -99,7 +93,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
uint32_t address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
uint32_t destination = address;
if ((address >= 0x02000000) && address < 0x10000000) {
@ -160,7 +154,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
}
std::vector<RelocationData> relocationData = getImportRelocationData(reader, destinations);
for (auto const &reloc : relocationData) {
for (auto const &reloc: relocationData) {
pluginInfo.addRelocationData(reloc);
}
@ -173,8 +167,6 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
pluginInfo.setTrampolinId(trampolinId);
DEBUG_FUNCTION_LINE_VERBOSE("Saved entrypoint as %08X", entrypoint);
std::optional<SectionInfo> secInfo = pluginInfo.getSectionInfo(".wups.hooks");
if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_hook_t);
@ -193,12 +185,15 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
if (secInfo && secInfo->getSize() > 0) {
size_t entries_count = secInfo->getSize() / sizeof(wups_loader_entry_t);
auto *entries = (wups_loader_entry_t *) secInfo->getAddress();
if (entries != NULL) {
if (entries != nullptr) {
for (size_t j = 0; j < entries_count; j++) {
wups_loader_entry_t *cur_function = &entries[j];
DEBUG_FUNCTION_LINE_VERBOSE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X", cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,
cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target, (void *) cur_function->_function.call_addr);
FunctionData function_data((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name, (function_replacement_library_type_t) cur_function->_function.library,
DEBUG_FUNCTION_LINE_VERBOSE("Saving function \"%s\" of plugin . PA:%08X VA:%08X Library: %08X, target: %08X, call_addr: %08X",
cur_function->_function.name/*,pluginData.getPluginInformation()->getName().c_str()*/,
cur_function->_function.physical_address, cur_function->_function.virtual_address, cur_function->_function.library, cur_function->_function.target,
(void *) cur_function->_function.call_addr);
FunctionData function_data((void *) cur_function->_function.physical_address, (void *) cur_function->_function.virtual_address, cur_function->_function.name,
(function_replacement_library_type_t) cur_function->_function.library,
(void *) cur_function->_function.target, (void *) cur_function->_function.call_addr, (FunctionPatcherTargetProcess) cur_function->_function.targetProcess);
pluginInfo.addFunctionData(function_data);
}
@ -212,7 +207,7 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
return pluginInfo;
}
std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(const elfio & reader, uint8_t **destinations) {
std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(const elfio &reader, uint8_t **destinations) {
std::vector<RelocationData> result;
std::map<uint32_t, std::string> infoMap;
@ -244,7 +239,7 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
break;
}
uint32_t adjusted_sym_value = (uint32_t) sym_value;
auto adjusted_sym_value = (uint32_t) sym_value;
if (adjusted_sym_value < 0xC0000000) {
continue;
}
@ -254,7 +249,7 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
bool isData = false;
std::string rplName = "";
std::string rplName;
std::string rawSectionName = infoMap[sym_section_index];
if (rawSectionName.size() < fimport.size()) {
@ -274,14 +269,15 @@ std::vector<RelocationData> PluginInformationFactory::getImportRelocationData(co
uint32_t section_index = psec->get_info();
result.push_back(RelocationData(type, offset - 0x02000000, addend, (void *) (destinations[section_index]), sym_name, rplInfo));
result.emplace_back(type, offset - 0x02000000, addend, (void *) (destinations[section_index]), sym_name, rplInfo);
}
}
}
return result;
}
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data,
uint32_t trampolin_data_length,
uint8_t trampolinId) {
uint32_t sec_num = reader.sections.size();
@ -303,7 +299,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
break;
}
uint32_t adjusted_sym_value = (uint32_t) sym_value;
auto adjusted_sym_value = (uint32_t) sym_value;
if ((adjusted_sym_value >= 0x02000000) && adjusted_sym_value < 0x10000000) {
adjusted_sym_value -= 0x02000000;
adjusted_sym_value += base_text;
@ -321,7 +317,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
return false;
}
uint32_t adjusted_offset = (uint32_t) offset;
auto adjusted_offset = (uint32_t) offset;
if ((offset >= 0x02000000) && offset < 0x10000000) {
adjusted_offset -= 0x02000000;
} else if ((adjusted_offset >= 0x10000000) && adjusted_offset < 0xC0000000) {
@ -336,9 +332,8 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
DEBUG_FUNCTION_LINE("NOT IMPLEMENTED: %04X", sym_section_index);
return false;
}
if (false) {
DEBUG_FUNCTION_LINE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
}
DEBUG_FUNCTION_LINE_VERBOSE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
if (!ElfUtils::elfLinkOne(type, adjusted_offset, addend, destination, adjusted_sym_value, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED, trampolinId)) {
DEBUG_FUNCTION_LINE("Link failed");
return false;

View File

@ -29,9 +29,12 @@
class PluginInformationFactory {
public:
static std::optional<PluginInformation> load(const PluginData &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
static std::optional<PluginInformation>
load(const PluginData &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
static bool linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
static bool
linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
uint8_t trampolinId);
static std::vector<RelocationData> getImportRelocationData(const elfio &reader, uint8_t **destinations);
};

View File

@ -24,38 +24,38 @@ class PluginMetaInformation {
public:
PluginMetaInformation(const PluginMetaInformation &other);
[[nodiscard]] std::string getName() const {
[[nodiscard]] const std::string &getName() const {
return name;
}
[[nodiscard]] std::string getAuthor() const {
[[nodiscard]] const std::string &getAuthor() const {
return this->author;
}
[[nodiscard]] std::string getVersion() const {
[[nodiscard]] const std::string &getVersion() const {
return this->version;
}
[[nodiscard]] std::string getLicense() const {
[[nodiscard]] const std::string &getLicense() const {
return this->license;
}
[[nodiscard]] std::string getBuildTimestamp() const {
[[nodiscard]] const std::string &getBuildTimestamp() const {
return this->buildtimestamp;
}
[[nodiscard]] std::string getDescription() const {
[[nodiscard]] const std::string &getDescription() const {
return this->description;
}
[[nodiscard]] const std::string &getId() const {
return this->id;
}
[[nodiscard]] size_t getSize() const {
return this->size;
}
[[nodiscard]] const std::string getId() const {
return this->id;
}
private:
PluginMetaInformation() = default;
@ -87,8 +87,8 @@ private:
this->size = _size;
}
void setId(const std::string &id) {
this->id = id;
void setId(const std::string &_id) {
this->id = _id;
}
std::string name;

View File

@ -28,8 +28,8 @@
using namespace ELFIO;
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const PluginData &pluginData) {
if (pluginData.buffer == NULL) {
DEBUG_FUNCTION_LINE("Buffer was NULL");
if (pluginData.buffer == nullptr) {
DEBUG_FUNCTION_LINE("Buffer was nullptr");
return std::nullopt;
}
elfio reader;
@ -59,7 +59,7 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(ch
return loadPlugin(reader);
}
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const elfio& reader) {
std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(const elfio &reader) {
size_t pluginSize = 0;
PluginMetaInformation pluginInfo;
@ -72,7 +72,7 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
// Calculate total size:
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
uint32_t address = (uint32_t) psec->get_address();
auto address = (uint32_t) psec->get_address();
if ((address >= 0x02000000) && address < 0x10000000) {
pluginSize += sectionSize;
} else if ((address >= 0x10000000) && address < 0xC0000000) {
@ -98,22 +98,22 @@ std::optional<PluginMetaInformation> PluginMetaInformationFactory::loadPlugin(co
std::string key(curEntry);
std::string value(curEntry + firstFound + 1);
if (key.compare("name") == 0) {
if (key == "name") {
pluginInfo.setName(value);
} else if (key.compare("author") == 0) {
} else if (key == "author") {
pluginInfo.setAuthor(value);
} else if (key.compare("version") == 0) {
} else if (key == "version") {
pluginInfo.setVersion(value);
} else if (key.compare("license") == 0) {
} else if (key == "license") {
pluginInfo.setLicense(value);
} else if (key.compare("buildtimestamp") == 0) {
} else if (key == "buildtimestamp") {
pluginInfo.setBuildTimestamp(value);
} else if (key.compare("description") == 0) {
} else if (key == "description") {
pluginInfo.setDescription(value);
} else if (key.compare("id") == 0) {
} else if (key == "id") {
pluginInfo.setId(value);
} else if (key.compare("wups") == 0) {
if (value.compare("0.6") != 0) {
} else if (key == "wups") {
if (value != "0.6") {
DEBUG_FUNCTION_LINE("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str());
return std::nullopt;
}

View File

@ -31,5 +31,5 @@ public:
static std::optional<PluginMetaInformation> loadPlugin(char *buffer, size_t size);
static std::optional<PluginMetaInformation> loadPlugin(const elfio& reader);
static std::optional<PluginMetaInformation> loadPlugin(const elfio &reader);
};

View File

@ -4,16 +4,13 @@
#include "../config/WUPSConfig.h"
#include "../globals.h"
#include "DrawUtils.h"
#include "StringTools.h"
#include <string>
#include <vector>
#include <coreinit/screen.h>
#include <coreinit/cache.h>
#include <memory/mappedmemory.h>
#include <vpad/input.h>
#include <padscore/kpad.h>
#include <padscore/wpad.h>
#include <gx2/display.h>
#define COLOR_BACKGROUND Color(238, 238, 238, 255)
@ -26,96 +23,94 @@
#define COLOR_BLACK Color(0, 0, 0, 255)
struct ConfigDisplayItem {
WUPSConfig* config;
WUPSConfig *config{};
std::string name;
std::string author;
std::string version;
bool enabled;
bool enabled{};
};
#define MAX_BUTTONS_ON_SCREEN 8
static uint32_t remapWiiMoteButtons(uint32_t buttons)
{
static uint32_t remapWiiMoteButtons(uint32_t buttons) {
uint32_t conv_buttons = 0;
if(buttons & WPAD_BUTTON_LEFT)
if (buttons & WPAD_BUTTON_LEFT)
conv_buttons |= VPAD_BUTTON_LEFT;
if(buttons & WPAD_BUTTON_RIGHT)
if (buttons & WPAD_BUTTON_RIGHT)
conv_buttons |= VPAD_BUTTON_RIGHT;
if(buttons & WPAD_BUTTON_DOWN)
if (buttons & WPAD_BUTTON_DOWN)
conv_buttons |= VPAD_BUTTON_DOWN;
if(buttons & WPAD_BUTTON_UP)
if (buttons & WPAD_BUTTON_UP)
conv_buttons |= VPAD_BUTTON_UP;
if(buttons & WPAD_BUTTON_PLUS)
if (buttons & WPAD_BUTTON_PLUS)
conv_buttons |= VPAD_BUTTON_PLUS;
if(buttons & WPAD_BUTTON_B)
if (buttons & WPAD_BUTTON_B)
conv_buttons |= VPAD_BUTTON_B;
if(buttons & WPAD_BUTTON_A)
if (buttons & WPAD_BUTTON_A)
conv_buttons |= VPAD_BUTTON_A;
if(buttons & WPAD_BUTTON_MINUS)
if (buttons & WPAD_BUTTON_MINUS)
conv_buttons |= VPAD_BUTTON_MINUS;
if(buttons & WPAD_BUTTON_HOME)
if (buttons & WPAD_BUTTON_HOME)
conv_buttons |= VPAD_BUTTON_HOME;
return conv_buttons;
}
static uint32_t remapClassicButtons(uint32_t buttons)
{
static uint32_t remapClassicButtons(uint32_t buttons) {
uint32_t conv_buttons = 0;
if(buttons & WPAD_CLASSIC_BUTTON_LEFT)
if (buttons & WPAD_CLASSIC_BUTTON_LEFT)
conv_buttons |= VPAD_BUTTON_LEFT;
if(buttons & WPAD_CLASSIC_BUTTON_RIGHT)
if (buttons & WPAD_CLASSIC_BUTTON_RIGHT)
conv_buttons |= VPAD_BUTTON_RIGHT;
if(buttons & WPAD_CLASSIC_BUTTON_DOWN)
if (buttons & WPAD_CLASSIC_BUTTON_DOWN)
conv_buttons |= VPAD_BUTTON_DOWN;
if(buttons & WPAD_CLASSIC_BUTTON_UP)
if (buttons & WPAD_CLASSIC_BUTTON_UP)
conv_buttons |= VPAD_BUTTON_UP;
if(buttons & WPAD_CLASSIC_BUTTON_PLUS)
if (buttons & WPAD_CLASSIC_BUTTON_PLUS)
conv_buttons |= VPAD_BUTTON_PLUS;
if(buttons & WPAD_CLASSIC_BUTTON_X)
if (buttons & WPAD_CLASSIC_BUTTON_X)
conv_buttons |= VPAD_BUTTON_X;
if(buttons & WPAD_CLASSIC_BUTTON_Y)
if (buttons & WPAD_CLASSIC_BUTTON_Y)
conv_buttons |= VPAD_BUTTON_Y;
if(buttons & WPAD_CLASSIC_BUTTON_B)
if (buttons & WPAD_CLASSIC_BUTTON_B)
conv_buttons |= VPAD_BUTTON_B;
if(buttons & WPAD_CLASSIC_BUTTON_A)
if (buttons & WPAD_CLASSIC_BUTTON_A)
conv_buttons |= VPAD_BUTTON_A;
if(buttons & WPAD_CLASSIC_BUTTON_MINUS)
if (buttons & WPAD_CLASSIC_BUTTON_MINUS)
conv_buttons |= VPAD_BUTTON_MINUS;
if(buttons & WPAD_CLASSIC_BUTTON_HOME)
if (buttons & WPAD_CLASSIC_BUTTON_HOME)
conv_buttons |= VPAD_BUTTON_HOME;
if(buttons & WPAD_CLASSIC_BUTTON_ZR)
if (buttons & WPAD_CLASSIC_BUTTON_ZR)
conv_buttons |= VPAD_BUTTON_ZR;
if(buttons & WPAD_CLASSIC_BUTTON_ZL)
if (buttons & WPAD_CLASSIC_BUTTON_ZL)
conv_buttons |= VPAD_BUTTON_ZL;
if(buttons & WPAD_CLASSIC_BUTTON_R)
if (buttons & WPAD_CLASSIC_BUTTON_R)
conv_buttons |= VPAD_BUTTON_R;
if(buttons & WPAD_CLASSIC_BUTTON_L)
if (buttons & WPAD_CLASSIC_BUTTON_L)
conv_buttons |= VPAD_BUTTON_L;
return conv_buttons;
@ -140,25 +135,19 @@ void ConfigUtils::displayMenu() {
if (hook_data->func_pointer == nullptr) {
break;
}
WUPSConfig *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle (*)()) ((uint32_t *) hook_data->func_pointer))());
if(cur_config == nullptr){
auto *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle (*)()) ((uint32_t *) hook_data->func_pointer))());
if (cur_config == nullptr) {
break;
}
//if(cur_config > 0x8000000);
//DCFlushRange(&cur_config, sizeof(WUPSConfig*));
//DCFlushRange(cur_config, sizeof(WUPSConfig));
cfg.config = cur_config;
DEBUG_FUNCTION_LINE("name %s author %s version %s enabled %d config %08X",cfg.name.c_str(),cfg.author.c_str(),cfg.version.c_str(),cfg.enabled, cfg.config)
configs.push_back(cfg);
break;
}
}
}
ConfigDisplayItem* currentConfig = nullptr;
WUPSConfigCategory* currentCategory = nullptr;
ConfigDisplayItem *currentConfig = nullptr;
WUPSConfigCategory *currentCategory = nullptr;
uint32_t selectedBtn = 0;
uint32_t start = 0;
@ -187,7 +176,7 @@ void ConfigUtils::displayMenu() {
}
for (int i = 0; i < 4; i++) {
if (KPADReadEx((KPADChan)i, &kpad_data, 1, &kpad_error) > 0) {
if (KPADReadEx((KPADChan) i, &kpad_data, 1, &kpad_error) > 0) {
if (kpad_error == KPAD_ERROR_OK) {
if (kpad_data.extensionType == WPAD_EXT_CORE || kpad_data.extensionType == WPAD_EXT_NUNCHUK) {
buttonsTriggered |= remapWiiMoteButtons(kpad_data.trigger);
@ -211,8 +200,7 @@ void ConfigUtils::displayMenu() {
selectedBtn++;
redraw = true;
}
}
else if (buttonsTriggered & VPAD_BUTTON_UP) {
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
if (selectedBtn > 0) {
selectedBtn--;
redraw = true;
@ -221,11 +209,9 @@ void ConfigUtils::displayMenu() {
if (buttonsTriggered & VPAD_BUTTON_X) {
configs[selectedBtn].enabled = !configs[selectedBtn].enabled;
redraw = true;
}
else if (buttonsTriggered & VPAD_BUTTON_A) {
} else if (buttonsTriggered & VPAD_BUTTON_A) {
currentConfig = &configs[selectedBtn];
if(currentConfig == nullptr){
DEBUG_FUNCTION_LINE("BYEBYE");
if (currentConfig == nullptr) {
break;
}
@ -245,8 +231,7 @@ void ConfigUtils::displayMenu() {
if (selectedBtn >= end) {
end = selectedBtn + 1;
start = end - MAX_BUTTONS_ON_SCREEN;
}
else if (selectedBtn < start) {
} else if (selectedBtn < start) {
start = selectedBtn;
end = start + MAX_BUTTONS_ON_SCREEN;
}
@ -265,17 +250,17 @@ void ConfigUtils::displayMenu() {
}
if (i == selectedBtn) {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16*2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
} else {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16*2, 44, 2, configs[i].enabled ? COLOR_BORDER : COLOR_DISABLED);
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 2, configs[i].enabled ? COLOR_BORDER : COLOR_DISABLED);
}
DrawUtils::setFontSize(24);
DrawUtils::print(16*2, index + 8 + 24, configs[i].name.c_str());
DrawUtils::print(16 * 2, index + 8 + 24, configs[i].name.c_str());
uint32_t sz = DrawUtils::getTextWidth(configs[i].name.c_str());
DrawUtils::setFontSize(12);
DrawUtils::print(16*2 + sz + 4, index + 8 + 24, configs[i].author.c_str());
DrawUtils::print(SCREEN_WIDTH - 16*2, index + 8 + 24, configs[i].version.c_str(), true);
DrawUtils::print(16 * 2 + sz + 4, index + 8 + 24, configs[i].author.c_str());
DrawUtils::print(SCREEN_WIDTH - 16 * 2, index + 8 + 24, configs[i].version.c_str(), true);
index += 42 + 8;
}
@ -289,7 +274,7 @@ void ConfigUtils::displayMenu() {
DrawUtils::drawRectFilled(8, 8 + 24 + 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK);
// draw bottom bar
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8*2, 3, COLOR_BLACK);
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK);
DrawUtils::setFontSize(18);
DrawUtils::print(16, SCREEN_HEIGHT - 8, "\ue07d Navigate ");
if (configs[selectedBtn].enabled) {
@ -309,7 +294,7 @@ void ConfigUtils::displayMenu() {
// draw home button
DrawUtils::setFontSize(18);
const char* exitHint = "\ue044 Exit";
const char *exitHint = "\ue044 Exit";
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHint) / 2, SCREEN_HEIGHT - 8, exitHint, true);
DrawUtils::endDraw();
@ -319,24 +304,22 @@ void ConfigUtils::displayMenu() {
continue;
}
if(!currentCategory){
auto cats = currentConfig->config->getCategories();
if (!currentCategory) {
auto cats = currentConfig->config->getCategories();
if (buttonsTriggered & VPAD_BUTTON_DOWN) {
if (selectedBtn < cats.size() - 1) {
selectedBtn++;
redraw = true;
}
}
else if (buttonsTriggered & VPAD_BUTTON_UP) {
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
if (selectedBtn > 0) {
selectedBtn--;
redraw = true;
}
}
else if (buttonsTriggered & VPAD_BUTTON_A) {
} else if (buttonsTriggered & VPAD_BUTTON_A) {
currentCategory = cats[selectedBtn];
if(currentCategory == nullptr){
if (currentCategory == nullptr) {
DEBUG_FUNCTION_LINE("BYEBYE");
break;
}
@ -368,8 +351,7 @@ void ConfigUtils::displayMenu() {
if (selectedBtn >= end) {
end = selectedBtn + 1;
start = end - MAX_BUTTONS_ON_SCREEN;
}
else if (selectedBtn < start) {
} else if (selectedBtn < start) {
start = selectedBtn;
end = start + MAX_BUTTONS_ON_SCREEN;
}
@ -384,13 +366,13 @@ void ConfigUtils::displayMenu() {
DrawUtils::setFontColor(COLOR_TEXT);
if (i == selectedBtn) {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16*2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
} else {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16*2, 44, 2, COLOR_BORDER);
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 2, COLOR_BORDER);
}
DrawUtils::setFontSize(24);
DrawUtils::print(16*2, index + 8 + 24, cats[i]->getName().c_str());
DrawUtils::print(16 * 2, index + 8 + 24, cats[i]->getName().c_str());
index += 42 + 8;
}
@ -404,7 +386,7 @@ void ConfigUtils::displayMenu() {
DrawUtils::drawRectFilled(8, 8 + 24 + 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK);
// draw bottom bar
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8*2, 3, COLOR_BLACK);
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK);
DrawUtils::setFontSize(18);
DrawUtils::print(16, SCREEN_HEIGHT - 8, "\ue07d Navigate ");
if (configs[selectedBtn].enabled) {
@ -424,7 +406,7 @@ void ConfigUtils::displayMenu() {
// draw home button
DrawUtils::setFontSize(18);
const char* exitHint = "\ue044 Exit";
const char *exitHint = "\ue044 Exit";
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHint) / 2, SCREEN_HEIGHT - 8, exitHint, true);
DrawUtils::endDraw();
@ -441,14 +423,12 @@ void ConfigUtils::displayMenu() {
selectedBtn++;
redraw = true;
}
}
else if (buttonsTriggered & VPAD_BUTTON_UP) {
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
if (selectedBtn > 0) {
selectedBtn--;
redraw = true;
}
}
else if (buttonsTriggered & VPAD_BUTTON_B) {
} else if (buttonsTriggered & VPAD_BUTTON_B) {
currentCategory = nullptr;
selectedBtn = 0;
start = 0;
@ -490,8 +470,7 @@ void ConfigUtils::displayMenu() {
if (selectedBtn >= end) {
end = selectedBtn + 1;
start = end - MAX_BUTTONS_ON_SCREEN;
}
else if (selectedBtn < start) {
} else if (selectedBtn < start) {
start = selectedBtn;
end = start + MAX_BUTTONS_ON_SCREEN;
}
@ -506,21 +485,20 @@ void ConfigUtils::displayMenu() {
DrawUtils::setFontColor(COLOR_TEXT);
if (i == selectedBtn) {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16*2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
} else {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16*2, 44, 2, COLOR_BORDER);
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 2, COLOR_BORDER);
}
DrawUtils::setFontSize(24);
DrawUtils::print(16*2, index + 8 + 24, config_items[i]->getDisplayName().c_str());
DrawUtils::print(16 * 2, index + 8 + 24, config_items[i]->getDisplayName().c_str());
if (i == selectedBtn) {
if (pressedButtons != WUPS_CONFIG_BUTTON_NONE) {
config_items[i]->onButtonPressed(pressedButtons);
}
DrawUtils::print(SCREEN_WIDTH - 16*2, index + 8 + 24, config_items[i]->getCurrentValueSelectedDisplay().c_str(), true);
}
else {
DrawUtils::print(SCREEN_WIDTH - 16*2, index + 8 + 24, config_items[i]->getCurrentValueDisplay().c_str(), true);
DrawUtils::print(SCREEN_WIDTH - 16 * 2, index + 8 + 24, config_items[i]->getCurrentValueSelectedDisplay().c_str(), true);
} else {
DrawUtils::print(SCREEN_WIDTH - 16 * 2, index + 8 + 24, config_items[i]->getCurrentValueDisplay().c_str(), true);
}
index += 42 + 8;
}
@ -528,7 +506,7 @@ void ConfigUtils::displayMenu() {
DrawUtils::setFontColor(COLOR_TEXT);
std::string headline;
StringTools::strprintf(headline, "%s - %s",currentConfig->config->getName().c_str(), currentCategory->getName().c_str());
StringTools::strprintf(headline, "%s - %s", currentConfig->config->getName().c_str(), currentCategory->getName().c_str());
// draw top bar
DrawUtils::setFontSize(24);
DrawUtils::print(16, 6 + 24, headline.c_str());
@ -537,7 +515,7 @@ void ConfigUtils::displayMenu() {
DrawUtils::print(SCREEN_WIDTH - 16, 8 + 24, currentConfig->version.c_str(), true);
// draw bottom bar
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8*2, 3, COLOR_BLACK);
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK);
DrawUtils::setFontSize(18);
DrawUtils::print(16, SCREEN_HEIGHT - 8, "\ue07d Navigate ");
DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 8, "\ue001 Back", true);
@ -553,7 +531,7 @@ void ConfigUtils::displayMenu() {
// draw home button
DrawUtils::setFontSize(18);
const char* exitHint = "\ue044 Exit";
const char *exitHint = "\ue044 Exit";
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHint) / 2, SCREEN_HEIGHT - 8, exitHint, true);
DrawUtils::endDraw();
@ -561,10 +539,10 @@ void ConfigUtils::displayMenu() {
}
}
for (const auto& element : configs) {
for (const auto& cat : element.config->getCategories()) {
for (const auto& item : cat->getItems()) {
if(item->isDirty()){
for (const auto &element: configs) {
for (const auto &cat: element.config->getCategories()) {
for (const auto &item: cat->getItems()) {
if (item->isDirty()) {
item->callCallback();
}
}
@ -589,36 +567,35 @@ void ConfigUtils::displayMenu() {
}
}
for (const auto& element : configs) {
for (const auto &element: configs) {
DEBUG_FUNCTION_LINE("Delete %08X", element.config);
delete element.config;
}
}
void ConfigUtils::openConfigMenu()
{
void ConfigUtils::openConfigMenu() {
bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled();
OSScreenInit();
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
void* screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100);
void* screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100);
void *screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100);
void *screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100);
bool skipScreen0Free = false;
bool skipScreen1Free = false;
if (!screenbuffer0 || !screenbuffer1) {
if(screenbuffer0 == nullptr){
if(storedTVBuffer.buffer_size >= screen_buf0_size){
if (screenbuffer0 == nullptr) {
if (storedTVBuffer.buffer_size >= screen_buf0_size) {
screenbuffer0 = storedTVBuffer.buffer;
skipScreen0Free = true;
DEBUG_FUNCTION_LINE("Use storedTVBuffer");
}
}
if(screenbuffer1 == nullptr){
if(storedDRCBuffer.buffer_size >= screen_buf1_size){
if (screenbuffer1 == nullptr) {
if (storedDRCBuffer.buffer_size >= screen_buf1_size) {
screenbuffer1 = storedDRCBuffer.buffer;
skipScreen1Free = true;
DEBUG_FUNCTION_LINE("Use storedDRCBuffer");
@ -658,22 +635,20 @@ void ConfigUtils::openConfigMenu()
error_exit:
if(storedTVBuffer.buffer != nullptr) {
if (storedTVBuffer.buffer != nullptr) {
GX2SetTVBuffer(storedTVBuffer.buffer, storedTVBuffer.buffer_size, static_cast<GX2TVRenderMode>(storedTVBuffer.mode),
storedTVBuffer.surface_format, storedTVBuffer.buffering_mode);
}
if(storedDRCBuffer.buffer != nullptr) {
if (storedDRCBuffer.buffer != nullptr) {
GX2SetDRCBuffer(storedDRCBuffer.buffer, storedDRCBuffer.buffer_size, static_cast<GX2DrcRenderMode>(storedDRCBuffer.mode),
storedDRCBuffer.surface_format, storedDRCBuffer.buffering_mode);
}
if (!skipScreen0Free && screenbuffer0) {
MEMFreeToMappedMemory(screenbuffer0);
screenbuffer0 = nullptr;
}
if (!skipScreen1Free && screenbuffer1) {
MEMFreeToMappedMemory(screenbuffer1);
screenbuffer1 = nullptr;
}
}

View File

@ -3,7 +3,7 @@
#include <gx2/enum.h>
struct StoredBuffer {
void* buffer;
void *buffer;
uint32_t buffer_size;
uint32_t mode;
GX2SurfaceFormat surface_format;

View File

@ -10,8 +10,12 @@ union Color {
explicit Color(uint32_t color) {
this->color = color;
}
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
this->r = r; this->g = g; this->b = b; this->a = a;
this->r = r;
this->g = g;
this->b = b;
this->a = a;
}
uint32_t color{};
@ -25,33 +29,47 @@ union Color {
class DrawUtils {
public:
static void initBuffers(void* tvBuffer, uint32_t tvSize, void* drcBuffer, uint32_t drcSize);
static void initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize);
static void beginDraw();
static void endDraw();
static void clear(Color col);
static void drawPixel(uint32_t x, uint32_t y, Color col) { drawPixel(x, y, col.r, col.g, col.b, col.a); }
static void drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
static void drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col);
static void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col);
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t* data);
static void drawPNG(uint32_t x, uint32_t y, const uint8_t* data);
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data);
static void drawPNG(uint32_t x, uint32_t y, const uint8_t *data);
static void initFont();
static void deinitFont();
static void setFontSize(uint32_t size);
static void setFontColor(Color col);
static void print(uint32_t x, uint32_t y, const char* string, bool alignRight = false);
static void print(uint32_t x, uint32_t y, const wchar_t* string, bool alignRight = false);
static uint32_t getTextWidth(const char* string);
static uint32_t getTextWidth(const wchar_t* string);
static void print(uint32_t x, uint32_t y, const char *string, bool alignRight = false);
static void print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight = false);
static uint32_t getTextWidth(const char *string);
static uint32_t getTextWidth(const wchar_t *string);
private:
static bool isBackBuffer;
static uint8_t* tvBuffer;
static uint8_t *tvBuffer;
static uint32_t tvSize;
static uint8_t* drcBuffer;
static uint8_t *drcBuffer;
static uint32_t drcSize;
};

View File

@ -1,14 +1,12 @@
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <coreinit/cache.h>
#include "utils/logger.h"
#include "elfio/elfio.hpp"
#include "ElfUtils.h"
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type, uint8_t trampolinId) {
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
RelocationType reloc_type, uint8_t trampolinId) {
if (type == R_PPC_NONE) {
return true;
}

View File

@ -46,5 +46,6 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
class ElfUtils {
public:
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type, uint8_t trampolinId);
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
RelocationType reloc_type, uint8_t trampolinId);
};

View File

@ -6,23 +6,23 @@
#include "fs/CFile.hpp"
#include "fs/FSUtils.h"
static void processJson(wups_storage_item_t* items, nlohmann::json json) {
static void processJson(wups_storage_item_t *items, nlohmann::json json) {
if (items == nullptr) {
return;
}
items->data = (wups_storage_item_t*) malloc(json.size() * sizeof(wups_storage_item_t));
items->data = (wups_storage_item_t *) malloc(json.size() * sizeof(wups_storage_item_t));
items->data_size = json.size();
uint32_t index = 0;
for (auto it = json.begin(); it != json.end(); ++it) {
wups_storage_item_t* item = &((wups_storage_item_t*) items->data)[index];
wups_storage_item_t *item = &((wups_storage_item_t *) items->data)[index];
item->type = WUPS_STORAGE_TYPE_INVALID;
item->pending_delete = false;
item->data = nullptr;
item->key = nullptr;
item->key = (char*) malloc(it.key().size() + 1);
item->key = (char *) malloc(it.key().size() + 1);
strcpy(item->key, it.key().c_str());
if (it.value().is_string()) {
@ -30,12 +30,12 @@ static void processJson(wups_storage_item_t* items, nlohmann::json json) {
uint32_t size = it.value().get<std::string>().size() + 1;
item->data = malloc(size);
item->data_size = size;
strcpy((char*) item->data, it.value().get<std::string>().c_str());
strcpy((char *) item->data, it.value().get<std::string>().c_str());
} else if (it.value().is_number_integer()) {
item->type = WUPS_STORAGE_TYPE_INT;
item->data = malloc(sizeof(int32_t));
item->data_size = sizeof(int32_t);
*(int32_t*) item->data = it.value().get<int32_t>();
*(int32_t *) item->data = it.value().get<int32_t>();
} else if (it.value().is_object()) {
if (it.value().size() > 0) {
item->type = WUPS_STORAGE_TYPE_ITEM;
@ -48,7 +48,7 @@ static void processJson(wups_storage_item_t* items, nlohmann::json json) {
}
}
int StorageUtils::OpenStorage(const char* plugin_id, wups_storage_item_t* items) {
int StorageUtils::OpenStorage(const char *plugin_id, wups_storage_item_t *items) {
if (!plugin_id || !items) {
return WUPS_STORAGE_ERROR_INVALID_BACKEND_PARAMS;
}
@ -58,7 +58,7 @@ int StorageUtils::OpenStorage(const char* plugin_id, wups_storage_item_t* items)
nlohmann::json j;
CFile file(filePath, CFile::ReadOnly);
if (file.isOpen() && file.size() > 0) {
uint8_t* json_data = new uint8_t[file.size() + 1];
uint8_t *json_data = new uint8_t[file.size() + 1];
json_data[file.size()] = '\0';
file.read(json_data, file.size());
@ -80,7 +80,7 @@ int StorageUtils::OpenStorage(const char* plugin_id, wups_storage_item_t* items)
return WUPS_STORAGE_ERROR_SUCCESS;
}
static nlohmann::json processItems(wups_storage_item_t* items) {
static nlohmann::json processItems(wups_storage_item_t *items) {
nlohmann::json json;
if (!items) {
@ -88,16 +88,16 @@ static nlohmann::json processItems(wups_storage_item_t* items) {
}
for (uint32_t i = 0; i < items->data_size; i++) {
wups_storage_item_t* item = &((wups_storage_item_t*) items->data)[i];
wups_storage_item_t *item = &((wups_storage_item_t *) items->data)[i];
if (item->pending_delete || item->type == WUPS_STORAGE_TYPE_INVALID || !item->data || !item->key) {
continue;
}
if (item->type == WUPS_STORAGE_TYPE_STRING) {
json[item->key] = (const char*) item->data;
json[item->key] = (const char *) item->data;
} else if (item->type == WUPS_STORAGE_TYPE_INT) {
json[item->key] = *(int32_t*) item->data;
json[item->key] = *(int32_t *) item->data;
} else if (item->type == WUPS_STORAGE_TYPE_ITEM) {
json[item->key] = processItems(item);
} else {
@ -107,7 +107,7 @@ static nlohmann::json processItems(wups_storage_item_t* items) {
return json;
}
int StorageUtils::CloseStorage(const char* plugin_id, wups_storage_item_t* items) {
int StorageUtils::CloseStorage(const char *plugin_id, wups_storage_item_t *items) {
if (!plugin_id || !items) {
return WUPS_STORAGE_ERROR_INVALID_BACKEND_PARAMS;
}
@ -127,7 +127,7 @@ int StorageUtils::CloseStorage(const char* plugin_id, wups_storage_item_t* items
j["storageitems"] = processItems(items);
std::string jsonString = j.dump(4);
file.write((const uint8_t*) jsonString.c_str(), jsonString.size());
file.write((const uint8_t *) jsonString.c_str(), jsonString.size());
file.close();
return WUPS_STORAGE_ERROR_SUCCESS;
}

View File

@ -4,6 +4,7 @@
class StorageUtils {
public:
static int OpenStorage(const char* plugin_id, wups_storage_item_t* items);
static int CloseStorage(const char* plugin_id, wups_storage_item_t* items);
static int OpenStorage(const char *plugin_id, wups_storage_item_t *items);
static int CloseStorage(const char *plugin_id, wups_storage_item_t *items);
};

View File

@ -25,14 +25,11 @@
***************************************************************************/
#include <vector>
#include <string>
#include <cstdarg>
#include <cstdlib>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <strings.h>
#include <wut_types.h>
#include <stdio.h>
#include <cstdio>
#include <utils/StringTools.h>
@ -78,7 +75,7 @@ const char *StringTools::fmt(const char *format, ...) {
}
va_end(va);
return NULL;
return nullptr;
}
const wchar_t *StringTools::wfmt(const char *format, ...) {
@ -107,7 +104,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
}
va_end(va);
return NULL;
return nullptr;
}
int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
@ -165,11 +162,11 @@ int32_t StringTools::strtokcmp(const char *string, const char *compare, const ch
char *strTok = strtok(TokCopy, separator);
while (strTok != NULL) {
while (strTok != nullptr) {
if (strcasecmp(string, strTok) == 0) {
return 0;
}
strTok = strtok(NULL, separator);
strTok = strtok(nullptr, separator);
}
return -1;

View File

@ -10,13 +10,13 @@
#include <wums.h>
void fillPluginInformation(plugin_information *out, PluginMetaInformation *metaInformation) {
strncpy(out->author, metaInformation->getAuthor().c_str(), 255);
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), 255);
strncpy(out->description, metaInformation->getDescription().c_str(), 255);
strncpy(out->name, metaInformation->getName().c_str(), 255);
strncpy(out->license, metaInformation->getLicense().c_str(), 255);
strncpy(out->version, metaInformation->getVersion().c_str(), 255);
strncpy(out->id, metaInformation->getId().c_str(), 255);
strncpy(out->author, metaInformation->getAuthor().c_str(), sizeof(out->author) - 1);
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), sizeof(out->buildTimestamp) - 1);
strncpy(out->description, metaInformation->getDescription().c_str(), sizeof(out->description) - 1);
strncpy(out->name, metaInformation->getName().c_str(), sizeof(out->name) - 1);
strncpy(out->license, metaInformation->getLicense().c_str(), sizeof(out->license) - 1);
strncpy(out->version, metaInformation->getVersion().c_str(), sizeof(out->version) - 1);
strncpy(out->id, metaInformation->getId().c_str(), sizeof(out->id) - 1);
out->size = metaInformation->getSize();
}
@ -26,7 +26,6 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
plugin_data_handle handle = plugin_data_handle_list[i];
auto *pluginData = (PluginData *) handle;
DEBUG_FUNCTION_LINE("Saving plugin data %08X", pluginData);
PluginDataPersistence::save(&gLinkOnReload.plugin_data[gLinkOnReload.number_used_plugins], *pluginData);
gLinkOnReload.number_used_plugins++;
@ -36,6 +35,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
}
DCFlushRange(&gLinkOnReload, sizeof(gLinkOnReload));
} else {
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
}
return PLUGIN_BACKEND_API_ERROR_NONE;
@ -46,7 +46,6 @@ extern "C" PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_cont
for (uint32_t i = 0; i < handle_list_size; i++) {
auto handle = handle_list[i];
auto *pluginContainer = (PluginContainer *) handle;
DEBUG_FUNCTION_LINE("Delete plugin container: %08X", pluginContainer);
delete pluginContainer;
}
}
@ -58,7 +57,6 @@ extern "C" PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_hand
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
auto handle = plugin_data_handle_list[i];
auto *pluginData = (PluginData *) handle;
DEBUG_FUNCTION_LINE("Delete plugin data: %08X", pluginData);
delete pluginData;
}
}
@ -78,16 +76,15 @@ extern "C" PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationIn
}
if (!pluginData) {
DEBUG_FUNCTION_LINE("Failed to alloc plugin data");
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC");
return PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC;
}
if (out == nullptr) {
DEBUG_FUNCTION_LINE("out was NULL");
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
} else {
auto *pluginDataHandle = new PluginData(pluginData.value());
DEBUG_FUNCTION_LINE("Saving plugin data handle: %08X", pluginDataHandle);
*out = (uint32_t) pluginDataHandle;
}
@ -102,27 +99,25 @@ extern "C" PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(plugin_data_ha
return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output);
}
extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char* path, char *buffer, size_t size, plugin_information *output) {
extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output) {
std::optional<PluginMetaInformation> pluginInfo;
if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH && path != nullptr) {
std::string pathStr(path);
DEBUG_FUNCTION_LINE("PLUGIN_INFORMATION_INPUT_TYPE_PATH %s", path);
pluginInfo = PluginMetaInformationFactory::loadPlugin(pathStr);
} else if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_BUFFER && buffer != nullptr && size > 0) {
DEBUG_FUNCTION_LINE("PLUGIN_INFORMATION_INPUT_TYPE_BUFFER %08X %d", buffer, size);
pluginInfo = PluginMetaInformationFactory::loadPlugin(buffer, size);
} else {
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
}
if (!pluginInfo) {
DEBUG_FUNCTION_LINE("Failed to load plugin meta information");
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND");
return PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND;
}
DEBUG_FUNCTION_LINE("Loaded plugin meta information");
if (output == nullptr) {
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
} else {
fillPluginInformation(output, &pluginInfo.value());
@ -145,10 +140,10 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const
auto handle = plugin_container_handle_list[i];
auto *container = (PluginContainer *) handle;
auto *pluginData = new PluginData(container->getPluginData());
DEBUG_FUNCTION_LINE("Created pluginData [%08X]", pluginData);
plugin_data_list[i] = (uint32_t) pluginData;
}
} else {
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
res = PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
}
return res;
@ -171,6 +166,7 @@ extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_contain
plugin_information_list[i].size = container->metaInformation.getSize();
}
} else {
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
res = PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
}
return res;
@ -182,7 +178,6 @@ extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handl
for (auto &plugin: plugins) {
if (counter < buffer_size) {
auto *container = new PluginContainer(plugin);
DEBUG_FUNCTION_LINE("Created container [%08X]", container);
io_handles[counter] = (uint32_t) container;
counter++;
} else {

View File

@ -16,11 +16,11 @@ extern "C" {
#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); \
} while (0);
} while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);
} while (0)
#ifdef __cplusplus
}