PS3 VSH Menu Optimized (POC by 3141card)

Discussion in 'VSH Menu' started by Evilnat, Jun 4, 2015.

  1. 186
    207
    72
    Evilnat

    Evilnat Developer

    Joined:
    Oct 25, 2014
    Messages:
    186
    Likes Received:
    207
    Trophy Points:
    72
    Location:
    Akihabara, Tokyo (Japan) [Akatsuki]
    PS3 VSH Menu Improved (3141card's POC)

    [​IMG]

    First of all, i want to thank [MENTION=21]3141card[/MENTION] and all behind PS3 VSH Menu, with it we can do a lot of better things ;)

    For moderators, sorry if this thread is unnecessary because there are more with the same tag, but if i do this all can see it quickly and improve the code

    I'm with PS3 VSH Menu and i'm using a base code for my SEN Enabler Plugin, i optimized the code to make it work in one thread because a like reduce it to the limit, and i deleted all dbg data because i don't use it, but you can add what you want

    The first thing i saw, if plugin is disabled the PS3 can't shutdown normally and need a forced shutdown, and with the plugin enabled multiMAN failed randomly and i needed shutdown the PS3, i don't know if this only happened to me but with this improved code is fixed

    I added the option to load font.png and background.png from file and memory, the SPRX inside RAR file doesn't need external PNGs, only install and start pressing SELECT, forget about using USB and HDD

    In the link with SRC i show how it works, it's simple, you only need to change some lines depending where you want to load files

    Load background.png and font.png from memory
    Code:
    main.c
    load_png_bitmap(1, NULL, background, background_size); // Load background.png from memory 
    
    blitting.c
    Buffer font = load_png(NULL, font_array, font_array_size); // Load font.png from memory 
    
    Load background.png and font.png from files
    Code:
    main.c
    load_png_bitmap(1, BACKGROUND_FONT_PATH, NULL, NULL);	// Load background.png from file
    
    blitting.c
    Buffer font = load_png(PNG_FONT_PATH, NULL, NULL); // Load font.png from file
    
    As you can see if you want to load font and background from files you need to NULL arrays (Buffer font = load_png(PNG_FONT_PATH, NULL, NULL);), PNG_FONT_PATH is defined as path to dev_usb000, along with BACKGROUND_FONT_PATH (load_png_bitmap(1, NULL, background, background_size);), this time NULL const char and use arrays:

    Code:
    #define PNG_FONT_PATH 		"/dev_usb000/font.png"  
    #define BACKGROUND_FONT_PATH	"/dev_usb000/background.png"
    When you load background.png and font.png from memory, it load data from font.c and background.c with his sizes defined in fonts.h and backgrounds.h

    Code:
    unsigned char background[61368]
    unsigned char font_array[14715] 
    
    #define background_size 61368
    #define font_array_size 14715
    And these are modified code from original SRC:

    Code:
    void init_graphic()
    {
    	memset(&ctx, 0, sizeof(DrawCtx));
    
    	// alloc VSH Menu graphic buffers
    	buf[0].addr = mem_alloc(MB(2));       // canvas buffer
    	buf[1].addr = mem_alloc(MB(2));       // background buffer
    
    	//Buffer font = load_png(PNG_FONT_PATH, NULL, NULL); 		// Load font.png from file
    	Buffer font = load_png(NULL, font_array, font_array_size);	// Load font.png from memory
    
    	// set drawing context
    	ctx.canvas   = buf[0].addr;
    	ctx.bg       = buf[1].addr;
    	ctx.font     = font.addr;
    	ctx.bg_color = 0xFF000000;            // black, opaque
    	ctx.fg_color = 0xFFFFFFFF;            // white, opaque
    
    	// get current display values
    	offset = *(uint32_t*)0x60201104;      // start offset of current framebuffer
    	getDisplayPitch(&pitch, &unk1);       // framebuffer pitch size
    	h = getDisplayHeight();               // display height
    	w = getDisplayWidth();                // display width
    
    	// get x/y start coordinates for our canvas
    	canvas_x = (w - CANVAS_W) / 2;
    	canvas_y = (h - CANVAS_H) / 2;
    
    	// dump background, for alpha blending
    	dump_bg();
    }
    
    int32_t load_png_bitmap(int32_t idx, const char *file, void *array, uint32_t array_size)
    {
    	if(idx > PNG_MAX) return -1;
    	if(file == NULL)	
    		ctx.png[idx] = load_png(NULL, array, array_size);
    	else	
    		ctx.png[idx] = load_png(file, NULL, NULL);
    	
    	return 0;
    }
    
    Buffer load_png(const char *file, void *array, uint32_t array_size)
    {
    	Buffer tmp;
    	png_dec_info dec_ctx;          // decryption handles
    	void *buf_addr = NULL;         // buffer for decoded png data	
    	
    	// create png decoder 
    	create_decoder(&dec_ctx);
    	
    	// open png stream
    	if(file == NULL)	
    		open_png(&dec_ctx, NULL, array, array_size);	
    	else	
    		open_png(&dec_ctx, file, NULL, NULL);	
    	
    	// set decode parameter
    	set_dec_param(&dec_ctx);
    	
    	// alloc target buffer
    	buf_addr = mem_alloc(png_w * png_h * 4);
    	
    	// decode png stream, into target buffer
    	decode_png_stream(&dec_ctx, buf_addr);
    	
    	// close png stream 
    	PngDecClose(dec_ctx.main_h, dec_ctx.sub_h);
    	
    	// destroy png decoder
    	PngDecDestroy(dec_ctx.main_h);
    	
    	// store png values
    	tmp.addr = (uint32_t*)buf_addr;
    	tmp.w = png_w;
    	tmp.h = png_h;
      
      	return tmp;
    }
    
    static int32_t open_png(png_dec_info *dec_ctx, const char *file, void *array, uint32_t array_size)
    {
    	uint32_t ret = 0;
    	CellPngDecSrc      src; 
    	CellPngDecOpnInfo  info;	
    
    	if(file == NULL)
    	{
    		src.srcSelect  = CELL_PNGDEC_BUFFER;      
    		src.fileName   = NULL;  
    		src.fileOffset = NULL;             	  	  
    		src.fileSize   = 0;
    		src.streamPtr  = array;
    		src.streamSize = array_size;
    	}
    	else
    	{
    		src.srcSelect  = CELL_PNGDEC_FILE;        
    		src.fileName   = file;              
    		src.fileOffset = 0;
    		src.fileSize   = 0;
    		src.streamPtr  = NULL;
    		src.streamSize = 0;		
    	}
    	
    	// spu thread disable
    	src.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_DISABLE;
    	
    	// open stream 
    	ret = PngDecOpen(dec_ctx->main_h, &dec_ctx->sub_h, &src, &info);
    	
    	return ret;
    }
    
    CellPngDecSrc uses CELL_PNGDEC_BUFFER for memory and CELL_PNGDEC_FILE for files, you need to specify stream and size for streamPtr and streamSize, and fileName must be a [const char*file] source

    It has some default an easy options as you can see on the picture above and you can modify it or add new ones:

    • Make a single beep
    • Make a double beep
    • Make a triple beep
    • Make screenshot
    • Make snd_cursor sound
    • Make snd_system_ok sound
    • Make snd_system_ng sound
    • Make snd_trophy sound
    • Show message in XMB
    • Disable plugin
    • Reset PS3
    • Shutdown PS3

    Shutdown the PS3 will delete turnoff flag from /dev_hdd0/tmp/turnoff, deleting it will avoid wrong shutdown, this is the code for delete it:

    Code:
    static void delete_turnoff_flag(void)
    {
        cellFsUnlink((char*)"/dev_hdd0/tmp/turnoff");
    }
    Hope this helps someone, i wanted to load PNG from memory instead files because for me is easier, and one more time, thanks [MENTION=21]3141card[/MENTION] for all, all credits to him ;)


    Regards
     
    Last edited: Jun 5, 2015
  2. 127
    172
    72
    3141card

    3141card Developer

    Joined:
    Oct 13, 2014
    Messages:
    127
    Likes Received:
    172
    Trophy Points:
    72
    Location:
    Germany
    Excellent, thank you very much for your sample and the useful improvements [MENTION=76]Evilnat[/MENTION] :)
     
  3. 4,687
    2,028
    397
    atreyu187

    atreyu187 Wanna-BeTA Tester Moderator

    Joined:
    Sep 29, 2014
    Messages:
    4,687
    Likes Received:
    2,028
    Trophy Points:
    397
    Gender:
    Male
    Occupation:
    MCU/Sony Enthusiast!
    Location:
    127.0.0.1
    Home Page:
    Can't wait for an easy DEX/CEX swap.
     
  4. 1,048
    1,704
    297
    habib

    habib Developer

    Joined:
    Oct 13, 2014
    Messages:
    1,048
    Likes Received:
    1,704
    Trophy Points:
    297
    Gender:
    Male
    I have done that already in rebug toolbox

    Btw, my grandma just passed away few hours ago ;(
     
  5. 3,980
    1,976
    297
    bitsbubba

    bitsbubba Super Moderator / Developer Super Moderator Developer

    Joined:
    Sep 27, 2014
    Messages:
    3,980
    Likes Received:
    1,976
    Trophy Points:
    297
    Gender:
    Male
    Occupation:
    Homicidal Super Moderator
    Location:
    Camp Crystal Lake, USA
    Home Page:
    Sorry to hear Habib, my condolences :(
     
  6. 8,604
    8,235
    1,022
    STLcardsWS

    STLcardsWS Administrator

    Joined:
    Sep 18, 2014
    Messages:
    8,604
    Likes Received:
    8,235
    Trophy Points:
    1,022
    Very Sorry to hear that as well..

    Hope your family is doing well, my condolence also .
     
  7. 49
    2
    12
    wicko

    wicko Forum Noob

    Joined:
    Nov 27, 2014
    Messages:
    49
    Likes Received:
    2
    Trophy Points:
    12
    I am so sorry to hear , my condolences :(
     
  8. 3,980
    1,976
    297
    bitsbubba

    bitsbubba Super Moderator / Developer Super Moderator Developer

    Joined:
    Sep 27, 2014
    Messages:
    3,980
    Likes Received:
    1,976
    Trophy Points:
    297
    Gender:
    Male
    Occupation:
    Homicidal Super Moderator
    Location:
    Camp Crystal Lake, USA
    Home Page:
    there's no SPRX inside the rar
     
  9. 8,604
    8,235
    1,022
    STLcardsWS

    STLcardsWS Administrator

    Joined:
    Sep 18, 2014
    Messages:
    8,604
    Likes Received:
    8,235
    Trophy Points:
    1,022
    I thought i had a post that mentioned that .. hmmm i can't find it lol... I guess i deleted it by mistake (the post).
     
  10. 186
    207
    72
    Evilnat

    Evilnat Developer

    Joined:
    Oct 25, 2014
    Messages:
    186
    Likes Received:
    207
    Trophy Points:
    72
    Location:
    Akihabara, Tokyo (Japan) [Akatsuki]
  11. 4,687
    2,028
    397
    atreyu187

    atreyu187 Wanna-BeTA Tester Moderator

    Joined:
    Sep 29, 2014
    Messages:
    4,687
    Likes Received:
    2,028
    Trophy Points:
    397
    Gender:
    Male
    Occupation:
    MCU/Sony Enthusiast!
    Location:
    127.0.0.1
    Home Page:
    Sorry to hear that but I was meaning via XMB using the VSH Menu.
     

Share This Page