mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-18 17:29:17 +01:00
some brlyt stuff
This commit is contained in:
parent
61d1559e95
commit
969ecde4d8
@ -1,21 +1,193 @@
|
||||
/*
|
||||
* brlyt.c
|
||||
* BannerPlayer
|
||||
* brlyt.h
|
||||
* Parses brlyt file
|
||||
*
|
||||
* Created by Alex Marshall on 09/03/16.
|
||||
* Copyright 2009 __MyCompanyName__. All rights reserved.
|
||||
* by nIxx
|
||||
* http://wiibrew.org/wiki/Wii_Animations#Textures_and_Material_lists_.28.2A.brlyt.29
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fat.h>
|
||||
|
||||
#include "brlyt.h"
|
||||
#include "openingbnr.h"
|
||||
|
||||
void BRLYT_Initialize(char rootpath[])
|
||||
int BRLYT_Initialize(const char *rootpath)
|
||||
{
|
||||
//fatInitDefault();
|
||||
FILE * fp = fopen(rootpath,"rb");
|
||||
|
||||
if (fp == NULL) return 0;
|
||||
|
||||
brlyt_header brlytheader;
|
||||
lyt1_header lyt1header;
|
||||
txl1_header txl1header;
|
||||
|
||||
fread((void*)&brlytheader,1,sizeof(brlytheader),fp);
|
||||
fread((void*)&lyt1header,1,sizeof(lyt1header),fp);
|
||||
fread((void*)&txl1header,1,sizeof(txl1header),fp);
|
||||
|
||||
//printf("Filesize: %i\n",be32((u8*)&brlytheader.file_size));
|
||||
//printf("Num Textures: %i\n",be16((u8*)&txl1header.num_textures));
|
||||
|
||||
txl1_offset **txl1offsets = (txl1_offset**)malloc(sizeof(txl1_offset*)*be16((u8*)&txl1header.num_textures));
|
||||
|
||||
if(txl1offsets == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for(i = 0; i < be16((u8*)&txl1header.num_textures); i++)
|
||||
{
|
||||
txl1offsets[i] = (txl1_offset*)malloc(sizeof(txl1_offset));
|
||||
if(txl1offsets[i] == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
fread(txl1offsets[i],1,sizeof(*txl1offsets[i]),fp);
|
||||
//printf("Offset Filename: %i\n",be32((u8*)&txl1offsets[i]->offset_filename));
|
||||
}
|
||||
|
||||
tpl_files **tplss = (tpl_files**)malloc(sizeof(tpl_files*)*be16((u8*)&txl1header.num_textures));
|
||||
if(tplss == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < be16((u8*)&txl1header.num_textures); i++)
|
||||
{
|
||||
tplss[i] = (tpl_files*)malloc(sizeof(tpl_files));
|
||||
if(tplss[i] == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fseek(fp,0x30+ be32((u8*)&txl1offsets[i]->offset_filename),SEEK_SET);
|
||||
fread(tplss[i],1,sizeof(*tplss[i]),fp);
|
||||
//printf("%i. Filename: %s\n",i,tplss[i]->tplfilename);
|
||||
}
|
||||
|
||||
fseek(fp,0x10+be32((u8*)&lyt1header.size_header)+be32((u8*)&txl1header.size_section),SEEK_SET);
|
||||
|
||||
mat1_header mat1header;
|
||||
fread((void*)&mat1header,1,sizeof(mat1header),fp);
|
||||
//printf("Sig: %s SizeHeader:%i Num materials%i\n",mat1header.sig ,be32((u8*)&mat1header.size_section) ,be16((u8*)&mat1header.num_materials) );
|
||||
|
||||
mat1_offset **mat1offsets = (mat1_offset**)malloc(sizeof(mat1_offset*)*be16((u8*)&mat1header.num_materials));
|
||||
if(mat1offsets == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < be16((u8*)&mat1header.num_materials); i++)
|
||||
{
|
||||
mat1offsets[i] = (mat1_offset*)malloc(sizeof(mat1_offset));
|
||||
if(mat1offsets[i] == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(mat1offsets[i],1,sizeof(*mat1offsets[i]),fp);
|
||||
//printf("%i. Material Offset: %X\n",i,be32((u8*)&mat1offsets[i]->offset));
|
||||
}
|
||||
|
||||
mat1_material **mat1materials = (mat1_material**)malloc(sizeof(mat1_material*)*be16((u8*)&mat1header.num_materials));
|
||||
if(mat1materials == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < be16((u8*)&mat1header.num_materials); i++)
|
||||
{
|
||||
mat1materials[i] = (mat1_material*)malloc(sizeof(mat1_material));
|
||||
if(mat1materials[i] == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
fseek(fp,0x10+be32((u8*)&lyt1header.size_header)+be32((u8*)&txl1header.size_section)+be32((u8*)&mat1offsets[i]->offset),SEEK_SET);
|
||||
fread(mat1materials[i],1,sizeof(*mat1materials[i]),fp);
|
||||
//printf("%i. Material Names: %s\n",i,mat1materials[i]->name);
|
||||
}
|
||||
|
||||
fseek(fp,0x10+be32((u8*)&lyt1header.size_header)+be32((u8*)&txl1header.size_section)+be32((u8*)&mat1header.size_section),SEEK_SET);
|
||||
|
||||
pan1_header pan1header;
|
||||
fread((void*)&pan1header,1,sizeof(pan1header),fp);
|
||||
|
||||
pas1_header pas1header;
|
||||
fread((void*)&pas1header,1,sizeof(pas1header),fp);
|
||||
|
||||
pic1_header **pic1header = (pic1_header**)malloc(sizeof(pic1_header*)*be16((u8*)&mat1header.num_materials));
|
||||
if(pic1header == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < be16((u8*)&mat1header.num_materials); i++)
|
||||
{
|
||||
pic1header[i] = (pic1_header*)malloc(sizeof(pic1_header));
|
||||
if(pic1header[i] == NULL)
|
||||
{
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
fpos_t pos;
|
||||
fgetpos(fp,&pos);
|
||||
|
||||
fread(pic1header[i],1,sizeof(*pic1header[i]),fp);
|
||||
fseek(fp,pos+be32((u8*)&pic1header[i]->size_section),SEEK_SET);
|
||||
// printf("%i. Pic1 Names: %s\n",i,pic1header[i]->name);
|
||||
}
|
||||
|
||||
pae1_header pae1header;
|
||||
fread((void*)&pae1header,1,sizeof(pae1header),fp);
|
||||
|
||||
grp1_header grp1header;
|
||||
fread((void*)&grp1header,1,sizeof(grp1header),fp);
|
||||
|
||||
//Close File
|
||||
fclose(fp);
|
||||
|
||||
//free memory
|
||||
for(i = 0; i < be16((u8*)&txl1header.num_textures); i++)
|
||||
free(txl1offsets[i]);
|
||||
|
||||
free(txl1offsets);
|
||||
|
||||
for(i = 0; i < be16((u8*)&txl1header.num_textures); i++)
|
||||
free(tplss[i]);
|
||||
|
||||
free(tplss);
|
||||
|
||||
for(i = 0; i < be16((u8*)&mat1header.num_materials); i++)
|
||||
free(mat1offsets[i]);
|
||||
|
||||
free(mat1offsets);
|
||||
|
||||
for(i = 0; i < be16((u8*)&mat1header.num_materials); i++)
|
||||
free(mat1materials[i]);
|
||||
|
||||
free(mat1materials);
|
||||
|
||||
for(i = 0; i < be16((u8*)&mat1header.num_materials); i++)
|
||||
free(pic1header[i]);
|
||||
|
||||
free(pic1header);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BRLYT_ReadObjects(BRLYT_object** objs)
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* brlyt.h
|
||||
* BannerPlayer
|
||||
* Parses brlyt file
|
||||
*
|
||||
* Created by Alex Marshall on 09/03/16.
|
||||
* Copyright 2009 __MyCompanyName__. All rights reserved.
|
||||
* by nIxx
|
||||
* http://wiibrew.org/wiki/Wii_Animations#Textures_and_Material_lists_.28.2A.brlyt.29
|
||||
*
|
||||
*/
|
||||
|
||||
@ -12,14 +12,134 @@
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int BRLYT_Initialize(const char *rootpath);
|
||||
|
||||
typedef struct BRLYT_objs
|
||||
{
|
||||
char type[4]; // The type of object (FourCC from BRLYT file)
|
||||
u32 offset; // Offset into the BRLYT file to find this object.
|
||||
} BRLYT_object;
|
||||
|
||||
void BRLYT_Initialize(char rootpath[]);
|
||||
int BRLYT_ReadObjects(BRLYT_object** objs);
|
||||
void BRLYT_Finish();
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "RLYT" in ASCII
|
||||
u32 unk; // Always 0xFE 0xFF 0x 00 0x08.
|
||||
u32 file_size; // Size of whole file, including the header.
|
||||
u32 num; // number of sections
|
||||
} brlyt_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "lyt1" in ASCII.
|
||||
u32 size_header;
|
||||
u32 unk2;
|
||||
u32 width;
|
||||
u32 height;
|
||||
} lyt1_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "txl1" in ASCII.
|
||||
u32 size_section; // Size of the whole section.
|
||||
u16 num_textures; // Number of textures in list.
|
||||
u16 unk2; // Always zero?
|
||||
} txl1_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 offset_filename; // Offset to a null-terminated ASCII string containing the filename.
|
||||
// The offset-base should be after the txl1-header.
|
||||
u32 unk; // Always zero?
|
||||
} txl1_offset;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "mat1" in ASCII.
|
||||
u32 size_section; // // Size of the whole section.
|
||||
u16 num_materials; //
|
||||
u16 size_header; // Offset to list start. Always zero
|
||||
} mat1_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 offset; // Offset from beginning of mat1-section.
|
||||
} mat1_offset;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[20];
|
||||
s16 tev_color[4];
|
||||
s16 unk_color[4];
|
||||
s16 unk_color_2[4];
|
||||
u32 tev_kcolor[4];
|
||||
u32 flags;
|
||||
} mat1_material;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "pan1" in ASCII.
|
||||
u32 size_section;
|
||||
u32 unk; // Always 01 04 FF 00?
|
||||
char pane_name [0x18]; // Pane name in ASCII.
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float xFlip;
|
||||
float yFlip;
|
||||
float zFlip; //rotate
|
||||
float xMag;
|
||||
float yMag;
|
||||
float width;
|
||||
float height;
|
||||
} pan1_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "pas1" in ASCII.
|
||||
u32 size_section;
|
||||
} pas1_header;
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "pic1" in ASCII.
|
||||
u32 size_section;
|
||||
u16 flags;
|
||||
u16 alpha;
|
||||
char name[0x18];
|
||||
float coords[10]; // x, y, unk, unk, unk, angle, xmag, ymag, width, height.
|
||||
} pic1_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sig [4]; // "pae1" in ASCII.
|
||||
u32 size_section;
|
||||
} pae1_header;
|
||||
|
||||
typedef struct {
|
||||
char sig [4]; // "grp1" in ASCII.
|
||||
u32 size_section;
|
||||
char name[16];
|
||||
u16 numsubs;
|
||||
u16 unk1;
|
||||
} grp1_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char tplfilename[40];
|
||||
} tpl_files;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_BRLYT_H_
|
||||
|
@ -34,6 +34,8 @@ int unpackBanner(const char * gameid, const char * outdir);
|
||||
//! Extract the lz77 compressed banner, icon and sound .bin
|
||||
u8* decompress_lz77(u8 *data, size_t data_size, size_t* decompressed_size);
|
||||
|
||||
u16 be16(const u8 *p);
|
||||
u32 be32(const u8 *p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user