Mercurial > vba-clojure
comparison clojure/com/aurellem/items.clj @ 99:9fad96094950
can now read and set the inventory of a state
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 12 Mar 2012 09:59:26 -0500 |
parents | 08cd8be1edc1 |
children | 2090bcb78f44 |
comparison
equal
deleted
inserted
replaced
98:08cd8be1edc1 | 99:9fad96094950 |
---|---|
1 (ns com.aurellem.items | 1 (ns com.aurellem.items |
2 (:use (com.aurellem gb-driver vbm title)) | 2 (:use (com.aurellem gb-driver vbm title)) |
3 ;; this is fucking bullshit | 3 ;; this is bullshit |
4 (:import [com.aurellem.gb_driver SaveState])) | 4 (:import [com.aurellem.gb_driver SaveState])) |
5 | |
6 | |
7 | 5 |
8 (defn game-name [] | 6 (defn game-name [] |
9 (map char (subvec (vec (memory)) 0x134 0x142))) | 7 (map char (subvec (vec (memory)) 0x134 0x142))) |
10 | 8 |
11 | 9 (def item-list-start 0xD31C) |
12 | 10 |
13 | 11 (defn item-list [^SaveState state] |
14 | 12 (subvec |
15 (defn current-items [^SaveState state] | 13 (vec (memory state)) |
14 item-list-start | |
15 (+ item-list-start 60))) | |
16 | |
17 (def item-hack-3 (read-state 77557)) | |
18 | |
19 (def item-code->item-name | |
20 (hash-map | |
21 1 :master-ball | |
22 2 :ultra-ball | |
23 3 :great-ball | |
24 4 :poke-ball | |
25 5 :town-map | |
26 6 :bicycle | |
27 8 :safari-ball | |
28 9 :pokedex | |
29 10 :moon-stone | |
30 11 :antidote | |
31 12 :burn-heal | |
32 13 :ice-heal | |
33 14 :awakening | |
34 15 :parlyz-heal | |
35 16 :full-restore | |
36 17 :max-potion | |
37 18 :hyper-potion | |
38 19 :super-potion | |
39 20 :potion | |
40 21 :boulderbadge | |
41 22 :cascadebadge | |
42 23 :thunderbadge | |
43 24 :rainbowbadge | |
44 25 :soulbadge | |
45 26 :marshbadge | |
46 27 :volcanobadge | |
47 28 :earthbadge | |
48 29 :escape-rope | |
49 30 :repel | |
50 31 :old-amber | |
51 32 :fire-stone | |
52 33 :thunderstone | |
53 34 :water-stone | |
54 35 :hp-up | |
55 36 :protein | |
56 37 :iron | |
57 38 :carbos | |
58 39 :calcium | |
59 40 :rare-candy | |
60 41 :dome-fossil | |
61 42 :helix-fossil | |
62 43 :secret-key | |
63 45 :bike-voucher | |
64 46 :x-accuracy | |
65 47 :leaf-stone | |
66 48 :card-key | |
67 49 :nugget | |
68 50 :pp-up | |
69 51 :poke-doll | |
70 52 :full-heal | |
71 53 :revive | |
72 54 :max-revive | |
73 55 :guard-spec | |
74 56 :super-repel | |
75 57 :max-repel | |
76 58 :dire-hit | |
77 59 :coin | |
78 60 :fresh-water | |
79 61 :soda-pop | |
80 62 :lemonade | |
81 63 :s.s.ticket | |
82 64 :gold-teeth | |
83 65 :x-attach | |
84 66 :x-defend | |
85 67 :x-speed | |
86 68 :x-special | |
87 69 :coin-case | |
88 70 :oaks-parcel | |
89 71 :itemfinder | |
90 72 :silph-scope | |
91 73 :poke-flute | |
92 74 :lift-key | |
93 75 :exp.all | |
94 76 :old-rod | |
95 77 :good-rod | |
96 78 :super-rod | |
97 79 :pp-up | |
98 80 :ether | |
99 81 :max-ether | |
100 82 :elixer | |
101 83 :max-elixer | |
102 196 :HM01 | |
103 197 :HM02 | |
104 198 :HM03 | |
105 199 :HM04 | |
106 200 :HM05 | |
107 201 :TM01 | |
108 202 :TM02 | |
109 203 :TM03 | |
110 204 :TM04 | |
111 205 :TM05 | |
112 206 :TM06 | |
113 207 :TM07 | |
114 208 :TM08 | |
115 209 :TM09 | |
116 210 :TM10 | |
117 211 :TM11 | |
118 212 :TM12 | |
119 213 :TM13 | |
120 214 :TM13 | |
121 215 :TM15 | |
122 216 :TM16 | |
123 217 :TM17 | |
124 218 :TM18 | |
125 219 :TM19 | |
126 220 :TM20 | |
127 221 :TM21 | |
128 222 :TM22 | |
129 223 :TM23 | |
130 224 :TM24 | |
131 225 :TM25 | |
132 226 :TM26 | |
133 227 :TM27 | |
134 228 :TM28 | |
135 229 :TM29 | |
136 230 :TM30 | |
137 231 :TM31 | |
138 232 :TM32 | |
139 233 :TM33 | |
140 234 :TM34 | |
141 235 :TM35 | |
142 236 :TM36 | |
143 237 :TM37 | |
144 238 :TM38 | |
145 239 :TM39 | |
146 240 :TM40 | |
147 241 :TM41 | |
148 242 :TM42 | |
149 243 :TM43 | |
150 244 :TM44 | |
151 245 :TM45 | |
152 246 :TM46 | |
153 247 :TM47 | |
154 248 :TM48 | |
155 249 :TM49 | |
156 250 :TM50 | |
157 251 :TM51 | |
158 252 :TM52 | |
159 253 :TM53 | |
160 254 :TM54 | |
161 255 :end-of-list-sentinel)) | |
162 | |
163 (def item-name->item-code | |
164 (zipmap (vals item-code->item-name) | |
165 (keys item-code->item-name))) | |
166 | |
167 (defn inventory [^SaveState state] | |
168 (let [items (item-list state)] | |
169 (map | |
170 (fn [[item-code quantity]] | |
171 [(item-code->item-name item-code) | |
172 quantity]) | |
173 (partition | |
174 2 | |
175 (next (take-while (partial not= 255) items)))))) | |
176 | |
177 (defn print-inventory [^SaveState state] | |
178 (println | |
179 (let [inv (inventory state)] | |
180 (reduce | |
181 str | |
182 (concat | |
183 ["+-------------------+----------+\n" | |
184 "|##| Item | Quantity |\n" | |
185 "+--+----------------+----------+\n"] | |
186 | |
187 (map | |
188 (fn [index [item-name quantity]] | |
189 (str | |
190 (format "|%-2d| %-14s | %3d |\n" index | |
191 (apply str (rest (str item-name))) | |
192 quantity))) | |
193 (range 0 (count inv)) inv) | |
194 ["+--+----------------+----------+\n"]))))) | |
195 | |
196 (defn inventory-codes [inventory] | |
197 (flatten | |
198 (concat [(count inventory)] | |
199 (map (fn [[item-name quantity]] | |
200 [(item-name->item-code item-name) | |
201 quantity]) inventory) | |
202 [(item-name->item-code :end-of-list-sentinel)]))) | |
203 | |
204 (defn set-inventory [^SaveState state new-inventory] | |
16 (set-state! state) | 205 (set-state! state) |
206 (let [mem (memory state) | |
207 inv (inventory-codes new-inventory)] | |
17 | 208 |
18 | 209 (dorun (map (fn [index val] |
19 ) | 210 (aset mem index val)) |
20 | 211 (range item-list-start |
21 | 212 (+ item-list-start (count inv))) inv)) |
22 | 213 (write-memory! mem) |
23 ;; try just buying five potions in sequence and see what changes | 214 (update-state))) |
24 ;; each time. | |
25 | |
26 (defn common-differences [& seqs] | |
27 (let [backbone (range (count (first seqs)))] | |
28 (filter | |
29 (comp (partial apply distinct?) second) | |
30 (zipmap backbone | |
31 (apply (partial map list) seqs))))) | |
32 | |
33 ;; trying to find how items are represented in memory | |
34 | |
35 (comment | |
36 (def empty-inventory @current-state) | |
37 | 215 |
38 (def one-potion @current-state) | |
39 | |
40 (def two-potions @current-state) | |
41 | |
42 (def three-potions @current-state) | |
43 | |
44 (def four-potions @current-state) | |
45 | |
46 (def five-potions @current-state) | |
47 | |
48 | |
49 ;; result | |
50 (def canidates | |
51 (apply common-differences | |
52 (map (comp vec memory) | |
53 [empty-inventory one-potion two-potions three-potions | |
54 four-potions five-potions]))) | |
55 | |
56 [55875 (37 15 49 27 14 44)] | |
57 [55876 (30 1 49 56 55 23)] | |
58 [49158 (154 191 78 135 70 73)] | |
59 [54087 (49 40 37 34 25 22)] | |
60 [49160 (7 24 59 243 50 217)] | |
61 [49704 (31 14 72 33 84 27)] | |
62 [49162 (126 159 183 110 176 179)] | |
63 [39984 (0 254 251 248 127 252)] | |
64 [49904 (29 72 64 78 1 95)] | |
65 [65491 (222 127 149 132 226 38)] | |
66 [65492 (44 20 89 11 253 163)] | |
67 [49335 (52 15 6 14 3 17)] | |
68 [49720 (78 152 96 60 83 103)] | |
69 [65304 (19 89 214 33 18 113)] | |
70 [53561 (132 185 145 162 159 183)] | |
71 [54046 (0 1 2 3 4 5)]) | |
72 | |
73 ;;; hmmmmmm...... I guess that the potion quantities are at 54046, | |
74 ;;;huh? | |
75 | |
76 | |
77 | |
78 (def item-hack (read-state 7999)) | |
79 | |
80 (def item-hack2 (read-state 75882)) | |
81 | |
82 (defn get-mem [] | |
83 (subvec (vec (memory @current-state)) 54040 (+ 54046 100))) | |
84 | |
85 | |
86 ;; potion -- 99 | |
87 [0 16 0 0 1 20 99 255 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10] | |
88 | |
89 ;; potion -- 95 | |
90 [0 16 0 0 1 20 95 255 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10] | |
91 | |
92 ;; potion -- 95 | |
93 ;; pokeball -- 1 | |
94 [0 16 0 0 2 20 95 4 1 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10] | |
95 | |
96 ;; potion -- 95 | |
97 ;; pokeball -- 10 | |
98 [0 16 0 0 2 20 95 4 10 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10] | |
99 | |
100 | |
101 ;; pokeball -- 10 | |
102 ;; potion -- 95 | |
103 [0 16 0 0 2 4 10 20 95 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10] | |
104 | |
105 ;; pokeball -- 10 | |
106 ;; potion -- 95 | |
107 ;; antidote -- 1 | |
108 | |
109 ;;prediction | |
110 ;;[0 16 0 0 3 4 10 20 95 ?? 1 255 0 0 0 0 0 ....] | |
111 [0 16 0 0 3 4 10 20 95 11 1 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 117 129 139 148 132 80 134 128 145 152 80 137 3 0 0 1 191 223 189 2 0 42 8 199 5 2 1 0 1 20 2 4 4 93 77 23 77 122 76 0 255 208 65 240 198 10 10 71 246 41 201 255 252 64 18 201 10 10] | |
112 | |
113 | |
114 | |
115 ;; now it's time to learn the item codes | |
116 | |
117 (def item-hack-3 (read-state 77557)) | |
118 (defn show-item | |
119 "Run a saved pokemon with the first item replaced by the item named | |
120 by n." | |
121 [n] | |
122 (set-state! item-hack-3) | |
123 (let [mem (memory)] | |
124 (aset mem 54045 n) | |
125 (write-memory! mem)) | |
126 (step) | |
127 (->> [[] @current-state] | |
128 (play-moves | |
129 [[:a] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] | |
130 [] [] [] [] []]))) | |
131 | |
132 | |
133 (defn get-item-names [] | |
134 (dorun (map (fn [n] (println n) | |
135 (show-item n) | |
136 (Thread/sleep 5000)) | |
137 (range 0x00 0xFF)))) | |
138 | |
139 | |
140 | |
141 ;; 0 garbage | |
142 ;; 1 master-ball | |
143 ;; 2 ultra-ball | |
144 ;; 3 great-ball | |
145 ;; 4 poke-ball | |
146 ;; 5 town-map | |
147 ;; 6 bicycle | |
148 ;; 7 ????? | |
149 ;; 8 safari-ball | |
150 ;; 9 pokedex | |
151 ;; 10 moon-stone | |
152 ;; 11 antidote | |
153 ;; 12 burn-heal | |
154 ;; 13 ice-heal | |
155 ;; 14 awakening | |
156 ;; 15 parlyz-heal | |
157 ;; 16 full-restore | |
158 ;; 17 max-potion | |
159 ;; 18 hyper-potion | |
160 ;; 19 super-potion | |
161 ;; 20 potion | |
162 ;; 21 boulderbadge | |
163 ;; 22 cascadebadge | |
164 ;; 23 thunderbadge | |
165 ;; 24 rainbowbadge | |
166 ;; 25 soulbadge | |
167 ;; 26 marshbadge | |
168 ;; 27 volcanobadge | |
169 ;; 28 earthbadge | |
170 ;; 29 escape-rope | |
171 ;; 30 repel | |
172 ;; 31 old amber | |
173 ;; 32 fire-stone | |
174 ;; 33 thunderstone | |
175 ;; 34 water-stone | |
176 ;; 35 hp-up | |
177 ;; 36 protein | |
178 ;; 37 iron | |
179 ;; 38 carbos | |
180 ;; 39 calcium | |
181 ;; 40 rare-candy | |
182 ;; 41 dome-fossil | |
183 ;; 42 helix-fossil | |
184 ;; 43 secret-key | |
185 ;; 44 ????? | |
186 ;; 45 bike-voucher | |
187 ;; 46 x-accuracy | |
188 ;; 47 leaf-stone | |
189 ;; 48 card-key | |
190 ;; 49 nugget | |
191 ;; 50 pp-up | |
192 ;; 51 poke-doll | |
193 ;; 52 full-heal | |
194 ;; 53 revive | |
195 ;; 54 max-revive | |
196 ;; 55 guard-spec. | |
197 ;; 56 super-repel | |
198 ;; 57 max-repel | |
199 ;; 58 dire-hit | |
200 ;; 59 coin | |
201 ;; 60 fresh-water | |
202 ;; 61 soda-pop | |
203 ;; 62 lemonade | |
204 ;; 63 s.s.ticket | |
205 ;; 64 gold-teeth | |
206 ;; 65 x-attach | |
207 ;; 66 x-defend | |
208 ;; 67 x-speed | |
209 ;; 68 x-special | |
210 ;; 69 coin-case | |
211 ;; 70 oak's-parcel | |
212 ;; 71 itemfinder | |
213 ;; 72 silph-scope | |
214 ;; 73 poke-flute | |
215 ;; 74 lift-key | |
216 ;; 75 exp.all | |
217 ;; 76 old-rod | |
218 ;; 77 good-rod | |
219 ;; 78 super-rod | |
220 ;; 79 pp-up | |
221 ;; 80 ether | |
222 ;; 81 max-ether | |
223 ;; 82 elixer | |
224 ;; 83 max-elixer | |
225 ;; 84 B2F | |
226 ;; 85 B1F | |
227 ;; 86 1F | |
228 ;; 87 2F | |
229 ;; 88 3F | |
230 ;; 89 4F | |
231 ;; 90 5F | |
232 ;; 91 6F | |
233 ;; 92 7F | |
234 ;; 93 8F | |
235 ;; 94 9F | |
236 ;; 95 10F | |
237 ;; 96 11F | |
238 ;; 97 B4F | |
239 ;; 98 garbage | |
240 ;; 99 garbage | |
241 ;; 100 garbage | |
242 ;; 101 garbage | |
243 ;; 102 garbage | |
244 ;; 103 garbage | |
245 ;; 104 garbage | |
246 ;; 105 garbage | |
247 ;; 106 garbage | |
248 ;; 107 garbage | |
249 ;; 108 garbage | |
250 ;; 109 garbage | |
251 ;; 110 garbage | |
252 ;; 111 garbage | |
253 ;; 112 garbage | |
254 ;; 113 garbage | |
255 ;; 114 garbage | |
256 ;; 115 garbage | |
257 ;; 116 garbage | |
258 ;; 117 garbage | |
259 ;; 118 garbage | |
260 ;; 119 4 | |
261 ;; 120 garbage | |
262 ;; 121 garbage | |
263 ;; 122 slow | |
264 ;; 123 garbage | |
265 ;; 124 garbage | |
266 ;; 125 garbage | |
267 ;; 126 garbage | |
268 ;; 127 garbage | |
269 ;; 128 garbage | |
270 ;; 129 garbage | |
271 ;; 130 garbage | |
272 ;; 131 slow | |
273 ;; 132 slow | |
274 ;; 133 garbage | |
275 ;; 134 slow | |
276 ;; 135 garbage | |
277 ;; 136 garbage | |
278 ;; 137 slow | |
279 ;; 138 garbage | |
280 ;; 139 garbage | |
281 ;; 140 garbage | |
282 ;; 141 slow | |
283 ;; 142 garbage | |
284 ;; 143 garbage | |
285 ;; 144 garbage | |
286 ;; 145 garbage | |
287 ;; 146 garbage | |
288 ;; 147 garbage | |
289 ;; 148 garbage | |
290 ;; 149 garbage | |
291 ;; 150 slow | |
292 ;; 151 garbage | |
293 ;; 152 Q | |
294 ;; 153 garbage | |
295 ;; 154 garbage | |
296 ;; 155 garbage | |
297 ;; 156 garbage | |
298 ;; 157 garbage | |
299 ;; 158 garbage | |
300 ;; 159 garbage | |
301 ;; 160 garbage (alaphabet) | |
302 ;; 161 garbage | |
303 ;; 162 garbage | |
304 ;; 163 garbage | |
305 ;; 164 rival's | |
306 ;; 165 name? | |
307 ;; 166 nickname? | |
308 ;; 167 slow | |
309 ;; 168 garbage | |
310 ;; 169 slow | |
311 ;; 170 garbage | |
312 ;; 171 garbage | |
313 ;; 172 garbage | |
314 ;; 173 garbage | |
315 ;; 174 garbage | |
316 ;; 175 yellow | |
317 ;; 176 ash | |
318 ;; 177 jack | |
319 ;; 178 new-name | |
320 ;; 179 blue | |
321 ;; 180 gary | |
322 ;; 181 john | |
323 ;; 182 garbage | |
324 ;; 183 garbage | |
325 ;; 184 garbage | |
326 ;; 185 garbage | |
327 ;; 186 slow | |
328 ;; 187 garbage | |
329 ;; 188 garbage | |
330 ;; 189 garbage | |
331 ;; 190 garbage | |
332 ;; 191 garbage | |
333 ;; 192 garbage | |
334 ;; 193 garbage | |
335 ;; 194 garbage | |
336 ;; 195 slow | |
337 ;; 196 HM01 | |
338 ;; 197 HM02 | |
339 ;; 198 HM03 | |
340 ;; 199 HM04 | |
341 ;; 200 HM05 | |
342 ;; 201 TM01 | |
343 ;; 202 TM02 | |
344 ;; 203 TM03 | |
345 ;; 204 TM04 | |
346 ;; 205 TM05 | |
347 ;; 206 TM06 | |
348 ;; 207 TM07 | |
349 ;; 208 TM08 | |
350 ;; 209 TM09 | |
351 ;; 210 TM10 | |
352 ;; 211 TM11 | |
353 ;; 212 TM12 | |
354 ;; 213 TM13 | |
355 ;; 214 TM13 | |
356 ;; 215 TM15 | |
357 ;; 216 TM16 | |
358 ;; 217 TM17 | |
359 ;; 218 TM18 | |
360 ;; 219 TM19 | |
361 ;; 220 TM20 | |
362 ;; 221 TM21 | |
363 ;; 222 TM22 | |
364 ;; 223 TM23 | |
365 ;; 224 TM24 | |
366 ;; 225 TM25 | |
367 ;; 226 TM26 | |
368 ;; 227 TM27 | |
369 ;; 228 TM28 | |
370 ;; 229 TM29 | |
371 ;; 230 TM30 | |
372 ;; 231 TM31 | |
373 ;; 232 TM32 | |
374 ;; 233 TM33 | |
375 ;; 234 TM34 | |
376 ;; 235 TM35 | |
377 ;; 236 TM36 | |
378 ;; 237 TM37 | |
379 ;; 238 TM38 | |
380 ;; 239 TM39 | |
381 ;; 240 TM40 | |
382 ;; 241 TM41 | |
383 ;; 242 TM42 | |
384 ;; 243 TM43 | |
385 ;; 244 TM44 | |
386 ;; 245 TM45 | |
387 ;; 246 TM46 | |
388 ;; 247 TM47 | |
389 ;; 248 TM48 | |
390 ;; 249 TM49 | |
391 ;; 250 TM50 | |
392 ;; 251 TM51 | |
393 ;; 252 TM52 | |
394 ;; 253 TM53 | |
395 ;; 254 TM54 | |
396 ;; 255 end-of-list-sentinel | |
397 | |
398 | |
399 | |
400 | |
401 | |
402 | |
403 |