/***********************************************************************
*Copyright (c)2012 , 天际边工作室
*All rights reserved.
**
文件名称：	PublicFun.cpp
*摘要：		公用函数，全局函数
**
*修改历史：
*	版本    日期     作者     改动内容和原因
*   ----------------------------------------------------
*	1.0    2012-10-5  wstjb     基本的功能完成
***********************************************************************/

#include "PublicFun.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include "GoodList.h"

using namespace std;

extern  PAINTSTRUCT ps;
extern 	HDC hdc;
extern 	HBITMAP hbmp; 
extern 	HBITMAP hbmp2; 
extern 	BITMAP bmp;
extern 	HDC hdcMem;
extern 	HDC hdcTmp;
extern 	RECT rect;
extern 	HWND hwnd;

extern int color;
extern byte resByte[2731][16384];//存储lib资源
extern int resByteLen[2731];
extern int resPos[2731][6];//存储lib地址和编号 第六位为长度
extern int resCount;
int tmp_order_msg_add;//20160730修正量
extern char g_gameName[9+1];
extern int g_debugFlag;
extern int g_dgdelayFlag;
extern int useEngStr;
extern byte engByte[294912];

char menu_main[4][4+1] ;//= {"属性","魔法","物品","系统"};
char menu_s1[2][4+1];// = {"状态","穿戴"};
char menu_s3[2][4+1];// = {"使用","装备"};
char menu_s4[4][8+1];// = {"读入进度","存储进度","游戏设置","结束游戏"};
char menu_s5[2][6+1];// = {"音乐开","音乐关"};
char menu_s6[5][4+1];// = {"围攻","道具","防御","逃跑","状态"};
char menu_s7[3][4+1];// = {"装备","投掷","使用"};
char menu_money[6+1];//"金钱："
char menu_num[6+1];//"数量"
char menu_price[4+1];//"价"
char menu_name[4+1];//"名"
char menu_cost[6+1];//"耗真气"
char menu_degree[4+1];//"等级"
char menu_hp[4+1];//"生命"
char menu_mp[4+1];//"真气"
char menu_at[6+1];//"攻击力"
char menu_df[6+1];//"防御力"
char menu_exp[6+1];//"经验值"
char menu_speed[4+1];//"身法"
char menu_anima[4+1];//"灵力"
char menu_luck[4+1];//"幸运"
char menu_anti[4+1];//menu_anti

extern int GMCUsed;
/***********************************************************************
* 说明:    显示图片函数
* 输入参数: int delay——显示的时间长度,char *name——显示的图片文件名称,
int ux——显示的x坐标,int uy——显示的y坐标
* 返回值  : 无
* 功能	   : 显示图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void ShowPic(int delay,int restype,int type,int idx,int ux,int uy,int no)
{
	LoadPic(restype,type,idx,hbmp,no);	//封装完成

	//GetObject(hbmp, sizeof(BITMAP), &bmp);
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);

	GetObject(hbmp, sizeof(BITMAP), (LPBYTE)&bmp);
	

	if(GMCUsed == 1)
	{
		PicConverter picConverter;
		int width = picConverter.GetDefaultWidth(restype,type,idx,no);
		int height = picConverter.GetDefaultHeight(restype,type,idx,no);
		if(ux== -1 && uy == -1)
		{
			ux = SCREENWIDTH/2 - width/2;
			uy = SCREENHEIGHT/2 - height/2;
		
		}
		SetStretchBltMode(hdcTmp, COLORONCOLOR);
		StretchBlt(hdcTmp,ux, uy, width, height, hdcMem, 0, 0,bmp.bmWidth,bmp.bmHeight, SRCCOPY);
	}
	else
	{
		if(ux== -1 && uy == -1)
		{
			ux = SCREENWIDTH/2 - bmp.bmWidth/2;
			uy = SCREENHEIGHT/2 - bmp.bmHeight/2;
		
		}
		BitBlt(hdcTmp, ux, uy, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
	}
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp);
	DeleteObject(oldhbmp);
	//BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);

	/*if (delay==-1)
	{
	Delay(2000);
	}
	else 
	{
	Delay(delay);
	}*/
	InvalidateRect(hwnd,&rect,false);
}

/***********************************************************************
* 说明:    直接显示图片函数
* 输入参数: int delay——显示的时间长度,char *name——显示的图片文件名称,
int ux——显示的x坐标,int uy——显示的y坐标
* 返回值  : 无
* 功能	   : 在HDC上直接显示图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-13       完成基本功能
***********************************************************************/

int ShowPicDirect(int delay,int restype,int type,int idx,int ux,int uy,int no)
{

	LoadPic(restype,type,idx,hbmp2,no);	//封装完成

	//GetObject(hbmp, sizeof(BITMAP), &bmp);
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp2);
	GetObject(hbmp2, sizeof(BITMAP), (LPBYTE)&bmp);
	if(ux== -1 && uy == -1)
	{
		
		ux = SCREENWIDTH/2 - bmp.bmWidth/2;
		uy = SCREENHEIGHT/2 - bmp.bmHeight/2;
	}

	if(GMCUsed == 1)
	{
		PicConverter picConverter;
		int width = picConverter.GetDefaultWidth(restype,type,idx,no);
		int height = picConverter.GetDefaultHeight(restype,type,idx,no);
		SetStretchBltMode(hdcTmp, COLORONCOLOR);
		StretchBlt(hdcTmp,ux, uy, width, height, hdcMem, 0, 0,bmp.bmWidth,bmp.bmHeight, SRCCOPY);
		
	}
	else
	{
		BitBlt(hdcTmp, ux, uy, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
		//BitBlt(hdcTmp, ux, uy, 800, 480, hdcMem, 0, 0, SRCCOPY);
		
	}

	BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);

	
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp2);
	DeleteObject(oldhbmp);
	if (delay==-1)
	{
		return(Delay(2000));
	}
	else 
	{
		return(Delay(delay));
	}

}

/***********************************************************************
* 说明:    开始游戏显示图片函数
* 输入参数: int delay——显示的时间长度,char *name——显示的图片文件名称,
int ux——显示的x坐标,int uy——显示的y坐标
* 返回值  : 无
* 功能	   : 开始游戏时直接显示图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-13       完成基本功能
***********************************************************************/
int ShowPicStart(int delay,int restype,int type,int idx,int ux,int uy,int no)
{

	//HDC hdc2=GetDC(hwnd);
	LoadPic(restype,type,idx,hbmp2,no);	//封装完成

	//GetObject(hbmp, sizeof(BITMAP), &bmp);
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp2);
	GetObject(hbmp2, sizeof(BITMAP), (LPBYTE)&bmp);
	if(ux== -1 && uy == -1)
	{
		
		ux = SCREENWIDTH/2 - bmp.bmWidth/2;
		uy = SCREENHEIGHT/2 - bmp.bmHeight/2;
	}

	if(GMCUsed == 1)
	{
		PicConverter picConverter;
		int width = picConverter.GetDefaultWidth(restype,type,idx,no);
		int height = picConverter.GetDefaultHeight(restype,type,idx,no);
		SetStretchBltMode(hdc, COLORONCOLOR);
		StretchBlt(hdc,ux, uy, width, height, hdcMem, 0, 0,bmp.bmWidth,bmp.bmHeight, SRCCOPY);
		
	}
	else
	{
		BitBlt(hdc, ux, uy, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
		//BitBlt(hdc, ux, uy, 800, 480, hdcMem, 0, 0, SRCCOPY);
		
	}

	
	//BitBlt(hdc, ux, uy+50, 800, 480, hdcMem, 0, 0, SRCCOPY);
	InvalidateRect(hwnd,NULL,TRUE);
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp2);
	DeleteObject(oldhbmp);
	//ReleaseDC(hwnd,hdc2);
	if (delay==-1)
	{
		return(Delay(2000));
	}
	else 
	{
		return(Delay(delay));
	}

}

/***********************************************************************
* 说明:    显示图片函数
* 输入参数: int delay——显示的时间长度,char *name——显示的图片文件名称,
char *name1——显示的图片文件的掩膜图片的名称,
int ux——显示的x坐标,int uy——显示的y坐标
int no-图片中编号
* 返回值  : 无
* 功能	   : 显示图片（透明化显示）
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void ShowPicAdd(int delay,int restype,int type,int idx,int ux,int uy,int no)
{

	LoadPicMask(restype,type,idx,hbmp,no);
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
	BitBlt(hdcTmp, ux, uy, 800, 480, hdcMem, 0, 0, SRCPAINT);
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp);
	DeleteObject(oldhbmp);

	LoadPicTrans(restype,type,idx,hbmp,no);	//封装完成
	GetObject(hbmp, sizeof(BITMAP), &bmp);
	oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
	if(GMCUsed == 1)
	{
		PicConverter picConverter;
		int width = picConverter.GetDefaultWidth(restype,type,idx,no);
		int height = picConverter.GetDefaultHeight(restype,type,idx,no);
		SetStretchBltMode(hdcTmp, COLORONCOLOR);
		StretchBlt(hdcTmp,ux, uy, width, height, hdcMem, 0, 0,bmp.bmWidth,bmp.bmHeight, SRCAND);
		
	}
	else
	{
		BitBlt(hdcTmp, ux, uy, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCAND);
		//BitBlt(hdcTmp, ux, uy, 800, 480, hdcMem, 0, 0, SRCAND);
		
	}

	
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp);
	DeleteObject(oldhbmp);
	InvalidateRect(hwnd,&rect,false);
	//DeleteObject(hbmp);


}



/***********************************************************************
* 说明:    加载图片函数
* 输入参数: char *name——显示的图片文件名称,HBITMAP &hbmp——图片dc
* 返回值  : 无
* 功能	   : 加密并加载图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void LoadPic(int restype,int type,int idx,HBITMAP &hbmp,int no)
{
	if(GMCUsed==1)
	{
		char name[MAX_PATH];
		char workpath[MAX_PATH];
		GetModuleFileName(NULL,(LPSTR)workpath,sizeof(workpath));   
		char *p = strrchr(workpath, '\\');  
		*p=0x00;  
		sprintf(name,"%s\\Res\\%s",workpath,Plugin_GetLIBName());
		hbmp = GMCBytesToHBitmap(name,restype,type,idx,no);
	//GMCBytesToHBitmapTrans =0;
	//GMCBytesToHBitmapMask =0;
	//GMCLoadALibhead =0;
	//GMCGetSuffix =0;
	}
	else
	{
		//ChangeFile(name);
		PicConverter picConverter;
		//picConverter = new PicConverter();
		hbmp = picConverter.BytesToHBitmap(restype,type,idx,no);
		//delete picConverter;
		//hbmp = (HBITMAP)LoadImage(NULL, name, IMAGE_BITMAP,0,0, LR_LOADFROMFILE);
		//ChangeFile(name);	
	}
}

/***********************************************************************
* 说明:    加载图片函数
* 输入参数: char *name——显示的图片文件名称,HBITMAP &hbmp——图片dc
* 返回值  : 无
* 功能	   : 加密并加载图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void LoadPicTrans(int restype,int type,int idx,HBITMAP &hbmp,int no)
{
	if(GMCUsed==1)
	{
		char name[MAX_PATH];
		char workpath[MAX_PATH];
		GetModuleFileName(NULL,(LPSTR)workpath,sizeof(workpath));   
		char *p = strrchr(workpath, '\\');  
		*p=0x00;  
		sprintf(name,"%s\\Res\\%s",workpath,Plugin_GetLIBName());
		hbmp = GMCBytesToHBitmapTrans(name,restype,type,idx,no);
	//GMCBytesToHBitmapTrans =0;
	//GMCBytesToHBitmapMask =0;
	//GMCLoadALibhead =0;
	//GMCGetSuffix =0;
	}
	else
	{
		PicConverter picConverter;
		//picConverter = new PicConverter();
		hbmp = picConverter.BytesToHBitmapTrans(restype,type,idx,no);
		//delete picConverter;
	}
}

/***********************************************************************
* 说明:    加载图片函数
* 输入参数: char *name——显示的图片文件名称,HBITMAP &hbmp——图片dc
* 返回值  : 无
* 功能	   : 加密并加载图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void LoadPicMask(int restype,int type,int idx,HBITMAP &hbmp,int no)
{
	if(GMCUsed==1)
	{
		char name[MAX_PATH];
		char workpath[MAX_PATH];
		GetModuleFileName(NULL,(LPSTR)workpath,sizeof(workpath));   
		char *p = strrchr(workpath, '\\');  
		*p=0x00;  
		sprintf(name,"%s\\Res\\%s",workpath,Plugin_GetLIBName());
		hbmp = GMCBytesToHBitmapMask(name,restype,type,idx,no);
	//GMCBytesToHBitmapTrans =0;
	//GMCBytesToHBitmapMask =0;
	//GMCLoadALibhead =0;
	//GMCGetSuffix =0;
	}
	else
	{
		PicConverter picConverter;
		//picConverter = new PicConverter();
		hbmp = picConverter.BytesToHBitmapMask(restype,type,idx,no);
		//delete picConverter;
	}
}


/***********************************************************************
* 说明:    延时函数
* 输入参数: long time——延时等待的时间（毫秒）
* 返回值  : 无
* 功能	   : 延时等待
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
int Delay(long time)
{
	//wlogfile(1, __FUNCTION__ ,"0",0);
	static long old_clock, new_clock; //延时变量
	new_clock=old_clock=GetTickCount();
	while( new_clock < old_clock + time )
	{
		new_clock=GetTickCount();
		int ret = CheckSysMsg();
		if(ret >0)return -1;
		Sleep(1);
	}
	return 0; 
}

int DelayB(long time)
{
	//wlogfile(1, __FUNCTION__ ,"0",0);
	static long old_clock, new_clock; //延时变量
	new_clock=old_clock=GetTickCount();
	while( new_clock < old_clock + time )
	{
		new_clock=GetTickCount();
		int ret = CheckSysMsgB();
		if(ret >0)return -1;
		Sleep(1);
	}
	return 0; 
}

int Check(long time)
{
	static long old_clock, new_clock; //延时变量
	new_clock=old_clock=GetTickCount();
	while( new_clock < old_clock + time )
	{
		new_clock=GetTickCount();
		int ret = CheckSysMsgA();
		if(ret >0)return -1;
		Sleep(1);
	}
	return 0; 
}

int DelayNoRet(long time)
{
	static long old_clock, new_clock; //延时变量
	new_clock=old_clock=GetTickCount();
	while( new_clock < old_clock + time )
	{
		new_clock=GetTickCount();
		Sleep(1);
	}
	return 0; 
}

int CheckSysMsg()
{
	MSG msg;
	if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
	{
		if(GetMessage(&msg,NULL,0,0)) 
		{
			if(msg.message == WM_KEYDOWN)
			{
				tmp_order_msg_add = 1;
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				return 1;
			}
			else if(msg.message != WM_PAINT)
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				//Sleep(5);
			}
		}

	}
	return 0;
}


int CheckSysMsgA()
{
	MSG msg;
	if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
	{
		if(GetMessage(&msg,NULL,0,0)) 
		{
			if(msg.message == WM_KEYDOWN && msg.wParam != VK_ESCAPE)//20181007+ !=VK_ESCAPE
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				return 1;
			}
			else if(msg.message != WM_PAINT)
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				//Sleep(5);
			}
		}

	}
	return 0;
}


int CheckSysMsgB()
{
	MSG msg;
	if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
	{
		if(GetMessage(&msg,NULL,0,0)) 
		{
			if(msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE)
			{
				tmp_order_msg_add = 1;
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				return 1;
			}
			else if(msg.message != WM_PAINT)
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				//Sleep(5);
			}
		}

	}
	return 0;
}


/***********************************************************************
* 说明:    文本显示函数
* 输入参数: char *text——显示的内容,int x——显示的x坐标,
int y——显示的y坐标,int size——文字大小
* 返回值  : 无
* 功能	   : 显示文本
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void ShowText(char *text,int x,int y,int size)
{
	HFONT	h;
	h = CreateFont(size,0,0,0,FW_NORMAL,0,FALSE,FALSE, 
		GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY,FIXED_PITCH|FF_MODERN,"宋体"); 
	HFONT oldh=(HFONT)SelectObject(hdcTmp,h); 

	TextOut(hdcTmp,x,y,text,strlen(text));
	InvalidateRect(hwnd,NULL,FALSE);

	SelectObject(hdcTmp,oldh); 
	DeleteObject(h);

}

void ShowTextDirect(char *text,int x,int y,int size)
{
	HFONT	h;
	h = CreateFont(size,0,0,0,FW_NORMAL,0,FALSE,FALSE, 
		GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY,FIXED_PITCH|FF_MODERN,"宋体"); 
	HFONT oldh=(HFONT)SelectObject(hdc,h); 

	TextOut(hdc,x,y,text,strlen(text));
	InvalidateRect(hwnd,NULL,FALSE);

	SelectObject(hdc,oldh); 
	DeleteObject(h);

}

/***********************************************************************
* 说明:    获取文本函数
* 输入参数: char *filename——文件名称
* 返回值  : 无
* 功能	   : 获取文本内容
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
int GetFileText(char *filename)
{
	ifstream infile(filename,ios::in);
	char *c=new char[20];
	int i=0;
	while(infile.getline(c,20,'\n'))
	{	
		for(int j=0;j<20;j++)
		{
			//texta[i][j]=c[j];
		}
		i++;
	}
	infile.close();
	return i;
}

/***********************************************************************
* 说明:    消息显示函数
* 输入参数: char *text——显示的消息,int posx——左上角x坐标,
int posy——左上角y坐标,int ux——宽度,int uy——高度
* 返回值  : 无
* 功能	   : 获取文本内容
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void Message(char *text,int posx,int posy,int ux,int uy)
{
	HPEN hpen=CreatePen(PS_SOLID,1, RGB(0,0,0));
	HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);
	
	if(GMCUsed == 1)
	{
		HBRUSH hbrush = CreateSolidBrush(RGB(24,132,96));
		HBRUSH holdbrush = (HBRUSH)SelectObject(hdcTmp,hbrush);
		Rectangle(hdcTmp,posx+3,posy+3,ux*16+posx+10,uy*16+posy+6); 
		Rectangle(hdcTmp,posx+4,posy+4,ux*16+posx+9,uy*16+posy+5); 
		Rectangle(hdcTmp,posx,posy,ux*16+posx+8,uy*16+posy+4); 	
		SelectObject(hdcTmp,holdbrush);
		DeleteObject(hbrush);
	}
	else
	{
		Rectangle(hdcTmp,posx+3,posy+3,ux*16+posx+10,uy*16+posy+6); 
		Rectangle(hdcTmp,posx+4,posy+4,ux*16+posx+9,uy*16+posy+5); 
		Rectangle(hdcTmp,posx,posy,ux*16+posx+8,uy*16+posy+4); 	
			
	}

	SelectObject(hdcTmp,oldhpen);
	DeleteObject(hpen);		

	ShowText(text,posx+4,posy+2,16);

}

int TimerMessage(char *text,int posx,int posy,int ux,int uy,int delay)
{
	if(strlen(text)>16 && strlen(text)<=32)
	{
		posy -=8;
		uy++;
	}

	HPEN hpen=CreatePen(PS_SOLID,1, RGB(0,0,0));
	HPEN oldhpen=(HPEN)SelectObject(hdc,hpen);
	
	if(GMCUsed == 1)
	{
		HBRUSH hbrush = CreateSolidBrush(RGB(24,132,96));
		HBRUSH holdbrush = (HBRUSH)SelectObject(hdc,hbrush);
		Rectangle(hdc,posx+3,posy+3,ux*16+posx+10,uy*16+posy+6); 
		Rectangle(hdc,posx+4,posy+4,ux*16+posx+9,uy*16+posy+5); 
		Rectangle(hdc,posx,posy,ux*16+posx+8,uy*16+posy+4); 	
		SelectObject(hdc,holdbrush);
		DeleteObject(hbrush);
	}
	else
	{
		Rectangle(hdc,posx+3,posy+3,ux*16+posx+10,uy*16+posy+6); 
		Rectangle(hdc,posx+4,posy+4,ux*16+posx+9,uy*16+posy+5); 
		Rectangle(hdc,posx,posy,ux*16+posx+8,uy*16+posy+4); 	
			
	}
	
	SelectObject(hdc,oldhpen);
	DeleteObject(hpen);		
	if(strlen(text)>16 && strlen(text)<=32)
	{
		char tmp[16+1];
		memcpy(tmp,text,16);
		tmp[16]='\0';
		ShowTextDirect(tmp,posx+4,posy+2,16);	
		memcpy(tmp,text+16,strlen(text)-8);
		tmp[16]='\0';
		ShowTextDirect(tmp,posx+4,posy+16+2,16);
	}
	else
	{
		ShowTextDirect(text,posx+4,posy+2,16);		
	}
	return(Delay(delay));

}

void TimerMessageNoText(char *text,int posx,int posy,int ux,int uy,int delay)
{


	HPEN hpen=CreatePen(PS_SOLID,1, RGB(0,0,0));
	HPEN oldhpen=(HPEN)SelectObject(hdc,hpen);
	Rectangle(hdc,posx+3,posy+3,ux*16+posx+10,uy*16+posy+6); 
	Rectangle(hdc,posx+4,posy+4,ux*16+posx+9,uy*16+posy+5); 
	Rectangle(hdc,posx,posy,ux*16+posx+8,uy*16+posy+4); 	
	SelectObject(hdc,oldhpen);
	DeleteObject(hpen);		

}


int PlcExtract(int num)//求平方根
{
	int	gen,step;
	int	tcnt;

	gen = 0;
	step = 10;
	while(1)
	{
		if(!step) break;
		tcnt = gen + step;
		if((int)tcnt * tcnt < num)
			gen = tcnt;
		else
			step -= 1;		
	}
	return gen;
}

/***********************************************************************
* 说明:  文件操作读取函数并获取文件长度
*输入参数：char *outBuf——输出的buff
*					char *filename ----文件名 flag-0lib 1gam
*         char *path ---相对路径（版本号）
* 返回值  : len-长度 -1 错误
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2014-11-17       完成基本功能
***********************************************************************/
long readFromFile(byte *outBuf,char *filename,int flag)
{

	int ret = 0;
	int len = 0;

	FILE *fp=NULL;
	fp = fopen(filename,"rb+");//二进制读，追加
	if(!fp)return -1;//出错处理
	fseek(fp,0L,SEEK_END);
	if(flag == 2)
	{
		len = 294912;
		fseek(fp,0L,SEEK_SET);
	}
	else
	{
		len = ftell(fp) - flag*294912;
		fseek(fp,0L + flag*294912,SEEK_SET);
	}

	fread(outBuf,1,len,fp);
	fclose(fp);
	return len;
}

int BytesToInt4(byte * bytes)
{
	int a = bytes[0] & 0xFF;
	a |= ((bytes[1] << 8) & 0xFF00);
	a |= ((bytes[2] << 16) & 0xFF0000);
	a |= ((bytes[3] << 24) & 0xFF000000);
	return a;
}

int BytesToInt2(byte * bytes)
{
	int a = bytes[0] & 0xFF;
	a |= ((bytes[1] << 8) & 0xFF00);
	return a;
}

int BytesToInt1(byte * bytes)
{
	int a = bytes[0] & 0xFF;
	return a;
}

void  IntToBytes4(int i,byte *bytes)
{
	memset(bytes,0,sizeof(byte) *  4);
	bytes[0] = (byte) (0xff & i);
	bytes[1] = (byte) ((0xff00 & i) >> 8);
	bytes[2] = (byte) ((0xff0000 & i) >> 16);
	bytes[3] = (byte) ((0xff000000 & i) >> 24);
	return ;
}

void  IntToBytes2(int i,byte *bytes)
{
	memset(bytes,0,sizeof(byte) *  2);
	bytes[0] = (byte) (0xff & i);
	bytes[1] = (byte) ((0xff00 & i) >> 8);
	return ;
}

void  IntToBytes1(int i,byte *bytes)
{
	memset(bytes,0,sizeof(byte) );
	bytes[0] = (byte) (0xff & i);
	return ;
}

/***********************************************************************
* 说明:    显示特效
* 输入参数: 
int ux——显示的x坐标,int uy——显示的y坐标 offsetx y-偏移量 用于战斗不同角色
showtype 0 -全屏清空显示 1-不清空显示
* 返回值  : 无
* 功能	   : 在HDC上直接显示特效
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-13       完成基本功能
***********************************************************************/
void ShowCG(int type,int idx,int ux,int uy,int showtype,int offsetx,int offsety)
{
	//wlogfile(3,__FUNCTION__,"START",idx);
	//获取特效属性。x y 延时等
	//获取特效图片,循环显示
	//类型 （01-过场动画 02-战斗动画） 编号 帧数 最大图号 起始帧 终止帧 【x y show nshow 图号 】*帧数 【特效图片（类型 编号 x y 01 透明 图片像素）】*图片数 
	//由于show nshow缘故 调整为预先加载图片。循环获取，判断生存期
	int effecttype = 0;
	int no = 0;
	int frameCount = 0;
	int picCount = 0;
	int startFrame = 0;
	int endFrame = 0;
	int frameInfo[200][5];//存储帧信息
	int frameStartTime[200];
	int lastTime = 0;//整个持续时间

	int resnum = GetResNum(RES_SRS,type,idx);
	//20181216
	if(resnum == -1)return;

	HBITMAP hbmp_a[200]; //mask
	HBITMAP hbmp_b[200]; //
	int pictype[200];//1-非透明 2-透明
	int tmpf = 0;

	
	effecttype = resByte[resnum][0];
	no = resByte[resnum][1];
	frameCount = resByte[resnum][2];
	picCount = resByte[resnum][3];
	startFrame = resByte[resnum][4];
	endFrame = resByte[resnum][5];

	for(int i = startFrame;i<frameCount;i++)
	{
		frameInfo[i][0]= resByte[resnum][6+i*5];
		frameInfo[i][1]= resByte[resnum][6+i*5+1];
		frameInfo[i][2]= resByte[resnum][6+i*5+2];
		frameInfo[i][3]= resByte[resnum][6+i*5+3];
		frameInfo[i][4]= resByte[resnum][6+i*5+4];

	}

	//循环获取图片到hbtmap
	for(int i = 0 ; i < picCount ; i++)
	{
		pictype[i] = LoadCGPicMask(i,resnum,frameCount,hbmp_a[i]);	
		if(pictype[i] == 1)
		{
			LoadCGPic(i,resnum,frameCount,hbmp_b[i]);	
		}
		else
		{
			LoadCGPicTrans(i,resnum,frameCount,hbmp_b[i]);	
		}
	}

	//获取每个帧的开始时间
	for(int i = 0 ;i <frameCount ; i++)
	{
		frameStartTime[i] = lastTime;
		lastTime += frameInfo[i][3];
	}

	HDC hdcstore = CreateCompatibleDC(hdc);
	HBITMAP hbmpstore = CreateCompatibleBitmap(hdc,800,600);
	SelectObject(hdcstore,hbmpstore);
	DeleteObject(hbmpstore);

	if(showtype > 1)//保存当前dc
	{
		BitBlt(hdcstore, 0, 0, 800, 480, hdcTmp, 0, 0, SRCCOPY);
	}

	//20170129修正部分情况下特效显示异常（nshow全部=0）
	if(lastTime == 0)lastTime = frameInfo[0][2];
	for(int i = 0 ;i < lastTime ; i++)
	{
		if(showtype == 0)  
		{
			//BitBlt(hdc, 0, 0, 800, 480, hdcMem, 0, 0, WHITENESS);
			BitBlt(hdcTmp, 0, 0, 800, 480, hdcMem, 0, 0, WHITENESS);
		}
		else if(showtype == 8)  
		{
			//BitBlt(hdc, 0, 0, 800, 480, hdcMem, 0, 0, WHITENESS);
			BitBlt(hdcTmp, 0, 0, 800, 480, hdcMem, 0, 0, WHITENESS);
		}
		else if(showtype > 1)  
		{
			BitBlt(hdcTmp, 0, 0, 800, 480, hdcMem, 0, 0, WHITENESS);
			BitBlt(hdcTmp, 0, 0, 800, 480, hdcstore, 0, 0, SRCCOPY);
		}

		//倒序检测之前帧有无持续的显示
		for(int k = startFrame;k< frameCount ; k++)
		{
			if( frameStartTime[k] + frameInfo[k][2] + 1 > i && frameStartTime[k] <= i )//判断为可显示帧
			{
				if(pictype[frameInfo[k][4]] == 1)//非透明
				{
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp_b[frameInfo[k][4]]);
					BitBlt(hdcTmp, offsetx + frameInfo[k][0], offsety + frameInfo[k][1], 800, 480, hdcMem, 0, 0, SRCCOPY);

					SelectObject(hdcMem, oldhbmp);
					DeleteObject(oldhbmp);
				}
				else
				{
					//BitBlt(hdcTmp, 0, 0, 800, 480, hdcMem, 0, 0, SRCCOPY);
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp_a[frameInfo[k][4]]);

					BitBlt(hdcTmp, offsetx + frameInfo[k][0], offsety + frameInfo[k][1], 800, 480, hdcMem, 0, 0, SRCPAINT);
					SelectObject(hdcMem, oldhbmp);

					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp_b[frameInfo[k][4]]);
					BitBlt(hdcTmp, offsetx + frameInfo[k][0], offsety + frameInfo[k][1], 800, 480, hdcMem, 0, 0, SRCAND);


					SelectObject(hdcMem, oldhbmp);
					DeleteObject(oldhbmp);
				}
			}

		}
		BitBlt(hdc, ux, uy, 800, 480, hdcTmp, 0, 0, SRCCOPY);
		InvalidateRect(hwnd,NULL,true);

		if(showtype < 0)//开头CHOICE，按ESC返回
		{
			if(Check(10))break;
		}
		else if(showtype == 8)//开头247 248，按ESC返回
		{
			if(DelayB(10))break;
		}
		else if(showtype == 9)//20181103特殊的战斗中的特效播放
        {
            DelayNoRet(10);
        }
		else if(showtype == 0||showtype == 2)//无按键
        {
            DelayNoRet(10);
        }
        else if(showtype == 1||showtype == 3)//按键返回
        {
            //DelayNoRet(10);
            if(Delay(10))break;//用delay替换允许esc
        }
		
	}
	
	//释放bitmap
	for(int i = 0 ; i < 100 ; i++)
	{
		if(hbmp_a[i]!=NULL)
		{
			DeleteObject(hbmp_a[i]);
			hbmp_a[i] = NULL;
		}
		if(hbmp_b[i]!=NULL)
		{
			DeleteObject(hbmp_b[i]);
			hbmp_b[i] = NULL;
		}
	}
	DeleteObject(hdcstore);

}

int GetResNum( int type,int restype,int idx)
{
	for (int ii = 0; ii < resCount / 3; ii++)//原有
	{
		if (resPos[ii][0] == type && resPos[ii][1] == restype && resPos[ii][2] == idx)
		{
			return ii;
		}
	}
	return -1;
}

int CheckResExits( int type,int restype,int idx)
{
	for (int ii = 0; ii < resCount / 3; ii++)//原有
	{
		if (resPos[ii][0] == type && resPos[ii][1] == restype && resPos[ii][2] == idx)
		{
			return 1;
		}
	}
	return 0;
}

/***********************************************************************
* 说明:    加载特效图片函数
* 输入参数: char *name——显示的图片文件名称,HBITMAP &hbmp——图片dc
* 返回值  : 无
* 功能	   : 加密并加载图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void LoadCGPic(int picnum,int resnum ,int framecount, HBITMAP &hbmp)
{
	PicConverter picConverter;
	//picConverter = new PicConverter();
	hbmp = picConverter.BytesToHBitmapCG(picnum,resnum,framecount);
	//delete picConverter;
}

/***********************************************************************
* 说明:    加载特效图片函数
* 输入参数: char *name——显示的图片文件名称,HBITMAP &hbmp——图片dc
* 返回值  : 无
* 功能	   : 加密并加载图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
int LoadCGPicMask(int picnum,int resnum ,int framecount, HBITMAP &hbmp)
{
	int ret = 0;
	PicConverter picConverter;
	//picConverter = new PicConverter();
	hbmp = picConverter.BytesToHBitmapCGMask(picnum,resnum,framecount,ret);
	//delete picConverter;
	return ret;

}

/***********************************************************************
* 说明:    加载特效图片函数
* 输入参数: char *name——显示的图片文件名称,HBITMAP &hbmp——图片dc
* 返回值  : 无
* 功能	   : 加密并加载图片
* 修改历史:
*               姓名            日期             说明
*             ------          ----------      -------------
*             wstjb          2012-10-5       完成基本功能
***********************************************************************/
void LoadCGPicTrans(int picnum,int resnum ,int framecount, HBITMAP &hbmp)
{
	PicConverter picConverter;
	//picConverter = new PicConverter();
	hbmp = picConverter.BytesToHBitmapCGTrans(picnum,resnum,framecount);
	//delete picConverter;

}


void ClrScence()
{
	//BitBlt(hdc, 0, 0, 800, 480, hdcMem, 0, 0, WHITENESS);
	BitBlt(hdcTmp, 0, 0, 800, 480, hdcMem, 0, 0, WHITENESS);
}

void ShowMapPic(int idx,int x,int y,int mapType,int mapIdx)
{
	int resnum = GetResNum(RES_MAP,mapType,mapIdx);

	int width = 0;
	int height = 0;
	byte mapByte[20000];
	int mapByteLen= 0;
	int b = 0;

	width = resByte[resnum][16];
	height = resByte[resnum][17];

	for(int a = 18 ; a < resByteLen[resnum] ;a++)
	{
		if(resByte[resnum][a]>=128)
		{
			mapByte[b] = resByte[resnum][a] - 128;
		}
		else
		{
			mapByte[b] = resByte[resnum][a];
		}
		a++;
		b++;
	}
	mapByteLen = b;

	BITMAP bwh;
	for(int g=0;g<6;g++)
	{
		for(int h=0;h<9;h++)
		{
			LoadTile(idx,mapByte[width * ( g + y ) + h + x],hbmp);	
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			
			if(GMCUsed == 1 )
			{
				GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
				SetStretchBltMode(hdcTmp, COLORONCOLOR);
				StretchBlt(hdcTmp,TILEPICWIDTH*h+8, TILEPICHEIGHT*g, TILEPICWIDTH, TILEPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
			}
			else
			{
				BitBlt(hdcTmp, TILEPICWIDTH*h+8, TILEPICHEIGHT*g, TILEPICWIDTH, TILEPICHEIGHT, hdcMem, 0, 0, SRCCOPY);
			}

			
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);
		}
	}



}

void LoadTile(int idx,int i ,HBITMAP &hbmp)
{
	if(GMCUsed==1)
	{
		char name[MAX_PATH];
		char workpath[MAX_PATH];
		GetModuleFileName(NULL,(LPSTR)workpath,sizeof(workpath));   
		char *p = strrchr(workpath, '\\');  
		*p=0x00;  
		sprintf(name,"%s\\Res\\%s",workpath,Plugin_GetLIBName());
		hbmp = GMCBytesToHBitmap(name,RES_TIL,1,idx,i);
	
	}
	else
	{
		PicConverter picConverter;
		//picConverter = new PicConverter();
		hbmp = picConverter.BytesToHBitmap(RES_TIL,1,idx,i);
		//delete picConverter;
	}


	
}

void ShowRolePic(int delay,int type,int idx,int ux,int uy,int roleIdx)
{
	int type1 = GetType(RES_ACP,type,idx);
	BITMAP bwh;

	if(type1 == 1)
	{
		LoadPic(RES_ACP,type,idx,hbmp,roleIdx);	//封装完成
		
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed==1)
		{
			
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, ACTORPICWIDTH, ACTORPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
		}
		else
		{
			
			BitBlt(hdcTmp, ux, uy, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCCOPY);
		}

		
		SelectObject(hdcMem, oldhbmp);
		InvalidateRect(hwnd,&rect,false);
		DeleteObject(hbmp);
	}
	else
	{
		LoadPicMask(RES_ACP,type,idx,hbmp,roleIdx);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed==1)
		{
			
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, ACTORPICWIDTH, ACTORPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCPAINT);
		}
		else
		{
			
			BitBlt(hdcTmp, ux, uy, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCPAINT);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_ACP,type,idx,hbmp,roleIdx);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed==1)
		{
			
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, ACTORPICWIDTH, ACTORPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCAND);
		}
		
		else
		{
			
			BitBlt(hdcTmp, ux, uy, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCAND);
		}
		
		SelectObject(hdcMem, oldhbmp);
		InvalidateRect(hwnd,&rect,false);
		DeleteObject(hbmp);
	}
}

void ShowSayBox(char *text1,char *text2,int type)
{

	if(type > 0 )
	{
		HPEN hpen=CreatePen(PS_SOLID,1, RGB(0,0,0));
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);
		if(GMCUsed == 1)
		{
			HBRUSH hbrush = CreateSolidBrush(RGB(24,132,96));
			HBRUSH holdbrush = (HBRUSH)SelectObject(hdcTmp,hbrush);
			Rectangle(hdcTmp,9,50,149,96); 	
			SelectObject(hdcTmp,holdbrush);
			DeleteObject(hbrush);
		}
		else
		{
			Rectangle(hdcTmp,9,50,149,96); 	
		}
		
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);		

		ShowText(text1,48,58,16);
		MoveToEx(hdcTmp,40,50,NULL);
		LineTo(hdcTmp,46,56);
		//MoveToEx(hdcTmp,46,56,NULL);
		LineTo(hdcTmp,149,56);
		ShowHeadPic(0,type,16,48);
	}
	else
	{
		HPEN hpen=CreatePen(PS_SOLID,1, RGB(0,0,0));
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);
		if(GMCUsed == 1)
		{
			HBRUSH hbrush = CreateSolidBrush(RGB(24,132,96));
			HBRUSH holdbrush = (HBRUSH)SelectObject(hdcTmp,hbrush);
			Rectangle(hdcTmp,9,55,149,96); 	
			SelectObject(hdcTmp,holdbrush);
			DeleteObject(hbrush);
		}
		else
		{
			Rectangle(hdcTmp,9,55,149,96); 	
		}
		
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);		

		ShowText(text1,16,58,16);
	}
	ShowText(text2,16,76,16);

}

void ShowHeadPic(int delay,int idx,int ux,int uy,int headIdx)
{
	int type1 = GetType(RES_PIC,1,idx);
	BITMAP bwh;
	if(type1 == 1)
	{
		LoadPic(RES_PIC,1,idx,hbmp,headIdx);	//封装完成
		
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, HEADPICWIDTH, HEADPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
		}
		else
		{
			BitBlt(hdcTmp, ux, uy, HEADPICWIDTH, HEADPICHEIGHT, hdcMem, 0, 0, SRCCOPY);
		}

		SelectObject(hdcMem, oldhbmp);
		InvalidateRect(hwnd,&rect,false);
		DeleteObject(hbmp);
	}
	else
	{
		LoadPicMask(RES_PIC,1,idx,hbmp,headIdx);
		
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, HEADPICWIDTH, HEADPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCPAINT);
		}
		else
		{
			BitBlt(hdcTmp, ux, uy, HEADPICWIDTH, HEADPICHEIGHT, hdcMem, 0, 0, SRCPAINT);
		}
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_PIC,1,idx,hbmp,headIdx);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, HEADPICWIDTH, HEADPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCAND);
		}
		else
		{
			BitBlt(hdcTmp, ux, uy, HEADPICWIDTH, HEADPICHEIGHT, hdcMem, 0, 0, SRCAND);
		}
		SelectObject(hdcMem, oldhbmp);
		InvalidateRect(hwnd,&rect,false);
		DeleteObject(hbmp);
	}
}

void CopyToHdc()
{
	BitBlt(hdc,0,0,800,480,hdcTmp,0,0,SRCCOPY);
}

void ShowGoodPic(int delay,int type,int idx,int ux,int uy)
{
	GoodList glist;
	glist.Init();
	BITMAP bwh;
	int picIdx = glist.good[type-1][idx-1].picnum;
	int type1 = GetType(RES_GDP,type,picIdx);
	if(type1 == 1)
	{
		LoadPic(RES_GDP,type,picIdx,hbmp);
		
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, GOODPICWIDTH, GOODPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
		}
		else
		{
			BitBlt(hdcTmp, ux, uy, GOODPICWIDTH, GOODPICHEIGHT, hdcMem, 0, 0, SRCCOPY);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
		InvalidateRect(hwnd,&rect,false);
	}
	else
	{
		LoadPicMask(RES_GDP,type,picIdx,hbmp);
		
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, GOODPICWIDTH, GOODPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCPAINT);
		}
		else
		{
			BitBlt(hdcTmp, ux, uy, GOODPICWIDTH, GOODPICHEIGHT, hdcMem, 0, 0, SRCPAINT);
		}
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_GDP,type,picIdx,hbmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,ux, uy, GOODPICWIDTH, GOODPICHEIGHT, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCAND);
		}
		else
		{
			BitBlt(hdcTmp, ux, uy, GOODPICWIDTH, GOODPICHEIGHT, hdcMem, 0, 0, SRCAND);
		}
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		InvalidateRect(hwnd,&rect,false);
	}
}

void ShowFightScene(int scrb,int scrl,int scrr)
{
	LoadPic(RES_PIC,4,scrb,hbmp);
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
	BitBlt(hdcTmp, 0, 0, 159, 96, hdcMem, 0, 0, SRCCOPY);
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp);

	BITMAP bwh;

	int type1 = GetType(RES_PIC,4,scrl);
	if(type1 == 1)
	{
		LoadPic(RES_PIC,4,scrl,hbmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,0, 96 - bwh.bmHeight, 159, 60,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
		}
		else
		{
			BitBlt(hdcTmp, 0, 96 - bwh.bmHeight, 159, 60, hdcMem, 0, 0, SRCCOPY);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}
	else
	{
		LoadPicMask(RES_PIC,4,scrl,hbmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,0, 96 - bwh.bmHeight, 159, 60,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCPAINT);
		}
		else
		{
			BitBlt(hdcTmp, 0, 96 - bwh.bmHeight, 159, 60, hdcMem, 0, 0, SRCPAINT);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_PIC,4,scrl,hbmp);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,0, 96 - bwh.bmHeight, 159, 60,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCAND);
		}
		else
		{
			BitBlt(hdcTmp, 0, 96 - bwh.bmHeight, 159, 60, hdcMem, 0, 0, SRCAND);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
		InvalidateRect(hwnd,&rect,false);
	}

	type1 = GetType(RES_PIC,4,scrr);
	if(type1 == 1)
	{
		LoadPic(RES_PIC,4,scrr,hbmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		if(GMCUsed == 1 )
		{
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,160 - bwh.bmWidth, 0, 159, 60,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
		}
		else
		{
			BitBlt(hdcTmp, 160 - bwh.bmWidth, 0, 159, 60, hdcMem, 0, 0, SRCCOPY);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}
	else
	{
		LoadPicMask(RES_PIC,4,scrr,hbmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		if(GMCUsed == 1 )
		{
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,160 - bwh.bmWidth, 0, 159, 60,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCPAINT);
		}
		else
		{
			BitBlt(hdcTmp, 160 - bwh.bmWidth, 0, 159, 60, hdcMem, 0, 0, SRCPAINT);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_PIC,4,scrr,hbmp);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,160 - bwh.bmWidth, 0, 159, 60,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCAND);
		}
		else
		{
			BitBlt(hdcTmp, 160 - bwh.bmWidth, 0, 159, 60, hdcMem, 0, 0, SRCAND);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}


	InvalidateRect(hwnd,&rect,false);


}

void ShowFightChoice(int id)
{
	BITMAP bwh;
	HBITMAP oldhbmp;
	//轮盘
	int type1 = GetType(RES_PIC,2,1);
	if(type1 == 1)
	{
		LoadPic(RES_PIC,2,1,hbmp,id);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			PicConverter picConverter;
			int width = picConverter.GetDefaultWidth(RES_PIC,2,1,id);
			int height = picConverter.GetDefaultHeight(RES_PIC,2,1,id);
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,7, 96 - height, 40, 34, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
		}
		else
		{
			BitBlt(hdcTmp, 7, 96 - bwh.bmHeight,40, 34,  hdcMem, 0, 0, SRCCOPY);
		}

		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}
	else
	{
		LoadPicMask(RES_PIC,2,1,hbmp,id);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			PicConverter picConverter;
			int width = picConverter.GetDefaultWidth(RES_PIC,2,1,id);
			int height = picConverter.GetDefaultHeight(RES_PIC,2,1,id);
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,7, 96 - height, 40, 34, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCPAINT);
		}
		else
		{
			BitBlt(hdcTmp, 7, 96 - bwh.bmHeight,40, 34,  hdcMem, 0, 0, SRCPAINT);
		}

		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_PIC,2,1,hbmp,id);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			PicConverter picConverter;
			int width = picConverter.GetDefaultWidth(RES_PIC,2,1,id);
			int height = picConverter.GetDefaultHeight(RES_PIC,2,1,id);
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,7, 96 - height, 40, 34, hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCAND);
		}
		else
		{
			BitBlt(hdcTmp, 7, 96 - bwh.bmHeight,40, 34,  hdcMem, 0, 0, SRCAND);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}

	//框
	type1 = GetType(RES_PIC,2,2);
	if(type1 == 1)
	{
		LoadPic(RES_PIC,2,2,hbmp);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,49, 66, 75, 27,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCCOPY);
		}
		else
		{
			BitBlt(hdcTmp, 49, 66, 75, 27, hdcMem, 0, 0, SRCCOPY);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}
	else
	{
		LoadPicMask(RES_PIC,2,2,hbmp);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,49, 66, 75, 27,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCPAINT);
		}
		else
		{
			BitBlt(hdcTmp, 49, 66, 75, 27, hdcMem, 0, 0, SRCPAINT);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_PIC,2,2,hbmp);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		if(GMCUsed == 1 )
		{
			
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			SetStretchBltMode(hdcTmp, COLORONCOLOR);
			StretchBlt(hdcTmp,49, 66, 75, 27,hdcMem, 0, 0,bwh.bmWidth,bwh.bmHeight, SRCAND);
		}
		else
		{
			BitBlt(hdcTmp, 49, 66, 75, 27, hdcMem, 0, 0, SRCAND);
		}
		
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}
}

int GetMaxPicNumber(int restype,int type,int idx)
{
	PicConverter picConverter;
	//picConverter = new PicConverter();
	int ret = picConverter.GetPicNumInPic(restype,type,idx);
	//delete picConverter;
	return ret;
}

void ShowNumInPic(int posX,int posY,int num,int before,int size)
{
	BITMAP bwh;
	if(before==1)
	{
		LoadPic(RES_PIC,2,6,hbmp);
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		BitBlt(hdcTmp, posX, posY, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCCOPY);
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
	}
	if(before==2)
	{
		LoadPic(RES_PIC,2,7,hbmp);
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		BitBlt(hdcTmp, posX, posY+2, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCCOPY);
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
		before = 1;
	}

	int tmpNum = num;
	if(tmpNum>99999999)return;
	int div = 10000000;
	int i = 0;
	while(div>1)
	{

		tmpNum = num%div/(div/10);

		if(tmpNum == 0 && div>num)
		{
			div = div/10;
			if(div == 1)//0值
			{
				LoadPicMask(RES_PIC,2,5,hbmp,tmpNum);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
				BitBlt(hdcTmp, posX+before*8+i*6, posY, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCPAINT);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);

				LoadPicTrans(RES_PIC,2,5,hbmp,tmpNum);	//封装完成
				//GetObject(hbmp, sizeof(BITMAP), &bmp);
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, posX+before*8+i*6, posY, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCAND);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);
			}
			continue;
		}
		LoadPicMask(RES_PIC,2,5,hbmp,tmpNum);
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
		BitBlt(hdcTmp, posX+before*size/2+i*6, posY, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCPAINT);
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);

		LoadPicTrans(RES_PIC,2,5,hbmp,tmpNum);	//封装完成
		//GetObject(hbmp, sizeof(BITMAP), &bmp);
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdcTmp, posX+before*size/2+i*6, posY, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCAND);
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
		//InvalidateRect(hwnd,&rect,false);
		div = div/10;
		i++;
	}

	InvalidateRect(hwnd,NULL,FALSE);
}

int TimerMessageFight(int exp,int money,int delay)
{
	char temp[20];
	int posx = 20;
	int posy = 20;
	memset (temp,0,sizeof(temp));
	ShowPic(0,RES_PIC,2,8,posx,posy-2,0);
	ShowPic(0,RES_PIC,2,8,posx+7*16,posy-2,1);
	ShowPic(0,RES_PIC,2,8,posx-10,posy+30-2,0);
	ShowPic(0,RES_PIC,2,8,posx-10+8*16,posy+30-2,1);

	HPEN hpen=CreatePen(PS_SOLID,1, RGB(0,0,0));
	HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);

	Rectangle(hdcTmp,posx+3,posy,posx+7*16+1,posy + 1*16+4); 	
	Rectangle(hdcTmp,posx+3-10,posy+30,posx-10+8*16+1,posy+30+1*16+4); 
	SelectObject(hdcTmp,oldhpen);
	DeleteObject(hpen);		



	ShowText("获得经验",posx+2,posy+2,16);	
	sprintf_s(temp,"%d",exp);
	ShowText(temp,posx+68,posy+2,16);	

	ShowText("战斗获得    钱",posx-8+2,posy+30+2,16);	
	sprintf_s(temp,"%d",money);
	ShowText(temp,posx-8+68,posy+30+2,16);	
	BitBlt(hdc,0,0,800,600,hdcTmp,0,0,SRCCOPY);

	return(Delay(delay));

}

int GetType(int type,int restype,int index)
{
	int resnum = 0;//资源编号

	resnum = GetResNum(type,restype,index);

	return BytesToInt1(&resByte[resnum][5]);
}


void wlogfile(int type,char *infun,char *inmsg,int result)
{
	char filename[100];
	char filename1[200];
	char name1[200];
	char now[30];
	memset(filename,0,sizeof(filename));
	memset(filename1,0,sizeof(filename1));
	memset(name1,0,sizeof(name1));
	memset(now,0,sizeof(now));
	time_t tt = time(NULL);
	tm* t= localtime(&tt);
	sprintf(now,"%d-%02d-%02d %02d:%02d:%02d", 
		t->tm_year + 1900,
		t->tm_mon + 1,
		t->tm_mday,
		t->tm_hour,
		t->tm_min,
		t->tm_sec);

	GetModuleFileName(NULL,name1,200); 
	(strrchr(name1, '\\'))[1] = 0;
	sprintf(filename,"%s\\Res\\Log\\%d%02d%02d.log",name1,t->tm_year + 1900,t->tm_mon + 1, t->tm_mday);


	if(type == 5)//清理现有日志
	{
		sprintf(filename1,"%s\\Res\\Log\\Err\\%d%02d%02d%02d%02d%02d.log",name1,t->tm_year + 1900,t->tm_mon + 1, t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
		MoveFile(filename,filename1);
		type = 1;
	}
	ofstream outfile(filename,ios::app|ios::out);
	//if(result != 0)
	{
		if(type == 1)
		{
			outfile<<now<<":"<<":常规:"<<infun<<":"<<inmsg<<":"<<result<<endl;
		}
		else if(type == 2)
		{
			outfile<<now<<":"<<":错误:"<<infun<<":"<<inmsg<<":"<<result<<endl;
		}
		else if(type == 3)
		{
			outfile<<now<<":"<<":测试:"<<infun<<":"<<inmsg<<":"<<result<<endl;
		}
	}
	/*else
	{
	if(type == 1)
	{
	outfile<<now<<":"<<":常规:"<<infun<<inmsg<<endl;
	}
	else if(type == 2)
	{
	outfile<<now<<":"<<":错误:"<<infun<<inmsg<<endl;
	}
	else if(type == 3)
	{
	outfile<<now<<":"<<":测试:"<<infun<<inmsg<<endl;
	}
	}*/
	outfile.close();
}

LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)  
{
	char filename1[500];
	char now[30];
	time_t tt = time(NULL);
	tm* t= localtime(&tt);
	sprintf(now,"%d-%02d-%02d %02d:%02d:%02d", 
		t->tm_year + 1900,
		t->tm_mon + 1,
		t->tm_mday,
		t->tm_hour,
		t->tm_min,
		t->tm_sec);
	wlogfile(1, "TopLevelExceptionFilter" ,"Enter TopLevelExceptionFilter Function",0); 

	TCHAR szPath[MAX_PATH];
	if( !GetModuleFileName( NULL, szPath, MAX_PATH ) )
	{
		wlogfile(2, "TopLevelExceptionFilter" ,"GetModuleFileName failed (%d)",GetLastError()); 
	}
	char *p = strrchr(szPath, '\\');  
	*p=0x00;  

	memset(filename1,0,sizeof(filename1));
	sprintf(filename1,"%s\\Res\\Log\\%d%02d%02d%02d%02d%02d.dmp",szPath,t->tm_year + 1900,t->tm_mon + 1, t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);

	HANDLE hFile = CreateFile(filename1,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);  
	MINIDUMP_EXCEPTION_INFORMATION stExceptionParam;  
	stExceptionParam.ThreadId    = GetCurrentThreadId();  
	stExceptionParam.ExceptionPointers = pExceptionInfo;  
	stExceptionParam.ClientPointers    = FALSE;  
	MiniDumpWriteDump(GetCurrentProcess(),GetCurrentProcessId(),hFile,MiniDumpNormal,&stExceptionParam,NULL,NULL);  
	CloseHandle(hFile);  

	//调用崩溃程序 包括以下信息 dmp save log 
	char execcmd[500];
	memset(execcmd,0,sizeof(execcmd));

	sprintf(execcmd,"CrashReport.exe SkySimulater %s SkySimulater错误报告 %s",filename1,g_gameName);
	//程序名 dmp文件名 标题

	STARTUPINFO si; //一些必备参数设置  
	memset(&si, 0, sizeof(STARTUPINFO));  
	si.cb = sizeof(STARTUPINFO);  
	si.dwFlags = STARTF_USESHOWWINDOW;  
	si.wShowWindow = SW_SHOW;  
	PROCESS_INFORMATION pi; //必备参数设置结束  
	CreateProcess(NULL,execcmd,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);


	return EXCEPTION_EXECUTE_HANDLER;
}

int GetPicSize(int restype,int type,int idx,int no)
{
	LoadPic(restype,type,idx,hbmp,no);	//封装完成

	GetObject(hbmp, sizeof(BITMAP), (LPBYTE)&bmp);
	DeleteObject(hbmp);
	return bmp.bmWidth*10000+bmp.bmHeight;

}

int CheckGamCorrect(char *filename)
{
	FILE *fp=NULL;
	char outBuf[60+1];//20170820 10-》60
	memset(outBuf,0,sizeof(outBuf));
	fp = fopen(filename,"rb+");//二进制读，追加
	if(!fp)return -1;//出错处理
	int len = 60;//20170820 10-》60
	fseek(fp,0L ,SEEK_SET);

	fread(outBuf,1,60,fp);
	fclose(fp);

	if(outBuf[55]==0)//20170820
	{
		//小游戏
		return -3;
	}
	//20160317增加对第5位判断
	else if(outBuf[4]==16||outBuf[4]==32||outBuf[4]==34||outBuf[4]==64)
	{
	}
	else if(outBuf[4]==33)
	{
		//6980
		return -1;
	}
	else
	{
		return -2;
	}

	return 0;
}

void ShowStatusInPic(int posX,int posY,int type)
{
	BITMAP bwh;
	LoadPic(RES_PIC,2,12,hbmp,type);
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
	GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
	BitBlt(hdcTmp, posX, posY, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCCOPY);
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp);



	InvalidateRect(hwnd,NULL,FALSE);
}

void del_sp(char *src)    // 删除C风格字符串中的空格
{
	char * fp = src;
	while (*src) {
		if (*src != ' ') { // 如果不是空格就复制
			*fp = *src;
			fp++;
		}
		src++;
	}
	*fp = '\0' ; //封闭字符串
}

int gettimeofday(struct timeval *tp, void *tzp)
{
	time_t clock;
	struct tm tm;
	SYSTEMTIME wtm;
	GetLocalTime(&wtm);
	tm.tm_year     = wtm.wYear - 1900;
	tm.tm_mon     = wtm.wMonth - 1;
	tm.tm_mday     = wtm.wDay;
	tm.tm_hour     = wtm.wHour;
	tm.tm_min     = wtm.wMinute;
	tm.tm_sec     = wtm.wSecond;
	tm. tm_isdst    = -1;
	clock = mktime(&tm);
	tp->tv_sec = clock;
	tp->tv_usec = wtm.wMilliseconds * 1000;
	return (0);
}

void SendMsg(int type,char * msg)
{

	HWND hRecvWindow = FindWindow(NULL, "SkyRPGFactory");//写死模拟器标题
	if (hRecvWindow != NULL)  
    {
		COPYDATASTRUCT cdata;
		cdata.dwData = type;
		cdata.lpData = msg;
		cdata.cbData = strlen(msg); 
		SendMessage(hRecvWindow, WM_COPYDATA, 0, (LPARAM)&cdata);
	}
}

int GoodAbs(byte b )
{
	int tmp = b & 0x7F;
	return (((b & 0x80)>> 7) == 1)?(-tmp):tmp;
	
}

int BytesToInt2_GoodAbs(byte * bytes )
{
	int tmp = bytes[0] & 0xFF;
	tmp |= ((bytes[1] << 8) & 0x7F00);
	if(((bytes[1] & 0x80) >> 7) == 1)
	{
		return -(~(tmp-1)&0x7FFF);
	}
	else
	{
		return tmp;
	}
	return (((bytes[1] & 0x8) >> 3) == 1)?(-tmp):tmp;

}

int CheckFit(int value,int max,int min)//20170111检测值上下限
{
	if(value > max)value = max;
	if(value < min)value = min;
	return value;
}

void getEngStr()//20170130获取gam文件中str
{
	if(useEngStr == 1)
	{

		memset(menu_main,0,sizeof(menu_main));

		//对于不同版本的游戏60栏位判断 =32老老版本 =33老版本
		int tmpPos0 = 80017;//v1.3
		int tmpPos3 = 79814;//v1.3
		if(memcmp(engByte+60,"2",1)==0)//老老版本v1.2
		{
			tmpPos0-= 204;
			tmpPos3-= 204;
		}
		if(memcmp(engByte+60,"1",1)==0)//老老老版本v1.1
		{
			tmpPos0-= 204;
			tmpPos3-= 204;
		}
		
		//对于不同版本的游戏112栏位判断 =35老版本 =37新版本
		int tmpPos = 128914;//老1.3
		if(memcmp(engByte+112,"7",1)==0)//新版本v1.3
		{
			tmpPos+= 14;
		}
		else if(memcmp(engByte+60,"2",1)==0)//v1.2版本
		{
			tmpPos = 129398;
		}
		else if(memcmp(engByte+60,"1",1)==0)//v1.1版本
		{
			tmpPos = 129398;
		}

		int tmpPos2 = 242758;
		if(memcmp(engByte+60,"2",1)==0)//老老版本v1.2
		{
			tmpPos2 = 242875;
		}
		if(memcmp(engByte+60,"1",1)==0)//老老版本v1.1
		{
			tmpPos2 = 242875;
		}

		memcpy(menu_main[0],engByte+tmpPos0,4);
		memcpy(menu_main[1],engByte+tmpPos0+4,4);
		memcpy(menu_main[2],engByte+tmpPos0+8,4);
		memcpy(menu_main[3],engByte+tmpPos0+12,4);

		memset(menu_s1,0,sizeof(menu_s1));
		memcpy(menu_s1[0],engByte+tmpPos0+18,4);
		memcpy(menu_s1[1],engByte+tmpPos0+22,4);

		memset(menu_s3,0,sizeof(menu_s3));
		memcpy(menu_s3[0],engByte+tmpPos0+28,4);
		memcpy(menu_s3[1],engByte+tmpPos0+32,4);

		memset(menu_s4,0,sizeof(menu_s4));
		memcpy(menu_s4[0],engByte+tmpPos0+38,8);
		memcpy(menu_s4[1],engByte+tmpPos0+46,8);
		memcpy(menu_s4[2],engByte+tmpPos0+54,8);
		memcpy(menu_s4[3],engByte+tmpPos0+62,8);

		memset(menu_s5,0,sizeof(menu_s5));
		memcpy(menu_s5[0],engByte+tmpPos0+72,6);
		memcpy(menu_s5[1],engByte+tmpPos0+78,6);

		//20181111add判断128799是否为00 85 29 28
		byte tmd = 0;
		byte tma = 0x85;
		byte tmb = 0x29;
		byte tmc = 0x28;
		const void * tmx ;
		const void * tmy ;
		const void * tmz ;
		const void * tmw ;
		tmx = &tma;
		tmy = &tmb;
		tmz = &tmc;
		tmw = &tmd;

		if(tmpPos == 128914 )
		{
			if(memcmp(engByte+128799,tmw,1)==0 && memcmp(engByte+128800,tmx,1)==0 && memcmp(engByte+128801,tmy,1)==0 &&memcmp(engByte+128802,tmz,1)==0)
			{

			}
			else
			{
				//需要+360
				tmpPos+=360;//JY
				if(memcmp(engByte+129159,tmw,1)==0 && memcmp(engByte+129160,tmx,1)==0 && memcmp(engByte+129161,tmy,1)==0 &&memcmp(engByte+129162,tmz,1)==0)
				{

				}
				else
				{
					//需要-80
					tmpPos-=80;//FMJ && NN
				}
			}
		}
		memset(menu_s6,0,sizeof(menu_s6));
		memcpy(menu_s6[0],engByte+tmpPos,4);
		memcpy(menu_s6[1],engByte+tmpPos+4,4);
		memcpy(menu_s6[2],engByte+tmpPos+8,4);
		memcpy(menu_s6[3],engByte+tmpPos+12,4);
		memcpy(menu_s6[4],engByte+tmpPos+16,4);


		memset(menu_s7,0,sizeof(menu_s7));
		memcpy(menu_s7[0],engByte+tmpPos+58,4);
		memcpy(menu_s7[1],engByte+tmpPos+58+4,4);
		memcpy(menu_s7[2],engByte+tmpPos+58+8,4);
		//sprintf(menu_s7[0],"%s","装备");
		//sprintf(menu_s7[1],"%s","投掷");
		//sprintf(menu_s7[2],"%s","使用");

		memset(menu_money,0,sizeof(menu_money));
		memcpy(menu_money,engByte+tmpPos0+86,6);

		memset(menu_num,0,sizeof(menu_num));
		memcpy(menu_num,engByte+tmpPos2,4);
		memcpy(menu_num+4,":",1);

		memset(menu_price,0,sizeof(menu_price));
		memcpy(menu_price,engByte+tmpPos2+7,2);
		memcpy(menu_price+2,":",1);

		memset(menu_name,0,sizeof(menu_name));
		memcpy(menu_name,engByte+tmpPos2+12,2);
		memcpy(menu_name+2,":",1);

		memset(menu_cost,0,sizeof(menu_cost));
		memcpy(menu_cost,engByte+tmpPos3,6);

		memset(menu_degree,0,sizeof(menu_degree));
		memcpy(menu_degree,engByte+tmpPos3+82,4);

		memset(menu_hp,0,sizeof(menu_hp));
		memcpy(menu_hp,engByte+tmpPos3+87,4);

		memset(menu_mp,0,sizeof(menu_mp));
		memcpy(menu_mp,engByte+tmpPos3+92,4);

		memset(menu_at,0,sizeof(menu_at));
		memcpy(menu_at,engByte+tmpPos3+97,6);

		memset(menu_df,0,sizeof(menu_df));
		memcpy(menu_df,engByte+tmpPos3+104,6);

		memset(menu_exp,0,sizeof(menu_exp));
		memcpy(menu_exp,engByte+tmpPos3+111,6);

		memset(menu_speed,0,sizeof(menu_speed));
		memcpy(menu_speed,engByte+tmpPos3+118,4);

		memset(menu_anima,0,sizeof(menu_anima));
		memcpy(menu_anima,engByte+tmpPos3+123,4);

		memset(menu_luck,0,sizeof(menu_luck));
		memcpy(menu_luck,engByte+tmpPos3+128,4);

		memset(menu_anti,0,sizeof(menu_anti));
		memcpy(menu_anti,engByte+tmpPos3+133,4);
	}
	else
	{
		memset(menu_main,0,sizeof(menu_main));
		sprintf(menu_main[0],"%s","属性");
		sprintf(menu_main[1],"%s","魔法");
		sprintf(menu_main[2],"%s","物品");
		sprintf(menu_main[3],"%s","系统");

		memset(menu_s1,0,sizeof(menu_s1));
		sprintf(menu_s1[0],"%s","状态");
		sprintf(menu_s1[1],"%s","穿戴");

		memset(menu_s3,0,sizeof(menu_s3));
		sprintf(menu_s3[0],"%s","使用");
		sprintf(menu_s3[1],"%s","装备");

		memset(menu_s4,0,sizeof(menu_s4));
		sprintf(menu_s4[0],"%s","读入进度");
		sprintf(menu_s4[1],"%s","存储进度");
		sprintf(menu_s4[2],"%s","游戏设置");
		sprintf(menu_s4[3],"%s","结束游戏");

		memset(menu_s5,0,sizeof(menu_s5));
		sprintf(menu_s5[0],"%s","音乐开");
		sprintf(menu_s5[1],"%s","音乐关");

		memset(menu_s6,0,sizeof(menu_s6));
		sprintf(menu_s6[0],"%s","围攻");
		sprintf(menu_s6[1],"%s","道具");
		sprintf(menu_s6[2],"%s","防御");
		sprintf(menu_s6[3],"%s","逃跑");
		sprintf(menu_s6[4],"%s","状态");

		memset(menu_s7,0,sizeof(menu_s7));
		sprintf(menu_s7[0],"%s","装备");
		sprintf(menu_s7[1],"%s","投掷");
		sprintf(menu_s7[2],"%s","使用");

		memset(menu_money,0,sizeof(menu_money));
		sprintf(menu_money,"%s","金钱：");

		memset(menu_num,0,sizeof(menu_num));
		sprintf(menu_num,"%s","数量");

		memset(menu_price,0,sizeof(menu_price));
		sprintf(menu_price,"%s","价:");

		memset(menu_name,0,sizeof(menu_name));
		sprintf(menu_name,"%s","名:");

		memset(menu_cost,0,sizeof(menu_cost));
		sprintf(menu_cost,"%s","耗真气");

		memset(menu_degree,0,sizeof(menu_degree));
		sprintf(menu_degree,"%s","等级");

		memset(menu_hp,0,sizeof(menu_hp));
		sprintf(menu_hp,"%s","生命");

		memset(menu_mp,0,sizeof(menu_mp));
		sprintf(menu_mp,"%s","真气");

		memset(menu_at,0,sizeof(menu_at));
		sprintf(menu_at,"%s","攻击力");

		memset(menu_df,0,sizeof(menu_df));
		sprintf(menu_df,"%s","防御力");

		memset(menu_exp,0,sizeof(menu_exp));
		sprintf(menu_exp,"%s","经验值");

		memset(menu_speed,0,sizeof(menu_speed));
		sprintf(menu_speed,"%s","身法");

		memset(menu_anima,0,sizeof(menu_anima));
		sprintf(menu_anima,"%s","灵力");

		memset(menu_luck,0,sizeof(menu_luck));
		sprintf(menu_luck,"%s","幸运");

		memset(menu_anti,0,sizeof(menu_anti));
		sprintf(menu_anti,"%s","免疫");

	}

}

void delchar(char s[], char c)
 
 {
 
     int i, j, len;
 
     len = strlen(s);
 
     for(i = 0; i < len; i++) {
 
         if(s[i] == c) {
 
             for(j = i; j < len; j++)
 
                 s[j] = s[j + 1];
 
             i = i - 1;
 
         }
 
     }
 
 }

void DelThirdPartyPluginEnableChoose(HMENU h,int enable)//20170602
{
	int nCount = GetMenuItemCount(h);   //获取该层菜单数  
    for(int i=1;i<nCount;i++)                //遍历所有菜单项  
    {  
		if(enable == 0)
		{
			EnableMenuItem ( h,i,MF_ENABLED |MF_BYPOSITION  );
		}
		else
		{
			CheckMenuItem ( h,i,MF_UNCHECKED|MF_BYPOSITION  );
			EnableMenuItem ( h,i,MF_GRAYED|MF_BYPOSITION  );
		}
    }  
}

/*状态显示：
等级 13818H 4+1
生命 1381d 4+1
真气 13822 4+1
攻击力 13827 6+1
防御力 1382e 6+1
经验值 13835 6+1
身法 1383c 4+1
灵力 41 4+1
幸运 46 4+1
免疫 4b 4+1
耗真气 137c6 6+1
金钱： 138e7 4
属性魔法物品系统 13891
状态穿戴 138a3
使用装备 138ad
读入进度存储进度游戏设置结束游戏138b7
音乐开音乐关 138d9
围攻道具防御逃跑状态 1f792
数量 3b446
价3b44d
名3b452
*/



