MirMiniMap.cpp
资源名称:盛大传奇外挂原代码.rar [点击查看]
上传用户:marco7834
上传日期:2010-02-24
资源大小:82k
文件大小:4k
源码类别:
游戏引擎
开发平台:
Visual C++
- // MirMiniMap.cpp: implementation of the CMirMiniMap class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MirMiniMap.h"
- #include <stdio.h>
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMirMiniMap::CMirMiniMap()
- {
- m_fpWilFile = NULL;
- m_ImageData = NULL;
- m_dwImageWidth = 0;
- m_dwImageHeight = 0;
- m_dwMapIndex = 0;
- m_xpos = 0;
- m_ypos = 0;
- }
- CMirMiniMap::~CMirMiniMap()
- {
- }
- BOOL CMirMiniMap::InitMiniMap(char *wixfile, char *wilfile)
- {
- m_fpWilFile = fopen( wilfile, "rb" );
- if( m_fpWilFile == NULL )
- return FALSE;
- m_dwCntMMap = LoadOfs( wixfile, &m_pResOfs );
- if( m_dwCntMMap == 0 || m_pResOfs == NULL )
- return FALSE;
- if( !LoadPal( m_BitmapHeader.pals ))
- return FALSE;
- return TRUE;
- }
- DWORD CMirMiniMap::LoadOfs( char * szWixFile, DWORD ** ofsbuf )
- {
- FILE * fp = NULL;
- DWORD dwcnt = 0;
- fp = fopen( szWixFile, "rb" );
- if( fp == NULL )
- return 0;
- fseek( fp, 0x2c, SEEK_SET );
- fread( &dwcnt, 4, 1, fp );
- if( dwcnt == 0 )
- {
- fclose( fp );
- return 0;
- }
- *ofsbuf = new DWORD[dwcnt];
- fread( (void*)(*ofsbuf), dwcnt* 4, 1, fp );
- fclose( fp );
- return dwcnt;
- }
- char * CMirMiniMap::LoadBuf( DWORD idx, DWORD & width, DWORD & height )
- {
- char * pData = NULL;
- WORD w,h;
- DWORD dwSize;
- if( m_fpWilFile == NULL )
- return NULL;
- fseek( m_fpWilFile, m_pResOfs[idx], SEEK_SET );
- fread( &w, 2, 1, m_fpWilFile );
- if( w == 0 )
- {
- return NULL;
- }
- fread( &h, 2, 1, m_fpWilFile );
- if( h == 0 )
- {
- return NULL;
- }
- width = w;
- height = h;
- dwSize = width * height;
- pData = new char[dwSize];
- if( pData == NULL )
- return NULL;
- fseek( m_fpWilFile, 4, SEEK_CUR );
- fread( (void*)pData, dwSize, 1, m_fpWilFile );
- return pData;
- }
- BOOL CMirMiniMap::LoadPal( char * ppal)
- {
- if( ppal == NULL )
- return FALSE;
- fseek( m_fpWilFile, 0x38, SEEK_SET );
- if( ftell( m_fpWilFile ) != 0x38 )
- return FALSE;
- fread( (void*)ppal, 1024, 1, m_fpWilFile);
- return TRUE;
- }
- BOOL CMirMiniMap::SetMMap(DWORD index)
- {
- // BITMAP bm;
- if( m_ImageData != NULL )
- delete []m_ImageData;
- m_ImageData = LoadBuf( index-1, m_dwImageWidth, m_dwImageHeight );
- if( m_ImageData == NULL )
- return FALSE;
- if( m_dwImageWidth == 0 || m_dwImageHeight == 0 )
- return FALSE;
- BITMAPFILEHEADER bfheader;
- MakeBitmapHeader( &bfheader, &m_BitmapHeader.header , m_dwImageWidth, m_dwImageHeight, 8 );
- return TRUE;
- }
- int CMirMiniMap::MakeBitmapHeader( BITMAPFILEHEADER * pBfHeader, BITMAPINFOHEADER * pBiHeader, int width, int height, int bits )
- {
- int imagesize = width * height * (bits/ 8 );
- int headersize = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER );
- memset( (void*)pBfHeader, 0, sizeof( BITMAPFILEHEADER ) );
- memset( (void*)pBiHeader, 0, sizeof( BITMAPINFOHEADER ) );
- if( bits == 8 )
- {
- headersize += sizeof( DWORD) * 256;
- pBiHeader->biClrImportant = 0x100;
- pBiHeader->biClrUsed = 0x100;
- }
- /*
- if( (balian % 4) )
- {
- imagesize = width * height * ( bits/8 );
- }
- */
- pBfHeader->bfSize = headersize + imagesize;
- pBfHeader->bfType = 0x4d42;
- pBfHeader->bfOffBits = headersize;
- pBiHeader->biWidth = width;
- pBiHeader->biHeight = height;
- pBiHeader->biBitCount = bits;
- pBiHeader->biPlanes = 1;
- pBiHeader->biCompression = 0;
- pBiHeader->biSize = 40;
- pBiHeader->biSizeImage = imagesize;
- return 1;
- }
- void CMirMiniMap::Draw(HDC dc, int x, int y, int w, int h )
- {
- if( m_ImageData == NULL )
- return;
- SetDIBitsToDevice( dc, x, y, w, h, (m_xpos + m_xpos/2 ) - (w/2), (m_dwImageHeight - m_ypos - (h/2)), 0, m_dwImageHeight,(void*)m_ImageData, (BITMAPINFO*)&m_BitmapHeader, DIB_RGB_COLORS );
- SetPixel( dc, x + w/2,y + h/2, RGB( 255,255,255));
- }
- void CMirMiniMap::SetCurPos(int x, int y)
- {
- m_xpos = x;
- m_ypos = y;
- }