Advertisement
Guest User

Dash levels lap skip script (BizHawk)

a guest
Jun 29th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. local function inject_old_y_tracker()
  2.     -- storing the old_y used for the lap calculation in a variable that we can read at the end of the frame
  3.     memory.write_u32_le(0x0C027C, 0x31EF0000) -- andi t7, 0x0          | clearing t7
  4.     memory.write_u32_le(0x0C028C, 0x3C0F8007) -- lui t7, 0x8007        | t7 = 0x80070000
  5.     memory.write_u32_le(0x0C0294, 0x35EF4900) -- ori t7, t7, 0x4900    | t7 = 0x80074900
  6.     memory.write_u32_le(0x0C029C, 0x0012C880) -- sll t9, s2, 0x2       | t9 = 4 * player_id
  7.     memory.write_u32_le(0x0C02A0, 0x00000000) -- nop                   | taking out the x > 0 from the logic
  8.     memory.write_u32_le(0x0C02A4, 0x01F97820) -- add t7, t7, t9        | t7 = 0x80074900 + 4 * player_id
  9.     memory.write_u32_le(0x0C02B0, 0x2858FE13) -- slti t8, v0, 0xFE13   | changing registers so we can save old_y
  10.     memory.write_u32_le(0x0C02B4, 0x1700001D) -- bne t8, zero, 0x001d  | changing registers so we can save old_y
  11.     memory.write_u32_le(0x0C02B8, 0xADE20000) -- sw v0, 0x0(t7)        | t7 <- old_y
  12. end
  13.  
  14. local function read_pointer(address)
  15.     x = memory.read_u32_le(address)
  16.     if (x == 0) then
  17.         return 0
  18.     end
  19.     return memory.read_u32_le(address) - 0x80000000
  20. end
  21.  
  22. -- Variables
  23. player_pointer = 0x09D530
  24. y = 0
  25. x = 0
  26. old_y = 0
  27. last_y = 0
  28. even_frame = true
  29. i = 0
  30.  
  31. while true do
  32.     -- I'm always injecting the tracker every frame because it's less annoying when dealing with save states
  33.     inject_old_y_tracker()
  34.  
  35.     -- Since Bash is a 30fps game, only gather data each 2 frames
  36.     if even_frame then
  37.  
  38.         -- Read data from memory
  39.         player_struct = read_pointer(player_pointer)
  40.         x = memory.read_s32_le(player_struct + 0x10)
  41.         y = memory.read_s32_le(player_struct + 0x18)
  42.         old_y = memory.read_s32_le(0x074900)
  43.     end
  44.  
  45.     -- If your old Y isn't the Y from the last frame, a mismatch happened
  46.     if old_y ~= last_y then
  47.         gui.text(2, 60, "Old Y mismatch", "yellow")
  48.     end
  49.  
  50.     gui.text(2, 80, "Old y: " .. old_y, "white")
  51.     gui.text(2, 100, "Y: " .. y, "white")
  52.  
  53.     -- Lap logic (lap skips happens because of old y mismatches due to collisions with A.Is)
  54.     if x > 0 and old_y > -494 and y < -493 then
  55.         gui.text(2, 120, "LAP COMPLETED" .. i, "green")
  56.         if even_frame then
  57.             i = i + 1
  58.         end
  59.     end
  60.  
  61.     gui.text(2, 140, "LAP #" .. i, "white")
  62.  
  63.     -- Only update the last_y in the odd frame
  64.     if not even_frame then
  65.         last_y = y
  66.     end
  67.  
  68.     -- Change the parity of the frame
  69.     even_frame = not even_frame
  70.  
  71.     emu.frameadvance()
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement