diff --git a/.vscode/settings.json b/.vscode/settings.json index ad01e7a..cd4e7cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -30,6 +30,7 @@ "config_mgr.h": "cpp", "scetypes.h": "c", "taihen.h": "c", - "fios2_types.h": "c" + "fios2_types.h": "c", + "display.h": "c" } } \ No newline at end of file diff --git a/QuickMenuReborn.emd b/QuickMenuReborn.emd index b19d7ab..9b2c5ae 100644 --- a/QuickMenuReborn.emd +++ b/QuickMenuReborn.emd @@ -23,3 +23,6 @@ Library: QuickMenuReborn function: QuickMenuRebornUpdateText nidvalue: 0x68680E2 Library: QuickMenuReborn function: QuickMenuRebornUpdatePlane nidvalue: 0xFC8EA5DB Library: QuickMenuReborn function: QuickMenuRebornRemoveSeparator nidvalue: 0x7550C9BF Library: QuickMenuReborn function: QuickMenuRebornGetCheckBoxState nidvalue: 0x65214907 +Library: QuickMenuReborn function: QuickMenuRebornAddAdvancedWidget nidvalue: 0xC698BC91 +Library: QuickMenuReborn function: QuickMenuRebornAddAdvancedWidgetWithStyleHash nidvalue: 0x5E63C077 +Library: QuickMenuReborn function: QuickMenuRebornSlider nidvalue: 0xB962832B diff --git a/QuickMenuReborn.yml b/QuickMenuReborn.yml index c132a0c..4390923 100644 --- a/QuickMenuReborn.yml +++ b/QuickMenuReborn.yml @@ -20,3 +20,6 @@ modules: QuickMenuRebornUpdatePlane: 0xFC8EA5DB QuickMenuRebornRemoveSeparator: 0x7550C9BF QuickMenuRebornGetCheckBoxState: 0x65214907 + QuickMenuRebornAddAdvancedWidget: 0xC698BC91 + QuickMenuRebornAddAdvancedWidgetWithStyleHash: 0x5E63C077 + QuickMenuRebornSlider: 0xB962832B diff --git a/exporter.py b/exporter.py index 0e9bd65..0e6b38b 100644 --- a/exporter.py +++ b/exporter.py @@ -3,8 +3,8 @@ EMD_PATH="QuickMenuReborn.emd" YML_PATH="QuickMenuReborn.yml" -EMD_START="Module: QuickMenuReborn major_version: 3 minor_version: 0\nsceModuleInfo_type: 6\nmodule_function: module_start localname: module_start\nmodule_function: module_stop localname: module_stop\n\nLibrary: QuickMenuReborn version: 1\nLibrary: QuickMenuReborn nidsuffix: \"\"\nLibrary: QuickMenuReborn attr: auto_export\n" LIB_NAME="QuickMenuReborn" +EMD_START="Module: " + LIB_NAME + " major_version: 3 minor_version: 0\nsceModuleInfo_type: 6\nmodule_function: module_start localname: module_start\nmodule_function: module_stop localname: module_stop\n\nLibrary: " + LIB_NAME + " version: 1\nLibrary: "+ LIB_NAME +" nidsuffix: \"\"\nLibrary: " + LIB_NAME + " attr: auto_export\n" functionNames=[ "QuickMenuRebornAddWidget", "QuickMenuRebornRemoveWidget", @@ -21,7 +21,10 @@ "QuickMenuRebornUpdateText", "QuickMenuRebornUpdatePlane", "QuickMenuRebornRemoveSeparator", - "QuickMenuRebornGetCheckBoxState" + "QuickMenuRebornGetCheckBoxState", + "QuickMenuRebornAddAdvancedWidget", + "QuickMenuRebornAddAdvancedWidgetWithStyleHash", + "QuickMenuRebornSlider" ] def getHash(string): diff --git a/src/quickmenureborn/c_types.h b/src/quickmenureborn/c_types.h index 65fc9f8..1f2deee 100644 --- a/src/quickmenureborn/c_types.h +++ b/src/quickmenureborn/c_types.h @@ -18,7 +18,8 @@ typedef enum button = 0, check_box, text, - plane + plane, + slidebar, } widget_type; typedef enum check_box_state @@ -54,6 +55,11 @@ typedef struct CheckBoxState state; } toggleData; +typedef struct +{ + void (*OnChange)(); +} slidebarData; + typedef struct { float r; @@ -73,7 +79,9 @@ typedef struct typedef struct { char type[256]; - char idType[256]; + char styleInfo[256]; + int useHash; + int hash; } advancedData; typedef struct @@ -96,6 +104,7 @@ typedef struct toggleData CheckBoxData; buttonData ButtonData; textData TextData; + slidebarData SlidebarData; } data; //BOOL: Set weather the advanced data is used diff --git a/src/quickmenureborn/qm_reborn.h b/src/quickmenureborn/qm_reborn.h index 6184ec3..16809dd 100644 --- a/src/quickmenureborn/qm_reborn.h +++ b/src/quickmenureborn/qm_reborn.h @@ -271,6 +271,26 @@ EXPORT int QuickMenuRebornUpdatePlane(const char *refID, vector4 *Size, vector4 */ EXPORT int QuickMenuRebornGetCheckBoxState(const char *refID); +/** + * + * @brief Add an advanced widget with stylehash directly + * + * @param refID Refrence ID of the widget + * @param parentRefID Refrence ID of the parent widget (pass NULL if none) + * @param Size Pointer to size of widget + * @param Position Pointer to position of widget + * @param Color Pointer to color of widget + * @param Type Type of widget + * @param styleHash Hash of the style of widget + * @param OnLoad Function to be called whenever widget is loaded in quick menu + * @todo + * @retval Bool: 0 or 1 on succes < 0 on error + * +*/ +EXPORT int QuickMenuRebornAddAdvancedWidgetWithStyleHash(const char *refID, const char *parentRefID, vector4 *Size, vector4 *Position, widgetColor *Color, const char *Type, int styleHash, void (*OnLoad)()); + +EXPORT int QuickMenuRebornSlider(const char *refID, const char *parentRefID, vector4 *Size, vector4 *Position, widgetColor *Color, void(*OnChange)(), void (*OnLoad)()); + #define COLOR_WHITE makeWidgetColor(1.0f, 1.0f, 1.0f, 1.0f) #define COLOR_RED makeWidgetColor(1.0f, 0.0f, 0.0f, 1.0f) #define COLOR_GREEN makeWidgetColor(0.0f, 1.0f, 0.0f, 1.0f) @@ -291,8 +311,8 @@ EXPORT int QuickMenuRebornGetCheckBoxState(const char *refID); #define makeCommonWidgetVector4Int(common) makeWidgetVector4(common##.0f, common##.0f, common##.0f, common##.0f) #define makeCommonWidgetColorInt(common) makeWidgetColor(common##.0f, common##.0f, common##.0f, common##.0f) -//Size of all the other planes in the quick menu (as close as I could get) -#define SCE_PLANE_WIDTH 825.0f +//Size of all the other planes in the quick menu +#define SCE_PLANE_WIDTH 835.0f #define CONFIG_MGR_ERROR_NOT_EXIST -1 #define CONFIG_MGR_ERROR_COULD_NOT_WRITE_FULL -2 diff --git a/src/user/event_handler.cpp b/src/user/event_handler.cpp index 024d146..e8a91b8 100644 --- a/src/user/event_handler.cpp +++ b/src/user/event_handler.cpp @@ -1,36 +1,40 @@ #include "event_handler.hpp" #include "config_mgr.h" - extern linked_list currentWidgets; +extern linked_list currentWidgets; - QMEventHandler::QMEventHandler() - { - eventHandler = onGet; - } +QMEventHandler::QMEventHandler() +{ + eventHandler = onGet; +} - void QMEventHandler::onGet(SceInt32 , Widget *self, SceInt32, ScePVoid puserData) +void QMEventHandler::onGet(SceInt32 , Widget *self, SceInt32, ScePVoid puserData) +{ + widgetData *widget = (widgetData *)puserData; + switch (widget->type) { - widgetData *widget = (widgetData *)puserData; - switch (widget->type) + case button: { - case button: - { - if(widget->data.ButtonData.onPress != NULL) widget->data.ButtonData.onPress(); - break; - } + if(widget->data.ButtonData.onPress != NULL) widget->data.ButtonData.onPress(); + break; + } - case check_box: - { - print("Setting checkbox state to %d\n", ((CheckBox *)self)->checked); - currentWidgets.update_checkbox_status(widget->refId, ((CheckBox *)self)->checked ? CHECKBOX_ON : CHECKBOX_OFF); - print("Got save ret = 0x%X\n", saveCheckBoxState(widget->refId, ((CheckBox *)self)->checked ? CHECKBOX_ON : CHECKBOX_OFF)); - if(widget->data.CheckBoxData.OnToggle != NULL) widget->data.CheckBoxData.OnToggle(((CheckBox *)self)->checked); - break; - } + case check_box: + { + currentWidgets.update_checkbox_status(widget->refId, ((CheckBox *)self)->checked ? CHECKBOX_ON : CHECKBOX_OFF); + if(widget->data.CheckBoxData.OnToggle != NULL) widget->data.CheckBoxData.OnToggle(((CheckBox *)self)->checked); + break; + } - default: - { - break; - } + case slidebar: + { + if(widget->data.SlidebarData.OnChange != NULL) widget->data.SlidebarData.OnChange(); + break; + } + + default: + { + break; } } +} diff --git a/src/user/export_handler.cpp b/src/user/export_handler.cpp index 8ad527e..3b5d101 100644 --- a/src/user/export_handler.cpp +++ b/src/user/export_handler.cpp @@ -161,20 +161,13 @@ int QuickMenuRebornPlane(const char *refID, const char *parentRefID, vector4 *Si int QuickMenuRebornSeparator(const char *refID) { char sepID[256] = {0}; - sce_paf_snprintf(sepID, sizeof(sepID), "qm_reborn_%s_separator_0", refID); + sce_paf_snprintf(sepID, sizeof(sepID), "qm_reborn_%s_separator", refID); //Invisible Spacer - vector4 size = makeWidgetVector4Int(825, 20, 0, 0), pos = makeCommonWidgetVector4Int(0); - widgetColor col = COLOR_TRANSPARENT; + vector4 size = makeWidgetVector4Int(835, 20, 0, 0), pos = makeCommonWidgetVector4Int(0); + widgetColor col = COLOR_WHITE; - QuickMenuRebornPlane(sepID, NULL, &size, &pos, &col, NULL); - - //Line - sce_paf_snprintf(sepID, sizeof(sepID), "qm_reborn_%s_separator_1", refID); - size = makeWidgetVector4(825.0f,2.0f,0.0f,0.0f); - pos = makeWidgetVector4(0,0,0,0); - col = makeWidgetColor(.75f,.75f,.75f,.75f); - QuickMenuRebornPlane(sepID, NULL, &size, &pos, &col, NULL); + QuickMenuRebornAddAdvancedWidgetWithStyleHash(sepID, NULL, &size, &pos, &col, "plane", 0x26C7781E, NULL); return 0; } @@ -231,7 +224,7 @@ int QuickMenuRebornUpdateCheckBox(const char *refID, vector4 *Size, vector4 *Pos widget.isAdvanced = 0; -return QuickMenuRebornUpdateWidget(&widget, flags); + return QuickMenuRebornUpdateWidget(&widget, flags); } int QuickMenuRebornUpdateText(const char *refID, vector4 *Size, vector4 *Position, widgetColor *Color, const char *Text, void (*OnLoad)(), int flags) @@ -253,11 +246,9 @@ int QuickMenuRebornUpdateText(const char *refID, vector4 *Size, vector4 *Positio } widget.OnLoad = OnLoad; - widget.isAdvanced = 0; -return QuickMenuRebornUpdateWidget(&widget, flags); - + return QuickMenuRebornUpdateWidget(&widget, flags); } int QuickMenuRebornUpdatePlane(const char *refID, vector4 *Size, vector4 *Position, widgetColor *Color, void (*OnLoad)(), int flags) @@ -276,11 +267,11 @@ int QuickMenuRebornUpdatePlane(const char *refID, vector4 *Size, vector4 *Positi widget.isAdvanced = 0; -return QuickMenuRebornUpdateWidget(&widget, flags); + return QuickMenuRebornUpdateWidget(&widget, flags); } -int QuickMenuRebornAddAdvancedWidget(const char *refID, const char *parentRefID, vector4 *Size, vector4 *Position, widgetColor *Color, const char *Type, const char *idType, void (*OnLoad)()) +int QuickMenuRebornAddAdvancedWidget(const char *refID, const char *parentRefID, vector4 *Size, vector4 *Position, widgetColor *Color, const char *Type, const char *styleInfo, void (*OnLoad)()) { widgetData widget; @@ -300,7 +291,7 @@ int QuickMenuRebornAddAdvancedWidget(const char *refID, const char *parentRefID, sceClibMemset(&widget.adata, 0, sizeof(widget.adata)); - sce_paf_strncpy(widget.adata.idType, idType, sizeof(widget.adata.idType)); + sce_paf_strncpy(widget.adata.styleInfo, styleInfo, sizeof(widget.adata.styleInfo)); sce_paf_strncpy(widget.adata.type, Type, sizeof(widget.adata.type)); widget.OnLoad = OnLoad; @@ -308,6 +299,62 @@ int QuickMenuRebornAddAdvancedWidget(const char *refID, const char *parentRefID, return registerWidget(&widget); } +int QuickMenuRebornAddAdvancedWidgetWithStyleHash(const char *refID, const char *parentRefID, vector4 *Size, vector4 *Position, widgetColor *Color, const char *Type, int styleHash, void (*OnLoad)()) +{ + widgetData widget; + + sceClibMemset(widget.refId, 0, sizeof(widget.refId)); + sce_paf_strncpy(widget.refId, refID, sizeof(widget.refId)); + + sceClibMemset(widget.parentRefId, 0, sizeof(widget.parentRefId)); + if(parentRefID != NULL) sce_paf_strncpy(widget.parentRefId, parentRefID, sizeof(widget.parentRefId)); + + if(Size != NULL) widget.size = *Size; + if(Position != NULL) widget.pos = *Position; + if(Color != NULL) widget.col = *Color; + + widget.isAdvanced = true; + + widget.hasParent = parentRefID != NULL; + + sceClibMemset(&widget.adata, 0, sizeof(widget.adata)); + + widget.adata.useHash = 1; + widget.adata.hash = styleHash; + sce_paf_strncpy(widget.adata.type, Type, sizeof(widget.adata.type)); + + widget.OnLoad = OnLoad; + + return registerWidget(&widget); +} + +int QuickMenuRebornSlider(const char *refID, const char *parentRefID, vector4 *Size, vector4 *Position, widgetColor *Color, void (*OnChange)(), void (*OnLoad)()) +{ + widgetData dat; + sceClibMemset(&dat, 0, sizeof(dat)); + + sceClibMemset(dat.refId, 0, sizeof(dat.refId)); + sce_paf_strncpy(dat.refId, refID, sizeof(dat.refId)); + + sceClibMemset(dat.parentRefId, 0, sizeof(dat.parentRefId)); + if(parentRefID != NULL) sce_paf_strncpy(dat.parentRefId, parentRefID, sizeof(dat.parentRefId)); + + dat.type = slidebar; + dat.hasParent = parentRefID != NULL; + + dat.pos = *Position; + dat.size = *Size; + dat.col = *Color; + + dat.OnLoad = OnLoad; + + dat.isAdvanced = 0; + + dat.data.SlidebarData.OnChange = OnChange; + + return registerWidget(&dat); +} + int QuickMenuRebornGetCheckBoxState(const char *refID) { return readCheckBoxState(refID); diff --git a/src/user/main.h b/src/user/main.h index bcabe2a..952d674 100644 --- a/src/user/main.h +++ b/src/user/main.h @@ -31,7 +31,7 @@ int sceClibPrintf(const char * fmt, ...); #else #define print dummyprint #define TRY(method) method; -#define TRY_RET(method, toSet, type) do { void *ret = (void *)method; toSet = (type)ret; } while(0) +#define TRY_RET(method, toSet, type) do { type ret = (type)method; toSet = (type)ret; } while(0) #define DO(method) #define FAIL_IF(con) if (con) { return 0; } #define FAILTHREAD_IF(con) if (con) { return sceKernelExitDeleteThread(0); } diff --git a/src/user/widgets.cpp b/src/user/widgets.cpp index 216fb44..f826e33 100644 --- a/src/user/widgets.cpp +++ b/src/user/widgets.cpp @@ -12,18 +12,22 @@ #include static widget::Widget *(*getImposeRoot)(); +//Power Manage Plugin static Plugin *imposePlugin; +//Impose Plugin +static Plugin *actualImposePlugin; static widget::Widget *powerRoot; static Widget *main_plane; linked_list currentWidgets; -const char *idTypes[] = +const char *widgetStyles[] = { "_common_default_style_button", "_common_default_style_check_box", "_common_default_style_text", - "_common_default_style_plane" + "_common_default_style_plane", + "30396CEA" // Hex }; const char *widgetTypes[] = @@ -31,7 +35,8 @@ const char *widgetTypes[] = "button", "check_box", "text", - "plane" + "plane", + "slidebar" }; Widget *findWidgetByHash(SceUInt32 hash) @@ -49,6 +54,10 @@ int initWidgets() //Get power manage plugin object imposePlugin = Plugin::Find("power_manage_plugin"); NULL_ERROR_FAIL(imposePlugin); + + actualImposePlugin = Plugin::Find("impose_plugin"); + NULL_ERROR_FAIL(actualImposePlugin); + //Power manage plugin -> power manage root powerRoot = imposePlugin->GetInterface(1); NULL_ERROR_FAIL(powerRoot); @@ -62,7 +71,7 @@ int initWidgets() } SceUInt32 getHashByID(const char *id) -{ +{ Resource::Element sinfo; Resource::Element searchRequest; @@ -72,7 +81,7 @@ SceUInt32 getHashByID(const char *id) return sinfo.hash; } -Widget *makeWidget(const char *refId, const char *idType, const char *type, Widget *parent) +Widget *makeWidget(const char *refId, const char *styleInfo, const char *type, Widget *parent) { //WidgetInfo paf::Resource::Element winfo; @@ -84,7 +93,7 @@ Widget *makeWidget(const char *refId, const char *idType, const char *type, Widg searchRequest.id.Set(refId); TRY_RET(winfo.GetHashById(&searchRequest), winfo.hash, SceUInt32); - searchRequest.id.Set(idType); + searchRequest.id.Set(styleInfo); TRY_RET(sinfo.GetHashById(&searchRequest), sinfo.hash, SceUInt32); @@ -94,6 +103,27 @@ Widget *makeWidget(const char *refId, const char *idType, const char *type, Widg return newWidget; } +Widget *makeWidget(const char *refId, int styleHash, const char *type, Widget *parent) +{ + //WidgetInfo + paf::Resource::Element winfo; + //StyleInfo + paf::Resource::Element sinfo; + //Search Request + paf::Resource::Element searchRequest; + + searchRequest.id.Set(refId); + TRY_RET(winfo.GetHashById(&searchRequest), winfo.hash, SceUInt32); + + sinfo.hash = styleHash; + + Widget *newWidget; + TRY_RET(actualImposePlugin->CreateWidgetWithStyle(parent, type, &winfo, &sinfo), newWidget, Widget *); + if(newWidget == NULL) sceClibPrintf("Error can't make widget with refID %s, type %s, styleid = 0x%X\n", refId, type, styleHash); + FAIL_IF(newWidget == NULL || newWidget < 0); + return newWidget; +} + int unregisterWidget(const char *refId) { #ifdef DEBUG @@ -182,11 +212,8 @@ int updateValues(Widget *made, widgetData *widget, int flags) { if(flags && UPDATE_EVENT) { - print("Updating event...\n"); eh->pUserData = sce_paf_malloc(sizeof(widgetData)); - print("Done malloc();\n"); sce_paf_memcpy(eh->pUserData, widget, sizeof(widgetData)); - print("Done memcpy();\n"); made->RegisterEventCallback(ON_PRESS_EVENT_ID, eh, 0); } if(flags && UPDATE_TEXT) @@ -201,16 +228,18 @@ int updateValues(Widget *made, widgetData *widget, int flags) { if(flags && UPDATE_EVENT) { - print("Updating checkbox event....\n"); eh->pUserData = sce_paf_malloc(sizeof(widgetData)); - print("Done malloc();\n"); sce_paf_memcpy(eh->pUserData, widget, sizeof(widgetData)); - print("Done memcpy();\n"); - print("OnToggle %s NULL\n", widget->data.CheckBoxData.OnToggle ? "==" : "!="); made->RegisterEventCallback(ON_PRESS_EVENT_ID, eh, 0); } break; } + + case slidebar: + { + delete eh; + break; + } case text: { @@ -270,6 +299,16 @@ int setupValues(Widget *widget, widgetData *dat) case text: { widget->SetOption(Widget::Option::Text_Bold, 0, 0, SCE_FALSE); + break; + } + case slidebar: + { + SceFVector4 size = makeSceVector4(65, 65, 0, 0); + + + Widget *ball = widget->GetChildByNum(0); + if(ball != NULL) ball->SetSize(&size); + break; } default: @@ -281,11 +320,22 @@ int setupValues(Widget *widget, widgetData *dat) int spawn(widgetData *widget, int flags) { Widget *made; - made = - makeWidget(widget->refId, - widget->isAdvanced ? widget->adata.idType : idTypes[widget->type], - widget->isAdvanced ? widget->adata.type : widgetTypes[widget->type], - (widget->hasParent == 0) ? main_plane : findWidgetByHash(getHashByID(widget->parentRefId))); + sceClibPrintf("Got widget %s parent %s\n", widget->refId, widget->parentRefId); + if(widget->isAdvanced) + { + if(widget->adata.useHash) + made = makeWidget(widget->refId, widget->adata.hash, widget->adata.type, (widget->hasParent == 0) ? main_plane : findWidgetByHash(getHashByID(widget->parentRefId))); + else + made = makeWidget(widget->refId, widget->adata.styleInfo, widget->adata.type, (widget->hasParent == 0) ? main_plane : findWidgetByHash(getHashByID(widget->parentRefId))); + } + else + { + int style = 0; + if(style = (int)sceClibStrtoll(widgetStyles[widget->type], NULL, 16), style != 0) + made = makeWidget(widget->refId, style, widgetTypes[widget->type], (widget->hasParent == 0) ? main_plane : findWidgetByHash(getHashByID(widget->parentRefId))); + else + made = makeWidget(widget->refId, widgetStyles[widget->type], widgetTypes[widget->type], (widget->hasParent == 0) ? main_plane : findWidgetByHash(getHashByID(widget->parentRefId))); + } #ifdef DEBUG diff --git a/src/user/widgets.h b/src/user/widgets.h index 093cbfd..bd40fec 100644 --- a/src/user/widgets.h +++ b/src/user/widgets.h @@ -6,7 +6,7 @@ Widget *findWidgetByHash(SceUInt32 hash); int initWidgets(); -Widget *makeWidget(const char *refId, const char *idType, const char *type, Widget *parent); +Widget *makeWidget(const char *refId, const char *styleInfo, const char *type, Widget *parent); int displayWidgets(); int openQuickMenu(); int editWidget(widgetData *data, int flags);