changeset 170:09caf6a5bbf4

added facilities to corrupt any state.
author Robert McIntyre <rlm@mit.edu>
date Wed, 21 Mar 2012 03:18:20 -0500
parents 4857f59f63a6
children d7e2cfecef1d
files clojure/com/aurellem/exp/item_bridge.clj clojure/com/aurellem/run/save_corruption.clj clojure/com/aurellem/run/title.clj save-states/mid-game.sav
diffstat 4 files changed, 96 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/exp/item_bridge.clj	Wed Mar 21 01:37:10 2012 -0500
     1.2 +++ b/clojure/com/aurellem/exp/item_bridge.clj	Wed Mar 21 03:18:20 2012 -0500
     1.3 @@ -1,20 +1,19 @@
     1.4 -(ns com.aurellem.item-bridge
     1.5 -  (:use (com.aurellem.gb gb-driver vbm title save-corruption items assembly))
     1.6 +(ns com.aurellem.exp.item-bridge
     1.7 +  (:use (com.aurellem.gb util constants gb-driver vbm items assembly))
     1.8 +  (:use (com.aurellem.run title save-corruption))
     1.9 +  (:use (com.aurellem.exp pokemon))
    1.10    (:import [com.aurellem.gb.gb_driver SaveState]))
    1.11  
    1.12 -
    1.13  (defn corrupt-item-state []
    1.14    (second (destroy-item-end-of-list-marker)))
    1.15  
    1.16  (defn corrupt-item-state []
    1.17    (read-state "corrupt-items"))
    1.18  
    1.19 -
    1.20  (defn view-memory-range [state start end]
    1.21    (dorun
    1.22     (map (fn [loc val]
    1.23            (println (format "%04X : %02X" loc val)))
    1.24 -        
    1.25          (range start end) (subvec (vec (memory state)) start end)))
    1.26    state)
    1.27  
    1.28 @@ -27,13 +26,11 @@
    1.29                          (subvec (vec (memory (mid-game)))
    1.30                                  (+ item-list-start 65)
    1.31                                  (+ item-list-start 65 n))
    1.32 -                        (repeat (- 255 65 n) 0x03)
    1.33 -                        ))
    1.34 -                
    1.35 +                        (repeat (- 255 65 n) 0x03)))
    1.36     item-list-start (+ item-list-start 255)))
    1.37  
    1.38  (defn actually-broken
    1.39 -  "if one more memory location is turned into 0x03, the game crashes."
    1.40 +  "if this memory location is turned into 0x03, the game crashes."
    1.41    []
    1.42    (set-memory (mid-game) 0xD35D 0x03))
    1.43  
    1.44 @@ -63,3 +60,87 @@
    1.45          (com.aurellem.gb.Gb/tick)
    1.46          (recur (inc i)
    1.47                 (conj pcs (first (registers))))))))
    1.48 +
    1.49 +(defn loop-program []
    1.50 +  [0xF3     ;0xD31D  ;; disable-interrupts
    1.51 +
    1.52 +   0xC3     ;; loop forever
    1.53 +   0x1D
    1.54 +   0xD3])
    1.55 +
    1.56 +(def map-function-address-start 0xD36D)
    1.57 +
    1.58 +(defn test-loop []
    1.59 +  (capture-program-counter
    1.60 +   (-> (mid-game) 
    1.61 +       (set-memory-range 0xD31D (loop-program))
    1.62 +       (set-memory-range
    1.63 +        map-function-address-start
    1.64 +        [0xD3 0x1D])
    1.65 +       (IE! 0))
    1.66 +   1000))
    1.67 +
    1.68 +
    1.69 +(defn-memo corrupt-moves []
    1.70 +  (concat
    1.71 +   (first
    1.72 +    (->>
    1.73 +     [[] (mid-game)]
    1.74 +     (advance [:b] [:b :start])
    1.75 +     (advance [] [:d])
    1.76 +     (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])
    1.77 +     scroll-text
    1.78 +     (play-moves
    1.79 +      ;; this section is copied from speedrun-2942
    1.80 +      ;; and corrupts the save so that the end-of-list marker
    1.81 +      ;; for the pokemon roster is destroyed, but the save is still
    1.82 +      ;; playable.
    1.83 +      [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
    1.84 +       [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
    1.85 +     (play-moves
    1.86 +      (first (title)))
    1.87 +     (advance [] [:start])
    1.88 +     (advance [] [:a])
    1.89 +     (advance [:a] [:a :start])))
    1.90 +   [[]]))
    1.91 +  
    1.92 +
    1.93 +
    1.94 +(defn corrupt
    1.95 +  "enter the codes to destroy the
    1.96 +   pokemon list using save corruption"
    1.97 +  ([^SaveState state]
    1.98 +  (run-moves
    1.99 +   state
   1.100 +   (corrupt-moves)))
   1.101 +    
   1.102 +
   1.103 +
   1.104 +   
   1.105 +  (step 
   1.106 +  (second 
   1.107 +   (->>
   1.108 +    [[] state]
   1.109 +    (advance [:b] [:a :b :start])
   1.110 +    (advance [] [:d])
   1.111 +    (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])
   1.112 +    scroll-text
   1.113 +    (play-moves
   1.114 +     ;; this section is copied from speedrun-2942
   1.115 +     ;; and corrupts the save so that the end-of-list marker
   1.116 +     ;; for the pokemon roster is destroyed, but the save is still
   1.117 +     ;; playable.
   1.118 +     [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   1.119 +      [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])
   1.120 +    (play-moves
   1.121 +     (first (title)))
   1.122 +    (advance [] [:start])
   1.123 +    (advance [] [:a])
   1.124 +    (advance [:a] [:a :start]))) []))
   1.125 +  
   1.126 +   
   1.127 +
   1.128 +             
   1.129 +
   1.130 +
   1.131 +
     2.1 --- a/clojure/com/aurellem/run/save_corruption.clj	Wed Mar 21 01:37:10 2012 -0500
     2.2 +++ b/clojure/com/aurellem/run/save_corruption.clj	Wed Mar 21 03:18:20 2012 -0500
     2.3 @@ -1,5 +1,6 @@
     2.4 -(ns com.aurellem.save-corruption
     2.5 -  (:use (com.aurellem gb-driver vbm title)))
     2.6 +(ns com.aurellem.run.save-corruption
     2.7 +  (:use (com.aurellem.gb gb-driver vbm))
     2.8 +  (:use (com.aurellem.run title)))
     2.9  
    2.10  (use 'clojure.repl)
    2.11  
    2.12 @@ -84,7 +85,7 @@
    2.13          [] [] [] [] [] [] [] [] [] [] []
    2.14  
    2.15          ;; [:b] [] [] [] [] [] [] [] []
    2.16 -        ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
    2.17 +        ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [] [][][][][] [] []
    2.18          ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [:d] [] [] [:a] [] []
    2.19          ;; [] [] [] [] [] [] [] [] [] [] [] [] [] [:d] [] [] [] [:d] []
    2.20          ])))
     3.1 --- a/clojure/com/aurellem/run/title.clj	Wed Mar 21 01:37:10 2012 -0500
     3.2 +++ b/clojure/com/aurellem/run/title.clj	Wed Mar 21 03:18:20 2012 -0500
     3.3 @@ -1,5 +1,5 @@
     3.4 -(ns com.aurellem.title
     3.5 -  (:use (com.aurellem gb-driver vbm)))
     3.6 +(ns com.aurellem.run.title
     3.7 +  (:use (com.aurellem.gb gb-driver vbm)))
     3.8  
     3.9  (defn first-difference [base alt summary root]
    3.10    (loop [branch-point root
     4.1 Binary file save-states/mid-game.sav has changed