Post subject: Making a Python-scriptable mupen64plus
mcc
Joined: 2/5/2008
Posts: 9
Hi! I've been doing a project with an N64 emulator the last couple of weeks and thought I should start trying to talk to people who know something about hacking N64 games. What I've done is extend the Python/Qt UI frontend for mupen64plus, so that it has a Python console and a setup for loading, starting and stopping scripts from disk. The scripts so far can read and write memory, can simulate controller input and can trigger code on mupen64plus breakpoints. So all stuff that as far as I know existing memory hacking tools can do, but I want to use this as a basis to make more complicated things. The two things I'm interested in doing are: 1. Automating searches for glitches, like the TTC upwarp glitch in Mario 64 2. I want to try to write a bot that can beat Mario 64 levels by itself. What I've got so far: I thought I'd post here to show what I've got so far, I also had a couple of questions. 1. I suspect I'm duplicating a certain amount of work here, actually until this weekend I didn't even know about the version of Bizhawk with the Lua scripting *_* I'm wondering how much I'm hurting myself by proceeding with Python+mupen64plus rather than switching to Bizhawk or something. Bizhawk is actually running mupen64plus on the inside, right? I glanced at the API for the Bizhawk lua scripting-- does anyone know, is it using Lua or LuaJIT (i.e.: does it have access to the luajit ffi mechanism or is it the api exposed with the stack interface)? 2. The biggest thing that worries me about proceeding with mupen64plus is that it does not currently support movie recording or playback, so I would have to hack that back into the core. The thing that worries me about this is save states. The m64 and bk2 formats both look pretty ?? simple to write, but in both cases the video starts with a savestate. Do Bizhawk and mupen64plus use the same save state format? Is there a way to convert mupen64plus save states to "old mupen64" save states?
darkszero
He/Him
Joined: 7/12/2009
Posts: 181
Location: São Paulo, Brazil
I've never written a lua script for emulators before, but I do have experience with lua scripts and have read many scripts shared on these forums. This seems a perfect use-case what is usually implemented with lua scripting. Normally you create wrappers using the lua c api and then export these wrappers to the lua scripts. If you need luajit, it shouldn't be too hard to change. And I think you will get more bizhawk support if you post of the bizhawk category.
Joined: 1/26/2009
Posts: 558
Location: Canada - Québec
One advantage of python 2/3 over lua is the amount of library available. So, I strongly encourage your current experimentation with a scriptable python interface. Thought, if LuaJIT could get implemented, so FFI call can be used as well, this could definitely offer a new kind of usage for people who dislike dealing with lua directly.
mcc
Joined: 2/5/2008
Posts: 9
BadPotato: Yeah, definitely one thing I have been viewing as an advantage of Python is having access to NumPy... As far as LuaJIT goes, I *think* it's supposed to be a drop-in replacement for the normal Lua library. So if that were actually important I suspect it wouldn't be hard to swap in. I think I am probably going to continue with my Python version. One thing I might consider trying later is hacking the same script engine I'm using with m64py into Bizhawk. That might mean I could use the same scripts on both, test them and do GUI stuff in m64py and then make videos in Bizhawk.
Amaraticando
It/Its
Editor, Player (162)
Joined: 1/10/2012
Posts: 673
Location: Brazil
I've learnt that Lua is faster than Python. Since we already experience some noticeable slowdown (if the script is complex and the emulator core is slow), would Python scripting be reasonable while TASing?
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11495
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Lua is slow when you do tons of calculations with it and you have to connect C and C# for each of them. There are Lua implementations in C#, which, if adopted, will make it run faster.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.