Partial refactor of TryWriteTrainerHill_r
This commit is contained in:
parent
cb0fa2fdc3
commit
a9918c3b89
5 changed files with 62 additions and 93 deletions
|
@ -3,14 +3,17 @@
|
|||
|
||||
#include "trainer_hill.h"
|
||||
|
||||
struct Unk81D38FC
|
||||
struct EReaderTrainerHillTrainer
|
||||
{
|
||||
u8 unk0;
|
||||
u8 filler_1[3];
|
||||
u8 unk4[0x148];
|
||||
u8 unk14C[0x124];
|
||||
struct TrainerHillTrainer unk4;
|
||||
u8 unk14C[0x100];
|
||||
u16 unk24C[16];
|
||||
u8 coords[2];
|
||||
u8 direction;
|
||||
u8 range;
|
||||
u32 checksum;
|
||||
};
|
||||
}; // size=0x274
|
||||
|
||||
struct EReaderTrainerHillSet
|
||||
{
|
||||
|
@ -18,26 +21,9 @@ struct EReaderTrainerHillSet
|
|||
u8 id;
|
||||
u16 dummy;
|
||||
u32 checksum;
|
||||
struct Unk81D38FC unk_8[6];
|
||||
struct EReaderTrainerHillTrainer unk_8[6];
|
||||
u8 unk_ec0[40];
|
||||
};
|
||||
|
||||
struct Unk81D3998Sub
|
||||
{
|
||||
u8 unk_000[4];
|
||||
u8 unk_004[0x148];
|
||||
u8 unk_14C[0x148];
|
||||
u8 unk_294[0x124];
|
||||
};
|
||||
|
||||
struct Unk81D3998
|
||||
{
|
||||
u8 unk_000;
|
||||
u8 unk_001;
|
||||
u8 unk_002;
|
||||
int checksum;
|
||||
struct Unk81D3998Sub unk_008[4];
|
||||
};
|
||||
}; // size = 0xf00
|
||||
|
||||
bool8 EReader_IsReceivedDataValid(struct EReaderTrainerHillSet *buffer);
|
||||
bool32 TryWriteTrainerHill(struct EReaderTrainerHillSet *arg0);
|
||||
|
|
|
@ -15,6 +15,39 @@ struct TrainerHillTrainer
|
|||
struct BattleTowerPokemon mons[PARTY_SIZE];
|
||||
};
|
||||
|
||||
struct TrHillRoomTrainers
|
||||
{
|
||||
u8 name[2][HILL_TRAINER_NAME_LENGTH];
|
||||
u8 facilityClass[2];
|
||||
};
|
||||
|
||||
struct TrHillFloor
|
||||
{
|
||||
u8 unk0;
|
||||
u8 unk1;
|
||||
struct TrainerHillTrainer trainers[2];
|
||||
u8 data[0x100];
|
||||
u16 unk3A0[16];
|
||||
u8 coords[2]; // x first 4 bits, y last 4 bits
|
||||
u8 direction; // array of 4 bits for each trainer
|
||||
u8 range; // array of 4 bits for each trainer
|
||||
};
|
||||
|
||||
struct TrHillTag
|
||||
{
|
||||
u8 unkField_0;
|
||||
u8 unused1;
|
||||
u8 unkField_2;
|
||||
u32 checksum;
|
||||
struct TrHillFloor floors[4];
|
||||
};
|
||||
|
||||
struct TrHillStruct2
|
||||
{
|
||||
u8 floorId;
|
||||
struct TrHillTag tag;
|
||||
};
|
||||
|
||||
extern u32 *gTrainerHillVBlankCounter;
|
||||
|
||||
void CallTrainerHillFunction(void);
|
||||
|
|
|
@ -5,10 +5,7 @@ static const struct TrHillTag sDataTagNormal =
|
|||
.unkField_0 = 8,
|
||||
.unused1 = 2,
|
||||
.unkField_2 = 4,
|
||||
.unused3 = 0,
|
||||
.unused4 = 5,
|
||||
.unused5 = 30,
|
||||
.unused6 = 5,
|
||||
.checksum = 0x00051E05,
|
||||
.floors =
|
||||
{
|
||||
[0] =
|
||||
|
@ -1218,10 +1215,7 @@ static const struct TrHillTag sDataTagVariety =
|
|||
.unkField_0 = 8,
|
||||
.unused1 = 1,
|
||||
.unkField_2 = 4,
|
||||
.unused3 = 0,
|
||||
.unused4 = 21,
|
||||
.unused5 = 76,
|
||||
.unused6 = 5,
|
||||
.checksum = 0x00054C15,
|
||||
.floors =
|
||||
{
|
||||
[0] =
|
||||
|
@ -2438,10 +2432,7 @@ static const struct TrHillTag sDataTagUnique =
|
|||
.unkField_0 = 8,
|
||||
.unused1 = 3,
|
||||
.unkField_2 = 4,
|
||||
.unused3 = 0,
|
||||
.unused4 = 243,
|
||||
.unused5 = 82,
|
||||
.unused6 = 6,
|
||||
.checksum = 0x000652F3,
|
||||
.floors =
|
||||
{
|
||||
[0] =
|
||||
|
@ -3643,10 +3634,7 @@ static const struct TrHillTag sDataTagExpert =
|
|||
.unkField_0 = 8,
|
||||
.unused1 = 1,
|
||||
.unkField_2 = 4,
|
||||
.unused3 = 0,
|
||||
.unused4 = 63,
|
||||
.unused5 = 31,
|
||||
.unused6 = 6,
|
||||
.checksum = 0x00061F3F,
|
||||
.floors =
|
||||
{
|
||||
[0] =
|
||||
|
|
|
@ -696,7 +696,7 @@ static u8 sub_81D38D4(void)
|
|||
return (gSaveBlock1Ptr->trainerHill.unused + 1) % 256;
|
||||
}
|
||||
|
||||
static bool32 Struct_Unk81D38FC_ValidateChecksum(struct Unk81D38FC *arg0)
|
||||
static bool32 Struct_EReaderTrainerHillTrainer_ValidateChecksum(struct EReaderTrainerHillTrainer *arg0)
|
||||
{
|
||||
int checksum = CalcByteArraySum((u8 *)arg0, 0x270);
|
||||
if (checksum != arg0->checksum)
|
||||
|
@ -715,11 +715,11 @@ bool8 EReader_IsReceivedDataValid(struct EReaderTrainerHillSet *buffer)
|
|||
|
||||
for (i = 0; i < var0; i++)
|
||||
{
|
||||
if (!Struct_Unk81D38FC_ValidateChecksum(&buffer->unk_8[i]))
|
||||
if (!Struct_EReaderTrainerHillTrainer_ValidateChecksum(&buffer->unk_8[i]))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
checksum = CalcByteArraySum((u8 *)buffer->unk_8, var0 * sizeof(struct Unk81D38FC));
|
||||
checksum = CalcByteArraySum((u8 *)buffer->unk_8, var0 * sizeof(struct EReaderTrainerHillTrainer));
|
||||
if (checksum != buffer->checksum)
|
||||
return FALSE;
|
||||
|
||||
|
@ -740,7 +740,7 @@ static bool32 TrainerHill_VerifyChecksum(struct EReaderTrainerHillSet *buffer)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static bool32 TryWriteTrainerHill_r(struct EReaderTrainerHillSet *ttdata, struct Unk81D3998 *buffer2)
|
||||
static bool32 TryWriteTrainerHill_r(struct EReaderTrainerHillSet *ttdata, struct TrHillTag *buffer2)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -748,33 +748,31 @@ static bool32 TryWriteTrainerHill_r(struct EReaderTrainerHillSet *ttdata, struct
|
|||
AGB_ASSERT_EX(ttdata->id == 0, "cereader_tool.c", 452);
|
||||
|
||||
memset(buffer2, 0, 0x1000);
|
||||
buffer2->unk_000 = ttdata->count;
|
||||
buffer2->unk_001 = sub_81D38D4();
|
||||
buffer2->unk_002 = (ttdata->count + 1) / 2;
|
||||
buffer2->unkField_0 = ttdata->count;
|
||||
buffer2->unused1 = sub_81D38D4();
|
||||
buffer2->unkField_2 = (ttdata->count + 1) / 2;
|
||||
|
||||
for (i = 0; i < ttdata->count; i++)
|
||||
{
|
||||
if (!(i & 1))
|
||||
{
|
||||
buffer2->unk_008[i / 2].unk_000[0] = ttdata->unk_8[i].unk0;
|
||||
memcpy(buffer2->unk_008[i / 2].unk_294, ttdata->unk_8[i].unk14C, 0x124);
|
||||
memcpy(buffer2->unk_008[i / 2].unk_004, ttdata->unk_8[i].unk4, 0x148);
|
||||
buffer2->floors[i / 2].unk0 = ttdata->unk_8[i].unk0;
|
||||
memcpy(buffer2->floors[i / 2].data, ttdata->unk_8[i].unk14C, 0x124);
|
||||
buffer2->floors[i / 2].trainers[0] = ttdata->unk_8[i].unk4;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer2->unk_008[i / 2].unk_000[1] = ttdata->unk_8[i].unk0;
|
||||
memcpy(buffer2->unk_008[i / 2].unk_14C, ttdata->unk_8[i].unk4, 0x148);
|
||||
buffer2->floors[i / 2].unk1 = ttdata->unk_8[i].unk0;
|
||||
buffer2->floors[i / 2].trainers[1] = ttdata->unk_8[i].unk4;
|
||||
}
|
||||
}
|
||||
|
||||
if (i & 1)
|
||||
{
|
||||
u8 * dest = buffer2->unk_008[i / 2].unk_14C;
|
||||
const struct TrainerHillTrainer * src = sTrainerHillTrainerTemplates_JP;
|
||||
memcpy(dest, &src[i / 2], 0x148);
|
||||
buffer2->floors[i / 2].trainers[1] = sTrainerHillTrainerTemplates_JP[i / 2];
|
||||
}
|
||||
|
||||
buffer2->checksum = CalcByteArraySum((u8 *)buffer2->unk_008, sizeof(struct Unk81D3998) - offsetof(struct Unk81D3998, unk_008));
|
||||
buffer2->checksum = CalcByteArraySum((u8 *)buffer2->floors, sizeof(buffer2->floors));
|
||||
if (TryWriteSpecialSaveSection(SECTOR_ID_TRAINER_HILL, (u8 *)buffer2) != 1)
|
||||
return FALSE;
|
||||
|
||||
|
@ -783,7 +781,7 @@ static bool32 TryWriteTrainerHill_r(struct EReaderTrainerHillSet *ttdata, struct
|
|||
|
||||
bool32 TryWriteTrainerHill(struct EReaderTrainerHillSet *arg0)
|
||||
{
|
||||
struct Unk81D3998 *var0 = AllocZeroed(0x1000);
|
||||
void *var0 = AllocZeroed(0x1000);
|
||||
bool32 result = TryWriteTrainerHill_r(arg0, var0);
|
||||
Free(var0);
|
||||
return result;
|
||||
|
|
|
@ -40,42 +40,6 @@
|
|||
|
||||
#define HILL_MAX_TIME 215999 // 60 * 60 * 60 - 1
|
||||
|
||||
struct TrHillRoomTrainers
|
||||
{
|
||||
u8 name[2][HILL_TRAINER_NAME_LENGTH];
|
||||
u8 facilityClass[2];
|
||||
};
|
||||
|
||||
struct TrHillFloor
|
||||
{
|
||||
u8 unk0;
|
||||
u8 unk1;
|
||||
struct TrainerHillTrainer trainers[2];
|
||||
u8 data[0x100];
|
||||
u16 unk3A0[16];
|
||||
u8 coords[2]; // x first 4 bits, y last 4 bits
|
||||
u8 direction; // array of 4 bits for each trainer
|
||||
u8 range; // array of 4 bits for each trainer
|
||||
};
|
||||
|
||||
struct TrHillTag
|
||||
{
|
||||
u8 unkField_0;
|
||||
u8 unused1;
|
||||
u8 unkField_2;
|
||||
u8 unused3;
|
||||
u8 unused4;
|
||||
u8 unused5;
|
||||
u8 unused6;
|
||||
struct TrHillFloor floors[4];
|
||||
};
|
||||
|
||||
struct TrHillStruct2
|
||||
{
|
||||
u8 floorId;
|
||||
struct TrHillTag tag;
|
||||
};
|
||||
|
||||
// EWRAM
|
||||
static EWRAM_DATA struct TrHillStruct2 *sHillData = NULL;
|
||||
static EWRAM_DATA struct TrHillRoomTrainers *sRoomTrainers = NULL;
|
||||
|
|
Loading…
Reference in a new issue