This software and its source code (if available) are licensed under the Apache-2.0 license (unless otherwise specified) which DOES NOT APPLY to any third-party code (such as zlib for example) and borrowed Assembler code (ripped code from other software executable files).
#pragma pack(push, 1)
typedef struct {
char magic[8]; /* "Dr.gong~" */
uint16_t imgid; /* image id? */
uint16_t fmark; /* always 0xFFFF ? */
uint8_t data1;
uint8_t data2;
uint32_t data3;
uint32_t data4;
uint32_t width;
uint32_t height;
uint32_t data5;
uint32_t data6;
uint32_t data7;
uint32_t data8;
uint8_t data9;
uint32_t isize; /* packed image size */
} spr1head; /* 47 */
typedef struct {
char magic[8]; /* "Dr.gong~" */
uint8_t data1;
uint16_t data2;
uint8_t data3;
uint8_t data4;
uint8_t data5;
uint16_t count;
} spr2head; /* 16 */
typedef struct {
uint8_t data1;
uint8_t data2;
uint8_t count;
uint16_t data3;
} spr2data;
typedef struct {
uint32_t x1;
uint32_t y1;
uint32_t x2;
uint32_t y2;
uint32_t isize;
/*
uint8_t data[isize]; // image data
uint32_t data1;
uint32_t data2;
*/
} spr2item;
#pragma pack(pop)
int conv_spr(FILE *fl, uint32_t sz, char *f) {
uint32_t i, j, l, info[2];
spr1head head1;
spr2head head2;
spr2data data2;
spr2item item2;
uint8_t *p, t;
char s[260];
fseek(fl, 0, SEEK_SET);
readdata(fl, &head1, sizeof(head1));
fseek(fl, 0, SEEK_SET);
readdata(fl, &head2, sizeof(head2));
t = 0;
do {
if (!CheckMagic("Dr.gong~", head1.magic)) { break; }
if (
(sz > sizeof(head1)) &&
(head1.fmark == 0xFFFFU) && (head1.isize) &&
(head1.width) && (head1.height)
) {
t = 1;
break;
}
if (sz > sizeof(head2)) {
t = 2;
break;
}
} while (0);
if (!t) {
return(3);
}
if (t == 1) {
fseek(fl, sizeof(head1), SEEK_SET);
printf(
"%u 0x%02X 0x%02X 0x%02X | 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
head1.imgid,
head1.data1,
head1.data2,
head1.data9,
head1.data3,
head1.data4,
head1.data5,
head1.data6,
head1.data7,
head1.data8
);
l = sizeof(tga_head) + (head1.width * head1.height * 2);
p = (uint8_t *) malloc(head1.isize + l);
if (!p) {
return(4);
}
readdata(fl, p, head1.isize);
strcpy(s, f);
printf("%s -> ", s);
newext(s, ".tga");
printf("%s\n\n", s);
tga_init(&p[head1.isize], head1.width, head1.height);
spr_unpack(p, head1.isize, &p[head1.isize + sizeof(tga_head)], head1.width, head1.height);
dumpdata(s, &p[head1.isize], l);
free(p);
} else {
printf(
"0x%02X 0x%04X 0x%02X 0x%02X 0x%02X\n",
head2.data1,
head2.data2,
head2.data3,
head2.data4,
head2.data5
);
fseek(fl, sizeof(head2), SEEK_SET);
newext(f, "");
for (j = 0; j < head2.count; j++) {
readdata(fl, &data2, sizeof(data2));
printf("0x%02X 0x%02X 0x%04X\n", data2.data1, data2.data2, data2.data3);
for (i = 0; i < data2.count; i++) {
sprintf(s, "%s.%03u-%03u.tga", f, j + 1, i + 1);
readdata(fl, &item2, sizeof(item2));
head1.width = item2.x2 - item2.x1;
head1.height = item2.y2 - item2.y1;
l = sizeof(tga_head) + (head1.width * head1.height * 2);
p = (uint8_t *) malloc(item2.isize + l);
if (p) {
tga_init(&p[item2.isize], head1.width, head1.height);
readdata(fl, p, item2.isize);
spr_unpack(p, item2.isize, (uint8_t *) &p[item2.isize + sizeof(tga_head)], head1.width, head1.height);
dumpdata(s, &p[item2.isize], l);
free(p);
} else {
fseek(fl, ftell(fl) + item2.isize, SEEK_SET);
}
readdata(fl, &info, sizeof(info));
printf("%u %u %u %u | %u %u | %s\n", item2.x1, item2.y1, item2.x2, item2.y2, info[0], info[1], s);
}
}
}
return(0);
}