Advertisement
exodus122

Triple Slash Clip Tester (Lua)

Jun 1st, 2022 (edited)
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. -- oot_triple_slash_clip_brute_force.lua
  2. --
  3. -- Brute force search for triple slash clip angles
  4. -- Used for Ocarina of Time NTSC 1.0
  5. --
  6. -- Author: Exodus
  7. -- Created: June 1st, 2022
  8.  
  9. function hexTranslator(result)
  10.   if result >= 16 then
  11.     local intQuotient = math.floor(result / 16)
  12.     local remainder = result % 16
  13.     return hexTranslator(intQuotient) .. hexTranslator(remainder)
  14.   else
  15.     if result == 10 then
  16.       io.write("A")
  17.       return "A"
  18.     elseif result == 11 then
  19.       io.write("B")
  20.       return "B"
  21.     elseif result == 12 then
  22.       io.write("C")
  23.       return "C"
  24.     elseif result == 13 then
  25.       io.write("D")
  26.       return "D"
  27.     elseif result == 14 then
  28.       io.write("E")
  29.       return "E"
  30.     elseif result == 15 then
  31.       io.write("F")
  32.       return "F"
  33.     else
  34.       io.write(result)
  35.       return tostring(result)
  36.     end
  37.   end
  38. end
  39.  
  40. -- Constants
  41. X_ADDR = 0x1DAA54
  42. Y_ADDR = 0x1DAA58
  43. Z_ADDR = 0x1DAA5C
  44. ANGLE_ADDR = 0x1DAAE6
  45. ANIM_ADDR = 0x1DABDE
  46. C_LEFT_ADDR = 0x11A639
  47. bow = 3
  48. slingshot = 6
  49. hookshot = 10
  50. boomerang = 14
  51. itemNames = {}
  52. itemNames[3] = "bow  "
  53. itemNames[6] = "sling"
  54. itemNames[10] = "hook "
  55. itemNames[14] = "rang "
  56.  
  57. function attemptTSC(angle, frameNum, item)
  58.     -- Load state
  59.     savestate.loadslot(2)
  60.    
  61.     -- Read starting coords
  62.     xpos1 = mainmemory.readfloat(X_ADDR, true)
  63.     ypos1 = mainmemory.readfloat(Y_ADDR, true)
  64.     zpos1 = mainmemory.readfloat(Z_ADDR, true)
  65.     -- print("START: "..xpos.." "..ypos.." "..zpos)
  66.    
  67.     -- Set Angle and C-Left item
  68.     mainmemory.write_u16_be(ANGLE_ADDR, math.fmod(angle, 0x10000))
  69.     mainmemory.write_s8(C_LEFT_ADDR, item)
  70.    
  71.     -- Attempt Triple Slash clip
  72.     repeat -- press b every other frame until link performs a triple slash
  73.         joypad.set({["B"] = true}, 1)
  74.         emu.frameadvance()
  75.         joypad.set({["B"] = false}, 1)
  76.         emu.frameadvance()
  77.     until (mainmemory.read_u16_be(ANIM_ADDR) == 0x2978)
  78.    
  79.     for f=0,(frameNum*3 + 22) do -- start holding Z
  80.         joypad.set({["Z"] = true}, 1)
  81.         emu.frameadvance()
  82.     end
  83.    
  84.     for f=0,30 do -- pull first person item
  85.         joypad.set({["Z"] = true, ["C Left"] = true}, 1)
  86.         emu.frameadvance()
  87.     end
  88.    
  89.     -- Read ending coords
  90.     xpos2 = mainmemory.readfloat(X_ADDR, true)
  91.     ypos2 = mainmemory.readfloat(Y_ADDR, true)
  92.     zpos2 = mainmemory.readfloat(Z_ADDR, true)
  93.    
  94.     xzDistance = math.floor(math.sqrt((xpos2 - xpos1)^2 + (zpos2 - zpos1)^2) * 100) / 100
  95.     yDistance = math.floor((ypos2 - ypos1) * 100) / 100
  96.    
  97.     if xzDistance > 10 then
  98.         CLIPPED = true
  99.        
  100.         --print(hexTranslator(math.fmod(angle, 0x10000)).." - xz ("..xzDistance.."), y ("..yDistance..")")
  101.         if yDistance < -20 then
  102.             print(hexTranslator(math.fmod(angle, 0x10000)).." ("..itemNames[item]..", "..frameNum..") - Fall ("..xzDistance..")")
  103.         else
  104.             print(hexTranslator(math.fmod(angle, 0x10000)).." ("..itemNames[item]..", "..frameNum..") - Clip ("..xzDistance..")")
  105.         end
  106.     end
  107. end
  108.  
  109. START_ANGLE = 0x1E1C
  110. END_ANGLE = 0x1E1C
  111. if END_ANGLE < START_ANGLE then
  112.     END_ANGLE = END_ANGLE + 0x10000
  113. end
  114.  
  115. CLIPPED = false
  116. print("START: "..hexTranslator(START_ANGLE)..", END: "..hexTranslator(END_ANGLE))
  117.  
  118. for angle = START_ANGLE, END_ANGLE, 0x10 do
  119.     attemptTSC(angle, 1, hookshot)
  120.     attemptTSC(angle, 2, hookshot)
  121.     attemptTSC(angle, 3, hookshot)
  122.     attemptTSC(angle, 4, hookshot)
  123.     attemptTSC(angle, 1, bow)
  124.     attemptTSC(angle, 2, bow)
  125.     attemptTSC(angle, 3, bow)
  126.     attemptTSC(angle, 4, bow)
  127. end
  128.  
  129. if CLIPPED == false then
  130.     print("failed to find anything")
  131. end
  132.  
  133. print("DONE!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement