Plexa

Golden Sun 2 Utility Script v2.1

Sep 2nd, 2017
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 48.21 KB | None | 0 0
  1. -- Golden Sun 2: The Lost Age utility script v1.0 for speedrunning. Would not be possible without the help of Fox aka teawater from the gs hacking community
  2. local AD1 = 0x02000A8A -- Felix PP
  3. local AD3 = (0x0200049A) -- Next Encounter
  4. local AD4 = (0x020054C8) -- Battle RN
  5. local AD5 = (0x030011BC) -- General RN
  6. local AD6 = (0x02030194) -- Encounter Rate
  7. local AD7 = (0x020004B4) -- Kraden gets mad counter, 4+ triggers event
  8. local EncounterRate = memory.readdword(0x02000498)
  9. local CurrentRate = 0
  10. local GoodRateThreshold = 0x900 -- Hex value between 0x100 and 0x16000
  11. local gcount = 0
  12. local brncount = 0
  13. local store = memory.readdword(0x030011BC)
  14. local bstore = memory.readdword(0x020054C8)
  15. local fleestore = 0
  16. local fleepercent = 0
  17. local mem = 0x2010000
  18. local memcount = 0
  19. local RNGvalue1 = 0x6733CCBF -- lower OW GRN limit, 1300 advances + load into game
  20. local RNGvalue2 = 0x19814424 -- upper OW GRN limit, 1309 advances + load into game
  21. -- Note, I actually fucked up here. load into game value differs between OW and dungeons :(
  22. -- For OW, I am 2 GRN behind the target
  23. -- 0x16A52B8D is 1030 advances
  24. local RNGvalue3 = 0xB91AAA65 -- Title screen GRN
  25. local j=1
  26. local k=1
  27. local trn={}
  28.  
  29. local psbrn = 1
  30. local cbsbrn = 1
  31. local psc1 = 0
  32. local psc2 = 0
  33. local psc3 = 0
  34. local cbsc1 = 0
  35. local cbsc2 = 0
  36. local cbsc3 = 0
  37.  
  38. local keypress = {}
  39. local state = false
  40. local brnadvancecounter = 0
  41. local brnreducecounter = 0
  42. local grnadvancecounter = 0
  43. local grnreducecounter = 0
  44.  
  45. local valuestate = false
  46.  
  47. local timerstate = false
  48. local timeron = false
  49. local fighttimer = 0
  50. local infight = false
  51. local fighttimertext = 0
  52. local fightlength = 0
  53.  
  54. local pplock = false
  55. local ppstate = false
  56.  
  57. local encounterlock = false
  58. local encounterstate = false
  59.  
  60. local overlaystate = false
  61. local overlay = false
  62.  
  63. local minorhudlock = true
  64. local minorhudstate = false
  65.  
  66. local randomiserstate = false
  67. local randomisercounter = 0
  68.  
  69. local menustate = false
  70. local menutimeron = false
  71. local menutimer = 0
  72. local menuopen = false
  73. local menutimertext = 0
  74. local menulength = 0
  75.  
  76. local diagstate = false
  77. local diagnostics = false
  78. local memoryentry = {}
  79. local diagnostictimer = 0
  80. local extendeddiagtimer = 0
  81. local oldmemorydifferencelocation = {0,0}
  82. local areacomparisontimer = 0
  83. local areacomparisonexception = false
  84. local areacomparisontimerstate = false
  85.  
  86. local encounterNumber = 0x0203018C
  87. local avoidstate = false
  88. local avoidInfo = false
  89.  
  90. local globaltimerstate = false
  91. local globaltimeron = false
  92. local globaltimerpause = false
  93. local globaltimertext = 0
  94. local globallength = 0
  95. local globaltimerstore = {0,0,0}
  96. local globaltimerstoretimer = 0
  97.  
  98.     --eel = memory.readbyte(0x0203089E) -- venus res
  99.     --eme = memory.readbyte(0x020308A2)
  100.     --ema = memory.readbyte(0x020308A6)
  101.     --eju = memory.readbyte(0x020308A8)
  102.  
  103.     -- Vulnerability Key
  104. --12 = Drop Def 25%
  105. --13 = Drop def 12%
  106. --16 = res drop 40
  107. --17 = res drop 20
  108. --20 = delusion
  109. --23 = stun
  110. local globaltimer = 0
  111. --24 = sleep
  112. --27 = death
  113. --31 = HP steal
  114. --32 = PP steal
  115. --60 = 50% dmg to health
  116. --69 = 10% dmg to PP
  117. print("Welcome to the Golden Sun: The Lost Age Utility Script")
  118. print("Commands:")
  119. print("shift+g: advances the GRN by one")
  120. print("shift+b: advances the BRN by one")
  121. print("shift+r: advance GRN/BRN by a random amount")
  122. print("shift+t: toggle battle timer")
  123. print("shift+y: force display of last fight length (timer must be on)")
  124. print("shift+m: toggle menu timer")
  125. print("shift+,: force display of last menu length (timer must be on)")
  126. print("shift+p: lock Felix's pp to 5")
  127. print("shift+e: toggle encounters")
  128. print("shift+o: toggle map data overlay")
  129. print("shift+a: toggle minor hud")
  130. print("shift+d: oob diagnostic tool")
  131. print("shift+l: avoid information toggle")
  132. print("shift+q: toggle global timer")
  133. --print("shift+d: toggle display of Isaac's party's djinn")
  134.  
  135. while true do
  136.  
  137. gui.text(160,00,"BRN: ".. (memory.readdword(AD4)))
  138. gui.text(160,10,"GRN: ".. (memory.readdword(AD5)))
  139.  
  140. if memory.readword(0x02000420) == 0x8D then
  141.     gui.text(160,20,"Item: ".. memory.readword(0x020004FC))
  142.     gui.text(160,30,"409 = ring")
  143. end
  144.  
  145. if mem <= 0x2008000 then
  146.     mem = 0x2010000
  147.     memcount=0
  148. end
  149. if memory.readdword(mem) ~= 0 then
  150.     if memory.readdword(mem+0x4) ~=0 or memory.readdword(mem+0x8)~=0 or memory.readdword(mem+0xB)~=0 or memory.readdword(mem+0xF)~=0 or memory.readdword(mem+0x10)~=0 then
  151.     mem = 0x2010000
  152.     memcount=0
  153. end
  154. end
  155. while memcount <= 20000 and memory.readdword(mem) == 0 or mem==0x02010000 do
  156.     mem = mem-0x4
  157.     memcount = memcount+1
  158. end
  159.  
  160. gui.text(0,30,"Nonzero Tile: " .. memcount)
  161.  
  162.  
  163. --gui.text(140,20,"X: " .. (memory.readdword(0x02030ec4))/1000000)
  164. --gui.text(140,30,"Y: " .. (memory.readdword(0x02030ecc))/1000000)
  165.  
  166. --g = memory.readdword(AD5)
  167. --print(bit.tohex(g))
  168.  
  169.     -- RNG Functions
  170.  
  171. function RNA (R) -- RN Advance Function
  172.  
  173.     g = R
  174.     m1 = 0x4e6d
  175.     m2 = 0x41c6
  176.     g1 = g*m1
  177.     g2 = g*m2
  178.     g2 = bit.band(g2,0xFFFF)
  179.     g = g1 + g2*0x10000
  180.     g = bit.band(g,0xFFFFFFFF)
  181.     c=0x3039
  182.     g = g+c
  183.     g = bit.band(g,0xFFFFFFFF)
  184.     return g
  185.  
  186. end
  187.  
  188. function RNR (R) -- RN reverse Function
  189.     gout = bit.band((R-0x3039),0xFFFFFFFF) -- or 0xFFFFFFFF? 0x80000000 seems to be the cap for the RNG
  190.     multi = 0x41c64e6d
  191.     g={}
  192.     m={}
  193.     a={}
  194.     for i=1,32,1 do
  195.         if bit.band(gout,2^(i-1)) == 0 then
  196.             g[i] = 0
  197.         else
  198.             g[i] =1
  199.         end
  200.         if bit.band(multi,2^(i-1)) == 0 then
  201.             m[i] = 0
  202.         else
  203.             m[i] = 1
  204.         end
  205.     end
  206.     aleftover=0
  207.     for i=1,32,1 do
  208.         j=i
  209.         adiff = 0
  210.         while j>1 do
  211.             adiff = adiff + a[i+1-j]*m[j]
  212.             j=j-1
  213.         end
  214.         adiff = adiff + aleftover
  215.         a[i] = (g[i] + adiff)%2
  216.         aleftover = math.floor((a[i]+adiff)/2)
  217.     end
  218.     gin = 0
  219.     for i=1,32,1 do
  220.          gin = gin + 2^(i-1)*a[i]
  221.     end
  222.     gin = bit.band(gin, 0xFFFFFFFF)
  223.     --gin = gin%0x80000000
  224.      return gin
  225.  end
  226.  
  227.  
  228. function RNB (R) -- RN Advance and reduce for use in RNG calculations
  229.  
  230.     g = R
  231.     m1 = 0x4e6d
  232.     m2 = 0x41c6
  233.     g1 = g*m1
  234.     g2 = g*m2
  235.     g2 = bit.band(g2,0xFFFF)
  236.     g = g1 + g2*0x10000
  237.     c=0x3039
  238.     g = g+c
  239.     g = bit.lshift(g,8)
  240.     g = bit.rshift(g,16)
  241.     return g
  242.  
  243. end
  244.  
  245. -- Attacks First, Caught by Surprise Check
  246.  
  247. function PS (R) -- Preemptive Strike Check, 0 = nothing, 1 = PS, 2= CBS
  248.     R1=R
  249.     R2 = RNB(R1)
  250.     R1 = bit.lshift(R1,8)
  251.     R1 = bit.rshift(R1,16)
  252.     if bit.band(R1,0xF) == 0 then
  253.         return 1
  254.     else
  255.         if bit.band(R2,0x1F) ==0 then
  256.             return 2
  257.         else
  258.             return 0
  259.         end
  260.     end
  261. end
  262.  
  263.     -- Dec to Hex Function
  264.  
  265.     function DEC_HEX(IN)
  266.         local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
  267.         while IN>0 do
  268.             I=I+1
  269.             IN,D=math.floor(IN/B),math.mod(IN,B)+1
  270.             OUT=string.sub(K,D,D)..OUT
  271.         end
  272.         return OUT
  273.     end
  274.  
  275.     -- Encounter Rate Functions
  276.  
  277.     function NormalisedRate(IN) -- takes the encounter rate value returns a number between 0-100, 0 being low enc and 100 being high enc
  278.         NormRate = memory.readdword(IN)
  279.         --IsNegative = 0
  280.         if NormRate == 0 then
  281.             NormRate = ""
  282.             return NormRate
  283.         else
  284.         if NormRate >= 0xFFFF0000 then
  285.             NormRate = NormRate - 0xFFFFFFFF
  286.             --IsNegative = 1
  287.         end
  288.         NormRate = math.floor((0xFFFF - NormRate)/0xFF0)
  289.         return NormRate
  290.     end
  291.     end
  292.  
  293.     if CurrentRate ~= NormalisedRate(AD6) then
  294.     --  print(CurrentRate)
  295.     --  print(NormalisedRate(AD6))
  296.     --  print(EncounterRate)
  297.     --  print(memory.readdword(0x02000498))
  298.     --  print(EncounterRate ~= memory.readdword(0x02000498))
  299.     --  print(memory.readdword(0x02000498) < 0x100000)
  300.         if memory.readdword(AD6) == 0 then
  301.             CurrentRate = 0
  302.         end
  303.         if EncounterRate ~= memory.readdword(0x02000498) and memory.readdword(0x02000498) < 0x100000 then
  304.             if store ~= memory.readdword(0x030011BC) then
  305.                 EncounterRate = memory.readdword(0x02000498)+1
  306.             end
  307.             ColorRate1 = memory.readdword(0x02000498)-EncounterRate
  308.             ColorRateShade = 0
  309.             ColorRate2 = {255,255,255}
  310.             if ColorRate1 < 0 then
  311.                 EncounterRate = memory.readdword(0x02000498)
  312.                 ColorRate2 = {255,255,255}
  313.                 CurrentRate = 0
  314.             else
  315.                 if memory.readword(0x02000420) ~= 2 then -- world map?
  316.                     GoodRateThreshold2 = GoodRateThreshold*1.5
  317.                     if memory.readword(0x020301A0)==0xCC then -- Is Felix Walking?
  318.                         GoodRateThreshold2 = GoodRateThreshold2 / 2
  319.                     end
  320.                 else
  321.                     GoodRateThreshold2 = GoodRateThreshold
  322.                     if memory.readword(0x020301A0)==0x66 then -- Is Felix Walking?
  323.                         GoodRateThreshold2 = GoodRateThreshold2 / 2
  324.                     end
  325.                 end
  326.                 if ColorRate1 >= GoodRateThreshold2 then
  327.                     ColorRate2= {255, 0, 0}
  328.                     EncounterRate = memory.readdword(0x02000498)
  329.                     CurrentRate = NormalisedRate(AD6)
  330.                     if NormalisedRate(AD6) == "" then
  331.                         ColorRate2= {255, 255, 255}
  332.                     end
  333.                 else
  334.                     ColorRateShade = math.floor((GoodRateThreshold2-ColorRate1)/GoodRateThreshold2*255)
  335.                     if ColorRateShade <= 63 then
  336.                         ColorRate2 = {255, 4*ColorRateShade, 0}
  337.                     elseif ColorRateShade <=191 then
  338.                         ColorRate2 = {255-255*(ColorRateShade-63)/128-1, 255, 0}
  339.                     else
  340.                         ColorRate2 = {0,255,0}
  341.                     end
  342.                     EncounterRate = memory.readdword(0x02000498)
  343.                     CurrentRate = NormalisedRate(AD6)
  344.                 end
  345.             end
  346.         end
  347.     end
  348.  
  349.  
  350.  
  351.     -- begin enemy HP/encounter loops
  352.  
  353.  
  354.     -- Encounter / Level up Stats
  355.  
  356.  
  357. if memory.readword(0x02000420) ~= 0x1FE then
  358.     gui.text(0,20,"Encounter: ".. (memory.readword(AD3)))
  359.     --gui.text(160,20,"Rate: ".. (DEC_HEX(memory.readdword(AD6))))
  360.     gui.text(160,20,"Rate: ".. NormalisedRate(AD6), ColorRate2)
  361.     gui.text(0,40,"PP Regen: ".. (math.floor((memory.readword(0x020301A0))/0xFFF)))
  362.     if memory.readword(0x020004A6) ~= 0 then
  363.         gui.text(0,50,"Avoid Counter: ".. (math.floor((memory.readword(0x020004A6)/24))))
  364.     end
  365.     if memory.readword(0x020026D0) ~= 0 then
  366.         gui.text(0,50,"Akafubu Counter: ".. (math.floor((memory.readword(0x020026D0)/60))+1))
  367.     end
  368.     if minorhudlock == false then
  369.  
  370.         fagi=memory.readbyte(0x02000520+0x1C+0x14C*4)
  371.         flv=memory.readbyte(0x02000520+0x14C*4+0xF)
  372.         fagilv=-fagi+(flv-5)*4+0x1B -- imperfect levels ups discounting randomly rolled stats on new file
  373.         jagi=memory.readbyte(0x02000520+0x1C+0x14C*5)
  374.         jlv=memory.readbyte(0x02000520+0x14C*5+0xF)
  375.         jagilv=-jagi+(jlv-5)*4+0x1B -- imperfect levels ups discounting randomly rolled stats on new file
  376.         sagi=memory.readbyte(0x02000520+0x1C+0x14C*6)
  377.         slv=memory.readbyte(0x02000520+0x14C*6+0xF)
  378.         sagilv=-sagi+(slv-5)*4+0x1E -- imperfect levels ups discounting randomly rolled stats on new file
  379.         pagi=memory.readbyte(0x02000520+0x1C+0x14C*7)
  380.         plv=memory.readbyte(0x02000520+0x14C*7+0xF)
  381.         pagilv=-pagi+(plv-18)*4+0x45 -- imperfect levels ups discounting randomly rolled stats on new file
  382.         gui.text(0,140,"Missing Agi F:" .. fagilv .. " J:" .. jagilv .. " S:" .. sagilv .. " P:" .. pagilv) -- -ve numbers indicate gained agility through mint
  383.  
  384.         if memory.readbyte(0x02000040)==0xFF then -- only display this after the reunion
  385.             iagi=memory.readbyte(0x02000520+0x1C+0x14C*0)
  386.             ilv=memory.readbyte(0x02000520+0x14C*0+0xF)
  387.             iagilv=-iagi+(ilv-28)*4+0x75 --
  388.             gagi=memory.readbyte(0x02000520+0x1C+0x14C*1)
  389.             glv=memory.readbyte(0x02000520+0x14C*1+0xF)
  390.             gagilv=-gagi+(glv-28)*4+0x68 --
  391.             vagi=memory.readbyte(0x02000520+0x1C+0x14C*2)
  392.             vlv=memory.readbyte(0x02000520+0x14C*2+0xF)
  393.             vagilv=-vagi+(vlv-28)*4+0x7B --
  394.             magi=memory.readbyte(0x02000520+0x1C+0x14C*3)
  395.             milv=memory.readbyte(0x02000520+0x14C*3+0xF)
  396.             magilv=-magi+(milv-28)*4+0x6F
  397.             gui.text(48,150,"I:" .. iagilv .. " G:" .. gagilv .. " V:" .. vagilv .. " M:" .. magilv)
  398.         else
  399.             gui.text(0,150,"Kraden Counter: " .. memory.readword(AD7))
  400.         end
  401.     end
  402. end
  403.  
  404.         -- begin RNG counters
  405.  
  406.  
  407. GRN = memory.readdword(AD5)
  408. BRN = memory.readdword(AD4)
  409.  
  410. if GRN == 1710661176 then
  411.     store = 1710661176
  412.     gcount=0
  413. end
  414. store2 = store
  415. gcountstore = gcount
  416. gcountbase = 0
  417. while store ~= GRN and gcountbase <= 10000 do
  418. --print(store)
  419.     store = RNA(store)
  420.         if store <= 0 then
  421.             store = 0xFFFFFFFF+store+1
  422.             gcount = gcount +1
  423.             gcountbase = gcountbase +1
  424.         else
  425.             gcount = gcount +1
  426.             gcountbase = gcountbase +1
  427.         end
  428. end
  429. if store == GRN then
  430.     gcountbase = 0
  431.     else
  432.         store = GRN
  433.         gcountbase = 0
  434.         gcount = gcountstore
  435.         while store2 ~= GRN and gcountbase <= 100 do
  436.             --print(store)
  437.             store2 = RNR(store2)
  438.             gcount = gcount -1
  439.             gcountbase = gcountbase +1
  440.         end
  441.         if store2 == GRN then
  442.             gcountbase = 0
  443.         else
  444.             gcountbase = 0
  445.             gcount = 0
  446.         end
  447. end
  448.  
  449. bcountbase = 0
  450.  
  451. while bstore ~= BRN and bcountbase <= 100 do
  452.     bstore = RNA(bstore)
  453.     if bstore <= 0 then
  454.         bstore = 0xFFFFFFFF+bstore+1
  455.         brncount = brncount+1
  456.         bcountbase = bcountbase+1
  457.     else
  458.         brncount = brncount+1
  459.         bcountbase = bcountbase+1
  460.     end
  461. end
  462.  
  463. if bstore == BRN then
  464.     bcountbase = 0
  465. else
  466.     bstore = BRN
  467.     bcountbase = 0
  468.     brncount = 0
  469. end
  470.  
  471.  
  472. if BRN == 0 then    -- reset BRN counter on loadstate
  473. bstore = BRN
  474. bcount = 0
  475. end
  476.  
  477.  
  478.         -- RNG Gui display
  479.  
  480. gui.text(0,10,"GRN count: " .. gcount)
  481. gui.text(0,00,"BRN count: " .. brncount)
  482.  
  483.         -- PS/CBS scripts
  484. if minorhudlock == false then -- inclusion in the minor hud
  485. psb=00
  486. cbsb=00
  487.  
  488. if psbrn ~= BRN then
  489.     psb = BRN
  490.     psb = RNA(psb)
  491.     psc1 = 0
  492.     while PS(psb) ~= 1 do
  493.         psb = RNA(psb)
  494.         psc1 = psc1 + 1
  495.     end
  496.     psc2 = psc1+1
  497.     psb = RNA(psb)
  498.     while PS(psb) ~=1 do
  499.         psb = RNA(psb)
  500.         psc2 = psc2 + 1
  501.     end
  502.     psc3 = psc2+1
  503.     psb = RNA(psb)
  504.     while PS(psb) ~= 1 do
  505.         psb = RNA(psb)
  506.         psc3 = psc3 + 1
  507.     end
  508.     psbrn=BRN
  509. end
  510.  
  511. if cbsbrn ~= BRN then
  512.     cbsb = BRN
  513.     cbsb = RNA(cbsb)
  514.     cbsc1 = 0
  515.     while PS(cbsb) ~= 2 do
  516.         cbsb = RNA(cbsb)
  517.         cbsc1 = cbsc1 + 1
  518.         if cbsc1 == 100 then break end
  519.     end
  520.     cbsc2 = cbsc1+1
  521.     cbsb = RNA(cbsb)
  522.     while PS(cbsb) ~= 2 do
  523.         cbsb = RNA(cbsb)
  524.         cbsc2 = cbsc2 + 1
  525.         if cbsc2 == 102 then break end
  526.     end
  527.     cbsc3 = cbsc2+1
  528.     cbsb = RNA(cbsb)
  529.     while PS(cbsb) ~= 2 do
  530.         cbsb = RNA(cbsb)
  531.         cbsc3 = cbsc3 + 1
  532.         if cbsc3 == 104 then break end
  533.     end
  534.     cbsbrn = BRN
  535. end
  536.  
  537.     gui.text(0,80,"AF  " .. psc1 .. " " .. psc2 .. " " .. psc3)
  538.     gui.text(0,90,"CBS " .. cbsc1 .. " " .. cbsc2 .. " " .. cbsc3)
  539. end
  540.  
  541. if minorhudlock == false then
  542. Roll = memory.readdword(AD4)
  543. Roll = bit.lshift(Roll,8)
  544. Roll = bit.rshift(Roll,16)
  545. Roll = Roll*100
  546. Roll = bit.rshift(Roll,16)
  547.  
  548. gui.text(120,00,"Roll: ".. Roll)
  549. gui.text(80,0,"Area: ".. memory.readword(0x02000420))
  550. gui.text(80,10,"Door: ".. memory.readword(0x02000422))
  551. gui.text(80,20,"Retreat: ".. memory.readword(0x020004A0))
  552. end
  553.     -- Begin Flee/Assassinate Scripts
  554.  
  555.     -- Level Calculations
  556.  
  557. local   el1 = memory.readbyte(0x020308D7) -- Enemy 1 Level
  558. local el2 = memory.readbyte(0x020308D7+0x14C) -- etc
  559. local   el3 = memory.readbyte(0x020308D7+2*0x14C)
  560. local   el4 = memory.readbyte(0x020308D7+3*0x14C)
  561. local   party = memory.readbyte(0x02000040) -- Party member number
  562. local   isl= memory.readbyte(0x0200052F) -- Isaac level, +14C *user ID to get rest.
  563. -- local    gal= memory.readbyte(0x0200067b) -- etc
  564. -- local    ivl= memory.readbyte(0x020007c7)
  565. -- local    mil= memory.readbyte(0x02000913)
  566. -- local    mil= memory.readbyte(0x020008F3)
  567. -- local    mil= memory.readbyte(0x020008F3)
  568. -- local    mil= memory.readbyte(0x020008F3)
  569. -- local    mil= memory.readbyte(0x020008F3)
  570.  
  571. if memory.readword(0x02000420) == 0x1FE then
  572.  
  573. if memory.readword(0x02030A12+3*0x14C) ~= 0 then -- enemy4 index nonzero
  574.     ela = (el1+el2+el3+el4)/4
  575. elseif memory.readword(0x02030A12+2*0x14C) ~=0 then
  576.     ela = (el1+el2+el3)/3
  577. elseif memory.readword(0x02030A12+1*0x14C) ~=0 then
  578.     ela = (el1+el2)/2
  579. else
  580.     ela = el1
  581. end
  582.  
  583. pc1 = memory.readbyte(0x02000458)
  584. pc2 = memory.readbyte(0x02000459)
  585. pc3 = memory.readbyte(0x0200045A)
  586. pc4 = memory.readbyte(0x0200045B)
  587. if party == 0x70 then
  588.     ml = (memory.readbyte(0x02000520+0x14C*pc1+0xF)+memory.readbyte(0x02000520+0x14C*pc2+0xF)+memory.readbyte(0x02000520+0x14C*pc3+0xF))/3
  589. else
  590.     ml = (memory.readbyte(0x02000520+0x14C*pc1+0xF)+memory.readbyte(0x02000520+0x14C*pc2+0xF)+memory.readbyte(0x02000520+0x14C*pc3+0xF)+memory.readbyte(0x02000520+0x14C*pc4+0xF))/4
  591. end
  592.  
  593. LevelAve = ml-ela
  594.  
  595.     --Agility/HP Battle Scripts
  596.  
  597.  
  598. local pcag1=memory.readword(0x02030338+0x04)
  599. local pcag2=memory.readword(0x02030338+0x04+0x10)
  600. local pcag3=memory.readword(0x02030338+0x04+0x20)
  601. local pcag4=memory.readword(0x02030338+0x04+0x30)
  602.  
  603. if  memory.readbyte(0x02030368)==0xFF then -- Hacky way of checking if we are in fight menu or battle
  604.     if pcag1 >= 1000 then
  605.         pcag1 = 0
  606.     end
  607.     if pcag2 >= 1000 then
  608.         pcag2 = 0
  609.     end
  610.     if pcag3 >= 1000 then
  611.         pcag3 = 0
  612.     end
  613.     if pcag4 >= 1000 then
  614.         pcag4 = 0
  615.     end
  616.     gui.text(0,40,"PC" .. pc1 .. " Agi: " .. pcag1) -- Displays agility of party member pc1
  617.     gui.text(0,50,"PC" .. pc2 .. " Agi: " .. pcag2)
  618.     gui.text(0,60,"PC" .. pc3 .. " Agi: " .. pcag3)
  619.     gui.text(0,70,"PC" .. pc4 .. " Agi: " .. pcag4)
  620.  
  621.     if memory.readbyte(0x02030900)>0 then
  622.         gui.text(60,40, "E1 Agi: " .. memory.readbyte(0x020308E4)) -- If Enemy 1 has nonzero HP display E1 agility
  623.         gui.text(110,40, "HP: " .. memory.readword(0x02030900))
  624.     else
  625.     end
  626.  
  627.     if memory.readbyte(0x02030900+0x14C)>0 then
  628.         gui.text(60,50, "E2 Agi: " .. memory.readbyte(0x020308E4+0x14C))
  629.         gui.text(110,50, "HP: " .. memory.readword(0x02030900+0x14C))
  630.     else
  631.     end
  632.  
  633.     if memory.readbyte(0x02030900+0x14C*2)>0 then
  634.         gui.text(60,60, "E3 Agi: " .. memory.readbyte(0x020308E4+0x14C*2))
  635.         gui.text(110,60, "HP: " .. memory.readword(0x02030900+0x14C*2))
  636.     else
  637.     end
  638.  
  639.     if memory.readbyte(0x02030900+0x14C*3)>0 then
  640.         gui.text(60,70, "E4 Agi: " .. memory.readbyte(0x020308E4+0x14C*3))
  641.         gui.text(110,70, "HP: " .. memory.readword(0x02030900+0x14C*3))
  642.     else
  643.     end
  644.  
  645.     if memory.readbyte(0x02030900+0x14C*4)>0 then
  646.         gui.text(60,80, "E5 Agi: " .. memory.readbyte(0x020308E4+0x14C*4))
  647.         gui.text(110,80, "HP: " .. memory.readword(0x02030900+0x14C*4))
  648.     else
  649.     end
  650.  
  651. elseif memory.readbyte(0x02030368)==0xFF and memory.readbyte(0x02030358)==0xFF then -- Hacky way of accounting for three person party
  652.     gui.text(0,40,"PC" .. pc1 .. " Agi: " .. pcag1)
  653.     gui.text(0,50,"PC" .. pc2 .. " Agi: " .. pcag2)
  654.     gui.text(0,60,"PC" .. pc3 .. " Agi: " .. pcag3)
  655.  
  656.     if memory.readbyte(0x02030900)>0 then
  657.         gui.text(60,40, "E1 Agi: " .. memory.readbyte(0x020308E4)) -- If Enemy 1 has nonzero HP display E1 agility
  658.         gui.text(110,40, "HP: " .. memory.readword(0x02030900+0x14C*0))
  659.     else
  660.     end
  661.  
  662.     if memory.readbyte(0x02030900+0x14C)>0 then
  663.         gui.text(60,50, "E2 Agi: " .. memory.readbyte(0x020308E4+0x14C))
  664.         gui.text(110,50, "HP: " .. memory.readbyte(0x02030900+0x14C*1))
  665.     else
  666.     end
  667.  
  668.     if memory.readbyte(0x02030900+0x14C*2)>0 then
  669.         gui.text(60,60, "E3 Agi: " .. memory.readbyte(0x020308E4+0x14C*2))
  670.         gui.text(110,60, "HP: " .. memory.readbyte(0x02030900+0x14C*2))
  671.     else
  672.     end
  673.  
  674.     if memory.readbyte(0x02030900+0x14C*3)>0 then
  675.         gui.text(60,70, "E4 Agi: " .. memory.readbyte(0x020308E4+0x14C*3))
  676.         gui.text(110,70, "HP: " .. memory.readbyte(0x02030900+0x14C*3))
  677.     else
  678.     end
  679.  
  680.     if memory.readbyte(0x02030900+0x14C*4)>0 then
  681.         gui.text(60,80, "E5 Agi: " .. memory.readbyte(0x020308E4+0x14C*4))
  682.         gui.text(110,80, "HP: " .. memory.readbyte(0x02030900+0x14C*4))
  683.     else
  684.     end
  685.  
  686. else -- otherwise, we are in a battle and do the following
  687.  
  688.     while memory.readbyte(0x0203033C+0x10*(j-1)) ~= 0 do --while loop which checks nonzero agilities and therefore count number of actors in the battle
  689.         trn[j]= memory.readbyte(0x02030338+0x10*(j-1)) -- add the character index to the trn array in order
  690.         if trn[j]==0xFF then -- if user has already acted then do nothing
  691.             j=j+1
  692.         else
  693.             gui.text(30+15*k,40,trn[j]) -- if user hasn't acted then display user in the turn order queue
  694.             j=j+1
  695.             k=k+1
  696.         end
  697.     end
  698.     j=1
  699.     k=1
  700.     gui.text(0,40, "Turn Order: ")
  701.     if memory.readbyte(0x02030900)>0 then
  702.             gui.text(70,50, "E1 HP: " .. memory.readword(0x02030900))
  703.     end
  704. end
  705.  
  706.     -- Agility Bonus Calculator
  707. if minorhudlock == false then
  708. if memory.readbyte(0x0203033C)>0 then
  709.     local l=1
  710.     while memory.readbyte(0x02030328+0x10*l) ~= pc1 and l<15 do
  711.             l=l+1
  712.     end
  713.     if l~=15 then
  714.         pcntag1=(memory.readbyte(0x02030328+0x10*l+0x04)-memory.readbyte(0x02000BDC+0x14C*(pc1-5)))/memory.readbyte(0x02000BDC+0x14C*(pc1-5))*10000
  715.         pcntag1= math.floor(pcntag1)/100
  716.         gui.text(0,100,"PC" .. pc1 .. " Bonus: " .. pcntag1 .. "%")
  717.     end
  718.  
  719.     local l=1
  720.     while memory.readbyte(0x02030328+0x10*l) ~= pc2 and l<15 do
  721.         l=l+1
  722.     end
  723.     if l~=15 then
  724.         pcntag2=(memory.readbyte(0x02030328+0x10*l+0x04)-memory.readbyte(0x02000BDC+0x14C*(pc2-5)))/memory.readbyte(0x02000BDC+0x14C*(pc2-5))*10000
  725.         pcntag2= math.floor(pcntag2)/100
  726.         gui.text(0,110,"PC" .. pc2 .. " Bonus: " .. pcntag2 .. "%")
  727.     end
  728.  
  729.     local l=1
  730.     while memory.readbyte(0x02030328+0x10*l) ~= pc3 and l<15 do
  731.         l=l+1
  732.     end
  733.     if l~=15 then
  734.         pcntag3=(memory.readbyte(0x02030328+0x10*l+0x04)-memory.readbyte(0x02000BDC+0x14C*(pc3-5)))/memory.readbyte(0x02000BDC+0x14C*(pc3-5))*10000
  735.         pcntag3= math.floor(pcntag3)/100
  736.         gui.text(0,120,"PC" .. pc3 .. " Bonus: " .. pcntag3 .. "%")
  737.     end
  738.  
  739.     if memory.readbyte(0x0200045B)==0 and memory.readbyte(0x0200045C)==0 then
  740.     else
  741.         local l=1
  742.         while memory.readbyte(0x02030328+0x10*l) ~= pc4 and l<15 do
  743.             l=l+1
  744.         end
  745.         if l~=15 then
  746.             pcntag4=(memory.readbyte(0x02030328+0x10*l+0x04)-memory.readbyte(0x02000BDC+0x14C*(pc4-5)))/memory.readbyte(0x02000BDC+0x14C*(pc4-5))*10000
  747.             pcntag4= math.floor(pcntag4)/100
  748.             -- gui.text(0,130,"PC" .. pc4 .. " Bonus: " .. pcntag4 .. "% Roll " .. memory.readbyte(0x02030328+0x10*l+0x04))
  749.         end
  750.     end
  751. end
  752. end
  753.  
  754. fleeFail = memory.readbyte(0x02030092)
  755.  
  756. function flee(S) -- Flee Success Calculation
  757.     g = S
  758.     g = RNB(g)*10000
  759.     fl = 5000 + (2000*fleeFail) + (LevelAve * 500)
  760.     g = bit.rshift(g, 16)
  761.     if fl >= g then
  762.         return true
  763.     else
  764.         return false
  765.     end
  766. end
  767.  
  768. RN= memory.readdword(0x030011BC)
  769. count = 0
  770.  
  771. while flee(RN) == false do -- Attack Cancel to Flee Calculation
  772. count = count + 1
  773. if count == 100 then break end
  774. RN= RNA(RN)
  775. end
  776.  
  777. gui.text(160,30,"ACs to Run: " .. count)
  778.  
  779.         -- % Chance to Run
  780. fleecount = 0
  781. if fleestore ~= memory.readdword(AD5) then
  782.     fleeRN = memory.readdword(AD5)
  783.     for i=1,1000 do
  784.         if flee(fleeRN) == true then
  785.             fleecount= fleecount +1
  786.         end
  787.         fleeRN=RNA(fleeRN)
  788.     end
  789.     fleepercent = fleecount/10
  790.     fleestore = memory.readdword(AD5)
  791.     fev = fleepercent/100
  792.     EV = (fev*1+ math.floor(fev+.20,1)*(1-fev)*2+ math.floor(fev+.40,1)*(1-math.floor(fev+.20,1))*(1-fev)*3+ math.floor(fev+.60,1)*(1-math.floor(fev+.40,1))*(1-math.floor(fev+.20,1))*(1-fev)*4+ math.floor(fev+.80,1)*(1-math.floor(fev+.60,1))*(1-math.floor(fev+.40,1))*(1-math.floor(fev+.20,1))*(1-fev)*5+ (1-math.floor(fev+.80,1))*(1-math.floor(fev+.60,1))*(1-math.floor(fev+.40,1))*(1-math.floor(fev+.20,1))*(1-fev)*6)
  793.     gui.text(100,20,"Run EV: ".. EV)
  794.     gui.text(160,20,"Run%: " .. fleepercent)
  795.     else
  796.     gui.text(100,20,"Run EV: ".. EV )
  797.     gui.text(160,20,"Run%: " .. fleepercent)
  798. end
  799.  
  800. evcount = 0
  801.  
  802.  
  803. function vuln (S)
  804.     e1Ind = S
  805.     vuln1 = memory.readbyte(0x080B9E7C  + ((e1Ind - 8) * 0x4C) + 0x3E)
  806.     vuln2 = memory.readbyte(0x080B9E7C  + ((e1Ind - 8) * 0x4C) + 0x3F)
  807.     vuln3 = memory.readbyte(0x080B9E7C  + ((e1Ind - 8) * 0x4C) + 0x40)
  808.     return vuln1, vuln2, vuln3
  809. end
  810.  
  811. function enemy (S,Elm) -- Enemy Elemental Data Table
  812.         elemInd = memory.readbyte(0x080B9E7C  + ((S - 8) * 0x4C) + 0x2A)
  813.         enemyelmlevel = memory.readbyte(0x080C6684  + (elemInd * 0x18) + 4+Elm)
  814.         return enemyelmlevel
  815. end
  816.  
  817. function bchance (E) -- base chance for status
  818.     if E == 16 or E == 17 then
  819.         c = 75
  820.     elseif E == 23 then
  821.     c = 40
  822.     elseif E == 24 then
  823.     c = 35
  824.     elseif E == 27 then
  825.     c = 20
  826.     end
  827.     return c
  828. end
  829.  
  830. function effectproc (S,E,Elm,U) -- Random number, What effect is this, Elmemental Affinity 0 = Venus, 1 = Mercury, 2= Mars, 3 = Jupiter, Who is using this 0 = Isaac, 1 = Garet, 2 = Ivan, 3 = Mia
  831.     uelm = memory.readbyte(0x0200061C+0x20+U*0x14C+Elm) -- Elemental Power of User
  832.     eluc = memory.readbyte(0x020308E6) -- Enemy Luck
  833.     eind = memory.readword(0x02030A12) -- Enemy Index
  834.     eelm = enemy(eind,Elm) -- Enemy Elemental Levels
  835.     vul1, vul2, vul3 = vuln(eind) -- Enemy Vulnerability
  836.     if vul1 == E or vul2 == E or vul3 == E then -- Vulnerability key at top
  837.         v=25
  838.     else
  839.         v=00
  840.     end
  841.     if memory.readbyte(0x080C0F4C  + (U * 0xB4) + 0x92 + Elm) == 54 then
  842.         elmaff = 5
  843.     else
  844.         elmaff = 0
  845.     end
  846.     proc = (((uelm + elmaff - eelm)-(math.floor(eluc/2))*3)+bchance(E)+v)
  847.     g = RNB(S)*100
  848.     g = bit.rshift(g,16)
  849.     if proc >= g then
  850.         return true
  851.     else
  852.         return false
  853.     end
  854.     end
  855.  
  856. function unleash (S)
  857.     g = S
  858.     g = RNB(g)*100
  859.     g = bit.rshift(g,16)
  860.     if 35 >= g then
  861.         return true
  862.     else
  863.         return false
  864.     end
  865. end
  866.  
  867. -- to add; themis axe, thanatos mace?, sleep bomb, stun, pirate sword
  868. if minorhudlock == false then-- inclusion in the minor hud
  869. psword=0
  870. for i=0,29 do
  871. --print(memory.readbyte(0x02000C74+i*0x2))
  872.     if memory.readbyte(0x02000C74+i*0x2)==0x1F then -- Jenna inventory check for psword
  873.         if memory.readbyte(0x02000C75+i*0x2)==0x3 then -- Equip check
  874.         psword=1
  875.         end
  876.     elseif memory.readbyte(0x02000C74+i*0x2-0x14C)==0x1F then
  877.         if memory.readbyte(0x02000C75+i*0x2-0x14C)==0x3 then -- Equip check
  878.         psword=2
  879.         end
  880.     end
  881. end
  882. if psword==1 then -- Psword Proc Calc
  883. BRN = memory.readdword(0x020054C8)
  884. bcount=0
  885.  
  886. while effectproc(RNA(BRN),24,1,5) == false or unleash(BRN) == false do
  887.     bcount = bcount+1
  888.     if bcount == 100 then break end
  889.     BRN=RNA(BRN)
  890. end
  891.  
  892. gui.text(160,40,"Psword Sleep: " .. bcount)
  893.  
  894. end
  895. if psword==2 then -- Psword Proc Calc
  896. BRN = memory.readdword(0x020054C8)
  897. bcount=0
  898.  
  899. while effectproc(RNA(BRN),24,1,4) == false or unleash(BRN) == false do
  900.     bcount = bcount+1
  901.     if bcount == 100 then break end
  902.     BRN=RNA(BRN)
  903. end
  904.  
  905. gui.text(160,40,"Psword Sleep: " .. bcount)
  906.  
  907. end
  908.  
  909. eindex=memory.readword(0x02030A12)
  910.  
  911. sleepb=0
  912. sleepuser=0
  913. for i=0,29 do
  914. --print(memory.readbyte(0x02000C74+i*0x2))
  915.     if memory.readbyte(0x02000C74+i*0x2)==0xE3 then
  916.     sleepb=1
  917.     sleepuser=5
  918.     elseif memory.readbyte(0x02000C74+0x14C+i*0x2)==0xE3 then
  919.     sleepb=1
  920.     sleepuser=6
  921.     elseif memory.readbyte(0x02000C74-0x14C+i*0x2)==0xE3 then
  922.     sleepb=1
  923.     sleepuser=4
  924.     elseif memory.readbyte(0x02000C74+i*0x2+0x14C*2)==0xE3 then -- Inventory check for sleepbomb
  925.     sleepb=1
  926.     sleepuser=7
  927.     end
  928. end
  929. if sleepb == 1 and eindex ~= 0x5B then
  930.     bcount=0
  931.     while effectproc(BRN,24,3,sleepuser) == false do
  932.     bcount=bcount+1
  933.     if bcount==100 then break end
  934.     BRN=RNA(BRN)
  935.     end
  936.     gui.text(160,50,"Sleep bomb: " .. bcount)
  937. end
  938.  
  939. if memory.readbyte(0x02000520+5*0x14C+0x129) >= 0x46 and memory.readbyte(0x02000520+5*0x14C+0x129) <= 0x54 then -- Jenna Class Check
  940.     BRN = memory.readdword(0x020054C8)
  941.     bcount=0
  942.  
  943.     while effectproc(BRN,16,3,5) == false do -- Weaken calculation
  944.         bcount = bcount+1
  945.         if bcount == 100 then break end
  946.         BRN=RNA(BRN)
  947.     end
  948.  
  949. gui.text(160,50,"Jenna Weaken: " .. bcount)
  950.  
  951. end
  952.  
  953. if memory.readbyte(0x02000520+4*0x14C+0x129) >= 0x46 and memory.readbyte(0x02000520+4*0x14C+0x129) <= 0x54 then -- Felix Class Check
  954.     BRN = memory.readdword(0x020054C8)
  955.     bcount=0
  956.  
  957.     while effectproc(BRN,16,3,4) == false do -- Weaken calculation
  958.         bcount = bcount+1
  959.         if bcount == 100 then break end
  960.         BRN=RNA(BRN)
  961.     end
  962.  
  963. gui.text(160,60,"Felix Weaken: " .. bcount)
  964.  
  965. if eindex == 0x5B then
  966.     Sour = memory.readdword(0x020054C8)
  967.     Sour = RNA(Sour)
  968.     bcount=0
  969.     while effectproc(Sour,16,3,7) == false do
  970.     bcount = bcount + 1
  971.     if bcount == 100 then break end
  972.     Sour = RNA(Sour)
  973.     end
  974.     gui.text(160,70, "Sour " .. bcount)
  975. end
  976.  
  977.  
  978. end
  979. end
  980.         -- Drop Stuff
  981.  
  982. function drop(S)
  983.     return memory.readbyte(0x080B9E7C+((S-8)*0x4C+0x44)), memory.readbyte(0x080B9E7C+((S-8)*0x4C+0x46))
  984. end
  985. function itemdrop(S,C)
  986.     g = RNB(S)*100
  987.     g = bit.rshift(g,16)
  988.     if C >= g then
  989.         return true
  990.     else
  991.         return false
  992.     end
  993. end
  994. function droprate(S,ch) -- enemy index, chance of drop
  995.     BRN = memory.readdword(0x020054C8)
  996.     bcount=0
  997.     bcount2=0
  998.     rate=bit.rshift(0x64,ch-1)
  999.     rate2=bit.rshift(0x64,ch-3)
  1000.         while itemdrop(BRN,rate) == false do
  1001.             bcount=bcount+1
  1002.                 if itemdrop(BRN,rate2) == true then
  1003.                 bcount2=bcount
  1004.                 end
  1005.                 if bcount == 100 then break end
  1006.             BRN=(RNA(BRN))
  1007.         end
  1008.     return bcount, bcount2
  1009. end
  1010. if minorhudlock == false then -- including drop stuff within the minor hud
  1011. if memory.readbyte(0x02030900)>0 then
  1012.     eindex=memory.readword(0x02030A12)
  1013.     dr,ch = drop(eindex)
  1014.     if dr == 0xE3 or dr == 0x44 then -- dropped item is something I care about, 0xE3 is sleep bomb, 0x44 is staff of anubis
  1015.         A,B= droprate(eindex,ch)
  1016.     gui.text(140,80, "E1 Item: " .. dr .. " Turns " .. A .. "|" .. B) -- A=turns without djinn, B=turns with djinn
  1017.     end
  1018. end
  1019.  
  1020. if memory.readbyte(0x02030900+0x14C)>0 then
  1021.     eindex2=memory.readword(0x02030A12+0x14C)
  1022.     dr,ch=drop(eindex2)
  1023.     if dr == 0xE3 or dr==0x44 then -- dropped item is something I care about, 0xE3 is sleep bomb
  1024.         A,B= droprate(eindex,ch)
  1025.         gui.text(140,100, "E2 Item: " .. dr .. " Turns " .. A .. "|" .. B)
  1026.     end
  1027. end
  1028.  
  1029. if memory.readbyte(0x02030900+0x14C*2)>0 then
  1030.     eindex3=memory.readword(0x02030A12+0x14C*2)
  1031.     dr,ch=drop(eindex3)
  1032.     if dr == 0xE3 or dr==0x44 then -- dropped item is something I care about, 0xE3 is sleep bomb
  1033.         A,B= droprate(eindex,ch)
  1034.         gui.text(140,120, "E3 Item: " .. dr .. " Turns " .. A .. "|" .. B)
  1035.     end
  1036. end
  1037. end
  1038. --end
  1039.  
  1040.  
  1041. -- if memory.readbyte(0x02000048)>=0x70 and memory.readbyte(0x02000155) < 0x14 then -- If you have mist, return mist information
  1042.  
  1043. -- BRN = memory.readdword(0x020023A8)
  1044. -- bcount=0
  1045.  
  1046. -- while effectproc(RNA(BRN),24,1,3) == false or unleash(BRN) == false do -- mist calculation
  1047.     -- bcount = bcount+1
  1048.     -- if bcount == 100 then break end
  1049.     -- BRN=RNA(BRN)
  1050. -- end
  1051. -- gui.text(160,50,"Mist: " .. bcount)
  1052. -- end
  1053. --end
  1054.  
  1055. end
  1056.  
  1057. --eindex=memory.readword(0x02030A12)
  1058.  
  1059. -- This code is for BRN / GRN advance via keypresses (note AD4 = BRN and AD5 = GRN)
  1060.  
  1061. keypress = input.get()
  1062. if state == true and keypress["G"] == nil and keypress["H"] == nil and keypress["B"] == nil and keypress["N"] == nil and keypress["plus"] == nil and keypress["minus"] == nil then
  1063.     state = false
  1064. end
  1065. if state == false and keypress["B"] == true and keypress["shift"] == true then
  1066.     memory.writedword(AD4,RNA(memory.readdword(AD4)))
  1067.     brnadvancecounter = 30
  1068.     state = true
  1069. end
  1070. if state == false and keypress["N"] == true and keypress["shift"] == true then
  1071.     memory.writedword(AD4,RNR(memory.readdword(AD4)))
  1072.     brnreducecounter = 30
  1073.     state = true
  1074.     bstore = memory.readdword(AD4)
  1075.     brncount = brncount - 1
  1076. end
  1077. if state == false and keypress["G"] == true and keypress["shift"] == true then -- remove the shift condition is two buttons are annoying
  1078.     memory.writedword(AD5,RNA(memory.readdword(AD5)))
  1079.     grnadvancecounter = 30
  1080.     state = true
  1081. end
  1082.  
  1083.     if state == false and keypress["H"] == true and keypress["shift"] == true then -- remove the shift condition is two buttons are annoying
  1084.         memory.writedword(AD5,RNR(memory.readdword(AD5)))
  1085.         grnreducecounter = 30
  1086.         state = true
  1087.         store = memory.readdword(AD5)
  1088.         gcount = gcount - 1
  1089.     end
  1090. if state == false and keypress["plus"] == true and keypress["shift"] == true then -- remove the shift condition is two buttons are annoying
  1091.     --if memory.readdword(AD5) == 0x80000000 then
  1092.     --  memory.writedword(AD5,0)
  1093.     --end
  1094.     memory.writedword(AD5,(memory.readdword(AD5)+1)%0x80000000) -- increase GRN by one
  1095.     grnadvancecounter = 30
  1096.     state = true
  1097. end
  1098. if state == false and keypress["minus"] == true and keypress["shift"] == true then -- remove the shift condition is two buttons are annoying
  1099.     --if memory.readdword(AD4) == 0x80000000 then
  1100.     --  memory.writedword(AD4,0)
  1101.     --end
  1102.     memory.writedword(AD4,(memory.readdword(AD4)+1)%0x80000000) -- increase BRN by one
  1103.     brnadvancecounter = 30
  1104.     state = true
  1105. end
  1106.  
  1107. if brnadvancecounter >= 1 then
  1108.     --gui.text(100,100, "BRN advanced by one","#00FF00")
  1109.     gui.text(225,00, "+1","#00FF00")
  1110.     brnadvancecounter = brnadvancecounter-1
  1111. end
  1112. if brnreducecounter >= 1 then
  1113.     --gui.text(100,100, "BRN advanced by one","#00FF00")
  1114.     gui.text(225,00, "-1","#FF0000")
  1115.     brnreducecounter = brnreducecounter-1
  1116. end
  1117. if grnadvancecounter >= 1 then
  1118.     --gui.text(100,100, "GRN advanced by one","#00FF00")
  1119.     gui.text(225,10, "+1","#00FF00")
  1120.     grnadvancecounter = grnadvancecounter-1
  1121. end
  1122. if grnreducecounter >= 1 then
  1123.     --gui.text(100,100, "GRN advanced by one","#00FF00")
  1124.     gui.text(225,10, "-1","#FF0000")
  1125.     grnreducecounter = grnreducecounter-1
  1126. end
  1127.  
  1128. -- This code is for setting the RNG to key values
  1129. if valuestate == false and keypress["V"] == true and keypress["shift"] == true then
  1130.     -- memory.writedword(AD4, 0x0)              -- BRN set to 0
  1131.     -- memory.writedword(0x02000498, 0)     -- Encounter rate to 0
  1132.     -- memory.writedword(0x02030194, 0)     -- Reset Encounter Generation
  1133.     if memory.readdword(0x02000420) == 0x00010001 then
  1134.         memory.writedword(AD5, bit.band(RNGvalue3,0xFFFFFFFF))
  1135.         print("GRN set to title screen value")
  1136.         valuestate = true
  1137.     else
  1138.         if memory.readdword(AD5) == RNGvalue1 then
  1139.                 memory.writedword(AD5,RNGvalue2)
  1140.                 print("GRN set to upper bound")
  1141.             --elseif memory.readdword(AD5) == RNGvalue2 then
  1142.             else
  1143.                 memory.writedword(AD5,RNGvalue1)
  1144.                 print("GRN set to lower bound")
  1145.             end
  1146.             valuestate = true
  1147.         end
  1148.     end
  1149. if valuestate == true and keypress["V"] == nil then
  1150.     valuestate = false
  1151. end
  1152.  
  1153.  
  1154. -- This code is for a fight timer, toggled by shift+T
  1155. -- This block is for toggling the timer on and off
  1156. if timerstate == false and timeron == false and keypress["T"] == true and keypress["shift"] == true then
  1157.     timerstate = true
  1158.     timeron = true
  1159.     print("Timer enabled. Press t to reset the timer at any point.")
  1160. end
  1161. if timerstate == false and timeron == true and keypress["T"] == true and keypress["shift"] == true then
  1162.     timerstate = true
  1163.     timeron = false
  1164.     fighttimer = 0
  1165.     print("Timer disabled.")
  1166. end
  1167. if timerstate == false and timeron == true and keypress["T"] == true and keypress["shift"] == nil then
  1168.     fighttimer = 0
  1169.     timerstate = true
  1170.     --print("Timer reset.") -- this gets annoying to print after a while
  1171. end
  1172. if timerstate == true and keypress["T"] == nil then
  1173.     timerstate = false
  1174. end
  1175. -- This code is the fight timer
  1176. if timeron == true then
  1177.     if memory.readbyte(0x02030468) == 0xFF then
  1178.         gui.text(0,20, "Timer " .. math.floor(fighttimer/60) .. "s")
  1179.         fighttimer = fighttimer+1
  1180.         infight = true
  1181.     end
  1182.     if infight == true and memory.readbyte(0x02030468) == 0x0 then
  1183.         fighttimertext = 360
  1184.         fightlength = fighttimer
  1185.         fighttimer = 0
  1186.         infight = false
  1187.     end
  1188.     if fighttimertext >= 1 then
  1189.         gui.text(0,100, "Last Fight " .. math.floor(fightlength/6)/10 .. "s (" .. fightlength .. " frames)","#00FF00")
  1190.         fighttimertext = fighttimertext - 1
  1191.     end
  1192.     if keypress["Y"] == true and keypress["shift"] == true then
  1193.         fighttimertext = 360
  1194.     end
  1195. end
  1196. -- This code is for a menu timer, toggled by shift+M
  1197. -- This block is for toggling the timer on and off
  1198. --if menustate == false and menutimeron == false and keypress["M"] == true and keypress["shift"] == true then
  1199. --  menustate = true
  1200. --  menutimeron = true
  1201. --  print("Menu timer enabled.")
  1202. --end
  1203. --if menustate == false and menutimeron == true and keypress["M"] == true and keypress["shift"] == true then
  1204. --  menustate = true
  1205. --  menutimeron = false
  1206. --  menutimer = 0
  1207. --  print("Menu timer disabled.")
  1208. --end
  1209. --if menustate == true and keypress["M"] == nil then
  1210. --  menustate = false
  1211. --end
  1212. -- This code is the menu timer
  1213. -- if menutimeron == true then
  1214. --  if memory.readword(0x02000060) == 0x50 then
  1215. --      gui.text(160,20, "Menu Timer " .. math.floor(menutimer/60) .. "s")
  1216. --      menutimer = menutimer+1
  1217. --      menuopen = true
  1218. --  end
  1219. --  if menuopen == true and memory.readbyte(0x02000060) == 0x0 then
  1220. --      menutimertext = 360
  1221. --      menulength = menutimer
  1222. --      menutimer = 0
  1223. --      menuopen = false
  1224. --  end
  1225. --  if menutimertext >= 1 then
  1226. --      gui.text(160,30, "Last Menu " .. math.floor(menulength/6)/10 .. "s","#00FF00")
  1227. --      gui.text(160,40, "(" .. menulength .. " frames)","#00FF00")
  1228. --      menutimertext = menutimertext - 1
  1229. --  end
  1230. --  if keypress["comma"] == true and keypress["shift"] == true then
  1231. --      menutimertext = 360
  1232. --  end
  1233. --end
  1234. -- This code is for locking Felix's pp
  1235. if ppstate == false and keypress["P"]==true and keypress["shift"]==true and pplock == false then
  1236.     pplock = true
  1237.     ppstate = true
  1238.     print("Felix PP lock enabled")
  1239. end
  1240. if ppstate == false and keypress["P"]==true and keypress["shift"]==true and pplock == true then
  1241.     pplock = false
  1242.     ppstate = true
  1243.     print("Felix PP lock disabled")
  1244. end
  1245. if ppstate == true and keypress["P"]==nil then
  1246.     ppstate = false
  1247. end
  1248. if pplock == true then
  1249.     memory.writeword(AD1,0x5)
  1250. end
  1251. -- This code is for toggling encounters
  1252. if encounterstate == false and keypress["E"]==true and keypress["shift"]==true and encounterlock == false then
  1253.     encounterlock = true
  1254.     encounterstate = true
  1255.     print("Encounters disabled")
  1256. end
  1257. if encounterstate == false and keypress["E"]==true and keypress["shift"]==true and encounterlock == true then
  1258.     encounterlock = false
  1259.     encounterstate = true
  1260.     print("Encounters enabled")
  1261. end
  1262. if encounterstate == true and keypress["E"]==nil then
  1263.     encounterstate = false
  1264. end
  1265. if encounterlock == true then
  1266.     memory.writeword(AD3,0x1)
  1267. end
  1268. -- This code is for the map data overlay
  1269.  
  1270. if overlaystate == false and keypress["O"]==true and keypress["shift"]==true and overlay == false then
  1271.     overlay = true
  1272.     overlaystate = true
  1273.     print("Overlay enabled")
  1274. end
  1275. if overlaystate == false and keypress["O"]==true and keypress["shift"]==true and overlay == true then
  1276.     overlay = false
  1277.     overlaystate = true
  1278.     print("Overlay disabled")
  1279. end
  1280. if overlaystate == true and keypress["O"]==nil then
  1281.     overlaystate = false
  1282. end
  1283. if overlay == true and infight == false then
  1284.     tile = memory.readdword(0x020301A4)
  1285.     tile_value = memory.readword(tile)
  1286.     gui.text(130,20,"Tile Address: 0x".. string.format("%x",tile))
  1287.     gui.line(108, 98, 123, 98)
  1288.     gui.line(123, 98, 123, 108)
  1289.     gui.line(123, 108, 108, 108)
  1290.     gui.line(108, 108, 108, 98)
  1291.  
  1292.     isaacDataAddr = memory.readdword(memory.readdword(0x0300006C) + 0x24)
  1293.     isaacX = memory.readdword(isaacDataAddr + 0x8)
  1294.     isaacY = memory.readdword(isaacDataAddr + 0x10)
  1295.  
  1296.     isaacLayer = memory.readbyte(isaacDataAddr + 0x22)
  1297.     layerAddrH = memory.readdword((memory.readdword(0x03000020) + 0x13C + (isaacLayer * 0x38)))
  1298.  
  1299.     tileOffset = bit.rshift(isaacX, 0x14) + (bit.rshift(isaacY, 0x14) * 0x80)
  1300.  
  1301.     currentHeightTile = memory.readbyte(layerAddrH + tileOffset)
  1302.     --gui.text(122,30,"Height address: 0x" .. string.format("%x",layerAddrH+tileOffset))
  1303.     function HeightTile(Xcoord, Ycoord, Layer)
  1304.         layerAddrH = memory.readdword((memory.readdword(0x03000020) + 0x13C + (Layer * 0x38)))
  1305.         tileOffset = bit.rshift(Xcoord, 0x14) + (bit.rshift(Ycoord, 0x14) * 0x80)
  1306.         HeightT = memory.readbyte(layerAddrH + tileOffset)
  1307.         return HeightT
  1308.     end
  1309.  
  1310.     function compress(S)
  1311.         R = bit.rshift(memory.readdword(S),16)
  1312.         R = bit.band(R,0xFF)
  1313.         return R
  1314.         end
  1315.  
  1316.     function colortla(X,Y,Z)
  1317.             T = HeightTile(isaacX,isaacY,isaacLayer)
  1318.             U = HeightTile(X,Y,Z)
  1319.             if T == U then
  1320.                 C= "white"
  1321.             elseif  T < U then
  1322.                 shade = math.min((U-T)/4*255,255)
  1323.                 C = { 255, 255-shade, 255-shade}
  1324.             elseif T > U then
  1325.                 shade = math.min((T-U)/4*255,255)
  1326.                 C = { 255-shade, 255, 255}
  1327.             end
  1328.             return C
  1329.         end
  1330.  
  1331.     if memory.readword(0x02000420) == 2 then
  1332.         for i=-4,4 do
  1333.         for j=-4,4 do
  1334.             gui.text(110+j*15,100+i*15, compress(tile+0x80*i+0x4*j), colortla(memory.readdword(0x020322F4)+1000000*j,memory.readdword(0x020322FC)+1000000*i,isaacLayer))
  1335.         end
  1336.         end
  1337.     else
  1338.         for i=-4,4 do
  1339.         for j=-4,4 do
  1340.             gui.text(110+j*15,100+i*15, compress(tile+0x200*i+0x4*j), colortla(memory.readdword(0x020322F4)+1000000*j,memory.readdword(0x020322FC)+1000000*i,isaacLayer))
  1341.         end
  1342.         end
  1343.     end
  1344. end
  1345. -- This code is for toggling af / cbs / missing agility display
  1346. if minorhudstate == false and keypress["A"]==true and keypress["shift"]==true and minorhudlock == false then
  1347.     minorhudlock = true
  1348.     minorhudstate = true
  1349.     print("Minor hud disabled")
  1350. end
  1351. if minorhudstate == false and keypress["A"]==true and keypress["shift"]==true and minorhudlock == true then
  1352.     minorhudlock = false
  1353.     minorhudstate = true
  1354.     print("Minor hud enabled")
  1355. end
  1356. if minorhudstate == true and keypress["A"]==nil then
  1357.     minorhudstate = false
  1358. end
  1359.  
  1360. --This code is for randomising the GRN/BRN by advancing the GRN/BRN a random number of times
  1361. if randomiserstate == true and keypress["R"] == nil then
  1362.     randomiserstate = false
  1363. end
  1364. if randomiserstate == false and keypress["R"] == true and keypress["shift"] == true then
  1365.     randomisercounter = 50
  1366.     randomiserstate = true
  1367. end
  1368. if randomisercounter == 50 then
  1369.     grnrandomadvance = math.random(1,100)
  1370.     brnrandomadvance = math.random(1,100)
  1371.     for i=1,grnrandomadvance do
  1372.         memory.writedword(AD5,RNA(memory.readdword(AD5)))
  1373.     end
  1374.     for i=1,brnrandomadvance do
  1375.         memory.writedword(AD4,RNA(memory.readdword(AD4)))
  1376.     end
  1377. end
  1378. if randomisercounter >= 1 then
  1379.     --gui.text(100,100, "BRN advanced by one","#00FF00")
  1380.     gui.text(225,00, "+" .. brnrandomadvance,"#00FF00")
  1381.     gui.text(225,10, "+" .. grnrandomadvance,"#00FF00")
  1382.     randomisercounter = randomisercounter-1
  1383. end
  1384.  
  1385. -- This code is for the oob diagnostic tool
  1386. if diagstate == false and keypress["D"]==true and keypress["shift"]==true and diagnostics == false then
  1387.     diagnostics = true
  1388.     currentarea = memory.readword(0x02000420)
  1389.     memorysnapshot = true
  1390.     diagstate = true
  1391.     memoryentry = {}
  1392.     oldmemorydifferencelocation = {0,0}
  1393.     print("OOB Diagnostis enabled")
  1394. end
  1395. if diagstate == false and keypress["D"]==true and keypress["shift"]==true and diagnostics == true then
  1396.     diagnostics = false
  1397.     diagstate = true
  1398.     print("OOB Diagnostis disabled")
  1399. end
  1400. if diagstate == true and keypress["D"]==nil then
  1401.     diagstate = false
  1402. end
  1403.  
  1404. if diagnostics == true then
  1405.     if memorysnapshot == true then -- take a snapshot of the memory for later comparisons
  1406.         for i=1,4096 do
  1407.             memorysum = 0
  1408.             memorysum = memorysum+memory.readword(0x02020000+0x4*i)
  1409.             memoryentry[i] = memorysum
  1410.         end
  1411.         memorysnapshot = false
  1412.     end
  1413.     if currentarea ~= memory.readword(0x02000420) then -- when area changes compare against snapshot
  1414.         if memory.readword(0x02000420) == 0x1FE and areacomparisonexception == false then -- battles have a 36 frame delay before memory is loaded, this script waits 36 frames for that to happen
  1415.             areacomparisontimer = 37
  1416.             areacomparisontimerstate = true
  1417.             areacomparisonexception = true
  1418.         end
  1419.         if memory.readword(0x02000420) ~= 0x1FE then
  1420.             areacomparisonexception = false
  1421.         end
  1422.         diagcounter = 0
  1423.         while diagcounter <= 4096 and areacomparisontimerstate == false do
  1424.             diagcounter = diagcounter + 1
  1425.             memorysum = 0
  1426.             memorysum = memorysum+memory.readword(0x02024000-0x4*diagcounter)
  1427.             memorycomparison = memorysum
  1428.             if memorycomparison ~= memoryentry[4096-diagcounter] then
  1429.                 -- memorysnapshot = true
  1430.                 memorydifferencelocation = 0x02024000-0x4*diagcounter
  1431.                 oldmemorydifferencelocation[2] = oldmemorydifferencelocation[1]
  1432.                 oldmemorydifferencelocation[1] = memorydifferencelocation
  1433.                 diagnostictimer = 300
  1434.                 break
  1435.             end
  1436.         end
  1437.         if areacomparisontimer == 1 then
  1438.             areacomparisontimerstate = false
  1439.         else
  1440.             areacomparisontimer = areacomparisontimer -1
  1441.         end
  1442.         if areacomparisontimer == 0 then
  1443.             currentarea = memory.readword(0x02000420)
  1444.         end
  1445.     end
  1446.     if diagnostictimer >= 1 then
  1447.         diagnostictimer = diagnostictimer - 1
  1448.         gui.text(60,90, "Tile difference at 0x" .. string.format("%x",memorydifferencelocation),"#FF0000")
  1449.     end
  1450.     if keypress["D"] == true and keypress["shift"] == nil then
  1451.         extendeddiagtimer = 300
  1452.     end
  1453.     if extendeddiagtimer >= 1 then
  1454.         extendeddiagtimer = extendeddiagtimer - 1
  1455.         gui.text(60,100, "Current difference at 0x" .. string.format("%x",oldmemorydifferencelocation[1]),"#FF0000")
  1456.         gui.text(60,110, "Previous difference at 0x" .. string.format("%x", oldmemorydifferencelocation[2]),"#FF0000")
  1457.         gui.text(60,120, "Delta: " .. string.format("%x", oldmemorydifferencelocation[1]-oldmemorydifferencelocation[2]),"#FF0000")
  1458.     end
  1459. end
  1460.  
  1461. -- This code is for the Avoid information
  1462. if avoidstate == false and keypress["L"]==true and keypress["shift"]==true and avoidInfo == false then
  1463.     avoidInfo = true
  1464.     MobIndex = {0,0}
  1465.     PartySize = 0
  1466.     TargetLevel = 0
  1467.     avoidstate = true
  1468.     print("Avoid information enabled")
  1469. end
  1470. if avoidstate == false and keypress["L"]==true and keypress["shift"]==true and avoidInfo == true then
  1471.     avoidInfo = false
  1472.     avoidstate = true
  1473.     print("Avoid information disabled")
  1474. end
  1475. if avoidstate == true and keypress["L"]==nil then
  1476.     avoidstate = false
  1477. end
  1478. if avoidInfo == true then
  1479.     if MobIndex[1] ~= memory.readbyte(encounterNumber) or MobIndex[2]~=memory.readbyte(encounterNumber+1) then
  1480.         MobIndex = {memory.readbyte(encounterNumber),memory.readbyte(encounterNumber+1)}
  1481.         if MobIndex[1] ~= 0 then
  1482.             TargetLevel = memory.readword(0x080EDACC + MobIndex[1]*0x1C + 2)
  1483.         else
  1484.             TargetLevel = memory.readword(0x080EDACC + MobIndex[2]*0x1C + 2)
  1485.         end
  1486.     end
  1487.     if avoidcurrentarea ~= 0x1FE then
  1488.         if memory.readbyte(0x02000040) ~= PartySize then -- would have been better to bit.rshift this instead of this hacky way
  1489.             FelixInParty = bit.band(0x10,memory.readbyte(0x02000040))/0x10
  1490.             JennaInParty = bit.band(0x20,memory.readbyte(0x02000040))/0x20
  1491.             ShebaInParty = bit.band(0x40,memory.readbyte(0x02000040))/0x40
  1492.             PiersInParty = bit.band(0x80,memory.readbyte(0x02000040))/0x80
  1493.             IsaacInParty = bit.band(0x1,memory.readbyte(0x02000040))/0x1
  1494.             GaretInParty = bit.band(0x2,memory.readbyte(0x02000040))/0x2
  1495.         IvanInParty = bit.band(0x4,memory.readbyte(0x02000040))/0x4
  1496.             MiaInParty = bit.band(0x8,memory.readbyte(0x02000040))/0x8
  1497.             PartySize = memory.readbyte(0x02000040)
  1498.         end
  1499.         PartyLevel =  math.floor((memory.readbyte(0x0200052F)*IsaacInParty + memory.readbyte(0x0200052F+0x14C)*GaretInParty +
  1500.                                     memory.readbyte(0x0200052F+0x14C*2)*IvanInParty + memory.readbyte(0x0200052F+0x14C*3)*MiaInParty +
  1501.                                     memory.readbyte(0x0200052F+0x14C*4)*FelixInParty + memory.readbyte(0x0200052F+0x14C*5)*JennaInParty +
  1502.                                     memory.readbyte(0x0200052F+0x14C*6)*ShebaInParty + memory.readbyte(0x0200052F+0x14C*7)*PiersInParty)/(
  1503.                                     IsaacInParty+GaretInParty+IvanInParty+MiaInParty+FelixInParty+JennaInParty+ShebaInParty+PiersInParty))
  1504.         gui.text(80,0,'Target Level: ' .. TargetLevel)
  1505.         gui.text(80,10,'Party Level: ' .. PartyLevel)
  1506.     end
  1507. end
  1508.  
  1509. -- This code is for a global timer, toggled by shift+Q
  1510. -- This block is for toggling the timer on and off and pausing the timer
  1511. if globaltimerstate == false and globaltimeron == false and keypress["Q"] == true and keypress["shift"] == true then
  1512.     globaltimerstate = true
  1513.     globaltimeron = true
  1514.     print("Global timer enabled.")
  1515.     print("Press q to reset the timer at any point.")
  1516.     print("Press w to pause or unpause the timer.")
  1517.     print("Press tab to record a time.")
  1518.     print("Press shift+w to display last three recorded times.")
  1519. end
  1520. if globaltimerstate == false and globaltimeron == true and keypress["Q"] == true and keypress["shift"] == true then
  1521.     globaltimerstate = true
  1522.     globaltimeron = false
  1523.     globaltimer = 0
  1524.     print("Global timer disabled.")
  1525. end
  1526. if globaltimerstate == false and globaltimeron == true and keypress["Q"] == true and keypress["shift"] == nil then
  1527.     globaltimer = 0
  1528.     globaltimerstate = true
  1529.     print("Global timer reset")
  1530. end
  1531. if globaltimerstate == false and globaltimeron == true and globaltimerpause == false and keypress["W"] == true and keypress["shift"] == nil then
  1532.     globaltimerpause = true
  1533.     globaltimerstate = true
  1534. end
  1535. if globaltimerstate == false and globaltimeron == true and globaltimerpause == true and keypress["W"] == true and keypress["shift"] == nil then
  1536.     globaltimerpause = false
  1537.     globaltimerstate = true
  1538. end
  1539. if globaltimerstate == true and keypress["W"] == nil and keypress["Q"] == nil and keypress["tab"] == nil then
  1540.     globaltimerstate = false
  1541. end
  1542. -- This code is the global timer
  1543. if globaltimeron == true then
  1544.     if globaltimerpause == false then
  1545.         gui.text(0,120, "Timer " .. math.floor(globaltimer/60) .. "s")
  1546.         globaltimer = globaltimer+1
  1547.     end
  1548.     if globaltimerpause == true then
  1549.         gui.text(0,120, "Timer " .. math.floor(globaltimer/6)/10 .. "s " .. globaltimer .. " frames","#FFFF00")
  1550.     end
  1551.     if keypress["tab"] == true and globaltimerstate == false then
  1552.         globaltimerstore[3] = globaltimerstore[2]
  1553.         globaltimerstore[2] = globaltimerstore[1]
  1554.         globaltimerstore[1] = globaltimer
  1555.         globaltimer = 0
  1556.         globaltimerstate = true
  1557.         print("Time recorded")
  1558.     end
  1559.     if keypress["W"] == true and keypress["shift"] == true and globaltimerstate == false then
  1560.         globaltimerstoretimer = 360
  1561.         globaltimerstate = true
  1562.     end
  1563.     if globaltimerstoretimer >= 1 then
  1564.         if globaltimerstore[1] >= 1 then
  1565.             gui.text(0,90, "Time #1 " .. math.floor(globaltimerstore[1]/6)/10 .. "s " .. globaltimerstore[1] .. " frames","#00FF00")
  1566.         end
  1567.         if globaltimerstore[2] >= 1 then
  1568.             gui.text(0,100, "Time #2 " .. math.floor(globaltimerstore[2]/6)/10 .. "s " .. globaltimerstore[2] .. " frames","#00FF00")
  1569.         end
  1570.         if globaltimerstore[3] >= 1 then
  1571.             gui.text(0,110, "Time #3 " .. math.floor(globaltimerstore[3]/6)/10 .. "s " .. globaltimerstore[3] .. " frames","#00FF00")
  1572.         end
  1573.         globaltimerstoretimer = globaltimerstoretimer - 1
  1574.     end
  1575. end
  1576.  
  1577.  
  1578.     vba.frameadvance();
  1579.  
  1580. end
Add Comment
Please, Sign In to add comment