# HG changeset patch # User Robert McIntyre # Date 1334046767 18000 # Node ID 08f8284e2f1ba057d044340e7c09974b248fc304 # Parent 845b2d88bef9eddf65ecb715bc0314b5f593c66a cleaning up code diff -r 845b2d88bef9 -r 08f8284e2f1b clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Mon Apr 09 13:21:34 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Tue Apr 10 03:32:47 2012 -0500 @@ -370,6 +370,16 @@ (aget (memory state) item-quantity-selected-address)) ([] (item-quantity-selected @current-state))) +(defn wait-until + ([script-fn default-key script] + (let [wait-time + (- (dec (count (first (script-fn script)))) + (count (first script)))] + (println "wait-time" wait-time) + (play-moves (repeat wait-time default-key) script))) + ([script-fn script] + (wait-until script-fn [] script))) + (defn set-cursor-relative "Assumes the arrow keys currently control the cursor. Moves the cursor n steps relative to its current @@ -382,21 +392,29 @@ [] key list-offset) script))) +(defn set-cursor* + [n [moves state :as script]] + (let [current-position (list-offset state) + difference (- n current-position)] + (set-cursor-relative difference script))) + (defn set-cursor "Assumes the arrow keys currently control the cursor. Sets the cursor to the desired position. Works for any menu that uses a cursor including the start menu, item menu, pokemon menu, and battle menu." [n [moves state :as script]] - (let [current-position (list-offset state) - difference (- n current-position)] - (println difference) - (set-cursor-relative difference script))) + (->> script + (wait-until (partial set-cursor-relative 1)) + (set-cursor* n))) -(defn set-quantity +(defn first-character [state] + (aget (memory state) 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." - ([total-quantity desired-quantity [moves state :as script]] + [total-quantity desired-quantity [moves state :as script]] (cond (= desired-quantity 1) (do (println "1 of 1") script) (= total-quantity desired-quantity) (do (println "get everything!") @@ -421,19 +439,19 @@ script)) script (range (Math/abs best-path)))))) + +(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))) ([desired-quantity [moves state :as script]] (set-quantity 99 desired-quantity script))) + (defn activate-start-menu [script] (first-difference [:b] [:b :start] AF script)) -(defn wait-until [script-fn script] - (let [wait-time - (- (dec (count (first (script-fn script)))) - (count (first script)))] - (println "wait-time" wait-time) - (do-nothing wait-time script))) - (defn select-menu-entry ([test-direction [moves state :as script]] (->> script diff -r 845b2d88bef9 -r 08f8284e2f1b clojure/com/aurellem/run/bootstrap_1.clj --- a/clojure/com/aurellem/run/bootstrap_1.clj Mon Apr 09 13:21:34 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_1.clj Tue Apr 10 03:32:47 2012 -0500 @@ -108,7 +108,7 @@ 0x01 ;; (item-hack) will never reach this instruction ] - (repeat 8 [0x00 0x01]) + (repeat 8 [0x00 0x02]);; these can be anything [;; jump to actual program 0x00 @@ -206,6 +206,9 @@ (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) @@ -384,7 +387,7 @@ [script] (->> script (delayed-difference [] [:a] 100 - #(aget (memory %) text-address)))) + first-character))) (defn-memo get-money-floor-two ([] (get-money-floor-two (go-to-floor-two))) @@ -646,13 +649,13 @@ (widthdraw-pc-item 0 99) (widthdraw-pc-item 0 1) (widthdraw-pc-item 2 0xFE) - (widthdraw-pc-item 3 0xFE)))) + (widthdraw-pc-item 3 0xFE) + close-menu))) (defn-memo hacking-4 ([] (hacking-4 (hacking-3))) ([script] (->> script - close-menu begin-deposit (deposit-held-item 19 243) (deposit-held-item-named :lemonade 16) @@ -696,6 +699,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) @@ -731,7 +751,7 @@ (widthdraw-pc-item 9 0xFE) (multiple-times 7 - (partial combine-items 2)) + (partial combine-pc-items 2)) close-menu))) (defn-memo hacking-10 @@ -802,7 +822,7 @@ select-menu-entry (scroll-text)))) -(defn hacking-13 +(defn-memo hacking-13 ([] (hacking-13 (hacking-12))) ([script] (->> script @@ -810,14 +830,69 @@ (select-menu-entry) (toss-pc-item 1 1) (toss-pc-item 0 156) - (toss-pc-item 0 11) + (toss-pc-item 0 11)))) + +(defn confirm-pattern [] + (let [start-address (inc pc-item-list-start) + target-pattern (pc-item-writer-program) + actual-pattern + (subvec (vec (memory (second (hacking-13)))) + start-address + (+ start-address (count target-pattern)))] + (println target-pattern) + (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] + (->> script + close-menu + close-menu + end-text ;;grr + (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓]) + (walk (repeat 17 ←)) + (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑]) + (walk [↓ ← ↑]) + (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ + ← ← ← ← ↑ ↑ ↑ ← ↑]) + (talk) + (scroll-text 2) 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 + (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 + \ No newline at end of file