-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_hud.rb
132 lines (111 loc) · 2.81 KB
/
update_hud.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require "stringio"
require "json"
def read_header(io)
io.read(14)
end
def read_block(io)
name = io.read(3)
io.read(1)
size = io.read(6).to_i
io.read(1)
data = io.read(size)
return [name, data]
end
SAVE_DIR = ARGV[1] + "Quick Save State.oesavestate"
SAVE_FILE = SAVE_DIR + "/State"
STARTING_ADDRESS = 0x1AC0
ITEMS_OFFSET = STARTING_ADDRESS + 0x340
AGA_OFFSET = STARTING_ADDRESS + 0x3C5
PENDANTS_OFFSET = STARTING_ADDRESS + 0x374
CRYSTALS_OFFSET = STARTING_ADDRESS + 0x37A
def update
puts "Updating..."
io = File.open(SAVE_FILE)
read_header(io)
name = nil
data = nil
while data.nil?
name, data = read_block(io)
data = nil if name != "SRA"
end
sram = StringIO.new(data)
sram.pos = ITEMS_OFFSET
items = {
bow: sram.read(1).ord,
boomerang: sram.read(1).ord,
hookshot: sram.read(1).ord,
bombs: sram.read(1).ord,
mushroom: sram.read(1).ord,
fireRod: sram.read(1).ord,
iceRod: sram.read(1).ord,
bombos: sram.read(1).ord,
ether: sram.read(1).ord,
quake: sram.read(1).ord,
lamp: sram.read(1).ord,
hammer: sram.read(1).ord,
flute: sram.read(1).ord,
bugNet: sram.read(1).ord,
book: sram.read(1).ord,
hasBottles: sram.read(1).ord,
somaria: sram.read(1).ord,
byrna: sram.read(1).ord,
cape: sram.read(1).ord,
mirror: sram.read(1).ord,
gloves: sram.read(1).ord,
boots: sram.read(1).ord,
flippers: sram.read(1).ord,
moonPearl: sram.read(1).ord,
unused: sram.read(1).ord,
sword: sram.read(1).ord,
shield: sram.read(1).ord,
armor: sram.read(1).ord,
bottle1: sram.read(1).ord,
bottle2: sram.read(1).ord,
bottle3: sram.read(1).ord,
bottle4: sram.read(1).ord,
}
sram.pos = PENDANTS_OFFSET
pendants = sram.read(1).ord
pendants = ("%08b" % pendants).split("").reverse.map(&:to_i)
items[:pendant_green] = pendants[0]
items[:pendant_blue] = pendants[1]
items[:pendant_red] = pendants[2]
sram.pos = CRYSTALS_OFFSET
crystals = sram.read(1).ord
crystals = ("%08b" % crystals).split("").reverse.map(&:to_i)
items[:crystal_mm] = crystals[0]
items[:crystal_pod] = crystals[1]
items[:crystal_ip] = crystals[2]
items[:crystal_tr] = crystals[3]
items[:crystal_sp] = crystals[4]
items[:crystal_tt] = crystals[5]
items[:crystal_sw] = crystals[6]
sram.pos = AGA_OFFSET
items[:aga] = sram.read(1).ord >= 3 ? 1 : 0
# sram.rewind
# sram.each_byte.with_index do |b, i|
# if b.ord == 3
# puts (i - STARTING_ADDRESS).to_s(16)
# end
# end
sram.close
io.close
File.write(
"items-data.js",
"var items = " + JSON.pretty_generate(items)
)
sleep ARGV[0].to_i
end
if ARGV[0] == "--listen"
require "listen"
Listen.to(SAVE_DIR) do
update
end.start
sleep
else
`./SaveOpenEmuState.applescript`
while true
update
sleep ARGV[0].to_i
end
end