2023-01-26 12:52:00 +01:00
|
|
|
#include "config.h"
|
2023-01-26 13:21:35 +01:00
|
|
|
#include "common.h"
|
2023-01-26 12:52:00 +01:00
|
|
|
#include "retain_vars.hpp"
|
|
|
|
#include "utils/WUPSConfigItemButtonCombo.h"
|
|
|
|
#include "utils/logger.h"
|
2023-01-26 13:21:35 +01:00
|
|
|
#include "utils/utils.h"
|
2023-01-26 12:52:00 +01:00
|
|
|
#include <vpad/input.h>
|
|
|
|
#include <wups.h>
|
2023-12-14 21:29:11 +01:00
|
|
|
#include <wups/config/WUPSConfigCategory.h>
|
2023-01-26 12:52:00 +01:00
|
|
|
#include <wups/config/WUPSConfigItemBoolean.h>
|
|
|
|
#include <wups/config/WUPSConfigItemIntegerRange.h>
|
|
|
|
#include <wups/config/WUPSConfigItemMultipleValues.h>
|
|
|
|
#include <wups/storage.h>
|
|
|
|
|
|
|
|
WUPS_USE_STORAGE("screenshot_plugin");
|
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle);
|
|
|
|
|
|
|
|
void ConfigMenuClosedCallback() {
|
|
|
|
WUPSStorageError storageRes;
|
|
|
|
if ((storageRes = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to close storage %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-26 12:52:00 +01:00
|
|
|
void InitConfig() {
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSConfigAPIOptionsV1 configOptions = {.name = "Screenshot Plugin"};
|
|
|
|
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
|
|
|
|
}
|
|
|
|
|
2023-01-26 12:52:00 +01:00
|
|
|
gButtonCombo = VPAD_BUTTON_TV;
|
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSStorageError storageRes;
|
|
|
|
if ((storageRes = WUPSStorageAPI::GetOrStoreDefault(ENABLED_CONFIG_STRING, gEnabled, ENABLED_CONFIG_DEFAULT)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to GetOrStoreDefault value %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
if ((storageRes = WUPSStorageAPI::GetOrStoreDefault(FORMAT_CONFIG_STRING, gOutputFormat, FORMAT_CONFIG_DEFAULT)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to GetOrStoreDefault value %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
if ((storageRes = WUPSStorageAPI::GetOrStoreDefault(QUALITY_CONFIG_STRING, gQuality, QUALITY_CONFIG_DEFAULT)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to GetOrStoreDefault value %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
if ((storageRes = WUPSStorageAPI::GetOrStoreDefault(SCREEN_CONFIG_STRING, gImageSource, SCREEN_CONFIG_DEFAULT)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to GetOrStoreDefault value %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
if ((storageRes = WUPSStorageAPI::GetOrStoreDefault<uint32_t>(BUTTON_COMBO_CONFIG_STRING, gButtonCombo, BUTTON_COMBO_CONFIG_DEFAULT)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to GetOrStoreDefault value %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((storageRes = WUPSStorageAPI::GetOrStoreDefault(RESERVED_BIT_USAGE_CONFIG_STRING, gReservedBitUsage, RESERVED_BIT_USAGE_CONFIG_DEFAULT)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to GetOrStoreDefault value %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((storageRes = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to save storage %s (%d)", WUPSStorageAPI::GetStatusStr(storageRes).data(), storageRes);
|
2023-01-26 12:52:00 +01:00
|
|
|
}
|
|
|
|
|
2023-01-26 13:04:33 +01:00
|
|
|
if (gButtonCombo & VPAD_BUTTON_TV) {
|
|
|
|
DEBUG_FUNCTION_LINE("Block TV Menu");
|
|
|
|
VPADSetTVMenuInvalid(VPAD_CHAN_0, true);
|
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE("Unblock TV Menu");
|
|
|
|
VPADSetTVMenuInvalid(VPAD_CHAN_0, false);
|
|
|
|
}
|
|
|
|
|
2023-01-26 12:52:00 +01:00
|
|
|
if (gOutputFormat >= 3) {
|
|
|
|
gOutputFormat = IMAGE_OUTPUT_FORMAT_JPEG;
|
|
|
|
}
|
|
|
|
if (gQuality < 10) {
|
|
|
|
gQuality = 10;
|
|
|
|
} else if (gQuality > 100) {
|
|
|
|
gQuality = 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void multipleValueItemCallback(ConfigItemMultipleValues *item, uint32_t newValue) {
|
2023-12-14 21:29:11 +01:00
|
|
|
if (item && item->identifier) {
|
2023-01-26 12:52:00 +01:00
|
|
|
DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue);
|
2023-12-14 21:29:11 +01:00
|
|
|
if (std::string_view(item->identifier) == FORMAT_CONFIG_STRING) {
|
2023-01-26 12:52:00 +01:00
|
|
|
gOutputFormat = (ImageOutputFormatEnum) newValue;
|
|
|
|
|
|
|
|
if (gOutputFormat >= 3) {
|
|
|
|
gOutputFormat = IMAGE_OUTPUT_FORMAT_JPEG;
|
|
|
|
}
|
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSStorageError err;
|
|
|
|
if ((err = WUPSStorageAPI::Store(item->identifier, gOutputFormat)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to store item %s (newValue: %d): %s", item->identifier, gOutputFormat, WUPSStorageAPI::GetStatusStr(err).data());
|
|
|
|
}
|
|
|
|
} else if (std::string_view(item->identifier) == SCREEN_CONFIG_STRING) {
|
2023-01-26 12:52:00 +01:00
|
|
|
gImageSource = (ImageSourceEnum) newValue;
|
|
|
|
|
|
|
|
if (gImageSource >= 3) {
|
|
|
|
gImageSource = IMAGE_SOURCE_TV_AND_DRC;
|
|
|
|
}
|
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSStorageError err;
|
|
|
|
if ((err = WUPSStorageAPI::Store(item->identifier, gImageSource)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to store item %s (newValue: %d): %s", item->identifier, gImageSource, WUPSStorageAPI::GetStatusStr(err).data());
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void integerRangeItemCallback(ConfigItemIntegerRange *item, int32_t newValue) {
|
2023-12-14 21:29:11 +01:00
|
|
|
if (item && item->identifier) {
|
2023-01-26 12:52:00 +01:00
|
|
|
DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue);
|
2023-12-14 21:29:11 +01:00
|
|
|
if (std::string_view(item->identifier) == QUALITY_CONFIG_STRING) {
|
2023-01-26 12:52:00 +01:00
|
|
|
gQuality = (ImageOutputFormatEnum) newValue;
|
|
|
|
|
|
|
|
if (gQuality < 10) {
|
|
|
|
gQuality = 10;
|
|
|
|
} else if (gQuality > 100) {
|
|
|
|
gQuality = 100;
|
|
|
|
}
|
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSStorageError err;
|
|
|
|
if ((err = WUPSStorageAPI::Store(item->identifier, gQuality)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to store item %s (newValue: %d): %s", item->identifier, gQuality, WUPSStorageAPI::GetStatusStr(err).data());
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void boolItemCallback(ConfigItemBoolean *item, bool newValue) {
|
2023-12-14 21:29:11 +01:00
|
|
|
if (item && item->identifier) {
|
2023-01-26 12:52:00 +01:00
|
|
|
DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue);
|
2023-12-14 21:29:11 +01:00
|
|
|
if (std::string_view(item->identifier) == ENABLED_CONFIG_STRING) {
|
2023-01-26 12:52:00 +01:00
|
|
|
gEnabled = newValue;
|
2023-01-26 13:21:35 +01:00
|
|
|
if (gEnabled) {
|
|
|
|
InitNotificationModule();
|
|
|
|
}
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSStorageError err;
|
|
|
|
if ((err = WUPSStorageAPI::Store(item->identifier, gEnabled)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to store item %s (newValue: %d): %s", item->identifier, gEnabled, WUPSStorageAPI::GetStatusStr(err).data());
|
|
|
|
}
|
|
|
|
} else if (std::string_view(item->identifier) == RESERVED_BIT_USAGE_CONFIG_STRING) {
|
2023-01-26 12:52:00 +01:00
|
|
|
gReservedBitUsage = newValue;
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSStorageError err;
|
|
|
|
if ((err = WUPSStorageAPI::Store(item->identifier, gReservedBitUsage)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to store item %s (newValue: %d): %s", item->identifier, gReservedBitUsage, WUPSStorageAPI::GetStatusStr(err).data());
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void buttonComboItemChanged(ConfigItemButtonCombo *item, uint32_t newValue) {
|
2023-12-14 21:29:11 +01:00
|
|
|
if (item && item->identifier) {
|
|
|
|
DEBUG_FUNCTION_LINE("New value in %s changed: %08X", item->configId, newValue);
|
|
|
|
if (std::string_view(item->identifier) == BUTTON_COMBO_CONFIG_STRING) {
|
2023-01-26 12:52:00 +01:00
|
|
|
gButtonCombo = newValue;
|
2023-01-26 13:04:33 +01:00
|
|
|
if (gButtonCombo & VPAD_BUTTON_TV) {
|
|
|
|
DEBUG_FUNCTION_LINE("Block TV Menu");
|
|
|
|
VPADSetTVMenuInvalid(VPAD_CHAN_0, true);
|
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE("Unblock TV Menu");
|
|
|
|
VPADSetTVMenuInvalid(VPAD_CHAN_0, false);
|
|
|
|
}
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSStorageError err;
|
|
|
|
if ((err = WUPSStorageAPI::Store(item->identifier, gButtonCombo)) != WUPS_STORAGE_ERROR_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to store item %s (newValue: %08X): %s", item->identifier, gButtonCombo, WUPSStorageAPI::GetStatusStr(err).data());
|
|
|
|
}
|
2023-01-26 12:52:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) {
|
|
|
|
try {
|
|
|
|
WUPSConfigCategory root = WUPSConfigCategory(rootHandle);
|
|
|
|
|
|
|
|
root.add(WUPSConfigItemBoolean::Create(ENABLED_CONFIG_STRING,
|
|
|
|
"Enabled",
|
|
|
|
ENABLED_CONFIG_DEFAULT, gEnabled,
|
|
|
|
&boolItemCallback));
|
|
|
|
|
|
|
|
root.add(WUPSConfigItemButtonCombo::Create(BUTTON_COMBO_CONFIG_STRING,
|
|
|
|
"Button combo",
|
|
|
|
BUTTON_COMBO_CONFIG_DEFAULT, gButtonCombo,
|
|
|
|
&buttonComboItemChanged));
|
|
|
|
|
|
|
|
constexpr WUPSConfigItemMultipleValues::ValuePair possibleScreenValues[] = {
|
|
|
|
{IMAGE_SOURCE_TV_AND_DRC, "TV & GamePad"},
|
|
|
|
{IMAGE_SOURCE_TV, "TV only"},
|
|
|
|
{IMAGE_SOURCE_DRC, "GamePad only"},
|
|
|
|
};
|
|
|
|
|
|
|
|
root.add(WUPSConfigItemMultipleValues::CreateFromValue(SCREEN_CONFIG_STRING,
|
|
|
|
"Screen",
|
|
|
|
SCREEN_CONFIG_DEFAULT, gImageSource,
|
|
|
|
possibleScreenValues,
|
|
|
|
&multipleValueItemCallback));
|
|
|
|
|
|
|
|
constexpr WUPSConfigItemMultipleValues::ValuePair possibleFormatValues[] = {
|
|
|
|
{IMAGE_OUTPUT_FORMAT_JPEG, "JPEG"},
|
|
|
|
{IMAGE_OUTPUT_FORMAT_PNG, "PNG"},
|
|
|
|
{IMAGE_OUTPUT_FORMAT_BMP, "BMP"}};
|
|
|
|
|
|
|
|
root.add(WUPSConfigItemMultipleValues::CreateFromValue(FORMAT_CONFIG_STRING,
|
|
|
|
"Output format",
|
|
|
|
FORMAT_CONFIG_DEFAULT, gOutputFormat,
|
|
|
|
possibleFormatValues,
|
|
|
|
&multipleValueItemCallback));
|
|
|
|
|
2024-03-02 11:22:16 +01:00
|
|
|
root.add(WUPSConfigItemIntegerRange::Create(QUALITY_CONFIG_STRING,
|
2023-12-14 21:29:11 +01:00
|
|
|
"JPEG quality",
|
2024-03-02 11:22:16 +01:00
|
|
|
QUALITY_CONFIG_DEFAULT, gQuality,
|
2023-12-14 21:29:11 +01:00
|
|
|
10, 100,
|
|
|
|
&integerRangeItemCallback));
|
|
|
|
root.add(WUPSConfigItemBoolean::Create(RESERVED_BIT_USAGE_CONFIG_STRING,
|
|
|
|
"Check ReservedBit for taking screenshots",
|
|
|
|
RESERVED_BIT_USAGE_CONFIG_DEFAULT, gReservedBitUsage,
|
|
|
|
&boolItemCallback));
|
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
2024-03-01 20:58:41 +01:00
|
|
|
OSReport("Exception: %s\n", e.what());
|
2023-12-14 21:29:11 +01:00
|
|
|
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
|
2023-01-26 12:52:00 +01:00
|
|
|
}
|
|
|
|
|
2023-12-14 21:29:11 +01:00
|
|
|
return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS;
|
2023-01-26 12:52:00 +01:00
|
|
|
}
|