View difference between Paste ID: 4nLWhckh and N03xvH1A
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
128
cp b 
129
jr z,checkMiddleByte
130
pop hl
131
pop de
132
pop af
133
pop bc
134
jp 728E ; if they are not equal, cap hasn't been reached
135
checkMiddleByte:
136
ld a,(FF00+B5) 
137
ld b,(DF15) 
138
cp b
139
jr z,checkMSB
140
pop hl
141
pop de
142
pop af
143
pop bc
144
jp 728E ; if they are not equal, cap hasn't been reached
145
ld a,(FF00+B4) 
146
ld b,(DF14) 
147
cp b
148
jr z,capReached ; if every byte is equal, cap has been reached, so stop experience growth
149
pop hl
150
pop de
151
pop af
152
pop bc
153
jp 728E ; if they are not equal, cap hasn't been reached
154
capReached:
155
pop hl
156
pop de
157
pop af
158
pop bc
159
jp 72A4
160
161
DayCareLady: 
162
;(...)
163
jr z,72C6
164
jp dclpatch ; jump from 72ab
165
nop
166
nop
167
nop
168
nop
169
ld hl,DF4F
170
;(...)
171
172
dclpatch: 01:7580
173
; cap at current badge level instead of at level 100
174
push bc
175
push af
176
push de
177
push hl
178
ld hl,DF45 ; species 
179
call calcExpCap ; output hQuotient = maximum experience allowed, given (hl)=species as input
180
ld a,(FF00+B6) ; cap LSB
181
ld b,(DF4F) ; current exp LSB 
182
cp b 
183
jr z,checkMiddleByte
184
pop hl
185
pop de
186
pop af
187
pop bc
188
jp 72B0 ; if they are not equal, cap hasn't been reached
189
checkMiddleByte:
190
ld a,(FF00+B5) 
191
ld b,(DF4E) 
192
cp b
193
jr z,checkMSB
194
pop hl
195
pop de
196
pop af
197
pop bc
198
jp 72B0 ; if they are not equal, cap hasn't been reached
199
ld a,(FF00+B4) 
200
ld b,(DF4D) 
201
cp b
202
jr z,capReached ; if every byte is equal, cap has been reached, so stop experience growth
203
pop hl
204
pop de
205
pop af
206
pop bc
207
jp 72B0 ; if they are not equal, cap hasn't been reached
208
capReached:
209
pop hl
210
pop de
211
pop af
212
pop bc
213
jp 72C6
214
215
getExpCapInBattle: ; get maximum experience allowed based on current badge level and Pokemon's growth rate
216
; outputs hQuotient = maximum experience allowed
217
push af
218
push bc
219
push de
220
push hl
221
ld a,(D109) ; CurPartyMon
222
ld hl,(DCAF); PartyMon1Species - (PartyMonNSpecies - PartyMonN-1Species) = PartyMon1Species - 30
223
ld bc,0030 ; PartyMonNSpecies - PartyMonN-1Species
224
inc a
225
loop: ; make hl point to species of current party Pokemon
226
add hl,bc
227
dec a
228
jr nz,loop
229
call calcExpCap ; 01:7600
230
; calculate maximum experience allowed given (hl)=species as input
231
pop hl
232
pop de
233
pop bc
234
pop af
235
ret
236
237
getFinalExperienceInBattle: ; calculate the experience that the Pokemon is going to receive
238
push af
239
push bc
240
push de
241
push hl
242
ld a,(D109) ; CurPartyMon
243
ld hl,(DCB9); PartyMon1Exp - (PartyMonNExp - PartyMonN-1Exp) = PartyMon1Exp - 30
244
ld bc,0030 ; PartyMonNExp - PartyMonN-1Exp
245
inc a
246
loop: ; make hl point to experience LSB of current party Pokemon
247
add hl,bc
248
dec a
249
jr nz,loop
250
ld e,(hl)
251
dec hl
252
ld d,(hl)
253
dec hl
254
ld h,(hl) ; hde = Pokemon's current experience
255
callba getExpCapInBattle ; hQuotient = maximum experience allowed 
256
ld a,(FF00+B6)
257
sub e
258
ld (FF00+B6),a
259
ld a,(FF00+B5)
260
sbc d
261
ld (FF00+B5),a
262
ld a,(FF00+B4)
263
sbc h
264
ld (FF00+B4),a ; Cap - Current = Maximum experience the Pokemon can gain not to surpass the cap
265
ld a,(FF00+B5)
266
ld b,(D086) ; exp about to gain MSB
267
cp b 
268
jr z, checkLSB
269
jr nc, finish ; exp about to gain is not higher than cap
270
ld (D086),a ; else, overwrite exp about to win with cap
271
ld a,(FF00+B6)
272
ld (D087),a 
273
checkLSB:
274
ld a,(FF00+B6)
275
ld b,(D087) ; exp about to gain LSB
276
cp b
277
jr nc, finish ; exp about to gain is not higher than cap
278
ld (D087),a ; else, overwrite exp about to win with cap
279
finish: 
280
pop hl
281
pop de
282
pop bc
283
pop af
284
ld a,(d109) ; original 0F:6f02
285
jp 6F05
286
287
exppatch: 
288
; at this point D086-D087 contains experience the Pokemon is about to gain
289
jp getFinalExperience ; jump from 0F:6f02
290
;(...)