From 86ee26436157eaa52b4945acfa72c499bb673896 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 30 Jun 2025 21:10:11 +0200 Subject: [PATCH] ax position sets struct --- include/decompress_sir.h | 6 +- include/sprite.h | 10 +-- include/structs/axdata.h | 21 ++++-- src/code_8041AD0.c | 4 +- src/code_806CD90.c | 2 +- src/decompress_sir.c | 21 +++--- src/sprite.c | 139 +++++++++++++++++++-------------------- 7 files changed, 103 insertions(+), 100 deletions(-) diff --git a/include/decompress_sir.h b/include/decompress_sir.h index 7835d31af..01af39641 100644 --- a/include/decompress_sir.h +++ b/include/decompress_sir.h @@ -3,11 +3,13 @@ #include "file_system.h" -// size: 0x8 +// size: 0x10 typedef struct SiroArchive { - /* 0x0 */ u32 magic; + /* 0x0 */ u8 magic[4]; /* 0x4 */ const void *data; + /* 0x8 */ u32 unused1; // Always 0 + /* 0xC */ u32 unused2; // Always 0 } SiroArchive; const void *GetSiroPtr(OpenedFile *openedFile); diff --git a/include/sprite.h b/include/sprite.h index d8d81f121..1fdc62f48 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -24,12 +24,12 @@ typedef struct SpriteList typedef struct unkStruct_20266B0 { /* 0x0 */ s32 byteCount; - /* 0x4 */ void *src; + /* 0x4 */ const void *src; /* 0x8 */ void *dest; } unkStruct_20266B0; -void AddAxSprite(ax_pose *, axdata1 *, UnkSpriteMem *, unkStruct_2039DB0 *spriteMasks); -void AddSprite(SpriteOAM *, s32, UnkSpriteMem *, unkStruct_2039DB0 *spriteMasks); +void AddAxSprite(ax_pose *, axdata1 *, ax_sprite *, unkStruct_2039DB0 *spriteMasks); +void AddSprite(SpriteOAM *, s32, ax_sprite *, unkStruct_2039DB0 *spriteMasks); void AxResInit(axdata *, axmain *, u32, u32 direction, u32, u32 spriteAnimIndex, bool8); void AxResInitFile(axdata *, OpenedFile *, u32, u32, u32, u32 spriteAnimIndex, bool8); void AxResInitUnorientedFile(axdata *, OpenedFile *, u32, u32, u32 spriteAnimIndex, bool8); @@ -41,7 +41,7 @@ void nullsub_7(DungeonPos *); void nullsub_8(u32); void nullsub_9(void); void nullsub_10(bool8); -void nullsub_11(SpriteOAM *, s32, UnkSpriteMem *, unkStruct_2039DB0 *); +void nullsub_11(SpriteOAM *, s32, ax_sprite *, unkStruct_2039DB0 *); void nullsub_12(void); void nullsub_13(void); void nullsub_14(void); @@ -54,7 +54,7 @@ void sub_8005304(void); void sub_8005610(OpenedFile *, s32 vramIdx, s32 brightness, const RGB *ramp); const RGB *sub_8005674(const EfoFileData *, s32 vramIdx); void sub_800569C(DungeonPos *, axdata *, u8); -void sub_8005700(DungeonPos *, axObject *); +void sub_8005700(DungeonPos *dstPos, axdata *axData); void sub_8005770(s32, const RGB *color, s32 brightness, const RGB *ramp); #endif // GUARD_SPRITE_H diff --git a/include/structs/axdata.h b/include/structs/axdata.h index 78a571e64..240cdc2a9 100644 --- a/include/structs/axdata.h +++ b/include/structs/axdata.h @@ -6,11 +6,11 @@ #include "structs/str_position.h" // size: 0x8 -typedef struct UnkSpriteMem +typedef struct ax_sprite { - /* 0x0 */ void *src; + /* 0x0 */ const void *gfx; /* 0x4 */ s32 byteCount; -} UnkSpriteMem; +} ax_sprite; // size: 0x20 typedef struct axdata1 @@ -55,6 +55,13 @@ typedef struct ax_anim /* 0x8 */ DungeonPos shadow; } ax_anim; +#define AX_POSITION_SETS_COUNT 4 + +struct PositionSets +{ + DungeonPos set[AX_POSITION_SETS_COUNT]; +}; + // size: 0x3C typedef struct axdata { @@ -65,9 +72,9 @@ typedef struct axdata /* 0x8 */ axdata1 sub1; /* 0x28 */ ax_anim *nextAnimData; // next animation data (if flags&0x1000) /* 0x2C */ ax_anim *activeAnimData; // current animation data - /* 0x30 */ DungeonPos *positions; + /* 0x30 */ struct PositionSets *positions; /* 0x34 */ ax_pose **poseData; - /* 0x38 */ UnkSpriteMem **spriteData; + /* 0x38 */ ax_sprite **spriteData; } axdata; // size: 0x14 @@ -76,8 +83,8 @@ typedef struct axmain /* 0x0 */ ax_pose **poses; /* 0x4 */ ax_anim ***animations; /* 0x8 */ u32 animCount; - /* 0xC */ UnkSpriteMem **spriteData; - /* 0x10 */ DungeonPos *positions; + /* 0xC */ ax_sprite **spriteData; + /* 0x10 */ struct PositionSets *positions; } axmain; // size: 0x4C diff --git a/src/code_8041AD0.c b/src/code_8041AD0.c index 923f75765..2ffd0ba60 100644 --- a/src/code_8041AD0.c +++ b/src/code_8041AD0.c @@ -1174,7 +1174,7 @@ void sub_8042390(Entity *entity, Item *item) local_14.y = (entity->pixelPos).y / 256; sVar1 = (local_14.y - gDungeon->unk181e8.cameraPixelPos.y) / 2 + 1; - sub_8005700(asStack_24,&entity->axObj); + sub_8005700(asStack_24,&entity->axObj.axdata); uVar6 = sub_800E49C(id,&local_14,asStack_24,0,sVar1); for (counter = 0; counter < 1000; counter++) { DungeonRunFrameActions(0x42); @@ -1202,7 +1202,7 @@ void sub_804245C(Entity *entity, Item *item) local_14.y = (entity->pixelPos).y / 256; sVar1 = (local_14.y - gDungeon->unk181e8.cameraPixelPos.y) / 2 + 1; - sub_8005700(asStack_24,&entity->axObj); + sub_8005700(asStack_24,&entity->axObj.axdata); uVar6 = sub_800E49C(id,&local_14,asStack_24,1,sVar1); for (counter = 0; counter < 1000; counter++) { DungeonRunFrameActions(0x42); diff --git a/src/code_806CD90.c b/src/code_806CD90.c index cb06ed751..6ca00297d 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -222,7 +222,7 @@ void sub_806C51C(Entity *entity) pos1.x = entity->pixelPos.x / 256; pos1.y = ((entity->pixelPos.y - entity->unk1C.raw) - entInfo->unk174.raw) / 256; - sub_8005700(posArray, &entity->axObj); + sub_8005700(posArray, &entity->axObj.axdata); UpdateDungeonPokemonSprite2(entInfo->dungeonSpriteId, &pos1, posArray, gDungeon->unk181e8.priority); statusSprites = EntityGetStatusSprites(entity); diff --git a/src/decompress_sir.c b/src/decompress_sir.c index f0ac4ef33..2d36b2fac 100644 --- a/src/decompress_sir.c +++ b/src/decompress_sir.c @@ -1,9 +1,6 @@ #include "global.h" #include "decompress_sir.h" -#define MAGIC_SIR0 0x30524953 -#define MAGIC_SIRO 0x4F524953 - static void NDS_DecompressRLE(const SiroArchive *); // arm9.bin::020093F4 @@ -11,20 +8,24 @@ const void *GetSiroPtr(OpenedFile *openedFile) { const SiroArchive *siro = (const SiroArchive *)openedFile->data; - if (siro->magic == MAGIC_SIR0) + if (siro->magic[0] == 'S' && siro->magic[1] == 'I' && siro->magic[2] == 'R' && siro->magic[3] == '0') { NDS_DecompressRLE(openedFile->data); - else if (siro->magic != MAGIC_SIRO) + openedFile->data = siro->data; return openedFile->data; - - openedFile->data = siro->data; - - return openedFile->data; + } + else if (siro->magic[0] == 'S' && siro->magic[1] == 'I' && siro->magic[2] == 'R' && siro->magic[3] == 'O') { + openedFile->data = siro->data; + return openedFile->data; + } + else { + return openedFile->data; + } } // arm9.bin::020093A0 UNUSED static const void *UnusedGetSir0Ptr(const SiroArchive *siro) { - if (siro->magic != MAGIC_SIR0) + if (siro->magic[0] != 'S' || siro->magic[1] != 'I' || siro->magic[2] != 'R' || siro->magic[3] != '0') return siro; NDS_DecompressRLE(siro); diff --git a/src/sprite.c b/src/sprite.c index 2122c591b..ed5c341cb 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -27,8 +27,8 @@ UNUSED EWRAM_DATA static u32 sUnused3 = {0}; // R=2026E34 EWRAM_INIT static unkStruct_20266B0 *sUnknown_203B074 = {0}; static void AxResInitUnoriented(axdata *, axmain *, u32, u32, u32, bool8); -static void RegisterSpriteParts_80052BC(UnkSpriteMem *); -static void sub_800533C(ax_pose **, UnkSpriteMem **, axdata1 *, unkStruct_2039DB0 *spriteMasks, bool8); +static void RegisterSpriteParts_80052BC(ax_sprite *); +static void sub_800533C(ax_pose **, ax_sprite **, axdata1 *, unkStruct_2039DB0 *spriteMasks, bool8); static void sub_800561C(const EfoFileData *, s32 vramIdx, s32 brightness, const RGB *ramp); // arm9.bin::0200265C @@ -177,36 +177,36 @@ void sub_8004E8C(unkStruct_2039DB0 *a0) } // arm9.bin::020021C4 -void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 *spriteMasks) +void AddAxSprite(ax_pose *axPose, axdata1 *axData, ax_sprite *axSprite, unkStruct_2039DB0 *spriteMasks) { // size: 0xC - struct UnkStackFor8004EA8 + struct AxOAMPose { - s16 unk0; + s16 spriteId; ax_pose_unk2 unk2; SpriteOAM oam; - } sp; + } axOamPose; SpriteOAM *sprite; s32 spriteId; s32 pos; // Has to be used for both x and y to match - struct UnkStackFor8004EA8 *spPtr; + struct AxOAMPose *axOamPosePtr; - if (a2 != NULL) - RegisterSpriteParts_80052BC(a2); + if (axSprite != NULL) + RegisterSpriteParts_80052BC(axSprite); if (sSpriteCount >= 128) return; - spPtr = &sp; - spPtr->unk0 = a0->sprite; - spPtr->unk2 = a0->unk2; + axOamPosePtr = &axOamPose; + axOamPosePtr->spriteId = axPose->sprite; + axOamPosePtr->unk2 = axPose->unk2; - spPtr->oam.attrib1 = a0->flags1 & ~((1 << SPRITEOAM_SHIFT_AFFINEMODE1) | (1 << SPRITEOAM_SHIFT_AFFINEMODE2)); - spPtr->oam.attrib2 = a0->flags2 & ~(0x200 | 0x400 | 0x800); - spPtr->oam.attrib3 = a0->flags3; - spPtr->oam.unk6 = ((a0->flags2 & (0x200 | 0x400 | 0x800)) >> 9) | ((a0->flags1 & (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x80 | 0x100 | 0x200)) << 4); + axOamPosePtr->oam.attrib1 = axPose->flags1 & ~((1 << SPRITEOAM_SHIFT_AFFINEMODE1) | (1 << SPRITEOAM_SHIFT_AFFINEMODE2)); + axOamPosePtr->oam.attrib2 = axPose->flags2 & ~(0x200 | 0x400 | 0x800); + axOamPosePtr->oam.attrib3 = axPose->flags3; + axOamPosePtr->oam.unk6 = ((axPose->flags2 & (0x200 | 0x400 | 0x800)) >> 9) | ((axPose->flags1 & (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40 | 0x80 | 0x100 | 0x200)) << 4); sprite = &sUnknown_20262A8[sSpriteCount]; - spriteId = a1->unk16 + sp.unk2.unk1; + spriteId = axData->unk16 + axOamPose.unk2.unk1; if (spriteId < 0) spriteId = 0; @@ -214,23 +214,23 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 * spriteId = 255; if (spriteMasks == NULL) { - SpriteCopy(sprite, &spPtr->oam); + SpriteCopy(sprite, &axOamPosePtr->oam); } else { - SpriteCopyWithMasks(sprite, &spPtr->oam, spriteMasks); + SpriteCopyWithMasks(sprite, &axOamPosePtr->oam, spriteMasks); } // Set tileNum - if (sp.unk2.unk0 != 0 && sUnknown_2025672[sp.unk2.unk0] != 0) { - SpriteSetTileNum(sprite, sUnknown_2025672[sp.unk2.unk0]); + if (axOamPose.unk2.unk0 != 0 && sUnknown_2025672[axOamPose.unk2.unk0] != 0) { + SpriteSetTileNum(sprite, sUnknown_2025672[axOamPose.unk2.unk0]); } else { // Animations add to existing tileNum - SpriteAddTileNum(sprite, a1->vramTileOrMaybeAnimTimer); + SpriteAddTileNum(sprite, axData->vramTileOrMaybeAnimTimer); } pos = SpriteGetX(sprite); - pos += a1->pos.x - 0x100; + pos += axData->pos.x - 0x100; if (pos < -64) return; @@ -240,7 +240,7 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 * SpriteSetX(sprite, pos); pos = SpriteGetY(sprite); - pos += a1->pos.y - 0x200; + pos += axData->pos.y - 0x200; if (pos < -64) return; if (pos >= DISPLAY_HEIGHT) @@ -250,11 +250,11 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 * // Set paletteNum if (!SpriteGetUnk6_1(sprite)) { - SpriteSetPalNum(sprite, a1->paletteNum); + SpriteSetPalNum(sprite, axData->paletteNum); } - if (sp.unk2.unk0 != 0) { - SpriteSetPalNum(sprite, sUnknown_2025682[sp.unk2.unk0]); + if (axOamPose.unk2.unk0 != 0) { + SpriteSetPalNum(sprite, sUnknown_2025682[axOamPose.unk2.unk0]); } sUnknown_2025EA8[sSpriteCount].unk0 = sSpriteList.sprites[spriteId].unk0; @@ -264,7 +264,7 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 * // a2 and spriteMasks are always called with NULL lol // arm9.bin::02002088 -void AddSprite(SpriteOAM *a0, s32 a1, UnkSpriteMem *a2, unkStruct_2039DB0 *spriteMasks) +void AddSprite(SpriteOAM *a0, s32 a1, ax_sprite *a2, unkStruct_2039DB0 *spriteMasks) { s32 yPos; SpriteOAM *spr; @@ -430,17 +430,17 @@ void BlinkSavingIcon(void) } // arm9.bin::02001E70 -static void RegisterSpriteParts_80052BC(UnkSpriteMem *a0) +static void RegisterSpriteParts_80052BC(ax_sprite *spritesPtr) { - while (a0->byteCount != 0) { - if ((uintptr_t)sUnknown_203B074 >= (uintptr_t)&sUnknown_20266B0[UNK_20266B0_ARR_COUNT]) + while (spritesPtr->byteCount != 0) { + if (sUnknown_203B074 >= &sUnknown_20266B0[UNK_20266B0_ARR_COUNT]) return; - sUnknown_203B074->byteCount = a0->byteCount; - sUnknown_203B074->src = a0->src; + sUnknown_203B074->byteCount = spritesPtr->byteCount; + sUnknown_203B074->src = spritesPtr->gfx; sUnknown_203B074->dest = sCharMemCursor; - sCharMemCursor += a0->byteCount; + sCharMemCursor += spritesPtr->byteCount; sUnknown_203B074++; - a0++; + spritesPtr++; } } @@ -458,9 +458,9 @@ void sub_8005304(void) } // arm9.bin::02001D88 -static void sub_800533C(ax_pose **a0, UnkSpriteMem **a1, axdata1 *a2, unkStruct_2039DB0 *spriteMasks, bool8 a4) +static void sub_800533C(ax_pose **a0, ax_sprite **a1, axdata1 *a2, unkStruct_2039DB0 *spriteMasks, bool8 a4) { - UnkSpriteMem *mem; + ax_sprite *mem; ax_pose *r4; r4 = a0[a2->poseId]; @@ -648,65 +648,58 @@ const RGB *sub_8005674(const EfoFileData *a0, s32 vramIdx) } // arm9.bin::02001894 -void sub_800569C(DungeonPos *a0, axdata *a1, u8 a2) +void sub_800569C(DungeonPos *dstPos, axdata *axData, u8 setId) { - DungeonPos *ptr; - DungeonPos *ptr2; - DungeonPos *ptr3; + dstPos->x = 0; + dstPos->y = 0; - a0->x = 0; - a0->y = 0; - - if (!(a1->flags >> 15) || a2 >= 4) + if (!(axData->flags >> 15) || setId >= AX_POSITION_SETS_COUNT) return; - if (a1->positions != NULL) { - ptr = &((DungeonPos*)a1->positions)[a1->sub1.poseId * 4]; - ptr2 = &ptr[a2]; - if (*&ptr2->x == 99 && *&ptr2->y == 99) { - a0->x = 99; - a0->y = 99; + if (axData->positions != NULL) { + struct PositionSets *ptr = &axData->positions[axData->sub1.poseId]; + if (ptr->set[setId].x == 99 && ptr->set[setId].y == 99) { + dstPos->x = 99; + dstPos->y = 99; } else { - ptr3 = &ptr[a2]; - a0->x = a1->sub1.offset.x + ptr3->x; - a0->y = a1->sub1.offset.y + ptr3->y; + dstPos->x = axData->sub1.offset.x + ptr->set[setId].x; + dstPos->y = axData->sub1.offset.y + ptr->set[setId].y; } } else { - a0->x = 99; - a0->y = 99; + dstPos->x = 99; + dstPos->y = 99; } } // arm9.bin::020017D4 -void sub_8005700(DungeonPos *a0, axObject *a1) +void sub_8005700(DungeonPos *dstPos, axdata *axData) { s32 i; - DungeonPos *ptr; - if (!(a1->axdata.flags >> 15)) + if (!(axData->flags >> 15)) return; - if (a1->axdata.positions != NULL) { - ptr = &((DungeonPos*)a1->axdata.positions)[a1->axdata.sub1.poseId * 4]; - for (i = 0; i < 4; i++) { - if (*&ptr[i].x == 99 && *&ptr[i].y == 99) { - a0->x = 99; - a0->y = 99; + if (axData->positions != NULL) { + struct PositionSets *ptr = &axData->positions[axData->sub1.poseId]; + for (i = 0; i < AX_POSITION_SETS_COUNT; i++) { + if (ptr->set[i].x == 99 && ptr->set[i].y == 99) { + dstPos->x = 99; + dstPos->y = 99; } else { - a0->x = a1->axdata.sub1.offset.x + ptr[i].x; - a0->y = a1->axdata.sub1.offset.y + ptr[i].y; + dstPos->x = axData->sub1.offset.x + ptr->set[i].x; + dstPos->y = axData->sub1.offset.y + ptr->set[i].y; } - a0++; + dstPos++; } } else { - for (i = 0; i < 4; i++) { - a0->x = 99; - a0->y = 99; - a0++; + for (i = 0; i < AX_POSITION_SETS_COUNT; i++) { + dstPos->x = 99; + dstPos->y = 99; + dstPos++; } } } @@ -753,7 +746,7 @@ UNUSED static void nullsub_144(void) { } -void nullsub_11(SpriteOAM *a0, s32 a1, UnkSpriteMem *a2, unkStruct_2039DB0 *a3) +void nullsub_11(SpriteOAM *a0, s32 a1, ax_sprite *a2, unkStruct_2039DB0 *a3) { }