papermario/src/code_fa4c0_len_3bf0.c

407 lines
12 KiB
C
Raw Normal View History

2020-08-04 08:49:11 +02:00
#include "common.h"
INCLUDE_ASM(code_fa4c0_len_3bf0, func_802D5B10);
2020-08-16 08:55:51 +02:00
ApiStatus FadeOutMusic(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 itemID = get_variable(script, *ptrReadPos++);
s32* ptrNextPos = ptrReadPos++;
2020-08-04 08:49:11 +02:00
return (set_music_track(itemID, -1, 0, get_variable(script, *ptrNextPos++), 8) != 0) * 2;
}
2020-08-16 08:55:51 +02:00
ApiStatus SetMusicTrack(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 musicPlayer = get_variable(script, *ptrReadPos++);
s32 songID = get_variable(script, *ptrReadPos++);
s32 variation = get_variable(script, *ptrReadPos++);
2020-08-12 04:45:27 +02:00
s16 volume = get_variable(script, *ptrReadPos++);
2020-08-12 04:45:27 +02:00
return (set_music_track(musicPlayer, songID, variation, 0x1F4, volume) != 0) * 2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, FadeInMusic);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus PlayAmbientSounds(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 soundID = get_variable(script, *ptrReadPos++);
return (play_ambient_sounds(soundID, 0xFA) != 0) * 2;
}
2020-08-16 08:55:51 +02:00
ApiStatus PlaySound(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 soundID = get_variable(script, *ptrReadPos++);
2020-08-04 08:49:11 +02:00
play_sound(soundID);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D617C(ScriptInstance* script, s32 initialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 soundID = get_variable(script, *ptrReadPos++);
s32 value2 = get_variable(script, *ptrReadPos++);
_play_sound(soundID, value2 & 0xFF, 0, 0);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus PlaySoundAt(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 soundID = get_variable(script, *ptrReadPos++);
s32 value2 = get_variable(script, *ptrReadPos++);
s32 x = get_variable(script, *ptrReadPos++);
s32 y = get_variable(script, *ptrReadPos++);
s32 z = get_variable(script, *ptrReadPos++);
2020-08-12 04:29:31 +02:00
play_sound_at_position(soundID, value2, x, y, z);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus StopSound(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-04 08:49:11 +02:00
stop_sound(get_variable(script, *ptrReadPos++));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus func_802D62E4(ScriptInstance* script, s32 initialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-04 08:49:11 +02:00
func_80149A6C(get_variable(script, *ptrReadPos++), 1);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus UseDoorSounds(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-04 08:49:11 +02:00
gCurrentDoorSoundsSet = get_variable(script, *ptrReadPos++);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D6340(ScriptInstance* script, s32 initialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
D_80151308 = get_variable(script, *ptrReadPos++);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, PlaySoundAtF);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus RemoveKeyItemAt(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 index = get_variable(script, *ptrReadPos++);
2020-08-13 07:12:32 +02:00
s16* ptrKeyItems = (s16 *) &gPlayerData.keyItems;
2020-08-12 04:29:31 +02:00
2020-08-13 06:10:41 +02:00
ptrKeyItems[index] = 0;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus RemoveItemAt(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 index = get_variable(script, *ptrReadPos++);
2020-08-13 07:12:32 +02:00
s16* ptrInvItems = (s16 *) &gPlayerData.invItems;
2020-08-16 05:19:00 +02:00
2020-08-13 06:10:41 +02:00
ptrInvItems[index] = 0;
sort_items();
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AddKeyItem(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 value = *ptrReadPos++;
2020-08-16 05:19:00 +02:00
PlayerData* playerData = &gPlayerData;
s32 itemID = get_variable(script, value);
s32 i;
2020-08-16 06:24:20 +02:00
if (itemID == ItemId_FORTRESS_KEY) {
playerData->fortressKeyCount++;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-13 07:03:47 +02:00
for (i = 0; i < ARRAY_COUNT(playerData->keyItems); i++) {
if (playerData->keyItems[i] == 0) {
break;
}
}
2020-08-13 00:52:55 +02:00
if (i < ARRAY_COUNT(playerData->keyItems)) {
playerData->keyItems[i] = itemID;
}
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus func_802D6954(ScriptInstance* script, s32 isInitialCall) {
func_800E01A4();
disable_player_physics();
func_800EF600();
2020-08-13 00:52:55 +02:00
D_8009A650[0] &= ~0x40;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus HasKeyItem(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 itemID = get_variable(script, *ptrReadPos++);
s32 value = *ptrReadPos++;
2020-08-16 05:19:00 +02:00
PlayerData* playerData = &gPlayerData;
s32 i;
2020-08-16 05:19:00 +02:00
2020-08-13 07:03:47 +02:00
for(i = 0; i < ARRAY_COUNT(playerData->keyItems); i++) {
if (playerData->keyItems[i] == itemID) {
break;
}
}
set_variable(script, value, i < ARRAY_COUNT(playerData->keyItems));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus FindKeyItem(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 itemID = get_variable(script, *ptrReadPos++);
s32 value = *ptrReadPos++;
2020-08-16 05:19:00 +02:00
PlayerData* playerData = &gPlayerData;
s32 i;
s32 itemIndex;
2020-08-13 07:03:47 +02:00
for(i = 0; i < ARRAY_COUNT(playerData->keyItems); i++) {
if (playerData->keyItems[i] == itemID) {
break;
}
}
itemIndex = -1;
if (i != ARRAY_COUNT(playerData->keyItems)) {
itemIndex = i;
}
set_variable(script, value, itemIndex);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AddItem(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 itemID = get_variable(script, *ptrReadPos++);
2020-08-13 07:12:32 +02:00
s32* ptrNextPos = (s32 *) *ptrReadPos++;
set_variable(script, ptrNextPos, add_item(itemID));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D6AF0(ScriptInstance* script, s32 initialCall) {
set_variable(script, *script->ptrReadPos, 0);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus FindItem(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-14 03:43:04 +02:00
s32 itemID = get_variable(script, *ptrReadPos++);
s32 value = *ptrReadPos++;
2020-08-16 05:19:00 +02:00
PlayerData* playerData = &gPlayerData;
2020-08-14 03:43:04 +02:00
s32 i;
s32 itemIndex;
2020-08-04 08:49:11 +02:00
2020-08-14 03:43:04 +02:00
for (i = 0; i < ARRAY_COUNT(playerData->invItems); i++) {
if (playerData->invItems[i] == itemID) {
break;
}
}
2020-08-04 08:49:11 +02:00
2020-08-14 03:43:04 +02:00
itemIndex = -1;
if (i != ARRAY_COUNT(playerData->invItems)) {
itemIndex = i;
}
set_variable(script, value, itemIndex);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-14 03:43:04 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus RemoveItem(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 itemID = get_variable(script, *ptrReadPos++);
s32 value = *ptrReadPos++;
2020-08-16 05:19:00 +02:00
PlayerData* playerData = &gPlayerData;
s32 i;
s32 itemIndex;
2020-08-04 08:49:11 +02:00
for (i = 0; i < ARRAY_COUNT(playerData->invItems); i++) {
if (playerData->invItems[i] == itemID) {
break;
}
}
itemIndex = -1;
if (i != ARRAY_COUNT(playerData->invItems)) {
itemIndex = i;
}
if (itemIndex >= 0) {
// This is `playerData->invItems[i]`, but we have to do weird
// pointer math to get the output asm to exactly match :/
*(playerData->invItems + i) = 0;
}
sort_items();
set_variable(script, value, itemIndex);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus CountFortressKeys(ScriptInstance* script, s32 isInitialCall) {
s32 outVar = *script->ptrReadPos;
set_variable(script, outVar, get_fortress_key_count());
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus RemoveFortressKeys(ScriptInstance* script, s32 isInitialCall) {
2020-08-14 04:24:21 +02:00
s32 num = get_variable(script, *script->ptrReadPos);
subtract_fortress_keys(num);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-14 04:24:21 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, MakeItemEntity);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, DropItemEntity);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, DropItemEntityB);
2020-08-13 20:37:53 +02:00
/*
// Close to working
2020-08-16 08:55:51 +02:00
ApiStatus DropItemEntityB(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-13 20:37:53 +02:00
s32 itemID = get_variable(script, *ptrReadPos++);
s32 x = get_variable(script, *ptrReadPos++);
s32 y = get_variable(script, *ptrReadPos++);
s32 z = get_variable(script, *ptrReadPos++);
s32 itemSpawnMode = get_variable(script, *ptrReadPos++);
s32 pickupFlag = get_variable(script, *ptrReadPos++);
script->varTable[0] = make_item_entity_nodelay(itemID, x, y, z);
set_item_entity_flags(script, 0x4000);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-13 20:37:53 +02:00
}
*/
2020-08-16 08:55:51 +02:00
ApiStatus RemoveItemEntity(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-13 20:37:53 +02:00
s32 itemEntityIndex = get_variable(script, *ptrReadPos++);
2020-08-04 08:49:11 +02:00
2020-08-13 20:37:53 +02:00
remove_item_entity_by_index(itemEntityIndex);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-13 20:37:53 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AddBadge(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
s32 itemID = get_variable(script, *ptrReadPos++);
2020-08-13 07:12:32 +02:00
s32* ptrNextPos = (s32 *) *ptrReadPos++;
set_variable(script, ptrNextPos, add_badge(itemID));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, RemoveBadge);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus SetItemPos(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-16 05:19:00 +02:00
ItemEntity* ptrItemEntity;
s32 itemEntityIndex;
s32 x, y, z;
itemEntityIndex = get_variable(script, *ptrReadPos++);
x = get_variable(script, *ptrReadPos++);
y = get_variable(script, *ptrReadPos++);
z = get_variable(script, *ptrReadPos++);
2020-08-16 05:19:00 +02:00
ptrItemEntity = (ItemEntity *) get_item_entity(itemEntityIndex);
2020-08-15 06:27:01 +02:00
ptrItemEntity->position.x = x;
ptrItemEntity->position.y = y;
ptrItemEntity->position.z = z;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, SetItemFlags);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AddCoin(ScriptInstance* script, s32 isInitialCall) {
script->varTable[0] = add_coins(get_variable(script, *script->ptrReadPos));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AddStarPoints(ScriptInstance* script, s32 isInitialCall) {
script->varTable[0] = add_star_points(get_variable(script, *script->ptrReadPos));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AddStarPieces(ScriptInstance* script, s32 isInitialCall) {
script->varTable[0] = add_star_pieces(get_variable(script, *script->ptrReadPos));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, GetItemPower);
2020-08-13 06:10:41 +02:00
/*
2020-08-13 20:37:53 +02:00
// Close to working
2020-08-16 08:55:51 +02:00
ApiStatus GetItemPower(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-13 20:37:53 +02:00
s32 itemID = get_variable(script, *ptrReadPos++);
s32* ptrNextPos = ptrReadPos++;
item_table_entry* item = &gItemTable[itemID];
2020-08-16 05:19:00 +02:00
2020-08-13 20:37:53 +02:00
set_variable(script, ptrNextPos++, item->potencyA);
set_variable(script, ptrNextPos++, item->potencyB);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-13 06:10:41 +02:00
}
*/
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowGotItem);
2020-08-04 08:49:11 +02:00
INCLUDE_ASM(code_fa4c0_len_3bf0, func_802D7460);
INCLUDE_ASM(code_fa4c0_len_3bf0, func_802D74C0);
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowEmote);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, RemoveEffect);
/*
2020-08-13 20:37:53 +02:00
// Works
2020-08-16 08:55:51 +02:00
ApiStatus RemoveEffect(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
remove_effect(get_variable(script, *ptrReadPos++));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-13 20:37:53 +02:00
// Works
2020-08-16 08:55:51 +02:00
ApiStatus func_802D7B10(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-13 06:10:41 +02:00
s32* ptrValue = get_variable(script, *ptrReadPos++);
*ptrValue |= 0x10;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-13 20:37:53 +02:00
// Works
2020-08-16 08:55:51 +02:00
ApiStatus func_802D7B44(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-13 06:10:41 +02:00
s32* ptrValue = get_variable(script, *ptrReadPos++);
s32* ptrTemp = ptrValue[3];
ptrTemp[5] = 10;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-13 20:37:53 +02:00
// Works
2020-08-16 08:55:51 +02:00
ApiStatus func_802D7B74(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-13 06:10:41 +02:00
s32* ptrValue = get_variable(script, *ptrReadPos++);
s32* ptrTemp = ptrValue[3];
ptrTemp[11] = 5;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-13 06:10:41 +02:00
// More functions still in RemoveEffect.s but the ones above are matching properly
*/
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowSleepBubble);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
INCLUDE_API_ASM(code_fa4c0_len_3bf0, PlayEffect);