summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arm9/arm9.lsf2
-rw-r--r--arm9/asm/scrcmd_18.s64
-rw-r--r--arm9/asm/script_pokemon_util.s83
-rw-r--r--arm9/global.inc1
-rw-r--r--arm9/src/scrcmd_18_c.c23
-rw-r--r--arm9/src/script_pokemon_util_c.c39
-rw-r--r--include/constants/pokemon.h4
-rw-r--r--include/unk_0202C144.h6
8 files changed, 75 insertions, 147 deletions
diff --git a/arm9/arm9.lsf b/arm9/arm9.lsf
index 39d2ed1e..493af3c1 100644
--- a/arm9/arm9.lsf
+++ b/arm9/arm9.lsf
@@ -167,6 +167,7 @@ Static arm9
Object scrcmd_15.o
Object scrcmd_16.o
Object scrcmd_17.o
+ Object scrcmd_18_c.o
Object scrcmd_18.o
Object scrcmd_19.o
Object scrcmd_20.o
@@ -184,6 +185,7 @@ Static arm9
Object unk_02048120.o
Object unk_020484A8.o
Object unk_02048904.o
+ Object script_pokemon_util_c.o
Object script_pokemon_util.o
Object unk_0204A368.o
Object unk_0204A498.o
diff --git a/arm9/asm/scrcmd_18.s b/arm9/asm/scrcmd_18.s
index 09cb74b0..4b0acb12 100644
--- a/arm9/asm/scrcmd_18.s
+++ b/arm9/asm/scrcmd_18.s
@@ -3,70 +3,6 @@
.text
- thumb_func_start ScrCmd_givemon
-ScrCmd_givemon: ; 0x020442BC
- push {r4-r7, lr}
- sub sp, #0x14
- add r4, r0, #0x0
- add r0, #0x80
- ldr r0, [r0, #0x0]
- ldr r0, [r0, #0x1c]
- ldr r0, [r0, #0x0]
- bl FUN_02034824
- add r6, r0, #0x0
- add r0, r4, #0x0
- add r0, #0x80
- ldr r5, [r0, #0x0]
- add r0, r4, #0x0
- bl ScriptReadHalfword
- add r1, r0, #0x0
- add r0, r4, #0x0
- add r0, #0x80
- ldr r0, [r0, #0x0]
- bl VarGet
- str r0, [sp, #0xc]
- add r0, r4, #0x0
- bl ScriptReadHalfword
- add r1, r0, #0x0
- add r0, r4, #0x0
- add r0, #0x80
- ldr r0, [r0, #0x0]
- bl VarGet
- add r7, r0, #0x0
- add r0, r4, #0x0
- bl ScriptReadHalfword
- add r1, r0, #0x0
- add r0, r4, #0x0
- add r0, #0x80
- ldr r0, [r0, #0x0]
- bl VarGet
- str r0, [sp, #0x10]
- add r0, r4, #0x0
- bl ScriptReadHalfword
- add r4, #0x80
- add r1, r0, #0x0
- ldr r0, [r4, #0x0]
- bl GetVarPointer
- add r4, r0, #0x0
- ldr r0, [r5, #0xc]
- bl SavArray_PlayerParty_get
- ldr r0, [sp, #0x10]
- lsl r3, r7, #0x18
- str r0, [sp, #0x0]
- str r6, [sp, #0x4]
- mov r0, #0xc
- str r0, [sp, #0x8]
- ldr r1, [r5, #0xc]
- ldr r2, [sp, #0xc]
- mov r0, #0xb
- lsr r3, r3, #0x18
- bl GiveMon
- strh r0, [r4, #0x0]
- mov r0, #0x0
- add sp, #0x14
- pop {r4-r7, pc}
- .balign 4
-
thumb_func_start ScrCmd_getpartyspecies
ScrCmd_getpartyspecies: ; 0x0204434C
; getpartyspecies XXXX, YYYY
diff --git a/arm9/asm/script_pokemon_util.s b/arm9/asm/script_pokemon_util.s
index 49ac1fa6..90891e3f 100644
--- a/arm9/asm/script_pokemon_util.s
+++ b/arm9/asm/script_pokemon_util.s
@@ -3,89 +3,6 @@
.text
- thumb_func_start MonNotFaintedOrEgg
-MonNotFaintedOrEgg: ; 0x0204A01C
- push {r4, lr}
- mov r1, #0xa2
- mov r2, #0x0
- add r4, r0, #0x0
- bl GetMonData
- cmp r0, #0x0
- bne _0204A030
- mov r0, #0x0
- pop {r4, pc}
-_0204A030:
- add r0, r4, #0x0
- mov r1, #0x4c
- mov r2, #0x0
- bl GetMonData
- cmp r0, #0x0
- bne _0204A042
- mov r0, #0x1
- pop {r4, pc}
-_0204A042:
- mov r0, #0x0
- pop {r4, pc}
- .balign 4
-
- thumb_func_start GiveMon
-GiveMon: ; 0x0204A048
- push {r3-r7, lr}
- sub sp, #0x20
- add r6, r1, #0x0
- add r5, r0, #0x0
- add r0, r6, #0x0
- add r7, r2, #0x0
- str r3, [sp, #0x10]
- bl Sav2_PlayerData_GetProfileAddr
- str r0, [sp, #0x14]
- add r0, r6, #0x0
- bl SavArray_PlayerParty_get
- str r0, [sp, #0x18]
- add r0, r5, #0x0
- bl AllocMonZeroed
- add r4, r0, #0x0
- bl ZeroMonData
- mov r0, #0x0
- str r0, [sp, #0x0]
- str r0, [sp, #0x4]
- str r0, [sp, #0x8]
- str r0, [sp, #0xc]
- ldr r2, [sp, #0x10]
- add r0, r4, #0x0
- add r1, r7, #0x0
- mov r3, #0x20
- bl CreateMon
- ldr r0, [sp, #0x40]
- ldr r1, [sp, #0x14]
- str r0, [sp, #0x0]
- ldr r3, [sp, #0x3c]
- add r0, r4, #0x0
- mov r2, #0x4
- str r5, [sp, #0x4]
- bl FUN_0206A014
- add r0, sp, #0x28
- ldrh r0, [r0, #0x10]
- mov r1, #0x6
- add r2, sp, #0x1c
- str r0, [sp, #0x1c]
- add r0, r4, #0x0
- bl SetMonData
- ldr r0, [sp, #0x18]
- add r1, r4, #0x0
- bl AddMonToParty
- add r5, r0, #0x0
- beq _0204A0BC
- add r0, r6, #0x0
- add r1, r4, #0x0
- bl FUN_0202C144
-_0204A0BC:
- add r0, r4, #0x0
- bl FreeToHeap
- add r0, r5, #0x0
- add sp, #0x20
- pop {r3-r7, pc}
-
thumb_func_start GiveEgg
GiveEgg: ; 0x0204A0C8
push {r4-r7, lr}
diff --git a/arm9/global.inc b/arm9/global.inc
index 29501049..787034d3 100644
--- a/arm9/global.inc
+++ b/arm9/global.inc
@@ -8482,3 +8482,4 @@
.extern gSineTable
.extern CARDi_IdentifyBackupCore
.extern CARDi_InitCommon
+.extern MonNotFaintedOrEgg
diff --git a/arm9/src/scrcmd_18_c.c b/arm9/src/scrcmd_18_c.c
new file mode 100644
index 00000000..e4f950c5
--- /dev/null
+++ b/arm9/src/scrcmd_18_c.c
@@ -0,0 +1,23 @@
+#include "global.h"
+#include "script.h"
+#include "party.h"
+#include "save_block_2.h"
+#include "unk_0204639C.h"
+#include "map_header.h"
+
+extern u16 VarGet(struct UnkStruct_0204639C* arg, u16 wk);
+extern u16 *GetVarPointer(struct UnkStruct_0204639C* arg, u16);
+extern BOOL GiveMon(u32 heap_id, struct SaveBlock2 * sav2, u16 species, u8 level, u16 item, u32 mapSec, u8 encounterType);
+
+THUMB_FUNC BOOL ScrCmd_givemon(struct ScriptContext* ctx)
+{
+ u32 mapSec = FUN_02034824(*(ctx->unk80->unk1C));
+ struct UnkStruct_0204639C *savePtr = ctx->unk80;
+ u16 species = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 level = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 item = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 * varPtr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ struct PlayerParty * party = SavArray_PlayerParty_get((struct SaveBlock2 *) savePtr->unkC);
+ *varPtr = GiveMon(11, (struct SaveBlock2 *) savePtr->unkC, species, level, item, mapSec, 12);
+ return FALSE;
+} \ No newline at end of file
diff --git a/arm9/src/script_pokemon_util_c.c b/arm9/src/script_pokemon_util_c.c
new file mode 100644
index 00000000..7ab52b67
--- /dev/null
+++ b/arm9/src/script_pokemon_util_c.c
@@ -0,0 +1,39 @@
+#include "global.h"
+#include "heap.h"
+#include "party.h"
+#include "player_data.h"
+#include "pokemon.h"
+#include "save_block_2.h"
+#include "unk_0202C144.h"
+#include "constants/items.h"
+
+#pragma thumb on
+
+BOOL MonNotFaintedOrEgg(struct Pokemon * pokemon)
+{
+ if (GetMonData(pokemon, MON_DATA_HP, NULL) == 0)
+ return FALSE;
+ if (GetMonData(pokemon, MON_DATA_IS_EGG, NULL))
+ return FALSE;
+ return TRUE;
+}
+
+BOOL GiveMon(u32 heap_id, struct SaveBlock2 * sav2, u16 species, u8 level, u16 item, u32 mapSec, u32 encounterType)
+{
+ u32 ptr;
+ struct PlayerData * data = Sav2_PlayerData_GetProfileAddr(sav2);
+ struct PlayerParty * party = SavArray_PlayerParty_get(sav2);
+ struct Pokemon * mon = AllocMonZeroed(heap_id);
+ ZeroMonData(mon);
+ CreateMon(mon, species, level, 32, 0, 0, OT_ID_PLAYER_ID, 0);
+ FUN_0206A014(mon, data, ITEM_POKE_BALL, mapSec, encounterType, heap_id);
+ ptr = item;
+ SetMonData(mon, MON_DATA_HELD_ITEM, &ptr);
+ BOOL isAdded = AddMonToParty(party, mon);
+ if (isAdded)
+ {
+ FUN_0202C144(sav2, mon);
+ }
+ FreeToHeap(mon);
+ return isAdded;
+}
diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h
index 06a105b6..2ae4964d 100644
--- a/include/constants/pokemon.h
+++ b/include/constants/pokemon.h
@@ -275,6 +275,10 @@
#define MON_DATA_TYPE_2 177
#define MON_DATA_SPECIES_NAME 178
+#define OT_ID_PLAYER_ID 0
+#define OT_ID_PRESET 1
+#define OT_ID_RANDOM_NO_SHINY 2
+
#define MON_RATIO_MALE 0
#define MON_RATIO_EIGHTH 31
#define MON_RATIO_QUARTER 63
diff --git a/include/unk_0202C144.h b/include/unk_0202C144.h
new file mode 100644
index 00000000..206beffb
--- /dev/null
+++ b/include/unk_0202C144.h
@@ -0,0 +1,6 @@
+#ifndef POKEDIAMOND_UNK_0202C144_H
+#define POKEDIAMOND_UNK_0202C144_H
+
+void FUN_0202C144(struct SaveBlock2 *, struct Pokemon *);
+
+#endif //POKEDIAMOND_UNK_0202C144_H \ No newline at end of file