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