General MQ2PEQMap Source(Titanium)
Reply
MQ2PEQMap Source(Titanium)
1. Click Start Menu->Run (win 7, type run in the search box, hit enter)
2. Type "CMD", Enter
3. navigate to your macroquest folder
4. Type "mkplugin MQ2PEQMap", Enter
5. Open your macroquest project
6. In the solution explorer window, right click the top item, "Solution 'Macroquest2' (xx projects)", and hit add->existing project.
7. In your MQ project folder there should be a folder named MQ2PEQMap, created in step 4. Open it and select "MQ2PEQMap.dsp"
8. MQ2PEQMap should now be a project listed in your solution explorer window. Find it and right click, add->new item...
9. Use this method to add 2 "C++ File (.cpp)" files, and 1 "Header File (.h)" :
MQ2PEQMapAPI.cpp
MQ2PEQMapCommands.cpp
MQ2PEQMap.h
10. Open those 3 files now to view the code, as well as MQ2MPEQMap.cpp which was created in step 4, and replace them with the code below.
11. compile normally

I don't have my GPL compliance comments in there, but this is basically a half assed hack job to just stop the display. The options still exist for NPCs, etc, but they are blocked. The edits consist of the plugin name change merely for destiction, and alterations to the switch in CanDisplaySpawn which I believe is in the API file. Edits occurred on 10 Oct 2009.

If someone really wants it I can take the time to go add the comments.

Note: sorry for posting this in thread form, The DL area is getting crowded enough without having individual plugins floating around. I'll add a download folder for individual plugins eventually and transition this over there.


MQ2PEQMapAPI.cpp
More +
#include "../MQ2Plugin.h"
#include "MQ2PEQMap.h"

#define pMap     ((PEQMAPWINDOW)pMapViewWnd)
typedef struct _MAPSPAWN
{
   PSPAWNINFO pSpawn;
   eSpawnType SpawnType;

   PMAPLABEL pMapLabel;
   PMAPLINE pVector;
   BOOL Highlight;
   BOOL Explicit;

   struct _MAPSPAWN *pLast;
   struct _MAPSPAWN *pNext;
} MAPSPAWN, *PMAPSPAWN;

#define FAKESPAWNTYPE 0xFF


PMAPSPAWN pActiveSpawns=0;

PMAPLABEL pLabelList=0;
PMAPLABEL pLabelListTail=0;
PMAPLINE  pLineList=0;
PMAPLINE  pLineListTail=0;



map<unsigned> SpawnMap;
map<unsigned> GroundItemMap;
map<PMAPLABEL> LabelMap;

BOOL Update=false;

#define CASTRADIUS_ANGLESIZE 10
PMAPLINE pCastRadius[(360/CASTRADIUS_ANGLESIZE)+1];

PMAPSPAWN pLastTarget=0;

PMAPLINE pTargetRadius[(360/CASTRADIUS_ANGLESIZE)+1];

PMAPLINE pTargetMelee[(360/CASTRADIUS_ANGLESIZE)+1];

PMAPLINE pTargetLine=0;


inline PMAPLINE InitLine()
{
   PMAPLINE pLine=new MAPLINE;
   pLine->pPrev=0;
   pLine->pNext=pLineList;
   if (pLineList)
      pLineList->pPrev=pLine;
   else
      pLineListTail=pLine;
   pLineList=pLine;
   return pLine;
}

inline void DeleteLine(PMAPLINE pLine)
{
   if (pLine->pNext)
      pLine->pNext->pPrev=pLine->pPrev;
   else
      pLineListTail=pLine->pPrev;
   if (pLine->pPrev)
      pLine->pPrev->pNext=pLine->pNext;
   else
      pLineList=pLine->pNext;
   delete pLine;
}

inline PMAPLABEL InitLabel(PMAPSPAWN pMapSpawn)
{
   PMAPLABEL pLabel=new MAPLABEL;
   pLabel->pPrev=0;
   pLabel->pNext=pLabelList;
   if (pLabelList)
      pLabelList->pPrev=pLabel;
   else
      pLabelListTail=pLabel;
   pLabelList=pLabel;
   LabelMap[pLabel]=pMapSpawn;
   return pLabel;
}

inline void DeleteLabel(PMAPLABEL pLabel)
{
   LabelMap[pLabel]=0;
   if (pLabel->pNext)
      pLabel->pNext->pPrev=pLabel->pPrev;
   else
      pLabelListTail=pLabel->pPrev;
   if (pLabel->pPrev)
      pLabel->pPrev->pNext=pLabel->pNext;
   else
      pLabelList=pLabel->pNext;
   delete pLabel;
}

inline PMAPSPAWN InitSpawn()
{
   PMAPSPAWN pSpawn=new MAPSPAWN;
   pSpawn->pLast=0;
   pSpawn->pNext=pActiveSpawns;
   if (pActiveSpawns)
      pActiveSpawns->pLast=pSpawn;
   pActiveSpawns=pSpawn;
   return pSpawn;   
}

inline void DeleteSpawn(PMAPSPAWN pMapSpawn)
{
   if (pMapSpawn->pNext)
      pMapSpawn->pNext->pLast=pMapSpawn->pLast;
   if (pMapSpawn->pLast)
      pMapSpawn->pLast->pNext=pMapSpawn->pNext;
   else
      pActiveSpawns=pMapSpawn->pNext;
   delete pMapSpawn;
}

PCHAR GenerateSpawnName(PSPAWNINFO pSpawn, PCHAR NameString);
DWORD GetSpawnColor(eSpawnType Type, PSPAWNINFO pSpawn);
PMAPLABEL GenerateLabel(PMAPSPAWN pMapSpawn, DWORD Color);
PMAPLINE GenerateVector(PMAPSPAWN pMapSpawn);
BOOL CanDisplaySpawn(eSpawnType Type, PSPAWNINFO pSpawn);

VOID MapInit()
{
   for (unsigned long i = 0 ; i <360>Type!=FAKESPAWNTYPE)
      SpawnMap[pNewSpawn->SpawnID]=pMapSpawn;
   pMapSpawn->SpawnType=Type;
   pMapSpawn->pSpawn=pNewSpawn;
   pMapSpawn->pMapLabel = GenerateLabel(pMapSpawn,GetSpawnColor(Type,pNewSpawn));
   pMapSpawn->Explicit = ExplicitAllow;
   if (IsOptionEnabled(MAPFILTER_Vector))
      pMapSpawn->pVector= GenerateVector(pMapSpawn);
   else
      pMapSpawn->pVector=0;

   pMapSpawn->Highlight=false;

#if 0
   //Debugging
   if (Type == SPAWN_CORPSE || Type == ITEM )
   {
      sprintf(buf, "AddSpawn(Corpse or Item): Name: %s, Type: %d, BodyType: %d",
         pMapSpawn->pSpawn->Name, pMapSpawn->pSpawn->Type, pMapSpawn->pSpawn->BodyType );
      DebugSpew(buf);
   }
#endif

   return pMapSpawn;
}

void RemoveSpawn(PMAPSPAWN pMapSpawn)
{
   free(pMapSpawn->pMapLabel->Label);
   DeleteLabel(pMapSpawn->pMapLabel);

   if (pMapSpawn->pVector)
   {
      DeleteLine(pMapSpawn->pVector);
      pMapSpawn->pVector=0;
   }

   if (pMapSpawn->pSpawn->Type==FAKESPAWNTYPE)
      delete pMapSpawn->pSpawn;
   else
      SpawnMap[pMapSpawn->pSpawn->SpawnID]=0;

   if (pMapSpawn==pLastTarget)
      pLastTarget=0;
   DeleteSpawn(pMapSpawn);
}

bool RemoveSpawn(PSPAWNINFO pSpawn)
{
   PMAPSPAWN pMapSpawn=SpawnMap[pSpawn->SpawnID];
   if (pMapSpawn)
   {
      RemoveSpawn(pMapSpawn);
      return true;
   }
   return false;
}

void AddGroundItem(PGROUNDITEM pGroundItem)
{
   PSPAWNINFO pFakeSpawn=new SPAWNINFO;
   memset(pFakeSpawn,0,sizeof(SPAWNINFO));
   GetFriendlyNameForGroundItem(pGroundItem,pFakeSpawn->Name);
    pFakeSpawn->X = pGroundItem->X;
    pFakeSpawn->Y = pGroundItem->Y;
    pFakeSpawn->Z = pGroundItem->Z;

   pFakeSpawn->HPCurrent = 1;
   pFakeSpawn->HPMax = 1;
   pFakeSpawn->pActorInfo = &EnviroActor;
   pFakeSpawn->Heading=pGroundItem->Heading;
   pFakeSpawn->Race = pGroundItem->DropID;

   pFakeSpawn->Type=FAKESPAWNTYPE;
   PMAPSPAWN pMapSpawn=AddSpawn(pFakeSpawn);
   if (pMapSpawn)
      GroundItemMap[pGroundItem->DropID]=pMapSpawn;
   else
      delete pFakeSpawn;
}

void RemoveGroundItem(PGROUNDITEM pGroundItem)
{
   PMAPSPAWN pMapSpawn=GroundItemMap[pGroundItem->DropID];
   if (pMapSpawn)
   {
      GroundItemMap[pGroundItem->DropID]=0;
      RemoveSpawn(pMapSpawn);
   }
}


void MapGenerate()
{
   if (!IsOptionEnabled(MAPFILTER_All))
      return;
   PSPAWNINFO pSpawn=(PSPAWNINFO)pSpawnList;
   while(pSpawn)
   {
      AddSpawn(pSpawn);
      pSpawn=pSpawn->pNext;
   }   
   if (!IsOptionEnabled(MAPFILTER_Ground))
      return;
   PGROUNDITEM pItem=(PGROUNDITEM)pItemList;
   while(pItem)
   {
      AddGroundItem(pItem);
      pItem=pItem->pNext;
   }   
}

void MapClear()
{
   GroundItemMap.clear();
   SpawnMap.clear();



   while(pActiveSpawns)
   {
      PMAPSPAWN pNextActive=pActiveSpawns->pNext;
      
      PMAPLABEL pLabel=pActiveSpawns->pMapLabel;
      DebugTry(free(pLabel->Label));
      DeleteLabel(pLabel);

      if (pActiveSpawns->pVector)
      {
         DeleteLine(pActiveSpawns->pVector);
         pActiveSpawns->pVector=0;
      }

      if (pActiveSpawns->pSpawn->Type==FAKESPAWNTYPE) // fake!
      {
         delete pActiveSpawns->pSpawn;
      }

      DeleteSpawn(pActiveSpawns);
      pActiveSpawns=pNextActive;
   }

   pLastTarget=0;

   if (pTargetLine)
   {
      DeleteLine(pTargetLine);
      pTargetLine=0;
   }

   if (pCastRadius[0])
   {
      for (unsigned long i = 0 ; i < (360/CASTRADIUS_ANGLESIZE) ; i++)
      {
         DeleteLine(pCastRadius[i]);
         pCastRadius[i]=0;
      }
   }
   if (pTargetRadius[0])
   {
      for (unsigned long i = 0 ; i < (360/CASTRADIUS_ANGLESIZE) ; i++)
      {
         DeleteLine(pTargetRadius[i]);
         pTargetRadius[i]=0;
      }
   }
   if (pTargetMelee[0])
   {
      for (unsigned long i = 0 ; i <360>pSpawn!=(PSPAWNINFO)pTarget)
   {
      if (pLastTarget->pSpawn==&EnviroTarget || !CanDisplaySpawn(pLastTarget->SpawnType,pLastTarget->pSpawn))
      {
         RemoveSpawn(pLastTarget);
      }
      pLastTarget=0;
   }
   
   if (pTarget && IsOptionEnabled(MAPFILTER_Target))
   {
      pLastTarget=SpawnMap[((PSPAWNINFO)pTarget)->SpawnID];
      if (!pLastTarget)
      {
         pLastTarget=AddSpawn((PSPAWNINFO)pTarget);
      }
   }

   pMapSpawn=pActiveSpawns;
#ifndef zWarp
   gSpewToFile=1;
#endif

   while(pMapSpawn)
   {
#if 0
      // Debugging
      if ( pMapSpawn->pSpawn->Type == SPAWN_PLAYER )
      {
         if ( pMapSpawn->pSpawn->BodyType != 1 )
         {
            sprintf(buf, "MapUpdate: Name: %s, Type: %d, BodyType: %d",
               pMapSpawn->pSpawn->Name, pMapSpawn->pSpawn->Type, pMapSpawn->pSpawn->BodyType );
            DebugSpew(buf);
         }
      }
      else if ( pMapSpawn->pSpawn->Type == SPAWN_NPC )
      {
         if ( pMapSpawn->pSpawn->BodyType != 1 && pMapSpawn->pSpawn->BodyType != 11 &&
             pMapSpawn->pSpawn->BodyType != 33 && pMapSpawn->pSpawn->BodyType != 65 &&
             pMapSpawn->pSpawn->BodyType != 66 && pMapSpawn->pSpawn->BodyType != 67 &&
             pMapSpawn->pSpawn->BodyType != 21 && pMapSpawn->pSpawn->BodyType != 23 &&
             pMapSpawn->pSpawn->BodyType != 34 && pMapSpawn->pSpawn->BodyType != 3  &&
             pMapSpawn->pSpawn->BodyType != 24 )
         {
            sprintf(buf, "MapUpdate: Name: %s, Type: %d, BodyType: %d",
               pMapSpawn->pSpawn->Name, pMapSpawn->pSpawn->Type, pMapSpawn->pSpawn->BodyType );
            DebugSpew(buf);
         }
      }
      else
      {
            sprintf(buf, "MapUpdate: Name: %s, Type: %d, BodyType: %d",
               pMapSpawn->pSpawn->Name, pMapSpawn->pSpawn->Type, pMapSpawn->pSpawn->BodyType );
            DebugSpew(buf);
      }

      //End Debugging
#endif

      //Starting New Checks
      if (!pMapSpawn->Explicit && !CanDisplaySpawn(GetSpawnType(pMapSpawn->pSpawn),pMapSpawn->pSpawn))
      {
         PMAPSPAWN pNext=pMapSpawn->pNext;
         RemoveSpawn(pMapSpawn);
         pMapSpawn=pNext;
         continue;
      }
      //End New Checks

      pMapSpawn->pMapLabel->Location.X = -pMapSpawn->pSpawn->X;
      pMapSpawn->pMapLabel->Location.Y = -pMapSpawn->pSpawn->Y;
      pMapSpawn->pMapLabel->Location.Z = pMapSpawn->pSpawn->Z;

      if (pMapSpawn->Highlight)
      {
         pMapSpawn->pMapLabel->Color.ARGB=HighlightColor;
      }
      else
      {
         Type=GetSpawnType(pMapSpawn->pSpawn);
         if (Type!=pMapSpawn->SpawnType)
         {
            if (!CanDisplaySpawn(Type,pMapSpawn->pSpawn))
            {
               PMAPSPAWN pNext=pMapSpawn->pNext;
               RemoveSpawn(pMapSpawn);
               pMapSpawn=pNext;
               continue;
            }

            pMapSpawn->SpawnType=Type;
            free(pMapSpawn->pMapLabel->Label);
            pMapSpawn->pMapLabel->Label=GenerateSpawnName(pMapSpawn->pSpawn,MapNameString);

         }
         pMapSpawn->pMapLabel->Color.ARGB=GetSpawnColor(pMapSpawn->SpawnType,pMapSpawn->pSpawn);
      }

      if (pMapSpawn->pVector)
      {
         if (pMapSpawn->pSpawn->SpeedRun>0) {
            pMapSpawn->pVector->Start.X = -pMapSpawn->pSpawn->X;
            pMapSpawn->pVector->Start.Y = -pMapSpawn->pSpawn->Y;
            pMapSpawn->pVector->Start.Z = pMapSpawn->pSpawn->Z;
            pMapSpawn->pVector->End.X = -pMapSpawn->pSpawn->X-pMapSpawn->pSpawn->SpeedX*4;
            pMapSpawn->pVector->End.Y = -pMapSpawn->pSpawn->Y-pMapSpawn->pSpawn->SpeedY*4;
            pMapSpawn->pVector->End.Z = pMapSpawn->pSpawn->Z+pMapSpawn->pSpawn->SpeedZ*4;
         } else {
         pMapSpawn->pVector->Start.X = -pMapSpawn->pSpawn->X;
         pMapSpawn->pVector->Start.Y = -pMapSpawn->pSpawn->Y;
         pMapSpawn->pVector->Start.Z = pMapSpawn->pSpawn->Z;
         pMapSpawn->pVector->End.X =-pMapSpawn->pSpawn->X-sinf(pMapSpawn->pSpawn->Heading/256.0f*(FLOAT)PI)*4;
         pMapSpawn->pVector->End.Y =-pMapSpawn->pSpawn->Y-cosf(pMapSpawn->pSpawn->Heading/256.0f*(FLOAT)PI)*4;
         pMapSpawn->pVector->End.Z =pMapSpawn->pSpawn->Z;
         }
      }

      pMapSpawn=pMapSpawn->pNext;
   }

   if (IsOptionEnabled(MAPFILTER_CastRadius))
   {
      unsigned long Angle=0;
      for (unsigned long i = 0 ; i <360>Layer=2;
         }

         pCastRadius[i]->Color.ARGB=MapFilterOptions[MAPFILTER_CastRadius].Color;
         pCastRadius[i]->Start.Z=pCharInfo->pSpawn->Z;
         pCastRadius[i]->End.Z=pCharInfo->pSpawn->Z;
         pCastRadius[i]->Start.X=-pCharInfo->pSpawn->X + (FLOAT)MapFilterOptions[MAPFILTER_CastRadius].Enabled*cosf((FLOAT)Angle/180.0f*(FLOAT)PI);
         pCastRadius[i]->Start.Y=-pCharInfo->pSpawn->Y + (FLOAT)MapFilterOptions[MAPFILTER_CastRadius].Enabled*sinf((FLOAT)Angle/180.0f*(FLOAT)PI);;
         pCastRadius[i]->End.X=-pCharInfo->pSpawn->X + (FLOAT)MapFilterOptions[MAPFILTER_CastRadius].Enabled*cosf((FLOAT)(Angle+CASTRADIUS_ANGLESIZE)/180.0f*(FLOAT)PI);
         pCastRadius[i]->End.Y=-pCharInfo->pSpawn->Y + (FLOAT)MapFilterOptions[MAPFILTER_CastRadius].Enabled*sinf((FLOAT)(Angle+CASTRADIUS_ANGLESIZE)/180.0f*(FLOAT)PI);
      }
   }
   else if (pCastRadius[0])
   {
      for (unsigned long i = 0 ; i < (360/CASTRADIUS_ANGLESIZE) ; i++)
      {
         DeleteLine(pCastRadius[i]);
         pCastRadius[i]=0;
      }
   }

   if (IsOptionEnabled(MAPFILTER_Group))
   {
      for (unsigned long i = 0 ; i <5>pMember[i])
         if (pMapSpawn=SpawnMap[pGroup->pMember[i]->SpawnID])
         {
            pMapSpawn->pMapLabel->Color.ARGB=MapFilterOptions[MAPFILTER_Group].Color;
         }
      }
   }

   if (pLastTarget)
   {
      pLastTarget->pMapLabel->Color.ARGB=MapFilterOptions[MAPFILTER_Target].Color;
      free(pLastTarget->pMapLabel->Label);
      pLastTarget->pMapLabel->Label=GenerateSpawnName(pLastTarget->pSpawn,MapTargetNameString);         

      if (IsOptionEnabled(MAPFILTER_TargetLine))
      {
         if (!pTargetLine)
         {
            pTargetLine=InitLine();
            pTargetLine->Layer=2;
         }
         pTargetLine->Color.ARGB=MapFilterOptions[MAPFILTER_Target].Color;
         pTargetLine->Start.X=-pCharInfo->pSpawn->X;
         pTargetLine->Start.Y=-pCharInfo->pSpawn->Y;
         pTargetLine->Start.Z=pCharInfo->pSpawn->Z;

         pTargetLine->End.X=-((PSPAWNINFO)pTarget)->X;
         pTargetLine->End.Y=-((PSPAWNINFO)pTarget)->Y;
         pTargetLine->End.Z=((PSPAWNINFO)pTarget)->Z;
      }
      else if (pTargetLine)
      {
         DeleteLine(pTargetLine);
         pTargetLine=0;
      }

      if (IsOptionEnabled(MAPFILTER_TargetRadius))
      {
         unsigned long Angle=0;
         for (unsigned long i = 0 ; i <360>Layer=2;
            }

            pTargetRadius[i]->Color.ARGB=MapFilterOptions[MAPFILTER_TargetRadius].Color;
            pTargetRadius[i]->Start.Z=((PSPAWNINFO)pTarget)->Z;
            pTargetRadius[i]->End.Z=((PSPAWNINFO)pTarget)->Z;
            pTargetRadius[i]->Start.X=-((PSPAWNINFO)pTarget)->X + (FLOAT)MapFilterOptions[MAPFILTER_TargetRadius].Enabled*cosf((FLOAT)Angle/180.0f*(FLOAT)PI);
            pTargetRadius[i]->Start.Y=-((PSPAWNINFO)pTarget)->Y + (FLOAT)MapFilterOptions[MAPFILTER_TargetRadius].Enabled*sinf((FLOAT)Angle/180.0f*(FLOAT)PI);;
            pTargetRadius[i]->End.X=-((PSPAWNINFO)pTarget)->X + (FLOAT)MapFilterOptions[MAPFILTER_TargetRadius].Enabled*cosf((FLOAT)(Angle+CASTRADIUS_ANGLESIZE)/180.0f*(FLOAT)PI);
            pTargetRadius[i]->End.Y=-((PSPAWNINFO)pTarget)->Y + (FLOAT)MapFilterOptions[MAPFILTER_TargetRadius].Enabled*sinf((FLOAT)(Angle+CASTRADIUS_ANGLESIZE)/180.0f*(FLOAT)PI);
         }
      }
      else if (pTargetRadius[0])
      {
         for (unsigned long i = 0 ; i < (360/CASTRADIUS_ANGLESIZE) ; i++)
         {
            DeleteLine(pTargetRadius[i]);
            pTargetRadius[i]=0;
         }
      }

      if (IsOptionEnabled(MAPFILTER_TargetMelee))
      {
         unsigned long Angle=0;
         for (unsigned long i = 0 ; i <360>Layer=2;
            }

            pTargetMelee[i]->Color.ARGB=MapFilterOptions[MAPFILTER_TargetMelee].Color;
            pTargetMelee[i]->Start.Z=((PSPAWNINFO)pTarget)->Z;
            pTargetMelee[i]->End.Z=((PSPAWNINFO)pTarget)->Z;
            FLOAT MaxMelee;
            if (MapFilterOptions[MAPFILTER_TargetMelee].Enabled==1)
               MaxMelee=get_melee_range(pLocalPlayer,pTarget);
            else
               MaxMelee=get_melee_range(pTarget,pTarget);
            pTargetMelee[i]->Start.X=-((PSPAWNINFO)pTarget)->X + MaxMelee*cosf((FLOAT)Angle/180.0f*(FLOAT)PI);
            pTargetMelee[i]->Start.Y=-((PSPAWNINFO)pTarget)->Y + MaxMelee*sinf((FLOAT)Angle/180.0f*(FLOAT)PI);;
            pTargetMelee[i]->End.X=-((PSPAWNINFO)pTarget)->X + MaxMelee*cosf((FLOAT)(Angle+CASTRADIUS_ANGLESIZE)/180.0f*(FLOAT)PI);
            pTargetMelee[i]->End.Y=-((PSPAWNINFO)pTarget)->Y + MaxMelee*sinf((FLOAT)(Angle+CASTRADIUS_ANGLESIZE)/180.0f*(FLOAT)PI);
         }
      }
      else if (pTargetMelee[0])
      {
         for (unsigned long i = 0 ; i < (360/CASTRADIUS_ANGLESIZE) ; i++)
         {
            DeleteLine(pTargetMelee[i]);
            pTargetMelee[i]=0;
         }
      }
   }
   else
   {
      if (pTargetRadius[0])
      {
         for (unsigned long i = 0 ; i < (360/CASTRADIUS_ANGLESIZE) ; i++)
         {
            DeleteLine(pTargetRadius[i]);
            pTargetRadius[i]=0;
         }
      }

      if (pTargetMelee[0])
      {
         for (unsigned long i = 0 ; i <360>pLabels;
      if (IsOptionEnabled(MAPFILTER_NormalLabels))
         pLabelListTail->pNext=pMap->pLabels;
      pMap->pLabels=pLabelList;
   }

   if (pLineList)
   {
      pLineListTail->pNext=pMap->pLines;
      pMap->pLines=pLineList;
   }
}

void MapDetach()
{
   if (pLabelList)
   {
      pMap->pLabels=pActualLineList;
      pLabelListTail->pNext=0;
   }
   if (pLineList)
   {
      pMap->pLines=pLineListTail->pNext;
      pLineListTail->pNext=0;
   }
}

void MapSelectTarget()
{
   if (!pCurrentMapLabel)
      return;
   PMAPSPAWN pMapSpawn=LabelMap[pCurrentMapLabel];
   if (!pMapSpawn)
      return;
   if (pMapSpawn->SpawnType==ITEM)
   {
      EnviroTarget=*pMapSpawn->pSpawn;
      EnviroTarget.Type = SPAWN_NPC;
      EnviroTarget.SpawnID=2999;
      pTarget = (EQPlayer*)&EnviroTarget;             
   }
   else
   {
      DWORD Flags=pWndMgr->GetKeyboardFlags();
      PCHARINFO pCharInfo=GetCharInfo();
      if (pCharInfo && Flags && MapSpecialClickString[Flags][0])
      {
         PCHAR Cmd=GenerateSpawnName(pMapSpawn->pSpawn,MapSpecialClickString[Flags]);
#ifndef ISXEQ
         DoCommand(pCharInfo->pSpawn,Cmd);
#else
         pISInterface->ExecuteCommand(Cmd);
#endif
         free(Cmd);
      }
      else
         pTarget=(EQPlayer*)pMapSpawn->pSpawn;
   }
}

DWORD MapHighlight(SEARCHSPAWN *pSearch)
{
   if (!pSearch)
   {
      PMAPSPAWN pMapSpawn=pActiveSpawns;
      while(pMapSpawn)
      {
         pMapSpawn->Highlight=false;
         pMapSpawn=pMapSpawn->pNext;
      }
      return 0;
   }
   else
   {
      PCHARINFO pCharInfo=GetCharInfo();
      if (!pCharInfo)
         return 0;
      PMAPSPAWN pMapSpawn=pActiveSpawns;
      unsigned long Count=0;
      while(pMapSpawn)
      {
         // update!
         if (SpawnMatchesSearch(pSearch,pCharInfo->pSpawn,pMapSpawn->pSpawn))
         {
            pMapSpawn->Highlight=true;
            Count++;
         }

         pMapSpawn=pMapSpawn->pNext;
      }
      return Count;
   }
}

PCHAR GenerateSpawnName(PSPAWNINFO pSpawn, PCHAR NameString)
{
   CHAR Name[MAX_STRING]={0};
   unsigned long outpos=0;
#define AddString(str) {strcpy(&Name[outpos],str);outpos+=strlen(&Name[outpos]);}
#define AddInt(yourint) {_itoa(yourint,&Name[outpos],10);outpos+=strlen(&Name[outpos]);}
#define AddFloat10th(yourfloat) {outpos+=sprintf(&Name[outpos],"%.1f",yourfloat);}
   for (unsigned long N = 0 ; NameString[N] ; N++)
   {
      if (NameString[N]=='%')
      {
         N++;
         switch(NameString[N])
         {
         case 'N':// cleaned up name
            strcpy(&Name[outpos],pSpawn->Name);
            CleanupName(&Name[outpos],FALSE);
            outpos+=strlen(&Name[outpos]);
            break;
         case 'n':// original name
            AddString(pSpawn->Name);
            break;
         case 'h':// current health %
            AddInt(pSpawn->HPCurrent);
            break;
         case 'i':
            AddInt(pSpawn->SpawnID);
            break;
         case 'x':
            AddFloat10th(pSpawn->X);
            break;
         case 'y':
            AddFloat10th(pSpawn->Y);
            break;
         case 'z':
            AddFloat10th(pSpawn->Z);
            break;
         case 'R':
            AddString(pEverQuest->GetRaceDesc(pSpawn->Race));
            break;
         case 'C':
            AddString(GetClassDesc(pSpawn->Class));
            break;
         case 'c':
            AddString(pEverQuest->GetClassThreeLetterCode(pSpawn->Class));
            break;
         case 'l':
            AddInt(pSpawn->Level);
            break;
         case '%':
            Name[outpos++]=NameString[N];
            break;
         }
      }
      else
         Name[outpos++]=NameString[N];
   }
   Name[outpos]=0;

   PCHAR ret=(PCHAR)malloc(strlen(Name)+1);
   strcpy(ret,Name);
   return ret;
}

BOOL CanDisplaySpawn(eSpawnType Type, PSPAWNINFO pSpawn)
{
   if (!pSpawn)
      return FALSE;

   if ( (Type == PC || Type == NPC) && (!pSpawn->pActorInfo) )
      return FALSE;

   if ((pSpawn==(PSPAWNINFO)pTarget) && IsOptionEnabled(MAPFILTER_Target) && Type == PC)
   {
      return TRUE;
   }
   if (IsOptionEnabled(MAPFILTER_Custom))
   {
      if (PCHARINFO pCharInfo=GetCharInfo())
         return SpawnMatchesSearch(&MapFilterCustom,pCharInfo->pSpawn,pSpawn);
   }
   switch(Type)
   {
   case PC:
      return IsOptionEnabled(MAPFILTER_PC);
   case NPC:
      return FALSE;
   case CORPSE:
      return IsOptionEnabled(MAPFILTER_Corpse);
   case ITEM:
      return FALSE;
   case UNTARGETABLE:
      return FALSE;
   case TIMER:
      return FALSE;
   case TRAP:
      return FALSE;
   case TRIGGER:
      return FALSE;
   case CHEST:
      return FALSE;
   case PET:
      return IsOptionEnabled(MAPFILTER_Pet);
   case MOUNT:
      return IsOptionEnabled(MAPFILTER_Mount);
   }
   return TRUE;
}

inline DWORD GetSpawnColor(eSpawnType Type, PSPAWNINFO pSpawn)
{
   PCHARINFO pChar=GetCharInfo();
   if (!pChar)
      return 0;

   switch(Type)
   {
   case PC:
      if (IsOptionEnabled(MAPFILTER_PCConColor))
         return ConColorToARGB(ConColor(pSpawn));
      return MapFilterOptions[MAPFILTER_PC].Color;
   case NPC:
      if (IsOptionEnabled(MAPFILTER_NPCConColor))
         return ConColorToARGB(ConColor(pSpawn));
      return MapFilterOptions[MAPFILTER_NPC].Color;
   case CORPSE:
      return MapFilterOptions[MAPFILTER_Corpse].Color;
   case UNTARGETABLE:
      return MapFilterOptions[MAPFILTER_Untargetable].Color;
   case CHEST:
      return MapFilterOptions[MAPFILTER_Chest].Color;
   case TRIGGER:
      return MapFilterOptions[MAPFILTER_Trigger].Color;
   case TIMER:
      return MapFilterOptions[MAPFILTER_Timer].Color;
   case TRAP:
      return MapFilterOptions[MAPFILTER_Trap].Color;
   case ITEM:
      return MapFilterOptions[MAPFILTER_Ground].Color;
   case MOUNT:
      return MapFilterOptions[MAPFILTER_Mount].Color;
   case PET:
      return MapFilterOptions[MAPFILTER_Pet].Color;
   }
   return 0;
}

PMAPLABEL GenerateLabel(PMAPSPAWN pMapSpawn, DWORD Color)
{
   PMAPLABEL pLabel=InitLabel(pMapSpawn);
    pLabel->Location.X = -pMapSpawn->pSpawn->X;
    pLabel->Location.Y = -pMapSpawn->pSpawn->Y;
    pLabel->Location.Z = pMapSpawn->pSpawn->Z;
    pLabel->Layer = 2;
    pLabel->Size = 3;
    pLabel->Label = GenerateSpawnName(pMapSpawn->pSpawn,MapNameString);
    pLabel->Color.ARGB = Color;
    pLabel->Width = 20;
    pLabel->Height= 14;
    pLabel->unk_0x2c = 0;
   pLabel->unk_0x30 = 0;
   return pLabel;
}

PMAPLINE GenerateVector(PMAPSPAWN pMapSpawn)
{

   PMAPLINE pNewLine = InitLine();
      
        if (pMapSpawn->pSpawn->SpeedRun>0) {
         pNewLine->Start.X = -pMapSpawn->pSpawn->X;
         pNewLine->Start.Y = -pMapSpawn->pSpawn->Y;
         pNewLine->Start.Z = pMapSpawn->pSpawn->Z;
         pNewLine->End.X = -pMapSpawn->pSpawn->X-pMapSpawn->pSpawn->SpeedX*4;
         pNewLine->End.Y = -pMapSpawn->pSpawn->Y-pMapSpawn->pSpawn->SpeedY*4;
         pNewLine->End.Z = pMapSpawn->pSpawn->Z+pMapSpawn->pSpawn->SpeedZ*4;
        } else {
           pNewLine->Start.X = -pMapSpawn->pSpawn->X;
           pNewLine->Start.Y = -pMapSpawn->pSpawn->Y;
           pNewLine->Start.Z = pMapSpawn->pSpawn->Z;
           pNewLine->End.X =-pMapSpawn->pSpawn->X-sinf(pMapSpawn->pSpawn->Heading/256.0f*(FLOAT)PI)*4;
           pNewLine->End.Y =-pMapSpawn->pSpawn->Y-cosf(pMapSpawn->pSpawn->Heading/256.0f*(FLOAT)PI)*4;
           pNewLine->End.Z =pMapSpawn->pSpawn->Z;
        }



    pNewLine->Layer = 2;
    pNewLine->Color = pMapSpawn->pMapLabel->Color;

   return pNewLine;   
}

DWORD MapHide(SEARCHSPAWN &Search)
{
   PCHARINFO pCharInfo=GetCharInfo();
   if (!pCharInfo)
      return 0;
   PMAPSPAWN pMapSpawn=pActiveSpawns;
   unsigned long Count=0;
   while(pMapSpawn)
   {
      if (pMapSpawn->pSpawn->Type!=FAKESPAWNTYPE && SpawnMatchesSearch(&Search,pCharInfo->pSpawn,pMapSpawn->pSpawn))
      {
         PMAPSPAWN pNext=pMapSpawn->pNext;
         RemoveSpawn(pMapSpawn);
         pMapSpawn=pNext;
         Count++;
      }
      else
         pMapSpawn=pMapSpawn->pNext;
   }
   return Count;
}

DWORD MapShow(SEARCHSPAWN &Search)
{
   PCHARINFO pCharInfo=GetCharInfo();
   if (!pCharInfo)
      return 0;

   PSPAWNINFO pSpawn=(PSPAWNINFO)pSpawnList;
   unsigned long Count=0;
   while(pSpawn)
   {
      if (!SpawnMap[pSpawn->SpawnID] && SpawnMatchesSearch(&Search,pCharInfo->pSpawn,pSpawn))
      {
         AddSpawn(pSpawn,true);
         Count++;
      }
      pSpawn=pSpawn->pNext;
   }
   return Count;
}

#ifndef ISXEQ
BOOL dataMapSpawn(PCHAR szIndex, MQ2TYPEVAR &Ret)
#else
bool dataMapSpawn(int argc, char *argv[], MQ2TYPEVAR &Ret)
#endif
{
   if (!pCurrentMapLabel)
      return false;
   if (PMAPSPAWN pMapSpawn=LabelMap[pCurrentMapLabel])
   {
      Ret.Ptr=pMapSpawn->pSpawn;
      Ret.Type=pSpawnType;
      return true;
   }
   return false;
}



MQ2MPEQMap.cpp
More +
// MQ2Map.cpp : Defines the entry point for the DLL application.
//

// PLUGIN_API is only to be used for callbacks.  All existing callbacks at this time
// are shown below. Remove the ones your plugin does not use.  Always use Initialize
// and Shutdown for setup and cleanup, do NOT do it in DllMain.


#include "../MQ2Plugin.h"
#include "MQ2PEQMap.h"
PreSetup("MQ2PEQMap");



unsigned long bmMapRefresh=0;

DWORD HighlightColor=0xFF700070;

CHAR MapSpecialClickString[16][MAX_STRING]=
{
   "",// unused, will always target
   "",//SHIFT
   "/maphide id %i",//CTRL
   "",//CTRL|SHIFT
   "/highlight id %i",//LALT
   "",//LALT|SHIFT
   "",//LALT|CTRL
   "",//LALT|SHIFT|CTRL
   "",//RALT
   "",//RALT|SHIFT
   "",//RALT|CTRL
   "",//RALT|SHIFT|CTRL
   "",//RALT|LALT
   "",//RALT|LALT|SHIFT
   "",//RALT|LALT|CTRL
   "" //RALT|LALT|SHIFT|CTRL
};

CHAR MapNameString[MAX_STRING]={"%N"};
CHAR MapTargetNameString[MAX_STRING]={"%N"};
SEARCHSPAWN MapFilterCustom = {0};
MAPFILTER MapFilterOptions[] = {
    {"All",          TRUE,-1,         TRUE,MAPFILTER_Invalid,TRUE,   "Enables/disables map functions"},
    {"PC",           FALSE,0xFF00FF,   TRUE,MAPFILTER_All,TRUE,   "Displays PCs"},
    {"PCConColor",   FALSE,-1,         TRUE,MAPFILTER_PC,FALSE,   "Displays PCs in consider colors"},
   {"Group",       FALSE,0x0080C0,         TRUE,MAPFILTER_PC,FALSE,   "Displays group members in a specific color"},
    {"Mount",        FALSE,0x707070,   TRUE,MAPFILTER_All,TRUE,   "Displays mounts"},
    {"NPC",          FALSE,0x404040,   TRUE,MAPFILTER_All,TRUE,   "Displays NPCs"},
    {"NPCConColor",  FALSE,-1,         TRUE,MAPFILTER_NPC,FALSE,   "Displays NPCs in consider colors"},
    {"Untargetable", FALSE,0x404040,   TRUE,MAPFILTER_All,TRUE,   "Displays Untargetable NPCs"},
    {"Pet",          FALSE,0x707070,   TRUE,MAPFILTER_All,TRUE,   "Displays pets"},
    {"Corpse",       FALSE,0x00C000,   TRUE,MAPFILTER_All,TRUE,   "Displays corpses"},
    {"Chest",        FALSE,0xC08000,   TRUE,MAPFILTER_All,TRUE,   "Displays chestesses"},
    {"Trigger",      FALSE,0xC08000,   TRUE,MAPFILTER_All,TRUE,   "Displays hidden triggers"},
    {"Trap",       FALSE,0xC08000,   TRUE,MAPFILTER_All,TRUE,    "Displays hidden traps"},
    {"Timer",        FALSE,0xC08000,   TRUE,MAPFILTER_All,TRUE,   "Displays hidden timers"},
    {"Ground",       FALSE,0xC0C0C0,   TRUE,MAPFILTER_All,TRUE,   "Displays ground items"},
    {"Target",       FALSE,0xC00000,   TRUE,MAPFILTER_All,FALSE,   "Displays your target"},
    {"TargetLine",   FALSE,0x808080,   TRUE,MAPFILTER_Target,FALSE,  "Displays a line to your target"},
    {"TargetRadius", FALSE,0x808080,   FALSE,MAPFILTER_Target,FALSE,  "Sets radius of a circle around your target to # (omit or set to 0 to disable)"},
   {"TargetMelee",  FALSE,0xFF8080,   FALSE,MAPFILTER_Target,FALSE,  "Draws a melee-range circle around your target"},
    {"Vector",       FALSE,-1,         TRUE,MAPFILTER_All,TRUE,   "Displays heading vectors"},
    {"Custom",       FALSE,-1,         FALSE,MAPFILTER_All,TRUE,  "Sets custom filter (omit to disable)"},
    {"CastRadius",   FALSE,0x808080,   FALSE,MAPFILTER_All,FALSE,  "Sets radius of casting circle to # (omit or set to 0 to disable)"},
    {"NormalLabels", 0,-1,         TRUE,MAPFILTER_Invalid,FALSE,   "Toggles non-MQ2 label display"},
    {"Menu",         FALSE,-1,         TRUE,MAPFILTER_Invalid,FALSE,   "Allows display of right-click context menu"},
    {NULL,           FALSE,-1,         FALSE,MAPFILTER_Invalid,FALSE,  NULL}
};





PCSIDLWNDVFTABLE CMyMapViewWnd__OldvfTable=0;
DWORD CMyMapViewWnd__OldDestructor=0;
DWORD CMyMapViewWnd__OldHandleRButtonDown=0;
DWORD CMyMapViewWnd__OldPostDraw=0;

DWORD __declspec(naked) CMyMapViewWnd__Destructor(const BOOL Deallocate)
{
   __asm {   
   push ecx;
   push eax;
   }

    if (CMyMapViewWnd__OldvfTable) {
        // make our own little stack frame here
        // operator delete assumes that it is there
        // it uses (unnecessarily) ebp-4
        __asm {
            push   ebp
            push   eax
            push   eax
            mov           ebp, esp
        }
        delete pMapViewWnd->pvfTable;
        pMapViewWnd->pvfTable=CMyMapViewWnd__OldvfTable;
        CMyMapViewWnd__OldvfTable = NULL;
        __asm {
            pop    eax
            pop    eax
            pop    ebp
        }
    }

   __asm {
   pop eax;
   pop ecx;
   jmp [CMyMapViewWnd__OldDestructor];
   }
}

bool RButtonDown()
{
   CHAR szOut[MAX_STRING]={0};
   if (pCurrentMapLabel)
   {
      MapSelectTarget();
      return false;
   }
   if (!IsOptionEnabled(MAPFILTER_ContextMenu))
      return false;
   return true;
}

VOID __declspec(naked) CMyMapViewWnd__HandleRButtonDown(DWORD point, DWORD unknown)
{
   __asm {   
   push ecx;
   push eax;
  }
   if (RButtonDown())
   {
   __asm {
   pop eax;
   pop ecx;
   jmp [CMyMapViewWnd__OldHandleRButtonDown];
   };
   }
   else
   {
      __asm {
         pop eax;
         pop ecx;
         xor eax, eax;
         retn 8;
      }
   }
}


VOID __declspec(naked) CMyMapViewWnd__PostDraw()
{
   __asm {
   
   push esi;
   mov esi, ecx;

   call [MapUpdate];
   call [MapAttach];

   mov ecx, esi;
   call [CMyMapViewWnd__OldPostDraw];
   push eax;

   call [MapDetach];
   pop eax;
   mov ecx, esi;
   pop esi;
   ret;
   };
}

class CMyMapViewWnd
{
public:
   DWORD Constructor_Trampoline(class CXWnd *);
   DWORD Constructor_Detour(class CXWnd *wnd)
   {
      CMapViewWnd *pWnd=(CMapViewWnd*)this;
      DWORD Ret=Constructor_Trampoline(wnd);
      PCSIDLWNDVFTABLE pvfTable = new CSIDLWNDVFTABLE;
      *pvfTable=*pWnd->pvfTable;

      CMyMapViewWnd__OldvfTable=pWnd->pvfTable;
      pWnd->pvfTable=pvfTable;
      CMyMapViewWnd__OldPostDraw=(DWORD)pWnd->pvfTable->PostDraw2;
      CMyMapViewWnd__OldHandleRButtonDown=(DWORD)pWnd->pvfTable->HandleRButtonDown;
      CMyMapViewWnd__OldDestructor=(DWORD)pWnd->pvfTable->vector_deleting_destructor;
      pWnd->pvfTable->vector_deleting_destructor=CMyMapViewWnd__Destructor;
      pWnd->pvfTable->HandleRButtonDown=CMyMapViewWnd__HandleRButtonDown;
      pWnd->pvfTable->PostDraw2=CMyMapViewWnd__PostDraw;
      return Ret;
   }

   static void StealVFTable()
   {
      if (CMapViewWnd *pWnd=(CMapViewWnd*)pMapViewWnd)
      {
         PCSIDLWNDVFTABLE pvfTable = new CSIDLWNDVFTABLE;
         *pvfTable=*pWnd->pvfTable;

         CMyMapViewWnd__OldvfTable=pWnd->pvfTable;
         pWnd->pvfTable=pvfTable;
         CMyMapViewWnd__OldPostDraw=(DWORD)pWnd->pvfTable->PostDraw2;
         CMyMapViewWnd__OldHandleRButtonDown=(DWORD)pWnd->pvfTable->HandleRButtonDown;
         CMyMapViewWnd__OldDestructor=(DWORD)pWnd->pvfTable->vector_deleting_destructor;
         pWnd->pvfTable->vector_deleting_destructor=CMyMapViewWnd__Destructor;
         pWnd->pvfTable->HandleRButtonDown=CMyMapViewWnd__HandleRButtonDown;
         pWnd->pvfTable->PostDraw2=CMyMapViewWnd__PostDraw;
      }
   }

   static void RestoreVFTable()
   {
      if (CMapViewWnd *pWnd=(CMapViewWnd*)pMapViewWnd)
      {
         if (CMyMapViewWnd__OldvfTable) {
            delete pWnd->pvfTable;
            pWnd->pvfTable=CMyMapViewWnd__OldvfTable;
         }
      }
   }
};

DETOUR_TRAMPOLINE_EMPTY(DWORD CMyMapViewWnd::Constructor_Trampoline(class CXWnd *));

bool Update=true;

#ifndef ISXEQ
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
   DebugSpewAlways("Initializing MQ2Map");

   bmMapRefresh=AddMQ2Benchmark("Map Refresh");
   unsigned long i;
   CHAR szBuffer[MAX_STRING]={0};
    for (i=0;MapFilterOptions[i].szName;i++) {
        sprintf(szBuffer,"%s-Color",MapFilterOptions[i].szName);
        MapFilterOptions[i].Enabled = GetPrivateProfileInt("Map Filters",MapFilterOptions[i].szName,MapFilterOptions[i].Default,INIFileName);
       MapFilterOptions[i].Color = GetPrivateProfileInt("Map Filters",szBuffer,MapFilterOptions[i].DefaultColor,INIFileName) | 0xFF000000;
    }
   MapInit();
   GetPrivateProfileString("Naming Schemes","Normal","%N",MapNameString,MAX_STRING,INIFileName);
   GetPrivateProfileString("Naming Schemes","Target","%N",MapTargetNameString,MAX_STRING,INIFileName);

   for (i=1;i<16>SpawnID != 0) {
       DebugSpewAlways("MQ2Map::OnAddSpawn(%s)",pNewSpawn->Name);
      AddSpawn(pNewSpawn);
    }
}

// This is called each time a spawn is removed from a zone (removed from EQ's list of spawns).
// It is NOT called for each existing spawn when a plugin shuts down.
PLUGIN_API VOID OnRemoveSpawn(PSPAWNINFO pSpawn)
{
   DebugSpewAlways("MQ2Map::OnRemoveSpawn(%s)",pSpawn->Name);
   if (Update)
      RemoveSpawn(pSpawn);
}

PLUGIN_API VOID SetGameState(DWORD GameState)
{
   if (GameState==3)
   {
      MapClear();
   }
}

// This is called each time a ground item is added to a zone
// or for each existing ground item when a plugin first initializes
// NOTE: When you zone, these will come BEFORE OnZoned
PLUGIN_API VOID OnAddGroundItem(PGROUNDITEM pNewGroundItem)
{
   DebugSpewAlways("MQ2Map::OnAddGroundItem(%d)",pNewGroundItem->DropID);
   if (Update)
      AddGroundItem(pNewGroundItem);
}

// This is called each time a ground item is removed from a zone
// It is NOT called for each existing ground item when a plugin shuts down.
PLUGIN_API VOID OnRemoveGroundItem(PGROUNDITEM pGroundItem)
{
   DebugSpewAlways("MQ2Map::OnRemoveGroundItem(%d)",pGroundItem->DropID);
   if (Update)
      RemoveGroundItem(pGroundItem);
}
#endif


MQ2PEQMapCommands.cpp
More +
#include "../MQ2Plugin.h"
#include "MQ2PEQMap.h"

#ifndef ISXEQ
// ***************************************************************************
// Function:    MapFilters
// Description: Our '/mapfilter' command
//              Sets map filters
// Usage:       /mapfilter [options|help]
// ***************************************************************************
VOID MapFilterSetting(PSPAWNINFO pChar, DWORD nMapFilter, PCHAR szValue)
{
    CHAR szBuffer[MAX_STRING] = {0};
    CHAR Buff[MAX_STRING]={0};
    DWORD dwValue = 0;
    PCHAR szFilterMap[] = {
        "hide",
        "show",
        NULL
    };
    if (!pChar) return;
   PMAPFILTER pMapFilter=&MapFilterOptions[nMapFilter];
   if (!RequirementsMet(nMapFilter))
   {
      sprintf(szBuffer,"'%s' requires '%s' option.  Please enable this option first.",pMapFilter->szName,MapFilterOptions[pMapFilter->RequiresOption].szName);
      WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
      return;
   }
    if (!szValue) {
        if (pMapFilter->bIsToggle) {
            sprintf(szBuffer,"%s: %s",pMapFilter->szName,szFilterMap[pMapFilter->Enabled]);
        } else if (nMapFilter == MAPFILTER_Custom) {
            if (IsOptionEnabled(nMapFilter)==0) {
                sprintf(szBuffer,"%s: Off",pMapFilter->szName);
            } else {
                sprintf(szBuffer,"%s: %s",pMapFilter->szName,FormatSearchSpawn(Buff,&MapFilterCustom));
            }
        } else {
            sprintf(szBuffer,"%s: %d",pMapFilter->szName,pMapFilter->Enabled);
        }
        if (pMapFilter->DefaultColor != -1) {
            CHAR szBuffer2[MAX_STRING] = {0};
            DWORD R,G,B;
            R= (pMapFilter->Color&0xFF0000)/0x10000;
            G= (pMapFilter->Color&0xFF00)/0x100;
            B= pMapFilter->Color&0xFF;
            sprintf(szBuffer2,"%s (Color: %d %d %d)",szBuffer,R,G,B);
            strcpy(szBuffer,szBuffer2);
        }
    } else {
        if (pMapFilter->bIsToggle) {
                        if (!stricmp(szFilterMap[0],szValue)) {
                            pMapFilter->Enabled = 0;
                        } else if (!stricmp(szFilterMap[1],szValue)) {
                            pMapFilter->Enabled = 1;
                        } else {
                pMapFilter->Enabled = 1 - pMapFilter->Enabled;
                        }
            sprintf(szBuffer,"%s is now set to: %s",pMapFilter->szName,szFilterMap[IsOptionEnabled(nMapFilter)]);
        } else if (nMapFilter == MAPFILTER_Custom) {
            ClearSearchSpawn(&MapFilterCustom);
            if (szValue[0]==0) {
                pMapFilter->Enabled = 0;
                sprintf(szBuffer,"%s is now set to: Off",pMapFilter->szName);
            } else {
                pMapFilter->Enabled = 1;
                ParseSearchSpawn(szValue,&MapFilterCustom);
                sprintf(szBuffer,"%s is now set to: %s",pMapFilter->szName,FormatSearchSpawn(Buff,&MapFilterCustom));
            }
        } else {
            pMapFilter->Enabled = atoi(szValue);
            sprintf(szBuffer,"%s is now set to: %d",pMapFilter->szName,pMapFilter->Enabled);
        }
    }
    WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
    if (szValue) {
        itoa(pMapFilter->Enabled,szBuffer,10);
        WritePrivateProfileString("Map Filters",pMapFilter->szName,szBuffer,INIFileName);
    }
}

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(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(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(szBuffer,"Option '%s' color set to: %d %d %d",MapFilterOptions[i].szName,R,G,B);
                        WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
                        itoa(MapFilterOptions[i].Color & 0xFFFFFF,szBuffer,10);
                        sprintf(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();
      }
    }
}


VOID MapHighlightCmd(PSPAWNINFO pChar, PCHAR szLine)
{
    CHAR szArg[MAX_STRING] = {0};
    CHAR szBuffer[MAX_STRING] = {0};
    bRunNextCommand = TRUE;
   if (szLine==0 || szLine[0]==0)
   {
      SyntaxError("Usage: /highlight [reset|spawnfilter|[color # # #]]");
      return;
   };

    GetArg(szArg,szLine,1);
   if (!stricmp(szArg,"color"))
   {
      GetArg(szArg,szLine,2);
      if (szLine[0]==0)
      {
         sprintf(szBuffer,"Highlight color: %d %d %d",(HighlightColor&0x00FF0000)>>16,(HighlightColor&0x0000FF00)>>8,(HighlightColor&0x000000FF));
         WriteChatColor(szBuffer);
         return;
      }
        unsigned char R=atoi(szArg);
        unsigned char G=atoi(GetArg(szArg,szLine,3));
        unsigned char B=atoi(GetArg(szArg,szLine,4));
      HighlightColor=0xFF000000 | (R << 16) | (G << 8) | (B);
      sprintf(szBuffer,"Highlight color: %d %d %d",R,G,B);
      WriteChatColor(szBuffer);
      return;
   }
   else if (!stricmp(szArg,"reset"))
   {
      MapHighlight(0);
      WriteChatColor("Highlighting reset",USERCOLOR_DEFAULT);
      return;
   }

   if (PCHARINFO pCharInfo=GetCharInfo())
   {
      SEARCHSPAWN ssHighlight;
      ClearSearchSpawn(&ssHighlight);
      ParseSearchSpawn(szLine,&ssHighlight);
      sprintf(szBuffer,"%d mapped spawns highlighted",MapHighlight(&ssHighlight));
      WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
   }
}

VOID MapHideCmd(PSPAWNINFO pChar, PCHAR szLine)
{
    CHAR szArg[MAX_STRING] = {0};
    CHAR szBuffer[MAX_STRING] = {0};
    bRunNextCommand = TRUE;
   if (szLine==0 || szLine[0]==0)
   {
      SyntaxError("Usage: /maphide [spawnfilter|reset]");
      return;
   };
   GetArg(szArg,szLine,1);
   if (!stricmp(szArg,"reset"))
   {
      MapClear();
      MapGenerate();
      WriteChatColor("Map spawns regenerated",USERCOLOR_DEFAULT);
      return;
   }
   if (PCHARINFO pCharInfo=GetCharInfo())
   {
      SEARCHSPAWN ssHide;
      ClearSearchSpawn(&ssHide);
      ParseSearchSpawn(szLine,&ssHide);
      sprintf(szBuffer,"%d mapped spawns hidden",MapHide(ssHide));
      WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
   }
}

VOID MapShowCmd(PSPAWNINFO pChar, PCHAR szLine)
{
    CHAR szArg[MAX_STRING] = {0};
    CHAR szBuffer[MAX_STRING] = {0};
    bRunNextCommand = TRUE;
   if (szLine==0 || szLine[0]==0)
   {
      SyntaxError("Usage: /mapshow [spawnfilter|reset]");
      return;
   };
   GetArg(szArg,szLine,1);
   if (!stricmp(szArg,"reset"))
   {
      MapClear();
      MapGenerate();
      WriteChatColor("Map spawns regenerated");
      return;
   }
   if (PCHARINFO pCharInfo=GetCharInfo())
   {
      SEARCHSPAWN ssShow;
      ClearSearchSpawn(&ssShow);
      ParseSearchSpawn(szLine,&ssShow);
      sprintf(szBuffer,"%d previously hidden spawns shown",MapShow(ssShow));
      WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
   }
}

VOID MapNames(PSPAWNINFO pChar, PCHAR szLine)
{
   bRunNextCommand = TRUE;
   CHAR szOut[MAX_STRING]={0};
   if (!szLine[0])
   {
      sprintf(szOut,"Normal naming string: %s",MapNameString);
      WriteChatColor(szOut,USERCOLOR_DEFAULT);
      sprintf(szOut,"Target naming string: %s",MapTargetNameString);
      WriteChatColor(szOut,USERCOLOR_DEFAULT);
      return;
   }
    CHAR szArg[MAX_STRING] = {0};
    GetArg(szArg,szLine,1);
    PCHAR szRest = GetNextArg(szLine);
   if (!stricmp(szArg,"target"))
   {
      if (!stricmp(szRest,"reset"))
         strcpy(MapTargetNameString,"%N");
      else
         strcpy(MapTargetNameString,szRest);
      sprintf(szOut,"Target naming string: %s",MapTargetNameString);
      WriteChatColor(szOut,USERCOLOR_DEFAULT);
      WritePrivateProfileString("Naming Schemes","Target",MapTargetNameString,INIFileName);
      MapClear();
      MapGenerate();
   }
   else if (!stricmp(szArg,"normal"))
   {
      if (!stricmp(szRest,"reset"))
         strcpy(MapNameString,"%N");
      else
         strcpy(MapNameString,szRest);
      sprintf(szOut,"Normal naming string: %s",MapNameString);
      WriteChatColor(szOut,USERCOLOR_DEFAULT);
      WritePrivateProfileString("Naming Schemes","Normal",MapNameString,INIFileName);
      MapClear();
      MapGenerate();
   }
   else
   {
      SyntaxError("Usage: /mapnames <target> [value|reset]");
   }
}
#endif

PCHAR DescribeCombo(DWORD Combo)
{
   static char Description[256];
   Description[0]=0;
   int pos=0;
   if (Combo&XKF_SHIFT)
   {
      strcpy(&Description[pos],"shift");
      pos+=5;
   }
   if (Combo&XKF_CTRL)
   {
      if (pos)
      {
         Description[pos]='+';
         pos++;
      }

      strcpy(&Description[pos],"ctrl");
      pos+=4;
   }

   if (Combo&XKF_LALT)
   {
      if (pos)
      {
         Description[pos]='+';
         pos++;
      }

      strcpy(&Description[pos],"lalt");
      pos+=4;
   }

   if (Combo&XKF_RALT)
   {
      if (pos)
      {
         Description[pos]='+';
         pos++;
      }

      strcpy(&Description[pos],"ralt");
   }

   if (!Description[0])
   {
      return "Invalid";
   }

   return &Description[0];
}

DWORD ParseCombo(PCHAR Combo)
{
   DWORD Ret=0;
   if (!Combo || !Combo[0])
      return 0;
   CHAR Copy[MAX_STRING];
   strcpy(Copy,Combo);
   Combo=strtok(Copy,"+");
   while(Combo)
   {
      if (!stricmp(Combo,"ctrl"))
         Ret+=XKF_CTRL;
      else if (!stricmp(Combo,"shift"))
         Ret+=XKF_SHIFT;
      else if (!stricmp(Combo,"lalt"))
         Ret+=XKF_LALT;
      else if (!stricmp(Combo,"ralt"))
         Ret+=XKF_RALT;
      else if (!stricmp(Combo,"alt"))
         Ret+=XKF_LALT;
      Combo=strtok(NULL,"+");
   }
   return Ret;
}
#ifndef ISXEQ
VOID MapClickCommand(PSPAWNINFO pChar, PCHAR szLine)
{
   if (!szLine[0])
   {
      SyntaxError("Usage: /mapclick <list|<key> <clear>>");
      return;
   }
   bRunNextCommand = TRUE;

    CHAR szArg[MAX_STRING] = {0};
   CHAR szBuffer[MAX_STRING] = {0};
    GetArg(szArg,szLine,1);
    PCHAR szRest = GetNextArg(szLine);

   if (!stricmp(szArg,"list"))
   {
      int Count=0;
      for (int i=1 ; i < 16 ; i++)
      {
         if (MapSpecialClickString[i][0])
         {
            sprintf(szBuffer,"%s: %s",DescribeCombo(i),MapSpecialClickString[i]);
            WriteChatColor(szBuffer);
            Count++;
         }
      }
      sprintf(szBuffer,"%d special right-click commands",Count);
      WriteChatColor(szBuffer);
      return;
   }

   DWORD Combo=ParseCombo(szArg);
   if (!Combo)
   {
      sprintf(szBuffer,"Invalid combo '%s'",szArg);
      WriteChatColor(szBuffer);
      return;
   }

   if (!szRest[0])
   {
      sprintf(szBuffer,"%s: %s",DescribeCombo(Combo),MapSpecialClickString[Combo]);
      WriteChatColor(szBuffer);
      return;
   }

   if (!stricmp(szRest,"clear"))
   {

      MapSpecialClickString[Combo][0]=0;

      sprintf(szBuffer,"KeyCombo%d",Combo);
      WritePrivateProfileString("Right Click",szBuffer,MapSpecialClickString[Combo],INIFileName);
      sprintf(szBuffer,"%s cleared",DescribeCombo(Combo));
      WriteChatColor(szBuffer);
      return;
   }

   strcpy(MapSpecialClickString[Combo],szRest);
   sprintf(szBuffer,"KeyCombo%d",Combo);
   WritePrivateProfileString("Right Click",szBuffer,MapSpecialClickString[Combo],INIFileName);
   sprintf(szBuffer,"%s: %s",DescribeCombo(Combo),MapSpecialClickString[Combo]);
   WriteChatColor(szBuffer);
}


#endif


MQ2PEQMap.h
More +
#include <map>
using namespace std;
#ifdef ISXEQ
#include "ISXEQMap.h"
#endif

#define MAPFILTER_All           0
#define MAPFILTER_PC            1
#define MAPFILTER_PCConColor   2
#define MAPFILTER_Group         3
#define MAPFILTER_Mount         4
#define MAPFILTER_NPC           5
#define MAPFILTER_NPCConColor   6
#define MAPFILTER_Untargetable  7
#define MAPFILTER_Pet           8
#define MAPFILTER_Corpse        9
#define MAPFILTER_Chest         10
#define MAPFILTER_Trigger       11
#define MAPFILTER_Trap           12
#define MAPFILTER_Timer         13
#define MAPFILTER_Ground        14
#define MAPFILTER_Target        15
#define MAPFILTER_TargetLine   16
#define MAPFILTER_TargetRadius   17
#define MAPFILTER_TargetMelee   18
#define MAPFILTER_Vector        19
#define MAPFILTER_Custom       20
#define MAPFILTER_CastRadius    21
#define MAPFILTER_NormalLabels  22
#define MAPFILTER_ContextMenu   23
#define MAPFILTER_NUMBER        24
#define MAPFILTER_Invalid      (-1)
// normal labels



typedef struct _MAPFILTER {
    PCHAR szName;
//    DWORD Index;
   DWORD Default;
    DWORD DefaultColor;
    BOOL bIsToggle;
   DWORD RequiresOption;
   BOOL RegenerateOnChange;
    PCHAR szHelpString;

   DWORD Enabled;
   DWORD Color;

} MAPFILTER, *PMAPFILTER;

extern unsigned long bmMapRefresh;

extern DWORD HighlightColor;

extern CHAR MapNameString[MAX_STRING];
extern CHAR MapTargetNameString[MAX_STRING];
extern SEARCHSPAWN MapFilterCustom;
extern MAPFILTER MapFilterOptions[];
extern CHAR MapSpecialClickString[16][MAX_STRING];


/* COMMANDS */
VOID MapFilters(PSPAWNINFO pChar, PCHAR szLine);
VOID MapFilterSetting(PSPAWNINFO pChar, DWORD nMapFilter, PCHAR szValue=NULL);
VOID MapHighlightCmd(PSPAWNINFO pChar, PCHAR szLine);
VOID MapHideCmd(PSPAWNINFO pChar, PCHAR szLine);
VOID MapShowCmd(PSPAWNINFO pChar, PCHAR szLine);
VOID MapNames(PSPAWNINFO pChar, PCHAR szLine);
VOID MapClickCommand(PSPAWNINFO pChar, PCHAR szLine);

/* API */
VOID MapInit();
VOID MapClear();
VOID MapGenerate();
DWORD MapHighlight(SEARCHSPAWN *pSearch);
DWORD MapHide(SEARCHSPAWN &Search);
DWORD MapShow(SEARCHSPAWN &Search);
VOID MapUpdate();
VOID MapAttach();
VOID MapDetach();

VOID MapSelectTarget();

#ifndef ISXEQ
BOOL dataMapSpawn(PCHAR szIndex, MQ2TYPEVAR &Ret);
#else
bool dataMapSpawn(int argc, char *argv[], LSTYPEVAR &Ret);
#endif

struct _MAPSPAWN* AddSpawn(PSPAWNINFO pNewSpawn,BOOL ExplicitAllow=false);
bool RemoveSpawn(PSPAWNINFO pSpawn);
void AddGroundItem(PGROUNDITEM pGroundItem);
void RemoveGroundItem(PGROUNDITEM pGroundItem);

static inline BOOL IsOptionEnabled(DWORD Option)
{
   if (Option==MAPFILTER_Invalid)
      return true;
   return (MapFilterOptions[Option].Enabled && IsOptionEnabled(MapFilterOptions[Option].RequiresOption));
}

static inline BOOL RequirementsMet(DWORD Option)
{
   if (Option==MAPFILTER_Invalid)
      return true;
   return (IsOptionEnabled(MapFilterOptions[Option].RequiresOption));
}

Mon Jun 28, 2010 9:11 pm
Project Lead
General MQ2PEQMap Source(Titanium)
Reply