Mercurial > vba-clojure
diff clojure/com/aurellem/run/bootstrap_1.clj @ 369:abcc522a3242
script: wrote memory pattern from within game!
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 10 Apr 2012 06:33:44 -0500 |
parents | 08f8284e2f1b |
children | 7c89fe478de4 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/bootstrap_1.clj Tue Apr 10 03:32:47 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/bootstrap_1.clj Tue Apr 10 06:33:44 2012 -0500 1.3 @@ -108,7 +108,7 @@ 1.4 0x01 ;; (item-hack) will never reach this instruction 1.5 1.6 ] 1.7 - (repeat 8 [0x00 0x02]);; these can be anything 1.8 + (repeat 8 [0x00 0x01]);; these can be anything 1.9 1.10 [;; jump to actual program 1.11 0x00 1.12 @@ -182,38 +182,20 @@ 1.13 finish-title 1.14 (walk [← ← ↑ ← ↑ ↑ ↑])))) 1.15 1.16 -(defn-memo bootstrap-corrupt-save 1.17 - ([] (bootstrap-corrupt-save (to-room-pc))) 1.18 - ([script] 1.19 - (->> script 1.20 - (do-save-corruption 2) 1.21 - (corrupt-item-list 0) 1.22 - close-all-menus))) 1.23 - 1.24 -(defn-memo begin-initial-deposits 1.25 - ([] (begin-initial-deposits 1.26 - (bootstrap-corrupt-save))) 1.27 - ([script] 1.28 - (->> script 1.29 - (first-difference [] [:a] AF) 1.30 - (scroll-text) 1.31 - (set-cursor 1) 1.32 - select-menu-entry))) 1.33 - 1.34 -(defn wait-for-quantity 1.35 - [[moves state :as script]] 1.36 - (if (not= (item-quantity-selected state) 1) 1.37 - (repeat-until-different [] item-quantity-selected script) 1.38 - script)) 1.39 +;; (defn wait-for-quantity 1.40 +;; [[moves state :as script]] 1.41 +;; (if (not= (item-quantity-selected state) 1) 1.42 +;; (repeat-until-different [] item-quantity-selected script) 1.43 +;; script)) 1.44 1.45 ;; TODO use this: 1.46 ;;(wait-until (partial set-cursor-relative 1)) 1.47 1.48 -(defn wait-for-cursor 1.49 - [[moves state :as script]] 1.50 - (if (not= (list-offset state) 0) 1.51 - (repeat-until-different [] list-offset script) 1.52 - script)) 1.53 +;; (defn wait-for-cursor 1.54 +;; [[moves state :as script]] 1.55 +;; (if (not= (list-offset state) 0) 1.56 +;; (repeat-until-different [] list-offset script) 1.57 +;; script)) 1.58 1.59 (defn deposit-held-item [n quantity [moves state :as script]] 1.60 (let [total-quantity (second (nth-item state n))] 1.61 @@ -221,7 +203,7 @@ 1.62 (->> script 1.63 (set-cursor n) 1.64 (select-menu-entry 1) 1.65 - (wait-for-quantity) 1.66 + ;;(wait-for-quantity) 1.67 (set-quantity total-quantity quantity) 1.68 (delayed-difference [] [:a] 100 #(search-string % "stored")) 1.69 (scroll-text)))) 1.70 @@ -229,10 +211,10 @@ 1.71 (defn sell-held-item [n quantity [moves state :as script]] 1.72 (let [total-quantity (second (nth-item state n))] 1.73 (->> script 1.74 - (wait-for-cursor) ;; when selling, the cursor always 1.75 + ;;(wait-for-cursor) ;; when selling, the cursor always 1.76 (set-cursor n) ;; returns to the top of the list. 1.77 (select-menu-entry 1) 1.78 - (wait-for-quantity) 1.79 + ;;(wait-for-quantity) 1.80 (set-quantity total-quantity quantity) 1.81 (delayed-difference [] [:a] 100 current-depth) 1.82 (play-moves (repeat 20 [:b])) 1.83 @@ -244,7 +226,7 @@ 1.84 (->> script 1.85 (set-cursor n) 1.86 (select-menu-entry 1) 1.87 - (wait-for-quantity) 1.88 + ;;(wait-for-quantity) 1.89 (set-quantity total-quantity quantity) 1.90 (delayed-difference [] [:a] 100 #(search-string % "Withdrew")) 1.91 (scroll-text)))) 1.92 @@ -256,7 +238,7 @@ 1.93 (select-menu-entry 1) 1.94 (set-cursor-relative 1) 1.95 (select-menu-entry -1) 1.96 - (wait-for-quantity) 1.97 + ;;(wait-for-quantity) 1.98 (set-quantity total-quantity quantity) 1.99 (play-moves [[:a]]) 1.100 (scroll-text) 1.101 @@ -269,11 +251,57 @@ 1.102 (set-cursor n) 1.103 (purchase-item quantity))) 1.104 1.105 +(defn switch-items [item-fn idx-1 idx-2 script] 1.106 + (->> script 1.107 + (wait-until select-menu-entry) 1.108 + (set-cursor idx-1) 1.109 + (wait-until select-menu-entry) 1.110 + (play-moves [[][:select][]]) 1.111 + (set-cursor idx-2) 1.112 + (delayed-difference [] [:select] 100 1.113 + #(item-fn % (list-offset %))))) 1.114 + 1.115 +(def switch-pc-items (partial switch-items nth-pc-item)) 1.116 +(def switch-held-items (partial switch-items nth-item)) 1.117 + 1.118 +(defn combine-pc-items [idx-1 script] 1.119 + (->> script 1.120 + (switch-pc-items idx-1 (inc idx-1)))) 1.121 1.122 (def desired-zero-quantities 1.123 (map second (filter (comp (partial = 0) first) 1.124 (partition 2 (pc-item-writer-program))))) 1.125 - 1.126 + 1.127 +(defn-memo bootstrap-corrupt-save 1.128 + ([] (bootstrap-corrupt-save (to-room-pc))) 1.129 + ([script] 1.130 + (->> script 1.131 + (do-save-corruption 3) 1.132 + (corrupt-item-list 0) 1.133 + close-all-menus))) 1.134 + 1.135 +(defn-memo prepare-celadon-warp 1.136 + ([] (prepare-celadon-warp (bootstrap-corrupt-save))) 1.137 + ([script] 1.138 + (->> script 1.139 + (activate-start-menu) 1.140 + (set-cursor-relative 1) 1.141 + (select-menu-entry) 1.142 + ;; vastly increase text speed while we're here. 1.143 + (switch-held-items 21 27) 1.144 + (toss-held-item 35 0xFA) 1.145 + (close-all-menus)))) 1.146 + 1.147 +(defn-memo begin-initial-deposits 1.148 + ([] (begin-initial-deposits 1.149 + (prepare-celadon-warp))) 1.150 + ([script] 1.151 + (->> script 1.152 + (first-difference [] [:a] AF) 1.153 + (scroll-text) 1.154 + (set-cursor 1) 1.155 + select-menu-entry))) 1.156 + 1.157 (defn-memo initial-deposits 1.158 ([] (initial-deposits (begin-initial-deposits))) 1.159 ([script] 1.160 @@ -287,28 +315,23 @@ 1.161 close-all-menus))) 1.162 1.163 1.164 -(defn-memo prepare-celadon-warp 1.165 - ([] (prepare-celadon-warp (initial-deposits))) 1.166 - ([script] 1.167 - (->> script 1.168 - (activate-start-menu) 1.169 - (set-cursor-relative 1) 1.170 - (select-menu-entry) 1.171 - (toss-held-item 35 0xFA) 1.172 - (close-all-menus)))) 1.173 - 1.174 - 1.175 ;;0 -- 256 1.176 ;;1 -- 254 1.177 ;;2 -- 254 1.178 ;;3 -- 255 1.179 1.180 +(defn activate-home-pc 1.181 + [script] 1.182 + (->> script 1.183 + (delayed-difference [] [:a] 1.184 + 200 first-character) 1.185 + (scroll-text))) 1.186 + 1.187 (defn-memo restore-items 1.188 - ([] (restore-items (prepare-celadon-warp))) 1.189 + ([] (restore-items (initial-deposits))) 1.190 ([script] 1.191 (->> script 1.192 - (first-difference [] [:a] AF) 1.193 - (scroll-text) 1.194 + activate-home-pc 1.195 (select-menu-entry) 1.196 (widthdraw-pc-item 0 1) 1.197 ;;(widthdraw-pc-item 0 99) 1.198 @@ -404,7 +427,7 @@ 1.199 ([] (floor-two-TMs (get-money-floor-two))) 1.200 ([script] 1.201 (->> script 1.202 - (wait-for-cursor) 1.203 + (set-cursor 0) 1.204 (select-menu-entry) 1.205 (buy-item 2 98) ;; TM02 (razor-wind) 1.206 (buy-item 4 71) ;; TM37 (doubleteam) 1.207 @@ -424,7 +447,6 @@ 1.208 ([] (floor-two-more-money (floor-two-TMs))) 1.209 ([script] 1.210 (->> script 1.211 - (wait-for-cursor) 1.212 (set-cursor 1) 1.213 (select-menu-entry) 1.214 (sell-held-item 0 1) 1.215 @@ -527,7 +549,6 @@ 1.216 (do-nothing 20) 1.217 (play-moves [[:a][:a]]) 1.218 scroll-text 1.219 - (wait-for-cursor) 1.220 (set-cursor n) 1.221 select-menu-entry 1.222 close-menu)) 1.223 @@ -545,8 +566,9 @@ 1.224 ([] (get-TM13 (roof-drinks))) 1.225 ([script] 1.226 (->> script 1.227 - (walk [← ← ← ← ← ← ↓]) 1.228 - (play-moves [[][:a][:a][]]) 1.229 + ;;(walk [← ← ← ← ← ← ↓]) 1.230 + (walk [↓ ↓ ↓ ← ← ← ← ← ←]) 1.231 + (play-moves [[][][][][:a][:a][]]) 1.232 (scroll-text 3) 1.233 select-menu-entry 1.234 select-menu-entry 1.235 @@ -557,7 +579,8 @@ 1.236 ([] (to-celadon-poke-center (get-TM13))) 1.237 ([script] 1.238 (->> script 1.239 - (walk [↑ → → → → → → → → → ↑]) ; leave roof 1.240 + ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof 1.241 + (walk [→ → → → → → → → → ↑ ↑ ↑ ↑]) 1.242 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ← 1.243 ↑ ↑ ↑ ← ← ↑]) ; to elevator 1.244 1.245 @@ -576,7 +599,7 @@ 1.246 (->> script 1.247 talk 1.248 scroll-text 1.249 - wait-for-cursor 1.250 + ;;wait-for-cursor 1.251 (set-cursor 1) 1.252 select-menu-entry 1.253 (scroll-text 2))) 1.254 @@ -602,9 +625,34 @@ 1.255 (println "index" index) 1.256 (deposit-held-item index quantity script))) 1.257 1.258 +(defn open-held-items 1.259 + [script] 1.260 + (->> script 1.261 + select-menu-entry)) 1.262 1.263 -(defn-memo begin-hacking 1.264 - ([] (begin-hacking(to-celadon-poke-center))) 1.265 +(defn to-held-items 1.266 + [script] 1.267 + (->> script 1.268 + close-menu 1.269 + close-menu 1.270 + end-text;;; grr 1.271 + 1.272 + activate-start-menu 1.273 + open-held-items)) 1.274 + 1.275 +(defn toss-pc-item [n quantity [moves state :as script]] 1.276 + (let [total-quantity (second (nth-pc-item state n))] 1.277 + (->> script 1.278 + (set-cursor n) 1.279 + (select-menu-entry 1) 1.280 + (set-quantity total-quantity quantity) 1.281 + (delayed-difference [] [:a] 100 #(search-string % "Is")) 1.282 + (scroll-text) 1.283 + select-menu-entry 1.284 + (scroll-text)))) 1.285 + 1.286 +(defn-memo hacking-1 1.287 + ([] (hacking-1 (to-celadon-poke-center))) 1.288 ([script] 1.289 (->> script 1.290 activate-rlm-pc 1.291 @@ -616,23 +664,8 @@ 1.292 (deposit-held-item-named :TM09 55) 1.293 (deposit-held-item-named 0x00 55)))) 1.294 1.295 -(defn open-held-items 1.296 - [script] 1.297 - (->> script 1.298 - select-menu-entry)) 1.299 - 1.300 -(defn to-held-items 1.301 - [script] 1.302 - (->> script 1.303 - close-menu 1.304 - close-menu 1.305 - end-text;;; grr 1.306 - 1.307 - activate-start-menu 1.308 - open-held-items)) 1.309 - 1.310 (defn-memo hacking-2 1.311 - ([] (hacking-2 (begin-hacking))) 1.312 + ([] (hacking-2 (hacking-1))) 1.313 ([script] 1.314 (->> script 1.315 (to-held-items) 1.316 @@ -697,34 +730,8 @@ 1.317 (deposit-held-item-named :ice-heal 55) 1.318 (deposit-held-item-named :fire-stone 23) 1.319 (deposit-held-item-named :burn-heal 12) 1.320 - close-menu))) 1.321 - 1.322 -(defn switch-items [item-fn idx-1 idx-2 script] 1.323 - (->> script 1.324 - (wait-until select-menu-entry) 1.325 - (set-cursor idx-1) 1.326 - (wait-until select-menu-entry) 1.327 - (play-moves [[][:select][]]) 1.328 - (set-cursor idx-2) 1.329 - (delayed-difference [] [:select] 100 1.330 - #(item-fn % (list-offset %))))) 1.331 - 1.332 -(def switch-pc-items (partial switch-items nth-pc-item)) 1.333 -(def switch-held-items (partial switch-items nth-item)) 1.334 - 1.335 -(defn combine-pc-items [idx-1 script] 1.336 - (->> script 1.337 - (switch-pc-items idx-1 (inc idx-1)))) 1.338 - 1.339 -(defn combine-items [idx-1 script] 1.340 - (->> script 1.341 - (wait-until select-menu-entry) 1.342 - (set-cursor idx-1) 1.343 - (wait-until select-menu-entry) 1.344 - (play-moves [[][:select][]]) 1.345 - (set-cursor-relative 1) 1.346 - (delayed-difference [] [:select] 100 1.347 - #(nth-pc-item % (list-offset %))))) 1.348 + ;; as a special case, /don't/ close the menu. 1.349 + ))) 1.350 1.351 (defn-memo hacking-8 1.352 "Clear cruft away from held item list." 1.353 @@ -769,7 +776,6 @@ 1.354 (deposit-held-item 13 191) 1.355 (deposit-held-item-named :TM02 98) 1.356 (deposit-held-item-named :TM09 1) 1.357 - close-menu 1.358 close-menu))) 1.359 1.360 (defn-memo hacking-11 1.361 @@ -785,7 +791,7 @@ 1.362 (widthdraw-pc-item 5 0xFB) 1.363 (multiple-times 1.364 3 1.365 - (partial combine-items 2)) 1.366 + (partial combine-pc-items 2)) 1.367 close-menu))) 1.368 1.369 (defn-memo hacking-12 1.370 @@ -799,28 +805,14 @@ 1.371 (deposit-held-item-named :TM05 1) 1.372 (multiple-times 1.373 8 1.374 - (partial deposit-held-item 14 2)) 1.375 + (partial deposit-held-item 14 1)) 1.376 (deposit-held-item 14 55) 1.377 (deposit-held-item-named :x-accuracy 58) 1.378 (deposit-held-item 14 38) 1.379 (deposit-held-item-named :TM13 1) 1.380 (deposit-held-item 13 1) 1.381 (deposit-held-item 13 233) 1.382 - close-menu 1.383 close-menu))) 1.384 - 1.385 - 1.386 -(defn toss-pc-item [n quantity [moves state :as script]] 1.387 - (let [total-quantity (second (nth-pc-item state n))] 1.388 - (->> script 1.389 - (set-cursor n) 1.390 - (select-menu-entry 1) 1.391 - (wait-for-quantity) 1.392 - (set-quantity total-quantity quantity) 1.393 - (delayed-difference [] [:a] 100 #(search-string % "Is")) 1.394 - (scroll-text) 1.395 - select-menu-entry 1.396 - (scroll-text)))) 1.397 1.398 (defn-memo hacking-13 1.399 ([] (hacking-13 (hacking-12))) 1.400 @@ -843,9 +835,6 @@ 1.401 (println actual-pattern) 1.402 (= target-pattern actual-pattern))) 1.403 1.404 -;; this will be useful for starting program 1.405 - 1.406 - 1.407 (defn-memo go-to-mansion-for-the-lulz 1.408 ([] (go-to-mansion-for-the-lulz (hacking-13))) 1.409 ([script] 1.410 @@ -861,38 +850,77 @@ 1.411 ← ← ← ← ↑ ↑ ↑ ← ↑]) 1.412 (talk) 1.413 (scroll-text 2) 1.414 + (do-nothing 100) 1.415 close-menu))) 1.416 1.417 -(defn get-cursor [script] 1.418 - (wait-until (partial set-cursor-relative 1) script)) 1.419 - 1.420 (defn-memo launch-bootstrap-program 1.421 ([] (launch-bootstrap-program 1.422 (go-to-mansion-for-the-lulz))) 1.423 ([script] 1.424 (->> script 1.425 ;; must corrupt item list again by switching pokemon 1.426 - activate-start-menu 1.427 - ;;get-cursor 1.428 - (set-cursor 0) 1.429 - select-menu-entry 1.430 - ;;get-cursor 1.431 - (select-menu-entry) 1.432 - ;;get-cursor 1.433 - (set-cursor 1) 1.434 - (select-menu-entry) 1.435 - ;;get-cursor 1.436 - (set-cursor 3) 1.437 - (delayed-difference [] [:a] 50 first-character) 1.438 - close-menu 1.439 - ;; now, open items and set map-function 1.440 - ;;get-cursor 1.441 + activate-start-menu ;; \ 1.442 + (set-cursor 0) ;; | 1.443 + select-menu-entry ;; | 1.444 + select-menu-entry ;; | 1.445 + (set-cursor 1) ;; | -- switch 9th pokemon 1.446 + select-menu-entry ;; | with 4th pokemon 1.447 + (set-cursor 3) ;; | 1.448 + select-menu-entry ;; | 1.449 + close-menu ;; / 1.450 + ;; now, open items and set map-function to 1.451 + ;; the program inside the item-computer. 1.452 (set-cursor 1) 1.453 (select-menu-entry) 1.454 (toss-held-item 22 12) 1.455 (switch-held-items 22 40) 1.456 close-all-menus))) 1.457 - 1.458 - 1.459 - 1.460 - 1.461 \ No newline at end of file 1.462 + 1.463 +(defn no-consecutive-repeats? [seq] 1.464 + (not (contains? (set(map - seq (rest seq))) 0))) 1.465 + 1.466 +(defn byte->nybbles [byte] 1.467 + [(bit-shift-right byte 4) (bit-and byte 0x0F)]) 1.468 + 1.469 +(defn bootstrap-pattern 1.470 + "Given an assembly sequence, generate the keypresses required to 1.471 + create that sequence in memory using the pc-item-writer 1.472 + program. The assembly must not have any consecutive repeating 1.473 + nybbles." 1.474 + [assembly] 1.475 + (let [nybbles (flatten (map byte->nybbles assembly)) 1.476 + moves (map (comp buttons (partial - 15)) nybbles) 1.477 + header (map buttons 1.478 + (concat (repeat 1.479 + 50 1.480 + (- 15 (first nybbles))) 1.481 + [(first nybbles)])) 1.482 + tail (map buttons 1.483 + (take 1.484 + (- 201 (count moves)) 1.485 + (interleave (repeat 100 (last nybbles)) 1.486 + (repeat 1000 (- 15 (last nybbles))))))] 1.487 + (assert (no-consecutive-repeats? nybbles)) 1.488 + (concat header moves tail))) 1.489 + 1.490 +(def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF]) 1.491 + 1.492 +(defn test-pattern-writing 1.493 + ([] (test-pattern-writing increasing-pattern)) 1.494 + ([pattern] 1.495 + (let [moves (bootstrap-pattern pattern) 1.496 + pattern-insertion 1.497 + (->> (launch-bootstrap-program) 1.498 + (play-moves 1.499 + (take 100 moves)))] 1.500 + (println "Input Pattern:") 1.501 + (apply println (map #(format "0x%02X" %) pattern)) 1.502 + (println "\nMemory Listing:") 1.503 + (print-listing (second pattern-insertion) 1.504 + 0xD162 (+ 0xD162 (count pattern))) 1.505 + (= (subvec (vec (memory (second pattern-insertion))) 1.506 + 0xD162 (+ 0xD162 (count pattern))) 1.507 + pattern)))) 1.508 + 1.509 + 1.510 + 1.511 \ No newline at end of file