View difference between Paste ID: 5Wk4SXUj and 4nLWhckh
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 ; 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 d,(CF60) ; CurSpecies
59
push de ; 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 de ; restore CurSpecies
103
ld (CF60),d ; 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 b,(DF16) ; current exp LSB
127+
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 b,(DF15) 
137+
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-
ld b,(DF14) 
146+
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 b,(DF4F) ; current exp LSB 
181+
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-
ld b,(DF4E) 
191+
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-
ld b,(DF4D) 
200+
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: ; get maximum experience allowed based on current badge level and Pokemon's growth rate
222
; outputs hQuotient = maximum experience allowed
223
push af
224
push bc
225
push de
226
push hl
227
ld a,(D109) ; CurPartyMon
228
ld hl,(DCAF); PartyMon1Species - (PartyMonNSpecies - PartyMonN-1Species) = PartyMon1Species - 30
229
ld bc,0030 ; PartyMonNSpecies - PartyMonN-1Species
230
inc a
231
loop: ; make hl point to species of current party Pokemon
232
add hl,bc
233
dec a
234
jr nz,loop
235
call calcExpCap ; 01:7600
236
; calculate maximum experience allowed given (hl)=species as input
237
pop hl
238
pop de
239
pop bc
240
pop af
241
ret
242
243
getFinalExperienceInBattle: ; calculate the experience that the Pokemon is going to receive
244
push af
245
push bc
246
push de
247
push hl
248
ld a,(D109) ; CurPartyMon
249
ld hl,(DCB9); PartyMon1Exp - (PartyMonNExp - PartyMonN-1Exp) = PartyMon1Exp - 30
250
ld bc,0030 ; PartyMonNExp - PartyMonN-1Exp
251
inc a
252
loop: ; make hl point to experience LSB of current party Pokemon
253
add hl,bc
254
dec a
255
jr nz,loop
256
ld e,(hl)
257
dec hl
258
ld d,(hl)
259
dec hl
260
ld h,(hl) ; hde = Pokemon's current experience
261
callba getExpCapInBattle ; hQuotient = maximum experience allowed 
262
ld a,(FF00+B6)
263
sub e
264
ld (FF00+B6),a
265
ld a,(FF00+B5)
266-
ld b,(D086) ; exp about to gain MSB
266+
267
ld (FF00+B5),a
268
ld a,(FF00+B4)
269
sbc h
270
ld (FF00+B4),a ; Cap - Current = Maximum experience the Pokemon can gain not to surpass the cap
271
ld a,(FF00+B5)
272
ld hl,D086
273
ld b,(hl) ; exp about to gain MSB
274
cp b 
275-
ld b,(D087) ; exp about to gain LSB
275+
276
jr nc, finish ; exp about to gain is not higher than cap
277
ld (D086),a ; else, overwrite exp about to win with cap
278
ld a,(FF00+B6)
279
ld (D087),a 
280
checkLSB:
281
ld a,(FF00+B6)
282
ld hl,D087
283
ld b,(hl) ; exp about to gain LSB
284
cp b
285
jr nc, finish ; exp about to gain is not higher than cap
286
ld (D087),a ; else, overwrite exp about to win with cap
287
finish: 
288
pop hl
289-
jp getFinalExperience ; jump from 0F:6f02
289+
290
pop bc
291
pop af
292
ld a,(d109) ; original 0F:6f02
293
jp 6F05
294
295
exppatch: 
296
;(...)
297
; at this point D086-D087 contains experience the Pokemon is about to gain
298
jp getFinalExperienceInBattle ; jump from 0F:6f02
299
;(...)