2022-08-25 15:53:37 +02:00
|
|
|
#include "globals.h"
|
2019-11-24 14:35:38 +01:00
|
|
|
#include "utils/TcpReceiver.h"
|
2022-02-04 15:47:35 +01:00
|
|
|
#include "utils/logger.h"
|
2022-05-14 16:19:26 +02:00
|
|
|
#include <coreinit/debug.h>
|
|
|
|
#include <rpxloader/rpxloader.h>
|
2022-02-04 15:47:35 +01:00
|
|
|
#include <wups.h>
|
2022-10-06 23:09:33 +02:00
|
|
|
#include <wups/config/WUPSConfigItemBoolean.h>
|
2019-11-24 14:35:38 +01:00
|
|
|
|
|
|
|
WUPS_PLUGIN_NAME("Wiiload");
|
|
|
|
WUPS_PLUGIN_DESCRIPTION("Wiiload Server");
|
|
|
|
WUPS_PLUGIN_VERSION("0.1");
|
|
|
|
WUPS_PLUGIN_AUTHOR("Maschell");
|
|
|
|
WUPS_PLUGIN_LICENSE("GPL");
|
|
|
|
|
2021-09-24 20:51:39 +02:00
|
|
|
WUPS_USE_WUT_DEVOPTAB();
|
2019-11-24 14:35:38 +01:00
|
|
|
|
2022-10-06 23:09:33 +02:00
|
|
|
WUPS_USE_STORAGE("wiiload"); // Unqiue id for the storage api
|
|
|
|
#define WIILOAD_ENABLED_STRING "enabled"
|
|
|
|
|
2021-01-10 18:22:17 +01:00
|
|
|
TcpReceiver *thread = nullptr;
|
2019-11-24 14:35:38 +01:00
|
|
|
|
2022-05-14 16:19:26 +02:00
|
|
|
INITIALIZE_PLUGIN() {
|
|
|
|
RPXLoaderStatus error;
|
2022-08-25 15:59:48 +02:00
|
|
|
if ((error = RPXLoader_InitLibrary()) != RPX_LOADER_RESULT_SUCCESS) {
|
2022-05-14 16:19:26 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("WiiLoad Plugin: Failed to init RPXLoader. Error %d", error);
|
2022-08-25 15:53:37 +02:00
|
|
|
} else {
|
|
|
|
gLibRPXLoaderInitDone = true;
|
2022-05-14 16:19:26 +02:00
|
|
|
}
|
2022-10-06 12:19:26 +02:00
|
|
|
thread = nullptr;
|
2022-05-14 16:19:26 +02:00
|
|
|
}
|
|
|
|
|
2022-10-06 23:09:33 +02:00
|
|
|
void gServerEnabledChanged(ConfigItemBoolean *item, bool newValue) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("New value in gWiiloadServerEnabled: %d", newValue);
|
|
|
|
gWiiloadServerEnabled = newValue;
|
|
|
|
if (thread) {
|
|
|
|
delete thread;
|
|
|
|
thread = nullptr;
|
|
|
|
}
|
|
|
|
if (gWiiloadServerEnabled) {
|
|
|
|
DEBUG_FUNCTION_LINE("Starting server!");
|
|
|
|
thread = new (std::nothrow) TcpReceiver(4299);
|
|
|
|
if (thread == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to create wiiload thread");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE("Wiiload server has been stopped!");
|
|
|
|
}
|
|
|
|
// If the value has changed, we store it in the storage.
|
|
|
|
auto res = WUPS_StoreInt(nullptr, item->configId, gWiiloadServerEnabled);
|
|
|
|
if (res != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to store gWiiloadServerEnabled: %s (%d)", WUPS_GetStorageStatusStr(res), res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WUPS_GET_CONFIG() {
|
|
|
|
// We open the storage, so we can persist the configuration the user did.
|
|
|
|
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to open storage");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
WUPSConfigHandle config;
|
|
|
|
WUPSConfig_CreateHandled(&config, "Wiiload");
|
|
|
|
|
|
|
|
WUPSConfigCategoryHandle setting;
|
|
|
|
WUPSConfig_AddCategoryByNameHandled(config, "Settings", &setting);
|
|
|
|
WUPSConfigItemBoolean_AddToCategoryHandled(config, setting, WIILOAD_ENABLED_STRING, "Enable Wiiload", gWiiloadServerEnabled, &gServerEnabledChanged);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
WUPS_CONFIG_CLOSED() {
|
|
|
|
// Save all changes
|
|
|
|
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 11:55:58 +02:00
|
|
|
/* Entry point */
|
|
|
|
ON_APPLICATION_START() {
|
|
|
|
initLogging();
|
2022-10-06 23:09:33 +02:00
|
|
|
if (gWiiloadServerEnabled) {
|
|
|
|
DEBUG_FUNCTION_LINE("Start wiiload thread");
|
|
|
|
thread = new (std::nothrow) TcpReceiver(4299);
|
|
|
|
if (thread == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to create wiiload thread");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE("Wiiload server is disabled");
|
2022-10-06 23:07:36 +02:00
|
|
|
}
|
2019-11-24 14:35:38 +01:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:19:26 +02:00
|
|
|
ON_APPLICATION_ENDS() {
|
2022-10-06 23:07:36 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Stop wiiload thread!");
|
2022-10-06 11:55:58 +02:00
|
|
|
if (thread != nullptr) {
|
|
|
|
delete thread;
|
|
|
|
thread = nullptr;
|
|
|
|
}
|
2022-10-06 23:07:36 +02:00
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Done!");
|
2022-01-30 17:49:03 +01:00
|
|
|
deinitLogging();
|
2021-01-10 18:22:17 +01:00
|
|
|
}
|