YesNoOk
avatar

lua scripts for Bizhawk (06-29-23) (Read 19877 times)

Started by N., June 21, 2021, 11:06:10 pm
Share this topic:

N.

lua scripts for Bizhawk (06-29-23)
#1  June 21, 2021, 11:06:10 pm
  • avatar
  • ***
Here's some .lua scripts for Bizhawk to attempt to help make it easier to rip character sprites (these won't work with older versions because they renamed the keybinds).  These started off as simple constant/conditional writes because I suck at lua, but then I wanted my "press _ to _" conditionals to stop firing every frame, and that threw me down a rabbit hole.  It resulted in me making it so you can switch various things on and off (repurposing unused RAM for all of this probably isn't the correct way to do this, but it works).
I'm going to copy/paste the key list from the .lua files.  You're welcome to check the comments in the .lua files with a text editor to see if there's any passive effects I didn't mention (going by memory because the .doc I initially typed up got corrupted).

I used A, S, H, Q, W, E, R, T, Y, U, I, O, P, 1-6, and 1-5 + direction keys for the conditional keys (I don't remember if anything's mapped to them by default, since I blanked whatever I didn't think I'd need and set everything else to Shift+_).  Pressing ` will bring up a key list popup (do not hold it, unless you really like closing luacanvas windows).  That's no longer an issue.  I keep forgetting every time I use a new key, I have to add it to the "and not" list for the button press timer so I can use the conditional I made for it.

Use BSNES core for SNES games.  The scripts won't work properly if you don't (anything using snes.setlayer_ won't work, and you'll get error messgages because there's no CGRAM in SNES9X core).

Spoiler: (SNES) Mighty Morphin' Power Rangers: Fighting Edition (click to see content)
Spoiler: (Sega CD) Eternal Champions 2: Challenge From the Dark Side (click to see content)
Spoiler: (PSX) Samurai Deeper Kyo (click to see content)
Spoiler: (SNES) Clayfighter 2: Judgement Clay (click to see content)
Spoiler: (PSX) Tatsunoko Fight (click to see content)
Spoiler: (GBA) Advance Guardian Heroes (click to see content)
Spoiler: (SNES) Battle Master - Kyuukyoku no Senshi-tachi (click to see content)
Spoiler: (SNES) Battle Tycoon Flash Hiders SFX 1.1 (click to see content)
Spoiler: (SNES) Rushing Beat Ran (click to see content)
Spoiler: (Sega CD) Revengers of Vengeance (click to see content)
Spoiler: (Genesis) Eternal Champions (click to see content)

Edit: Updated Clayfighter 2 because the regular characters were locked as a side effect of unlocking the alt characters (there's an address for character slots and a bunch of unlock flag addresses for all of the characters.  My script only had unlock flags for the alt characters because "why would you need to check the regular characters unlock flags?  It's not like this script can force them to somehow be switched off, right?" ).
1 Last Updated: 4/19/23
2 Last Updated: 1/16/21
3 Last Updated: 04/20/23
4 Last Updated: 7/16/17
Last Edit: June 29, 2023, 07:19:17 am by N.
Re: lua scripts for Bizhawk (5-12-22)
#2  December 24, 2022, 05:00:01 pm
  • avatar
Xavier Sprites Won't Freezes Color Shifting With Green Color Using Recolor Background to Green. Eternal Champions Challenge From the Dark Side Scripts

N.

Re: lua scripts for Bizhawk (5-12-22)
#3  December 25, 2022, 12:04:27 am
  • avatar
  • ***
I added something to freeze the timer for his eyes.
1 Last Updated: 4/19/23
2 Last Updated: 1/16/21
3 Last Updated: 04/20/23
4 Last Updated: 7/16/17
Re: lua scripts for Bizhawk (5-12-22)
#4  December 25, 2022, 05:37:55 pm
  • avatar
Can you make a Lua Scripts of Battle Monsters (Saturn), Battle Master: Kyuukyoku no Senshitachi (Snes), Strip Fighter 2 (PCE), Battle Tycoon: Flash Hiders SFX (Snes), Revengers of Vengeance (Sega CD), Rushing Beat Ran (Snes), The Incredibles (GBA), Gekido Advance (GBA), Eternal Champions 1 (Genesis), and Burning Fists: Force Striker (Prototype) (Sega CD) for Ripped Sprites and Sound This Bizhawk.
Last Edit: December 26, 2022, 02:46:21 pm by Th3W0r53
Re: lua scripts for Bizhawk (5-12-22)
#5  December 26, 2022, 08:08:24 am
  • *
    • Japan
    • http://sakisukebekkan.blog.fc2.com/
Excuse me, could you please make a Lua for Gundam Battle Assault 2 (PSX)?
I have been capturing sprites of this game in the past using RAM Search and adjusting them with cheat codes, but I am having trouble disabling some FX layers and some Mega Special attacks are making the camera move when it is supposed to be fixed.
I know the address is quite complicated, but please help me.

N.

Re: lua scripts for Bizhawk (5-12-22)
#6  December 26, 2022, 11:43:48 pm
  • avatar
  • ***
Ok, Battle Masters and Battle Tycoon are done.  Rushing Beat Ran's going to be.  It could've been done, but I kept trying to get around having to find addresses for the enemies (this is fine for MAME, but notsomuch for Bizhawk).  Cycling through sprites is going to suck because some animations aren't arranged the way you'd think they are.  I don't know about Eternal Champions yet because I was stuck dealing with hiding BG layers (turns out I was wrong about how I thought it was all set up) and trying to find where the colors are in the RAM.  The issue I've run into is seeing if I can find a way to cycle through the sprites like with Eternal Champions 2.  Edit: I haven't found something to cycle through sprites.  I can cycle through frames of an animation and I can sorta get a certain sprite to display.
Don't know about the others yet.

Edit: 2 of those are beat 'em ups, so I may not do them because I either have to find a way to force the enemy to change into the other enemies or find what you'd need for P1 for every possible enemy slot and then figure out how the hell to get it to work in lua.  Revengers of Vengeance I very briefly did, but that was to check color and tile modding.  The game's sorta in a rippable state if I use tilemodding on a certain stage.  Haven't found color mods yet. I hope Genesis and Sega CD use this color format for all of their games because of how stupidly simple it is to get a value to search for from a screenshot (it only took me stumbling into how to recolor the black BG by messing in the 68K RAM).  Battle Monsters I very briefly looked at.  I sorta turned the black BG magenta, but it was by accident and I haven't hidden whatever can't be hidden by disabling layers yet.

olt-EDEN: I'll look at it when I can.

Edit: Rushing Beat Ran's done.

Edit2: I got fed up of dealing with guitext (the text goes away when you release the key, but the box just stays there) and figured out another way to show you the keylist (it involves making a luacanvas window pop up that has the text on it).  All of the luascripts have it now, and all of them will probably use it going forward.
1 Last Updated: 4/19/23
2 Last Updated: 1/16/21
3 Last Updated: 04/20/23
4 Last Updated: 7/16/17
Last Edit: December 27, 2022, 11:24:38 pm by N.
Re: lua scripts for Bizhawk (12-26-22)
#7  December 27, 2022, 09:21:40 pm
  • avatar
I Forgot a Mention, make a Lua scripts for Tuff E Nuff (Snes), Power Moves (Snes), Fighter's History: Mizoguchi Kiki Ippatsu!! (Snes), Doomsday Warrior (Snes), Teenage Mutant Ninja Turtles: Tournament Fighters (Snes), and Flash Hiders (PCE)

Edit: Doomsday Warrior (Snes)
Edit2: There also Flash Hiders on PCE
Last Edit: December 29, 2022, 12:56:57 am by Th3W0r53

N.

Re: lua scripts for Bizhawk (01-31-24)
#8  October 16, 2023, 07:05:19 am
  • avatar
  • ***

Samurai Deeper Kyo

This weirdness in the form of a lua script is something I came up with while attempting to type up a tutorial.  It uses a lot of conditionals and repurposed memory to attempt to make a cheat menu like the one MAME uses (I went with what I know.  I'm not as proficient at lua as I'd like to be).
You're welcome to try and repurpose it, but you'll have to keep the following in mind:

- This is set up for PSX resolution on a 2x window.  You'll have to do a bit of messing around with with it to get it to look right for anything else.  The drawbox is the resolution minus 1 pixel, and everything is spaced by 11 pixels vertically (in light of recent changes).  The list text and activated/inactive cheat text has different x position values.  Also, it'll probably not look right if you maximize the window (the quirks of guitext and guidrawbox are why I went with luacanvas popups for explaining how to use my cheats).  Sorry about that.
-  You'll have to use the hex editor to find unused memory to repurpose for your cheats.
-  This uses conditionals to keep track of whether you're in the menu, what screen you're on (I did 3 screens of cheats, but it uses a 16-bit value, because why not?), what position the cursor is at on the screen, and what buttons you're pressing.  You'll mainly want to keep an eye on the ListNumber and CheatList.  If you want your cheat to work outside of the menu, you'll have to account for that too (I have conditionals trigger when my menu addresses have a nonzero value). 
One more thing: The MenuMem addresses are not only for the previously mentioned usage outside the menu, but they're also used for switching cheats on/off, so you'll wanna keep track of how you use those too.

Spoiler: my various progress updates (click to see content)
1 Last Updated: 4/19/23
2 Last Updated: 1/16/21
3 Last Updated: 04/20/23
4 Last Updated: 7/16/17
Last Edit: February 16, 2024, 05:18:54 am by N.

N.

Re: lua scripts for Bizhawk (02-13-24)
#9  February 13, 2024, 10:47:13 pm
  • avatar
  • ***
Hello again.  If you've been following this thread, thanks and I'm sorry for all the updates.  If you haven't, but have seen my earlier post, I've made a lot of progress since then.  Moreso when I asked ChatGPT to help me out with some stuff.  This version's a lot more easier to use and the code's more easier to read (it has to be, since I intended for others to be able to easily repurpose it to make their own cheat lists).  I've tested it with 4 different game systems to see if there's anything that would cause me to struggle with adding cheats. 
You'll still have to use the hex editor to search the RAM for unused memory to get this all working though (if you want to repurpose it.  It should be fine if you use it for ripping sprites in vs mode). 

Things to pay attention to for this version:
(If you're going to completely repurpose this for another game system).
- The memory domain at the top (probably doesn't need to be there, but you never know).
- The names of the controller inputs, so that you can disable then when the menu is active (more on this below).
- The addresses being used, and how you use your menumem globals for values over 1 byte.
- The maximum value of CursorPositions.
- The values for listEntry (1 past the maximum value and the maximum value).
- The maximum value of ICTYPosition.
- How many entries are on a page (which means adding/subtracting an entry from the draw cheat list).

(If you're going to add a new cheat):
- The ListPageNo value (what page of cheats it should be on).
- The ListEntry value (where it'll show up on the list to that page).
- The ICTYPosition (should be the same value as the ListEntry value.  The y position of your interactive text will be affected by what you set this value as.  It's currently a multiple of 0x0B because of the textscale value).  No calculations required.
- Again, your addresses and globals (I should've set it up the way it currently is from the start).

Keylist:
O: Opens/closes the menu
Backtick/Tilde: Prints list of joypad inputs to lua console (commented out)
Up, down, left, right: Interacts with the menu
Enter: Sets/pokes a value for certain cheats
Q, W: Deincrements/increments a value by 10/0x0A for certain cheats
E: Sets a value for certain cheats.
Note: Some of these have a repeat delay applied to them, so holding them down will increment/deincrement the value faster.

I wanna mention some minor issues (besides the ones that I'll inevitably have to fix because I overlooked something):
- These scripts have a code in them intended to disable controller inputs while the menu is active (SNES: Gamepad, PSX: DualShock, Genesis/SegaCD: Six Button).  It's only for one of the multiple controller settings that exist, so if you find you're able to press those buttons while the menu is active, I've added something that will print the names of all your inputs to the lua console (didn't want to get them all only to have the code stop working.  I've had this code break on me because I used it for 2 different things, but I did something wrong to one of them).  Just remove the --[[ and ]] around "-- Have lua console print list of controller inputs.", and it should work when you press the backtick/tilde key.

- At the bottom is something I initially made to make it easier to position the text on the screen.  It's pretty much useless now because of tying most of the stuff to X/Y position mod addresses and simplified the y position code, but if you have something you want to put on the screen and want to use it figure out where it'll show up, it's at the bottom commented out like the code for telling you the names of your controller inputs.  You'll have to tweak it, since it's set up to move by 1x11 pixels though.  It uses I and numpad numbers 2, 4, 6, and 8.

Spoiler: images (click to see content)
https://www.mediafire.com/file/fwfas7c83ycaor5/EternalChampions_MM.lua/file
https://www.mediafire.com/file/dii58c856vurgzz/EternalChampions_2_MM.lua/file
https://www.mediafire.com/file/1dvjmk14fuu2gk2/SamuraiDeeperKyo_MM.lua/file
https://www.mediafire.com/file/2ufwww3j58g9k6c/Weaponlord_MM.lua/file

Edit: Ok, it's fixed now.  Forgot to fix the freeze champions color timer cheat.

Edit: I've just came up with a crazy/dumb idea, asked ChatGPT, and eventually came up with a lua script for going through a memory domain and saving you a list of addresses that have 0x00000000 for the value:
Spoiler, click to toggle visibilty
I think this can be improved by making it check those domains at different points in the game using savestates, and generating a list after it's compared the values of those addresses. Nevermind.  I couldn't get it to work.
1 Last Updated: 4/19/23
2 Last Updated: 1/16/21
3 Last Updated: 04/20/23
4 Last Updated: 7/16/17
Last Edit: February 16, 2024, 05:16:18 am by N.

N.

Re: lua scripts for Bizhawk (02-29-23)
#10  February 22, 2024, 02:19:57 am
  • avatar
  • ***
Hello again.  I didn't think I'd be adding any more to this thread so soon, but I was able to make some more things with ChatGPT's help.  Much like the cheat menus, you'll need to search for unused memory addresses to get them working.  Since I built them on my MAME styled menu, their behavior is similar (you use O and the arrow keys.  Hold them down for faster movement).


https://www.mediafire.com/file/s0t18rjyaoqjztg/snes_color_test.lua/file
Script 1: 16-bit color tool
It's like GBA color tool and buddmelvin's color converter.  You take a 24-bit color value you got from a screenshot, use this to set the three color channels as close as you can without going over, and try searching for the 16-bit color value it gives you.  This doesn't take into account flipped color channels, or sometimes having to add 0x8000 to the value for PSX games (not always, but it's a thing that happens).  What you could use this for: SNES, GBA, Arcade, PSX, Saturn, etc.  This one's used quite a bit.


https://www.mediafire.com/file/ipbywu80uov193z/genesis-segacd_color_test.lua/file
Script 2: Sega Genesis/CD color tool
This one's kinda weird with how I had to set it up because it only uses 1 1/2 bytes for the 3 color channels.  It'll probably display weird because it's set up for Genesis.


These could someday be usable in Bizhawk, so I made them in case that ever happens.



https://www.mediafire.com/file/p6308k2t7c4mq8i/ms_dos_color_test.lua/file
Script 3: MS-Dos color tool (whatever games I had to load up in Dosbox anyways.  The arcade version of Battletoads uses this)
There was a point in time that this would've been very useful to me.


https://www.mediafire.com/file/agf963n2g19xd57/cps2_color_test.lua/file
Script 4: CPS2 color tool
If Bizhawk ever lets you have access to the colorram/palram for CPS2 games, this might somehow be something resembling useful then.  Might.  This works backwards because of color values repeating at various points (you set the half bytes to a 16-bit value, and it tells you the decimal values to that color channel).  You should probably set white to 0x0F first and go from there. 
When I tried this with SFA, I wasn't able to use MAME's cheat search to find these color values, but when I went to the addresses the colorram's at I found 2 color addresses using the values from the screenshot and eyeballing the value the tool gave me.


Edit: I've changed the orientation of the hex values for the CPS2 tool.  Should've been like that from the start, TBH.  I also fixed the cursor getting cropped because of my trying to avoid using drawbox.
1 Last Updated: 4/19/23
2 Last Updated: 1/16/21
3 Last Updated: 04/20/23
4 Last Updated: 7/16/17
Last Edit: March 01, 2024, 12:54:08 am by N.

N.

Re: lua scripts for Bizhawk (03-23-24)
#11  March 24, 2024, 05:20:55 am
  • avatar
  • ***
Hello again.  So here's another bit of craziness I've come up with with ChatGPT's help. 


It's a script that tries to *automate brute-force checking values to an address (you can modify it for other things, but I initially made it to see if I could find the Character Test in Street Fighter Alpha 2 yet again) minus the inconvenience of the value sometimes getting reset for whatever reason (ex: loading a savestate and increasing the value at the same time.  I'm looking at you, artmoney/cheat engine).  Since this saves the (decimal) value to a .txt file as it increments it (it'll appear in the same folder as this script), it doesn't matter if the emulator crashes or you can't do it in one sitting.

*What it does is add 1 to the current value of an address, save that value to a text file, load savestate 1 after 60 frames, and write the saved value in the text file to the address.  It also shows you the value of the address on the screen in decimal and hexadcimal so you don't have to do a RAM watch.

Set up:
You need save state slot 1 containing the thing you want to observe.  Increasing the emulator speed or going to "if frameCount == 60 then" and changing 60 to a lower value (but not too low.  The frame counter is ticking as it loads your savestate) can make it go faster.  Opening the RAM Search and Hex Editor will make it slow down.
Every instance of 0x8000 needs to be changed to the address you want to observe.  memory.write_u16_le and memory.read_u16_le need to be changed depending on what you're doing with the values.  MainRAM needs to be changed to the memory domain containing the value you want to observe.

Code:
memory.usememorydomain("MainRAM")
local valueFile = "value.txt"

function saveValue(value)
    local file = io.open(valueFile, "w")
    file:write(value)
    file:close()
end

function loadValue()
    local file = io.open(valueFile, "r")
    if file then
        local value = file:read("*n")
        file:close()
        return value
    else
        return 0
    end
end

local frameCount = 0
local savestateLoaded = false

function hex(val)
    val = string.format("%X", val)
    return val
end

while true do
    gui.drawText(0x0, 0x0, "0x8000 (Dec): " .. (memory.read_u16_le(0x8000)), 0XFFFFFFFF, 0XFF000000, 0x0B, "Arial", "normal", "left", "top")
    gui.drawText(0x0, 0x0B, "0x8000 (Hex): " .. hex(memory.read_u16_le(0x8000)), 0XFFFFFFFF, 0XFF000000, 0x0B, "Arial", "normal", "left", "top")
   
    local value = loadValue() or 0
    memory.write_u16_le(0x8000, value + 0x01)
   
    emu.frameadvance()
    frameCount = frameCount + 1
   
    if frameCount == 60 then
        savestate.loadslot(1)
        value = value + 0x01
        memory.write_u16_le(0x8000, value)
        saveValue(value)
        frameCount = 0
        savestateLoaded = false
    end
end
1 Last Updated: 4/19/23
2 Last Updated: 1/16/21
3 Last Updated: 04/20/23
4 Last Updated: 7/16/17