Finish updating macro comments

This commit is contained in:
GriffinR 2021-11-18 00:32:28 -05:00
parent b5b5d95de6
commit c89dfd9f56
11 changed files with 202 additions and 158 deletions

View File

@ -76,63 +76,62 @@
.byte \function
.endm
@ Executes a script stored in a default RAM location.
@ Equivalent to the 'return' command for a RAM script.
.macro returnram
.byte 0x0c
.endm
@ Terminates script execution and "resets the script RAM".
.macro killscript
@ Equivalent to the 'end' command for a RAM script.
.macro endram
.byte 0x0d
.endm
@ Sets some status related to Mystery Event.
@ Sets the Mystery Event script status (MEVENT_STATUS_*).
.macro setmysteryeventstatus value:req
.byte 0x0e
.byte \value
.endm
@ Sets the specified script bank to value.
.macro loadword destination:req, value:req
@ Sets the value at the specified script data index to a fixed 4-byte value.
.macro loadword destIndex:req, value:req
.byte 0x0f
.byte \destination
.byte \destIndex
.4byte \value
.endm
@ Sets the specified script bank to value.
.macro loadbyte destination:req, value:req
@ Sets the value at the specified script data index to a fixed byte value.
.macro loadbyte destIndex:req, value:req
.byte 0x10
.byte \destination
.byte \destIndex
.byte \value
.endm
@ Sets the byte at offset to value.
.macro writebytetoaddr value:req, offset:req
@ Sets the value at the specified pointer.
.macro setptr value:req, ptr:req
.byte 0x11
.byte \value
.4byte \offset
.4byte \ptr
.endm
@ Copies the byte value at source into the specified script bank.
.macro loadbytefromaddr destination:req, source:req
@ Sets the value at the specified script data index to the value at pointer 'source'.
.macro loadbytefromptr destIndex:req, source:req
.byte 0x12
.byte \destination
.byte \destIndex
.4byte \source
.endm
@ TODO
@ Not sure. Judging from XSE's description I think it takes the least-significant byte in bank source and writes it to destination.
.macro setptrbyte source:req, destination:req
@ Sets the value at pointer 'destination' to the contents of the script data at 'srcIndex'.
.macro setptrbyte srcIndex:req, destination:req
.byte 0x13
.byte \source
.byte \srcIndex
.4byte \destination
.endm
@ Copies the contents of bank source into bank destination.
.macro copylocal destination:req, source:req
@ Copies the contents of the script data from one index to another.
.macro copylocal destIndex:req, srcIndex:req
.byte 0x14
.byte \destination
.byte \source
.byte \destIndex
.byte \srcIndex
.endm
@ Copies the byte at source to destination, replacing whatever byte was previously there.
@ -177,56 +176,64 @@
.2byte \source
.endm
@ Compares the values of script banks a and b, after forcing the values to bytes.
.macro compare_local_to_local byte1:req, byte2:req
@ Compares the values of the script data at indexes 'local1' and 'local2'.
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_local_to_local local1:req, local2:req
.byte 0x1b
.byte \byte1
.byte \byte2
.byte \local1
.byte \local2
.endm
@ Compares the least-significant byte of the value of script bank a to a fixed byte value (b).
.macro compare_local_to_value a:req, b:req
@ Compares the value of the script data at index 'local' to a fixed value.
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_local_to_value local:req, value:req
.byte 0x1c
.byte \a
.byte \b
.byte \local
.byte \value
.endm
@ Compares the least-significant byte of the value of script bank a to the byte located at offset b.
.macro compare_local_to_addr a:req, b:req
@ Compares the value of the script data at index 'local' to the value at 'ptr'
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_local_to_ptr local:req, ptr:req
.byte 0x1d
.byte \a
.4byte \b
.byte \local
.4byte \ptr
.endm
@ Compares the byte located at offset a to the least-significant byte of the value of script bank b.
.macro compare_addr_to_local a:req, b:req
@ Compares the value at 'ptr' to the value of the script data at index 'local'.
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_ptr_to_local ptr:req, local:req
.byte 0x1e
.4byte \a
.byte \b
.4byte \ptr
.byte \local
.endm
@ Compares the byte located at offset a to a fixed byte value (b).
.macro compare_addr_to_value a:req, b:req
@ Compares the value at 'ptr' to a fixed value.
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_ptr_to_value ptr:req, value:req
.byte 0x1f
.4byte \a
.byte \b
.4byte \ptr
.byte \value
.endm
@ Compares the byte located at offset a to the byte located at offset b.
.macro compare_addr_to_addr a:req, b:req
@ Compares the value at 'ptr1' to the value at 'ptr2'.
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_ptr_to_ptr ptr1:req, ptr2:req
.byte 0x20
.4byte \a
.4byte \b
.4byte \ptr1
.4byte \ptr2
.endm
@ Compares the value of `var` to a fixed word value (b).
@ Compares the value of 'var' to a fixed value.
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_var_to_value var:req, value:req
.byte 0x21
.2byte \var
.2byte \value
.endm
@ Compares the value of `var1` to the value of `var2`.
@ Compares the value of 'var1' to the value of 'var2'.
@ The result is stored in comparisonResult to be acted on by goto_if / call_if
.macro compare_var_to_var var1:req, var2:req
.byte 0x22
.2byte \var1
@ -269,9 +276,8 @@
.2byte SPECIAL_\function
.endm
@ Blocks script execution until a command or ASM code manually unblocks it. Generally used with specific
@ commands and specials. If this command runs, and a subsequent command or piece of ASM does not unblock
@ state, the script will remain blocked indefinitely (essentially a hang).
@ Blocks script execution until a command or C code manually unblocks it. Generally used with specific
@ commands and specials. Calling EnableBothScriptContexts for instance will allow execution to continue.
.macro waitstate
.byte 0x27
.endm
@ -308,7 +314,7 @@
.2byte \minute
.endm
@ Runs time based events.
@ Updates local time using the RTC and runs time based events.
.macro dotimebasedevents
.byte 0x2d
.endm
@ -649,12 +655,14 @@
.2byte \y
.endm
@ Sets the specified object's invisibility to FALSE.
.macro showobjectat localId:req, map:req
.byte 0x58
.2byte \localId
map \map
.endm
@ Sets the specified object's invisibility to TRUE.
.macro hideobjectat localId:req, map:req
.byte 0x59
.2byte \localId
@ -673,7 +681,7 @@
.byte \direction
.endm
@ TODO
@ Configures the arguments for a trainer battle, then jumps to the appropriate script in scripts/trainer_battle.inc
.macro trainerbattle type:req, trainer:req, local_id:req, pointer1:req, pointer2, pointer3, pointer4
.byte 0x5c
.byte \type
@ -770,9 +778,9 @@
.endm
@ Starts a trainer battle using the battle information stored in RAM (usually by trainerbattle, which actually calls this
@ command behind-the-scenes), and blocks script execution until the battle finishes.
.macro trainerbattlebegin
@ Starts a trainer battle using the battle information stored in RAM (usually by the scripts in trainer_battle.inc, which
@ are run by trainerbattle), and blocks script execution until the battle finishes.
.macro dotrainerbattle
.byte 0x5d
.endm
@ -1129,7 +1137,7 @@
.byte \growthStage
.endm
@ This allows you to choose a Pokemon to use in a contest
@ Opens the party menu to select a Pokemon for a contest.
.macro choosecontestmon
.byte 0x8b
.endm
@ -1262,7 +1270,7 @@
.2byte \animation
.endm
@ Sets which healing place the player will return to if all of the Pokemon in their party faint.
@ Sets which healing location (HEAL_LOCATION_*) the player will return to if all of the Pokemon in their party faint.
.macro setrespawn heallocation:req
.byte 0x9f
.2byte \heallocation
@ -1437,43 +1445,51 @@
.byte 0xb7
.endm
@ Sets a relative address to be used by the other vcommands as part of a Mystery Gift script.
.macro setvaddress pointer:req
.byte 0xb8
.4byte \pointer
.endm
@ Equivalent to goto using the relative address set by setvaddress.
.macro vgoto pointer:req
.byte 0xb9
.4byte \pointer
.endm
@ Equivalent to call using the relative address set by setvaddress.
.macro vcall pointer:req
.byte 0xba
.4byte \pointer
.endm
@ Equivalent to goto_if using the relative address set by setvaddress.
.macro vgoto_if byte:req, pointer:req
.byte 0xbb
.byte \byte
.4byte \pointer
.endm
@ Equivalent to call_if using the relative address set by setvaddress.
.macro vcall_if byte:req, pointer:req
.byte 0xbc
.byte \byte
.4byte \pointer
.endm
@ Equivalent to message using the relative address set by setvaddress.
.macro vmessage pointer:req
.byte 0xbd
.4byte \pointer
.endm
.macro vloadptr pointer:req
@ Expands the given text at the pointer (- the relative address set by setvaddress) into gStringVar4
.macro vbuffermessage ptr:req
.byte 0xbe
.4byte \pointer
.4byte \ptr
.endm
@ Equivalent to bufferstring using the relative address set by setvaddress.
.macro vbufferstring stringVarIndex:req, pointer:req
.byte 0xbf
stringvar \stringVarIndex
@ -1576,7 +1592,7 @@
@ Jumps to the ram script saved from a Wonder Card. If there is no valid saved Wonder Card or if the
@ ram script is invalid then this does nothing.
.macro gotowondercardscript
.macro trywondercardscript
.byte 0xcf
.endm
@ -1586,6 +1602,8 @@
.2byte \worldmapflag
.endm
@ Warps the player to the specified map using a teleport effect. Effect is similar to warpteleport, but
@ this warp has no fade out and maintains the original facing direction.
@ Warp commands can be given either the id of which warp location to go to on the destination map
@ or a pair of x/y coordinates to go to directly on the destination map.
.macro warpspinenter map:req, a, b, c
@ -1625,6 +1643,8 @@
.byte 0xd6
.endm
@ Warp used by the teleport tiles in the Mossdeep Gym. Plays SE_WARP_IN and does a simple fade transition.
@ Also skips reloading object events by setting SKIP_OBJECT_EVENT_LOAD.
@ Warp commands can be given either the id of which warp location to go to on the destination map
@ or a pair of x/y coordinates to go to directly on the destination map.
.macro warpmossdeepgym map:req, a, b, c
@ -1655,15 +1675,19 @@
.4byte \text
.endm
@ Equivalent to fadescreen but copies gPlttBufferUnfaded to gPaletteDecompressionBuffer on the fade out
@ and the reverse on the fade in, in effect saving gPlttBufferUnfaded to restore it.
.macro fadescreenswapbuffers mode:req
.byte 0xdc
.byte \mode
.endm
.macro buffertrainerclassname stringVarId:req, class:req
@ Buffers the specified trainer's class name to the given string var.
@ If the trainer id is >= TRAINERS_COUNT it will be treated as TRAINER_NONE.
.macro buffertrainerclassname stringVarId:req, trainerId:req
.byte 0xdd
stringvar \stringVarId
.2byte \class
.2byte \trainerId
.endm
@ Buffers the specified trainer's name to the given string var.
@ -1680,9 +1704,10 @@
.4byte \text
.endm
@ Warp with a fade to white. Used during the Sootopolis legendary fight.
@ Warp commands can be given either the id of which warp location to go to on the destination map
@ or a pair of x/y coordinates to go to directly on the destination map.
.macro warpsootopolislegend map:req, a, b, c
.macro warpwhitefade map:req, a, b, c
.byte 0xe0
formatwarp \map, \a, \b, \c
.endm
@ -1835,6 +1860,7 @@
YES = 1
NO = 0
@ Buffers the given text and calls the relevant standard message script (see gStdScripts).
.macro msgbox text:req, type=MSGBOX_DEFAULT
loadword 0, \text
callstd \type
@ -1850,17 +1876,21 @@
callstd STD_OBTAIN_ITEM
.endm
@ For picking up items in the overworld. Similar to giveitem, but with different language and
@ sets the flag of the last-talked to object (the item the player picked up).
.macro finditem item:req, amount=1
setorcopyvar VAR_0x8000, \item
setorcopyvar VAR_0x8001, \amount
callstd STD_FIND_ITEM
.endm
@ Equivalent to giveitem but for a single decoration.
.macro givedecoration decoration:req
setorcopyvar VAR_0x8000, \decoration
callstd STD_OBTAIN_DECORATION
.endm
@ Registers the specified trainer in Match Call and plays a fanfare with a notification message.
.macro register_matchcall trainer:req
setvar VAR_0x8004, \trainer
special SetMatchCallRegisteredFlag
@ -1868,6 +1898,7 @@
callstd STD_REGISTER_MATCH_CALL
.endm
@ Does a sparkle field effect (e.g. when the Trick Master is hiding) at the given coordinates.
.macro dofieldeffectsparkle x:req, y:req, priority:req
setfieldeffectargument 0, \x
setfieldeffectargument 1, \y

View File

@ -565,7 +565,7 @@ SootopolisCity_EventScript_RayquazaSceneFromPokeCenter::
fadenewbgm MUS_SOOTOPOLIS
delay 120
clearflag FLAG_HIDE_MAP_NAME_POPUP
warpsootopolislegend MAP_SOOTOPOLIS_CITY, 43, 32
warpwhitefade MAP_SOOTOPOLIS_CITY, 43, 32
waitstate
end
@ -618,7 +618,7 @@ SootopolisCity_EventScript_RayquazaSceneFromDive::
fadenewbgm MUS_SURF
delay 120
clearflag FLAG_HIDE_MAP_NAME_POPUP
warpsootopolislegend MAP_SOOTOPOLIS_CITY, 29, 53
warpwhitefade MAP_SOOTOPOLIS_CITY, 29, 53
waitstate
end

View File

@ -13,12 +13,12 @@ gScriptCmdTable::
.4byte ScrCmd_gotostd_if @ 0x0a
.4byte ScrCmd_callstd_if @ 0x0b
.4byte ScrCmd_returnram @ 0x0c
.4byte ScrCmd_killscript @ 0x0d
.4byte ScrCmd_endram @ 0x0d
.4byte ScrCmd_setmysteryeventstatus @ 0x0e
.4byte ScrCmd_loadword @ 0x0f
.4byte ScrCmd_loadbyte @ 0x10
.4byte ScrCmd_writebytetoaddr @ 0x11
.4byte ScrCmd_loadbytefromaddr @ 0x12
.4byte ScrCmd_setptr @ 0x11
.4byte ScrCmd_loadbytefromptr @ 0x12
.4byte ScrCmd_setptrbyte @ 0x13
.4byte ScrCmd_copylocal @ 0x14
.4byte ScrCmd_copybyte @ 0x15
@ -29,10 +29,10 @@ gScriptCmdTable::
.4byte ScrCmd_setorcopyvar @ 0x1a
.4byte ScrCmd_compare_local_to_local @ 0x1b
.4byte ScrCmd_compare_local_to_value @ 0x1c
.4byte ScrCmd_compare_local_to_addr @ 0x1d
.4byte ScrCmd_compare_addr_to_local @ 0x1e
.4byte ScrCmd_compare_addr_to_value @ 0x1f
.4byte ScrCmd_compare_addr_to_addr @ 0x20
.4byte ScrCmd_compare_local_to_ptr @ 0x1d
.4byte ScrCmd_compare_ptr_to_local @ 0x1e
.4byte ScrCmd_compare_ptr_to_value @ 0x1f
.4byte ScrCmd_compare_ptr_to_ptr @ 0x20
.4byte ScrCmd_compare_var_to_value @ 0x21
.4byte ScrCmd_compare_var_to_var @ 0x22
.4byte ScrCmd_callnative @ 0x23
@ -190,7 +190,7 @@ gScriptCmdTable::
.4byte ScrCmd_vgoto_if @ 0xbb
.4byte ScrCmd_vcall_if @ 0xbc
.4byte ScrCmd_vmessage @ 0xbd
.4byte ScrCmd_vloadword @ 0xbe
.4byte ScrCmd_vbuffermessage @ 0xbe
.4byte ScrCmd_vbufferstring @ 0xbf
.4byte ScrCmd_showcoinsbox @ 0xc0
.4byte ScrCmd_hidecoinsbox @ 0xc1
@ -207,7 +207,7 @@ gScriptCmdTable::
.4byte ScrCmd_nop1 @ 0xcc
.4byte ScrCmd_setmoneventlegal @ 0xcd
.4byte ScrCmd_checkmoneventlegal @ 0xce
.4byte ScrCmd_gotowondercardscript @ 0xcf
.4byte ScrCmd_trywondercardscript @ 0xcf
.4byte ScrCmd_nop1 @ 0xd0
.4byte ScrCmd_warpspinenter @ 0xd1
.4byte ScrCmd_setmonmetlocation @ 0xd2
@ -224,7 +224,7 @@ gScriptCmdTable::
.4byte ScrCmd_buffertrainerclassname @ 0xdd
.4byte ScrCmd_buffertrainername @ 0xde
.4byte ScrCmd_pokenavcall @ 0xdf
.4byte ScrCmd_warpsootopolislegend @ 0xe0
.4byte ScrCmd_warpwhitefade @ 0xe0
.4byte ScrCmd_buffercontestname @ 0xe1
.4byte ScrCmd_bufferitemnameplural @ 0xe2

View File

@ -28,7 +28,7 @@ CableClub_EventScript_MysteryGiftMan::
end
CableClub_EventScript_TryWonderCardScript::
gotowondercardscript
trywondercardscript
CableClub_EventScript_MysteryGiftThankYou::
msgbox gText_ThankYouForAccessingMysteryGift, MSGBOX_NPC
end

View File

@ -50,7 +50,7 @@ EventScript_DoNoIntroTrainerBattle::
applymovement VAR_LAST_TALKED, Movement_RevealTrainer
waitmovement 0
special PlayTrainerEncounterMusic
trainerbattlebegin
dotrainerbattle
gotopostbattlescript
EventScript_TryDoRematchBattle::
@ -117,7 +117,7 @@ EventScript_ShowTrainerIntroMsg::
goto EventScript_DoTrainerBattle
EventScript_DoTrainerBattle::
trainerbattlebegin
dotrainerbattle
@ Below battle mode check only needed in FRLG
specialvar VAR_RESULT, GetTrainerBattleMode
compare VAR_RESULT, TRAINER_BATTLE_SINGLE

View File

@ -22,7 +22,7 @@ void FieldCB_ReturnToFieldNoScript(void);
void FieldCB_ReturnToFieldNoScriptCheckMusic(void);
void DoWarp(void);
void DoDiveWarp(void);
void DoSootopolisLegendWarp(void);
void DoWhiteFadeWarp(void);
void DoDoorWarp(void);
void DoFallWarp(void);
void DoEscalatorWarp(u8 metatileBehavior);

View File

@ -1,8 +1,16 @@
#ifndef GUARD_MYSTERY_EVENT_SCRIPT_H
#define GUARD_MYSTERY_EVENT_SCRIPT_H
enum {
MEVENT_STATUS_LOAD_OK,
MEVENT_STATUS_LOAD_ERROR,
MEVENT_STATUS_SUCCESS,
MEVENT_STATUS_FAILURE,
MEVENT_STATUS_FF = 0xFF
};
void InitMysteryEventScriptContext(u8 *script);
bool32 RunMysteryEventScriptContextCommand(u32 *script);
bool32 RunMysteryEventScriptContextCommand(u32 *status);
u32 RunMysteryEventScript(u8 *script);
void SetMysteryEventScriptStatus(u32 val);
u16 GetRecordMixingGift(void);

View File

@ -502,7 +502,7 @@ void DoDiveWarp(void)
CreateTask(Task_WarpAndLoadMap, 10);
}
void DoSootopolisLegendWarp(void)
void DoWhiteFadeWarp(void)
{
ScriptContext2_Enable();
TryFadeOutOldMapMusic();

View File

@ -111,16 +111,16 @@ static bool8 GetEventLoadMessage(u8 *dest, u32 status)
{
bool8 retVal = TRUE;
if (status == 0)
if (status == MEVENT_STATUS_LOAD_OK)
{
StringCopy(dest, gText_EventSafelyLoaded);
retVal = FALSE;
}
if (status == 2)
if (status == MEVENT_STATUS_SUCCESS)
retVal = FALSE;
if (status == 1)
if (status == MEVENT_STATUS_LOAD_ERROR)
StringCopy(dest, gText_LoadErrorEndingSession);
return retVal;
@ -193,7 +193,7 @@ static void CB2_MysteryEventMenu(void)
}
else
{
GetEventLoadMessage(gStringVar4, 1);
GetEventLoadMessage(gStringVar4, MEVENT_STATUS_LOAD_ERROR);
PrintMysteryMenuText(0, gStringVar4, 1, 2, 1);
gMain.state = 13;
}
@ -206,7 +206,7 @@ static void CB2_MysteryEventMenu(void)
if (GetLinkPlayerDataExchangeStatusTimed(2, 2) == EXCHANGE_DIFF_SELECTIONS)
{
SetCloseLinkCallback();
GetEventLoadMessage(gStringVar4, 1);
GetEventLoadMessage(gStringVar4, MEVENT_STATUS_LOAD_ERROR);
PrintMysteryMenuText(0, gStringVar4, 1, 2, 1);
gMain.state = 13;
}
@ -218,7 +218,7 @@ static void CB2_MysteryEventMenu(void)
else
{
CloseLink();
GetEventLoadMessage(gStringVar4, 1);
GetEventLoadMessage(gStringVar4, MEVENT_STATUS_LOAD_ERROR);
PrintMysteryMenuText(0, gStringVar4, 1, 2, 1);
gMain.state = 13;
}
@ -252,9 +252,9 @@ static void CB2_MysteryEventMenu(void)
case 11:
if (gReceivedRemoteLinkPlayers == 0)
{
u16 unkVal = RunMysteryEventScript(gDecompressionBuffer);
u16 status = RunMysteryEventScript(gDecompressionBuffer);
CpuFill32(0, gDecompressionBuffer, 0x7D4);
if (!GetEventLoadMessage(gStringVar4, unkVal))
if (!GetEventLoadMessage(gStringVar4, status))
TrySavingData(SAVE_NORMAL);
gMain.state++;
}
@ -290,7 +290,7 @@ static void CB2_MysteryEventMenu(void)
if (gLinkStatus & 0x40 && !IsLinkMaster())
{
CloseLink();
GetEventLoadMessage(gStringVar4, 1);
GetEventLoadMessage(gStringVar4, MEVENT_STATUS_LOAD_ERROR);
PrintMysteryMenuText(0, gStringVar4, 1, 2, 1);
gMain.state = 13;
}

View File

@ -22,6 +22,11 @@ extern ScrCmdFunc gMysteryEventScriptCmdTableEnd[];
#define LANGUAGE_MASK 0x1
#define VERSION_MASK 0x200
#define mScriptBase data[0]
#define mOffset data[1]
#define mStatus data[2]
#define mValid data[3]
EWRAM_DATA static struct ScriptContext sMysteryEventScriptContext = {0};
static bool32 CheckCompatibility(u16 a1, u32 a2, u16 a3, u32 a4)
@ -44,22 +49,22 @@ static bool32 CheckCompatibility(u16 a1, u32 a2, u16 a3, u32 a4)
static void SetIncompatible(void)
{
StringExpandPlaceholders(gStringVar4, gText_MysteryEventCantBeUsed);
SetMysteryEventScriptStatus(3);
SetMysteryEventScriptStatus(MEVENT_STATUS_FAILURE);
}
static void InitMysteryEventScript(struct ScriptContext *ctx, u8 *script)
{
InitScriptContext(ctx, gMysteryEventScriptCmdTable, gMysteryEventScriptCmdTableEnd);
SetupBytecodeScript(ctx, script);
ctx->data[0] = (u32)script;
ctx->data[1] = 0;
ctx->data[2] = 0;
ctx->data[3] = 0;
ctx->mScriptBase = (u32)script;
ctx->mOffset = 0;
ctx->mStatus = MEVENT_STATUS_LOAD_OK;
ctx->mValid = FALSE;
}
static bool32 RunMysteryEventScriptCommand(struct ScriptContext *ctx)
{
if (RunScriptCommand(ctx) && ctx->data[3])
if (RunScriptCommand(ctx) && ctx->mValid)
return TRUE;
else
return FALSE;
@ -70,10 +75,10 @@ void InitMysteryEventScriptContext(u8 *script)
InitMysteryEventScript(&sMysteryEventScriptContext, script);
}
bool32 RunMysteryEventScriptContextCommand(u32 *script)
bool32 RunMysteryEventScriptContextCommand(u32 *status)
{
bool32 ret = RunMysteryEventScriptCommand(&sMysteryEventScriptContext);
*script = sMysteryEventScriptContext.data[2];
*status = sMysteryEventScriptContext.mStatus;
return ret;
}
@ -84,12 +89,12 @@ u32 RunMysteryEventScript(u8 *script)
InitMysteryEventScript(ctx, script);
while (RunMysteryEventScriptCommand(ctx));
return ctx->data[2];
return ctx->mStatus;
}
void SetMysteryEventScriptStatus(u32 val)
void SetMysteryEventScriptStatus(u32 status)
{
sMysteryEventScriptContext.data[2] = val;
sMysteryEventScriptContext.mStatus = status;
}
static int CalcRecordMixingGiftChecksum(void)
@ -174,14 +179,14 @@ bool8 MEScrCmd_checkcompat(struct ScriptContext *ctx)
u16 v3;
u32 v4;
ctx->data[1] = ScriptReadWord(ctx);
ctx->mOffset = ScriptReadWord(ctx);
v1 = ScriptReadHalfword(ctx);
v2 = ScriptReadWord(ctx);
v3 = ScriptReadHalfword(ctx);
v4 = ScriptReadWord(ctx);
if (CheckCompatibility(v1, v2, v3, v4) == TRUE)
ctx->data[3] = 1;
ctx->mValid = TRUE;
else
SetIncompatible();
@ -195,23 +200,23 @@ bool8 MEScrCmd_nop(struct ScriptContext *ctx)
bool8 MEScrCmd_setstatus(struct ScriptContext *ctx)
{
u8 value = ScriptReadByte(ctx);
ctx->data[2] = value;
u8 status = ScriptReadByte(ctx);
ctx->mStatus = status;
return FALSE;
}
bool8 MEScrCmd_setmsg(struct ScriptContext *ctx)
{
u8 value = ScriptReadByte(ctx);
u8 *str = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
if (value == 0xFF || value == ctx->data[2])
u8 status = ScriptReadByte(ctx);
u8 *str = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
if (status == MEVENT_STATUS_FF || status == ctx->mStatus)
StringExpandPlaceholders(gStringVar4, str);
return FALSE;
}
bool8 MEScrCmd_runscript(struct ScriptContext *ctx)
{
u8 *script = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *script = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
ScriptContext2_RunNewScript(script);
return FALSE;
}
@ -221,7 +226,7 @@ bool8 MEScrCmd_setenigmaberry(struct ScriptContext *ctx)
u8 *str;
const u8 *message;
bool32 haveBerry = IsEnigmaBerryValid();
u8 *berry = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *berry = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
StringCopyN(gStringVar1, gSaveBlock1Ptr->enigmaBerry.berry.name, BERRY_NAME_LENGTH + 1);
SetEnigmaBerry(berry);
StringCopyN(gStringVar2, gSaveBlock1Ptr->enigmaBerry.berry.name, BERRY_NAME_LENGTH + 1);
@ -244,12 +249,12 @@ bool8 MEScrCmd_setenigmaberry(struct ScriptContext *ctx)
StringExpandPlaceholders(str, message);
ctx->data[2] = 2;
ctx->mStatus = MEVENT_STATUS_SUCCESS;
if (IsEnigmaBerryValid() == TRUE)
VarSet(VAR_ENIGMA_BERRY_AVAILABLE, 1);
else
ctx->data[2] = 1;
ctx->mStatus = MEVENT_STATUS_LOAD_ERROR;
return FALSE;
}
@ -260,7 +265,7 @@ bool8 MEScrCmd_giveribbon(struct ScriptContext *ctx)
u8 ribbonId = ScriptReadByte(ctx);
GiveGiftRibbonToParty(index, ribbonId);
StringExpandPlaceholders(gStringVar4, gText_MysteryEventSpecialRibbon);
ctx->data[2] = 2;
ctx->mStatus = MEVENT_STATUS_SUCCESS;
return FALSE;
}
@ -269,8 +274,8 @@ bool8 MEScrCmd_initramscript(struct ScriptContext *ctx)
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
u8 objectId = ScriptReadByte(ctx);
u8 *script = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *scriptEnd = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *script = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
u8 *scriptEnd = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
InitRamScript(script, scriptEnd - script, mapGroup, mapNum, objectId);
return FALSE;
}
@ -279,7 +284,7 @@ bool8 MEScrCmd_givenationaldex(struct ScriptContext *ctx)
{
EnableNationalPokedex();
StringExpandPlaceholders(gStringVar4, gText_MysteryEventNationalDex);
ctx->data[2] = 2;
ctx->mStatus = MEVENT_STATUS_SUCCESS;
return FALSE;
}
@ -287,7 +292,7 @@ bool8 MEScrCmd_addrareword(struct ScriptContext *ctx)
{
UnlockAdditionalPhrase(ScriptReadByte(ctx));
StringExpandPlaceholders(gStringVar4, gText_MysteryEventRareWord);
ctx->data[2] = 2;
ctx->mStatus = MEVENT_STATUS_SUCCESS;
return FALSE;
}
@ -306,7 +311,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx)
struct Pokemon pokemon;
u16 species;
u16 heldItem;
u32 data = ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0];
u32 data = ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase;
void *pokemonPtr = (void *)data;
void *mailPtr = (void *)(data + sizeof(struct Pokemon));
@ -321,7 +326,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx)
if (gPlayerPartyCount == PARTY_SIZE)
{
StringExpandPlaceholders(gStringVar4, gText_MysteryEventFullParty);
ctx->data[2] = 3;
ctx->mStatus = MEVENT_STATUS_FAILURE;
}
else
{
@ -341,7 +346,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx)
CompactPartySlots();
CalculatePlayerPartyCount();
StringExpandPlaceholders(gStringVar4, gText_MysteryEventSentOver);
ctx->data[2] = 2;
ctx->mStatus = MEVENT_STATUS_SUCCESS;
}
return FALSE;
@ -349,11 +354,11 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx)
bool8 MEScrCmd_addtrainer(struct ScriptContext *ctx)
{
u32 data = ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0];
u32 data = ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase;
memcpy(&gSaveBlock2Ptr->frontier.ereaderTrainer, (void *)data, sizeof(gSaveBlock2Ptr->frontier.ereaderTrainer));
ValidateEReaderTrainer();
StringExpandPlaceholders(gStringVar4, gText_MysteryEventNewTrainer);
ctx->data[2] = 2;
ctx->mStatus = MEVENT_STATUS_SUCCESS;
return FALSE;
}
@ -361,19 +366,19 @@ bool8 MEScrCmd_enableresetrtc(struct ScriptContext *ctx)
{
EnableResetRTC();
StringExpandPlaceholders(gStringVar4, gText_InGameClockUsable);
ctx->data[2] = 2;
ctx->mStatus = MEVENT_STATUS_SUCCESS;
return FALSE;
}
bool8 MEScrCmd_checksum(struct ScriptContext *ctx)
{
int checksum = ScriptReadWord(ctx);
u8 *data = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *dataEnd = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *data = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
u8 *dataEnd = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
if (checksum != CalcByteArraySum(data, dataEnd - data))
{
ctx->data[3] = 0;
ctx->data[2] = 1;
ctx->mValid = FALSE;
ctx->mStatus = MEVENT_STATUS_LOAD_ERROR;
}
return TRUE;
}
@ -381,12 +386,12 @@ bool8 MEScrCmd_checksum(struct ScriptContext *ctx)
bool8 MEScrCmd_crc(struct ScriptContext *ctx)
{
int crc = ScriptReadWord(ctx);
u8 *data = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *dataEnd = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]);
u8 *data = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
u8 *dataEnd = (u8 *)(ScriptReadWord(ctx) - ctx->mOffset + ctx->mScriptBase);
if (crc != CalcCRC16(data, dataEnd - data))
{
ctx->data[3] = 0;
ctx->data[2] = 1;
ctx->mValid = FALSE;
ctx->mStatus = MEVENT_STATUS_LOAD_ERROR;
}
return TRUE;
}

View File

@ -286,7 +286,7 @@ bool8 ScrCmd_returnram(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_killscript(struct ScriptContext *ctx)
bool8 ScrCmd_endram(struct ScriptContext *ctx)
{
ClearRamScript();
StopScript(ctx);
@ -295,9 +295,9 @@ bool8 ScrCmd_killscript(struct ScriptContext *ctx)
bool8 ScrCmd_setmysteryeventstatus(struct ScriptContext *ctx)
{
u8 value = ScriptReadByte(ctx);
u8 status = ScriptReadByte(ctx);
SetMysteryEventScriptStatus(value);
SetMysteryEventScriptStatus(status);
return FALSE;
}
@ -309,7 +309,7 @@ bool8 ScrCmd_loadword(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx)
bool8 ScrCmd_loadbytefromptr(struct ScriptContext *ctx)
{
u8 index = ScriptReadByte(ctx);
@ -317,7 +317,7 @@ bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_writebytetoaddr(struct ScriptContext *ctx)
bool8 ScrCmd_setptr(struct ScriptContext *ctx)
{
u8 value = ScriptReadByte(ctx);
@ -405,7 +405,7 @@ bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx)
bool8 ScrCmd_compare_local_to_ptr(struct ScriptContext *ctx)
{
const u8 value1 = ctx->data[ScriptReadByte(ctx)];
const u8 value2 = *(const u8 *)ScriptReadWord(ctx);
@ -414,7 +414,7 @@ bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx)
bool8 ScrCmd_compare_ptr_to_local(struct ScriptContext *ctx)
{
const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = ctx->data[ScriptReadByte(ctx)];
@ -423,7 +423,7 @@ bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx)
bool8 ScrCmd_compare_ptr_to_value(struct ScriptContext *ctx)
{
const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = ScriptReadByte(ctx);
@ -432,7 +432,7 @@ bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx)
bool8 ScrCmd_compare_ptr_to_ptr(struct ScriptContext *ctx)
{
const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = *(const u8 *)ScriptReadWord(ctx);
@ -1653,7 +1653,7 @@ bool8 ScrCmd_bufferstring(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_vloadword(struct ScriptContext *ctx)
bool8 ScrCmd_vbuffermessage(struct ScriptContext *ctx)
{
const u8 *ptr = (u8 *)(ScriptReadWord(ctx) - sAddressOffset);
@ -2227,7 +2227,7 @@ bool8 ScrCmd_checkmoneventlegal(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_gotowondercardscript(struct ScriptContext *ctx)
bool8 ScrCmd_trywondercardscript(struct ScriptContext *ctx)
{
const u8* script = GetSavedRamScriptIfValid();
@ -2295,7 +2295,7 @@ void SetMovingNpcId(u16 npcId)
sMovingNpcId = npcId;
}
bool8 ScrCmd_warpsootopolislegend(struct ScriptContext *ctx)
bool8 ScrCmd_warpwhitefade(struct ScriptContext *ctx)
{
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
@ -2304,7 +2304,7 @@ bool8 ScrCmd_warpsootopolislegend(struct ScriptContext *ctx)
u16 y = VarGet(ScriptReadHalfword(ctx));
SetWarpDestination(mapGroup, mapNum, warpId, x, y);
DoSootopolisLegendWarp();
DoWhiteFadeWarp();
ResetInitialPlayerAvatarState();
return TRUE;
}