示例#1
0
文件: Detours.cpp 项目: oenayet/bwapi
void __fastcall CommandFilter(BYTE *buffer, DWORD length)
{
  if ( !buffer || !length )
    return;

  /* Filter commands using BWAPI rules */
  if ( BWAPI::BroodwarImpl.isFlagEnabled(BWAPI::Flag::UserInput) || 
       !BWAPI::BroodwarImpl.onStartCalled ||
       buffer[0] <= 0x0B ||
       (buffer[0] >= 0x0F && buffer[0] <= 0x12) ||
       (length >= 3 && buffer[0] == 0x13 && buffer[1] == 1)    || // Hotkey (select only)
       (buffer[0] >= 0x37 && buffer[0] <= 0x59) ||
       buffer[0] >= 0x5B )
  {
    // Custom select code
    if ( buffer[0] == 0x09 ||
         buffer[0] == 0x0A ||
         buffer[0] == 0x0B ||
         (length >= 3 && buffer[0] == 0x13 && buffer[1] == 1) ) // Select Units
    {
      // Do our own center view on hotkeys, since BWAPI introduces a bug that destroys this
      if ( length >= 3 && buffer[0] == 0x13 && buffer[1] == 1 ) // Recall Hotkey
      {
        DWORD thisHotkeyTime = GetTickCount();
        if ( lastHotkey == buffer[2] && (thisHotkeyTime - lastHotkeyTime) < 800 )
        {
          // do center view here
          BWAPI::BroodwarImpl.moveToSelectedUnits();
          lastHotkeyTime = 0;
          lastHotkey     = -1;
        }
        else
        {
          lastHotkeyTime = thisHotkeyTime;
          lastHotkey     = buffer[2];
        }
      }
      BWAPI::BroodwarImpl.wantSelectionUpdate = true;
      return;
    } // selections

    if ( buffer[0] == 0x0C ||
         (buffer[0] == 0x13 && !(buffer[1] & 1)) ||
         buffer[0] == 0x14 ||
         buffer[0] == 0x15 ||
         (buffer[0] >= 0x18 && buffer[0] <= 0x36) ||
         buffer[0] == 0x5A )
    {
      //reload the unit selection states (so that the user doesn't notice any changes in selected units in the Starcraft GUI.
      BW::Orders::Select sel = BW::Orders::Select(*BW::BWDATA_ClientSelectionCount, BW::BWDATA_ClientSelectionGroup);
      QueueGameCommand(&sel, sel.size);
    } // user select
    QueueGameCommand(buffer, length);
  }
}
示例#2
0
  bool UnitImpl::issueCommand(UnitCommand command)
  {
    if ( !canIssueCommand(command) )
      return false;
    
    // If the command optimizer has decided to take over
    if ( this->prepareIssueCommand(command) )
      return true;

    // Select High templar for morphing
    if (command.type == UnitCommandTypes::Use_Tech_Unit && command.target &&
       (command.extra == TechTypes::Archon_Warp || command.extra == TechTypes::Dark_Archon_Meld))
    {
      //select both units for archon warp or dark archon meld
      Unit sel2[2] = { command.unit, command.target };
      BW::Orders::Select sel(2, sel2);
      QueueGameCommand(&sel, sel.size());
      BroodwarImpl.apmCounter.addSelect();
    }
    else if (command.type != UnitCommandTypes::Unload || BroodwarImpl.commandOptimizer.level < 2)
    {
      // TODO this piece should be extracted to the CommandOptimizer
      static_cast<UnitImpl*>(command.unit)->orderSelect();   // Unload optimization (no select)
    }

    // Immediately execute the command
    BroodwarImpl.executeCommand( command );
    return true;
  }
示例#3
0
 //---------------------------------------------- ORDER SELECT ----------------------------------------------
 void UnitImpl::orderSelect()
 {
   Unit u = this;
   BW::Orders::Select sel = BW::Orders::Select(1, &u);
   QueueGameCommand(&sel, sel.size());
   BroodwarImpl.apmCounter.addSelect();
 }