# HG changeset patch # User Robert McIntyre # Date 1332216861 18000 # Node ID 06426d25c65b7cd50944319be6fd3fe3c518ecb9 # Parent 279e9ee6fccb3bcb60b53ac46e4dc562cd13f21e can now get/set pokemon OT name diff -r 279e9ee6fccb -r 06426d25c65b clojure/com/aurellem/exp/pokemon.clj --- a/clojure/com/aurellem/exp/pokemon.clj Mon Mar 19 22:42:36 2012 -0500 +++ b/clojure/com/aurellem/exp/pokemon.clj Mon Mar 19 23:14:21 2012 -0500 @@ -92,14 +92,14 @@ (def max-name-length 10) (def name-width 11) -(defn read-pokemon-name [codes] +(defn read-name [codes] (character-codes->str (take-while (partial not= end-of-name-marker) codes))) (defn sixth-pokemon-name [^SaveState state] - (read-pokemon-name + (read-name (subvec (vec (memory state)) sixth-pokemon-name-start (+ (inc max-name-length) @@ -127,16 +127,12 @@ ([begin end] (print-text @current-state begin end))) - - - (defn examine-name-memory [] (print-text named-A (- sixth-pokemon-name-start 100) (+ sixth-pokemon-name-start 100))) - ;; results: ;; 0xD287: end-of-name-sentinel ;; 0xD288: R @@ -436,13 +432,62 @@ (subvec (vec (memory state)) pokemon-names-start (+ pokemon-names-start - (* name-width 6)))] + (* name-width 6)))] (map - read-pokemon-name + read-name (take (party-number state) (partition name-width raw-names))))) ([] (party-names @current-state))) - \ No newline at end of file + +(defn rename-pokemon + ([^SaveState state n new-name] + (assert (<= 0 n (dec (party-number state)))) + (assert (<= (count new-name) max-name-length)) + (set-memory-range + state + (+ (* n name-width) pokemon-names-start) + (concat (str->character-codes new-name) [end-of-name-marker]))) + ([n new-name] + (rename-pokemon @current-state n new-name))) + + +;; on further analysis, it appears that the original +;; trainer info for each pokemon is also stored together, +;; starting at 0xD272 and continuing to 0xD2B3, with +;; 11 bytes reserved for each OT name. + +(def OT-start 0xD272) + +(defn original-trainers + ([^SaveState state] + (let [raw-names + (subvec (vec (memory state)) + OT-start + (+ OT-start + (* name-width 6)))] + (map read-name + (take (party-number state) + (partition name-width raw-names))))) + ([] (original-trainers @current-state))) + +(defn set-original-trainer + "Set the OT name for a pokemon. + Note that a pokemon is still considered 'yours' if + the OT ID is the same as your own." + ([^SaveState state n new-name] + (assert (<= 0 n (dec (party-number state)))) + (assert (<= (count new-name) max-name-length)) + (set-memory-range + state + (+ (* n name-width) OT-start) + (concat (str->character-codes new-name) [end-of-name-marker]))) + ([n new-name] + (set-original-trainer @current-state n new-name))) + +;; PIKACHU stops following if you set it's OT to another name +;; and then back to you own. +;; But not if you set it to your own name, obviously. + \ No newline at end of file diff -r 279e9ee6fccb -r 06426d25c65b clojure/com/aurellem/gb/characters.clj --- a/clojure/com/aurellem/gb/characters.clj Mon Mar 19 22:42:36 2012 -0500 +++ b/clojure/com/aurellem/gb/characters.clj Mon Mar 19 23:14:21 2012 -0500 @@ -79,6 +79,7 @@ 0xE0 "'" 0xE1 "PK" 0xE2 "MN" + 0xE3 "-" 0xE6 "?" 0xE7 "!" 0xE8 "."