Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpack resdat and cldat files, create C headers for offsets into palette resdats #279

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

joshua-smith-12
Copy link
Contributor

@joshua-smith-12 joshua-smith-12 commented Oct 25, 2024

Uncovered how the resdat files and palette offsets were being used while I was working on #269 so figured I would unpack the files + add a build step while it was fresh in the brain

shoutout to the txt files such as res/data/tmapn_celact.txt which were probably left in the filesystem by mistake and contain a direct explanation for the binary format for resdat/cldat files, lol

I'll probably extend this to do a bit more documentation in the files I've already modified, specifically around unk_0200C6E4.c. I need to check if the other gen4 projects already did work in this area (I think pokeheartgold does have a bunch of this file documented already)

@joshua-smith-12 joshua-smith-12 marked this pull request as draft October 25, 2024 19:08
Comment on lines 5 to 6
"narc": 20,
"member": 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to reference the NARC and member by name here and have the build step convert them into IDs on the fly, but need to figure out where the data mapping NARCs and members to indices would be available at this point in the build

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could move them from the C constants in include/constants/narc.h to be a generated multi-lang constant in consts/. Then, you'd have access to these in the Python script that builds the NARCs.

Copy link
Collaborator

@lhearachel lhearachel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any documentation on what these files actually represent? Are they just packs of resources that should always be loaded together?

@@ -430,7 +431,7 @@ void sub_0208F16C(PokemonSummaryApp *param0)
static void sub_0208F194(PokemonSummaryApp *param0, u8 param1, u8 param2, u8 param3)
{
sub_0200D948(param0->renderer, param0->gfxHandler, sub_0207C944(), sub_0207C908(param3), 1, param2);
sub_0200D414(param0->unk_41C[param1], sub_0207C92C(param3) + 3);
sub_0200D414(param0->unk_41C[param1], sub_0207C92C(param3) + RESDAT_PST_PAL_NARC_27_MEMBER_74_1_OFFSET);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an naix value?

@lhearachel lhearachel marked this pull request as ready for review October 26, 2024 03:07
@joshua-smith-12
Copy link
Contributor Author

Is there any documentation on what these files actually represent? Are they just packs of resources that should always be loaded together?

yes! if I understand it right,

  • each resdat file contains a list of resources of 1 type (e.g. cells, tiles, anims, palettes) which are all loaded as SpriteResource types into a SpriteResourceCollection
  • each cldat file contains a list of indices into these collections which can be used to construct a CellActorResourceData type which contains data for each resource type (NNSG2dImageProxy, NNSG2dCellAnimBankData, etc)

so all of these resdat files get loaded together, and then the cldat file constructs what is essentially templates of CellActorResourceData from the data in the resdats which can be used for constructing a CellActor

Copy link
Collaborator

@lhearachel lhearachel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some cursory questions and basic polish comments.

Comment on lines +49 to +62
typedef struct CellActorPropsTemplate {
int resourceIndex;
s16 x;
s16 y;
s16 z;
u16 anim;
int priority;
int palette;
int vramType;
int unk_18;
int unk_1C;
int unk_20;
int unk_24;
} CellActorPropsTemplate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: How does this differ from the existing SpriteTemplate?

Comment on lines +1 to +2
#ifndef POKEPLATINUM_UNK_0200C6E4_H
#define POKEPLATINUM_UNK_0200C6E4_H
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Modify the include guards (and the comment at the end of this file).

@@ -68,3 +68,4 @@ subdir('items')
subdir('pokemon')
subdir('sound')
subdir('trainers')
subdir('data')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Keep this list sorted in lexicographical order, unless a specific processing order is needed.

@@ -7,8 +7,7 @@

#include "applications/pokemon_summary_screen/main.h"
#include "applications/pokemon_summary_screen/subscreen.h"
#include "overlay007/struct_ov7_0224F2EC.h"
#include "overlay007/struct_ov7_0224F358.h"
#include "data/pst_pal.naix"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: #include "res/data/pst_pal.naix" will sort this to the bottom of the includes, which I think is preferable.


BOOL SpriteRenderer_CreateCellActorList(SpriteRenderer *renderer, SpriteGfxHandler *gfxHandler, int numCells)
{
if ((renderer == NULL) || (gfxHandler == NULL)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Unnecessary parens.

Comment on lines +81 to +90
{
UnkStruct_ov22_022559F8 v0;

v0.unk_00 = param2->unk_00;
v0.unk_04 = param2->unk_04;
v0.unk_08 = param2->unk_08;
v0.unk_0C = renderer->heapID;

sub_0201E88C(&v0, param2->unk_0C, param2->unk_10);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: I'll leave it up to you if you want to break down this unnecessary scope-block or not; since the inner struct here is undocumented, I can let it slide.

Comment on lines +677 to +721
static BOOL sub_0200D27C(SpriteResourceCollection *resourceCollection, SpriteResourceList *resourceList, int resourceID)
{
for (int i = 0; i < resourceList->capacity; i++) {
if (resourceList->resources[i] == NULL) {
continue;
}

int spriteResourceID = SpriteResource_GetID(resourceList->resources[i]);

if (spriteResourceID == resourceID) {
sub_0201EB50(resourceID);
SpriteResourceCollection_Remove(resourceCollection, resourceList->resources[i]);

resourceList->resources[i] = NULL;
resourceList->count--;

return TRUE;
}
}

return FALSE;
}

static BOOL sub_0200D2D0(SpriteResourceCollection *resourceCollection, SpriteResourceList *resourceList, int resourceID)
{
for (int i = 0; i < resourceList->capacity; i++) {
if (resourceList->resources[i] == NULL) {
continue;
}

int spriteResourceID = SpriteResource_GetID(resourceList->resources[i]);

if (spriteResourceID == resourceID) {
sub_0201F9F0(resourceID);
SpriteResourceCollection_Remove(resourceCollection, resourceList->resources[i]);

resourceList->resources[i] = NULL;
resourceList->count--;

return TRUE;
}
}

return FALSE;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Can we name these functions?

Comment on lines +4 to +9
{
"narc": 123,
"file": 3,
"compressed": false,
"id": 0
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think that, in general, I would rather we get these to map to NARCs and NAIX files. Maybe this means that the conversion utility should be in C code so that we can easily import the necessary header files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants