ROA.cpp
资源名称:ROA3.40.rar [点击查看]
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:30k
源码类别:
外挂编程
开发平台:
Visual C++
- // ROA.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "ROA.h"
- #include "MainFrm.h"
- #include "ROADoc.h"
- #include "ROAView.h"
- #include "DlgOption.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CROAApp theApp;
- int processModeMvp()
- {
- int nTargetIndex = monsters.FindId(dwMvpId);
- if(settingmvp.bAttack && nTargetIndex != -1)
- {
- CString strSkillName = _T("");
- int nSkillId = -1;
- do
- {
- // Check for REGION ATTACK
- if(settingmvp.bRegionAtk)
- {
- if(CheckForRegionAttack(strSkillName, nTargetIndex))
- break;
- }
- // Check for ATTACK2
- if(settingmvp.bAttack2)
- {
- for(int j=0; j<spells.GetSize(); j++)
- {
- if((spells[j].pntPos.x == monsters[nTargetIndex].pntPos.x && spells[j].pntPos.y == monsters[nTargetIndex].pntPos.y) ||
- (spells[j].pntPos.x == monsters[nTargetIndex].pntTo.x && spells[j].pntPos.y == monsters[nTargetIndex].pntTo.y))
- {
- if(mapStatus011f.FindValue(spells[j].wSkill).CompareNoCase(settingmvp.strAttack2Cond) == 0)
- {
- strSkillName = settingmvp.strAttack2Skill;
- break;
- }
- }
- }
- }
- /* if(0 != monsters[nTargetIndex].nProtecting)
- if(utlFindSkillIdByAlias(settingmvp.strAttack2Cond) == monsters[nTargetIndex].nProtecting)
- break;}*/
- if(strSkillName.IsEmpty())
- strSkillName = settingmvp.strAttackSkill;
- break;
- }while(0);
- if(0 != strSkillName.CompareNoCase(_T("停止攻击")))
- {
- do
- {
- POINT pnt;
- if(settingmvp.bFollow &&
- utlDistanceFrom(you.pntTo, monsters[nTargetIndex].pntPos) > 3 &&
- field.FindNearestPoint(you.pntTo, monsters[nTargetIndex].pntPos, &pnt))
- {
- sendMove(pnt);
- break;
- }
- if(0 == strSkillName.CompareNoCase(_T("普通物理攻击")))
- {
- for(int attack=0; attack < utlGetAttackPerSecond(); attack++)
- sendAttack(monsters[nTargetIndex].dwId, 0);
- break;
- }
- nSkillId = utlFindSkillByAlias(strSkillName);
- if(nSkillId != -1 && you.wSp > 20)
- {
- for(int attack=0; attack < utlGetAttackPerSecond(); attack++)
- {
- sendUseSkill(skills[nSkillId].wLevel, (WORD)skills[nSkillId].dwId, monsters[nTargetIndex].dwId);
- }
- break;
- }
- }while(0);
- }
- }
- return(0);
- }
- int processModeNormal()
- {
- if(bAutoSearch && dwAutoSearchTick != 0 && GetTickCount() > dwAutoSearchTick)
- {
- if(strAutoSearchMap.CompareNoCase(field.m_strFieldname) == 0)
- {
- utlUseTeleport(1);
- dwAutoSearchTick = 0;
- }
- else
- {
- // Lock map
- utlSetAutoSearchMvp(false);
- }
- }
- if(bAutoSa && GetTickCount() > dwAutoSaTick)
- {
- int nIndex = utlFindSkillByAlias(_T("随机技能"));
- if(nIndex != -1 && you.wSp >= 50)
- {
- sendUseSkill(skills[nIndex].wLevel, (unsigned short)skills[nIndex].dwId, dwAccountId);
- dwAutoSaTick = GetTickCount() + 500;
- }
- else
- {
- ufAutoSaClassChange(0);
- }
- }
- return(0);
- }
- int processShortkey()
- {
- EnterCriticalSection(&csShortcutFuncs);
- if(curFunc != NULL)
- {
- curFunc(curFuncPara);
- curFunc = NULL;
- curFuncPara = 0;
- }
- LeaveCriticalSection(&csShortcutFuncs);
- return(0);
- }
- int LaunchRoProgram()
- {
- int nRet = -1;
- CString strTemp, strRoFile, strRoPath, strError, strRoaFile, strRoaInject, strDInput, strDInputFake;
- CString strRoExec, strRoaExec;
- int nIndex;
- int nClientType = eUnknown;
- strTemp = option.strLauncher;
- do
- {
- // Get EXE Name
- nIndex = strTemp.ReverseFind(_T('\'));
- if(-1 == nIndex)
- {
- strError = "客户端启动程序定义错误,请检查并重新定义!";
- nRet = -2;
- break;
- }
- strRoFile = strTemp.Right(strTemp.GetLength() - nIndex -1);
- strRoPath = strTemp.Left(nIndex + 1);
- if(strRoFile.CompareNoCase("roclient.exe") == 0)
- {
- nClientType = eRagexe;
- }
- else if(strRoFile.CompareNoCase("sakclient.exe") == 0)
- {
- nClientType = eSakexe;
- }
- else if(strRoFile.CompareNoCase("sakexe.exe") == 0 || strRoFile.CompareNoCase("ragexe.exe") == 0)
- {
- nClientType = eSfExe;
- }
- if(nClientType == eUnknown)
- {
- strError = "未知RO客户端版本,请去论坛发布所使用的SF及客户端类型!";
- nRet = -3;
- break;
- }
- // COPY INJECT
- strRoaInject = strRoPath + "ROAInject.dll";
- if(0 == ::CopyFile("ROAInject.dll", strRoaInject, false))
- {
- strError = "无法复制ROAInject.dll,请检查客户端目录后重新启动ROA!";
- nRet = -4;
- break;
- }
- // Check for dinput.dll
- strDInput = strRoPath + "dinput.dll";
- strDInputFake = strRoPath + "dinput.dl_";
- if(utlGetFileSize(strDInput) > 0)
- {
- strTemp = _T("发现十全大补丸,十全大补丸中的键盘和鼠标功能有可能会使使用ROA的客户端无法正常运行,是否要禁止?");
- utlLogout(strTemp, eLogError, false);
- if(IDYES == AfxMessageBox(strTemp, MB_ICONQUESTION | MB_YESNO))
- {
- ::CopyFile(strDInput, strDInputFake, false);
- DeleteFile(strDInput);
- }
- }
- // COPY RAGEXE
- switch(nClientType)
- {
- case eRagexe:
- strRoExec = strRoPath + "ragexe.exe";
- strRoaFile = "ROARagexe.exe";
- break;
- case eSakexe:
- strRoExec = strRoPath + "sakexe.exe";
- strRoaFile = "ROASakexe.exe";
- break;
- case eSfExe:
- strRoExec = strRoPath + strRoFile;
- strRoaFile = "ROA" + strRoFile;
- break;
- default:
- ASSERT(false);
- }
- strRoaExec = strRoPath + strRoaFile;
- if(utlGetFileSize(strRoExec) > 200000)
- {
- if(0 == ::CopyFile(strRoExec, strRoaExec, false))
- {
- strError.Format(_T("无法复制%s,请检查客户端目录后重新启动ROA!"), strRoaExec);
- nRet = -6;
- break;
- }
- }
- // COPY LOADER
- if(0 == ::CopyFile("ROALoader.exe", strRoExec, false))
- {
- strError.Format(_T("无法复制%s,请检查客户端目录后重新启动ROA!"), strRoExec);
- nRet = -8;
- break;
- }
- // WRITE REGISTRY
- {
- HKEY hKey;
- long lRet = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Gravity Soft", &hKey);
- if(lRet == ERROR_SUCCESS && hKey != 0)
- {
- lRet = RegSetValue(hKey, "LaunchTarget", REG_SZ, (LPCTSTR)strRoaFile, strRoaFile.GetLength());
- strTemp.Format("%d", nClientType);
- lRet |= RegSetValue(hKey, "LaunchType", REG_SZ, (LPCTSTR)strTemp, strTemp.GetLength());
- lRet |= RegSetValue(hKey, "LaunchParam", REG_SZ, (LPCTSTR)option.strLaunchParam, option.strLaunchParam.GetLength());
- RegCloseKey(hKey);
- strcpy(cSendKey, strRoaFile);
- if(lRet != ERROR_SUCCESS)
- {
- strError = "无法写入注册表,请重新启动ROA!";
- nRet = -9;
- break;
- }
- }
- else
- {
- strError = "无法打开注册表,请检查后重新启动ROA!";
- nRet = -10;
- break;
- }
- }
- // Launch process
- {
- STARTUPINFO si = {sizeof(STARTUPINFO)};
- PROCESS_INFORMATION pi;
- CreateProcess(NULL, (LPTSTR)(LPCTSTR)option.strLauncher, NULL, NULL, true, CREATE_DEFAULT_ERROR_MODE,
- NULL, strRoPath, &si, &pi);
- nRet = 0;
- }
- }while(0);
- if(nRet != 0)
- {
- strTemp = strError;
- strError.Format(_T("%s(ERROR=%d)"), strTemp, nRet);
- AfxMessageBox(strError, MB_ICONSTOP | MB_OK);
- utlLogout(strError, eLogError, false);
- }
- return(nRet);
- }
- int parseRecvPacket(char *buf, int len)
- {
- static char recvbuf[MAX_BUFFER_LEN*3];
- static int recvbuflen = 0;
- memcpy(recvbuf+recvbuflen, buf, len);
- recvbuflen += len;
- while(recvbuflen > 0)
- {
- int ret = parseRecvData(recvbuf, recvbuflen);
- if(ret == -1)
- {
- recvbuflen = 0;
- break;
- }else
- if(ret > recvbuflen)
- {
- break;
- }else
- {
- memcpy(recvbuf, recvbuf+ret, recvbuflen-ret);
- recvbuflen -= ret;
- }
- }
- return(0);
- }
- int parseInfoPacket(char *buf, int len)
- {
- WORD port;
- port = buf[0]*256 + buf[0];
- if(port != 2350)
- {
- switch(nConnState)
- {
- case 1:
- memcpy(serverip[0], buf, 6);
- serverip[1][0] = 0;
- serverip[2][0] = 0;
- break;
- case 2:
- memcpy(serverip[1], buf, 6);
- serverip[2][0] = 0;
- break;
- case 4:
- memcpy(serverip[2], buf, 6);
- break;
- }
- }
- return(0);
- }
- int parseSendPacket(char *buf, int len)
- {
- parseSendData(buf, len, false);
- return(0);
- }
- int connectToInject()
- {
- int nFuncRet = -1, nRet;
- CString strError;
- fd_set readfds;
- timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 10;
- #ifdef _DEBUG
- DWORD timereconnect = GetTickCount();
- #endif
- do
- {
- sockServer.Close();
- if(!sockServer.Create(ROA_PORT, SOCK_STREAM, "127.0.0.1"))
- {
- strError.Format("Failed to create socket on port %d!", ROA_PORT);
- utlLogout(strError, eLogError, false);
- ::MessageBox(AfxGetMainWnd()->m_hWnd, strError, "ROA ERROR", MB_OK | MB_ICONSTOP);
- break;
- }
- if(!sockServer.Listen(5))
- {
- strError.Format("Failed to listen!");
- utlLogout(strError, eLogError, false);
- ::MessageBox(AfxGetMainWnd()->m_hWnd, strError, "ROA ERROR", MB_OK | MB_ICONSTOP);
- sockServer.Close();
- break;
- }
- sockInject.Close();
- do
- {
- if(1 == nThreadTerm)
- {
- nRet = SOCKET_ERROR; // Force to quit
- break;
- }
- readfds.fd_count = 1;
- readfds.fd_array[0] = sockServer.m_hSocket;
- Sleep(200);
- nRet = select(0, &readfds, 0, 0, &tv);
- }while(nRet == 0);
- if(nRet == SOCKET_ERROR)
- break;
- if(sockServer.Accept(sockInject))
- nFuncRet = 0;
- }while(0);
- #ifdef _DEBUG
- TRACE("PROC_RECONNECT: %dn", GetTickCount() - timereconnect);
- #endif
- return(nFuncRet);
- }
- void loadKeyboardHook()
- {
- HOOKPROC keybdproc;
- hInstDll = LoadLibrary((LPCTSTR) "ROATools.dll");
- keybdproc = (HOOKPROC)GetProcAddress(hInstDll, "KeyboardProc");
- if(keybdproc != NULL && hInstDll != NULL)
- hHook = SetWindowsHookEx(WH_KEYBOARD, keybdproc, hInstDll,0);
- else
- hHook = NULL;
- return;
- }
- UINT _workingThread(LPVOID lpPara)
- {
- CString strError;
- CString strTemp;
- DWORD dwSync = GetTickCount();
- DWORD dwKeepAlive = 0; //force to connect first time
- DWORD dwCheckTime = 0;
- char sockbuffer[MAX_BUFFER_LEN];
- static char buffer[MAX_BUFFER_LEN*3];
- static int buflen = 0;
- int nBytesRecv;
- DWORD dwSendWelcome = 0;
- CString strFile, strPath;
- // Receive
- fd_set readfds;
- timeval tv;
- // Load Keyboard Hook
- loadKeyboardHook();
- // Init Server Ip
- memset(serverip, 0, 6*3);
- while(true)
- {
- // Check for terminate
- if(1 == nThreadTerm)
- {
- break;
- }
- // Keep alive
- if(GetTickCount() - dwKeepAlive > 12000)
- {
- if(0 == connectToInject())
- {
- bConnected = true;
- MessageBeep(MB_OK);
- dwKeepAlive = GetTickCount();
- }
- else
- {
- bConnected = false;
- strError.Format("Failed to connect to RO Client!");
- utlLogout(strError, eLogError, false);
- ::MessageBox(AfxGetMainWnd()->m_hWnd, strError, "ROA ERROR", MB_OK | MB_ICONSTOP);
- break;
- }
- }
- // Sync
- if(GetTickCount() - dwSync > 5000)
- {
- sendSyncInject();
- dwSync = GetTickCount();
- }
- // Select
- while(true)
- {
- tv.tv_sec = 0;
- tv.tv_usec = 1000;
- readfds.fd_count = 1;
- readfds.fd_array[0] = sockInject.m_hSocket;
- if(0 != select(0, &readfds, 0, 0, &tv))
- break;
- // ShortKey
- processShortkey();
- Sleep(200);
- }
- // Process packets
- TRACE("PROC_PRE-RECVn");
- nBytesRecv = sockInject.Receive(sockbuffer, MAX_BUFFER_LEN);
- TRACE("PROC_RECV: %dn", nBytesRecv);
- if(nBytesRecv <= 0)
- {
- int err = sockInject.GetLastError();
- if(err != 10053)
- {
- strTemp.Format("Receive error: code:%d", err);
- utlLogout(strTemp, eLogError, false);
- break;
- }
- dwKeepAlive = 0; // force to reconnect
- continue;
- }
- memcpy(buffer + buflen, sockbuffer, nBytesRecv);
- buflen += nBytesRecv;
- while(buflen >= 3)
- {
- char cPackType = *buffer;
- int nPackLen = *((WORD*)(buffer+1));
- int nParsed = 0;
- if(cPackType == 'K')
- {
- // KEEP ALIVE
- nParsed = 3;
- }
- else
- {
- if((cPackType != 'R' && cPackType != 'S' && cPackType != 'I') || nPackLen > MAX_BUFFER_LEN)
- {
- // Found Illegle Package, RESET
- buflen = 0;
- break;
- }
- if(buflen < nPackLen + 3)
- {
- // Incompleted packet
- strTemp.Format("(%d/%d)", nPackLen + 3, buflen);
- strTemp += utlPrintHex(buffer, buflen);
- utlLogout(strTemp, eLogDebug, false);
- utlLogout("Found incompleted packet, receive next package!", eLogError, false);
- break;
- }
- if(cPackType == 'S')
- {
- // SEND
- strTemp.Format(_T(">>>(%d) %s"), nPackLen, utlPrintHex(buffer+3, nPackLen));
- utlLogout(strTemp, eLogDebug, false);
- parseSendPacket(buffer+3, nPackLen);
- nParsed = nPackLen + 3;
- }
- else
- {
- if(cPackType == 'R')
- {
- // RECEIVE
- strTemp.Format(_T("<<<(%d) %s"), nPackLen, utlPrintHex(buffer+3, nPackLen));
- utlLogout(strTemp, eLogDebug, false);
- parseRecvPacket(buffer+3, nPackLen);
- nParsed = nPackLen + 3;
- }
- else
- {
- // INFO
- parseInfoPacket(buffer+3, nPackLen);
- nParsed = nPackLen + 3;
- }
- }
- }
- // Shift buffer
- memcpy(buffer, buffer+nParsed, buflen-nParsed);
- buflen -= nParsed;
- }
- processShortkey();
- dwKeepAlive = GetTickCount();
- if(nConnState < 5)
- {
- Sleep(200);
- continue;
- }
- // Do Ai
- if(!bWelcomeSent)
- {
- if(dwSendWelcome == 0)
- {
- dwSendWelcome = GetTickCount() + option.nWelcomeDelay;
- }
- else
- {
- if(GetTickCount() >= dwSendWelcome)
- {
- utlLoadBossInfo();
- sendWelcomeMessage();
- }
- }
- }
- // Process Mode Normal
- if(mode == eModeNormal)
- {
- processModeNormal();
- }
- if(mode == eModeMvp)
- {
- processModeMvp();
- }
- // Process for important items
- if(option.bAutoPickup/* && option.bMovePickup*/)
- {
- for(int i=0; i<items.GetSize(); i++)
- {
- if(items[i].nPickupFailed < 500)
- {
- if(utlDistanceFrom(items[i].pntPos, you.pntTo) <= option.nPickupDistance || utlDistanceFrom(items[i].pntPos, you.pntPos) <= option.nPickupDistance)
- {
- sendTake(items[i].dwId);
- }
- }
- }
- }
- // Process for miscs
- if(GetTickCount() - dwCheckTime > 1000)
- {
- for(int i=0; i<players.GetSize(); i++)
- {
- if(strcmp(players[i].cName, _T("Unknown")) == 0)
- {
- strcpy(players[i].cName, _T("Unknown*"));
- sendGetPlayerInfo(players[i].dwId);
- }
- }
- if(option.bBossInfo)
- utlPopupBossWarning();
- dwCheckTime = GetTickCount();
- }
- Sleep(100);
- }
- bConnected = false;
- sockInject.Close();
- sockServer.Close();
- if(hHook != NULL)
- UnhookWindowsHookEx(hHook);
- AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
- return(0);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CROAApp
- BEGIN_MESSAGE_MAP(CROAApp, CWinApp)
- //{{AFX_MSG_MAP(CROAApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CROAApp construction
- CROAApp::CROAApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CROAApp object
- /////////////////////////////////////////////////////////////////////////////
- // CROAApp initialization
- BOOL CROAApp::InitInstance()
- {
- AfxEnableControlContainer();
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- // Check for WinSock dll and version
- WORD wVersionRequested;
- WSADATA wsaData;
- int err;
- srand( (unsigned)time( NULL ) );
- wVersionRequested = MAKEWORD( 2, 2 );
- err = WSAStartup( wVersionRequested, &wsaData );
- if ( err != 0 )
- {
- ::MessageBox(0, "WinSock DLL could not be found!", "ROA ERROR", MB_OK | MB_ICONSTOP);
- return(-1);
- }
- if ( LOBYTE( wsaData.wVersion ) != 2 ||
- HIBYTE( wsaData.wVersion ) != 2 )
- {
- WSACleanup( );
- ::MessageBox(0, "WinSock DLL version error!", "ROA ERROR", MB_OK | MB_ICONSTOP);
- return(-1);
- }
- if(!fLog.Open("Packets.log", CFile::modeWrite | CFile::modeCreate | CFile::shareDenyNone))
- {
- WSACleanup( );
- ::MessageBox(0, "Failed to create log file!", "ROA ERROR", MB_OK | MB_ICONSTOP);
- return(-1);
- }
- pWorkingThread = NULL;
- bConnected = false;
- memset(cSendKey, 0, sizeof(cSendKey));
- srand( (unsigned) time(NULL) );
- // The one and only window has been initialized, so show and update it.
- InitializeCriticalSection(&csShortcutFuncs);
- // Change the registry key under which our settings are stored.
- // TODO: You should modify this string to be something appropriate
- // such as the name of your company or organization.
- SetRegistryKey(_T("Local AppWizard-Generated Applications"));
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- utlLoadOption(option);
- CDlgOption dlgOption(false);
- dlgOption.m_option = option;
- bIsModal = true;
- if(dlgOption.DoModal() != IDOK)
- {
- return(0);
- }
- bIsModal = false;
- option = dlgOption.m_option;
- utlSaveOption(option);
- utlParseHpSpItems();
- if(LaunchRoProgram() < 0)
- return(0);
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
- CSingleDocTemplate* pDocTemplate;
- pDocTemplate = new CSingleDocTemplate(
- IDR_MAINFRAME,
- RUNTIME_CLASS(CROADoc),
- RUNTIME_CLASS(CMainFrame), // main SDI frame window
- RUNTIME_CLASS(CROAView));
- AddDocTemplate(pDocTemplate);
- // Parse command line for standard shell commands, DDE, file open
- CCommandLineInfo cmdInfo;
- ParseCommandLine(cmdInfo);
- // Dispatch commands specified on the command line
- if (!ProcessShellCommand(cmdInfo))
- return FALSE;
- m_pMainWnd->ShowWindow(SW_SHOWMINIMIZED);
- m_pMainWnd->UpdateWindow();
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- // No message handlers
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- // App command to run the dialog
- void CROAApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- bIsModal = true;
- aboutDlg.DoModal();
- bIsModal = false;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CROAApp message handlers
- int CROAApp::Start()
- {
- nConnState = 1;
- dwAccountId = 0;
- nCharSelected = -1;
- dwCharId = 0;
- dwSessionId = 0;
- mode = eModeNormal;
- bWelcomeSent = false;
- bProfileLoaded = false;
- curFunc = NULL;
- curFuncPara = 0;
- bFlyUsed = false;
- bAutoSearch = false;
- strAutoSearchMap.Empty();
- bAutoSa = false;
- dwAutoSearchTick = 0;
- dwAttackTick = 0;
- dwUseItemTick = 0;
- bAiEnabled = false;
- pWorkingThread = NULL;
- nThreadTerm = 0;
- pWorkingThread = AfxBeginThread(_workingThread, NULL, THREAD_PRIORITY_ABOVE_NORMAL);
- if( pWorkingThread == NULL )
- return( false );
- return(true);
- }
- int CROAApp::ExitInstance()
- {
- // TODO: Add your specialized code here and/or call the base class
- if(hInstDll != NULL)
- ::FreeLibrary(hInstDll);
- return CWinApp::ExitInstance();
- }
- void ufDummy(DWORD dwPara)
- {
- return;
- }
- void ufShowStatus(DWORD dwPara)
- {
- CString strOutput;
- strOutput.Format(_T("------------------------------设置列表---------------------------------"));
- injectMessage(strOutput);
- strOutput.Format(_T("所有AI[%s]"), ((bAiEnabled)?_T("打开"):_T("关闭")));
- injectMessage(strOutput);
- strOutput.Format(_T("自动攻击[%s]"), (settingmvp.bAttack?_T("打开"):_T("关闭")));
- injectMessage(strOutput);
- strOutput.Format(_T("被围攻时自动使用技能[%s]"), (settingmvp.bAttack2?_T("打开"):_T("关闭")));
- injectMessage(strOutput);
- strOutput.Format(_T("使用队聊共享信息[%s]"), (option.bUsePartyChat?_T("打开"):_T("关闭")));
- injectMessage(strOutput);
- strOutput.Format(_T("自动捡物[%s]"), (option.bAutoPickup?_T("打开"):_T("关闭")));
- injectMessage(strOutput);
- if(option.bAutoPickup)
- {
- strOutput.Format(_T("移动捡物[%s]"), (option.bMovePickup?_T("打开"):_T("关闭")));
- injectMessage(strOutput);
- }
- // strOutput.Format(_T("攻击延迟设置为%2.2f秒"), (float)dwDelay[nDelay] / 1000);
- // injectMessage(strOutput);
- }
- void ufAutoAttackMvp(DWORD dwPara)
- {
- settingmvp.bAttack = !settingmvp.bAttack;
- CString strOutput;
- strOutput.Format(_T("自动攻击[%s]"), (settingmvp.bAttack?_T("打开"):_T("关闭")));
- injectAdminMessage(strOutput);
- /* if(monsters.GetSize() > 0)
- {
- injectAdminMessage(_T("抓宠"));
- sendUseSkill(1, 297, monsters[0].dwId);
- for(int i=0; i<5; i++)
- {
- char buffer[6];
- *(WORD*)(buffer) = 0x019F;
- *(DWORD*)(buffer+2) = monsters[0].dwId;
- parseSendData(buffer, 6, true);
- }
- }*/
- }
- void ufAutoSearchMvp(DWORD dwPara)
- {
- utlSetAutoSearchMvp(!bAutoSearch);
- }
- void ufUseSkillWhen(DWORD dwPara)
- {
- settingmvp.bRegionAtk = !settingmvp.bRegionAtk;
- CString strOutput;
- strOutput.Format(_T("被围攻时自动使用技能[%s]"), (settingmvp.bRegionAtk?_T("打开"):_T("关闭")));
- injectAdminMessage(strOutput);
- }
- void ufUseSkillOnMvp(DWORD dwPara)
- {
- int nMvp = -1;
- int nIndex;
- if(mode == eModeMvp)
- {
- nMvp = monsters.FindId(dwMvpId);
- if(nMvp != -1)
- {
- nIndex = utlFindSkillByAlias(_T("光之障壁"));
- if(nIndex != -1)
- {
- sendUseSkillOnLoc(skills[nIndex].wLevel, (WORD)skills[nIndex].dwId, monsters[nMvp].pntTo);
- }
- }
- }
- }
- void ufTeleport(DWORD dwPara)
- {
- utlUseTeleport(1);
- }
- void ufHome(DWORD dwPara)
- {
- int nIndex;
- CString strSavePoint;
- nIndex = settingcmn.strSavePoint.Find(_T(" - "));
- if(nIndex != -1)
- {
- strSavePoint = settingcmn.strSavePoint.Left(nIndex);
- strSavePoint += _T(".gat");
- sendTeleport(strSavePoint);
- }
- else
- {
- injectAdminMessage(_T("无法使用技能[回保存地点]"));
- }
- }
- void ufBossList(DWORD dwPara)
- {
- utlSortBossInfo();
- CTime tm=CTime::GetCurrentTime();
- CString strTemp;
- strTemp.Format(_T("------------------------------BOSS列表---------------------------------"));
- injectMessage(strTemp);
- for(int i=0; i<bossinfo.GetSize(); i++)
- {
- CTime tmNow = tm - CTimeSpan( 0, 1, 0, 0 ); // 1 hour exactly
- CString strTemp;
- CTimeSpan timespan = bossinfo[i].tmBossTime - tmNow;
- strTemp.Format(_T("%30s %02d/%02d %02d:%02d:%02d %02d分%02d秒"), bossinfo[i].strBossName,
- bossinfo[i].tmBossTime.GetMonth(),
- bossinfo[i].tmBossTime.GetDay(),
- bossinfo[i].tmBossTime.GetHour(),
- bossinfo[i].tmBossTime.GetMinute(),
- bossinfo[i].tmBossTime.GetSecond(),
- timespan.GetTotalSeconds() > 0?timespan.GetTotalSeconds() / 60:0,
- timespan.GetTotalSeconds() > 0?timespan.GetTotalSeconds() % 60:0);
- sendChatParty(strTemp);
- Sleep(50);
- }
- strTemp.Format(_T("-----------------------------------------------------------------------"));
- sendChatParty(strTemp);
- strTemp.Format(_T("%30s %02d/%02d %02d:%02d:%02d"), _T(" 现在时间"),
- tm.GetMonth(),
- tm.GetDay(),
- tm.GetHour(),
- tm.GetMinute(),
- tm.GetSecond());
- sendChatParty(strTemp);
- }
- void ufPartyChat(DWORD dwPara)
- {
- option.bUsePartyChat = !option.bUsePartyChat;
- CString strOutput;
- strOutput.Format(_T("使用队聊共享信息%s"), (option.bUsePartyChat?_T("打开"):_T("关闭")));
- injectAdminMessage(strOutput);
- }
- void ufTakeItem(DWORD dwPara)
- {
- option.bAutoPickup = !option.bAutoPickup;
- CString strOutput;
- strOutput.Format(_T("自动捡物%s"), (option.bAutoPickup?_T("打开"):_T("关闭")));
- injectAdminMessage(strOutput);
- }
- void ufSpeedUp(DWORD dwPara)
- {
- CString strOutput;
- if(option.nAttackPerSecond < 10)
- {
- option.nAttackPerSecond++;
- }
- strOutput.Format(_T("攻击速度倍率设为 %d 倍"), option.nAttackPerSecond);
- injectAdminMessage(strOutput);
- }
- void ufSpeedDown(DWORD dwPara)
- {
- CString strOutput;
- if(option.nAttackPerSecond > 1)
- {
- option.nAttackPerSecond--;
- }
- strOutput.Format(_T("攻击速度倍率设为 %d 倍"), option.nAttackPerSecond);
- injectAdminMessage(strOutput);
- }
- #define DEFINE_FUNC(funcname, skillname)
- void funcname(DWORD dwPara){
- int nIndex = utlFindSkillByAlias(_T(skillname));
- if(nIndex != -1 || skills[nIndex].wLevel > 0)
- sendUseSkill(skills[nIndex].wLevel, (unsigned short)skills[nIndex].dwId, dwAccountId);
- else
- injectAdminMessage(_T("无法使用技能[#skillname]"));}
- DEFINE_FUNC(ufRuwach, "光猎");
- DEFINE_FUNC(ufAngelus, "天使之障壁");
- DEFINE_FUNC(ufMagnificat, "圣母之颂歌");
- DEFINE_FUNC(ufGloria, "幸运之颂歌");
- DEFINE_FUNC(ufEndure, "霸体");
- DEFINE_FUNC(ufLoud, "大声呐喊");
- DEFINE_FUNC(ufMaximize, "武器值最大化");
- DEFINE_FUNC(ufOverthrust, "凶砍");
- DEFINE_FUNC(ufAdrenaline, "速度激发");
- DEFINE_FUNC(ufWeaponperfect, "无视体型攻击");
- DEFINE_FUNC(ufSight, "火狩");
- DEFINE_FUNC(ufConcentration, "心神凝聚");
- DEFINE_FUNC(ufEnergyCoat, "能量外套");
- DEFINE_FUNC(ufAppleIdun, "伊登的苹果");
- DEFINE_FUNC(ufAssassinCross, "刺客的黄昏");
- DEFINE_FUNC(ufFrostJoke, "冷笑话");
- DEFINE_FUNC(ufDissonance, "不谐和音");
- DEFINE_FUNC(ufUglyDance, "丑陋之舞");
- DEFINE_FUNC(ufScream, "惊声尖叫");
- void ufShowMonsters(DWORD dwPara)
- {
- CString strTemp;
- strTemp.Format(_T("------------------------------怪物列表---------------------------------"));
- injectMessage(strTemp);
- for(int i=0; i<monsters.GetSize(); i++)
- {
- strTemp.Format(_T(" [%02d] %08X %s"),
- i,
- monsters[i].dwId,
- monsters[i].cName);
- injectMessage(strTemp);
- Sleep(10);
- }
- return;
- }
- void ufShowPlayers(DWORD dwPara)
- {
- CString strTemp;
- strTemp.Format(_T("------------------------------人物列表---------------------------------"));
- injectMessage(strTemp);
- for(int i=0; i<players.GetSize(); i++)
- {
- strTemp.Format(_T(" [%02d] %08X %8s %24s %24s"),
- i,
- players[i].dwId,
- mapJob.FindValue(players[i].wType),
- players[i].cName,
- players[i].cGuild);
- injectMessage(strTemp);
- Sleep(50);
- }
- return;
- }
- void ufShowCarts(DWORD dwPara)
- {
- CString strTemp;
- INVENTORY inv;
- strTemp.Format(_T("------------------------------手推车内物品列表---------------------------------"));
- injectMessage(strTemp);
- for(int i=0; i<cart.GetSize(); i++)
- {
- inv = cart[i];
- if(inv.wEquipType > 0)
- {
- strTemp.Format(_T(" [%2d] %-20s | 鉴定: %s | 装备: %s"),
- inv.dwIndex, utlGetInventoryName(&inv),
- (inv.bIdentified?_T("是"):_T("否")),
- (inv.wEquipped?mapEquipType.FindValue(inv.wEquipType):_T("否")));
- }
- else
- {
- strTemp.Format(_T(" [%2d] %-20s | 数量: %d"),
- inv.dwIndex, utlGetInventoryName(&inv),
- inv.wAmount);
- }
- injectMessage(strTemp);
- Sleep(50);
- }
- }
- void ufShowInventory(DWORD dwPara)
- {
- CString strTemp;
- INVENTORY inv;
- strTemp.Format(_T("------------------------------物品列表---------------------------------"));
- injectMessage(strTemp);
- for(int i=0; i<inventory.GetSize(); i++)
- {
- inv = inventory[i];
- if(inv.wEquipType > 0)
- {
- strTemp.Format(_T(" [%2d] %-20s | 鉴定: %s | 装备: %s"),
- inv.dwIndex, utlGetInventoryName(&inv),
- (inv.bIdentified?_T("是"):_T("否")),
- (inv.wEquipped?mapEquipType.FindValue(inv.wEquipType):_T("否")));
- }
- else
- {
- strTemp.Format(_T(" [%2d] %-20s | 数量: %d"),
- inv.dwIndex, utlGetInventoryName(&inv),
- inv.wAmount);
- }
- injectMessage(strTemp);
- Sleep(50);
- }
- }
- void ufShowSkills(DWORD dwPara)
- {
- }
- void ufShowEmotion(DWORD dwPara)
- {
- int nIndex = -1;
- for(int i=0; i<EMNUM; i++)
- {
- if(EMOTIONDEF[i].CompareNoCase(emotions[dwPara]) == 0)
- {
- nIndex = i;
- break;
- }
- }
- if(nIndex != -1)
- {
- sendEmotion(nIndex);
- }
- }
- void ufAutoSaClassChange(DWORD dwPara)
- {
- CString strOutput;
- BOOL bStatusOld;
- switch(dwPara)
- {
- case 0:
- // OFF
- bAutoSa = false;
- break;
- case 1:
- // ON
- bAutoSa = true;
- break;
- case 2:
- bAutoSa = !bAutoSa;
- break;
- default:
- ASSERT(false);
- }
- if(bStatusOld == bAutoSa)
- return;
- if(bAutoSa)
- {
- dwAutoSaTick = GetTickCount();
- }
- else
- {
- dwAutoSaTick = 0;
- }
- strOutput.Format(_T("自动贤者 [%s]"), (bAutoSa?_T("打开"):_T("关闭")));
- injectAdminMessage(strOutput);
- return;
- }
- void ufPopupRoaWindow(DWORD dwPara)
- {
- CWnd *pWnd = AfxGetMainWnd();
- HWND hWnd = FindWindow(NULL, "仙境传说");
- if(bIsModal)
- {
- return;
- }
- if(::IsWindow(pWnd->m_hWnd) && ::IsWindow(hWnd))
- {
- ::ShowWindow(hWnd, SW_SHOWMINIMIZED);
- pWnd->ShowWindow(SW_MINIMIZE);
- pWnd->ShowWindow(SW_RESTORE);
- }
- return;
- }
- void ufShowServerIp(DWORD dwPara)
- {
- CString strServerIp;
- strServerIp.Format(_T("------------------------------服务器列表---------------------------------"));
- injectMessage(strServerIp);
- if(0 != serverip[0][0])
- {
- strServerIp.Format(_T("游戏服务器: %d.%d.%d.%d(%d)"),
- serverip[0][2],
- serverip[0][3],
- serverip[0][4],
- serverip[0][5],
- serverip[0][0]*256 + serverip[0][1]);
- injectMessage(strServerIp);
- }
- if(0 != serverip[1][0])
- {
- strServerIp.Format(_T("人物服务器: %d.%d.%d.%d(%d)"),
- serverip[1][2],
- serverip[1][3],
- serverip[1][4],
- serverip[1][5],
- serverip[1][0]*256 + serverip[1][1]);
- injectMessage(strServerIp);
- }
- if(0 != serverip[2][0])
- {
- strServerIp.Format(_T("地图服务器: %d.%d.%d.%d(%d) [%s(%s)]"),
- serverip[2][2],
- serverip[2][3],
- serverip[2][4],
- serverip[2][5],
- serverip[2][0]*256 + serverip[2][1],
- field.m_strAlias,
- field.m_strFieldname);
- injectMessage(strServerIp);
- }
- return;
- }