Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_1.clj @ 411:0406867ead8a
Saving work -- found Pokedex menu text, and other things.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Fri, 13 Apr 2012 05:06:56 -0500 |
parents | 1f14c1b8af7e |
children | 0162dd315814 |
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-12 (:use (com.aurellem.gb saves gb-driver util constants3 items vbm characters money))4 (:use (com.aurellem.run util title save-corruption bootstrap-0))5 (:use (com.aurellem.exp item-bridge))6 (:import [com.aurellem.gb.gb_driver SaveState]))8 (defn pc-item-writer-program9 []10 (let [limit 20111 [target-high target-low] (disect-bytes-2 pokemon-list-start)]12 (flatten13 [[0x00 ;; (item-hack) set increment stack pointer no-op14 0x1E ;; load limit into E15 limit16 0x3F ;; (item-hack) set carry flag no-op18 ;; load 2 into C.19 0x0E ;; C == 1 means input-first nybble20 0x04 ;; C == 0 means input-second nybble22 0x21 ;; load target into HL23 target-low24 target-high25 0x37 ;; (item-hack) set carry flag no-op27 0x00 ;; (item-hack) no-op28 0x37 ;; (item-hack) set carry flag no-op30 0x00 ;; (item-hack) no-op31 0xF3 ;; disable interrupts32 ;; Input Section34 0x3E ;; load 0x20 into A, to measure buttons35 0x1037 0x00 ;; (item-hack) no-op38 0xE0 ;; load A into [FF00]39 0x0041 0xF0 ;; load 0xFF00 into A to get42 0x00 ;; button presses44 0xE645 0x0F ;; select bottom four bits of A46 0x37 ;; (item-hack) set carry flag no-op48 0x00 ;; (item-hack) no-op49 0xB8 ;; see if input is different (CP A B)51 0x00 ;; (item-hack) (INC SP)52 0x28 ;; repeat above steps if input is not different53 ;; (jump relative backwards if B != A)54 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37)56 0x47 ;; load A into B58 0x0D ;; dec C59 0x37 ;; (item-hack) set-carry flag60 ;; branch based on C:61 0x20 ;; JR NZ62 23 ;; skip "input second nybble" and "jump to target" below64 ;; input second nybble66 0x0C ;; inc C67 0x0C ;; inc C69 0x00 ;; (item-hack) no-op70 0xE6 ;; select bottom bits71 0x0F72 0x37 ;; (item-hack) set-carry flag no-op74 0x00 ;; (item-hack) no-op75 0xB2 ;; (OR A D) -> A77 0x22 ;; (do (A -> (HL)) (INC HL))79 0x1D ;; (DEC E)81 0x00 ;; (item-hack)82 0x20 ;; jump back to input section if not done83 0xDA ;; literal -36 == TM 18 (counter)84 0x01 ;; (item-hack) set BC to literal (no-op)86 ;; jump to target87 0x00 ;; (item-hack) these two bytes can be anything.88 0x0190 0x00 ;; (item-hack) no-op91 0xBF ;; (CP A A) ensures Z93 0xCA ;; (item-hack) jump if Z94 target-low95 target-high96 0x01 ;; (item-hack) will never be reached.98 ;; input first nybble99 0x00100 0xCB101 0x37 ;; swap nybbles on A103 0x57 ;; A -> D105 0x37 ;; (item-hack) set carry flag no-op106 0x18 ;; relative jump backwards107 0xCD ;; literal -51 == TM05; go back to input section108 0x01 ;; (item-hack) will never reach this instruction110 ]111 (repeat 8 [0x00 0x01]);; these can be anything113 [;; jump to actual program114 0x00115 0x37 ;; (item-hack) set carry flag no-op117 0x2E ;; 0x3A -> L118 0x3A121 0x00 ;; (item-hack) no-op122 0x26 ;; 0xD5 -> L123 0xD5124 0x01 ;; (item-hack) set-carry BC126 0x00 ;; (item-hack) these can be anything127 0x01129 0x00130 0xE9 ;; jump to (HL)131 ]])))133 (defn print-desired-item-layout []134 (clojure.pprint/pprint135 (raw-inventory->inventory (pc-item-writer-program))))137 (defn pc-item-writer-state []138 (-> (read-state "bootstrap-init")139 (set-memory pc-item-list-start 50)140 (set-memory-range141 map-function-address-start142 [0x8B 0xD5])143 (set-memory-range144 (inc pc-item-list-start)145 (pc-item-writer-program))))147 (defn test-pc-item-writer []148 (let [orig (read-state "pc-item-writer")]149 (-> orig150 (print-listing 0xD162 (+ 0xD162 20))151 (run-moves (reduce concat152 (repeat 10 [[:a :b :start :select] []])))153 ((fn [_] (println "===========") _))154 (print-listing 0xD162 (+ 0xD162 20)))))156 (defn close-all-menus [[moves state :as script]]157 (loop [s script]158 (let [depth (current-depth (second (do-nothing 50 s)))]159 (println "depth" depth)160 (if (= depth 1)161 s162 (recur (close-menu s))))))164 (defn-memo name-rival165 ([] (name-rival (to-rival-name)))166 ([script]167 (->> script168 (first-difference [] [:a] AF)169 (first-difference [] [:r] DE)170 (play-moves171 [[]172 [] [] [:r] [] [:d] [:a] ;; L173 [:r] [] [:r] [] [:r] [] [:r] []174 [:r] [] [:d] [] [:d] [:a] ;; [PK]175 [:d] [] [:r] [:a]176 ]))))178 (defn-memo to-room-pc179 ([] (to-room-pc (name-rival)))180 ([script]181 (->> script182 finish-title183 (walk [← ← ↑ ← ↑ ↑ ↑]))))185 ;; (defn wait-for-quantity186 ;; [[moves state :as script]]187 ;; (if (not= (item-quantity-selected state) 1)188 ;; (repeat-until-different [] item-quantity-selected script)189 ;; script))191 ;; TODO use this:192 ;;(wait-until (partial set-cursor-relative 1))194 ;; (defn wait-for-cursor195 ;; [[moves state :as script]]196 ;; (if (not= (list-offset state) 0)197 ;; (repeat-until-different [] list-offset script)198 ;; script))200 (defn deposit-held-item [n quantity [moves state :as script]]201 (let [total-quantity (second (nth-item state n))]202 (println "total-quantity" total-quantity)203 (->> script204 (set-cursor n)205 (select-menu-entry 1)206 ;;(wait-for-quantity)207 (set-quantity total-quantity quantity)208 (delayed-difference [] [:a] 100 #(search-string % "stored"))209 (scroll-text))))211 (defn sell-held-item [n quantity [moves state :as script]]212 (let [total-quantity (second (nth-item state n))]213 (->> script214 ;;(wait-for-cursor) ;; when selling, the cursor always215 (set-cursor n) ;; returns to the top of the list.216 (select-menu-entry 1)217 ;;(wait-for-quantity)218 (set-quantity total-quantity quantity)219 (delayed-difference [] [:a] 100 current-depth)220 (play-moves (repeat 20 [:b]))221 (delayed-difference [] [:a] 100 #(search-string % "What"))222 )))224 (defn widthdraw-pc-item [n quantity [moves state :as script]]225 (let [total-quantity (second (nth-pc-item state n))]226 (->> script227 (set-cursor n)228 (select-menu-entry 1)229 ;;(wait-for-quantity)230 (set-quantity total-quantity quantity)231 (delayed-difference [] [:a] 100 #(search-string % "Withdrew"))232 (scroll-text))))234 (defn toss-held-item [n quantity [moves state :as script]]235 (let [total-quantity (second (nth-item state n))]236 (->> script237 (set-cursor n)238 (select-menu-entry 1)239 (set-cursor-relative 1)240 (select-menu-entry -1)241 ;;(wait-for-quantity)242 (set-quantity total-quantity quantity)243 (play-moves [[:a]])244 (scroll-text)245 (delayed-difference [] [:a] 100 #(search-string % "Threw"))246 (scroll-text)247 )))249 (defn buy-item [n quantity [moves state :as script]]250 (->> script251 (set-cursor n)252 (purchase-item quantity)))254 (defn switch-items [item-fn idx-1 idx-2 script]255 (->> script256 (wait-until select-menu-entry)257 (set-cursor idx-1)258 (wait-until select-menu-entry)259 (play-moves [[][:select][]])260 (set-cursor idx-2)261 (delayed-difference [] [:select] 100262 #(item-fn % (list-offset %)))))264 (def switch-pc-items (partial switch-items nth-pc-item))265 (def switch-held-items (partial switch-items nth-item))267 (defn combine-pc-items [idx-1 script]268 (->> script269 (switch-pc-items idx-1 (inc idx-1))))271 (def desired-zero-quantities272 (map second (filter (comp (partial = 0) first)273 (partition 2 (pc-item-writer-program)))))275 (defn-memo bootstrap-corrupt-save276 ([] (bootstrap-corrupt-save (to-room-pc)))277 ([script]278 (->> script279 (do-save-corruption 3)280 (corrupt-item-list 0)281 close-all-menus)))283 (defn-memo prepare-celadon-warp284 ([] (prepare-celadon-warp (bootstrap-corrupt-save)))285 ([script]286 (->> script287 (activate-start-menu)288 (set-cursor-relative 1)289 (select-menu-entry)290 ;; vastly increase text speed while we're here.291 (switch-held-items 21 27)292 (toss-held-item 35 0xFA)293 (close-all-menus))))295 (defn-memo begin-initial-deposits296 ([] (begin-initial-deposits297 (prepare-celadon-warp)))298 ([script]299 (->> script300 (first-difference [] [:a] AF)301 (scroll-text)302 (set-cursor 1)303 select-menu-entry)))305 (defn-memo initial-deposits306 ([] (initial-deposits (begin-initial-deposits)))307 ([script]308 (->> script309 (deposit-held-item 0 0x1)310 ((fn [script]311 (reduce312 (fn [script item] (deposit-held-item item 0xFF script))313 script314 (range 3 (+ 13 3)))))315 close-all-menus)))318 ;;0 -- 256319 ;;1 -- 254320 ;;2 -- 254321 ;;3 -- 255323 (defn activate-home-pc324 [script]325 (->> script326 (delayed-difference [] [:a]327 200 first-character)328 (scroll-text)))330 (defn-memo restore-items331 ([] (restore-items (initial-deposits)))332 ([script]333 (->> script334 activate-home-pc335 (select-menu-entry)336 (widthdraw-pc-item 0 1)337 ;;(widthdraw-pc-item 0 99)338 ;;(widthdraw-pc-item 1 1)339 (widthdraw-pc-item 13 255)340 (close-all-menus))))342 (defn-memo to-celadon343 ([] (to-celadon (restore-items)))344 ([script]345 (->> script346 (walk [→ → → → → → → ↑347 ↓ ↓ ↓ ↓ ↓ ← ← ← ←348 ↓ ↓]))))351 ;; celadon store inventory353 ;; Floor 2354 ;;=====================================355 ;; Great Ball TM32 (double-team)356 ;; Super Potion TM33 (reflect)357 ;; Revive TM02 (razor-wind)358 ;; Super Repel TM07 (horn-drill)359 ;; Antidote TM37 (egg-bomb)360 ;; Burn Heal TM01 (mega-punch)361 ;; Ice Heal TM05 (mega-kick)362 ;; Awakening TM09 (take-down)363 ;; Parlyz Heal TM17 (submission)366 ;; Floor 3367 ;;=====================================368 ;; TM18 (counter)371 ;; Floor 4372 ;;=====================================373 ;; Poke Doll374 ;; Fire Stone375 ;; Thunder Stone376 ;; Water Stone377 ;; Leaf Stone379 ;; Floor 5380 ;;=====================================381 ;; X Accuracy HP UP382 ;; Guard Spec. Protein383 ;; Dire Hit Iron384 ;; X Attack Carbos385 ;; X Defend Calcium386 ;; X Speed387 ;; X Special389 ;; Roof390 ;;=====================================391 ;; Fresh Water TM13 (ice-beam)392 ;; Soda Pop TM48 (rock-slide)393 ;; Lemonade :) TM49 (tri-attack)396 (defn-memo go-to-floor-two397 ([] (go-to-floor-two (to-celadon)))398 ([script]399 (->> script400 (walk [↑ → → → → → → → → → → →401 ↑ ↑ ↑ ↑ ↑ ↑402 ← ← ← ←403 ↓ ↓ ↓404 ← ←])405 (first-difference [] ↑ AF))))407 (defn talk408 "Assumes that you are facing something that initiates text and409 causes it to do so."410 [script]411 (->> script412 (delayed-difference [] [:a] 100413 first-character)))415 (defn-memo get-money-floor-two416 ([] (get-money-floor-two (go-to-floor-two)))417 ([script]418 (->> script419 talk420 (set-cursor 1)421 (select-menu-entry)422 (sell-held-item 0 1)423 (sell-held-item 0 1)424 (close-menu))))426 (defn-memo floor-two-TMs427 ([] (floor-two-TMs (get-money-floor-two)))428 ([script]429 (->> script430 (set-cursor 0)431 (select-menu-entry)432 (buy-item 2 98) ;; TM02 (razor-wind)433 (buy-item 4 71) ;; TM37 (doubleteam)434 (buy-item 5 63) ;; TM01 (mega-punch)435 (buy-item 6 1) ;; TM05 (mega-kick)436 (buy-item 7 56) ;; TM09 (take-down)437 (close-menu))))439 (defn end-shop-conversation440 [script]441 (->> script442 (wait-until scroll-text [:b])443 (play-moves [[] [:b]])444 close-menu))446 (defn-memo floor-two-more-money447 ([] (floor-two-more-money (floor-two-TMs)))448 ([script]449 (->> script450 (set-cursor 1)451 (select-menu-entry)452 (sell-held-item 0 1)453 (sell-held-item 0 1)454 close-menu455 end-shop-conversation)))457 (defn turn [direction script]458 (->> script459 (first-difference [] direction AF)))461 (defn-memo floor-two-items462 ([] (floor-two-items (floor-two-more-money)))463 ([script]464 (->> script465 (walk [←])466 (turn ↑)467 talk468 select-menu-entry469 (buy-item 5 12) ;; burn heal470 (buy-item 6 55) ;; ice heal471 (buy-item 7 4) ;; awakening472 (buy-item 8 99) ;; parlyz heal473 (buy-item 8 55) ;; parlyz heal474 close-menu475 end-shop-conversation)))477 (defn-memo go-to-floor-three478 ([] (go-to-floor-three (floor-two-items)))479 ([script]480 (->> script481 (walk [→ → → → → → → → → → ↑ ↑ ↑482 → ↑]))))483 (defn-memo get-TM18484 ([] (get-TM18 (go-to-floor-three)))485 ([script]486 (->> script487 (walk [↓ ↓])488 talk489 (scroll-text 3)490 end-text)))492 (defn-memo go-to-floor-four493 ([] (go-to-floor-four (get-TM18)))494 ([script]495 (->> script496 (walk [← ← ← ← ↑ ↑497 ↓ ← ← ↓ ↓ ↓498 ← ← ← ← ←])499 (turn ↓))))501 (defn-memo floor-four-items502 ([] (floor-four-items (go-to-floor-four)))503 ([script]504 (->> script505 talk506 select-menu-entry507 (buy-item 1 23) ;; Fire Stone508 (buy-item 2 98) ;; Thunder Stone509 (buy-item 3 29) ;; Water Stone510 close-menu511 end-shop-conversation)))513 (defn-memo go-to-floor-five514 ([] (go-to-floor-five (floor-four-items)))515 ([script]516 (->> script517 (walk [→ → → → → →518 ↑ ↑ ↑519 → → → → → ↑ ;; leave floor four520 ↓ ← ← ← ← ← ← ← ←521 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk522 (turn ↑))))524 (defn-memo floor-five-items525 ([] (floor-five-items (go-to-floor-five)))526 ([script]527 (->> script528 talk529 select-menu-entry530 (buy-item 0 58) ;; X-Accuracy531 (buy-item 1 99) ;; Guard Spec.532 (buy-item 1 24) ;; Guard Spec.533 close-menu534 end-shop-conversation)))536 (defn-memo go-to-roof537 ([] (go-to-roof (floor-five-items)))538 ([script]539 (->> script540 (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five541 ↓ ← ← ←]) ;; walk to vending machine542 (turn ↑))))544 (defn buy-drink545 "Assumes you're in front of the vending machine. Buys the indicated546 drink."547 [n script]548 (->> script549 (do-nothing 20)550 (play-moves [[:a][:a]])551 scroll-text552 (set-cursor n)553 select-menu-entry554 close-menu))556 (defn-memo roof-drinks557 ([] (roof-drinks (go-to-roof)))558 ([script]559 (->> script560 (buy-drink 0) ;; fresh water (for TM13)561 ;; buy 16 lemonades562 ;; LEMONADE is the best item <3 :)563 (multiple-times 16 (partial buy-drink 2)))))565 (defn-memo get-TM13566 ([] (get-TM13 (roof-drinks)))567 ([script]568 (->> script569 ;;(walk [← ← ← ← ← ← ↓])570 (walk [↓ ↓ ↓ ← ← ← ← ← ←])571 (play-moves [[][][][][:a][:a][]])572 (scroll-text 3)573 select-menu-entry574 select-menu-entry575 (scroll-text 6)576 close-menu)))578 (defn-memo to-celadon-poke-center579 ([] (to-celadon-poke-center (get-TM13)))580 ([script]581 (->> script582 ;;(walk [↑ → → → → → → → → → ↑]) ; leave roof583 (walk [→ → → → → → → → → ↑ ↑ ↑ ↑])584 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←585 ↑ ↑ ↑ ← ← ↑]) ; to elevator587 (walk [→ → ↑ ↑]) ; to controls588 talk589 select-menu-entry ; to floor 1590 (walk [↓ ↓ ← ←])591 (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store592 (walk [↓ → → → → → → → → → → ↑ ↑])593 (walk (repeat 23 →))594 (walk [↑ ↑ ↑ ↑]) ; enter poke center595 (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer596 (turn ↑))))598 (defn activate-rlm-pc [script]599 (->> script600 talk601 scroll-text602 ;;wait-for-cursor603 (set-cursor 1)604 select-menu-entry605 (scroll-text 2)))607 (defn begin-deposit [script]608 (->> script609 (set-cursor 1)610 select-menu-entry))612 (defn begin-withdraw [script]613 (->> script614 (set-cursor 0)615 (select-menu-entry)))617 (defn deposit-held-item-named618 [item-name quantity [moves state :as script]]619 (let [index (count620 (take-while621 (fn [[name quant]]622 (or (not= name item-name)623 (< quant quantity)))624 (inventory state)))]625 (println "index" index)626 (deposit-held-item index quantity script)))628 (defn open-held-items629 [script]630 (->> script631 select-menu-entry))633 (defn to-held-items634 [script]635 (->> script636 close-menu637 close-menu638 end-text;;; grr640 activate-start-menu641 open-held-items))643 (defn toss-pc-item [n quantity [moves state :as script]]644 (let [total-quantity (second (nth-pc-item state n))]645 (->> script646 (set-cursor n)647 (select-menu-entry 1)648 (set-quantity total-quantity quantity)649 (delayed-difference [] [:a] 100 #(search-string % "Is"))650 (scroll-text)651 select-menu-entry652 (scroll-text))))654 (defn-memo hacking-1655 ([] (hacking-1 (to-celadon-poke-center)))656 ([script]657 (->> script658 activate-rlm-pc659 begin-deposit660 (deposit-held-item-named 0x00 30)661 (deposit-held-item-named :TM01 63)662 (deposit-held-item-named :awakening 4)663 (deposit-held-item-named :thunderstone 98)664 (deposit-held-item-named :TM09 55)665 (deposit-held-item-named 0x00 55))))667 (defn-memo hacking-2668 ([] (hacking-2 (hacking-1)))669 ([script]670 (->> script671 (to-held-items)672 (toss-held-item 0 166) ;; discard cruft673 close-menu674 close-menu)))676 (defn-memo hacking-3677 ([] (hacking-3 (hacking-2)))678 ([script]679 (->> script680 activate-rlm-pc681 begin-withdraw682 (widthdraw-pc-item 0 99)683 (widthdraw-pc-item 0 1)684 (widthdraw-pc-item 2 0xFE)685 (widthdraw-pc-item 3 0xFE)686 close-menu)))688 (defn-memo hacking-4689 ([] (hacking-4 (hacking-3)))690 ([script]691 (->> script692 begin-deposit693 (deposit-held-item 19 243)694 (deposit-held-item-named :lemonade 16)695 (deposit-held-item 18 224))))697 (defn-memo hacking-5698 "clean out the held-item list again"699 ([] (hacking-5 (hacking-4)))700 ([script]701 (->> script702 (to-held-items)703 (toss-held-item 18 30)704 (toss-held-item 17 1)705 close-menu706 close-menu)))708 (defn-memo hacking-6709 ([] (hacking-6 (hacking-5)))710 ([script]711 (->> script712 activate-rlm-pc713 begin-withdraw714 (widthdraw-pc-item 4 0xFE)715 (widthdraw-pc-item 5 0xFE)716 (widthdraw-pc-item 6 0xFE)717 close-menu)))719 (defn-memo hacking-7720 ([] (hacking-7 (hacking-6)))721 ([script]722 (->> script723 begin-deposit724 (deposit-held-item 19 240)725 (deposit-held-item 18 230)726 (deposit-held-item-named :parlyz-heal 55)727 (deposit-held-item 17 184)728 (deposit-held-item 17 40)729 (deposit-held-item-named :TM37 71)730 (deposit-held-item-named :ice-heal 55)731 (deposit-held-item-named :fire-stone 23)732 (deposit-held-item-named :burn-heal 12)733 ;; as a special case, /don't/ close the menu.734 )))736 (defn-memo hacking-8737 "Clear cruft away from held item list."738 ([] (hacking-8 (hacking-7)))739 ([script]740 (->> script741 to-held-items742 (toss-held-item 15 1)743 (toss-held-item 14 1)744 (toss-held-item 13 1)745 close-menu746 close-menu)))748 (defn-memo hacking-9749 ([] (hacking-9 (hacking-8)))750 ([script]751 (->> script752 activate-rlm-pc753 begin-withdraw754 (widthdraw-pc-item 7 0xFE)755 (widthdraw-pc-item 8 0xFC)756 (widthdraw-pc-item 8 1)757 (widthdraw-pc-item 8 1)758 (widthdraw-pc-item 9 0xFE)759 (multiple-times760 7761 (partial combine-pc-items 2))762 close-menu)))764 (defn-memo hacking-10765 ([] (hacking-10 (hacking-9)))766 ([script]767 (->> script768 begin-deposit769 (deposit-held-item 17 230)770 (deposit-held-item-named :parlyz-heal 55)771 (deposit-held-item 14 178)772 (deposit-held-item-named :water-stone 29)773 (deposit-held-item 14 32)774 (deposit-held-item-named :TM18 1)775 (deposit-held-item 13 1)776 (deposit-held-item 13 191)777 (deposit-held-item-named :TM02 98)778 (deposit-held-item-named :TM09 1)779 close-menu)))781 (defn-memo hacking-11782 ([] (hacking-11 (hacking-10)))783 ([script]784 (->> script785 begin-withdraw786 (widthdraw-pc-item 3 0xFE)787 (widthdraw-pc-item 4 0xFE)788 (widthdraw-pc-item 5 1)789 (widthdraw-pc-item 5 1)790 (widthdraw-pc-item 5 1)791 (widthdraw-pc-item 5 0xFB)792 (multiple-times793 3794 (partial combine-pc-items 2))795 close-menu)))797 (defn-memo hacking-12798 ([] (hacking-12 (hacking-11)))799 ([script]800 (->> script801 begin-deposit802 (deposit-held-item 18 203)803 (deposit-held-item-named :guard-spec 87)804 (deposit-held-item-named :guard-spec 24)805 (deposit-held-item-named :TM05 1)806 (multiple-times807 8808 (partial deposit-held-item 14 1))809 (deposit-held-item 14 55)810 (deposit-held-item-named :x-accuracy 58)811 (deposit-held-item 14 38)812 (deposit-held-item-named :TM13 1)813 (deposit-held-item 13 1)814 (deposit-held-item 13 233)815 close-menu)))817 (defn-memo hacking-13818 ([] (hacking-13 (hacking-12)))819 ([script]820 (->> script821 (set-cursor-relative 1)822 (select-menu-entry)823 (toss-pc-item 1 1)824 (toss-pc-item 0 156)825 (toss-pc-item 0 11))))827 (defn confirm-pattern []828 (let [start-address (inc pc-item-list-start)829 target-pattern (pc-item-writer-program)830 actual-pattern831 (subvec (vec (memory (second (hacking-13))))832 start-address833 (+ start-address (count target-pattern)))]834 (println target-pattern)835 (println actual-pattern)836 (= target-pattern actual-pattern)))838 (defn-memo go-to-mansion-for-the-lulz839 ([] (go-to-mansion-for-the-lulz (hacking-13)))840 ([script]841 (->> script842 close-menu843 close-menu844 end-text ;;grr845 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])846 (walk (repeat 17 ←))847 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])848 (walk [↓ ← ↑])849 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓850 ← ← ← ← ↑ ↑ ↑ ← ↑])851 (talk)852 (scroll-text 2)853 (do-nothing 100)854 close-menu)))856 (defn-memo launch-bootstrap-program857 ([] (launch-bootstrap-program858 (go-to-mansion-for-the-lulz)))859 ([script]860 (->> script861 ;; must corrupt item list again by switching pokemon862 activate-start-menu ;; \863 (set-cursor 0) ;; |864 select-menu-entry ;; |865 select-menu-entry ;; |866 (set-cursor 1) ;; | -- switch 9th pokemon867 select-menu-entry ;; | with 4th pokemon868 (set-cursor 3) ;; |869 select-menu-entry ;; |870 close-menu ;; /871 ;; now, open items and set map-function to872 ;; the program inside the item-computer.873 (set-cursor 1)874 (select-menu-entry)875 (toss-held-item 22 12)876 (switch-held-items 22 40)877 close-all-menus)))879 (defn regen-control-checkpoint!880 [] (write-script! (launch-bootstrap-program) "control-checkpoint"))882 (defn control-checkpoint []883 (read-script "control-checkpoint"))885 (defn no-consecutive-repeats? [seq]886 (not (contains? (set(map - seq (rest seq))) 0)))888 (defn byte->nybbles [byte]889 [(bit-shift-right byte 4) (bit-and byte 0x0F)])891 (defn bootstrap-pattern892 "Given an assembly sequence, generate the keypresses required to893 create that sequence in memory using the pc-item-writer894 program. The assembly must not have any consecutive repeating895 nybbles."896 [assembly]897 (let [nybbles (flatten (map byte->nybbles assembly))898 moves (map (comp buttons (partial - 15)) nybbles)899 header (map buttons900 (concat (repeat901 50902 (- 15 (first nybbles)))903 [(first nybbles)]))904 tail (map buttons905 (take906 (- 201 (count moves))907 (interleave (repeat 100 (last nybbles))908 (repeat 1000 (- 15 (last nybbles))))))]909 (assert (no-consecutive-repeats? nybbles))910 (concat header moves tail)))912 (def increasing-pattern [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF])914 (defn test-pattern-writing915 ([] (test-pattern-writing increasing-pattern))916 ([pattern]917 (let [moves (bootstrap-pattern pattern)918 pattern-insertion919 (->> (launch-bootstrap-program)920 (play-moves921 (take 100 moves)))]922 (println "Input Pattern:")923 (apply println (map #(format "0x%02X" %) pattern))924 (println "\nMemory Listing:")925 (print-listing (second pattern-insertion)926 0xD162 (+ 0xD162 (count pattern)))927 (= (subvec (vec (memory (second pattern-insertion)))928 0xD162 (+ 0xD162 (count pattern)))929 pattern))))