Advertisement
Anwonu

ML:PiT script

Feb 19th, 2016
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. -- auxiliary functions; don't worry about them (unless something's wrong)
  2. -- http://stackoverflow.com/questions/5977654/lua-bitwise-logical-operations
  3.  
  4. local function BitXOR(a,b)--Bitwise xor
  5.     local p,c=1,0
  6.     while a>0 and b>0 do
  7.         local ra,rb=a%2,b%2
  8.         if ra~=rb then c=c+p end
  9.         a,b,p=(a-ra)/2,(b-rb)/2,p*2
  10.     end
  11.     if a<b then a=b end
  12.     while a>0 do
  13.         local ra=a%2
  14.         if ra>0 then c=c+p end
  15.         a,p=(a-ra)/2,p*2
  16.     end
  17.     return c
  18. end
  19.  
  20. local function BitOR(a,b)--Bitwise or
  21.     local p,c=1,0
  22.     while a+b>0 do
  23.         local ra,rb=a%2,b%2
  24.         if ra+rb>0 then c=c+p end
  25.         a,b,p=(a-ra)/2,(b-rb)/2,p*2
  26.     end
  27.     return c
  28. end
  29.  
  30. local function BitNOT(n)
  31.     local p,c=1,0
  32.     while n>0 do
  33.         local r=n%2
  34.         if r<1 then c=c+p end
  35.         n,p=(n-r)/2,p*2
  36.     end
  37.     return c
  38. end
  39.  
  40. local function BitAND(a,b)--Bitwise and
  41.     local p,c=1,0
  42.     while a>0 and b>0 do
  43.         local ra,rb=a%2,b%2
  44.         if ra+rb>1 then c=c+p end
  45.         a,b,p=(a-ra)/2,(b-rb)/2,p*2
  46.     end
  47.     return c
  48. end
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. -- this is where you want to change stuff
  57.  
  58. -- RNG:
  59. --- U: 0x02060A86
  60. --- E: 0x02060E06
  61. --- J: 0x02060DE6
  62.  
  63. -- stache (same for all versions?):
  64. --- Mario: 0x0233C42A
  65. --- Luigi: 0x0233C44E
  66. --- BMario: 0x1233C472
  67. --- BLuigi: 0x1233C496
  68.  
  69. -- enemies (E)
  70. local pos_x = {0x020D1302, 0x020D1406, 0x020D150A, 0x020D160E, 0x020D1712, 0x020D1816}
  71. local pos_y = {0x020D1304, 0x020D1408, 0x020D150C, 0x020D1610, 0x020D1714, 0x020D1818}
  72. local arr_hp = {0x020D2066, 0x020D2306, 0x020D25A6, 0x020D2846, 0x020D2AE6, 0x020D2D86}
  73. local arr_lv = {0x020D2084, 0x020D2324, 0x020D25C4, 0x020D2864, 0x020D2B04, 0x020D2DA4}
  74.  
  75. -- rng stuff
  76. local arr_stache = {0x0233C42A, 0x0233C44E, 0x1233C472, 0x1233C496} -- M, L, m, l
  77. local arr_name  = {"M", "L", "m", "l"}
  78. local arr_color = {"red", "green", "red", "green"}
  79. local rng, luckyvalue, luckychance
  80. local hasLucky
  81.  
  82. -- others
  83. local v_space = 12
  84. local hp, x, y
  85. local numEn
  86. local output
  87.  
  88. local function nextRNG(seed)
  89.     local res = BitAND(math.floor(seed * 20.5), 0x7fff)
  90.     if seed % 2 == 1 then
  91.         res = res + 0x8000
  92.     end
  93.    
  94.     return res
  95. end
  96.  
  97. local function top(x, y, text, c1, c2)
  98.     gui.text(x, y - 190, text, c1, c2)
  99. end
  100.  
  101. local function bot(x, y, text, c1, c2)
  102.     gui.text(x, y, text, c1, c2)
  103. end
  104.  
  105. function fn()
  106.     -- shows HP close to enemies' position
  107.     numEn = 0
  108.     for i = 1,6 do
  109.         hp = memory.readword(arr_hp[i])
  110.         x = memory.readbyte(pos_x[i])
  111.         y = memory.readbyte(pos_y[i])-10
  112.         if y > 0 and hp > 0 then
  113.             bot(x, y, hp)
  114.             numEn = numEn + 1
  115.         end
  116.     end
  117.    
  118.     -- get current rng value
  119.     rng = memory.readword(0x02060E06)
  120.     top(0, 0, rng, "red")
  121.    
  122.     -- shows next 10 values
  123.     for i = 1,10 do
  124.         rng = nextRNG(rng)
  125.         luckyvalue = rng % 100
  126.         hasLucky = false
  127.        
  128.         -- for each enemy, check lucky hit chances
  129.         for j = 1, numEn do
  130.             for k = 1,4 do -- each bro
  131.                 luckychance = math.max(math.min(math.floor((memory.readword(arr_stache[k]) / 4) - (memory.readbyte(arr_lv[j]) / 8)), 99), 1)
  132.                
  133.                 -- lucky hit!
  134.                 if luckyvalue < luckychance then
  135.                     -- put a letter with a color in front of the value
  136.                     top(30 + k * 6, i * v_space, arr_name[k], arr_color[k])
  137.                     hasLucky = true
  138.                     -- if it's the next value, shows text near the enemies that can get lucky hit
  139.                     if i == 1 then
  140.                         bot(memory.readbyte(pos_x[j]), memory.readbyte(pos_y[j]), "Lucky!")
  141.                     end
  142.                 end
  143.             end
  144.         end
  145.        
  146.         if i == 1 then
  147.             top(0, i * v_space, rng, "#00FFFF")
  148.         elseif hasLucky then
  149.             top(0, i * v_space, rng, "#FFFF00")
  150.         else
  151.             top(0, i * v_space, rng)
  152.         end
  153.     end
  154.    
  155. end
  156. gui.register(fn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement