DWORD __stdcall searchthread(PVOID pData) { lockit lk(bzsrchhandle); if (CSidlScreenWnd *ptr = (CSidlScreenWnd *)pBazaarSearchWnd->GetChildItem("BZR_QueryButton")) { ULONGLONG startwait = MQGetTickCount64(); startwait += 5000; while (ptr->Enabled == 0) { Sleep(100); if (startwait < MQGetTickCount64()) { MacroError("timed out in /bzsrch waiting for BZR_QueryButton to enable."); break; } } if (ptr->Enabled) { if (CListWnd *ptr = (CListWnd *)pBazaarSearchWnd->GetChildItem("BZR_ItemList")) { ptr->DeleteAll(); } BzCount = 0; BzDone = 0; SendWndClick2((CXWnd*)ptr, "leftmouseup"); } else { MacroError("woah! hold your horses there bazaarmule... BZR_QueryButton is not enabled, I suggest you check that in your macro before you issue a /bzsrch command."); } } return 0; }
void DoRace(PCHAR szArg) { if (szArg[0] == 0) { MacroError("Bad race name."); return; } int index = -1; CHAR szRace[255] = { 0 }; if (isdigit(szArg[0])) { index = atoi(szArg); if (index == 0) { strcpy_s(szRace, "Any Race"); } else { for (int i = 0; i < sizeof(races) / sizeof(races[0]); i++) { if (races[i].race==index) { strcpy_s(szRace, races[i].name); break; } } } } else { for (int i = 0; i < sizeof(races) / sizeof(races[0]); i++) { if (!_stricmp(szArg, races[i].name)) { strcpy_s(szRace, szArg); break; } } } if (szRace[0] == '\0') { MacroError("Bad race name."); return; } if (!_stricmp(szArg, "any")) { strcpy_s(szRace, "Any Race"); } if (CComboWnd *pCombo = (CComboWnd *)pBazaarSearchWnd->GetChildItem("BZR_RaceSlotCombobox")) { if (CListWnd*pListWnd = (CListWnd*)pCombo->Items) { CXStr Str; CHAR szOut[255] = { 0 }; DWORD itemcnt = pCombo->GetItemCount(); for (DWORD i = 0; i < itemcnt; i++) { pListWnd->GetItemText(&Str, i, 0); GetCXStr(Str.Ptr, szOut, 254); if (szOut[0] != '\0') { if (!_stricmp(szRace, szOut)) { SetComboSelection((CSidlScreenWnd*)pCombo, i); break; } } } } } }
void DoClass(PCHAR szArg) { if (szArg[0] == 0) { MacroError("Bad class name."); return; } int index = -1; CHAR szClass[255] = { 0 }; if (isdigit(szArg[0])) { index = atoi(szArg); if (index == 0) { strcpy_s(szClass, "Any Class"); } else { for (int i = 0; i < sizeof(classes) / sizeof(classes[0]); i++) { if (classes[i].classn==index) { strcpy_s(szClass, classes[i].name); break; } } } } else { for (int i = 0; i < sizeof(classes) / sizeof(classes[0]); i++) { if (!_stricmp(szArg, classes[i].name)) { strcpy_s(szClass, szArg); break; } } } if (szClass[0] == '\0') { MacroError("Bad class name."); return; } if (!_stricmp(szArg, "any")) { strcpy_s(szClass, "Any Class"); } if (CComboWnd *pCombo = (CComboWnd *)pBazaarSearchWnd->GetChildItem("BZR_ClassSlotCombobox")) { if (CListWnd*pListWnd = pCombo->pListWnd) { CXStr Str; CHAR szOut[MAX_STRING] = { 0 }; DWORD itemcnt = pCombo->GetItemCount(); for (DWORD i = 0; i < itemcnt; i++) { pListWnd->GetItemText(&Str, i, 0); GetCXStr(Str.Ptr, szOut, MAX_STRING); if (szOut[0] != '\0') { if (!_stricmp(szClass, szOut)) { SetComboSelection(pCombo, i); break; } } } } } }
VOID ClickMouseLoc(PCHAR szMouseLoc, PCHAR szButton) { CHAR szArg1[MAX_STRING] = {0}; CHAR szArg2[MAX_STRING] = {0}; int ClickX; //actual location to click, calculated from ButtonX int ClickY; //actual location to click, calculated from ButtonY // determine mouse location - x and y given if ((szMouseLoc[0]=='+') || (szMouseLoc[0]=='-') || ((szMouseLoc[0]>='0') && (szMouseLoc[0]<='9'))) { // x and y were given so lets convert them and move mouse GetArg(szArg1,szMouseLoc,1); GetArg(szArg2,szMouseLoc,2); ClickX = atoi(szArg1); ClickY = atoi(szArg2); if ((szArg1[0]=='+') || (szArg1[0]=='-') || (szArg2[0]=='+') || (szArg2[0]=='-')) { // relative location was passed so offset from current ClickX += EQADDR_MOUSE->X; ClickY += EQADDR_MOUSE->Y; DebugSpew("Clicking mouse by relative offset"); } else { DebugSpew("Clicking mouse at absolute position"); } MouseButtonUp(ClickX,ClickY,szButton); } else { MacroError("'%s' mouse click is either invalid or should be done using /notify",szMouseLoc); } }
// *************************************************************************** // Function: Return // Description: Our '/return' command // Usage: /return [value] // *************************************************************************** VOID Return(PSPAWNINFO pChar, PCHAR szLine) { bRunNextCommand = TRUE; PMACROSTACK pStack = gMacroStack; if (!gMacroBlock) { MacroError("Cannot return when a macro isn't running."); return; } if (!pStack->pNext) { // Top of stack (ie. returning from Sub Main) EndMacro(pChar,""); return; } if (pStack->LocalVariables) ClearMQ2DataVariables(&pStack->LocalVariables); if (pStack->Parameters) ClearMQ2DataVariables(&pStack->Parameters); strcpy(pStack->pNext->Return,szLine); gMacroBlock = pStack->pNext->Location; gMacroStack = pStack->pNext; free(pStack); DebugSpewNoFile("Return - Returned to %s",gMacroBlock->Line); }
// *************************************************************************** // Function: CommandUntil // Description: Our '/until' command // Usage: /until (<conditions>) // *************************************************************************** VOID CommandUntil(PSPAWNINFO pChar, PCHAR szLine) { CHAR szCond[MAX_STRING] = {0}; CHAR WhileLine[MAX_STRING] = {0}; if (!gMacroBlock) { MacroError("Can only use /until during a macro."); return; } bRunNextCommand = TRUE; if (szLine[0]!='(') { FatalError("Failed to parse /until command. Expected () around conditions."); SyntaxError("Usage: /until (<conditions>)"); return; } PCHAR pEnd=&szLine[1]; DWORD nParens=1; while(1) { if (*pEnd=='(') nParens++; else if (*pEnd==')') { nParens--; if (nParens==0) { pEnd++; if (*pEnd!=0) { FatalError("Failed to parse /until command. Parameters after conditions."); SyntaxError("Usage: /until (<conditions>)"); return; } break; } } else if (*pEnd==0) { FatalError("Failed to parse /until command. Could not find condition to evaluate."); SyntaxError("Usage: /until (<conditions>)"); return; } ++pEnd; } // while strcpy(szCond,szLine); DOUBLE Result=0; if (!Calculate(szCond,Result)) { FatalError("Failed to parse /until condition '%s', non-numeric encountered",szCond); return; } if (Result==0) ContinueDo(pChar, gMacroBlock); }
// *************************************************************************** // Function: CommandDo // Description: Our '/do' command // Usage: /do // *************************************************************************** VOID CommandDo(PSPAWNINFO pChar, PCHAR szLine) { if (!gMacroBlock) { MacroError("Can only use /do during a macro."); return; } bRunNextCommand = TRUE; if (szLine[0]) { FatalError("Failed to parse /do command. Unexpected parameters."); SyntaxError("Usage: /do"); return; } }
// *************************************************************************** // Function: Include // Description: Includes another macro file // Usage: #include <filename> // *************************************************************************** DWORD Include(PCHAR szFile) { CHAR szTemp[MAX_STRING] = {0}; FILE *fMacro = fopen(szFile,"rt"); DWORD LineNumber=0; BOOL InBlockComment = FALSE; PMACROBLOCK pAddedLine = NULL; char *tmp; if (!fMacro) { FatalError("Couldn't open include file: %s",szFile); return 0; } DebugSpewNoFile("Include - Including: %s",szFile); while (!feof(fMacro)) { tmp = fgets(szTemp,MAX_STRING,fMacro); if (!tmp && feof(fMacro)) break; CleanMacroLine(szTemp); LineNumber++; if (!strncmp(szTemp,"|**",3)) { InBlockComment=TRUE; } if (!InBlockComment) { if (NULL == (pAddedLine=AddMacroLine(szTemp))) { MacroError("Unable to add macro line."); fclose(fMacro); gszMacroName[0]=0; gRunning = 0; return 0; } else if (1 != (DWORD)pAddedLine) { pAddedLine->LineNumber = LineNumber; strcpy(pAddedLine->SourceFile, GetFilenameFromFullPath(szFile)); } } else { DebugSpewNoFile("Macro - BlockComment: %s",szTemp); if (!strncmp(&szTemp[strlen(szTemp)-3],"**|",3)) { InBlockComment=FALSE; } } } fclose(fMacro); return 1; }
// *************************************************************************** // Function: CommandEndWhile // Description: Our '/endwhile' command // Usage: /endwhile // *************************************************************************** VOID CommandEndWhile(PSPAWNINFO pChar, PCHAR szLine) { if (!gMacroBlock) { MacroError("Can only use /endwhile during a macro."); return; } bRunNextCommand = TRUE; if (szLine[0]) { FatalError("Failed to parse /endwhile command. Unexpected parameters."); SyntaxError("Usage: /endwhile"); return; } ContinueWhile(pChar, gMacroBlock); }
// *************************************************************************** // Function: CommandContinue // Description: Our '/continue' command // Usage: /continue // *************************************************************************** VOID CommandContinue(PSPAWNINFO pChar, PCHAR szLine) { if (!gMacroBlock) { MacroError("Can only use /continue during a macro."); return; } bRunNextCommand = TRUE; if (szLine[0]) { FatalError("Failed to parse /continue command. Unexpected parameters."); SyntaxError("Usage: /continue"); return; } DoBreak(pChar, gMacroBlock, true); }
// *************************************************************************** // Function: For // Description: Our '/for' command // Usage: /for v# <start> <to|downto> <end> // *************************************************************************** VOID For(PSPAWNINFO pChar, PCHAR szLine) { bRunNextCommand = TRUE; CHAR ArgLoop[MAX_STRING] = {0}; CHAR ArgStart[MAX_STRING] = {0}; CHAR ArgDirection[MAX_STRING] = {0}; CHAR ArgEnd[MAX_STRING] = {0}; GetArg(ArgLoop,szLine,1); GetArg(ArgStart,szLine,2); GetArg(ArgDirection,szLine,3); GetArg(ArgEnd,szLine,4); _strlwr(ArgDirection); PDATAVAR pVar = FindMQ2DataVariable(ArgLoop); if (!pVar) { FatalError("/for loop using invalid variable"); return; } if (pVar->Var.Type!=pIntType) { FatalError("/for loops must use an int variable"); return; } if ((ArgStart[0] == 0) || (ArgDirection[0] == 0) || (ArgEnd[0] == 0) || ((strcmp(ArgDirection,"to")) && (strcmp(ArgDirection,"downto")))) { FatalError("Usage: /for <variable> <start> <to|downto> <end> [step x]"); return; } if (!gMacroBlock) { MacroError("Can only use /for during a macro."); return; } if (!pVar->Var.Type->FromString(pVar->Var.VarPtr,ArgStart)) { FatalError("/for loop could not assign value '%s' to variable",ArgStart); return; } }
void DoCombo(PCHAR szArg, PCHAR key, PCHAR szCombostring) { if (szArg[0] == 0) { MacroError("Bad %s name.", key); return; } DWORD index = -1; CHAR szValue[255] = { 0 }; if (isdigit(szArg[0])) { index = atoi(szArg); index--; } if (!_stricmp(szArg, "any")) { sprintf_s(szValue, "Any %s",key); } else { strcpy_s(szValue, szArg); } if (CComboWnd *pCombo = (CComboWnd *)pBazaarSearchWnd->GetChildItem(szCombostring)) { if (CListWnd*pListWnd = (CListWnd*)pCombo->Items) { CXStr Str; CHAR szOut[255] = { 0 }; DWORD itemcnt = pCombo->GetItemCount(); if (index != -1 && index <= itemcnt) { SetComboSelection((CSidlScreenWnd*)pCombo, index); } else { for (DWORD i = 0; i < itemcnt; i++) { pListWnd->GetItemText(&Str, i, 0); GetCXStr(Str.Ptr, szOut, 254); if (szOut[0] != '\0') { if (!_stricmp(szValue, szOut)) { SetComboSelection((CSidlScreenWnd*)pCombo, i); break; } } } } } } }
/* MQ2DataVars */ VOID Goto(PSPAWNINFO pChar, PCHAR szLine) { CHAR szTemp[MAX_STRING] = {0}; PMACROBLOCK pFromLine = gMacroBlock; bRunNextCommand = TRUE; if (!gMacroBlock) { MacroError("Cannot goto when a macro isn't running."); return; } while (gMacroBlock->pPrev) { gMacroBlock=gMacroBlock->pPrev; if (!strnicmp(gMacroBlock->Line,"Sub ",4)) break; } while (gMacroBlock->pNext) { gMacroBlock=gMacroBlock->pNext; if (!strnicmp(gMacroBlock->Line,"Sub ",4)) { gMacroBlock=pFromLine; FatalError("Couldn't find label %s",szLine); return; } if (!stricmp(szLine,gMacroBlock->Line)) { // DebugSpewNoFile("Goto - went to label %s",szLine); return; } } if (!stricmp(szLine,gMacroBlock->Line)) { // DebugSpewNoFile("Goto - went to label %s",szLine); return; } gMacroBlock=pFromLine; FatalError("Couldn't find label %s",szLine); }
// *************************************************************************** // Function: Break // Description: Our '/break' command // Usage: /break // *************************************************************************** VOID Break(PSPAWNINFO pChar, PCHAR szLine) { if (!gMacroBlock) { MacroError("Can only use /break during a macro."); return; } while (bRunNextCommand = TRUE) { if (!strnicmp(gMacroBlock->Line,"Sub ",4) || (!gMacroBlock->pNext)) { FatalError("/break without matching /for ... /next block"); return; } if (!strnicmp(gMacroBlock->Line,"/next",5)) { break; } gMacroBlock = gMacroBlock->pNext; } }
// *************************************************************************** // Function: EndMacro // Description: Our '/endmacro' command // Usage: /endmacro // *************************************************************************** VOID EndMacro(PSPAWNINFO pChar, PCHAR szLine) { CHAR Buffer[MAX_STRING] = {0}; DWORD i; PMACROBLOCK pPrev; PMACROSTACK pStack; PEVENTQUEUE pEvent; PEVENTLIST pEventL; BOOL bKeepKeys = gKeepKeys; if (szLine[0]!=0) { GetArg(Buffer,szLine,1); szLine = GetNextArg(szLine); if (stricmp(Buffer,"keep")) { SyntaxError("Usage: /endmacro [keep keys]"); return; } while (szLine[0]!=0) { GetArg(Buffer,szLine,1); szLine = GetNextArg(szLine); if (!stricmp(Buffer,"keys")) bKeepKeys = TRUE; } } if (!gMacroBlock) { MacroError("Cannot end a macro when one isn't running."); return; } /////////////// // Code allowing for a routine for "OnExit" while (gMacroBlock->pNext) { gMacroBlock=gMacroBlock->pNext; //DebugSpew("%s",gMacroBlock->Line); if (!stricmp(":OnExit",gMacroBlock->Line)) { if (gReturn) // return to the macro the first time around { gReturn = false; // We don't want to return the 2nd time. return; } else break; } } gReturn = true; // reset for next time // /////////////// #ifdef MQ2_PROFILING // How many performance counters in 1 second? LARGE_INTEGER PerformanceFrequency; QueryPerformanceCounter(&PerformanceFrequency); // Move to first macro line while (gMacroBlock->pPrev) gMacroBlock = gMacroBlock->pPrev; CHAR Filename[MAX_STRING] = {0}; FILE *fMacro = NULL; while (gMacroBlock) { // Is this a different macro file? if (strcmp(Filename, gMacroBlock->SourceFile)) { // Close existing file if (fMacro) { fclose(fMacro); } // Open new profiling log file strcpy(Filename, gMacroBlock->SourceFile); sprintf(Buffer, "%s\\%s.mqp", gszMacroPath, Filename); fMacro = fopen(Buffer, "w"); if (fMacro) { fprintf(fMacro, " Execute | Total | Avg uSec | Line | Macro Source Code\n"); fprintf(fMacro, " Count | uSec | Per 1000 |\n"); fprintf(fMacro, "------------------------------------------------------------------------------------------------------------- \n"); } } // Log execution/profiling information. Output format is: // Execution Count | Microseconds | Line # | Macro Source if (fMacro) { DWORD count = gMacroBlock->ExecutionCount; DWORD total = (DWORD)(gMacroBlock->ExecutionTime * 1000000 / PerformanceFrequency.QuadPart); DWORD avg = 0; if (count > 0) { avg = total * 1000 / count; } fprintf(fMacro, "%8lu | %8lu | %8lu | %4lu | %s\n", count, total, avg, gMacroBlock->LineNumber, gMacroBlock->Line); } // Terminate on last macro line if (gMacroBlock->pNext) { gMacroBlock = gMacroBlock->pNext; } else { break; } } // Close existing file if (fMacro) { fclose(fMacro); } #endif while (gMacroBlock->pNext) gMacroBlock=gMacroBlock->pNext; while (gMacroBlock) { pPrev = gMacroBlock->pPrev; free(gMacroBlock); gMacroBlock = pPrev; } while (gMacroStack) { pStack = gMacroStack->pNext; if (gMacroStack->LocalVariables) ClearMQ2DataVariables(&gMacroStack->LocalVariables); if (gMacroStack->Parameters) ClearMQ2DataVariables(&gMacroStack->Parameters); free(gMacroStack); gMacroStack = pStack; } gMacroSubLookupMap.clear(); while (gEventQueue) { pEvent = gEventQueue->pNext; free(gEventQueue); gEventQueue = pEvent; } while (pEventList) { pEventL = pEventList->pNext; free(pEventList); pEventList = pEventL; } #ifdef USEBLECHEVENTS pEventBlech->Reset(); #endif for (i=0;i<NUM_EVENTS;i++) { gEventFunc[i]=NULL; } gMacroPause = FALSE; gEventChat=0; gFaceAngle=10000.0f; gLookAngle=10000.0f; gDelay = 0; gTurbo = FALSE; pDoorTarget = NULL; #ifdef ISXEQ_LEGACY char ShortName[128]; ShortName[0]=0; _splitpath(gszMacroName,0,0,ShortName,0); IS_ScriptEngineScriptEnds(pExtension,pISInterface,hScriptEngineService,&g_LegacyEngine,ShortName); #endif gszMacroName[0]=0; gRunning = 0; if (!bKeepKeys) { KeyCombo TempCombo; for (i=0;gDiKeyID[i].szName[0];i++) { TempCombo.Data[3]=(unsigned char)gDiKeyID[i].Id; MQ2HandleKeyUp(TempCombo); } } ClearMQ2DataVariables(&pMacroVariables); DebugSpewNoFile("EndMacro - Ended"); if (gFilterMacro != FILTERMACRO_NONE && gFilterMacro != FILTERMACRO_MACROENDED) WriteChatColor("The current macro has ended.",USERCOLOR_DEFAULT); }
// *************************************************************************** // Function: Macro // Description: Our '/macro' command // Usage: /macro <filename> // *************************************************************************** VOID Macro(PSPAWNINFO pChar, PCHAR szLine) { bRunNextCommand = TRUE; CHAR szTemp[MAX_STRING] = {0}; CHAR Filename[MAX_STRING] = {0}; PCHAR Params = NULL; PCHAR szNext = NULL; BOOL InBlockComment = FALSE; if (szLine[0] == 0) { SyntaxError("Usage: /macro <filename> [param [param...]]"); return; } if (gMacroBlock) { gReturn = false; EndMacro(pChar,"");//"keep keys vars arrays timers"); gReturn = true; } gMaxTurbo=20; gTurbo=true; GetArg(szTemp,szLine,1); Params = GetNextArg(szLine); strcpy(gszMacroName,szTemp); #ifdef ISXEQ_LEGACY strcpy(Filename,szTemp); FILE *fMacro = fopen(szTemp,"rt"); #else if (!strstr(szTemp,".")) strcat(szTemp,".mac"); sprintf(Filename,"%s\\%s",gszMacroPath, szTemp); FILE *fMacro = fopen(Filename,"rt"); #endif if (!fMacro) { FatalError("Couldn't open macro file: %s",Filename); gszMacroName[0]=0; gRunning = 0; return; } gRunning = GetTickCount(); gEventChat = 0; strcpy(gszMacroName,szTemp); DebugSpew("Macro - Loading macro: %s",Filename); DWORD LineNumber = 0; PMACROBLOCK pAddedLine = NULL; while (!feof(fMacro)) { fgets(szTemp,MAX_STRING,fMacro); CleanMacroLine(szTemp); LineNumber++; if (!strncmp(szTemp,"|**",3)) { InBlockComment=TRUE; } if (!InBlockComment) { if (NULL == (pAddedLine=AddMacroLine(szTemp))) { MacroError("Unable to add macro line."); fclose(fMacro); gszMacroName[0]=0; gRunning = 0; return; } else if (1 != (DWORD)pAddedLine) { pAddedLine->LineNumber = LineNumber; strcpy(pAddedLine->SourceFile, GetFilenameFromFullPath(Filename)); } } else { DebugSpew("Macro - BlockComment: %s",szTemp); if (!strncmp(&szTemp[strlen(szTemp)-3],"**|",3)) { InBlockComment=FALSE; } } } fclose(fMacro); PDEFINE pDef; while (pDefines) { pDef = pDefines->pNext; free(pDefines); pDefines = pDef; } strcpy(szTemp, "Main"); if (Params[0] !=0) { strcat(szTemp, " "); strcat(szTemp, Params); } DebugSpew("Macro - Starting macro with '/call %s'",szTemp); Call(pChar, szTemp); if ((gMacroBlock) && (gMacroBlock->pNext)) gMacroBlock = gMacroBlock->pNext; if (gMacroBlock) gMacroBlock->MacroCmd = 1; if ((!gMacroBlock) || (!gMacroStack)) { gszMacroName[0]=0; gRunning = 0; } #ifdef ISXEQ_LEGACY else { char ShortName[128]; ShortName[0]=0; _splitpath(Filename,0,0,ShortName,0); IS_ScriptEngineScriptBegins(pExtension,pISInterface,hScriptEngineService,&g_LegacyEngine,ShortName); } #endif }
// *************************************************************************** // Function: AddMacroLine // Description: Add a line to the MacroBlock // *************************************************************************** PMACROBLOCK AddMacroLine(PCHAR szLine) { PMACROBLOCK pBlock = NULL; // replace all tabs with spaces if ((szLine[0]==0) || (szLine[0]=='|')) return (PMACROBLOCK)1; PDEFINE pDef = pDefines; if (szLine[0]!='#') while (pDef) { while (strstr(szLine,pDef->szName)) { CHAR szNew[MAX_STRING] = {0}; strncpy(szNew,szLine,strstr(szLine,pDef->szName)-szLine); strcat(szNew,pDef->szReplace); strcat(szNew,strstr(szLine,pDef->szName)+strlen(pDef->szName)); strcpy(szLine,szNew); } pDef = pDef->pNext; } if (szLine[0]=='#') { if (!strnicmp(szLine,"#include ",9)) { CHAR Filename[MAX_STRING] = {0}; szLine+=8; while (szLine[0]==' ') szLine++; if (!strstr(szLine,".")) strcat(szLine,".mac"); sprintf(Filename,"%s\\%s",gszMacroPath, szLine); //DebugSpewNoFile("AddMacroLine - Including file: %s",Filename); return (PMACROBLOCK)Include(Filename); } else if (!strnicmp(szLine,"#turbo",6)) { gTurbo = TRUE; CHAR szArg[MAX_STRING] = {0}; GetArg(szArg,szLine,2); gMaxTurbo = atoi(szArg); if (gMaxTurbo==0) gMaxTurbo=20; else if (gMaxTurbo>40) { MacroError("#turbo %d is too high, setting at 40 (maximum)",gMaxTurbo); gMaxTurbo=40; } } else if (!strnicmp(szLine,"#define ",8)) { CHAR szArg1[MAX_STRING] = {0}; CHAR szArg2[MAX_STRING] = {0}; PDEFINE pDef = (PDEFINE)malloc(sizeof(DEFINE)); GetArg(szArg1,szLine,2); GetArg(szArg2,szLine,3); if ((szArg1[0]!=0) && (szArg2[0]!=0)) { strcpy(pDef->szName,szArg1); strcpy(pDef->szReplace,szArg2); pDef->pNext = pDefines; pDefines = pDef; } else { MacroError("Bad #define: %s",szLine); } } else if (!strnicmp(szLine,"#event ",7)) { CHAR szArg1[MAX_STRING] = {0}; CHAR szArg2[MAX_STRING] = {0}; PEVENTLIST pEvent = (PEVENTLIST)malloc(sizeof(EVENTLIST)); GetArg(szArg1,szLine,2); GetArg(szArg2,szLine,3); if ((szArg1[0]!=0) && (szArg2[0]!=0)) { sprintf(pEvent->szName,"Sub Event_%s",szArg1); strcpy(pEvent->szMatch,szArg2); #ifdef USEBLECHEVENTS pEvent->BlechID=pEventBlech->AddEvent(pEvent->szMatch,EventBlechCallback,pEvent); #endif pEvent->pEventFunc = NULL; pEvent->pNext = pEventList; pEventList = pEvent; } else { MacroError("Bad #event: %s",szLine); } } else if (!strnicmp(szLine,"#chat ",6)) { szLine+=5; while (szLine[0]==' ') szLine++; if (!stricmp(szLine,"say")) gEventChat = gEventChat | CHAT_SAY; if (!stricmp(szLine,"tell")) gEventChat = gEventChat | CHAT_TELL; if (!stricmp(szLine,"ooc")) gEventChat = gEventChat | CHAT_OOC; if (!stricmp(szLine,"shout")) gEventChat = gEventChat | CHAT_SHOUT; if (!stricmp(szLine,"auc")) gEventChat = gEventChat | CHAT_AUC; if (!stricmp(szLine,"guild")) gEventChat = gEventChat | CHAT_GUILD; if (!stricmp(szLine,"group")) gEventChat = gEventChat | CHAT_GROUP; if (!stricmp(szLine,"chat")) gEventChat = gEventChat | CHAT_CHAT; } else if (szLine[1]=='!') { // Like: #!/usr/local/bin/LegacyMQ2 // ignore. } else { MacroError("Unknown # command: %s",szLine); return FALSE; } } pBlock = (PMACROBLOCK)malloc(sizeof(MACROBLOCK)); if (!pBlock) return NULL; //DebugSpewNoFile("AddMacroLine - Adding: %s",szLine); strcpy(pBlock->Line,szLine); pBlock->LineNumber = -1; pBlock->SourceFile[0]=0; pBlock->pNext=NULL; pBlock->pPrev=NULL; if ((!stricmp(szLine,"Sub Event_Chat")) || (!strnicmp(szLine,"Sub Event_Chat(",15))) { gEventFunc[EVENT_CHAT] = pBlock; } else if ((!stricmp(szLine,"Sub Event_Timer")) || (!strnicmp(szLine,"Sub Event_Timer(",16))) { gEventFunc[EVENT_TIMER] = pBlock; } else { PEVENTLIST pEvent = pEventList; while (pEvent) { if (!stricmp(szLine,pEvent->szName)) { pEvent->pEventFunc = pBlock; } else { CHAR szNameP[MAX_STRING] = {0}; sprintf(szNameP,"%s(",pEvent->szName); if (!strnicmp(szLine,szNameP,strlen(szNameP))) { pEvent->pEventFunc = pBlock; } } pEvent = pEvent->pNext; } } if (!gMacroBlock) { gMacroBlock=pBlock; } else { PMACROBLOCK pLoop = gMacroBlock; while (pLoop->pNext) pLoop = pLoop->pNext; pLoop->pNext = pBlock; pBlock->pPrev = pLoop; } return pBlock; }
// *************************************************************************** // Function: Next // Description: Our '/next' command // Usage: /next v# // *************************************************************************** VOID Next(PSPAWNINFO pChar, PCHAR szLine) { bRunNextCommand = TRUE; CHAR szComp[MAX_STRING] = {0}; CHAR ForLine[MAX_STRING] = {0}; CHAR szNext[MAX_STRING] = {0}; PMACROBLOCK pMacroLine = gMacroBlock; LONG StepSize = 1; GetArg(szNext,szLine,1); PDATAVAR pVar = FindMQ2DataVariable(szNext); if (!pVar) { FatalError("/next using invalid variable"); return; } if (pVar->Var.Type!=pIntType) { FatalError("/for loops must use an int variable"); return; } if (!gMacroBlock) { MacroError("Can only use /next during a macro."); return; } sprintf(szComp,"/for %s ",pVar->szName); while (pMacroLine->pPrev) { strcpy(ForLine,pMacroLine->Line); if (!strnicmp(ForLine,"Sub ",4)) { FatalError("/next without matching /for"); return; } if (strnicmp(ForLine,"/for ",5)) { pMacroLine = pMacroLine->pPrev; continue; } if (!strnicmp(ParseMacroParameter(pChar,ForLine),szComp,strlen(szComp))) { if (!gMacroBlock) { // PMP bailed on us, we need to exit... return; } CHAR szTemp[MAX_STRING] = {0}; DWORD VarNum = atoi(szLine+1); LONG Loop; if (strstr(_strlwr(strcpy(szTemp,ForLine)),"step")) { PCHAR pTemp = strstr(szTemp,"step")+4; while ( (pTemp[0]!=0) && (pTemp[0]!=' ') && (pTemp[0]!='\t')) pTemp++; if (pTemp[0]!=0) StepSize = atoi(pTemp); } pVar = FindMQ2DataVariable(szNext); if (!pVar) { FatalError("/next without badly matching /for"); return; } if (strstr(_strlwr(strcpy(szTemp,ForLine)),"downto")) { Loop = atoi(strstr(szTemp,"downto")+7); DebugSpewNoFile("Next - End of loop %d downto %d", pVar->Var.Int, Loop); pVar->Var.Int-=StepSize; if (pVar->Var.Int >= Loop) gMacroBlock = pMacroLine; } else { Loop = atoi(strstr(szTemp,"to")+3); DebugSpewNoFile("Next - End of loop %d to %d", pVar->Var.Int, Loop); pVar->Var.Int+=StepSize; if (pVar->Var.Int <= Loop) gMacroBlock = pMacroLine; } return; } pMacroLine = pMacroLine->pPrev; } FatalError("/next without matching /for"); }
VOID BzSrchMe(PSPAWNINFO pChar, PCHAR szLine) { lockit lk(bzsrchhandle,"BzSrchMe"); BzDone = FALSE; CHAR szArg[MAX_STRING] = { 0 }; CHAR szItem[MAX_STRING] = { 0 }; PCHARINFO pCharInfo = GetCharInfo(); BOOL bArg = TRUE; bool first = true; if (CButtonWnd *pDefaultButton = (CButtonWnd *)pBazaarSearchWnd->GetChildItem("BZR_Default")) { if (pDefaultButton && pDefaultButton->Enabled) { SendWndClick2((CXWnd*)pDefaultButton, "leftmouseup"); } else { MacroError("Whats wrong? BZR_Default wasnt enabled."); } } else { MacroError("Whats wrong? Counldnt find the BZR_Default window."); } if (CListWnd *pList = (CListWnd *)pBazaarSearchWnd->GetChildItem("BZR_ItemList")) { pList->DeleteAll(); } BzCount = 0; while (bArg) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); if (szArg[0] == 0) { bArg = FALSE; } else if (!strcmp(szArg, "class")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoClass(szArg); } else if (!_stricmp(szArg, "race")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoRace(szArg); } else if (!_stricmp(szArg, "stat")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Stat", "BZR_StatSlotCombobox"); } else if (!_stricmp(szArg, "slot")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Slot", "BZR_ItemSlotCombobox"); } else if (!_stricmp(szArg, "type")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Type", "BZR_ItemTypeCombobox"); } else if (!strcmp(szArg, "price")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); if (szArg[0] == 0) { MacroError("Bad price low."); goto error_out; } if (CXWnd *pEdit = (CXWnd *)pBazaarSearchWnd->GetChildItem("BZR_MinPriceInput")) { pEdit->SetWindowTextA(CXStr(szArg)); } GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); if (szArg[0] == 0) { MacroError("Bad price high."); goto error_out; } if (CXWnd *pEdit = (CXWnd *)pBazaarSearchWnd->GetChildItem("BZR_MaxPriceInput")) { pEdit->SetWindowTextA(CXStr(szArg)); } } else if (!_stricmp(szArg, "trader")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Trader", "BZR_PlayersCombobox"); } else if (!_stricmp(szArg, "prestige")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Prestige", "BZR_ItemPrestigeCombobox"); } else if (!_stricmp(szArg, "augment")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Augment", "BZR_ItemAugmentCombobox"); } else { if (first) { first = false; } else { strcat_s(szItem, " "); } strcat_s(szItem, szArg); } } if (CXWnd *pMaxEdit = (CXWnd *)pBazaarSearchWnd->GetChildItem("BZR_MaxResultsPerTraderInput")) { pMaxEdit->SetWindowTextA(CXStr("200")); } else { MacroError("Whats wrong? couldnt find the BZR_MaxResultsPerTraderInput window."); } if (CXWnd *pEdit = (CXWnd *)pBazaarSearchWnd->GetChildItem("BZR_ItemNameInput")) { pEdit->SetWindowTextA(CXStr(szItem)); DWORD nThreadID = 0; CreateThread(NULL, NULL, searchthread, 0, 0, &nThreadID); } else { MacroError("Whats wrong? couldnt find the BZR_ItemNameInput window."); } error_out: return; }
VOID BzSrchMe(PSPAWNINFO pChar, PCHAR szLine) { lockit lk(bzsrchhandle); CHAR szArg[MAX_STRING] = { 0 }; CHAR szItem[MAX_STRING] = { 0 }; PCHARINFO pCharInfo = GetCharInfo(); BOOL bArg = TRUE; bool first = true; if (CButtonWnd *ptr = (CButtonWnd *)pBazaarSearchWnd->GetChildItem("BZR_Default")) { SendWndClick2((CXWnd*)ptr, "leftmouseup"); } while (bArg) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); if (szArg[0] == 0) { bArg = FALSE; } else if (!strcmp(szArg, "class")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoClass(szArg); } else if (!_stricmp(szArg, "race")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoRace(szArg); } else if (!_stricmp(szArg, "stat")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Stat", "BZR_StatSlotCombobox"); } else if (!_stricmp(szArg, "slot")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Slot", "BZR_ItemSlotCombobox"); } else if (!_stricmp(szArg, "type")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Type", "BZR_ItemTypeCombobox"); } else if (!strcmp(szArg, "price")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); if (szArg[0] == 0) { MacroError("Bad price low."); goto error_out; } if (CXWnd *pEdit = (CXWnd *)pBazaarSearchWnd->GetChildItem("BZR_MinPriceInput")) { pEdit->SetWindowTextA(CXStr(szArg)); } GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); if (szArg[0] == 0) { MacroError("Bad price high."); goto error_out; } if (CXWnd *pEdit = (CXWnd *)pBazaarSearchWnd->GetChildItem("BZR_MaxPriceInput")) { pEdit->SetWindowTextA(CXStr(szArg)); } } else if (!_stricmp(szArg, "trader")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Trader", "BZR_PlayersCombobox"); } else if (!_stricmp(szArg, "prestige")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Prestige", "BZR_ItemPrestigeCombobox"); } else if (!_stricmp(szArg, "augment")) { GetArg(szArg, szLine, 1); szLine = GetNextArg(szLine, 1); DoCombo(szArg, "Augment", "BZR_ItemAugmentCombobox"); } else { if (first) { first = false; } else { strcat(szItem, " "); } strcat(szItem, szArg); } } if (CXWnd *pEdit = (CXWnd *)pBazaarSearchWnd->GetChildItem("BZR_ItemNameInput")) { pEdit->SetWindowTextA(CXStr(szItem)); DWORD nThreadID = 0; CreateThread(NULL, NULL, searchthread, 0, 0, &nThreadID); } error_out: return; }
VOID HideDoCommand(PSPAWNINFO pChar, PCHAR szLine, BOOL delayed) { if (delayed) { lockit lk(ghLockDelayCommand,"HideDoCommand"); CHAR szTheCmd[MAX_STRING]; strcpy_s(szTheCmd, szLine); PCHATBUF pChat = 0; try { pChat = new CHATBUF; strcpy_s(pChat->szText,szTheCmd); pChat->pNext = 0; if (!gDelayedCommands) { gDelayedCommands = pChat; } else { PCHATBUF pCurrent = 0; for (pCurrent = gDelayedCommands;pCurrent->pNext;pCurrent=pCurrent->pNext); pCurrent->pNext = pChat; } } catch(std::bad_alloc& exc) { UNREFERENCED_PARAMETER(exc); MessageBox(NULL,"HideDoCommand failed to allocate memory for gDelayedCommands","Did we just discover a memory leak?",MB_SYSTEMMODAL|MB_OK); }; return; } CAutoLock DoCommandLock(&gCommandCS); CHAR szTheCmd[MAX_STRING]; strcpy_s(szTheCmd, szLine); WeDidStuff(); CHAR szOriginalLine[MAX_STRING]; strcpy_s(szOriginalLine,szTheCmd); CHAR szArg1[MAX_STRING]; GetArg(szArg1,szTheCmd,1); std::string sName = szArg1; std::transform(sName.begin(), sName.end(), sName.begin(), tolower); if (mAliases.find(sName) != mAliases.end()) { sprintf_s(szTheCmd, "%s%s", mAliases[sName].c_str(), szOriginalLine + sName.size()); } GetArg(szArg1,szTheCmd,1); if (szArg1[0]==0) return; CHAR szParam[MAX_STRING]; strcpy_s(szParam, GetNextArg(szTheCmd)); if ((szArg1[0]==':') || (szArg1[0]=='{')) { bRunNextCommand = TRUE; return; } PMACROBLOCK pBlock = GetCurrentMacroBlock(); if (szArg1[0]=='}') { if (pBlock && pBlock->Line[pBlock->CurrIndex].LoopStart != 0) { pBlock->CurrIndex = pBlock->Line[pBlock->CurrIndex].LoopStart; extern void pop_loop(); pop_loop(); return; } if (strstr(szTheCmd,"{")) { GetArg(szArg1,szTheCmd,2); if (_stricmp(szArg1,"else")) { FatalError("} and { seen on the same line without an else present"); } // DebugSpew("DoCommand - handing {} off to FailIf"); if(pBlock) FailIf(pChar,"{",pBlock->CurrIndex,TRUE); } else { // handle this: // /if () { // } else /echo stuff GetArg(szArg1,szTheCmd,2); if (!_stricmp(szArg1,"else")) { // check here to fail this: // /if () { // } else // /echo stuff GetArg(szArg1,szTheCmd,3); if (!_stricmp(szArg1,"")) { FatalError("no command or { following else"); } bRunNextCommand = TRUE; } else { bRunNextCommand = TRUE; } } return; } if (szArg1[0]==';' || szArg1[0]=='[') { pEverQuest->InterpretCmd((EQPlayer*)pChar,szOriginalLine); return; } PMQCOMMAND pCommand=pCommands; while(pCommand) { if (pCommand->InGameOnly && gGameState!=GAMESTATE_INGAME) { pCommand=pCommand->pNext; continue; } int Pos=_strnicmp(szArg1,pCommand->Command,strlen(szArg1)); if (Pos<0) {// command not found break; } if (Pos==0) { if (pCommand->Parse && bAllowCommandParse) { pCommand->Function(pChar,ParseMacroParameter(pChar,szParam)); } else { pCommand->Function(pChar,szParam); } strcpy_s(szLastCommand,szOriginalLine); return; } pCommand=pCommand->pNext; } PBINDLIST pBind = pBindList; while( pBind ) { if( gGameState != GAMESTATE_INGAME ) { // Macro Binds only supported in-game pBind = pBind->pNext; continue; } int Pos = _strnicmp( szArg1, pBind->szName, strlen( szArg1 ) ); if( Pos == 0 ) { // found it! if( pBind->szFuncName ) { if( PCHARINFO pCharInfo = GetCharInfo() ) { std::string sCallFunc( pBind->szFuncName ); sCallFunc += " "; sCallFunc += szParam; CHAR szCallFunc[MAX_STRING] = { 0 }; strcpy_s(szCallFunc, sCallFunc.c_str()); ParseMacroData(szCallFunc, MAX_STRING); //Call(pCharInfo->pSpawn, (PCHAR)szCallFunc.c_str()); if (pBlock && !pBlock->BindCmd.size()) { if (!gBindInProgress) { gBindInProgress = true; pBlock->BindCmd = szCallFunc; } else { Beep(1000, 100); WriteChatf("Can't execute bind while another bind is on progress"); } } } } strcpy_s( szLastCommand, szOriginalLine ); return; } pBind = pBind->pNext; } // skip this logic for Bind Commands. if( _strnicmp( szOriginalLine, "sub bind_", 9 ) != 0 ) { if( !_strnicmp( szOriginalLine, "sub ", 4 ) ) { FatalError( "Flow ran into another subroutine. (%s)", szOriginalLine ); return; } strcpy_s( szLastCommand, szOriginalLine ); MacroError( "DoCommand - Couldn't parse '%s'", szOriginalLine ); } }
// *************************************************************************** // Function: Call // Description: Our '/call' command // Usage: /call <Subroutine> // *************************************************************************** VOID Call(PSPAWNINFO pChar, PCHAR szLine) { PMACROSTACK pStack; PMACROBLOCK pCallingPoint = gMacroBlock; CHAR SubName[MAX_STRING] = {0}; PCHAR SubParam = NULL; CHAR SubLine[MAX_STRING] = {0}; CHAR SubLineP[MAX_STRING] = {0}; DWORD StackNum = 0; bRunNextCommand = TRUE; if (szLine[0]==0) { SyntaxError("Usage: /call <subroutine> [param [param...]]"); return; } if (!gMacroBlock) { MacroError("Cannot call when a macro isn't running."); return; } GetArg(SubName,szLine,1); SubParam = GetNextArg(szLine); sprintf(SubLine,"sub %s",SubName); sprintf(SubLineP,"sub %s(",SubName); // Sub in Map? PMACROBLOCK pSubBlock = gMacroSubLookupMap[SubName]; // If not, find it and add. if (!pSubBlock) { while (gMacroBlock->pPrev) gMacroBlock = gMacroBlock->pPrev; while (gMacroBlock->pNext) { if (!stricmp(gMacroBlock->Line,SubLine) || !strnicmp(gMacroBlock->Line,SubLineP,strlen(SubLineP))) { pSubBlock = gMacroBlock; break; } gMacroBlock = gMacroBlock->pNext; } if (!pSubBlock) { gMacroBlock=pCallingPoint; FatalError("Subroutine %s wasn't found",SubName); return; } else { gMacroSubLookupMap[SubName] = pSubBlock; } } // Prep to call the Sub gMacroBlock = pSubBlock; DebugSpewNoFile("Call - Calling subroutine %s with params %s",SubName,SubParam); pStack = (PMACROSTACK)malloc(sizeof(MACROSTACK)); pStack->Location = gMacroBlock; pStack->Return[0] = 0; pStack->Parameters = NULL; pStack->LocalVariables = NULL; pStack->pNext = gMacroStack; gMacroStack = pStack; if (SubParam) { StackNum = 0; while (SubParam[0]!=0) { CHAR szParamName[MAX_STRING] = {0}; CHAR szParamType[MAX_STRING] = {0}; CHAR szNewValue[MAX_STRING]={0}; GetArg(szNewValue,SubParam,1); GetFuncParam(gMacroBlock->Line,StackNum,szParamName,szParamType); MQ2Type *pType = FindMQ2DataType(szParamType); if (!pType) pType=pStringType; AddMQ2DataVariable(szParamName,"",pType,&gMacroStack->Parameters,szNewValue); SubParam = GetNextArg(SubParam); StackNum++; } } return; }
VOID Click(PSPAWNINFO pChar, PCHAR szLine) { if(GetGameState()!=GAMESTATE_INGAME) { MacroError("Dont /click stuff(%s) when not in game... Gamestate is %d",szLine,GetGameState()); return; } CHAR szArg1[MAX_STRING] = {0}; PCHAR szMouseLoc; MOUSE_DATA_TYPES mdType = MD_Unknown; DWORD RightOrLeft = 0; GetArg(szArg1, szLine, 1); //left or right szMouseLoc = GetNextArg(szLine, 1); //location to click //parse location for click location (szMouseLoc) here if (szMouseLoc && szMouseLoc[0]!=0) { if (!strnicmp(szMouseLoc, "target", 6)) { if (!pTarget) { WriteChatColor("You must have a target selected for /click x target.",CONCOLOR_RED); return; } if (!strnicmp(szArg1, "left", 4)) { pEverQuest->LeftClickedOnPlayer(pTarget); gMouseEventTime = GetFastTime(); } else if (!strnicmp(szArg1, "right", 5)) { pEverQuest->RightClickedOnPlayer(pTarget, 0); gMouseEventTime = GetFastTime(); } return; } else if(!strnicmp(szMouseLoc,"center",6)) { sprintf(szMouseLoc,"%d %d",ScreenXMax/2,ScreenYMax/2); } else if (!strnicmp(szMouseLoc, "item", 4)) { if(pGroundTarget) { if (!strnicmp(szArg1, "left", 4)) { if(EnviroTarget.Name[0]!=0) { if(DistanceToSpawn(pChar,&EnviroTarget)<=20.0f) { //do stuff if(PEQSWITCH pSwitch = (PEQSWITCH)pGroundTarget->pSwitch) { *((DWORD*)__LMouseHeldTime)=((PCDISPLAY)pDisplay)->TimeStamp-0x45; //we "click" at -1000,-1000 because we know the user doesnt have any windows there... //if its possible, i would like to figure out a pixel //on the users screen that isnt covered by a window... //the click need to be issued on the main UI... //but for now this will work -eqmule 8 mar 2014 pEverQuest->LMouseUp(-1000,-1000); } } else { WriteChatf("You are to far away from the item, please move closer before issuing the /click left item command."); } } else { WriteChatf("No Item targeted, use /itemtarget <theid> before issuing a /click left item command."); } } else { WriteChatf("Invalid click args, use \"/click left item\", aborting: %s",szMouseLoc); } } else { WriteChatf("No Item targeted, use /itemtarget <theid> before issuing a /click left item command."); } return; } else if (!strnicmp(szMouseLoc, "door", 4)) { // a right clicked door spawn does nothing if(pDoorTarget) { if (!strnicmp(szArg1, "left", 4)) { if(DoorEnviroTarget.Name[0]!=0) { if(DistanceToSpawn(pChar,&DoorEnviroTarget)<20.0f) { EQSwitch *pSwitch = (EQSwitch *)pDoorTarget; srand((unsigned int)time(0)); int randclickY = rand() % 5; int randclickX = rand() % 5; int randclickZ = rand() % 5; PSWITCHCLICK pclick = new SWITCHCLICK; if(pclick) { pclick->Y=pDoorTarget->Y+randclickY; pclick->X=pDoorTarget->X+randclickX; pclick->Z=pDoorTarget->Z+randclickZ; randclickY = rand() % 5; randclickX = rand() % 5; randclickZ = rand() % 5; pclick->Y1=pclick->Y+randclickY; pclick->X1=pclick->X+randclickX; pclick->Z1=pclick->Z+randclickZ; pSwitch->UseSwitch(GetCharInfo()->pSpawn->SpawnID,0xFFFFFFFF,0,(DWORD)pclick); delete pclick; } //DoorEnviroTarget.Name[0]='\0'; if (pTarget==(EQPlayer*)&DoorEnviroTarget) {//this should NEVER happen pTarget=NULL; } return; } else { WriteChatf("You are to far away from the door, please move closer before issuing the /click left door command."); } } else { WriteChatf("No Door targeted, use /doortarget <theid> before issuing a /click left door command."); } } else { WriteChatf("Invalid click args, use \"/click left door\", aborting: %s",szMouseLoc); } } else { WriteChatf("No Door targeted, use /doortarget <theid> before issuing a /click left door command."); } return;; } ClickMouseLoc(szMouseLoc, szArg1); return; } if (szArg1[0]!=0) { if (!strnicmp(szArg1, "left", 4)) { ClickMouse(0); } else if (!strnicmp(szArg1, "right", 5)) { ClickMouse(1); } else { WriteChatColor("Usage: /click <left|right>",USERCOLOR_DEFAULT); DebugSpew("Bad command: %s",szLine); return; } } }
VOID HideDoCommand(PSPAWNINFO pChar, PCHAR szLine, BOOL delayed) { if (delayed) { PCHATBUF pChat = (PCHATBUF)malloc(sizeof(CHATBUF)); if (pChat) { strcpy(pChat->szText,szLine); pChat->pNext = NULL; if (!gDelayedCommands) { gDelayedCommands = pChat; } else { PCHATBUF pCurrent; for (pCurrent = gDelayedCommands;pCurrent->pNext;pCurrent=pCurrent->pNext); pCurrent->pNext = pChat; } } return; } CAutoLock DoCommandLock(&gCommandCS); CHAR szCmd[MAX_STRING] = {0}; CHAR szParam[MAX_STRING] = {0}; CHAR szOriginalLine[MAX_STRING] = {0}; strcpy(szOriginalLine,szLine); GetArg(szCmd,szLine,1); PALIAS pLoop = pAliases; while (pLoop) { if (!stricmp(szCmd,pLoop->szName)) { sprintf(szLine,"%s%s",pLoop->szCommand,szOriginalLine+strlen(pLoop->szName)); break; } pLoop = pLoop->pNext; } GetArg(szCmd,szLine,1); if (szCmd[0]==0) return; strcpy(szParam, GetNextArg(szLine)); if ((szCmd[0]==':') || (szCmd[0]=='{')) { bRunNextCommand = TRUE; return; } if(gMacroBlock && gMacroBlock->LoopLine!=0) { //this is a command thats inside a while loop //so its time to loop back gMacroBlock = GetWhileBlock(gMacroBlock->LoopLine); if (szCmd[0]=='}') { bRunNextCommand = TRUE; return; } } else if (szCmd[0]=='}') { if (strstr(szLine,"{")) { GetArg(szCmd,szLine,2); if (stricmp(szCmd,"else")) { FatalError("} and { seen on the same line without an else present"); } // DebugSpew("DoCommand - handing {} off to FailIf"); FailIf(pChar,"{",gMacroBlock,TRUE); } else { // handle this: // /if () { // } else /echo stuff GetArg(szCmd,szLine,2); if (!stricmp(szCmd,"else")) { // check here to fail this: // /if () { // } else // /echo stuff GetArg(szCmd,szLine,3); if (!stricmp(szCmd,"")) { FatalError("no command or { following else"); } bRunNextCommand = TRUE; } else { bRunNextCommand = TRUE; } } return; } if (szCmd[0]==';' || szCmd[0]=='[') { pEverQuest->InterpretCmd((EQPlayer*)pChar,szOriginalLine); return; } PMQCOMMAND pCommand=pCommands; while(pCommand) { if (pCommand->InGameOnly && gGameState!=GAMESTATE_INGAME) { pCommand=pCommand->pNext; continue; } int Pos=strnicmp(szCmd,pCommand->Command,strlen(szCmd)); if (Pos<0) {// command not found break; } if (Pos==0) { if (pCommand->Parse && bAllowCommandParse) { pCommand->Function(pChar,ParseMacroParameter(pChar,szParam)); } else { pCommand->Function(pChar,szParam); } strcpy(szLastCommand,szOriginalLine); return; } pCommand=pCommand->pNext; } if (!strnicmp(szOriginalLine,"sub ",4)) { FatalError("Flow ran into another subroutine."); return; } strcpy(szLastCommand,szOriginalLine); MacroError("DoCommand - Couldn't parse '%s'",szOriginalLine); }