WIP nx-python: Create Python Homebrew for the Switch!

Discussion in 'Switch - Emulation, Homebrew & Software Projects' started by AileenLumina, Mar 18, 2018.

  1. UnsureSherlock

    UnsureSherlock Advanced Member

    Newcomer
    2
    Aug 20, 2015
    United States
    Excellent work!

    Do you have any plans to bring over some of the more popular packages, such as numpy or matplotlib?
     
    TotalInsanity4 likes this.
  2. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    Yes, both are planned, but many scientific packages (e.g. the ones you named) require a Fortran compiler. This is in the works, though, so fear not. :)

    Also, after taking a short break (sorry 'bout that :P), I just finished implementing Savedata read/write, which means you can now start writing savedata editors for Switch games in Python. Here is some example code:

    import nx
    BOTW_TITLE_ID = 0x01007ef00011e000 # title IDs are just hexadecimal numbers
    botw = nx.titles[BOTW_TITLE_ID]
    with botw.savedata.open('0/save_game.sav') as savegame_file:
    # do something with savegame_file, it's just a regular file object​

    As you can see, I used the new nx package to get a botw Title object from nx.titles. Then I opened a file in botw's savedata, which provides me with a regular file object. It's that simple. (The open method takes the same arguments as pathlib.Path.open, in addition to the file_path as its first positional argument.)

    If you want to experiment a bit, there's also a TCP REPL example script which you can use as a replacement to your main.py. It allows you to enter Python code via your PC and let your Switch run it.

    Warning: Do not edit your savedata without backing it up, or you will risk losing it! As stated in the license of PyNX, nx and _nx, we cannot be held liable for any damage caused by the usage of the software. Be careful and create a backup before you edit a game's savedata.


    10 hours later...

    I just released v0.3.0-alpha (and I forgot to actually submit this post before, oops). It adds the aforementioned functions plus controller input:

    import nx
    while True:
    if nx.p1.a_button.is_pressed:
    print("a", end="")​

    Enjoy! :)
     
    Last edited by AileenLumina, Apr 22, 2018 - Reason: Updated TCP REPL script link
    jakibaki, lordelan and Brawl345 like this.
  3. pwsincd

    pwsincd Garage Flower

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

    Our Patreon
    Dec 4, 2011
    Manchester UK
    Masterwin, lordelan and AileenLumina like this.
  4. lordelan

    lordelan GBAtemp Psycho!

    Member
    10
    Jan 4, 2015
    Germany
    That's such a great update! Can't believe no one is commenting on this. Really appreciate your work! PyNX is one of the most fun things to follow on the Switch these days. Please keep it up! :)
     
    AileenLumina likes this.
  5. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    Thank you!

    On that note, I'd like to announce that our first small community project will be a BotW savedata editor. This will be an opportunity for you to dive right into learning how to write Python homebrew for the Switch, so don't miss out! If you would like to join us, please check out our Discord community. No prior experience with Python required, as long as you're willing to learn, we'll be happy to get you started!

    Edit: I forgot to mention that v0.3.1-alpha was released a few days ago. It fixes multiple bugs and adds virtual buttons:

    abxy = (nx.p1.a_button, nx.p1.b_button, nx.p1.x_button, nx.p1.y_button)
    abxy_button = nx.Button.from_buttons(*abxy)

    abxy_button.is_pressed will be true if either A, B, X or Y is pressed. Enjoy! ^^
     
    Last edited by AileenLumina, Apr 4, 2018
    vgmoose, TotalInsanity4 and lordelan like this.
  6. MemeMachine

    MemeMachine Member

    Newcomer
    1
    Jan 30, 2017
    United States
    That example script's link is broken

    EDIT: Found the new one
     
    Last edited by MemeMachine, Apr 6, 2018
    AileenLumina likes this.
  7. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    Thanks, I updated the link :)

    I had to take a short break due to final exams, but I've got a few weeks of time to work on this again. ^^
     
  8. Shrike

    Shrike GBAtemp Regular

    Member
    4
    Mar 10, 2018
    Germany
    I feel you @____@ same here
     
  9. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    Added full multitouch support and fixed issues with savedata writing. A new release will be out tomorrow, hopefully.

    In the meantime,
    please take a few minutes to participate in this quick survey. Your answers will help shape the future of nx-python.

    Thank you for your time!
     
    lordelan likes this.
  10. lordelan

    lordelan GBAtemp Psycho!

    Member
    10
    Jan 4, 2015
    Germany
    Great news. Did the survey. :)
     
    AileenLumina likes this.
  11. 0x25b3

    0x25b3 Advanced Member

    Newcomer
    1
    May 1, 2018
    Germany
    Why is Nintendo not releasing Netflix for Switch already!!1 :lol:
     
  12. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    I should probably mention that we now have a documentation, and there is a new release that fixes lots of bugs. Enjoy! :)
     
    lordelan and wicksand420 like this.
  13. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    This isn't really something new, but I'll post it here regardless for increased visibility. You can type Python code on your PC to be executed on your Switch using the TCP REPL example as your main.py.

    After you launch PyNX, connect to your Switch via a TCP client (Port 1337; you can find your Switch's IP address in the settings, under the "Internet" tab). On Linux, the command to do that is rlwrap cat | tee log.py | nc switch.ip 1337 (replace `switch.ip` with the IP address of your Switch). This also logs the input to log.py, which might be useful. You can exit the TCP REPL by typing exit().
     
    Cyan, lordelan, senas8 and 1 other person like this.
  14. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    New release: v0.4.1-alpha

    Fixes a bunch of bugs related to the controller input of player 1 as well as nx.utils.AnsiMenu
     
    lordelan likes this.
  15. cots

    cots GBAtemp Advanced Fan

    Member
    7
    Dec 29, 2014
    United States
    Amazing work! I see a bright future for Switch homebrew. I'm glad developers are interested in the console as the homebrew scene for the PS3/WiiU/3DS hasn't really produced anything other then a few game ports, emulators and utilities. It would be nice to see some original content popping up like in the NDS/Wii scene.
     
    AileenLumina likes this.
  16. YamiZee

    YamiZee GBAtemp Regular

    Member
    5
    Aug 18, 2013
    Finland
    This should just be integrated to the actual homebrew launcher so fiddling around wouldn't be necessary.
     
    AileenLumina and TotalInsanity4 like this.
  17. Dontwait00

    Dontwait00 Unknown

    Member
    4
    Sep 3, 2017
    Italy
    this leads to python developers to break out they own limits, putting the best apps on Switch now!
     
    AileenLumina likes this.
  18. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    22
    Oct 27, 2002
    France
    Engine room, learning
    You can only have one main.py in the same folder?
    you have to replace the file every time and only have one project at a time?

    I guess a launcher could be written in python?
    main.py to list sub-folders and other main.py projects?

    I didn't try yet, but thank you for making and maintaining this :)
     
    Last edited by Cyan, May 19, 2018
    AileenLumina likes this.
  19. Ritsuki

    Ritsuki ORAORAORAORA

    Member
    6
    Mar 15, 2008
    Switzerland
    Why is this on the homepage only now ? Great news!
     
    AileenLumina likes this.
  20. AileenLumina
    OP

    AileenLumina Python main, software engineer and API designer

    Member
    4
    Sep 27, 2015
    Germany
    You can give this loader a try. Use it as your main.py; it should display a simple file browser that allows you to select a Python program to run. It is intended to be a temporary workaround until this upstream issue is resolved. (Please report back if it works. :P )

    You can also use this TCP REPL script as your main.py for testing purposes.

    I wasn't confident enough about the stability of nx-python until today. That's why I decided to contact T-hug today, not earlier. :)
     
    Last edited by AileenLumina, May 19, 2018
Loading...