Пример #1
0
unsigned short fget16(FILE* fp)
{	
	unsigned short a=fget8(fp);
	unsigned short b=fget8(fp);
	b<<=8;
	return a|b;
}
Пример #2
0
uint8 ReadTypeDescriptor(FILE* fp)
{
	/*
	struct TypeDescriptorPrefix
	{
	BYTE	is_pointer : 1,
	is_unique_pointer : 1,
	is_reference : 1,
	tag : 5;
	};
	*/
	
	uint8 TypeDescriptorPrefix = fget8(fp);
	uint8 tag = TypeDescriptorPrefix & 0x1f;
	if (tag <= 17)
	{
	//	BYTE SimpleTypeDescriptor = fget8(fp);
	}
	else if (tag == 18)	// InterfaceTypeDescriptor
	{
		uint16  interface_index = fget16(fp);
	}
	else if (tag == 19)	// InterfaceIsTypeDescriptor
	{
		uint8    arg_num = fget8(fp);
	}
	else
	{
		throw -1;//exit(1);
	}

	return tag;
}
Пример #3
0
HRESULT ReadIdentifier(FILE* fp, __live_object_ptr<StringA> ident)
{
	while (!feof(fp))
	{
		int c = fget8(fp);

		ident += c;

		if (c == 0)
			break;
	}

	return S_OK;
}
Пример #4
0
void ReadParamDescriptor(FILE* fp)
{
/*
ParamDescriptor {
boolean         in;
boolean         out;
boolean         retval;
boolean         shared;
boolean         dipper;
uint3           reserved;
TypeDescriptor  type;
}
	*/
	uint8 flags = fget8(fp);

	ReadTypeDescriptor(fp);
}
Пример #5
0
int main(int argc,char* argv[])
{	
	int map=0,pat=0,mapgroup=0;
	int maps=-1,pats,mapgroups,pmaps;
	int mapchg=1,patchg=1,mapgroupchg=1;
	int width[0x200],height[0x200];
	int px,py,pw,ph;
	int rle0,data,i,j,t;
	int running=1;
	int len=0,s;
	int max;
	int vx[0x200],vy[0x200];
	char filename[12];
	char tosay[100];
	byte *buf=(byte*)malloc(0x12000),
	     *here;
	
	static BITMAP *bmp[0x200];
	BITMAP *tb;;
	PALETTE pal;
	
	FILE* fp=fopen(argv[1],"rb");
	FILE* fppat=fopen("pat.mkf","rb");
	
	if((fp==NULL)||(fppat==NULL))
	{
		printf("Usage:rle *.mkf");
		exit(-1);
	}
	
	//*(strrchr(argv[1],'.'))='\0';
	
	mapgroups=fget32(fp)/4-2,pats=fget32(fppat)/4-2;
	
	allegro_init();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED,320,200,0,0);
	install_keyboard();
	atexit(allegro_exit);


	tb=create_bitmap(320,200);
	clear(tb);

	while(running)
	{		
		if(mapgroupchg)
		{	
			seekmkf(fp,mapgroup);s=ftell(fp);
			seekmkf(fp,mapgroup+1);len=ftell(fp)-s;
			if(len==0)
			{
				mapgroupchg=mapchg=1;
				map=0;
				mapgroup++;
				continue;
			}
			else
			{
				fseek(fp,s,SEEK_SET);
				fread(buf,len,1,fp);
				max=*(int*)(buf+4);
				deyj1(&buf);
				pmaps=maps;
				maps=(*(short*)(buf))-1;
				map=0;
				mapchg=1;
				mapgroupchg=0;
				for(j=0;j<=maps;j++)
				{
					if((here=seeksub(buf,j,max))==NULL)
					{
						maps=j-1;break;
					}
					width[j]=*(short*)(here),height[j]=*(short*)(here+2);
					vx[j]=(320-width[j])/2,vy[j]=(200-height[j])/2;
					here+=4;
					if(j<=pmaps) destroy_bitmap(bmp[j]);
					bmp[j]=create_bitmap(width[j],height[j]);
					for(i=0;i<width[j]*height[j];)
					{
						data=*here++;
						rle0=data>0x80?1:0;
						t=i;
						if(rle0)
							for(;i<t+data-0x80;i++)
								putpixel(bmp[j],i%width[j],i/width[j],0);
						else
							for(;i<t+data;i++)
								putpixel(bmp[j],i%width[j],i/width[j],*here++);
					}
				}
				blit(tb,screen,0,0,0,0,320,200);
			}
		}
		
		//change a palette
		if(patchg)
		{
			seekmkf(fppat,pat);
			for(i=0;i<256;i++)
			{	pal[i].r=fget8(fppat);
				pal[i].g=fget8(fppat);
				pal[i].b=fget8(fppat);
			}
			set_palette(pal);
			patchg=0;
		}		
		
		//render a frame
		if(mapchg)
		{
			if((vx[map]>px)||(vy[map]>py)||(width[map]<pw)||(height[map]<ph))
				blit(tb,screen,0,0,0,0,320,200);
			px=vx[map],py=vy[map],pw=width[map],ph=height[map];
			blit(bmp[map], screen, 0, 0, px, py, pw, ph);
			mapchg=0;
		}
		
		textprintf(screen,font,0,0,0xFF,"group:%x,id:%x,pat:%x",mapgroup,map,pat);			

		//Event handling
		while(!keypressed())	rest(100000);
		switch(readkey()>>8) {
		case KEY_DOWN:
			map=(map+1)%(maps+1);
			mapchg=1;
			if(!map)	
				blit(tb,screen,0,0,0,0,320,200);
			break;
		case KEY_RIGHT:
			pat=(pat+1>pats)?pat:pat+1;
			patchg=1;
			break;
		case KEY_PGDN:
			mapgroup=(mapgroup+1>mapgroups)?mapgroup:mapgroup+1;
			mapgroupchg=1;
			break;
		case KEY_UP:
			map=(map-1<0)?maps:map-1;
			mapchg=1;
			break;
		case KEY_LEFT:
			pat=(pat-1<0)?0:pat-1;
			patchg=1;
			break;
		case KEY_PGUP:
			mapgroup=(mapgroup-1<0)?mapgroup:mapgroup-1;
			mapgroupchg=1;
			break;
		case KEY_ESC:
			running=0;
			break;
		case KEY_S:
			sprintf(filename,"%s-%d-%d.bmp",argv[1],mapgroup,map);
			save_bmp(filename,bmp[map],pal);
			break;
		}
	}
	//finalize
	destroy_bitmap(tb);
	for(i=0;i<maps;i++)
		destroy_bitmap(bmp[i]);
	fclose(fp);fclose(fppat);
	free(buf);
	return 0;
}
Пример #6
0
HRESULT XPTypeLibParse(FILE* fp, IXPTypeLib** ppTypeLib)
{
	CXPTypeLib* pTypeLib = new CXPTypeLib;
	pTypeLib->fp = fp;

	int nread = fread(pTypeLib->header.magic, 1, 16, fp);
	if (nread >= 16 && memcmp(pTypeLib->header.magic, "XPCOM\nTypeLib\r\n\032", 16)==0)
	{
		pTypeLib->header.major_version = fget8(fp);
		pTypeLib->header.minor_version = fget8(fp);
		pTypeLib->header.num_interfaces = fget16(fp);
		pTypeLib->header.file_length = fget32(fp);
		pTypeLib->header.interface_directory = fget32(fp);
		pTypeLib->header.data_pool = fget32(fp);

		if (pTypeLib->header.major_version > 1)
		{
//			ATLTRACE("XPCOM TypeLib unsupported major version %d\n", pTypeLib->header.major_version);
			return E_FAIL;
		}

		pTypeLib->ifaces = new CXPIFaceInfo*[pTypeLib->header.num_interfaces];

		fseek(fp, -1 + pTypeLib->header.interface_directory/* + i*sizeof(InterfaceDirectoryEntry)*/, SEEK_SET);

		int i;

		// Read all these in one go
		for (i = 0; i < pTypeLib->header.num_interfaces; i++)
		{
			pTypeLib->ifaces[i] = new CXPIFaceInfo;

			fread(&pTypeLib->ifaces[i]->m_iface_entry.m_iid, 16, 1, fp);
			pTypeLib->ifaces[i]->m_iface_entry.m_name = fget32(fp);
			pTypeLib->ifaces[i]->m_iface_entry.m_namespace = fget32(fp);
			pTypeLib->ifaces[i]->m_iface_entry.m_interface_descriptor = fget32(fp);
		}

		// I currently also read the rest now, but later I may read it only when necessary
		for (i = 0; i < 44/*pTypeLib->header.num_interfaces*/; i++)
		{
			ReadIdentifierFromLocation(fp, -1 + pTypeLib->header.data_pool + pTypeLib->ifaces[i]->m_iface_entry.m_name, pTypeLib->ifaces[i]->m_name);

			if (pTypeLib->ifaces[i]->m_iface_entry.m_namespace)
			{
				ReadIdentifierFromLocation(fp, -1 + pTypeLib->header.data_pool + pTypeLib->ifaces[i]->m_iface_entry.m_namespace, pTypeLib->ifaces[i]->m_namespace);
			}

			pTypeLib->ifaces[i]->m_nFuncs = 0;
			if (pTypeLib->ifaces[i]->m_iface_entry.m_interface_descriptor)
			{
				fseek(fp, -1 + pTypeLib->header.data_pool + pTypeLib->ifaces[i]->m_iface_entry.m_interface_descriptor, SEEK_SET);

				uint16 parent_interface_index = fget16(fp);
				pTypeLib->ifaces[i]->m_nFuncs = fget16(fp);

				pTypeLib->ifaces[i]->m_funcs = new XPFUNCDESC*[pTypeLib->ifaces[i]->m_nFuncs];

				for (int m = 0; m < pTypeLib->ifaces[i]->m_nFuncs; m++)
				{
					pTypeLib->ifaces[i]->m_funcs[m] = new XPFUNCDESC;
					/*
MethodDescriptor {
    boolean         is_getter;
    boolean         is_setter;
    boolean         is_not_xpcom;
    boolean         is_constructor;
    boolean         is_hidden;
    uint3           reserved;
    Identifier*     name;
    uint8           num_args;
    ParamDescriptor params[num_args];
    ParamDescriptor result;
}
*/

					uint8 flags = fget8(fp);
					DWORD name = fget32(fp);
					uint8 num_args = fget8(fp);

					for (int p = 0; p < num_args; p++)
					{
						ReadParamDescriptor(fp);
					}
					ReadParamDescriptor(fp);

					sysstring str;
					ReadIdentifierFromLocation(fp, -1 + pTypeLib->header.data_pool + name, str);
					pTypeLib->ifaces[i]->m_funcs[m]->name = str;
				}

				uint16 num_constants = fget16(fp);
				for (int c = 0; c < num_constants; c++)
				{
				/*
				ConstDescriptor
				{ 
				Identifier*     name;
				TypeDescriptor  type; 
				<type>          value;}
				*/
					DWORD name = fget32(fp);
					uint8 tag = ReadTypeDescriptor(fp);
					if (tag == 0)
					{
						char value = fget8(fp);
					}
					else if (tag == 1)
					{
						short value = fget16(fp);
					}
					else if (tag == 2)
					{
						long value = fget32(fp);
					}
					else if (tag == 4)
					{
						uint8 value = fget8(fp);
					}
					else if (tag == 5)
					{
						uint16 value = fget16(fp);
					}
					else if (tag == 6)
					{
						uint32 value = fget32(fp);
					}
					else
					{
						throw -1;//exit(1);
					}
				}
				/*
				boolean                  is_scriptable;
				boolean                  is_function;
				uint6                    reserved;
				*/
				uint8 flags = fget8(fp);

		/*
InterfaceDescriptor {
    uint16                   parent_interface_index;
    uint16                   num_methods;
    MethodDescriptor         method_descriptors[num_methods];
    uint16                   num_constants;
    ConstDescriptor          const_descriptors[num_constants];
    boolean                  is_scriptable;
    boolean                  is_function;
    uint6                    reserved;

}
		*/
			}
		}

		*ppTypeLib = pTypeLib;
		return S_OK;
	}
	else
	{
		return E_FAIL;
	}
}