News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Constructing a TIM/TIM2/GIM file header  (Read 10149 times)

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Constructing a TIM/TIM2/GIM file header
« on: May 27, 2014, 03:18:31 am »
Hey all, I'm posting this right now because it's after midnight, I'm tired, and I've already put in a healthy amount of work locating the data in question... so.

I'm taking apart a PSP game at the moment. I've found the font, but the problem is that it (and its accompanying CLUT) are stored raw, with no header data. Here's the load information from ppsspp:

b8000909: Texture size 0: 000909, width : 512, height : 512
cb000000: TexFlush
c2000001: TexMode 000001 (swizzle, 0 levels, shared clut)
c3000004: TexFormat 000004 (CLUT4)
cb000000: TexFlush
c5000f03: Clut format: 000f03 (ABGR 8888)
b1080000: CLUT addr upper 00080000
b0e293c0: CLUT base addr: e293c0
c4000002: Clut load: 000002

Can anyone help construct a header for this thing so I can actually look at the font, get the kanji identified, and start extracting the script? I'd appreciate it!

Gemini

  • Hero Member
  • *****
  • Posts: 2017
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: Constructing a TIM/TIM2/GIM file header
« Reply #1 on: May 27, 2014, 06:28:27 am »
If that CLUT is ARGB888 like PPSSPP states, then you definitively can't use TIM for it (it's locked to RGBA5551). TIM2 has a bloated header, better avoid that one too for simplicity's sake (probably GIM as well, I don't remember the specs). You better use either Bitmap for entries having no alpha (WinXP specs do allow the fourth channel in an RGBQUAD array to be used for that, but I doubt regular editing software reads said parameter) or PNG if the alpha actually has some use.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

Dashman

  • Full Member
  • ***
  • Posts: 210
    • View Profile
Re: Constructing a TIM/TIM2/GIM file header
« Reply #2 on: May 27, 2014, 07:28:41 am »
If you just need to see the font, probably building a bmp out of the raw data is the easiest way, yeah. Chances are the first colour in the CLUT is the transparency and will most probably just be black (00 00 00 00), so you shouldn't worry about it. I'm not the most knowledgeable guy when it comes to image formats, but the last time I dumped indexed raw images into bmp, I gave them this header format:

* all sizes are big endian
* header size is 54

bytes 0 - 1: 42 4d ("BM")
bytes 2 - 5: file size (header size + CLUT size + number of pixels)
bytes 6 - 9: 00 00 00 00
bytes 10 - 13: offset to start of image (header size + CLUT size)
bytes 14 - 17: 28 00 00 00
bytes 18 - 21: Width (00 02 00 00 in your case)
bytes 22 - 25: Heigth (00 02 00 00 in your case)
bytes 26 - 27: 01 00 (number of planes in the image)
bytes 28 - 29: 08 00 (bits per pixel, if it looks wrong, make it 04 00 or 10 00)
bytes 30 - 33: 00 00 00 00
bytes 34 - 37: number of pixels
bytes 38 - 49: 00 00 00 00 00 00 00 00 00 00 00 00
bytes 50 - 53: number of colours in your CLUT

Next would be the CLUT data and then the image data. Of course, you only want to put one CLUT in there if you have several. Aaaand this was meant for RGBA format, so you'll want to reverse your ABGR colours to see things properly. Hope that helps.

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Constructing a TIM/TIM2/GIM file header
« Reply #3 on: May 27, 2014, 08:28:29 am »
Can you post the raw data? I have some private tools to convert raw files to BMP.

RetroHelix

  • Full Member
  • ***
  • Posts: 147
    • View Profile
Re: Constructing a TIM/TIM2/GIM file header
« Reply #4 on: May 27, 2014, 08:34:12 am »
I would suggest using https://code.google.com/p/tiledggd/ if you only want to take a look at the graphics.

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Re: Constructing a TIM/TIM2/GIM file header
« Reply #5 on: May 27, 2014, 12:58:25 pm »
Can you post the raw data? I have some private tools to convert raw files to BMP.

File can be found here. First 0x400 bytes are CLUT data; the rest of it is texture. I'm reasonably certain (I'd say about 80%) that it's copied straight into RAM as-is without any transformation or anything done on it, but I haven't been able to get anything legible displayed in tiledggd or crystaltile2, just some vague fuzzy glyphs that I can confirm are in fact the font.

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Constructing a TIM/TIM2/GIM file header
« Reply #6 on: May 27, 2014, 02:39:09 pm »
The font seems swizzled, and I have not been able to unswizzle the data :(

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Re: Constructing a TIM/TIM2/GIM file header
« Reply #7 on: May 27, 2014, 02:57:32 pm »
The font seems swizzled, and I have not been able to unswizzle the data :(

This is the first I've heard of that term, but it would explain why things look so fuzzy in crystaltile2. Research time!

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Constructing a TIM/TIM2/GIM file header
« Reply #8 on: May 27, 2014, 03:04:20 pm »
Wow! This is very indecent! 18 years old, if not 28!
http://agtp.romhack.net/temp/mac21.jpg
 ;D

Err sorry, I got side-tracked. Which of the files are we talking about agan? ;)
Also - is there outline or are there shadows in the font's graphics?
Only a single font size/sort?

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Re: Constructing a TIM/TIM2/GIM file header
« Reply #9 on: May 27, 2014, 03:33:43 pm »
The characters are all 16x16 but I don't think they quite render at 16x16 - it looks more like 15x15 in PPSSPP's GE debugger. They ARE outlined, though it's not always immediately apparent depending on which part of the interface is being rendered.

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Constructing a TIM/TIM2/GIM file header
« Reply #10 on: May 27, 2014, 05:12:56 pm »
The font seems swizzled, and I have not been able to unswizzle the data :(

PSPemu's code seems to have a method to unswizzle:
https://code.google.com/p/pspemu/source/browse/branches/pspemu31/pspemu/core/gpu/impl/gl/GpuOpenglTexture.d?spec=svn284&r=267

jjjewel

  • Jr. Member
  • **
  • Posts: 23
    • View Profile
Re: Constructing a TIM/TIM2/GIM file header
« Reply #11 on: May 27, 2014, 05:40:39 pm »
Is it font.bin that you're looking for?
If so, it can be viewed with GBA 4bpp mode with offset 400 and 32x8 tile.
If not, then I don't know. Since you didn't tell which file you need help for. :P

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Re: Constructing a TIM/TIM2/GIM file header
« Reply #12 on: May 27, 2014, 05:46:08 pm »
Sweet, yeah, that's it :) I'd extracted font.bin from a larger binary; it should contain just the font. But yeah, that looks like what I need.

Thanks very much!

Edit: Actually while I'm here, could I ask how you figured this out? I'm no expert with CT2 (it seems horribly clunky to me) but I did play around with it for a good long while and wasn't able to get this far.

FAST6191

  • Hero Member
  • *****
  • Posts: 2623
    • View Profile
Re: Constructing a TIM/TIM2/GIM file header
« Reply #13 on: May 27, 2014, 07:21:38 pm »
If jjjewel is anything like me then probably by learning the keyboard shortcuts (should be in the help sections for a given thing you can fiddle with, it is usually control, shift or alt and a button) and spotting fragments of things that start to make sense (starts with something not looking quite like random noise* and goes from there). About the only thing I miss in CT2 is the ability to cycle through palettes one colour at a time, it being quite useful on these modern consoles that you do not know the amount of random padding in the header for.

*it usually happens before then but you can drop down to one pixel height/width and use the number of tiles on the screen to bash it into form.

jjjewel

  • Jr. Member
  • **
  • Posts: 23
    • View Profile
Re: Constructing a TIM/TIM2/GIM file header
« Reply #14 on: May 27, 2014, 07:48:52 pm »
Edit: Actually while I'm here, could I ask how you figured this out? I'm no expert with CT2 (it seems horribly clunky to me) but I did play around with it for a good long while and wasn't able to get this far.
Oh, I've worked on non-English translation project for PSP so the first criteria to look is whether the font is editable or not. So I've checked a bunch of PSP fonts and I got some idea what I should try. :D It was also a fluke that your font wasn't in any weird format so it was quite easy to figure out.

And it's as FAST6191 said, if you've been using CT long enough, you'll get familiar with it. (I've been using it pretty much for everything from hex editing to graphic editing. ^_^)

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3512
    • View Profile
    • Aeon Genesis
Re: Constructing a TIM/TIM2/GIM file header
« Reply #15 on: May 27, 2014, 08:27:46 pm »
If jjjewel is anything like me then probably by learning the keyboard shortcuts (should be in the help sections for a given thing you can fiddle with, it is usually control, shift or alt and a button) and spotting fragments of things that start to make sense (starts with something not looking quite like random noise* and goes from there).

Yeah, if you'd read, you'd know that I already did that. I'm not exactly new to romhacking, just to PSP stuff. It wasn't a question of finding the font (the binary I uploaded *only* contains the font); it was more about the specific settings used in CT2, notably the 32x8 thing.

FAST6191

  • Hero Member
  • *****
  • Posts: 2623
    • View Profile
Re: Constructing a TIM/TIM2/GIM file header
« Reply #16 on: May 27, 2014, 08:39:48 pm »
I did not mean to imply otherwise and certainly did not approach it from that angle, I just wanted to provide a quick overview of how I tend to brute force an image format with CT2.

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Constructing a TIM/TIM2/GIM file header
« Reply #17 on: May 28, 2014, 01:17:23 am »
If so, it can be viewed with GBA 4bpp mode with offset 400 and 32x8 tile.
You're right ;)
The "problem" was the 32x8.

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Constructing a TIM/TIM2/GIM file header
« Reply #18 on: May 28, 2014, 02:31:16 am »
Edit: Actually while I'm here, could I ask how you figured this out? I'm no expert with CT2 (it seems horribly clunky to me) but I did play around with it for a good long while and wasn't able to get this far.

I have the same question actually.
I know I can increase/decrease the size of the watched chunk with shift + arrows (more useful in linear mode than in tiled mode like here).
I know I can change formats with ctrl + up/down.
I know I can fine-tune the starting offset with ctrl + left/right.
and changing the tile size requires going back to the editable field with the mouse (no known shortcut).

But still, I have also been fiddling around without being able to find this. So there has to be some kind of "poking around method" that you guys apply?
I mean, both Gideon and I got to the idea that 16 height was used, because we almost saw the font with that. (But not quite, so we thought we had to keep on searching.) Even Cue did not find it (even though he is a very smart one).

So pragmatically:
What made you change the width and height from there?
Did you just try all multiples of 4 for both width and height?
How did you decide what to try next from one attempt to the next?

Thanks for your insights.
We could by the way try and write this down somewhere in the documents section. ;)

FAST6191

  • Hero Member
  • *****
  • Posts: 2623
    • View Profile
Re: Constructing a TIM/TIM2/GIM file header
« Reply #19 on: May 28, 2014, 07:37:43 am »
ctrl and 8 and ctrl and 9 change between 8x8 and 16x16, to the best of my knowledge there is no fine tuning option there.

Going by various threads over the years I reckon jjjewel has probably pulled apart about as many graphics formats as anybody for the DS and similar vintage consoles where custom sizes are nothing unusual, on older consoles I typically only see such things for the occasional font and even that is usually more of a software scaling/stored as 16x16 but with a soft table for the widths affair.
Likewise if you go for the full width right away (or maybe 64 or 128) then once you tend to see a kind of interlaced affair (alternating lines) which is still very readable vs having things double packed when you go too small, this is nice for although there are custom sizes they do tend towards the multiples of 8 or 16.