Want excuse me how to take the unit linked list?
How to obtain a handle to the unit?



It is my current use of methods[WC3 1.24X]:
Code:
BOOL APIENTRY DllMain( HMODULE hModule,
       DWORD  ul_reason_for_call,
       LPVOID lpReserved
       )
{
 switch (ul_reason_for_call)
 {
 case DLL_PROCESS_ATTACH:
  DisableThreadLibraryCalls(hModule);
  EnableDebugPriv(); 
  Init();
 case DLL_THREAD_ATTACH:
 case DLL_THREAD_DETACH:
 case DLL_PROCESS_DETACH:
  break;
 }
 return TRUE;
}
void Init()
{
 //Hmodule_D3D8=(HMODULE)GetModuleHandle("d3d8");
 OpenWar3();
 GetVersionAndInit(GameAddr);
 initGameAddress();
 HookChat();
 Config();
 MinMap=CASIni.MinMap;
 if (CASIni.ManaBar==TRUE)
 {
  InitManaBar();
  ManaBarOn();
 }
 if (CASIni.RuneNotifier==TRUE)
 {
  RuneNotifierON();
 }
 if (CASIni.ZSGWS==TRUE)
 {
  HookGetPlayerOrder1();
  HookGetPlayerOrder2();
 }
 if (CASIni.NumShow)
 {
  SetTimer(Hwnd_War3,5555,100,(TIMERPROC)NumShowProc);
 }
 //D3DInit();
 UINT Re=SetTimer(Hwnd_War3,4444,100,(TIMERPROC)TimerProc);
 if(Re==0)
 {
  ::MessageBox(NULL,"SetTimerHook ERROR","eror",0);
 }
 
}
void Config()
{
 fstream stream("CasWar.ini", ios::in);
 if(!stream.is_open())
 {
  ofstream newStream("CasWar.ini", ios::out);
  newStream.close();    
  do 
  {
   CIniWriter iniWriter(".\\CasWar.ini");
   iniWriter.WriteBoolean("CasWar", "小地图亮圈", false);
   iniWriter.WriteBoolean("CasWar", "显示魔法条", true);
   iniWriter.WriteBoolean("CasWar", "数显血蓝", true);
   iniWriter.WriteBoolean("ZSGWS", "躲踢躲雷", false);
   iniWriter.WriteBoolean("DOTA", "神符提示", false);
  } while (0);
  do 
  {
   CIniReader iniReader(".\\CasWar.ini");
   CASIni.MinMap=iniReader.ReadBoolean("CasWar","小地图亮圈",false);
   CASIni.ManaBar=iniReader.ReadBoolean("CasWar","显示魔法条",true);
   CASIni.NumShow=iniReader.ReadBoolean("CasWar","数显血蓝",true);
   CASIni.ZSGWS=iniReader.ReadBoolean("ZSGWS","躲踢躲雷",false);
   CASIni.RuneNotifier=iniReader.ReadBoolean("DOTA","神符提示",false);
  } while (0);
 }
 else
 {
  do 
  {
   stream.close();
   CIniReader iniReader(".\\CasWar.ini");
   CASIni.MinMap=iniReader.ReadBoolean("CasWar","小地图亮圈",false);
   CASIni.ManaBar=iniReader.ReadBoolean("CasWar","显示魔法条",true);
   CASIni.NumShow=iniReader.ReadBoolean("CasWar","数显血蓝",true);
   CASIni.ZSGWS=iniReader.ReadBoolean("ZSGWS","躲踢躲雷",false);
   CASIni.RuneNotifier=iniReader.ReadBoolean("DOTA","神符提示",false);
  } while (0);
 }
}
BOOL OpenWar3()
{
    Hwnd_War3=FindWindow("Warcraft III",NULL);  
    if (Hwnd_War3==NULL)
    {  
  ::MessageBox(NULL,"1->is war3 started?","error",0);
        return FALSE;     
    } 
 Tid_War3=GetWindowThreadProcessId(Hwnd_War3, &Pid_War3);  
    Handle_War3=OpenProcess(PROCESS_ALL_ACCESS, false,Pid_War3); 
 if(!ListProcessModules())
 {
  ::MessageBox(NULL,"枚举魔兽模块失败","ERROR",0);
        return FALSE;
 };
 return true;
}
BOOL ListProcessModules()
{
 HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
 MODULEENTRY32 me32;
 hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, Pid_War3 );
 if( hModuleSnap == INVALID_HANDLE_VALUE )
 {
  return FALSE;
 }
 me32.dwSize = sizeof( MODULEENTRY32 );
 if( !Module32First( hModuleSnap, &me32 ) )
 {
  CloseHandle( hModuleSnap );  
  return FALSE;
 }
 do
 {
  if(lstrcmpi(me32.szModule,"game.dll")==0)
  {
   GameSize=me32.modBaseSize;
   GameAddr=(DWORD)me32.modBaseAddr;
  };
  if(lstrcmpi(me32.szModule,"storm.dll")==0)
  {
   
   StormSize=me32.modBaseSize;
   StormAddr=(DWORD)me32.modBaseAddr;
  }
 } while( Module32Next( hModuleSnap, &me32 ) );
 CloseHandle( hModuleSnap );
 if((GameAddr!=NULL)&&(StormAddr!=NULL))
  return TRUE;
 return FALSE;
}
void GetVersionAndInit(DWORD dwGameDllBase)
{
 
 DWORD veraddr;
 veraddr = dwGameDllBase + 0x636F5D;
 unsigned char p124b[] ={0x80, 0xBE, 0xA8, 0x01}; 
 unsigned char p124e[] = {0x8B, 0x50, 0x3C, 0x3B};
 unsigned char p125b[] = {0x10, 0x75, 0x72, 0xC7};
 unsigned char  p126[] = { 0xb6, 0x89,0x7c, 0x73};
 
 if (0 == memcmp(p124b, (unsigned char*)veraddr, sizeof(p124b)))
 {
  War3Ver=_124B;
 }
 else if (0 == memcmp(p124e, (unsigned char*)veraddr, sizeof(p124e)))
 {
  War3Ver=_124E;
 }
 else if (0 == memcmp(p126, (unsigned char*)(veraddr-0x2), sizeof(p126)))
 {
  War3Ver=_126A;
 }
 else
 {
  War3Ver=_UNKNOWN;
 } 
}
void EnableDebugPriv()  
{  
 
    HANDLE hToken;  
 
    LUID sedebugnameValue;  
 
    TOKEN_PRIVILEGES tkp;  
 
    OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);  
 
    LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue);  
 
    tkp.PrivilegeCount = 1;  
 
    tkp.Privileges[0].Luid = sedebugnameValue;  
 
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;  
 
    AdjustTokenPrivileges(hToken, false, &tkp, sizeof tkp, NULL, NULL);  
 
    CloseHandle(hToken);  
 
} 
void GameBegin() 
{
 ClearText();
 DisplayGameText(WideCharToUTF8(L"[|cFFCE0005Castiel_Silt|r]|cFFFFFF00插件加载成功!|r"));
 DisplayGameText("");
 DisplayHelpMenu();
 player_color[0] = 0xFFFF0202;
 player_color[1] = 0xFF0041FF;
 player_color[2] = 0xFF1BE6D8;
 player_color[3] = 0xFF530080;
 player_color[4] = 0xFFFFFC00;
 player_color[5] = 0xFFFE890D;
 player_color[6] = 0xFF1FBF00;
 player_color[7] = 0xFFE55AAF;
 player_color[8] = 0xFF949596;
 player_color[9] = 0xFF7DBEF1;
 player_color[10] = 0xFF0F6145;
 player_color[11] = 0xFF4D2903;
 player_color[12] = 0xFF272727;
 player_color[13] = 0xFF272727;
 player_color[14] = 0xFF272727;
 player_color[15] = 0xFF272727; 
 IsGameing=TRUE;
} 
void GameOver() 
{
 for(int i=0;i<12;i++)
 {
  htp[i].Handle=0;
  htp[i].HeroAddr=0;
  htp[i].Id=0;
  htp[i].Team=0;
  htp[i].Init=FALSE;
  if (htp[i].tag!=NULL)
  {
   WaitToRemoveTextTag(htp[i].tag);
   htp[i].tag=NULL;
  }
 }
 IsGameing=FALSE;
}
VOID CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
 DWORD HeroNum=0;
 BYTE GameState=0;
 memcpy(&HeroNum,(LPCVOID)(addHeroNum),4);
 memcpy(&GameState,(LPCVOID)(addGameState),1);
 if (GameState==0xC4)
 {
  if (!IsGameing)
  {
   GameBegin();
  }
  if (HeroNum>0)
  {
   Show();
  }
 } 
 else
 {
  if (IsGameing)
  {
   GameOver();
  }
 }
}; 
VOID Show()
{
 float x=100,y=100; 
 DWORD HeroAddrPoint;
 DWORD HeroPoint;
 DWORD HeroNext;
 BYTE Dead=0;
 DWORD Team;
 DWORD dwColor = 0xFFFFFFFF;
 
 UINT a=GetLocalPlayer();
 if(a<=6)
 {
  LocalPlayerTeamId=1;
 }
 else
 {
  LocalPlayerTeamId=2;
 }
 memcpy(&HeroPoint,(LPCVOID)(StormAddr+0x55514),4);
 HeroAddrPoint=HeroPoint+0x98;
 memcpy(&HeroNext,(LPVOID)HeroAddrPoint,4);
 int count=-1;
 while(HeroNext!=0)
 {
  BOOL isInit=FALSE;
  count=count+1;
  DWORD HeroTeye;
  DWORD HeroHandle;
  HeroHandle=AddrToHandle(HeroNext);
  memcpy(&Team,(LPVOID)(HeroNext+0x24),4);
  memcpy(&Dead,(LPVOID)(HeroNext+0x20),1);
  
  DWORD rgb = player_color[Team];
  BYTE r = *((BYTE*)&rgb + 2);
  BYTE g = *((BYTE*)&rgb + 1);
  BYTE b = *((BYTE*)&rgb);
  if (Team<=6)
  {
   HeroTeye=1;
  } 
  else
  {
   HeroTeye=2;
  }
  if (Team==a)
  {
   MyHero=HeroHandle;
  }
  if ((Dead==0x46)&&(LocalPlayerTeamId!=HeroTeye))
  {
   
   float pingtime=0.1;
   if (MinMap)
   {
    x=GetUnitX(HeroHandle);
    y=GetUnitY(HeroHandle);
    PingMinimapEx(&x, &y, &pingtime, r, g, b, false);
   } 
  } 
  if (Dead==0x46)
  {
   htp[count].Dead=FALSE;
  } 
  else
  {
   htp[count].Dead=TRUE;
  }
  for(int i=0;i<12;i++)
  {
   if (htp[i].HeroAddr==HeroNext)
   {
    isInit=TRUE;
   }
  }
  if (isInit==FALSE)
  {
   htp[count].Handle=HeroHandle;
   htp[count].HeroAddr=HeroNext;
   htp[count].Id=Team;
   htp[count].Init=TRUE;
   htp[count].Team=HeroTeye;
   /*sprintf(puf,"Handle:%d Id:%d Team:%d",htp[count].Handle,htp[count].Id,htp[count].Team);
   OutputDebugString(puf);*/
  }  
  HeroAddrPoint=HeroAddrPoint+0x18;
  memcpy(&HeroNext,(LPVOID)HeroAddrPoint,4);
  
 } 
}
VOID CALLBACK NumShowProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
 char msg[100];
 
 if (IsGameing)
 {
  for (int i=0;i<12;i++)
  {
   if (htp[i].Init==TRUE)
   {
    if (htp[i].tag==NULL)
    {
     htp[i].tag=CreateTextTag("nothing", 1, 0, -1, 0, 0);
    } 
    else
    {
     if (htp[i].Team!=LocalPlayerTeamId)
     {
      DWORD rgb = player_color[i];
      BYTE r = *((BYTE*)&rgb + 2);
      BYTE g = *((BYTE*)&rgb + 1);
      BYTE b = *((BYTE*)&rgb);
      sprintf(msg,WideCharToUTF8(L"|cFFFF0000%s|r |cff60d020%0.0f|r/|cff4090FF%0.0f|r"),
       GetUnitName(htp[i].Handle),
       GetUnitState(htp[i].Handle,UNIT_STATE_LIFE),
       GetUnitState(htp[i].Handle,UNIT_STATE_MANA));
      MoveTextTagToUnitLoc(htp[i].tag, htp[i].Handle, 0);
      ChangeTexttagText(htp[i].tag, msg, 20, -1); 
      UnitAddIndicator(htp[i].Handle,r, g, b,255);
     }
     else
     {
      sprintf(msg,WideCharToUTF8(L"|cff60d020%0.0f|r/|cff4090FF%0.0f|r"),
       GetUnitState(htp[i].Handle,UNIT_STATE_LIFE),
       GetUnitState(htp[i].Handle,UNIT_STATE_MANA));
      MoveTextTagToUnitLoc(htp[i].tag, htp[i].Handle, 10);
      ChangeTexttagText(htp[i].tag, msg, 20, -1); 
     }
     
    }
   
   }
  }
 } 
}