--If there is no controller parameter, then all of the buttons are returned as they are stored in the system, just like joypad.set(input) takes button names as is.
--If there is a controller parameter, all of the buttons for that controller are returned without the "PX ", just like joypad.set(input, controller) takes button names without the "PX " and assigns them to the matching buttons for that controller.
--No one approved this change, but seriously, this is common sense. I expect some "change denied" April Fool's stuff tomorrow...
-Implemented a blacklist for ButtonCount. By default, Lag, Pause, and Reset are blacklisted. I don't think any of these buttons should be tracked.
-adelikat has informed me that in FCEUX, savestates contained the button state of the frame on which you saved on. He claims that this is redundant because you could retrieve the state from the frame you're loading on, so BizHawk will not do this.
-As such, I just retrieved the input for the frame you're saving on before associating the data with the state.
--This essentially includes the missing info without having to depend on a movie frame to get the data from.
--In order for this to make sense, I made it so that the main joypad.get() doesn't run on a frame you're saving / loading on.
--Finally, in order to show the data from before the save frame when loading the data, I cached that data as well.
---The two above steps require collecting the data for a state once and using that until the frame is advanced or a state is loaded. Otherwise, I'd be able to increase the count significantly by saving multiple times.
-All this said and done, I think this script is perfect now, and is way more convenient to use than the FCEUX counterpart.
Notes:
-As mentioned before, it seems that the scripts are disabled when the console is reset / a movie begins playing. I don't like this to begin with, but worse yet, I noticed that this somehow makes the button data carry over from before the reset. Why is this?
-It seems that using gui.text in savestate.registersave/load causes the text to be written over the previous text instead of clearing the screen and then writing. Is this expected? How can I avoid overlapping text?
--TODO: Disallow Reset, Lag, and other non-buttons. Pause?
--If this works like adelikat says, my missing load state idea will be possible.
-Made the loading information show up on the console instead of the gui.
Note: Still need savestate.registersave/load!
-As you'll recall, the script has 3 methods of keeping track of input:
--1. Tracking the button counts in real time. This took some minor adjustments, but seems to work fine.
--2. Parsing the button presses from a loaded, read-only TAS file when starting the script, if possible.
---This works well enough after a good amount of refactoring, but I only have it rigged to work for NES.
---As always, note that this method is very slow for big movies, which is why we only use it once.
--3. Caching the counts when saving a state and loading them when loading a state.
---savestate.registerload and savestate.registersave are not currently supported by BizHawk, so this is not functioning at all.
-I propose that a function called movie.getframe(frame) be added that gets status of all of the buttons, just like joypad.get(), for a given frame of a movie.
--This makes the would make method 2 trivial and fast.
--It would allow me to generalize the function for all platforms easily.
---Certainly there might be some discrepancies about which buttons should be disallowed, if any (Is Reset a button press?), but still.
--If this method could somehow work for non-readonly movies, then I'd be able to use the movie to get the counts when I load a state that doesn't have cached data.
---Trust me when I tell you that this would be immensely useful for minimum button TASing. The process would be seamless, and all of these methods combined would provide perfect accuracy while being fairly efficient and only using intensive routines when absolutely necessary.
Note: Earlier, I came up with the idea for a function that lets you set what frame of the movie you are on, which would be useful for endless TASes like we've already discussed, adelikat. Do you still think this is worth having?