Advertisement
Crystal_

Untitled

Mar 11th, 2014
235
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
  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. DayCareMan:
  56. ;(...)
  57. jr z,72A4
  58. jp dcmpatch ; jump from 7289
  59. nop
  60. nop
  61. jr nc,72A4
  62. ;(...)
  63.  
  64. dcmpatch: ; cap at current badge level instead of at level 100
  65. push bc
  66. push af
  67. push de
  68. push hl
  69. call 3FDD ; getBadgeLevel
  70. pop hl
  71. pop de
  72. pop af
  73. ld a,(DF2B) ; level
  74. cp b ; compare to b = badgeLevel instead of to 100
  75. pop bc
  76. jp 728E
  77.  
  78. DayCareLady:
  79. ;(...)
  80. jr z,72C6
  81. jp dclpatch ; jump from 72ab
  82. nop
  83. nop
  84. jr nc,72C6
  85. ;(...)
  86.  
  87. dclpatch: ; cap at current badge level instead of at level 100
  88. push bc
  89. push af
  90. push de
  91. push hl
  92. call 3FDD ; getBadgeLevel
  93. pop hl
  94. pop de
  95. pop af
  96. ld a,(DF64) ; level
  97. cp b ; compare to b = badgeLevel instead of to 100
  98. pop bc
  99. jp 72B0
  100.  
  101. calcExpCap: ; calculate maximum experience allowed based on current badge level and Pokemon's growth rate
  102. ; outputs hQuotient = maximum experience allowed
  103. push af
  104. push bc
  105. push de
  106. push hl
  107. ld a,(D109) ; CurPartyMon
  108. ld hl,(DCAF); PartyMon1Species - (PartyMonNSpecies - PartyMonN-1Species) = PartyMon1Species - 30
  109. ld bc,0030 ; PartyMonNSpecies - PartyMonN-1Species
  110. inc a
  111. loop: ; make hl point to species of current party Pokemon
  112. add hl,bc
  113. dec a
  114. jr nz,loop
  115. ld d,(CF60) ; CurSpecies
  116. push de ; save (CF60) to restore CurSpecies later
  117. ld a,(hl)
  118. ld (CF60),a ; load species of current party Pokemon into CurSpecies
  119. call GetBaseData ; load base data of Pokemon identified by CurSpecies into RAM, including growth rate
  120. ; Growth Rates:
  121. ; 0: exp = level^3
  122. ; 4: exp = level^3 * 4 / 5 (fast)
  123. ; 5: exp = level^3 * 5 / 4 (slow)
  124. call 3FDD ; getBadgeLevel
  125. xor a
  126. ld (FF00+B4),a ; hMultiplicand
  127. ld (FF00+B5),a ; hMultiplicand
  128. ld a,b ; badgeLevel
  129. ld (FF00+B6),a ; hMultiplicand
  130. ld (FF00+B7),a ; hMultiplier
  131. push af
  132. call Multiply ; 3119
  133. pop af
  134. ld (FF00+B7),a ;
  135. call Multiply
  136. ; we now have badgeLevel^3 at FFB3-FFB6, but FFB3 is never higher than 00
  137. ld a,(D24C) ; BaseGrowthRate
  138. and a
  139. jr z,finish ; if growth rate is 0 then exp = level^3
  140. cp 5
  141. jr z,slowExpGroup
  142. fastExpGroup: ; multiply by 4 and divide by 5
  143. ld a,4
  144. ld (FF00+B7),a
  145. call Multiply ; again, result is at FFB3-FFB6
  146. ld a,5
  147. ld b,4 ; dividend is 4 bytes long (or 3)
  148. ld (FF00+B7),a ; hDivisor
  149. call Divide ; hDividend is FFB3-FFB6
  150. jr, finish
  151. slowExpGroup: ; multiply by 5 and divide by 4
  152. ld a,5
  153. ld (FF00+B7),a
  154. call Multiply ; again, result is at FFB3-FFB6
  155. ld a,4
  156. ld b,4 ; dividend is 4 bytes long (or 3)
  157. ld (FF00+B7),a ; hDivisor
  158. call Divide ; hDividend is FFB3-FFB6
  159. finish:
  160. pop de ; restore CurSpecies
  161. ld (CF60),d ; CurSpecies
  162. call GetBaseData ; restore base data of original Pokemon
  163. pop hl
  164. pop de
  165. pop bc
  166. pop af
  167. ret
  168.  
  169. getFinalExperience: ; calculate the experience that the Pokemon is going to receive
  170. push af
  171. push bc
  172. push de
  173. push hl
  174. ld a,(D109) ; CurPartyMon
  175. ld hl,(DCB9); PartyMon1Exp - (PartyMonNExp - PartyMonN-1Exp) = PartyMon1Exp - 30
  176. ld bc,0030 ; PartyMonNExp - PartyMonN-1Exp
  177. inc a
  178. loop: ; make hl point to experience LSB of current party Pokemon
  179. add hl,bc
  180. dec a
  181. jr nz,loop
  182. ld e,(hl)
  183. dec hl
  184. ld d,(hl)
  185. dec hl
  186. ld h,(hl) ; hde = Pokemon's current experience
  187. call calcExpCap ; hQuotient = maximum experience allowed
  188. ld a,(FF00+B6)
  189. sub e
  190. ld (FF00+B6),a
  191. ld a,(FF00+B5)
  192. sbc d
  193. ld (FF00+B5),a
  194. ld a,(FF00+B4)
  195. sbc h
  196. ld (FF00+B4),a ; Cap - Current = Maximum experience the Pokemon can gain not to surpass the cap
  197. ld a,(FF00+B5)
  198. ld b,(D086) ; exp about to gain MSB
  199. cp b
  200. jr z, checkLSB
  201. jr nc, finish ; exp about to gain is not higher than cap
  202. ld (D086),a ; else, overwrite exp about to win with cap
  203. ld a,(FF00+B6)
  204. ld (D087),a
  205. checkLSB:
  206. ld a,(FF00+B6)
  207. ld b,(D087) ; exp about to gain LSB
  208. cp b
  209. jr nc, finish ; exp about to gain is not higher than cap
  210. ld (D087),a ; else, overwrite exp about to win with cap
  211. finish:
  212. pop hl
  213. pop de
  214. pop bc
  215. pop af
  216. ld a,(d109) ; original 0F:6f02
  217. jp 6F05
  218.  
  219. exppatch:
  220. ; at this point D086-D087 contains experience the Pokemon is about to gain
  221. jp getFinalExperience ; jump from 0F:6f02
  222. ;(...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement