• Revista PROGRAMAR: Já está disponível a edição #53 da revista programar. Faz já o download aqui!

Triton

Nesquik Computer Game

6 mensagens neste tópico

Aqui fica para os interessados, qualquer dúvida não hesitem... ;)

// MAP VISUALIZER FOR TRICKY QUIKY GAMES 2
// Date: 2007-05-07
// Authors: Roman Vetter, Joao Matos

#include <cstdio>
#include <string>
#include <Windows.h>
#include <iostream>

#define iwidth	16 // icon size
#define iheight 16
#define palsize 3*256 // size of the PCC color palette
#define are_header 0x160 // ARE file header size

using namespace std;


// standard MS Paint 8-bit bmp header data:
const unsigned char bmpheader1 [12] =
{0x00, 0x00, 0x00, 0x00, 0x36, 0x04, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00};

const unsigned char bmpheader2 [8] =
{0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00};

const unsigned char bmpheader3 [16] = 
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};

// each item has its own pixel position offset
const short x_offset [256+5] = {
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
 5, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 1, 0, 0};

const short y_offset [256+5] = {
 0,16,16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-2,
10,10, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 9,12, 9, 0,10};


int makemap(char * fname)
{
string world = string(fname, 2); // "W1" to "W5"

FILE * fmap = fopen(fname, "rb");
cout << "MAP file: " << fname;
if (!fmap)
{	
	cout << " not found!\n";
	return 2;
}

FILE * fare = fopen((string(fname, 5) + "ARE").c_str(), "rb");
cout << "  ARE file: " << (string(fname, 5) + "ARE").c_str();
if (!fare)
{	
	cout << " not found!\n";
	return 2;
}

FILE * fico = fopen((world + ".ICO").c_str(), "rb");
cout << "  ICO file: " << (string(fname, 2) + ".ICO").c_str();
if (!fico)
{
	cout << " not found!\n";
	return 2;
}

FILE * fpcc = fopen((world + ".PCC").c_str(), "rb");
cout << "  PCC file: " << (world + ".PCC").c_str();
if (!fpcc)
{
	cout << " not found!\n";
	return 2;
}
else
{
	cout << "\n";
}

// read ICO file to memory
fseek(fico, 0, SEEK_END);
unsigned long ficosize = ftell(fico); // size of the ICO file
fseek(fico, 0, SEEK_SET);
char * icodata = new char [ficosize];
fread(icodata, 1, ficosize, fico);
fclose(fico);

// get MAP information
fseek(fmap, 0, SEEK_END);
unsigned long fmapsize = ftell(fmap); // size of the MAP file
short mheight, mwidth;
fseek(fmap, 7, SEEK_SET);
fread(&mheight, 1, 2, fmap); // map height
mwidth = (static_cast<short>(fmapsize) - 10) / mheight / 2; // map width

// write bitmap header data
FILE * fout = fopen((string(fname) + ".bmp").c_str(), "wb");
fwrite("BM", 1, 2, fout); // write bitmap identifier
long bmpsize = 14 + 40 + 4*256 + mheight * mwidth * iheight * iwidth;
fwrite(&bmpsize, 1, 4, fout); // write total bmp file size
fwrite(&bmpheader1, 1, 12, fout);
long lwidth = iwidth * mwidth;
long lheight = -iheight * mheight; // row order is top-down -> negative height
fwrite(&lwidth, 1, 4, fout);
fwrite(&lheight, 1, 4, fout);
fwrite(&bmpheader2, 1, 8, fout);
lwidth *= lheight; // total bitmap data size
fwrite(&lwidth, 1, 4, fout);
fwrite(&bmpheader3, 1, 16, fout);

// write color palette
char palette [palsize];
fseek(fpcc, -palsize, SEEK_END); // palette is at end of PCC file
fread(palette, 1, palsize, fpcc); // read the color palette data
for (int i = 0; i < palsize; i += 3)
{
	// convert palette from GRB to BRG0 and write it
	fputc(*(palette + i+2), fout);
	fputc(*(palette + i+1), fout);
	fputc(*(palette + i  ), fout);
	fputc(0, fout);
}
fclose(fpcc);

unsigned short tile;
char * index; // pointer to icon row to be written
cout << "Map height: " << mheight << "\n";
cout << "Map width : " << mwidth << "\n";

for (int mh = 0; mh < mheight; ++mh)
// go through all tile rows
{
	for (int ih = 0; ih < iheight; ++ih)
	// process all pixel rows for each tile row
	{
		fseek(fmap, 2*mh*mwidth+10, SEEK_SET); // reset MAP reading head
		for (int mw = 0; mw < mwidth; ++mw)
		// process all tiles in a tile row
		{
			fread(&tile, 1, 2, fmap); // read one tile
			tile = (tile >> 8) + (tile << 8); // correct endianness
			if (tile > 0x2000 && tile < 0x23FF) tile %= 0x200; // remove acclivity mark
			tile %= 0x5000; // remove "unwalkable" mark
			tile %= 0x0800; // remove elevator block mark

			index = icodata + tile * iwidth * iheight + ih * iwidth; // point to the icon row
			for (int iw = 0; iw < iwidth/4; ++iw)
			// write one pixel row of one icon
			{
				// the pixels are 4-flipped
				fputc(*(index   ), fout);
				fputc(*(index+ 4), fout);
				fputc(*(index+ 8), fout);
				fputc(*(index+12), fout);
				++index;
			}
		}
	}
}

fclose(fmap);
delete [] icodata;

// insert items
unsigned short bhor = 0, bver = 0; // number of blocks (vertically & horizontally)
fseek(fare, 15, SEEK_SET); // goto size information
fread(&bhor, 2, 1, fare);
fread(&bver, 2, 1, fare);
fseek(fare, are_header, SEEK_SET); // skip rest of header
unsigned short * blocks = new unsigned short [bhor*bver]; // 4x4-tile blocks
fread(blocks, 2, bhor*bver, fare); // read block offsets

unsigned short item [3]; // data of one item
for (i = 0; i < bhor*bver; ++i)
{
	// process all non-empty blocks
	if (blocks[i] != 0xFFFF)
	{
		blocks[i] = (blocks[i]>>8) + (blocks[i]<<8); // correct endianness
		fseek(fare, are_header + blocks[i], SEEK_SET); // goto block items
		fread(&item, 2, 1, fare); // read item ID
		// process all items of the block
		while (item[0] != 0xFFFF)
		{
			// valid item
			item[0] = (item[0]>>8) + (item[0]<<8); // correct endianness
			fread(&item[1], 2, 2, fare); // read rest of item data

			// determine SRB file in which the item graphics is
			string srb_name;
			short sprite_num;
			bool inverted = false;
			if (item[0] == 1 || item[0] == 2) // worm
			{
				srb_name = "WURM2.SRB";
				sprite_num = 0;
				if (item[0] == 1) inverted = true;
			}
			else if (item[0] == 3 || item[0] == 4) // bee
			{
				srb_name = "BIENE.SRB";
				sprite_num = 0;
				if (item[0] == 3) inverted = true;
			}
			else if (item[0] == 44) // extra life
			{
				srb_name = "PAPIER.SRB";
				sprite_num = 0;
			}
			else if (item[0] == 52) // bump
			{
				srb_name = "BUMP_" + world +".SRB";
				sprite_num = 1;
				// different pixel position offset for each world:
				item[0] = 255 + atoi(world.substr(1,1).c_str());
				if (world == "W4") srb_name = ""; // DEBUG: no BUMP_W4.SRB
			}
			else if (item[0] >= 111 && item[0] <= 114) // cereal packs
			{
				srb_name = "WERBE.SRB";
				sprite_num = item[0] - 111;
			}
			else if (item[0] >= 121 && item[0] <= 127) // Nesquik letters
			{
				srb_name = "PUZZLE.SRB";
				sprite_num = item[0] - 121;
			}

			if (!srb_name.empty()) { // DEBUG: until not all items implemented

			FILE * fsrb = fopen(srb_name.c_str(), "rb");
			if (!fsrb)
			{
				cout << srb_name << " not found!\n";
				return 2;
			}

			// goto graphics data corresponding to this item 
			fseek(fsrb, 255, SEEK_SET); // goto first size info minus 13
			short width = 0, height = 0;
			for (int j = 0; j <= sprite_num; ++j)
			{
				fseek(fsrb, width*height+9, SEEK_CUR); // goto next sprite
				fread(&width,  1, 2, fsrb); // read sprite width
				fread(&height, 1, 2, fsrb); // read sprite height
			}
			fseek(fsrb, 1, SEEK_CUR);
			char alpha = fgetc(fsrb); // read alpha channel
			fseek(fsrb, 1, SEEK_CUR);

			char * item_graph = new char [width*height];
			fread(item_graph, 1, width*height, fsrb); // read item data

			unsigned long xy = ((item[1]>>12) + i%bhor*4)*iwidth	 // pixel position x
				+ ((item[2]>>12) + i/bhor*4)*iheight * mwidth*iwidth // pixel position y
				+ x_offset[item[0]]					 // individual position x offset
				+ y_offset[item[0]] * mwidth*iwidth; // individual position y offset
			for (j = 0; j < height; ++j)
			{
				// write one item pixel row
				fseek(fout, xy + 1078, SEEK_SET);
				int pos;
				for (int p = 0; p < width; ++p)
				{
					pos = (inverted ? width-p-1 : p); // move backwards if item inverted
					if (item_graph[j*width+pos] != alpha) // pixel not transparent
						fputc(item_graph[j*width+pos], fout); // draw pixel
					else
						fseek(fout, 1, SEEK_CUR); // skip pixel
				}
				xy += mwidth*iwidth;
			}

			delete [] item_graph;
			fclose(fsrb);

			} // end DEBUG statement

			fread(&item, 2, 1, fare); // read ID of next item
		}
	}
}

delete [] blocks;
fclose(fare);
fclose(fout);

return 0;
}


int main(int argc, char * argv[])
{
if(argc != 2) // make all maps
{
	WIN32_FIND_DATA wfd;
	HANDLE fHandle = FindFirstFile("*.MAP",&wfd);

	do
	{
		int failed = makemap(wfd.cFileName);
		if (failed) return failed;
	}
	while (FindNextFile(fHandle, &wfd));

	FindClose(fHandle);
}
else // make only the map whose name was passed
{
	int failed = makemap(argv[1]);
	if (failed) return failed;
}

return 0;
}

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

// FILE EXTRACTION PROGRAM FOR TRICKY QUIKY GAMES 2
// EXTRACTS ALL FILES FROM QUIKY.PRE
// 2007-04-20
// Authors: Roman Vetter, Joao Matos

#include <cstdio>
#include <string>

using namespace std;

int main()
{
FILE * fpre = fopen("QUIKY.PRE", "rb");
if(!fpre) return 2; // file not found

fseek(fpre, 0, SEEK_END);
unsigned long filesize = ftell(fpre); // source file size
fseek(fpre, 0, SEEK_SET);

// EXTRACT FILES
unsigned char namelen;
char name [12];
unsigned long size;
while(ftell(fpre) < filesize)
{
	// READ HEADER (FILE INFO)
	namelen = fgetc(fpre);					// read length of file name string
	fread(&name, 1, namelen, fpre);			// read file name
	fseek(fpre, 255 - namelen, SEEK_CUR);	// skip rest of header
	fread(&size, 1, 4, fpre);				// read file length

	// READ FILE DATA
	char * data = new char [size];
	fread(data, 1, size, fpre); // read data from source file

	// WRITE FILE
	FILE * fout = fopen(string(name, namelen).c_str(), "wb");
	fwrite(data, 1, size, fout); // write data to new file
	fclose(fout);
	delete [] data;
}

fclose(fpre);

return 0;
}


// FILE EXTRACTION PROGRAM FOR TRICKY QUIKY GAMES 2
// EXTRACTS ALL FILES FROM NESTLE.DAT
// 2007-04-20
// Authors: Roman Vetter, João Matos

#include <cstdio>
#include <string>
#include <vector>

using namespace std;

int main()
{
FILE * fdat = fopen("NESTLE.DAT", "rb");
if(!fdat) return 2; // file not found

long toc, num_of_files;
fseek(fdat, -8, SEEK_END); // 8 bytes before EOF:
fread(&toc, 1, 4, fdat); // TOC offset
fread(&num_of_files, 1, 4, fdat); // number of archives files
fseek(fdat, toc, SEEK_SET); // go to beginning of TOC

// READ TABLE OF CONTENTS
short namelen;
char n [12];
vector <long> offset(num_of_files);
vector <string> name;
for (int i = 0; i < num_of_files; ++i)
{
	fread(&namelen, 1, 2, fdat); // read length of file name string
	fread(&n, 1, namelen, fdat); // read file name
	name.push_back(string(n, namelen));
	fread(&offset[i], 1, 4, fdat); // read file offset
}
offset.push_back(toc);

// EXTRACT FILES
for (int j = 0; j < num_of_files; ++j)
{
	long filesize = offset[j+1] - offset[j];
	char * data = new char [filesize];
	fseek(fdat, offset[j], SEEK_SET); // go to beginning of jth file
	FILE * fout = fopen(name[j].c_str(), "wb");
	fread(data, 1, filesize, fdat); // read data from source file
	fwrite(data, 1, filesize, fout); // write data to new file
	fclose(fout);
	delete [] data;
}

fclose(fdat);

return 0;
}

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites
// GRAPHICS EXTRACTION PROGRAM FOR TRICKY QUIKY GAMES 2
// 2007-04-19
// Authors: Roman Vetter, Joao Matos

#include <cstdio>
#include <string>
#include <Windows.h>
#include <iostream>

#define palsize 3*256

using namespace std;

// standard MS Paint 8-bit bmp header data:
const unsigned char bmpheader1 [12] =
{0x00, 0x00, 0x00, 0x00, 0x36, 0x04, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00};

const unsigned char bmpheader2 [8] =
{0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00};

const unsigned char bmpheader3 [16] = 
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};

int extractsrb(char * fname)
{
FILE * fsrb = fopen(fname, "rb");
cout << "SRB file: " << fname << " ";
if (!fsrb)
{	
	cout << "not found!\n";
	return 2;
}

// determine world affiliation
string world = string(fname);
if (world == "BIENE.SRB" || world == "BIENE2.SRB" || world == "BIENE3.SRB" ||
	world == "BLATT.SRB" || world == "BUMP_W1.SRB" || world == "DOKTOR1.SRB" ||
	world == "EMPTY0.SRB" || world == "END1.SRB" || world == "GAMEBAR.SRB" ||
	world == "FR_W1.SRB" || world == "NESQUIK.SRB" || world == "PLATFW1.SRB" ||
	world == "PUFF.SRB" || world == "PUZZLE.SRB" || world == "SCHUSS.SRB" ||
	world == "SPATZ.SRB" || world == "SPRECH.SRB" || world == "WURM.SRB" ||
	world == "WURM2.SRB" || world == "WOLKE.SRB")
	world = "W1.PCC";
else if (world == "BLASEN.SRB" || world == "BUMP_W2.SRB" || world == "DOKTOR2.SRB" ||
	world == "END2.SRB" || world == "FISCH.SRB" || world == "FISCH2.SRB" ||
	world == "KRABBE.SRB" || world == "PAPIER.SRB" || world == "PLATFW2.SRB" ||
	world == "PROP.SRB" || world == "PUFFW2.SRB")
	world = "W2.PCC";
else if (world == "BUMP_W3.SRB" || world == "DOKTOR3.SRB" || world == "END3.SRB" ||
	world == "FLOCKE.SRB" || world == "FR_W3.SRB" || world == "PENGO.SRB" ||
	world == "PLATFW3.SRB" || world == "QUIKYW3.SRB" || world == "SCHNEE.SRB" ||
	world == "EXTRAS.SRB")
	world = "W3.PCC";
else if (world == "BUMP_W4.SRB" || world == "DOKTOR4.SRB" || world == "END4.SRB" ||
	world == "FLIEGE.SRB" || world == "PLATFW4.SRB" || world == "SPINNE.SRB" ||
	world == "WIND.SRB")
	world = "W4.PCC";
else if (world == "BUGGY.SRB" || world == "BUMP_W5.SRB" || world == "DOKTOR5.SRB" ||
	world == "END5.SRB" || world == "FR_W5.SRB" || world == "KAKAO.SRB" ||
	world == "KNUSPER.SRB" || world == "MINIUFO.SRB" || world == "PLATFW5.SRB" ||
	world == "QUIKYW5.SRB" || world == "SCHROTT.SRB" || world == "UFO.SRB" ||
	world == "WERBE.SRB")
	world = "W5.PCC";

FILE * fpcc = fopen(world.c_str(), "rb");
cout << "  PCC file: " << world;
if (!fpcc)
{
	cout << " not found!\n";
	return 2;
}

// read color palette
char palette [palsize];
fseek(fpcc, -palsize, SEEK_END); // palette is at end of PCC file
fread(palette, 1, palsize, fpcc); // read the color palette data
fclose(fpcc);

short snum, width, height;
char buffer [640*400]; // maximum possible sprite size
fseek(fsrb, 0, SEEK_END);
unsigned long filesize = ftell(fsrb); // size of the SRB file
fseek(fsrb, 258, SEEK_SET); // skip file header
char number [4] = {0,0,0,0};
short gnum = 0; // graphics counter
cout << "... ";

while (ftell(fsrb) < filesize)
{
	fread(&snum, 1, 2, fsrb);	// read sprite number
	fseek(fsrb, 4, SEEK_CUR);	// go to first width/height info
	fread(&width,  1, 2, fsrb); // read sprite width
	fread(&height, 1, 2, fsrb); // read sprite height
	fseek(fsrb, 3, SEEK_CUR);	// go to sprite bitmap
	fread(buffer, 1, width * height, fsrb); // read sprite bitmap

	itoa(snum, number, 10);
	FILE * fout = fopen((string(fname) + "." + string(number) + ".bmp").c_str(), "wb");

	fwrite("BM", 1, 2, fout); // write bitmap identifier
	long size = height * (width + 4 - width % 4) + 14 + 40 + 256*4;
	fwrite(&size, 1, 4, fout); // write total bmp file size
	fwrite(&bmpheader1, 1, 12, fout);
	long lwidth = width;
	long lheight = -height; // row order is top-down -> negative height
	fwrite(&lwidth, 1, 4, fout);
	fwrite(&lheight, 1, 4, fout);
	fwrite(&bmpheader2, 1, 8, fout);
	lwidth *= lheight; // total bitmap data size
	fwrite(&lwidth, 1, 4, fout);
	fwrite(&bmpheader3, 1, 16, fout);

	// write color palette
	for (int i = 0; i < palsize; i += 3)
	{
		// convert palette from GRB to BRG0 and write it
		fputc(*(palette + i+2), fout);
		fputc(*(palette + i+1), fout);
		fputc(*(palette + i  ), fout);
		fputc(0, fout);
	}

	// write sprite (top-down)
	for (int j = 0; j < height*width; j += width)
	{
		fwrite(&buffer[j], 1, width, fout); // write pixel row
		if (width % 4)  // row width must be multiple of 4 -> fill up with zeros
			fwrite(&bmpheader1, 1, 4 - width % 4, fout);
	}

	fclose(fout);
	++gnum;
}

cout << gnum << " graphics extracted.\n";

fclose(fsrb);

return 0;
}


int main(int argc, char * argv[])
{
if(argc != 2) // extract all SRB files
{
	WIN32_FIND_DATA wfd;
	HANDLE fHandle = FindFirstFile("*.SRB",&wfd);

	do
	{
		int failed = extractsrb(wfd.cFileName);
		if (failed) return failed;
	}
	while (FindNextFile(fHandle, &wfd));

	FindClose(fHandle);
}
else // extract only the one whose name was passed
{
	int failed = extractsrb(argv[1]);
	if (failed) return failed;
}

return 0;
}

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites
// ICON EXTRACTION PROGRAM FOR TRICKY QUIKY GAMES 2
// 2007-04-18
// Authors: Roman Vetter, Joao Matos

#include <cstdio>
#include <string>
#include <Windows.h>
#include <iostream>

#define width  16 // icon size
#define height 16
#define palsize 3*256 // size of the PCC color palette

using namespace std;

// standard MS Paint 8-bit bmp header data:
const unsigned char bmpheader1 [12] =
{0x00, 0x00, 0x00, 0x00, 0x36, 0x04, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00};

const unsigned char bmpheader2 [8] =
{0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00};

const unsigned char bmpheader3 [16] = 
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};

int extractico(char * fname)
{
FILE * fico = fopen(fname, "rb");
cout << "ICO file: " << fname << " ";
if (!fico)
{	
	cout << "not found!\n";
	return 2;
}

string fnamestr = string(fname);
if (fnamestr.length() == 11)
	fnamestr = (fnamestr.substr(5)).erase(2); // LOOP file
else
	fnamestr = fnamestr.erase(2); // other ICO file

FILE * fpcc = fopen((fnamestr + ".PCC").c_str(), "rb");
cout << "\tPCC file: " << (fnamestr + ".PCC").c_str() << " ";
if (!fpcc)
{
	cout << "not found!\n";
	return 2;
}

// read color palette
char palette [palsize];
fseek(fpcc, -palsize, SEEK_END); // palette is at end of PCC file
fread(palette, 1, palsize, fpcc); // read the color palette data
fclose(fpcc);

fseek(fico, 0, SEEK_END);
unsigned long filesize = ftell(fico); // size of the ICO file
fseek(fico, 0, SEEK_SET);

char buffer [width*height]; // icon data buffer
char number [4] = {0,0,0,0};
short inum = 0; // icon counter
cout << "...";

while (ftell(fico) < filesize)
{
	fread(buffer, 1, width * height, fico); // read icon data

	itoa(inum, number, 10);
	FILE * fout = fopen((string(fname) + "." + string(number) + ".bmp").c_str(), "wb");

	fwrite("BM", 1, 2, fout); // write bitmap identifier
	long size = 14 + 40 + 4*256 + height * width;
	fwrite(&size, 1, 4, fout); // write total bmp file size
	fwrite(&bmpheader1, 1, 12, fout);
	long lwidth = width;
	long lheight = -height; // row order is top-down -> negative height
	fwrite(&lwidth, 1, 4, fout);
	fwrite(&lheight, 1, 4, fout);
	fwrite(&bmpheader2, 1, 8, fout);
	lwidth *= lheight; // total bitmap data size
	fwrite(&lwidth, 1, 4, fout);
	fwrite(&bmpheader3, 1, 16, fout);

	// write color palette
	for (int c = 0; c < palsize; c += 3)
	{
		// convert palette from GRB to BRG0 and write it
		fputc(*(palette + c+2), fout);
		fputc(*(palette + c+1), fout);
		fputc(*(palette + c  ), fout);
		fputc(0, fout);
	}

	int index; // pixel offset
	for (int i = 0; i < height; ++i)
	{
		for (int j = 0; j < width/4; ++j)
		{
			// write icon data (top-down), 4-flipped colums
			index = i*width + j;
			fputc(buffer[index   ], fout);
			fputc(buffer[index+ 4], fout);
			fputc(buffer[index+ 8], fout);
			fputc(buffer[index+12], fout);
		}
	}

	fclose(fout);
	++inum;
}

cout << "\t" << inum << " icons extracted.\n";

fclose(fico);

return 0;
}


int main(int argc, char * argv[])
{
if(argc != 2) // extract all ICO files
{
	WIN32_FIND_DATA wfd;
	HANDLE fHandle = FindFirstFile("*.ICO",&wfd);

	do
	{
		int failed = extractico(wfd.cFileName);
		if (failed) return failed;
	}
	while (FindNextFile(fHandle, &wfd));

	FindClose(fHandle);
}
else // extract only the one whose name was passed
{
	int failed = extractico(argv[1]);
	if (failed) return failed;
}

return 0;
}

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Oh triton... que raio são estes tópicos?

São o código fonte de aplicações para extrair e fazer a desencriptação de alguns ficheiros do jogo Tricky Quiky Games 2, lançado em 1995, o link para download do jogo está no tópico de Discussão Geral. ;)

Pensei que alguém estivesse interessado nisto, para aprender como funcionam os aspectos internos do jogo... eu acho interessante este tipo de coisas.

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora