changeset 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 143a2dfb3177
files clojure/com/aurellem/run/bootstrap_0.clj clojure/com/aurellem/run/bootstrap_1.clj moves/temp.vbm
diffstat 3 files changed, 178 insertions(+), 147 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/bootstrap_0.clj	Tue Apr 10 03:32:47 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/bootstrap_0.clj	Tue Apr 10 06:33:44 2012 -0500
     1.3 @@ -411,6 +411,9 @@
     1.4  (defn first-character [state]
     1.5    (aget (memory state) text-address))
     1.6  
     1.7 +(defn first-20-characters [state]
     1.8 +  (subvec (vec (memory state)) text-address (+ 20 text-address)))
     1.9 +
    1.10  (defn set-quantity*
    1.11    "Set the quantity of an item to buy or sell to the desired value
    1.12    using the fewest possible button presses."
    1.13 @@ -442,9 +445,9 @@
    1.14  
    1.15  (defn set-quantity
    1.16    ([total-quantity desired-quantity [moves state :as script]]
    1.17 -     (->> script (wait-until (partial first-difference [] [:a]
    1.18 -                                      first-character))
    1.19 -          (set-quantity* total-quantity desired-quantity script)))
    1.20 +     (->> script (wait-until (partial delayed-difference [] [:a] 100
    1.21 +                                      first-20-characters))
    1.22 +          (set-quantity* total-quantity desired-quantity)))
    1.23    ([desired-quantity [moves state :as script]]
    1.24       (set-quantity 99 desired-quantity script)))
    1.25  
     2.1 --- a/clojure/com/aurellem/run/bootstrap_1.clj	Tue Apr 10 03:32:47 2012 -0500
     2.2 +++ b/clojure/com/aurellem/run/bootstrap_1.clj	Tue Apr 10 06:33:44 2012 -0500
     2.3 @@ -108,7 +108,7 @@
     2.4         0x01  ;; (item-hack) will never reach this instruction
     2.5  
     2.6         ]
     2.7 -      (repeat 8 [0x00 0x02]);; these can be anything
     2.8 +      (repeat 8 [0x00 0x01]);; these can be anything
     2.9  
    2.10        [;; jump to actual program
    2.11         0x00
    2.12 @@ -182,38 +182,20 @@
    2.13            finish-title
    2.14            (walk [← ← ↑ ← ↑ ↑ ↑]))))
    2.15  
    2.16 -(defn-memo bootstrap-corrupt-save
    2.17 -  ([] (bootstrap-corrupt-save (to-room-pc)))
    2.18 -  ([script]
    2.19 -   (->> script
    2.20 -        (do-save-corruption 2)
    2.21 -        (corrupt-item-list 0)
    2.22 -        close-all-menus)))
    2.23 -
    2.24 -(defn-memo begin-initial-deposits
    2.25 -  ([] (begin-initial-deposits
    2.26 -       (bootstrap-corrupt-save)))
    2.27 -  ([script]
    2.28 -     (->> script
    2.29 -          (first-difference [] [:a] AF)
    2.30 -          (scroll-text)
    2.31 -          (set-cursor 1)
    2.32 -          select-menu-entry)))
    2.33 -
    2.34 -(defn wait-for-quantity
    2.35 -  [[moves state :as script]]
    2.36 -  (if (not= (item-quantity-selected state) 1)
    2.37 -    (repeat-until-different [] item-quantity-selected script)
    2.38 -    script))
    2.39 +;; (defn wait-for-quantity
    2.40 +;;   [[moves state :as script]]
    2.41 +;;   (if (not= (item-quantity-selected state) 1)
    2.42 +;;     (repeat-until-different [] item-quantity-selected script)
    2.43 +;;     script))
    2.44  
    2.45  ;; TODO use this:
    2.46  ;;(wait-until (partial set-cursor-relative 1))
    2.47  
    2.48 -(defn wait-for-cursor
    2.49 -  [[moves state :as script]]
    2.50 -  (if (not= (list-offset state) 0)
    2.51 -    (repeat-until-different [] list-offset script)
    2.52 -    script))
    2.53 +;; (defn wait-for-cursor
    2.54 +;;   [[moves state :as script]]
    2.55 +;;   (if (not= (list-offset state) 0)
    2.56 +;;     (repeat-until-different [] list-offset script)
    2.57 +;;     script))
    2.58  
    2.59  (defn deposit-held-item [n quantity [moves state :as script]]
    2.60    (let [total-quantity (second (nth-item state n))]
    2.61 @@ -221,7 +203,7 @@
    2.62      (->> script
    2.63           (set-cursor n)
    2.64           (select-menu-entry 1)
    2.65 -         (wait-for-quantity)
    2.66 +         ;;(wait-for-quantity)
    2.67           (set-quantity total-quantity quantity)
    2.68           (delayed-difference [] [:a] 100 #(search-string % "stored"))
    2.69           (scroll-text))))
    2.70 @@ -229,10 +211,10 @@
    2.71  (defn sell-held-item [n quantity [moves state :as script]]
    2.72    (let [total-quantity (second (nth-item state n))]
    2.73      (->> script
    2.74 -         (wait-for-cursor)  ;; when selling, the cursor always
    2.75 +         ;;(wait-for-cursor)  ;; when selling, the cursor always
    2.76           (set-cursor n)     ;; returns to the top of the list.
    2.77           (select-menu-entry 1)
    2.78 -         (wait-for-quantity)
    2.79 +         ;;(wait-for-quantity)
    2.80           (set-quantity total-quantity quantity)
    2.81           (delayed-difference [] [:a] 100 current-depth)
    2.82           (play-moves (repeat 20 [:b]))
    2.83 @@ -244,7 +226,7 @@
    2.84      (->> script
    2.85           (set-cursor n)
    2.86           (select-menu-entry 1)
    2.87 -         (wait-for-quantity)
    2.88 +         ;;(wait-for-quantity)
    2.89           (set-quantity total-quantity quantity)
    2.90           (delayed-difference [] [:a] 100 #(search-string % "Withdrew"))
    2.91           (scroll-text))))
    2.92 @@ -256,7 +238,7 @@
    2.93           (select-menu-entry 1)
    2.94           (set-cursor-relative 1)
    2.95           (select-menu-entry -1)
    2.96 -         (wait-for-quantity)
    2.97 +         ;;(wait-for-quantity)
    2.98           (set-quantity total-quantity quantity)
    2.99           (play-moves [[:a]])
   2.100           (scroll-text)
   2.101 @@ -269,11 +251,57 @@
   2.102         (set-cursor n)
   2.103         (purchase-item quantity)))
   2.104  
   2.105 +(defn switch-items [item-fn idx-1 idx-2 script]
   2.106 +  (->> script
   2.107 +       (wait-until select-menu-entry)
   2.108 +       (set-cursor idx-1)
   2.109 +       (wait-until select-menu-entry)
   2.110 +       (play-moves [[][:select][]])
   2.111 +       (set-cursor idx-2)
   2.112 +       (delayed-difference [] [:select] 100
   2.113 +                           #(item-fn % (list-offset %)))))
   2.114 +
   2.115 +(def switch-pc-items (partial switch-items nth-pc-item))
   2.116 +(def switch-held-items (partial switch-items nth-item))
   2.117 +
   2.118 +(defn combine-pc-items [idx-1 script]
   2.119 +  (->> script
   2.120 +       (switch-pc-items idx-1 (inc idx-1))))
   2.121  
   2.122  (def desired-zero-quantities
   2.123    (map second (filter (comp (partial = 0) first)
   2.124                        (partition 2 (pc-item-writer-program)))))
   2.125 -  
   2.126 +
   2.127 +(defn-memo bootstrap-corrupt-save
   2.128 +  ([] (bootstrap-corrupt-save (to-room-pc)))
   2.129 +  ([script]
   2.130 +   (->> script
   2.131 +        (do-save-corruption 3)
   2.132 +        (corrupt-item-list 0)
   2.133 +        close-all-menus)))
   2.134 +
   2.135 +(defn-memo prepare-celadon-warp
   2.136 +  ([] (prepare-celadon-warp (bootstrap-corrupt-save)))
   2.137 +  ([script]
   2.138 +     (->> script
   2.139 +          (activate-start-menu)
   2.140 +          (set-cursor-relative 1)
   2.141 +          (select-menu-entry)
   2.142 +          ;; vastly increase text speed while we're here.
   2.143 +          (switch-held-items 21 27)
   2.144 +          (toss-held-item 35 0xFA)
   2.145 +          (close-all-menus))))
   2.146 +
   2.147 +(defn-memo begin-initial-deposits
   2.148 +  ([] (begin-initial-deposits
   2.149 +       (prepare-celadon-warp)))
   2.150 +  ([script]
   2.151 +     (->> script
   2.152 +          (first-difference [] [:a] AF)
   2.153 +          (scroll-text)
   2.154 +          (set-cursor 1)
   2.155 +          select-menu-entry)))
   2.156 +
   2.157  (defn-memo initial-deposits
   2.158    ([] (initial-deposits (begin-initial-deposits)))
   2.159    ([script]
   2.160 @@ -287,28 +315,23 @@
   2.161            close-all-menus)))
   2.162  
   2.163  
   2.164 -(defn-memo prepare-celadon-warp
   2.165 -  ([] (prepare-celadon-warp (initial-deposits)))
   2.166 -  ([script]
   2.167 -     (->> script
   2.168 -          (activate-start-menu)
   2.169 -          (set-cursor-relative 1)
   2.170 -          (select-menu-entry)
   2.171 -          (toss-held-item 35 0xFA)
   2.172 -          (close-all-menus))))
   2.173 -
   2.174 -
   2.175  ;;0 -- 256
   2.176  ;;1 -- 254
   2.177  ;;2 -- 254
   2.178  ;;3 -- 255
   2.179  
   2.180 +(defn activate-home-pc
   2.181 +  [script]
   2.182 +  (->> script
   2.183 +       (delayed-difference [] [:a]
   2.184 +                           200 first-character)
   2.185 +       (scroll-text)))
   2.186 +
   2.187  (defn-memo restore-items
   2.188 -  ([] (restore-items (prepare-celadon-warp)))
   2.189 +  ([] (restore-items (initial-deposits)))
   2.190    ([script]
   2.191       (->> script
   2.192 -          (first-difference [] [:a] AF)
   2.193 -          (scroll-text)
   2.194 +          activate-home-pc
   2.195            (select-menu-entry)
   2.196            (widthdraw-pc-item 0 1)
   2.197            ;;(widthdraw-pc-item 0 99)
   2.198 @@ -404,7 +427,7 @@
   2.199    ([] (floor-two-TMs (get-money-floor-two)))
   2.200    ([script]
   2.201       (->> script
   2.202 -          (wait-for-cursor)
   2.203 +          (set-cursor 0)
   2.204            (select-menu-entry)
   2.205            (buy-item 2 98)  ;; TM02 (razor-wind)
   2.206            (buy-item 4 71)  ;; TM37 (doubleteam)
   2.207 @@ -424,7 +447,6 @@
   2.208    ([] (floor-two-more-money (floor-two-TMs)))
   2.209    ([script]
   2.210       (->> script
   2.211 -          (wait-for-cursor)
   2.212            (set-cursor 1)
   2.213            (select-menu-entry)
   2.214            (sell-held-item 0 1)
   2.215 @@ -527,7 +549,6 @@
   2.216         (do-nothing 20)
   2.217         (play-moves [[:a][:a]])
   2.218         scroll-text
   2.219 -       (wait-for-cursor)
   2.220         (set-cursor n)
   2.221         select-menu-entry
   2.222         close-menu))
   2.223 @@ -545,8 +566,9 @@
   2.224    ([] (get-TM13 (roof-drinks)))
   2.225    ([script]
   2.226       (->> script
   2.227 -          (walk [← ← ← ← ← ← ↓])
   2.228 -          (play-moves [[][:a][:a][]])
   2.229 +          ;;(walk [← ← ← ← ← ← ↓])
   2.230 +          (walk [↓ ↓ ↓ ← ← ← ← ← ←])
   2.231 +          (play-moves [[][][][][:a][:a][]])
   2.232            (scroll-text 3)
   2.233            select-menu-entry
   2.234            select-menu-entry
   2.235 @@ -557,7 +579,8 @@
   2.236    ([] (to-celadon-poke-center (get-TM13)))
   2.237    ([script]
   2.238       (->> script
   2.239 -          (walk [↑ → → → → → → → → → ↑])       ; leave roof
   2.240 +          ;;(walk [↑ → → → → → → → → → ↑])       ; leave roof
   2.241 +          (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])
   2.242            (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ← 
   2.243                   ↑ ↑ ↑ ← ← ↑])                 ; to elevator
   2.244                   
   2.245 @@ -576,7 +599,7 @@
   2.246    (->> script
   2.247         talk
   2.248         scroll-text
   2.249 -       wait-for-cursor
   2.250 +       ;;wait-for-cursor
   2.251         (set-cursor 1)
   2.252         select-menu-entry
   2.253         (scroll-text 2)))
   2.254 @@ -602,9 +625,34 @@
   2.255      (println "index" index)
   2.256      (deposit-held-item index quantity script)))
   2.257  
   2.258 +(defn open-held-items
   2.259 +  [script]
   2.260 +  (->> script
   2.261 +       select-menu-entry))
   2.262  
   2.263 -(defn-memo begin-hacking
   2.264 -  ([] (begin-hacking(to-celadon-poke-center)))
   2.265 +(defn to-held-items
   2.266 +  [script]
   2.267 +  (->> script
   2.268 +       close-menu
   2.269 +       close-menu
   2.270 +       end-text;;; grr
   2.271 +       
   2.272 +       activate-start-menu
   2.273 +       open-held-items))
   2.274 +
   2.275 +(defn toss-pc-item [n quantity  [moves state :as script]]
   2.276 +  (let [total-quantity (second (nth-pc-item state n))]
   2.277 +    (->> script
   2.278 +         (set-cursor n)
   2.279 +         (select-menu-entry 1)
   2.280 +         (set-quantity total-quantity quantity)
   2.281 +         (delayed-difference [] [:a] 100 #(search-string % "Is"))
   2.282 +         (scroll-text)
   2.283 +         select-menu-entry
   2.284 +         (scroll-text))))
   2.285 +
   2.286 +(defn-memo hacking-1
   2.287 +  ([] (hacking-1 (to-celadon-poke-center)))
   2.288    ([script]
   2.289       (->> script
   2.290            activate-rlm-pc
   2.291 @@ -616,23 +664,8 @@
   2.292            (deposit-held-item-named :TM09          55)
   2.293            (deposit-held-item-named 0x00           55))))
   2.294  
   2.295 -(defn open-held-items
   2.296 -  [script]
   2.297 -  (->> script
   2.298 -       select-menu-entry))
   2.299 -
   2.300 -(defn to-held-items
   2.301 -  [script]
   2.302 -  (->> script
   2.303 -       close-menu
   2.304 -       close-menu
   2.305 -       end-text;;; grr
   2.306 -       
   2.307 -       activate-start-menu
   2.308 -       open-held-items))
   2.309 -
   2.310  (defn-memo hacking-2
   2.311 -  ([] (hacking-2 (begin-hacking)))
   2.312 +  ([] (hacking-2 (hacking-1)))
   2.313    ([script]
   2.314       (->> script
   2.315            (to-held-items)
   2.316 @@ -697,34 +730,8 @@
   2.317            (deposit-held-item-named :ice-heal 55)
   2.318            (deposit-held-item-named :fire-stone 23)
   2.319            (deposit-held-item-named :burn-heal 12)
   2.320 -          close-menu)))
   2.321 -
   2.322 -(defn switch-items [item-fn idx-1 idx-2 script]
   2.323 -  (->> script
   2.324 -       (wait-until select-menu-entry)
   2.325 -       (set-cursor idx-1)
   2.326 -       (wait-until select-menu-entry)
   2.327 -       (play-moves [[][:select][]])
   2.328 -       (set-cursor idx-2)
   2.329 -       (delayed-difference [] [:select] 100
   2.330 -                           #(item-fn % (list-offset %)))))
   2.331 -
   2.332 -(def switch-pc-items (partial switch-items nth-pc-item))
   2.333 -(def switch-held-items (partial switch-items nth-item))
   2.334 -
   2.335 -(defn combine-pc-items [idx-1 script]
   2.336 -  (->> script
   2.337 -       (switch-pc-items idx-1 (inc idx-1))))
   2.338 -
   2.339 -(defn combine-items [idx-1 script]
   2.340 -  (->> script
   2.341 -       (wait-until select-menu-entry)
   2.342 -       (set-cursor idx-1)
   2.343 -       (wait-until select-menu-entry)
   2.344 -       (play-moves [[][:select][]])
   2.345 -       (set-cursor-relative 1)
   2.346 -       (delayed-difference [] [:select] 100
   2.347 -                           #(nth-pc-item % (list-offset %)))))
   2.348 +          ;; as a special case, /don't/ close the menu.
   2.349 +          )))
   2.350  
   2.351  (defn-memo hacking-8
   2.352    "Clear cruft away from held item list."
   2.353 @@ -769,7 +776,6 @@
   2.354            (deposit-held-item 13 191)
   2.355            (deposit-held-item-named :TM02 98)
   2.356            (deposit-held-item-named :TM09 1)
   2.357 -          close-menu
   2.358            close-menu)))
   2.359  
   2.360  (defn-memo hacking-11
   2.361 @@ -785,7 +791,7 @@
   2.362            (widthdraw-pc-item 5 0xFB)
   2.363            (multiple-times
   2.364             3
   2.365 -           (partial combine-items 2))
   2.366 +           (partial combine-pc-items 2))
   2.367            close-menu)))
   2.368  
   2.369  (defn-memo hacking-12
   2.370 @@ -799,28 +805,14 @@
   2.371            (deposit-held-item-named :TM05 1)
   2.372            (multiple-times
   2.373             8
   2.374 -           (partial deposit-held-item 14 2))
   2.375 +           (partial deposit-held-item 14 1))
   2.376            (deposit-held-item 14 55)
   2.377            (deposit-held-item-named :x-accuracy 58)
   2.378            (deposit-held-item 14 38)
   2.379            (deposit-held-item-named :TM13 1)
   2.380            (deposit-held-item 13 1)
   2.381            (deposit-held-item 13 233)
   2.382 -          close-menu
   2.383            close-menu)))
   2.384 -
   2.385 -
   2.386 -(defn toss-pc-item [n quantity  [moves state :as script]]
   2.387 -  (let [total-quantity (second (nth-pc-item state n))]
   2.388 -    (->> script
   2.389 -         (set-cursor n)
   2.390 -         (select-menu-entry 1)
   2.391 -         (wait-for-quantity)
   2.392 -         (set-quantity total-quantity quantity)
   2.393 -         (delayed-difference [] [:a] 100 #(search-string % "Is"))
   2.394 -         (scroll-text)
   2.395 -         select-menu-entry
   2.396 -         (scroll-text))))
   2.397         
   2.398  (defn-memo hacking-13
   2.399    ([] (hacking-13 (hacking-12)))
   2.400 @@ -843,9 +835,6 @@
   2.401      (println actual-pattern)
   2.402      (= target-pattern actual-pattern)))
   2.403  
   2.404 -;; this will be useful for starting program
   2.405 -
   2.406 -
   2.407  (defn-memo go-to-mansion-for-the-lulz
   2.408    ([] (go-to-mansion-for-the-lulz (hacking-13)))
   2.409    ([script]
   2.410 @@ -861,38 +850,77 @@
   2.411                   ← ← ← ← ↑ ↑ ↑ ← ↑])
   2.412            (talk)
   2.413            (scroll-text 2)
   2.414 +          (do-nothing 100)
   2.415            close-menu)))
   2.416  
   2.417 -(defn get-cursor [script]
   2.418 -  (wait-until (partial set-cursor-relative 1) script))
   2.419 -
   2.420  (defn-memo launch-bootstrap-program
   2.421    ([] (launch-bootstrap-program
   2.422         (go-to-mansion-for-the-lulz)))
   2.423    ([script]
   2.424       (->> script
   2.425            ;; must corrupt item list again by switching pokemon
   2.426 -          activate-start-menu
   2.427 -          ;;get-cursor
   2.428 -          (set-cursor 0)
   2.429 -          select-menu-entry
   2.430 -          ;;get-cursor
   2.431 -          (select-menu-entry)
   2.432 -          ;;get-cursor
   2.433 -          (set-cursor 1)
   2.434 -          (select-menu-entry)
   2.435 -          ;;get-cursor
   2.436 -          (set-cursor 3)
   2.437 -          (delayed-difference [] [:a] 50 first-character)
   2.438 -          close-menu
   2.439 -          ;; now, open items and set map-function
   2.440 -          ;;get-cursor
   2.441 +          activate-start-menu    ;; \
   2.442 +          (set-cursor 0)         ;; |
   2.443 +          select-menu-entry      ;; |
   2.444 +          select-menu-entry      ;; |
   2.445 +          (set-cursor 1)         ;; | -- switch 9th pokemon
   2.446 +          select-menu-entry      ;; |    with 4th pokemon
   2.447 +          (set-cursor 3)         ;; |
   2.448 +          select-menu-entry      ;; |
   2.449 +          close-menu             ;; /
   2.450 +          ;; now, open items and set map-function to
   2.451 +          ;; the program inside the item-computer.
   2.452            (set-cursor 1)
   2.453            (select-menu-entry)
   2.454            (toss-held-item 22 12)
   2.455            (switch-held-items 22 40)
   2.456            close-all-menus)))
   2.457 -          
   2.458 -          
   2.459 -          
   2.460 -     
   2.461 \ No newline at end of file
   2.462 +
   2.463 +(defn no-consecutive-repeats? [seq]
   2.464 +  (not (contains? (set(map - seq (rest seq))) 0)))
   2.465 +
   2.466 +(defn byte->nybbles [byte]
   2.467 +  [(bit-shift-right byte 4) (bit-and byte 0x0F)])
   2.468 +
   2.469 +(defn bootstrap-pattern
   2.470 +  "Given an assembly sequence, generate the keypresses required to
   2.471 +   create that sequence in memory using the pc-item-writer
   2.472 +   program. The assembly must not have any consecutive repeating
   2.473 +   nybbles."
   2.474 +  [assembly]
   2.475 +  (let [nybbles (flatten (map byte->nybbles assembly))
   2.476 +        moves (map (comp buttons (partial - 15)) nybbles)
   2.477 +        header (map buttons
   2.478 +                    (concat (repeat
   2.479 +                             50
   2.480 +                             (- 15 (first nybbles)))
   2.481 +                            [(first nybbles)]))
   2.482 +        tail (map buttons
   2.483 +                  (take
   2.484 +                   (- 201 (count moves))
   2.485 +                   (interleave (repeat 100 (last nybbles))
   2.486 +                               (repeat 1000 (- 15 (last nybbles))))))]
   2.487 +    (assert (no-consecutive-repeats? nybbles))
   2.488 +    (concat header moves tail)))
   2.489 +
   2.490 +(def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])
   2.491 +
   2.492 +(defn test-pattern-writing
   2.493 +  ([] (test-pattern-writing increasing-pattern))
   2.494 +  ([pattern]
   2.495 +     (let [moves (bootstrap-pattern pattern)
   2.496 +           pattern-insertion
   2.497 +           (->> (launch-bootstrap-program)
   2.498 +                (play-moves
   2.499 +                 (take 100 moves)))]
   2.500 +       (println "Input Pattern:")
   2.501 +       (apply println  (map #(format "0x%02X" %) pattern))
   2.502 +       (println "\nMemory Listing:")
   2.503 +       (print-listing (second pattern-insertion)
   2.504 +                      0xD162 (+ 0xD162 (count pattern)))
   2.505 +       (= (subvec (vec (memory (second pattern-insertion)))
   2.506 +                       0xD162 (+ 0xD162 (count pattern)))
   2.507 +          pattern))))
   2.508 +
   2.509 +
   2.510 +  
   2.511 \ No newline at end of file
     3.1 Binary file moves/temp.vbm has changed