move const data to ground event

This commit is contained in:
DizzyEggg 2025-05-13 16:26:31 +02:00
parent 7588a11b17
commit fbccb7fc74
5 changed files with 7120 additions and 7188 deletions

File diff suppressed because it is too large Load Diff

6908
data/data_8115F5C_3.s Normal file

File diff suppressed because it is too large Load Diff

View File

@ -356,6 +356,7 @@ SECTIONS {
asm/ground_effect.o(.text);
src/ground_link.o(.text);
src/ground_event.o(.text);
src/unk_dungeon_load_maybe.o(.text);
src/m4a_1.o(.text);
src/m4a.o(.text);
*libagbsyscall.a:CpuSet.o(.text);
@ -695,6 +696,9 @@ SECTIONS {
data/data_8115F5C.o(.rodata);
src/code_809A560.o(.rodata);
data/data_8115F5C_2.o(.rodata);
src/ground_event.o(.rodata);
src/unk_dungeon_load_maybe.o(.rodata);
data/data_8115F5C_3.o(.rodata);
src/ground_event_data.o(.rodata);
data/friend_area_dialogue.o(.rodata);
src/ground_data_t00p01_station.o(.rodata);

View File

@ -1,4 +1,5 @@
#include "global.h"
#include "globaldata.h"
#include "ground_script.h"
#include "debug.h"
#include "memory.h"
@ -23,15 +24,11 @@ extern void GroundLives_CancelBlank_2(void);
void DeleteGroundEvents(void);
void GroundEvent_Delete(s32);
const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *);
const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *);
s32 GroundEvent_Add(s32 id, const GroundEventData*, s32 group, s32 sector);
extern DebugLocation gUnknown_81187DC;
extern u8 gGroundEventSelectText[];
extern u8 gGroundEventCancelText[];
extern u8 gGroundEventAddText[];
extern u8 gGroundEventDeleteText[];
void AllocGroundEvents(void) {
void AllocGroundEvents(void)
{
s32 ind;
GroundEvent *ptr;
gGroundEvents = MemoryAlloc(sizeof(GroundEvent) * 0x20, 0x6);
@ -43,7 +40,8 @@ void AllocGroundEvents(void) {
DeleteGroundEvents();
}
void DeleteGroundEvents(void) {
void DeleteGroundEvents(void)
{
s32 v1;
GroundEvent* current;
@ -61,6 +59,15 @@ void FreeGroundEvents(void)
gGroundEvents = NULL;
}
ALIGNED(4) static const char sFileName[] = "../ground/ground_event.c";
ALIGNED(4) static const char sFuncName[] = "GroundEvent_Select";
static const DebugLocation sGroundEvent_DebugLoc = {
.file = sFileName,
.line = 160, // Nice, the line here is 63...
.func = sFuncName,
};
void GroundEvent_Select(s32 scriptID, s32 group, s32 sector)
{
const struct GroundScriptHeader *scriptPtr;
@ -77,8 +84,8 @@ void GroundEvent_Select(s32 scriptID, s32 group, s32 sector)
scriptID_s32 = (s16)scriptID;
group_s32 = (s16)group;
sector_s32 = (s8)sector;
scriptPtr = GetGroundScript(scriptID_s32, &gUnknown_81187DC);
Log('\0',gGroundEventSelectText, scriptID_s32, group_s32, sector_s32);
scriptPtr = GetGroundScript(scriptID_s32, &sGroundEvent_DebugLoc);
Log('\0',"GroundEvent Select %3d %3d %3d", scriptID_s32, group_s32, sector_s32);
groupPtr = &scriptPtr->groups[group_s32];
sectorPtr = &groupPtr->sectors[sector_s32];
@ -101,8 +108,7 @@ void GroundEvent_Cancel(s32 scriptID, s32 sector)
scriptID_s32 = (s16)scriptID;
sector_s32 = (s8) sector;
Log('\0',gGroundEventCancelText, scriptID_s32, sector_s32);
Log('\0',"GroundEvent Cancel %3d %3d", scriptID_s32, sector_s32);
index = 0;
ptr = &gGroundEvents[0];
@ -171,7 +177,7 @@ s32 GroundEvent_Add(s32 id, const GroundEventData *eventData, s32 group, s32 sec
ptr = &gGroundEvents[scriptID_s32];
}
Log(0, gGroundEventAddText, scriptID_s32, script->id, group_s32, sector_s32, eventData->script->script);
Log(0, "GroundEvent Add id %3d kind %3d group %3d sector %3d script %p\0", scriptID_s32, script->id, group_s32, sector_s32, eventData->script->script);
ptr->unk0 = scriptID_s32;
ptr->unk2 = script->id;
@ -209,7 +215,7 @@ void GroundEvent_Delete(s32 id)
{
s32 scriptID_s32 = (s16) id;
GroundEvent *ptr = &gGroundEvents[scriptID_s32];
Log(0, gGroundEventDeleteText, scriptID_s32);
Log(0, "GroundEvent Delete id %3d\0", scriptID_s32);
ptr->unk2 = -1;
}
@ -272,197 +278,3 @@ UNUSED static s16 UnusedFindGroundEvent(u32 flags, s32 *arg1, s32 *arg2)
}
void nullsub_124(void) {}
// TODO: Check if file split here
#include "dungeon.h"
#include "decompress_at.h"
#include "def_filearchives.h"
#include "file_system.h"
#include "constants/dungeon.h"
extern bool8 IsWaterDungeon(u32 r0);
struct UnkDungeonFileData
{
s16 unk0;
s16 unk2;
s16 unk4;
s16 unk6[5];
};
struct UnkDataFileStruct
{
struct UnkDungeonFileData **unk0;
FloorProperties *unk4;
u16 **unk8;
UnkDungeonGlobal_unk1CD98 **unkC;
u16 **unk10;
};
s32 sub_80ADFB8(s32 a0, s32 a1, s32 a2, s32 a3, u16 *a4, s32 a5, u8 *a6, s32 a7);
extern const u8 gUnknown_8108EC0[];
extern const u8 gMapparamText[];
extern const u8 gUnknown_811889C[];
extern const u8 gUnknown_81188B4[];
extern const u8 gUnknown_81188A8[];
extern const u8 gUnknown_81188C0[];
extern const u8 gUnknown_81188CC[];
extern const u8 gUnknown_81188DC[];
void sub_80ADD9C(OpenedFile **a0, OpenedFile **a1, u32 *a2, u32 *a3, u16 *a4, DungeonLocation *a5, s32 a6, s32 a7, s32 a8, u16 *a9)
{
OpenedFile *file;
s32 r8;
s32 i, j;
u8 name[12];
DungeonLocation dungLoc;
u8 dungId;
s32 dungFloor;
struct UnkDungeonFileData *strPtr;
void *r10 = MemoryAlloc(0x930, 7);
OpenedFile *mapParamFile = OpenFileAndGetFileDataPtr(gMapparamText, &gDungeonFileArchive);
sub_80901D8(&dungLoc, a5);
dungId = dungLoc.id;
dungFloor = dungLoc.floor;
if (dungId > 62) {
dungId = 62;
}
if (dungFloor <= 0) {
dungFloor = 1;
}
if (dungFloor >= GetDungeonFloorCount(dungId)) {
dungFloor = GetDungeonFloorCount(dungId) - 1;
}
strPtr = &((struct UnkDataFileStruct *)(mapParamFile->data))->unk0[dungId][dungFloor];
r8 = ((struct UnkDataFileStruct *)(mapParamFile->data))->unk4[strPtr->unk0].unk2;
CloseFile(mapParamFile);
sprintf(name, gUnknown_811889C, gUnknown_8108EC0[r8]);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATGlobalFile(a2, 0, file);
CloseFile(file);
sprintf(name, gUnknown_81188A8, r8);
*a0 = OpenFile(name, &gDungeonFileArchive);
sprintf(name, gUnknown_81188B4, gUnknown_8108EC0[r8]);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATFile(a3, 0x1194, file);
CloseFile(file);
if (r8 < 64) {
sprintf(name, gUnknown_81188C0, gUnknown_8108EC0[r8]);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATFile(r10, 0x930, file);
CloseFile(file);
}
else {
sprintf(name, gUnknown_81188CC, r8, a6);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATFile(r10, 0x240, file);
CloseFile(file);
}
for (i = 0; i < a8; i++) {
s32 r7 = !IsWaterDungeon(r8) ? 0 : 3;
for (j = 0; j < a7; j++) {
a4[(i * a7) + j] = sub_80ADFB8(j, i, a7, a8, a9, r7, r10, r8);
}
}
sprintf(name, gUnknown_81188DC, r8);
*a1 = OpenFile(name, &gDungeonFileArchive);
MemoryFree(r10);
}
s32 sub_80ADF8C(s32 a0, s32 a1, s32 a2, s32 a3, u16 *a4, s32 a5)
{
s32 ret = a5;
if (a0 >= 0 && a1 >= 0 && a0 < a2 && a1 < a3) {
ret = a4[a0 + (a1 * a2)];
}
return ret;
}
s32 sub_80ADFB8(s32 a0, s32 a1, s32 a2, s32 a3, u16 *a4, s32 a5, u8 *a6, s32 a7)
{
s32 id;
s32 offsets[8];
u32 mask = 0;
s32 baseResult = sub_80ADF8C(a0, a1, a2, a3, a4, a5);
if (a7 >= 64) {
if (a0 < 24 && a1 < 24) {
id = a0 + (a1 * 24);
return a6[id];
}
else {
return a5;
}
}
offsets[0] = sub_80ADF8C(a0 + 0, a1 + 1, a2, a3, a4, a5);
offsets[1] = sub_80ADF8C(a0 + 1, a1 + 1, a2, a3, a4, a5);
offsets[2] = sub_80ADF8C(a0 + 1, a1 + 0, a2, a3, a4, a5);
offsets[3] = sub_80ADF8C(a0 + 1, a1 - 1, a2, a3, a4, a5);
offsets[4] = sub_80ADF8C(a0 + 0, a1 - 1, a2, a3, a4, a5);
offsets[5] = sub_80ADF8C(a0 - 1, a1 - 1, a2, a3, a4, a5);
offsets[6] = sub_80ADF8C(a0 - 1, a1 + 0, a2, a3, a4, a5);
offsets[7] = sub_80ADF8C(a0 - 1, a1 + 1, a2, a3, a4, a5);
if (baseResult == 1) {
mask = 0xFF;
if (offsets[0] == 0) mask &= ~0x01;
if (offsets[1] == 0) mask &= ~0x02;
if (offsets[2] == 0) mask &= ~0x04;
if (offsets[3] == 0) mask &= ~0x08;
if (offsets[4] == 0) mask &= ~0x10;
if (offsets[5] == 0) mask &= ~0x20;
if (offsets[6] == 0) mask &= ~0x40;
if (offsets[7] == 0) mask &= ~0x80;
mask |= 0x200;
}
else if (baseResult == 2) {
mask = 0xFF;
if (offsets[0] != 2) mask &= ~0x01;
if (offsets[1] != 2) mask &= ~0x02;
if (offsets[2] != 2) mask &= ~0x04;
if (offsets[3] != 2) mask &= ~0x08;
if (offsets[4] != 2) mask &= ~0x10;
if (offsets[5] != 2) mask &= ~0x20;
if (offsets[6] != 2) mask &= ~0x40;
if (offsets[7] != 2) mask &= ~0x80;
mask |= 0x100;
}
else if (baseResult == 3) {
mask = 0xFF;
if (offsets[0] != 3) mask &= ~0x01;
if (offsets[1] != 3) mask &= ~0x02;
if (offsets[2] != 3) mask &= ~0x04;
if (offsets[3] != 3) mask &= ~0x08;
if (offsets[4] != 3) mask &= ~0x10;
if (offsets[5] != 3) mask &= ~0x20;
if (offsets[6] != 3) mask &= ~0x40;
if (offsets[7] != 3) mask &= ~0x80;
mask |= 0x100;
}
else {
mask = 0;
if (offsets[0] == 0) mask |= 0x01;
if (offsets[1] == 0) mask |= 0x02;
if (offsets[2] == 0) mask |= 0x04;
if (offsets[3] == 0) mask |= 0x08;
if (offsets[4] == 0) mask |= 0x10;
if (offsets[5] == 0) mask |= 0x20;
if (offsets[6] == 0) mask |= 0x40;
if (offsets[7] == 0) mask |= 0x80;
}
id = mask * 3;
return a6[id];
}

View File

@ -0,0 +1,188 @@
#include "global.h"
#include "globaldata.h"
#include "memory.h"
#include "dungeon.h"
#include "decompress_at.h"
#include "def_filearchives.h"
#include "file_system.h"
#include "constants/dungeon.h"
extern bool8 IsWaterDungeon(u32 r0);
struct UnkDungeonFileData
{
s16 unk0;
s16 unk2;
s16 unk4;
s16 unk6[5];
};
struct UnkDataFileStruct
{
struct UnkDungeonFileData **unk0;
FloorProperties *unk4;
u16 **unk8;
UnkDungeonGlobal_unk1CD98 **unkC;
u16 **unk10;
};
extern const u8 gUnknown_8108EC0[];
static s32 sub_80ADFB8(s32 a0, s32 a1, s32 a2, s32 a3, u16 *a4, s32 a5, u8 *a6, s32 a7);
// This function is called when loading a transition between a dungeon and its summit, where the player can continue, save, or go back.
void sub_80ADD9C(OpenedFile **a0, OpenedFile **a1, u32 *a2, u32 *a3, u16 *a4, DungeonLocation *a5, s32 a6, s32 a7, s32 a8, u16 *a9)
{
OpenedFile *file;
s32 r8;
s32 i, j;
u8 name[12];
DungeonLocation dungLoc;
u8 dungId;
s32 dungFloor;
struct UnkDungeonFileData *strPtr;
void *r10 = MemoryAlloc(0x930, 7);
OpenedFile *mapParamFile = OpenFileAndGetFileDataPtr("mapparam", &gDungeonFileArchive);
sub_80901D8(&dungLoc, a5);
dungId = dungLoc.id;
dungFloor = dungLoc.floor;
if (dungId > 62) {
dungId = 62;
}
if (dungFloor <= 0) {
dungFloor = 1;
}
if (dungFloor >= GetDungeonFloorCount(dungId)) {
dungFloor = GetDungeonFloorCount(dungId) - 1;
}
strPtr = &((struct UnkDataFileStruct *)(mapParamFile->data))->unk0[dungId][dungFloor];
r8 = ((struct UnkDataFileStruct *)(mapParamFile->data))->unk4[strPtr->unk0].unk2;
CloseFile(mapParamFile);
sprintf(name, "b%02dfon", gUnknown_8108EC0[r8]);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATGlobalFile(a2, 0, file);
CloseFile(file);
sprintf(name, "b%02dpal", r8);
*a0 = OpenFile(name, &gDungeonFileArchive);
sprintf(name, "b%02dcel", gUnknown_8108EC0[r8]);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATFile(a3, 0x1194, file);
CloseFile(file);
if (r8 < 64) {
sprintf(name, "b%02dcex", gUnknown_8108EC0[r8]);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATFile(r10, 0x930, file);
CloseFile(file);
}
else {
sprintf(name, "b%02demap%01d", r8, a6);
file = OpenFileAndGetFileDataPtr(name, &gDungeonFileArchive);
DecompressATFile(r10, 0x240, file);
CloseFile(file);
}
for (i = 0; i < a8; i++) {
s32 r7 = !IsWaterDungeon(r8) ? 0 : 3;
for (j = 0; j < a7; j++) {
a4[(i * a7) + j] = sub_80ADFB8(j, i, a7, a8, a9, r7, r10, r8);
}
}
sprintf(name, "b%02dcanm", r8);
*a1 = OpenFile(name, &gDungeonFileArchive);
MemoryFree(r10);
}
static s32 sub_80ADF8C(s32 a0, s32 a1, s32 a2, s32 a3, u16 *a4, s32 a5)
{
s32 ret = a5;
if (a0 >= 0 && a1 >= 0 && a0 < a2 && a1 < a3) {
ret = a4[a0 + (a1 * a2)];
}
return ret;
}
static s32 sub_80ADFB8(s32 a0, s32 a1, s32 a2, s32 a3, u16 *a4, s32 a5, u8 *a6, s32 a7)
{
s32 id;
s32 offsets[8];
u32 mask = 0;
s32 baseResult = sub_80ADF8C(a0, a1, a2, a3, a4, a5);
if (a7 >= 64) {
if (a0 < 24 && a1 < 24) {
id = a0 + (a1 * 24);
return a6[id];
}
else {
return a5;
}
}
offsets[0] = sub_80ADF8C(a0 + 0, a1 + 1, a2, a3, a4, a5);
offsets[1] = sub_80ADF8C(a0 + 1, a1 + 1, a2, a3, a4, a5);
offsets[2] = sub_80ADF8C(a0 + 1, a1 + 0, a2, a3, a4, a5);
offsets[3] = sub_80ADF8C(a0 + 1, a1 - 1, a2, a3, a4, a5);
offsets[4] = sub_80ADF8C(a0 + 0, a1 - 1, a2, a3, a4, a5);
offsets[5] = sub_80ADF8C(a0 - 1, a1 - 1, a2, a3, a4, a5);
offsets[6] = sub_80ADF8C(a0 - 1, a1 + 0, a2, a3, a4, a5);
offsets[7] = sub_80ADF8C(a0 - 1, a1 + 1, a2, a3, a4, a5);
if (baseResult == 1) {
mask = 0xFF;
if (offsets[0] == 0) mask &= ~0x01;
if (offsets[1] == 0) mask &= ~0x02;
if (offsets[2] == 0) mask &= ~0x04;
if (offsets[3] == 0) mask &= ~0x08;
if (offsets[4] == 0) mask &= ~0x10;
if (offsets[5] == 0) mask &= ~0x20;
if (offsets[6] == 0) mask &= ~0x40;
if (offsets[7] == 0) mask &= ~0x80;
mask |= 0x200;
}
else if (baseResult == 2) {
mask = 0xFF;
if (offsets[0] != 2) mask &= ~0x01;
if (offsets[1] != 2) mask &= ~0x02;
if (offsets[2] != 2) mask &= ~0x04;
if (offsets[3] != 2) mask &= ~0x08;
if (offsets[4] != 2) mask &= ~0x10;
if (offsets[5] != 2) mask &= ~0x20;
if (offsets[6] != 2) mask &= ~0x40;
if (offsets[7] != 2) mask &= ~0x80;
mask |= 0x100;
}
else if (baseResult == 3) {
mask = 0xFF;
if (offsets[0] != 3) mask &= ~0x01;
if (offsets[1] != 3) mask &= ~0x02;
if (offsets[2] != 3) mask &= ~0x04;
if (offsets[3] != 3) mask &= ~0x08;
if (offsets[4] != 3) mask &= ~0x10;
if (offsets[5] != 3) mask &= ~0x20;
if (offsets[6] != 3) mask &= ~0x40;
if (offsets[7] != 3) mask &= ~0x80;
mask |= 0x100;
}
else {
mask = 0;
if (offsets[0] == 0) mask |= 0x01;
if (offsets[1] == 0) mask |= 0x02;
if (offsets[2] == 0) mask |= 0x04;
if (offsets[3] == 0) mask |= 0x08;
if (offsets[4] == 0) mask |= 0x10;
if (offsets[5] == 0) mask |= 0x20;
if (offsets[6] == 0) mask |= 0x40;
if (offsets[7] == 0) mask |= 0x80;
}
id = mask * 3;
return a6[id];
}