Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- auxiliary functions; don't worry about them (unless something's wrong)
- -- http://stackoverflow.com/questions/5977654/lua-bitwise-logical-operations
- local function BitXOR(a,b)--Bitwise xor
- local p,c=1,0
- while a>0 and b>0 do
- local ra,rb=a%2,b%2
- if ra~=rb then c=c+p end
- a,b,p=(a-ra)/2,(b-rb)/2,p*2
- end
- if a<b then a=b end
- while a>0 do
- local ra=a%2
- if ra>0 then c=c+p end
- a,p=(a-ra)/2,p*2
- end
- return c
- end
- local function BitOR(a,b)--Bitwise or
- local p,c=1,0
- while a+b>0 do
- local ra,rb=a%2,b%2
- if ra+rb>0 then c=c+p end
- a,b,p=(a-ra)/2,(b-rb)/2,p*2
- end
- return c
- end
- local function BitNOT(n)
- local p,c=1,0
- while n>0 do
- local r=n%2
- if r<1 then c=c+p end
- n,p=(n-r)/2,p*2
- end
- return c
- end
- local function BitAND(a,b)--Bitwise and
- local p,c=1,0
- while a>0 and b>0 do
- local ra,rb=a%2,b%2
- if ra+rb>1 then c=c+p end
- a,b,p=(a-ra)/2,(b-rb)/2,p*2
- end
- return c
- end
- -- this is where you want to change stuff
- -- RNG:
- --- U: 0x02060A86
- --- E: 0x02060E06
- --- J: 0x02060DE6
- -- stache (same for all versions?):
- --- Mario: 0x0233C42A
- --- Luigi: 0x0233C44E
- --- BMario: 0x1233C472
- --- BLuigi: 0x1233C496
- -- enemies (E)
- local pos_x = {0x020D1302, 0x020D1406, 0x020D150A, 0x020D160E, 0x020D1712, 0x020D1816}
- local pos_y = {0x020D1304, 0x020D1408, 0x020D150C, 0x020D1610, 0x020D1714, 0x020D1818}
- local arr_hp = {0x020D2066, 0x020D2306, 0x020D25A6, 0x020D2846, 0x020D2AE6, 0x020D2D86}
- local arr_lv = {0x020D2084, 0x020D2324, 0x020D25C4, 0x020D2864, 0x020D2B04, 0x020D2DA4}
- -- rng stuff
- local arr_stache = {0x0233C42A, 0x0233C44E, 0x1233C472, 0x1233C496} -- M, L, m, l
- local arr_name = {"M", "L", "m", "l"}
- local arr_color = {"red", "green", "red", "green"}
- local rng, luckyvalue, luckychance
- local hasLucky
- -- others
- local v_space = 12
- local hp, x, y
- local numEn
- local output
- local function nextRNG(seed)
- local res = BitAND(math.floor(seed * 20.5), 0x7fff)
- if seed % 2 == 1 then
- res = res + 0x8000
- end
- return res
- end
- local function top(x, y, text, c1, c2)
- gui.text(x, y - 190, text, c1, c2)
- end
- local function bot(x, y, text, c1, c2)
- gui.text(x, y, text, c1, c2)
- end
- function fn()
- -- shows HP close to enemies' position
- numEn = 0
- for i = 1,6 do
- hp = memory.readword(arr_hp[i])
- x = memory.readbyte(pos_x[i])
- y = memory.readbyte(pos_y[i])-10
- if y > 0 and hp > 0 then
- bot(x, y, hp)
- numEn = numEn + 1
- end
- end
- -- get current rng value
- rng = memory.readword(0x02060E06)
- top(0, 0, rng, "red")
- -- shows next 10 values
- for i = 1,10 do
- rng = nextRNG(rng)
- luckyvalue = rng % 100
- hasLucky = false
- -- for each enemy, check lucky hit chances
- for j = 1, numEn do
- for k = 1,4 do -- each bro
- luckychance = math.max(math.min(math.floor((memory.readword(arr_stache[k]) / 4) - (memory.readbyte(arr_lv[j]) / 8)), 99), 1)
- -- lucky hit!
- if luckyvalue < luckychance then
- -- put a letter with a color in front of the value
- top(30 + k * 6, i * v_space, arr_name[k], arr_color[k])
- hasLucky = true
- -- if it's the next value, shows text near the enemies that can get lucky hit
- if i == 1 then
- bot(memory.readbyte(pos_x[j]), memory.readbyte(pos_y[j]), "Lucky!")
- end
- end
- end
- end
- if i == 1 then
- top(0, i * v_space, rng, "#00FFFF")
- elseif hasLucky then
- top(0, i * v_space, rng, "#FFFF00")
- else
- top(0, i * v_space, rng)
- end
- end
- end
- gui.register(fn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement