aboutsummaryrefslogtreecommitdiff
path: root/project/src/lib-breff.h
blob: 50807d182bb266975cc68852e7f8b8b5c68dd10c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

/***************************************************************************
 *                         _______ _______ _______                         *
 *                        |  ___  |____   |  ___  |                        *
 *                        | |   |_|    / /| |   |_|                        *
 *                        | |_____    / / | |_____                         *
 *                        |_____  |  / /  |_____  |                        *
 *                         _    | | / /    _    | |                        *
 *                        | |___| |/ /____| |___| |                        *
 *                        |_______|_______|_______|                        *
 *                                                                         *
 *                            Wiimms SZS Tools                             *
 *                          https://szs.wiimm.de/                          *
 *                                                                         *
 ***************************************************************************
 *                                                                         *
 *   This file is part of the SZS project.                                 *
 *   Visit https://szs.wiimm.de/ for project details and sources.          *
 *                                                                         *
 *   Copyright (c) 2011-2022 by Dirk Clemens <wiimm@wiimm.de>              *
 *                                                                         *
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt       *
 *                                                                         *
 ***************************************************************************/

// all about SZS, YAZ0 and U8 files:
//	https://wiki.tockdom.de/index.php?title=SZS
//	https://wiki.tockdom.de/index.php?title=YAZ0
//	https://wiki.tockdom.de/index.php?title=U8

///////////////////////////////////////////////////////////////////////////////

#ifndef SZS_LIB_BREFF_H
#define SZS_LIB_BREFF_H 1

#include "lib-brres.h"

//
///////////////////////////////////////////////////////////////////////////////
///////////////		   BREFF + BREFT file header		///////////////
///////////////////////////////////////////////////////////////////////////////

// BREFF + BREFT uses the same header like BRRES, but other magics

#define BREFF_MAGIC		"REFF"
#define BREFF_MAGIC_NUM		0x52454646
#define BREFF_DEFAULT_ALIGN	0x04

#define BREFT_MAGIC		"REFT"
#define BREFT_MAGIC_NUM		0x52454654
#define BREFT_9_DEFAULT_ALIGN	0x20
#define BREFT_11_DEFAULT_ALIGN	0x40

//
///////////////////////////////////////////////////////////////////////////////
///////////////			breff root			///////////////
///////////////////////////////////////////////////////////////////////////////

typedef struct breff_root_head_t
{
    char		magic[4];	// magic
    u32			data_size;	// data size
    u8			data[0];	// data, starting with a breff_root_t

}
__attribute__ ((packed)) breff_root_head_t;

//-----------------------------------------------------------------------------

typedef struct breff_root_t
{
    u32			first_item_off;	// offset of first breff_item_t
    u32			unknown1;	// always 0 in MKW
    u32			unknown2;	// always 0 in MKW
    u16			name_len0;	// length of name including terminating NULL
    u16			unknown3;	// always 0 in MKW
    char		name[0];	// NULL terminated name
    //u8		data[];		// padding or real data
}
__attribute__ ((packed)) breff_root_t;

///////////////////////////////////////////////////////////////////////////////

typedef struct breff_item_name_t
{
    u16			name_len0;	// length of name including terminating NULL
    //char		name[0];	// NULL terminated name
					// breff_item_data_t follows not aligned
					// -> disabled because of MVC
}
__attribute__ ((packed)) breff_item_name_t;

//-----------------------------------------------------------------------------

typedef struct breff_item_data_t
{
    u32			offset;		// data offset relative to item list
    u32			size;		// data size
}
__attribute__ ((packed)) breff_item_data_t;

//-----------------------------------------------------------------------------

typedef struct breff_item_list_t
{
    u32			size;		// size of all items
    u16			n_item;		// number of itmes
    u16			unknown1;
    breff_item_name_t	item[0];	// first item
}
__attribute__ ((packed)) breff_item_list_t;

//-----------------------------------------------------------------------------

typedef struct breft_image_t
{
    u32		unknown1;	// always 0
    u16		width;
    u16		height;
    u32		img_size;
    u8		iform;
    u8		unknown2[3+4];	// nearly always 0
    u8		n_image;	// >0: number of images (=N(mipmaps)+1)
    u8		unknown3[3+8];	// nearly always 0
    u8		data[];		// image data
}
__attribute__ ((packed)) breft_image_t;

//
///////////////////////////////////////////////////////////////////////////////
///////////////			Interface			///////////////
///////////////////////////////////////////////////////////////////////////////

int IterateFilesBREFF
(
    struct szs_iterator_t	*it,	// iterator struct with all infos
    bool			term	// true: termination hint
);

//-----------------------------------------------------------------------------

enumError CreateBREFF
(
    szs_file_t		* szs,		// valid szs
    ccp			source_dir,	// NULL or path to source dir
    u8			* source_data,	// NULL or source data
    u32			total_size,	// total file size
    SetupParam_t	* setup_param	// NULL or setup parameters
);

//
///////////////////////////////////////////////////////////////////////////////
///////////////			    END				///////////////
///////////////////////////////////////////////////////////////////////////////

#endif // SZS_LIB_BREFF_H