Advertisement
Crystal_

Pokemon Pyrite - Badge-Sensitive Level Cap

Mar 11th, 2014
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. getBadgeLevel ; 3fdd
  2. ; outputs b = badgeLevel
  3. ld hl,D857 ; JohtoBadges
  4. ld b,02
  5. call CountSetBits
  6. ld e,a
  7. ld d,00
  8. ld hl,3FEF ; badgeLevelTable
  9. add hl,de
  10. ld a,(hl)
  11. ld b,a
  12. ret
  13.  
  14. badgeLevelTable ; 3fef
  15. db 14
  16. db 1E
  17. db 26
  18. db 2D
  19. db 36
  20. db 3C
  21. db 3F
  22. db 49
  23. db 52
  24. db 54
  25. db 56
  26. db 58
  27. db 5A
  28. db 5C
  29. db 5E
  30. db 60
  31. db 64
  32.  
  33. RareCandy: ; 03:6f14
  34. ;(...)
  35. call GetPartyParamLocation
  36. jp rcpatch ; jump from ef24
  37. jp nc,Functionee83 ; no effect if carry flag is clear
  38. ;(...)
  39.  
  40. rcpatch: ; 03:7a30
  41. ; cap at current badge level instead of at level 100
  42. push bc
  43. push af
  44. push de
  45. push hl
  46. call 3FDD ; getBadgeLevel
  47. pop hl
  48. pop de
  49. pop af
  50. ld a,(hl)
  51. cp b ; compare to b = badgeLevel instead of to 100
  52. pop bc
  53. jp 6F27
  54.  
  55. calcExpCap: ; 01:7600
  56. ; calculate maximum experience allowed given (hl)=species as input
  57. ; outputs hQuotient = maximum experience allowed
  58. ld a,(CF60) ; CurSpecies
  59. push af ; save (CF60) to restore CurSpecies later
  60. ld a,(hl)
  61. ld (CF60),a ; load species of Pokemon we're dealing with into CurSpecies
  62. call GetBaseData ; load base data of Pokemon identified by CurSpecies into RAM, including growth rate
  63. ; Growth Rates:
  64. ; 0: exp = level^3
  65. ; 4: exp = level^3 * 4 / 5 (fast)
  66. ; 5: exp = level^3 * 5 / 4 (slow)
  67. call 3FDD ; getBadgeLevel
  68. xor a
  69. ld (FF00+B4),a ; hMultiplicand
  70. ld (FF00+B5),a ; hMultiplicand
  71. ld a,b ; badgeLevel
  72. ld (FF00+B6),a ; hMultiplicand
  73. ld (FF00+B7),a ; hMultiplier
  74. push af
  75. call Multiply ; 3119
  76. pop af
  77. ld (FF00+B7),a  
  78. call Multiply ; we now have badgeLevel^3 at FFB3-FFB6, but FFB3 is never higher than 00
  79. ld a,(D24C) ; BaseGrowthRate
  80. and a
  81. jr z,finish ; if growth rate is 0 then exp = level^3
  82. cp 5
  83. jr z,slowExpGroup
  84. fastExpGroup: ; multiply by 4 and divide by 5
  85. ld a,4
  86. ld (FF00+B7),a
  87. call Multiply ; again, result is at FFB3-FFB6
  88. ld a,5
  89. ld b,4 ; dividend is 4 bytes long (or 3)
  90. ld (FF00+B7),a ; hDivisor
  91. call Divide ; hDividend is FFB3-FFB6
  92. jr, finish
  93. slowExpGroup: ; multiply by 5 and divide by 4
  94. ld a,5
  95. ld (FF00+B7),a
  96. call Multiply ; again, result is at FFB3-FFB6
  97. ld a,4
  98. ld b,4 ; dividend is 4 bytes long (or 3)
  99. ld (FF00+B7),a ; hDivisor
  100. call Divide ; hDividend is FFB3-FFB6
  101. finish:
  102. pop af ; restore CurSpecies
  103. ld (CF60),a ; CurSpecies
  104. call GetBaseData ; restore base data of original Pokemon
  105. ret
  106.  
  107. DayCareMan:
  108. ;(...)
  109. jr z,72A4
  110. jp dcmpatch ; jump from 7289
  111. nop
  112. nop
  113. nop
  114. nop
  115. ld hl,DF16
  116. ;(...)
  117.  
  118. dcmpatch: ; 01:7500
  119. ; cap at current badge level instead of at level 100
  120. push bc
  121. push af
  122. push de
  123. push hl
  124. ld hl,DF0C ; species
  125. call calcExpCap ; output hQuotient = maximum experience allowed, given (hl)=species as input
  126. ld a,(FF00+B6) ; cap LSB
  127. ld hl,DF16
  128. ld b,(hl) ; current exp LSB
  129. cp b
  130. jr z,checkMiddleByte
  131. pop hl
  132. pop de
  133. pop af
  134. pop bc
  135. jp 728E ; if they are not equal, cap hasn't been reached
  136. checkMiddleByte:
  137. ld a,(FF00+B5)
  138. dec hl
  139. ld b,(hl)
  140. cp b
  141. jr z,checkMSB
  142. pop hl
  143. pop de
  144. pop af
  145. pop bc
  146. jp 728E ; if they are not equal, cap hasn't been reached
  147. ld a,(FF00+B4)
  148. dec hl
  149. ld b,(hl)
  150. cp b
  151. jr z,capReached ; if every byte is equal, cap has been reached, so stop experience growth
  152. pop hl
  153. pop de
  154. pop af
  155. pop bc
  156. jp 728E ; if they are not equal, cap hasn't been reached
  157. capReached:
  158. pop hl
  159. pop de
  160. pop af
  161. pop bc
  162. jp 72A4
  163.  
  164. DayCareLady:
  165. ;(...)
  166. jr z,72C6
  167. jp dclpatch ; jump from 72ab
  168. nop
  169. nop
  170. nop
  171. nop
  172. ld hl,DF4F
  173. ;(...)
  174.  
  175. dclpatch: 01:7580
  176. ; cap at current badge level instead of at level 100
  177. push bc
  178. push af
  179. push de
  180. push hl
  181. ld hl,DF45 ; species
  182. call calcExpCap ; output hQuotient = maximum experience allowed, given (hl)=species as input
  183. ld a,(FF00+B6) ; cap LSB
  184. ld hl,DF4F
  185. ld b,(hl) ; current exp LSB
  186. cp b
  187. jr z,checkMiddleByte
  188. pop hl
  189. pop de
  190. pop af
  191. pop bc
  192. jp 72B0 ; if they are not equal, cap hasn't been reached
  193. checkMiddleByte:
  194. ld a,(FF00+B5)
  195. dec hl
  196. ld b,(hl)
  197. cp b
  198. jr z,checkMSB
  199. pop hl
  200. pop de
  201. pop af
  202. pop bc
  203. jp 72B0 ; if they are not equal, cap hasn't been reached
  204. ld a,(FF00+B4)
  205. dec hl
  206. ld b,(hl)
  207. cp b
  208. jr z,capReached ; if every byte is equal, cap has been reached, so stop experience growth
  209. pop hl
  210. pop de
  211. pop af
  212. pop bc
  213. jp 72B0 ; if they are not equal, cap hasn't been reached
  214. capReached:
  215. pop hl
  216. pop de
  217. pop af
  218. pop bc
  219. jp 72C6
  220.  
  221. getExpCapInBattle: ; 01:7680
  222. ; get maximum experience allowed based on current badge level and Pokemon's growth rate
  223. ; outputs hQuotient = maximum experience allowed
  224. push af
  225. push bc
  226. push de
  227. push hl
  228. ld a,(D109) ; CurPartyMon
  229. ld hl,DCAF; PartyMon1Species - (PartyMonNSpecies - PartyMonN-1Species) = PartyMon1Species - 30
  230. ld bc,0030 ; PartyMonNSpecies - PartyMonN-1Species
  231. inc a
  232. loop: ; make hl point to species of current party Pokemon
  233. add hl,bc
  234. dec a
  235. jr nz,loop
  236. call calcExpCap ; 01:7600
  237. ; calculate maximum experience allowed given (hl)=species as input
  238. pop hl
  239. pop de
  240. pop bc
  241. pop af
  242. ret
  243.  
  244. getFinalExperienceInBattle: ; 0F:7f50
  245. ; calculate the experience that the Pokemon is going to receive
  246. push af
  247. push bc
  248. push de
  249. push hl
  250. ld a,(D109) ; CurPartyMon
  251. ld hl,DCB9; PartyMon1Exp - (PartyMonNExp - PartyMonN-1Exp) = PartyMon1Exp - 30
  252. ld bc,0030 ; PartyMonNExp - PartyMonN-1Exp
  253. inc a
  254. loop: ; make hl point to experience LSB of current party Pokemon
  255. add hl,bc
  256. dec a
  257. jr nz,loop
  258. ld e,(hl)
  259. dec hl
  260. ld d,(hl)
  261. dec hl
  262. ld h,(hl) ; hde = Pokemon's current experience
  263. push hl
  264. ; ld hl,7680 ; ld a,01 ; rst 08
  265. callba getExpCapInBattle ; 01:7680
  266. ; outputs hQuotient = maximum experience allowed
  267. pop hl
  268. ld a,(FF00+B6)
  269. sub e
  270. ld (FF00+B6),a
  271. ld a,(FF00+B5)
  272. sbc d
  273. ld (FF00+B5),a
  274. ld a,(FF00+B4)
  275. sbc h
  276. ld (FF00+B4),a ; Cap - Current = Maximum experience the Pokemon can gain not to surpass the cap
  277. ld a,(FF00+B5)
  278. ld hl,D086
  279. ld b,(hl) ; exp about to gain MSB
  280. cp b
  281. jr z, checkLSB
  282. jr nc, finish ; exp about to gain is not higher than cap
  283. ld (D086),a ; else, overwrite exp about to win with cap
  284. ld a,(FF00+B6)
  285. ld (D087),a
  286. checkLSB:
  287. ld a,(FF00+B6)
  288. ld hl,D087
  289. ld b,(hl) ; exp about to gain LSB
  290. cp b
  291. jr nc, finish ; exp about to gain is not higher than cap
  292. ld (D087),a ; else, overwrite exp about to win with cap
  293. finish:
  294. pop hl
  295. pop de
  296. pop bc
  297. pop af
  298. ld a,(d109) ; original 0F:6f02
  299. jp 6F05
  300.  
  301. exppatch:
  302. ;(...)
  303. ; at this point D086-D087 contains experience the Pokemon is about to gain
  304. jp getFinalExperienceInBattle ; jump from 0F:6f02
  305. ;(...)
  306.  
  307.  
  308.  
  309. https://www.youtube.com/watch?v=F5hpoVvl8fU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement