rlm@98
|
1 (ns com.aurellem.items
|
rlm@98
|
2 (:use (com.aurellem gb-driver vbm title))
|
rlm@99
|
3 ;; this is bullshit
|
rlm@98
|
4 (:import [com.aurellem.gb_driver SaveState]))
|
rlm@98
|
5
|
rlm@98
|
6 (defn game-name []
|
rlm@98
|
7 (map char (subvec (vec (memory)) 0x134 0x142)))
|
rlm@98
|
8
|
rlm@99
|
9 (def item-list-start 0xD31C)
|
rlm@98
|
10
|
rlm@99
|
11 (defn item-list [^SaveState state]
|
rlm@99
|
12 (subvec
|
rlm@99
|
13 (vec (memory state))
|
rlm@99
|
14 item-list-start
|
rlm@100
|
15 (+ item-list-start 150)))
|
rlm@98
|
16
|
rlm@98
|
17 (def item-hack-3 (read-state 77557))
|
rlm@98
|
18
|
rlm@99
|
19 (def item-code->item-name
|
rlm@99
|
20 (hash-map
|
rlm@99
|
21 1 :master-ball
|
rlm@99
|
22 2 :ultra-ball
|
rlm@99
|
23 3 :great-ball
|
rlm@99
|
24 4 :poke-ball
|
rlm@99
|
25 5 :town-map
|
rlm@99
|
26 6 :bicycle
|
rlm@99
|
27 8 :safari-ball
|
rlm@99
|
28 9 :pokedex
|
rlm@99
|
29 10 :moon-stone
|
rlm@99
|
30 11 :antidote
|
rlm@99
|
31 12 :burn-heal
|
rlm@99
|
32 13 :ice-heal
|
rlm@99
|
33 14 :awakening
|
rlm@99
|
34 15 :parlyz-heal
|
rlm@99
|
35 16 :full-restore
|
rlm@99
|
36 17 :max-potion
|
rlm@99
|
37 18 :hyper-potion
|
rlm@99
|
38 19 :super-potion
|
rlm@99
|
39 20 :potion
|
rlm@99
|
40 21 :boulderbadge
|
rlm@99
|
41 22 :cascadebadge
|
rlm@99
|
42 23 :thunderbadge
|
rlm@99
|
43 24 :rainbowbadge
|
rlm@99
|
44 25 :soulbadge
|
rlm@99
|
45 26 :marshbadge
|
rlm@99
|
46 27 :volcanobadge
|
rlm@99
|
47 28 :earthbadge
|
rlm@99
|
48 29 :escape-rope
|
rlm@99
|
49 30 :repel
|
rlm@99
|
50 31 :old-amber
|
rlm@99
|
51 32 :fire-stone
|
rlm@99
|
52 33 :thunderstone
|
rlm@99
|
53 34 :water-stone
|
rlm@99
|
54 35 :hp-up
|
rlm@99
|
55 36 :protein
|
rlm@99
|
56 37 :iron
|
rlm@99
|
57 38 :carbos
|
rlm@99
|
58 39 :calcium
|
rlm@99
|
59 40 :rare-candy
|
rlm@99
|
60 41 :dome-fossil
|
rlm@99
|
61 42 :helix-fossil
|
rlm@99
|
62 43 :secret-key
|
rlm@99
|
63 45 :bike-voucher
|
rlm@99
|
64 46 :x-accuracy
|
rlm@99
|
65 47 :leaf-stone
|
rlm@99
|
66 48 :card-key
|
rlm@99
|
67 49 :nugget
|
rlm@99
|
68 50 :pp-up
|
rlm@99
|
69 51 :poke-doll
|
rlm@99
|
70 52 :full-heal
|
rlm@99
|
71 53 :revive
|
rlm@99
|
72 54 :max-revive
|
rlm@99
|
73 55 :guard-spec
|
rlm@99
|
74 56 :super-repel
|
rlm@99
|
75 57 :max-repel
|
rlm@99
|
76 58 :dire-hit
|
rlm@99
|
77 59 :coin
|
rlm@99
|
78 60 :fresh-water
|
rlm@99
|
79 61 :soda-pop
|
rlm@99
|
80 62 :lemonade
|
rlm@99
|
81 63 :s.s.ticket
|
rlm@99
|
82 64 :gold-teeth
|
rlm@99
|
83 65 :x-attach
|
rlm@99
|
84 66 :x-defend
|
rlm@99
|
85 67 :x-speed
|
rlm@99
|
86 68 :x-special
|
rlm@99
|
87 69 :coin-case
|
rlm@99
|
88 70 :oaks-parcel
|
rlm@99
|
89 71 :itemfinder
|
rlm@99
|
90 72 :silph-scope
|
rlm@99
|
91 73 :poke-flute
|
rlm@99
|
92 74 :lift-key
|
rlm@99
|
93 75 :exp.all
|
rlm@99
|
94 76 :old-rod
|
rlm@99
|
95 77 :good-rod
|
rlm@99
|
96 78 :super-rod
|
rlm@99
|
97 79 :pp-up
|
rlm@99
|
98 80 :ether
|
rlm@99
|
99 81 :max-ether
|
rlm@99
|
100 82 :elixer
|
rlm@99
|
101 83 :max-elixer
|
rlm@99
|
102 196 :HM01
|
rlm@99
|
103 197 :HM02
|
rlm@99
|
104 198 :HM03
|
rlm@99
|
105 199 :HM04
|
rlm@99
|
106 200 :HM05
|
rlm@99
|
107 201 :TM01
|
rlm@99
|
108 202 :TM02
|
rlm@99
|
109 203 :TM03
|
rlm@99
|
110 204 :TM04
|
rlm@99
|
111 205 :TM05
|
rlm@99
|
112 206 :TM06
|
rlm@99
|
113 207 :TM07
|
rlm@99
|
114 208 :TM08
|
rlm@99
|
115 209 :TM09
|
rlm@99
|
116 210 :TM10
|
rlm@99
|
117 211 :TM11
|
rlm@99
|
118 212 :TM12
|
rlm@99
|
119 213 :TM13
|
rlm@99
|
120 214 :TM13
|
rlm@99
|
121 215 :TM15
|
rlm@99
|
122 216 :TM16
|
rlm@99
|
123 217 :TM17
|
rlm@99
|
124 218 :TM18
|
rlm@99
|
125 219 :TM19
|
rlm@99
|
126 220 :TM20
|
rlm@99
|
127 221 :TM21
|
rlm@99
|
128 222 :TM22
|
rlm@99
|
129 223 :TM23
|
rlm@99
|
130 224 :TM24
|
rlm@99
|
131 225 :TM25
|
rlm@99
|
132 226 :TM26
|
rlm@99
|
133 227 :TM27
|
rlm@99
|
134 228 :TM28
|
rlm@99
|
135 229 :TM29
|
rlm@99
|
136 230 :TM30
|
rlm@99
|
137 231 :TM31
|
rlm@99
|
138 232 :TM32
|
rlm@99
|
139 233 :TM33
|
rlm@99
|
140 234 :TM34
|
rlm@99
|
141 235 :TM35
|
rlm@99
|
142 236 :TM36
|
rlm@99
|
143 237 :TM37
|
rlm@99
|
144 238 :TM38
|
rlm@99
|
145 239 :TM39
|
rlm@99
|
146 240 :TM40
|
rlm@99
|
147 241 :TM41
|
rlm@99
|
148 242 :TM42
|
rlm@99
|
149 243 :TM43
|
rlm@99
|
150 244 :TM44
|
rlm@99
|
151 245 :TM45
|
rlm@99
|
152 246 :TM46
|
rlm@99
|
153 247 :TM47
|
rlm@99
|
154 248 :TM48
|
rlm@99
|
155 249 :TM49
|
rlm@99
|
156 250 :TM50
|
rlm@99
|
157 251 :TM51
|
rlm@99
|
158 252 :TM52
|
rlm@99
|
159 253 :TM53
|
rlm@99
|
160 254 :TM54
|
rlm@99
|
161 255 :end-of-list-sentinel))
|
rlm@98
|
162
|
rlm@99
|
163 (def item-name->item-code
|
rlm@99
|
164 (zipmap (vals item-code->item-name)
|
rlm@99
|
165 (keys item-code->item-name)))
|
rlm@98
|
166
|
rlm@99
|
167 (defn inventory [^SaveState state]
|
rlm@99
|
168 (let [items (item-list state)]
|
rlm@99
|
169 (map
|
rlm@99
|
170 (fn [[item-code quantity]]
|
rlm@99
|
171 [(item-code->item-name item-code)
|
rlm@99
|
172 quantity])
|
rlm@99
|
173 (partition
|
rlm@99
|
174 2
|
rlm@99
|
175 (next (take-while (partial not= 255) items))))))
|
rlm@98
|
176
|
rlm@99
|
177 (defn print-inventory [^SaveState state]
|
rlm@99
|
178 (println
|
rlm@99
|
179 (let [inv (inventory state)]
|
rlm@99
|
180 (reduce
|
rlm@99
|
181 str
|
rlm@99
|
182 (concat
|
rlm@99
|
183 ["+-------------------+----------+\n"
|
rlm@99
|
184 "|##| Item | Quantity |\n"
|
rlm@99
|
185 "+--+----------------+----------+\n"]
|
rlm@98
|
186
|
rlm@99
|
187 (map
|
rlm@99
|
188 (fn [index [item-name quantity]]
|
rlm@99
|
189 (str
|
rlm@99
|
190 (format "|%-2d| %-14s | %3d |\n" index
|
rlm@99
|
191 (apply str (rest (str item-name)))
|
rlm@99
|
192 quantity)))
|
rlm@99
|
193 (range 0 (count inv)) inv)
|
rlm@99
|
194 ["+--+----------------+----------+\n"])))))
|
rlm@98
|
195
|
rlm@99
|
196 (defn inventory-codes [inventory]
|
rlm@99
|
197 (flatten
|
rlm@99
|
198 (concat [(count inventory)]
|
rlm@99
|
199 (map (fn [[item-name quantity]]
|
rlm@99
|
200 [(item-name->item-code item-name)
|
rlm@99
|
201 quantity]) inventory)
|
rlm@99
|
202 [(item-name->item-code :end-of-list-sentinel)])))
|
rlm@98
|
203
|
rlm@99
|
204 (defn set-inventory [^SaveState state new-inventory]
|
rlm@99
|
205 (set-state! state)
|
rlm@99
|
206 (let [mem (memory state)
|
rlm@99
|
207 inv (inventory-codes new-inventory)]
|
rlm@98
|
208
|
rlm@99
|
209 (dorun (map (fn [index val]
|
rlm@99
|
210 (aset mem index val))
|
rlm@99
|
211 (range item-list-start
|
rlm@99
|
212 (+ item-list-start (count inv))) inv))
|
rlm@99
|
213 (write-memory! mem)
|
rlm@99
|
214 (update-state)))
|
rlm@98
|
215
|