annotate clojure/com/aurellem/exp/pokemon.clj @ 163:9c3769060201

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