Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement the Config API #63

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ASFLAGS := -g $(MACHDEP)
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
LIBDIRS := $(WUT_ROOT)

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
Expand Down
11 changes: 10 additions & 1 deletion include/wups.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@

#include "wups/common.h"
#include "wups/config.h"
#include "wups/config_imports.h"
#include "wups/config_api.h"
#include "wups/function_patching.h"
#include "wups/hooks.h"
#include "wups/meta.h"
#include "wups/storage.h"
#ifdef DEBUG
#include <coreinit/debug.h>
#endif

#ifdef DEBUG
#define WUPS_DEBUG_REPORT(fmt, ...) OSReport(fmt, ##__VA_ARGS__)
#else
#define WUPS_DEBUG_REPORT(fmt, ...)
#endif
121 changes: 117 additions & 4 deletions include/wups/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@
#define WUPS_CONFIG_BUTTON_MINUS (1 << 15)
typedef int32_t WUPSConfigButtons;

typedef enum WUPSConfigAPIStatus {
WUPSCONFIG_API_RESULT_SUCCESS = 0,
WUPSCONFIG_API_RESULT_INVALID_ARGUMENT = -0x01,
WUPSCONFIG_API_RESULT_OUT_OF_MEMORY = -0x03,
WUPSCONFIG_API_RESULT_NOT_FOUND = -0x06,
WUPSCONFIG_API_RESULT_INVALID_PLUGIN_IDENTIFIER = -0x70,
WUPSCONFIG_API_RESULT_MISSING_CALLBACK = -0x71,
WUPSCONFIG_API_RESULT_MODULE_NOT_FOUND = -0x80,
WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT = -0x81,
WUPSCONFIG_API_RESULT_UNSUPPORTED_VERSION = -0x82,
WUPSCONFIG_API_RESULT_UNSUPPORTED_COMMAND = -0x83,
WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED = -0x84,
WUPSCONFIG_API_RESULT_UNKNOWN_ERROR = -0x100,
} WUPSConfigAPIStatus;

typedef enum WUPSConfigAPICallbackStatus {
WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS = 0,
WUPSCONFIG_API_CALLBACK_RESULT_ERROR = -1,
} WUPSConfigAPICallbackStatus;

typedef struct {
int32_t (*getCurrentValueDisplay)(void *context, char *out_buf, int32_t out_size);

Expand All @@ -54,8 +74,101 @@ typedef struct {
void (*onButtonPressed)(void *context, WUPSConfigButtons button);

void (*onDelete)(void *context);
} WUPSConfigCallbacks_t;
} WUPSConfigAPIItemCallbacksV1;

#define WUPS_API_ITEM_OPTION_VERSION_V1 1
typedef struct WUPSConfigAPIItemOptionsV1 {
const char *displayName;
void *context;
WUPSConfigAPIItemCallbacksV1 callbacks;
} WUPSConfigAPIItemOptionsV1;

typedef struct WUPSConfigAPICreateItemOptions {
uint32_t version;
union {
WUPSConfigAPIItemOptionsV1 v1;
} data;
} WUPSConfigAPICreateItemOptions;

typedef uint32_t WUPSConfigAPIVersion;

typedef struct WUPSConfigItemHandle {
void *handle;
#ifdef __cplusplus
WUPSConfigItemHandle() {
handle = nullptr;
}
explicit WUPSConfigItemHandle(void *handle) : handle(handle) {}
bool operator==(const WUPSConfigItemHandle other) const {
return handle == other.handle;
}
bool operator==(const void *other) const {
return handle == other;
}
#endif
} WUPSConfigItemHandle;

typedef struct WUPSConfigHandle {
void *handle;
#ifdef __cplusplus
WUPSConfigHandle() {
handle = nullptr;
}
explicit WUPSConfigHandle(void *handle) : handle(handle) {}
bool operator==(const WUPSConfigHandle other) const {
return handle == other.handle;
}
bool operator==(const void *other) const {
return handle == other;
}
#endif
} WUPSConfigHandle;

typedef struct WUPSConfigCategoryHandle {
void *handle;
#ifdef __cplusplus
WUPSConfigCategoryHandle() {
handle = nullptr;
}
explicit WUPSConfigCategoryHandle(void *handle) : handle(handle) {}
bool operator==(const WUPSConfigCategoryHandle other) const {
return handle == other.handle;
}
bool operator==(const void *other) const {
return handle == other;
}
#endif
} WUPSConfigCategoryHandle;

#define WUPS_API_CATEGORY_OPTION_VERSION_V1 1

typedef struct WUPSConfigAPICreateCategoryOptionsV1 {
const char *name;
} WUPSConfigAPICreateCategoryOptionsV1;

typedef struct WUPSConfigAPICreateCategoryOptions {
uint32_t version;
union {
WUPSConfigAPICreateCategoryOptionsV1 v1;
} data;
} WUPSConfigAPICreateCategoryOptions;

#define WUPS_API_CONFIG_API_OPTION_VERSION_V1 1

typedef struct WUPSConfigAPIOptionsV1 {
const char *name;
} WUPSConfigAPIOptionsV1;

typedef struct WUPSConfigAPIOptions {
uint32_t version;
union {
WUPSConfigAPIOptionsV1 v1;
} data;
} WUPSConfigAPIOptions;

#define WUPS_CONFIG_API_VERSION_ERROR 0xFFFFFFFF

typedef uint32_t WUPSConfigItemHandle;
typedef uint32_t WUPSConfigHandle;
typedef uint32_t WUPSConfigCategoryHandle;
typedef struct wups_loader_init_config_args_t {
uint32_t arg_version;
uint32_t plugin_identifier;
} wups_loader_init_config_args_t;
16 changes: 0 additions & 16 deletions include/wups/config/WUPSConfigItemBoolean.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ bool WUPSConfigItemBoolean_AddToCategory(WUPSConfigCategoryHandle cat, const cha
bool WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback, const char *trueValue,
const char *falseValue);

#define WUPSConfigItemBoolean_AddToCategoryHandled(__config__, __cat__, __configIs__, __displayName__, __defaultValue__, __callback__) \
do { \
if (!WUPSConfigItemBoolean_AddToCategory(__cat__, __configIs__, __displayName__, __defaultValue__, __callback__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \
} while (0)

#define WUPSConfigItemBoolean_AddToCategoryHandledEx(__config__, __cat__, __configID__, __displayName__, __defaultValue__, __callback__, __trueValue__, __falseValue__) \
do { \
if (!WUPSConfigItemBoolean_AddToCategoryEx(__cat__, __configID__, __displayName__, __defaultValue__, __callback__, __trueValue__, __falseValue__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \
} while (0)

#ifdef __cplusplus
}
#endif
8 changes: 0 additions & 8 deletions include/wups/config/WUPSConfigItemIntegerRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandle cat, cons
int32_t defaultValue, int32_t minValue, int32_t maxValue,
IntegerRangeValueChangedCallback callback);

#define WUPSConfigItemIntegerRange_AddToCategoryHandled(__config__, __cat__, __configId__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__) \
do { \
if (!WUPSConfigItemIntegerRange_AddToCategory(__cat__, __configId__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \
} while (0)

#ifdef __cplusplus
}
#endif
12 changes: 3 additions & 9 deletions include/wups/config/WUPSConfigItemMultipleValues.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <wups.h>
#include <stdbool.h>
#include <stdint.h>
#include <wups/config.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -24,14 +26,6 @@ typedef void (*MultipleValuesChangedCallback)(ConfigItemMultipleValues *, uint32
bool WUPSConfigItemMultipleValues_AddToCategory(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, int defaultValueIndex, ConfigItemMultipleValuesPair *possibleValues,
int pairCount, MultipleValuesChangedCallback callback);

#define WUPSConfigItemMultipleValues_AddToCategoryHandled(__config__, __cat__, __configID__, __displayName__, __defaultValueIndex__, __possibleValues__, __pairCount__, __callback__) \
do { \
if (!WUPSConfigItemMultipleValues_AddToCategory(__cat__, __configID__, __displayName__, __defaultValueIndex__, __possibleValues__, __pairCount__, __callback__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \
} while (0)

#ifdef __cplusplus
}
#endif
8 changes: 0 additions & 8 deletions include/wups/config/WUPSConfigItemStub.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ typedef struct ConfigItemStub {

bool WUPSConfigItemStub_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName);

#define WUPSConfigItemStub_AddToCategoryHandled(__config__, __cat__, __configID__, __displayName__) \
do { \
if (!WUPSConfigItemStub_AddToCategory(__cat__, __configID__, __displayName__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \
} while (0)

#ifdef __cplusplus
}
#endif
52 changes: 52 additions & 0 deletions include/wups/config_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include "config.h"
#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef WUPSConfigAPICallbackStatus (*WUPSConfigAPI_MenuOpenedCallback)(WUPSConfigCategoryHandle root);
typedef void (*WUPSConfigAPI_MenuClosedCallback)();

WUPSConfigAPIStatus WUPSConfigAPI_InitEx(uint32_t pluginIdentifier, WUPSConfigAPIOptions, WUPSConfigAPI_MenuOpenedCallback, WUPSConfigAPI_MenuClosedCallback);

WUPSConfigAPIStatus WUPSConfigAPI_Init(WUPSConfigAPIOptionsV1 optionsV1, WUPSConfigAPI_MenuOpenedCallback openedCallback, WUPSConfigAPI_MenuClosedCallback closedCallback);

WUPSConfigAPIStatus WUPSConfigAPI_GetVersion(WUPSConfigAPIVersion *outVariable);

WUPSConfigAPIStatus WUPSConfigAPI_Category_CreateEx(WUPSConfigAPICreateCategoryOptions options, WUPSConfigCategoryHandle *out);

static inline WUPSConfigAPIStatus WUPSConfigAPI_Category_Create(WUPSConfigAPICreateCategoryOptionsV1 options, WUPSConfigCategoryHandle *out) {
WUPSConfigAPICreateCategoryOptions optionsWrapper = {
.version = WUPS_API_CATEGORY_OPTION_VERSION_V1,
.data = {.v1 = options},
};
return WUPSConfigAPI_Category_CreateEx(optionsWrapper, out);
}

WUPSConfigAPIStatus WUPSConfigAPI_Category_Destroy(WUPSConfigCategoryHandle handle);

WUPSConfigAPIStatus WUPSConfigAPI_Category_AddCategory(WUPSConfigCategoryHandle parentHandle, WUPSConfigCategoryHandle categoryHandle);

WUPSConfigAPIStatus WUPSConfigAPI_Category_AddItem(WUPSConfigCategoryHandle parentHandle, WUPSConfigItemHandle itemHandle);

WUPSConfigAPIStatus WUPSConfigAPI_Item_CreateEx(WUPSConfigAPICreateItemOptions options, WUPSConfigItemHandle *out);

static inline WUPSConfigAPIStatus WUPSConfigAPI_Item_Create(WUPSConfigAPIItemOptionsV1 options, WUPSConfigItemHandle *out) {
WUPSConfigAPICreateItemOptions itemOptions = {
.version = WUPS_API_ITEM_OPTION_VERSION_V1,
.data = {.v1 = options},
};
return WUPSConfigAPI_Item_CreateEx(itemOptions, out);
}

WUPSConfigAPIStatus WUPSConfigAPI_Item_Destroy(WUPSConfigItemHandle handle);

const char *WUPSConfigAPI_GetStatusStr(WUPSConfigAPIStatus status);

#ifdef __cplusplus
}
#endif
63 changes: 0 additions & 63 deletions include/wups/config_imports.h

This file was deleted.

Loading
Loading