Reverse-engineering Klik & Play .IMG files

SpindleyQ's picture

Inspired by qrleon's painstaking hand-capture of some of Klik & Play's most glorious sprites, I decided to look into how hard it would be to crack the Klik & Play file format.

As it turns out, it wasn't really that hard at all! Reverse engineering is kind of fun. And I discovered 010 Editor in the process, which is all kinds of badass.

I'm pretty sure I now have enough information to batch extract raw bitmap data, if I just knew exactly what KNP's colour palette was. I think the simplest way to find out is just to take a screen grab of the sprite editor and slurp up the colours from that.

The on-screen colour palette maps onto colour indexes like so:

0 16 32 ... 240
1 17 33 ... 241
2 18 34 ... 242
... ... ... ... ...
15 31 48 ... 255

except for one cute trick. The first colour, 0, doesn't actually map to 0, it maps to some other black elsewhere in the palette (207, IIRC). 0 is the transparent colour.

I'm not sure yet if there's any way to tell, just given the .img file, which images correspond to which objects, animations, etc. I'm guessing that there probably isn't, which is unfortunate, as .gam files are a lot more complicated. (There's all kinds of friggin' garbage data in them.)

I've attached the 010 Binary Template that I whipped up while I was figuring out the Klik & Play .img file format, to help future generations of people who want to reverse-engineer the Klik & Play file format. I also loaded that last sentence up with keywords so that Klik & Play hackers might find this page via Google.

knp.bt1.1 KB


SpindleyQ's picture

So, I've written a python

So, I've written a python script to scrape all of the images out of an .IMG file! Hooray!

The filenames are of the format [ImgID]_[Hotspot X]_[Hotspot Y].png, so that after manual sorting, I'll be able to write a script that churns out properly lined-up animated gifs and so forth.

Unfortunately, it only sort of works. Boo!


  1. It seems like images have a fifty percent chance of requiring an extra pixel of padding on their width, and I haven't found any indication of how this is triggered. Right now these images look like this:
  2. I seem to occasionally be getting black values where I shouldn't have them. See: I assume that this has to do with my hacky way of fetching the palette, but for the moment this leads to terrifying images like this one. SECRET BLACKFACE CLOWNS HIDDEN IN KLIK & PLAY

5_0_0.png46.32 KB
4_40_78.png2.9 KB
9_34_55.png1.7 KB
8_15_55.png1.59 KB
SpindleyQ's picture

Fixed the bugs! I should be

Fixed the bugs! I should be releasing the script soon, once I can package it up into a vaguely nice EXE.

For the curious:

  1. Images in Klik & Play are always stored internally with an even number of pixels per row, even if the width is marked as odd.
  2. The image I was basing my palette on had a line of black across the top, causing every number that was a multiple of 16 to mistakenly show up as black.

kirkjerk's picture

Pretty bad ass! If I were

Pretty bad ass!

If I were more into the proper spirit of Trainwrecks I'd probably be working on an import sprite to processing mechanism right now so I could partake of more of this cliparty goodness. But, I'm wicked lazy.

SpindleyQ's picture

Yeah, I'm definitely

Yeah, I'm definitely interested in writing scripts to ease the importation of klipart into other rapid game creation systems.

qrleon's picture

Awesome! Thank you for doing

Awesome! Thank you for doing this.

I'd love to see what crazy stuff it extracts from Venture 2.

SpindleyQ's picture

Holy shit, thanks for the

Holy shit, thanks for the torture test. Venture 2 has 8170 individual images inside of it. I'm now pretty confident that my tool will successfully rip any Klik & Play .IMG file.

8034_40_83.png2.82 KB
snapman's picture


This feels like the earliest stages of something I'd been hoping would eventually come about... You know how the first things to show up in every new homebrew community are emulators, and various ports or game engine recreations (I'm lumping JNES/SNES9X/JENESIS/STELLA in with SCUMMVM/REMINISCE/CLONEKEEN/PRBOOM). Usually it's DOS-era games or 4th generation consoles (and only commercial games!). But the idea of an easily ported engine to play cheesy freeware KnP games is terribly appealing. The two central problem are the absense of any source code for porting and the lack of a definitive archive of the best games written in the format (Don't rom archives drive emulator development? Or is it the other way around?).

Of course, games that rely on the buggy nature of the engine (such as every game I make) probably wouldn't run very well on a port, much like ZZT games running in DREAMZZT. Still, it's an interesting thought.

SpindleyQ's picture

You know, I hadn't even

You know, I hadn't even thought of that, but it would be pretty incredible to have the Pirate Kart running on the Wii.

snapman's picture

First MMF Java, and then...

Man, those clickteam folks way, waaay in the future of two-thousand-and-nine are making their futuristic-klik-n-play program export to flash. Their first example is Gracillis V, the demo game they've been re-exporting since the first days of knp. Assuming they're backwards-compatible all the way back to the first format, and realizing that the Opera browser on the Wii can play flash files...

Still, I'd rather they release an open-source version of their first game engine, bugs and all.

snapman's picture

further KnP Wii thoughts

With the port of DosBox to the Wii, it's now possible to install Windows 3.1 on a Wii, which means, of course, it is now possible to play KnP games on a Wii.

Also, the flash route was probably no good, since the wii browser is locked into an older version of flash, and their new export option probably uses the flash 10 player.

Pizza Time's picture

I'm still waiting for

I'm still waiting for someone to hack KnP to fix up its tricky relationship with importing images with a higher bit depth than the graphics mode you are working with as well as all those little things that cause it to crash for no apparent reason. It would be a halfway house but as a halfway house it would be a damn sight better than the home we can run away from.

snapman's picture

They kinda did that.

It's called "Click & Create", I believe. ;)

GoreCore's picture

I was thinking lately about

I was thinking lately about making a KnP games on-line archive. Shouldn't be too hard as those games aren't really that big. Just need now some motivation and moneys for server space and bandwidth. Will do something around this after my exams.

SpindleyQ's picture

I've got like 10 gig of free

I've got like 10 gig of free storage on my linode right now -- obviously I don't want to cram it absolutely full of other peoples' stuff, but I don't mind mirroring old Klik & Play games for preservation's sake myself, if you find some cool stuff.

GoreCore's picture

Great. I will undust an old

Great. I will undust an old cd from PC World komputer with KNP competition - about 20 games, e.g. point-and-click adventure game, sidescrolling shmup, some kind of action-strategy etc. Also I will browse some polish sites about klik games.

snapman's picture

Another fascinating

Another fascinating possibility here is writing .IMG files. Wasn't there some wonderful archive of beautiful animated gifs extracted from C64 games posted here a while ago? How difficult would it be to make a streamlined app to import animated gifs, remap them to the KnPalette, and write out a library?

SpindleyQ's picture

Doesn't KNP accept some kind

Doesn't KNP accept some kind of import-at-once spritemap format? If so, it's probably much easier to write a tool to generate THAT than a .gam/.img pair. (There are still some bits of the .img format that are a total mystery to me. Not a big deal to skip over when you're reading, but probably tough to trick KNP.)

Still, it'd be nice to have, sure.

Pizza Time's picture

It does but it's totally ass.

It does but it's totally ass.

kirkjerk's picture

So is there any way to get

So is there any way to get like a giant set of KNP anims as animated GIFs?

I realize that someone else has made a nice animated GIF import tool for processing

.... actually in terms of the Pirate Kart... I know one time I asked if I should keep on w/ processing, or force myself to KNP, and I think SpindlyQ said "KNP sprites in Processing" -- is that a good idea? is it cooler to keep w/ the theme that way, or to have this one set of idiosyncratic looking shape-based games?

SpindleyQ's picture

The problem is that I

The problem is that I haven't decoded quite enough information to figure out which images go together, in which order.

That might be a fun bus project for me to work on next week, though!

Re: "going with the theme", my experience with the first Pirate Kart was that everyone had their own discernible style anyway, even when using the same sprites. To me, that was an unexpected and really cool result; a direct refutation of the idea that a tool like Klik & Play led directly to cookie-cutter games that were all really just the same. What I mean to say is, make games in the way that feels most simple, natural and comfortable to you. Keep the conduit between your brain and the screen flowing as smoothly as possible.