mirror of
https://github.com/red031000/nitrogfx.git
synced 2025-06-18 21:25:38 -04:00
support partition data in NCER JSON format
This commit is contained in:
parent
fa38e17f0d
commit
8d191dbb9a
39
gfx.c
39
gfx.c
@ -912,6 +912,9 @@ void ReadNtrCell_CEBK(unsigned char * restrict data, unsigned int blockOffset, u
|
|||||||
{
|
{
|
||||||
options->cellCount = data[blockOffset + 0x8] | (data[blockOffset + 0x9] << 8);
|
options->cellCount = data[blockOffset + 0x8] | (data[blockOffset + 0x9] << 8);
|
||||||
options->extended = data[blockOffset + 0xA] == 1;
|
options->extended = data[blockOffset + 0xA] == 1;
|
||||||
|
|
||||||
|
int partitionOffset = (data[blockOffset + 0x14] | data[blockOffset + 0x15] << 8);
|
||||||
|
options->partitionEnabled = partitionOffset > 0;
|
||||||
/*if (!options->extended)
|
/*if (!options->extended)
|
||||||
{
|
{
|
||||||
//in theory not extended should be implemented, however not 100% sure
|
//in theory not extended should be implemented, however not 100% sure
|
||||||
@ -1002,6 +1005,20 @@ void ReadNtrCell_CEBK(unsigned char * restrict data, unsigned int blockOffset, u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options->partitionEnabled)
|
||||||
|
{
|
||||||
|
// FindNitroDataBlock returns a block size less 0x10 for header, but this requires the real block size
|
||||||
|
int realBlockSize = blockSize + 0x10;
|
||||||
|
offset = blockOffset + 0x08 + partitionOffset;
|
||||||
|
options->partitionData = malloc(realBlockSize - offset);
|
||||||
|
int index = 0;
|
||||||
|
while (offset < realBlockSize)
|
||||||
|
{
|
||||||
|
options->partitionData[index++] = (data[offset] | data[offset + 1] << 8 | data[offset + 2] << 16 | data[offset + 3] << 24);
|
||||||
|
offset += 4;
|
||||||
|
}
|
||||||
|
options->partitionCount = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadNtrCell_LABL(unsigned char * restrict data, unsigned int blockOffset, unsigned int blockSize, struct JsonToCellOptions *options)
|
void ReadNtrCell_LABL(unsigned char * restrict data, unsigned int blockOffset, unsigned int blockSize, struct JsonToCellOptions *options)
|
||||||
@ -1078,6 +1095,8 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
|
|||||||
|
|
||||||
// KBEC base size: 0x08 per bank, or 0x10 per extended bank
|
// KBEC base size: 0x08 per bank, or 0x10 per extended bank
|
||||||
unsigned int kbecSize = options->cellCount * (options->extended ? 0x10 : 0x08);
|
unsigned int kbecSize = options->cellCount * (options->extended ? 0x10 : 0x08);
|
||||||
|
// additional 0x04 for each partition.
|
||||||
|
kbecSize += options->partitionCount * 0x04;
|
||||||
// add 0x06 for number of OAMs - can be more than 1
|
// add 0x06 for number of OAMs - can be more than 1
|
||||||
for (int idx = 0; idx < options->cellCount * iterNum; idx += iterNum)
|
for (int idx = 0; idx < options->cellCount * iterNum; idx += iterNum)
|
||||||
{
|
{
|
||||||
@ -1114,6 +1133,16 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
|
|||||||
|
|
||||||
KBECHeader[16] = (options->mappingType & 0xFF); //not possible to be more than 8 bits, though 32 are allocated
|
KBECHeader[16] = (options->mappingType & 0xFF); //not possible to be more than 8 bits, though 32 are allocated
|
||||||
|
|
||||||
|
// offset to partition data within KBEC section (offset from KBEC start + 0x08)
|
||||||
|
if (options->partitionEnabled)
|
||||||
|
{
|
||||||
|
unsigned int partitionStart = (kbecSize + 0x20) - (options->partitionCount * 0x04) - 0x08;
|
||||||
|
KBECHeader[20] = partitionStart & 0xFF;
|
||||||
|
KBECHeader[21] = (partitionStart >> 8) & 0xFF;
|
||||||
|
KBECHeader[22] = (partitionStart >> 16) & 0xFF;
|
||||||
|
KBECHeader[23] = (partitionStart >> 24) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
fwrite(KBECHeader, 1, 0x20, fp);
|
fwrite(KBECHeader, 1, 0x20, fp);
|
||||||
|
|
||||||
unsigned char *KBECContents = malloc(kbecSize);
|
unsigned char *KBECContents = malloc(kbecSize);
|
||||||
@ -1210,6 +1239,16 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// partition data
|
||||||
|
for (int idx = 0; idx < options->partitionCount; idx++)
|
||||||
|
{
|
||||||
|
KBECContents[offset] = options->partitionData[idx] & 0xFF;
|
||||||
|
KBECContents[offset + 1] = (options->partitionData[idx] >> 8) & 0xFF;
|
||||||
|
KBECContents[offset + 2] = (options->partitionData[idx] >> 16) & 0xFF;
|
||||||
|
KBECContents[offset + 3] = (options->partitionData[idx] >> 24) & 0xFF;
|
||||||
|
offset += 4;
|
||||||
|
}
|
||||||
|
|
||||||
fwrite(KBECContents, 1, kbecSize, fp);
|
fwrite(KBECContents, 1, kbecSize, fp);
|
||||||
|
|
||||||
free(KBECContents);
|
free(KBECContents);
|
||||||
|
27
json.c
27
json.c
@ -47,11 +47,13 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cJSON *labelBool = cJSON_GetObjectItemCaseSensitive(json, "labelEnabled");
|
cJSON *labelBool = cJSON_GetObjectItemCaseSensitive(json, "labelEnabled");
|
||||||
|
cJSON *partitionBool = cJSON_GetObjectItemCaseSensitive(json, "partitionEnabled");
|
||||||
cJSON *extended = cJSON_GetObjectItemCaseSensitive(json, "extended");
|
cJSON *extended = cJSON_GetObjectItemCaseSensitive(json, "extended");
|
||||||
cJSON *cellCount = cJSON_GetObjectItemCaseSensitive(json, "cellCount");
|
cJSON *cellCount = cJSON_GetObjectItemCaseSensitive(json, "cellCount");
|
||||||
cJSON *mappingType = cJSON_GetObjectItemCaseSensitive(json, "mappingType");
|
cJSON *mappingType = cJSON_GetObjectItemCaseSensitive(json, "mappingType");
|
||||||
|
|
||||||
options->labelEnabled = GetBool(labelBool);
|
options->labelEnabled = GetBool(labelBool);
|
||||||
|
options->partitionEnabled = GetBool(partitionBool);
|
||||||
options->extended = GetBool(extended);
|
options->extended = GetBool(extended);
|
||||||
options->cellCount = GetInt(cellCount);
|
options->cellCount = GetInt(cellCount);
|
||||||
options->mappingType = GetInt(mappingType);
|
options->mappingType = GetInt(mappingType);
|
||||||
@ -77,6 +79,23 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options->partitionEnabled)
|
||||||
|
{
|
||||||
|
cJSON *partitionCount = cJSON_GetObjectItemCaseSensitive(json, "partitionCount");
|
||||||
|
options->partitionCount = GetInt(partitionCount);
|
||||||
|
options->partitionData = malloc(sizeof(int) * options->partitionCount);
|
||||||
|
|
||||||
|
cJSON *partitions = cJSON_GetObjectItemCaseSensitive(json, "partitions");
|
||||||
|
cJSON *partition = NULL;
|
||||||
|
|
||||||
|
int j = 0;
|
||||||
|
cJSON_ArrayForEach(partition, partitions)
|
||||||
|
{
|
||||||
|
int partitionValue = GetInt(partition);
|
||||||
|
options->partitionData[j++] = partitionValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < options->cellCount; i++)
|
for (int i = 0; i < options->cellCount; i++)
|
||||||
{
|
{
|
||||||
options->cells[i] = malloc(sizeof(struct Cell));
|
options->cells[i] = malloc(sizeof(struct Cell));
|
||||||
@ -195,6 +214,7 @@ char *GetNCERJson(struct JsonToCellOptions *options)
|
|||||||
|
|
||||||
cJSON_AddBoolToObject(ncer, "labelEnabled", options->labelEnabled);
|
cJSON_AddBoolToObject(ncer, "labelEnabled", options->labelEnabled);
|
||||||
cJSON_AddBoolToObject(ncer, "extended", options->extended);
|
cJSON_AddBoolToObject(ncer, "extended", options->extended);
|
||||||
|
cJSON_AddBoolToObject(ncer, "partitionEnabled", options->partitionEnabled);
|
||||||
cJSON_AddNumberToObject(ncer, "cellCount", options->cellCount);
|
cJSON_AddNumberToObject(ncer, "cellCount", options->cellCount);
|
||||||
cJSON_AddNumberToObject(ncer, "mappingType", options->mappingType);
|
cJSON_AddNumberToObject(ncer, "mappingType", options->mappingType);
|
||||||
|
|
||||||
@ -263,6 +283,13 @@ char *GetNCERJson(struct JsonToCellOptions *options)
|
|||||||
cJSON_AddNumberToObject(ncer, "labelCount", options->labelCount);
|
cJSON_AddNumberToObject(ncer, "labelCount", options->labelCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options->partitionEnabled)
|
||||||
|
{
|
||||||
|
cJSON *partitions = cJSON_CreateIntArray(options->partitionData, options->partitionCount);
|
||||||
|
cJSON_AddItemToObject(ncer, "partitions", partitions);
|
||||||
|
cJSON_AddNumberToObject(ncer, "partitionCount", options->partitionCount);
|
||||||
|
}
|
||||||
|
|
||||||
char *jsonString = cJSON_Print(ncer);
|
char *jsonString = cJSON_Print(ncer);
|
||||||
cJSON_Delete(ncer);
|
cJSON_Delete(ncer);
|
||||||
return jsonString;
|
return jsonString;
|
||||||
|
@ -100,9 +100,12 @@ struct Cell {
|
|||||||
struct JsonToCellOptions {
|
struct JsonToCellOptions {
|
||||||
bool labelEnabled;
|
bool labelEnabled;
|
||||||
bool extended;
|
bool extended;
|
||||||
|
bool partitionEnabled;
|
||||||
int mappingType;
|
int mappingType;
|
||||||
int cellCount;
|
int cellCount;
|
||||||
struct Cell **cells;
|
struct Cell **cells;
|
||||||
|
int *partitionData;
|
||||||
|
int partitionCount;
|
||||||
char **labels;
|
char **labels;
|
||||||
int labelCount;
|
int labelCount;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user