forked from PretendoNetwork/Inkay
feat: Improvements in module exports
Add new `Inkay_GetStatus` which can be used for retrieving the status of the module. Also add better handling of module initialization, and show a notification from the plugin if the module can't be found.
This commit is contained in:
parent
d3ff378cc4
commit
7958373394
7 changed files with 104 additions and 4 deletions
|
|
@ -77,6 +77,7 @@ INITIALIZE_PLUGIN() {
|
|||
}
|
||||
|
||||
DEINITIALIZE_PLUGIN() {
|
||||
Inkay_Finalize();
|
||||
NotificationModule_DeInitLibrary();
|
||||
|
||||
WHBLogCafeDeinit();
|
||||
|
|
|
|||
|
|
@ -14,25 +14,54 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include <coreinit/dynload.h>
|
||||
|
||||
#include "Notification.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
static OSDynLoad_Module module;
|
||||
static void (*moduleInitialize)(bool) = nullptr;
|
||||
static InkayStatus (*moduleGetStatus)() = nullptr;
|
||||
|
||||
void Inkay_Initialize(bool apply_patches) {
|
||||
OSDynLoad_Module module;
|
||||
void (*moduleInitialize)(bool) = nullptr;
|
||||
if (module) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (OSDynLoad_Acquire("inkay", &module) != OS_DYNLOAD_OK) {
|
||||
DEBUG_FUNCTION_LINE("Failed to acquire module");
|
||||
ShowNotification("Cannot find Inkay module. Ensure the Inkay module is properly installed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (OSDynLoad_FindExport(module, OS_DYNLOAD_EXPORT_FUNC, "Inkay_Initialize", reinterpret_cast<void * *>(&moduleInitialize)) != OS_DYNLOAD_OK) {
|
||||
DEBUG_FUNCTION_LINE("Failed to find initialization function");
|
||||
ShowNotification("Cannot find Inkay module initialization function. Ensure the Inkay module is properly installed");
|
||||
OSDynLoad_Release(module);
|
||||
return;
|
||||
}
|
||||
|
||||
moduleInitialize(apply_patches);
|
||||
|
||||
OSDynLoad_Release(module);
|
||||
}
|
||||
|
||||
void Inkay_Finalize() {
|
||||
if (module) {
|
||||
OSDynLoad_Release(module);
|
||||
moduleInitialize = nullptr;
|
||||
moduleGetStatus = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
InkayStatus Inkay_GetStatus() {
|
||||
if (!module) {
|
||||
return InkayStatus::Error;
|
||||
}
|
||||
|
||||
if (!moduleGetStatus && OSDynLoad_FindExport(module, OS_DYNLOAD_EXPORT_FUNC, "Inkay_GetStatus", reinterpret_cast<void * *>(&moduleGetStatus)) != OS_DYNLOAD_OK) {
|
||||
DEBUG_FUNCTION_LINE("Failed to find status function");
|
||||
return InkayStatus::Error;
|
||||
}
|
||||
|
||||
return moduleGetStatus();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
enum class InkayStatus {
|
||||
Uninitialized, ///< The module isn't initialized
|
||||
Nintendo, ///< The module is initialized but hasn't applied any patches
|
||||
Pretendo, ///< The module is initialized and has applied the Pretendo patches
|
||||
|
||||
Error = -1 ///< Failed to retrieve the module status
|
||||
};
|
||||
|
||||
void Inkay_Initialize(bool apply_patches);
|
||||
void Inkay_Finalize();
|
||||
InkayStatus Inkay_GetStatus();
|
||||
|
|
|
|||
Loading…
Reference in a new issue