rlm@170
|
1 (ns com.aurellem.exp.item-bridge
|
rlm@170
|
2 (:use (com.aurellem.gb util constants gb-driver vbm items assembly))
|
rlm@170
|
3 (:use (com.aurellem.run title save-corruption))
|
rlm@170
|
4 (:use (com.aurellem.exp pokemon))
|
rlm@154
|
5 (:import [com.aurellem.gb.gb_driver SaveState]))
|
rlm@130
|
6
|
rlm@131
|
7 (defn corrupt-item-state []
|
rlm@131
|
8 (second (destroy-item-end-of-list-marker)))
|
rlm@131
|
9
|
rlm@131
|
10 (defn corrupt-item-state []
|
rlm@131
|
11 (read-state "corrupt-items"))
|
rlm@131
|
12
|
rlm@133
|
13 (defn view-memory-range [state start end]
|
rlm@133
|
14 (dorun
|
rlm@133
|
15 (map (fn [loc val]
|
rlm@133
|
16 (println (format "%04X : %02X" loc val)))
|
rlm@133
|
17 (range start end) (subvec (vec (memory state)) start end)))
|
rlm@133
|
18 state)
|
rlm@131
|
19
|
rlm@133
|
20 (defn almost-broken
|
rlm@133
|
21 "if one more memory location is turned into 0x03, the game crashes."
|
rlm@133
|
22 [n]
|
rlm@133
|
23 (view-memory-range
|
rlm@133
|
24 (set-inv-mem (mid-game)
|
rlm@133
|
25 (concat [0xFF] (repeat 64 0x03)
|
rlm@133
|
26 (subvec (vec (memory (mid-game)))
|
rlm@133
|
27 (+ item-list-start 65)
|
rlm@133
|
28 (+ item-list-start 65 n))
|
rlm@170
|
29 (repeat (- 255 65 n) 0x03)))
|
rlm@133
|
30 item-list-start (+ item-list-start 255)))
|
rlm@131
|
31
|
rlm@133
|
32 (defn actually-broken
|
rlm@170
|
33 "if this memory location is turned into 0x03, the game crashes."
|
rlm@133
|
34 []
|
rlm@133
|
35 (set-memory (mid-game) 0xD35D 0x03))
|
rlm@131
|
36
|
rlm@131
|
37
|
rlm@133
|
38 ;; (almost-broken 20) more or less works
|
rlm@133
|
39
|
rlm@133
|
40 (defn capture-program-counter
|
rlm@133
|
41 "records the program counter for each tick"
|
rlm@133
|
42 [^SaveState state ticks]
|
rlm@133
|
43 (let [i (atom 0)]
|
rlm@133
|
44 (reduce (fn [[program-counters state] _]
|
rlm@133
|
45 (println (swap! i inc))
|
rlm@133
|
46 [(conj program-counters (PC state))
|
rlm@133
|
47 (tick state)])
|
rlm@133
|
48 [[] state]
|
rlm@133
|
49 (range ticks))))
|
rlm@133
|
50
|
rlm@133
|
51
|
rlm@133
|
52 (defn capture-program-counter
|
rlm@133
|
53 [^SaveState state ticks]
|
rlm@133
|
54 (set-state! state)
|
rlm@133
|
55 (loop [i 0
|
rlm@133
|
56 pcs []]
|
rlm@133
|
57 (if (= i ticks)
|
rlm@133
|
58 pcs
|
rlm@133
|
59 (do
|
rlm@133
|
60 (com.aurellem.gb.Gb/tick)
|
rlm@133
|
61 (recur (inc i)
|
rlm@133
|
62 (conj pcs (first (registers))))))))
|
rlm@170
|
63
|
rlm@170
|
64 (defn loop-program []
|
rlm@170
|
65 [0xF3 ;0xD31D ;; disable-interrupts
|
rlm@170
|
66
|
rlm@170
|
67 0xC3 ;; loop forever
|
rlm@170
|
68 0x1D
|
rlm@170
|
69 0xD3])
|
rlm@170
|
70
|
rlm@170
|
71 (def map-function-address-start 0xD36D)
|
rlm@170
|
72
|
rlm@170
|
73 (defn test-loop []
|
rlm@170
|
74 (capture-program-counter
|
rlm@170
|
75 (-> (mid-game)
|
rlm@170
|
76 (set-memory-range 0xD31D (loop-program))
|
rlm@170
|
77 (set-memory-range
|
rlm@170
|
78 map-function-address-start
|
rlm@170
|
79 [0xD3 0x1D])
|
rlm@170
|
80 (IE! 0))
|
rlm@170
|
81 1000))
|
rlm@170
|
82
|
rlm@170
|
83
|
rlm@170
|
84 (defn-memo corrupt-moves []
|
rlm@170
|
85 (concat
|
rlm@170
|
86 (first
|
rlm@170
|
87 (->>
|
rlm@170
|
88 [[] (mid-game)]
|
rlm@170
|
89 (advance [:b] [:b :start])
|
rlm@170
|
90 (advance [] [:d])
|
rlm@170
|
91 (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])
|
rlm@170
|
92 scroll-text
|
rlm@170
|
93 (play-moves
|
rlm@170
|
94 ;; this section is copied from speedrun-2942
|
rlm@170
|
95 ;; and corrupts the save so that the end-of-list marker
|
rlm@170
|
96 ;; for the pokemon roster is destroyed, but the save is still
|
rlm@170
|
97 ;; playable.
|
rlm@170
|
98 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
|
rlm@170
|
99 [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
|
rlm@170
|
100 (play-moves
|
rlm@170
|
101 (first (title)))
|
rlm@170
|
102 (advance [] [:start])
|
rlm@170
|
103 (advance [] [:a])
|
rlm@170
|
104 (advance [:a] [:a :start])))
|
rlm@170
|
105 [[]]))
|
rlm@170
|
106
|
rlm@170
|
107
|
rlm@170
|
108
|
rlm@170
|
109 (defn corrupt
|
rlm@170
|
110 "enter the codes to destroy the
|
rlm@170
|
111 pokemon list using save corruption"
|
rlm@170
|
112 ([^SaveState state]
|
rlm@170
|
113 (run-moves
|
rlm@170
|
114 state
|
rlm@170
|
115 (corrupt-moves)))
|
rlm@171
|
116 ([] (corrupt @current-state)))
|
rlm@170
|
117
|
rlm@170
|
118
|
rlm@170
|
119
|
rlm@170
|
120
|
rlm@170
|
121
|
rlm@170
|
122
|
rlm@170
|
123
|