annotate clojure/com/aurellem/exp/pokemon.clj @ 158:339220ab3f5d

finally found the species identifiers!
author Robert McIntyre <rlm@mit.edu>
date Tue, 20 Mar 2012 03:40:24 -0500
parents 9367bb5e55e6
children 9ca350a476f0
rev   line source
rlm@145 1 (ns com.aurellem.exp.pokemon
rlm@145 2 "Here I find out how pokemon are stored in memory."
rlm@145 3 (:use (com.aurellem.gb gb-driver items assembly util
rlm@145 4 characters))
rlm@145 5 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@145 6
rlm@145 7
rlm@145 8 (def pidgeot-lvl-36 (mid-game))
rlm@145 9
rlm@145 10
rlm@145 11 (def pidgeot-lvl-37 (read-state "pidgeot-lvl-37"))
rlm@145 12
rlm@145 13
rlm@145 14 (def pidgeot-lvl-38 (read-state "pidgeot-lvl-38"))
rlm@145 15
rlm@145 16
rlm@145 17 (def pidgeot-lvl-39 (read-state "pidgeot-lvl-39"))
rlm@145 18
rlm@145 19
rlm@145 20 (def pidgeot-lvl-40 (read-state "pidgeot-lvl-40"))
rlm@145 21
rlm@145 22
rlm@145 23 (defn level-analysis []
rlm@145 24 (apply common-differences
rlm@145 25 (map (comp vec memory)
rlm@145 26 [pidgeot-lvl-36
rlm@145 27 pidgeot-lvl-37
rlm@145 28 pidgeot-lvl-38
rlm@145 29 pidgeot-lvl-39
rlm@145 30 pidgeot-lvl-40])))
rlm@145 31
rlm@145 32 ;; inconclusive -- implies that level is calculated from
rlm@145 33 ;; some other values.
rlm@145 34
rlm@145 35
rlm@145 36 (def name-pidgeotto (read-state "name-pidgeotto"))
rlm@145 37 (def named-A (read-state "named-A"))
rlm@145 38 (def named-B (read-state "named-B"))
rlm@145 39 (def named-C (read-state "named-C"))
rlm@145 40 (def named-D (read-state "named-D"))
rlm@145 41 (def named-E (read-state "named-E"))
rlm@145 42 (def named-F (read-state "named-F"))
rlm@145 43
rlm@145 44 (defn name-analysis []
rlm@145 45 (apply common-differences
rlm@145 46 (map (comp vec memory)
rlm@145 47 [named-A
rlm@145 48 named-B
rlm@145 49 named-C
rlm@145 50 named-D
rlm@145 51 named-E
rlm@145 52 named-F])))
rlm@145 53
rlm@145 54 ;; resluted in 3 separate locations that could
rlm@145 55 ;; possibly hold the first letter of the pokemon's name
rlm@145 56
rlm@145 57 0xCF4A
rlm@145 58 0xD2EB
rlm@145 59 0xCEED
rlm@145 60
rlm@145 61 ;; try changing each of them
rlm@145 62
rlm@145 63
rlm@145 64 (defn test-cf4a []
rlm@145 65 (continue!
rlm@145 66 (set-memory named-A 0xCF4A (character->character-code "Z"))))
rlm@145 67 ;; result -- pidgeotto named "A"
rlm@145 68
rlm@145 69 (defn test-d2eb []
rlm@145 70 (continue!
rlm@145 71 (set-memory named-A 0xD2EB (character->character-code "Z"))))
rlm@145 72 ;; result -- pidgeotto named "Z"
rlm@145 73
rlm@145 74 (defn test-ceed []
rlm@145 75 (continue!
rlm@145 76 (set-memory named-A 0xCEED (character->character-code "Z"))))
rlm@145 77 ;; result -- pidgeotto named "A"
rlm@145 78
rlm@145 79 (def sixth-pokemon-name-start 0xD2EB)
rlm@145 80
rlm@145 81
rlm@145 82 (defn set-sixth-pokemon-name-first-character
rlm@145 83 ([state character]
rlm@145 84 (set-memory state sixth-pokemon-name-start
rlm@145 85 (character->character-code character)))
rlm@145 86 ([character]
rlm@145 87 (set-sixth-pokemon-name-first-character @current-state
rlm@145 88 character)))
rlm@145 89
rlm@145 90
rlm@146 91 (def end-of-name-marker 0x50)
rlm@147 92 (def max-name-length 10)
rlm@147 93 (def name-width 11)
rlm@147 94
rlm@148 95 (defn read-name [codes]
rlm@147 96 (character-codes->str
rlm@147 97 (take-while
rlm@147 98 (partial not= end-of-name-marker) codes)))
rlm@147 99
rlm@145 100
rlm@146 101 (defn sixth-pokemon-name [^SaveState state]
rlm@148 102 (read-name
rlm@146 103 (subvec (vec (memory state))
rlm@146 104 sixth-pokemon-name-start
rlm@146 105 (+ (inc max-name-length)
rlm@147 106 sixth-pokemon-name-start))))
rlm@145 107
rlm@147 108 (defn rename-sixth-pokemon
rlm@147 109 ([^SaveState state new-name]
rlm@147 110 (assert (< (count new-name) max-name-length))
rlm@147 111 (set-memory-range state sixth-pokemon-name-start
rlm@147 112 (concat (str->character-codes new-name)
rlm@147 113 [end-of-name-marker])))
rlm@147 114 ([new-name]
rlm@147 115 (rename-sixth-pokemon @current-state new-name)))
rlm@147 116
rlm@147 117 (defn print-text
rlm@147 118 ([^SaveState state begin end]
rlm@147 119 (dorun
rlm@147 120 (map (fn [character-code line]
rlm@147 121 (println
rlm@147 122 (format "0x%04X: " line)
rlm@149 123 (str (character-code->character character-code))))
rlm@147 124 (subvec (vec (memory state)) begin end)
rlm@147 125 (range begin end)))
rlm@147 126 state)
rlm@147 127 ([begin end]
rlm@147 128 (print-text @current-state begin end)))
rlm@147 129
rlm@147 130 (defn examine-name-memory []
rlm@147 131 (print-text
rlm@147 132 named-A
rlm@147 133 (- sixth-pokemon-name-start 100)
rlm@147 134 (+ sixth-pokemon-name-start 100)))
rlm@147 135
rlm@147 136 ;; results:
rlm@147 137 ;; 0xD287: end-of-name-sentinel
rlm@147 138 ;; 0xD288: R
rlm@147 139 ;; 0xD289: L
rlm@147 140 ;; 0xD28A: M
rlm@147 141 ;; 0xD28B: end-of-pokemon-name-sentinel
rlm@147 142 ;; 0xD28C: end-of-name-sentinel
rlm@147 143 ;; 0xD28D: end-of-name-sentinel
rlm@147 144 ;; 0xD28E: end-of-name-sentinel
rlm@147 145 ;; 0xD28F: end-of-name-sentinel
rlm@147 146 ;; 0xD290: end-of-name-sentinel
rlm@147 147 ;; 0xD291: end-of-name-sentinel
rlm@147 148 ;; 0xD292: end-of-name-sentinel
rlm@147 149 ;; 0xD293: R
rlm@147 150 ;; 0xD294: L
rlm@147 151 ;; 0xD295: M
rlm@147 152 ;; 0xD296: end-of-pokemon-name-sentinel
rlm@147 153 ;; 0xD297: end-of-name-sentinel
rlm@147 154 ;; 0xD298: end-of-name-sentinel
rlm@147 155 ;; 0xD299: end-of-name-sentinel
rlm@147 156 ;; 0xD29A: end-of-name-sentinel
rlm@147 157 ;; 0xD29B: end-of-name-sentinel
rlm@147 158 ;; 0xD29C: end-of-name-sentinel
rlm@147 159 ;; 0xD29D: end-of-name-sentinel
rlm@147 160 ;; 0xD29E: R
rlm@147 161 ;; 0xD29F: L
rlm@147 162 ;; 0xD2A0: M
rlm@147 163 ;; 0xD2A1: end-of-pokemon-name-sentinel
rlm@147 164 ;; 0xD2A2: end-of-name-sentinel
rlm@147 165 ;; 0xD2A3: end-of-name-sentinel
rlm@147 166 ;; 0xD2A4: end-of-name-sentinel
rlm@147 167 ;; 0xD2A5: end-of-name-sentinel
rlm@147 168 ;; 0xD2A6: end-of-name-sentinel
rlm@147 169 ;; 0xD2A7: end-of-name-sentinel
rlm@147 170 ;; 0xD2A8: end-of-name-sentinel
rlm@147 171 ;; 0xD2A9: R
rlm@147 172 ;; 0xD2AA: L
rlm@147 173 ;; 0xD2AB: M
rlm@147 174 ;; 0xD2AC: end-of-pokemon-name-sentinel
rlm@147 175 ;; 0xD2AD: end-of-name-sentinel
rlm@147 176 ;; 0xD2AE: end-of-name-sentinel
rlm@147 177 ;; 0xD2AF: end-of-name-sentinel
rlm@147 178 ;; 0xD2B0: end-of-name-sentinel
rlm@147 179 ;; 0xD2B1: end-of-name-sentinel
rlm@147 180 ;; 0xD2B2: end-of-name-sentinel
rlm@147 181 ;; 0xD2B3: end-of-name-sentinel
rlm@147 182 ;; 0xD2B4: P
rlm@147 183 ;; 0xD2B5: I
rlm@147 184 ;; 0xD2B6: D
rlm@147 185 ;; 0xD2B7: G
rlm@147 186 ;; 0xD2B8: E
rlm@147 187 ;; 0xD2B9: O
rlm@147 188 ;; 0xD2BA: T
rlm@147 189 ;; 0xD2BB: end-of-pokemon-name-sentinel
rlm@147 190 ;; 0xD2BC: end-of-pokemon-name-sentinel
rlm@147 191 ;; 0xD2BD: end-of-pokemon-name-sentinel
rlm@147 192 ;; 0xD2BE: end-of-pokemon-name-sentinel
rlm@147 193 ;; 0xD2BF: P
rlm@147 194 ;; 0xD2C0: I
rlm@147 195 ;; 0xD2C1: K
rlm@147 196 ;; 0xD2C2: A
rlm@147 197 ;; 0xD2C3: C
rlm@147 198 ;; 0xD2C4: H
rlm@147 199 ;; 0xD2C5: U
rlm@147 200 ;; 0xD2C6: end-of-pokemon-name-sentinel
rlm@147 201 ;; 0xD2C7: end-of-pokemon-name-sentinel
rlm@147 202 ;; 0xD2C8: end-of-pokemon-name-sentinel
rlm@147 203 ;; 0xD2C9: end-of-pokemon-name-sentinel
rlm@147 204 ;; 0xD2CA: C
rlm@147 205 ;; 0xD2CB: H
rlm@147 206 ;; 0xD2CC: A
rlm@147 207 ;; 0xD2CD: R
rlm@147 208 ;; 0xD2CE: I
rlm@147 209 ;; 0xD2CF: Z
rlm@147 210 ;; 0xD2D0: A
rlm@147 211 ;; 0xD2D1: R
rlm@147 212 ;; 0xD2D2: D
rlm@147 213 ;; 0xD2D3: end-of-pokemon-name-sentinel
rlm@147 214 ;; 0xD2D4: end-of-pokemon-name-sentinel
rlm@147 215 ;; 0xD2D5: V
rlm@147 216 ;; 0xD2D6: E
rlm@147 217 ;; 0xD2D7: N
rlm@147 218 ;; 0xD2D8: U
rlm@147 219 ;; 0xD2D9: S
rlm@147 220 ;; 0xD2DA: A
rlm@147 221 ;; 0xD2DB: U
rlm@147 222 ;; 0xD2DC: R
rlm@147 223 ;; 0xD2DD: end-of-pokemon-name-sentinel
rlm@147 224 ;; 0xD2DE: end-of-pokemon-name-sentinel
rlm@147 225 ;; 0xD2DF: end-of-pokemon-name-sentinel
rlm@147 226 ;; 0xD2E0: P
rlm@147 227 ;; 0xD2E1: R
rlm@147 228 ;; 0xD2E2: I
rlm@147 229 ;; 0xD2E3: M
rlm@147 230 ;; 0xD2E4: E
rlm@147 231 ;; 0xD2E5: A
rlm@147 232 ;; 0xD2E6: P
rlm@147 233 ;; 0xD2E7: E
rlm@147 234 ;; 0xD2E8: end-of-pokemon-name-sentinel
rlm@147 235 ;; 0xD2E9: end-of-pokemon-name-sentinel
rlm@147 236 ;; 0xD2EA: end-of-pokemon-name-sentinel
rlm@147 237 ;; 0xD2EB: A
rlm@147 238 ;; 0xD2EC: end-of-pokemon-name-sentinel
rlm@147 239 ;; 0xD2ED: S
rlm@147 240 ;; 0xD2EE: T
rlm@147 241 ;; 0xD2EF: E
rlm@147 242 ;; 0xD2F0: R
rlm@147 243 ;; 0xD2F1:
rlm@147 244 ;; 0xD2F2: B
rlm@147 245 ;; 0xD2F3: A
rlm@147 246 ;; 0xD2F4: L
rlm@147 247 ;; 0xD2F5: L
rlm@147 248 ;; 0xD2F6:
rlm@147 249 ;; 0xD2F7: A
rlm@147 250 ;; 0xD2F8:
rlm@147 251 ;; 0xD2F9:
rlm@147 252 ;; 0xD2FA: end-of-name-sentinel
rlm@147 253 ;; 0xD2FB: end-of-name-sentinel
rlm@147 254 ;; 0xD2FC: A
rlm@147 255 ;; 0xD2FD:
rlm@147 256 ;; 0xD2FE: end-of-name-sentinel
rlm@147 257 ;; 0xD2FF: end-of-name-sentinel
rlm@147 258 ;; 0xD300: end-of-name-sentinel
rlm@147 259 ;; 0xD301: end-of-name-sentinel
rlm@147 260 ;; 0xD302: end-of-name-sentinel
rlm@147 261 ;; 0xD303: end-of-name-sentinel
rlm@147 262 ;; 0xD304: end-of-name-sentinel
rlm@147 263 ;; 0xD305: end-of-name-sentinel
rlm@147 264 ;; 0xD306: end-of-name-sentinel
rlm@147 265 ;; 0xD307: end-of-name-sentinel
rlm@147 266 ;; 0xD308: end-of-name-sentinel
rlm@147 267 ;; 0xD309:
rlm@147 268 ;; 0xD30A: w
rlm@147 269 ;; 0xD30B:
rlm@147 270 ;; 0xD30C: V
rlm@147 271 ;; 0xD30D:
rlm@147 272 ;; 0xD30E:
rlm@147 273 ;; 0xD30F: K
rlm@147 274 ;; 0xD310:
rlm@147 275 ;; 0xD311:
rlm@147 276 ;; 0xD312:
rlm@147 277 ;; 0xD313: A
rlm@147 278 ;; 0xD314:
rlm@147 279 ;; 0xD315:
rlm@147 280 ;; 0xD316:
rlm@147 281 ;; 0xD317: i
rlm@147 282 ;; 0xD318:
rlm@147 283 ;; 0xD319:
rlm@147 284 ;; 0xD31A: end-of-name-sentinel
rlm@147 285 ;; 0xD31B: end-of-name-sentinel
rlm@147 286 ;; 0xD31C:
rlm@147 287 ;; 0xD31D:
rlm@147 288 ;; 0xD31E:
rlm@147 289 ;; 0xD31F:
rlm@147 290 ;; 0xD320:
rlm@147 291 ;; 0xD321:
rlm@147 292 ;; 0xD322:
rlm@147 293 ;; 0xD323:
rlm@147 294 ;; 0xD324:
rlm@147 295 ;; 0xD325:
rlm@147 296 ;; 0xD326:
rlm@147 297 ;; 0xD327:
rlm@147 298 ;; 0xD328:
rlm@147 299 ;; 0xD329:
rlm@147 300 ;; 0xD32A:
rlm@147 301 ;; 0xD32B:
rlm@147 302 ;; 0xD32C:
rlm@147 303 ;; 0xD32D:
rlm@147 304 ;; 0xD32E:
rlm@147 305 ;; 0xD32F:
rlm@147 306 ;; 0xD330:
rlm@147 307 ;; 0xD331: 9
rlm@147 308 ;; 0xD332: end-of-name-sentinel
rlm@147 309 ;; 0xD333: 9
rlm@147 310 ;; 0xD334:
rlm@147 311 ;; 0xD335: 9
rlm@147 312 ;; 0xD336:
rlm@147 313 ;; 0xD337: 9
rlm@147 314 ;; 0xD338: end-of-name-sentinel
rlm@147 315 ;; 0xD339: end-of-name-sentinel
rlm@147 316 ;; 0xD33A: end-of-name-sentinel
rlm@147 317 ;; 0xD33B: end-of-name-sentinel
rlm@147 318 ;; 0xD33C: end-of-name-sentinel
rlm@147 319 ;; 0xD33D: end-of-name-sentinel
rlm@147 320 ;; 0xD33E: end-of-name-sentinel
rlm@147 321 ;; 0xD33F: end-of-name-sentinel
rlm@147 322 ;; 0xD340: end-of-name-sentinel
rlm@147 323 ;; 0xD341: end-of-name-sentinel
rlm@147 324 ;; 0xD342: end-of-name-sentinel
rlm@147 325 ;; 0xD343: end-of-name-sentinel
rlm@147 326 ;; 0xD344: end-of-name-sentinel
rlm@147 327 ;; 0xD345: end-of-name-sentinel
rlm@147 328 ;; 0xD346:
rlm@147 329 ;; 0xD347:
rlm@147 330 ;; 0xD348:
rlm@147 331 ;; 0xD349: G
rlm@147 332 ;; 0xD34A: A
rlm@147 333 ;; 0xD34B: R
rlm@147 334 ;; 0xD34C: Y
rlm@147 335 ;; 0xD34D: end-of-pokemon-name-sentinel
rlm@147 336 ;; 0xD34E: J
rlm@147 337
rlm@147 338
rlm@147 339 ;; from this, it looks like the pokemon names are stored all
rlm@147 340 ;; together in one location that begins at 0xD2B4 and
rlm@147 341 ;; extends until 0xD2F5, with each name taking up 11 bytes.
rlm@147 342 ;;
rlm@147 343 ;; rival's name again clearly starts at 0xD349.
rlm@147 344
rlm@147 345
rlm@147 346 (def pokemon-names-start 0xD2B4)
rlm@147 347
rlm@147 348
rlm@147 349 ;; determine whether "number of pokemon in party"
rlm@147 350 ;; might be kept in RAM and if so, where?
rlm@147 351
rlm@147 352 (def six-pokemon (read-state "6-pokemon"))
rlm@147 353 (def five-pokemon (read-state "5-pokemon"))
rlm@147 354 (def four-pokemon (read-state "4-pokemon"))
rlm@147 355 (def three-pokemon (read-state "3-pokemon"))
rlm@147 356 (def two-pokemon (read-state "2-pokemon"))
rlm@147 357 (def one-pokemon (read-state "1-pokemon"))
rlm@147 358
rlm@147 359
rlm@147 360 (defn analyze-num-pokemon []
rlm@147 361 (apply common-differences
rlm@147 362 (map (comp vec memory)
rlm@147 363 [one-pokemon
rlm@147 364 two-pokemon
rlm@147 365 three-pokemon
rlm@147 366 four-pokemon
rlm@147 367 five-pokemon
rlm@147 368 six-pokemon])))
rlm@147 369
rlm@147 370 ;; ;; results
rlm@147 371 ;; ([53602 (1 2 3 4 5 6)]
rlm@147 372 ;; [65314 (105 61 93 60 92 34)]
rlm@147 373 ;; [55875 (34 36 43 52 7 0)]
rlm@147 374 ;; [55876 (18 0 33 52 54 30)]
rlm@147 375 ;; [49158 (197 194 77 117 174 134)]
rlm@147 376 ;; [49160 (29 26 57 239 15 243)]
rlm@147 377 ;; [49736 (74 93 34 89 91 59)]
rlm@147 378 ;; [49162 (165 162 182 179 197 109)]
rlm@147 379 ;; [49227 (187 105 204 5 90 238)]
rlm@147 380 ;; [53067 (128 136 132 145 135 11)]
rlm@147 381 ;; [53068 (147 131 141 136 128 7)]
rlm@147 382 ;; [53069 (136 134 148 140 145 2)]
rlm@147 383 ;; [49904 (2 11 10 3 27 12)]
rlm@147 384 ;; [49172 (100 109 213 195 68 104)]
rlm@147 385 ;; [65492 (11 103 128 160 19 56)]
rlm@147 386 ;; [49173 (80 77 72 75 76 67)]
rlm@147 387 ;; [49334 (8 10 11 5 3 1)]
rlm@147 388 ;; [49335 (49 10 11 19 17 15)]
rlm@147 389 ;; [49336 (8 10 11 5 3 1)]
rlm@147 390 ;; [49720 (106 14 118 0 38 11)]
rlm@147 391 ;; [65304 (32 88 19 114 106 33)]
rlm@147 392 ;; [53561 (59 229 48 17 155 103)]
rlm@147 393 ;; [55935 (6 5 4 3 2 1)])
rlm@147 394
rlm@147 395
rlm@147 396 ;; two canidates : 0xD162 or 0xDA7F
rlm@147 397 ;; they seem to always sum to 6...
rlm@147 398
rlm@147 399 ;; try to set both of them when having only one pokemon.
rlm@147 400
rlm@147 401 (defn change-party-number [^SaveState state new-num]
rlm@147 402 (set-memory state 0xD162 new-num))
rlm@147 403
rlm@147 404 ;; (continue! (change-party-number one-pokemon 3))
rlm@147 405 ;; result -- can scroll down beyone first pokemon, finding
rlm@147 406 ;; glitched pokemon in places where there were previously no
rlm@147 407 ;; pokemon.
rlm@147 408
rlm@147 409
rlm@147 410 (defn change-party-number* [^SaveState state new-num]
rlm@147 411 (set-memory state 0xDA7F new-num))
rlm@147 412
rlm@147 413
rlm@147 414 ;; (continue! (change-party-number* one-pokemon 3))
rlm@147 415 ;; cannot widthdraw any pokemon from box 1 past the third
rlm@147 416 ;; pokemon.
rlm@147 417
rlm@147 418 (def party-number-address 0xD162)
rlm@147 419
rlm@147 420 (defn party-number
rlm@147 421 ([^SaveState state]
rlm@147 422 (aget (memory state) party-number-address))
rlm@147 423 ([] (party-number @current-state)))
rlm@147 424
rlm@147 425 (def pokemon-in-box-1-address 0xDA7F)
rlm@147 426
rlm@147 427 (defn party-names
rlm@147 428 ([^SaveState state]
rlm@147 429 (let [raw-names
rlm@147 430 (subvec (vec (memory state))
rlm@147 431 pokemon-names-start
rlm@147 432 (+ pokemon-names-start
rlm@148 433 (* name-width 6)))]
rlm@147 434 (map
rlm@148 435 read-name
rlm@147 436 (take
rlm@147 437 (party-number state)
rlm@147 438 (partition name-width
rlm@147 439 raw-names)))))
rlm@147 440 ([] (party-names @current-state)))
rlm@147 441
rlm@148 442
rlm@148 443 (defn rename-pokemon
rlm@148 444 ([^SaveState state n new-name]
rlm@148 445 (assert (<= 0 n (dec (party-number state))))
rlm@148 446 (assert (<= (count new-name) max-name-length))
rlm@148 447 (set-memory-range
rlm@148 448 state
rlm@148 449 (+ (* n name-width) pokemon-names-start)
rlm@148 450 (concat (str->character-codes new-name) [end-of-name-marker])))
rlm@148 451 ([n new-name]
rlm@148 452 (rename-pokemon @current-state n new-name)))
rlm@148 453
rlm@148 454 ;; on further analysis, it appears that the original
rlm@148 455 ;; trainer info for each pokemon is also stored together,
rlm@148 456 ;; starting at 0xD272 and continuing to 0xD2B3, with
rlm@148 457 ;; 11 bytes reserved for each OT name.
rlm@148 458
rlm@148 459 (def OT-start 0xD272)
rlm@148 460
rlm@148 461 (defn original-trainers
rlm@148 462 ([^SaveState state]
rlm@148 463 (let [raw-names
rlm@148 464 (subvec (vec (memory state))
rlm@148 465 OT-start
rlm@148 466 (+ OT-start
rlm@148 467 (* name-width 6)))]
rlm@148 468 (map read-name
rlm@148 469 (take (party-number state)
rlm@148 470 (partition name-width raw-names)))))
rlm@148 471 ([] (original-trainers @current-state)))
rlm@148 472
rlm@148 473 (defn set-original-trainer
rlm@148 474 "Set the OT name for a pokemon.
rlm@148 475 Note that a pokemon is still considered 'yours' if
rlm@148 476 the OT ID is the same as your own."
rlm@148 477 ([^SaveState state n new-name]
rlm@148 478 (assert (<= 0 n (dec (party-number state))))
rlm@148 479 (assert (<= (count new-name) max-name-length))
rlm@148 480 (set-memory-range
rlm@148 481 state
rlm@148 482 (+ (* n name-width) OT-start)
rlm@148 483 (concat (str->character-codes new-name) [end-of-name-marker])))
rlm@148 484 ([n new-name]
rlm@148 485 (set-original-trainer @current-state n new-name)))
rlm@148 486
rlm@148 487 ;; PIKACHU stops following if you set it's OT to another name
rlm@148 488 ;; and then back to you own.
rlm@148 489 ;; But not if you set it to your own name, obviously.
rlm@149 490
rlm@149 491
rlm@150 492
rlm@150 493
rlm@150 494 ;; OT ID Numbers.
rlm@152 495 ;; My own id is 05195. A quick search of memory between
rlm@150 496 ;; 0xD162 and 0xD31B revealed the pattern 0x144B exactly
rlm@150 497 ;; six times.
rlm@150 498
rlm@150 499 ;; the locations were:
rlm@150 500
rlm@150 501 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252])
rlm@150 502
rlm@150 503
rlm@150 504 (defn set-pokemon-id
rlm@150 505 ([^SaveState state n new-id]
rlm@150 506 (assert (<= 0 n (dec (party-number state))))
rlm@150 507 (assert (<= 0 new-id 0xFFFF))
rlm@150 508 (set-memory-range
rlm@150 509 state
rlm@150 510 (OT-ID-addresses n)
rlm@151 511 [(bit-shift-right (bit-and new-id 0xFF00) 8)
rlm@151 512 (bit-and new-id 0xFF)
rlm@151 513 ]))
rlm@150 514 ([n new-id]
rlm@151 515 (set-pokemon-id @current-state n new-id)))
rlm@152 516
rlm@152 517
rlm@152 518