mirgroup.cpp
资源名称:盛大传奇外挂原代码.rar [点击查看]
上传用户:marco7834
上传日期:2010-02-24
资源大小:82k
文件大小:6k
源码类别:
游戏引擎
开发平台:
Visual C++
- #include "mirgroup.h"
- #include <windowsx.h>
- #include <stdio.h>
- typedef char SHORTSTRING[64];
- typedef struct
- {
- char AreaName[64];
- char IpAddress[16];
- SHORTSTRING ServerCaption[10];
- SHORTSTRING ServerName[10];
- DWORD dwServerCount;
- }AREAINFO;
- AREAINFO m_AreaInfo[100];
- int m_AreaCount = 0;
- char m_grpBuffer[128 * 1024];
- DWORD *dwOfsList = (DWORD*)&m_grpBuffer[12];
- char * GetStreamPtr( int id )
- {
- if( id < 0 || id >= m_AreaCount * 2 + 2 )
- return NULL;
- return (&m_grpBuffer[dwOfsList[id * 2]]);
- }
- int GetStream( int id, char * stream )
- {
- if( id < 0 || id >= m_AreaCount * 2 + 2 )
- return NULL;
- memcpy( (void*)stream, (void*)&m_grpBuffer[dwOfsList[id * 2]], dwOfsList[id * 2 + 1] );
- stream[dwOfsList[id * 2 + 1]] = 0x0a;
- stream[dwOfsList[id * 2 + 1]+1] = 0;
- return 1;
- }
- int GetSetting( char * stream, char * segment, char * name, char * setting )
- {
- char mtmp[3024];
- int ilen = 0;
- if( stream == 0 )
- return 0;
- if( segment == 0 )
- return 0;
- if( name == 0 )
- return 0;
- if( setting == 0 )
- return 0;
- setting[0] = ' ';
- ilen = strlen( stream );
- int iptr = -1;
- int lstart = 0;
- int sstart = 0;
- #define FLAG_SEARCHSEG 0
- #define FLAG_SEARCHNAME 0xff
- #define FLAG_GETSETTING 0xff00
- int iflag = FLAG_SEARCHSEG;
- int i = 0;
- for( i = 0;i < ilen;i ++ )
- {
- if( stream[i] == 0x0a || stream[i] == 0x0d )
- {
- if( iflag == FLAG_GETSETTING )
- {
- memcpy( (void*)mtmp, (void*)&stream[sstart], i - sstart );
- mtmp[i - sstart] = ' ';
- strcpy( setting, mtmp );
- //printf( "Found %sn", mtmp );
- return 1;
- }
- lstart = i + 1;
- }
- if( iflag == FLAG_SEARCHNAME )
- {
- if( stream[i] == '=' )
- {
- memcpy( (void*)mtmp, (void*)&stream[lstart],i - lstart );
- mtmp[i - lstart] = ' ';
- if( stricmp( mtmp, name ) == 0 )
- {
- iflag = FLAG_GETSETTING;
- sstart = i + 1;
- }
- printf( "%sn", mtmp );
- }
- }
- if( stream[i] == '[' )
- {
- if( iflag == FLAG_SEARCHNAME )
- {
- return 0;
- }
- iptr = i + 1;
- }
- if( stream[i] == ']' )
- {
- memcpy( (void*)mtmp, (void*)&stream[iptr], i - iptr);
- mtmp[i-iptr] = ' ';
- printf( "%sn", mtmp );
- if( stricmp( mtmp, segment ) == 0 )
- iflag = FLAG_SEARCHNAME;
- }
- }
- return 0;
- }
- int UnGroupStream( char * stream, int size )
- {
- int i = 0;
- if( stream == NULL )
- return 0;
- if( size == 0 )
- return 0;
- for( i = 0;i < size;i ++ )
- {
- if( stream[i] & 1 )
- {
- stream[i] --;
- }
- else
- {
- stream[i] ++;
- }
- }
- stream[size] = ' ';
- return 1;
- }
- int ProcAreaInfo()
- {
- char tmps[200];
- char name[3048];
- char * ptrStream;
- int pptr = 0;
- int i = 0;
- int iptr = 0;
- ptrStream = GetStreamPtr( 0 );
- if( ptrStream == NULL )
- return 0;
- GetSetting( ptrStream, "main", "name", name );
- // MessageBox(0,name, 0, 0 );
- int ilen = strlen( name );
- for( i = 0;i <= ilen;i ++ )
- {
- if( name[i] == ';' || name[i] == ' ' )
- {
- memcpy( (void*)tmps, (void*)&name[iptr], i - iptr );
- tmps[i-iptr] = ' ';
- strcpy( m_AreaInfo[pptr].AreaName, tmps );
- pptr ++;
- iptr = i + 1;
- }
- }
- for( i = 0;i < m_AreaCount;i ++ )
- {
- ptrStream = GetStreamPtr( i * 2 + 1 );
- GetStream( i * 2 + 1, name );
- if( ptrStream == NULL )
- return 0;
- if( !GetSetting( name, "server","servercount", tmps ))
- {
- if( !GetSetting( name, "group", "groupnum", tmps ))
- {
- return 0;
- }
- }
- pptr = atoi( tmps );
- m_AreaInfo[i].dwServerCount = pptr;
- if( pptr <= 0 || pptr >= 9 )
- return 0;
- //if( i > 50 && i < 60 )MessageBox( 0, name, 0, 0 );
- for( iptr = 0;iptr < pptr;iptr ++ )
- {
- sprintf( tmps, "Server%dCaption", iptr + 1);
- if( !GetSetting( name, "server", tmps, m_AreaInfo[i].ServerCaption[iptr] ))
- {
- sprintf( tmps, "Group%d", iptr );
- if( !GetSetting( name, "group", tmps, m_AreaInfo[i].ServerCaption[iptr] ))
- {
- return 0;
- }
- }
- sprintf( tmps, "Server%dName", iptr + 1 );
- if( !GetSetting( name, "server", tmps, m_AreaInfo[i].ServerName[iptr] ) )
- {
- sprintf( tmps, "GroupNick%d", iptr );
- if( !GetSetting( name, "group", tmps, m_AreaInfo[i].ServerName[iptr] ))
- {
- return 0;
- }
- }
- // MessageBox( 0, m_AreaInfo[i].ServerName[iptr], 0, 0 );
- }
- ptrStream = GetStreamPtr( i * 2 + 2 );
- if( ptrStream == NULL )
- return 0;
- GetSetting( ptrStream, "setup", "ServerAddr", m_AreaInfo[i].IpAddress );
- }
- return 1;
- }
- int SetGroupFile( char * file )
- {
- // DWORD *pdw = (DWORD*)m_grpBuffer;
- int filelen = 0;
- int i = 0;
- FILE * fp;
- fp = fopen( file, "rb" );
- if( fp == NULL )
- return 0;
- fseek( fp, 0, SEEK_END );
- filelen = ftell( fp );
- fseek( fp, 0, SEEK_SET );
- fread( (void*)m_grpBuffer, filelen, 1,fp );
- fclose( fp );
- m_AreaCount = (int)m_grpBuffer[8] & 0xff;
- UnGroupStream( (char*)&m_grpBuffer[dwOfsList[0]], filelen - dwOfsList[0] );
- if( !ProcAreaInfo())
- return 0;
- return 1;
- }
- char tmpBufname[3048];
- int SetAreaList( HWND hWnd )
- {
- int i = 0;
- for( i = 0;i < m_AreaCount;i++)
- {
- ComboBox_AddString( hWnd, m_AreaInfo[i].AreaName );
- }
- ComboBox_SetCurSel( hWnd, 0 );
- return 1;
- }
- int SetServerCaptionList( HWND hWnd, int AreaID )
- {
- int i = 0;
- int icnt = 0;
- icnt = ComboBox_GetCount( hWnd );
- ComboBox_ResetContent( hWnd );
- for( i = 0;i < icnt;i ++ )
- {
- ComboBox_DeleteString( hWnd, i );
- }
- if( AreaID >= 0 && AreaID < m_AreaCount )
- {
- for( i = 0;i < (int)m_AreaInfo[AreaID].dwServerCount;i ++ )
- {
- ComboBox_AddString( hWnd, m_AreaInfo[AreaID].ServerCaption[i] );
- }
- ComboBox_SetCurSel( hWnd, 0 );
- return 1;
- }
- return 0;
- }
- int GetServerName( int AreaID, int ServerIndex, char * ServerName )
- {
- if( AreaID >= 0 && AreaID < m_AreaCount )
- {
- if( ServerIndex >= 0 && ServerIndex < (int)m_AreaInfo[AreaID].dwServerCount )
- {
- strcpy( ServerName, m_AreaInfo[AreaID].ServerName[ServerIndex] );
- return 1;
- }
- return 0;
- }
- return 0;
- }
- int GetIpAddress( int AreaID, char * IpAddr )
- {
- if( AreaID >= 0 && AreaID < m_AreaCount )
- {
- strcpy( IpAddr, m_AreaInfo[AreaID].IpAddress );
- return 1;
- }
- return 0;
- }