annotate clojure/com/aurellem/run/bootstrap_1.clj @ 368:08f8284e2f1b

cleaning up code
author Robert McIntyre <rlm@mit.edu>
date Tue, 10 Apr 2012 03:32:47 -0500
parents 845b2d88bef9
children abcc522a3242
rev   line source
rlm@345 1 (ns com.aurellem.run.bootstrap-1
rlm@345 2 (:use (com.aurellem.gb saves gb-driver util
rlm@345 3 items vbm characters money))
rlm@345 4 (:use (com.aurellem.run util title save-corruption bootstrap-0))
rlm@345 5 (:use (com.aurellem.exp item-bridge))
rlm@345 6 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@345 7
rlm@345 8 (defn pc-item-writer-program
rlm@345 9 []
rlm@345 10 (let [limit 201
rlm@345 11 [target-high target-low] (disect-bytes-2 0xD162)]
rlm@345 12 (flatten
rlm@345 13 [[0x00 ;; (item-hack) set increment stack pointer no-op
rlm@345 14 0x1E ;; load limit into E
rlm@345 15 limit
rlm@345 16 0x3F ;; (item-hack) set carry flag no-op
rlm@345 17
rlm@345 18 ;; load 2 into C.
rlm@345 19 0x0E ;; C == 1 means input-first nybble
rlm@345 20 0x04 ;; C == 0 means input-second nybble
rlm@345 21
rlm@345 22 0x21 ;; load target into HL
rlm@345 23 target-low
rlm@345 24 target-high
rlm@345 25 0x37 ;; (item-hack) set carry flag no-op
rlm@345 26
rlm@345 27 0x00 ;; (item-hack) no-op
rlm@345 28 0x37 ;; (item-hack) set carry flag no-op
rlm@345 29
rlm@345 30 0x00 ;; (item-hack) no-op
rlm@345 31 0xF3 ;; disable interrupts
rlm@345 32 ;; Input Section
rlm@345 33
rlm@345 34 0x3E ;; load 0x20 into A, to measure buttons
rlm@345 35 0x10
rlm@345 36
rlm@345 37 0x00 ;; (item-hack) no-op
rlm@345 38 0xE0 ;; load A into [FF00]
rlm@345 39 0x00
rlm@345 40
rlm@345 41 0xF0 ;; load 0xFF00 into A to get
rlm@345 42 0x00 ;; button presses
rlm@345 43
rlm@345 44 0xE6
rlm@345 45 0x0F ;; select bottom four bits of A
rlm@345 46 0x37 ;; (item-hack) set carry flag no-op
rlm@345 47
rlm@345 48 0x00 ;; (item-hack) no-op
rlm@345 49 0xB8 ;; see if input is different (CP A B)
rlm@345 50
rlm@345 51 0x00 ;; (item-hack) (INC SP)
rlm@345 52 0x28 ;; repeat above steps if input is not different
rlm@345 53 ;; (jump relative backwards if B != A)
rlm@345 54 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37)
rlm@345 55
rlm@345 56 0x47 ;; load A into B
rlm@345 57
rlm@345 58 0x0D ;; dec C
rlm@345 59 0x37 ;; (item-hack) set-carry flag
rlm@345 60 ;; branch based on C:
rlm@345 61 0x20 ;; JR NZ
rlm@345 62 23 ;; skip "input second nybble" and "jump to target" below
rlm@345 63
rlm@345 64 ;; input second nybble
rlm@345 65
rlm@345 66 0x0C ;; inc C
rlm@345 67 0x0C ;; inc C
rlm@345 68
rlm@345 69 0x00 ;; (item-hack) no-op
rlm@345 70 0xE6 ;; select bottom bits
rlm@345 71 0x0F
rlm@345 72 0x37 ;; (item-hack) set-carry flag no-op
rlm@345 73
rlm@345 74 0x00 ;; (item-hack) no-op
rlm@345 75 0xB2 ;; (OR A D) -> A
rlm@345 76
rlm@345 77 0x22 ;; (do (A -> (HL)) (INC HL))
rlm@345 78
rlm@345 79 0x1D ;; (DEC E)
rlm@345 80
rlm@345 81 0x00 ;; (item-hack)
rlm@345 82 0x20 ;; jump back to input section if not done
rlm@345 83 0xDA ;; literal -36 == TM 18 (counter)
rlm@345 84 0x01 ;; (item-hack) set BC to literal (no-op)
rlm@345 85
rlm@345 86 ;; jump to target
rlm@345 87 0x00 ;; (item-hack) these two bytes can be anything.
rlm@345 88 0x01
rlm@345 89
rlm@345 90 0x00 ;; (item-hack) no-op
rlm@345 91 0xBF ;; (CP A A) ensures Z
rlm@345 92
rlm@345 93 0xCA ;; (item-hack) jump if Z
rlm@345 94 target-low
rlm@345 95 target-high
rlm@345 96 0x01 ;; (item-hack) will never be reached.
rlm@345 97
rlm@345 98 ;; input first nybble
rlm@345 99 0x00
rlm@345 100 0xCB
rlm@345 101 0x37 ;; swap nybbles on A
rlm@345 102
rlm@345 103 0x57 ;; A -> D
rlm@345 104
rlm@345 105 0x37 ;; (item-hack) set carry flag no-op
rlm@345 106 0x18 ;; relative jump backwards
rlm@345 107 0xCD ;; literal -51 == TM05; go back to input section
rlm@345 108 0x01 ;; (item-hack) will never reach this instruction
rlm@345 109
rlm@345 110 ]
rlm@368 111 (repeat 8 [0x00 0x02]);; these can be anything
rlm@345 112
rlm@345 113 [;; jump to actual program
rlm@345 114 0x00
rlm@345 115 0x37 ;; (item-hack) set carry flag no-op
rlm@345 116
rlm@345 117 0x2E ;; 0x3A -> L
rlm@345 118 0x3A
rlm@345 119
rlm@345 120
rlm@345 121 0x00 ;; (item-hack) no-op
rlm@345 122 0x26 ;; 0xD5 -> L
rlm@345 123 0xD5
rlm@345 124 0x01 ;; (item-hack) set-carry BC
rlm@345 125
rlm@345 126 0x00 ;; (item-hack) these can be anything
rlm@345 127 0x01
rlm@345 128
rlm@345 129 0x00
rlm@345 130 0xE9 ;; jump to (HL)
rlm@345 131 ]])))
rlm@345 132
rlm@367 133 (defn print-desired-item-layout []
rlm@345 134 (clojure.pprint/pprint
rlm@345 135 (raw-inventory->inventory (pc-item-writer-program))))
rlm@345 136
rlm@345 137 (defn pc-item-writer-state []
rlm@345 138 (-> (read-state "bootstrap-init")
rlm@345 139 (set-memory pc-item-list-start 50)
rlm@345 140 (set-memory-range
rlm@345 141 map-function-address-start
rlm@345 142 [0x8B 0xD5])
rlm@345 143 (set-memory-range
rlm@345 144 (inc pc-item-list-start)
rlm@345 145 (pc-item-writer-program))))
rlm@345 146
rlm@345 147 (defn test-pc-item-writer []
rlm@345 148 (let [orig (read-state "pc-item-writer")]
rlm@345 149 (-> orig
rlm@345 150 (print-listing 0xD162 (+ 0xD162 20))
rlm@345 151 (run-moves (reduce concat
rlm@345 152 (repeat 10 [[:a :b :start :select] []])))
rlm@345 153 ((fn [_] (println "===========") _))
rlm@345 154 (print-listing 0xD162 (+ 0xD162 20)))))
rlm@345 155
rlm@345 156 (defn close-all-menus [[moves state :as script]]
rlm@345 157 (loop [s script]
rlm@345 158 (let [depth (current-depth (second (do-nothing 50 s)))]
rlm@345 159 (println "depth" depth)
rlm@345 160 (if (= depth 1)
rlm@345 161 s
rlm@345 162 (recur (close-menu s))))))
rlm@345 163
rlm@345 164 (defn-memo name-rival
rlm@345 165 ([] (name-rival (to-rival-name)))
rlm@345 166 ([script]
rlm@345 167 (->> script
rlm@345 168 (first-difference [] [:a] AF)
rlm@345 169 (first-difference [] [:r] DE)
rlm@345 170 (play-moves
rlm@345 171 [[]
rlm@345 172 [] [] [:r] [] [:d] [:a] ;; L
rlm@345 173 [:r] [] [:r] [] [:r] [] [:r] []
rlm@345 174 [:r] [] [:d] [] [:d] [:a] ;; [PK]
rlm@345 175 [:d] [] [:r] [:a]
rlm@345 176 ]))))
rlm@345 177
rlm@345 178 (defn-memo to-room-pc
rlm@345 179 ([] (to-room-pc (name-rival)))
rlm@345 180 ([script]
rlm@345 181 (->> script
rlm@345 182 finish-title
rlm@345 183 (walk [← ← ↑ ← ↑ ↑ ↑]))))
rlm@345 184
rlm@345 185 (defn-memo bootstrap-corrupt-save
rlm@345 186 ([] (bootstrap-corrupt-save (to-room-pc)))
rlm@345 187 ([script]
rlm@345 188 (->> script
rlm@345 189 (do-save-corruption 2)
rlm@345 190 (corrupt-item-list 0)
rlm@345 191 close-all-menus)))
rlm@345 192
rlm@345 193 (defn-memo begin-initial-deposits
rlm@345 194 ([] (begin-initial-deposits
rlm@345 195 (bootstrap-corrupt-save)))
rlm@345 196 ([script]
rlm@345 197 (->> script
rlm@345 198 (first-difference [] [:a] AF)
rlm@345 199 (scroll-text)
rlm@345 200 (set-cursor 1)
rlm@345 201 select-menu-entry)))
rlm@345 202
rlm@353 203 (defn wait-for-quantity
rlm@353 204 [[moves state :as script]]
rlm@353 205 (if (not= (item-quantity-selected state) 1)
rlm@353 206 (repeat-until-different [] item-quantity-selected script)
rlm@353 207 script))
rlm@353 208
rlm@368 209 ;; TODO use this:
rlm@368 210 ;;(wait-until (partial set-cursor-relative 1))
rlm@368 211
rlm@353 212 (defn wait-for-cursor
rlm@353 213 [[moves state :as script]]
rlm@353 214 (if (not= (list-offset state) 0)
rlm@353 215 (repeat-until-different [] list-offset script)
rlm@353 216 script))
rlm@353 217
rlm@345 218 (defn deposit-held-item [n quantity [moves state :as script]]
rlm@345 219 (let [total-quantity (second (nth-item state n))]
rlm@345 220 (println "total-quantity" total-quantity)
rlm@345 221 (->> script
rlm@345 222 (set-cursor n)
rlm@345 223 (select-menu-entry 1)
rlm@353 224 (wait-for-quantity)
rlm@345 225 (set-quantity total-quantity quantity)
rlm@345 226 (delayed-difference [] [:a] 100 #(search-string % "stored"))
rlm@345 227 (scroll-text))))
rlm@345 228
rlm@353 229 (defn sell-held-item [n quantity [moves state :as script]]
rlm@353 230 (let [total-quantity (second (nth-item state n))]
rlm@353 231 (->> script
rlm@353 232 (wait-for-cursor) ;; when selling, the cursor always
rlm@353 233 (set-cursor n) ;; returns to the top of the list.
rlm@353 234 (select-menu-entry 1)
rlm@353 235 (wait-for-quantity)
rlm@353 236 (set-quantity total-quantity quantity)
rlm@353 237 (delayed-difference [] [:a] 100 current-depth)
rlm@353 238 (play-moves (repeat 20 [:b]))
rlm@353 239 (delayed-difference [] [:a] 100 #(search-string % "What"))
rlm@353 240 )))
rlm@353 241
rlm@345 242 (defn widthdraw-pc-item [n quantity [moves state :as script]]
rlm@345 243 (let [total-quantity (second (nth-pc-item state n))]
rlm@345 244 (->> script
rlm@345 245 (set-cursor n)
rlm@345 246 (select-menu-entry 1)
rlm@353 247 (wait-for-quantity)
rlm@345 248 (set-quantity total-quantity quantity)
rlm@345 249 (delayed-difference [] [:a] 100 #(search-string % "Withdrew"))
rlm@345 250 (scroll-text))))
rlm@345 251
rlm@345 252 (defn toss-held-item [n quantity [moves state :as script]]
rlm@353 253 (let [total-quantity (second (nth-item state n))]
rlm@345 254 (->> script
rlm@345 255 (set-cursor n)
rlm@345 256 (select-menu-entry 1)
rlm@345 257 (set-cursor-relative 1)
rlm@345 258 (select-menu-entry -1)
rlm@353 259 (wait-for-quantity)
rlm@345 260 (set-quantity total-quantity quantity)
rlm@345 261 (play-moves [[:a]])
rlm@345 262 (scroll-text)
rlm@345 263 (delayed-difference [] [:a] 100 #(search-string % "Threw"))
rlm@345 264 (scroll-text)
rlm@345 265 )))
rlm@345 266
rlm@354 267 (defn buy-item [n quantity [moves state :as script]]
rlm@354 268 (->> script
rlm@354 269 (set-cursor n)
rlm@354 270 (purchase-item quantity)))
rlm@354 271
rlm@345 272
rlm@345 273 (def desired-zero-quantities
rlm@345 274 (map second (filter (comp (partial = 0) first)
rlm@345 275 (partition 2 (pc-item-writer-program)))))
rlm@345 276
rlm@345 277 (defn-memo initial-deposits
rlm@345 278 ([] (initial-deposits (begin-initial-deposits)))
rlm@345 279 ([script]
rlm@345 280 (->> script
rlm@354 281 (deposit-held-item 0 0x1)
rlm@345 282 ((fn [script]
rlm@345 283 (reduce
rlm@345 284 (fn [script item] (deposit-held-item item 0xFF script))
rlm@345 285 script
rlm@360 286 (range 3 (+ 13 3)))))
rlm@345 287 close-all-menus)))
rlm@345 288
rlm@345 289
rlm@345 290 (defn-memo prepare-celadon-warp
rlm@345 291 ([] (prepare-celadon-warp (initial-deposits)))
rlm@345 292 ([script]
rlm@345 293 (->> script
rlm@345 294 (activate-start-menu)
rlm@345 295 (set-cursor-relative 1)
rlm@345 296 (select-menu-entry)
rlm@345 297 (toss-held-item 35 0xFA)
rlm@345 298 (close-all-menus))))
rlm@345 299
rlm@345 300
rlm@345 301 ;;0 -- 256
rlm@345 302 ;;1 -- 254
rlm@345 303 ;;2 -- 254
rlm@345 304 ;;3 -- 255
rlm@345 305
rlm@345 306 (defn-memo restore-items
rlm@345 307 ([] (restore-items (prepare-celadon-warp)))
rlm@345 308 ([script]
rlm@345 309 (->> script
rlm@345 310 (first-difference [] [:a] AF)
rlm@345 311 (scroll-text)
rlm@345 312 (select-menu-entry)
rlm@345 313 (widthdraw-pc-item 0 1)
rlm@354 314 ;;(widthdraw-pc-item 0 99)
rlm@354 315 ;;(widthdraw-pc-item 1 1)
rlm@360 316 (widthdraw-pc-item 13 255)
rlm@345 317 (close-all-menus))))
rlm@345 318
rlm@345 319 (defn-memo to-celadon
rlm@345 320 ([] (to-celadon (restore-items)))
rlm@345 321 ([script]
rlm@345 322 (->> script
rlm@345 323 (walk [→ → → → → → → ↑
rlm@345 324 ↓ ↓ ↓ ↓ ↓ ← ← ← ←
rlm@345 325 ↓ ↓]))))
rlm@345 326
rlm@345 327
rlm@351 328 ;; celadon store inventory
rlm@345 329
rlm@351 330 ;; Floor 2
rlm@351 331 ;;=====================================
rlm@351 332 ;; Great Ball TM32 (double-team)
rlm@351 333 ;; Super Potion TM33 (reflect)
rlm@351 334 ;; Revive TM02 (razor-wind)
rlm@351 335 ;; Super Repel TM07 (horn-drill)
rlm@351 336 ;; Antidote TM37 (egg-bomb)
rlm@351 337 ;; Burn Heal TM01 (mega-punch)
rlm@351 338 ;; Ice Heal TM05 (mega-kick)
rlm@351 339 ;; Awakening TM09 (take-down)
rlm@351 340 ;; Parlyz Heal TM17 (submission)
rlm@345 341
rlm@345 342
rlm@351 343 ;; Floor 3
rlm@351 344 ;;=====================================
rlm@351 345 ;; TM18 (counter)
rlm@345 346
rlm@351 347
rlm@351 348 ;; Floor 4
rlm@351 349 ;;=====================================
rlm@351 350 ;; Poke Doll
rlm@351 351 ;; Fire Stone
rlm@351 352 ;; Thunder Stone
rlm@351 353 ;; Water Stone
rlm@351 354 ;; Leaf Stone
rlm@351 355
rlm@351 356 ;; Floor 5
rlm@351 357 ;;=====================================
rlm@351 358 ;; X Accuracy HP UP
rlm@351 359 ;; Guard Spec. Protein
rlm@351 360 ;; Dire Hit Iron
rlm@351 361 ;; X Attack Carbos
rlm@351 362 ;; X Defend Calcium
rlm@351 363 ;; X Speed
rlm@351 364 ;; X Special
rlm@351 365
rlm@351 366 ;; Roof
rlm@351 367 ;;=====================================
rlm@351 368 ;; Fresh Water TM13 (ice-beam)
rlm@351 369 ;; Soda Pop TM48 (rock-slide)
rlm@352 370 ;; Lemonade :) TM49 (tri-attack)
rlm@352 371
rlm@352 372
rlm@353 373 (defn-memo go-to-floor-two
rlm@352 374 ([] (go-to-floor-two (to-celadon)))
rlm@352 375 ([script]
rlm@352 376 (->> script
rlm@352 377 (walk [↑ → → → → → → → → → → →
rlm@352 378 ↑ ↑ ↑ ↑ ↑ ↑
rlm@352 379 ← ← ← ←
rlm@352 380 ↓ ↓ ↓
rlm@352 381 ← ←])
rlm@352 382 (first-difference [] ↑ AF))))
rlm@352 383
rlm@353 384 (defn talk
rlm@360 385 "Assumes that you are facing something that initiates text and
rlm@360 386 causes it to do so."
rlm@360 387 [script]
rlm@360 388 (->> script
rlm@360 389 (delayed-difference [] [:a] 100
rlm@368 390 first-character)))
rlm@353 391
rlm@354 392 (defn-memo get-money-floor-two
rlm@353 393 ([] (get-money-floor-two (go-to-floor-two)))
rlm@353 394 ([script]
rlm@353 395 (->> script
rlm@353 396 talk
rlm@353 397 (set-cursor 1)
rlm@353 398 (select-menu-entry)
rlm@354 399 (sell-held-item 0 1)
rlm@354 400 (sell-held-item 0 1)
rlm@354 401 (close-menu))))
rlm@352 402
rlm@354 403 (defn-memo floor-two-TMs
rlm@354 404 ([] (floor-two-TMs (get-money-floor-two)))
rlm@354 405 ([script]
rlm@354 406 (->> script
rlm@354 407 (wait-for-cursor)
rlm@354 408 (select-menu-entry)
rlm@354 409 (buy-item 2 98) ;; TM02 (razor-wind)
rlm@354 410 (buy-item 4 71) ;; TM37 (doubleteam)
rlm@354 411 (buy-item 5 63) ;; TM01 (mega-punch)
rlm@354 412 (buy-item 6 1) ;; TM05 (mega-kick)
rlm@354 413 (buy-item 7 56) ;; TM09 (take-down)
rlm@354 414 (close-menu))))
rlm@354 415
rlm@354 416 (defn end-shop-conversation
rlm@354 417 [script]
rlm@354 418 (->> script
rlm@354 419 (wait-until scroll-text [:b])
rlm@354 420 (play-moves [[] [:b]])
rlm@354 421 close-menu))
rlm@354 422
rlm@354 423 (defn-memo floor-two-more-money
rlm@354 424 ([] (floor-two-more-money (floor-two-TMs)))
rlm@354 425 ([script]
rlm@354 426 (->> script
rlm@354 427 (wait-for-cursor)
rlm@354 428 (set-cursor 1)
rlm@354 429 (select-menu-entry)
rlm@354 430 (sell-held-item 0 1)
rlm@354 431 (sell-held-item 0 1)
rlm@354 432 close-menu
rlm@354 433 end-shop-conversation)))
rlm@354 434
rlm@354 435 (defn turn [direction script]
rlm@354 436 (->> script
rlm@354 437 (first-difference [] direction AF)))
rlm@352 438
rlm@355 439 (defn-memo floor-two-items
rlm@355 440 ([] (floor-two-items (floor-two-more-money)))
rlm@355 441 ([script]
rlm@355 442 (->> script
rlm@355 443 (walk [←])
rlm@355 444 (turn ↑)
rlm@355 445 talk
rlm@355 446 select-menu-entry
rlm@355 447 (buy-item 5 12) ;; burn heal
rlm@355 448 (buy-item 6 55) ;; ice heal
rlm@355 449 (buy-item 7 4) ;; awakening
rlm@355 450 (buy-item 8 99) ;; parlyz heal
rlm@355 451 (buy-item 8 55) ;; parlyz heal
rlm@355 452 close-menu
rlm@355 453 end-shop-conversation)))
rlm@352 454
rlm@356 455 (defn-memo go-to-floor-three
rlm@356 456 ([] (go-to-floor-three (floor-two-items)))
rlm@356 457 ([script]
rlm@356 458 (->> script
rlm@361 459 (walk [→ → → → → → → → → → ↑ ↑ ↑
rlm@361 460 → ↑]))))
rlm@357 461 (defn-memo get-TM18
rlm@356 462 ([] (get-TM18 (go-to-floor-three)))
rlm@356 463 ([script]
rlm@356 464 (->> script
rlm@356 465 (walk [↓ ↓])
rlm@356 466 talk
rlm@356 467 (scroll-text 3)
rlm@356 468 end-text)))
rlm@352 469
rlm@357 470 (defn-memo go-to-floor-four
rlm@357 471 ([] (go-to-floor-four (get-TM18)))
rlm@357 472 ([script]
rlm@357 473 (->> script
rlm@357 474 (walk [← ← ← ← ↑ ↑
rlm@357 475 ↓ ← ← ↓ ↓ ↓
rlm@357 476 ← ← ← ← ←])
rlm@357 477 (turn ↓))))
rlm@352 478
rlm@357 479 (defn-memo floor-four-items
rlm@357 480 ([] (floor-four-items (go-to-floor-four)))
rlm@357 481 ([script]
rlm@357 482 (->> script
rlm@357 483 talk
rlm@357 484 select-menu-entry
rlm@357 485 (buy-item 1 23) ;; Fire Stone
rlm@357 486 (buy-item 2 98) ;; Thunder Stone
rlm@357 487 (buy-item 3 29) ;; Water Stone
rlm@357 488 close-menu
rlm@357 489 end-shop-conversation)))
rlm@352 490
rlm@358 491 (defn-memo go-to-floor-five
rlm@358 492 ([] (go-to-floor-five (floor-four-items)))
rlm@358 493 ([script]
rlm@358 494 (->> script
rlm@358 495 (walk [→ → → → → →
rlm@358 496 ↑ ↑ ↑
rlm@358 497 → → → → → ↑ ;; leave floor four
rlm@358 498 ↓ ← ← ← ← ← ← ← ←
rlm@359 499 ↓ ↓ ↓ ← ← ← ]);; go to five's clerk
rlm@358 500 (turn ↑))))
rlm@358 501
rlm@358 502 (defn-memo floor-five-items
rlm@358 503 ([] (floor-five-items (go-to-floor-five)))
rlm@358 504 ([script]
rlm@358 505 (->> script
rlm@358 506 talk
rlm@358 507 select-menu-entry
rlm@358 508 (buy-item 0 58) ;; X-Accuracy
rlm@358 509 (buy-item 1 99) ;; Guard Spec.
rlm@358 510 (buy-item 1 24) ;; Guard Spec.
rlm@358 511 close-menu
rlm@358 512 end-shop-conversation)))
rlm@352 513
rlm@359 514 (defn-memo go-to-roof
rlm@359 515 ([] (go-to-roof (floor-five-items)))
rlm@359 516 ([script]
rlm@359 517 (->> script
rlm@359 518 (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five
rlm@359 519 ↓ ← ← ←]) ;; walk to vending machine
rlm@359 520 (turn ↑))))
rlm@352 521
rlm@359 522 (defn buy-drink
rlm@359 523 "Assumes you're in front of the vending machine. Buys the indicated
rlm@359 524 drink."
rlm@359 525 [n script]
rlm@359 526 (->> script
rlm@361 527 (do-nothing 20)
rlm@361 528 (play-moves [[:a][:a]])
rlm@361 529 scroll-text
rlm@359 530 (wait-for-cursor)
rlm@359 531 (set-cursor n)
rlm@359 532 select-menu-entry
rlm@359 533 close-menu))
rlm@359 534
rlm@359 535 (defn-memo roof-drinks
rlm@359 536 ([] (roof-drinks (go-to-roof)))
rlm@359 537 ([script]
rlm@359 538 (->> script
rlm@361 539 (buy-drink 0) ;; fresh water (for TM13)
rlm@359 540 ;; buy 16 lemonades
rlm@359 541 ;; LEMONADE is the best item <3 :)
rlm@361 542 (multiple-times 16 (partial buy-drink 2)))))
rlm@361 543
rlm@362 544 (defn-memo get-TM13
rlm@359 545 ([] (get-TM13 (roof-drinks)))
rlm@359 546 ([script]
rlm@359 547 (->> script
rlm@361 548 (walk [← ← ← ← ← ← ↓])
rlm@361 549 (play-moves [[][:a][:a][]])
rlm@361 550 (scroll-text 3)
rlm@359 551 select-menu-entry
rlm@359 552 select-menu-entry
rlm@359 553 (scroll-text 6)
rlm@359 554 close-menu)))
rlm@362 555
rlm@363 556 (defn-memo to-celadon-poke-center
rlm@362 557 ([] (to-celadon-poke-center (get-TM13)))
rlm@362 558 ([script]
rlm@362 559 (->> script
rlm@362 560 (walk [↑ → → → → → → → → → ↑]) ; leave roof
rlm@362 561 (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ←
rlm@362 562 ↑ ↑ ↑ ← ← ↑]) ; to elevator
rlm@362 563
rlm@362 564 (walk [→ → ↑ ↑]) ; to controls
rlm@362 565 talk
rlm@362 566 select-menu-entry ; to floor 1
rlm@362 567 (walk [↓ ↓ ← ←])
rlm@362 568 (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store
rlm@362 569 (walk [↓ → → → → → → → → → → ↑ ↑])
rlm@362 570 (walk (repeat 23 →))
rlm@362 571 (walk [↑ ↑ ↑ ↑]) ; enter poke center
rlm@362 572 (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer
rlm@362 573 (turn ↑))))
rlm@363 574
rlm@363 575 (defn activate-rlm-pc [script]
rlm@363 576 (->> script
rlm@363 577 talk
rlm@363 578 scroll-text
rlm@363 579 wait-for-cursor
rlm@363 580 (set-cursor 1)
rlm@363 581 select-menu-entry
rlm@363 582 (scroll-text 2)))
rlm@363 583
rlm@363 584 (defn begin-deposit [script]
rlm@363 585 (->> script
rlm@363 586 (set-cursor 1)
rlm@363 587 select-menu-entry))
rlm@363 588
rlm@363 589 (defn begin-withdraw [script]
rlm@363 590 (->> script
rlm@363 591 (set-cursor 0)
rlm@363 592 (select-menu-entry)))
rlm@363 593
rlm@363 594 (defn deposit-held-item-named
rlm@363 595 [item-name quantity [moves state :as script]]
rlm@363 596 (let [index (count
rlm@363 597 (take-while
rlm@363 598 (fn [[name quant]]
rlm@363 599 (or (not= name item-name)
rlm@363 600 (< quant quantity)))
rlm@363 601 (inventory state)))]
rlm@363 602 (println "index" index)
rlm@363 603 (deposit-held-item index quantity script)))
rlm@363 604
rlm@363 605
rlm@363 606 (defn-memo begin-hacking
rlm@363 607 ([] (begin-hacking(to-celadon-poke-center)))
rlm@363 608 ([script]
rlm@363 609 (->> script
rlm@363 610 activate-rlm-pc
rlm@363 611 begin-deposit
rlm@363 612 (deposit-held-item-named 0x00 30)
rlm@363 613 (deposit-held-item-named :TM01 63)
rlm@363 614 (deposit-held-item-named :awakening 4)
rlm@363 615 (deposit-held-item-named :thunderstone 98)
rlm@363 616 (deposit-held-item-named :TM09 55)
rlm@363 617 (deposit-held-item-named 0x00 55))))
rlm@363 618
rlm@363 619 (defn open-held-items
rlm@363 620 [script]
rlm@363 621 (->> script
rlm@363 622 select-menu-entry))
rlm@363 623
rlm@364 624 (defn to-held-items
rlm@364 625 [script]
rlm@364 626 (->> script
rlm@364 627 close-menu
rlm@364 628 close-menu
rlm@364 629 end-text;;; grr
rlm@364 630
rlm@364 631 activate-start-menu
rlm@364 632 open-held-items))
rlm@364 633
rlm@363 634 (defn-memo hacking-2
rlm@363 635 ([] (hacking-2 (begin-hacking)))
rlm@363 636 ([script]
rlm@363 637 (->> script
rlm@364 638 (to-held-items)
rlm@363 639 (toss-held-item 0 166) ;; discard cruft
rlm@363 640 close-menu
rlm@363 641 close-menu)))
rlm@363 642
rlm@363 643 (defn-memo hacking-3
rlm@363 644 ([] (hacking-3 (hacking-2)))
rlm@363 645 ([script]
rlm@363 646 (->> script
rlm@363 647 activate-rlm-pc
rlm@363 648 begin-withdraw
rlm@363 649 (widthdraw-pc-item 0 99)
rlm@363 650 (widthdraw-pc-item 0 1)
rlm@363 651 (widthdraw-pc-item 2 0xFE)
rlm@368 652 (widthdraw-pc-item 3 0xFE)
rlm@368 653 close-menu)))
rlm@363 654
rlm@364 655 (defn-memo hacking-4
rlm@364 656 ([] (hacking-4 (hacking-3)))
rlm@364 657 ([script]
rlm@364 658 (->> script
rlm@364 659 begin-deposit
rlm@364 660 (deposit-held-item 19 243)
rlm@364 661 (deposit-held-item-named :lemonade 16)
rlm@364 662 (deposit-held-item 18 224))))
rlm@364 663
rlm@364 664 (defn-memo hacking-5
rlm@364 665 "clean out the held-item list again"
rlm@364 666 ([] (hacking-5 (hacking-4)))
rlm@364 667 ([script]
rlm@364 668 (->> script
rlm@364 669 (to-held-items)
rlm@364 670 (toss-held-item 18 30)
rlm@364 671 (toss-held-item 17 1)
rlm@364 672 close-menu
rlm@364 673 close-menu)))
rlm@363 674
rlm@364 675 (defn-memo hacking-6
rlm@364 676 ([] (hacking-6 (hacking-5)))
rlm@364 677 ([script]
rlm@364 678 (->> script
rlm@364 679 activate-rlm-pc
rlm@364 680 begin-withdraw
rlm@364 681 (widthdraw-pc-item 4 0xFE)
rlm@364 682 (widthdraw-pc-item 5 0xFE)
rlm@365 683 (widthdraw-pc-item 6 0xFE)
rlm@365 684 close-menu)))
rlm@364 685
rlm@365 686 (defn-memo hacking-7
rlm@365 687 ([] (hacking-7 (hacking-6)))
rlm@365 688 ([script]
rlm@365 689 (->> script
rlm@365 690 begin-deposit
rlm@365 691 (deposit-held-item 19 240)
rlm@365 692 (deposit-held-item 18 230)
rlm@365 693 (deposit-held-item-named :parlyz-heal 55)
rlm@365 694 (deposit-held-item 17 184)
rlm@365 695 (deposit-held-item 17 40)
rlm@365 696 (deposit-held-item-named :TM37 71)
rlm@365 697 (deposit-held-item-named :ice-heal 55)
rlm@365 698 (deposit-held-item-named :fire-stone 23)
rlm@366 699 (deposit-held-item-named :burn-heal 12)
rlm@366 700 close-menu)))
rlm@365 701
rlm@368 702 (defn switch-items [item-fn idx-1 idx-2 script]
rlm@368 703 (->> script
rlm@368 704 (wait-until select-menu-entry)
rlm@368 705 (set-cursor idx-1)
rlm@368 706 (wait-until select-menu-entry)
rlm@368 707 (play-moves [[][:select][]])
rlm@368 708 (set-cursor idx-2)
rlm@368 709 (delayed-difference [] [:select] 100
rlm@368 710 #(item-fn % (list-offset %)))))
rlm@368 711
rlm@368 712 (def switch-pc-items (partial switch-items nth-pc-item))
rlm@368 713 (def switch-held-items (partial switch-items nth-item))
rlm@368 714
rlm@368 715 (defn combine-pc-items [idx-1 script]
rlm@368 716 (->> script
rlm@368 717 (switch-pc-items idx-1 (inc idx-1))))
rlm@368 718
rlm@366 719 (defn combine-items [idx-1 script]
rlm@366 720 (->> script
rlm@366 721 (wait-until select-menu-entry)
rlm@366 722 (set-cursor idx-1)
rlm@366 723 (wait-until select-menu-entry)
rlm@366 724 (play-moves [[][:select][]])
rlm@366 725 (set-cursor-relative 1)
rlm@366 726 (delayed-difference [] [:select] 100
rlm@366 727 #(nth-pc-item % (list-offset %)))))
rlm@366 728
rlm@366 729 (defn-memo hacking-8
rlm@366 730 "Clear cruft away from held item list."
rlm@366 731 ([] (hacking-8 (hacking-7)))
rlm@366 732 ([script]
rlm@366 733 (->> script
rlm@366 734 to-held-items
rlm@366 735 (toss-held-item 15 1)
rlm@366 736 (toss-held-item 14 1)
rlm@366 737 (toss-held-item 13 1)
rlm@366 738 close-menu
rlm@366 739 close-menu)))
rlm@366 740
rlm@366 741 (defn-memo hacking-9
rlm@366 742 ([] (hacking-9 (hacking-8)))
rlm@366 743 ([script]
rlm@366 744 (->> script
rlm@366 745 activate-rlm-pc
rlm@366 746 begin-withdraw
rlm@366 747 (widthdraw-pc-item 7 0xFE)
rlm@366 748 (widthdraw-pc-item 8 0xFC)
rlm@366 749 (widthdraw-pc-item 8 1)
rlm@366 750 (widthdraw-pc-item 8 1)
rlm@366 751 (widthdraw-pc-item 9 0xFE)
rlm@366 752 (multiple-times
rlm@366 753 7
rlm@368 754 (partial combine-pc-items 2))
rlm@366 755 close-menu)))
rlm@366 756
rlm@366 757 (defn-memo hacking-10
rlm@366 758 ([] (hacking-10 (hacking-9)))
rlm@366 759 ([script]
rlm@366 760 (->> script
rlm@366 761 begin-deposit
rlm@366 762 (deposit-held-item 17 230)
rlm@366 763 (deposit-held-item-named :parlyz-heal 55)
rlm@366 764 (deposit-held-item 14 178)
rlm@366 765 (deposit-held-item-named :water-stone 29)
rlm@366 766 (deposit-held-item 14 32)
rlm@366 767 (deposit-held-item-named :TM18 1)
rlm@366 768 (deposit-held-item 13 1)
rlm@366 769 (deposit-held-item 13 191)
rlm@366 770 (deposit-held-item-named :TM02 98)
rlm@366 771 (deposit-held-item-named :TM09 1)
rlm@367 772 close-menu
rlm@366 773 close-menu)))
rlm@366 774
rlm@366 775 (defn-memo hacking-11
rlm@366 776 ([] (hacking-11 (hacking-10)))
rlm@366 777 ([script]
rlm@366 778 (->> script
rlm@367 779 begin-withdraw
rlm@367 780 (widthdraw-pc-item 3 0xFE)
rlm@367 781 (widthdraw-pc-item 4 0xFE)
rlm@367 782 (widthdraw-pc-item 5 1)
rlm@367 783 (widthdraw-pc-item 5 1)
rlm@367 784 (widthdraw-pc-item 5 1)
rlm@367 785 (widthdraw-pc-item 5 0xFB)
rlm@367 786 (multiple-times
rlm@367 787 3
rlm@367 788 (partial combine-items 2))
rlm@367 789 close-menu)))
rlm@367 790
rlm@367 791 (defn-memo hacking-12
rlm@367 792 ([] (hacking-12 (hacking-11)))
rlm@367 793 ([script]
rlm@367 794 (->> script
rlm@367 795 begin-deposit
rlm@367 796 (deposit-held-item 18 203)
rlm@367 797 (deposit-held-item-named :guard-spec 87)
rlm@367 798 (deposit-held-item-named :guard-spec 24)
rlm@367 799 (deposit-held-item-named :TM05 1)
rlm@367 800 (multiple-times
rlm@367 801 8
rlm@367 802 (partial deposit-held-item 14 2))
rlm@367 803 (deposit-held-item 14 55)
rlm@367 804 (deposit-held-item-named :x-accuracy 58)
rlm@367 805 (deposit-held-item 14 38)
rlm@367 806 (deposit-held-item-named :TM13 1)
rlm@367 807 (deposit-held-item 13 1)
rlm@367 808 (deposit-held-item 13 233)
rlm@366 809 close-menu
rlm@366 810 close-menu)))
rlm@367 811
rlm@367 812
rlm@367 813 (defn toss-pc-item [n quantity [moves state :as script]]
rlm@367 814 (let [total-quantity (second (nth-pc-item state n))]
rlm@367 815 (->> script
rlm@367 816 (set-cursor n)
rlm@367 817 (select-menu-entry 1)
rlm@367 818 (wait-for-quantity)
rlm@367 819 (set-quantity total-quantity quantity)
rlm@367 820 (delayed-difference [] [:a] 100 #(search-string % "Is"))
rlm@367 821 (scroll-text)
rlm@367 822 select-menu-entry
rlm@367 823 (scroll-text))))
rlm@367 824
rlm@368 825 (defn-memo hacking-13
rlm@367 826 ([] (hacking-13 (hacking-12)))
rlm@367 827 ([script]
rlm@367 828 (->> script
rlm@367 829 (set-cursor-relative 1)
rlm@367 830 (select-menu-entry)
rlm@367 831 (toss-pc-item 1 1)
rlm@367 832 (toss-pc-item 0 156)
rlm@368 833 (toss-pc-item 0 11))))
rlm@368 834
rlm@368 835 (defn confirm-pattern []
rlm@368 836 (let [start-address (inc pc-item-list-start)
rlm@368 837 target-pattern (pc-item-writer-program)
rlm@368 838 actual-pattern
rlm@368 839 (subvec (vec (memory (second (hacking-13))))
rlm@368 840 start-address
rlm@368 841 (+ start-address (count target-pattern)))]
rlm@368 842 (println target-pattern)
rlm@368 843 (println actual-pattern)
rlm@368 844 (= target-pattern actual-pattern)))
rlm@368 845
rlm@368 846 ;; this will be useful for starting program
rlm@368 847
rlm@368 848
rlm@368 849 (defn-memo go-to-mansion-for-the-lulz
rlm@368 850 ([] (go-to-mansion-for-the-lulz (hacking-13)))
rlm@368 851 ([script]
rlm@368 852 (->> script
rlm@368 853 close-menu
rlm@368 854 close-menu
rlm@368 855 end-text ;;grr
rlm@368 856 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])
rlm@368 857 (walk (repeat 17 ←))
rlm@368 858 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])
rlm@368 859 (walk [↓ ← ↑])
rlm@368 860 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓
rlm@368 861 ← ← ← ← ↑ ↑ ↑ ← ↑])
rlm@368 862 (talk)
rlm@368 863 (scroll-text 2)
rlm@367 864 close-menu)))
rlm@367 865
rlm@368 866 (defn get-cursor [script]
rlm@368 867 (wait-until (partial set-cursor-relative 1) script))
rlm@368 868
rlm@368 869 (defn-memo launch-bootstrap-program
rlm@368 870 ([] (launch-bootstrap-program
rlm@368 871 (go-to-mansion-for-the-lulz)))
rlm@368 872 ([script]
rlm@368 873 (->> script
rlm@368 874 ;; must corrupt item list again by switching pokemon
rlm@368 875 activate-start-menu
rlm@368 876 ;;get-cursor
rlm@368 877 (set-cursor 0)
rlm@368 878 select-menu-entry
rlm@368 879 ;;get-cursor
rlm@368 880 (select-menu-entry)
rlm@368 881 ;;get-cursor
rlm@368 882 (set-cursor 1)
rlm@368 883 (select-menu-entry)
rlm@368 884 ;;get-cursor
rlm@368 885 (set-cursor 3)
rlm@368 886 (delayed-difference [] [:a] 50 first-character)
rlm@368 887 close-menu
rlm@368 888 ;; now, open items and set map-function
rlm@368 889 ;;get-cursor
rlm@368 890 (set-cursor 1)
rlm@368 891 (select-menu-entry)
rlm@368 892 (toss-held-item 22 12)
rlm@368 893 (switch-held-items 22 40)
rlm@368 894 close-all-menus)))
rlm@367 895
rlm@367 896
rlm@367 897
rlm@368 898