# HG changeset patch # User Robert McIntyre # Date 1331564366 18000 # Node ID 9fad96094950b555f9770644348fa48e039ca24b # Parent 08cd8be1edc148dbdb9c8df0132361611d1c3ff0 can now read and set the inventory of a state diff -r 08cd8be1edc1 -r 9fad96094950 clojure/com/aurellem/experiments/items.clj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clojure/com/aurellem/experiments/items.clj Mon Mar 12 09:59:26 2012 -0500 @@ -0,0 +1,374 @@ +;; try just buying five potions in sequence and see what changes +;; each time. + +(defn common-differences [& seqs] + (let [backbone (range (count (first seqs)))] + (filter + (comp (partial apply distinct?) second) + (zipmap backbone + (apply (partial map list) seqs))))) + +;; trying to find how items are represented in memory + +(comment + (def empty-inventory @current-state) + + (def one-potion @current-state) + + (def two-potions @current-state) + + (def three-potions @current-state) + + (def four-potions @current-state) + + (def five-potions @current-state) + + + ;; result + (def canidates + (apply common-differences + (map (comp vec memory) + [empty-inventory one-potion two-potions three-potions + four-potions five-potions]))) + + [55875 (37 15 49 27 14 44)] + [55876 (30 1 49 56 55 23)] + [49158 (154 191 78 135 70 73)] + [54087 (49 40 37 34 25 22)] + [49160 (7 24 59 243 50 217)] + [49704 (31 14 72 33 84 27)] + [49162 (126 159 183 110 176 179)] + [39984 (0 254 251 248 127 252)] + [49904 (29 72 64 78 1 95)] + [65491 (222 127 149 132 226 38)] + [65492 (44 20 89 11 253 163)] + [49335 (52 15 6 14 3 17)] + [49720 (78 152 96 60 83 103)] + [65304 (19 89 214 33 18 113)] + [53561 (132 185 145 162 159 183)] + [54046 (0 1 2 3 4 5)]) + +;;; hmmmmmm...... I guess that the potion quantities are at 54046, +;;;huh? + + + +(def item-hack (read-state 7999)) + +(def item-hack2 (read-state 75882)) + +(defn get-mem [] + (subvec (vec (memory @current-state)) 54040 (+ 54046 100))) + + +;; potion -- 99 +[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] + +;; potion -- 95 +[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] + +;; potion -- 95 +;; pokeball -- 1 +[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] + +;; potion -- 95 +;; pokeball -- 10 +[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] + + +;; pokeball -- 10 +;; potion -- 95 +[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] + +;; pokeball -- 10 +;; potion -- 95 +;; antidote -- 1 + +;;prediction +;;[0 16 0 0 3 4 10 20 95 ?? 1 255 0 0 0 0 0 ....] + [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] + + + +;; now it's time to learn the item codes + +(def item-hack-3 (read-state 77557)) +(defn show-item + "Run a saved pokemon with the first item replaced by the item named + by n." + [n] + (set-state! item-hack-3) + (let [mem (memory)] + (aset mem 54045 n) + (write-memory! mem)) + (step) + (->> [[] @current-state] + (play-moves + [[:a] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] + [] [] [] [] []]))) + + +(defn get-item-names [] + (dorun (map (fn [n] (println n) + (show-item n) + (Thread/sleep 5000)) + (range 0x00 0xFF)))) + +;; results (took about 10 minutes to generate) + +;; 0 garbage +;; 1 master-ball +;; 2 ultra-ball +;; 3 great-ball +;; 4 poke-ball +;; 5 town-map +;; 6 bicycle +;; 7 ????? +;; 8 safari-ball +;; 9 pokedex +;; 10 moon-stone +;; 11 antidote +;; 12 burn-heal +;; 13 ice-heal +;; 14 awakening +;; 15 parlyz-heal +;; 16 full-restore +;; 17 max-potion +;; 18 hyper-potion +;; 19 super-potion +;; 20 potion +;; 21 boulderbadge +;; 22 cascadebadge +;; 23 thunderbadge +;; 24 rainbowbadge +;; 25 soulbadge +;; 26 marshbadge +;; 27 volcanobadge +;; 28 earthbadge +;; 29 escape-rope +;; 30 repel +;; 31 old amber +;; 32 fire-stone +;; 33 thunderstone +;; 34 water-stone +;; 35 hp-up +;; 36 protein +;; 37 iron +;; 38 carbos +;; 39 calcium +;; 40 rare-candy +;; 41 dome-fossil +;; 42 helix-fossil +;; 43 secret-key +;; 44 ????? +;; 45 bike-voucher +;; 46 x-accuracy +;; 47 leaf-stone +;; 48 card-key +;; 49 nugget +;; 50 pp-up +;; 51 poke-doll +;; 52 full-heal +;; 53 revive +;; 54 max-revive +;; 55 guard-spec. +;; 56 super-repel +;; 57 max-repel +;; 58 dire-hit +;; 59 coin +;; 60 fresh-water +;; 61 soda-pop +;; 62 lemonade +;; 63 s.s.ticket +;; 64 gold-teeth +;; 65 x-attach +;; 66 x-defend +;; 67 x-speed +;; 68 x-special +;; 69 coin-case +;; 70 oak's-parcel +;; 71 itemfinder +;; 72 silph-scope +;; 73 poke-flute +;; 74 lift-key +;; 75 exp.all +;; 76 old-rod +;; 77 good-rod +;; 78 super-rod +;; 79 pp-up +;; 80 ether +;; 81 max-ether +;; 82 elixer +;; 83 max-elixer +;; 84 B2F +;; 85 B1F +;; 86 1F +;; 87 2F +;; 88 3F +;; 89 4F +;; 90 5F +;; 91 6F +;; 92 7F +;; 93 8F +;; 94 9F +;; 95 10F +;; 96 11F +;; 97 B4F +;; 98 garbage +;; 99 garbage +;; 100 garbage +;; 101 garbage +;; 102 garbage +;; 103 garbage +;; 104 garbage +;; 105 garbage +;; 106 garbage +;; 107 garbage +;; 108 garbage +;; 109 garbage +;; 110 garbage +;; 111 garbage +;; 112 garbage +;; 113 garbage +;; 114 garbage +;; 115 garbage +;; 116 garbage +;; 117 garbage +;; 118 garbage +;; 119 4 +;; 120 garbage +;; 121 garbage +;; 122 slow +;; 123 garbage +;; 124 garbage +;; 125 garbage +;; 126 garbage +;; 127 garbage +;; 128 garbage +;; 129 garbage +;; 130 garbage +;; 131 slow +;; 132 slow +;; 133 garbage +;; 134 slow +;; 135 garbage +;; 136 garbage +;; 137 slow +;; 138 garbage +;; 139 garbage +;; 140 garbage +;; 141 slow +;; 142 garbage +;; 143 garbage +;; 144 garbage +;; 145 garbage +;; 146 garbage +;; 147 garbage +;; 148 garbage +;; 149 garbage +;; 150 slow +;; 151 garbage +;; 152 Q +;; 153 garbage +;; 154 garbage +;; 155 garbage +;; 156 garbage +;; 157 garbage +;; 158 garbage +;; 159 garbage +;; 160 garbage (alaphabet) +;; 161 garbage +;; 162 garbage +;; 163 garbage +;; 164 rival's +;; 165 name? +;; 166 nickname? +;; 167 slow +;; 168 garbage +;; 169 slow +;; 170 garbage +;; 171 garbage +;; 172 garbage +;; 173 garbage +;; 174 garbage +;; 175 yellow +;; 176 ash +;; 177 jack +;; 178 new-name +;; 179 blue +;; 180 gary +;; 181 john +;; 182 garbage +;; 183 garbage +;; 184 garbage +;; 185 garbage +;; 186 slow +;; 187 garbage +;; 188 garbage +;; 189 garbage +;; 190 garbage +;; 191 garbage +;; 192 garbage +;; 193 garbage +;; 194 garbage +;; 195 slow +;; 196 HM01 +;; 197 HM02 +;; 198 HM03 +;; 199 HM04 +;; 200 HM05 +;; 201 TM01 +;; 202 TM02 +;; 203 TM03 +;; 204 TM04 +;; 205 TM05 +;; 206 TM06 +;; 207 TM07 +;; 208 TM08 +;; 209 TM09 +;; 210 TM10 +;; 211 TM11 +;; 212 TM12 +;; 213 TM13 +;; 214 TM13 +;; 215 TM15 +;; 216 TM16 +;; 217 TM17 +;; 218 TM18 +;; 219 TM19 +;; 220 TM20 +;; 221 TM21 +;; 222 TM22 +;; 223 TM23 +;; 224 TM24 +;; 225 TM25 +;; 226 TM26 +;; 227 TM27 +;; 228 TM28 +;; 229 TM29 +;; 230 TM30 +;; 231 TM31 +;; 232 TM32 +;; 233 TM33 +;; 234 TM34 +;; 235 TM35 +;; 236 TM36 +;; 237 TM37 +;; 238 TM38 +;; 239 TM39 +;; 240 TM40 +;; 241 TM41 +;; 242 TM42 +;; 243 TM43 +;; 244 TM44 +;; 245 TM45 +;; 246 TM46 +;; 247 TM47 +;; 248 TM48 +;; 249 TM49 +;; 250 TM50 +;; 251 TM51 +;; 252 TM52 +;; 253 TM53 +;; 254 TM54 +;; 255 end-of-list-sentinel diff -r 08cd8be1edc1 -r 9fad96094950 clojure/com/aurellem/gb_driver.clj --- a/clojure/com/aurellem/gb_driver.clj Mon Mar 12 00:31:10 2012 -0500 +++ b/clojure/com/aurellem/gb_driver.clj Mon Mar 12 09:59:26 2012 -0500 @@ -99,6 +99,11 @@ (defrecord Move [keys state]) +(defn update-state [] + (reset! current-state + (SaveState. (:frame @current-state) + (Gb/saveState)))) + (defn step ([^SaveState state buttons] (set-state! state) diff -r 08cd8be1edc1 -r 9fad96094950 clojure/com/aurellem/items.clj --- a/clojure/com/aurellem/items.clj Mon Mar 12 00:31:10 2012 -0500 +++ b/clojure/com/aurellem/items.clj Mon Mar 12 09:59:26 2012 -0500 @@ -1,403 +1,215 @@ (ns com.aurellem.items (:use (com.aurellem gb-driver vbm title)) - ;; this is fucking bullshit + ;; this is bullshit (:import [com.aurellem.gb_driver SaveState])) - - (defn game-name [] (map char (subvec (vec (memory)) 0x134 0x142))) +(def item-list-start 0xD31C) - - - -(defn current-items [^SaveState state] - (set-state! state) - - - ) - - - -;; try just buying five potions in sequence and see what changes -;; each time. - -(defn common-differences [& seqs] - (let [backbone (range (count (first seqs)))] - (filter - (comp (partial apply distinct?) second) - (zipmap backbone - (apply (partial map list) seqs))))) - -;; trying to find how items are represented in memory - -(comment - (def empty-inventory @current-state) - - (def one-potion @current-state) - - (def two-potions @current-state) - - (def three-potions @current-state) - - (def four-potions @current-state) - - (def five-potions @current-state) - - - ;; result - (def canidates - (apply common-differences - (map (comp vec memory) - [empty-inventory one-potion two-potions three-potions - four-potions five-potions]))) - - [55875 (37 15 49 27 14 44)] - [55876 (30 1 49 56 55 23)] - [49158 (154 191 78 135 70 73)] - [54087 (49 40 37 34 25 22)] - [49160 (7 24 59 243 50 217)] - [49704 (31 14 72 33 84 27)] - [49162 (126 159 183 110 176 179)] - [39984 (0 254 251 248 127 252)] - [49904 (29 72 64 78 1 95)] - [65491 (222 127 149 132 226 38)] - [65492 (44 20 89 11 253 163)] - [49335 (52 15 6 14 3 17)] - [49720 (78 152 96 60 83 103)] - [65304 (19 89 214 33 18 113)] - [53561 (132 185 145 162 159 183)] - [54046 (0 1 2 3 4 5)]) - -;;; hmmmmmm...... I guess that the potion quantities are at 54046, -;;;huh? - - - -(def item-hack (read-state 7999)) - -(def item-hack2 (read-state 75882)) - -(defn get-mem [] - (subvec (vec (memory @current-state)) 54040 (+ 54046 100))) - - -;; potion -- 99 -[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] - -;; potion -- 95 -[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] - -;; potion -- 95 -;; pokeball -- 1 -[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] - -;; potion -- 95 -;; pokeball -- 10 -[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] - - -;; pokeball -- 10 -;; potion -- 95 -[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] - -;; pokeball -- 10 -;; potion -- 95 -;; antidote -- 1 - -;;prediction -;;[0 16 0 0 3 4 10 20 95 ?? 1 255 0 0 0 0 0 ....] - [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] - - - -;; now it's time to learn the item codes +(defn item-list [^SaveState state] + (subvec + (vec (memory state)) + item-list-start + (+ item-list-start 60))) (def item-hack-3 (read-state 77557)) -(defn show-item - "Run a saved pokemon with the first item replaced by the item named - by n." - [n] - (set-state! item-hack-3) - (let [mem (memory)] - (aset mem 54045 n) - (write-memory! mem)) - (step) - (->> [[] @current-state] - (play-moves - [[:a] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] - [] [] [] [] []]))) +(def item-code->item-name + (hash-map + 1 :master-ball + 2 :ultra-ball + 3 :great-ball + 4 :poke-ball + 5 :town-map + 6 :bicycle + 8 :safari-ball + 9 :pokedex + 10 :moon-stone + 11 :antidote + 12 :burn-heal + 13 :ice-heal + 14 :awakening + 15 :parlyz-heal + 16 :full-restore + 17 :max-potion + 18 :hyper-potion + 19 :super-potion + 20 :potion + 21 :boulderbadge + 22 :cascadebadge + 23 :thunderbadge + 24 :rainbowbadge + 25 :soulbadge + 26 :marshbadge + 27 :volcanobadge + 28 :earthbadge + 29 :escape-rope + 30 :repel + 31 :old-amber + 32 :fire-stone + 33 :thunderstone + 34 :water-stone + 35 :hp-up + 36 :protein + 37 :iron + 38 :carbos + 39 :calcium + 40 :rare-candy + 41 :dome-fossil + 42 :helix-fossil + 43 :secret-key + 45 :bike-voucher + 46 :x-accuracy + 47 :leaf-stone + 48 :card-key + 49 :nugget + 50 :pp-up + 51 :poke-doll + 52 :full-heal + 53 :revive + 54 :max-revive + 55 :guard-spec + 56 :super-repel + 57 :max-repel + 58 :dire-hit + 59 :coin + 60 :fresh-water + 61 :soda-pop + 62 :lemonade + 63 :s.s.ticket + 64 :gold-teeth + 65 :x-attach + 66 :x-defend + 67 :x-speed + 68 :x-special + 69 :coin-case + 70 :oaks-parcel + 71 :itemfinder + 72 :silph-scope + 73 :poke-flute + 74 :lift-key + 75 :exp.all + 76 :old-rod + 77 :good-rod + 78 :super-rod + 79 :pp-up + 80 :ether + 81 :max-ether + 82 :elixer + 83 :max-elixer + 196 :HM01 + 197 :HM02 + 198 :HM03 + 199 :HM04 + 200 :HM05 + 201 :TM01 + 202 :TM02 + 203 :TM03 + 204 :TM04 + 205 :TM05 + 206 :TM06 + 207 :TM07 + 208 :TM08 + 209 :TM09 + 210 :TM10 + 211 :TM11 + 212 :TM12 + 213 :TM13 + 214 :TM13 + 215 :TM15 + 216 :TM16 + 217 :TM17 + 218 :TM18 + 219 :TM19 + 220 :TM20 + 221 :TM21 + 222 :TM22 + 223 :TM23 + 224 :TM24 + 225 :TM25 + 226 :TM26 + 227 :TM27 + 228 :TM28 + 229 :TM29 + 230 :TM30 + 231 :TM31 + 232 :TM32 + 233 :TM33 + 234 :TM34 + 235 :TM35 + 236 :TM36 + 237 :TM37 + 238 :TM38 + 239 :TM39 + 240 :TM40 + 241 :TM41 + 242 :TM42 + 243 :TM43 + 244 :TM44 + 245 :TM45 + 246 :TM46 + 247 :TM47 + 248 :TM48 + 249 :TM49 + 250 :TM50 + 251 :TM51 + 252 :TM52 + 253 :TM53 + 254 :TM54 + 255 :end-of-list-sentinel)) -(defn get-item-names [] - (dorun (map (fn [n] (println n) - (show-item n) - (Thread/sleep 5000)) - (range 0x00 0xFF)))) +(def item-name->item-code + (zipmap (vals item-code->item-name) + (keys item-code->item-name))) +(defn inventory [^SaveState state] + (let [items (item-list state)] + (map + (fn [[item-code quantity]] + [(item-code->item-name item-code) + quantity]) + (partition + 2 + (next (take-while (partial not= 255) items)))))) +(defn print-inventory [^SaveState state] + (println + (let [inv (inventory state)] + (reduce + str + (concat + ["+-------------------+----------+\n" + "|##| Item | Quantity |\n" + "+--+----------------+----------+\n"] -;; 0 garbage -;; 1 master-ball -;; 2 ultra-ball -;; 3 great-ball -;; 4 poke-ball -;; 5 town-map -;; 6 bicycle -;; 7 ????? -;; 8 safari-ball -;; 9 pokedex -;; 10 moon-stone -;; 11 antidote -;; 12 burn-heal -;; 13 ice-heal -;; 14 awakening -;; 15 parlyz-heal -;; 16 full-restore -;; 17 max-potion -;; 18 hyper-potion -;; 19 super-potion -;; 20 potion -;; 21 boulderbadge -;; 22 cascadebadge -;; 23 thunderbadge -;; 24 rainbowbadge -;; 25 soulbadge -;; 26 marshbadge -;; 27 volcanobadge -;; 28 earthbadge -;; 29 escape-rope -;; 30 repel -;; 31 old amber -;; 32 fire-stone -;; 33 thunderstone -;; 34 water-stone -;; 35 hp-up -;; 36 protein -;; 37 iron -;; 38 carbos -;; 39 calcium -;; 40 rare-candy -;; 41 dome-fossil -;; 42 helix-fossil -;; 43 secret-key -;; 44 ????? -;; 45 bike-voucher -;; 46 x-accuracy -;; 47 leaf-stone -;; 48 card-key -;; 49 nugget -;; 50 pp-up -;; 51 poke-doll -;; 52 full-heal -;; 53 revive -;; 54 max-revive -;; 55 guard-spec. -;; 56 super-repel -;; 57 max-repel -;; 58 dire-hit -;; 59 coin -;; 60 fresh-water -;; 61 soda-pop -;; 62 lemonade -;; 63 s.s.ticket -;; 64 gold-teeth -;; 65 x-attach -;; 66 x-defend -;; 67 x-speed -;; 68 x-special -;; 69 coin-case -;; 70 oak's-parcel -;; 71 itemfinder -;; 72 silph-scope -;; 73 poke-flute -;; 74 lift-key -;; 75 exp.all -;; 76 old-rod -;; 77 good-rod -;; 78 super-rod -;; 79 pp-up -;; 80 ether -;; 81 max-ether -;; 82 elixer -;; 83 max-elixer -;; 84 B2F -;; 85 B1F -;; 86 1F -;; 87 2F -;; 88 3F -;; 89 4F -;; 90 5F -;; 91 6F -;; 92 7F -;; 93 8F -;; 94 9F -;; 95 10F -;; 96 11F -;; 97 B4F -;; 98 garbage -;; 99 garbage -;; 100 garbage -;; 101 garbage -;; 102 garbage -;; 103 garbage -;; 104 garbage -;; 105 garbage -;; 106 garbage -;; 107 garbage -;; 108 garbage -;; 109 garbage -;; 110 garbage -;; 111 garbage -;; 112 garbage -;; 113 garbage -;; 114 garbage -;; 115 garbage -;; 116 garbage -;; 117 garbage -;; 118 garbage -;; 119 4 -;; 120 garbage -;; 121 garbage -;; 122 slow -;; 123 garbage -;; 124 garbage -;; 125 garbage -;; 126 garbage -;; 127 garbage -;; 128 garbage -;; 129 garbage -;; 130 garbage -;; 131 slow -;; 132 slow -;; 133 garbage -;; 134 slow -;; 135 garbage -;; 136 garbage -;; 137 slow -;; 138 garbage -;; 139 garbage -;; 140 garbage -;; 141 slow -;; 142 garbage -;; 143 garbage -;; 144 garbage -;; 145 garbage -;; 146 garbage -;; 147 garbage -;; 148 garbage -;; 149 garbage -;; 150 slow -;; 151 garbage -;; 152 Q -;; 153 garbage -;; 154 garbage -;; 155 garbage -;; 156 garbage -;; 157 garbage -;; 158 garbage -;; 159 garbage -;; 160 garbage (alaphabet) -;; 161 garbage -;; 162 garbage -;; 163 garbage -;; 164 rival's -;; 165 name? -;; 166 nickname? -;; 167 slow -;; 168 garbage -;; 169 slow -;; 170 garbage -;; 171 garbage -;; 172 garbage -;; 173 garbage -;; 174 garbage -;; 175 yellow -;; 176 ash -;; 177 jack -;; 178 new-name -;; 179 blue -;; 180 gary -;; 181 john -;; 182 garbage -;; 183 garbage -;; 184 garbage -;; 185 garbage -;; 186 slow -;; 187 garbage -;; 188 garbage -;; 189 garbage -;; 190 garbage -;; 191 garbage -;; 192 garbage -;; 193 garbage -;; 194 garbage -;; 195 slow -;; 196 HM01 -;; 197 HM02 -;; 198 HM03 -;; 199 HM04 -;; 200 HM05 -;; 201 TM01 -;; 202 TM02 -;; 203 TM03 -;; 204 TM04 -;; 205 TM05 -;; 206 TM06 -;; 207 TM07 -;; 208 TM08 -;; 209 TM09 -;; 210 TM10 -;; 211 TM11 -;; 212 TM12 -;; 213 TM13 -;; 214 TM13 -;; 215 TM15 -;; 216 TM16 -;; 217 TM17 -;; 218 TM18 -;; 219 TM19 -;; 220 TM20 -;; 221 TM21 -;; 222 TM22 -;; 223 TM23 -;; 224 TM24 -;; 225 TM25 -;; 226 TM26 -;; 227 TM27 -;; 228 TM28 -;; 229 TM29 -;; 230 TM30 -;; 231 TM31 -;; 232 TM32 -;; 233 TM33 -;; 234 TM34 -;; 235 TM35 -;; 236 TM36 -;; 237 TM37 -;; 238 TM38 -;; 239 TM39 -;; 240 TM40 -;; 241 TM41 -;; 242 TM42 -;; 243 TM43 -;; 244 TM44 -;; 245 TM45 -;; 246 TM46 -;; 247 TM47 -;; 248 TM48 -;; 249 TM49 -;; 250 TM50 -;; 251 TM51 -;; 252 TM52 -;; 253 TM53 -;; 254 TM54 -;; 255 end-of-list-sentinel + (map + (fn [index [item-name quantity]] + (str + (format "|%-2d| %-14s | %3d |\n" index + (apply str (rest (str item-name))) + quantity))) + (range 0 (count inv)) inv) + ["+--+----------------+----------+\n"]))))) - +(defn inventory-codes [inventory] + (flatten + (concat [(count inventory)] + (map (fn [[item-name quantity]] + [(item-name->item-code item-name) + quantity]) inventory) + [(item-name->item-code :end-of-list-sentinel)]))) - +(defn set-inventory [^SaveState state new-inventory] + (set-state! state) + (let [mem (memory state) + inv (inventory-codes new-inventory)] + (dorun (map (fn [index val] + (aset mem index val)) + (range item-list-start + (+ item-list-start (count inv))) inv)) + (write-memory! mem) + (update-state))) -