READ THE RULES: Click here

Follow us on Facebook: https://www.facebook.com/xentax/ :)

16x8 pixel tiled graphics (.tpl)

Get your graphics formats figures out here! Got details for others? Post here!
User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

16x8 pixel tiled graphics (.tpl)

Post by mugi » Fri Nov 08, 2013 9:19 pm

I'm moving my questions into the graphics section now as it appears my initial thought about these files was completely off and they are indeed not compressed, nor encrypted.

original thread here

the .tpl files are 16x8 pixel tiled graphics with a 256 color RGBA palette.

here's pretty much what i do know.


Image

Image

0x00: number of files
0x04: table start address
0x08: first file entry address
0x0C: palette entry address
0x10: second file entry address

0x18: vertical resolution (first file) [2byte value]
0x1A: horizontal resolution (first file) [2byte value]
0x1C: horizontal resolution (first file) [2byte value]

0x20: start address (first file)

0x2C: vertical resolution (second file) [2byte value]
0x2E: horizontal resolution (second file) [2byte value]
0x30: horizontal resolution (second file) [2byte value]

0x34: start address (second file)

0x40: palette color count [2byte value]
0x44: palette address


my goal is to get these files into a format i can actually edit, and then get the edited graphic back into the game.

could use any help possible as im at my very limits with this. My programming knowledge is a total ZERO, and this is the first time i've worked with tiled graphics.

grab the example file; egbg00 from HERE
Last edited by mugi on Sat Nov 09, 2013 1:13 pm, edited 2 times in total.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2730
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 675 times
Been thanked: 1407 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by shakotay2 » Sat Nov 09, 2013 11:36 am

mugi wrote:here's pretty much what i do know.
How did you get that pic? Which app, which params?

(Maybe in your formats description you should mention palette color count being a WORD value.)

I created a BM file header (360x480), appended the 1024 bytes palette and the first files data but the resulting bitmap looked scrambled again.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by mugi » Sat Nov 09, 2013 1:08 pm

added indicators for value sizes in first post :)

as for the image, i used tilemolester.

1-dimensional mode
8bpp linear
32bpp RGB palette (888)
offset 0x50
60x45 tiles (480x360 pixels resolution)

it looks distorted because tilemolester only allows using 8x8 tiles and the tiles in this format are 16x8 pixels.

edit: lol it appears i mixed up vertical and horizontal resolutions between eachother. Fixed this in first post too

my apologies, english isnt my first language :P

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2730
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 675 times
Been thanked: 1407 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by shakotay2 » Sat Nov 09, 2013 2:49 pm

your posts are fairly readable (though I'm not a native speaker, too :wink: )

But still I won't get it. Set codec to 8bpp linear, mode 1-D, canvas 60x45.
Always have a colored pic without the "fence" structure of yours.

The molester seems to reset palette format to 24 RGB (888) when loading the egbg00 file.

Where to set the offset? (I just tried a copy of egbg00 with the first 0x50 bytes cut off.)

Molester version is 0.16?
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by mugi » Sat Nov 09, 2013 3:12 pm

i dont know, maybe my copy of tilemolester is just bad :P (version.... 0.16 lol)

here's how it looks on my end.

/click for image

the settings are just as you put them, so it should look the same.

can you post an image of how it looks on your end ?

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2730
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 675 times
Been thanked: 1407 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by shakotay2 » Sat Nov 09, 2013 4:54 pm

this is what I get: Image

I'm pretty sure my copy of tm.jar is outdated (1/11/2005).

How do you get the dialogue window? I used every menu point: in vain.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by mugi » Sat Nov 09, 2013 5:02 pm

yours looks like a palette issue really, i get the same result without loading a palette.
and i see you dont have it loaded (correctly atleast) on your screenshot either.

use: [palette] -> [import from...] -> [this file]
to bring out the dialogue window for the palette. (you can see the settings on my picture, the address of the palette is entered as DEC)

i noticed that using the selections in the palette menu directly dont work 99% of the time.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2730
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 675 times
Been thanked: 1407 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by shakotay2 » Sat Nov 09, 2013 6:55 pm

aah, yep. Thx! :)

(The dialogue title "Import internal palette" is missing from your screenshot, is it? :D )

Interesting that the palette address is without the offset of 0x50.

Sadly when saving this the settings are not applied to the data. The saved file simply being a copy of egbg00.

(then I realized that you can use Edit Copy To...)

btw: how the hell did you figure out the settings? There are hundreds of possibilities... (:
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by mugi » Sat Nov 09, 2013 7:09 pm

i looked at the data and concluded that the values can't be anything else, and since then i got the resolution of the image from the data, and it started to shape up like an image a little.

a friend of mine looked at it and realized it's 16x8pixel tiles, and that's why it doesnt display correctly.
i dont understand tiled graphics at all so i wouldn't have ever figured that out by myself.

the rest was just raw data analyzing though. when you stare at it with hex editor enough, it'll start making sense.

im sort of hoping someone at the forum who knows their thing with stuff like this would whip up some kind of a converter for this format
(i noticed that a 256 color .tga uses an RGBA palette identical to this file)

i've been doing a ton of work on this, and the text regarding this game really. Since this morning i succesfully located, decompressed and reverse engineered the event scripts of the game too, and im very soon at the point where only thing preventing me from fully translating this game is the graphics that i yet, cant rebuild (or even extract correctly)

edit:

i found this: http://wiki.tockdom.com/wiki/TPL_%28File_Format%29

the tpl format used on wii seem largely similar, however, i noticed that atleast the image mode flags differ.
and that the tpl files i have at hand are completely void of file signature.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2730
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 675 times
Been thanked: 1407 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by shakotay2 » Mon Nov 11, 2013 1:02 pm

mugi wrote:[...]and that the tpl files i have at hand are completely void of file signature.
The format ID (05?) doesn't fit either.

How the data is organized in your sample?
We have 8 bits per pixel = one byte per pixel (256 colors mode).
Is it B0, B1, B2,..,B15 means 16 bytes for the first line of a 16x8 tile?
So it's
AAAAAAAAAAAAAAAA (16 bytes per tile row)
BBBBBBBBBBBBBBBB
..
PPPPPPPPPPPPPPPPPPPP (8th row)
And it's read as B0,B1,B2,..,B7, B0,B1,B2,...,B7 by the Molester? (8x8 tiles)
AAAAAAAA
AAAAAAAA
BBBBBBBB
BBBBBBBB
...
But this doesn't refer to the pic we get.
(As a test I moved every odd 8 pixel colum 8 pixels down thus getting a more smooth image but the vertical structure getting worse.)Image

As the Molester's java code is a little bit complex I would prefer reorganizing the sample's structure a little bit.
AAAAAAAABBBBBBBB etc.

But before I'm bothering myself with this the underlying problem must be clear.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by mugi » Mon Nov 11, 2013 4:53 pm

this here is the part where i run out of skills really...


i have no idea how the pixel tiles are structured and whatnot,
graphics editing im decent at, but graphics formats, i really have no clue about, hence i believe i can no longer be of any further assistance myself.
(which is why i asked for help to begin with.)

in any case, here's a tiny bit of code that allows taking the raw data out of the example file, and aligning it so that it works.
a freind of mine, Paulguy wrote this for me as an attempt to get closer to how these files are built, but i never actually tested it as i dont have a compiler handy.

Code: Select all

#include <stdio.h>
#include <stdlib.h>

#define TILE_WIDTH (16)
#define TILE_HEIGHT (8)

int main(int argc, char **argv) {
	int offset, width, height, paloffset;
	long filesize;
	FILE *infile;
	char buffer[TILE_WIDTH];
	char palbuffer[1024];
	int i, j, k;

	if(argc < 6) {
		fprintf(stderr, "USAGE: %s <filename> <offset> <width> <height> <paloffset>\n"\
		                "\tOutput goes to standard output.\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	offset = atoi(argv[2]);
	width = atoi(argv[3]);
	height = atoi(argv[4]);
	paloffset = atoi(argv[5]);

	if(offset < 0) {
		fprintf(stderr, "Offset must be positive.\n");
		exit(EXIT_FAILURE);
	}
	if(width < TILE_WIDTH || width % TILE_WIDTH != 0) {
		fprintf(stderr, "Width must be greater than 0 and a multiple of %i.", TILE_WIDTH);
		exit(EXIT_FAILURE);
	}
	if(height < TILE_HEIGHT || height % TILE_HEIGHT != 0) {
		fprintf(stderr, "Height must be greater than 0 and a multiple of %i.", TILE_HEIGHT);
		exit(EXIT_FAILURE);
	}

	infile = fopen(argv[1], "r");
	if(infile == NULL) {
		fprintf(stderr, "Failed to open %s.", argv[1]);
		exit(EXIT_FAILURE);
	}

	fseek(infile, 0, SEEK_END);
	filesize = ftell(infile);
	fseek(infile, 0, SEEK_SET);

	if(width * height + offset > filesize) {
		fprintf(stderr, "Read with set width(%i), height(%i) and offset(%i) would go past the end of the file.\n", width, height, offset);
		fclose(infile);
		exit(EXIT_FAILURE);
	}
	if(paloffset < 0 || paloffset + 1024 > filesize) {
		fprintf(stderr, "Palette offset must be a positive value and within 1024 bytes from the end of the file.\n");
		fclose(infile);
		exit(EXIT_FAILURE);
	}

	for(i = 0; i < height; i += TILE_HEIGHT) {
		for(j = 0; j < TILE_HEIGHT; j++) {
			for(k = 0; k < width; k += TILE_WIDTH) {
				fseek(infile, offset + (i * width) + (j * TILE_WIDTH) + (k * TILE_HEIGHT), SEEK_SET);
				fread(buffer, TILE_WIDTH, 1, infile);
				fwrite(buffer, TILE_WIDTH, 1, stdout);
			}
		}
	}

	fseek(infile, paloffset, SEEK_SET);
	fread(palbuffer, 1024, 1, infile);
	fwrite(palbuffer, 1024, 1, stdout);
	fprintf(stderr, "Palette written to %i.\n", width * height);

	fclose(infile);
	exit(EXIT_SUCCESS);
}
this bit of code realigns the data so that it can be displayed correctly with conventional means.

another piece of code below, encodes back to tiled format. Again, not tested by me as i still dont have a compiler set up.

i dont see the guy much who writes these so i never had the chance to ask how exactly they do their job, but as far as i understood, they take the raw pixel data and just realign it.

here's what he wrote:

- I wrote the program that can encode back in to the tiled format.
- but it still doesn't work with any image format.
- it'll work on the output of the original decoder.
- if you know the palette and data offsets of a TGA it should just work as-is though.

Code: Select all

#include <stdio.h>
#include <stdlib.h>

#define TILE_WIDTH (16)
#define TILE_HEIGHT (8)

int main(int argc, char **argv) {
	int offset, width, height, paloffset;
	long filesize;
	FILE *infile;
	char buffer[TILE_WIDTH];
	char palbuffer[1024];
	int i, j, k;

	if(argc < 6) {
		fprintf(stderr, "USAGE: %s <filename> <offset> <width> <height> <paloffset>\n"\
		                "\tOutput goes to standard output.\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	offset = atoi(argv[2]);
	width = atoi(argv[3]);
	height = atoi(argv[4]);
	paloffset = atoi(argv[5]);

	if(offset < 0) {
		fprintf(stderr, "Offset must be positive.\n");
		exit(EXIT_FAILURE);
	}
	if(width < TILE_WIDTH || width % TILE_WIDTH != 0) {
		fprintf(stderr, "Width must be greater than 0 and a multiple of %i.", TILE_WIDTH);
		exit(EXIT_FAILURE);
	}
	if(height < TILE_HEIGHT || height % TILE_HEIGHT != 0) {
		fprintf(stderr, "Height must be greater than 0 and a multiple of %i.", TILE_HEIGHT);
		exit(EXIT_FAILURE);
	}

	infile = fopen(argv[1], "r");
	if(infile == NULL) {
		fprintf(stderr, "Failed to open %s.", argv[1]);
		exit(EXIT_FAILURE);
	}

	fseek(infile, 0, SEEK_END);
	filesize = ftell(infile);
	fseek(infile, 0, SEEK_SET);

	if(width * height + offset > filesize) {
		fprintf(stderr, "Read with set width(%i), height(%i) and offset(%i) would go past the end of the file.\n", width, height, offset);
		fclose(infile);
		exit(EXIT_FAILURE);
	}
	if(paloffset < 0 || paloffset + 1024 > filesize) {
		fprintf(stderr, "Palette offset must be a positive value and within 1024 bytes from the end of the file.\n");
		fclose(infile);
		exit(EXIT_FAILURE);
	}

	for(i = 0; i < height; i += TILE_HEIGHT) {
		for(j = 0; j < width; j += TILE_WIDTH) {
			for(k = 0; k < TILE_HEIGHT; k++) {
				fseek(infile, offset + (i * width) + j + (k * width), SEEK_SET);
				fread(buffer, TILE_WIDTH, 1, infile);
				fwrite(buffer, TILE_WIDTH, 1, stdout);
			}
		}
	}

	fseek(infile, paloffset, SEEK_SET);
	fread(palbuffer, 1024, 1, infile);
	fwrite(palbuffer, 1024, 1, stdout);
	fprintf(stderr, "Palette written to %i.\n", width * height);

	fclose(infile);
	exit(EXIT_SUCCESS);
}
hopefully it'll be of assistance.

i am currently examining wiht him the possibility to convert to a 256-color TGA with an RGBA palette (ps2 graphics artists tool supports this format, even though i failed to get it to display right on paint shop pro and photoshop)

we chose the TGA as target format due to it's significant similarity to the "corrected" TPL file.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2730
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 675 times
Been thanked: 1407 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by shakotay2 » Mon Nov 11, 2013 8:33 pm

mugi wrote:this here is the part where i run out of skills really...

i have no idea how the pixel tiles are structured and whatnot,
mugi, you're too modest. I like that.
graphics editing im decent at,
I'm pretty sure, you are. :)
i really have no clue about, hence i believe i can no longer be of any further assistance myself.
I don't think so. You could hack the egbg00 file for example. Look at this pic to see what I mean:

Image
, but i never actually tested it as i dont have a compiler handy.
Thx for the code. I'll check it in codeblocks (IDE with mingw, gcc compiler for windows)
we chose the TGA as target format due to it's significant similarity to the "corrected" TPL file.
Good idea, though I think this might be the 2nd step after hacking (see above).
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by mugi » Mon Nov 11, 2013 9:03 pm

well, as soon as i get the code from the previous post functioning correctly, there's no need for any hacking.

Image

it's pretty much figured out that a TGA can be used to contain the data after realigning it.

the issue i really have with these files is the fact that they contain multiple images within one file (up to 20 in some extreme cases) and as you found out yourself earlier too
the data format isnt always the same (there's that 160x224 pixel "thumpnail" there that's raw RGBA data)

hence why i need a programmer, it will be plain maddness to decompile and reassemble these files by hand so in order to continue my translation project, i will need an application, capable of rewriting the tpl files and converting back and forth between the 3 formats (the tiled main graphic, the RGBA raw thumbnail and TGA to edit)

i REALLY want this project done. and im willing to pay for someone to code such a tool.
i can dump more examples (or even all of them) if need be.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2730
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 675 times
Been thanked: 1407 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by shakotay2 » Mon Nov 11, 2013 10:39 pm

Again I'm stuck. How did you display the pic?
I used these params egbg00 80 480 360 172880 > out.bin with the compiled exe of your first code sample.

As the resulting bin has no header what did you do to display it (as TGA, I guess)?

Just added a binary TGA header? Maybe upload it cause I don't have the time to build one for myself.

last question: why again the pic looks distorted. Is this caused by the zoom?
very last question: How does it look ingame?

This is what I get using TextureFinder:
Image
(Strangely the width 480 isn't good, so I used 240 on format 8888, nothing other suitable in this tool.)
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
mugi
beginner
Posts: 32
Joined: Wed Mar 23, 2011 8:02 pm
Has thanked: 3 times
Been thanked: 9 times

Re: 16x8 pixel tiled graphics (.tpl)

Post by mugi » Mon Nov 11, 2013 11:00 pm

haent tried them ingame yet.
i'll do that once i get them to extract and rebuild the way i want.

i trust data, so once its' verified that the data is fine, i'll start doing in-game implementations.

as for tga header.

use: 0001 0100 0000 0120 0000 0000 E001 6801 0800
as the header, paste the palette after the header, and the data after the palette.

if you want the code to write the palette before the data, just move the bit of code at the end regarding writing the palette, to before writing the pixel data.

the image is distorted because the code is not working as it should. Paulguy had it display the image correctly, but i haven't gotten it to do that yet. Reason for this is currently unknown.
We are working on it. (it looks like for some reason the output randomly generates an extra "0A" bytes to the data, several can be seen at the first 10 entries of the palette, the rest somewhere in the data.)

note: the tga you will generate with this header is a 256-color indexed (RGBA palette) TGA. a good deal of graphics editors do not display it correctly at all.
it is also worth a note that due to the way TGA is being read, theimage output will be flipped both horizontally and vertically

when the code works as it should, this is what it does. (paulguy's raw output as a test. I just screenshotted it :P)

Image

Post Reply