Percobaan12

.equ Total\_Item\_Amount, 700 @Change to largest item index number

.equ Regular\_Item\_Num, 200 @Change to number of items in main bag pocket divided by 2
.equ Key\_Item\_Num, 30 @Change to number of items in key item pocket divided by 2
.equ Poke\_Ball\_Num, 14 @Change to number of items in Poke Ball pocket divided by 2
.equ TM\_Num, 128 @Change to number of TMs + HMs
.equ Berry\_Num, 67 @Change to number of berries

@When changing the following RAM Adresses, make sure no data is being overwritten.
@For example, if you want to change the Poke\_Ball\_Ram, it needs to be changed to
@a location where there are (Poke\_Ball\_Num \* 2 \* 4) bytes of memory free.
.equ TM\_Ram, 0x202583C @Change to your TM Case RAM address
.equ Berry\_Ram, 0x2025A3C @Change to your Berry Pouch RAM address
.equ Key\_Item\_Ram, 0x203C7D0 @Change to your Key Item pocket RAM address
.equ Poke\_Ball\_Ram, 0x203C8C0 @Change to your main Poke Ball Pocket RAM address
.equ Item\_Ram, 0x203C930 @Change to your main bag pocket RAM address

.equ Free\_Ram, 0x203D900 @Don't change unless you don't like this free ram
.equ offset, 0x8D1980 @Change to Free Space Offset

.equ largest\_pocket\_size, Regular\_Item\_Num \* 2
.equ largest\_pocket\_size\_plus\_one, largest\_pocket\_size + 1
.equ strings\_size, largest\_pocket\_size\_plus\_one \* 19

.equ rom, 0x8000000

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@HelperRoutine

.org 0x28760, 0xFF
GetItemAmount:
 push {r1,lr}
 ldr r0, .CurrentPocket
 ldrb r0, [r0]
 lsl r0, #0x1
 ldr r1, .ItemStorage
 ldrh r0, [r0, r1]
 pop {r1,pc}

.align 2
.CurrentPocket: .word 0x203AD02
.ItemStorage: .word Free\_Ram

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Decryption and DMA Negation
@The first few of these actually decrypt the Pokemon Data because why not?

.org 0x3F906, 0xFF
mov r8, r8
str r0, [r2]
ldr r1, [r3, #0x4]
mov r8, r8

.org 0x3F92A, 0xFF
mov r8, r8
str r0, [r2]
ldr r1, [r3]
mov r8, r8

.org 0x3F94C, 0xFF
mov r0, #0x0
mov r8, r8
mov r8, r8

.org 0x3FDA8, 0xFF
b 0x3FDC2

.org 0x40530, 0xFF
b 0x40550

.org 0x40AE6, 0xFF
mov r8, r8

.org 0x4C062, 0xFF
mov r1, #0x0
mov r1, #0x0

.org 0x4C13C, 0xFF
mov r4, #0x0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

.org 0x6BDEC, 0xFF
 ldr r0, .BerryFix1Ptr
 bx r0
.align 2
.BerryFix1Ptr: .word BerryFix1Ptr + rom + 1

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Removal of Item Limiters

.org 0x98998, 0xFF
.word Total\_Item\_Amount

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Routines Related to Obtaining Items

.org 0x99DFC, 0xFF
ldrh r0, [r0, #0x4]

.org 0x99E1A, 0xFF
ldrh r4, [r4, #0x4]

.org 0x99E44, 0xFF
ldr r1, .BagPocket0

@Regular items
ldr r0, ram\_FREE\_item
str r0, [r1]
mov r0, #Regular\_Item\_Num
lsl r0, #0x1 @400 regular items
strh r0, [r1, #0x4]

@Key items
ldr r0, ram\_FREE\_keyitem
str r0, [r1, #0x8]
mov r0, #(Key\_Item\_Num \* 2) @60 key items
strh r0, [r1, #0xC]

@Poke balls
ldr r0, ball\_ram
str r0, [r1, #0x10]
mov r0, #(Poke\_Ball\_Num \* 2) @28 balls
strh r0, [r1, #0x14]

@Tms
ldr r0, tm\_ram
str r0, [r1, #0x18]
mov r0, #TM\_Num @128 TMs
strh r0, [r1, #0x1C]

@Berries
ldr r0, berry\_ram
str r0, [r1, #0x20]
add r1, #0x24
mov r0, #Berry\_Num @67 berries
strh r0, [r1]
bx lr

.align 2
.BagPocket0: .word 0x203988C
tm\_ram: .word TM\_Ram
berry\_ram: .word Berry\_Ram
ram\_FREE\_keyitem: .word Key\_Item\_Ram
ball\_ram: .word Poke\_Ball\_Ram
ram\_FREE\_item: .word Item\_Ram

.org 0x99ED8, 0xFF
ldrh r1, [r0, #0x4]

.org 0x99EEA, 0xFF
lsl r0, r2, #0x10
lsr r0, r0, #0x10

.org 0x99F16, 0xFF
ldrh r1, [r0, #0x4]

.org 0x99F32, 0xFF
lsl r0, r0, #0x10
lsl r2, r0, #0x10

.org 0x99F6E, 0xFF
ldrh r1, [r0, #0x4]

.org 0x99F9A, 0xFF
lsl r0, r0, #0x10
lsr r2, r0, #0x10
ldrh r0, [r3, #0x4]

.org 0x99FD4, 0xFF
CheckBerryInBagFix:
 ldr r4, .LastResult
 ldr r0, .CheckBerryBerryRam
 ldrh r0, [r0]
 cmp r0, #0x0
 beq NoBerriesInBag
 mov r0, #0x1
 strh r0, [r4]
 pop {r4,pc}

NoBerriesInBag:
 mov r0, #0x0
 strh r0, [r4]
 pop {r4,pc}

.align 2
.CheckBerryBerryRam: .word Berry\_Ram
.LastResult: .word 0x020370D0

.org 0x9A02A, 0xFF
ldrh r1, [r0, #0x4]

.org 0x9A05E, 0xFF
lsl r0, r0, #0x10
lsr r2, r0, #0x10
ldrh r0, [r3, #0x4]

.org 0x9A06E, 0xFF
lsl r0, r0, #0x10
lsr r0, r0, #0x10

.org 0x9A0B6, 0xFF
ldrh r1, [r0, #0x4]

.org 0x9A0EA, 0xFF
lsl r0, r0, #0x10
lsr r2, r0, #0x10
ldrh r0, [r5, #0x4]

.org 0x9A110, 0xFF
lsl r0, r0, #0x10
lsr r1, r0, #0x10

.org 0x9A14C, 0xFF
lsl r0, r0, #0x10
lsr r1, r0, #0x10

.org 0x9A186, 0xFF
lsl r0, r0, #0x10
lsr r2, r0, #0x10

.org 0x9A204, 0xFF
ldrh r1, [r0, #0x4]

.org 0x9A24E, 0xFF
lsl r0, r0, #0x10
lsr r2, r0, #0x10
ldrh r0, [r6, #0x4]

.org 0x9A2E8, 0xFF
ldrh r1, [r1, #0x4]

.org 0x9A58E, 0xFF @Shifting Items Up
lsl r1, #0x10
lsr r1, #0x10

.org 0x09A8A4, 0xFF
 lsl r0, #0x10
 lsr r0, #0x10
 ldr r1, .ItemLimit
 cmp r1, r0
 bge Return
 mov r0, #0x0
Return:
 bx lr

.align 2
.ItemLimit: .word Total\_Item\_Amount

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Routines Related to the Pokedex

@The original ram provided above for the berries overrites a copy of the Pokedex data.
@Thus, when the Berry Pouch is sorted upon opening it, garbage data from this dex
@data is loaded. These routines prevent this copy from being read from or written to.

BerryPokedexDataFix:
.org 0x104B34, 0xFF
b 0x104B56

.org 0x104B78, 0xFF
b 0x104BB0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Routines Related to Viewing Items in Bag

Bag\_Allocate\_Stuff: @Credits to azurile13
.org 0x1083F4, 0xFF
 push {r4,lr}
 ldr r4, .AllocationPointer
 ldr r0, .LargestSize
 lsl r0, #0x3
 bl 0x2B9C @malloc
 str r0, [r4]
 cmp r0, #0x0
 beq No
 ldr r0, .strings\_size
 bl 0x2B9C @malloc
 str r0, [r4, #0x4]
 cmp r0, #0x0
 beq No
 mov r0, #0x1
 b End

No:
 mov r0, #0x0

End:
 pop {r4,pc}

.align 2
.LargestSize: .word largest\_pocket\_size\_plus\_one
.AllocationPointer: .word 0x0203AD18
.strings\_size: .word strings\_size

.org 0x108440, 0xFF
bl 0x28760 @GetItemAmount
b 0x10844A

.org 0x10847E, 0xFF @Shop is dis one
bl 0x28760 @GetItemAmount
b 0x108488

.org 0x1084C2, 0xFF
bl 0x28760 @GetItemAmount
b 0x1084CA

.org 0x1085D8, 0xFF
push {r1}
bl 0x28760 @GetItemAmount
pop {r1}
cmp r0, r5

.org 0x108698, 0xFF
ldr r5, .Thing
ldrh r1, [r5, #0x6]
push {r1}
bl 0x28760 @GetItemAmount
pop {r1}
.hword 0x0
cmp r0, r4

.org 0x10871C, 0xFF
.Thing: .word 0x203ACFC

.org 0x10881E, 0xFF
ldr r1, .Thing2
ldrh r1, [r1, #0x6]
push {r1}
bl 0x28760 @GetItemAmount
pop {r1}
.hword 0x0
cmp r2, r0

.org 0x108850, 0xFF
.Thing2: .word 0x203ACFC

.org 0x108894, 0xFF
push {r1}
bl 0x28760 @GetItemAmount
pop {r1}
add r1, #0xD

.org 0x108A1C, 0xFF @Up Cursor Bug 1
ldr r1, .OpenBagBugFix1Pointer
bx r1
.align 2
.OpenBagBugFix1Pointer: .word OpenBagBugFix1 + rom + 1

.org 0x108A40, 0xFF @Up Cursor Bug 2
ldr r0, .OpenBagBugFix2Pointer
bx r0
.align 2
.OpenBagBugFix2Pointer: .word OpenBagBugFix2 + rom + 1
.hword 0x0

.org 0x108AC0, 0xFF @Up Cursor Bug 3
ldr r0, .OpenBagBugFix3Pointer
bx r0
.align 2
.OpenBagBugFix3Pointer: .word OpenBagBugFix3 + rom + 1

.org 0x108DC8, 0xFF
ldr r1, .StoreItemPointer
bx r1
.align 2
.StoreItemPointer: .word StoreItem + rom + 1

ldr r0, .Bag\_Pocket\_0\_2
add r4, r1, r0
ldr r0, [r4]
ldrh r1, [r4, #0x4]

.org 0x108DEA, 0xFF
ldrh r0, [r4, #0x4]

.org 0x108E0A, 0xFF
ldrh r0, [r4, #0x4]

.org 0x108E20, 0xFF
ldr r0, .GetSmallestItemAmountPointer
bx r0
.align 2
.GetSmallestItemAmountPointer: .word GetSmallestItemAmount + rom + 1

.org 0x108E3C, 0xFF
.Bag\_Pocket\_0\_2: .word 0x203988C

.org 0x108E4C, 0xFF
pop {r4-r6,pc}

.org 0x108FB6, 0xFF
ldrh r5, [r5, #0x6]
push {r1}
bl 0x28760 @GetItemAmount
pop {r1}
.hword 0x0
cmp r1, r0

.org 0x10904A, 0xFF
 ldrh r1, [r5, #0x6]
 push {r1}
 bl 0x28760 @GetItemAmount
 pop {r1}
 .hword 0x0
 cmp r4, r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Poke Dude Stuff

.org 0x10ADDE, 0xFF
 ldr r0, .PokeDudeBackupRegularBagFixPtr
 bx r0
.align 2
.PokeDudeBackupRegularBagFixPtr: .word PokeDudeBackupRegularBagFix + rom + 1

.org 0x10AE78, 0xFF
 ldr r0, .PokeDudeBackupRegularBagClearPtr
 bx r0
.align 2
.PokeDudeBackupRegularBagClearPtr: .word PokeDudeBackupRegularBagClear + rom + 1

.org 0x10AEDA, 0xFF
 ldr r0, .PokeDudeBackupBagRestorePtr
 bx r0
.align 2
.PokeDudeBackupBagRestorePtr: .word PokeDudeBackupBagRestore + rom + 1

.org 0x132E76, 0xFF
 ldr r1, .PokeDudeBackupTMCasePtr
 bx r1
.align 2
.PokeDudeBackupTMCasePtr: .word PokeDudeBackupTMCase + rom + 1

.org 0x132EB0, 0xFF
 ldr r0, .PokeDudeClearTMCasePtr
 bx r0
.align 2
.PokeDudeClearTMCasePtr: .word PokeDudeClearTMCase + rom + 1

.org 0x13318C, 0xFF
 ldr r0, .PokeDudeRestoreTMCasePtr
 bx r0
.align 2
.PokeDudeRestoreTMCasePtr: .word PokeDudeRestoreTMCase + rom + 1

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Remove Help System

.org 0x13B8C2, 0xFF
b 0x13B900

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@More Berry Stuff

.org 0x13D1C4, 0xFF
 mov r0, #Berry\_Num + 1
 lsl r0, #0x3

**.org 0x13D33C, 0xFF
BerryNumFixesHook:
 ldr r0, .BerryNumFixesPtr
 bx r0
.align 2
.BerryNumFixesPtr: .word BerryNumFixes + rom + 1**

BerryFix2Hook:
.org 0x14A490, 0xFF
 ldr r0, .BerryFix2Ptr
 bx r0
.align 2
.BerryFix2Ptr: .word BerryFix2 + rom + 1

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@New Routine

.org offset, 0xFF
StoreItem:
 push {r4-r6,lr}
 lsl r0, r0, #0x18
 lsr r5, r0, #0x18
 mov r4, #0x0

GetItemInBagCount:
 mov r6, #0x0
 lsl r0, r4, #0x3
 ldr r1, .Table
 add r0, r1
 ldrh r3, [r0, #0x4]
 lsl r3, #0x1
 ldr r0, [r0]
 mov r1, #0x0

Loop:
 cmp r1, r3
 beq StoreAmount
 ldrh r2, [r0]
 cmp r2, #0x0
 beq CheckNextItemJustInCase
 add r0, #0x4
 add r1, #0x1
 b Loop

CheckNextItemJustInCase:
 ldrh r2, [r0, #0x4]
 cmp r2, #0x0
 beq StoreAmount
 add r0, #0x4
 add r1, #0x1
 mov r6, #0x1
 b Loop

StoreAmount:
 cmp r6, #0x0
 beq NotShopSkip
 sub r1, #0x1
NotShopSkip:
 ldr r0, .ItemStorage2
 lsl r2, r4, #0x1
 add r0, r2
 strh r1, [r0]
 add r4, #0x1
 cmp r4, #0x3
 beq ReturnToThing
 b GetItemInBagCount

ReturnToThing:
 lsl r1, r5, #0x3
 ldr r0, =0x8108DD1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

GetSmallestItemAmount:
 push {r1}
 ldr r0, .ItemStorage2
 lsl r1, r5, #0x1
 add r0, r1
 pop {r1}
 ldrh r0, [r0]
 ldr r3, =0x8108E29
 bx r3

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

OpenBagBugFix1:
 push {r0}
 lsl r0, r4, #0x1
 ldr r1, .ItemStorage2
 add r1, r0
 ldrh r1, [r1]
 pop {r0}
 add r0, r1, #0x1
 cmp r2, r0
 ldr r0, =0x8108A26 | 1
 bx r0

OpenBagBugFix2:
 lsl r3, r4, #0x1
 ldr r0, .ItemStorage2
 add r0, r3
 ldrh r0, [r0]
 add r3, r0, #0x1
 ldr r4, =0x8108A4C | 1
 bx r4

OpenBagBugFix3:
 lsl r1, r6, #0x1
 ldr r0, .ItemStorage2
 add r0, r1
 ldrh r0, [r0]
 add r0, #0x1
 ldr r1, =0x8108AC8 | 1
 bx r1

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

PokeDudeBackupRegularBagFix:
 ldr r5, .PokeDudeItemBackupPtr
 ldr r0, .NewMallocPokeDudeBagSpace
 bl Calloc
 str r0, [r5]
 ldr r1, =Item\_Ram
 ldr r2, =Regular\_Item\_Num \* 2 \* 4
 mov r4, r2
 bl Memcpy

 ldr r0, [r5]
 add r0, r4
 ldr r1, =Key\_Item\_Ram
 ldr r2, =Key\_Item\_Num \* 2 \* 4
 add r4, r2
 bl Memcpy

 ldr r0, [r5]
 add r0, r4
 ldr r1, =Poke\_Ball\_Ram
 ldr r2, =Poke\_Ball\_Num \* 2 \* 4
 bl Memcpy

 ldr r4, .SaveBlock1
 ldr r0, =0x810AE22 | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@0x810AE78 with r0
PokeDudeBackupRegularBagClear:
 ldr r0, =Item\_Ram
 ldr r1, =Regular\_Item\_Num \* 2
 bl RemoveNItems

 ldr r0, =Key\_Item\_Ram
 mov r1, #Key\_Item\_Num \* 2
 bl RemoveNItems

 ldr r0, =Poke\_Ball\_Ram
 mov r1, #Poke\_Ball\_Num \* 2
 bl RemoveNItems

 ldr r4, .SaveBlock1
 ldr r0, =0x810AEA4 | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@0x10AEDA with r0
PokeDudeBackupBagRestore:
 ldr r0, =Item\_Ram
 ldr r1, [r5]
 ldr r2, =Regular\_Item\_Num \* 2 \* 4
 mov r4, r2
 bl Memcpy

 ldr r0, =Key\_Item\_Ram
 ldr r1, [r5]
 add r1, r4
 ldr r2, =Key\_Item\_Num \* 2 \* 4
 add r4, r2
 bl Memcpy

 ldr r0, =Poke\_Ball\_Ram
 ldr r1, [r5]
 add r1, r4
 ldr r2, =Poke\_Ball\_Num \* 2 \* 4
 bl Memcpy

 ldr r4, .SaveBlock1
 ldr r0, =0x810AF0C | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@0x8132E76 with r1
PokeDudeBackupTMCase:
 ldr r1, =TM\_Ram
 ldr r2, =TM\_Num \* 4
 mov r5, r2
 bl Memcpy

 ldr r0, [r4]
 add r0, r5
 ldr r1, =Key\_Item\_Ram \* 2 \* 4
 ldr r2, =Key\_Item\_Num \* 2 \* 4
 bl Memcpy

 ldr r0, =0x8132E98 | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@0x132EB0 with r0
PokeDudeClearTMCase:
 ldr r0, =TM\_Ram
 mov r1, #TM\_Num
 bl RemoveNItems

 ldr r0, =Key\_Item\_Ram
 mov r1, #Key\_Item\_Num
 bl RemoveNItems

 ldr r0, =0x8132EC4 | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@0x813318C with r0
PokeDudeRestoreTMCase:
 ldr r0, =TM\_Ram
 ldr r2, =TM\_Num \* 4
 bl Memcpy

 ldr r0, =Key\_Item\_Ram
 ldr r1, [r5]
 ldr r2, =Key\_Item\_Num \* 2 \* 4
 bl Memcpy

 ldr r0, =0x81331A4 | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

BerryFix1Ptr:
 cmp r6, #0x1
 bls BerryFix1Return
 mov r0, r5
 bl GetItemPocket
 cmp r0, #0x5 @Berry Pouch
 bne BerryFix1Return
 ldr r0, =0x806BDFC | 1
 bx r0

BerryFix1Return:
 ldr r0, =0x806BE22 | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@0x14A490 with r0
BerryFix2:
 cmp r6, #0x0
 beq BerryFix2Return
 mov r0, r4
 bl GetItemMystery2 @BerryId

BerryFix2Return:
 ldr r0, =0x814A4C2 | 1
 bx r0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@0x13D33C with r0
BerryNumFixes:
 mov r0, r5
 bl GetItemMystery2
 mov r1, r0
 mov r0, r6
 mov r2, #0x2
 ldr r3, =0x813D344 | 1
 bx r3

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Calloc:
 ldr r1, =0x8002BB0 | 1
 bx r1

Memcpy:
 ldr r3, =0x81E5E78 | 1
 bx r3

RemoveNItems:
 ldr r2, =0x809A274 | 1
 bx r2

GetItemPocket:
 ldr r1, =0x809A9D8 | 1
 bx r1

GetItemMystery2:
 ldr r1, =0x809A9B4 | 1
 bx r1

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

.align 2
.ItemStorage2: .word Free\_Ram
.Table: .word TABLE + rom
.PokeDudeItemBackupPtr: .word 0x203AD2C
.NewMallocPokeDudeBagSpace: .word (Regular\_Item\_Num + Key\_Item\_Num + Poke\_Ball\_Num) \* 2 \* 4
.SaveBlock1: .word 0x3005008

.align 2
TABLE:
.word Item\_Ram
.hword Regular\_Item\_Num, 0x0

.word Key\_Item\_Ram
.hword Key\_Item\_Num, 0x0

.word Poke\_Ball\_Ram
.hword Poke\_Ball\_Num, 0x0

.word 0xFFFFFFFF, 0xFFFFFFFF