Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getBadgeLevel ; 3fdd
- ; outputs b = badgeLevel
- ld hl,D857 ; JohtoBadges
- ld b,02
- call CountSetBits
- ld e,a
- ld d,00
- ld hl,3FEF ; badgeLevelTable
- add hl,de
- ld a,(hl)
- ld b,a
- ret
- badgeLevelTable ; 3fef
- db 14
- db 1E
- db 26
- db 2D
- db 36
- db 3C
- db 3F
- db 49
- db 52
- db 54
- db 56
- db 58
- db 5A
- db 5C
- db 5E
- db 60
- db 64
- RareCandy: ; 03:6f14
- ;(...)
- call GetPartyParamLocation
- jp rcpatch ; jump from ef24
- jp nc,Functionee83 ; no effect if carry flag is clear
- ;(...)
- rcpatch: ; 03:7a30
- ; cap at current badge level instead of at level 100
- push bc
- push af
- push de
- push hl
- call 3FDD ; getBadgeLevel
- pop hl
- pop de
- pop af
- ld a,(hl)
- cp b ; compare to b = badgeLevel instead of to 100
- pop bc
- jp 6F27
- calcExpCap: ; 01:7600
- ; calculate maximum experience allowed given (hl)=species as input
- ; outputs hQuotient = maximum experience allowed
- ld a,(CF60) ; CurSpecies
- push af ; save (CF60) to restore CurSpecies later
- ld a,(hl)
- ld (CF60),a ; load species of Pokemon we're dealing with into CurSpecies
- call GetBaseData ; load base data of Pokemon identified by CurSpecies into RAM, including growth rate
- ; Growth Rates:
- ; 0: exp = level^3
- ; 4: exp = level^3 * 4 / 5 (fast)
- ; 5: exp = level^3 * 5 / 4 (slow)
- call 3FDD ; getBadgeLevel
- xor a
- ld (FF00+B4),a ; hMultiplicand
- ld (FF00+B5),a ; hMultiplicand
- ld a,b ; badgeLevel
- ld (FF00+B6),a ; hMultiplicand
- ld (FF00+B7),a ; hMultiplier
- push af
- call Multiply ; 3119
- pop af
- ld (FF00+B7),a
- call Multiply ; we now have badgeLevel^3 at FFB3-FFB6, but FFB3 is never higher than 00
- ld a,(D24C) ; BaseGrowthRate
- and a
- jr z,finish ; if growth rate is 0 then exp = level^3
- cp 5
- jr z,slowExpGroup
- fastExpGroup: ; multiply by 4 and divide by 5
- ld a,4
- ld (FF00+B7),a
- call Multiply ; again, result is at FFB3-FFB6
- ld a,5
- ld b,4 ; dividend is 4 bytes long (or 3)
- ld (FF00+B7),a ; hDivisor
- call Divide ; hDividend is FFB3-FFB6
- jr, finish
- slowExpGroup: ; multiply by 5 and divide by 4
- ld a,5
- ld (FF00+B7),a
- call Multiply ; again, result is at FFB3-FFB6
- ld a,4
- ld b,4 ; dividend is 4 bytes long (or 3)
- ld (FF00+B7),a ; hDivisor
- call Divide ; hDividend is FFB3-FFB6
- finish:
- pop af ; restore CurSpecies
- ld (CF60),a ; CurSpecies
- call GetBaseData ; restore base data of original Pokemon
- ret
- DayCareMan:
- ;(...)
- jr z,72A4
- jp dcmpatch ; jump from 7289
- nop
- nop
- nop
- nop
- ld hl,DF16
- ;(...)
- dcmpatch: ; 01:7500
- ; cap at current badge level instead of at level 100
- push bc
- push af
- push de
- push hl
- ld hl,DF0C ; species
- call calcExpCap ; output hQuotient = maximum experience allowed, given (hl)=species as input
- ld a,(FF00+B6) ; cap LSB
- ld hl,DF16
- ld b,(hl) ; current exp LSB
- cp b
- jr z,checkMiddleByte
- pop hl
- pop de
- pop af
- pop bc
- jp 728E ; if they are not equal, cap hasn't been reached
- checkMiddleByte:
- ld a,(FF00+B5)
- dec hl
- ld b,(hl)
- cp b
- jr z,checkMSB
- pop hl
- pop de
- pop af
- pop bc
- jp 728E ; if they are not equal, cap hasn't been reached
- ld a,(FF00+B4)
- dec hl
- ld b,(hl)
- cp b
- jr z,capReached ; if every byte is equal, cap has been reached, so stop experience growth
- pop hl
- pop de
- pop af
- pop bc
- jp 728E ; if they are not equal, cap hasn't been reached
- capReached:
- pop hl
- pop de
- pop af
- pop bc
- jp 72A4
- DayCareLady:
- ;(...)
- jr z,72C6
- jp dclpatch ; jump from 72ab
- nop
- nop
- nop
- nop
- ld hl,DF4F
- ;(...)
- dclpatch: 01:7580
- ; cap at current badge level instead of at level 100
- push bc
- push af
- push de
- push hl
- ld hl,DF45 ; species
- call calcExpCap ; output hQuotient = maximum experience allowed, given (hl)=species as input
- ld a,(FF00+B6) ; cap LSB
- ld hl,DF4F
- ld b,(hl) ; current exp LSB
- cp b
- jr z,checkMiddleByte
- pop hl
- pop de
- pop af
- pop bc
- jp 72B0 ; if they are not equal, cap hasn't been reached
- checkMiddleByte:
- ld a,(FF00+B5)
- dec hl
- ld b,(hl)
- cp b
- jr z,checkMSB
- pop hl
- pop de
- pop af
- pop bc
- jp 72B0 ; if they are not equal, cap hasn't been reached
- ld a,(FF00+B4)
- dec hl
- ld b,(hl)
- cp b
- jr z,capReached ; if every byte is equal, cap has been reached, so stop experience growth
- pop hl
- pop de
- pop af
- pop bc
- jp 72B0 ; if they are not equal, cap hasn't been reached
- capReached:
- pop hl
- pop de
- pop af
- pop bc
- jp 72C6
- getExpCapInBattle: ; 01:7680
- ; get maximum experience allowed based on current badge level and Pokemon's growth rate
- ; outputs hQuotient = maximum experience allowed
- push af
- push bc
- push de
- push hl
- ld a,(D109) ; CurPartyMon
- ld hl,DCAF; PartyMon1Species - (PartyMonNSpecies - PartyMonN-1Species) = PartyMon1Species - 30
- ld bc,0030 ; PartyMonNSpecies - PartyMonN-1Species
- inc a
- loop: ; make hl point to species of current party Pokemon
- add hl,bc
- dec a
- jr nz,loop
- call calcExpCap ; 01:7600
- ; calculate maximum experience allowed given (hl)=species as input
- pop hl
- pop de
- pop bc
- pop af
- ret
- getFinalExperienceInBattle: ; 0F:7f50
- ; calculate the experience that the Pokemon is going to receive
- push af
- push bc
- push de
- push hl
- ld a,(D109) ; CurPartyMon
- ld hl,DCB9; PartyMon1Exp - (PartyMonNExp - PartyMonN-1Exp) = PartyMon1Exp - 30
- ld bc,0030 ; PartyMonNExp - PartyMonN-1Exp
- inc a
- loop: ; make hl point to experience LSB of current party Pokemon
- add hl,bc
- dec a
- jr nz,loop
- ld e,(hl)
- dec hl
- ld d,(hl)
- dec hl
- ld h,(hl) ; hde = Pokemon's current experience
- push hl
- ; ld hl,7680 ; ld a,01 ; rst 08
- callba getExpCapInBattle ; 01:7680
- ; outputs hQuotient = maximum experience allowed
- pop hl
- ld a,(FF00+B6)
- sub e
- ld (FF00+B6),a
- ld a,(FF00+B5)
- sbc d
- ld (FF00+B5),a
- ld a,(FF00+B4)
- sbc h
- ld (FF00+B4),a ; Cap - Current = Maximum experience the Pokemon can gain not to surpass the cap
- ld a,(FF00+B5)
- ld hl,D086
- ld b,(hl) ; exp about to gain MSB
- cp b
- jr z, checkLSB
- jr nc, finish ; exp about to gain is not higher than cap
- ld (D086),a ; else, overwrite exp about to win with cap
- ld a,(FF00+B6)
- ld (D087),a
- checkLSB:
- ld a,(FF00+B6)
- ld hl,D087
- ld b,(hl) ; exp about to gain LSB
- cp b
- jr nc, finish ; exp about to gain is not higher than cap
- ld (D087),a ; else, overwrite exp about to win with cap
- finish:
- pop hl
- pop de
- pop bc
- pop af
- ld a,(d109) ; original 0F:6f02
- jp 6F05
- exppatch:
- ;(...)
- ; at this point D086-D087 contains experience the Pokemon is about to gain
- jp getFinalExperienceInBattle ; jump from 0F:6f02
- ;(...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement