ROAUtils.cpp
资源名称:ROA3.40.rar [点击查看]
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:45k
源码类别:
外挂编程
开发平台:
Visual C++
- #include <stdafx.h>
- #include "ROA.h"
- #include "ROAUtils.h"
- #include "ROAView.h"
- #include "math.h"
- CString utlParseString(CString& str)
- {
- CString strRtn = _T("");
- int nIndex;
- nIndex = str.Find((","));
- if(nIndex == -1)
- {
- strRtn = str;
- str.Empty();
- }
- else
- {
- strRtn = str.Left(nIndex);
- str = str.Mid(nIndex+1);
- }
- return(strRtn);
- }
- int sendSyncInject()
- {
- char lpBuffer[3];
- memset(lpBuffer, 0, 3);
- lpBuffer[0] = 'K';
- sockInject.Send(lpBuffer, 3);
- return(0);
- }
- DWORD getROProcessId()
- {
- HANDLE hSnapshot = INVALID_HANDLE_VALUE;
- DWORD dwIdRo = 0;
- HANDLE toolhelp;
- PROCESSENTRY32 pe;
- CString strTemp;
- pe.dwSize = sizeof(PROCESSENTRY32);
- toolhelp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (Process32First(toolhelp,&pe)) {
- do {
- strTemp = pe.szExeFile;
- int nIndex = strTemp.ReverseFind(_T('\'));
- if(nIndex != -1)
- strTemp = strTemp.Right(strTemp.GetLength() - nIndex - 1);
- if (!stricmp("ragexe.exe", strTemp) || !stricmp("sakexe.exe", strTemp))
- {
- dwIdRo = pe.th32ProcessID;
- break;
- }
- } while (Process32Next(toolhelp,&pe));
- }
- CloseHandle(toolhelp);
- return(dwIdRo);
- }
- int sendToServerByInject(char *lpBuffer, WORD sSize)
- {
- ASSERT(sSize > 0);
- static char pBufNew[MAX_BUFFER_LEN];
- WORD sSizeNew = sSize + 3;
- memset(pBufNew, 0, MAX_BUFFER_LEN);
- pBufNew[0] = 'S';
- *((WORD*)(pBufNew+1)) = sSize;
- int cntMax = strlen(cSendKey);
- if(cntMax > 0)
- {
- int cnt = 0;
- for(int i=0; i<sSize; i++)
- {
- *(lpBuffer+i) = (*(lpBuffer+i)) + cSendKey[cnt];
- if(++cnt >= cntMax)
- cnt = 0;
- }
- }
- memcpy(pBufNew+3, lpBuffer, sSize);
- sockInject.Send(pBufNew, sSizeNew);
- return(0);
- }
- int sendToClientByInject(char *lpBuffer, WORD sSize)
- {
- ASSERT(sSize > 0);
- static char pBufNew[MAX_BUFFER_LEN];
- WORD sSizeNew = sSize + 3;
- memset(pBufNew, 0, sSizeNew);
- pBufNew[0] = 'R';
- *((WORD*)(pBufNew+1)) = sSize;
- memcpy(pBufNew+3, lpBuffer, sSize);
- sockInject.Send(pBufNew, sSizeNew);
- return(0);
- }
- int injectAdminMessage(LPCTSTR lpMsg)
- {
- ASSERT(lpMsg != NULL);
- if(nConnState < 5)
- return(-1);
- utlLogout(lpMsg, eLogError, false);
- char *pBufNew = NULL;
- char *p = NULL;
- WORD sSizeNew = strlen(lpMsg) + 5 + strlen(ROA_HEADER);
- pBufNew = new char [sSizeNew];
- memset(pBufNew, 0, sSizeNew);
- p = pBufNew;
- *((WORD*)p) = 0x009A; p += 2;
- *((WORD*)p) = sSizeNew; p += 2;
- strcpy(p, ROA_HEADER); p += strlen(ROA_HEADER);
- strcpy(p, lpMsg); p += strlen(lpMsg);
- *p = 0;
- // encrypt($msg, $msg);
- sendToClientByInject(pBufNew, sSizeNew);
- delete pBufNew;
- return(0);
- }
- int injectMessage(LPCTSTR lpMsg)
- {
- ASSERT(lpMsg != NULL);
- if(nConnState < 5)
- return(-1);
- utlLogout(lpMsg, eLogCommon, false);
- static char cBufferMsg[1024];
- char *p = cBufferMsg;
- WORD sSizeNew = strlen(lpMsg) + 9 + strlen(ROA_HEADER);
- *((WORD*)p) = 0x0109; p += 2;
- *((WORD*)p) = sSizeNew; p += 2;
- *((DWORD*)p) = 0; p += 4;
- strcpy(p, ROA_HEADER); p += strlen(ROA_HEADER);
- strcpy(p, lpMsg); p += strlen(lpMsg);
- *p = 0;
- // encrypt($msg, $msg);
- sendToClientByInject(cBufferMsg, sSizeNew);
- // EnterCriticalSection(&criticalSection);
- return(0);
- }
- char* utlPrintHex(char *lpBuffer, WORD wLen)
- {
- static char cPrintBuf[1024];
- // memset(cPrinted, 0, 1024);
- char *p = cPrintBuf;
- int nPrintlen = (wLen>100) ? 100 : wLen;
- for(int i=0; i<nPrintlen; i++)
- {
- if(i % 5 == 0)
- sprintf(p++, "|");
- else
- sprintf(p++, " ");
- BYTE temp = lpBuffer[i];
- sprintf(p, "%02X", temp);
- p += 2;
- }
- if(wLen>100)
- {
- sprintf(p, "...");
- p += 3;
- }
- p = ' ';
- return(cPrintBuf);
- }
- int sendWelcomeMessage()
- {
- CString strOutput;
- int i;
- for(i=0; i<sizeof(strWelcome)/sizeof(strWelcome[0]); i++)
- {
- injectAdminMessage(strWelcome[i]);
- }
- if(dwAccountId == 0)
- {
- injectAdminMessage("无法获取人物信息,请重新登录帐号!");
- }
- else
- {
- if(bProfileLoaded)
- injectAdminMessage(_T("已读入用户设定文件"));
- else
- injectAdminMessage(_T("无法读入用户设定文件,请按END键或选择ROA菜单进行战斗设置"));
- }
- if(hHook == NULL)
- {
- injectAdminMessage(_T("快捷键无效或已关闭!"));
- }
- bWelcomeSent = true;
- return(0);
- }
- void utlLogout(LPCTSTR lpszMsg, LOG_LEVEL level, BOOL bAi)
- {
- #ifndef VIPMODE
- return;
- #endif
- if(llFile == eLogNone && llDlg == eLogNone)
- return;
- CString strLog;
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime.Format( _T("[%02d/%02d %02d:%02d:%02d] "), time.GetMonth(), time.GetDay(),
- time.GetHour(), time.GetMinute(), time.GetSecond() );
- switch(level)
- {
- case eLogError:
- strLog = "(E) ";
- break;
- case eLogCommon:
- strLog = "(C) ";
- break;
- case eLogInfo:
- strLog = "(I) ";
- break;
- default:
- strLog = "(D) ";
- break;
- }
- if(bAi)
- strLog += "****AI****";
- strLog = strTime + strLog + lpszMsg;
- if(level <= llFile)
- {
- fLog.Write(strLog, strlen(strLog));
- fLog.Write("rn", 2);
- }
- if(level <= llDlg)
- {
- ((CROAView*)AfxGetMainWnd())->AddMessage(lpszMsg, level, bAi);
- }
- if(level <= llRo && nConnState == 5)
- {
- injectMessage(strLog);
- }
- }
- void utlLogout2(LPCTSTR lpszMsg, LOG_LEVEL level, BOOL bAi)
- {
- #ifndef VIPMODE
- return;
- #endif
- CString strLog;
- CTime time = CTime::GetCurrentTime();
- CString strTime;
- strTime.Format( _T("[%02d/%02d %02d:%02d:%02d] "), time.GetMonth(), time.GetDay(),
- time.GetHour(), time.GetMinute(), time.GetSecond() );
- switch(level)
- {
- case eLogError:
- strLog = "(E) ";
- break;
- case eLogCommon:
- strLog = "(C) ";
- break;
- case eLogInfo:
- strLog = "(I) ";
- break;
- default:
- strLog = "(D) ";
- break;
- }
- if(bAi)
- strLog += "****AI****";
- strLog = strTime + strLog + lpszMsg;
- if(level <= llFile)
- {
- fLog.Write(strLog, strlen(strLog));
- }
- if(level <= llDlg)
- {
- ((CROAView*)AfxGetMainWnd())->AddMessage2(lpszMsg, level, bAi);
- }
- if(level <= llRo && nConnState == 5)
- {
- injectMessage(strLog);
- }
- }
- void utlLogout3(LPCTSTR lpszMsg, LOG_LEVEL level, BOOL bAi)
- {
- #ifndef VIPMODE
- return;
- #endif
- if(level <= llFile)
- {
- fLog.Write(lpszMsg, strlen(lpszMsg));
- fLog.Write("rn", 2);
- }
- if(level <= llDlg)
- {
- ((CROAView*)AfxGetMainWnd())->AddMessage3(lpszMsg, level, bAi);
- }
- if(level <= llRo && nConnState == 5)
- {
- injectMessage(lpszMsg);
- }
- }
- void utlLogout4(LPCTSTR lpszMsg)
- {
- injectMessage(lpszMsg);
- return;
- }
- void utlChangeState(int nState1, int nState2)
- {
- CString strLog;
- int nStateOld = nConnState;
- if(nState1 == -1 || nConnState == nState1)
- nConnState = nState2;
- if(nStateOld != nConnState)
- {
- strLog.Format("切换连换状态: %d -> %d", nStateOld, nConnState);
- utlLogout(strLog, eLogInfo, false);
- }
- if(nConnState == 5)
- {
- ;
- }
- }
- void utlInitMapChangeVars()
- {
- inventory.RemoveAll();
- monsters.RemoveAll();
- players.RemoveAll();
- portals.RemoveAll();
- items.RemoveAll();
- cart.RemoveAll();
- damages.RemoveAll();
- spells.RemoveAll();
- you.init();
- if(nCharSelected >= 0 && nCharSelected <= 2)
- you = youTemp[nCharSelected];
- utlChangeMode(eModeNormal, 0);
- bAiEnabled = true;
- ufAutoSaClassChange(0);
- dwAttackTick = 0;
- dwUseItemTick = 0;
- }
- POINT utlMakeCoords(BYTE *pCoords)
- {
- POINT pntRtn;
- pntRtn.x = pCoords[0] * 4 + (pCoords[1] & 0xC0) / 64;
- pntRtn.y = (pCoords[1] & 0x3F) * 16 + (pCoords[2] & 0xF0) / 16;
- return(pntRtn);
- }
- POINT utlMakeCoords2(BYTE *pCoords)
- {
- POINT pntRtn;
- pntRtn.x = (pCoords[1] & 0xFC) / 4 + (pCoords[0] & 0x0F) * 64;
- pntRtn.y = (pCoords[1] & 0x03) * 256 + pCoords[2];
- return(pntRtn);
- }
- double utlDistanceFrom(POINT pnt1, POINT pnt2)
- {
- return(sqrt((pnt1.x-pnt2.x)*(pnt1.x-pnt2.x)+(pnt1.y-pnt2.y)*(pnt1.y-pnt2.y)));
- }
- CString utlFindTarget(DWORD dwId)
- {
- CString strRtn = "未知人物";
- do
- {
- if(dwId == dwAccountId)
- {
- strRtn = _T("你");
- break;
- }
- if(-1 != monsters.FindId(dwId))
- {
- strRtn.Format("%s(%X)@(%d, %d)", monsters[monsters.FindId(dwId)].cName, dwId, monsters[monsters.FindId(dwId)].pntTo.x, monsters[monsters.FindId(dwId)].pntTo.y);
- break;
- }
- if(-1 != players.FindId(dwId))
- {
- strRtn.Format("%s(%X)", players[players.FindId(dwId)].cName, dwId);
- break;
- }
- }while(0);
- return(strRtn);
- }
- CString utlFindTargetItem(DWORD dwId)
- {
- CString strRtn = "未知物品";
- int nIdx = items.FindId(dwId);
- if(-1 != nIdx)
- {
- strRtn.Format("%s(%X)@(%d, %d)", mapItem.FindValue(items[nIdx].wType, eItemName), dwId, items[nIdx].pntPos.x, items[nIdx].pntPos.y);
- }
- return(strRtn);
- }
- CString utlFindTargetInventory(int nIndex)
- {
- CString strRtn = "未知物品/装备";
- int nIdx = inventory.FindIndex(nIndex);
- if(-1 != nIdx)
- {
- strRtn = utlGetInventoryName(&inventory[nIdx]);
- }
- return(strRtn);
- }
- void utlUpdateDamage(DWORD dwSource, DWORD dwTarget, WORD wDamage, int nType)
- {
- DAMAGE damage;
- int nIndex;
- CString strTemp, strOutput;
- strOutput = "Unknown damage!";
- if(dwSource == dwAccountId || dwTarget == dwAccountId)
- {
- if((dwSource == dwAccountId &&
- -1 != monsters.FindId(dwTarget)) ||
- (dwTarget == dwAccountId &&
- -1 != monsters.FindId(dwSource)))
- {
- // Attack
- nIndex = damages.FindDamage(dwSource, dwTarget);
- if(-1 != nIndex)
- {
- damage = damages.GetAt(nIndex);
- }
- else
- {
- damage.dwId1 = dwSource;
- damage.dwId2 = dwTarget;
- damage.dwDamage = 0;
- damage.dwStart = GetTickCount();
- nIndex = damages.Add(damage);
- }
- // if(dwSource == dwAccountId && wDamage == 0)
- // wDamage = 1;
- damage.dwDamage += wDamage;
- damage.dwDamage2[nType] += wDamage;
- if(wDamage != 0)
- {
- damage.dwHits[nType]++;
- if(wDamage > damage.dwDamageMax[nType])
- {
- damage.dwDamageMax[nType] = wDamage;
- }
- if(wDamage < damage.dwDamageMin[nType])
- {
- damage.dwDamageMin[nType] = wDamage;
- }
- }
- else
- damage.dwMiss[nType]++;
- damages.SetAt(nIndex, damage);
- }
- }
- /*
- if(-1 != monsters.FindId(dwTarget))
- {
- // Attack
- monsters[monsters.FindId(dwTarget)].bClean = false;
- }
- */
- return;
- }
- CString utlCalculateHits(WORD wDamage)
- {
- CString strRtn;
- if(0 == wDamage)
- strRtn = "Miss!";
- else
- strRtn.Format("%d hits!", wDamage);
- return(strRtn);
- }
- BYTE* utlGetCoord(POINT pnt)
- {
- static BYTE coord[3];
- coord[0] = pnt.x / 4;
- coord[1] = (pnt.x % 4) * 64 + int(pnt.y / 16);
- coord[2] = (pnt.y % 16) * 16;
- return(coord);
- }
- int sendTeleport(LPCTSTR pLocation)
- {
- ASSERT(pLocation != NULL);
- char *pBufNew = NULL;
- char *p = NULL;
- WORD sSizeNew = 16+4;
- CString strOutput;
- pBufNew = new char [sSizeNew];
- memset(pBufNew, 0, sSizeNew);
- p = pBufNew;
- *((DWORD*)p) = 0x001A011B; p += 4;
- strncpy(p, pLocation, 15);
- // encrypt($msg, $msg);
- parseSendData(pBufNew, sSizeNew, true);
- delete pBufNew;
- return(0);
- }
- int utlUseTeleport(int nLevel)
- {
- int nItem = -1, nSkill = -1;
- BOOL bDone = false;
- if(nConnState < 5)
- return(-1);
- nItem = inventory.FindId((DWORD)(600 + nLevel));
- nSkill = utlFindSkillByAlias(_T("瞬间移动"));
- if(nLevel == 2)
- {
- if(nItem != -1)
- {
- sendUseItem((WORD)inventory[nItem].dwIndex, dwAccountId);
- bDone = true;
- }
- }
- else
- {
- if(nSkill != -1)
- {
- if(bFlyUsed)
- {
- sendTeleport(_T("Random"));
- }
- else
- {
- sendUseSkill(1, (WORD)skills[nSkill].dwId, dwAccountId);
- Sleep(100);
- bFlyUsed = true;
- sendTeleport(_T("Random"));
- }
- bDone = true;
- }
- else
- {
- if(nItem != -1)
- {
- sendUseItem((WORD)inventory[nItem].dwIndex, dwAccountId);
- bDone = true;
- }
- }
- }
- if(!bDone)
- {
- injectAdminMessage(_T("无法使用技能[瞬移]"));
- }
- return(0);
- }
- int sendMove(POINT pntTo)
- {
- char buffer[5];
- *(WORD*)buffer = 0x0085;
- memcpy(buffer+2, utlGetCoord(pntTo), 3);
- parseSendData(buffer, 5, true);
- return(0);
- }
- int sendEmotion(BYTE bEmotion)
- {
- char buffer[3];
- *(WORD*)buffer = 0x00BF;
- buffer[2] = bEmotion;
- parseSendData(buffer, 3, true);
- return(0);
- }
- int sendTake(DWORD dwItemId)
- {
- char buffer[6];
- *(WORD*)(buffer+0) = 0x009f;
- *(DWORD*)(buffer+2) = dwItemId;
- if(!you.bSit)
- parseSendData(buffer, 6, true);
- return(0);
- }
- int sendAttack(DWORD dwMonster, BYTE byMode)
- {
- char buffer[7];
- *(WORD*)(buffer+0) = 0x0089;
- *(DWORD*)(buffer+2) = dwMonster;
- *(BYTE*)(buffer+6) = byMode;
- parseSendData(buffer, 7, true);
- return(0);
- }
- int sendUseSkill(WORD wLevel, WORD wSkillId, DWORD dwTarget)
- {
- char buffer[10];
- *(WORD*)(buffer+0) = 0x0113;
- *(WORD*)(buffer+2) = wLevel;
- *(WORD*)(buffer+4) = wSkillId;
- *(DWORD*)(buffer+6) = dwTarget;
- parseSendData(buffer, 10, true);
- return(0);
- }
- int sendUseSkillOnLoc(WORD wLevel, WORD wSkillId, POINT pnt)
- {
- char buffer[10];
- *(WORD*)(buffer+0) = 0x0116;
- *(WORD*)(buffer+2) = wLevel;
- *(WORD*)(buffer+4) = wSkillId;
- *(WORD*)(buffer+6) = (WORD)pnt.x;
- *(WORD*)(buffer+8) = (WORD)pnt.y;
- parseSendData(buffer, 10, true);
- return(0);
- }
- int sendStand()
- {
- char buffer[7];
- memset(buffer, 0, 7);
- *(WORD*)(buffer+0) = 0x0089;
- *(BYTE*)(buffer+6) = 3;
- parseSendData(buffer, 7, true);
- return(0);
- }
- int sendSit()
- {
- char buffer[7];
- memset(buffer, 0, 7);
- *(WORD*)(buffer+0) = 0x0089;
- *(BYTE*)(buffer+6) = 2;
- parseSendData(buffer, 7, true);
- return(0);
- }
- int sendRespawn()
- {
- char buffer[3];
- *(BYTE*)(buffer+0) = 0xB2;
- *(BYTE*)(buffer+1) = 0;
- *(BYTE*)(buffer+2) = 1;
- parseSendData(buffer, 3, true);
- return(0);
- }
- int sendUseItem(WORD wIndex, DWORD dwTarget)
- {
- char buffer[8];
- *(WORD*)(buffer+0) = 0x00A7;
- *(WORD*)(buffer+2) = wIndex;
- *(DWORD*)(buffer+4) = dwTarget;
- parseSendData(buffer, 8, true);
- return(0);
- }
- int sendDealCancel()
- {
- char buffer[3];
- *(BYTE*)(buffer+0) = 0xE6;
- *(BYTE*)(buffer+1) = 0x00;
- *(BYTE*)(buffer+2) = 0x04;
- parseSendData(buffer, 3, true);
- return(0);
- }
- int sendAttackStop()
- {
- char buffer[2];
- *(WORD*)(buffer+0) = 0x0118;
- parseSendData(buffer, 2, true);
- return(0);
- }
- int sendGetPlayerInfo(DWORD dwId)
- {
- char buffer[6];
- *(WORD*)(buffer+0) = 0x0094;
- *(DWORD*)(buffer+2) = dwId;
- parseSendData(buffer, 6, true);
- return(0);
- }
- int sendChatParty(LPCTSTR lpszMsg)
- {
- if(!option.bUsePartyChat)
- {
- injectMessage(lpszMsg);
- return(0);
- }
- char *pBufNew = NULL;
- char *p = NULL;
- WORD sSizeNew = strlen(lpszMsg) + 8 + strlen(you.cName);
- pBufNew = new char [sSizeNew];
- memset(pBufNew, 0, sSizeNew);
- p = pBufNew;
- *((WORD*)p) = 0x0108; p += 2;
- *((WORD*)p) = sSizeNew; p += 2;
- strcpy(p, you.cName); p += strlen(you.cName);
- strcpy(p, _T(" : ")); p += 3;
- strcpy(p, lpszMsg);
- parseSendData(pBufNew, sSizeNew, true);
- delete pBufNew;
- return(0);
- }
- int sendChatPublic(LPCTSTR lpszMsg)
- {
- char *pBufNew = NULL;
- char *p = NULL;
- WORD sSizeNew = strlen(lpszMsg) + 8 + strlen(you.cName);
- pBufNew = new char [sSizeNew];
- memset(pBufNew, 0, sSizeNew);
- p = pBufNew;
- *((WORD*)p) = 0x008C; p += 2;
- *((WORD*)p) = sSizeNew; p += 2;
- strcpy(p, you.cName); p += strlen(you.cName);
- strcpy(p, _T(" : ")); p += 3;
- strcpy(p, lpszMsg);
- parseSendData(pBufNew, sSizeNew, true);
- delete pBufNew;
- return(0);
- }
- BOOL utlCheckForGmByName(PLAYER player)
- {
- BOOL bRtn = false;
- if(0 == strcmp(player.cName, _T("gm01")) ||
- 0 == strcmp(player.cName, _T("gm02")) ||
- 0 == strcmp(player.cName, _T("gm03")) ||
- 0 == strcmp(player.cName, _T("gm04")) ||
- 0 == strcmp(player.cName, _T("gm05")) ||
- 0 == strcmp(player.cName, _T("gm06")))
- bRtn = true;
- return(bRtn);
- }
- BOOL utlCheckForWanzi(LPCTSTR lpszGuild)
- {
- BOOL bRtn = false;
- BOOL bFound = false;
- int i;
- if(strlen(lpszGuild) > 1)
- {
- for(i=0; i<(int)strlen(lpszGuild)-1; i++)
- {
- if(lpszGuild[i] == (char)0xCD && lpszGuild[i+1] == (char)0xE8)
- {
- bFound = true;
- break;
- }
- }
- if(bFound)
- {
- bFound = false;
- for(i=0; i<(int)strlen(lpszGuild)-1; i++)
- {
- if(lpszGuild[i] == (char)0xD7 && lpszGuild[i+1] == (char)0xD3)
- {
- bFound = true;
- break;
- }
- }
- }
- if(bFound)
- {
- bFound = false;
- for(i=0; i<(int)strlen(lpszGuild)-1; i++)
- {
- if(lpszGuild[i] == (char)0xBC && lpszGuild[i+1] == (char)0xD2)
- {
- bFound = true;
- break;
- }
- }
- }
- if(bFound)
- {
- bFound = false;
- for(i=0; i<(int)strlen(lpszGuild)-1; i++)
- {
- if(lpszGuild[i] == (char)0xD7 && lpszGuild[i+1] == (char)0xE5)
- {
- bFound = true;
- break;
- }
- }
- }
- if(bFound)
- bRtn = true;
- }
- return(bRtn);
- }
- BOOL utlCheckForGm(PLAYER player)
- {
- BOOL bRtn = false;
- CString strAid, strDummy;
- if(0 != serverip[0][0])
- {
- strAid.Format(_T("%d.%d.%d.%d#%d"),
- serverip[0][2],
- serverip[0][3],
- serverip[0][4],
- serverip[0][5],
- player.dwId);
- bRtn = mapAvoidAid.Lookup(strAid, strDummy);
- }
- return(bRtn);
- }
- int utlFindItemInInventory(LPCTSTR lpszItemName)
- {
- int nRtn = -1;
- CString strTemp;
- CString strItemName = lpszItemName;
- for(int i=0; i<inventory.GetSize(); i++)
- {
- strTemp = mapItem.FindValue(inventory[i].dwId, eItemName);
- if(strTemp == strItemName)
- {
- nRtn = inventory[i].dwIndex;
- break;
- }
- }
- return(nRtn);
- }
- #define USE_ITEM(ITEM)
- for(i=0; i<ITEM.GetSize(); i++) {
- nIndex = utlFindItemInInventory(ITEM[i]);
- if(-1 != nIndex){
- sendUseItem(nIndex, dwAccountId);
- bHealed = true;}}
- void utlCheckForAutoHeal()
- {
- if(dwUseItemTick != 0 && dwUseItemTick > GetTickCount())
- return;
- if(you.wHp <= 1 || you.bDied || nConnState < 5)
- return;
- AUTOHEAL2 *pHeal;
- BOOL bHealNeed = false;
- BOOL bHealed = false;
- int nIndex, i;
- static BOOL bTeleported = false;
- switch(mode)
- {
- case eModeNormal:
- case eModePvp:
- case eModeGvg:
- pHeal = &settingcmn.autoheal;
- break;
- case eModeMvp:
- pHeal = &settingmvp.autoheal;
- break;
- }
- if(pHeal->bHP)
- {
- if(you.wHp > pHeal->nHP1Lower && you.wHp < pHeal->nHP1Upper && pHeal->nHP1Upper <= you.wHpMax)
- {
- bHealNeed = true;
- nIndex = utlFindItemInInventory(pHeal->strHP1Item);
- if(-1 != nIndex)
- {
- sendUseItem(nIndex, dwAccountId);
- you.wHp = pHeal->nHP1Upper;
- bHealed = true;
- }
- else
- {
- USE_ITEM(HPITEMS);
- you.wHp = pHeal->nHP1Upper;
- }
- }
- if(!bHealed && ((you.wHp > pHeal->nHP2Lower && you.wHp < pHeal->nHP2Upper && pHeal->nHP2Upper <= you.wHpMax) ||
- (you.wHp > pHeal->nHP1Lower && you.wHp < pHeal->nHP1Upper && pHeal->nHP1Upper <= you.wHpMax)) &&
- you.wSp >= 40)
- {
- nIndex = utlFindSkillByAlias(_T("治愈术"));
- if(nIndex != -1)
- {
- sendUseSkill(skills[nIndex].wLevel, (unsigned short)skills[nIndex].dwId, dwAccountId);
- bHealed = true;
- }
- }
- }
- if(bHealNeed && !bHealed)
- {
- injectAdminMessage(_T("无法自动回复HP,回动回复HP已关闭,请检查物品或技能后手动打开"));
- pHeal->bHP = false;
- }
- if(bHealNeed && bHealed)
- {
- dwUseItemTick = GetTickCount() + option.nItemUseInterval;
- return;
- }
- bHealNeed = bHealed = false;
- if(pHeal->bSP && you.wSp < pHeal->nSPUpper && pHeal->nSPUpper <= you.wSpMax)
- {
- bHealNeed = true;
- nIndex = utlFindItemInInventory(pHeal->strSPItem);
- if(-1 != nIndex)
- {
- sendUseItem(nIndex, dwAccountId);
- you.wSp = pHeal->nSPUpper;
- bHealed = true;
- }
- else
- {
- USE_ITEM(SPITEMS);
- you.wSp = pHeal->nSPUpper;
- }
- }
- if(bHealNeed && !bHealed)
- {
- injectAdminMessage(_T("无法自动回复SP,回动回复SP已关闭,请检查物品后手动打开"));
- pHeal->bSP = false;
- }
- if(bHealNeed && bHealed)
- dwUseItemTick = GetTickCount() + option.nItemUseInterval;
- if(pHeal->bHPTele && you.wHp < pHeal->nHPTeleUpper && pHeal->nHPTeleUpper <= you.wHpMax)
- {
- CDWordArray dwTargetArray, dwDamageArray;
- if(damages.FindDamageFrom(dwAccountId, dwTargetArray, dwDamageArray))
- {
- if(dwTargetArray.GetSize() > 0)
- {
- utlUseTeleport(1);
- }
- }
- }
- return;
- }
- void utlReportMonsterToParty(DWORD dwId)
- {
- CString strMsg, strTemp;
- CString strArraw[] = {"↑", "↗", "→", "↘", "↓", "↙", "←", "↖"};
- int nIndex = monsters.FindId(dwId);
- if(-1 != nIndex)
- {
- int tempX, tempY;
- tempX = monsters[nIndex].pntPos.x - field.m_szField.cx / 2;
- tempY = monsters[nIndex].pntPos.y - field.m_szField.cy / 2;
- double dRadio, dRadio1;
- dRadio1 = dRadio = atan2(tempY, tempX);
- dRadio = dRadio * 180 / 3.1415926;
- if(dRadio < 0)
- dRadio += 360;
- dRadio -= 90;
- if(dRadio < 0)
- dRadio += 360;
- dRadio = 360 - dRadio;
- double dDist;
- // if(cos(dRadio1) != 0)
- // {
- // dDist1 = double(field.m_szField.cx)/2/cos(dRadio1);
- // }
- dDist = sqrt(tempX*tempX + tempY*tempY);
- strMsg.Format(_T("发现%s(%d,%d), %d点%d分方向, 距离中心点%d "),
- monsters[nIndex].cName, monsters[nIndex].pntPos.x, monsters[nIndex].pntPos.y,
- (int)dRadio / 30, ((int)dRadio % 30)*2, (int)dDist);
- if(dDist < 50)
- {
- strTemp = _T("⊙");
- }
- else
- {
- if(dRadio <= 22.5 || dRadio >= 337.5)
- strTemp = strArraw[0];
- else
- {
- dRadio -= 22.5;
- strTemp = strArraw[(int)dRadio/45+1];
- }
- }
- strMsg += strTemp;
- sendChatParty(strMsg);
- }
- }
- void utlSetAutoSearchMvp(BOOL bOn)
- {
- if(bAutoSearch == bOn)
- return;
- CString strOutput;
- bAutoSearch = bOn;
- if(bOn)
- {
- strOutput.Format(_T("开始自动寻找"));
- injectAdminMessage(strOutput);
- dwAutoSearchTick = GetTickCount() + option.nAutoSearchDelay;
- strAutoSearchMap = field.m_strFieldname;
- }
- else
- {
- strOutput.Format(_T("结束自动寻找"));
- injectAdminMessage(strOutput);
- dwAutoSearchTick = 0;
- strAutoSearchMap.Empty();
- }
- return;
- }
- int utlFindSkillByAlias(LPCTSTR lpszSkillName)
- {
- CString strTemp;
- int nRtn = -1;
- for(int i=0; i<mapSkill.GetCount(); i++)
- {
- strTemp = mapSkill.FindValue(i, eSkillAlias);
- if(strTemp.CompareNoCase(lpszSkillName) == 0)
- {
- for(int j=0; j<skills.GetSize(); j++)
- {
- int temp = skills[j].dwId;
- if(skills[j].dwId == (DWORD)i)
- {
- nRtn = j;
- break;
- }
- }
- }
- }
- return(nRtn);
- }
- int utlFindSkillIdByAlias(LPCTSTR lpszSkillName)
- {
- CString strTemp;
- int nRtn = -1;
- for(int i=0; i<mapSkill.GetCount(); i++)
- {
- strTemp = mapSkill.FindValue(i, eSkillAlias);
- if(strTemp.CompareNoCase(lpszSkillName) == 0)
- {
- nRtn = i;
- break;
- }
- }
- return(nRtn);
- }
- int utlLoadBossInfo()
- {
- CString strProfile, strTemp, strTemp1;
- char buffer[1024];
- int i;
- DWORD dwRtn;
- BOSSINFO boss;
- int nBossNumber;
- bossinfo.RemoveAll();
- dwRtn = GetPrivateProfileString(ROA_INI2_BOSSINFO, _T("BossNumber"), _T(""), buffer, 1024, ROA_INI2_FILENAME);
- nBossNumber = atoi(buffer);
- for(i=0; i<nBossNumber; i++)
- {
- int y, m, d, h, min, s;
- y=m=d=h=min=s=0;
- strTemp.Format(_T("Boss%d"), i+1);
- dwRtn = GetPrivateProfileString(ROA_INI2_BOSSINFO, strTemp, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- strProfile = buffer;
- strTemp = utlParseString(strProfile);
- boss.strBossName = strTemp;
- strTemp = utlParseString(strProfile);
- y = atoi(strTemp);
- strTemp = utlParseString(strProfile);
- m = atoi(strTemp);
- strTemp = utlParseString(strProfile);
- d = atoi(strTemp);
- strTemp = utlParseString(strProfile);
- h = atoi(strTemp);
- strTemp = utlParseString(strProfile);
- min = atoi(strTemp);
- strTemp = utlParseString(strProfile);
- s = atoi(strTemp);
- CTime time(y, m, d, h, min, s);
- boss.tmBossTime = time;
- CTime tmNow = CTime::GetCurrentTime();
- CTimeSpan ts = tmNow - boss.tmBossTime;
- if(ts.GetTotalHours() <= 24)
- {
- bossinfo.Add(boss);
- }
- }
- utlSortBossInfo();
- return(0);
- }
- int utlWriteBossInfo()
- {
- CString strProfile, strTemp, strTemp1;
- int i;
- strProfile.Format(_T("%d"), bossinfo.GetSize());
- WritePrivateProfileString(ROA_INI2_BOSSINFO, _T("BossNumber"), strProfile, ROA_INI2_FILENAME);
- for(i=0; i<bossinfo.GetSize(); i++)
- {
- strProfile.Format(_T("%s,%d,%d,%d,%d,%d,%d"), bossinfo[i].strBossName,
- bossinfo[i].tmBossTime.GetYear(),
- bossinfo[i].tmBossTime.GetMonth(),
- bossinfo[i].tmBossTime.GetDay(),
- bossinfo[i].tmBossTime.GetHour(),
- bossinfo[i].tmBossTime.GetMinute(),
- bossinfo[i].tmBossTime.GetSecond());
- strTemp.Format(_T("Boss%d"), i+1);
- WritePrivateProfileString(ROA_INI2_BOSSINFO, strTemp, strProfile, ROA_INI2_FILENAME);
- }
- return(0);
- }
- int utlSetMonsterDiedTime(LPCTSTR lpszMonsterName)
- {
- int i, nIndex = -1;
- BOSSINFO boss;
- CString bossfullname;
- bossfullname.Format(_T("%s(%s)"), lpszMonsterName, field.m_strAlias);
- for(i=0; i<bossinfo.GetSize(); i++)
- {
- if(bossinfo[i].strBossName.CompareNoCase(bossfullname) == 0)
- {
- boss = bossinfo[i];
- nIndex = i;
- break;
- }
- }
- CTime tm = CTime::GetCurrentTime();
- boss.tmBossTime = tm;
- boss.reset();
- if(-1 == nIndex)
- {
- boss.strBossName = bossfullname;
- bossinfo.Add(boss);
- }
- else
- {
- bossinfo.SetAt(nIndex, boss);
- }
- utlWriteBossInfo();
- return(0);
- }
- BOOL utlCheckSpellLoc(POINT pnt, WORD wSkill)
- {
- BOOL bRtn = false;
- for(int i=0; i<spells.GetSize(); i++)
- {
- if(spells[i].pntPos.x == pnt.x && spells[i].pntPos.y == pnt.y && spells[i].wSkill == wSkill)
- {
- bRtn = true;
- break;
- }
- }
- return(bRtn);
- }
- int utlSortBossInfo()
- {
- BOSSINFO boss;
- for(int i=0; i<bossinfo.GetSize(); i++)
- {
- for(int j=i+1; j<bossinfo.GetSize(); j++)
- {
- CTimeSpan ts = bossinfo[i].tmBossTime - bossinfo[j].tmBossTime;
- if(ts.GetTotalSeconds() > 0)
- {
- boss = bossinfo[i];
- bossinfo[i] = bossinfo[j];
- bossinfo[j] = boss;
- }
- }
- }
- return(0);
- }
- int utlGMAppeared(PLAYER player)
- {
- CString strOutput;
- strOutput.Format("发现GM帐号[%08X:%s]", player.dwId, player.cName);
- sendChatParty(strOutput);
- injectAdminMessage(strOutput);
- bAiEnabled = false;
- return(0);
- }
- int utlGMDisappeared(PLAYER player)
- {
- CString strOutput;
- strOutput.Format("GM帐号[%08X:%s]消失了", player.dwId, player.cName);
- sendChatParty(strOutput);
- injectAdminMessage(strOutput);
- bAiEnabled = true;
- return(0);
- }
- int utlShowAttackResult(DWORD nMonIndex)
- {
- int nIndex;
- CString strOutput;
- DWORD dwTick;
- int i;
- double dSecond;
- nIndex = damages.FindDamage(dwAccountId, monsters[nMonIndex].dwId);
- if(nIndex != -1)
- {
- dwTick = GetTickCount() - damages[nIndex].dwStart;
- dSecond = (double)dwTick/1000;
- strOutput.Format(_T("攻击 %s : 持续时间: %2.2f秒,DMG: %d"), utlFindTarget(monsters[nMonIndex].dwId), dSecond, damages[nIndex].dwDamage);
- injectMessage(strOutput);
- for(i=0; i<MAX_SKILL; i++)
- {
- if( damages[nIndex].dwHits[i] == 0 &&
- damages[nIndex].dwDamage2[i] == 0 &&
- damages[nIndex].dwMiss[i] == 0)
- continue;
- strOutput.Format(_T(" -- %s %dHits %dMiss %dDMG [MAX:%d MIN:%d %2.2fHits/s %2.2fDMG/s]"),
- mapSkill.FindValue(i, eSkillAlias),
- damages[nIndex].dwHits[i],
- damages[nIndex].dwMiss[i],
- damages[nIndex].dwDamage2[i],
- damages[nIndex].dwDamageMax[i],
- damages[nIndex].dwDamageMin[i],
- dSecond < 0.01 ? 0 : (double)damages[nIndex].dwHits[i]/dSecond,
- dSecond < 0.01 ? 0 : (double)damages[nIndex].dwDamage2[i]/dSecond
- );
- injectMessage(strOutput);
- }
- }
- return(0);
- }
- int utlParseInventory(char *pBuffer, INVENTORY* pInv, DWORD dwParseId)
- {
- switch(dwParseId)
- {
- case 0x00A0: //00a0 <index>.w <amount>.w <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w <equip type>.w <type>.B <fail>.B
- pInv->dwIndex = *((WORD*)(pBuffer));
- pInv->wAmount = *((WORD*)(pBuffer+2));
- pInv->dwId = *((WORD*)(pBuffer+4));
- pInv->bIdentified = *(pBuffer+6);
- pInv->byAttrib = *(pBuffer+7);
- pInv->byRefine = *(pBuffer+8);
- pInv->wCard[0] = *((WORD*)(pBuffer+9));
- if(pInv->wCard[0] == 0x00FF)
- {
- pInv->byElement = *(pBuffer+11);
- pInv->byStar = *(pBuffer+12) / 5;
- }
- else
- {
- pInv->wCard[1] = *((WORD*)(pBuffer+11));
- pInv->wCard[2] = *((WORD*)(pBuffer+13));
- pInv->wCard[3] = *((WORD*)(pBuffer+15));
- }
- pInv->wEquipType = *((WORD*)(pBuffer+17));
- pInv->wType = *(pBuffer+19);
- break;
- case 0x00A4:
- case 0x0122:
- pInv->dwIndex = *((WORD*)(pBuffer));
- pInv->dwId = *((WORD*)(pBuffer+2));
- pInv->wAmount = 1;
- pInv->wType = *(pBuffer+4);
- pInv->bIdentified = *(pBuffer+5);
- pInv->wEquipType = *((WORD*)(pBuffer+6));
- pInv->wEquipped = *((WORD*)(pBuffer+8));
- pInv->byRefine = *(pBuffer+11);
- pInv->wCard[0] = *((WORD*)(pBuffer+12));
- if(pInv->wCard[0] == 0x00FF)
- {
- pInv->byElement = *(pBuffer+14);
- pInv->byStar = *(pBuffer+15) / 5;
- }
- else
- {
- pInv->wCard[1] = *((WORD*)(pBuffer+14));
- pInv->wCard[2] = *((WORD*)(pBuffer+16));
- pInv->wCard[3] = *((WORD*)(pBuffer+18));
- }
- break;
- }
- return(0);
- }
- CString utlGetInventoryName(INVENTORY *pInv)
- {
- CString strRtn, strTemp;
- strRtn.Empty();
- if(pInv->wEquipType)
- {
- if(pInv->byRefine)
- {
- strRtn.Format(_T("+%d"), pInv->byRefine);
- }
- strRtn += mapItem.FindValue(pInv->dwId, eItemName);
- if(pInv->wCard[0] == 0x00FF)
- {
- if(pInv->byStar != 0)
- {
- strTemp.Format(_T("[%d级强悍]"), pInv->byStar);
- strRtn += strTemp;
- }
- if(pInv->byElement != 0)
- {
- strTemp.Format(_T("[%s属性]"), mapElements.FindValue(pInv->byElement));
- strRtn += strTemp;
- }
- }
- else
- {
- CString strTemp1[4];
- int nTemp1[4];
- for(int i=0; i<4; i++)
- {
- nTemp1[i] = 0;
- if(pInv->wCard[i] != 0)
- {
- strTemp1[i].Format(_T("%s"), mapItem.FindValue(pInv->wCard[i], eItemName));
- nTemp1[i] = 1;
- }
- }
- for(i=3; i>0; i--)
- {
- if(!strTemp1[1].IsEmpty() && strTemp1[i] == strTemp1[i-1])
- {
- nTemp1[i-1] += nTemp1[i];
- strTemp1[i].Empty();
- nTemp1[i] = 0;
- }
- }
- for(i=0; i<4; i++)
- {
- if(nTemp1[i] == 0 || strTemp1[i].IsEmpty())
- continue;
- if(nTemp1[i] == 1)
- {
- strTemp.Format(_T("[%s]"), strTemp1[i]);
- }
- else
- {
- strTemp.Format(_T("[%d倍%s]"), nTemp1[i], strTemp1[i]);
- }
- strRtn += strTemp;
- }
- }
- }
- else
- {
- strRtn = mapItem.FindValue(pInv->dwId, eItemName);
- }
- return(strRtn);
- }
- BOOL utlPlayerInParty(DWORD dwId)
- {
- // return(false);
- return(partners.FindId(dwId) != -1);
- }
- BOOL utlIsMvpMonster(MONSTER monster)
- {
- CString strId, strName;
- BOOL bFound = false;
- mapMvpMonster.FindValue(monster.wType, 0, &bFound);
- if(!bFound)
- {
- POSITION pos = mapMvpMonster.GetStartPosition();
- while (pos)
- {
- mapMvpMonster.GetNextAssoc(pos, strId, strName);
- if (strName == monster.cName)
- {
- bFound = true;
- break;
- }
- }
- }
- return(bFound);
- }
- int sendUnequip(int nIndex)
- {
- char buffer[4];
- *(WORD*)buffer = 0x00AB;
- *(WORD*)(buffer+2) = (WORD)nIndex;
- parseSendData(buffer, 4, true);
- return(0);
- }
- int sendEquip(int nIndex, WORD wType)
- {
- char buffer[6];
- *(WORD*)buffer = 0x00A9;
- *(WORD*)(buffer+2) = (WORD)nIndex;
- *(WORD*)(buffer+4) = (WORD)wType;
- parseSendData(buffer, 6, true);
- return(0);
- }
- int utlPopupBossWarning()
- {
- CTimeSpan timespan;
- CTime tmNow;
- long dwSecond;
- tmNow = CTime::GetCurrentTime();
- tmNow -= CTimeSpan( 0, 1, 0, 0 ); // 1 hour exactly
- CString strTemp;
- for(int i=0; i<bossinfo.GetSize(); i++)
- {
- timespan = bossinfo[i].tmBossTime - tmNow;
- dwSecond = timespan.GetTotalSeconds();
- if(dwSecond > 10*60 || dwSecond < -60)
- continue;
- if(dwSecond < 10*60 && dwSecond >= 5*60 && !bossinfo[i].bWaring[0])
- {
- strTemp.Format(_T("%s还有%d分%d秒重生"), bossinfo[i].strBossName, dwSecond / 60, dwSecond%60);
- sendChatParty(strTemp);
- injectAdminMessage(strTemp);
- bossinfo[i].bWaring[0] = true;
- }
- if(dwSecond < 5*60 && dwSecond >= 3*60 && !bossinfo[i].bWaring[1])
- {
- strTemp.Format(_T("%s还有%d分%d秒重生"), bossinfo[i].strBossName, dwSecond / 60, dwSecond%60);
- sendChatParty(strTemp);
- injectAdminMessage(strTemp);
- bossinfo[i].bWaring[0] = true;
- bossinfo[i].bWaring[1] = true;
- }
- if(dwSecond < 3*60 && dwSecond >= 30 && !bossinfo[i].bWaring[2])
- {
- strTemp.Format(_T("%s还有%d分%d秒重生"), bossinfo[i].strBossName, dwSecond / 60, dwSecond%60);
- sendChatParty(strTemp);
- injectAdminMessage(strTemp);
- bossinfo[i].bWaring[0] = true;
- bossinfo[i].bWaring[1] = true;
- bossinfo[i].bWaring[2] = true;
- }
- if(dwSecond < 30 && dwSecond >= 1 && !bossinfo[i].bWaring[3])
- {
- strTemp.Format(_T("%s还有%d秒重生"), bossinfo[i].strBossName, dwSecond);
- sendChatParty(strTemp);
- injectAdminMessage(strTemp);
- bossinfo[i].bWaring[0] = true;
- bossinfo[i].bWaring[1] = true;
- bossinfo[i].bWaring[2] = true;
- bossinfo[i].bWaring[3] = true;
- }
- if(dwSecond < 1 && !bossinfo[i].bWaring[4])
- {
- strTemp.Format(_T("%s重生了"), bossinfo[i].strBossName);
- sendChatParty(strTemp);
- injectAdminMessage(strTemp);
- bossinfo[i].bWaring[0] = true;
- bossinfo[i].bWaring[1] = true;
- bossinfo[i].bWaring[2] = true;
- bossinfo[i].bWaring[3] = true;
- bossinfo[i].bWaring[4] = true;
- }
- }
- return(0);
- }
- int utlLoadOption(OPTION& option)
- {
- char buffer[1024];
- DWORD dwRtn;
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_TESTSVR, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.bTestServer = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_PARTYCHAT, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.bUsePartyChat = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_AUTOPICKUP, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.bAutoPickup = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_BOSSINFO, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.bBossInfo = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_MOVEPICKUP, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.bMovePickup = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_LAUNCHER, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.strLauncher = buffer;
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_LAUNCHERPAPRAM, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.strLaunchParam = buffer;
- for(int i=0; i<10; i++)
- {
- CString strProfile;
- strProfile.Format(_T("%s%d"), ROA_INI2_OPT_EMOTION, i);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, strProfile, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- emotions[i] = buffer;
- }
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_AUTOCONT, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.bNpcTalkContinue = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_WELCOMEDELAY, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.nWelcomeDelay = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_SEARCHDELAY, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.nAutoSearchDelay = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_PICKUPDISTANCE, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.nPickupDistance = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_ATTACKPERS, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.nAttackPerSecond = atoi(buffer);
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_HPITEMS, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.strHPRecoverItems = buffer;
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_SPITEMS, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.strSPRecoverItems = buffer;
- dwRtn = GetPrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_ITEMUSEINT, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(buffer[0] != 0)
- option.nItemUseInterval = atoi(buffer);
- return(0);
- }
- int utlSaveOption(OPTION option)
- {
- CString strProfile;
- strProfile.Format(_T("%d"), option.bTestServer);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_TESTSVR, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.bUsePartyChat);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_PARTYCHAT, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.bAutoPickup);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_AUTOPICKUP, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.bBossInfo);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_BOSSINFO, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.bMovePickup);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_MOVEPICKUP, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%s"), option.strLauncher);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_LAUNCHER, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%s"), option.strLaunchParam);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_LAUNCHERPAPRAM, strProfile, ROA_INI2_FILENAME);
- for(int i=0; i<10; i++)
- {
- strProfile.Format(_T("%s%d"), ROA_INI2_OPT_EMOTION, i);
- WritePrivateProfileString(ROA_INI2_OPTION, strProfile, emotions[i], ROA_INI2_FILENAME);
- }
- strProfile.Format(_T("%d"), option.bNpcTalkContinue);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_AUTOCONT, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.nWelcomeDelay);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_WELCOMEDELAY, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.nAutoSearchDelay);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_SEARCHDELAY, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.nPickupDistance);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_PICKUPDISTANCE, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.nAttackPerSecond);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_ATTACKPERS, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%s"), option.strHPRecoverItems);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_HPITEMS, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%s"), option.strSPRecoverItems);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_SPITEMS, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), option.nItemUseInterval);
- WritePrivateProfileString(ROA_INI2_OPTION, ROA_INI2_OPT_ITEMUSEINT, strProfile, ROA_INI2_FILENAME);
- return(0);
- }
- void utlWriteUserProfile()
- {
- CString strProfile;
- CString strName, strTemp;
- strName = utlProcessUserName(you.cName);
- strProfile = settingcmn.GetProfileString();
- WritePrivateProfileString(strName, ROA_INI2_SETTING_CMN, strProfile, ROA_INI2_FILENAME);
- strProfile = settingmvp.GetProfileString();
- WritePrivateProfileString(strName, ROA_INI2_SETTING_MVP, strProfile, ROA_INI2_FILENAME);
- strProfile.Format(_T("%d"), userfuncs[0]);
- for(int i=1; i<12; i++)
- {
- strTemp.Format(_T(",%d"), userfuncs[i]);
- strProfile += strTemp;
- }
- WritePrivateProfileString(strName, ROA_INI2_SETTING_KEY, strProfile, ROA_INI2_FILENAME);
- return;
- }
- CString utlProcessUserName(LPCTSTR lpszName)
- {
- CString strRet, strName;
- BOOL bWide = false;
- if(0 == strlen(lpszName))
- strName = _T("[未知人物]");
- else
- strName = lpszName;
- strName += _T("_V3");
- strRet.Empty();
- for(int i=0; i<(int)strlen(strName); i++)
- {
- if(bWide)
- {
- strRet += strName[i];
- bWide = false;
- continue;
- }
- if(strName[i] & 0x80)
- {
- bWide = true;
- strRet += strName[i];
- continue;
- }
- if(strName[i] != _T('[') && strName[i] != _T(']') && strName[i] >= 32)
- {
- strRet += strName[i];
- }
- }
- return(strRet);
- }
- void utlReadUserProfile()
- {
- char buffer[1024];
- DWORD dwRtn;
- CString strProfile;
- CString strName, strTemp;
- bProfileLoaded = false;
- strName = utlProcessUserName(you.cName);
- dwRtn = GetPrivateProfileString(strName, ROA_INI2_SETTING_CMN, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(dwRtn > 0)
- {
- strProfile = buffer;
- settingcmn.ParseProfileString(strProfile);
- bProfileLoaded = true;
- }
- dwRtn = GetPrivateProfileString(strName, ROA_INI2_SETTING_MVP, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(dwRtn > 0)
- {
- strProfile = buffer;
- settingmvp.ParseProfileString(strProfile);
- bProfileLoaded = true;
- }
- dwRtn = GetPrivateProfileString(strName, ROA_INI2_SETTING_KEY, _T(""), buffer, 1024, ROA_INI2_FILENAME);
- if(dwRtn > 0)
- {
- strProfile = buffer;
- for(int i=0; i<12; i++)
- {
- strTemp = utlParseString(strProfile);
- userfuncs[i] = (USERFUNCTION)atoi(strTemp);
- }
- bProfileLoaded = true;
- }
- return;
- }
- int utlAddComboHPItem(CComboBox *pCombo)
- {
- for(int i=0; i<HPITEMS.GetSize(); i++)
- {
- pCombo->AddString(HPITEMS[i]);
- }
- return(0);
- }
- int utlAddComboSPItem(CComboBox *pCombo)
- {
- for(int i=0; i<SPITEMS.GetSize(); i++)
- {
- pCombo->AddString(SPITEMS[i]);
- }
- return(0);
- }
- int utlAddComboAttackSkill(CComboBox *pCombo)
- {
- for(int i=0; i<ATTACKSKILLNUM; i++)
- {
- pCombo->AddString(ATTACKSKILL[i]);
- }
- return(0);
- }
- int utlAddComboProtectState(CComboBox *pCombo)
- {
- for(int i=0; i<PROTECTSTATENUM; i++)
- {
- pCombo->AddString(PROTECTSTATE[i]);
- }
- return(0);
- }
- int utlAddComboProtectSkill(CComboBox *pCombo)
- {
- for(int i=0; i<PROTECTSKILLNUM; i++)
- {
- pCombo->AddString(PROTECTSKILL[i]);
- }
- return(0);
- }
- BOOL CheckForRegionAttack(CString& strSkillName, int& nMonIndex)
- {
- CDWordArray dwTargetArray, dwDamageArray;
- BOOL bRet = false;
- if(damages.FindDamageFrom(dwAccountId, dwTargetArray, dwDamageArray))
- {
- if(dwTargetArray.GetSize() > settingmvp.nRegionAtkNum)
- {
- bRet = true;
- int nMonsters = dwTargetArray.GetSize();
- int x=0, y=0, nCount = 0;
- POINT pntCenter;
- double dDist = 999;
- int nIndex;
- for(int i=0; i<nMonsters; i++)
- {
- nIndex = monsters.FindId(dwTargetArray[i]);
- if(nIndex != -1)
- {
- x += monsters[nIndex].pntTo.x;
- y += monsters[nIndex].pntTo.y;
- nCount++;
- }
- }
- pntCenter.x = (int)((double)x/nCount);
- pntCenter.y = (int)((double)y/nCount);
- for(i=0; i<nMonsters; i++)
- {
- nIndex = monsters.FindId(dwTargetArray[i]);
- if(nIndex != -1)
- {
- if(utlDistanceFrom(pntCenter, monsters[nIndex].pntPos) < dDist)
- {
- dDist = utlDistanceFrom(pntCenter, monsters[nIndex].pntPos);
- strSkillName = settingmvp.strRegionAtkSkill;
- nMonIndex = nIndex;
- }
- }
- }
- }
- }
- return(bRet);
- }
- int utlChangeMode(BYTE eMode, DWORD dwId)
- {
- CString strOutput;
- BYTE eModeOld = mode;
- if(mode != eMode)
- {
- mode = eMode;
- switch(mode)
- {
- case eModeNormal:
- dwMvpId = 0;
- break;
- case eModeMvp:
- dwMvpId = dwId;
- if(bAutoSearch)
- {
- ufAutoSearchMvp(false);
- }
- break;
- }
- }
- if(mode != eModeNormal && !utlCheckForWanzi(you.cGuild))
- {
- for(int i=0; i<players.GetSize(); i++)
- {
- if(utlCheckForWanzi(players[i].cGuild) && !utlPlayerInParty(players[i].dwId))
- {
- mode = eModeNormal;
- break;
- }
- }
- }
- if(eModeOld != mode)
- {
- switch(mode)
- {
- case eModeNormal:
- strOutput = _T("进入正常模式");
- break;
- case eModeMvp:
- strOutput = _T("进入MVP模式");
- break;
- }
- injectAdminMessage(strOutput);
- }
- return(0);
- }
- int sendTalkContinue(DWORD dwNpcId)
- {
- char buffer[6];
- *(WORD*)(buffer+0) = 0x00B9;
- *(DWORD*)(buffer+2) = dwNpcId;
- parseSendData(buffer, 6, true);
- return(0);
- }
- int sendTalkCancel(DWORD dwNpcId)
- {
- char buffer[6];
- *(WORD*)(buffer+0) = 0x0146;
- *(DWORD*)(buffer+2) = dwNpcId;
- parseSendData(buffer, 6, true);
- return(0);
- }
- void utlParseHpSpItems()
- {
- CString strTemp;
- int nIndex = -1;
- CString strHpItems, strSpItems;
- HPITEMS.RemoveAll();
- SPITEMS.RemoveAll();
- strHpItems = option.strHPRecoverItems;
- strSpItems = option.strSPRecoverItems;
- while(-1 != (nIndex = strHpItems.Find(_T("|"))))
- {
- strTemp = strHpItems.Left(nIndex);
- if(!strTemp.IsEmpty())
- HPITEMS.Add(strTemp);
- strHpItems = strHpItems.Mid(nIndex+1);
- }
- if(!strHpItems.IsEmpty())
- HPITEMS.Add(strHpItems);
- while(-1 != (nIndex = strSpItems.Find(_T("|"))))
- {
- strTemp = strSpItems.Left(nIndex);
- if(!strTemp.IsEmpty())
- SPITEMS.Add(strTemp);
- strSpItems = strSpItems.Mid(nIndex+1);
- }
- if(!strSpItems.IsEmpty())
- SPITEMS.Add(strSpItems);
- return;
- }
- DWORD utlGetFileSize(LPCTSTR lpszFilename)
- {
- HANDLE hFile;
- DWORD dwRet = 0;
- hFile = CreateFile(lpszFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
- if(hFile != INVALID_HANDLE_VALUE)
- {
- dwRet = GetFileSize(hFile, NULL);
- CloseHandle(hFile);
- }
- return(dwRet);
- }
- int utlGetAttackPerSecond()
- {
- int nRet = option.nAttackPerSecond;
- if(option.bTestServer)
- {
- if(nRet >= 10)
- nRet = 10;
- }
- else
- {
- if(nRet >= 3)
- nRet = 3;
- }
- return(nRet);
- }