Add support for supplying exiting CGFX and CWAV files to makebanner, add command for creating SMDH files.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "cbmd.h"
|
||||
#include "cwav.h"
|
||||
#include "smdh.h"
|
||||
#include "lz11.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
@@ -1,11 +1,53 @@
|
||||
#include "cwav.h"
|
||||
|
||||
#include "../wav.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
char magic[4] = {'C', 'W', 'A', 'V'};
|
||||
u16 endianess = 0xFEFF;
|
||||
u16 structLength = 0x40;
|
||||
u32 unknown0 = 0;
|
||||
u32 fileSize;
|
||||
u32 numChunks = 2;
|
||||
u32 infoChunkFlags = 0x7000;
|
||||
u32 infoChunkOffset;
|
||||
u32 infoChunkLength;
|
||||
u32 dataChunkFlags = 0x7000;
|
||||
u32 dataChunkOffset;
|
||||
u32 dataChunkLength;
|
||||
u8 reserved[0x14] = {0};
|
||||
} Header;
|
||||
|
||||
typedef struct {
|
||||
char magic[4] = {'I', 'N', 'F', 'O'};
|
||||
u32 length = 0xC0;
|
||||
u32 type;
|
||||
u32 sampleRate;
|
||||
u32 unknown1 = 0;
|
||||
u32 totalSamples;
|
||||
u32 unknown2 = 0;
|
||||
u32 totalChannels;
|
||||
} InfoHeader;
|
||||
|
||||
typedef struct {
|
||||
char magic[4] = {'D', 'A', 'T', 'A'};
|
||||
u32 length;
|
||||
} DataHeader;
|
||||
|
||||
typedef struct {
|
||||
u32 flags = 0x7100;
|
||||
u32 offset;
|
||||
} ChannelDataPointer;
|
||||
|
||||
typedef struct {
|
||||
u32 flags = 0x1F00;
|
||||
u32 offset;
|
||||
u32 unknown3 = 0;
|
||||
u32 unknown4 = 0;
|
||||
u32 padding = 0;
|
||||
} ChannelData;
|
||||
|
||||
u8* build_cwav(WAV wav, u32* size) {
|
||||
Header header;
|
||||
u32 offset = sizeof(Header);
|
||||
|
||||
@@ -4,51 +4,6 @@
|
||||
#include "../types.h"
|
||||
#include "../wav.h"
|
||||
|
||||
typedef struct {
|
||||
char magic[4] = {'C', 'W', 'A', 'V'};
|
||||
u16 endianess = 0xFEFF;
|
||||
u16 structLength = 0x40;
|
||||
u32 unknown0 = 0;
|
||||
u32 fileSize;
|
||||
u32 numChunks = 2;
|
||||
u32 infoChunkFlags = 0x7000;
|
||||
u32 infoChunkOffset;
|
||||
u32 infoChunkLength;
|
||||
u32 dataChunkFlags = 0x7000;
|
||||
u32 dataChunkOffset;
|
||||
u32 dataChunkLength;
|
||||
u8 reserved[0x14] = {0};
|
||||
} Header;
|
||||
|
||||
typedef struct {
|
||||
char magic[4] = {'I', 'N', 'F', 'O'};
|
||||
u32 length = 0xC0;
|
||||
u32 type;
|
||||
u32 sampleRate;
|
||||
u32 unknown1 = 0;
|
||||
u32 totalSamples;
|
||||
u32 unknown2 = 0;
|
||||
u32 totalChannels;
|
||||
} InfoHeader;
|
||||
|
||||
typedef struct {
|
||||
char magic[4] = {'D', 'A', 'T', 'A'};
|
||||
u32 length;
|
||||
} DataHeader;
|
||||
|
||||
typedef struct {
|
||||
u32 flags = 0x7100;
|
||||
u32 offset;
|
||||
} ChannelDataPointer;
|
||||
|
||||
typedef struct {
|
||||
u32 flags = 0x1F00;
|
||||
u32 offset;
|
||||
u32 unknown3 = 0;
|
||||
u32 unknown4 = 0;
|
||||
u32 padding = 0;
|
||||
} ChannelData;
|
||||
|
||||
u8* build_cwav(WAV wav, u32* size);
|
||||
|
||||
#endif
|
||||
96
source/3ds/smdh.h
Normal file
96
source/3ds/smdh.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef __SMDH_H__
|
||||
#define __SMDH_H__
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
typedef enum {
|
||||
JAPANESE,
|
||||
ENGLISH,
|
||||
FRENCH,
|
||||
GERMAN,
|
||||
ITALIAN,
|
||||
SPANISH,
|
||||
SIMPLIFIED_CHINESE,
|
||||
KOREAN,
|
||||
DUTCH,
|
||||
PORTUGESE,
|
||||
RUSSIAN,
|
||||
TRADITIONAL_CHINESE
|
||||
} SMDHTitleLanguage;
|
||||
|
||||
typedef struct {
|
||||
u16 shortDescription[0x40] = {0};
|
||||
u16 longDescription[0x80] = {0};
|
||||
u16 publisher[0x40] = {0};
|
||||
} SMDHTitle;
|
||||
|
||||
typedef struct {
|
||||
// TODO: values...
|
||||
u8 cero = 0;
|
||||
u8 esrb = 0;
|
||||
u8 reserved0 = 0;
|
||||
u8 usk = 0;
|
||||
u8 pegiGen = 0;
|
||||
u8 reserved1 = 0;
|
||||
u8 pegiPrt = 0;
|
||||
u8 pegiBbfc = 0;
|
||||
u8 cob = 0;
|
||||
u8 grb = 0;
|
||||
u8 cgsrr = 0;
|
||||
u8 reserved2 = 0;
|
||||
u8 reserved3 = 0;
|
||||
u8 reserved4 = 0;
|
||||
u8 reserved5 = 0;
|
||||
u8 reserved6 = 0;
|
||||
} SMDHGameRatings;
|
||||
|
||||
typedef struct _region_lock {
|
||||
_region_lock() : japan(true), northAmerica(true), europe(true), australia(true), china(true), korea(true), taiwan(true) {}
|
||||
|
||||
bool japan : 1;
|
||||
bool northAmerica : 1;
|
||||
bool europe : 1;
|
||||
bool australia : 1;
|
||||
bool china : 1;
|
||||
bool korea : 1;
|
||||
bool taiwan : 1;
|
||||
} SMDHRegionLock;
|
||||
|
||||
typedef struct _flags {
|
||||
_flags() : visible(true), autoBoot(false), allow3d(true), requireEula(false), autoSaveOnExit(false), useExtendedBanner(false), ratingRequired(false), useSaveData(false), recordUsage(true), disableSaveBackups(false) {}
|
||||
|
||||
bool visible : 1;
|
||||
bool autoBoot : 1;
|
||||
bool allow3d : 1;
|
||||
bool requireEula : 1;
|
||||
bool autoSaveOnExit : 1;
|
||||
bool useExtendedBanner : 1;
|
||||
bool ratingRequired : 1;
|
||||
bool useSaveData : 1;
|
||||
bool recordUsage : 1;
|
||||
bool disableSaveBackups : 1;
|
||||
} SMDHFlags;
|
||||
|
||||
typedef struct {
|
||||
SMDHGameRatings gameRatings;
|
||||
SMDHRegionLock regionLock;
|
||||
u8 matchMakerId[0xC] = {0};
|
||||
SMDHFlags flags;
|
||||
u16 eulaVersion = 0;
|
||||
u16 reserved1 = 0;
|
||||
u32 optimalBannerFrame = 0;
|
||||
u32 streetpassId = 0;
|
||||
} SMDHSettings;
|
||||
|
||||
typedef struct {
|
||||
char magic[4] = {'S', 'M', 'D', 'H'};
|
||||
u16 version = 0;
|
||||
u16 reserved0 = 0;
|
||||
SMDHTitle titles[0x10];
|
||||
SMDHSettings settings;
|
||||
u64 reserved2 = 0;
|
||||
u8 smallIcon[0x480] = {0};
|
||||
u8 largeIcon[0x1200] = {0};
|
||||
} SMDH;
|
||||
|
||||
#endif
|
||||
@@ -7,7 +7,14 @@ u8 TILE_ORDER[64] = { 0, 1, 8, 9, 2, 3, 10, 11, 16, 17, 24, 25, 18, 19, 26
|
||||
32, 33, 40, 41, 34, 35, 42, 43, 48, 49, 56, 57, 50, 51, 58, 59,
|
||||
36, 37, 44, 45, 38, 39, 46, 47, 52, 53, 60, 61, 54, 55, 62, 63 };
|
||||
|
||||
u8* image_to_tiles(const char* image, u32 width, u32 height, u32* size) {
|
||||
u16 rgba_to_rgb565(u8 r, u8 g, u8 b, u8 a) {
|
||||
r = (u8) (1.0f * r * a / 255.0f) >> 3;
|
||||
g = (u8) (1.0f * g * a / 255.0f) >> 2;
|
||||
b = (u8) (1.0f * b * a / 255.0f) >> 3;
|
||||
return (r << 11) | (g << 5) | b;
|
||||
}
|
||||
|
||||
u16* image_to_tiles(const char* image, u32 width, u32 height, u32* size) {
|
||||
unsigned char* img;
|
||||
unsigned int imgWidth, imgHeight;
|
||||
if(lodepng_decode32_file(&img, &imgWidth, &imgHeight, image)) {
|
||||
@@ -28,7 +35,7 @@ u8* image_to_tiles(const char* image, u32 width, u32 height, u32* size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u8* converted = (u8*) malloc(width * height * 2);
|
||||
u16* converted = (u16*) malloc(width * height * sizeof(u16));
|
||||
u32 n = 0;
|
||||
for(int y = 0; y < height; y += 8) {
|
||||
for(int x = 0; x < width; x += 8) {
|
||||
@@ -37,15 +44,26 @@ u8* image_to_tiles(const char* image, u32 width, u32 height, u32* size) {
|
||||
u32 yy = (u32) (TILE_ORDER[k] >> 3);
|
||||
|
||||
u8* pixel = img + (((y + yy) * width + (x + xx)) * 4);
|
||||
converted[n++] = ((pixel[2] >> 4) << 4) | (pixel[3] >> 4);
|
||||
converted[n++] = ((pixel[0] >> 4) << 4) | (pixel[1] >> 4);
|
||||
converted[n++] = rgba_to_rgb565(pixel[0], pixel[1], pixel[2], pixel[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(size != NULL) {
|
||||
*size = width * height * 2;
|
||||
*size = width * height * (u32) sizeof(u16);
|
||||
}
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
void utf8_to_utf16(u16* dst, const char* src, size_t max_len) {
|
||||
u8* u8dst = (u8*) dst;
|
||||
size_t n = 0;
|
||||
while(src[n]) {
|
||||
u8dst[n * 2] = (u8) src[n];
|
||||
u8dst[n * 2 + 1] = 0;
|
||||
if(n++ >= max_len) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
u8* image_to_tiles(const char* image, u32 width, u32 height, u32* size);
|
||||
u16 rgba_to_rgb565(u8 r, u8 g, u8 b, u8 a);
|
||||
u16* image_to_tiles(const char* image, u32 width, u32 height, u32* size);
|
||||
void utf8_to_utf16(u16* dst, const char* src, size_t max_len);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user