# HG changeset patch # User Robert McIntyre # Date 1334057624 18000 # Node ID abcc522a3242735d84ffde8724f7d617bc8cd3c3 # Parent 08f8284e2f1ba057d044340e7c09974b248fc304 script: wrote memory pattern from within game! diff -r 08f8284e2f1b -r abcc522a3242 clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Tue Apr 10 03:32:47 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Tue Apr 10 06:33:44 2012 -0500 @@ -411,6 +411,9 @@ (defn first-character [state] (aget (memory state) text-address)) +(defn first-20-characters [state] + (subvec (vec (memory state)) text-address (+ 20 text-address))) + (defn set-quantity* "Set the quantity of an item to buy or sell to the desired value using the fewest possible button presses." @@ -442,9 +445,9 @@ (defn set-quantity ([total-quantity desired-quantity [moves state :as script]] - (->> script (wait-until (partial first-difference [] [:a] - first-character)) - (set-quantity* total-quantity desired-quantity script))) + (->> script (wait-until (partial delayed-difference [] [:a] 100 + first-20-characters)) + (set-quantity* total-quantity desired-quantity))) ([desired-quantity [moves state :as script]] (set-quantity 99 desired-quantity script))) diff -r 08f8284e2f1b -r abcc522a3242 clojure/com/aurellem/run/bootstrap_1.clj --- a/clojure/com/aurellem/run/bootstrap_1.clj Tue Apr 10 03:32:47 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_1.clj Tue Apr 10 06:33:44 2012 -0500 @@ -108,7 +108,7 @@ 0x01 ;; (item-hack) will never reach this instruction ] - (repeat 8 [0x00 0x02]);; these can be anything + (repeat 8 [0x00 0x01]);; these can be anything [;; jump to actual program 0x00 @@ -182,38 +182,20 @@ finish-title (walk [← ← ↑ ← ↑ ↑ ↑])))) -(defn-memo bootstrap-corrupt-save - ([] (bootstrap-corrupt-save (to-room-pc))) - ([script] - (->> script - (do-save-corruption 2) - (corrupt-item-list 0) - close-all-menus))) - -(defn-memo begin-initial-deposits - ([] (begin-initial-deposits - (bootstrap-corrupt-save))) - ([script] - (->> script - (first-difference [] [:a] AF) - (scroll-text) - (set-cursor 1) - select-menu-entry))) - -(defn wait-for-quantity - [[moves state :as script]] - (if (not= (item-quantity-selected state) 1) - (repeat-until-different [] item-quantity-selected script) - script)) +;; (defn wait-for-quantity +;; [[moves state :as script]] +;; (if (not= (item-quantity-selected state) 1) +;; (repeat-until-different [] item-quantity-selected script) +;; script)) ;; TODO use this: ;;(wait-until (partial set-cursor-relative 1)) -(defn wait-for-cursor - [[moves state :as script]] - (if (not= (list-offset state) 0) - (repeat-until-different [] list-offset script) - script)) +;; (defn wait-for-cursor +;; [[moves state :as script]] +;; (if (not= (list-offset state) 0) +;; (repeat-until-different [] list-offset script) +;; script)) (defn deposit-held-item [n quantity [moves state :as script]] (let [total-quantity (second (nth-item state n))] @@ -221,7 +203,7 @@ (->> script (set-cursor n) (select-menu-entry 1) - (wait-for-quantity) + ;;(wait-for-quantity) (set-quantity total-quantity quantity) (delayed-difference [] [:a] 100 #(search-string % "stored")) (scroll-text)))) @@ -229,10 +211,10 @@ (defn sell-held-item [n quantity [moves state :as script]] (let [total-quantity (second (nth-item state n))] (->> script - (wait-for-cursor) ;; when selling, the cursor always + ;;(wait-for-cursor) ;; when selling, the cursor always (set-cursor n) ;; returns to the top of the list. (select-menu-entry 1) - (wait-for-quantity) + ;;(wait-for-quantity) (set-quantity total-quantity quantity) (delayed-difference [] [:a] 100 current-depth) (play-moves (repeat 20 [:b])) @@ -244,7 +226,7 @@ (->> script (set-cursor n) (select-menu-entry 1) - (wait-for-quantity) + ;;(wait-for-quantity) (set-quantity total-quantity quantity) (delayed-difference [] [:a] 100 #(search-string % "Withdrew")) (scroll-text)))) @@ -256,7 +238,7 @@ (select-menu-entry 1) (set-cursor-relative 1) (select-menu-entry -1) - (wait-for-quantity) + ;;(wait-for-quantity) (set-quantity total-quantity quantity) (play-moves [[:a]]) (scroll-text) @@ -269,11 +251,57 @@ (set-cursor n) (purchase-item quantity))) +(defn switch-items [item-fn idx-1 idx-2 script] + (->> script + (wait-until select-menu-entry) + (set-cursor idx-1) + (wait-until select-menu-entry) + (play-moves [[][:select][]]) + (set-cursor idx-2) + (delayed-difference [] [:select] 100 + #(item-fn % (list-offset %))))) + +(def switch-pc-items (partial switch-items nth-pc-item)) +(def switch-held-items (partial switch-items nth-item)) + +(defn combine-pc-items [idx-1 script] + (->> script + (switch-pc-items idx-1 (inc idx-1)))) (def desired-zero-quantities (map second (filter (comp (partial = 0) first) (partition 2 (pc-item-writer-program))))) - + +(defn-memo bootstrap-corrupt-save + ([] (bootstrap-corrupt-save (to-room-pc))) + ([script] + (->> script + (do-save-corruption 3) + (corrupt-item-list 0) + close-all-menus))) + +(defn-memo prepare-celadon-warp + ([] (prepare-celadon-warp (bootstrap-corrupt-save))) + ([script] + (->> script + (activate-start-menu) + (set-cursor-relative 1) + (select-menu-entry) + ;; vastly increase text speed while we're here. + (switch-held-items 21 27) + (toss-held-item 35 0xFA) + (close-all-menus)))) + +(defn-memo begin-initial-deposits + ([] (begin-initial-deposits + (prepare-celadon-warp))) + ([script] + (->> script + (first-difference [] [:a] AF) + (scroll-text) + (set-cursor 1) + select-menu-entry))) + (defn-memo initial-deposits ([] (initial-deposits (begin-initial-deposits))) ([script] @@ -287,28 +315,23 @@ close-all-menus))) -(defn-memo prepare-celadon-warp - ([] (prepare-celadon-warp (initial-deposits))) - ([script] - (->> script - (activate-start-menu) - (set-cursor-relative 1) - (select-menu-entry) - (toss-held-item 35 0xFA) - (close-all-menus)))) - - ;;0 -- 256 ;;1 -- 254 ;;2 -- 254 ;;3 -- 255 +(defn activate-home-pc + [script] + (->> script + (delayed-difference [] [:a] + 200 first-character) + (scroll-text))) + (defn-memo restore-items - ([] (restore-items (prepare-celadon-warp))) + ([] (restore-items (initial-deposits))) ([script] (->> script - (first-difference [] [:a] AF) - (scroll-text) + activate-home-pc (select-menu-entry) (widthdraw-pc-item 0 1) ;;(widthdraw-pc-item 0 99) @@ -404,7 +427,7 @@ ([] (floor-two-TMs (get-money-floor-two))) ([script] (->> script - (wait-for-cursor) + (set-cursor 0) (select-menu-entry) (buy-item 2 98) ;; TM02 (razor-wind) (buy-item 4 71) ;; TM37 (doubleteam) @@ -424,7 +447,6 @@ ([] (floor-two-more-money (floor-two-TMs))) ([script] (->> script - (wait-for-cursor) (set-cursor 1) (select-menu-entry) (sell-held-item 0 1) @@ -527,7 +549,6 @@ (do-nothing 20) (play-moves [[:a][:a]]) scroll-text - (wait-for-cursor) (set-cursor n) select-menu-entry close-menu)) @@ -545,8 +566,9 @@ ([] (get-TM13 (roof-drinks))) ([script] (->> script - (walk [← ← ← ← ← ← ↓]) - (play-moves [[][:a][:a][]]) + ;;(walk [← ← ← ← ← ← ↓]) + (walk [↓ ↓ ↓ ← ← ← ← ← ←]) + (play-moves [[][][][][:a][:a][]]) (scroll-text 3) select-menu-entry select-menu-entry @@ -557,7 +579,8 @@ ([] (to-celadon-poke-center (get-TM13))) ([script] (->> script - (walk [↑ → → → → → → → → → ↑]) ; leave roof + ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof + (walk [→ → → → → → → → → ↑ ↑ ↑ ↑]) (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ← ↑ ↑ ↑ ← ← ↑]) ; to elevator @@ -576,7 +599,7 @@ (->> script talk scroll-text - wait-for-cursor + ;;wait-for-cursor (set-cursor 1) select-menu-entry (scroll-text 2))) @@ -602,9 +625,34 @@ (println "index" index) (deposit-held-item index quantity script))) +(defn open-held-items + [script] + (->> script + select-menu-entry)) -(defn-memo begin-hacking - ([] (begin-hacking(to-celadon-poke-center))) +(defn to-held-items + [script] + (->> script + close-menu + close-menu + end-text;;; grr + + activate-start-menu + open-held-items)) + +(defn toss-pc-item [n quantity [moves state :as script]] + (let [total-quantity (second (nth-pc-item state n))] + (->> script + (set-cursor n) + (select-menu-entry 1) + (set-quantity total-quantity quantity) + (delayed-difference [] [:a] 100 #(search-string % "Is")) + (scroll-text) + select-menu-entry + (scroll-text)))) + +(defn-memo hacking-1 + ([] (hacking-1 (to-celadon-poke-center))) ([script] (->> script activate-rlm-pc @@ -616,23 +664,8 @@ (deposit-held-item-named :TM09 55) (deposit-held-item-named 0x00 55)))) -(defn open-held-items - [script] - (->> script - select-menu-entry)) - -(defn to-held-items - [script] - (->> script - close-menu - close-menu - end-text;;; grr - - activate-start-menu - open-held-items)) - (defn-memo hacking-2 - ([] (hacking-2 (begin-hacking))) + ([] (hacking-2 (hacking-1))) ([script] (->> script (to-held-items) @@ -697,34 +730,8 @@ (deposit-held-item-named :ice-heal 55) (deposit-held-item-named :fire-stone 23) (deposit-held-item-named :burn-heal 12) - close-menu))) - -(defn switch-items [item-fn idx-1 idx-2 script] - (->> script - (wait-until select-menu-entry) - (set-cursor idx-1) - (wait-until select-menu-entry) - (play-moves [[][:select][]]) - (set-cursor idx-2) - (delayed-difference [] [:select] 100 - #(item-fn % (list-offset %))))) - -(def switch-pc-items (partial switch-items nth-pc-item)) -(def switch-held-items (partial switch-items nth-item)) - -(defn combine-pc-items [idx-1 script] - (->> script - (switch-pc-items idx-1 (inc idx-1)))) - -(defn combine-items [idx-1 script] - (->> script - (wait-until select-menu-entry) - (set-cursor idx-1) - (wait-until select-menu-entry) - (play-moves [[][:select][]]) - (set-cursor-relative 1) - (delayed-difference [] [:select] 100 - #(nth-pc-item % (list-offset %))))) + ;; as a special case, /don't/ close the menu. + ))) (defn-memo hacking-8 "Clear cruft away from held item list." @@ -769,7 +776,6 @@ (deposit-held-item 13 191) (deposit-held-item-named :TM02 98) (deposit-held-item-named :TM09 1) - close-menu close-menu))) (defn-memo hacking-11 @@ -785,7 +791,7 @@ (widthdraw-pc-item 5 0xFB) (multiple-times 3 - (partial combine-items 2)) + (partial combine-pc-items 2)) close-menu))) (defn-memo hacking-12 @@ -799,28 +805,14 @@ (deposit-held-item-named :TM05 1) (multiple-times 8 - (partial deposit-held-item 14 2)) + (partial deposit-held-item 14 1)) (deposit-held-item 14 55) (deposit-held-item-named :x-accuracy 58) (deposit-held-item 14 38) (deposit-held-item-named :TM13 1) (deposit-held-item 13 1) (deposit-held-item 13 233) - close-menu close-menu))) - - -(defn toss-pc-item [n quantity [moves state :as script]] - (let [total-quantity (second (nth-pc-item state n))] - (->> script - (set-cursor n) - (select-menu-entry 1) - (wait-for-quantity) - (set-quantity total-quantity quantity) - (delayed-difference [] [:a] 100 #(search-string % "Is")) - (scroll-text) - select-menu-entry - (scroll-text)))) (defn-memo hacking-13 ([] (hacking-13 (hacking-12))) @@ -843,9 +835,6 @@ (println actual-pattern) (= target-pattern actual-pattern))) -;; this will be useful for starting program - - (defn-memo go-to-mansion-for-the-lulz ([] (go-to-mansion-for-the-lulz (hacking-13))) ([script] @@ -861,38 +850,77 @@ ← ← ← ← ↑ ↑ ↑ ← ↑]) (talk) (scroll-text 2) + (do-nothing 100) close-menu))) -(defn get-cursor [script] - (wait-until (partial set-cursor-relative 1) script)) - (defn-memo launch-bootstrap-program ([] (launch-bootstrap-program (go-to-mansion-for-the-lulz))) ([script] (->> script ;; must corrupt item list again by switching pokemon - activate-start-menu - ;;get-cursor - (set-cursor 0) - select-menu-entry - ;;get-cursor - (select-menu-entry) - ;;get-cursor - (set-cursor 1) - (select-menu-entry) - ;;get-cursor - (set-cursor 3) - (delayed-difference [] [:a] 50 first-character) - close-menu - ;; now, open items and set map-function - ;;get-cursor + activate-start-menu ;; \ + (set-cursor 0) ;; | + select-menu-entry ;; | + select-menu-entry ;; | + (set-cursor 1) ;; | -- switch 9th pokemon + select-menu-entry ;; | with 4th pokemon + (set-cursor 3) ;; | + select-menu-entry ;; | + close-menu ;; / + ;; now, open items and set map-function to + ;; the program inside the item-computer. (set-cursor 1) (select-menu-entry) (toss-held-item 22 12) (switch-held-items 22 40) close-all-menus))) - - - - \ No newline at end of file + +(defn no-consecutive-repeats? [seq] + (not (contains? (set(map - seq (rest seq))) 0))) + +(defn byte->nybbles [byte] + [(bit-shift-right byte 4) (bit-and byte 0x0F)]) + +(defn bootstrap-pattern + "Given an assembly sequence, generate the keypresses required to + create that sequence in memory using the pc-item-writer + program. The assembly must not have any consecutive repeating + nybbles." + [assembly] + (let [nybbles (flatten (map byte->nybbles assembly)) + moves (map (comp buttons (partial - 15)) nybbles) + header (map buttons + (concat (repeat + 50 + (- 15 (first nybbles))) + [(first nybbles)])) + tail (map buttons + (take + (- 201 (count moves)) + (interleave (repeat 100 (last nybbles)) + (repeat 1000 (- 15 (last nybbles))))))] + (assert (no-consecutive-repeats? nybbles)) + (concat header moves tail))) + +(def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF]) + +(defn test-pattern-writing + ([] (test-pattern-writing increasing-pattern)) + ([pattern] + (let [moves (bootstrap-pattern pattern) + pattern-insertion + (->> (launch-bootstrap-program) + (play-moves + (take 100 moves)))] + (println "Input Pattern:") + (apply println (map #(format "0x%02X" %) pattern)) + (println "\nMemory Listing:") + (print-listing (second pattern-insertion) + 0xD162 (+ 0xD162 (count pattern))) + (= (subvec (vec (memory (second pattern-insertion))) + 0xD162 (+ 0xD162 (count pattern))) + pattern)))) + + + \ No newline at end of file diff -r 08f8284e2f1b -r abcc522a3242 moves/temp.vbm Binary file moves/temp.vbm has changed