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