[WIP] (S)NESInject: A ROM injector tool for Loadiine

Discussion in 'Wii U - Hacking & Backup Loaders' started by daxtsu, Nov 24, 2015.

  1. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    No network required, just feed the program an NES/SNES VC ELF file and an NES/SNES ROM, and it figures out the rest. If the ROM is too big, it'll refuse to do anything with it.

    Source is included, along with a pre-compiled, static-linked Windows build (should work on XP too). It should compile and run on any OS with a C compiler, though.

    To use the program, first use Hykem's rpl2elf to convert your VC RPX into an ELF file:
    Code:
    rpl2elf vc-file.rpx vc-file.elf
    

    Next, use the injector program:
    Code:
    snesinject <input VC ELF> <NES or SNES ROM> <output VC ELF>
    
    (Don't actually use <> when running the program.)


    After that, use makerpl64 from the Wii U SDK to convert your ELF back to an RPX:
    Code:
    makerpl64 -f -z8 -old -s xxxx.elf
    
    Then you should be good to go with testing it on your Wii U using Loadiine.

    Edit 1: I found a way of getting the ROM offset easier, so I'll try to make an update soon that won't require Super Metroid.

    Edit 2: v0.2 is now out. You should be able to use any SNES VC ELF that supports 4MB games (Super Metroid is apparently 3, but it works fine for me; guess I got lucky with it not crashing?). I'm not sure if I'll bother adding support for ELFs that use base ROMs smaller than 4MB, but we'll see if there's enough demand.

    Edit 3: v0.3 is now out. It supports both SNES and NES ROMs of nearly any size. I highly suggest using this build over 0.2, but 0.2 is included for legacy purposes.
     

    Attached Files:

    Last edited by daxtsu, Dec 1, 2015
    Masterwin, eco95, oumoumad and 7 others like this.


  2. Sumea

    Sumea Disco Ninja Frog

    Member
    1,442
    253
    Aug 16, 2008
    Finland
    Turku
    Great stuff. Really like this, would love to see same for N64 and so on.

    Still; great good stuff.
     
  3. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    As far as I understand, you can already just replace the loose files for N64, can't you? The only ones that are really lacking easy tools are SNES, NES (before this tool came), and GBA. Loadiine should make N64 and NDS easy.
     
  4. Sumea

    Sumea Disco Ninja Frog

    Member
    1,442
    253
    Aug 16, 2008
    Finland
    Turku
    OK. I do not have dumps of any of them since my Wii U which I have few bought games on is not the same one that I have in FW 5.3.2, and I have not found any... other means to find VC games yet. I want to be in the inside know how club but oh well.
     
  5. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    I don't have an N64 dump to confirm it myself, but from browsing the injection thread, it looks like they're just files that you can replace. It's only SNES and NES that are locked up in the RPX, while GBA is in alldata.bin, sadly.

    On an unrelated note, I'll work on a size option so it'll "just work" with NES ROMs and base SNES games that are smaller than 4MB. NES ROM ELFs on the Wii U VC follow the same format as the SNES ones, so it's trivial to add support for it (they also use iNES-format dumps from the internet, lol).
     
  6. Sumea

    Sumea Disco Ninja Frog

    Member
    1,442
    253
    Aug 16, 2008
    Finland
    Turku
    Fun stuff. Yeah that is nice, injecting something like translated final fantasy or so on would be fun. And if you get GBA working at one point, mother 3 or something like that.
     
  7. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    It probably won't be me who gets GBA working, alldata.bin is encrypted or something, and reverse-engineering is hardly my forte.
     
  8. Sumea

    Sumea Disco Ninja Frog

    Member
    1,442
    253
    Aug 16, 2008
    Finland
    Turku
    So do I have to basically extract an ELF out of the RPX?
    Hmm, how do I go on about that...
     
  9. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
  10. gunner007

    gunner007 GBAtemp Advanced Maniac

    Member
    1,506
    368
    Dec 31, 2013
    United States
    So can we use this with an existing setup? I have a Earthworm Jim that's set up already. If I convert the RPX to ELF and then attempt to add a Secret of Mana rom, I get the warning that it's smaller and will pad and then create an RPX from the ELF, but loading from Loadiine causes a system error.
     
  11. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    If Earthworm Jim isn't a 4MB base (it doesn't appear to be, judging by the size of the game on the internet, it's 3MBytes), it won't work right for you. This program pretty much assumes you have a 4MB base game right now (Donkey Kong Country, and maybe a few others). I plan on changing that in a day or so. If you can't wait, you can recompile it to only use 3MB (change line 7, ROM_SIZE, to 3 * 1024 *1024 instead of 4 * 1024 * 1024).

    There's no reliable way to detect how large the ROM is in the VC ELF, unfortunately.
     
  12. VinsCool

    VinsCool Insecure

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

    Our Patreon
    11,494
    26,859
    Jan 7, 2014
    Canada
    Another World
    How about adding a function to ask user what size is the base rom?
     
  13. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    That was the idea, yes. I just hard-coded it initially to get a release out.
     
    VinsCool likes this.
  14. Xplic1T

    Xplic1T GBAtemp Regular

    Member
    151
    52
    May 26, 2006
    Loadiine gives me a white screen on a few snes roms.
     
  15. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    What game are you using as a base, and what games did you try with it? If you're not using a game with a 4MB base (Donkey Kong Country or possibly a couple others, like mentioned above), you'll get crashes/freezes/unexpected behaviour since the program will end up overwriting other stuff in the ELF, and not just the ROM.
     
    Last edited by daxtsu, Nov 25, 2015
  16. Coto

    Coto GBAtemp Addict

    Member
    2,343
    394
    Jun 4, 2010
    Chile
    Really? I always thought you were a quick learner.
     
  17. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    I am, but I don't really know anything about encryption.
     
  18. gamesquest1

    gamesquest1 Nabnut

    Member
    14,081
    9,416
    Sep 23, 2013
    i messaged normmatt about the alldata.bin file, see if he can work his magic, he said he will take a look (but no promises, so please don't bug him about it :P )
    figured with M2 making the sega 3DS VC emulators and the wiiu GBA emulator the formatting/encryption may be similar enough for him to figure it out seeing as he figured out the 3DS sega VC encryption
    you should be able to get that info from the WUP header, at 0xE it appears to store the rom size
    40=4MB
    20=2MB
    10=1MB
    08=512kb
    04=256kb
    02=128kb
    01=64kb
    00=32kb
    ....that should be good for injecting into any NES/SNES game and detecting the size automatically

    oh and as an added bonus, 0x01 will let you detect if its a snes game or a NES game automatically
    , 01 for snes, 00 for nes
     
    Last edited by gamesquest1, Nov 25, 2015
  19. daxtsu
    OP

    daxtsu GBAtemp Guru

    Member
    5,491
    3,878
    Jun 9, 2007
    By WUP header, you mean in the area where it says "WUP-XXXX"? Interesting, if so.
     
  20. gamesquest1

    gamesquest1 Nabnut

    Member
    14,081
    9,416
    Sep 23, 2013
    yeah you would probably have to do some sort of detection as the game id part (WUP-XXXX) part shifts depending on if its a nes or snes rom too, but the wup header itself is always the same length.....to have a better look at the header you can download the amiibo classics game from the eshop, it has a bunch of roms you can look at to compare headers
     
    daxtsu likes this.