Need help creating an application in LPP3DS (Lua)

Discussion in '3DS - Homebrew Development and Emulators' started by Chelsea_Fantasy, Apr 7, 2015.

  1. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    Hello,
    First of all: my mother tongue (born language) is Spanish. I will try to make this an "understandable" English post.
    I'm trying to make my own CIA installer and I have a problem installing the file. The application it's running as a CIA.

    My intention it's to make a cool-looking "install and delete" cia installer, so it will look great and also will work like the "Install All CIAs" funtion but also will delete the cia file after the installation.

    I used the compiled LPP-3DS elf in your repository (in the "bin" folder) (I striped it, off course). Then I make the CIA file with the cia_workaround.rsf in the repository. It works perfectly, I even made a hello world app.

    The problem is creating the CIA installer. The interface works great, the problem is when the software tries to install the file. It shows the cover art (see the code for reference) and after a few seconds (may vary in dependence of the file size) it jumps to the next game and does not installs nothing (see code for reference). I have enough space (16GB SD Card with 10GB of free space, so that's not the deal).

    The code it's below this line and also it's attached to thepost (I comment it), if I made any mistake, please, let me know where. Thanks

    Code:
    --Code START-------------------------------------------------------------------------------
    --my mothertongue it's spanish so I made a small variable name translation as a commentary, example in the next line:
    --hola = 1+2 --hola means hello
    --I also write some "lazy" commentaries in my very bad english.
    Screen.refresh()
    Screen.clear(TOP_SCREEN)
    Screen.clear(BOTTOM_SCREEN)
    --load the interface background pictures for the software
    LWNOADV = Screen.loadImage("/backgrounds/bottom/LWNOADV.PNG") --normal bottom screen
    LOWWADV = Screen.loadImage("/backgrounds/bottom/LOWWADV.PNG") --bottom screen with the "do not shutdown" warning
    EXITING = Screen.loadImage("/backgrounds/upper/EXITING.PNG") --the "all done / wave bye bye" screen
    LOADING = Screen.loadImage("/backgrounds/upper/LOADING.PNG") --the loading list of games screen
    INSTBKG = Screen.loadImage("/backgrounds/upper/INSTBKG.PNG") --the background for the game installation screen (haves a black space for the cover art of the game)
    Screen.drawImage(0,0,LOADING,TOP_SCREEN)
    Screen.drawImage(0,0,LWNOADV,BOTTOM_SCREEN)
    Screen.waitVblankStart()
    Screen.flip()
    Screen.refresh()
    Controls.init()
    pad = Controls.read()
    white = Color.new(255,255,255)
    here="/InstDir/"
    for zzz = 1,5 do -- I repeat this to be able of at least read the loading text
        Controls.init()
        pad = Controls.read()
        Screen.waitVblankStart()
        Screen.drawImage(0,0,LOADING,TOP_SCREEN)
        Screen.drawImage(0,0,LWNOADV,BOTTOM_SCREEN)
        Screen.flip()
        Screen.refresh()
    end
    --lets stop here and let me explain something:
    --the structure its the same:
    --    "SDMC:/InstDir/[GAMENAME]/CTR-P-GAME.CIA" for the CIA file
    --  "SDMC:/InstDir/[GAMENAME]/CTR-P-GAME.PNG" for the cover art (must be 186x165)
    --example:
    --    "SDMC:/InstDir/Mario 3D Land/CTR-P-GAME.CIA"
    --    "SDMC:/InstDir/Mario 3D Land/CTR-P-GAME.PNG"
    --    "SDMC:/InstDir/Fantasy Life/CTR-P-GAME.CIA"
    --    "SDMC:/InstDir/Fantasy Life/CTR-P-GAME.PNG"
    --    "SDMC:/InstDir/Power Rangers/CTR-P-GAME.CIA"
    --    "SDMC:/InstDir/Power Rangers/CTR-P-GAME.PNG"
    --the name for the png and cia files will always be "CTR-P-GAME"
    juegos = System.listDirectory("/InstDir/") --juego means game
    totaljuegos=#juegos --juego means game
    for i = 1,totaljuegos do
    nombredeljuego=juegos[i].name
    coverart=here..nombredeljuego.."/CTR-P-GAME.PNG" --pic must be 186x165
    LITTLEG = Screen.loadImage(coverart)
    Controls.init()
    pad = Controls.read()
    Screen.waitVblankStart()
    Screen.drawImage(0,0,INSTBKG,TOP_SCREEN)
    Screen.drawImage(192,60,LITTLEG,TOP_SCREEN)
    Screen.drawImage(0,0,LOWWADV,BOTTOM_SCREEN)
    Screen.flip()
    Screen.refresh()
    ciainst=here..nombredeljuego.."/CTR-P-GAME.CIA" --"nombredeljuego" means "nameofthegame"
    System.installCIA(ciainst)
    --dummy repetition start
    pad = Controls.read()
    Screen.waitVblankStart()
    Screen.drawImage(0,0,INSTBKG,TOP_SCREEN)
    Screen.drawImage(192,60,LITTLEG,TOP_SCREEN)
    Screen.drawImage(0,0,LOWWADV,BOTTOM_SCREEN)
    Screen.flip()
    Screen.refresh()
    --dummy repetition end
    System.deleteFile(coverart)
    System.deleteFile(ciainst)
    System.deleteDirectory(here..nombredeljuego)
    end
    System.deleteDirectory("/InstDir/")
    zzz=0
    for zzz = 1,5 do -- I repeat this to be able of at least read the "all done, bye bye" text
        Controls.init()
        pad = Controls.read()
        Screen.waitVblankStart()
        Screen.drawImage(0,0,EXITING,TOP_SCREEN)
        Screen.drawImage(0,0,LWNOADV,BOTTOM_SCREEN)
        Screen.flip()
        Screen.refresh()
    end
    System.exit()
    while true do
        --bla, bla, bla...tralala
    end
    --Code END-------------------------------------------------------------------------------
     

    Attached Files:



  2. Technicmaster0

    Technicmaster0 GBAtemp Psycho!

    Member
    3,068
    633
    Oct 22, 2011
    Gambia, The
    Did you try Big Blue Menu/ Devmenu to install the CIA?
     
  3. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    That's not the deal, i'm trying to create a cool and comfortable legal CIA installer
     
  4. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    off course I install my app's cia using devmenu/bbm, the deal it's my code itself
     
  5. Technicmaster0

    Technicmaster0 GBAtemp Psycho!

    Member
    3,068
    633
    Oct 22, 2011
    Gambia, The
  6. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    know that
    the thing is that im trying to create a more confortable Big Red Menu, with bugs and all (since my software uses th same functions and the same lua executor my "EasyCIAInstaller" it's basically a Big Red Menu

    EDIT: (with bug I mean not the list ones, I mean the memory one)
     
  7. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,263
    Nov 24, 2014
    Italy
    Bologna
    Why you use normal for syntax instead of using a paired for? (Something like for index,object in pairs(juegos) do)
     
  8. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    it's classic style
    I learn to code by myself so there are a lot of things that I dont use cause I found an alternative first and then when I learn the prooper one I keep using the easy one that I found early if it works ok.

    in this case, it does not seems to affect the code
     
  9. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,263
    Nov 24, 2014
    Italy
    Bologna
    What workaround are you using to generate your CIA file?
     
  10. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    cia_workaround.rsf

    I used the compiled elf in the repository's "bin" folder

    sorry if I reply late but my internet connection is a 20kbps one
     
  11. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,263
    Nov 24, 2014
    Italy
    Bologna
    Your code seems substantially correct (also, if it takes time before swapping to the next CIA, seems installing process is correctly initialized).

    This is a more correct and readable version of your code:
    Code:
    Screen.refresh()
    Screen.clear(TOP_SCREEN)
    Screen.clear(BOTTOM_SCREEN)
    LWNOADV = Screen.loadImage("/backgrounds/bottom/LWNOADV.PNG")
    LOWWADV = Screen.loadImage("/backgrounds/bottom/LOWWADV.PNG")
    EXITING = Screen.loadImage("/backgrounds/upper/EXITING.PNG")
    LOADING = Screen.loadImage("/backgrounds/upper/LOADING.PNG")
    INSTBKG = Screen.loadImage("/backgrounds/upper/INSTBKG.PNG")
    Screen.drawImage(0,0,LOADING,TOP_SCREEN)
    Screen.drawImage(0,0,LWNOADV,BOTTOM_SCREEN)
    Screen.waitVblankStart()
    Screen.flip()
    Screen.refresh()
    --Controls.init() NOT USED
    --pad = Controls.read()
    white = Color.new(255,255,255)
    here="/InstDir/"
    for zzz = 1,5 do
        --Controls.init() NOT USED
        --pad = Controls.read()
        Screen.waitVblankStart()
        Screen.drawImage(0,0,LOADING,TOP_SCREEN)
        Screen.drawImage(0,0,LWNOADV,BOTTOM_SCREEN)
        Screen.flip()
        Screen.refresh()
    end
    juegos = System.listDirectory("/InstDir/")
    for i,juego in pairs(juegos) do -- Better using paired for
        coverart=here..juego.name.."/CTR-P-GAME.PNG"
        LITTLEG = Screen.loadImage(coverart)
        --Controls.init() NOT USED
        --pad = Controls.read()
        Screen.waitVblankStart()
        Screen.drawImage(0,0,INSTBKG,TOP_SCREEN)
        Screen.drawImage(192,60,LITTLEG,TOP_SCREEN)
        Screen.drawImage(0,0,LOWWADV,BOTTOM_SCREEN)
        Screen.flip()
        Screen.refresh()
        ciainst=here..juego.name.."/CTR-P-GAME.CIA" --"nombredeljuego" means "nameofthegame"
        System.installCIA(ciainst)
        --dummy repetition start [Why you do this?]
        --pad = Controls.read()
        --Screen.waitVblankStart()
        --Screen.drawImage(0,0,INSTBKG,TOP_SCREEN)
        --Screen.drawImage(192,60,LITTLEG,TOP_SCREEN)
        --Screen.drawImage(0,0,LOWWADV,BOTTOM_SCREEN)
        --Screen.flip()
        --Screen.refresh()
        --dummy repetition end
        Screen.freeImage(LITTLEG) -- You MUST always free all used RAM before losing access to objects
        System.deleteFile(coverart)
        System.deleteFile(ciainst)
        System.deleteDirectory(here..juego.name)
        end
        System.deleteDirectory("/InstDir/")
        zzz=0
        for zzz = 1,5 do -- I repeat this to be able of at least read the "all done, bye bye" text
            --Controls.init() NOT USED
            --pad = Controls.read()
            Screen.waitVblankStart()
            Screen.drawImage(0,0,EXITING,TOP_SCREEN)
            Screen.drawImage(0,0,LWNOADV,BOTTOM_SCREEN)
            Screen.flip()
            Screen.refresh()
        end
       
        -- You MUST always free all used RAM before exiting
        Screen.freeImage(EXITING)
        Screen.freeImage(LOADING)
        Screen.freeImage(LWNOADV)
        Screen.freeImage(INSTBKG)
        Screen.freeImage(LOWWADV)
       
        System.exit()
     
    ravihpa likes this.
  12. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    thanks I will test it when I go home

    just a question: why I must free all used RAM before exit? if I quit the app the 3ds does not blank it itself?

    I code some Lua apps for PSP and never have to do that (I used Lua Player HM7 and that Lua Player haves a 17 480x272 pictures limit and never have clean the RAM, when I run another Lua homebrew it loads ok)
     
  13. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,263
    Nov 24, 2014
    Italy
    Bologna
    When you return to Homebrew Menu with ninjhax, there isn't an automatic garbage collection.
    Also, if with your code you try to install 10.000 CIAs, you'll get a crash cause you don't free covers.
     
  14. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    if I load the image over the previous image variable it should delete the older and replace it with the new one so I should have ilimited covers to load, right?

    also, i'm using gateway and custom firmware to test this.

    I don't use ninjhax, also..... ninjhax does not have am:u access
     
  15. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,263
    Nov 24, 2014
    Italy
    Bologna
    Absolutely NOT.
    Pointers (Userdata in LUA) != Memory blocks

    If you think like this, so you'll create bad coded homebrews with bad memory management.
     
    WhoAmI? likes this.
  16. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    so I should free every image after the installation? that neven happen to me before in psp, but I will do what you said, you are the senpai

    just say that I dont use ninjhax for this homebrew. ninjhax cannot install cia files. I test it on GW and CFW
     
  17. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    another question:
    is there any way to pack the default pngs used by the software in the cia/3ds and load it from there (LWNOADV, LOWWADV, EXITING, LOADING, INSTBKG)?
    this is to avoid create an extra folder in the root of the sd card

    off topic: I'm creating a Mirai Nikki Theme for you. Can you give me a HD render of your avatar for the Theme?
     
  18. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,263
    Nov 24, 2014
    Italy
    Bologna
    Yes, it's possible but you need to recompile lpp-3ds.
     
  19. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    it is impossible for me.
    I download your entire LPP3DS Github repository and tried to compile it with DevKitPro and I can't
     
  20. Chelsea_Fantasy
    OP

    Chelsea_Fantasy GBAtemp Advanced Fan

    Member
    991
    695
    Mar 25, 2014
    Cuba
    I launch the corrected code that you give me in this thread and does not installs nothing.
    remember that I was using the elf in the bin folder
    may be I do something wrong compiling the cia or may be that el was for a 3ds version and not a cia version.
    I am testing all in cia format, in GW and in CFW.

    Also, I tried to load your BigRedMenu's index.lua in my compiled LPP3DS and it freezes at a black screen loading the software, so may be it is a fault of mine compiling the cia file

    I take the elf that was in the "bin" folder in your GitHub repository, create an icon and banner, strip the elf like 3dbrew says and then compiled the CIA usin cia_workaround.rsf and desc app:4
    did I do something wrong?

    may be it's also an icon error. what flags should the icon have to be able to install cia files?