[Release] cagen: Stupid script to speed up .cia generation

Discussion in '3DS - Flashcards & Custom Firmwares' started by mmn, Dec 22, 2014.

  1. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    CIA Auto Generator

    Download latest version

    Please note: You can technically use this for xorpad generation on 9.x, but you have to replace the launcher.dat file and ncchinfo_gen.py with suitable replacements.

    CIA Auto Generator is a Windows only script that was thrown together to speed up the generation of .cia files from .3ds files. It requires Queno138's CIA conversion kit, and it doesn't come with slot0x25KeyX.bin.

    All it does is automatically follow all of the steps laid out by Queno138 in his guide. Even the unneccessary copying. It works out of the box, just put cagen.exe in the root directory of Queno138's kit and drag a .3ds file onto it.

    Instructions
    • Download and extract Queno138's CIA conversion kit.
    • Make sure python is installed and in your PATH.
    • Make sure slot0x25KeyX.bin is in both the "Step 1" and "For 3DS SD Card" folders.
    • Download cagen.exe (or compile from source). Put it in the root directory of the conversion kit. The default name of that directory is "CIA".
    • Copy the .3ds file you want to convert to the root directory of the conversion kit. You may name it whatever you want except rom.3ds.
    • Drag the .3ds file onto cagen.exe to start the process.
    You can download the .exe here
    The source is here. But don't look at it. It's really poorly-written.

    Changes
    v0.3.0 - 2015-01-25:
    • Clean up everything that isn't the .cia, for real this time
    • Remove unnecessary copying
    • Option to keep misc. things that aren't xorpads
    • Warn user that their rom will be deleted if it's named "rom.3ds"
    v0.2.2 - 2015-01-18:
    • Rename Launcher.dat.backup to Launcher.dat when everything is finished
    v0.2.1 - 2015-01-18:
    • Add (y/n) option for those who don't want xorpads to be deleted
    v0.2.0 - 2014-12-23:
    The process is now entirely automated, other than the steps needed to generate xorpads.
    • Optionally automatically detect 3DS SD Card to copy necessary files (thanks Smiths!)
    • Menu system with failsafe options if the card can't be detected
    • Delete xorpads and other files from 3DS SD Card after finishing the process
    Please let me know if you have any problems. My 3DS is on firmware 9.2.0, so I have no way of testing the xorpad step and install.cia generation. It should work though, as I tested it with dummy files.

    v0.1.2 - 2014-12-22:
    • Switch to Windows API functions instead of system() calls
    • Add "Continue?" prompt when an operation fails
    v0.1.1 - 2014-12-21:
    • Initial release
     
    lordfelix, Ra1d, sup3rgh0st and 11 others like this.


  2. Timburpton

    Timburpton GBAtemp Advanced Fan

    Member
    557
    129
    Nov 18, 2014
    So we still have to decrypt the rom?

    What about eshop dumps?
     
    Margen67 and thorasgar like this.
  3. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    The process is exactly the same as before, it just requires fewer individual steps that you have complete yourself. So, it will work on exactly the same files as before.
     
    Margen67 likes this.
  4. Timburpton

    Timburpton GBAtemp Advanced Fan

    Member
    557
    129
    Nov 18, 2014
    So I can drag and drop eshop roms directly without having to decrypt?
     
  5. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    If your eshop rom is a) in .3ds format and b) can be converted to .cia using this guide, then yes.
    I don't know enough about eshop roms to determine whether either of those points are often true.
     
  6. Timburpton

    Timburpton GBAtemp Advanced Fan

    Member
    557
    129
    Nov 18, 2014
    Anyway to batch it? For example batch converting multiple 3ds to cia?
     
  7. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    Technically yes, I could add batch functionality to cagen or someone could write a trivial script that runs cagen multiple times.
    But, practically, there's a step in the process that requires you to copy files to an SD card, put that in your 3DS and run a program, after which you then have to copy files back from the SD card. So the usefulness of doing a batch is questionable.
     
    Margen67 likes this.
  8. Timburpton

    Timburpton GBAtemp Advanced Fan

    Member
    557
    129
    Nov 18, 2014
    I thought decryptor could batch decrypt?
     
  9. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    That might be true, but, as far as I know, new xorpads need to be generated for each .3ds file that you want to convert to .cia. This means copying at least ncchinfo.bin to an SD card, running NCCH Decryptor on a physical 3DS, and copying the resulting xorpads for use during generation of the final .cia file. For every rom.
     
  10. Apache Thunder

    Apache Thunder I have cameras in your head!

    Member
    4,088
    3,987
    Oct 7, 2007
    United States
    Levelland, Texas
    This automates the old process a bit better. So yes, you still need to do the 3DS end of things like decrypting the game files. :P
     
    Margen67 likes this.
  11. Smiths

    Smiths AKAIO Person of Interest

    Member
    1,337
    155
    Feb 24, 2003
    United States
    The land of Dairy Queen
    surprised you went full out C++ on this. You could throw in something (I made a batch file for this process that is very similar to your code btw... just.. batch :) )that detects the 3DS sd card.

    I put the SD card in my reader, and the batch file looks for a file on the drive roots of E-G (since that's where USB et al begin on my PC) that indicates it's a 3DS main SD card.

    So it starts, prompts to put the card in an SD-slot/adapter if it isn't there, rescans, then does the other stuff with copying, etc... copies the rom to the sd card leaving a prompt on the screen saying "put card back in when 3ds is done its garbage and hit enter"... then detects card again, copies xorpads, etc...

    Scripting is fun.
     
    Margen67, cearp and Assasin1990 like this.
  12. Kylecito

    Kylecito eats warnings for breakfast

    Member
    344
    379
    May 6, 2009
    Cote d'Ivoire
    Really wish there was any way to speed up the 3DS part of this tedious process... Anyone up for emulating the AES engine on the 3DS? :P
     
    Margen67 likes this.
  13. Asia81

    Asia81 In my Ecchi World <3

    Member
    4,846
    2,340
    Nov 15, 2014
    France
    Albi
  14. Jayro

    Jayro MediCat DVD and Mini Windows 10 Developer

    Member
    GBAtemp Patron
    Jayro is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    4,722
    2,473
    Jul 23, 2012
    United States
    Octo Canyon
    Eventually someone will compile all this shit into one single portable .exe file with an input file, and an output file... (And not in fucking Chinese...!) But I guess nobody can figure that shit out...
     
    Xenon Hacks and Margen67 like this.
  15. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    Well, I've been working with C++ for school all quarter, so it's actually easier for me to just throw something together in C++ than it is in, say, python. It's certainly easier for me than a batch file, as I've never worked with those.

    As for detecting the SD card, that's a great idea that I didn't have :D. I'll work on adding that.


    Try naming the rom something other than "rom.3ds". It's supposed to do that part automatically, so something's going wrong there. I'll take a look at it.
     
    Margen67, Assasin1990 and Smiths like this.
  16. Smiths

    Smiths AKAIO Person of Interest

    Member
    1,337
    155
    Feb 24, 2003
    United States
    The land of Dairy Queen
    automation is the soul of programming. remember: the goal is to replace real employees with shell scripts because of your abilities. preferably people you don't like.
     
  17. cearp

    cearp the ticket master

    Member
    7,399
    4,645
    May 26, 2008
    Tuvalu
    if you want to dump eshop, do not convert to 3ds and then convert to cia form that, eshop is basically in cia already, keep it neat :)
    trust me (if you want!) - i used c++ for years and never touched scripting stuff like python, bash, etc. - until recently. and i'm happy i worked in python now. but if you can use c++, python will be fine. it's really simple and easy to use, relative to c++, very powerful too :) give it a try if you want to make more things, it will save time, etc :)
     
    Margen67 likes this.
  18. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    Thanks for the tip, cearp. Maybe I'll give python a spin for another project.

    I've updated cagen to v0.2.0 with automatic detection of the 3DS SD Card, thanks to Smiths. It also cleans up after itself better now.

    It seems quite a bit more useful, now that the only manual step is xorpad generation.
     
  19. Smiths

    Smiths AKAIO Person of Interest

    Member
    1,337
    155
    Feb 24, 2003
    United States
    The land of Dairy Queen
    Awesome work btw. Glad to give ideas.

    I also realized I use the gateway launcher.dat by default (which is what my SD card detection looks for on each drive) and like to keep that after all is done. I'm pretty anal retentive when I batch stuff... you shoulda seen the AKAIO build scripts.

    So I do the whole process and copy over the launcher.dat for CIA making, copying the existing launcher to launcher_Gw.dat temporarily. Then when all is said and done and a CIA is made on the PC, I copy the CIA over to the SD and also rename my Gateway Launcher back to launcher.dat.
    It's a 100% "for Smiths" routine since other people don't even have the Gateway, etc... but that's 99% of the code I write :)
     
  20. mmn
    OP

    mmn GBAtemp Regular

    Member
    200
    183
    Dec 22, 2014
    United States
    Haha, yeah.
    My script looks for the "Nintendo 3DS" folder on all removable drives and confirms that it has found the correct drive. When it then proceeds to copy files, if there's already a Launcher.dat it'll get renamed to Launcher.dat.autobackup. If there's already both Launcher.dat and Launcher.dat.autobackup, the renaming step will fail and wait for the go-ahead to continue or quit (which happens when any step fails).

    I had to draw this little diagram to get the auto-detection menu straight in my head :wacko:
    Warning: Spoilers inside!
     
    Margen67 and Smiths like this.