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

#pragma once

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <Dbghelp.h>
#include <time.h>
#include "Public.h"
#include "PicConverter.h"
#include "Plugin.h"
//#include "GoodList.h"
#pragma comment(lib,"Dbghelp.lib") 

#define STARTINIPATH "Res\\startup.ini"
#define VERSIONINIPATH "Res\\version.ini"

void ShowPic(int delay,int restype,int type,int idx,int ux=0,int uy=0,int no = 0);
void ShowPicAdd(int delay,int restype,int type,int idx,int x=0,int y= 0,int no = 0);
void LoadPic(int restype,int type,int idx,HBITMAP &hbmp,int no = 0);
void LoadPicTrans(int restype,int type,int idx,HBITMAP &hbmp,int no = 0);
void LoadPicMask(int restype,int type,int idx,HBITMAP &hbmp,int no = 0);
int ChangeFile(char filename[]);
int Delay(long time);
int Check(long time);
int CheckSysMsg();
int CheckSysMsgA();
void ShowText(char *text,int x,int y,int size=16);
void ShowTextDirect(char *text,int x,int y,int size=16);
void Message(char *text,int posx,int posy,int ux,int uy);
int GetFileText(char *filename);
int ChangeRes(char *filename);
int ShowPicDirect(int delay,int restype,int type,int idx,int ux=0,int uy=0,int no = 0);
int ShowPicStart(int delay,int restype,int type,int idx,int ux=0,int uy=0,int no = 0);
int TimerMessage(char *text,int posx,int posy,int ux,int uy,int delay);
int TimerMessageFight(int exp,int money,int delay);
void TimerMessageNoText(char *text,int posx,int posy,int ux,int uy,int delay);
int PlcExtract(int num);
long readFromFile(byte *outBuf,char *filename,int flag);

int BytesToInt4(byte * bytes );
int BytesToInt2(byte * bytes );
int BytesToInt1(byte * bytes );
void  IntToBytes4(int i,byte *bytes);
void  IntToBytes2(int i,byte *bytes);
void  IntToBytes1(int i,byte *bytes);

void ShowCG(int type,int idx,int ux=0,int uy=0,int showtype = 0,int offsetx = 0,int offsety = 0);//显示特效
int CheckResExits( int type,int restype,int idx);//判断资源存在
int GetResNum( int type,int restype,int idx);
void LoadCGPic(int picnum,int resnum ,int framecount, HBITMAP &hbmp);
int LoadCGPicMask(int picnum,int resnum ,int framecount, HBITMAP &hbmp);
void LoadCGPicTrans(int picnum,int resnum ,int framecount, HBITMAP &hbmp);
void ClrScence();
void ShowMapPic(int idx,int x,int y,int mapType,int mapIdx);
void LoadTile(int idx,int i ,HBITMAP &hbmp);
void ShowRolePic(int delay,int type,int idx,int x,int y,int roleIdx);
void ShowSayBox(char *text1,char *text2,int type = 0);
void ShowHeadPic(int delay,int idx,int ux=0,int uy=0,int headIdx=0);
void CopyToHdc();
void ShowGoodPic(int delay,int type,int idx,int ux=0,int uy=0);

void ShowFightScene(int scrb,int scrl,int scrr);
void ShowFightChoice(int id);


int GetMaxPicNumber(int restype,int type,int idx);
void ShowNumInPic(int posX,int posY,int num,int before,int size = 8);//before 0-无 1-+ 2--
int GetType(int type,int restype,int index);//获取编码类型1-单色2透明

void wlogfile(int type,char *infun,char *inmsg,int result);
LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)  ;
int GetPicSize(int restype,int type,int idx,int no);

int CheckGamCorrect(char *filename);
void ShowStatusInPic(int posX,int posY,int type);
void del_sp(char *src);
int gettimeofday(struct timeval *tp, void *tzp);
void SendMsg(int type,char * msg);
int GoodAbs(byte b );//20170107
int BytesToInt2_GoodAbs(byte * bytes );//20170107
int CheckFit(int value,int max,int min = 0);//20170111检测值上下限
void getEngStr();//20170130获取gam文件中str

void delchar(char s[], char c);

void DelThirdPartyPluginEnableChoose(HMENU h,int enable);//20170602
//void InitGMC(HINSTANCE hDLLDrv);//20170708
int DelayB(long time);
int CheckSysMsgB();