Add support for supplying exiting CGFX and CWAV files to makebanner, add command for creating SMDH files.

This commit is contained in:
Steveice10
2015-01-24 12:47:21 -08:00
parent 45a90edba5
commit c0c54f81cb
8 changed files with 277 additions and 69 deletions

View File

@@ -3,6 +3,7 @@
#include "data.h"
#include "types.h"
#include "wav.h"
#include "3ds/smdh.h"
#include <stdio.h>
#include <malloc.h>
@@ -10,7 +11,7 @@
u8* convert_to_cgfx(const char* image, u32 width, u32 height, u32* size) {
u32 convertedSize = 0;
u8* converted = image_to_tiles(image, width, height, &convertedSize);
u16* converted = image_to_tiles(image, width, height, &convertedSize);
if(converted == NULL) {
return NULL;
}
@@ -37,17 +38,49 @@ u8* convert_to_cwav(const char* file, u32* size) {
return cwav;
}
int make_banner(const char* image, const char* audio, const char* output) {
int make_banner(const char* image, const char* audio, char* cgfxFile, char* cwavFile, const char* output) {
u32 cgfxSize = 0;
u8* cgfx = convert_to_cgfx(image, 256, 128, &cgfxSize);
if(!cgfx) {
return 1;
u8* cgfx = NULL;
if(cgfxFile != NULL) {
FILE* fd = fopen(cgfxFile, "r");
if(!fd) {
printf("ERROR: Could not open CGFX file: %s\n", strerror(errno));
}
fseek(fd, 0, SEEK_END);
cgfxSize = (u32) ftell(fd);
fseek(fd, 0, SEEK_SET);
cgfx = (u8*) malloc(cgfxSize);
fread(cgfx, 1, cgfxSize, fd);
fclose(fd);
} else {
cgfx = convert_to_cgfx(image, 256, 128, &cgfxSize);
if(!cgfx) {
return 1;
}
}
u32 cwavSize = 0;
u8* cwav = convert_to_cwav(audio, &cwavSize);
if(!cwav) {
return 2;
u8* cwav = NULL;
if(cwavFile != NULL) {
FILE* fd = fopen(cwavFile, "r");
if(!fd) {
printf("ERROR: Could not open CWAV file: %s\n", strerror(errno));
}
fseek(fd, 0, SEEK_END);
cwavSize = (u32) ftell(fd);
fseek(fd, 0, SEEK_SET);
cwav = (u8*) malloc(cwavSize);
fread(cwav, 1, cwavSize, fd);
fclose(fd);
} else {
cwav = convert_to_cwav(audio, &cwavSize);
if(!cwav) {
return 2;
}
}
CBMD cbmd;
@@ -76,6 +109,43 @@ int make_banner(const char* image, const char* audio, const char* output) {
return 0;
}
int make_smdh(char* shortDescription, char* longDescription, char* publisher, char* icon, char* output) {
u16* icon48 = image_to_tiles(icon, 48, 48, NULL);
if(icon48 == NULL) {
return 1;
}
u16 icon24[24 * 24];
for(int y = 0; y < 24; y++) {
for(int x = 0; x < 24; x++) {
icon24[y * 24 + x] = icon48[y * 48 + x];
}
}
SMDH smdh;
for(int i = 0; i < 0x10; i++) {
utf8_to_utf16(smdh.titles[i].shortDescription, shortDescription, 0x40);
utf8_to_utf16(smdh.titles[i].longDescription, longDescription, 0x80);
utf8_to_utf16(smdh.titles[i].publisher, publisher, 0x40);
}
memcpy(smdh.largeIcon, icon48, 0x1200);
memcpy(smdh.smallIcon, icon24, 0x480);
free(icon48);
FILE* fd = fopen(output, "wb");
if(!fd) {
printf("ERROR: Could not open output file: %s\n", strerror(errno));
return 2;
}
fwrite(&smdh, 1, sizeof(SMDH), fd);
fclose(fd);
printf("Created SMDH \"%s\".\n", output);
return 0;
}
int make_cwav(char* input, char* output) {
u32 cwavSize = 0;
u8* cwav = convert_to_cwav(input, &cwavSize);
@@ -143,15 +213,29 @@ int main(int argc, char* argv[]) {
char* command = argv[1];
std::map<char*, char*, compare_strings> args = cmd_get_args(argc, argv);
if(strcmp(command, "makebanner") == 0) {
char* banner = cmd_find_arg(args, "i", "image");
char* audio = cmd_find_arg(args, "a", "audio");
char* output = cmd_find_arg(args, "o", "output");
if(!banner || !audio || !output) {
char *banner = cmd_find_arg(args, "i", "image");
char *audio = cmd_find_arg(args, "a", "audio");
char *cgfxFile = cmd_find_arg(args, "ci", "cgfximage");
char *cwavFile = cmd_find_arg(args, "ca", "cwavaudio");
char *output = cmd_find_arg(args, "o", "output");
if(!(banner || cgfxFile) || !(audio || cwavFile) || !output) {
cmd_missing_args(command);
return -1;
}
return make_banner(banner, audio, output);
return make_banner(banner, audio, cgfxFile, cwavFile, output);
} else if(strcmp(command, "makesmdh") == 0) {
char* shortDescription = cmd_find_arg(args, "s", "shortdescription");
char* longDescription = cmd_find_arg(args, "l", "longdescription");
char* publisher = cmd_find_arg(args, "p", "publisher");
char* icon = cmd_find_arg(args, "i", "icon");
char* output = cmd_find_arg(args, "o", "output");
if(!shortDescription || !longDescription || !publisher || !icon || !output) {
cmd_missing_args(command);
return -1;
}
return make_smdh(shortDescription, longDescription, publisher, icon, output);
} else if(strcmp(command, "makecwav") == 0) {
char* input = cmd_find_arg(args, "i", "input");
char* output = cmd_find_arg(args, "o", "output");