2017-11-12 22:59:36 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "battle.h"
|
|
|
|
#include "recorded_battle.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "pokemon.h"
|
|
|
|
#include "rng.h"
|
|
|
|
#include "event_data.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "string_util.h"
|
2017-11-13 00:10:34 +01:00
|
|
|
#include "palette.h"
|
2017-11-12 22:59:36 +01:00
|
|
|
|
|
|
|
#define BANK_RECORD_SIZE 664
|
|
|
|
|
|
|
|
extern u32 gBattleTypeFlags;
|
|
|
|
|
|
|
|
struct PlayerInfo
|
|
|
|
{
|
|
|
|
u32 trainerId;
|
|
|
|
u8 name[PLAYER_NAME_LENGTH];
|
|
|
|
u8 gender;
|
|
|
|
u16 field_E;
|
|
|
|
u16 language;
|
|
|
|
};
|
|
|
|
|
|
|
|
EWRAM_DATA u32 gRecordedBattleRngSeed = 0;
|
|
|
|
EWRAM_DATA u32 gBattlePalaceMoveSelectionRngValue = 0;
|
|
|
|
EWRAM_DATA u8 sBattleRecords[BATTLE_BANKS_COUNT][BANK_RECORD_SIZE] = {0};
|
|
|
|
EWRAM_DATA u16 sRecordedBytesNo[BATTLE_BANKS_COUNT] = {0};
|
|
|
|
EWRAM_DATA u16 gUnknown_0203C79C[4] = {0};
|
|
|
|
EWRAM_DATA u16 gUnknown_0203C7A4[4] = {0};
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7AC = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7AD = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7AE = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7AF = 0;
|
|
|
|
EWRAM_DATA MainCallback sRecordedBattle_Callback2 = NULL;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7B4 = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7B5 = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7B6 = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203C7B7 = 0;
|
|
|
|
EWRAM_DATA u32 sRecordedBattle_BattleFlags = 0;
|
|
|
|
EWRAM_DATA u32 sRecordedBattle_AI_Scripts = 0;
|
|
|
|
EWRAM_DATA struct Pokemon sSavedPlayerParty[PARTY_SIZE] = {0};
|
|
|
|
EWRAM_DATA struct Pokemon sSavedOpponentParty[PARTY_SIZE] = {0};
|
|
|
|
EWRAM_DATA u16 gUnknown_0203CC70[8] = {0};
|
|
|
|
EWRAM_DATA struct PlayerInfo sRecordedBattle_Players[BATTLE_BANKS_COUNT] = {0};
|
2017-11-13 00:10:34 +01:00
|
|
|
EWRAM_DATA u8 gUnknown_0203CCD0 = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203CCD1[8] = {0};
|
|
|
|
EWRAM_DATA u8 gUnknown_0203CCD9 = 0;
|
|
|
|
EWRAM_DATA u8 gUnknown_0203CCDA = 0;
|
|
|
|
EWRAM_DATA u16 gUnknown_0203CCDC[6] = {0};
|
|
|
|
EWRAM_DATA u8 gUnknown_0203CCE8 = 0;
|
2017-11-12 22:59:36 +01:00
|
|
|
|
|
|
|
extern u32 sub_81A513C(void);
|
|
|
|
|
2017-11-13 00:10:34 +01:00
|
|
|
// this file's functions
|
|
|
|
static u8 sub_8185278(u8 *arg0, u8 *arg1, u8 *arg2);
|
|
|
|
|
2017-11-12 22:59:36 +01:00
|
|
|
void sub_8184DA4(u8 arg0)
|
|
|
|
{
|
|
|
|
s32 i, j;
|
|
|
|
|
|
|
|
gUnknown_0203C7AC = arg0;
|
|
|
|
gUnknown_0203CCD0 = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < BATTLE_BANKS_COUNT; i++)
|
|
|
|
{
|
|
|
|
sRecordedBytesNo[i] = 0;
|
|
|
|
gUnknown_0203C79C[i] = 0;
|
|
|
|
gUnknown_0203C7A4[i] = 0;
|
|
|
|
|
|
|
|
if (arg0 == 1)
|
|
|
|
{
|
|
|
|
for (j = 0; j < BANK_RECORD_SIZE; j++)
|
|
|
|
{
|
|
|
|
sBattleRecords[i][j] |= 0xFF;
|
|
|
|
}
|
|
|
|
sRecordedBattle_BattleFlags = gBattleTypeFlags;
|
|
|
|
sRecordedBattle_AI_Scripts = gBattleResources->ai->aiFlags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8184E58(void)
|
|
|
|
{
|
|
|
|
s32 i, j;
|
|
|
|
|
|
|
|
if (gUnknown_0203C7AC == 1)
|
|
|
|
{
|
|
|
|
gRecordedBattleRngSeed = gRngValue;
|
|
|
|
gUnknown_0203C7AE = VarGet(VAR_FRONTIER_FACILITY);
|
|
|
|
gUnknown_0203C7AF = sub_81A513C();
|
|
|
|
}
|
|
|
|
else if (gUnknown_0203C7AC == 2)
|
|
|
|
{
|
|
|
|
gRngValue = gRecordedBattleRngSeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
|
|
|
|
{
|
|
|
|
u8 linkPlayersCount;
|
|
|
|
u8 text[30];
|
|
|
|
|
|
|
|
gUnknown_0203C7B4 = GetMultiplayerId();
|
|
|
|
linkPlayersCount = GetLinkPlayerCount();
|
|
|
|
|
|
|
|
for (i = 0; i < BATTLE_BANKS_COUNT; i++)
|
|
|
|
{
|
|
|
|
sRecordedBattle_Players[i].trainerId = gLinkPlayers[i].trainerId;
|
|
|
|
sRecordedBattle_Players[i].gender = gLinkPlayers[i].gender;
|
|
|
|
sRecordedBattle_Players[i].field_E = gLinkPlayers[i].lp_field_18;
|
|
|
|
sRecordedBattle_Players[i].language = gLinkPlayers[i].language;
|
|
|
|
|
|
|
|
if (i < linkPlayersCount)
|
|
|
|
{
|
|
|
|
StringCopy(text, gLinkPlayers[i].name);
|
|
|
|
StripExtCtrlCodes(text);
|
|
|
|
StringCopy(sRecordedBattle_Players[i].name, text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j = 0; j < PLAYER_NAME_LENGTH; j++)
|
|
|
|
sRecordedBattle_Players[i].name[j] = gLinkPlayers[i].name[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sRecordedBattle_Players[0].trainerId = (gSaveBlock2Ptr->playerTrainerId[0])
|
|
|
|
| (gSaveBlock2Ptr->playerTrainerId[1] << 8)
|
|
|
|
| (gSaveBlock2Ptr->playerTrainerId[2] << 16)
|
|
|
|
| (gSaveBlock2Ptr->playerTrainerId[3] << 24);
|
|
|
|
|
|
|
|
sRecordedBattle_Players[0].gender = gSaveBlock2Ptr->playerGender;
|
|
|
|
sRecordedBattle_Players[0].field_E = 0;
|
|
|
|
sRecordedBattle_Players[0].language = gGameLanguage;
|
|
|
|
|
|
|
|
for (i = 0; i < PLAYER_NAME_LENGTH; i++)
|
|
|
|
sRecordedBattle_Players[0].name[i] = gSaveBlock2Ptr->playerName[i];
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 00:10:34 +01:00
|
|
|
|
|
|
|
void RecordedBattle_SetBankAction(u8 bank, u8 action)
|
|
|
|
{
|
|
|
|
if (sRecordedBytesNo[bank] < BANK_RECORD_SIZE && gUnknown_0203C7AC != 2)
|
|
|
|
{
|
|
|
|
sBattleRecords[bank][sRecordedBytesNo[bank]++] = action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordedBattle_ClearBankAction(u8 bank, u8 bytesToClear)
|
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < bytesToClear; i++)
|
|
|
|
{
|
|
|
|
sRecordedBytesNo[bank]--;
|
|
|
|
sBattleRecords[bank][sRecordedBytesNo[bank]] |= 0xFF;
|
|
|
|
if (sRecordedBytesNo[bank] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 RecordedBattle_ReadBankAction(u8 bank)
|
|
|
|
{
|
|
|
|
// trying to read past array or invalid action byte, battle is over
|
|
|
|
if (sRecordedBytesNo[bank] >= BANK_RECORD_SIZE || sBattleRecords[bank][sRecordedBytesNo[bank]] == 0xFF)
|
|
|
|
{
|
|
|
|
gScriptResult = gBattleOutcome = BATTLE_PLAYER_TELEPORTED; // hah
|
|
|
|
ResetPaletteFadeControl();
|
|
|
|
BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
|
|
|
|
SetMainCallback2(CB2_QuitRecordedBattle);
|
|
|
|
return 0xFF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return sBattleRecords[bank][sRecordedBytesNo[bank]++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_81850D0(void)
|
|
|
|
{
|
|
|
|
return gUnknown_0203C7AC;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_81850DC(u8 *arg0)
|
|
|
|
{
|
|
|
|
u8 i, j;
|
|
|
|
u8 ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < BATTLE_BANKS_COUNT; i++)
|
|
|
|
{
|
|
|
|
if (sRecordedBytesNo[i] != gUnknown_0203C79C[i])
|
|
|
|
{
|
|
|
|
arg0[ret++] = i;
|
|
|
|
arg0[ret++] = sRecordedBytesNo[i] - gUnknown_0203C79C[i];
|
|
|
|
|
|
|
|
for (j = 0; j < sRecordedBytesNo[i] - gUnknown_0203C79C[i]; j++)
|
|
|
|
{
|
|
|
|
arg0[ret++] = sBattleRecords[i][gUnknown_0203C79C[i] + j];
|
|
|
|
}
|
|
|
|
|
|
|
|
gUnknown_0203C79C[i] = sRecordedBytesNo[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_81851A8(u8 *arg0)
|
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
u8 var1 = 2;
|
|
|
|
u8 var2;
|
|
|
|
|
|
|
|
if (!(gBattleTypeFlags & BATTLE_TYPE_LINK))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
|
|
|
{
|
|
|
|
if ((gLinkPlayers[i].version & 0xFF) != VERSION_EMERALD)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(gBattleTypeFlags & BATTLE_TYPE_WILD))
|
|
|
|
{
|
|
|
|
for (var2 = *arg0; var2 != 0;)
|
|
|
|
{
|
|
|
|
u8 unkVar = sub_8185278(arg0, &var1, &var2);
|
|
|
|
u8 unkVar2 = sub_8185278(arg0, &var1, &var2);
|
|
|
|
|
|
|
|
for (i = 0; i < unkVar2; i++)
|
|
|
|
{
|
|
|
|
sBattleRecords[unkVar][gUnknown_0203C7A4[unkVar]++] = sub_8185278(arg0, &var1, &var2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 sub_8185278(u8 *arg0, u8 *arg1, u8 *arg2)
|
|
|
|
{
|
|
|
|
(*arg2)--;
|
|
|
|
return arg0[(*arg1)++];
|
|
|
|
}
|