PS3 custom xai_plugin (+ source)

Discussion in 'XMB Modifications' started by mysis, Jan 22, 2017.

  1. 142
    238
    72
    mysis

    mysis Developer

    Joined:
    Jan 29, 2016
    Messages:
    142
    Likes Received:
    238
    Trophy Points:
    72
    Hi there,

    due to some request and the lack of time I currently have, I hereby release the source of my custom xai_plugin and I will also explain on code side whats needed to create your own xai_plugin that can be fed with commands from XMB.

    The minimum amount of code needed is provided as a reboot template, but it does not contain the required xmb xml modification to call.

    When you create your prx it will have some entry point:
    Code:
    SYS_MODULE_START( _xai_plugin_prx_entry );
    
    It all comes down into specifying two interfaces:

    =Main module interface=

    We first have to tell that our prx module is having an interface for VSH:
    Code:
    plugin_SetInterface2(view, 1, xai_plugin_functions);
    The view is provided when our entry function is called.
    1 is the main exporting interface of our module.
    The functions we provide are basically: init, start, stop, exit functionalities.

    In our init function, we then specify the second interface.

    =Plugin interface=

    Now comes the most interesting part. Modules can register different kinds of interfaces.
    We can also register our own interfaces!
    Common interfaces i have encountered and documented:
    • 1 - the main talking interface
    • 'XMM0' - for overall XMB module plugin information and control (load/unload/...)
    • 'XMB2' - for XMB UI interaction
    • 'MOD0' - for your own module behavior (LoadOpinion)
    • 'CAT0' - for XMB category behavior
    • 'Z'
    • 'ACT0' - for XMB module action communication
    So, we need to set up another interface, that is the 'ACT0' one. This can have only 1 function handler, which will be responsible for handling the commands from the XMB xml. When XMB tries to execute a command from xml it basically loads the module, checks if ACT0 is registered and then calls the handler from it. This is how we register it:
    Code:
    plugin_SetInterface(view,'ACT0', xai_plugin_action_if);
    Afterwards you just will just have to parse within our handler whatever data is sent:

    Code:
    void xai_plugin_interface_action::xai_plugin_action(const char * action)
    {   
        cellFsUnlink("/dev_hdd0/tmp/turnoff");
        if(strcmp(action,"soft_reboot_action")==0)
        {
            sys_sm_shutdown(SYS_SOFT_REBOOT);
        }
        else if(strcmp(action,"hard_reboot_action")==0)
        {
            sys_sm_shutdown(SYS_HARD_REBOOT);
        }
    }
    
    =XMB xml=

    When you modify the XMB xml files and add your view and table you use:

    Code:
    <Pair key="module_name"><String>xai_plugin</String></Pair>
    <Pair key="module_action"><String>soft_reboot_action</String></Pair>
    Sony and other people for example in a similar fashion use this with the webbrowser_plugin and provide a URL as module_action.

    Here you can find more information about the other plugins: http://www.psdevwiki.com/ps3/Plugin_Interfaces

    Template code, containing soft and hard reboot functionality:

    https://www.dropbox.com/s/qpy133wudq0kkce/xai_plugin_reboot_template_src.rar?dl=1

    My xai_plugin source:
    https://www.dropbox.com/s/sp31la3wh7rz40d/xai_plugin_src.rar?dl=1

    I apologize for the badly written code, but sometimes the compiler did not produce the code/data i needed :)

    /mysis
     
  2. 9,043
    9,253
    1,172
    STLcardsWS

    STLcardsWS Administrator

    Joined:
    Sep 18, 2014
    Messages:
    9,043
    Likes Received:
    9,253
    Trophy Points:
    1,172
    Thanks for the share @mysis
     
    mysis likes this.
  3. 1,198
    1,222
    272
    littlebalup

    littlebalup Developer PSX-Place Supporter

    Joined:
    Oct 16, 2014
    Messages:
    1,198
    Likes Received:
    1,222
    Trophy Points:
    272
    Location:
    43°36'16.0"N 1°26'36.1"E
    Awesome. Many thanks @mysis.
     
  4. 7,260
    8,558
    797
    DeViL303

    DeViL303 Developer PSX-Place Supporter

    Joined:
    Jan 23, 2016
    Messages:
    7,260
    Likes Received:
    8,558
    Trophy Points:
    797
    Nice. Thanks Mysis.
     
  5. 164
    233
    72
    zecoxao

    zecoxao Developer

    Joined:
    Dec 9, 2014
    Messages:
    164
    Likes Received:
    233
    Trophy Points:
    72
    fapping material :O thanks mysis :)
     
  6. 6,113
    5,796
    622
    sandungas

    sandungas Moderator Developer

    Joined:
    Dec 31, 2014
    Messages:
    6,113
    Likes Received:
    5,796
    Trophy Points:
    622
    Location:
    Babylon 20xxE series
    Great @mysis, pushing on XMB ;)

    Next big step for XMB modding are the "events" used inside rcoxml and vsmx code inside .rco that are sent to the sprx modules
    I regret a bit for not motivating you to look at this when you was more active, i documented half of it in wiki but i guess you had not much time to read all the mess i wrote, i did not mentioned it much to you also because is a bit unrelated with the ACT0 interface stuff you was working at that time (i think is another interface, but not sure wich one) and because i didnt made any test at all, but eventually i will return to it at some point :)
     
    Last edited: Jan 23, 2017
    DeViL303 and WTF-IGO like this.
  7. 7,849
    6,541
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,849
    Likes Received:
    6,541
    Trophy Points:
    647
    Location:
    Earth
    Thanks a bunch @mysis, I have wanted a peek at this for a while. It will be most useful.
    It's actually very simple to use...
     
    Last edited: Jan 23, 2017
    WTF-IGO likes this.
  8. 582
    2,463
    322
    deank

    deank Developer

    Joined:
    Sep 22, 2016
    Messages:
    582
    Likes Received:
    2,463
    Trophy Points:
    322
    Gender:
    Male
    @mysis (or anyone who can help): I had to convert the code to C but I'm having the following issue:
    1) plugin loads fine-> init/start/action
    2) I receive the action (just for a test - display it as notification)
    3) the ps3 stays on the XMB waves screen and doesn't return back

    It doesn't crash/lock but I can't continue from there. After "action" is complete nothing happens - stop/exit functions are never called.




    Code:
    SYS_MODULE_INFO(webftp_server, 0, 1, 1);
    SYS_MODULE_START(wwwd_start);
    SYS_MODULE_STOP(wwwd_stop);
    SYS_MODULE_EXIT(wwwd_stop);
    
    ...
    
    static int (*plugin_SetInterface)(int view, int interface, void * Handler);
    static int (*plugin_SetInterface2)(int view, int interface, void * Handler);
    
    static void *wm_plugin_action_if[3] = {(void*)(wm_plugin_action), 0, 0};
    
    static void wm_plugin_init (int view)     {plugin_SetInterface( view, 0x41435430 /*ACT0*/, wm_plugin_action_if);}
    static int  wm_plugin_start(void * view)   {return SYS_PRX_START_OK;}
    static int  wm_plugin_stop (void)       {return SYS_PRX_STOP_OK;}
    static void wm_plugin_exit (void)       {return;}
    
    static void *wm_plugin_functions[4] =
       {
         (void*)(wm_plugin_init),
         (int* )(wm_plugin_start),
         (int* )(wm_plugin_stop),
         (void*)(wm_plugin_exit)
       };
    
    int setInterface(unsigned int view)
    {
       plugin_SetInterface = (void*)((int)getNIDfunc("paf",0xA1DC401));
       plugin_SetInterface2 = (void*)((int)getNIDfunc("paf",0x3F7CB0BF));
       plugin_SetInterface2(view, 1, (void*)wm_plugin_functions);
       return 0;
    }
    
    void wm_plugin_action(const char * action)
    {
       show_msg((char*)action);
    }
    ...
    int wwwd_start(size_t args, void *argp)
    {
       setInterface(*(unsigned int*)argp);
       return SYS_PRX_RESIDENT;
    }
    int wwwd_stop(void)
    {
       show_msg((char*)"Stop");
       return SYS_PRX_STOP_OK;
    }
    
     
    Last edited: Jan 28, 2017
    DeViL303 and WTF-IGO like this.
  9. 582
    2,463
    322
    deank

    deank Developer

    Joined:
    Sep 22, 2016
    Messages:
    582
    Likes Received:
    2,463
    Trophy Points:
    322
    Gender:
    Male
    Ah it seems there is nothing wrong with the code, but the XML required two pairs:
    Code:
            <Pair key="bar_action"><String>none</String></Pair>
             <Pair key="lbl_half"><String>1</String></Pair>
    Now it works :)

    late edit: lbl_half pair key is not needed.
     
    Last edited: Jan 29, 2017
  10. 6,113
    5,796
    622
    sandungas

    sandungas Moderator Developer

    Joined:
    Dec 31, 2014
    Messages:
    6,113
    Likes Received:
    5,796
    Trophy Points:
    622
    Location:
    Babylon 20xxE series
    The key="lbl_half" was used as a crash prevention, dont remember why it happens, but without it was not working
    Probably is the same that happened to you

    But we could not understand what it does exactlly, actually that name including the word "half" i still cant imagine what is refered (half what ?... are we talking about a progress bar ?, some kind of display mode ?, a frame ?... is unknown)

    I mention this because i think there must be a better way to make it work without the need to use the key="lbl_half"
    That... or the key="lbl_half" is really being used right, but as said, is not documented what it does exactlly

    Anyway, by now seems mandatory to use it, no other workaround was found
    Personally i dont like it because i dont understand it, and this makes me think is wrong used (but it works, so we will have to live with this mistery)
     
    DeViL303 and WTF-IGO like this.
  11. 582
    2,463
    322
    deank

    deank Developer

    Joined:
    Sep 22, 2016
    Messages:
    582
    Likes Received:
    2,463
    Trophy Points:
    322
    Gender:
    Male
    Actually in webMAN's proxy I didn't use lbl_half - only bar_action and everything works fine.

    Sent from my Lenovo P1a42 using Tapatalk
     
    WTF-IGO likes this.
  12. 6,113
    5,796
    622
    sandungas

    sandungas Moderator Developer

    Joined:
    Dec 31, 2014
    Messages:
    6,113
    Likes Received:
    5,796
    Trophy Points:
    622
    Location:
    Babylon 20xxE series
    I think the bar_action is related with lbl_half... both are unknown btw but iirc are used together in some xmbml of some ofw
    So is posible the "b" letter of lbl_half is refered to "bar"

    And by looking at the names of the rcoxml objects (are the tags under "objecttree" in the main .xml file inside .rco files) there are only 2 posible "bars"
    http://www.psdevwiki.com/ps3/RCOXML_Objects
    One is a vertical scroll bar, like the one used in web browsers (but is not for the web browser, is the vertical bar that appears in some xmb menues when are displayed lot of items vertically... like the vertical scroll bar of "install package files")
    The other is the horizontal progress bar... used in lot of places of the xmb, like the bar when installing a firmware

    There are only those two bars... and i could bet is refered to one (or both) of them because that rcoxml objects im talking about are like the LEGO blocks that builds the XMB, and some of the "pair keys" used in xmbml files are settings for those rcoxml objects

    A part of what i just said is speculation though, im talking about it to give an small hint of how i think is working incase someone finds what it does accuratelly
     
    Last edited: Jan 29, 2017
    WTF-IGO likes this.
  13. 582
    2,463
    322
    deank

    deank Developer

    Joined:
    Sep 22, 2016
    Messages:
    582
    Likes Received:
    2,463
    Trophy Points:
    322
    Gender:
    Male
    You can see here: http://www.psdevwiki.com/ps3/XMB-Settings

    bar_action is present in some entries (no mention of lbl_half). We have "module_action" and "bar_action" - obviously the "module_action" is dispatched to the interface of the plugin and the "bar_action" probably is a function of the current column "utility" module.
     
    WTF-IGO likes this.
  14. 582
    2,463
    322
    deank

    deank Developer

    Joined:
    Sep 22, 2016
    Messages:
    582
    Likes Received:
    2,463
    Trophy Points:
    322
    Gender:
    Male
    Also besides the xai_plugin it is possible to use kensaku_plugin, which is called when you click "internet search" in the Network column. I just tested it - it receives a simple "kensaku_google" parameter from the xml. :)
     
    WTF-IGO, Joonie and bguerville like this.
  15. 582
    2,463
    322
    deank

    deank Developer

    Joined:
    Sep 22, 2016
    Messages:
    582
    Likes Received:
    2,463
    Trophy Points:
    322
    Gender:
    Male
    While looking at xmb_plugin.prx I notice that there are at least six parameters for bar_action: onInit, onPush, onContextMenu, onScrollIn, onScrollOut and onCursorMove. Could be wrong about that, but I'll see if I can test that.
     
    WTF-IGO likes this.
  16. 6,113
    5,796
    622
    sandungas

    sandungas Moderator Developer

    Joined:
    Dec 31, 2014
    Messages:
    6,113
    Likes Received:
    5,796
    Trophy Points:
    622
    Location:
    Babylon 20xxE series
    onInit, onPush, onContextMenu, onScrollIn, onScrollOut, onCursorMove...
    Are the "events" used inside rcoxml objects i was mentioning in my first post of this thread, where i said i think are a bit offtopic because i think are used by other interface, not ACT0 (but maybe im wrong and are actually sent with ACT0)
    I said are a bit offtopic because i didnt wanted to disturb much this thread, just wanted to point at them because are used to trigger actions from the .sprx
    So the concept is the same than when sending a module_action from a XMBML file... the difference is who sends it because this ones im talking about are sent by the RCO

    The way i see is...
    ACT0 = communications between XMBML ---> SPRX
    ???? = communications between RCOXML ---> SPRX

    If you open an RCO in a hexeditor at top (after the header) there is a TOC that works as an index of the contents of the RCO and uses a few bytes for each entry
    Some of the stuff that needs to be indexed in that TOC because are long character strings appears at the TOC as a "reference" that points to other offset in the RCO... to a "label table", "event table", or "text table"... all them stores strings but are separated by its type, note the "events" has its own table
    Im explaining this because you can see the list of reference types in this table, the "events" are at top identifyed by 0x04000000
    http://www.psdevwiki.com/ps3/Template:RCO_TOC_reference_types

    The events that communicates with the SPRX, like this:
    Code:
    <Entry event="event:native:/onPush"> 
    
    or...
    Code:
    <Entry event="event:script:/onPush"> 
    
    The name "event" is a codename, also "native" (sends actions to the SPRX) and "script" (sends actions to a JSX script inside the RCO)
    The name "onPush" is also a codename, i think is the action associated to the press of the cross button (or circle in japan) in the dualshock over an icon, pretty useful :)

    ------------------
    The lbl_half actually appears in the link you posted
    The 4 keys together and consecutivelly
    Code:
    				<Pair key="module_name"><String>explore_plugin</String></Pair>
    				<Pair key="module_action"><String>NotifyErrorNoExecute</String></Pair>
    				<Pair key="bar_action"><String>none</String></Pair>
    				<Pair key="lbl_half"><String>1</String></Pair>
    
    I think you have found where mysis found the idea of using "bar_action" and "lbl_half" to solve the display problems he was having, heheh

    I knew about them, but in the .xml i prepared for him i didn't added them because i thought was not needed (also because i dont know what means so i prefered not to add something i didnt knew how it works)
    This is something mysis found (by the test-error method i guess) by looking at the ofw files like the link you posted

    Is good you verifyed is still working after removing the lbl_half for your plugin btw, i have no idea if mysis tryed without it

    And returning of what i said... bar_action and lbl_half appears together and consecutivelly... this is the only reason why i think they could be related (and both belongs to some kind of "bar" that i still cant imagine what it means)
    Or not... i know this argument has no weight... and it can sound stupid... but we dont have any other hint of what those keys means

    Im thinking just now it could be interesting to see in the xmbml files of some ofw if everywhere that appears a lbl_half there is always a bar_action before it
    This could give a bit more weight to my argument, but still doesnt proves anything
     
    Last edited: Jan 31, 2017
  17. 6,113
    5,796
    622
    sandungas

    sandungas Moderator Developer

    Joined:
    Dec 31, 2014
    Messages:
    6,113
    Likes Received:
    5,796
    Trophy Points:
    622
    Location:
    Babylon 20xxE series
    An small sample to show where are used the "events", this is a chunk taken from xmb_plugin_normal.rco (associated with xmb_plugin.sprx... not with xmb_ingame.sprx)

    Btw, this file type is usually named "rcoxml" because is the name given by zingaburga (who coded rcomage)
    The name rcoxml has been accepted unnoficially because the file doesnt exists inside an rco... is just a representation of the RCO contents converted to XML but there is not any XML files inside RCO, also because doesnt seems to exists any codename for it (or maybe nobody found it, or maybe was found but nobody suggested it, or maybe zingaburga was right and rcoxml is the accurate codename)
    In other words... there is not an accurate official codename for it by now, so rcoxml looks good enought

    The tag "XMenu" is an "rcoxml object" (because is under "ObjectTree") and is the main row of XMB with the 10 category icons (users, game, photo, music, etc...), it uses some "events"

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!-- This XML representation of an RCO structure was generated by Rcomage v1.1.1 -->
    <RcoFile UMDFlag="0" rcomageXmlVer="1.1" type="ps3" minFirmwareVer="unknownId0x120">
    	<MainTree name="xmb_plugin">
    		<ObjectTree>
    			<Page name="page_xmb" unknownInt0="0x1110000" onInit="nothing" onCancel="nothing" onContextMenu="nothing" onActivate="nothing">
    				<XMenu name="xmenu" posX="-395" posY="40" objectScale="0" redScale="1" greenScale="1" blueScale="1" alphaScale="1" width="0" height="0" posUnknown="0" scaleWidth="1" scaleHeight="1" elementScale="1" iconOffset="0x0" onLoad="event:native:/Bar::onInit" unknown17="0x1010100" unknown18="0x2010100" unknown19="0x3010100" unknownInt20="0x0" unknownInt21="0x0" unknown22="0x0" menus="0xa" onEnter="event:native:/Bar::onPush" onContext="event:native:/Bar::onContextMenu" unknownEvent28="event:native:/Bar::onCursorMove" onLabelLoad="event:native:/Bar::onScrollIn" unknownRef32="event:native:/Bar::onScrollOut">
    		</ObjectTree>
    	</MainTree>
    </RcoFile>
    
    Edit:
    There are a lot more "rcoxml objects" that uses "events"
    My suggestion if someone wants to play wth this is to dont use the "XMenu" object i used for the sample, mostlly because there are better objects for tests, specially the object "Button"
    http://www.psdevwiki.com/ps3/RCOXML_Objects#.280x08_0x03.29_Button
    Also, because that "Button" objects are going to be located more deeper in the XML tree, this means there are less risks to break the XMB if a test goes wrong

    You could try to find an RCO where is used the "Button" and change some "event" names with custom ones and try to see if you can interface with it from the .sprx
     
    Last edited: Jan 31, 2017
  18. 7,849
    6,541
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,849
    Likes Received:
    6,541
    Trophy Points:
    647
    Location:
    Earth
    If I understand this correctly, tweaking the rco & the prx code potentially gives us a multitude of possibilities to reuse for own purposes the already implemented event handling system... Doesn't it?
     
  19. 6,113
    5,796
    622
    sandungas

    sandungas Moderator Developer

    Joined:
    Dec 31, 2014
    Messages:
    6,113
    Likes Received:
    5,796
    Trophy Points:
    622
    Location:
    Babylon 20xxE series
    Not sure bguerville because as i said i think is another interface, not ACT0
    So no idea if it shares some handling methods with ACT0

    It was mysis who was doing the experiments with SPRX and i was helping him a bit with other files related but at that time i didnt talk with him much about this, now i understand it much better, i think is the first time i write a bit serious and resumed explain about it
    I been writing a lot more in wiki about all this though, but the info is spreaded in several pages, the way is written in wiki is hard to get the overall idea
     
    bguerville likes this.
  20. 7,849
    6,541
    647
    bguerville

    bguerville Moderator

    Joined:
    Feb 25, 2015
    Messages:
    7,849
    Likes Received:
    6,541
    Trophy Points:
    647
    Location:
    Earth
    In any case it's definitely something to explore because it could be very useful if could leverage the rco/prx event handling potential in our remapped system plugin...
    Maybe @mysis could also provide a few more hints regarding the event handling system.....?? We would all be grateful...

    And I agree that the related info on wiki has spread into various pages & is still hard to synthesise overall as is..
    Your posts are always very interesting as well btw..
     

Share This Page