Code Monkey home page Code Monkey logo

py-desmume's Introduction

logo

SkyTemple

Build Status Localization Progress Version Downloads License (GPLv3) Supported Python versions Discord

ROM hacking tool for Pokémon Mystery Dungeon Explorers of Sky.

It is available for Linux, macOS and Windows.

It includes a Python library for editing the ROM through Python (skytemple-files) and a debugger / script editor is integrated into the UI of SkyTemple (skytemple-ssb-debugger). Inside the debugger you can edit the game's scripts via the programming language ExplorerScript.

Ko-Fi

Support and Features

See the Project Pokémon forums page.

Windows & macOS

To download SkyTemple for Windows and macOS head over to the download page or Project Pokémon.

If you want to set up SkyTemple for development, see the "BUILDING_WINDOWS.md" or "BUILDING_MACOS.md" file.

Linux

Flatpak

SkyTemple is distributed as a Flatpak on Flathub for all major Linux distributions.

Install on Flathub

This Flatpak contains everything needed to use all SkyTemple features.

Source repository for the Flatpak: https://github.com/flathub/org.skytemple.SkyTemple

Manual

The Linux version can be installed manually/"natively" via Pip.

For this Python 3.9+ must be installed and GTK+ 3 (which you most likely both have). Additionally GtkSourceView 4 is required (package gtksourceview4 on Arch and libgtksourceview-4-dev on Ubuntu).

Then install SkyTemple via pip:

pip install --upgrade skytemple[eventserver,discord]

You may need to run pip3 instead and/or need to update pip by running:

pip3 install --upgrade pip

After this, you can run skytemple to run it. If this doesn't work, you don't have ~/.local/bin in your PATH. Run ~/.local/bin/skytemple instead.

To be able to apply patches, you need to install armips. Sadly they don't provide builds. However for Arch Linux a version is available through the AUR.

If you want to set up SkyTemple for development, clone the repos and install in editable mode instead. See the steps 7 and onward in "BUILDING_WINDOWS.md".

Star History

Star History Graph

py-desmume's People

Contributors

dependabot[bot] avatar mike8699 avatar minabsapi avatar tech-ticks avatar thecapypara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

py-desmume's Issues

keypad_add_key not working with "easy way of running the emulator"

When running the emulator in the window, I am not able to interact with it with the "keypad_add_key" and "keypad_rm_key", but the "touch_set_pos" seems to work as intended. When querying the keys (keypad_get()) it seems to be registering the "keypad_add_key" but the game does not seem to progress according to the keys I press. The script seems to work fine if it is headless (without the window it seems to register them) and it registers keys fine when pressing them on the keyboard during gameplay (in the window). Could you help?

from desmume.emulator import DeSmuME
from desmume.controls import keymask, Keys

emu = DeSmuME()
emu.open('D:\\Dropbox\\Speed Run\\DeSmuME 9.11\\Roms\\ROMs\\NA\\0561 - Harvest Moon DS (U)(Legacy).nds')

window = emu.create_sdl_window()

frame = 0
while not window.has_quit():

    frame += 1

    if frame == 405:
        emu.input.touch_set_pos(100, 100)

    if frame == 406:
        emu.input.touch_release()

    if frame == 405+150:
        emu.input.touch_set_pos(100, 100)

    if frame == 406+150:
        emu.input.touch_release()    

    if frame == 1500:
        a_keymask = keymask(Keys.KEY_A)
        emu.input.keypad_add_key(a_keymask)
        print("Press A")

    if frame == 1502:
        a_keymask = keymask(Keys.KEY_A)
        emu.input.keypad_rm_key(a_keymask)

    window.process_input()
    emu.cycle()
    window.draw()

Finding Desired Memory Addresses

Is there any functionality to help find desired memory addresses?

For example, if I were trying to graph my Mario Kart DS speed over time, how would I go about finding the actual address where your character's speed is located? According to this resource I should be able to find my speed at the address 0x217ACF8+0x2A8 as a 4 byte address, but emu_memory.unsigned[0x217ACF8+0x2A8:4] does not work.

Similarly, if I try to access memory addresses that I found using cheat engine on the regular DeSmuME emulator, or the RAM search and RAM watch tools of the regular BizHawk emulator, they do not work as I expect. It seems like I am accessing different memory entirely.

I'm rather new to reading memory, so please let me know if I have a conceptual misunderstanding. If anyone has a small example similar to what I am trying to do that they could share I would appreciate that.

My end goal is to develop some reinforcement learning models for DS games. My main needs are to efficiently read the upper and lower images of the emulator, read memory addresses, supply input to the emulator, and programmatically advance the emulator one frame at a time. If anyone knows of another library I should look at which might better suit my needs, please let me know. However, if I can just figure out how to access the right addresses, I'll finally have everything I need with just this library.

Thank you for your help!

pip install py-desume doesn't work on Windows

Latest version of pip 20.3.3
Python 3.7.9
Windows 10

pip install py-desume, it says:
ERROR: Could not find a version that satisfies the requirement py-desmume
ERROR: No matching distribution found for py-desmume

Cheat input

Just wondering if there is a way to interface with the chat input - adding/removing action replay codes specifically?

Custom inputs not working

Hi,
I made a simple script that opens a room and the custom input processing isn't working.
I've used the following code that is used in the documentation as a test run:
keym = keymask(Keys.KEY_A)
emu.input.keypad_add_key(keym)
emu.input.keypad_rm_key(keym)
I can see the values of emu.input.keypad_get() changing, as it does when I press a button on the keyboard, but the input isn't being shown in the game.
I am using python 3.8.7 and am on windows 7 (I also tried on a Windows 10 computer, and had the same problem)
this is my full code:
`from desmume.controls import keymask, Keys, add_key
from desmume.emulator import DeSmuME
import time
import desmume

print(desmume.controls.key_names)
emu = DeSmuME()
emu.open("Pokemon Platinum.nds")

window = emu.create_sdl_window()
i = 0
while not window.has_quit():
window.process_input()
x = str(emu.input.keypad_get())
emu.cycle()
window.draw()
i += 1
if i == 1000:
keym = keymask(Keys.KEY_A)
emu.input.keypad_add_key(keym)
print(emu.input.keypad_get())
window.process_input()
emu.cycle()
window.draw()
window.process_input()
emu.cycle()
window.draw()
emu.input.keypad_rm_key(keym)
print(emu.input.keypad_get())
img = emu.screenshot()
img.save("Image.png")
if x != "0":
print(x)
`

Running on command line without video device

I'm trying to run some simulations on a remote Linux server via command line. I have no need for a live screen input (but I will be occasionally dumping the screen as images), so I want to try to run it in a "headless" mode.

This is the error I get when I try to instantiate the emulator

emu = DeSmuME()
Microphone successfully inited.
DeSmuME 0.9.12 git#0 x64-JIT SSE4.2+AVX2
SoftRasterizer: Running using 32 additional threads. (Multithreading enabled.)
Error trying to initialize SDL: No available video device
Traceback (most recent call last):
  File "/misc/scratch/miniconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-cf54966c5578>", line 1, in <module>
    emu = DeSmuME()
  File "/misc/scratch/miniconda3/lib/python3.8/site-packages/desmume/emulator.py", line 741, in __init__
    raise RuntimeError("Failed to init DeSmuME")

Any ideas? Thanks

savestates with Desmume 9.11

It seems that the emulator gets corrupted whenever I load savestates generated by the standalone Desmume 9.11 version (and vice versa). Any fixes here? Thanks

This image whenever I upload a savestate generated by py-desmume into my standalone Desmume 9.11
image

When I do it the other way around, I get There was an error loading the savestate error.

I'm trying to switch between savestates because I need to use the standalone Desmume 9.11 for finding memory locations of interest. Obviously, this would be difficult to do in the python version because there's no disassembly/watch/etc. If there's an easy way to do it in python, that would also be great

Trouble installing

i ran setup.py with pip install -e . without any errors. but when i try to do the quick start example i get an error desumume/libdesmume.dll mussung
i am on windows with python 3.10.7

no module named 'desmume'

i wanted to mess around with this library, copy and pasted the quick start example in the documentation and i got this error

Modifying the emulation speed

Hi ! I was wondering if I could modify the emulation speed ? It seems already sped up using the startup code, maybe I missed something in the doc 😳

Advancing emulator to next instruction

The desmume.emulator.DeSmuME().cycle() method advances execution by one frame, but there doesn't seem to be a way to advance by one instruction. Does such a capability exist in py-desmume? I wasn't able to find one in the docs.

I tried to do some hacky stuff like setting a breakpoint using register_exec to the next instruction and pausing the emulator there, but this doesn't seem to work when the next instruction is the result of a branch.

Is there a way to accomplish this using py-desmume, and if not, would you be open to a PR that adds it? The latest desmume version seems to have expanded debugging features, so I'd be happy to take a look to see if there's somewhere the interface could hook into to get this into py-desmume. no promises that I would succeed, but I'm willing to try if you're open to it 😄 .

Open game State

Hi, is it possible to open a previous state when opening the game?

`emulator.memory.get_next_instruction()` function return value not what is expected

The desmume.emulator.memory.get_next_instruction() function doesn't seem to behave the way the docs specify it should. The docs say that it "(r)eturns the next instruction to be executed by the ARM9 processor", but that doesn't appear to the case. Here's a sample program demonstrating this:

from desmume.emulator import DeSmuME

e = DeSmuME()
e.open('base/out/out.nds')

def callback(address: int, size: int):
    print(f'get_next_instruction(): {hex(e.memory.get_next_instruction())}')
    print(f'register_arm9.pc: {hex(e.memory.register_arm9.pc)}')

e.memory.register_exec(0x2058954, callback)

for _ in range(500):
    e.cycle()

Output:

get_next_instruction(): 0x2058958
register_arm9.pc: 0x205895c

I've also printed out the contents of the program counter register to compare. As you can see, the value returned by get_next_instruction is 4 bytes less than that of the program counter. So, it seems that the get_next_instruction function actually returns the memory address of the most recently executed instruction.

I'm happy to contribute a PR that corrects this behavior if that would help. From what I can tell, the solution is to either
a) Change get_next_instruction() to a name more appropriate for its actual functionality, or
b) Modify get_next_instruction() to actually return the bytecode for the next ARM instruction.

Any thoughts @theCapypara? The ROM used in that sample code is Zelda: Phantom Hourglass US, if you'd like to confirm for yourself.

Windows Wheels to pip

Upload Windows wheels for native Python to pip


Beep, boop, I'm a bot! This issue was created by @Parakoopa in #scripting-help.

New release so this works on python 3.10?

Would it be possible for a new release to be cut? I see Python 3.10 support has been added to master, but the current release on pypi hasn't been updated so pip install py-desmume doesn't work with 3.10.

Need guidance on using setup.py

Hi, I would like to use py-desmume but I'm having trouble. Notably, I believe I'm supposed to build desmume, but when I ran setup.py with python setup.py install, it returned an error that it could not find the specified path. Is there a guide on how to set this up? Thanks.

emu.savestate.save() and emu.savestate.load() not working

Hello! I am trying to save and load from the Desmume slots. It works fine when saving and loading using the "save_file and load_file" but it does not work when using only "save(1)" and load(1)". Is there futher set-up that I need to do for it to work with save and load?

from desmume.emulator import DeSmuME
from desmume.controls import keymask, Keys

emu = DeSmuME()
emu.open('D:\\Dropbox\\Speed Run\\DeSmuME 9.11\\Roms\\ROMs\\NA\\0561 - Harvest Moon DS (U)(Legacy).nds')

window = emu.create_sdl_window()

frame = 0
emu.input.keypad_rm_key(Keys.KEY_A)
while not window.has_quit():

    frame += 1

    if frame == 500:
        emu.savestate.save_file("test.dsm")
        print("Save to file")

    if frame == 500:
        emu.savestate.save(1)
        print("Save to slot #1")

    if frame == 2000:
        emu.savestate.load_file("test.dsm")
        print("Load from file")

    if frame == 3000:
        emu.savestate.load(1)
        print("Load from slot #1")

    window.process_input()    

    emu.cycle()
    window.draw()

Memory leak?

I'm using py-desmume to assist with automated testing on my project. I have a series of pytest-driven tests that use py-desmume to open various NDS roms in desmume, control them, inspect their memory contents, etc. I have a singleton instance of desmume.emulator.DeSmuME that I call .open(<rom_path>) on at the start of every test.

This has worked extremely well up to this point, when I had only a couple tests. However, now that the number of tests has grown significantly, I'm running into memory usage issues. Memory usage seems to continuously climb as more roms are opened, almost as if the emulator is not properly "closing" the currently running rom and freeing it from memory. I've collected some metrics below - each time entry represents a new call to DeSmuME.open().

    Time         Memory usage (%)
---------------  ----
23:03:58.733414  23.3
23:04:35.335415  28.8
23:05:13.583826  34.5
23:05:51.558359  40.9
23:06:29.880842  53.8
23:07:08.236224  66.1
23:07:09.310240  66.4
23:07:48.239835  78.3
23:08:27.003041  91.0
23:09:06.626569  94.7
23:09:47.978964  95.7

I did not see any DeSmuME.close() method in the API docs - is there a way to tell py-desmume to close the current ROM and free its memory without calling destroy() on the entire object? If not, I think there may be some sort of memory leaking going on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.