Skip to content

Commit

Permalink
Create a new Exp. All routine
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseurae committed Oct 20, 2024
1 parent ecb9a27 commit 030df17
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 148 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ A `output.gba` will be created as your patched file.
- PRET for their [decompilation of Pokemon Ruby](https://github.com/pret/pokeruby).
- Super Versekr Dark for their Exp Points on capturing routine.
- merpp for pokeemerald's overworld shadow feature.
- Andrea for their Exp. All routine.
- Andrea for their P/S Split routine.
283 changes: 161 additions & 122 deletions assembly/hooks/exp_all.s
Original file line number Diff line number Diff line change
@@ -1,124 +1,163 @@
.global CountEligiblePokeForExp, SetExpAmount, GetSentInPokeForExp
.global ExpAllHook1, ExpAllHook2, ExpAllHook3

@
CountEligiblePokeForExp:
PUSH {R0,R2-R7}
LDR R0, =(gExpAllEnabled)
ldrb r0, [r0]
CMP R0, #0
BEQ RETURN1

MOV R4, #0
MOV R5, #0

LOOP:
LDR R0, = 0x03004360
MOV R1, #0x64
MUL R1, R4
ADD R0, R0, R1
MOV R1, #0x56
LDRH R2, [R0, R1]
CMP R2, #0
BEQ COUNTER

IS_EGG:
MOV R1, #0x2D
PUSH {R4,R5}
BL GET_DATA
POP {R4, R5}
CMP R0, #1
BEQ COUNTER

MOV R1, #1
LSL R1, R1, R4
ORR R5, R1

COUNTER:
ADD R4, #1
CMP R4, #6
BNE LOOP

MOV R1, R5

POP {R0,R2-R7}
LDR R0, = 0x08020030+1
BX R0

RETURN1:
POP {R0,R2-R7}
LDR R2, = 0x02024DEA
MOV R1, #2
LDR R3, = 0x08020026+1
BX R3

GET_DATA:
LDR R2, = 0x0803CB60+1
BX R2

@
SetExpAmount:
PUSH {R0}
LDR R0, =(gExpAllEnabled)
@ 0x802019a - hook via r4
@ 0x80201fa - return
@ 0x80201e0 - else branch
@ r5 - viaSentIn
ExpAllHook1:
ldr r4, =(gExpAllEnabled)
ldrb r4, [r4]

cmp r4, #0
beq ExpAllHook1_GoToMainElseBranch

mov r4, r1

mov r0, r4
mov r1, r5
swi #6

mov r1, sl

cmp r0, #0
bne ExpAllHook1_NormalExpSet
mov r0, #1

ExpAllHook1_NormalExpSet:
strh r0, [r1]

ldr r5, =(0x2024dee)
lsr r0, r4, #1

cmp r0, #0
bne ExpAllHook1_SharedExpSet
mov r0, #1

ExpAllHook1_SharedExpSet:
strh r0, [r5]

ldr r1, =(0x80201fa | 1)
bx r1

ExpAllHook1_GoToMainElseBranch:
ldr r0, =(0x80201e0 | 1)
bx r0

@ 0x8020276 - hook via r3
@ 0x80202a0 - next condition
@ 0x80202c8 - end condition
ExpAllHook2:
push {r0-r7}
@ Check if Pokemon is an egg
ldr r0, =(0x2016018)
ldrb r0, [r0]
CMP R0, #0
BEQ NOT_EXP

POP {R0}

LSR R0, R1, #1

@ mov r0, r1
@ push {r1, r3}
@ mov r1, #2
@ swi #0x6
@ pop {r1, r3}

BACK_TO:
LDR R1, = 0x080201A8+1
BX R1

NOT_EXP:
POP {R0}
LDR R2, = 0x080201E0+1
BX R2

@
GetSentInPokeForExp:
LDRH R0, [R3]

LDR R2, = 0x02016018
LDRB R2, [R2]

LDR R5, = 0x02024A6A
LDRB R7, [R5]
CMP R7, R2
BEQ RETURN

LDR R7, = 0x020239F8
LDRB R7, [R7]
MOV R3, #1
AND R7, R3
CMP R7, #1
BEQ DOUBLE

DIVIDE:
PUSH {R1-R7}
MOV R1, #3
BL DIVISION
POP {R1-R7}

RETURN:
STRH R0, [R1]
MOV R8, R1
LDR R0, = 0x08020376+1
BX R0

DOUBLE:
LDRB R7, [R5, #4]
CMP R7, R2
BEQ RETURN
B DIVIDE

DIVISION:
LDR R2, = 0x081E0868+1
BX R2

mov r1, #100
mul r1, r0, r1

ldr r0, =(gPlayerParty)
add r0, r1, r0

mov r1, #45

bl ExpAllHook2_GetMonData

cmp r0, #1
beq ExpAllHook2_ConditionBlock

push {r0-r7}
bl PrintR0
pop {r0-r7}

@ Check if Exp All is enabled
ldr r3, =(gExpAllEnabled)
ldrb r3, [r3]

cmp r3, #0
bne ExpAllHook2_NextCondition

@ Check if Pokemon was sent out
ldr r1, =(0x201605F)
ldrb r0, [r1]

mov r2, #1
and r2, r0

cmp r2, #0
bne ExpAllHook2_NextCondition

ExpAllHook2_ConditionBlock:
@ set sent in pokes
ldr r1, =(0x201605F)
ldrb r0, [r1]

lsr r0, r0, #1
strb r0, [r1]

@ Get exp tracker state
ldr r1, =(0x201600F)
mov r0, #5
strb r0, [r1]

@ Set total exp to zero
ldr r1, =(0x2024bec)
mov r0, #0
str r0, [r1]

ExpAllHook2_ConditionEnd:
pop {r0-r7}
ldr r0, =(0x8020996 | 1)
bx r0

ExpAllHook2_NextCondition:
pop {r0-r7}
ldr r3, =(0x80202a0 | 1)
bx r3

ExpAllHook2_GetMonData:
ldr r7, =(GetMonData)
bx r7

@ 0x802033c - hook via r1
@ 0x8020386 - return
ExpAllHook3:
push {r0-r7}

@ Check if Pokemon was sent out
ldr r1, =(0x201605F)
ldrb r0, [r1]

mov r1, #1
and r1, r0

cmp r1, #0
beq ExpAllHook3_CheckIfShareActive
mov r7, sl
ldrh r7, [r7]

b ExpAllHook3_ConditionEnd

ExpAllHook3_CheckIfShareActive:
ldr r1, =(gExpAllEnabled)
ldrb r1, [r1]

cmp r1, #0
beq ExpAllHook3_SetExpToZero

ldr r7, =(0x2024dee)
ldrh r7, [r7]

b ExpAllHook3_ConditionEnd

ExpAllHook3_SetExpToZero:
mov r7, #0

ExpAllHook3_ConditionEnd:
ldr r1, =(0x2024bec)
str r7, [r1]

pop {r0-r7}

ldr r3, =(0x8020386 | 1)
bx r3

2 changes: 1 addition & 1 deletion config.asm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
.definelabel AUTORUN, 1

; Doubles Exp. Points gained after battles.
.definelabel MORE_EXP, 1
.definelabel MORE_EXP, 0

; New "Snakewood" logo
.definelabel NEW_TITLE_SCREEN, 1
Expand Down
6 changes: 5 additions & 1 deletion linker/ram.ld
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ gBattleBufferA = 0x2023a60;
gAutorunEnabled = 0x2024f34;
gExpandedItemPockets = 0x2025420;
gRegisteredItems = 0x2025520;
gExpAllEnabled = 0x202552C;
gExpAllEnabled = 0x2025530;

gMapHeader = 0x202e828;
gPlayerAvatar = 0x202e858;
Expand All @@ -65,6 +65,9 @@ sCurrentBagPocket = 0x2038559;
gSpecialVar_ItemId = 0x203855e;
gWeather = 0x202f7e8;
gMoveSelectionCursor = 0x2024e64;
gBank1 = 0x2024c09;
gBattlerPartyIndexes = 0x2024a6a;
gSentPokesToOpponent = 0x2024dea;

/* gRepelMenuChoices = 0x203a400; */
/* gLastUsedRegisteredItem = 0x203a404; */
Expand All @@ -81,3 +84,4 @@ gCurrentBagPocketItemSlots = 0x3005d24;
gScriptContext1 = 0x3007440;
sMessageBoxMode = 0x30074b8;
gWindowTemplate_Contest_MoveDescription = 0x3004210;
gBattleTextBuff1 = 0x30041c0;
5 changes: 4 additions & 1 deletion linker/rodata.ld
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ BattleStatText_SpDef = 0x84007f2;
OtherText_MaleSymbol = 0x8410458;
OtherText_FemaleSymbol = 0x841045a;
gNamingScreenPtr = 0x83ce214;
gTrainers = 0x81f04fc;
gTrainers = 0x81f04fc;
gBitTable = 0x820872c;
BattleScript_LevelUp = 0x81d8ef3;

1 change: 1 addition & 0 deletions linker/text.ld
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,4 @@ MainState_StartPageSwap = 0x80b61c8 | 1;
GetTextEntryPosition = 0x80b6f44 | 1;
ResetGpuAndVram = 0x80f9368 | 1;
CountPartyNonEggMons = 0x8095b6c | 1;
HandleLowHpMusicChange = 0x80324f8 | 1;
21 changes: 10 additions & 11 deletions scripts/exp_all.asm
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
.if EXP_ALL

.org 0x8020024
.halfword 0x4710
.org 0x8020164
b 0x802016a

.org 0x8020058
.word (CountEligiblePokeForExp | 1)
.org 0x802019a
nop
set_function_hook r4, ExpAllHook1

.org 0x802019A
.halfword 0x0
.word 0x47004800
.word (SetExpAmount | 1)
.org 0x8020276
nop
set_function_hook r3, ExpAllHook2

.org 0x8020344
.word 0x47004800
.word (GetSentInPokeForExp | 1)
.org 0x802033c
set_function_hook r3, ExpAllHook3

.org 0x83c5564 + 44 * ITEM_BRAIN_LINK + 24
.byte 0x1, 0x1
Expand Down
Loading

0 comments on commit 030df17

Please sign in to comment.