// ***************************************************************************
// Function:    Delay
// Description: Our '/delay' command
// Usage:       /delay <time> [condition to end early]
// ***************************************************************************
VOID Delay(PSPAWNINFO pChar, PCHAR szLine)
{
    CHAR szVal[MAX_STRING] = {0};
    LONG VarValue;

    if (szLine[0]==0) {
        SyntaxError("Usage: /delay <time> [condition to end early]");
        return;
    }
    GetArg(szVal,szLine,1);
    ParseMacroParameter(GetCharInfo()->pSpawn,szVal);
    strcpy(gDelayCondition,GetNextArg(szLine));
    VarValue = atol(szVal);
    switch (szVal[strlen(szVal)-1]) {
        case 'm':
        case 'M':
            VarValue *= 60;
        case 's':
        case 'S':
            VarValue *= 10;
    }
    gDelay = VarValue;
    bRunNextCommand=false;
    //    DebugSpewNoFile("Delay - %d",gDelay);
}
Ejemplo n.º 2
0
static int Parse4Args(char *buf, char **arg1, char **arg2, char **arg3,
	char **arg4)
{
	SkipSpaces(buf);

	GetNextArg(buf, arg1);
	SkipSpaces(buf);

	GetNextArg(buf, arg2);
	SkipSpaces(buf);

	GetNextArg(buf, arg3);
	SkipSpaces(buf);

	GetLastArg(buf, arg4);
	CheckExtraParameter(buf);

	return 0;
}
Ejemplo n.º 3
0
static int Parse5or6Args(char *buf, char **arg1, char **arg2, char **arg3,
	char **arg4, char **arg5, char **arg6)
{
	SkipSpaces(buf);

	GetNextArg(buf, arg1);
	SkipSpaces(buf);

	GetNextArg(buf, arg2);
	SkipSpaces(buf);

	GetNextArg(buf, arg3);
	SkipSpaces(buf);

	GetNextArg(buf, arg4);
	SkipSpaces(buf);

	GetNextAndOptionalArg(buf, arg5, arg6);
	CheckExtraParameter(buf);

	return 0;
}
Ejemplo n.º 4
0
void csWrappedDocumentNode::ParseTemplateArguments (const char* str, 
						    Template::Params& strings,
                                                    bool omitEmpty)
{
  if (!str) return;

  TempString<> currentStr;
  while (*str != 0)
  {
    GetNextArg (str, currentStr);
    if (!omitEmpty || !currentStr.IsEmpty())
      strings.Push (currentStr);
  }
}
Ejemplo n.º 5
0
SAFEARRAY *CreateArgList(LPWSTR wszArgs)
{
    // Count number of args
    unsigned cArgs = 0;
    LPWSTR wszArgStart;
    LPWSTR wszArgEnd = wszArgs;
    while (GetNextArg(wszArgEnd, wszArgStart, wszArgEnd)) cArgs++;

    // Allocate safearray
    SAFEARRAY * psa;
    SAFEARRAYBOUND rgsabound[1];
    rgsabound[0].lLbound = 0;
    rgsabound[0].cElements = cArgs;
    psa = SafeArrayCreate(VT_BSTR, 1, &rgsabound[0]);

    // Create each string
    wszArgEnd = wszArgs;
    LONG iArg = 0;
    while (GetNextArg(wszArgEnd, wszArgStart, wszArgEnd))
    {
        WCHAR origChar = *wszArgEnd;
        *wszArgEnd = L'\0';
        BSTR bstrArg = SysAllocString(wszArgStart);
        if (bstrArg != NULL)
        {
            HRESULT hr = SafeArrayPutElement(psa, &iArg, bstrArg);
            _ASSERTE(SUCCEEDED(hr));
        }
        *wszArgEnd = origChar;
        iArg++;
    }

    _ASSERT(iArg == cArgs);

    return psa;
}
Ejemplo n.º 6
0
bool csWrappedDocumentNode::ProcessUndef (NodeProcessingState* state, 
                                          iDocumentNode* node, 
                                          const TempString<>& args)
{
  TempString<> param;
  const char* p = args;
  GetNextArg (p, param);
  if (p) { while (*p && isspace (*p)) p++; }
  if (param.IsEmpty() || (*p != 0))
  {
    Report (syntaxErrorSeverity, node,
            "One parameter expected for %s",
	    CS::Quote::Single ("Undef"));
    return false;
  }
  globalState->defines.Delete (param);
  return true;
}
Ejemplo n.º 7
0
bool csWrappedDocumentNode::ProcessStaticIfDef (NodeProcessingState* state, 
                                                iDocumentNode* node, 
                                                const TempString<>& args, bool invert)
{
  TempString<> param;
  const char* p = args;
  GetNextArg (p, param);
  if (p) { while (*p && isspace (*p)) p++; }
  if (param.IsEmpty() || (*p != 0))
  {
    Report (syntaxErrorSeverity, node,
            "One parameter expected for %s",
	    CS::Quote::Single ("SIfDef"));
    return false;
  }
  bool lastState = 
    state->staticIfStateStack.IsEmpty() ? true : 
    state->staticIfStateStack.Top().processNodes;
  bool defineExists = globalState->defines.Contains (param);
  state->staticIfStateStack.Push (
    (invert ? !defineExists : defineExists) && lastState);
  state->staticIfNest.Push (1);
  return true;
}
Ejemplo n.º 8
0
EFI_STATUS
SEnvCmdSA (
  IN EFI_HANDLE               ImageHandle,
  IN EFI_SYSTEM_TABLE         *SystemTable,
  IN EFI_LIST_ENTRY           *Head,
  IN EFI_GUID                 *Guid,
  IN CHAR16                   *CmdName,
  IN UINT16                   VHlpToken
  )
/*++

Routine Description:

  Code for shell "set" & "alias" command

Arguments:

  ImageHandle - The image handle
  SystemTable - The system table
  Head        - The variable list head
  Guid        - The guid
  CmdName     - The command name
  VHlpToken   - The help token

Returns:

--*/
{
  EFI_LIST_ENTRY          *Link;
  VARIABLE_ID             *Var;
  VARIABLE_ID             *Found;
  CHAR16                  *Name;
  CHAR16                  *Value;
  UINTN                   SLen;
  UINTN                   Len;
  BOOLEAN                 Delete;
  EFI_STATUS              Status;
  BOOLEAN                 Volatile;
  UINTN                   Index;
  SHELL_VAR_CHECK_CODE    RetCode;
  CHAR16                  *Useful;
  SHELL_VAR_CHECK_PACKAGE ChkPck;
  SHELL_ARG_LIST          *ArgItem;

  EFI_SHELL_APP_INIT (ImageHandle, SystemTable);

  Status = LibFilterNullArgs ();
  if (EFI_ERROR (Status)) {
    goto Quit;
  }

  ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE));
  ArgItem = NULL;

  RetCode = LibCheckVariables (SI, VarCheckList, &ChkPck, &Useful);
  if (VarCheckOk != RetCode) {
    switch (RetCode) {
    case VarCheckConflict:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_FLAG_CONFLICT), HiiEnvHandle, CmdName, Useful);
      break;

    case VarCheckDuplicate:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiEnvHandle, CmdName, Useful);
      break;

    case VarCheckUnknown:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiEnvHandle, CmdName, Useful);
      break;

    default:
      break;
    }

    Status = EFI_INVALID_PARAMETER;
    goto Quit;
  }
  //
  // Initializing variable to aVOID level 4 warning
  //
  Name      = NULL;
  Value     = NULL;
  Delete    = FALSE;
  Status    = EFI_SUCCESS;
  Found     = NULL;
  Var       = NULL;
  Volatile  = FALSE;

  //
  // Crack arguments
  //
  if (ChkPck.ValueCount > 2) {
    PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName);
    Status = EFI_INVALID_PARAMETER;
    goto Quit;
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) {
    EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) {
    if (IS_OLD_SHELL) {
      PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle);
      goto Quit;
    }

    if (ChkPck.ValueCount > 0 ||
        ChkPck.FlagCount > 2 ||
        (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b"))
        ) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName);
      Status = EFI_INVALID_PARAMETER;
      goto Quit;
    }

    PrintToken (VHlpToken, HiiEnvHandle);
    Status = EFI_SUCCESS;
    goto Quit;
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-d") != NULL) {
    if (ChkPck.ValueCount > 1) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName);
      Status = EFI_INVALID_PARAMETER;
      goto Quit;
    } else if (ChkPck.ValueCount < 1) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiEnvHandle, CmdName);
      Status = EFI_INVALID_PARAMETER;
      goto Quit;
    }

    Delete = TRUE;
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-v") != NULL) {
    if (ChkPck.ValueCount < 2) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiEnvHandle, CmdName);
      Status = EFI_INVALID_PARAMETER;
      goto Quit;
    }

    Volatile = TRUE;
  }

  ArgItem = GetFirstArg (&ChkPck);
  if (NULL != ArgItem) {
    if (SEnvGetCmdDispath (ArgItem->VarStr) && (StriCmp (CmdName, L"alias") == 0)) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_VAR_INTERNAL_COMAMND), HiiEnvHandle, CmdName, ArgItem->VarStr);
      Status = EFI_INVALID_PARAMETER;
      goto Quit;
    } else if (StrSubCmp (L"*", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"?", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"<", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L">", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"#", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L":", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"^", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"%", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"/", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"|", ArgItem->VarStr, 1) == TRUE ||
             StrSubCmp (L"\"", ArgItem->VarStr, 1) == TRUE
            ) {
      //
      // we donot allow *,?,<,>,#,:,^,%,/,|," in alias or variable name
      //
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiEnvHandle, CmdName, ArgItem->VarStr);
      Status = EFI_INVALID_PARAMETER;
      goto Quit;
    } else {
      Name = ArgItem->VarStr;
    }

    ArgItem = GetNextArg (ArgItem);
  }

  if (NULL != ArgItem) {
    Value = ArgItem->VarStr;
  }

  if (Delete && Value) {
    PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName);
    Status = EFI_INVALID_PARAMETER;
    goto Quit;
  }

  if (Name != NULL) {
    for (Index = 0; mSpecVarTable[Index].CmdName != NULL; Index++) {
      if (StriCmp (mSpecVarTable[Index].CmdName, CmdName) == 0 &&
          StriCmp (mSpecVarTable[Index].VarName, Name) == 0 &&
          mSpecVarTable[Index].SpecCheckFun != NULL
          ) {
        Status = mSpecVarTable[Index].SpecCheckFun (Value, Delete, Volatile);
        if (EFI_ERROR (Status)) {
          goto Quit;
        }
      }
    }
  }
  //
  // Process
  //
  AcquireLock (&SEnvLock);

  if (!Name) {
    //
    // dump the list
    //
    SEnvSortVarList (Head);

    SLen = 0;
    for (Link = Head->Flink; Link != Head; Link = Link->Flink) {
      Var = CR (Link, VARIABLE_ID, Link, VARIABLE_SIGNATURE);
      if (_IsReserved (Var->Name, CmdName)) {
        continue;
      }

      Len = StrLen (Var->Name);
      if (Len > SLen) {
        SLen = Len;
      }
    }

    for (Link = Head->Flink; Link != Head; Link = Link->Flink) {
      //
      // Break the execution?
      //
      if (GetExecutionBreak ()) {
        goto Done;
      }

      Var = CR (Link, VARIABLE_ID, Link, VARIABLE_SIGNATURE);
      if (_IsReserved (Var->Name, CmdName)) {
        continue;
      }

      if (Var->Flags & VAR_ID_NON_VOL) {
        PrintToken (
          STRING_TOKEN (STR_SHELLENV_VAR_DUMP_VAR_LIST),
          HiiEnvHandle,
          L' ',
          SLen,
          Var->Name,
          Var->u.Str
          );
      } else {
        PrintToken (
          STRING_TOKEN (STR_SHELLENV_VAR_DUMP_VAR_LIST),
          HiiEnvHandle,
          L'*',
          SLen,
          Var->Name,
          Var->u.Str
          );
      }
    }
  } else {
    //
    // Find the specified value
    //
    Found = SEnvFindVar (Head, Name);

    if (Found && Delete) {
      //
      // Remove it from the store
      //
      Status = RT->SetVariable (Found->Name, Guid, 0, 0, NULL);
      if (Status == EFI_NOT_FOUND) {
        PrintToken (
          STRING_TOKEN (STR_SHELLENV_VAR_NOT_FOUND),
          HiiEnvHandle,
          CmdName,
          Found->Name
          );
      }
    } else if (Value) {
      //
      // Add it to the store
      //
      if (Found && ((Volatile && (Found->Flags & VAR_ID_NON_VOL)) || (!Volatile && !(Found->Flags & VAR_ID_NON_VOL)))) {
        if (Found->Flags & VAR_ID_NON_VOL) {
          PrintToken (
            STRING_TOKEN (STR_SHELLENV_VAR_ALREADY_EXISTS_NONVOLATILE),
            HiiEnvHandle,
            CmdName,
            Found->Name
            );
        } else {
          PrintToken (
            STRING_TOKEN (STR_SHELLENV_VAR_ALREADY_EXISTS_VOLATILE),
            HiiEnvHandle,
            CmdName,
            Found->Name
            );
        }

        Found   = NULL;
        Status  = EFI_ACCESS_DENIED;
      } else {
        Status = SEnvAddVar (
                  Head,
                  Guid,
                  Found ? Found->Name : Name,
                  (UINT8 *) Value,
                  StrSize (Value),
                  Volatile
                  );
      }
    } else {
      if (Found) {
        if (Found->Flags & VAR_ID_NON_VOL) {
          PrintToken (
            STRING_TOKEN (STR_SHELLENV_VAR_DISPLAY_VAR),
            HiiEnvHandle,
            L' ',
            Found->Name,
            Found->u.Str
            );
        } else {
          PrintToken (
            STRING_TOKEN (STR_SHELLENV_VAR_DISPLAY_VAR),
            HiiEnvHandle,
            L'*',
            Found->Name,
            Found->u.Str
            );
        }
      } else {
        PrintToken (
          STRING_TOKEN (STR_SHELLENV_VAR_NOT_FOUND),
          HiiEnvHandle,
          CmdName,
          Name
          );
      }

      Found = NULL;
    }
    //
    // Remove the old in memory copy if there was one
    //
    if (Found && !EFI_ERROR (Status)) {
      RemoveEntryList (&Found->Link);
      FreePool (Found);
    }
  }

Done:
  ReleaseLock (&SEnvLock);
Quit:
  LibCheckVarFreeVarList (&ChkPck);
  return Status;
}
Ejemplo n.º 9
0
    VOID Detour(PSPAWNINFO pChar, PCHAR szFullLine) 
    { 
        DebugSpew("CCommandHook::Detour(%s)",szFullLine);
        CHAR szFullCommand[MAX_STRING] = {0}; 
        CHAR szCommand[MAX_STRING] = {0}; 
        CHAR szArgs[MAX_STRING] = {0}; 
        CHAR szOrig[MAX_STRING] = {0};
        CHAR szSub[MAX_STRING] = {0};
        string szSubFullCommand = "";
        unsigned int k=0;
        bool OneCharacterSub = false;
        PALIAS pLoop = pAliases; 
        PSUB pSubLoop = pSubs;

        if (szFullLine[0]!=0) { 
            strcpy(szFullCommand,szFullLine); 
            GetArg(szCommand,szFullCommand,1); 

            if (!stricmp(szCommand,"/camp"))
            {
                if (gMacroBlock)
                {
                    WriteChatColor("A macro is currently running.  You may wish to /endmacro before you finish camping.", CONCOLOR_YELLOW );
                }
            }

            szSubFullCommand = szFullCommand;
            for (unsigned int i=0; i < sizeof(szFullCommand); i++ ) 
            {
                if (szFullCommand[i] == '%') 
                {
                    if (szFullCommand[i+2] == ' ' || szFullCommand[i+2] == '\0' ||
                        !isalnum(szFullCommand[i+2]) ) {
                            if (szFullCommand[i+1] == 'm' || szFullCommand[i+1] == 'M' ||
                                szFullCommand[i+1] == 'o' || szFullCommand[i+1] == 'O' ||
                                szFullCommand[i+1] == 'p' || szFullCommand[i+1] == 'P' ||
                                szFullCommand[i+1] == 'r' || szFullCommand[i+1] == 'R' ||
                                szFullCommand[i+1] == 's' || szFullCommand[i+1] == 'S' ||
                                szFullCommand[i+1] == 't' || szFullCommand[i+1] == 'T' )
                                continue;
                            else { 
                                szOrig[0] = szFullCommand[i+1];
                                szOrig[1] = '\0';
                                k = 1;
                                OneCharacterSub = true;
                            }
                    }

                    if (!OneCharacterSub) {
                        for (unsigned int j=i+1; j < sizeof(szFullCommand); j++ )
                        {
                            if (szFullCommand[j] == ' ' || szFullCommand[j] == '\0' ) 
                                break;
                            else if (!isalnum(szFullCommand[j]))
                                break;
                            szOrig[k] = szFullCommand[j];
                            k++;
                        }
                    }
                    while (pSubLoop)
                    {
                        if (!stricmp(szOrig, pSubLoop->szOrig)) 
                        {
                            sprintf( szSub, "%s", pSubLoop->szSub );
                            break;
                        }
                        pSubLoop = pSubLoop->pNext;
                    }
                    if (szSub[0] != '\0' ) {
                        szSubFullCommand.replace(i,k+1,szSub);
                        sprintf( szFullCommand, "%s",szSubFullCommand.c_str() ); 
                    }
                    szOrig[0] = '\0';
                    szSub[0] = '\0';
                    k=0;
                    OneCharacterSub = false;
                    pSubLoop = pSubs;
                }
            }
            sprintf(szFullCommand, "%s", szSubFullCommand.c_str() );

            while (pLoop) { 
                if (!stricmp(szCommand,pLoop->szName)) { 
                    sprintf(szCommand,"%s%s",pLoop->szCommand,szFullCommand+strlen(pLoop->szName)); 
                    strncpy(szFullCommand,szCommand,MAX_STRING); 
                    break;
                } 
                pLoop = pLoop->pNext; 
            } 
            GetArg(szCommand,szFullCommand,1); 
            strcpy(szArgs, GetNextArg(szFullCommand)); 

            PMQCOMMAND pCommand=pCommands;
            while(pCommand)
            {
                if (pCommand->InGameOnly && gGameState!=GAMESTATE_INGAME)
                {
                    pCommand=pCommand->pNext;
                    continue;
                }
                int Pos=strnicmp(szCommand,pCommand->Command,strlen(szCommand));
                if (Pos<0)
                {// command not found
                    break;
                }
                if (Pos==0)
                {
                    if (pCommand->Parse && bAllowCommandParse)
                        ParseMacroParameter(pChar,szArgs); 
                    if (pCommand->EQ)
                    {
                        strcat(szCommand," "); 
                        strcat(szCommand,szArgs); 
                        Trampoline(pChar,szCommand); 
                    }
                    else
                    {
                        pCommand->Function(pChar,szArgs);
                    }
                    strcpy(szLastCommand,szFullCommand);
                    return;
                }
                pCommand=pCommand->pNext;
            }
        }
        Trampoline(pChar,szFullLine); 
        strcpy(szLastCommand,szFullCommand);
    } 
// ***************************************************************************
// 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:    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;
} 
// ***************************************************************************
// 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
}
Ejemplo n.º 13
0
char *CNWNXSortSet::OnRequest(char *gameObject, char *SetName, char* Parameters) {
	char setkey[32], name[22], cmd[32], arg1[1024], arg2[1024], arg3[1024], *lastarg, *pos;


	arg1[0] = 0;
	arg2[0] = 0;
	arg3[0] = 0;

	// Parameters are the call "ADD!value", "GET!15", "LENGTH", etc.
	
	GetNextArg(SetName, name, 22);
	results = Parameters;

	sprintf(setkey, "%08x-%s", gameObject, name);
	
	lastarg = Parameters;
	if ((pos = GetNextArg(Parameters, cmd, 31)) != NULL) {
		lastarg = pos;
		if ((pos = GetNextArg(pos, arg1, 1024)) != NULL) {
			lastarg = pos;
			if ((pos = GetNextArg(pos, arg2, 1024)) != NULL) {
				lastarg = pos;
				if ((pos = GetNextArg(pos, arg3, 1024)) != NULL) {
					lastarg = pos;
				}
			}
		}
	}

	if (strcmp("INIT", cmd) == 0) {
		SetInit(setkey);
	} else if (strcmp("ADD", cmd) == 0) {
		Add(setkey, arg1, arg2, arg3);
	} else if (strcmp("EXISTS", cmd) == 0) {
		Exists(setkey, arg1);
	} else if (strcmp("LENGTH", cmd) == 0) {
		Length(setkey);
	} else if (strcmp("SORT", cmd) == 0) {
		Sort(setkey);
	} else if (strcmp("DESTROY", cmd) == 0) {
		Destroy(setkey);
	} else if (sets.find(setkey) == sets.end()) {
		Log(0, "[%s] Set does not exist\n", setkey);
		sprintf(Parameters, "-5 [%s] Set does not exist.", setkey);
	} else if (strcmp("SETBYIDX", cmd) == 0) {
		SetByIdx(setkey, arg1, arg2, arg3);
	} else if (strcmp("SETBYTAG", cmd) == 0) {
		SetByTag(setkey, arg1, arg2, arg3);
	} else if (strcmp("REMOVE", cmd) == 0) {
		Remove(setkey, arg1);
	} else if (strcmp("GETBYIDX", cmd) == 0) {
		GetByIdx(setkey, arg1);
	} else if (strcmp("GETBYTAG", cmd) == 0) {
		GetByTag(setkey, arg1);
	} else {
		sprintf(Parameters, "[%s] bad command", cmd);
		Log(0, "[%s] %s\n", setkey, Parameters);
	}

	return NULL;
}
Ejemplo n.º 14
0
EFI_STATUS
SEnvCmdEcho (
  IN EFI_HANDLE           ImageHandle,
  IN EFI_SYSTEM_TABLE     *SystemTable
  )
/*++

Routine Description:

  Shell command "echo".

Arguments:

  ImageHandle - The image handle
  SystemTable - The system table
  
Returns:

--*/
{
  EFI_STATUS              Status;
  SHELL_VAR_CHECK_CODE    RetCode;
  CHAR16                  *Useful;
  SHELL_VAR_CHECK_PACKAGE ChkPck;
  SHELL_ARG_LIST          *Item;
  BOOLEAN                 PageBreak;

  EFI_SHELL_APP_INIT (ImageHandle, SystemTable);

  if (!EFI_PROPER_VERSION (0, 99)) {
    PrintToken (
      STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT),
      HiiEnvHandle,
      L"echo",
      EFI_VERSION_0_99 
      );
    Status = EFI_UNSUPPORTED;
    goto Done;
  }

  Status    = EFI_SUCCESS;
  PageBreak = FALSE;
  ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE));

  //
  //  No args: print status
  //  One arg, either -on or -off: set console echo flag
  //  Otherwise: echo all the args.  Shell parser will expand any args or vars.
  //
  RetCode = LibCheckVariables (SI, EchoCheckList, &ChkPck, &Useful);
  if (VarCheckOk != RetCode) {
    switch (RetCode) {
    case VarCheckDuplicate:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiEnvHandle, L"echo", Useful);
      break;

    case VarCheckUnknown:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiEnvHandle, L"echo", Useful);
      break;

    case VarCheckConflict:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_FLAG_CONFLICT), HiiEnvHandle, L"echo", Useful);
      break;

    default:
      break;
    }

    Status = EFI_INVALID_PARAMETER;
    goto Done;
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) {
    EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);
    PageBreak = TRUE;
  }

  //
  // Out put help.
  //
  if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) {
    if (IS_OLD_SHELL) {
      PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle);
    } else if (ChkPck.ValueCount > 0 ||
             ChkPck.FlagCount > 2 ||
             (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b"))
            ) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, L"echo");
      Status = EFI_INVALID_PARAMETER;
    } else {
      PrintToken (STRING_TOKEN (STR_SHELLENV_ECHO_VERBOSE_HELP), HiiEnvHandle);
    }

    goto Done;
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-on") != NULL) {
    if (ChkPck.ValueCount != 0) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, L"echo");
      Status = EFI_INVALID_PARAMETER;
      goto Done;
    } else {
      SEnvBatchSetEcho (TRUE);
    }
  } else if (LibCheckVarGetFlag (&ChkPck, L"-off") != NULL) {
    if (ChkPck.ValueCount != 0) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, L"echo");
      Status = EFI_INVALID_PARAMETER;
      goto Done;
    } else {
      SEnvBatchSetEcho (FALSE);
    }
  }

  if ((ChkPck.FlagCount == 0 || (1 == ChkPck.FlagCount && PageBreak)) && ChkPck.ValueCount == 0) {
    PrintToken (STRING_TOKEN (STR_SHELLENV_ECHO_ECHO_IS), HiiEnvHandle, (SEnvBatchGetEcho () ? L"on" : L"off"));
  } else if (ChkPck.ValueCount > 0) {
    Item = GetFirstArg (&ChkPck);
    for (;;) {
      Print (L"%s", Item->VarStr);
      Item = GetNextArg (Item);
      if (!Item) {
        break;
      }

      Print (L" ");
    }

    Print (L"\n");
  }

Done:
  LibCheckVarFreeVarList (&ChkPck);
  return Status;
}
Ejemplo n.º 15
0
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; 
        } 
    } 
}
Ejemplo n.º 16
0
int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
{
	bool bSetFullScreen = false;
	bool bBoot = false;
	LPSTR szImageName_drive1 = NULL;
	LPSTR szImageName_drive2 = NULL;
	const std::string strCmdLine(lpCmdLine);		// Keep a copy for log ouput

	while (*lpCmdLine)
	{
		LPSTR lpNextArg = GetNextArg(lpCmdLine);

		if (((strcmp(lpCmdLine, "-l") == 0) || (strcmp(lpCmdLine, "-log") == 0)) && (g_fh == NULL))
		{
			g_fh = fopen("AppleWin.log", "a+t");	// Open log file (append & text mode)
			setvbuf(g_fh, NULL, _IONBF, 0);			// No buffering (so implicit fflush after every fprintf)
			CHAR aDateStr[80], aTimeStr[80];
			GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, (LPTSTR)aDateStr, sizeof(aDateStr));
			GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, (LPTSTR)aTimeStr, sizeof(aTimeStr));
			fprintf(g_fh, "*** Logging started: %s %s\n", aDateStr, aTimeStr);
		}
		else if (strcmp(lpCmdLine, "-noreg") == 0)
		{
			g_bRegisterFileTypes = false;
		}
		else if (strcmp(lpCmdLine, "-d1") == 0)
		{
			lpCmdLine = GetCurrArg(lpNextArg);
			lpNextArg = GetNextArg(lpNextArg);
			szImageName_drive1 = lpCmdLine;
		}
		else if (strcmp(lpCmdLine, "-d2") == 0)
		{
			lpCmdLine = GetCurrArg(lpNextArg);
			lpNextArg = GetNextArg(lpNextArg);
			szImageName_drive2 = lpCmdLine;
		}
		else if (strcmp(lpCmdLine, "-f") == 0)
		{
			bSetFullScreen = true;
		}
		else if (strcmp(lpCmdLine, "-fs8bit") == 0)
		{
			SetFullScreen32Bit(false);				// Support old v1.24 fullscreen 8-bit palette mode
		}
		else if (strcmp(lpCmdLine, "-no-di") == 0)
		{
			g_bDisableDirectInput = true;
		}
		else if (strcmp(lpCmdLine, "-m") == 0)
		{
			g_bDisableDirectSound = true;
		}
		else if (strcmp(lpCmdLine, "-no-mb") == 0)
		{
			g_bDisableDirectSoundMockingboard = true;
		}
		else if (strcmp(lpCmdLine, "-memclear") == 0)
		{
			lpCmdLine = GetCurrArg(lpNextArg);
			lpNextArg = GetNextArg(lpNextArg);
			g_nMemoryClearType = atoi(lpCmdLine);
			if (g_nMemoryClearType < 0)
				g_nMemoryClearType = 0;
			else
			if (g_nMemoryClearType >= NUM_MIP)
				g_nMemoryClearType = NUM_MIP - 1;
		}
#ifdef RAMWORKS
		else if (strcmp(lpCmdLine, "-r") == 0)		// RamWorks size [1..127]
		{
			lpCmdLine = GetCurrArg(lpNextArg);
			lpNextArg = GetNextArg(lpNextArg);
			g_uMaxExPages = atoi(lpCmdLine);
			if (g_uMaxExPages > 127)
				g_uMaxExPages = 128;
			else if (g_uMaxExPages < 1)
				g_uMaxExPages = 1;
		}
#endif
		else if (strcmp(lpCmdLine, "-f8rom") == 0)		// Use custom 2K ROM at [$F800..$FFFF]
		{
			lpCmdLine = GetCurrArg(lpNextArg);
			lpNextArg = GetNextArg(lpNextArg);
			g_hCustomRomF8 = CreateFile(lpCmdLine, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
			if ((g_hCustomRomF8 == INVALID_HANDLE_VALUE) || (GetFileSize(g_hCustomRomF8, NULL) != 0x800))
				g_bCustomRomF8Failed = true;
		}
		else if (strcmp(lpCmdLine, "-printscreen") == 0)		// Turn on display of the last filename print screen was saved to
		{
			g_bDisplayPrintScreenFileName = true;
		}
		else if (strcmp(lpCmdLine, "-no-printscreen-dlg") == 0)		// Turn off the PrintScreen warning message dialog (if PrintScreen key can't be grabbed)
		{
			g_bShowPrintScreenWarningDialog = false;
		}
		else if (strcmp(lpCmdLine, "-spkr-inc") == 0)
		{
			lpCmdLine = GetCurrArg(lpNextArg);
			lpNextArg = GetNextArg(lpNextArg);
			const int nErrorInc = atoi(lpCmdLine);
			SoundCore_SetErrorInc( nErrorInc );
		}
		else if (strcmp(lpCmdLine, "-spkr-max") == 0)
		{
			lpCmdLine = GetCurrArg(lpNextArg);
			lpNextArg = GetNextArg(lpNextArg);
			const int nErrorMax = atoi(lpCmdLine);
			SoundCore_SetErrorMax( nErrorMax );
		}
		else if (strcmp(lpCmdLine, "-use-real-printer") == 0)	// Enable control in Advanced config to allow dumping to a real printer
		{
			g_bEnableDumpToRealPrinter = true;
		}
		else if (strcmp(lpCmdLine, "-speech") == 0)
		{
			g_bEnableSpeech = true;
		}
		else if (strcmp(lpCmdLine, "-multimon") == 0)
		{
			g_bMultiMon = true;
		}
		else	// unsupported
		{
			LogFileOutput("Unsupported arg: %s\n", lpCmdLine);
		}

		lpCmdLine = lpNextArg;
	}

	LogFileOutput("CmdLine: %s\n",  strCmdLine.c_str());

#if 0
#ifdef RIFF_SPKR
	RiffInitWriteFile("Spkr.wav", SPKR_SAMPLE_RATE, 1);
#endif
#ifdef RIFF_MB
	RiffInitWriteFile("Mockingboard.wav", 44100, 2);
#endif
#endif

	//-----

    char szPath[_MAX_PATH];

    if (0 == GetModuleFileName(NULL, szPath, sizeof(szPath)))
    {
        strcpy(szPath, __argv[0]);
    }

    // Extract application version and store in a global variable
    DWORD dwHandle, dwVerInfoSize;

    dwVerInfoSize = GetFileVersionInfoSize(szPath, &dwHandle);

    if (dwVerInfoSize > 0)
    {
        char* pVerInfoBlock = new char[dwVerInfoSize];

        if (GetFileVersionInfo(szPath, NULL, dwVerInfoSize, pVerInfoBlock))
        {
            VS_FIXEDFILEINFO* pFixedFileInfo;
            UINT pFixedFileInfoLen;

            VerQueryValue(pVerInfoBlock, TEXT("\\"), (LPVOID*) &pFixedFileInfo, (PUINT) &pFixedFileInfoLen);

            // Construct version string from fixed file info block

            unsigned long major     = pFixedFileInfo->dwFileVersionMS >> 16;
            unsigned long minor     = pFixedFileInfo->dwFileVersionMS & 0xffff;
            unsigned long fix       = pFixedFileInfo->dwFileVersionLS >> 16;
			unsigned long fix_minor = pFixedFileInfo->dwFileVersionLS & 0xffff;
            sprintf(VERSIONSTRING, "%d.%d.%d.%d", major, minor, fix, fix_minor); // potential buffer overflow
		}
    }
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
EFI_STATUS
EFIAPI
InitializeAttrib (
  IN EFI_HANDLE           ImageHandle,
  IN EFI_SYSTEM_TABLE     *SystemTable
  )
/*++

Routine Description:

  Command entry point. Parses command line arguments and calls internal
  function to perform actual action.

Arguments:

  ImageHandle    The image handle. 
  SystemTable    The system table.

Returns:

  EFI_SUCCESS             - Command completed successfully
  EFI_INVALID_PARAMETER   - Command usage error
  Other value             - Unknown error
  
--*/
{
  UINTN                   Index;
  EFI_LIST_ENTRY          FileList;
  EFI_LIST_ENTRY          *Link;
  SHELL_FILE_ARG          *Arg;
  UINT64                  Remove;
  UINT64                  Add;
  EFI_STATUS              Status;

  SHELL_VAR_CHECK_CODE    RetCode;
  CHAR16                  *Useful;
  SHELL_ARG_LIST          *Item;
  SHELL_VAR_CHECK_PACKAGE ChkPck;

  ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE));

  //
  // We are no being installed as an internal command driver, initialize
  // as an nshell app and run
  //
  EFI_SHELL_APP_INIT (ImageHandle, SystemTable);

  //
  // Enable tab key which can pause the output
  //
  EnableOutputTabPause();
  
  Status = LibFilterNullArgs ();
  if (EFI_ERROR (Status)) {
    return Status;
  }
  //
  // Register our string package with HII and return the handle to it.
  // If previously registered we will simply receive the handle
  //
  EFI_SHELL_STR_INIT (HiiHandle, STRING_ARRAY_NAME, EfiAttribGuid);

  if (!EFI_PROPER_VERSION (0, 99)) {
    PrintToken (
      STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT),
      HiiHandle,
      L"attrib",
      EFI_VERSION_0_99 
      );
    Status = EFI_UNSUPPORTED;
    goto Quit;
  }

  RetCode = LibCheckVariables (SI, AttribCheckList, &ChkPck, &Useful);
  if (VarCheckOk != RetCode) {
    switch (RetCode) {
    case VarCheckConflict:

      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_FLAG_CONFLICT), HiiHandle, L"attrib", Useful);
      break;

    case VarCheckDuplicate:

      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiHandle, L"attrib", Useful);
      break;

    case VarCheckUnknown:

      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiHandle, L"attrib", Useful);
      break;

    default:
      break;
    }

    Status = EFI_INVALID_PARAMETER;
    goto Quit;
  }
  //
  // Out put help.
  //
  if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) {
    EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) {
    if (IS_OLD_SHELL) {
      PrintToken (STRING_TOKEN (STR_NO_HELP), HiiHandle);
      goto Quit;
    }

    if (ChkPck.ValueCount > 0 ||
        ChkPck.FlagCount > 2 ||
        (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b"))
        ) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"attrib");
      Status = EFI_INVALID_PARAMETER;
    } else {
      PrintToken (STRING_TOKEN (STR_ATTRIB_VERBOSE_HELP), HiiHandle);
      Status = EFI_SUCCESS;
    }

    goto Quit;
  }
  //
  // Local Variable Initializations
  //
  InitializeListHead (&FileList);
  Link    = NULL;
  Arg     = NULL;
  Remove  = 0;
  Add     = 0;

  //
  // Parse command line arguments
  //
  Item = GetFirstFlag (&ChkPck);
  for (Index = 0; Index < ChkPck.FlagCount; Index += 1) {
    if (Item->FlagStr[0] == '-') {
      //
      // Attributes to remove
      //
      Status = AttribSet (&Item->FlagStr[1], &Remove);
      if (EFI_ERROR (Status)) {
        PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"attrib", Item->FlagStr);
        goto Done;
      }
    } else if (Item->FlagStr[0] == '+') {
      //
      // Attributes to Add
      //
      Status = AttribSet (&Item->FlagStr[1], &Add);
      if (EFI_ERROR (Status)) {
        PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"attrib", Item->FlagStr);
        goto Done;
      }
    } else {
      //
      // we should never get here
      //
      ASSERT (FALSE);
    }

    Item = GetNextArg (Item);
  }

  Item = GetFirstArg (&ChkPck);
  for (Index = 0; Index < ChkPck.ValueCount; Index += 1) {
    Status = ShellFileMetaArg (Item->VarStr, &FileList);
    if (EFI_ERROR (Status)) {
      PrintToken (STRING_TOKEN (STR_ATTRIB_CANNOT_OPEN), HiiHandle, L"attrib", Item->VarStr, Status);
      goto Done;
    }

    Item = GetNextArg (Item);
  }
  //
  // if no file is specified, get the whole directory
  //
  if (IsListEmpty (&FileList)) {
    Status = ShellFileMetaArg (L"*", &FileList);
    if (EFI_ERROR (Status)) {
      PrintToken (STRING_TOKEN (STR_ATTRIB_CANNOT_OPEN_DIR), HiiHandle, L"attrib", Status);
      goto Done;
    }
  }

  ShellDelDupFileArg (&FileList);
  //
  // Attrib each file
  //
  for (Link = FileList.Flink; Link != &FileList; Link = Link->Flink) {
    //
    // Break the execution?
    //
    if (GetExecutionBreak ()) {
      goto Done;
    }

    Arg     = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
    Status  = AttribFile (Arg, Remove, Add);
  }

Done:
  ShellFreeFileList (&FileList);
Quit:
  LibCheckVarFreeVarList (&ChkPck);
  LibUnInitializeStrings ();
  return Status;
}
Ejemplo n.º 19
0
VOID MapFilters(PSPAWNINFO pChar, PCHAR szLine)
{
	bRunNextCommand = TRUE;
	CHAR szArg[MAX_STRING] = { 0 };
	GetArg(szArg, szLine, 1);
	PCHAR szRest = GetNextArg(szLine);
	CHAR szBuffer[MAX_STRING] = { 0 };

	// Display settings
	if (szArg[0] == 0) {
		WriteChatColor("Map filtering settings:", USERCOLOR_DEFAULT);
		WriteChatColor("-----------------------", USERCOLOR_DEFAULT);
		for (DWORD i = 0; MapFilterOptions[i].szName != NULL; i++)
			if (RequirementsMet(i))
				MapFilterSetting(pChar, i);

		// Display Help
	}
	else if (!_strnicmp(szArg, "help", 4))
	{
		WriteChatColor("Map filtering options:", USERCOLOR_DEFAULT);
		for (DWORD i = 0; MapFilterOptions[i].szName != NULL; i++) {
			sprintf_s(szBuffer, "%s%s: %s", MapFilterOptions[i].szName, (MapFilterOptions[i].bIsToggle) ? "" : " #", MapFilterOptions[i].szHelpString);
			WriteChatColor(szBuffer, USERCOLOR_DEFAULT);
		}
		WriteChatColor("'option' color [r g b]: Set display color for 'option' (Omit to reset to default)", USERCOLOR_DEFAULT);

		// Set option
	}
	else {
		PMAPFILTER Found = 0;
		for (DWORD i = 0; MapFilterOptions[i].szName != NULL; i++) {
			if (!_stricmp(szArg, MapFilterOptions[i].szName)) {
				if (!_strnicmp(szRest, "color", 5)) {
					if (MapFilterOptions[i].DefaultColor == -1) {
						sprintf_s(szBuffer, "Option '%s' does not have a color.", MapFilterOptions[i].szName);
						WriteChatColor(szBuffer, USERCOLOR_DEFAULT);
					}
					else {
						DWORD R, G, B;
						CHAR szBuffer2[MAX_STRING] = { 0 };
						GetArg(szArg, szRest, 2);
						if (szArg[0] == 0) {
							MapFilterOptions[i].Color = MapFilterOptions[i].DefaultColor;
						}
						else {
							R = atoi(szArg);
							G = atoi(GetArg(szArg, szRest, 3));
							B = atoi(GetArg(szArg, szRest, 4));
							if (R>255) R = 255;
							if (G>255) G = 255;
							if (B>255) B = 255;
							MapFilterOptions[i].Color = R * 0x10000 + G * 0x100 + B;
						}
						sprintf_s(szBuffer, "Option '%s' color set to: %d %d %d", MapFilterOptions[i].szName, R, G, B);
						WriteChatColor(szBuffer, USERCOLOR_DEFAULT);
						_itoa_s(MapFilterOptions[i].Color & 0xFFFFFF, szBuffer, 10);
						sprintf_s(szBuffer2, "%s-Color", MapFilterOptions[i].szName);
						WritePrivateProfileString("Map Filters", szBuffer2, szBuffer, INIFileName);
						MapFilterOptions[i].Color |= 0xFF000000;
					}
				}
				else {
					MapFilterSetting(pChar, i, szRest);
				}
				Found = &MapFilterOptions[i];
			}
		}
		if (!Found)
			SyntaxError("Usage: /mapfilter [option|help]");
		else if (Found->RegenerateOnChange)
		{
			MapClear();
			MapGenerate();
		}
	}
}
Ejemplo n.º 20
0
VOID CustomBindCmd(PSPAWNINFO pChar, PCHAR szLine)
{
    if (szLine[0]==0)
    {
        SyntaxError("Usage: /custombind <list|add <name>|delete <name>|clear <name><-down|-up>|set <name><-down|-up> <command>>");
        return;
    }
    CHAR szBuffer[MAX_STRING];
    CHAR szArg[MAX_STRING] = {0};
    CHAR szArg2[MAX_STRING] = {0};
    GetArg(szArg,szLine,1);
    GetArg(szArg2,szLine,2);
    PCHAR szRest = GetNextArg(szLine,2);

    if (!_stricmp(szArg,"list"))
    {
        WriteChatColor("Custom binds");
        WriteChatColor("--------------");
        for (unsigned long N = 0 ; N < CustomBinds.Size ; N++)
            if (PCUSTOMBIND pBind=CustomBinds[N])
            {
                sprintf_s(szBuffer,"[\ay%s\ax] [Down:\at%s\ax] [Up:\at%s\ax]",pBind->Name,pBind->CommandDown,pBind->CommandUp);
                WriteChatColor(szBuffer);
            }
            WriteChatColor("--------------");
            WriteChatColor("End custom binds");
            return;
    }
    if (!_stricmp(szArg,"add"))
    {
        if (strchr(szArg2,'-'))
        {
            WriteChatColor("'-' is not allowed in a custom bind name");
        }
        if (PCUSTOMBIND pBind=AddCustomBind(szArg2,0,0))
        {
            WriteChatColor("Custom bind added.  Use /custombind set to set the custom commands.");
        }
        else
        {
            WriteChatColor("Failed to add custom bind (name in use)");
        }
        return;
    }
    if (!_stricmp(szArg,"delete"))
    {
        int N=FindCustomBind(szArg2);
        if (N>=0)
        {
            RemoveCustomBind(N);
            WriteChatColor("Custom bind deleted");
        }
        else
        {
            WriteChatColor("Could not find custom bind with that name to delete");
        }
        return;
    }
    if (!_stricmp(szArg,"set"))
    {
        BOOL Down=true;
        if (PCHAR minus=strchr(szArg2,'-'))
        {
            minus[0]=0;
            if (!_stricmp(&minus[1],"up"))
                Down=false;
        }
        int N=FindCustomBind(szArg2);
        if (N<0)
        {
            sprintf_s(szBuffer,"Could not find custom bind '%s'",szArg2);
            WriteChatColor(szBuffer);
            return;
        }
        PCUSTOMBIND pBind=CustomBinds[N];
        if (Down)
            strcpy_s(pBind->CommandDown,szRest);
        else
            strcpy_s(pBind->CommandUp,szRest);
        sprintf_s(szBuffer,"[\ay%s\ax] [Down:\at%s\ax] [Up:\at%s\ax]",pBind->Name,pBind->CommandDown,pBind->CommandUp);
        WriteChatColor(szBuffer);
        SaveCustomBinds();
        return;
    }
    if (!_stricmp(szArg,"clear"))
    {
        BOOL Down=true;
        if (PCHAR minus=strchr(szArg2,'-'))
        {
            minus[0]=0;
            if (!_stricmp(&minus[1],"up"))
                Down=false;
        }
        int N=FindCustomBind(szArg2);
        if (N<0)
        {
            sprintf_s(szBuffer,"Could not find custom bind '%s'",szArg2);
            WriteChatColor(szBuffer);
            return;
        }
        PCUSTOMBIND pBind=CustomBinds[N];
        if (Down)
            pBind->CommandDown[0]=0;
        else
            pBind->CommandUp[0]=0;
        sprintf_s(szBuffer,"[\ay%s\ax] [Down:\at%s\ax] [Up:\at%s\ax]",pBind->Name,pBind->CommandDown,pBind->CommandUp);
        WriteChatColor(szBuffer);
        SaveCustomBinds();
        return;
    }
}
Ejemplo n.º 21
0
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 );
    }
}
Ejemplo n.º 22
0
    VOID Detour(PSPAWNINFO pChar, PCHAR szFullLine) 
    {
		lockit lk(ghCCommandLock,"CCommandHook::Detour");
        DebugSpew("CCommandHook::Detour(%s)",szFullLine);
        CHAR szFullCommand[MAX_STRING] = {0}; 
        CHAR szCommand[MAX_STRING] = {0}; 
        CHAR szArgs[MAX_STRING] = {0}; 
        CHAR szOrig[MAX_STRING] = {0};
        CHAR szSub[MAX_STRING] = {0};
        std::string szSubFullCommand = "";
        unsigned int k=0;
        bool OneCharacterSub = false;
        PSUB pSubLoop = pSubs;
        if (szFullLine[0]!=0) { 
			strcpy_s(szFullCommand,szFullLine);
            GetArg(szCommand,szFullCommand,1); 

            if (!_stricmp(szCommand,"/camp"))
            {
                if (GetmacroBlockCount())
                {
                    WriteChatColor("A macro is currently running.  You may wish to /endmacro before you finish camping.", CONCOLOR_YELLOW );
                }
            }

            szSubFullCommand = szFullCommand;
            size_t len = strnlen_s(szFullCommand, MAX_STRING);
			for (unsigned int i=0; i < sizeof(szFullCommand); i++ ) 
            {
                if (szFullCommand[i] == '%' && ((i+2)<len))
                {
                    if (szFullCommand[i+2] == ' ' || szFullCommand[i+2] == '\0' ||
                        !isalnum(szFullCommand[i+2]) ) {
                            if (szFullCommand[i+1] == 'm' || szFullCommand[i+1] == 'M' ||
                                szFullCommand[i+1] == 'o' || szFullCommand[i+1] == 'O' ||
                                szFullCommand[i+1] == 'p' || szFullCommand[i+1] == 'P' ||
                                szFullCommand[i+1] == 'r' || szFullCommand[i+1] == 'R' ||
                                szFullCommand[i+1] == 's' || szFullCommand[i+1] == 'S' ||
                                szFullCommand[i+1] == 't' || szFullCommand[i+1] == 'T' )
                                continue;
                            else { 
                                szOrig[0] = szFullCommand[i+1];
                                szOrig[1] = '\0';
                                k = 1;
                                OneCharacterSub = true;
                            }
                    }

                    if (!OneCharacterSub) {
                        for (unsigned int j=i+1; j < sizeof(szFullCommand); j++ )
                        {
                            if (szFullCommand[j] == ' ' || szFullCommand[j] == '\0' ) 
                                break;
                            else if (!isalnum(szFullCommand[j]))
                                break;
                            szOrig[k] = szFullCommand[j];
                            k++;
                        }
                    }
                    while (pSubLoop)
                    {
                        if (!_stricmp(szOrig, pSubLoop->szOrig)) 
                        {
                            sprintf_s( szSub, "%s", pSubLoop->szSub );
                            break;
                        }
                        pSubLoop = pSubLoop->pNext;
                    }
                    if (szSub[0] != '\0' ) {
                        szSubFullCommand.replace(i,k+1,szSub);
						sprintf_s( szFullCommand, "%s",szSubFullCommand.c_str() );
                    }
                    szOrig[0] = '\0';
                    szSub[0] = '\0';
                    k=0;
                    OneCharacterSub = false;
                    pSubLoop = pSubs;
                }
            }
			sprintf_s(szFullCommand, "%s", szSubFullCommand.c_str() );
			std::string sName = szCommand;
			std::transform(sName.begin(), sName.end(), sName.begin(), tolower);
			if (mAliases.find(sName) != mAliases.end()) {
				sprintf_s(szCommand,"%s%s",mAliases[sName].c_str(),szFullCommand+sName.size());
                strcpy_s(szFullCommand,szCommand); 
			}

            GetArg(szCommand,szFullCommand,1); 
            strcpy_s(szArgs, GetNextArg(szFullCommand)); 

            PMQCOMMAND pCommand=pCommands;
            while(pCommand)
            {
                if (pCommand->InGameOnly && gGameState!=GAMESTATE_INGAME)
                {
                    pCommand=pCommand->pNext;
                    continue;
                }
                int Pos=_strnicmp(szCommand,pCommand->Command,strlen(szCommand));
                if (Pos<0)
                {// command not found
                    break;
                }
                if (Pos==0)
                {
					if (pCommand->Parse && bAllowCommandParse) {
						ParseMacroParameter(pChar, szArgs);
					}
                    if (pCommand->EQ)
                    {
                        strcat_s(szCommand," "); 
						strcat_s(szCommand,szArgs);
                        Trampoline(pChar,szCommand); 
                    }
                    else
                    {
                        pCommand->Function(pChar,szArgs);
                    }
                    strcpy_s(szLastCommand,szFullCommand);
                    return;
                }
                pCommand=pCommand->pNext;
            }

            PBINDLIST pBind = pBindList;
			PMACROBLOCK pBlock = GetCurrentMacroBlock();
            while( pBind )
            {
                if( gGameState != GAMESTATE_INGAME )
                {
                    // Macro Binds only supported in-game
                    pBind = pBind->pNext;
                    continue;
                }

                int Pos = _strnicmp( szCommand, pBind->szName, strlen( szCommand ) );

                if( Pos == 0 )
                {
                    // found it!
                    if( pBind->szFuncName )
                    {
                        if( PCHARINFO pCharInfo = GetCharInfo() )
                        {
                            std::string sCallFunc( pBind->szFuncName );
                            sCallFunc += " ";
                            sCallFunc += szArgs;
							CHAR szCallFunc[MAX_STRING] = { 0 };
							strcpy_s(szCallFunc, sCallFunc.c_str());
							ParseMacroData(szCallFunc, MAX_STRING);
							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");
								}
							}
							//CHAR szOrg[MAX_STRING] = {"${Time}"};
							//ParseMacroData(szOrg, MAX_STRING);
							//WriteChatf("[%s] %s called",szOrg, szCallFunc.c_str());
							//Beep(1000, 100);
                        }
                    }
                    strcpy_s( szLastCommand, szFullCommand );
                    return;
                }

                pBind = pBind->pNext;
            }
        }
        Trampoline(pChar,szFullLine); 
		strcpy_s(szLastCommand,szFullCommand);
    } 
Ejemplo n.º 23
0
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);
}
Ejemplo n.º 24
0
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;
}