Merge pull request #522 from red031000/master

nitrogfx upgrades
This commit is contained in:
Akira Akashi 2023-07-04 21:08:52 +01:00 committed by GitHub
commit d16888ebe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 991 additions and 376 deletions

View File

@ -1,6 +1,5 @@
narc_0000.NCLR
narc_0001.NANR
narc_0003.NANR
*.NANR
*.NCER
narc_0007.NCGR
narc_0008.NCGR

View File

@ -1,46 +1,36 @@
{
"labelEnabled": true,
"sequenceCount": 2,
"frameCount": 2,
"sequences": [
{
"frameCount": 1,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 1,
"frameData": [
{
"frameDelay": 1,
"resultId": 0
}
]
},
{
"frameCount": 1,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 1,
"frameData": [
{
"frameDelay": 1,
"resultId": 1
}
]
}
],
"animationResults": [
{
"resultType": 0,
"index": 0
},
{
"resultType": 0,
"index": 1
}
],
"resultCount": 2,
"labels": ["CellAnime0", "CellAnime1"],
"labelCount": 2
}
"labelEnabled": true,
"sequenceCount": 2,
"frameCount": 2,
"sequences": [{
"frameCount": 1,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 1,
"frameData": [{
"frameDelay": 1,
"resultId": 0
}]
}, {
"frameCount": 1,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 1,
"frameData": [{
"frameDelay": 1,
"resultId": 1
}]
}],
"animationResults": [{
"resultType": 0,
"index": 0
}, {
"resultType": 0,
"index": 1
}],
"resultCount": 2,
"labels": ["CellAnime0", "CellAnime1"],
"labelCount": 2
}

View File

@ -1,68 +1,75 @@
{
"labelEnabled": true,
"extended": true,
"imageHeight": 32,
"imageWidth": 32,
"cellCount": 2,
"mappingType": 0,
"cells": [
{
"readOnly": 2054,
"maxX": 15,
"maxY": 15,
"minX": 65520,
"minY": 65520,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
"labelEnabled": true,
"extended": true,
"cellCount": 2,
"mappingType": 0,
"cells": [{
"cellAttrs": {
"hFlip": false,
"vFlip": false,
"hvFlip": false,
"boundingRect": true,
"boundingSphereRadius": 6
},
"maxX": 15,
"maxY": 15,
"minX": -16,
"minY": -16,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
},
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
},
"Attr2": {
"CharName": 0,
"Priority": 0,
"Palette": 0
"Attr2": {
"CharName": 0,
"Priority": 0,
"Palette": 0
}
}
},
{
"readOnly": 2054,
"maxX": 15,
"maxY": 15,
"minX": 65520,
"minY": 65520,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
}, {
"cellAttrs": {
"hFlip": false,
"vFlip": false,
"hvFlip": false,
"boundingRect": true,
"boundingSphereRadius": 6
},
"maxX": 15,
"maxY": 15,
"minX": -16,
"minY": -16,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
},
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
},
"Attr2": {
"CharName": 16,
"Priority": 0,
"Palette": 0
"Attr2": {
"CharName": 16,
"Priority": 0,
"Palette": 0
}
}
}
],
"labels": ["CellAnime0", "CellAnime1"],
"labelCount": 2
}
}],
"labels": ["CellAnime0", "CellAnime1"],
"labelCount": 2
}

View File

@ -1,140 +1,109 @@
{
"labelEnabled": true,
"sequenceCount": 6,
"frameCount": 12,
"sequences": [
{
"frameCount": 1,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 1,
"frameData": [
{
"frameDelay": 1,
"resultId": 0
}
]
},
{
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [
{
"frameDelay": 4,
"resultId": 0
},
{
"frameDelay": 4,
"resultId": 1
}
]
},
{
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [
{
"frameDelay": 6,
"resultId": 0
},
{
"frameDelay": 6,
"resultId": 1
}
]
},
{
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [
{
"frameDelay": 12,
"resultId": 0
},
{
"frameDelay": 12,
"resultId": 1
}
]
},
{
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [
{
"frameDelay": 20,
"resultId": 0
},
{
"frameDelay": 20,
"resultId": 1
}
]
},
{
"frameCount": 3,
"loopStartFrame": 0,
"animationElement": 2,
"animationType": 1,
"playbackMode": 2,
"frameData": [
{
"frameDelay": 32,
"resultId": 2
},
{
"frameDelay": 2,
"resultId": 3
},
{
"frameDelay": 2,
"resultId": 4
}
]
}
],
"animationResults": [
{
"resultType": 0,
"index": 0
},
{
"resultType": 0,
"index": 1
},
{
"resultType": 2,
"index": 0,
"positionX": 0,
"positionY": 0
},
{
"resultType": 2,
"index": 0,
"positionX": 1,
"positionY": 0
},
{
"resultType": 2,
"index": 0,
"positionX": -1,
"positionY": 0
}
],
"resultCount": 5,
"labels": ["CellAnime0", "CellAnime1", "CellAnime2", "CellAnime3", "CellAnime4", "CellAnime5"],
"labelCount": 6
"labelEnabled": true,
"sequenceCount": 6,
"frameCount": 12,
"sequences": [{
"frameCount": 1,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 1,
"frameData": [{
"frameDelay": 1,
"resultId": 0
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 4,
"resultId": 0
}, {
"frameDelay": 4,
"resultId": 1
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 6,
"resultId": 0
}, {
"frameDelay": 6,
"resultId": 1
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 12,
"resultId": 0
}, {
"frameDelay": 12,
"resultId": 1
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 20,
"resultId": 0
}, {
"frameDelay": 20,
"resultId": 1
}]
}, {
"frameCount": 3,
"loopStartFrame": 0,
"animationElement": 2,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 32,
"resultId": 2
}, {
"frameDelay": 2,
"resultId": 3
}, {
"frameDelay": 2,
"resultId": 4
}]
}],
"animationResults": [{
"resultType": 0,
"index": 0
}, {
"resultType": 0,
"index": 1
}, {
"resultType": 2,
"index": 0,
"positionX": 0,
"positionY": 0
}, {
"resultType": 2,
"index": 0,
"positionX": 1,
"positionY": 0
}, {
"resultType": 2,
"index": 0,
"positionX": -1,
"positionY": 0
}],
"resultCount": 5,
"labels": ["CellAnime0", "CellAnime1", "CellAnime2", "CellAnime3", "CellAnime4", "CellAnime5"],
"labelCount": 6
}

View File

@ -1,68 +1,75 @@
{
"labelEnabled": true,
"extended": true,
"imageHeight": 32,
"imageWidth": 32,
"cellCount": 2,
"mappingType": 0,
"cells": [
{
"readOnly": 2054,
"maxX": 15,
"maxY": 15,
"minX": 65520,
"minY": 65520,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
"labelEnabled": true,
"extended": true,
"cellCount": 2,
"mappingType": 0,
"cells": [{
"cellAttrs": {
"hFlip": false,
"vFlip": false,
"hvFlip": false,
"boundingRect": true,
"boundingSphereRadius": 6
},
"maxX": 15,
"maxY": 15,
"minX": -16,
"minY": -16,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
},
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
},
"Attr2": {
"CharName": 0,
"Priority": 0,
"Palette": 0
"Attr2": {
"CharName": 0,
"Priority": 0,
"Palette": 0
}
}
},
{
"readOnly": 2054,
"maxX": 15,
"maxY": 15,
"minX": 65520,
"minY": 65520,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
}, {
"cellAttrs": {
"hFlip": false,
"vFlip": false,
"hvFlip": false,
"boundingRect": true,
"boundingSphereRadius": 6
},
"maxX": 15,
"maxY": 15,
"minX": -16,
"minY": -16,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
},
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
},
"Attr2": {
"CharName": 16,
"Priority": 0,
"Palette": 0
"Attr2": {
"CharName": 16,
"Priority": 0,
"Palette": 0
}
}
}
],
"labels": ["CellAnime0", "CellAnime1", "CellAnime2", "CellAnime3", "CellAnime4", "CellAnime5"],
"labelCount": 6
}
}],
"labels": ["CellAnime0", "CellAnime1", "CellAnime2", "CellAnime3", "CellAnime4", "CellAnime5"],
"labelCount": 6
}

View File

@ -0,0 +1,109 @@
{
"labelEnabled": true,
"sequenceCount": 6,
"frameCount": 12,
"sequences": [{
"frameCount": 1,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 1,
"frameData": [{
"frameDelay": 1,
"resultId": 0
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 4,
"resultId": 0
}, {
"frameDelay": 4,
"resultId": 1
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 6,
"resultId": 0
}, {
"frameDelay": 6,
"resultId": 1
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 12,
"resultId": 0
}, {
"frameDelay": 12,
"resultId": 1
}]
}, {
"frameCount": 2,
"loopStartFrame": 0,
"animationElement": 0,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 20,
"resultId": 0
}, {
"frameDelay": 20,
"resultId": 1
}]
}, {
"frameCount": 3,
"loopStartFrame": 0,
"animationElement": 2,
"animationType": 1,
"playbackMode": 2,
"frameData": [{
"frameDelay": 32,
"resultId": 2
}, {
"frameDelay": 2,
"resultId": 3
}, {
"frameDelay": 2,
"resultId": 4
}]
}],
"animationResults": [{
"resultType": 0,
"index": 0
}, {
"resultType": 0,
"index": 1
}, {
"resultType": 2,
"index": 0,
"positionX": 0,
"positionY": 0
}, {
"resultType": 2,
"index": 0,
"positionX": 1,
"positionY": 0
}, {
"resultType": 2,
"index": 0,
"positionX": -1,
"positionY": 0
}],
"resultCount": 5,
"labels": ["CellAnime0", "CellAnime1", "CellAnime2", "CellAnime3", "CellAnime4", "CellAnime5"],
"labelCount": 6
}

View File

@ -1,68 +1,75 @@
{
"labelEnabled": true,
"extended": true,
"imageHeight": 32,
"imageWidth": 32,
"cellCount": 2,
"mappingType": 1,
"cells": [
{
"readOnly": 2054,
"maxX": 15,
"maxY": 15,
"minX": 65520,
"minY": 65520,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
"labelEnabled": true,
"extended": true,
"cellCount": 2,
"mappingType": 1,
"cells": [{
"cellAttrs": {
"hFlip": false,
"vFlip": false,
"hvFlip": false,
"boundingRect": true,
"boundingSphereRadius": 6
},
"maxX": 15,
"maxY": 15,
"minX": -16,
"minY": -16,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
},
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
},
"Attr2": {
"CharName": 0,
"Priority": 0,
"Palette": 0
"Attr2": {
"CharName": 0,
"Priority": 0,
"Palette": 0
}
}
},
{
"readOnly": 2054,
"maxX": 15,
"maxY": 15,
"minX": 65520,
"minY": 65520,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
}, {
"cellAttrs": {
"hFlip": false,
"vFlip": false,
"hvFlip": false,
"boundingRect": true,
"boundingSphereRadius": 6
},
"maxX": 15,
"maxY": 15,
"minX": -16,
"minY": -16,
"OAM": {
"Attr0": {
"YCoordinate": 240,
"Rotation": false,
"SizeDisable": false,
"Mode": 0,
"Mosaic": false,
"Colours": 16,
"Shape": 0
},
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
"Attr1": {
"XCoordinate": 496,
"RotationScaling": 0,
"Size": 2
},
"Attr2": {
"CharName": 8,
"Priority": 0,
"Palette": 0
"Attr2": {
"CharName": 8,
"Priority": 0,
"Palette": 0
}
}
}
],
"labels": ["CellAnime0", "CellAnime1", "CellAnime2", "CellAnime3", "CellAnime4", "CellAnime5"],
"labelCount": 6
}
}],
"labels": ["CellAnime0", "CellAnime1", "CellAnime2", "CellAnime3", "CellAnime4", "CellAnime5"],
"labelCount": 6
}

View File

@ -2675,6 +2675,7 @@ files/poketool/icongra/poke_icon.narc: \
files/poketool/icongra/poke_icon/narc_0002.NCER \
files/poketool/icongra/poke_icon/narc_0003.NANR \
files/poketool/icongra/poke_icon/narc_0004.NCER \
files/poketool/icongra/poke_icon/narc_0005.NANR \
files/poketool/icongra/poke_icon/narc_0006.NCER \
files/poketool/icongra/poke_icon/narc_0007.NCGR \
files/poketool/icongra/poke_icon/narc_0008.NCGR \

View File

@ -1213,4 +1213,5 @@ NCER_CLEAN_LIST := files/poketool/icongra/poke_icon/narc_0002.NCER \
files/poketool/icongra/poke_icon/narc_0006.NCER
NANR_CLEAN_LIST := files/poketool/icongra/poke_icon/narc_0001.NANR \
files/poketool/icongra/poke_icon/narc_0003.NANR
files/poketool/icongra/poke_icon/narc_0003.NANR \
files/poketool/icongra/poke_icon/narc_0005.NANR

View File

@ -774,6 +774,135 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, in
fclose(fp);
}
void ReadNtrCell(char *path, struct JsonToCellOptions *options)
{
int fileSize;
unsigned char *data = ReadWholeFile(path, &fileSize);
if (memcmp(data, "RECN", 4) != 0) //NCER
{
FATAL_ERROR("Not a valid NCER cell file.\n");
}
options->labelEnabled = data[0xE] != 1;
if (memcmp(data + 0x10, "KBEC", 4) != 0 ) //KBEC
{
FATAL_ERROR("Not a valid KBEC cell file.\n");
}
options->cellCount = data[0x18] | (data[0x19] << 8);
options->extended = data[0x1A] == 1;
if (!options->extended)
{
FATAL_ERROR("Don't know how to deal with not extended yet, bug red031000.\n");
}
options->mappingType = data[0x20];
options->cells = malloc(sizeof(struct Cell *) * options->cellCount);
for (int i = 0; i < options->cellCount; i++)
{
int offset = 0x30 + (i * 0x10);
options->cells[i] = malloc(sizeof(struct Cell));
short cellAttrs = data[offset + 2] | (data[offset + 3] << 8);
options->cells[i]->attributes.hFlip = (cellAttrs >> 8) & 1;
options->cells[i]->attributes.vFlip = (cellAttrs >> 9) & 1;
options->cells[i]->attributes.hvFlip = (cellAttrs >> 10) & 1;
options->cells[i]->attributes.boundingRect = (cellAttrs >> 11) & 1;
options->cells[i]->attributes.boundingSphereRadius = cellAttrs & 0x3F;
options->cells[i]->maxX = data[offset + 8] | (data[offset + 9] << 8);
options->cells[i]->maxY = data[offset + 10] | (data[offset + 11] << 8);
options->cells[i]->minX = data[offset + 12] | (data[offset + 13] << 8);
options->cells[i]->minY = data[offset + 14] | (data[offset + 15] << 8);
}
for (int i = 0; i < options->cellCount; i++)
{
int offset = 0x30 + (options->cellCount * 0x10) + (i * 0x6);
//Attr0
//bits 0-7 Y coordinate
options->cells[i]->oam.attr0.YCoordinate = data[offset];
//bit 8 rotation
options->cells[i]->oam.attr0.Rotation = data[offset + 1] & 1;
//bit 9 Obj Size (if rotation) or Obj Disable (if not rotation)
options->cells[i]->oam.attr0.SizeDisable = (data[offset + 1] >> 1) & 1;
//bits 10-11 Obj Mode
options->cells[i]->oam.attr0.Mode = (data[offset + 1] >> 2) & 3;
//bit 12 Obj Mosaic
options->cells[i]->oam.attr0.Mosaic = (data[offset + 1] >> 4) & 1;
//bit 13 Colours
options->cells[i]->oam.attr0.Colours = ((data[offset + 1] >> 5) & 1) == 0 ? 16 : 256;
//bits 14-15 Obj Shape
options->cells[i]->oam.attr0.Shape = (data[offset + 1] >> 6) & 3;
//Attr1
//bits 0-8 X coordinate
options->cells[i]->oam.attr1.XCoordinate = data[offset + 2] | ((data[offset + 3] & 1) << 8);
//bits 9-13 Rotation and scaling (if rotation) bit 12 Horizontal flip, bit 13 Vertical flip (if not rotation)
options->cells[i]->oam.attr1.RotationScaling = (data[offset + 3] >> 1) & 0x1F;
//bits 14-15 Obj Size
options->cells[i]->oam.attr1.Size = (data[offset + 3] >> 6) & 3;
//Attr2
//bits 0-9 Character Name?
options->cells[i]->oam.attr2.CharName = data[offset + 4] | ((data[offset + 5] & 3) << 8);
//bits 10-11 Priority
options->cells[i]->oam.attr2.Priority = (data[offset + 5] >> 2) & 3;
//bits 12-15 Palette Number
options->cells[i]->oam.attr2.Palette = (data[offset + 5] >> 4) & 0xF;
}
if (options->labelEnabled)
{
int count = 0;
int offset = 0x30 + (options->cellCount * 0x16) + 0x8;
bool flag = false;
//this entire thing is a huge assumption, it will not work with labels that are less than 2 characters long
while (!flag)
{
if (strlen((char *) data + offset) < 2)
{
//probably a pointer, maybe?
count++;
offset += 4;
}
else
{
//huzzah a string
flag = true;
}
}
options->labelCount = count;
options->labels = malloc(sizeof(char *) * count);
for (int i = 0; i < count; i++)
{
options->labels[i] = malloc(strlen((char *) data + offset) + 1);
strcpy(options->labels[i], (char *) data + offset);
offset += strlen(options->labels[i]) + 1;
}
//after this should be txeu, if everything was done right
}
free(data);
}
void WriteNtrCell(char *path, struct JsonToCellOptions *options)
{
FILE *fp = fopen(path, "wb");
@ -828,8 +957,11 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
for (i = 0; i < options->cellCount * 0x10; i += 0x10)
{
KBECContents[i] = 0x01; //number of images
KBECContents[i + 2] = options->cells[i / 0x10]->readOnly & 0xff; //unknown
KBECContents[i + 3] = options->cells[i / 0x10]->readOnly >> 8;
short cellAttrs = (options->cells[i / 0x10]->attributes.hFlip << 8) | (options->cells[i / 0x10]->attributes.vFlip << 9)
| (options->cells[i / 0x10]->attributes.hvFlip << 10) | (options->cells[i / 0x10]->attributes.boundingRect << 11)
| (options->cells[i / 0x10]->attributes.boundingSphereRadius & 0x3F);
KBECContents[i + 2] = cellAttrs & 0xff; //cell attributes
KBECContents[i + 3] = cellAttrs >> 8;
KBECContents[i + 4] = (i / 0x10 * 6) & 0xff; //pointer to OAM data
KBECContents[i + 5] = (i / 0x10 * 6) >> 8; //unlikely to be more than 16 bits, but there are 32 allocated, change if necessary
KBECContents[i + 8] = options->cells[i / 0x10]->maxX & 0xff; //maxX
@ -982,6 +1114,184 @@ void WriteNtrScreen(char *path, struct JsonToScreenOptions *options)
fclose(fp);
}
void ReadNtrAnimation(char *path, struct JsonToAnimationOptions *options)
{
int fileSize;
unsigned char *data = ReadWholeFile(path, &fileSize);
if (memcmp(data, "RNAN", 4) != 0 && memcmp(data, "RAMN", 4) != 0) //NANR/NMAR
{
FATAL_ERROR("Not a valid NANR/NMAR animation file.\n");
}
options->labelEnabled = data[0xE] != 1;
if (memcmp(data + 0x10, "KNBA", 4) != 0 ) //ABNK
{
FATAL_ERROR("Not a valid ABNK animation file.\n");
}
options->sequenceCount = data[0x18] | (data[0x19] << 8);
options->frameCount = data[0x1A] | (data[0x1B] << 8);
options->sequenceData = malloc(sizeof(struct SequenceData *) * options->sequenceCount);
for (int i = 0; i < options->sequenceCount; i++)
{
options->sequenceData[i] = malloc(sizeof(struct SequenceData));
}
int offset = 0x30;
unsigned int *frameOffsets = malloc(sizeof(unsigned int) * options->sequenceCount);
for (int i = 0; i < options->sequenceCount; i++, offset += 0x10)
{
options->sequenceData[i]->frameCount = data[offset] | (data[offset + 1] << 8);
options->sequenceData[i]->loopStartFrame = data[offset + 2] | (data[offset + 3] << 8);
options->sequenceData[i]->animationElement = data[offset + 4] | (data[offset + 5] << 8);
options->sequenceData[i]->animationType = data[offset + 6] | (data[offset + 7] << 8);
options->sequenceData[i]->playbackMode = data[offset + 8] | (data[offset + 9] << 8) | (data[offset + 10] << 16) | (data[offset + 11] << 24);
frameOffsets[i] = data[offset + 12] | (data[offset + 13] << 8) | (data[offset + 14] << 16) | (data[offset + 15] << 24);
options->sequenceData[i]->frameData = malloc(sizeof(struct FrameData *) * options->sequenceData[i]->frameCount);
for (int j = 0; j < options->sequenceData[i]->frameCount; j++)
{
options->sequenceData[i]->frameData[j] = malloc(sizeof(struct FrameData));
}
}
int *resultOffsets = malloc(sizeof(int) * options->frameCount);
memset(resultOffsets, -1, sizeof(int) * options->frameCount);
for (int i = 0; i < options->sequenceCount; i++)
{
for (int j = 0; j < options->sequenceData[i]->frameCount; j++)
{
int frameOffset = offset + frameOffsets[i] + j * 0x8;
options->sequenceData[i]->frameData[j]->resultOffset = data[frameOffset] | (data[frameOffset + 1] << 8) | (data[frameOffset + 2] << 16) | (data[frameOffset + 3] << 24);
options->sequenceData[i]->frameData[j]->frameDelay = data[frameOffset + 4] | (data[frameOffset + 5] << 8);
//0xBEEF
//the following is messy
bool present = false;
//check for offset in array
for (int k = 0; k < options->frameCount; k++)
{
if (resultOffsets[k] == options->sequenceData[i]->frameData[j]->resultOffset)
{
present = true;
break;
}
}
//add data if not present
if (!present)
{
for (int k = 0; i < options->frameCount; k++)
{
if (resultOffsets[k] == -1)
{
resultOffsets[k] = options->sequenceData[i]->frameData[j]->resultOffset;
break;
}
}
}
}
}
free(frameOffsets);
offset = 0x18 + (data[0x24] | (data[0x25] << 8) | (data[0x26] << 16) | (data[0x27] << 24)); //start of animation results
int k;
for (k = 0; k < options->frameCount; k++)
{
if (resultOffsets[k] == -1)
break;
}
options->resultCount = k;
free(resultOffsets);
options->animationResults = malloc(sizeof(struct AnimationResults *) * options->resultCount);
for (int i = 0; i < options->resultCount; i++)
{
options->animationResults[i] = malloc(sizeof(struct AnimationResults));
}
int resultOffset = 0;
for (int i = 0; i < options->resultCount; i++)
{
if (data[offset + 2] == 0xCC && data[offset + 3] == 0xCC)
{
options->animationResults[i]->resultType = 0;
}
else if (data[offset + 2] == 0xEF && data[offset + 3] == 0xBE)
{
options->animationResults[i]->resultType = 2;
}
else
{
options->animationResults[i]->resultType = 1;
}
for (int j = 0; j < options->sequenceCount; j++)
{
for (int k = 0; k < options->sequenceData[j]->frameCount; k++)
{
if (options->sequenceData[j]->frameData[k]->resultOffset == resultOffset)
{
options->sequenceData[j]->frameData[k]->resultId = i;
}
}
}
switch (options->animationResults[i]->resultType)
{
case 0: //index
options->animationResults[i]->index = data[offset] | (data[offset + 1] << 8);
resultOffset += 0x4;
offset += 0x4;
break;
case 1: //SRT
options->animationResults[i]->dataSrt.index = data[offset] | (data[offset + 1] << 8);
options->animationResults[i]->dataSrt.rotation = data[offset + 2] | (data[offset + 3] << 8);
options->animationResults[i]->dataSrt.scaleX = data[offset + 4] | (data[offset + 5] << 8) | (data[offset + 6] << 16) | (data[offset + 7] << 24);
options->animationResults[i]->dataSrt.scaleY = data[offset + 8] | (data[offset + 9] << 8) | (data[offset + 10] << 16) | (data[offset + 11] << 24);
options->animationResults[i]->dataSrt.positionX = data[offset + 12] | (data[offset + 13] << 8);
options->animationResults[i]->dataSrt.positionY = data[offset + 14] | (data[offset + 15] << 8);
resultOffset += 0x10;
offset += 0x10;
break;
case 2: //T
options->animationResults[i]->dataT.index = data[offset] | (data[offset + 1] << 8);
options->animationResults[i]->dataT.positionX = data[offset + 4] | (data[offset + 5] << 8);
options->animationResults[i]->dataT.positionY = data[offset + 6] | (data[offset + 7] << 8);
resultOffset += 0x8;
offset += 0x8;
break;
}
}
if (options->labelEnabled)
{
options->labelCount = options->sequenceCount; //*should* be the same
options->labels = malloc(sizeof(char *) * options->labelCount);
offset += 0x8 + options->labelCount * 0x4; //skip to label data
for (int i = 0; i < options->labelCount; i++)
{
options->labels[i] = malloc(strlen((char *)data + offset) + 1);
strcpy(options->labels[i], (char *)data + offset);
offset += strlen((char *)data + offset) + 1;
}
}
free(data);
}
void WriteNtrAnimation(char *path, struct JsonToAnimationOptions *options)
{
FILE *fp = fopen(path, "wb");
@ -1137,8 +1447,6 @@ void WriteNtrAnimation(char *path, struct JsonToAnimationOptions *options)
case 2:
KBNAContents[resPtrCounter] = options->animationResults[k]->dataT.index & 0xff;
KBNAContents[resPtrCounter + 1] = options->animationResults[k]->dataT.index >> 8;
//KBNAContents[resPtrCounter + 2] = options->animationResults[k]->dataT.rotation & 0xff;
//KBNAContents[resPtrCounter + 3] = options->animationResults[k]->dataT.rotation >> 8;
KBNAContents[resPtrCounter + 2] = 0xEF;
KBNAContents[resPtrCounter + 3] = 0xBE;
KBNAContents[resPtrCounter + 4] = options->animationResults[k]->dataT.positionX & 0xff;

View File

@ -40,8 +40,10 @@ void ReadGbaPalette(char *path, struct Palette *palette);
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIndex);
void WriteGbaPalette(char *path, struct Palette *palette);
void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum);
void ReadNtrCell(char *path, struct JsonToCellOptions *options);
void WriteNtrCell(char *path, struct JsonToCellOptions *options);
void WriteNtrScreen(char *path, struct JsonToScreenOptions *options);
void ReadNtrAnimation(char *path, struct JsonToAnimationOptions *options);
void WriteNtrAnimation(char *path, struct JsonToAnimationOptions *options);
#endif // GFX_H

View File

@ -48,15 +48,11 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
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");
cJSON *mappingType = cJSON_GetObjectItemCaseSensitive(json, "mappingType");
options->labelEnabled = GetBool(labelBool);
options->extended = GetBool(extended);
options->imageHeight = GetInt(imageHeight);
options->imageWidth = GetInt(imageWidth);
options->cellCount = GetInt(cellCount);
options->mappingType = GetInt(mappingType);
@ -95,9 +91,24 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
if (i > options->cellCount - 1)
FATAL_ERROR("Cell count is incorrect.\n");
cJSON *readOnly = cJSON_GetObjectItemCaseSensitive(cell, "readOnly");
cJSON *cellAttrs = cJSON_GetObjectItemCaseSensitive(cell, "cellAttrs");
cJSON *hFlip = cJSON_GetObjectItemCaseSensitive(cellAttrs, "hFlip");
cJSON *vFlip = cJSON_GetObjectItemCaseSensitive(cellAttrs, "vFlip");
cJSON *hvFlip = cJSON_GetObjectItemCaseSensitive(cellAttrs, "hvFlip");
options->cells[i]->attributes.hFlip = GetBool(hFlip);
options->cells[i]->attributes.vFlip = GetBool(vFlip);
options->cells[i]->attributes.hvFlip = GetBool(hvFlip);
cJSON *boundingRect = cJSON_GetObjectItemCaseSensitive(cellAttrs, "boundingRect");
options->cells[i]->attributes.boundingRect = GetBool(boundingRect);
cJSON *boundingSphereRadius = cJSON_GetObjectItemCaseSensitive(cellAttrs, "boundingSphereRadius");
options->cells[i]->attributes.boundingSphereRadius = GetInt(boundingSphereRadius);
options->cells[i]->readOnly = (short)GetInt(readOnly);
if (options->extended)
{
cJSON *maxX = cJSON_GetObjectItemCaseSensitive(cell, "maxX");
@ -162,6 +173,76 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
return options;
}
char *GetNCERJson(struct JsonToCellOptions *options)
{
cJSON *ncer = cJSON_CreateObject();
cJSON_AddBoolToObject(ncer, "labelEnabled", options->labelEnabled);
cJSON_AddBoolToObject(ncer, "extended", options->extended);
cJSON_AddNumberToObject(ncer, "cellCount", options->cellCount);
cJSON_AddNumberToObject(ncer, "mappingType", options->mappingType);
cJSON *cells = cJSON_AddArrayToObject(ncer, "cells");
for (int i = 0; i < options->cellCount; i++)
{
cJSON *cell = cJSON_CreateObject();
cJSON *cellAttrs = cJSON_AddObjectToObject(cell, "cellAttrs");
cJSON_AddBoolToObject(cellAttrs, "hFlip", options->cells[i]->attributes.hFlip);
cJSON_AddBoolToObject(cellAttrs, "vFlip", options->cells[i]->attributes.vFlip);
cJSON_AddBoolToObject(cellAttrs, "hvFlip", options->cells[i]->attributes.hvFlip);
cJSON_AddBoolToObject(cellAttrs, "boundingRect", options->cells[i]->attributes.boundingRect);
cJSON_AddNumberToObject(cellAttrs, "boundingSphereRadius", options->cells[i]->attributes.boundingSphereRadius);
if (options->extended)
{
cJSON_AddNumberToObject(cell, "maxX", options->cells[i]->maxX);
cJSON_AddNumberToObject(cell, "maxY", options->cells[i]->maxY);
cJSON_AddNumberToObject(cell, "minX", options->cells[i]->minX);
cJSON_AddNumberToObject(cell, "minY", options->cells[i]->minY);
}
cJSON *OAM = cJSON_AddObjectToObject(cell, "OAM");
cJSON *Attr0 = cJSON_AddObjectToObject(OAM, "Attr0");
cJSON_AddNumberToObject(Attr0, "YCoordinate", options->cells[i]->oam.attr0.YCoordinate);
cJSON_AddBoolToObject(Attr0, "Rotation", options->cells[i]->oam.attr0.Rotation);
cJSON_AddBoolToObject(Attr0, "SizeDisable", options->cells[i]->oam.attr0.SizeDisable);
cJSON_AddNumberToObject(Attr0, "Mode", options->cells[i]->oam.attr0.Mode);
cJSON_AddBoolToObject(Attr0, "Mosaic", options->cells[i]->oam.attr0.Mosaic);
cJSON_AddNumberToObject(Attr0, "Colours", options->cells[i]->oam.attr0.Colours);
cJSON_AddNumberToObject(Attr0, "Shape", options->cells[i]->oam.attr0.Shape);
cJSON *Attr1 = cJSON_AddObjectToObject(OAM, "Attr1");
cJSON_AddNumberToObject(Attr1, "XCoordinate", options->cells[i]->oam.attr1.XCoordinate);
cJSON_AddNumberToObject(Attr1, "RotationScaling", options->cells[i]->oam.attr1.RotationScaling);
cJSON_AddNumberToObject(Attr1, "Size", options->cells[i]->oam.attr1.Size);
cJSON *Attr2 = cJSON_AddObjectToObject(OAM, "Attr2");
cJSON_AddNumberToObject(Attr2, "CharName", options->cells[i]->oam.attr2.CharName);
cJSON_AddNumberToObject(Attr2, "Priority", options->cells[i]->oam.attr2.Priority);
cJSON_AddNumberToObject(Attr2, "Palette", options->cells[i]->oam.attr2.Palette);
cJSON_AddItemToArray(cells, cell);
}
if (options->labelEnabled)
{
cJSON *labels = cJSON_CreateStringArray((const char * const*)options->labels, options->labelCount);
cJSON_AddItemToObject(ncer, "labels", labels);
cJSON_AddNumberToObject(ncer, "labelCount", options->labelCount);
}
char *jsonString = cJSON_Print(ncer);
cJSON_Delete(ncer);
return jsonString;
}
struct JsonToScreenOptions *ParseNSCRJson(char *path)
{
int fileLength;
@ -400,6 +481,85 @@ struct JsonToAnimationOptions *ParseNANRJson(char *path)
return options;
}
char *GetNANRJson(struct JsonToAnimationOptions *options)
{
cJSON *nanr = cJSON_CreateObject();
cJSON_AddBoolToObject(nanr, "labelEnabled", options->labelEnabled);
cJSON_AddNumberToObject(nanr, "sequenceCount", options->sequenceCount);
cJSON_AddNumberToObject(nanr, "frameCount", options->frameCount);
cJSON *sequences = cJSON_AddArrayToObject(nanr, "sequences");
for (int i = 0; i < options->sequenceCount; i++)
{
cJSON *sequence = cJSON_CreateObject();
cJSON_AddNumberToObject(sequence, "frameCount", options->sequenceData[i]->frameCount);
cJSON_AddNumberToObject(sequence, "loopStartFrame", options->sequenceData[i]->loopStartFrame);
cJSON_AddNumberToObject(sequence, "animationElement", options->sequenceData[i]->animationElement);
cJSON_AddNumberToObject(sequence, "animationType", options->sequenceData[i]->animationType);
cJSON_AddNumberToObject(sequence, "playbackMode", options->sequenceData[i]->playbackMode);
cJSON *frameData = cJSON_AddArrayToObject(sequence, "frameData");
for (int j = 0; j < options->sequenceData[i]->frameCount; j++)
{
cJSON *frame = cJSON_CreateObject();
cJSON_AddNumberToObject(frame, "frameDelay", options->sequenceData[i]->frameData[j]->frameDelay);
cJSON_AddNumberToObject(frame, "resultId", options->sequenceData[i]->frameData[j]->resultId);
cJSON_AddItemToArray(frameData, frame);
}
cJSON_AddItemToArray(sequences, sequence);
}
cJSON *animationResults = cJSON_AddArrayToObject(nanr, "animationResults");
for (int i = 0; i < options->resultCount; i++)
{
cJSON *animationResult = cJSON_CreateObject();
cJSON_AddNumberToObject(animationResult, "resultType", options->animationResults[i]->resultType);
switch (options->animationResults[i]->resultType)
{
case 0: //index
cJSON_AddNumberToObject(animationResult, "index", options->animationResults[i]->index);
break;
case 1: //SRT
cJSON_AddNumberToObject(animationResult, "index", options->animationResults[i]->dataSrt.index);
cJSON_AddNumberToObject(animationResult, "rotation", options->animationResults[i]->dataSrt.rotation);
cJSON_AddNumberToObject(animationResult, "scaleX", options->animationResults[i]->dataSrt.scaleX);
cJSON_AddNumberToObject(animationResult, "scaleY", options->animationResults[i]->dataSrt.scaleY);
cJSON_AddNumberToObject(animationResult, "positionX", options->animationResults[i]->dataSrt.positionX);
cJSON_AddNumberToObject(animationResult, "positionY", options->animationResults[i]->dataSrt.positionY);
break;
case 2: //T
cJSON_AddNumberToObject(animationResult, "index", options->animationResults[i]->dataT.index);
cJSON_AddNumberToObject(animationResult, "positionX", options->animationResults[i]->dataT.positionX);
cJSON_AddNumberToObject(animationResult, "positionY", options->animationResults[i]->dataT.positionY);
break;
}
cJSON_AddItemToArray(animationResults, animationResult);
}
cJSON_AddNumberToObject(nanr, "resultCount", options->resultCount);
if (options->labelEnabled)
{
cJSON *labels = cJSON_CreateStringArray((const char * const*)options->labels, options->labelCount);
cJSON_AddItemToObject(nanr, "labels", labels);
cJSON_AddNumberToObject(nanr, "labelCount", options->labelCount);
}
char *jsonString = cJSON_Print(nanr);
cJSON_Delete(nanr);
return jsonString;
}
void FreeNCERCell(struct JsonToCellOptions *options)
{
for (int i = 0; i < options->cellCount; i++)

View File

@ -6,8 +6,10 @@
#include "options.h"
struct JsonToCellOptions *ParseNCERJson(char *path);
char *GetNCERJson(struct JsonToCellOptions *options);
struct JsonToScreenOptions *ParseNSCRJson(char *path);
struct JsonToAnimationOptions *ParseNANRJson(char *path);
char *GetNANRJson(struct JsonToAnimationOptions *options);
void FreeNCERCell(struct JsonToCellOptions *options);
void FreeNSCRScreen(struct JsonToScreenOptions *options);
void FreeNANRAnimation(struct JsonToAnimationOptions *options);

View File

@ -768,6 +768,19 @@ void HandleJsonToNtrCellCommand(char *inputPath, char *outputPath, int argc UNUS
FreeNCERCell(options);
}
void HandleNtrCellToJsonCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct JsonToCellOptions *options = malloc(sizeof(struct JsonToCellOptions));
ReadNtrCell(inputPath, options);
char *json = GetNCERJson(options);
WriteWholeStringToFile(outputPath, json);
FreeNCERCell(options);
}
void HandleJsonToNtrScreenCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct JsonToScreenOptions *options;
@ -819,6 +832,19 @@ void HandleJsonToNtrAnimationCommand(char *inputPath, char *outputPath, int argc
FreeNANRAnimation(options);
}
void HandleNtrAnimationToJsonCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct JsonToAnimationOptions *options = malloc(sizeof(struct JsonToAnimationOptions));
ReadNtrAnimation(inputPath, options);
char *json = GetNANRJson(options);
WriteWholeStringToFile(outputPath, json);
FreeNANRAnimation(options);
}
void HandleJsonToNtrMulticellAnimationCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct JsonToAnimationOptions *options;
@ -1072,12 +1098,15 @@ int main(int argc, char **argv)
{ "1bpp", "png", HandleGbaToPngCommand },
{ "4bpp", "png", HandleGbaToPngCommand },
{ "8bpp", "png", HandleGbaToPngCommand },
{ "nbfc", "png", HandleGbaToPngCommand },
{ "NCGR", "png", HandleNtrToPngCommand },
{ "png", "1bpp", HandlePngToGbaCommand },
{ "png", "4bpp", HandlePngToGbaCommand },
{ "png", "nbfc", HandlePngToGbaCommand },
{ "png", "8bpp", HandlePngToGbaCommand },
{ "png", "NCGR", HandlePngToNtrCommand },
{ "png", "gbapal", HandlePngToGbaPaletteCommand },
{ "png", "nbfp", HandlePngToGbaPaletteCommand },
{ "png", "NCLR", HandlePngToNtrPaletteCommand },
{ "gbapal", "pal", HandleGbaToJascPaletteCommand },
{ "NCLR", "pal", HandleNtrToJascPaletteCommand },
@ -1091,9 +1120,12 @@ int main(int argc, char **argv)
{ "fwjpnfont", "png", HandleFullwidthJapaneseFontToPngCommand },
{ "png", "fwjpnfont", HandlePngToFullwidthJapaneseFontCommand },
{ "json", "NCER", HandleJsonToNtrCellCommand },
{ "NCER", "json", HandleNtrCellToJsonCommand },
{ "json", "NSCR", HandleJsonToNtrScreenCommand },
{ "json", "NANR", HandleJsonToNtrAnimationCommand },
{ "NANR", "json", HandleNtrAnimationToJsonCommand },
{ "json", "NMAR", HandleJsonToNtrMulticellAnimationCommand },
{ "NMAR", "json", HandleNtrAnimationToJsonCommand },
{ NULL, "huff", HandleHuffCompressCommand },
{ NULL, "lz", HandleLZCompressCommand },
{ "huff", NULL, HandleHuffDecompressCommand },

View File

@ -77,8 +77,16 @@ struct OAM {
struct Attr2 attr2;
};
struct CellAttributes {
bool hFlip; // 1 << 8
bool vFlip; // 1 << 9
bool hvFlip; // 1 << 10
bool boundingRect; // 1 << 11
int boundingSphereRadius; // 1 << 0 (6 bits);
};
struct Cell {
short readOnly;
struct CellAttributes attributes;
short maxX;
short maxY;
short minX;
@ -90,8 +98,6 @@ struct JsonToCellOptions {
bool labelEnabled;
bool extended;
int mappingType;
int imageHeight;
int imageWidth;
int cellCount;
struct Cell **cells;
char **labels;
@ -108,6 +114,7 @@ struct JsonToScreenOptions {
struct FrameData {
int resultId;
short frameDelay;
int resultOffset;
};
struct SequenceData {

View File

@ -111,6 +111,19 @@ unsigned char *ReadWholeFileZeroPadded(char *path, int *size, int padAmount)
return buffer;
}
void WriteWholeStringToFile(char *path, char *string)
{
FILE *fp = fopen(path, "wb");
if (fp == NULL)
FATAL_ERROR("Failed to open \"%s\" for writing.\n", path);
if (fputs(string, fp) == EOF)
FATAL_ERROR("Failed to write to \"%s\".\n", path);
fclose(fp);
}
void WriteWholeFile(char *path, void *buffer, int bufferSize)
{
FILE *fp = fopen(path, "wb");

View File

@ -10,6 +10,7 @@ bool ParseNumber(char *s, char **end, int radix, int *intValue);
char *GetFileExtension(char *path);
unsigned char *ReadWholeFile(char *path, int *size);
unsigned char *ReadWholeFileZeroPadded(char *path, int *size, int padAmount);
void WriteWholeStringToFile(char *path, char *string);
void WriteWholeFile(char *path, void *buffer, int bufferSize);
void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder, bool version101, uint16_t sectionCount);