Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/SNES/Y's III.lua
2 views
1
-- Y's III (SNES) Collision box viewer
2
-- Bizhawk
3
-- Author: Pasky
4
5
local camx
6
local camy
7
8
function findbit(p)
9
return 2 ^ (p - 1)
10
end
11
12
function hasbit(x, p)
13
return x % (p + p) >= p
14
end
15
16
local function hex(val)
17
val = string.format("%X",val)
18
if string.len(val) == 1 then
19
val = "0" .. val
20
end
21
return val
22
end
23
24
local function camera()
25
camx = mainmemory.read_u16_le(0x12D8)
26
camy = mainmemory.read_u16_le(0x12E0)
27
end
28
29
memory.usememorydomain("CARTROM")
30
31
local function player()
32
local x = mainmemory.read_u8(0x1274)
33
local y = mainmemory.read_u8(0x1276)
34
local x1 = x
35
local y1 = y
36
local x2 = 0
37
local y2 = 0
38
if mainmemory.read_u8(0x1273) == 3 then
39
x1 = x1 - 4
40
x2= x1 + 0x18
41
y1= y1 + 0x12
42
y2= y1 + 0x10
43
else
44
x2 = x1 + 0x10
45
y1 = y1 + 0x08
46
y2 = y1 + 0x18
47
end
48
49
gui.drawBox(x1,y1,x2,y2,0xFF0000FF,0x300000FF)
50
-- cheat
51
-- memory.writebyte(0x1294,0x90) -- infinite hp
52
-- memory.writeword(0x1299,0x400) -- experience
53
54
-- Attacking
55
if mainmemory.read_u8(0x1283) ~= 0 then
56
local offset1 = bit.band(mainmemory.read_u8(0x1287),0x3)
57
offset1 = offset1 + mainmemory.read_u8(0x1278) + mainmemory.read_u8(0x127A) - 0x10
58
offset1 = bit.lshift(offset1,1)
59
local offset2 = bit.band(mainmemory.read_u8(0x127C),0x40)
60
offset2 = bit.rshift(offset2,6)
61
offset2 = bit.bor(offset2,offset1)
62
offset2 = bit.lshift(offset2,2)
63
local ax1 = bit.band(x + memory.read_u8(0xBA4BE + offset2),0xFF)
64
local ay1 = bit.band(y + memory.read_u8(0xBA4BF + offset2),0xFF)
65
local ax2 = bit.band(x + memory.read_u8(0xBA4BC + offset2),0xFF)
66
local ay2 = bit.band(y + memory.read_u8(0xBA4BD + offset2),0xFF)
67
gui.drawBox(ax1,ay1,ax2,ay2)
68
end
69
end
70
71
local function enemies()
72
local start = 0x17FB - 0x22
73
for i =0,15,1 do
74
local base = start + (i * 0x22)
75
local x = mainmemory.read_u16_le(base) - camx
76
local y = mainmemory.read_u16_le(base + 2) - camy
77
local facing = mainmemory.read_u8(base + 0xf)
78
local offset = mainmemory.read_u8(base + 0xD) * 2
79
local pointer = memory.read_u16_le(0xB9A25 + offset)
80
local hp = mainmemory.read_u8(base + 0x8)
81
local active = mainmemory.read_u8(base + 0x1D)
82
83
if active ~= 0 then
84
if bit.band(facing,0x40) ~= 0 then
85
-- left
86
pointer = pointer + 4
87
else
88
-- right
89
end
90
local x1 = x + memory.read_u8(0xB9A26 + pointer)
91
local y1 = y + memory.read_u8(0xB9A27 + pointer)
92
local x2 = x + memory.read_u8(0xB9A28 + pointer)
93
local y2 = y + memory.read_u8(0xB9A29 + pointer)
94
95
gui.text(x,y,"HP: " .. hp )
96
gui.drawBox(x1,y1,x2,y2,0xFFFF0000,0x30FF0000)
97
end
98
end
99
end
100
101
102
while true do
103
camera()
104
player()
105
enemies()
106
emu.frameadvance()
107
end
108