diff options
author | Diegoisawesome <Diegoisawesome@users.noreply.github.com> | 2017-10-14 00:05:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-14 00:05:50 -0500 |
commit | 0d38d443b561f9baaae12324712503dfccaf01ea (patch) | |
tree | 2c22380365ddf70f1432cac5f9cbede0bdef2abc /src | |
parent | f6af9e7013107154df62d2eff53e3accb7a24b3d (diff) | |
parent | 924c0c6b5a9ceeb27fdc9e41e69d283c2b8d36d8 (diff) |
Merge pull request #84 from Diegoisawesome/decomp_scrcmd
Decomp scrcmd
Diffstat (limited to 'src')
-rwxr-xr-x | src/braille_puzzles.c | 8 | ||||
-rw-r--r-- | src/coins.c | 2 | ||||
-rw-r--r-- | src/event_data.c | 52 | ||||
-rwxr-xr-x | src/field_map_obj.c | 28 | ||||
-rwxr-xr-x | src/field_special_scene.c | 18 | ||||
-rw-r--r-- | src/lilycove_lady.c | 2 | ||||
-rw-r--r-- | src/money.c | 4 | ||||
-rw-r--r-- | src/new_game.c | 4 | ||||
-rw-r--r-- | src/palette.c | 6 | ||||
-rw-r--r-- | src/pokemon_2.c | 2 | ||||
-rw-r--r-- | src/reset_save_heap.c | 2 | ||||
-rw-r--r-- | src/safari_zone.c | 2 | ||||
-rw-r--r-- | src/scrcmd.c | 2451 | ||||
-rw-r--r-- | src/script.c | 4 | ||||
-rw-r--r-- | src/text.c | 2 | ||||
-rw-r--r-- | src/tv.c | 30 |
16 files changed, 2527 insertions, 90 deletions
diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index 83d32b56c..9a6f0371c 100755 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c @@ -220,7 +220,7 @@ bool8 ShouldDoBrailleStrengthEffect(void) void sub_8179834(void) { - gFieldEffectSpawnParams[0] = brm_get_pokemon_selection(); + gFieldEffectArguments[0] = brm_get_pokemon_selection(); FieldEffectStart(FLDEFF_USE_FLY_ANCIENT_TOMB); } @@ -256,7 +256,7 @@ bool8 ShouldDoBrailleFlyEffect(void) void sub_8179918(void) { - gFieldEffectSpawnParams[0] = brm_get_pokemon_selection(); + gFieldEffectArguments[0] = brm_get_pokemon_selection(); FieldEffectStart(FLDEFF_USE_FLY_ANCIENT_TOMB); } @@ -417,7 +417,7 @@ bool8 ShouldDoBrailleRegicePuzzle(void) } // TODO: Find what flags 2 and 3 are. FlagSet(3); - FlagReset(2); + FlagClear(2); return FALSE; } #else @@ -568,7 +568,7 @@ _08179B44:\n\ movs r0, 0x3\n\ bl FlagSet\n\ movs r0, 0x2\n\ - bl FlagReset\n\ + bl FlagClear\n\ _08179B5A:\n\ movs r0, 0\n\ _08179B5C:\n\ diff --git a/src/coins.c b/src/coins.c index 4ee601b22..e651bc6ca 100644 --- a/src/coins.c +++ b/src/coins.c @@ -54,7 +54,7 @@ void SetCoins(u16 coinAmount) } /* Can't match it lol -bool8 AddCoins(u16 toAdd) +bool8 GiveCoins(u16 toAdd) { u16 newAmount; u16 ownedCoins = GetCoins(); diff --git a/src/event_data.c b/src/event_data.c index fb2edb063..19a310db5 100644 --- a/src/event_data.c +++ b/src/event_data.c @@ -40,11 +40,11 @@ void ClearTempFieldEventData(void) { memset(gSaveBlock1Ptr->flags, 0, TEMP_FLAGS_SIZE); memset(gSaveBlock1Ptr->vars, 0, TEMP_VARS_SIZE); - FlagReset(SYS_ENC_UP_ITEM); - FlagReset(SYS_ENC_DOWN_ITEM); - FlagReset(SYS_USE_STRENGTH); - FlagReset(SYS_CTRL_OBJ_DELETE); - FlagReset(SYS_UNKNOWN_880); + FlagClear(SYS_ENC_UP_ITEM); + FlagClear(SYS_ENC_DOWN_ITEM); + FlagClear(SYS_USE_STRENGTH); + FlagClear(SYS_CTRL_OBJ_DELETE); + FlagClear(SYS_UNKNOWN_880); } // probably had different flag splits at one point. @@ -58,7 +58,7 @@ void DisableNationalPokedex(void) u16 *nationalDexVar = GetVarPointer(VAR_NATIONAL_DEX); gSaveBlock2Ptr->pokedex.nationalMagic = 0; *nationalDexVar = 0; - FlagReset(SYS_NATIONAL_DEX); + FlagClear(SYS_NATIONAL_DEX); } void EnableNationalPokedex(void) @@ -82,7 +82,7 @@ bool32 IsNationalPokedexEnabled(void) void DisableMysteryEvent(void) { - FlagReset(SYS_MYSTERY_EVENT_ENABLE); + FlagClear(SYS_MYSTERY_EVENT_ENABLE); } void EnableMysteryEvent(void) @@ -97,7 +97,7 @@ bool32 IsMysteryEventEnabled(void) void DisableMysteryGift(void) { - FlagReset(SYS_MYSTERY_GIFT_ENABLE); + FlagClear(SYS_MYSTERY_GIFT_ENABLE); } void EnableMysteryGift(void) @@ -112,22 +112,22 @@ bool32 IsMysteryGiftEnabled(void) void sub_809D4D8(void) { - FlagReset(0x1E4); - FlagReset(0x1E5); - FlagReset(0x1E6); - FlagReset(0x1E7); - FlagReset(0x1E8); - FlagReset(0x1E9); - FlagReset(0x1EA); - FlagReset(0x1EB); - FlagReset(0x1EC); - FlagReset(0x1ED); - FlagReset(0x1EE); - FlagReset(0x1EF); - FlagReset(0x1F0); - FlagReset(0x1F1); - FlagReset(0x1F2); - FlagReset(0x1F3); + FlagClear(0x1E4); + FlagClear(0x1E5); + FlagClear(0x1E6); + FlagClear(0x1E7); + FlagClear(0x1E8); + FlagClear(0x1E9); + FlagClear(0x1EA); + FlagClear(0x1EB); + FlagClear(0x1EC); + FlagClear(0x1ED); + FlagClear(0x1EE); + FlagClear(0x1EF); + FlagClear(0x1F0); + FlagClear(0x1F1); + FlagClear(0x1F2); + FlagClear(0x1F3); } void sub_809D570(void) @@ -145,7 +145,7 @@ void sub_809D570(void) void DisableResetRTC(void) { VarSet(VAR_RESET_RTC_ENABLE, 0); - FlagReset(SYS_RESET_RTC_ENABLE); + FlagClear(SYS_RESET_RTC_ENABLE); } void EnableResetRTC(void) @@ -214,7 +214,7 @@ u8 FlagSet(u16 id) return 0; } -u8 FlagReset(u16 id) +u8 FlagClear(u16 id) { u8 *ptr = GetFlagPointer(id); if (ptr) diff --git a/src/field_map_obj.c b/src/field_map_obj.c index e80e402c8..e822fc1ca 100755 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c @@ -3,7 +3,7 @@ #include "global.h" #include "malloc.h" #include "sprite.h" -#include "rom4.h" +#include "overworld.h" #include "rng.h" #include "event_scripts.h" #include "berry.h" @@ -2386,10 +2386,10 @@ bool8 do_berry_tree_growth_sparkle_1 (struct MapObject *mapObject, struct Sprite { if (!(sprite->data7 & 0x0004) && sprite->animNum == 4) { - gFieldEffectSpawnParams[0] = mapObject->coords2.x; - gFieldEffectSpawnParams[1] = mapObject->coords2.y; - gFieldEffectSpawnParams[2] = sprite->subpriority - 1; - gFieldEffectSpawnParams[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObject->coords2.x; + gFieldEffectArguments[1] = mapObject->coords2.y; + gFieldEffectArguments[2] = sprite->subpriority - 1; + gFieldEffectArguments[3] = sprite->oam.priority; FieldEffectStart(FLDEFF_BERRY_TREE_GROWTH_SPARKLE); sprite->animNum = berryStage; } @@ -2425,10 +2425,10 @@ bool8 do_berry_tree_growth_sparkle_2 (struct MapObject *mapObject, struct Sprite sprite->data1 = 3; sprite->data2 = 0; sprite->data7 |= 0x0002; - gFieldEffectSpawnParams[0] = mapObject->coords2.x; - gFieldEffectSpawnParams[1] = mapObject->coords2.y; - gFieldEffectSpawnParams[2] = sprite->subpriority - 1; - gFieldEffectSpawnParams[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObject->coords2.x; + gFieldEffectArguments[1] = mapObject->coords2.y; + gFieldEffectArguments[2] = sprite->subpriority - 1; + gFieldEffectArguments[3] = sprite->oam.priority; FieldEffectStart(FLDEFF_BERRY_TREE_GROWTH_SPARKLE); return TRUE; } @@ -3425,7 +3425,7 @@ void FieldObjectCB_TreeDisguise(struct Sprite *sprite) mapObject = &gMapObjects[sprite->data0]; if (mapObject->mapobj_unk_21 == 0 || (mapObject->mapobj_unk_21 == 1 && !sprite->data7)) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectSpawnParams[0], (u8 *)&gFieldEffectSpawnParams[1], (u8 *)&gFieldEffectSpawnParams[2]); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); mapObject->mapobj_unk_1A = FieldEffectStart(FLDEFF_TREE_DISGUISE); mapObject->mapobj_unk_21 = 1; sprite->data7 ++; @@ -3446,7 +3446,7 @@ void FieldObjectCB_MountainDisguise(struct Sprite *sprite) mapObject = &gMapObjects[sprite->data0]; if (mapObject->mapobj_unk_21 == 0 || (mapObject->mapobj_unk_21 == 1 && !sprite->data7)) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectSpawnParams[0], (u8 *)&gFieldEffectSpawnParams[1], (u8 *)&gFieldEffectSpawnParams[2]); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); mapObject->mapobj_unk_1A = FieldEffectStart(FLDEFF_MOUNTAIN_DISGUISE); mapObject->mapobj_unk_21 = 1; sprite->data7 ++; @@ -4693,7 +4693,7 @@ bool8 sub_80954CC(struct MapObject *mapObject, struct Sprite *sprite) bool8 do_exclamation_mark_bubble_1(struct MapObject *mapObject, struct Sprite *sprite) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectSpawnParams[0], (u8 *)&gFieldEffectSpawnParams[1], (u8 *)&gFieldEffectSpawnParams[2]); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_1); sprite->data2 = 1; return TRUE; @@ -4701,7 +4701,7 @@ bool8 do_exclamation_mark_bubble_1(struct MapObject *mapObject, struct Sprite *s bool8 do_exclamation_mark_bubble_2(struct MapObject *mapObject, struct Sprite *sprite) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectSpawnParams[0], (u8 *)&gFieldEffectSpawnParams[1], (u8 *)&gFieldEffectSpawnParams[2]); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_2); sprite->data2 = 1; return TRUE; @@ -4709,7 +4709,7 @@ bool8 do_exclamation_mark_bubble_2(struct MapObject *mapObject, struct Sprite *s bool8 do_heart_bubble(struct MapObject *mapObject, struct Sprite *sprite) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectSpawnParams[0], (u8 *)&gFieldEffectSpawnParams[1], (u8 *)&gFieldEffectSpawnParams[2]); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); FieldEffectStart(FLDEFF_HEART_ICON); sprite->data2 = 1; return TRUE; diff --git a/src/field_special_scene.c b/src/field_special_scene.c index 9c35a33da..54c1d8144 100755 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -13,10 +13,10 @@ #define SECONDS(value) ((signed) (60.0 * value + 0.5)) extern u8 GetSSTidalLocation(s8 *, s8 *, s16 *, s16 *); // should be in field_specials.h -extern void warp1_set(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); -extern bool8 sub_80D3340(u8, u8, u8); +extern void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); +extern bool8 ScriptMovement_IsObjectMovementFinished(u8, u8, u8); extern bool32 CountSSTidalStep(u16); -extern bool8 exec_movement(u8, u8, u8, u8 *); +extern bool8 ScriptMovement_StartObjectMovementScript(u8, u8, u8, u8 *); extern void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); extern void sp13E_warp_to_last_warp(void); extern void saved_warp2_set(int unused, s8 mapGroup, s8 mapNum, s8 warpId); @@ -264,7 +264,7 @@ bool8 sub_80FB59C(void) } else { - warp1_set(mapGroup, mapNum, -1, x, y); + Overworld_SetWarpDestination(mapGroup, mapNum, -1, x, y); return TRUE; } } @@ -287,7 +287,7 @@ void Task_HandlePorthole(u8 taskId) case IDLE_CHECK: // idle and move. if (gMain.newKeys & A_BUTTON) data[1] = 1; - if (!sub_80D3340(0xFF, location->mapNum, location->mapGroup)) + if (!ScriptMovement_IsObjectMovementFinished(0xFF, location->mapNum, location->mapGroup)) return; if (CountSSTidalStep(1) == TRUE) { @@ -308,18 +308,18 @@ void Task_HandlePorthole(u8 taskId) // run this once. if (*var == 2) // which direction? { - exec_movement(0xFF, location->mapNum, location->mapGroup, gUnknown_0858E8AB); + ScriptMovement_StartObjectMovementScript(0xFF, location->mapNum, location->mapGroup, gUnknown_0858E8AB); data[0] = IDLE_CHECK; // run case 1. } else { - exec_movement(0xFF, location->mapNum, location->mapGroup, gUnknown_0858E8AD); + ScriptMovement_StartObjectMovementScript(0xFF, location->mapNum, location->mapGroup, gUnknown_0858E8AD); data[0] = IDLE_CHECK; // run case 1. } break; case EXIT_PORTHOLE: // exit porthole. - FlagReset(0x4001); - FlagReset(0x4000); + FlagClear(0x4001); + FlagClear(0x4000); copy_saved_warp2_bank_and_enter_x_to_warp1(0); sp13E_warp_to_last_warp(); DestroyTask(taskId); diff --git a/src/lilycove_lady.c b/src/lilycove_lady.c index 9f38824f9..3b7ae49f2 100644 --- a/src/lilycove_lady.c +++ b/src/lilycove_lady.c @@ -4,7 +4,7 @@ #include "global.h" #include "main.h" -#include "rom4.h" +#include "overworld.h" #include "rom6.h" #include "event_data.h" #include "script.h" diff --git a/src/money.c b/src/money.c index 65a45b158..98f25a42a 100644 --- a/src/money.c +++ b/src/money.c @@ -110,7 +110,7 @@ void AddMoney(u32* moneyPtr, u32 toAdd) SetMoney(moneyPtr, toSet); } -void SubtractMoney(u32* moneyPtr, u32 toSub) +void RemoveMoney(u32* moneyPtr, u32 toSub) { u32 toSet = GetMoney(moneyPtr); @@ -130,7 +130,7 @@ bool8 IsEnoughForCostInVar0x8005(void) void SubtractMoneyFromVar0x8005(void) { - SubtractMoney(&gSaveBlock1Ptr->money, gSpecialVar_0x8005); + RemoveMoney(&gSaveBlock1Ptr->money, gSpecialVar_0x8005); } void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, u8 speed) diff --git a/src/new_game.c b/src/new_game.c index d01aa69d4..d0666dd71 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -29,7 +29,7 @@ extern u8 gUnknown_030060B0; // TODO: replace those declarations with file headers extern u16 GetGeneratedTrainerIdLower(void); extern void ClearContestWinnerPicsInContestHall(void); -extern void warp1_set(s8 mapBank, s8 mapNo, s8 warpNo, s8 xPos, s8 yPos); +extern void Overworld_SetWarpDestination(s8 mapBank, s8 mapNo, s8 warpNo, s8 xPos, s8 yPos); extern void warp_in(void); extern void sub_80BB358(void); extern void ResetBagScrollPositions(void); @@ -131,7 +131,7 @@ void sub_8084400(void) void WarpToTruck(void) { - warp1_set(25, 40, -1, -1, -1); // inside of truck + Overworld_SetWarpDestination(25, 40, -1, -1, -1); // inside of truck warp_in(); } diff --git a/src/palette.c b/src/palette.c index d60efdbc5..d4bb593da 100644 --- a/src/palette.c +++ b/src/palette.c @@ -53,13 +53,13 @@ static void UpdateBlendRegisters(void); static bool8 IsSoftwarePaletteFadeFinishing(void); static void sub_80A2D54(u8 taskId); -EWRAM_DATA u16 gPlttBufferUnfaded[0x200] = {0}; -EWRAM_DATA u16 gPlttBufferFaded[0x200] = {0}; +EWRAM_DATA u16 gPlttBufferUnfaded[PLTT_BUFFER_SIZE] = {0}; +EWRAM_DATA u16 gPlttBufferFaded[PLTT_BUFFER_SIZE] = {0}; EWRAM_DATA struct PaletteStruct sPaletteStructs[0x10] = {0}; EWRAM_DATA struct PaletteFadeControl gPaletteFade = {0}; static EWRAM_DATA u32 gFiller_2037FE0 = 0; static EWRAM_DATA u32 sPlttBufferTransferPending = 0; -EWRAM_DATA u8 gPaletteDecompressionBuffer[0x400] = {0}; +EWRAM_DATA u8 gPaletteDecompressionBuffer[PLTT_DECOMP_BUFFER_SIZE] = {0}; static const struct PaletteStructTemplate gDummyPaletteStructTemplate = { .uid = 0xFFFF, diff --git a/src/pokemon_2.c b/src/pokemon_2.c index ee54f0e4d..27441f952 100644 --- a/src/pokemon_2.c +++ b/src/pokemon_2.c @@ -1089,7 +1089,7 @@ u8 SendMonToPC(struct Pokemon* mon) gSpecialVar_0x8012 = boxNo; gSpecialVar_0x8013 = boxPos; if (get_unknown_box_id() != boxNo) - FlagReset(SYS_STORAGE_UNKNOWN_FLAG); + FlagClear(SYS_STORAGE_UNKNOWN_FLAG); VarSet(VAR_STORAGE_UNKNOWN, boxNo); return MON_GIVEN_TO_PC; } diff --git a/src/reset_save_heap.c b/src/reset_save_heap.c index b786ff9f8..d4dbc5f42 100644 --- a/src/reset_save_heap.c +++ b/src/reset_save_heap.c @@ -5,7 +5,7 @@ #include "load_save.h" #include "save.h" #include "new_game.h" -#include "rom4.h" +#include "overworld.h" #include "malloc.h" void sub_81700F8(void) diff --git a/src/safari_zone.c b/src/safari_zone.c index f7ef28577..a1ec38920 100644 --- a/src/safari_zone.c +++ b/src/safari_zone.c @@ -60,7 +60,7 @@ void SetSafariZoneFlag(void) void ResetSafariZoneFlag(void) { - FlagReset(SYS_SAFARI_MODE); + FlagClear(SYS_SAFARI_MODE); } void EnterSafariMode(void) diff --git a/src/scrcmd.c b/src/scrcmd.c index b56a53caf..af314609c 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1,15 +1,2452 @@ - -// Includes #include "global.h" +#include "battle_frontier_2.h" +#include "battle_setup.h" +#include "berry.h" +#include "clock.h" +#include "coins.h" +#include "contest_link_80F57C4.h" +#include "contest_painting.h" +#include "data2.h" +#include "decoration.h" +#include "decoration_inventory.h" +#include "event_data.h" +#include "field_door.h" +#include "field_effect.h" +#include "field_fadetransition.h" +#include "field_map_obj.h" +#include "field_map_obj_helpers.h" +#include "field_message_box.h" +#include "field_player_avatar.h" +#include "field_screen_effect.h" +#include "field_specials.h" +#include "field_tasks.h" +#include "field_weather.h" +#include "fieldmap.h" +#include "item.h" +#include "lilycove_lady.h" +#include "main.h" +#include "map_obj_lock.h" +#include "menu.h" +#include "money.h" +#include "mystery_event_script.h" +#include "new_menu_helpers.h" +#include "palette.h" +#include "party_menu.h" +#include "pokemon_3.h" +#include "pokemon_storage_system.h" +#include "rng.h" +#include "overworld.h" +#include "rtc.h" +#include "script.h" +#include "script_menu.h" +#include "script_movement.h" +#include "script_pokemon_80F8.h" +#include "script_pokemon_81B9.h" +#include "shop.h" +#include "slot_machine.h" +#include "sound.h" +#include "string_util.h" +#include "text.h" +#include "text_window.h" +#include "trainer_see.h" +#include "tv.h" +#include "window.h" + +typedef u16 (*SpecialFunc)(void); +typedef void (*NativeFunc)(void); + +extern u32 gUnknown_020375C0; + +static EWRAM_DATA u32 gUnknown_020375C4 = 0; +static EWRAM_DATA u16 sPauseCounter = 0; +static EWRAM_DATA u16 sMovingNpcId = 0; +static EWRAM_DATA u16 sMovingNpcMapBank = 0; +static EWRAM_DATA u16 sMovingNpcMapId = 0; +static EWRAM_DATA u16 sFieldEffectScriptId = 0; -// Static type declarations +extern u16 gSpecialVar_0x8000; +extern u16 gSpecialVar_0x8001; +extern u16 gSpecialVar_0x8002; +extern u16 gSpecialVar_0x8004; -// Static RAM declarations +extern u16 gScriptResult; + +extern u16 gScriptContestCategory; IWRAM_DATA u8 gUnknown_03000F30; -// Static ROM declarations +extern const SpecialFunc gSpecials[]; +extern const u8 *gStdScripts[]; +extern const u8 *gStdScripts_End[]; + +void sub_809BDB4(void); + +// This is defined in here so the optimizer can't see its value when compiling +// script.c. +void * const gNullScriptPtr = NULL; + +static const u8 sScriptConditionTable[6][3] = +{ +// < = > + 1, 0, 0, // < + 0, 1, 0, // = + 0, 0, 1, // > + 1, 1, 0, // <= + 0, 1, 1, // >= + 1, 0, 1, // != +}; + +static u8 * const sScriptStringVars[] = +{ + gStringVar1, + gStringVar2, + gStringVar3, +}; + +bool8 ScrCmd_nop(struct ScriptContext *ctx) +{ + return FALSE; +} + +bool8 ScrCmd_nop1(struct ScriptContext *ctx) +{ + return FALSE; +} + +bool8 ScrCmd_end(struct ScriptContext *ctx) +{ + StopScript(ctx); + return FALSE; +} + +bool8 ScrCmd_gotonative(struct ScriptContext *ctx) +{ + bool8 (*addr)(void) = (bool8 (*)(void))ScriptReadWord(ctx); + + SetupNativeScript(ctx, addr); + return TRUE; +} + +bool8 ScrCmd_special(struct ScriptContext *ctx) +{ + u16 index = ScriptReadHalfword(ctx); + + gSpecials[index](); + return FALSE; +} + +bool8 ScrCmd_specialvar(struct ScriptContext *ctx) +{ + u16 *var = GetVarPointer(ScriptReadHalfword(ctx)); + + *var = gSpecials[ScriptReadHalfword(ctx)](); + return FALSE; +} + +bool8 ScrCmd_callnative(struct ScriptContext *ctx) +{ + NativeFunc func = (NativeFunc)ScriptReadWord(ctx); + + func(); + return FALSE; +} + +bool8 ScrCmd_waitstate(struct ScriptContext *ctx) +{ + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_goto(struct ScriptContext *ctx) +{ + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); + + ScriptJump(ctx, ptr); + return FALSE; +} + +bool8 ScrCmd_return(struct ScriptContext *ctx) +{ + ScriptReturn(ctx); + return FALSE; +} + +bool8 ScrCmd_call(struct ScriptContext *ctx) +{ + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); + + ScriptCall(ctx, ptr); + return FALSE; +} + +bool8 ScrCmd_goto_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); + + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptJump(ctx, ptr); + return FALSE; +} + +bool8 ScrCmd_call_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); + + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptCall(ctx, ptr); + return FALSE; +} + +bool8 ScrCmd_setvaddress(struct ScriptContext *ctx) +{ + u32 addr1 = (u32)ctx->scriptPtr - 1; + u32 addr2 = ScriptReadWord(ctx); + + gUnknown_020375C4 = addr2 - addr1; + return FALSE; +} + +bool8 ScrCmd_vgoto(struct ScriptContext *ctx) +{ + u32 addr = ScriptReadWord(ctx); + + ScriptJump(ctx, (u8 *)(addr - gUnknown_020375C4)); + return FALSE; +} + +bool8 ScrCmd_vcall(struct ScriptContext *ctx) +{ + u32 addr = ScriptReadWord(ctx); + + ScriptCall(ctx, (u8 *)(addr - gUnknown_020375C4)); + return FALSE; +} + +bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptJump(ctx, ptr); + return FALSE; +} + +bool8 ScrCmd_vcall_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + ScriptCall(ctx, ptr); + return FALSE; +} + +bool8 ScrCmd_gotostd(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + const u8 **ptr = &gStdScripts[index]; + + if (ptr < gStdScripts_End) + ScriptJump(ctx, *ptr); + return FALSE; +} + +bool8 ScrCmd_callstd(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + const u8 **ptr = &gStdScripts[index]; + + if (ptr < gStdScripts_End) + ScriptCall(ctx, *ptr); + return FALSE; +} + +bool8 ScrCmd_gotostd_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + u8 index = ScriptReadByte(ctx); + + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + { + const u8 **ptr = &gStdScripts[index]; + if (ptr < gStdScripts_End) + ScriptJump(ctx, *ptr); + } + return FALSE; +} + +bool8 ScrCmd_callstd_if(struct ScriptContext *ctx) +{ + u8 condition = ScriptReadByte(ctx); + u8 index = ScriptReadByte(ctx); + + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) + { + const u8 **ptr = &gStdScripts[index]; + if (ptr < gStdScripts_End) + ScriptCall(ctx, *ptr); + } + return FALSE; +} + +bool8 ScrCmd_gotoram(struct ScriptContext *ctx) +{ + ScriptJump(ctx, (const u8 *)gUnknown_020375C0); + return FALSE; +} + +bool8 ScrCmd_killscript(struct ScriptContext *ctx) +{ + ClearRamScript(); + StopScript(ctx); + return TRUE; +} + +bool8 ScrCmd_setmysteryeventstatus(struct ScriptContext *ctx) +{ + u8 value = ScriptReadByte(ctx); + + SetMysteryEventScriptStatus(value); + return FALSE; +} + +bool8 ScrCmd_loadword(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + + ctx->data[index] = ScriptReadWord(ctx); + return FALSE; +} + +bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + + ctx->data[index] = *(const u8 *)ScriptReadWord(ctx); + return FALSE; +} + +bool8 ScrCmd_writebytetoaddr(struct ScriptContext *ctx) +{ + u8 value = ScriptReadByte(ctx); + + *(u8 *)ScriptReadWord(ctx) = value; + return FALSE; +} + +bool8 ScrCmd_loadbyte(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + + ctx->data[index] = ScriptReadByte(ctx); + return FALSE; +} + +bool8 ScrCmd_setptrbyte(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + + *(u8 *)ScriptReadWord(ctx) = ctx->data[index]; + return FALSE; +} + +bool8 ScrCmd_copylocal(struct ScriptContext *ctx) +{ + u8 destIndex = ScriptReadByte(ctx); + u8 srcIndex = ScriptReadByte(ctx); + + ctx->data[destIndex] = ctx->data[srcIndex]; + return FALSE; +} + +bool8 ScrCmd_copybyte(struct ScriptContext *ctx) +{ + u8 *ptr = (u8 *)ScriptReadWord(ctx); + *ptr = *(const u8 *)ScriptReadWord(ctx); + return FALSE; +} + +bool8 ScrCmd_setvar(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr = ScriptReadHalfword(ctx); + return FALSE; +} + +bool8 ScrCmd_copyvar(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr = *GetVarPointer(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_setorcopyvar(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr = VarGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +u8 compare_012(u16 a1, u16 a2) +{ + if (a1 < a2) + return 0; + if (a1 == a2) + return 1; + return 2; +} + +// comparelocaltolocal +bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx) +{ + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = ctx->data[ScriptReadByte(ctx)]; + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +// comparelocaltoimm +bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) +{ + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = ScriptReadByte(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) +{ + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = *(const u8 *)ScriptReadWord(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) +{ + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = ctx->data[ScriptReadByte(ctx)]; + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) +{ + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = ScriptReadByte(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx) +{ + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = *(const u8 *)ScriptReadWord(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx) +{ + const u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx)); + const u16 value2 = ScriptReadHalfword(ctx); + + ctx->comparisonResult = compare_012(value1, value2); + return FALSE; +} + +bool8 ScrCmd_compare_var_to_var(struct ScriptContext *ctx) +{ + const u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); + const u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); + + ctx->comparisonResult = compare_012(*ptr1, *ptr2); + return FALSE; +} + +bool8 ScrCmd_addvar(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr += ScriptReadHalfword(ctx); + return FALSE; +} + +bool8 ScrCmd_subvar(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr -= VarGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_random(struct ScriptContext *ctx) +{ + u16 max = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = Random() % max; + return FALSE; +} + +bool8 ScrCmd_additem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = AddBagItem(itemId, (u8)quantity); + return FALSE; +} + +bool8 ScrCmd_removeitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = RemoveBagItem(itemId, (u8)quantity); + return FALSE; +} + +bool8 ScrCmd_checkitemspace(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = CheckBagHasSpace(itemId, (u8)quantity); + return FALSE; +} + +bool8 ScrCmd_checkitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 quantity = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = CheckBagHasItem(itemId, (u8)quantity); + return FALSE; +} + +bool8 ScrCmd_checkitemtype(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = GetPocketByItemId(itemId); + return FALSE; +} + +bool8 ScrCmd_addpcitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = AddPCItem(itemId, quantity); + return FALSE; +} + +bool8 ScrCmd_checkpcitem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = CheckPCHasItem(itemId, quantity); + return FALSE; +} + +bool8 ScrCmd_adddecor(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = DecorationAdd(decorId); + return FALSE; +} + +bool8 ScrCmd_removedecor(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = DecorationRemove(decorId); + return FALSE; +} + +bool8 ScrCmd_checkdecor(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = DecorationCheckSpace(decorId); + return FALSE; +} + +bool8 ScrCmd_hasdecor(struct ScriptContext *ctx) +{ + u32 decorId = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = CheckHasDecoration(decorId); + return FALSE; +} + +bool8 ScrCmd_setflag(struct ScriptContext *ctx) +{ + FlagSet(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_clearflag(struct ScriptContext *ctx) +{ + FlagClear(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_checkflag(struct ScriptContext *ctx) +{ + ctx->comparisonResult = FlagGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_incrementgamestat(struct ScriptContext *ctx) +{ + IncrementGameStat(ScriptReadByte(ctx)); + return FALSE; +} + +bool8 ScrCmd_animdarklevel(struct ScriptContext *ctx) +{ + sub_80B009C(ScriptReadByte(ctx)); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_setdarklevel(struct ScriptContext *ctx) +{ + u16 flashLevel = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetFlashLevel(flashLevel); + return FALSE; +} + +static bool8 IsPaletteNotActive(void) +{ + if (!gPaletteFade.active) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_fadescreen(struct ScriptContext *ctx) +{ + fade_screen(ScriptReadByte(ctx), 0); + SetupNativeScript(ctx, IsPaletteNotActive); + return TRUE; +} + +bool8 ScrCmd_fadescreendelay(struct ScriptContext *ctx) +{ + u8 mode = ScriptReadByte(ctx); + u8 delay = ScriptReadByte(ctx); + + fade_screen(mode, delay); + SetupNativeScript(ctx, IsPaletteNotActive); + return TRUE; +} + +bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) +{ + u8 mode = ScriptReadByte(ctx); + + switch (mode) + { + case 1: + default: + CpuCopy32(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_DECOMP_BUFFER_SIZE); + fade_screen(mode, 0); + break; + case 0: + case 2: + CpuCopy32(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_DECOMP_BUFFER_SIZE); + fade_screen(mode, 0); + break; + } + + SetupNativeScript(ctx, IsPaletteNotActive); + return TRUE; +} + +static bool8 RunPauseTimer(void) +{ + sPauseCounter--; + + if (sPauseCounter == 0) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_delay(struct ScriptContext *ctx) +{ + sPauseCounter = ScriptReadHalfword(ctx); + SetupNativeScript(ctx, RunPauseTimer); + return TRUE; +} + +bool8 ScrCmd_initclock(struct ScriptContext *ctx) +{ + u8 hour = VarGet(ScriptReadHalfword(ctx)); + u8 minute = VarGet(ScriptReadHalfword(ctx)); + + RtcInitLocalTimeOffset(hour, minute); + return FALSE; +} + +bool8 ScrCmd_dodailyevents(struct ScriptContext *ctx) +{ + DoTimeBasedEvents(); + return FALSE; +} + +bool8 ScrCmd_gettime(struct ScriptContext *ctx) +{ + RtcCalcLocalTime(); + gSpecialVar_0x8000 = gLocalTime.hours; + gSpecialVar_0x8001 = gLocalTime.minutes; + gSpecialVar_0x8002 = gLocalTime.seconds; + return FALSE; +} + +bool8 ScrCmd_setweather(struct ScriptContext *ctx) +{ + u16 weather = VarGet(ScriptReadHalfword(ctx)); + + SetSav1Weather(weather); + return FALSE; +} + +bool8 ScrCmd_resetweather(struct ScriptContext *ctx) +{ + sub_80AEDBC(); + return FALSE; +} + +bool8 ScrCmd_doweather(struct ScriptContext *ctx) +{ + DoCurrentWeather(); + return FALSE; +} + +bool8 ScrCmd_tileeffect(struct ScriptContext *ctx) +{ + ActivatePerStepCallback(ScriptReadByte(ctx)); + return FALSE; +} + +bool8 ScrCmd_setmaplayoutindex(struct ScriptContext *ctx) +{ + u16 value = VarGet(ScriptReadHalfword(ctx)); + + sub_8085524(value); + return FALSE; +} + +bool8 ScrCmd_warp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_80AF734(); + player_avatar_init_params_reset(); + return TRUE; +} + +bool8 ScrCmd_warpsilent(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sp13E_warp_to_last_warp(); + player_avatar_init_params_reset(); + return TRUE; +} + +bool8 ScrCmd_warpdoor(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_80AF7D0(); + player_avatar_init_params_reset(); + return TRUE; +} + +bool8 ScrCmd_warphole(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u16 x; + u16 y; + + PlayerGetDestCoords(&x, &y); + if (mapGroup == 0xFF && mapNum == 0xFF) + sub_8084EBC(x - 7, y - 7); + else + Overworld_SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7); + sp13F_fall_to_last_warp(); + player_avatar_init_params_reset(); + return TRUE; +} + +bool8 ScrCmd_warpteleport(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_80AF848(); + player_avatar_init_params_reset(); + return TRUE; +} + +bool8 ScrCmd_warpD7(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_80AF87C(); + player_avatar_init_params_reset(); + return TRUE; +} + +bool8 ScrCmd_setwarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setdynamicwarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + saved_warp2_set_2(0, mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setdivewarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_8084E2C(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setholewarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_8084E80(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_setescapewarp(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_8084DD4(mapGroup, mapNum, warpId, x, y); + return FALSE; +} + +bool8 ScrCmd_getplayerxy(struct ScriptContext *ctx) +{ + u16 *pX = GetVarPointer(ScriptReadHalfword(ctx)); + u16 *pY = GetVarPointer(ScriptReadHalfword(ctx)); + + *pX = gSaveBlock1Ptr->pos.x; + *pY = gSaveBlock1Ptr->pos.y; + return FALSE; +} + +bool8 ScrCmd_countpokemon(struct ScriptContext *ctx) +{ + gScriptResult = CalculatePlayerPartyCount(); + return FALSE; +} + +bool8 ScrCmd_playse(struct ScriptContext *ctx) +{ + PlaySE(ScriptReadHalfword(ctx)); + return FALSE; +} + +static bool8 WaitForSoundEffectFinish(void) +{ + if (!IsSEPlaying()) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_waitse(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, WaitForSoundEffectFinish); + return TRUE; +} + +bool8 ScrCmd_playfanfare(struct ScriptContext *ctx) +{ + PlayFanfare(ScriptReadHalfword(ctx)); + return FALSE; +} + +static bool8 WaitForFanfareFinish(void) +{ + return IsFanfareTaskInactive(); +} + +bool8 ScrCmd_waitfanfare(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, WaitForFanfareFinish); + return TRUE; +} + +bool8 ScrCmd_playbgm(struct ScriptContext *ctx) +{ + u16 songId = ScriptReadHalfword(ctx); + bool8 val = ScriptReadByte(ctx); + + if (val == TRUE) + Overworld_SetSavedMusic(songId); + PlayNewMapMusic(songId); + return FALSE; +} + +bool8 ScrCmd_savebgm(struct ScriptContext *ctx) +{ + Overworld_SetSavedMusic(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_fadedefaultbgm(struct ScriptContext *ctx) +{ + Overworld_ChangeMusicToDefault(); + return FALSE; +} + +bool8 ScrCmd_fadenewbgm(struct ScriptContext *ctx) +{ + Overworld_ChangeMusicTo(ScriptReadHalfword(ctx)); + return FALSE; +} + +bool8 ScrCmd_fadeoutbgm(struct ScriptContext *ctx) +{ + u8 speed = ScriptReadByte(ctx); + + if (speed != 0) + FadeOutBGMTemporarily(4 * speed); + else + FadeOutBGMTemporarily(4); + SetupNativeScript(ctx, IsBGMPausedOrStopped); + return TRUE; +} + +bool8 ScrCmd_fadeinbgm(struct ScriptContext *ctx) +{ + u8 speed = ScriptReadByte(ctx); + + if (speed != 0) + FadeInBGM(4 * speed); + else + FadeInBGM(4); + return FALSE; +} + +bool8 ScrCmd_applymovement(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + const void *movementScript = (const void *)ScriptReadWord(ctx); + + ScriptMovement_StartObjectMovementScript(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, movementScript); + sMovingNpcId = localId; + return FALSE; +} + +bool8 ScrCmd_applymovement_at(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + const void *movementScript = (const void *)ScriptReadWord(ctx); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + ScriptMovement_StartObjectMovementScript(localId, mapNum, mapGroup, movementScript); + sMovingNpcId = localId; + return FALSE; +} + +static bool8 WaitForMovementFinish(void) +{ + return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapId, sMovingNpcMapBank); +} + +bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + if (localId != 0) + sMovingNpcId = localId; + sMovingNpcMapBank = gSaveBlock1Ptr->location.mapGroup; + sMovingNpcMapId = gSaveBlock1Ptr->location.mapNum; + SetupNativeScript(ctx, WaitForMovementFinish); + return TRUE; +} + +bool8 ScrCmd_waitmovement_at(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapBank; + u8 mapId; + + if (localId != 0) + sMovingNpcId = localId; + mapBank = ScriptReadByte(ctx); + mapId = ScriptReadByte(ctx); + sMovingNpcMapBank = mapBank; + sMovingNpcMapId = mapId; + SetupNativeScript(ctx, WaitForMovementFinish); + return TRUE; +} + +bool8 ScrCmd_removeobject(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + RemoveFieldObjectByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + return FALSE; +} + +bool8 ScrCmd_removeobject_at(struct ScriptContext *ctx) +{ + u16 objectId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + RemoveFieldObjectByLocalIdAndMap(objectId, mapNum, mapGroup); + return FALSE; +} + +bool8 ScrCmd_addobject(struct ScriptContext *ctx) +{ + u16 objectId = VarGet(ScriptReadHalfword(ctx)); + + show_sprite(objectId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + return FALSE; +} + +bool8 ScrCmd_addobject_at(struct ScriptContext *ctx) +{ + u16 objectId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + show_sprite(objectId, mapNum, mapGroup); + return FALSE; +} + +bool8 ScrCmd_setobjectxy(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_808EBA8(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, x, y); + return FALSE; +} + +bool8 ScrCmd_setobjectxyperm(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetMapObjTemplateCoords(localId, x, y); + return FALSE; +} + +bool8 ScrCmd_moveobjectoffscreen(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + sub_808F254(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + return FALSE; +} + +bool8 ScrCmd_showobject(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 0); + return FALSE; +} + +bool8 ScrCmd_hideobject(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 1); + return FALSE; +} + +bool8 ScrCmd_setobjectpriority(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 priority = ScriptReadByte(ctx); + + sub_808E78C(localId, mapNum, mapGroup, priority + 83); + return FALSE; +} + +bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + sub_808E7E4(localId, mapNum, mapGroup); + return FALSE; +} + +bool8 ScrCmd_faceplayer(struct ScriptContext *ctx) +{ + if (gMapObjects[gSelectedMapObject].active) + { + FieldObjectFaceOppositeDirection(&gMapObjects[gSelectedMapObject], + player_get_direction_lower_nybble()); + } + return FALSE; +} + +bool8 ScrCmd_turnobject(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 direction = ScriptReadByte(ctx); + + FieldObjectTurnByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, direction); + return FALSE; +} + +bool8 ScrCmd_setobjectmovementtype(struct ScriptContext *ctx) +{ + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 movementType = ScriptReadByte(ctx); + + Overworld_SetMapObjTemplateMovementType(localId, movementType); + return FALSE; +} + +bool8 ScrCmd_createvobject(struct ScriptContext *ctx) +{ + u8 graphicsId = ScriptReadByte(ctx); + u8 v2 = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u32 y = VarGet(ScriptReadHalfword(ctx)); + u8 elevation = ScriptReadByte(ctx); + u8 direction = ScriptReadByte(ctx); + + sprite_new(graphicsId, v2, x, y, elevation, direction); + return FALSE; +} + +bool8 ScrCmd_turnvobject(struct ScriptContext *ctx) +{ + u8 v1 = ScriptReadByte(ctx); + u8 direction = ScriptReadByte(ctx); + + sub_8097B78(v1, direction); + return FALSE; +} + +bool8 ScrCmd_lockall(struct ScriptContext *ctx) +{ + if (is_c1_link_related_active()) + { + return FALSE; + } + else + { + ScriptFreezeMapObjects(); + SetupNativeScript(ctx, sub_80983C4); + return TRUE; + } +} + +bool8 ScrCmd_lock(struct ScriptContext *ctx) +{ + if (is_c1_link_related_active()) + { + return FALSE; + } + else + { + if (gMapObjects[gSelectedMapObject].active) + { + LockSelectedMapObject(); + SetupNativeScript(ctx, sub_809847C); + } + else + { + ScriptFreezeMapObjects(); + SetupNativeScript(ctx, sub_80983C4); + } + return TRUE; + } +} + +bool8 ScrCmd_releaseall(struct ScriptContext *ctx) +{ + u8 objectId; + + HideFieldMessageBox(); + objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0); + FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]); + sub_80D338C(); + UnfreezeMapObjects(); + return FALSE; +} + +bool8 ScrCmd_release(struct ScriptContext *ctx) +{ + u8 objectId; + + HideFieldMessageBox(); + if (gMapObjects[gSelectedMapObject].active) + FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[gSelectedMapObject]); + objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0); + FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]); + sub_80D338C(); + UnfreezeMapObjects(); + return FALSE; +} + +bool8 ScrCmd_message(struct ScriptContext *ctx) +{ + const u8 *msg = (const u8 *)ScriptReadWord(ctx); + + if (msg == NULL) + msg = (const u8 *)ctx->data[0]; + ShowFieldMessage(msg); + return FALSE; +} + +bool8 ScrCmd_pokenavcall(struct ScriptContext *ctx) +{ + const u8 *msg = (const u8 *)ScriptReadWord(ctx); + + if (msg == NULL) + msg = (const u8 *)ctx->data[0]; + sub_8098238(msg); + return FALSE; +} + +bool8 ScrCmd_messageautoscroll(struct ScriptContext *ctx) +{ + const u8 *msg = (const u8 *)ScriptReadWord(ctx); + + if (msg == NULL) + msg = (const u8 *)ctx->data[0]; + gTextFlags.flag_2 = TRUE; + gTextFlags.flag_3 = TRUE; + ShowFieldAutoScrollMessage(msg); + return FALSE; +} + +bool8 ScrCmd_cmdDB(struct ScriptContext *ctx) +{ + const u8 *msg = (const u8 *)ScriptReadWord(ctx); + + if (msg == NULL) + msg = (const u8 *)ctx->data[0]; + sub_81973A4(); + sub_81973C4(0, 1); + PrintTextOnWindow(0, 1, msg, 0, 1, 0, 0); + return FALSE; +} + +bool8 ScrCmd_waitmessage(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, IsFieldMessageBoxHidden); + return TRUE; +} + +bool8 ScrCmd_closemessage(struct ScriptContext *ctx) +{ + HideFieldMessageBox(); + return FALSE; +} + +static bool8 WaitForAorBPress(void) +{ + if (gMain.newKeys & A_BUTTON) + return TRUE; + if (gMain.newKeys & B_BUTTON) + return TRUE; + return FALSE; +} + +bool8 ScrCmd_waitbutton(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, WaitForAorBPress); + return TRUE; +} + +bool8 ScrCmd_yesnobox(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + + if (ScriptMenu_YesNo(left, top) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_multichoice(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + + if (ScriptMenu_Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_multichoicedefault(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 defaultChoice = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + + if (ScriptMenu_MultichoiceWithDefault(left, top, multichoiceId, ignoreBPress, defaultChoice) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_drawbox(struct ScriptContext *ctx) +{ + /*u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 right = ScriptReadByte(ctx); + u8 bottom = ScriptReadByte(ctx); + + MenuDrawTextWindow(left, top, right, bottom);*/ + return FALSE; +} + +bool8 ScrCmd_multichoicegrid(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 numColumns = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + + if (ScriptMenu_MultichoiceGrid(left, top, multichoiceId, ignoreBPress, numColumns) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + } + else + { + return FALSE; + } +} + +bool8 ScrCmd_erasebox(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 right = ScriptReadByte(ctx); + u8 bottom = ScriptReadByte(ctx); + + // MenuZeroFillWindowRect(left, top, right, bottom); + return FALSE; +} + +bool8 ScrCmd_drawboxtext(struct ScriptContext *ctx) +{ + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + + /*if (Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) + { + ScriptContext1_Stop(); + return TRUE; + }*/ + return FALSE; +} + +bool8 ScrCmd_drawpokepic(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + ScriptMenu_ShowPokemonPic(species, x, y); + return FALSE; +} + +bool8 ScrCmd_erasepokepic(struct ScriptContext *ctx) +{ + bool8 (*func)(void) = ScriptMenu_GetPicboxWaitFunc(); + + if (func == NULL) + return FALSE; + SetupNativeScript(ctx, func); + return TRUE; +} + +bool8 ScrCmd_drawcontestwinner(struct ScriptContext *ctx) +{ + u8 v1 = ScriptReadByte(ctx); + + if (v1) + sub_812FDA8(v1); + ShowContestWinner(); + ScriptContext1_Stop(); + return TRUE; +} + +// Lots of math, can't figure it out. +/* +bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) +{ + u8 *ptr = (u8 *)ScriptReadWord(ctx); + struct WindowTemplate template1; + struct WindowTemplate template2; + int i; + u8 width; + u8 height; + int temp1; + int temp2; + u8 x; + u8 y; + + StringExpandPlaceholders(gStringVar4, ptr + 6); + + width = GetStringWidth(6, gStringVar4, -1) / 8; + + if (width > 0x1C) + width = 0x1C; + + for (i = 0, height = 4; gStringVar4[i] != 0xFF;) + { + if (gStringVar4[i++] == 0xFE) + height += 3; + } + + if (height > 0x12) + height = 0x12; + + x = width + 2; + temp1 = (0x1E - x) / 2; + x = temp1 + 1; + temp1 = ((x - temp1 - 1) * 8 + 3); + + y = height + 2; + temp2 = (0x14 - y) / 2; + y = temp2 + 2; + temp2 = ((y - temp2 - 1) * 8); + + sub_8198A50(&template1, 0, x, y, width, height, 0xF, 0x1); + template2 = template1; + gUnknown_03000F30 = AddWindow(&template2); + sub_809882C(gUnknown_03000F30, 0x214, 0xE0); + sub_81973FC(gUnknown_03000F30, 0); + PutWindowTilemap(gUnknown_03000F30); + FillWindowPixelBuffer(gUnknown_03000F30, 0x11); + PrintTextOnWindow(gUnknown_03000F30, 6, gStringVar4, temp1, temp2, 0xFF, 0x0); + CopyWindowToVram(gUnknown_03000F30, 3); + return FALSE; +}*/ +__attribute__((naked)) +bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) +{ + asm("push {r4-r7,lr}\n\ + mov r7, r8\n\ + push {r7}\n\ + sub sp, #0x20\n\ + bl ScriptReadWord\n\ + add r1, r0, #0\n\ + ldr r4, =gStringVar4\n\ + add r1, #0x6\n\ + add r0, r4, #0\n\ + bl StringExpandPlaceholders\n\ + mov r2, #0x1\n\ + neg r2, r2\n\ + mov r0, #0x6\n\ + add r1, r4, #0\n\ + bl GetStringWidth\n\ + lsr r0, #3\n\ + lsl r0, #24\n\ + lsr r7, r0, #24\n\ + cmp r7, #0x1C\n\ + bls _0809AE9C\n\ + mov r7, #0x1C\n\ +_0809AE9C:\n\ + mov r5, #0x4\n\ + ldrb r0, [r4]\n\ + add r2, r7, #0x2\n\ + add r1, sp, #0x18\n\ + mov r8, r1\n\ + cmp r0, #0xFF\n\ + beq _0809AEC0\n\ + add r1, r4, #0\n\ +_0809AEAC:\n\ + ldrb r0, [r1]\n\ + add r1, #0x1\n\ + cmp r0, #0xFE\n\ + bne _0809AEBA\n\ + add r0, r5, #0x3\n\ + lsl r0, #24\n\ + lsr r5, r0, #24\n\ +_0809AEBA:\n\ + ldrb r0, [r1]\n\ + cmp r0, #0xFF\n\ + bne _0809AEAC\n\ +_0809AEC0:\n\ + cmp r5, #0x12\n\ + bls _0809AEC6\n\ + mov r5, #0x12\n\ +_0809AEC6:\n\ + lsl r0, r2, #24\n\ + lsr r0, #24\n\ + mov r2, #0x1E\n\ + sub r2, r0\n\ + lsr r0, r2, #31\n\ + add r2, r0\n\ + asr r2, #1\n\ + lsl r2, #24\n\ + add r0, r5, #0x2\n\ + lsl r0, #24\n\ + lsr r0, #24\n\ + mov r4, #0x14\n\ + sub r4, r0\n\ + lsr r0, r4, #31\n\ + add r4, r0\n\ + asr r4, #1\n\ + lsl r4, #24\n\ + lsr r6, r2, #24\n\ + mov r0, #0x80\n\ + lsl r0, #17\n\ + add r2, r0\n\ + lsr r2, #24\n\ + lsr r3, r4, #24\n\ + mov r1, #0x80\n\ + lsl r1, #18\n\ + add r4, r1\n\ + lsr r4, #24\n\ + sub r6, r2, r6\n\ + sub r6, #0x1\n\ + lsl r6, #3\n\ + add r6, #0x3\n\ + lsl r6, #24\n\ + lsr r6, #24\n\ + sub r4, r3\n\ + sub r4, #0x1\n\ + lsl r4, #27\n\ + lsr r4, #24\n\ + add r3, #0x1\n\ + lsl r3, #24\n\ + lsr r3, #24\n\ + str r7, [sp]\n\ + str r5, [sp, #0x4]\n\ + mov r0, #0xF\n\ + str r0, [sp, #0x8]\n\ + mov r0, #0x1\n\ + str r0, [sp, #0xC]\n\ + add r0, sp, #0x10\n\ + mov r1, #0\n\ + bl sub_8198A50\n\ + ldr r0, [sp, #0x10]\n\ + ldr r1, [sp, #0x14]\n\ + str r0, [sp, #0x18]\n\ + str r1, [sp, #0x1C]\n\ + ldr r5, =gUnknown_03000F30\n\ + mov r0, r8\n\ + bl AddWindow\n\ + strb r0, [r5]\n\ + ldrb r0, [r5]\n\ + mov r1, #0x85\n\ + lsl r1, #2\n\ + mov r2, #0xE0\n\ + bl sub_809882C\n\ + ldrb r0, [r5]\n\ + mov r1, #0\n\ + bl sub_81973FC\n\ + ldrb r0, [r5]\n\ + bl PutWindowTilemap\n\ + ldrb r0, [r5]\n\ + mov r1, #0x11\n\ + bl FillWindowPixelBuffer\n\ + ldrb r0, [r5]\n\ + ldr r2, =gStringVar4\n\ + str r4, [sp]\n\ + mov r1, #0xFF\n\ + str r1, [sp, #0x4]\n\ + mov r1, #0\n\ + str r1, [sp, #0x8]\n\ + mov r1, #0x6\n\ + add r3, r6, #0\n\ + bl PrintTextOnWindow\n\ + ldrb r0, [r5]\n\ + mov r1, #0x3\n\ + bl CopyWindowToVram\n\ + mov r0, #0\n\ + add sp, #0x20\n\ + pop {r3}\n\ + mov r8, r3\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1\n\ + .pool"); +} + +bool8 ScrCmd_cmdDA(struct ScriptContext *ctx) +{ + sub_809BDB4(); + return FALSE; +} + +bool8 ScrCmd_vmessage(struct ScriptContext *ctx) +{ + u32 v1 = ScriptReadWord(ctx); + + ShowFieldMessage((u8 *)(v1 - gUnknown_020375C4)); + return FALSE; +} + +bool8 ScrCmd_getspeciesname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 species = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], gSpeciesNames[species]); + return FALSE; +} + +bool8 ScrCmd_getfirstpartypokename(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + + u8 *dest = sScriptStringVars[stringVarIndex]; + u8 partyIndex = GetLeadMonIndex(); + u32 species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); + StringCopy(dest, gSpeciesNames[species]); + return FALSE; +} + +bool8 ScrCmd_getpartypokename(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, sScriptStringVars[stringVarIndex]); + StringGetEnd10(sScriptStringVars[stringVarIndex]); + return FALSE; +} + +bool8 ScrCmd_getitemname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + + CopyItemName(itemId, sScriptStringVars[stringVarIndex]); + return FALSE; +} + +bool8 ScrCmd_getitemnameplural(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ScriptReadHalfword(ctx)); + + CopyItemNameHandlePlural(itemId, sScriptStringVars[stringVarIndex], quantity); + return FALSE; +} + +bool8 ScrCmd_getdecorname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 decorId = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], gDecorations[decorId].name); + return FALSE; +} + +bool8 ScrCmd_getmovename(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 moveId = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], gMoveNames[moveId]); + return FALSE; +} + +bool8 ScrCmd_getnumberstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 v1 = VarGet(ScriptReadHalfword(ctx)); + u8 v2 = sub_80EF370(v1); + + ConvertIntToDecimalStringN(sScriptStringVars[stringVarIndex], v1, 0, v2); + return FALSE; +} + +bool8 ScrCmd_getstdstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 index = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], gUnknown_0858BAF0[index]); + return FALSE; +} + +bool8 ScrCmd_getcontesttype(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 index = VarGet(ScriptReadHalfword(ctx)); + + sub_818E868(sScriptStringVars[stringVarIndex], index); + return FALSE; +} + +bool8 ScrCmd_getstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + const u8 *text = (u8 *)ScriptReadWord(ctx); + + StringCopy(sScriptStringVars[stringVarIndex], text); + return FALSE; +} + +bool8 ScrCmd_vloadword(struct ScriptContext *ctx) +{ + const u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + + StringExpandPlaceholders(gStringVar4, ptr); + return FALSE; +} + +bool8 ScrCmd_vgetstring(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u32 addr = ScriptReadWord(ctx); + + const u8 *src = (u8 *)(addr - gUnknown_020375C4); + u8 *dest = sScriptStringVars[stringVarIndex]; + StringCopy(dest, src); + return FALSE; +} + +bool8 ScrCmd_getboxname(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 boxId = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], GetBoxNamePtr(boxId)); + return FALSE; +} + +bool8 ScrCmd_givepoke(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + u8 level = ScriptReadByte(ctx); + u16 item = VarGet(ScriptReadHalfword(ctx)); + u32 unkParam1 = ScriptReadWord(ctx); + u32 unkParam2 = ScriptReadWord(ctx); + u8 unkParam3 = ScriptReadByte(ctx); + + gScriptResult = ScriptGiveMon(species, level, item, unkParam1, unkParam2, unkParam3); + return FALSE; +} + +bool8 ScrCmd_giveegg(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = ScriptGiveEgg(species); + return FALSE; +} + +bool8 ScrCmd_setpokemove(struct ScriptContext *ctx) +{ + u8 partyIndex = ScriptReadByte(ctx); + u8 slot = ScriptReadByte(ctx); + u16 move = ScriptReadHalfword(ctx); + + ScriptSetMonMoveSlot(partyIndex, move, slot); + return FALSE; +} + +bool8 ScrCmd_checkpokemove(struct ScriptContext *ctx) +{ + u8 i; + u16 moveId = ScriptReadHalfword(ctx); + + gScriptResult = 6; + for (i = 0; i < 6; i++) + { + u16 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL); + if (!species) + break; + // UB: GetMonData() arguments don't match function definition + if (!GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) && pokemon_has_move(&gPlayerParty[i], moveId) == TRUE) + { + gScriptResult = i; + gSpecialVar_0x8004 = species; + break; + } + } + return FALSE; +} + +bool8 ScrCmd_givemoney(struct ScriptContext *ctx) +{ + u32 amount = ScriptReadWord(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + AddMoney(&gSaveBlock1Ptr->money, amount); + return FALSE; +} + +bool8 ScrCmd_takemoney(struct ScriptContext *ctx) +{ + u32 amount = ScriptReadWord(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + RemoveMoney(&gSaveBlock1Ptr->money, amount); + return FALSE; +} + +bool8 ScrCmd_checkmoney(struct ScriptContext *ctx) +{ + u32 amount = ScriptReadWord(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + gScriptResult = IsEnoughMoney(&gSaveBlock1Ptr->money, amount); + return FALSE; +} + +bool8 ScrCmd_showmoneybox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + DrawMoneyBox(GetMoney(&gSaveBlock1Ptr->money), x, y); + return FALSE; +} + +bool8 ScrCmd_hidemoneybox(struct ScriptContext *ctx) +{ + /*u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx);*/ + + HideMoneyBox(); + return FALSE; +} + +bool8 ScrCmd_updatemoneybox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + u8 ignore = ScriptReadByte(ctx); + + if (!ignore) + ChangeAmountInMoneyBox(GetMoney(&gSaveBlock1Ptr->money)); + return FALSE; +} + +bool8 ScrCmd_showcoinsbox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + ShowCoinsWindow(GetCoins(), x, y); + return FALSE; +} + +bool8 ScrCmd_hidecoinsbox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + HideCoinsWindow(); + return FALSE; +} + +bool8 ScrCmd_updatecoinsbox(struct ScriptContext *ctx) +{ + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + PrintCoinsString(GetCoins()); + return FALSE; +} + +bool8 ScrCmd_trainerbattle(struct ScriptContext *ctx) +{ + ctx->scriptPtr = BattleSetup_ConfigureTrainerBattle(ctx->scriptPtr); + return FALSE; +} + +bool8 ScrCmd_battlebegin(struct ScriptContext *ctx) +{ + BattleSetup_StartTrainerBattle(); + return TRUE; +} + +bool8 ScrCmd_ontrainerbattleend(struct ScriptContext *ctx) +{ + ctx->scriptPtr = BattleSetup_GetScriptAddrAfterBattle(); + return FALSE; +} + +bool8 ScrCmd_ontrainerbattleendgoto(struct ScriptContext *ctx) +{ + ctx->scriptPtr = BattleSetup_GetTrainerPostBattleScript(); + return FALSE; +} + +bool8 ScrCmd_checktrainerflag(struct ScriptContext *ctx) +{ + u16 index = VarGet(ScriptReadHalfword(ctx)); + + ctx->comparisonResult = HasTrainerAlreadyBeenFought(index); + return FALSE; +} + +bool8 ScrCmd_settrainerflag(struct ScriptContext *ctx) +{ + u16 index = VarGet(ScriptReadHalfword(ctx)); + + trainer_flag_set(index); + return FALSE; +} + +bool8 ScrCmd_cleartrainerflag(struct ScriptContext *ctx) +{ + u16 index = VarGet(ScriptReadHalfword(ctx)); + + trainer_flag_clear(index); + return FALSE; +} + +bool8 ScrCmd_setwildbattle(struct ScriptContext *ctx) +{ + u16 species = ScriptReadHalfword(ctx); + u8 level = ScriptReadByte(ctx); + u16 item = ScriptReadHalfword(ctx); + + CreateScriptedWildMon(species, level, item); + return FALSE; +} + +bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx) +{ + BattleSetup_StartScriptedWildBattle(); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_pokemart(struct ScriptContext *ctx) +{ + const void *ptr = (void *)ScriptReadWord(ctx); + + CreatePokemartMenu(ptr); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_pokemartdecor(struct ScriptContext *ctx) +{ + const void *ptr = (void *)ScriptReadWord(ctx); + + CreateDecorationShop1Menu(ptr); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_pokemartbp(struct ScriptContext *ctx) +{ + const void *ptr = (void *)ScriptReadWord(ctx); + + CreateDecorationShop2Menu(ptr); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_playslotmachine(struct ScriptContext *ctx) +{ + u8 slotMachineIndex = VarGet(ScriptReadHalfword(ctx)); + + PlaySlotMachine(slotMachineIndex, c2_exit_to_overworld_1_continue_scripts_restart_music); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_plantberrytree(struct ScriptContext *ctx) +{ + u8 treeId = ScriptReadByte(ctx); + u8 berry = ScriptReadByte(ctx); + u8 growthStage = ScriptReadByte(ctx); + + if (berry == 0) + PlantBerryTree(treeId, 0, growthStage, FALSE); + else + PlantBerryTree(treeId, berry, growthStage, FALSE); + return FALSE; +} + +bool8 ScrCmd_getpricereduction(struct ScriptContext *ctx) +{ + u16 value = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = GetPriceReduction(value); + return FALSE; +} + +bool8 ScrCmd_choosecontestpkmn(struct ScriptContext *ctx) +{ + sub_81B9404(); + ScriptContext1_Stop(); + return TRUE; +} + + +bool8 ScrCmd_startcontest(struct ScriptContext *ctx) +{ + sub_80F840C(); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_showcontestresults(struct ScriptContext *ctx) +{ + sub_80F8484(); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_contestlinktransfer(struct ScriptContext *ctx) +{ + sub_80F84C4(gScriptContestCategory); + ScriptContext1_Stop(); + return TRUE; +} + +bool8 ScrCmd_dofieldeffect(struct ScriptContext *ctx) +{ + u16 effectId = VarGet(ScriptReadHalfword(ctx)); + + sFieldEffectScriptId = effectId; + FieldEffectStart(sFieldEffectScriptId); + return FALSE; +} + +bool8 ScrCmd_setfieldeffect(struct ScriptContext *ctx) +{ + u8 argNum = ScriptReadByte(ctx); + + gFieldEffectArguments[argNum] = (s16)VarGet(ScriptReadHalfword(ctx)); + return FALSE; +} + +static bool8 WaitForFieldEffectFinish(void) +{ + if (!FieldEffectActiveListContains(sFieldEffectScriptId)) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_waitfieldeffect(struct ScriptContext *ctx) +{ + sFieldEffectScriptId = VarGet(ScriptReadHalfword(ctx)); + SetupNativeScript(ctx, WaitForFieldEffectFinish); + return TRUE; +} + +bool8 ScrCmd_sethealplace(struct ScriptContext *ctx) +{ + u16 healLocationId = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetHealLocationWarp(healLocationId); + return FALSE; +} + +bool8 ScrCmd_checkplayergender(struct ScriptContext *ctx) +{ + gScriptResult = gSaveBlock2Ptr->playerGender; + return FALSE; +} + +bool8 ScrCmd_playpokecry(struct ScriptContext *ctx) +{ + u16 species = VarGet(ScriptReadHalfword(ctx)); + u16 mode = VarGet(ScriptReadHalfword(ctx)); + + PlayCry5(species, mode); + return FALSE; +} + +bool8 ScrCmd_waitpokecry(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, IsCryFinished); + return TRUE; +} + +bool8 ScrCmd_setmaptile(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + u16 tileId = VarGet(ScriptReadHalfword(ctx)); + u16 v8 = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + if (!v8) + MapGridSetMetatileIdAt(x, y, tileId); + else + MapGridSetMetatileIdAt(x, y, tileId | 0xC00); + return FALSE; +} + +bool8 ScrCmd_opendoor(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + PlaySE(GetDoorSoundEffect(x, y)); + FieldAnimateDoorOpen(x, y); + return FALSE; +} + +bool8 ScrCmd_closedoor(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + FieldAnimateDoorClose(x, y); + return FALSE; +} + +static bool8 IsDoorAnimationStopped(void) +{ + if (!FieldIsDoorAnimationRunning()) + return TRUE; + else + return FALSE; +} + +bool8 ScrCmd_waitdooranim(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, IsDoorAnimationStopped); + return TRUE; +} + +bool8 ScrCmd_setdooropen(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + FieldSetDoorOpened(x, y); + return FALSE; +} + +bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx) +{ + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + x += 7; + y += 7; + FieldSetDoorClosed(x, y); + return FALSE; +} + +bool8 ScrCmd_addelevmenuitem(struct ScriptContext *ctx) +{ + u8 v3 = ScriptReadByte(ctx); + u16 v5 = VarGet(ScriptReadHalfword(ctx)); + u16 v7 = VarGet(ScriptReadHalfword(ctx)); + u16 v9 = VarGet(ScriptReadHalfword(ctx)); + + //ScriptAddElevatorMenuItem(v3, v5, v7, v9); + return FALSE; +} + +bool8 ScrCmd_showelevmenu(struct ScriptContext *ctx) +{ + /*ScriptShowElevatorMenu(); + ScriptContext1_Stop(); + return TRUE;*/ + return FALSE; +} + +bool8 ScrCmd_checkcoins(struct ScriptContext *ctx) +{ + u16 *ptr = GetVarPointer(ScriptReadHalfword(ctx)); + *ptr = GetCoins(); + return FALSE; +} + +bool8 ScrCmd_givecoins(struct ScriptContext *ctx) +{ + u16 coins = VarGet(ScriptReadHalfword(ctx)); + + if (GiveCoins(coins) == TRUE) + gScriptResult = 0; + else + gScriptResult = 1; + return FALSE; +} + +bool8 ScrCmd_takecoins(struct ScriptContext *ctx) +{ + u16 coins = VarGet(ScriptReadHalfword(ctx)); + + if (TakeCoins(coins) == TRUE) + gScriptResult = 0; + else + gScriptResult = 1; + return FALSE; +} + +bool8 ScrCmd_mossdeepgym1(struct ScriptContext *ctx) +{ + u16 v1 = VarGet(ScriptReadHalfword(ctx)); + + sMovingNpcId = sub_81A89A0(v1); + return FALSE; +} + +bool8 ScrCmd_mossdeepgym2(struct ScriptContext *ctx) +{ + sub_81A8AF8(); + return FALSE; +} + +bool8 ScrCmd_mossdeepgym3(struct ScriptContext *ctx) +{ + u16 v1 = VarGet(ScriptReadHalfword(ctx)); + + sub_81A8934(v1); + return FALSE; +} + +bool8 ScrCmd_mossdeepgym4(struct ScriptContext *ctx) +{ + sub_81A895C(); + return FALSE; +} + +bool8 ScrCmd_cmdD8(struct ScriptContext *ctx) +{ + gSelectedMapObject = sub_80B47BC(); + return FALSE; +} + +bool8 ScrCmd_cmdD9(struct ScriptContext *ctx) +{ + if (is_c1_link_related_active()) + { + return FALSE; + } + else + { + if (gMapObjects[gSelectedMapObject].active) + { + sub_8098630(); + SetupNativeScript(ctx, sub_8098734); + } + return TRUE; + } +} + +// This command will force the Pokémon to be obedient, you don't get to choose which value to set its obedience to +bool8 ScrCmd_setpokeobedient(struct ScriptContext *ctx) +{ + bool8 obedient = TRUE; + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + SetMonData(&gPlayerParty[partyIndex], MON_DATA_OBEDIENCE, &obedient); + return FALSE; +} + +bool8 ScrCmd_checkpokeobedience(struct ScriptContext *ctx) +{ + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + gScriptResult = GetMonData(&gPlayerParty[partyIndex], MON_DATA_OBEDIENCE, NULL); + return FALSE; +} + +bool8 ScrCmd_cmdCF(struct ScriptContext *ctx) +{ + const u8* v1 = sub_8099244(); + + if (v1) + { + ((u8*)gUnknown_020375C0) = ctx->scriptPtr; + ScriptJump(ctx, v1); + } + return FALSE; +} + +bool8 ScrCmd_warpD1(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_808D074(player_get_direction_lower_nybble()); + sub_80B0244(); + player_avatar_init_params_reset(); + return TRUE; +} + +bool8 ScrCmd_setpokemetlocation(struct ScriptContext *ctx) +{ + u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + u8 location = ScriptReadByte(ctx); + + if (partyIndex < PARTY_SIZE) + SetMonData(&gPlayerParty[partyIndex], MON_DATA_MET_LOCATION, &location); + return FALSE; +} + +void sub_809BDB4(void) +{ + sub_819746C(gUnknown_03000F30, 1); + RemoveWindow(gUnknown_03000F30); +} + +bool8 ScrCmd_gettrainerclass(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 trainerClassId = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], GetTrainerClassNameFromId(trainerClassId)); + return FALSE; +} + +bool8 ScrCmd_gettrainername(struct ScriptContext *ctx) +{ + u8 stringVarIndex = ScriptReadByte(ctx); + u16 trainerClassId = VarGet(ScriptReadHalfword(ctx)); + + StringCopy(sScriptStringVars[stringVarIndex], GetTrainerNameFromId(trainerClassId)); + return FALSE; +} + +void sub_809BE48(u16 npcId) +{ + sMovingNpcId = npcId; +} -// .rodata +bool8 ScrCmd_warpE0(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); -// .text + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + sub_80AF79C(); + player_avatar_init_params_reset(); + return TRUE; +} diff --git a/src/script.c b/src/script.c index b2809a137..5a1c5daa9 100644 --- a/src/script.c +++ b/src/script.c @@ -134,12 +134,12 @@ const u8 *ScriptPop(struct ScriptContext *ctx) return ctx->stack[ctx->stackDepth]; } -void ScriptJump(struct ScriptContext *ctx, u8 *ptr) +void ScriptJump(struct ScriptContext *ctx, const u8 *ptr) { ctx->scriptPtr = ptr; } -void ScriptCall(struct ScriptContext *ctx, u8 *ptr) +void ScriptCall(struct ScriptContext *ctx, const u8 *ptr) { ScriptPush(ctx, ctx->scriptPtr); ctx->scriptPtr = ptr; diff --git a/src/text.c b/src/text.c index 7cc46cd92..8108a6867 100644 --- a/src/text.c +++ b/src/text.c @@ -145,7 +145,7 @@ void DeactivateAllTextPrinters (void) gTextPrinters[printer].sub_union.sub.active = 0; } -u16 PrintTextOnWindow(u8 windowId, u8 fontId, u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextSubPrinter *, u16)) +u16 PrintTextOnWindow(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextSubPrinter *, u16)) { struct TextSubPrinter subPrinter; @@ -2,7 +2,7 @@ // Includes #include "global.h" #include "rtc.h" -#include "rom4.h" +#include "overworld.h" #include "map_constants.h" #include "rng.h" #include "event_data.h" @@ -838,7 +838,7 @@ void UpdateTVScreensOnMap(int width, int height) } else if (FlagGet(SYS_TV_START) && (FindAnyTVShowOnTheAir() != 0xff || FindAnyTVNewsOnTheAir() != 0xff || IsTVShowInSearchOfTrainersAiring())) { - FlagReset(SYS_TV_WATCH); + FlagClear(SYS_TV_WATCH); SetTVMetatilesOnMap(width, height, 0x3); } break; @@ -1263,7 +1263,7 @@ void InterviewAfter_ContestLiveUpdates(void) show2->contestLiveUpdates.kind = TVSHOW_CONTEST_LIVE_UPDATES; show2->contestLiveUpdates.active = TRUE; StringCopy(show2->contestLiveUpdates.playerName, gSaveBlock2Ptr->playerName); - show2->contestLiveUpdates.category = gUnknown_02039F2C; + show2->contestLiveUpdates.category = gScriptContestCategory; show2->contestLiveUpdates.species = GetMonData(&gPlayerParty[gUnknown_02039F24], MON_DATA_SPECIES, NULL); show2->contestLiveUpdates.winningSpecies = show->contestLiveUpdates.winningSpecies; show2->contestLiveUpdates.appealFlags2 = show->contestLiveUpdates.appealFlags2; @@ -1527,7 +1527,7 @@ void BravoTrainerPokemonProfile_BeforeInterview2(u8 a0) if (sCurTVShowSlot != -1) { show->bravoTrainer.contestResult = a0; - show->bravoTrainer.contestCategory = gUnknown_02039F2C; + show->bravoTrainer.contestCategory = gScriptContestCategory; show->bravoTrainer.contestRank = gUnknown_02039F2E; show->bravoTrainer.species = GetMonData(&gPlayerParty[gUnknown_02039F24], MON_DATA_SPECIES, NULL); GetMonData(&gPlayerParty[gUnknown_02039F24], MON_DATA_NICKNAME, show->bravoTrainer.pokemonNickname); @@ -1675,7 +1675,7 @@ void InterviewAfter_FanClubLetter(void) show->fanclubLetter.kind = TVSHOW_FAN_CLUB_LETTER; show->fanclubLetter.active = TRUE; StringCopy(show->fanclubLetter.playerName, gSaveBlock2Ptr->playerName); - show->fanclubLetter.species = GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_SPECIES, NULL); + show->fanclubLetter.species = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL); tv_store_id_2x(show); show->fanclubLetter.language = gGameLanguage; } @@ -1700,21 +1700,21 @@ void InterviewAfter_PkmnFanClubOpinions(void) show = &gSaveBlock1Ptr->tvShows[sCurTVShowSlot]; show->fanclubOpinions.kind = TVSHOW_PKMN_FAN_CLUB_OPINIONS; show->fanclubOpinions.active = TRUE; - show->fanclubOpinions.friendshipHighNybble = GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_FRIENDSHIP, NULL) >> 4; + show->fanclubOpinions.friendshipHighNybble = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_FRIENDSHIP, NULL) >> 4; show->fanclubOpinions.questionAsked = gSpecialVar_0x8007; StringCopy(show->fanclubOpinions.playerName, gSaveBlock2Ptr->playerName); - GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_NICKNAME, show->fanclubOpinions.nickname); + GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_NICKNAME, show->fanclubOpinions.nickname); StripExtCtrlCodes(show->fanclubOpinions.nickname); - show->fanclubOpinions.species = GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_SPECIES, NULL); + show->fanclubOpinions.species = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL); tv_store_id_2x(show); show->fanclubOpinions.language = gGameLanguage; - if (gGameLanguage == LANGUAGE_JAPANESE || GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_LANGUAGE) == LANGUAGE_JAPANESE) + if (gGameLanguage == LANGUAGE_JAPANESE || GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_LANGUAGE) == LANGUAGE_JAPANESE) { show->fanclubOpinions.pokemonNameLanguage = LANGUAGE_JAPANESE; } else { - show->fanclubOpinions.pokemonNameLanguage = GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_LANGUAGE); + show->fanclubOpinions.pokemonNameLanguage = GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_LANGUAGE); } } @@ -3073,7 +3073,7 @@ void TV_PrintIntToStringVar(u8 varIdx, int value) ConvertIntToDecimalStringN(gTVStringVarPtrs[varIdx], value, STR_CONV_MODE_LEFT_ALIGN, nDigits); } -int sub_80EF370(int value) +size_t sub_80EF370(int value) { if (value / 10 == 0) { @@ -3246,7 +3246,7 @@ void InterviewBefore_FanClubLetter(void) FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_FAN_CLUB_LETTER); if (!gScriptResult) { - StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_SPECIES, NULL)]); + StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL)]); InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubLetter.words, 6); } } @@ -3265,8 +3265,8 @@ void InterviewBefore_PkmnFanClubOpinions(void) FindActiveBroadcastByShowType_SetScriptResult(TVSHOW_PKMN_FAN_CLUB_OPINIONS); if (!gScriptResult) { - StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_SPECIES, NULL)]); - GetMonData(&gPlayerParty[GetIdxOfFirstPartyMemberThatIsNotAnEgg()], MON_DATA_NICKNAME, gStringVar2); + StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL)]); + GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_NICKNAME, gStringVar2); StringGetEnd10(gStringVar2); InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubOpinions.words, 2); } @@ -3336,7 +3336,7 @@ bool8 sub_80EF88C(u8 monIdx) bool8 sub_80EF8F8(void) { - return sub_80EF88C(GetIdxOfFirstPartyMemberThatIsNotAnEgg()); + return sub_80EF88C(GetLeadMonIndex()); } void DeleteTVShowInArrayByIdx(TVShow *shows, u8 idx) |