summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/nitrogfx/gfx.c31
-rw-r--r--tools/nitrogfx/json.c42
-rw-r--r--tools/nitrogfx/options.h5
3 files changed, 49 insertions, 29 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index be01a456..305fbeb2 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -744,16 +744,17 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
if (fp == NULL)
FATAL_ERROR("Failed to open \"%s\" for writing.\n", path);
- unsigned int totalSize = (options->label > 0 ? 0x34 : 0x20) + options->cellCount * (options->extended ? 0x16 : 0xe);
+ unsigned int totalSize = (options->labelEnabled > 0 ? 0x34 : 0x20) + options->cellCount * (options->extended ? 0x16 : 0xe);
- if (options->label)
+ if (options->labelEnabled)
{
- for (int i = 0; i < options->cellCount; i++) {
- totalSize += strlen(options->cells[i]->label) + 5; //strlen + terminator + pointer
+ for (int j = 0; j < options->labelCount; j++)
+ {
+ totalSize += strlen(options->labels[j]) + 5; //strlen + terminator + pointer
}
}
- WriteGenericNtrHeader(fp, "RECN", totalSize, true, false, options->label ? 3 : 1);
+ WriteGenericNtrHeader(fp, "RECN", totalSize, true, false, options->labelEnabled ? 3 : 1);
unsigned char KBECHeader[0x20] =
{
@@ -858,12 +859,12 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
free(KBECContents);
- if (options->label)
+ if (options->labelEnabled)
{
- unsigned int lablSize = 8 + options->cellCount * 4;
- for (i = 0; i < options->cellCount; i++)
+ unsigned int lablSize = 8;
+ for (int j = 0; j < options->labelCount; j++)
{
- lablSize += strlen(options->cells[i]->label) + 1;
+ lablSize += strlen(options->labels[j]) + 5;
}
unsigned char *labl = malloc(lablSize);
@@ -876,18 +877,20 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
unsigned int position = 0;
- for (i = 0; i < options->cellCount * 4; i += 4)
+ i = 0;
+ for (int j = 0; j < options->labelCount; j++)
{
labl[i + 8] = position & 0xff;
labl[i + 9] = position >> 8;
- position += strlen(options->cells[i / 4]->label) + 1;
+ position += strlen(options->labels[j]) + 1;
+ i += 4;
}
- for (int j = 0; j < options->cellCount; j++)
+ for (int j = 0; j < options->labelCount; j++)
{
- strcpy((char *) (labl + (i + 8)), options->cells[j]->label);
- i += strlen(options->cells[j]->label) + 1;
+ strcpy((char *) (labl + (i + 8)), options->labels[j]);
+ i += strlen(options->labels[j]) + 1;
}
fwrite(labl, 1, lablSize, fp);
diff --git a/tools/nitrogfx/json.c b/tools/nitrogfx/json.c
index 53f83ceb..aad325be 100644
--- a/tools/nitrogfx/json.c
+++ b/tools/nitrogfx/json.c
@@ -46,13 +46,13 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
FATAL_ERROR("Error in line \"%s\"\n", errorPtr);
}
- cJSON *labelBool = cJSON_GetObjectItemCaseSensitive(json, "label");
+ cJSON *labelBool = cJSON_GetObjectItemCaseSensitive(json, "labelEnabled");
cJSON *extended = cJSON_GetObjectItemCaseSensitive(json, "extended");
cJSON *imageHeight = cJSON_GetObjectItemCaseSensitive(json, "imageHeight");
cJSON *imageWidth = cJSON_GetObjectItemCaseSensitive(json, "imageWidth");
cJSON *cellCount = cJSON_GetObjectItemCaseSensitive(json, "cellCount");
- options->label = GetBool(labelBool);
+ options->labelEnabled = GetBool(labelBool);
options->extended = GetBool(extended);
options->imageHeight = GetInt(imageHeight);
options->imageWidth = GetInt(imageWidth);
@@ -60,6 +60,26 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
options->cells = malloc(sizeof(struct Cell *) * options->cellCount);
+
+ if (options->labelEnabled)
+ {
+ cJSON *labelCount = cJSON_GetObjectItemCaseSensitive(json, "labelCount");
+ options->labelCount = GetInt(labelCount);
+ options->labels = malloc(sizeof(char *) * options->labelCount);
+
+ cJSON *labels = cJSON_GetObjectItemCaseSensitive(json, "labels");
+ cJSON *label = NULL;
+
+ int j = 0;
+ cJSON_ArrayForEach(label, labels)
+ {
+ char *labelString = GetString(label);
+ options->labels[j] = malloc(strlen(labelString) + 1);
+ strcpy(options->labels[j], labelString);
+ j++;
+ }
+ }
+
for (int i = 0; i < options->cellCount; i++)
{
options->cells[i] = malloc(sizeof(struct Cell));
@@ -89,14 +109,6 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
options->cells[i]->minX = (short)GetInt(minX);
options->cells[i]->minY = (short)GetInt(minY);
}
-
- if (options->label)
- {
- cJSON *label = cJSON_GetObjectItemCaseSensitive(cell, "label");
- char *labelString = GetString(label);
- options->cells[i]->label = malloc(strlen(labelString) + 1);
- strcpy(options->cells[i]->label, labelString);
- }
//OAM data
cJSON *OAM = cJSON_GetObjectItemCaseSensitive(cell, "OAM");
@@ -221,11 +233,15 @@ void FreeNCERCell(struct JsonToCellOptions *options)
{
for (int i = 0; i < options->cellCount; i++)
{
- if (options->label)
+ free(options->cells[i]);
+ }
+ if (options->labelEnabled)
+ {
+ for (int j = 0; j < options->labelCount; j++)
{
- free(options->cells[i]->label);
+ free(options->labels[j]);
}
- free(options->cells[i]);
+ free(options->labels);
}
free(options);
}
diff --git a/tools/nitrogfx/options.h b/tools/nitrogfx/options.h
index f4626df9..780c83e6 100644
--- a/tools/nitrogfx/options.h
+++ b/tools/nitrogfx/options.h
@@ -69,16 +69,17 @@ struct Cell {
short minX;
short minY;
struct OAM oam;
- char *label;
};
struct JsonToCellOptions {
- bool label;
+ bool labelEnabled;
bool extended;
int imageHeight;
int imageWidth;
int cellCount;
struct Cell **cells;
+ char **labels;
+ int labelCount;
};
struct JsonToScreenOptions {