Use std::list instead of array

This commit is contained in:
Maschell 2022-12-30 19:51:47 +01:00
parent c719b4c8ac
commit f94b857f12
2 changed files with 14 additions and 16 deletions

View File

@ -7,19 +7,18 @@ uint32_t FunctionAddressProvider::getEffectiveAddressOfFunction(function_replace
uint32_t real_addr = 0;
OSDynLoad_Module rpl_handle = nullptr;
OSDynLoad_Error err = OS_DYNLOAD_OK;
int32_t rpl_handles_size = sizeof rpl_handles / sizeof rpl_handles[0];
for (int32_t i = 0; i < rpl_handles_size; i++) {
if (rpl_handles[i].library == library) {
if (rpl_handles[i].handle == nullptr) {
DEBUG_FUNCTION_LINE_VERBOSE("Lets acquire handle for rpl: %s", rpl_handles[i].rplname);
err = OSDynLoad_IsModuleLoaded((char *) rpl_handles[i].rplname, &rpl_handles[i].handle);
for (auto &rplHandle : rpl_handles) {
if (rplHandle.library == library) {
if (rplHandle.handle == nullptr) {
DEBUG_FUNCTION_LINE_VERBOSE("Lets acquire handle for rpl: %s", rplHandle.rplname);
err = OSDynLoad_IsModuleLoaded((char *) rplHandle.rplname, &rplHandle.handle);
}
if (err != OS_DYNLOAD_OK || !rpl_handles[i].handle) {
DEBUG_FUNCTION_LINE_VERBOSE("%s is not loaded yet", rpl_handles[i].rplname, err, rpl_handles[i].handle);
if (err != OS_DYNLOAD_OK || !rplHandle.handle) {
DEBUG_FUNCTION_LINE_VERBOSE("%s is not loaded yet", rplHandle.rplname, err, rplHandle.handle);
return 0;
}
rpl_handle = rpl_handles[i].handle;
rpl_handle = rplHandle.handle;
break;
}
}
@ -50,13 +49,11 @@ uint32_t FunctionAddressProvider::getEffectiveAddressOfFunction(function_replace
}
void FunctionAddressProvider::resetHandles() {
int32_t rpl_handles_size = sizeof rpl_handles / sizeof rpl_handles[0];
for (int32_t i = 0; i < rpl_handles_size; i++) {
if (rpl_handles[i].handle != nullptr) {
DEBUG_FUNCTION_LINE_VERBOSE("Resetting handle for rpl: %s", rpl_handles[i].rplname);
for (auto &rplHandle : rpl_handles) {
if (rplHandle.handle != nullptr) {
DEBUG_FUNCTION_LINE_VERBOSE("Resetting handle for rpl: %s", rplHandle.rplname);
}
rpl_handles[i].handle = nullptr;
rplHandle.handle = nullptr;
}
}

View File

@ -3,6 +3,7 @@
#include <coreinit/dynload.h>
#include <cstdint>
#include <function_patcher/fpatching_defines.h>
#include <list>
typedef struct rpl_handling {
function_replacement_library_type_t library;
@ -15,7 +16,7 @@ public:
uint32_t getEffectiveAddressOfFunction(function_replacement_library_type_t library, const char *functionName);
void resetHandles();
rpl_handling rpl_handles[LIBRARY_OTHER] = {
std::list<rpl_handling> rpl_handles = {
{LIBRARY_AVM, "avm.rpl", nullptr},
{LIBRARY_CAMERA, "camera.rpl", nullptr},
{LIBRARY_COREINIT, "coreinit.rpl", nullptr},